@thedanbob/esbuild-plugin-sass 1.0.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,8 +10,8 @@ npm install --save-dev esbuild @thedanbob/esbuild-plugin-sass
10
10
 
11
11
  ## How to use
12
12
 
13
+ `esbuild.config.js`:
13
14
  ```js
14
- // esbuild.config.js
15
15
  import { build } from "esbuild"
16
16
  import sassPlugin from "@thedanbob/esbuild-plugin-sass"
17
17
 
@@ -23,6 +23,13 @@ await build({
23
23
  });
24
24
  ```
25
25
 
26
+ `app.scss`:
27
+ ```scss
28
+ /* Prepend with ~ to import from node_modules */
29
+ @import "~bootstrap/scss/bootstrap"
30
+ ```
31
+
32
+ Run:
26
33
  ```bash
27
34
  node esbuild.config.js
28
35
  ```
@@ -30,17 +37,22 @@ node esbuild.config.js
30
37
  ## Config
31
38
 
32
39
  ### `filter`
33
-
34
40
  Type: `RegExp`<br>
35
41
  Default: `/.(s[ac]ss|css)$/`
36
42
 
37
43
  Esbuild load filter (go syntax).
38
44
 
39
- ### `importers`
40
- Type: `(NodePackageImporter | Importer<sync> | FileImporter<sync>)[]`<br>
45
+ ### `quietDeps`
46
+ Type: `boolean`<br>
47
+ Default: `false`
48
+
49
+ Silence warnings in dependencies.
50
+
51
+ ### `silenceDeprecations`
52
+ Type: `DeprecationOrId[]`<br>
41
53
  Default: `[]`
42
54
 
43
- Array of [importers](https://sass-lang.com/documentation/js-api/interfaces/options/#importers) passed to the Sass compiler.
55
+ Array of [deprecations](https://sass-lang.com/documentation/js-api/interfaces/options/#silenceDeprecations) to silence.
44
56
 
45
57
  ### `transform`
46
58
  Type: `(css: string, resolveDir: string, filePath: string) => string | Promise<string>`<br>
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { Plugin } from "esbuild";
2
- import { Options } from "sass";
2
+ import { DeprecationOrId } from "sass";
3
3
  export interface PluginOptions {
4
4
  filter?: RegExp;
5
- importers?: Options<"sync">["importers"];
5
+ quietDeps?: boolean;
6
+ silenceDeprecations?: DeprecationOrId[];
6
7
  transform?: (css: string, resolveDir: string, filePath: string) => string | Promise<string>;
7
8
  }
8
- declare const _default: ({ filter, importers, transform }?: PluginOptions) => Plugin;
9
+ declare const _default: ({ filter, quietDeps, silenceDeprecations, transform }?: PluginOptions) => Plugin;
9
10
  export default _default;
package/dist/index.js CHANGED
@@ -1,7 +1,15 @@
1
1
  import { compile } from "sass";
2
2
  import { dirname } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
- export default ({ filter = /.(s[ac]ss|css)$/, importers = [], transform = undefined } = {}) => ({
4
+ const importer = {
5
+ findFileUrl: (url) => {
6
+ if (!url.startsWith("~"))
7
+ return null;
8
+ const pkg = url.replace(/^~(.+?)\/.+/, "$1");
9
+ return new URL(url.substring(1), import.meta.resolve(pkg).replace(/(?<=node_modules\/).+/, ""));
10
+ }
11
+ };
12
+ export default ({ filter = /.(s[ac]ss|css)$/, quietDeps = false, silenceDeprecations = [], transform = undefined } = {}) => ({
5
13
  name: "sass",
6
14
  setup: async ({ initialOptions, onLoad }) => {
7
15
  onLoad({ filter }, async ({ path }) => {
@@ -33,24 +41,24 @@ export default ({ filter = /.(s[ac]ss|css)$/, importers = [], transform = undefi
33
41
  sourceMap: !!initialOptions.sourcemap,
34
42
  sourceMapIncludeSources: true,
35
43
  logger,
36
- importers
44
+ quietDeps,
45
+ silenceDeprecations,
46
+ importers: [importer]
37
47
  });
38
- let cssText = css.toString();
48
+ let contents = css.toString();
39
49
  if (sourceMap) {
40
50
  const data = Buffer.from(JSON.stringify(sourceMap), "utf-8").toString("base64");
41
- const sm = `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${data} */`;
42
- cssText += "\n" + sm;
51
+ contents += `\n/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${data} */`;
43
52
  }
44
53
  if (transform) {
45
- cssText = await transform(cssText, resolveDir, path);
54
+ contents = await transform(contents, resolveDir, path);
46
55
  }
47
- const watchFiles = [path, ...loadedUrls.map(u => fileURLToPath(u))];
48
56
  return {
49
- contents: cssText,
50
57
  loader: "css",
58
+ contents,
51
59
  resolveDir,
52
60
  warnings,
53
- watchFiles
61
+ watchFiles: [path, ...loadedUrls.map(u => fileURLToPath(u))]
54
62
  };
55
63
  });
56
64
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@thedanbob/esbuild-plugin-sass",
3
3
  "author": "Dan Arnfield <npm@thedanbob.com>",
4
- "version": "1.0.1",
4
+ "version": "2.0.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "repository": {