UNPKG

6.36 kBTypeScriptView Raw
1import {LegacyPluginThis} from './plugin_this';
2
3/**
4 * The value of `this` in the context of a {@link LegacyImporter} function.
5 *
6 * @category Legacy
7 * @deprecated This is only used by the legacy {@link render} and {@link
8 * renderSync} APIs. Use {@link Importer} with {@link compile}, {@link
9 * compileString}, {@link compileAsync}, and {@link compileStringAsync} instead.
10 */
11interface LegacyImporterThis extends LegacyPluginThis {
12 /**
13 * Whether the importer is being invoked because of a Sass `@import` rule, as
14 * opposed to a `@use` or `@forward` rule.
15 *
16 * This should *only* be used for determining whether or not to load
17 * [import-only files](https://sass-lang.com/documentation/at-rules/import#import-only-files).
18 *
19 * @compatibility dart: "1.33.0", node: false
20 */
21 fromImport: boolean;
22}
23
24/**
25 * The result of running a {@link LegacyImporter}. It must be one of the
26 * following types:
27 *
28 * * An object with the key `contents` whose value is the contents of a stylesheet
29 * (in SCSS syntax). This causes Sass to load that stylesheet’s contents.
30 *
31 * * An object with the key `file` whose value is a path on disk. This causes Sass
32 * to load that file as though it had been imported directly.
33 *
34 * * `null`, which indicates that it doesn’t recognize the URL and another
35 * importer should be tried instead.
36 *
37 * * An [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
38 * object, indicating that importing failed.
39 *
40 * @category Legacy
41 * @deprecated This only works with the legacy {@link render} and {@link
42 * renderSync} APIs. Use {@link ImporterResult} with {@link compile}, {@link
43 * compileString}, {@link compileAsync}, and {@link compileStringAsync} instead.
44 */
45export type LegacyImporterResult =
46 | {file: string}
47 | {contents: string}
48 | Error
49 | null;
50
51/**
52 * A synchronous callback that implements custom Sass loading logic for
53 * [`@import` rules](https://sass-lang.com/documentation/at-rules/import) and
54 * [`@use` rules](https://sass-lang.com/documentation/at-rules/use). This can be
55 * passed to {@link LegacySharedOptions.importer} for either {@link render} or
56 * {@link renderSync}.
57 *
58 * See {@link LegacySharedOptions.importer} for more detailed documentation.
59 *
60 * ```js
61 * sass.renderSync({
62 * file: "style.scss",
63 * importer: [
64 * function(url, prev) {
65 * if (url != "big-headers") return null;
66 *
67 * return {
68 * contents: 'h1 { font-size: 40px; }'
69 * };
70 * }
71 * ]
72 * });
73 * ```
74 *
75 * @param url - The `@use` or `@import` rule’s URL as a string, exactly as it
76 * appears in the stylesheet.
77 *
78 * @param prev - A string identifying the stylesheet that contained the `@use`
79 * or `@import`. This string’s format depends on how that stylesheet was loaded:
80 *
81 * * If the stylesheet was loaded from the filesystem, it’s the absolute path of
82 * its file.
83 * * If the stylesheet was loaded from an importer that returned its contents,
84 * it’s the URL of the `@use` or `@import` rule that loaded it.
85 * * If the stylesheet came from the data option, it’s the string "stdin".
86 *
87 * @category Legacy
88 * @deprecated This only works with the legacy {@link render} and {@link
89 * renderSync} APIs. Use {@link Importer} with {@link compile}, {@link
90 * compileString}, {@link compileAsync}, and {@link compileStringAsync} instead.
91 */
92type LegacySyncImporter = (
93 this: LegacyImporterThis,
94 url: string,
95 prev: string
96) => LegacyImporterResult;
97
98/**
99 * An asynchronous callback that implements custom Sass loading logic for
100 * [`@import` rules](https://sass-lang.com/documentation/at-rules/import) and
101 * [`@use` rules](https://sass-lang.com/documentation/at-rules/use). This can be
102 * passed to {@link LegacySharedOptions.importer} for either {@link render} or
103 * {@link renderSync}.
104 *
105 * An asynchronous importer must return `undefined`, and then call `done` with
106 * the result of its {@link LegacyImporterResult} once it's done running.
107 *
108 * See {@link LegacySharedOptions.importer} for more detailed documentation.
109 *
110 * ```js
111 * sass.render({
112 * file: "style.scss",
113 * importer: [
114 * function(url, prev, done) {
115 * if (url != "big-headers") done(null);
116 *
117 * done({
118 * contents: 'h1 { font-size: 40px; }'
119 * });
120 * }
121 * ]
122 * });
123 * ```
124 *
125 * @param url - The `@use` or `@import` rule’s URL as a string, exactly as it
126 * appears in the stylesheet.
127 *
128 * @param prev - A string identifying the stylesheet that contained the `@use`
129 * or `@import`. This string’s format depends on how that stylesheet was loaded:
130 *
131 * * If the stylesheet was loaded from the filesystem, it’s the absolute path of
132 * its file.
133 * * If the stylesheet was loaded from an importer that returned its contents,
134 * it’s the URL of the `@use` or `@import` rule that loaded it.
135 * * If the stylesheet came from the data option, it’s the string "stdin".
136 *
137 * @param done - The callback to call once the importer has finished running.
138 *
139 * @category Legacy
140 * @deprecated This only works with the legacy {@link render} and {@link
141 * renderSync} APIs. Use {@link Importer} with {@link compile}, {@link
142 * compileString}, {@link compileAsync}, and {@link compileStringAsync} instead.
143 */
144type LegacyAsyncImporter = (
145 this: LegacyImporterThis,
146 url: string,
147 prev: string,
148 done: (result: LegacyImporterResult) => void
149) => void;
150
151/**
152 * A callback that implements custom Sass loading logic for [`@import`
153 * rules](https://sass-lang.com/documentation/at-rules/import) and [`@use`
154 * rules](https://sass-lang.com/documentation/at-rules/use). For {@link
155 * renderSync}, this must be a {@link LegacySyncImporter} which returns its
156 * result directly; for {@link render}, it may be either a {@link
157 * LegacySyncImporter} or a {@link LegacyAsyncImporter} which calls a callback
158 * with its result.
159 *
160 * See {@link LegacySharedOptions.importer} for more details.
161 *
162 * @category Legacy
163 * @deprecated This only works with the legacy {@link render} and {@link
164 * renderSync} APIs. Use {@link Importer} with {@link compile}, {@link
165 * compileString}, {@link compileAsync}, and {@link compileStringAsync} instead.
166 */
167export type LegacyImporter<sync = 'sync' | 'async'> = sync extends 'async'
168 ? LegacySyncImporter | LegacyAsyncImporter
169 : LegacySyncImporter;