sass 1.69.7 → 1.71.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/sass.default.js CHANGED
@@ -10,6 +10,10 @@ export const compile = _cliPkgExports.compile;
10
10
  export const compileAsync = _cliPkgExports.compileAsync;
11
11
  export const compileString = _cliPkgExports.compileString;
12
12
  export const compileStringAsync = _cliPkgExports.compileStringAsync;
13
+ export const initCompiler = _cliPkgExports.initCompiler;
14
+ export const initAsyncCompiler = _cliPkgExports.initAsyncCompiler;
15
+ export const Compiler = _cliPkgExports.Compiler;
16
+ export const AsyncCompiler = _cliPkgExports.AsyncCompiler;
13
17
  export const Logger = _cliPkgExports.Logger;
14
18
  export const SassArgumentList = _cliPkgExports.SassArgumentList;
15
19
  export const SassBoolean = _cliPkgExports.SassBoolean;
package/sass.node.mjs CHANGED
@@ -4,6 +4,10 @@ export const compile = cjs.compile;
4
4
  export const compileAsync = cjs.compileAsync;
5
5
  export const compileString = cjs.compileString;
6
6
  export const compileStringAsync = cjs.compileStringAsync;
7
+ export const initCompiler = cjs.initCompiler;
8
+ export const initAsyncCompiler = cjs.initAsyncCompiler;
9
+ export const Compiler = cjs.Compiler;
10
+ export const AsyncCompiler = cjs.AsyncCompiler;
7
11
  export const Logger = cjs.Logger;
8
12
  export const SassArgumentList = cjs.SassArgumentList;
9
13
  export const SassBoolean = cjs.SassBoolean;
@@ -59,6 +63,22 @@ export default {
59
63
  defaultExportDeprecation();
60
64
  return cjs.compileStringAsync;
61
65
  },
