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

esbuild-plugin-sass

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esbuild-plugin-sass - npm Package Compare versions

Comparing version 0.7.0 to 1.0.0

2

index.d.ts
import { Plugin } from "esbuild";
import sass = require("sass");
declare type SassOptions = Omit<sass.Options, 'file'>;
declare type SassOptions = Omit<sass.Options<"sync">, "file">;
interface Options {

@@ -5,0 +5,0 @@ rootDir?: string;

@@ -5,7 +5,5 @@ "use strict";

const sass = require("sass");
const util = require("util");
const tmp = require("tmp");
const path = require("path");
const csstree = require("css-tree");
const sassRender = util.promisify(sass.render);
async function replaceUrls(css, newCssFileName, sourceDir, rootDir, externals) {

@@ -35,3 +33,3 @@ const ast = csstree.parse(css);

const normalizedUrl = value.type === "String" ? normalizeQuotes(value.value) : value.value;
if (external_1.isExternal(normalizedUrl, externals)) {
if ((0, external_1.isExternal)(normalizedUrl, externals)) {
return;

@@ -75,3 +73,3 @@ }

function fixCssUrl(filePath) {
return filePath.split(path.sep).join('/');
return filePath.split(path.sep).join("/");
}

@@ -106,3 +104,5 @@ function resolveUrl(url, originalFolder, rootDir) {

build.onResolve({ filter: /.\.(scss|sass)$/, namespace: "file" }, async (args) => {
const sourceFullPath = path.resolve(args.resolveDir, args.path);
const sourceFullPath = require.resolve(args.path, {
paths: [args.resolveDir],
});
const sourceExt = path.extname(sourceFullPath);

@@ -116,6 +116,6 @@ const sourceBaseName = path.basename(sourceFullPath, sourceExt);

// Compile SASS to CSS
const sassRenderResult = await sassRender({ ...customSassOptions, file: sourceFullPath });
const sassRenderResult = await sass.compile(sourceFullPath, customSassOptions);
let css = sassRenderResult.css.toString();
// Replace all relative urls
css = await replaceUrls(css, tmpFilePath, sourceDir, rootDir, external_1.compilePatterns(external));
css = await replaceUrls(css, tmpFilePath, sourceDir, rootDir, (0, external_1.compilePatterns)(external));
// Write result file

@@ -125,3 +125,5 @@ await fs.writeFile(tmpFilePath, css);

path: tmpFilePath,
watchFiles: sassRenderResult.stats.includedFiles,
watchFiles: sassRenderResult.loadedUrls
.filter((x) => x.protocol === "file:")
.map((x) => x.pathname),
};

@@ -128,0 +130,0 @@ });

{
"name": "esbuild-plugin-sass",
"version": "0.7.0",
"version": "1.0.0",
"description": "Plugin for esbuild to support SASS styles",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"all": "npm-run-all --serial --print-label",
"build": "tsc",
"test:prepare": "npx pack-to-folder --renameTo=.npm-package --forceRewrite",
"test:unit": "tape \"tests/*.js\"",
"test:clean": "npx rimraf .npm-package",
"test": "npm run all build test:*",
"prepare": "npm run build"
},
"author": {

@@ -32,6 +23,6 @@ "name": "Nikolai Mavrenkov",

"dependencies": {
"css-tree": "^1.1.2",
"fs-extra": "^9.0.1",
"sass": "^1.32.4",
"tmp": "^0.2.1"
"css-tree": "1.1.3",
"fs-extra": "10.0.0",
"sass": "1.47.0",
"tmp": "0.2.1"
},

@@ -42,21 +33,20 @@ "peerDependencies": {

"devDependencies": {
"@types/css-tree": "^1.0.5",
"@types/fs-extra": "^9.0.8",
"@types/node": "^14.14.35",
"@types/sass": "^1.16.0",
"@types/tmp": "^0.2.0",
"esbuild": "^0.11.14",
"husky": "^4.3.7",
"lint-staged": "^10.5.3",
"npm-run-all": "^4.1.5",
"pack-to-folder": "^1.0.0",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"tap-spec": "^5.0.0",
"tape": "^5.1.1",
"typescript": "^4.2.3"
"@types/css-tree": "1.0.7",
"@types/fs-extra": "9.0.13",
"@types/node": "14.14.35",
"@types/sass": "1.43.1",
"@types/tmp": "0.2.3",
"esbuild": "0.14.10",
"husky": "7.0.4",
"lint-staged": "12.1.7",
"npm-run-all": "4.1.5",
"pack-to-folder": "1.0.0",
"prettier": "2.5.1",
"rimraf": "3.0.2",
"tape": "5.4.0",
"typescript": "4.5.4"
},
"husky": {
"hooks": {
"pre-commit": "npx lint-staged"
"pre-commit": "pnpm exec lint-staged"
}

@@ -76,3 +66,12 @@ },

"internals/*.d.ts.map"
]
}
],
"scripts": {
"all": "npm-run-all --serial --print-label",
"build": "pnpm exec tsc",
"test:prepare": "pnpm exec pack-to-folder --renameTo=.npm-package --forceRewrite",
"test:unit": "pnpm exec tape \"tests/*.js\"",
"test:clean": "pnpm exec rimraf .npm-package",
"test": "pnpm run all build test:*"
},
"readme": "# esbuild-plugin-sass\n\n![Node.js CI](https://github.com/koluch/esbuild-plugin-sass/workflows/Node.js%20CI/badge.svg)\n\nPlugin for [esbuild](https://esbuild.github.io/) to support Sass style sheets\n\n## Install\n\n```shell\nnpm i esbuild esbuild-plugin-sass\n```\n\nor, using [pnpm](https://pnpm.io/):\n\n```shell\npnpm add esbuild esbuild-plugin-sass\n```\n\n## Usage example\n\nCreate file `src/test.scss`:\n\n```scss\nbody {\n &.isRed {\n background: red;\n }\n}\n```\n\nCreate file `src/index.js`:\n\n```js\nimport \"./test.scss\";\n```\n\nCreate file `build.js`:\n\n```js\nconst esbuild = require(\"esbuild\");\nconst sassPlugin = require(\"esbuild-plugin-sass\");\n\nesbuild\n .build({\n entryPoints: [\"src/index.js\"],\n bundle: true,\n outfile: \"bundle.js\",\n plugins: [sassPlugin()],\n })\n .catch((e) => console.error(e.message));\n```\n\nRun:\n\n```console\n$ node build.js\n```\n\nFile named `bundle.css` with following content will be created:\n\n```css\nbody.isRed {\n background: red;\n}\n```\n\n# API\n\nModule default-exports a function, which need to be called with or without options object:\n\n```typescript\nimport sass = require(\"sass\");\n\ninterface Options {\n rootDir?: string;\n customSassOptions?: Omit<sass.Options, \"file\">;\n}\n\nexport = (options: Options = {}) => Plugin;\n```\n\nSupported options:\n\n- `rootDir` - folder to resolve paths against\n- `customSassOptions` - options object passed to `sass` [render](https://sass-lang.com/documentation/js-api#render) function, except `file` option, which is overriden by plugin for each processed file\n"
}

@@ -13,2 +13,8 @@ # esbuild-plugin-sass

or, using [pnpm](https://pnpm.io/):
```shell
pnpm add esbuild esbuild-plugin-sass
```
## Usage example

@@ -15,0 +21,0 @@

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