@sass/types 1.93.2
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/LICENSE +20 -0
- package/README.md +6 -0
- package/package.json +18 -0
- package/types/compile.d.ts +342 -0
- package/types/deprecations.d.ts +290 -0
- package/types/exception.d.ts +41 -0
- package/types/importer.d.ts +471 -0
- package/types/index.d.ts +122 -0
- package/types/legacy/exception.d.ts +55 -0
- package/types/legacy/function.d.ts +757 -0
- package/types/legacy/importer.d.ts +169 -0
- package/types/legacy/options.d.ts +700 -0
- package/types/legacy/plugin_this.d.ts +74 -0
- package/types/legacy/render.d.ts +144 -0
- package/types/logger/index.d.ts +115 -0
- package/types/logger/source_location.d.ts +21 -0
- package/types/logger/source_span.d.ts +34 -0
- package/types/options.d.ts +468 -0
- package/types/util/promise_or.d.ts +17 -0
- package/types/value/argument_list.d.ts +47 -0
- package/types/value/boolean.d.ts +29 -0
- package/types/value/calculation.d.ts +137 -0
- package/types/value/color.d.ts +566 -0
- package/types/value/function.d.ts +22 -0
- package/types/value/index.d.ts +219 -0
- package/types/value/list.d.ts +54 -0
- package/types/value/map.d.ts +41 -0
- package/types/value/mixin.d.ts +14 -0
- package/types/value/number.d.ts +305 -0
- package/types/value/string.d.ts +84 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {SourceSpan} from './logger';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* An exception thrown because a Sass compilation failed.
|
|
5
|
+
*
|
|
6
|
+
* @category Other
|
|
7
|
+
*/
|
|
8
|
+
export class Exception extends Error {
|
|
9
|
+
private constructor();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A human-friendly representation of the exception.
|
|
13
|
+
*
|
|
14
|
+
* Because many tools simply print `Error.message` directly, this includes not
|
|
15
|
+
* only the textual description of what went wrong (the {@link sassMessage})
|
|
16
|
+
* but also an indication of where in the Sass stylesheet the error occurred
|
|
17
|
+
* (the {@link span}) and the Sass stack trace at the point of error (the
|
|
18
|
+
* {@link sassStack}).
|
|
19
|
+
*/
|
|
20
|
+
message: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A textual description of what went wrong.
|
|
24
|
+
*
|
|
25
|
+
* Unlike {@link message}, this does *not* include representations of {@link
|
|
26
|
+
* span} or {@link sassStack}.
|
|
27
|
+
*/
|
|
28
|
+
readonly sassMessage: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A human-friendly representation of the Sass stack trace at the point of
|
|
32
|
+
* error.
|
|
33
|
+
*/
|
|
34
|
+
readonly sassStack: string;
|
|
35
|
+
|
|
36
|
+
/** The location the error occurred in the Sass file that triggered it. */
|
|
37
|
+
readonly span: SourceSpan;
|
|
38
|
+
|
|
39
|
+
/** Returns the same string as {@link message}. */
|
|
40
|
+
toString(): string;
|
|
41
|
+
}
|
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import {Syntax} from './options';
|
|
2
|
+
import {PromiseOr} from './util/promise_or';
|
|
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
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A special type of importer that redirects all loads to existing files on
|
|
38
|
+
* disk. Although this is less powerful than a full {@link Importer}, it
|
|
39
|
+
* automatically takes care of Sass features like resolving partials and file
|
|
40
|
+
* extensions and of loading the file from disk.
|
|
41
|
+
*
|
|
42
|
+
* Like all importers, this implements custom Sass loading logic for [`@use`
|
|
43
|
+
* rules](https://sass-lang.com/documentation/at-rules/use) and [`@import`
|
|
44
|
+
* rules](https://sass-lang.com/documentation/at-rules/import). It can be passed
|
|
45
|
+
* to {@link Options.importers} or {@link StringOptions.importer}.
|
|
46
|
+
*
|
|
47
|
+
* @typeParam sync - A `FileImporter<'sync'>`'s {@link findFileUrl} must return
|
|
48
|
+
* synchronously, but in return it can be passed to {@link compile} and {@link
|
|
49
|
+
* compileString} in addition to {@link compileAsync} and {@link
|
|
50
|
+
* compileStringAsync}.
|
|
51
|
+
*
|
|
52
|
+
* A `FileImporter<'async'>`'s {@link findFileUrl} may either return
|
|
53
|
+
* synchronously or asynchronously, but it can only be used with {@link
|
|
54
|
+
* compileAsync} and {@link compileStringAsync}.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
*
|
|
58
|
+
* ```js
|
|
59
|
+
* const {pathToFileURL} = require('url');
|
|
60
|
+
*
|
|
61
|
+
* sass.compile('style.scss', {
|
|
62
|
+
* importers: [{
|
|
63
|
+
* // An importer that redirects relative URLs starting with "~" to
|
|
64
|
+
* // `node_modules`.
|
|
65
|
+
* findFileUrl(url) {
|
|
66
|
+
* if (!url.startsWith('~')) return null;
|
|
67
|
+
* return new URL(url.substring(1), pathToFileURL('node_modules'));
|
|
68
|
+
* }
|
|
69
|
+
* }]
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @category Importer
|
|
74
|
+
*/
|
|
75
|
+
export interface FileImporter<
|
|
76
|
+
sync extends 'sync' | 'async' = 'sync' | 'async'
|
|
77
|
+
> {
|
|
78
|
+
/**
|
|
79
|
+
* A callback that's called to partially resolve a load (such as
|
|
80
|
+
* [`@use`](https://sass-lang.com/documentation/at-rules/use) or
|
|
81
|
+
* [`@import`](https://sass-lang.com/documentation/at-rules/import)) to a file
|
|
82
|
+
* on disk.
|
|
83
|
+
*
|
|
84
|
+
* Unlike an {@link Importer}, the compiler will automatically handle relative
|
|
85
|
+
* loads for a {@link FileImporter}. See {@link Options.importers} for more
|
|
86
|
+
* details on the way loads are resolved.
|
|
87
|
+
*
|
|
88
|
+
* @param url - The loaded URL. Since this might be relative, it's represented
|
|
89
|
+
* as a string rather than a {@link URL} object.
|
|
90
|
+
*
|
|
91
|
+
* @returns An absolute `file:` URL if this importer recognizes the `url`.
|
|
92
|
+
* This may be only partially resolved: the compiler will automatically look
|
|
93
|
+
* for [partials](https://sass-lang.com/documentation/at-rules/use#partials),
|
|
94
|
+
* [index files](https://sass-lang.com/documentation/at-rules/use#index-files),
|
|
95
|
+
* and file extensions based on the returned URL. An importer may also return
|
|
96
|
+
* a fully resolved URL if it so chooses.
|
|
97
|
+
*
|
|
98
|
+
* If this importer doesn't recognize the URL, it should return `null` instead
|
|
99
|
+
* to allow other importers or {@link Options.loadPaths | load paths} to
|
|
100
|
+
* handle it.
|
|
101
|
+
*
|
|
102
|
+
* This may also return a `Promise`, but if it does the importer may only be
|
|
103
|
+
* passed to {@link compileAsync} and {@link compileStringAsync}, not {@link
|
|
104
|
+
* compile} or {@link compileString}.
|
|
105
|
+
*
|
|
106
|
+
* @throws any - If this importer recognizes `url` but determines that it's
|
|
107
|
+
* invalid, it may throw an exception that will be wrapped by Sass. If the
|
|
108
|
+
* exception object has a `message` property, it will be used as the wrapped
|
|
109
|
+
* exception's message; otherwise, the exception object's `toString()` will be
|
|
110
|
+
* used. This means it's safe for importers to throw plain strings.
|
|
111
|
+
*/
|
|
112
|
+
findFileUrl(
|
|
113
|
+
url: string,
|
|
114
|
+
context: CanonicalizeContext
|
|
115
|
+
): PromiseOr<URL | null, sync>;
|
|
116
|
+
|
|
117
|
+
/** @hidden */
|
|
118
|
+
canonicalize?: never;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* An object that implements custom Sass loading logic for [`@use`
|
|
123
|
+
* rules](https://sass-lang.com/documentation/at-rules/use) and [`@import`
|
|
124
|
+
* rules](https://sass-lang.com/documentation/at-rules/import). It can be passed
|
|
125
|
+
* to {@link Options.importers} or {@link StringOptions.importer}.
|
|
126
|
+
*
|
|
127
|
+
* Importers that simply redirect to files on disk are encouraged to use the
|
|
128
|
+
* {@link FileImporter} interface instead.
|
|
129
|
+
*
|
|
130
|
+
* ### Resolving a Load
|
|
131
|
+
*
|
|
132
|
+
* This is the process of resolving a load using a custom importer:
|
|
133
|
+
*
|
|
134
|
+
* - The compiler encounters `@use "db:foo/bar/baz"`.
|
|
135
|
+
* - It calls {@link canonicalize} with `"db:foo/bar/baz"`.
|
|
136
|
+
* - {@link canonicalize} returns `new URL("db:foo/bar/baz/_index.scss")`.
|
|
137
|
+
* - If the compiler has already loaded a stylesheet with this canonical URL, it
|
|
138
|
+
* re-uses the existing module.
|
|
139
|
+
* - Otherwise, it calls {@link load} with `new
|
|
140
|
+
* URL("db:foo/bar/baz/_index.scss")`.
|
|
141
|
+
* - {@link load} returns an {@link ImporterResult} that the compiler uses as
|
|
142
|
+
* the contents of the module.
|
|
143
|
+
*
|
|
144
|
+
* See {@link Options.importers} for more details on the way loads are resolved
|
|
145
|
+
* using multiple importers and load paths.
|
|
146
|
+
*
|
|
147
|
+
* @typeParam sync - An `Importer<'sync'>`'s {@link canonicalize} and {@link
|
|
148
|
+
* load} must return synchronously, but in return it can be passed to {@link
|
|
149
|
+
* compile} and {@link compileString} in addition to {@link compileAsync} and
|
|
150
|
+
* {@link compileStringAsync}.
|
|
151
|
+
*
|
|
152
|
+
* An `Importer<'async'>`'s {@link canonicalize} and {@link load} may either
|
|
153
|
+
* return synchronously or asynchronously, but it can only be used with {@link
|
|
154
|
+
* compileAsync} and {@link compileStringAsync}.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
*
|
|
158
|
+
* ```js
|
|
159
|
+
* sass.compile('style.scss', {
|
|
160
|
+
* // An importer for URLs like `bgcolor:orange` that generates a
|
|
161
|
+
* // stylesheet with the given background color.
|
|
162
|
+
* importers: [{
|
|
163
|
+
* canonicalize(url) {
|
|
164
|
+
* if (!url.startsWith('bgcolor:')) return null;
|
|
165
|
+
* return new URL(url);
|
|
166
|
+
* },
|
|
167
|
+
* load(canonicalUrl) {
|
|
168
|
+
* return {
|
|
169
|
+
* contents: `body {background-color: ${canonicalUrl.pathname}}`,
|
|
170
|
+
* syntax: 'scss'
|
|
171
|
+
* };
|
|
172
|
+
* }
|
|
173
|
+
* }]
|
|
174
|
+
* });
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* @category Importer
|
|
178
|
+
*/
|
|
179
|
+
export interface Importer<sync extends 'sync' | 'async' = 'sync' | 'async'> {
|
|
180
|
+
/**
|
|
181
|
+
* If `url` is recognized by this importer, returns its canonical format.
|
|
182
|
+
*
|
|
183
|
+
* If Sass has already loaded a stylesheet with the returned canonical URL, it
|
|
184
|
+
* re-uses the existing parse tree (and the loaded module for `@use`). This
|
|
185
|
+
* means that importers **must ensure** that the same canonical URL always
|
|
186
|
+
* refers to the same stylesheet, *even across different importers*. As such,
|
|
187
|
+
* importers are encouraged to use unique URL schemes to disambiguate between
|
|
188
|
+
* one another.
|
|
189
|
+
*
|
|
190
|
+
* As much as possible, custom importers should canonicalize URLs the same way
|
|
191
|
+
* as the built-in filesystem importer:
|
|
192
|
+
*
|
|
193
|
+
* - The importer should look for stylesheets by adding the prefix `_` to the
|
|
194
|
+
* URL's basename, and by adding the extensions `.sass` and `.scss` if the
|
|
195
|
+
* URL doesn't already have one of those extensions. For example, if the
|
|
196
|
+
* URL was `foo/bar/baz`, the importer would look for:
|
|
197
|
+
* - `foo/bar/baz.sass`
|
|
198
|
+
* - `foo/bar/baz.scss`
|
|
199
|
+
* - `foo/bar/_baz.sass`
|
|
200
|
+
* - `foo/bar/_baz.scss`
|
|
201
|
+
*
|
|
202
|
+
* If the URL was `foo/bar/baz.scss`, the importer would just look for:
|
|
203
|
+
* - `foo/bar/baz.scss`
|
|
204
|
+
* - `foo/bar/_baz.scss`
|
|
205
|
+
*
|
|
206
|
+
* If the importer finds a stylesheet at more than one of these URLs, it
|
|
207
|
+
* should throw an exception indicating that the URL is ambiguous. Note that
|
|
208
|
+
* if the extension is explicitly specified, a stylesheet with the opposite
|
|
209
|
+
* extension is allowed to exist.
|
|
210
|
+
*
|
|
211
|
+
* - If none of the possible paths is valid, the importer should perform the
|
|
212
|
+
* same resolution on the URL followed by `/index`. In the example above,
|
|
213
|
+
* it would look for:
|
|
214
|
+
* - `foo/bar/baz/index.sass`
|
|
215
|
+
* - `foo/bar/baz/index.scss`
|
|
216
|
+
* - `foo/bar/baz/_index.sass`
|
|
217
|
+
* - `foo/bar/baz/_index.scss`
|
|
218
|
+
*
|
|
219
|
+
* As above, if the importer finds a stylesheet at more than one of these
|
|
220
|
+
* URLs, it should throw an exception indicating that the import is
|
|
221
|
+
* ambiguous.
|
|
222
|
+
*
|
|
223
|
+
* If no stylesheets are found, the importer should return `null`.
|
|
224
|
+
*
|
|
225
|
+
* Calling {@link canonicalize} multiple times with the same URL must return
|
|
226
|
+
* the same result. Calling {@link canonicalize} with a URL returned by a
|
|
227
|
+
* previous call to {@link canonicalize} must return that URL.
|
|
228
|
+
*
|
|
229
|
+
* #### Relative URLs
|
|
230
|
+
*
|
|
231
|
+
* Relative loads in stylesheets loaded from an importer are first resolved
|
|
232
|
+
* relative to the canonical URL of the stylesheet that contains it and passed
|
|
233
|
+
* back to the {@link canonicalize} method for the local importer that loaded
|
|
234
|
+
* that stylesheet. For example, suppose the "Resolving a Load" example {@link
|
|
235
|
+
* Importer | above} returned a stylesheet that contained `@use "mixins"`:
|
|
236
|
+
*
|
|
237
|
+
* - The compiler resolves the URL `mixins` relative to the current
|
|
238
|
+
* stylesheet's canonical URL `db:foo/bar/baz/_index.scss` to get
|
|
239
|
+
* `db:foo/bar/baz/mixins`.
|
|
240
|
+
* - It calls {@link canonicalize} with `"db:foo/bar/baz/mixins"`.
|
|
241
|
+
* - {@link canonicalize} returns `new URL("db:foo/bar/baz/_mixins.scss")`.
|
|
242
|
+
*
|
|
243
|
+
* Because of this, {@link canonicalize} must return a meaningful result when
|
|
244
|
+
* called with a URL relative to one returned by an earlier call to {@link
|
|
245
|
+
* canonicalize}.
|
|
246
|
+
*
|
|
247
|
+
* If the local importer's `canonicalize` method returns `null`, the relative
|
|
248
|
+
* URL is then passed to each of {@link Options.importers}' `canonicalize()`
|
|
249
|
+
* methods in turn until one returns a canonical URL. If none of them do, the
|
|
250
|
+
* load fails.
|
|
251
|
+
*
|
|
252
|
+
* @param url - The loaded URL. Since this might be relative, it's represented
|
|
253
|
+
* as a string rather than a {@link URL} object.
|
|
254
|
+
*
|
|
255
|
+
* @returns An absolute URL if this importer recognizes the `url`, or `null`
|
|
256
|
+
* if it doesn't. If this returns `null`, other importers or {@link
|
|
257
|
+
* Options.loadPaths | load paths} may handle the load.
|
|
258
|
+
*
|
|
259
|
+
* This may also return a `Promise`, but if it does the importer may only be
|
|
260
|
+
* passed to {@link compileAsync} and {@link compileStringAsync}, not {@link
|
|
261
|
+
* compile} or {@link compileString}.
|
|
262
|
+
*
|
|
263
|
+
* @throws any - If this importer recognizes `url` but determines that it's
|
|
264
|
+
* invalid, it may throw an exception that will be wrapped by Sass. If the
|
|
265
|
+
* exception object has a `message` property, it will be used as the wrapped
|
|
266
|
+
* exception's message; otherwise, the exception object's `toString()` will be
|
|
267
|
+
* used. This means it's safe for importers to throw plain strings.
|
|
268
|
+
*/
|
|
269
|
+
canonicalize(
|
|
270
|
+
url: string,
|
|
271
|
+
context: CanonicalizeContext
|
|
272
|
+
): PromiseOr<URL | null, sync>;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Loads the Sass text for the given `canonicalUrl`, or returns `null` if this
|
|
276
|
+
* importer can't find the stylesheet it refers to.
|
|
277
|
+
*
|
|
278
|
+
* @param canonicalUrl - The canonical URL of the stylesheet to load. This is
|
|
279
|
+
* guaranteed to come from a call to {@link canonicalize}, although not every
|
|
280
|
+
* call to {@link canonicalize} will result in a call to {@link load}.
|
|
281
|
+
*
|
|
282
|
+
* @returns The contents of the stylesheet at `canonicalUrl` if it can be
|
|
283
|
+
* loaded, or `null` if it can't.
|
|
284
|
+
*
|
|
285
|
+
* This may also return a `Promise`, but if it does the importer may only be
|
|
286
|
+
* passed to {@link compileAsync} and {@link compileStringAsync}, not {@link
|
|
287
|
+
* compile} or {@link compileString}.
|
|
288
|
+
*
|
|
289
|
+
* @throws any - If this importer finds a stylesheet at `url` but it fails to
|
|
290
|
+
* load for some reason, or if `url` is uniquely associated with this importer
|
|
291
|
+
* but doesn't refer to a real stylesheet, the importer may throw an exception
|
|
292
|
+
* that will be wrapped by Sass. If the exception object has a `message`
|
|
293
|
+
* property, it will be used as the wrapped exception's message; otherwise,
|
|
294
|
+
* the exception object's `toString()` will be used. This means it's safe for
|
|
295
|
+
* importers to throw plain strings.
|
|
296
|
+
*/
|
|
297
|
+
load(canonicalUrl: URL): PromiseOr<ImporterResult | null, sync>;
|
|
298
|
+
|
|
299
|
+
/** @hidden */
|
|
300
|
+
findFileUrl?: never;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* A URL scheme or set of schemes (without the `:`) that this importer
|
|
304
|
+
* promises never to use for URLs returned by {@link canonicalize}. If it does
|
|
305
|
+
* return a URL with one of these schemes, that's an error.
|
|
306
|
+
*
|
|
307
|
+
* If this is set, any call to canonicalize for a URL with a non-canonical
|
|
308
|
+
* scheme will be passed {@link CanonicalizeContext.containingUrl} if it's
|
|
309
|
+
* known.
|
|
310
|
+
*
|
|
311
|
+
* These schemes may only contain lowercase ASCII letters, ASCII numerals,
|
|
312
|
+
* `+`, `-`, and `.`. They may not be empty.
|
|
313
|
+
*/
|
|
314
|
+
nonCanonicalScheme?: string | string[];
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
declare const nodePackageImporterKey: unique symbol;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* The built-in Node.js package importer. This loads pkg: URLs from node_modules
|
|
321
|
+
* according to the standard Node.js resolution algorithm.
|
|
322
|
+
*
|
|
323
|
+
* A Node.js package importer is exposed as a class that can be added to the
|
|
324
|
+
* `importers` option.
|
|
325
|
+
*
|
|
326
|
+
*```js
|
|
327
|
+
* const sass = require('sass');
|
|
328
|
+
* sass.compileString('@use "pkg:vuetify', {
|
|
329
|
+
* importers: [new sass.NodePackageImporter()]
|
|
330
|
+
* });
|
|
331
|
+
*```
|
|
332
|
+
*
|
|
333
|
+
* ## Writing Sass packages
|
|
334
|
+
*
|
|
335
|
+
* Package authors can control what is exposed to their users through their
|
|
336
|
+
* `package.json` manifest. The recommended method is to add a `sass`
|
|
337
|
+
* conditional export to `package.json`.
|
|
338
|
+
*
|
|
339
|
+
* ```json
|
|
340
|
+
* // node_modules/uicomponents/package.json
|
|
341
|
+
* {
|
|
342
|
+
* "exports": {
|
|
343
|
+
* ".": {
|
|
344
|
+
* "sass": "./src/scss/index.scss",
|
|
345
|
+
* "import": "./dist/js/index.mjs",
|
|
346
|
+
* "default": "./dist/js/index.js"
|
|
347
|
+
* }
|
|
348
|
+
* }
|
|
349
|
+
* }
|
|
350
|
+
* ```
|
|
351
|
+
*
|
|
352
|
+
* This allows a package user to write `@use "pkg:uicomponents"` to load the
|
|
353
|
+
* file at `node_modules/uicomponents/src/scss/index.scss`.
|
|
354
|
+
*
|
|
355
|
+
* The Node.js package importer supports the variety of formats supported by
|
|
356
|
+
* Node.js [package entry points], allowing authors to expose multiple subpaths.
|
|
357
|
+
*
|
|
358
|
+
* [package entry points]:
|
|
359
|
+
* https://nodejs.org/api/packages.html#package-entry-points
|
|
360
|
+
*
|
|
361
|
+
* ```json
|
|
362
|
+
* // node_modules/uicomponents/package.json
|
|
363
|
+
* {
|
|
364
|
+
* "exports": {
|
|
365
|
+
* ".": {
|
|
366
|
+
* "sass": "./src/scss/index.scss",
|
|
367
|
+
* },
|
|
368
|
+
* "./colors.scss": {
|
|
369
|
+
* "sass": "./src/scss/_colors.scss",
|
|
370
|
+
* },
|
|
371
|
+
* "./theme/*.scss": {
|
|
372
|
+
* "sass": "./src/scss/theme/*.scss",
|
|
373
|
+
* },
|
|
374
|
+
* }
|
|
375
|
+
* }
|
|
376
|
+
* ```
|
|
377
|
+
*
|
|
378
|
+
* This allows a package user to write:
|
|
379
|
+
*
|
|
380
|
+
* - `@use "pkg:uicomponents";` to import the root export.
|
|
381
|
+
* - `@use "pkg:uicomponents/colors";` to import the colors partial.
|
|
382
|
+
* - `@use "pkg:uicomponents/theme/purple";` to import a purple theme.
|
|
383
|
+
*
|
|
384
|
+
* Note that while library users can rely on the importer to resolve
|
|
385
|
+
* [partials](https://sass-lang.com/documentation/at-rules/use#partials), [index
|
|
386
|
+
* files](https://sass-lang.com/documentation/at-rules/use#index-files), and
|
|
387
|
+
* extensions, library authors must specify the entire file path in `exports`.
|
|
388
|
+
*
|
|
389
|
+
* In addition to the `sass` condition, the `style` condition is also
|
|
390
|
+
* acceptable. Sass will match the `default` condition if it's a relevant file
|
|
391
|
+
* type, but authors are discouraged from relying on this. Notably, the key
|
|
392
|
+
* order matters, and the importer will resolve to the first value with a key
|
|
393
|
+
* that is `sass`, `style`, or `default`, so you should always put `default`
|
|
394
|
+
* last.
|
|
395
|
+
*
|
|
396
|
+
* To help package authors who haven't transitioned to package entry points
|
|
397
|
+
* using the `exports` field, the Node.js package importer provides several
|
|
398
|
+
* fallback options. If the `pkg:` URL does not have a subpath, the Node.js
|
|
399
|
+
* package importer will look for a `sass` or `style` key at the root of
|
|
400
|
+
* `package.json`.
|
|
401
|
+
*
|
|
402
|
+
* ```json
|
|
403
|
+
* // node_modules/uicomponents/package.json
|
|
404
|
+
* {
|
|
405
|
+
* "sass": "./src/scss/index.scss",
|
|
406
|
+
* }
|
|
407
|
+
* ```
|
|
408
|
+
*
|
|
409
|
+
* This allows a user to write `@use "pkg:uicomponents";` to import the
|
|
410
|
+
* `index.scss` file.
|
|
411
|
+
*
|
|
412
|
+
* Finally, the Node.js package importer will look for an `index` file at the
|
|
413
|
+
* package root, resolving partials and extensions. For example, if the file
|
|
414
|
+
* `_index.scss` exists in the package root of `uicomponents`, a user can import
|
|
415
|
+
* that with `@use "pkg:uicomponents";`.
|
|
416
|
+
*
|
|
417
|
+
* If a `pkg:` URL includes a subpath that doesn't have a match in package entry
|
|
418
|
+
* points, the Node.js importer will attempt to find that file relative to the
|
|
419
|
+
* package root, resolving for file extensions, partials and index files. For
|
|
420
|
+
* example, if the file `src/sass/_colors.scss` exists in the `uicomponents`
|
|
421
|
+
* package, a user can import that file using `@use
|
|
422
|
+
* "pkg:uicomponents/src/sass/colors";`.
|
|
423
|
+
*
|
|
424
|
+
* @compatibility dart: "1.71.0", node: false
|
|
425
|
+
* @category Importer
|
|
426
|
+
*/
|
|
427
|
+
export class NodePackageImporter {
|
|
428
|
+
/** Used to distinguish this type from any arbitrary object. */
|
|
429
|
+
private readonly [nodePackageImporterKey]: true;
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* The NodePackageImporter has an optional `entryPointDirectory` option, which
|
|
433
|
+
* is the directory where the Node Package Importer should start when
|
|
434
|
+
* resolving `pkg:` URLs in sources other than files on disk. This will be
|
|
435
|
+
* used as the `parentURL` in the [Node Module
|
|
436
|
+
* Resolution](https://nodejs.org/api/esm.html#resolution-algorithm-specification)
|
|
437
|
+
* algorithm.
|
|
438
|
+
*
|
|
439
|
+
* In order to be found by the Node Package Importer, a package will need to
|
|
440
|
+
* be inside a node_modules folder located in the `entryPointDirectory`, or
|
|
441
|
+
* one of its parent directories, up to the filesystem root.
|
|
442
|
+
*
|
|
443
|
+
* Relative paths will be resolved relative to the current working directory.
|
|
444
|
+
* If a path is not provided, this defaults to the parent directory of the
|
|
445
|
+
* Node.js entrypoint. If that's not available, this will throw an error.
|
|
446
|
+
*/
|
|
447
|
+
constructor(entryPointDirectory?: string);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* The result of successfully loading a stylesheet with an {@link Importer}.
|
|
452
|
+
*
|
|
453
|
+
* @category Importer
|
|
454
|
+
*/
|
|
455
|
+
export interface ImporterResult {
|
|
456
|
+
/** The contents of the stylesheet. */
|
|
457
|
+
contents: string;
|
|
458
|
+
|
|
459
|
+
/** The syntax with which to parse {@link contents}. */
|
|
460
|
+
syntax: Syntax;
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* The URL to use to link to the loaded stylesheet's source code in source
|
|
464
|
+
* maps. A `file:` URL is ideal because it's accessible to both browsers and
|
|
465
|
+
* other build tools, but an `http:` URL is also acceptable.
|
|
466
|
+
*
|
|
467
|
+
* If this isn't set, it defaults to a `data:` URL that contains the contents
|
|
468
|
+
* of the loaded stylesheet.
|
|
469
|
+
*/
|
|
470
|
+
sourceMapUrl?: URL;
|
|
471
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// This is a mirror of the JS API definitions in `spec/js-api`, but with comments
|
|
2
|
+
// written to provide user-facing documentation rather than to specify behavior for
|
|
3
|
+
// implementations.
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
AsyncCompiler,
|
|
7
|
+
CompileResult,
|
|
8
|
+
Compiler,
|
|
9
|
+
compile,
|
|
10
|
+
compileAsync,
|
|
11
|
+
compileString,
|
|
12
|
+
compileStringAsync,
|
|
13
|
+
initCompiler,
|
|
14
|
+
initAsyncCompiler,
|
|
15
|
+
} from './compile';
|
|
16
|
+
export {
|
|
17
|
+
deprecations,
|
|
18
|
+
Deprecation,
|
|
19
|
+
Deprecations,
|
|
20
|
+
DeprecationOrId,
|
|
21
|
+
DeprecationStatus,
|
|
22
|
+
Version,
|
|
23
|
+
} from './deprecations';
|
|
24
|
+
export {Exception} from './exception';
|
|
25
|
+
export {
|
|
26
|
+
CanonicalizeContext,
|
|
27
|
+
FileImporter,
|
|
28
|
+
Importer,
|
|
29
|
+
ImporterResult,
|
|
30
|
+
NodePackageImporter,
|
|
31
|
+
} from './importer';
|
|
32
|
+
export {Logger, LoggerWarnOptions, SourceSpan, SourceLocation} from './logger';
|
|
33
|
+
export {
|
|
34
|
+
CustomFunction,
|
|
35
|
+
Options,
|
|
36
|
+
OutputStyle,
|
|
37
|
+
StringOptions,
|
|
38
|
+
StringOptionsWithImporter,
|
|
39
|
+
StringOptionsWithoutImporter,
|
|
40
|
+
Syntax,
|
|
41
|
+
} from './options';
|
|
42
|
+
export {PromiseOr} from './util/promise_or';
|
|
43
|
+
export {
|
|
44
|
+
CalculationInterpolation,
|
|
45
|
+
CalculationOperation,
|
|
46
|
+
CalculationOperator,
|
|
47
|
+
CalculationValue,
|
|
48
|
+
ChannelName,
|
|
49
|
+
ChannelNameHsl,
|
|
50
|
+
ChannelNameHwb,
|
|
51
|
+
ChannelNameLch,
|
|
52
|
+
ChannelNameLab,
|
|
53
|
+
ChannelNameRgb,
|
|
54
|
+
ChannelNameXyz,
|
|
55
|
+
ColorSpaceHsl,
|
|
56
|
+
ColorSpaceHwb,
|
|
57
|
+
ColorSpaceLch,
|
|
58
|
+
ColorSpaceLab,
|
|
59
|
+
ColorSpaceRgb,
|
|
60
|
+
ColorSpaceXyz,
|
|
61
|
+
GamutMapMethod,
|
|
62
|
+
HueInterpolationMethod,
|
|
63
|
+
KnownColorSpace,
|
|
64
|
+
ListSeparator,
|
|
65
|
+
PolarColorSpace,
|
|
66
|
+
RectangularColorSpace,
|
|
67
|
+
SassArgumentList,
|
|
68
|
+
SassBoolean,
|
|
69
|
+
SassCalculation,
|
|
70
|
+
SassColor,
|
|
71
|
+
SassFunction,
|
|
72
|
+
SassList,
|
|
73
|
+
SassMap,
|
|
74
|
+
SassMixin,
|
|
75
|
+
SassNumber,
|
|
76
|
+
SassString,
|
|
77
|
+
Value,
|
|
78
|
+
sassFalse,
|
|
79
|
+
sassNull,
|
|
80
|
+
sassTrue,
|
|
81
|
+
} from './value';
|
|
82
|
+
|
|
83
|
+
// Legacy APIs
|
|
84
|
+
export {LegacyException} from './legacy/exception';
|
|
85
|
+
export {
|
|
86
|
+
FALSE,
|
|
87
|
+
LegacyAsyncFunction,
|
|
88
|
+
LegacyAsyncFunctionDone,
|
|
89
|
+
LegacyFunction,
|
|
90
|
+
LegacySyncFunction,
|
|
91
|
+
LegacyValue,
|
|
92
|
+
NULL,
|
|
93
|
+
TRUE,
|
|
94
|
+
types,
|
|
95
|
+
} from './legacy/function';
|
|
96
|
+
export {
|
|
97
|
+
LegacyAsyncImporter,
|
|
98
|
+
LegacyImporter,
|
|
99
|
+
LegacyImporterResult,
|
|
100
|
+
LegacyImporterThis,
|
|
101
|
+
LegacySyncImporter,
|
|
102
|
+
} from './legacy/importer';
|
|
103
|
+
export {
|
|
104
|
+
LegacySharedOptions,
|
|
105
|
+
LegacyFileOptions,
|
|
106
|
+
LegacyStringOptions,
|
|
107
|
+
LegacyOptions,
|
|
108
|
+
} from './legacy/options';
|
|
109
|
+
export {LegacyPluginThis} from './legacy/plugin_this';
|
|
110
|
+
export {LegacyResult, render, renderSync} from './legacy/render';
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Information about the Sass implementation. This always begins with a unique
|
|
114
|
+
* identifier for the Sass implementation, followed by U+0009 TAB, followed by
|
|
115
|
+
* its npm package version. Some implementations include additional information
|
|
116
|
+
* as well, but not in any standardized format.
|
|
117
|
+
*
|
|
118
|
+
* * For Dart Sass, the implementation name is `dart-sass`.
|
|
119
|
+
* * For Node Sass, the implementation name is `node-sass`.
|
|
120
|
+
* * For the embedded host, the implementation name is `sass-embedded`.
|
|
121
|
+
*/
|
|
122
|
+
export const info: string;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The exception type thrown by {@link renderSync} and passed as the error to
|
|
3
|
+
* {@link render}'s callback.
|
|
4
|
+
*
|
|
5
|
+
* @category Legacy
|
|
6
|
+
* @deprecated This is only thrown by the legacy {@link render} and {@link
|
|
7
|
+
* renderSync} APIs. Use {@link compile}, {@link compileString}, {@link
|
|
8
|
+
* compileAsync}, and {@link compileStringAsync} instead.
|
|
9
|
+
*/
|
|
10
|
+
export interface LegacyException extends Error {
|
|
11
|
+
/**
|
|
12
|
+
* The error message. For Dart Sass, when possible this includes a highlighted
|
|
13
|
+
* indication of where in the source file the error occurred as well as the
|
|
14
|
+
* Sass stack trace.
|
|
15
|
+
*/
|
|
16
|
+
message: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The error message. For Dart Sass, this is the same as the result of calling
|
|
20
|
+
* {@link toString}, which is itself the same as {@link message} but with the
|
|
21
|
+
* prefix "Error:".
|
|
22
|
+
*/
|
|
23
|
+
formatted: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The (1-based) line number on which the error occurred, if this exception is
|
|
27
|
+
* associated with a specific Sass file location.
|
|
28
|
+
*/
|
|
29
|
+
line?: number;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The (1-based) column number within {@link line} at which the error
|
|
33
|
+
* occurred, if this exception is associated with a specific Sass file
|
|
34
|
+
* location.
|
|
35
|
+
*/
|
|
36
|
+
column?: number;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Analogous to the exit code for an executable. `1` for an error caused by a
|
|
40
|
+
* Sass file, `3` for any other type of error.
|
|
41
|
+
*/
|
|
42
|
+
status: number;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* If this exception was caused by an error in a Sass file, this will
|
|
46
|
+
* represent the Sass file's location. It can be in one of three formats:
|
|
47
|
+
*
|
|
48
|
+
* * If the Sass file was loaded from disk, this is the path to that file.
|
|
49
|
+
* * If the Sass file was generated by an importer, this is its canonical URL.
|
|
50
|
+
* * If the Sass file was passed as {@link LegacyStringOptions.data} without a
|
|
51
|
+
* corresponding {@link LegacyStringOptions.file}, this is the special
|
|
52
|
+
* string `"stdin"`.
|
|
53
|
+
*/
|
|
54
|
+
file?: string;
|
|
55
|
+
}
|