66
+ get initCompiler() {
67
+ defaultExportDeprecation();
68
+ return cjs.initCompiler;
69
+ },
70
+ get initAsyncCompiler() {
71
+ defaultExportDeprecation();
72
+ return cjs.initAsyncCompiler;
73
+ },
74
+ get Compiler() {
75
+ defaultExportDeprecation();
76
+ return cjs.Compiler;
77
+ },
78
+ get AsyncCompiler() {
79
+ defaultExportDeprecation();
80
+ return cjs.AsyncCompiler;
81
+ },
62
82
  get Logger() {
63
83
  defaultExportDeprecation();
64
84
  return cjs.Logger;
@@ -37,6 +37,104 @@ export interface CompileResult {
37
37
  sourceMap?: RawSourceMap;
38
38
  }
39
39
 
40
+ /**
41
+ * The result of creating a synchronous compiler. Returned by
42
+ * {@link initCompiler}.
43
+ *
44
+ * @category Compile
45
+ */
46
+ export class Compiler {
47
+ /**
48
+ * Throws an error if constructed directly, instead of via
49
+ * {@link initCompiler}.
50
+ */
51
+ private constructor();
52
+
53
+ /**
54
+ * The {@link compile} method exposed through a Compiler instance while it is
55
+ * active. If this is called after {@link dispose} on the Compiler
56
+ * instance, an error will be thrown.
57
+ *
58
+ * During the Compiler instance's lifespan, given the same input, this will
59
+ * return an identical result to the {@link compile} method exposed at the
60
+ * module root.
61
+ */
62
+ compile(path: string, options?: Options<'sync'>): CompileResult;
63
+
64
+ /**
65
+ * The {@link compileString} method exposed through a Compiler instance while
66
+ * it is active. If this is called after {@link dispose} on the Compiler
67
+ * instance, an error will be thrown.
68
+ *
69
+ * During the Compiler instance's lifespan, given the same input, this will
70
+ * return an identical result to the {@link compileString} method exposed at
71
+ * the module root.
72
+ */
73
+ compileString(source: string, options?: StringOptions<'sync'>): CompileResult;
74
+
75
+ /**
76
+ * Ends the lifespan of this Compiler instance. After this is invoked, all
77
+ * calls to the Compiler instance's {@link compile} or {@link compileString}
78
+ * methods will result in an error.
79
+ */
80
+ dispose(): void;
81
+ }
82
+
83
+ /**
84
+ * The result of creating an asynchronous compiler. Returned by
85
+ * {@link initAsyncCompiler}.
86
+ *
87
+ * @category Compile
88
+ */
89
+ export class AsyncCompiler {
90
+ /**
91
+ * Throws an error if constructed directly, instead of via
92
+ * {@link initAsyncCompiler}.
93
+ */
94
+ private constructor();
95
+
96
+ /**
97
+ * The {@link compileAsync} method exposed through an Async Compiler instance
98
+ * while it is active. If this is called after {@link dispose} on the Async
99
+ * Compiler instance, an error will be thrown.
100
+ *
101
+ * During the Async Compiler instance's lifespan, given the same input, this
102
+ * will return an identical result to the {@link compileAsync} method exposed
103
+ * at the module root.
104
+ */
105
+ compileAsync(
106
+ path: string,
107
+ options?: Options<'async'>
108
+ ): Promise<CompileResult>;
109
+
110
+ /**
111
+ * The {@link compileStringAsync} method exposed through an Async Compiler
112
+ * instance while it is active. If this is called after {@link dispose} on the
113
+ * Async Compiler instance, an error will be thrown.
114
+ *
115
+ * During the Async Compiler instance's lifespan, given the same input, this
116
+ * will return an identical result to the {@link compileStringAsync} method
117
+ * exposed at the module root.
118
+ */
119
+ compileStringAsync(
120
+ source: string,
121
+ options?: StringOptions<'async'>
122
+ ): Promise<CompileResult>;
123
+
124
+ /**
125
+ * Ends the lifespan of this Async Compiler instance. After this is invoked,
126
+ * all subsequent calls to the Compiler instance's `compileAsync` or
127
+ * `compileStringAsync` methods will result in an error.
128
+ *
129
+ * Any compilations that are submitted before `dispose` will not be cancelled,
130
+ * and will be allowed to settle.
131
+ *
132
+ * After all compilations have been settled and Sass completes any internal
133
+ * task cleanup, `dispose` will resolve its promise.
134
+ */
135
+ dispose(): Promise<void>;
136
+ }
137
+
40
138
  /**
41
139
  * Synchronously compiles the Sass file at `path` to CSS. If it succeeds it
42
140
  * returns a {@link CompileResult}, and if it fails it throws an {@link
@@ -44,10 +142,16 @@ export interface CompileResult {
44
142
  *
45
143
  * This only allows synchronous {@link Importer}s and {@link CustomFunction}s.
46
144
  *
47
- * **Heads up!** When using the `sass-embedded` npm package,
48
- * **{@link compileAsync} is almost always faster than {@link compile}**, due to
49
- * the overhead of emulating synchronous messaging with worker threads and
50
- * concurrent compilations being blocked on main thread.
145
+ * **Heads up!** When using the [sass-embedded] npm package for single
146
+ * compilations, **{@link compileAsync} is almost always faster than
147
+ * {@link compile}**, due to the overhead of emulating synchronous messaging
148
+ * with worker threads and concurrent compilations being blocked on main thread.
149
+ *
150
+ * If you are running multiple compilations with the [sass-embedded] npm
151
+ * package, using a {@link Compiler} will provide some speed improvements over
152
+ * the module-level methods, and an {@link AsyncCompiler} will be much faster.
153
+ *
154
+ * [sass-embedded]: https://www.npmjs.com/package/sass-embedded
51
155
  *
52
156
  * @example
53
157
  *
@@ -99,12 +203,18 @@ export function compileAsync(
99
203
  *
100
204
  * This only allows synchronous {@link Importer}s and {@link CustomFunction}s.
101
205
  *
102
- * **Heads up!** When using the `sass-embedded` npm package,
103
- * **{@link compileStringAsync} is almost always faster than
206
+ * **Heads up!** When using the [sass-embedded] npm package for single
207
+ * compilations, **{@link compileStringAsync} is almost always faster than
104
208
  * {@link compileString}**, due to the overhead of emulating synchronous
105
209
  * messaging with worker threads and concurrent compilations being blocked on
106
210
  * main thread.
107
211
  *
212
+ * If you are running multiple compilations with the [sass-embedded] npm
213
+ * package, using a {@link Compiler} will provide some speed improvements over
214
+ * the module-level methods, and an {@link AsyncCompiler} will be much faster.
215
+ *
216
+ * [sass-embedded]: https://www.npmjs.com/package/sass-embedded
217
+ *
108
218
  * @example
109
219
  *
110
220
  * ```js
@@ -162,3 +272,71 @@ export function compileStringAsync(
162
272
  source: string,
163
273
  options?: StringOptions<'async'>
164
274
  ): Promise<CompileResult>;
275
+
276
+ /**
277
+ * Creates a synchronous {@link Compiler}. Each compiler instance exposes the
278
+ * {@link compile} and {@link compileString} methods within the lifespan of the
279
+ * Compiler. Given identical input, these methods will return results identical
280
+ * to their counterparts exposed at the module root. To use asynchronous
281
+ * compilation, use {@link initAsyncCompiler}.
282
+ *
283
+ * When calling the compile functions multiple times, using a compiler instance
284
+ * with the [sass-embedded] npm package is much faster than using the top-level
285
+ * compilation methods or the [sass] npm package.
286
+ *
287
+ * [sass-embedded]: https://www.npmjs.com/package/sass-embedded
288
+ *
289
+ * [sass]: https://www.npmjs.com/package/sass
290
+ *
291
+ * @example
292
+ *
293
+ * ```js
294
+ * const sass = require('sass');
295
+ * function setup() {
296
+ * const compiler = sass.initCompiler();
297
+ * const result1 = compiler.compileString('a {b: c}').css;
298
+ * const result2 = compiler.compileString('a {b: c}').css;
299
+ * compiler.dispose();
300
+ *
301
+ * // throws error
302
+ * const result3 = sass.compileString('a {b: c}').css;
303
+ * }
304
+ * ```
305
+ * @category Compile
306
+ * @compatibility dart: "1.70.0", node: false
307
+ */
308
+ export function initCompiler(): Compiler;
309
+
310
+ /**
311
+ * Creates an asynchronous {@link AsyncCompiler}. Each compiler
312
+ * instance exposes the {@link compileAsync} and {@link compileStringAsync}
313
+ * methods within the lifespan of the Compiler. Given identical input, these
314
+ * methods will return results identical to their counterparts exposed at the
315
+ * module root. To use synchronous compilation, use {@link initCompiler};
316
+ *
317
+ * When calling the compile functions multiple times, using a compiler instance
318
+ * with the [sass-embedded] npm package is much faster than using the top-level
319
+ * compilation methods or the [sass] npm package.
320
+ *
321
+ * [sass-embedded]: https://www.npmjs.com/package/sass-embedded
322
+ *
323
+ * [sass]: https://www.npmjs.com/package/sass
324
+ *
325
+ * @example
326
+ *
327
+ * ```js
328
+ * const sass = require('sass');
329
+ * async function setup() {
330
+ * const compiler = await sass.initAsyncCompiler();
331
+ * const result1 = await compiler.compileStringAsync('a {b: c}').css;
332
+ * const result2 = await compiler.compileStringAsync('a {b: c}').css;
333
+ * await compiler.dispose();
334
+ *
335
+ * // throws error
336
+ * const result3 = await sass.compileStringAsync('a {b: c}').css;
337
+ * }
338
+ * ```
339
+ * @category Compile
340
+ * @compatibility dart: "1.70.0", node: false
341
+ */
342
+ export function initAsyncCompiler(): Promise<AsyncCompiler>;
@@ -308,6 +308,139 @@ export interface Importer<sync extends 'sync' | 'async' = 'sync' | 'async'> {
308
308
  nonCanonicalScheme?: string | string[];
309
309
  }
310
310
 
311
+ declare const nodePackageImporterKey: unique symbol;
312
+
313
+ /**
314
+ * The built-in Node.js package importer. This loads pkg: URLs from node_modules
315
+ * according to the standard Node.js resolution algorithm.
316
+ *
317
+ * A Node.js package importer is exposed as a class that can be added to the
318
+ * `importers` option.
319
+ *
320
+ *```js
321
+ * const sass = require('sass');
322
+ * sass.compileString('@use "pkg:vuetify', {
323
+ * importers: [new sass.NodePackageImporter()]
324
+ * });
325
+ *```
326
+ *
327
+ * ## Writing Sass packages
328
+ *
329
+ * Package authors can control what is exposed to their users through their
330
+ * `package.json` manifest. The recommended method is to add a `sass`
331
+ * conditional export to `package.json`.
332
+ *
333
+ * ```json
334
+ * // node_modules/uicomponents/package.json
335
+ * {
336
+ * "exports": {
337
+ * ".": {
338
+ * "sass": "./src/scss/index.scss",
339
+ * "import": "./dist/js/index.mjs",
340
+ * "default": "./dist/js/index.js"
341
+ * }
342
+ * }
343
+ * }
344
+ * ```
345
+ *
346
+ * This allows a package user to write `@use "pkg:uicomponents"` to load the
347
+ * file at `node_modules/uicomponents/src/scss/index.scss`.
348
+ *
349
+ * The Node.js package importer supports the variety of formats supported by
350
+ * Node.js [package entry points], allowing authors to expose multiple subpaths.
351
+ *
352
+ * [package entry points]:
353
+ * https://nodejs.org/api/packages.html#package-entry-points
354
+ *
355
+ * ```json
356
+ * // node_modules/uicomponents/package.json
357
+ * {
358
+ * "exports": {
359
+ * ".": {
360
+ * "sass": "./src/scss/index.scss",
361
+ * },
362
+ * "./colors": {
363
+ * "sass": "./src/scss/_colors.scss",
364
+ * },
365
+ * "./theme/*": {
366
+ * "sass": "./src/scss/theme/*.scss",
367
+ * },
368
+ * }
369
+ * }
370
+ * ```
371
+ *
372
+ * This allows a package user to write:
373
+ *
374
+ * - `@use "pkg:uicomponents";` to import the root export.
375
+ * - `@use "pkg:uicomponents/colors";` to import the colors partial.
376
+ * - `@use "pkg:uicomponents/theme/purple";` to import a purple theme.
377
+ *
378
+ * Note that while library users can rely on the importer to resolve
379
+ * [partials](https://sass-lang.com/documentation/at-rules/use#partials), [index
380
+ * files](https://sass-lang.com/documentation/at-rules/use#index-files), and
381
+ * extensions, library authors must specify the entire file path in `exports`.
382
+ *
383
+ * In addition to the `sass` condition, the `style` condition is also
384
+ * acceptable. Sass will match the `default` condition if it's a relevant file
385
+ * type, but authors are discouraged from relying on this. Notably, the key
386
+ * order matters, and the importer will resolve to the first value with a key
387
+ * that is `sass`, `style`, or `default`, so you should always put `default`
388
+ * last.
389
+ *
390
+ * To help package authors who haven't transitioned to package entry points
391
+ * using the `exports` field, the Node.js package importer provides several
392
+ * fallback options. If the `pkg:` URL does not have a subpath, the Node.js
393
+ * package importer will look for a `sass` or `style` key at the root of
394
+ * `package.json`.
395
+ *
396
+ * ```json
397
+ * // node_modules/uicomponents/package.json
398
+ * {
399
+ * "sass": "./src/scss/index.scss",
400
+ * }
401
+ * ```
402
+ *
403
+ * This allows a user to write `@use "pkg:uicomponents";` to import the
404
+ * `index.scss` file.
405
+ *
406
+ * Finally, the Node.js package importer will look for an `index` file at the
407
+ * package root, resolving partials and extensions. For example, if the file
408
+ * `_index.scss` exists in the package root of `uicomponents`, a user can import
409
+ * that with `@use "pkg:uicomponents";`.
410
+ *
411
+ * If a `pkg:` URL includes a subpath that doesn't have a match in package entry
412
+ * points, the Node.js importer will attempt to find that file relative to the
413
+ * package root, resolving for file extensions, partials and index files. For
414
+ * example, if the file `src/sass/_colors.scss` exists in the `uicomponents`
415
+ * package, a user can import that file using `@use
416
+ * "pkg:uicomponents/src/sass/colors";`.
417
+ *
418
+ * @compatibility dart: "2.0", node: false
419
+ * @category Importer
420
+ */
421
+ export class NodePackageImporter {
422
+ /** Used to distinguish this type from any arbitrary object. */
423
+ private readonly [nodePackageImporterKey]: true;
424
+
425
+ /**
426
+ * The NodePackageImporter has an optional `entryPointDirectory` option, which
427
+ * is the directory where the Node Package Importer should start when
428
+ * resolving `pkg:` URLs in sources other than files on disk. This will be
429
+ * used as the `parentURL` in the [Node Module
430
+ * Resolution](https://nodejs.org/api/esm.html#resolution-algorithm-specification)
431
+ * algorithm.
432
+ *
433
+ * In order to be found by the Node Package Importer, a package will need to
434
+ * be inside a node_modules folder located in the `entryPointDirectory`, or
435
+ * one of its parent directories, up to the filesystem root.
436
+ *
437
+ * Relative paths will be resolved relative to the current working directory.
438
+ * If a path is not provided, the default value of `require.main.filename`
439
+ * will be used.
440
+ */
441
+ constructor(entryPointDirectory?: string);
442
+ }
443
+
311
444
  /**
312
445
  * The result of successfully loading a stylesheet with an {@link Importer}.
313
446
  *
package/types/index.d.ts CHANGED
@@ -3,11 +3,15 @@
3
3
  // implementations.
4
4
 
5
5
  export {
6
+ AsyncCompiler,
6
7
  CompileResult,
8
+ Compiler,
7
9
  compile,
8
10
  compileAsync,
9
11
  compileString,
10
12
  compileStringAsync,
13
+ initCompiler,
14
+ initAsyncCompiler,
11
15
  } from './compile';
12
16
  export {Exception} from './exception';
13
17
  export {
@@ -15,6 +19,7 @@ export {
15
19
  FileImporter,
16
20
  Importer,
17
21
  ImporterResult,
22
+ NodePackageImporter,
18
23
  } from './importer';
19
24
  export {Logger, SourceSpan, SourceLocation} from './logger';
20
25
  export {
@@ -1,6 +1,7 @@
1
1
  import {Logger} from '../logger';
2
2
  import {LegacyImporter} from './importer';
3
3
  import {LegacyFunction} from './function';
4
+ import {NodePackageImporter} from '../importer';
4
5
 
5
6
  /**
6
7
  * Options for {@link render} and {@link renderSync} that are shared between
@@ -508,6 +509,24 @@ export interface LegacySharedOptions<sync extends 'sync' | 'async'> {
508
509
  * @compatibility dart: "1.43.0", node: false
509
510
  */
510
511
  logger?: Logger;
512
+
513
+ /**
514
+ * If this option is set to an instance of `NodePackageImporter`, Sass will
515
+ * use the built-in Node.js package importer to resolve Sass files with a
516
+ * `pkg:` URL scheme. Details for library authors and users can be found in
517
+ * the {@link NodePackageImporter} documentation.
518
+ *
519
+ * @example
520
+ * ```js
521
+ * sass.renderSync({
522
+ * data: '@use "pkg:vuetify";',
523
+ * pkgImporter: new sass.NodePackageImporter()
524
+ * });
525
+ * ```
526
+ * @category Plugins
527
+ * @compatibility dart: "2.0", node: false
528
+ */
529
+ pkgImporter?: NodePackageImporter;
511
530
  }
