20d3e27d1f4e988bd1b9082b5cbec922273e6f2303346c7e5fc4336ed9fdb10c8cdadcc04ba26db2105c4a86ef6b939cacab7b53dcd1bb8897460765eb1b5d 4.3 KB

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