Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esbuild-sass-plugin

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esbuild-sass-plugin - npm Package Compare versions

Comparing version 1.4.2 to 1.4.3

lib/importer.d.ts

0

lib/index.d.ts

@@ -0,0 +0,0 @@ import { OnLoadResult } from "esbuild";

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { OnLoadResult } from "esbuild";

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=options.js.map
import { Plugin } from "esbuild";
import { SassPluginOptions } from "./index";
export declare function sassPlugin(options?: SassPluginOptions): Plugin;

46

lib/plugin.js

@@ -11,2 +11,3 @@ "use strict";

const utils_1 = require("./utils");
const importer_1 = require("./importer");
const cssTextModule = cssText => `\

@@ -79,27 +80,22 @@ export default \`

: () => type;
function pathResolve({ resolveDir, path }) {
return path_1.resolve(resolveDir, path);
function pathResolve({ resolveDir, path, importer }) {
return path_1.resolve(resolveDir || path_1.dirname(importer), path);
}
function requireResolve({ resolveDir, path }) {
function requireResolve({ resolveDir, path, importer }) {
if (!resolveDir) {
resolveDir = path_1.dirname(importer);
}
const paths = options.includePaths ? [resolveDir, ...options.includePaths] : [resolveDir];
return require.resolve(path, { paths });
}
const moduleDirectory = utils_1.findModuleDirectory(options);
if (!moduleDirectory) {
console.error("Unable to find 'node_modules' from: " + options.basedir);
process.exit(1);
}
function readCssFileSync(path) {
return { css: fs_1.readFileSync(path, "utf-8"), watchFiles: [path] };
}
const importer = importer_1.createSassImporter(options);
function renderSync(file) {
const { css, stats: { includedFiles: watchFiles } } = sass.renderSync({
importer(url, prev) {
const relativeBaseUrl = utils_1.moduleRelativeUrl(path_1.posix.dirname(prev), moduleDirectory);
return { file: url.replace(/^~/, relativeBaseUrl) };
},
...options,
file
});
return { css: css.toString("utf-8"), watchFiles };
const { css, stats: { includedFiles } } = sass.renderSync({ importer, ...options, file });
return {
css: css.toString("utf-8"),
watchFiles: includedFiles
};
}

@@ -111,2 +107,8 @@ const cache = !options.cache

: new Map();
function collectStats(watchFiles) {
return Promise.all(watchFiles.map(filename => fs_1.promises.stat(filename)));
}
function maxMtimeMs(stats) {
return stats.reduce((max, { mtimeMs }) => Math.max(max, mtimeMs), 0);
}
return {

@@ -129,7 +131,7 @@ name: "sass-plugin",

let watchFiles = cached.result.watchFiles;
let stats = await Promise.all(watchFiles.map(filename => fs_1.promises.stat(filename)));
let stats = await collectStats(watchFiles);
for (const { mtimeMs } of stats) {
if (mtimeMs > cached.mtimeMs) {
cached.result = await transform(watchFiles[0], cached.type);
cached.mtimeMs = stats.reduce((max, { mtimeMs }) => Math.max(max, mtimeMs), 0);
cached.mtimeMs = maxMtimeMs(stats);
break;

@@ -143,3 +145,7 @@ }

let result = await transform(filename, type);
group.set(args.path, { type, mtimeMs: Date.now(), result });
group.set(args.path, {
type,
mtimeMs: maxMtimeMs(await collectStats(result.watchFiles)),
result
});
return result;

@@ -146,0 +152,0 @@ };

import { SassPluginOptions } from "./index";
export declare function loadSass({ implementation: module, basedir }: SassPluginOptions): any;
export declare function findModuleDirectory({ basedir }: SassPluginOptions): string | undefined;
export declare function moduleRelativeUrl(basedir: any, pathname: any): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.moduleRelativeUrl = exports.findModuleDirectory = exports.loadSass = void 0;
const fs_1 = require("fs");
exports.moduleRelativeUrl = exports.loadSass = void 0;
const path_1 = require("path");

@@ -16,14 +15,2 @@ function loadSass({ implementation: module = "sass", basedir = process.cwd() }) {

exports.loadSass = loadSass;
function findModuleDirectory({ basedir = process.cwd() }) {
do {
const path = path_1.join(basedir, "node_modules");
if (fs_1.existsSync(path)) {
return path;
}
else {
basedir = path_1.dirname(basedir);
}
} while (basedir !== "/");
}
exports.findModuleDirectory = findModuleDirectory;
function moduleRelativeUrl(basedir, pathname) {

@@ -30,0 +17,0 @@ let url = path_1.relative(basedir, pathname).replace(/\\/g, "/");

{
"name": "esbuild-sass-plugin",
"version": "1.4.2",
"version": "1.4.3",
"description": "esbuild plugin for sass/scss files supporting both css loader and css result import (lit-element)",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -0,0 +0,0 @@ ![logo created with https://cooltext.com](https://images.cooltext.com/5500652.png)

@@ -0,0 +0,0 @@ import {OnLoadResult} from "esbuild";

import {Loader, OnLoadArgs, OnLoadResult, OnResolveArgs, Plugin} from "esbuild";
import {promises as fsp, readFileSync} from "fs";
import {dirname, posix, resolve} from "path";
import {promises as fsp, readFileSync, Stats} from "fs";
import {dirname, resolve} from "path";
import picomatch from "picomatch";
import {CachedResult, SassPluginOptions} from "./index";
import {findModuleDirectory, loadSass, moduleRelativeUrl} from "./utils";
import {loadSass} from "./utils";
import {createSassImporter} from "./importer";

@@ -84,7 +85,10 @@ const cssTextModule = cssText => `\