512
531
 
513
532
  /**
@@ -1,4 +1,4 @@
1
- import {FileImporter, Importer} from './importer';
1
+ import {FileImporter, Importer, NodePackageImporter} from './importer';
2
2
  import {Logger} from './logger';
3
3
  import {Value} from './value';
4
4
  import {PromiseOr} from './util/promise_or';
@@ -208,8 +208,8 @@ export interface Options<sync extends 'sync' | 'async'> {
208
208
  * - The importer that was used to load the current stylesheet, with the
209
209
  * loaded URL resolved relative to the current stylesheet's canonical URL.
210
210
  *
211
- * - Each {@link Importer} or {@link FileImporter} in {@link importers}, in
212
- * order.
211
+ * - Each {@link Importer}, {@link FileImporter}, or
212
+ * {@link NodePackageImporter} in {@link importers}, in order.
213
213
  *
214
214
  * - Each load path in {@link loadPaths}, in order.
215
215
  *
@@ -218,7 +218,7 @@ export interface Options<sync extends 'sync' | 'async'> {
218
218
  *
219
219
  * @category Plugins
220
220
  */
221
- importers?: (Importer<sync> | FileImporter<sync>)[];
221
+ importers?: (Importer<sync> | FileImporter<sync> | NodePackageImporter)[];
222
222
 
223
223
  /**
224
224
  * Paths in which to look for stylesheets loaded by rules like