1 | import {LegacyException} from './exception';
|
2 | import {LegacyOptions} from './options';
|
3 |
|
4 | /**
|
5 | * The object returned by [[render]] and [[renderSync]] after a successful
|
6 | * compilation.
|
7 | *
|
8 | * @category Legacy
|
9 | * @deprecated This is only used by the legacy [[render]] and [[renderSync]]
|
10 | * APIs. Use [[compile]], [[compileString]], [[compileAsync]], and
|
11 | * [[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 | * * [[LegacySharedOptions.sourceMap]] is a string; or
|
36 | * * [[LegacySharedOptions.sourceMap]] is `true` and
|
37 | * [[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
|
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 [[LegacyFileOptions.file]] or
|
62 | * [[LegacyStringOptions.file]], or `"data"` if [[LegacyStringOptions.file]]
|
63 | * 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 [[LegacyImporter]] that
|
88 | * 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 | * @example
|
100 | *
|
101 | * ```js
|
102 | * const sass = require('sass'); // or require('node-sass');
|
103 | *
|
104 | * const result = sass.renderSync({file: "style.scss"});
|
105 | * // ...
|
106 | * ```
|
107 | *
|
108 | * @category Legacy
|
109 | * @deprecated Use [[compile]] or [[compileString]] instead.
|
110 | */
|
111 | export function renderSync(options: LegacyOptions<'sync'>): LegacyResult;
|
112 |
|
113 | /**
|
114 |
|
115 | * This function asynchronously compiles a Sass file to CSS, and calls
|
116 | * `callback` with a [[LegacyResult]] if compilation succeeds or
|
117 | * [[LegacyException]] if it fails.
|
118 | *
|
119 | * **Heads up!** When using Dart Sass, **[[renderSync]] is almost twice as fast
|
120 | * as [[render]]** by default, due to the overhead of making the entire
|
121 | * evaluation process asynchronous.
|
122 | *
|
123 | * ```js
|
124 | * const sass = require('sass'); // or require('node-sass');
|
125 | *
|
126 | * sass.render({
|
127 | * file: "style.scss"
|
128 | * }, function(err, result) {
|
129 | * // ...
|
130 | * });
|
131 | * ```
|
132 | *
|
133 | * @category Legacy
|
134 | * @deprecated Use [[compileAsync]] or [[compileStringAsync]] instead.
|
135 | */
|
136 | export function render(
|
137 | options: LegacyOptions<'async'>,
|
138 | callback: (exception?: LegacyException, result?: LegacyResult) => void
|
139 | ): void;
|