sass 1.66.1 → 1.68.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.
@@ -1,6 +1,38 @@
1
1
  import {Syntax} from './options';
2
2
  import {PromiseOr} from './util/promise_or';
3
3
 
4
+ /**
5
+ * Contextual information passed to {@link Importer.canonicalize} and {@link
6
+ * FileImporter.findFileUrl}. Not all importers will need this information to
7
+ * resolve loads, but some may find it useful.
8
+ */
9
+ export interface CanonicalizeContext {
10
+ /**
11
+ * Whether this is being invoked because of a Sass
12
+ * `@import` rule, as opposed to a `@use` or `@forward` rule.
13
+ *
14
+ * This should *only* be used for determining whether or not to load
15
+ * [import-only files](https://sass-lang.com/documentation/at-rules/import#import-only-files).
16
+ */
17
+ fromImport: boolean;
18
+
19
+ /**
20
+ * The canonical URL of the file that contains the load, if that information
21
+ * is available.
22
+ *
23
+ * For an {@link Importer}, this is only passed when the `url` parameter is a
24
+ * relative URL _or_ when its [URL scheme] is included in {@link
25
+ * Importer.nonCanonicalScheme}. This ensures that canonical URLs are always
26
+ * resolved the same way regardless of context.
27
+ *
28
+ * [URL scheme]: https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL#scheme
29
+ *
30
+ * For a {@link FileImporter}, this is always available as long as Sass knows
31
+ * the canonical URL of the containing file.
32
+ */
33
+ containingUrl: URL | null;
34
+ }
35
+
4
36
  /**
5
37
  * A special type of importer that redirects all loads to existing files on
6
38
  * disk. Although this is less powerful than a full {@link Importer}, it
@@ -56,12 +88,6 @@ export interface FileImporter<
56
88
  * @param url - The loaded URL. Since this might be relative, it's represented
57
89
  * as a string rather than a {@link URL} object.
58
90
  *
59
- * @param options.fromImport - Whether this is being invoked because of a Sass
60
- * `@import` rule, as opposed to a `@use` or `@forward` rule.
61
- *
62
- * This should *only* be used for determining whether or not to load
63
- * [import-only files](https://sass-lang.com/documentation/at-rules/import#import-only-files).
64
- *
65
91
  * @returns An absolute `file:` URL if this importer recognizes the `url`.
66
92
  * This may be only partially resolved: the compiler will automatically look
67
93
  * for [partials](https://sass-lang.com/documentation/at-rules/use#partials),
@@ -85,7 +111,7 @@ export interface FileImporter<
85
111
  */
86
112
  findFileUrl(
87
113
  url: string,
88
- options: {fromImport: boolean}
114
+ context: CanonicalizeContext
89
115
  ): PromiseOr<URL | null, sync>;
90
116
 
91
117
  /** @hidden */
@@ -220,12 +246,6 @@ export interface Importer<sync extends 'sync' | 'async' = 'sync' | 'async'> {
220
246
  * @param url - The loaded URL. Since this might be relative, it's represented
221
247
  * as a string rather than a {@link URL} object.
222
248
  *
223
- * @param options.fromImport - Whether this is being invoked because of a Sass
224
- * `@import` rule, as opposed to a `@use` or `@forward` rule.
225
- *
226
- * This should *only* be used for determining whether or not to load
227
- * [import-only files](https://sass-lang.com/documentation/at-rules/import#import-only-files).
228
- *
229
249
  * @returns An absolute URL if this importer recognizes the `url`, or `null`
230
250
  * if it doesn't. If this returns `null`, other importers or {@link
231
251
  * Options.loadPaths | load paths} may handle the load.
@@ -242,7 +262,7 @@ export interface Importer<sync extends 'sync' | 'async' = 'sync' | 'async'> {
242
262
  */
243
263
  canonicalize(
244
264
  url: string,
245
- options: {fromImport: boolean}
265
+ context: CanonicalizeContext
246
266
  ): PromiseOr<URL | null, sync>;
247
267
 
248
268
  /**
@@ -272,6 +292,20 @@ export interface Importer<sync extends 'sync' | 'async' = 'sync' | 'async'> {
272
292
 
273
293
  /** @hidden */
274
294
  findFileUrl?: never;
295
+
296
+ /**
297
+ * A URL scheme or set of schemes (without the `:`) that this importer
298
+ * promises never to use for URLs returned by {@link canonicalize}. If it does
299
+ * return a URL with one of these schemes, that's an error.
300
+ *
301
+ * If this is set, any call to canonicalize for a URL with a non-canonical
302
+ * scheme will be passed {@link CanonicalizeContext.containingUrl} if it's
303
+ * known.
304
+ *
305
+ * These schemes may only contain lowercase ASCII letters, ASCII numerals,
306
+ * `+`, `-`, and `.`. They may not be empty.
307
+ */
308
+ nonCanonicalScheme?: string | string[];
275
309
  }
276
310
 
277
311
  /**
package/types/index.d.ts CHANGED
@@ -10,7 +10,12 @@ export {
10
10
  compileStringAsync,
11
11
  } from './compile';
12
12
  export {Exception} from './exception';
13
- export {FileImporter, Importer, ImporterResult} from './importer';
13
+ export {
14
+ CanonicalizeContext,
15
+ FileImporter,
16
+ Importer,
17
+ ImporterResult,
18
+ } from './importer';
14
19
  export {Logger, SourceSpan, SourceLocation} from './logger';
15
20
  export {
16
21
  CustomFunction,