@angular-devkit/build-angular 18.0.0-next.3 → 18.0.0-next.5

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.
Files changed (252) hide show
  1. package/builders.json +1 -5
  2. package/package.json +14 -13
  3. package/src/builders/app-shell/index.js +3 -5
  4. package/src/builders/browser/index.d.ts +1 -1
  5. package/src/builders/browser/index.js +8 -12
  6. package/src/builders/browser-esbuild/index.d.ts +2 -2
  7. package/src/builders/browser-esbuild/index.js +6 -9
  8. package/src/builders/dev-server/builder.d.ts +2 -2
  9. package/src/builders/dev-server/builder.js +11 -6
  10. package/src/builders/dev-server/index.d.ts +1 -1
  11. package/src/builders/dev-server/webpack-server.d.ts +1 -1
  12. package/src/builders/dev-server/webpack-server.js +3 -4
  13. package/src/builders/extract-i18n/application-extraction.js +2 -2
  14. package/src/builders/extract-i18n/builder.js +3 -4
  15. package/src/builders/extract-i18n/options.d.ts +1 -1
  16. package/src/builders/extract-i18n/options.js +2 -2
  17. package/src/builders/jest/index.js +2 -2
  18. package/src/builders/karma/index.js +3 -4
  19. package/src/builders/ng-packagr/index.js +8 -7
  20. package/src/builders/ng-packagr/schema.d.ts +4 -0
  21. package/src/builders/ng-packagr/schema.json +4 -0
  22. package/src/builders/prerender/index.js +2 -2
  23. package/src/builders/prerender/render-worker.js +1 -1
  24. package/src/builders/server/index.js +3 -4
  25. package/src/builders/server/platform-server-exports-loader.js +2 -1
  26. package/src/builders/ssr-dev-server/index.js +7 -7
  27. package/src/builders/web-test-runner/index.js +2 -2
  28. package/src/index.d.ts +1 -1
  29. package/src/index.js +2 -2
  30. package/src/tools/babel/presets/application.js +1 -1
  31. package/src/tools/webpack/configs/styles.js +2 -2
  32. package/src/tools/webpack/plugins/any-component-style-budget-checker.d.ts +1 -1
  33. package/src/tools/webpack/plugins/any-component-style-budget-checker.js +5 -5
  34. package/src/tools/webpack/plugins/css-optimizer-plugin.js +2 -2
  35. package/src/tools/webpack/plugins/index-html-webpack-plugin.d.ts +1 -1
  36. package/src/tools/webpack/plugins/index-html-webpack-plugin.js +2 -2
  37. package/src/tools/webpack/plugins/javascript-optimizer-plugin.js +2 -2
  38. package/src/tools/webpack/plugins/service-worker-plugin.js +2 -2
  39. package/src/tools/webpack/utils/stats.d.ts +1 -1
  40. package/src/tools/webpack/utils/stats.js +2 -2
  41. package/src/utils/i18n-webpack.d.ts +1 -1
  42. package/src/utils/i18n-webpack.js +5 -6
  43. package/src/utils/index.d.ts +1 -2
  44. package/src/utils/index.js +4 -2
  45. package/src/utils/normalize-builder-schema.js +2 -2
  46. package/src/utils/normalize-cache.js +1 -1
  47. package/src/utils/normalize-optimization.d.ts +1 -1
  48. package/src/utils/normalize-optimization.js +0 -2
  49. package/src/builders/application/build-action.d.ts +0 -33
  50. package/src/builders/application/build-action.js +0 -183
  51. package/src/builders/application/execute-build.d.ts +0 -11
  52. package/src/builders/application/execute-build.js +0 -125
  53. package/src/builders/application/execute-post-bundle.d.ts +0 -25
  54. package/src/builders/application/execute-post-bundle.js +0 -93
  55. package/src/builders/application/i18n.d.ts +0 -29
  56. package/src/builders/application/i18n.js +0 -128
  57. package/src/builders/application/index.d.ts +0 -57
  58. package/src/builders/application/index.js +0 -121
  59. package/src/builders/application/options.d.ts +0 -149
  60. package/src/builders/application/options.js +0 -369
  61. package/src/builders/application/schema.d.ts +0 -512
  62. package/src/builders/application/schema.js +0 -58
  63. package/src/builders/application/schema.json +0 -635
  64. package/src/builders/application/setup-bundling.d.ts +0 -19
  65. package/src/builders/application/setup-bundling.js +0 -71
  66. package/src/builders/dev-server/vite-server.d.ts +0 -30
  67. package/src/builders/dev-server/vite-server.js +0 -502
  68. package/src/tools/babel/plugins/adjust-static-class-members.d.ts +0 -27
  69. package/src/tools/babel/plugins/adjust-static-class-members.js +0 -351
  70. package/src/tools/babel/plugins/adjust-typescript-enums.d.ts +0 -23
  71. package/src/tools/babel/plugins/adjust-typescript-enums.js +0 -113
  72. package/src/tools/babel/plugins/elide-angular-metadata.d.ts +0 -23
  73. package/src/tools/babel/plugins/elide-angular-metadata.js +0 -110
  74. package/src/tools/babel/plugins/index.d.ts +0 -11
  75. package/src/tools/babel/plugins/index.js +0 -21
  76. package/src/tools/babel/plugins/pure-toplevel-functions.d.ts +0 -16
  77. package/src/tools/babel/plugins/pure-toplevel-functions.js +0 -90
  78. package/src/tools/esbuild/angular/angular-host.d.ts +0 -26
  79. package/src/tools/esbuild/angular/angular-host.js +0 -72
  80. package/src/tools/esbuild/angular/compilation/angular-compilation.d.ts +0 -42
  81. package/src/tools/esbuild/angular/compilation/angular-compilation.js +0 -94
  82. package/src/tools/esbuild/angular/compilation/aot-compilation.d.ts +0 -21
  83. package/src/tools/esbuild/angular/compilation/aot-compilation.js +0 -228
  84. package/src/tools/esbuild/angular/compilation/factory.d.ts +0 -16
  85. package/src/tools/esbuild/angular/compilation/factory.js +0 -56
  86. package/src/tools/esbuild/angular/compilation/index.d.ts +0 -10
  87. package/src/tools/esbuild/angular/compilation/index.js +0 -17
  88. package/src/tools/esbuild/angular/compilation/jit-compilation.d.ts +0 -21
  89. package/src/tools/esbuild/angular/compilation/jit-compilation.js +0 -106
  90. package/src/tools/esbuild/angular/compilation/noop-compilation.d.ts +0 -20
  91. package/src/tools/esbuild/angular/compilation/noop-compilation.js +0 -26
  92. package/src/tools/esbuild/angular/compilation/parallel-compilation.d.ts +0 -42
  93. package/src/tools/esbuild/angular/compilation/parallel-compilation.js +0 -123
  94. package/src/tools/esbuild/angular/compilation/parallel-worker.d.ts +0 -33
  95. package/src/tools/esbuild/angular/compilation/parallel-worker.js +0 -90
  96. package/src/tools/esbuild/angular/compilation-state.d.ts +0 -15
  97. package/src/tools/esbuild/angular/compilation-state.js +0 -44
  98. package/src/tools/esbuild/angular/compiler-plugin.d.ts +0 -27
  99. package/src/tools/esbuild/angular/compiler-plugin.js +0 -441
  100. package/src/tools/esbuild/angular/component-stylesheets.d.ts +0 -44
  101. package/src/tools/esbuild/angular/component-stylesheets.js +0 -150
  102. package/src/tools/esbuild/angular/diagnostics.d.ts +0 -15
  103. package/src/tools/esbuild/angular/diagnostics.js +0 -69
  104. package/src/tools/esbuild/angular/file-reference-tracker.d.ts +0 -17
  105. package/src/tools/esbuild/angular/file-reference-tracker.js +0 -57
  106. package/src/tools/esbuild/angular/jit-plugin-callbacks.d.ts +0 -23
  107. package/src/tools/esbuild/angular/jit-plugin-callbacks.js +0 -117
  108. package/src/tools/esbuild/angular/jit-resource-transformer.d.ts +0 -17
  109. package/src/tools/esbuild/angular/jit-resource-transformer.js +0 -186
  110. package/src/tools/esbuild/angular/source-file-cache.d.ts +0 -18
  111. package/src/tools/esbuild/angular/source-file-cache.js +0 -65
  112. package/src/tools/esbuild/angular/uri.d.ts +0 -54
  113. package/src/tools/esbuild/angular/uri.js +0 -74
  114. package/src/tools/esbuild/angular/web-worker-transformer.d.ts +0 -17
  115. package/src/tools/esbuild/angular/web-worker-transformer.js +0 -94
  116. package/src/tools/esbuild/application-code-bundle.d.ts +0 -20
  117. package/src/tools/esbuild/application-code-bundle.js +0 -368
  118. package/src/tools/esbuild/budget-stats.d.ts +0 -19
  119. package/src/tools/esbuild/budget-stats.js +0 -59
  120. package/src/tools/esbuild/bundler-context.d.ts +0 -75
  121. package/src/tools/esbuild/bundler-context.js +0 -366
  122. package/src/tools/esbuild/bundler-execution-result.d.ts +0 -71
  123. package/src/tools/esbuild/bundler-execution-result.js +0 -131
  124. package/src/tools/esbuild/cache.d.ts +0 -88
  125. package/src/tools/esbuild/cache.js +0 -92
  126. package/src/tools/esbuild/commonjs-checker.d.ts +0 -28
  127. package/src/tools/esbuild/commonjs-checker.js +0 -151
  128. package/src/tools/esbuild/compiler-plugin-options.d.ts +0 -16
  129. package/src/tools/esbuild/compiler-plugin-options.js +0 -49
  130. package/src/tools/esbuild/external-packages-plugin.d.ts +0 -18
  131. package/src/tools/esbuild/external-packages-plugin.js +0 -70
  132. package/src/tools/esbuild/global-scripts.d.ts +0 -16
  133. package/src/tools/esbuild/global-scripts.js +0 -142
  134. package/src/tools/esbuild/global-styles.d.ts +0 -10
  135. package/src/tools/esbuild/global-styles.js +0 -74
  136. package/src/tools/esbuild/i18n-inliner-worker.d.ts +0 -42
  137. package/src/tools/esbuild/i18n-inliner-worker.js +0 -136
  138. package/src/tools/esbuild/i18n-inliner.d.ts +0 -44
  139. package/src/tools/esbuild/i18n-inliner.js +0 -150
  140. package/src/tools/esbuild/i18n-locale-plugin.d.ts +0 -22
  141. package/src/tools/esbuild/i18n-locale-plugin.js +0 -120
  142. package/src/tools/esbuild/index-html-generator.d.ts +0 -15
  143. package/src/tools/esbuild/index-html-generator.js +0 -81
  144. package/src/tools/esbuild/javascript-transformer-worker.d.ts +0 -19
  145. package/src/tools/esbuild/javascript-transformer-worker.js +0 -154
  146. package/src/tools/esbuild/javascript-transformer.d.ts +0 -54
  147. package/src/tools/esbuild/javascript-transformer.js +0 -147
  148. package/src/tools/esbuild/license-extractor.d.ts +0 -25
  149. package/src/tools/esbuild/license-extractor.js +0 -158
  150. package/src/tools/esbuild/load-result-cache.d.ts +0 -21
  151. package/src/tools/esbuild/load-result-cache.js +0 -75
  152. package/src/tools/esbuild/profiling.d.ts +0 -11
  153. package/src/tools/esbuild/profiling.js +0 -78
  154. package/src/tools/esbuild/rxjs-esm-resolution-plugin.d.ts +0 -18
  155. package/src/tools/esbuild/rxjs-esm-resolution-plugin.js +0 -44
  156. package/src/tools/esbuild/sourcemap-ignorelist-plugin.d.ts +0 -17
  157. package/src/tools/esbuild/sourcemap-ignorelist-plugin.js +0 -73
  158. package/src/tools/esbuild/stylesheets/bundle-options.d.ts +0 -35
  159. package/src/tools/esbuild/stylesheets/bundle-options.js +0 -64
  160. package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.d.ts +0 -25
  161. package/src/tools/esbuild/stylesheets/css-inline-fonts-plugin.js +0 -57
  162. package/src/tools/esbuild/stylesheets/css-language.d.ts +0 -9
  163. package/src/tools/esbuild/stylesheets/css-language.js +0 -15
  164. package/src/tools/esbuild/stylesheets/css-resource-plugin.d.ts +0 -18
  165. package/src/tools/esbuild/stylesheets/css-resource-plugin.js +0 -114
  166. package/src/tools/esbuild/stylesheets/less-language.d.ts +0 -9
  167. package/src/tools/esbuild/stylesheets/less-language.js +0 -155
  168. package/src/tools/esbuild/stylesheets/sass-language.d.ts +0 -10
  169. package/src/tools/esbuild/stylesheets/sass-language.js +0 -185
  170. package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.d.ts +0 -58
  171. package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.js +0 -282
  172. package/src/tools/esbuild/utils.d.ts +0 -41
  173. package/src/tools/esbuild/utils.js +0 -378
  174. package/src/tools/esbuild/virtual-module-plugin.d.ts +0 -33
  175. package/src/tools/esbuild/virtual-module-plugin.js +0 -43
  176. package/src/tools/esbuild/watcher.d.ts +0 -25
  177. package/src/tools/esbuild/watcher.js +0 -118
  178. package/src/tools/sass/lexer.d.ts +0 -18
  179. package/src/tools/sass/lexer.js +0 -161
  180. package/src/tools/sass/rebasing-importer.d.ts +0 -101
  181. package/src/tools/sass/rebasing-importer.js +0 -334
  182. package/src/tools/sass/sass-service.d.ts +0 -72
  183. package/src/tools/sass/sass-service.js +0 -213
  184. package/src/tools/sass/worker.d.ts +0 -8
  185. package/src/tools/sass/worker.js +0 -192
  186. package/src/tools/vite/angular-memory-plugin.d.ts +0 -24
  187. package/src/tools/vite/angular-memory-plugin.js +0 -268
  188. package/src/tools/vite/i18n-locale-plugin.d.ts +0 -18
  189. package/src/tools/vite/i18n-locale-plugin.js +0 -55
  190. package/src/typings.d.ts +0 -21
  191. package/src/utils/bundle-calculator.d.ts +0 -44
  192. package/src/utils/bundle-calculator.js +0 -303
  193. package/src/utils/check-port.d.ts +0 -8
  194. package/src/utils/check-port.js +0 -58
  195. package/src/utils/delete-output-dir.d.ts +0 -11
  196. package/src/utils/delete-output-dir.js +0 -46
  197. package/src/utils/format-bytes.d.ts +0 -8
  198. package/src/utils/format-bytes.js +0 -22
  199. package/src/utils/i18n-options.d.ts +0 -33
  200. package/src/utils/i18n-options.js +0 -161
  201. package/src/utils/index-file/add-event-dispatch-contract.d.ts +0 -8
  202. package/src/utils/index-file/add-event-dispatch-contract.js +0 -28
  203. package/src/utils/index-file/augment-index-html.d.ts +0 -40
  204. package/src/utils/index-file/augment-index-html.js +0 -239
  205. package/src/utils/index-file/html-rewriting-stream.d.ts +0 -11
  206. package/src/utils/index-file/html-rewriting-stream.js +0 -28
  207. package/src/utils/index-file/index-html-generator.d.ts +0 -57
  208. package/src/utils/index-file/index-html-generator.js +0 -135
  209. package/src/utils/index-file/inline-critical-css.d.ts +0 -24
  210. package/src/utils/index-file/inline-critical-css.js +0 -179
  211. package/src/utils/index-file/inline-fonts.d.ts +0 -23
  212. package/src/utils/index-file/inline-fonts.js +0 -267
  213. package/src/utils/index-file/nonce.d.ts +0 -12
  214. package/src/utils/index-file/nonce.js +0 -55
  215. package/src/utils/load-proxy-config.d.ts +0 -8
  216. package/src/utils/load-proxy-config.js +0 -189
  217. package/src/utils/load-translations.d.ts +0 -16
  218. package/src/utils/load-translations.js +0 -84
  219. package/src/utils/postcss-configuration.d.ts +0 -17
  220. package/src/utils/postcss-configuration.js +0 -86
  221. package/src/utils/purge-cache.d.ts +0 -10
  222. package/src/utils/purge-cache.js +0 -40
  223. package/src/utils/resolve-assets.d.ts +0 -18
  224. package/src/utils/resolve-assets.js +0 -35
  225. package/src/utils/routes-extractor/extractor.d.ts +0 -15
  226. package/src/utils/routes-extractor/extractor.js +0 -97
  227. package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.d.ts +0 -18
  228. package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.js +0 -129
  229. package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.d.ts +0 -8
  230. package/src/utils/server-rendering/esm-in-memory-loader/register-hooks.js +0 -13
  231. package/src/utils/server-rendering/fetch-patch.d.ts +0 -8
  232. package/src/utils/server-rendering/fetch-patch.js +0 -66
  233. package/src/utils/server-rendering/load-esm-from-memory.d.ts +0 -10
  234. package/src/utils/server-rendering/load-esm-from-memory.js +0 -26
  235. package/src/utils/server-rendering/main-bundle-exports.d.ts +0 -27
  236. package/src/utils/server-rendering/main-bundle-exports.js +0 -9
  237. package/src/utils/server-rendering/prerender.d.ts +0 -23
  238. package/src/utils/server-rendering/prerender.js +0 -192
  239. package/src/utils/server-rendering/render-page.d.ts +0 -26
  240. package/src/utils/server-rendering/render-page.js +0 -110
  241. package/src/utils/server-rendering/render-worker.d.ts +0 -22
  242. package/src/utils/server-rendering/render-worker.js +0 -30
  243. package/src/utils/server-rendering/routes-extractor-worker.d.ts +0 -21
  244. package/src/utils/server-rendering/routes-extractor-worker.js +0 -53
  245. package/src/utils/service-worker.d.ts +0 -25
  246. package/src/utils/service-worker.js +0 -211
  247. package/src/utils/stats-table.d.ts +0 -20
  248. package/src/utils/stats-table.js +0 -205
  249. package/src/utils/supported-browsers.d.ts +0 -10
  250. package/src/utils/supported-browsers.js +0 -42
  251. package/src/utils/version.d.ts +0 -8
  252. package/src/utils/version.js +0 -59
@@ -1,213 +0,0 @@
1
- "use strict";
2
- /**
3
- * @license
4
- * Copyright Google LLC All Rights Reserved.
5
- *
6
- * Use of this source code is governed by an MIT-style license that can be
7
- * found in the LICENSE file at https://angular.io/license
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.SassWorkerImplementation = void 0;
11
- const node_path_1 = require("node:path");
12
- const node_url_1 = require("node:url");
13
- const node_worker_threads_1 = require("node:worker_threads");
14
- const environment_options_1 = require("../../utils/environment-options");
15
- /**
16
- * The maximum number of Workers that will be created to execute render requests.
17
- */
18
- const MAX_RENDER_WORKERS = environment_options_1.maxWorkers;
19
- /**
20
- * A Sass renderer implementation that provides an interface that can be used by Webpack's
21
- * `sass-loader`. The implementation uses a Worker thread to perform the Sass rendering
22
- * with the `dart-sass` package. The `dart-sass` synchronous render function is used within
23
- * the worker which can be up to two times faster than the asynchronous variant.
24
- */
25
- class SassWorkerImplementation {
26
- rebase;
27
- workers = [];
28
- availableWorkers = [];
29
- requests = new Map();
30
- workerPath = (0, node_path_1.join)(__dirname, './worker.js');
31
- idCounter = 1;
32
- nextWorkerIndex = 0;
33
- constructor(rebase = false) {
34
- this.rebase = rebase;
35
- }
36
- /**
37
- * Provides information about the Sass implementation.
38
- * This mimics enough of the `dart-sass` value to be used with the `sass-loader`.
39
- */
40
- get info() {
41
- return 'dart-sass\tworker';
42
- }
43
- /**
44
- * The synchronous render function is not used by the `sass-loader`.
45
- */
46
- compileString() {
47
- throw new Error('Sass compileString is not supported.');
48
- }
49
- /**
50
- * Asynchronously request a Sass stylesheet to be renderered.
51
- *
52
- * @param source The contents to compile.
53
- * @param options The `dart-sass` options to use when rendering the stylesheet.
54
- */
55
- compileStringAsync(source, options) {
56
- // The `functions`, `logger` and `importer` options are JavaScript functions that cannot be transferred.
57
- // If any additional function options are added in the future, they must be excluded as well.
58
- const { functions, importers, url, logger, ...serializableOptions } = options;
59
- // The CLI's configuration does not use or expose the ability to defined custom Sass functions
60
- if (functions && Object.keys(functions).length > 0) {
61
- throw new Error('Sass custom functions are not supported.');
62
- }
63
- return new Promise((resolve, reject) => {
64
- let workerIndex = this.availableWorkers.pop();
65
- if (workerIndex === undefined) {
66
- if (this.workers.length < MAX_RENDER_WORKERS) {
67
- workerIndex = this.workers.length;
68
- this.workers.push(this.createWorker());
69
- }
70
- else {
71
- workerIndex = this.nextWorkerIndex++;
72
- if (this.nextWorkerIndex >= this.workers.length) {
73
- this.nextWorkerIndex = 0;
74
- }
75
- }
76
- }
77
- const callback = (error, result) => {
78
- if (error) {
79
- const url = error.span?.url;
80
- if (url) {
81
- error.span.url = (0, node_url_1.pathToFileURL)(url);
82
- }
83
- reject(error);
84
- return;
85
- }
86
- if (!result) {
87
- reject(new Error('No result.'));
88
- return;
89
- }
90
- resolve(result);
91
- };
92
- const request = this.createRequest(workerIndex, callback, logger, importers);
93
- this.requests.set(request.id, request);
94
- this.workers[workerIndex].postMessage({
95
- id: request.id,
96
- source,
97
- hasImporter: !!importers?.length,
98
- hasLogger: !!logger,
99
- rebase: this.rebase,
100
- options: {
101
- ...serializableOptions,
102
- // URL is not serializable so to convert to string here and back to URL in the worker.
103
- url: url ? (0, node_url_1.fileURLToPath)(url) : undefined,
104
- },
105
- });
106
- });
107
- }
108
- /**
109
- * Shutdown the Sass render worker.
110
- * Executing this method will stop any pending render requests.
111
- */
112
- close() {
113
- for (const worker of this.workers) {
114
- try {
115
- void worker.terminate();
116
- }
117
- catch { }
118
- }
119
- this.requests.clear();
120
- }
121
- createWorker() {
122
- const { port1: mainImporterPort, port2: workerImporterPort } = new node_worker_threads_1.MessageChannel();
123
- const importerSignal = new Int32Array(new SharedArrayBuffer(4));
124
- const worker = new node_worker_threads_1.Worker(this.workerPath, {
125
- workerData: { workerImporterPort, importerSignal },
126
- transferList: [workerImporterPort],
127
- });
128
- worker.on('message', (response) => {
129
- const request = this.requests.get(response.id);
130
- if (!request) {
131
- return;
132
- }
133
- this.requests.delete(response.id);
134
- this.availableWorkers.push(request.workerIndex);
135
- if (response.warnings && request.logger?.warn) {
136
- for (const { message, span, ...options } of response.warnings) {
137
- request.logger.warn(message, {
138
- ...options,
139
- span: span && {
140
- ...span,
141
- url: span.url ? (0, node_url_1.pathToFileURL)(span.url) : undefined,
142
- },
143
- });
144
- }
145
- }
146
- if (response.result) {
147
- request.callback(undefined, {
148
- ...response.result,
149
- // URL is not serializable so in the worker we convert to string and here back to URL.
150
- loadedUrls: response.result.loadedUrls.map((p) => (0, node_url_1.pathToFileURL)(p)),
151
- });
152
- }
153
- else {
154
- request.callback(response.error);
155
- }
156
- });
157
- mainImporterPort.on('message', ({ id, url, options }) => {
158
- const request = this.requests.get(id);
159
- if (!request?.importers) {
160
- mainImporterPort.postMessage(null);
161
- Atomics.store(importerSignal, 0, 1);
162
- Atomics.notify(importerSignal, 0);
163
- return;
164
- }
165
- this.processImporters(request.importers, url, {
166
- ...options,
167
- // URL is not serializable so in the worker we convert to string and here back to URL.
168
- containingUrl: options.containingUrl
169
- ? (0, node_url_1.pathToFileURL)(options.containingUrl)
170
- : null,
171
- })
172
- .then((result) => {
173
- mainImporterPort.postMessage(result);
174
- })
175
- .catch((error) => {
176
- mainImporterPort.postMessage(error);
177
- })
178
- .finally(() => {
179
- Atomics.store(importerSignal, 0, 1);
180
- Atomics.notify(importerSignal, 0);
181
- });
182
- });
183
- mainImporterPort.unref();
184
- return worker;
185
- }
186
- async processImporters(importers, url, options) {
187
- for (const importer of importers) {
188
- if (!this.isFileImporter(importer)) {
189
- // Importer
190
- throw new Error('Only File Importers are supported.');
191
- }
192
- // File importer (Can be sync or aync).
193
- const result = await importer.findFileUrl(url, options);
194
- if (result) {
195
- return (0, node_url_1.fileURLToPath)(result);
196
- }
197
- }
198
- return null;
199
- }
200
- createRequest(workerIndex, callback, logger, importers) {
201
- return {
202
- id: this.idCounter++,
203
- workerIndex,
204
- callback,
205
- logger,
206
- importers,
207
- };
208
- }
209
- isFileImporter(value) {
210
- return 'findFileUrl' in value;
211
- }
212
- }
213
- exports.SassWorkerImplementation = SassWorkerImplementation;
@@ -1,8 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright Google LLC All Rights Reserved.
4
- *
5
- * Use of this source code is governed by an MIT-style license that can be
6
- * found in the LICENSE file at https://angular.io/license
7
- */
8
- export {};
@@ -1,192 +0,0 @@
1
- "use strict";
2
- /**
3
- * @license
4
- * Copyright Google LLC All Rights Reserved.
5
- *
6
- * Use of this source code is governed by an MIT-style license that can be
7
- * found in the LICENSE file at https://angular.io/license
8
- */
9
- var __importDefault = (this && this.__importDefault) || function (mod) {
10
- return (mod && mod.__esModule) ? mod : { "default": mod };
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- const remapping_1 = __importDefault(require("@ampproject/remapping"));
14
- const node_path_1 = require("node:path");
15
- const node_url_1 = require("node:url");
16
- const node_worker_threads_1 = require("node:worker_threads");
17
- const sass_1 = require("sass");
18
- const rebasing_importer_1 = require("./rebasing-importer");
19
- if (!node_worker_threads_1.parentPort || !node_worker_threads_1.workerData) {
20
- throw new Error('Sass worker must be executed as a Worker.');
21
- }
22
- // The importer variables are used to proxy import requests to the main thread
23
- const { workerImporterPort, importerSignal } = node_worker_threads_1.workerData;
24
- node_worker_threads_1.parentPort.on('message', (message) => {
25
- if (!node_worker_threads_1.parentPort) {
26
- throw new Error('"parentPort" is not defined. Sass worker must be executed as a Worker.');
27
- }
28
- const { id, hasImporter, hasLogger, source, options, rebase } = message;
29
- const entryDirectory = (0, node_path_1.dirname)(options.url);
30
- let warnings;
31
- try {
32
- const directoryCache = new Map();
33
- const rebaseSourceMaps = options.sourceMap ? new Map() : undefined;
34
- if (hasImporter) {
35
- // When a custom importer function is present, the importer request must be proxied
36
- // back to the main thread where it can be executed.
37
- // This process must be synchronous from the perspective of dart-sass. The `Atomics`
38
- // functions combined with the shared memory `importSignal` and the Node.js
39
- // `receiveMessageOnPort` function are used to ensure synchronous behavior.
40
- const proxyImporter = {
41
- findFileUrl: (url, options) => {
42
- Atomics.store(importerSignal, 0, 0);
43
- workerImporterPort.postMessage({
44
- id,
45
- url,
46
- options: {
47
- ...options,
48
- containingUrl: options.containingUrl ? (0, node_url_1.fileURLToPath)(options.containingUrl) : null,
49
- },
50
- });
51
- Atomics.wait(importerSignal, 0, 0);
52
- const result = (0, node_worker_threads_1.receiveMessageOnPort)(workerImporterPort)?.message;
53
- return result ? (0, node_url_1.pathToFileURL)(result) : null;
54
- },
55
- };
56
- options.importers = [
57
- rebase
58
- ? (0, rebasing_importer_1.sassBindWorkaround)(new rebasing_importer_1.ModuleUrlRebasingImporter(entryDirectory, directoryCache, rebaseSourceMaps, proxyImporter.findFileUrl))
59
- : proxyImporter,
60
- ];
61
- }
62
- if (rebase && options.loadPaths?.length) {
63
- options.importers ??= [];
64
- options.importers.push((0, rebasing_importer_1.sassBindWorkaround)(new rebasing_importer_1.LoadPathsUrlRebasingImporter(entryDirectory, directoryCache, rebaseSourceMaps, options.loadPaths)));
65
- options.loadPaths = undefined;
66
- }
67
- let relativeImporter;
68
- if (rebase) {
69
- relativeImporter = (0, rebasing_importer_1.sassBindWorkaround)(new rebasing_importer_1.RelativeUrlRebasingImporter(entryDirectory, directoryCache, rebaseSourceMaps));
70
- }
71
- // The synchronous Sass render function can be up to two times faster than the async variant
72
- const result = (0, sass_1.compileString)(source, {
73
- ...options,
74
- // URL is not serializable so to convert to string in the parent and back to URL here.
75
- url: (0, node_url_1.pathToFileURL)(options.url),
76
- // The `importer` option (singular) handles relative imports
77
- importer: relativeImporter,
78
- logger: hasLogger
79
- ? {
80
- warn(message, warnOptions) {
81
- warnings ??= [];
82
- warnings.push({
83
- ...warnOptions,
84
- message,
85
- span: warnOptions.span && convertSourceSpan(warnOptions.span),
86
- ...convertDeprecation(warnOptions.deprecation,
87
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
88
- warnOptions.deprecationType),
89
- });
90
- },
91
- }
92
- : undefined,
93
- });
94
- if (result.sourceMap && rebaseSourceMaps?.size) {
95
- // Merge the intermediate rebasing source maps into the final Sass generated source map.
96
- // Casting is required due to small but compatible differences in typings between the packages.
97
- result.sourceMap = (0, remapping_1.default)(result.sourceMap,
98
- // To prevent an infinite lookup loop, skip getting the source when the rebasing source map
99
- // is referencing its original self.
100
- (file, context) => (file !== context.importer ? rebaseSourceMaps.get(file) : null));
101
- }
102
- node_worker_threads_1.parentPort.postMessage({
103
- id,
104
- warnings,
105
- result: {
106
- ...result,
107
- // URL is not serializable so to convert to string here and back to URL in the parent.
108
- loadedUrls: result.loadedUrls.map((p) => (0, node_url_1.fileURLToPath)(p)),
109
- },
110
- });
111
- }
112
- catch (error) {
113
- // Needed because V8 will only serialize the message and stack properties of an Error instance.
114
- if (error instanceof sass_1.Exception) {
115
- const { span, message, stack, sassMessage, sassStack } = error;
116
- node_worker_threads_1.parentPort.postMessage({
117
- id,
118
- warnings,
119
- error: {
120
- span: convertSourceSpan(span),
121
- message,
122
- stack,
123
- sassMessage,
124
- sassStack,
125
- },
126
- });
127
- }
128
- else if (error instanceof Error) {
129
- const { message, stack } = error;
130
- node_worker_threads_1.parentPort.postMessage({ id, warnings, error: { message, stack } });
131
- }
132
- else {
133
- node_worker_threads_1.parentPort.postMessage({
134
- id,
135
- warnings,
136
- error: { message: 'An unknown error has occurred.' },
137
- });
138
- }
139
- }
140
- });
141
- /**
142
- * Converts a Sass SourceSpan object into a serializable form.
143
- * The SourceSpan object contains a URL property which must be converted into a string.
144
- * Also, most of the interface's properties are get accessors and are not automatically
145
- * serialized when sent back from the worker.
146
- *
147
- * @param span The Sass SourceSpan object to convert.
148
- * @returns A serializable form of the SourceSpan object.
149
- */
150
- function convertSourceSpan(span) {
151
- return {
152
- text: span.text,
153
- context: span.context,
154
- end: {
155
- column: span.end.column,
156
- offset: span.end.offset,
157
- line: span.end.line,
158
- },
159
- start: {
160
- column: span.start.column,
161
- offset: span.start.offset,
162
- line: span.start.line,
163
- },
164
- url: span.url ? (0, node_url_1.fileURLToPath)(span.url) : undefined,
165
- };
166
- }
167
- function convertDeprecation(deprecation, deprecationType) {
168
- if (!deprecation || !deprecationType) {
169
- return { deprecation: false };
170
- }
171
- const { obsoleteIn, deprecatedIn, ...rest } = deprecationType;
172
- return {
173
- deprecation: true,
174
- deprecationType: {
175
- ...rest,
176
- obsoleteIn: obsoleteIn
177
- ? {
178
- major: obsoleteIn.major,
179
- minor: obsoleteIn.minor,
180
- patch: obsoleteIn.patch,
181
- }
182
- : null,
183
- deprecatedIn: deprecatedIn
184
- ? {
185
- major: deprecatedIn.major,
186
- minor: deprecatedIn.minor,
187
- patch: deprecatedIn.patch,
188
- }
189
- : null,
190
- },
191
- };
192
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright Google LLC All Rights Reserved.
4
- *
5
- * Use of this source code is governed by an MIT-style license that can be
6
- * found in the LICENSE file at https://angular.io/license
7
- */
8
- import type { Connect, Plugin } from 'vite';
9
- export interface AngularMemoryPluginOptions {
10
- workspaceRoot: string;
11
- virtualProjectRoot: string;
12
- outputFiles: Map<string, {
13
- contents: Uint8Array;
14
- servable: boolean;
15
- }>;
16
- assets: Map<string, string>;
17
- ssr: boolean;
18
- external?: string[];
19
- extensionMiddleware?: Connect.NextHandleFunction[];
20
- extraHeaders?: Record<string, string>;
21
- indexHtmlTransformer?: (content: string) => Promise<string>;
22
- normalizePath: (path: string) => string;
23
- }
24
- export declare function createAngularMemoryPlugin(options: AngularMemoryPluginOptions): Plugin;