sass 1.70.0 → 1.71.1

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
@@ -42,3 +42,4 @@ export const TRUE = _cliPkgExports.TRUE;
42
42
  export const FALSE = _cliPkgExports.FALSE;
43
43
  export const NULL = _cliPkgExports.NULL;
44
44
  export const types = _cliPkgExports.types;
45
+ export const NodePackageImporter = _cliPkgExports.NodePackageImporter;
package/sass.js CHANGED
@@ -9,6 +9,7 @@ library.load({
9
9
  chokidar: require("chokidar"),
10
10
  util: require("util"),
11
11
  stream: require("stream"),
12
+ nodeModule: require("module"),
12
13
  fs: require("fs"),
13
14
  immutable: require("immutable"),
14
15
  });
package/sass.node.js CHANGED
@@ -4,6 +4,7 @@ if (globalThis._cliPkgExports.length === 0) delete globalThis._cliPkgExports;
4
4
  library.load({
5
5
  util: require("util"),
6
6
  stream: require("stream"),
7
+ nodeModule: require("module"),
7
8
  fs: require("fs"),
8
9
  immutable: require("immutable"),
9
10
  });
package/sass.node.mjs CHANGED
@@ -36,6 +36,7 @@ export const TRUE = cjs.TRUE;
36
36
  export const FALSE = cjs.FALSE;
37
37
  export const NULL = cjs.NULL;
38
38
  export const types = cjs.types;
39
+ export const NodePackageImporter = cjs.NodePackageImporter;
39
40
 
40
41
  let printedDefaultExportDeprecation = false;
41
42
  function defaultExportDeprecation() {
@@ -191,4 +192,8 @@ export default {
191
192
  defaultExportDeprecation();
192
193
  return cjs.types;
193
194
  },
195
+ get NodePackageImporter() {
196
+ defaultExportDeprecation();
197
+ return cjs.NodePackageImporter;
198
+ },
194
199
  };
@@ -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: "1.71.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, this defaults to the parent directory of the
439
+ * Node.js entrypoint. If that's not available, this will throw an error.
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
@@ -19,6 +19,7 @@ export {
19
19
  FileImporter,
20
20
  Importer,
21
21
  ImporterResult,
22
+ NodePackageImporter,
22
23
  } from './importer';
23
24
  export {Logger, SourceSpan, SourceLocation} from './logger';
24
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