1 | import {LegacyException} from './exception';
|
2 | import {LegacyOptions} from './options';
|
3 |
|
4 | /**
|
5 | * The object returned by {@link render} and {@link renderSync} after a
|
6 | * successful compilation.
|
7 | *
|
8 | * @category Legacy
|
9 | * @deprecated This is only used by the legacy {@link render} and {@link
|
10 | * renderSync} APIs. Use {@link compile}, {@link compileString}, {@link
|
11 | * compileAsync}, and {@link compileStringAsync} instead.
|
12 | */
|
13 | export interface LegacyResult {
|
14 | /**
|
15 | * The compiled CSS. This can be converted to a string by calling
|
16 | * [Buffer.toString](https://nodejs.org/api/buffer.html#buffer_buf_tostring_encoding_start_end).
|
17 | *
|
18 | * @example
|
19 | *
|
20 | * ```js
|
21 | * const result = sass.renderSync({file: "style.scss"});
|
22 | *
|
23 | * console.log(result.css.toString());
|
24 | * ```
|
25 | */
|
26 | css: Buffer;
|
27 |
|
28 | /**
|
29 | * The source map that maps the compiled CSS to the source files from which it
|
30 | * was generated. This can be converted to a string by calling
|
31 | * [Buffer.toString](https://nodejs.org/api/buffer.html#buffer_buf_tostring_encoding_start_end).
|
32 | *
|
33 | * This is `undefined` unless either
|
34 | *
|
35 | * * {@link LegacySharedOptions.sourceMap} is a string; or
|
36 | * * {@link LegacySharedOptions.sourceMap} is `true` and
|
37 | * {@link LegacySharedOptions.outFile} is set.
|
38 | *
|
39 | * The source map uses absolute [`file:`
|
40 | * URLs](https://en.wikipedia.org/wiki/File_URI_scheme) to link to the Sass
|
41 | * source files, except if the source file comes from {@link
|
42 | * LegacyStringOptions.data} in which case it lists its URL as `"stdin"`.
|
43 | *
|
44 | * @example
|
45 | *
|
46 | * ```js
|
47 | * const result = sass.renderSync({
|
48 | * file: "style.scss",
|
49 | * sourceMap: true,
|
50 | * outFile: "style.css"
|
51 | * })
|
52 | *
|
53 | * console.log(result.map.toString());
|
54 | * ```
|
55 | */
|
56 | map?: Buffer;
|
57 |
|
58 | /** Additional information about the compilation. */
|
59 | stats: {
|
60 | /**
|
61 | * The absolute path of {@link LegacyFileOptions.file} or {@link
|
62 | * LegacyStringOptions.file}, or `"data"` if {@link
|
63 | * LegacyStringOptions.file} wasn't set.
|
64 | */
|
65 | entry: string;
|
66 |
|
67 | /**
|
68 | * The number of milliseconds between 1 January 1970 at 00:00:00 UTC and the
|
69 | * time at which Sass compilation began.
|
70 | */
|
71 | start: number;
|
72 |
|
73 | /**
|
74 | * The number of milliseconds between 1 January 1970 at 00:00:00 UTC and the
|
75 | * time at which Sass compilation ended.
|
76 | */
|
77 | end: number;
|
78 |
|
79 | /**
|
80 | * The number of milliseconds it took to compile the Sass file. This is
|
81 | * always equal to `start` minus `end`.
|
82 | */
|
83 | duration: number;
|
84 |
|
85 | /**
|
86 | * An array of the absolute paths of all Sass files loaded during
|
87 | * compilation. If a stylesheet was loaded from a {@link LegacyImporter}
|
88 | * that returned the stylesheet’s contents, the raw string of the `@use` or
|
89 | * `@import` that loaded that stylesheet included in this array.
|
90 | */
|
91 | includedFiles: string[];
|
92 | };
|
93 | }
|
94 |
|
95 | /**
|
96 | * This function synchronously compiles a Sass file to CSS. If it succeeds, it
|
97 | * returns the result, and if it fails it throws an error.
|
98 | *
|
99 | * **Heads up!** When using the `sass-embedded` npm package, **{@link render}
|
100 | * is almost always faster than {@link renderSync}**, due to the overhead of
|
101 | * emulating synchronous messaging with worker threads and concurrent
|
102 | * compilations being blocked on main thread.
|
103 | *
|
104 | * @example
|
105 | *
|
106 | * ```js
|
107 | * const sass = require('sass'); // or require('node-sass');
|
108 | *
|
109 | * const result = sass.renderSync({file: "style.scss"});
|
110 | * // ...
|
111 | * ```
|
112 | *
|
113 | * @category Legacy
|
114 | * @deprecated Use {@link compile} or {@link compileString} instead.
|
115 | */
|
116 | export function renderSync(options: LegacyOptions<'sync'>): LegacyResult;
|
117 |
|
118 | /**
|
119 |
|
120 | * This function asynchronously compiles a Sass file to CSS, and calls
|
121 | * `callback` with a {@link LegacyResult} if compilation succeeds or {@link
|
122 | * LegacyException} if it fails.
|
123 | *
|
124 | * **Heads up!** When using the `sass` npm package, **{@link renderSync} is
|
125 | * almost twice as fast as {@link render}** by default, due to the overhead of
|
126 | * making the entire evaluation process asynchronous.
|
127 | *
|
128 | * ```js
|
129 | * const sass = require('sass'); // or require('node-sass');
|
130 | *
|
131 | * sass.render({
|
132 | * file: "style.scss"
|
133 | * }, function(err, result) {
|
134 | * // ...
|
135 | * });
|
136 | * ```
|
137 | *
|
138 | * @category Legacy
|
139 | * @deprecated Use {@link compileAsync} or {@link compileStringAsync} instead.
|
140 | */
|
141 | export function render(
|
142 | options: LegacyOptions<'async'>,
|
143 | callback: (exception?: LegacyException, result?: LegacyResult) => void
|
144 | ): void;
|