esbuild-plugin-sass
Advanced tools
Comparing version 0.7.0 to 1.0.0
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; |
18
index.js
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
12531
14
174
1
86
2
+ Addedanymatch@3.1.3(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbinary-extensions@2.3.0(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedchokidar@3.6.0(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs-extra@10.0.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedimmutable@4.3.7(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-binary-path@2.1.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addednormalize-path@3.0.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedreaddirp@3.6.0(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedsass@1.47.0(transitive)
+ Addedtmp@0.2.1(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removed@parcel/watcher@2.5.0(transitive)
- Removed@parcel/watcher-android-arm64@2.5.0(transitive)
- Removed@parcel/watcher-darwin-arm64@2.5.0(transitive)
- Removed@parcel/watcher-darwin-x64@2.5.0(transitive)
- Removed@parcel/watcher-freebsd-x64@2.5.0(transitive)
- Removed@parcel/watcher-linux-arm-glibc@2.5.0(transitive)
- Removed@parcel/watcher-linux-arm-musl@2.5.0(transitive)
- Removed@parcel/watcher-linux-arm64-glibc@2.5.0(transitive)
- Removed@parcel/watcher-linux-arm64-musl@2.5.0(transitive)
- Removed@parcel/watcher-linux-x64-glibc@2.5.0(transitive)
- Removed@parcel/watcher-linux-x64-musl@2.5.0(transitive)
- Removed@parcel/watcher-win32-arm64@2.5.0(transitive)
- Removed@parcel/watcher-win32-ia32@2.5.0(transitive)
- Removed@parcel/watcher-win32-x64@2.5.0(transitive)
- Removedat-least-node@1.0.0(transitive)
- Removedchokidar@4.0.1(transitive)
- Removeddetect-libc@1.0.3(transitive)
- Removedfs-extra@9.1.0(transitive)
- Removedimmutable@5.0.3(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removednode-addon-api@7.1.1(transitive)
- Removedreaddirp@4.0.2(transitive)
- Removedsass@1.83.0(transitive)
- Removedtmp@0.2.3(transitive)
Updatedcss-tree@1.1.3
Updatedfs-extra@10.0.0
Updatedsass@1.47.0
Updatedtmp@0.2.1