function pathResolve({resolveDir, path}: OnResolveArgs) {
return resolve(resolveDir, path);
function pathResolve({resolveDir, path, importer}: OnResolveArgs) {
return resolve(resolveDir || dirname(importer), path);
}
function requireResolve({resolveDir, path}: OnResolveArgs) {
function requireResolve({resolveDir, path, importer}: OnResolveArgs) {
if (!resolveDir) {
resolveDir = dirname(importer);
}
const paths = options.includePaths ? [resolveDir, ...options.includePaths] : [resolveDir];

@@ -94,8 +98,2 @@ return require.resolve(path, {paths});

const moduleDirectory = findModuleDirectory(options);
if (!moduleDirectory) {
console.error("Unable to find 'node_modules' from: " + options.basedir);
process.exit(1);
}
function readCssFileSync(path: string) {

@@ -105,12 +103,15 @@ return {css: readFileSync(path, "utf-8"), watchFiles: [path]};

const importer = createSassImporter(options);
function renderSync(file) {
const {css, stats: {includedFiles: watchFiles}} = sass.renderSync({
importer(url, prev) {
const relativeBaseUrl = moduleRelativeUrl(posix.dirname(prev), moduleDirectory);
return {file: url.replace(/^~/, relativeBaseUrl!)};
},
...options,
file
});
return {css: css.toString("utf-8"), watchFiles};
const {
css,
stats: {
includedFiles
}
} = sass.renderSync({importer, ...options, file});
return {
css: css.toString("utf-8"),
watchFiles: includedFiles
};
}

@@ -124,2 +125,10 @@

function collectStats(watchFiles):Promise<Stats[]> {
return Promise.all(watchFiles.map(filename => fsp.stat(filename)));
}
function maxMtimeMs(stats: Stats[]) {
return stats.reduce((max, {mtimeMs}) => Math.max(max, mtimeMs), 0);
}
return {

@@ -148,7 +157,7 @@ name: "sass-plugin",

let watchFiles = cached.result.watchFiles!;
let stats = await Promise.all(watchFiles.map(filename => fsp.stat(filename)));
let stats = await collectStats(watchFiles);
for (const {mtimeMs} of stats) {
if (mtimeMs > cached.mtimeMs) {
cached.result = await transform(watchFiles[0], cached.type);
cached.mtimeMs = stats.reduce((max, {mtimeMs})=>Math.max(max, mtimeMs),0);
cached.mtimeMs = maxMtimeMs(stats);
break;

@@ -162,3 +171,7 @@ }

let result = await transform(filename, type);
group.set(args.path, {type, mtimeMs: Date.now(), result});
group.set(args.path, {
type,
mtimeMs: maxMtimeMs(await collectStats(result.watchFiles)),
result
});
return result;

@@ -165,0 +178,0 @@ };

@@ -1,3 +0,2 @@

import {existsSync} from "fs";
import {dirname, join, relative} from "path";
import {relative} from "path";
import {SassPluginOptions} from "./index";

@@ -14,13 +13,2 @@

export function findModuleDirectory({basedir = process.cwd()}: SassPluginOptions) {
do {
const path = join(basedir, "node_modules");
if (existsSync(path)) {
return path;
} else {
basedir = dirname(basedir);
}
} while (basedir !== "/");
}
export function moduleRelativeUrl(basedir, pathname) {

@@ -27,0 +15,0 @@ let url = relative(basedir, pathname).replace(/\\/g, "/");

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc