@angular-devkit/build-angular 17.3.2 → 18.0.0-next.1

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 (58) hide show
  1. package/package.json +33 -33
  2. package/src/builders/app-shell/index.js +1 -1
  3. package/src/builders/application/build-action.d.ts +2 -3
  4. package/src/builders/application/options.d.ts +3 -1
  5. package/src/builders/application/schema.d.ts +1 -1
  6. package/src/builders/application/schema.json +2 -1
  7. package/src/builders/browser/schema.d.ts +1 -1
  8. package/src/builders/browser/schema.json +2 -1
  9. package/src/builders/browser-esbuild/schema.d.ts +1 -1
  10. package/src/builders/browser-esbuild/schema.json +2 -1
  11. package/src/builders/dev-server/builder.d.ts +0 -2
  12. package/src/builders/dev-server/vite-server.js +14 -7
  13. package/src/builders/dev-server/webpack-server.js +1 -1
  14. package/src/builders/karma/schema.d.ts +1 -1
  15. package/src/builders/karma/schema.json +2 -1
  16. package/src/builders/prerender/index.d.ts +2 -3
  17. package/src/builders/server/schema.d.ts +1 -1
  18. package/src/builders/server/schema.json +2 -1
  19. package/src/builders/ssr-dev-server/utils.d.ts +1 -2
  20. package/src/builders/web-test-runner/schema.d.ts +1 -1
  21. package/src/builders/web-test-runner/schema.json +2 -1
  22. package/src/tools/babel/plugins/adjust-static-class-members.js +3 -6
  23. package/src/tools/babel/plugins/index.d.ts +11 -0
  24. package/src/tools/babel/plugins/index.js +21 -0
  25. package/src/tools/babel/presets/application.js +4 -3
  26. package/src/tools/esbuild/angular/compilation/parallel-worker.d.ts +0 -2
  27. package/src/tools/esbuild/javascript-transformer-worker.js +82 -26
  28. package/src/tools/esbuild/utils.d.ts +2 -2
  29. package/src/tools/esbuild/utils.js +1 -1
  30. package/src/tools/vite/angular-memory-plugin.js +5 -7
  31. package/src/tools/webpack/configs/dev-server.js +20 -11
  32. package/src/tools/webpack/configs/styles.js +22 -53
  33. package/src/tools/webpack/plugins/builder-watch-plugin.js +2 -2
  34. package/src/tools/webpack/plugins/styles-webpack-plugin.js +1 -1
  35. package/src/tools/webpack/utils/helpers.js +1 -1
  36. package/src/utils/environment-options.d.ts +0 -1
  37. package/src/utils/environment-options.js +1 -11
  38. package/src/utils/i18n-options.d.ts +3 -2
  39. package/src/utils/i18n-options.js +39 -33
  40. package/src/utils/index-file/inline-fonts.d.ts +0 -4
  41. package/src/utils/index-file/inline-fonts.js +3 -5
  42. package/src/utils/normalize-asset-patterns.d.ts +4 -3
  43. package/src/utils/normalize-asset-patterns.js +7 -3
  44. package/src/utils/normalize-cache.d.ts +1 -2
  45. package/src/utils/normalize-cache.js +15 -9
  46. package/src/utils/normalize-file-replacements.d.ts +1 -2
  47. package/src/utils/normalize-file-replacements.js +1 -2
  48. package/src/utils/server-rendering/esm-in-memory-loader/loader-hooks.js +0 -2
  49. package/src/utils/server-rendering/prerender.js +11 -3
  50. package/src/utils/service-worker.d.ts +2 -2
  51. package/src/utils/supported-browsers.d.ts +3 -2
  52. package/src/utils/webpack-browser-config.d.ts +1 -2
  53. package/src/tools/sass/sass-service-legacy.d.ts +0 -51
  54. package/src/tools/sass/sass-service-legacy.js +0 -173
  55. package/src/tools/sass/worker-legacy.d.ts +0 -8
  56. package/src/tools/sass/worker-legacy.js +0 -43
  57. package/src/utils/server-rendering/esm-in-memory-loader/node-18-utils.d.ts +0 -10
  58. package/src/utils/server-rendering/esm-in-memory-loader/node-18-utils.js +0 -39
@@ -13,9 +13,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.prerenderPages = void 0;
14
14
  const promises_1 = require("node:fs/promises");
15
15
  const node_path_1 = require("node:path");
16
+ const node_url_1 = require("node:url");
16
17
  const piscina_1 = __importDefault(require("piscina"));
17
18
  const bundler_context_1 = require("../../tools/esbuild/bundler-context");
18
- const node_18_utils_1 = require("./esm-in-memory-loader/node-18-utils");
19
19
  async function prerenderPages(workspaceRoot, appShellOptions = {}, prerenderOptions = {}, outputFiles, assets, document, sourcemap = false, inlineCriticalCss = false, maxThreads = 1, verbose = false) {
20
20
  const outputFilesForWorker = {};
21
21
  const serverBundlesSourceMaps = new Map();
@@ -82,7 +82,11 @@ async function renderPages(sourcemap, allRoutes, maxThreads, workspaceRoot, outp
82
82
  const output = {};
83
83
  const warnings = [];
84
84
  const errors = [];
85
- const workerExecArgv = (0, node_18_utils_1.getESMLoaderArgs)();
85
+ const workerExecArgv = [
86
+ '--import',
87
+ // Loader cannot be an absolute path on Windows.
88
+ (0, node_url_1.pathToFileURL)((0, node_path_1.join)(__dirname, 'esm-in-memory-loader/register-hooks.js')).href,
89
+ ];
86
90
  if (sourcemap) {
87
91
  workerExecArgv.push('--enable-source-maps');
88
92
  }
@@ -149,7 +153,11 @@ async function getAllRoutes(workspaceRoot, outputFilesForWorker, assetFilesForWo
149
153
  if (!discoverRoutes) {
150
154
  return { routes };
151
155
  }
152
- const workerExecArgv = (0, node_18_utils_1.getESMLoaderArgs)();
156
+ const workerExecArgv = [
157
+ '--import',
158
+ // Loader cannot be an absolute path on Windows.
159
+ (0, node_url_1.pathToFileURL)((0, node_path_1.join)(__dirname, 'esm-in-memory-loader/register-hooks.js')).href,
160
+ ];
153
161
  if (sourcemap) {
154
162
  workerExecArgv.push('--enable-source-maps');
155
163
  }
@@ -5,8 +5,8 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- /// <reference types="@types/node/fs" />
9
- /// <reference types="@types/node/ts4.8/fs" />
8
+ /// <reference types="node" />
9
+ /// <reference types="node" />
10
10
  import type { Config, Filesystem } from '@angular/service-worker/config';
11
11
  import { promises as fsPromises } from 'node:fs';
12
12
  import { BuildOutputFile } from '../tools/esbuild/bundler-context';
@@ -5,5 +5,6 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
- import { logging } from '@angular-devkit/core';
9
- export declare function getSupportedBrowsers(projectRoot: string, logger: logging.LoggerApi): string[];
8
+ export declare function getSupportedBrowsers(projectRoot: string, logger: {
9
+ warn(message: string): void;
10
+ }): string[];
@@ -6,7 +6,6 @@
6
6
  * found in the LICENSE file at https://angular.io/license
7
7
  */
8
8
  import { BuilderContext } from '@angular-devkit/architect';
9
- import { logging } from '@angular-devkit/core';
10
9
  import { Configuration } from 'webpack';
11
10
  import { Schema as BrowserBuilderSchema } from '../builders/browser/schema';
12
11
  import { NormalizedBrowserBuilderSchema } from '../utils';
@@ -14,7 +13,7 @@ import { WebpackConfigOptions } from '../utils/build-options';
14
13
  import { I18nOptions } from './i18n-options';
15
14
  export type BrowserWebpackConfigOptions = WebpackConfigOptions<NormalizedBrowserBuilderSchema>;
16
15
  export type WebpackPartialGenerator = (configurationOptions: BrowserWebpackConfigOptions) => (Promise<Configuration> | Configuration)[];
17
- export declare function generateWebpackConfig(workspaceRoot: string, projectRoot: string, sourceRoot: string | undefined, projectName: string, options: NormalizedBrowserBuilderSchema, webpackPartialGenerator: WebpackPartialGenerator, logger: logging.LoggerApi, extraBuildOptions: Partial<NormalizedBrowserBuilderSchema>): Promise<Configuration>;
16
+ export declare function generateWebpackConfig(workspaceRoot: string, projectRoot: string, sourceRoot: string | undefined, projectName: string, options: NormalizedBrowserBuilderSchema, webpackPartialGenerator: WebpackPartialGenerator, logger: BuilderContext['logger'], extraBuildOptions: Partial<NormalizedBrowserBuilderSchema>): Promise<Configuration>;
18
17
  export declare function generateI18nBrowserWebpackConfigFromContext(options: BrowserBuilderSchema, context: BuilderContext, webpackPartialGenerator: WebpackPartialGenerator, extraBuildOptions?: Partial<NormalizedBrowserBuilderSchema>): Promise<{
19
18
  config: Configuration;
20
19
  projectRoot: string;
@@ -1,51 +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 { LegacyResult as CompileResult, LegacyException as Exception, LegacyOptions as Options } from 'sass';
9
- /**
10
- * The callback type for the `dart-sass` asynchronous render function.
11
- */
12
- type RenderCallback = (error?: Exception, result?: CompileResult) => void;
13
- /**
14
- * A Sass renderer implementation that provides an interface that can be used by Webpack's
15
- * `sass-loader`. The implementation uses a Worker thread to perform the Sass rendering
16
- * with the `dart-sass` package. The `dart-sass` synchronous render function is used within
17
- * the worker which can be up to two times faster than the asynchronous variant.
18
- */
19
- export declare class SassLegacyWorkerImplementation {
20
- private readonly workers;
21
- private readonly availableWorkers;
22
- private readonly requests;
23
- private readonly workerPath;
24
- private idCounter;
25
- private nextWorkerIndex;
26
- /**
27
- * Provides information about the Sass implementation.
28
- * This mimics enough of the `dart-sass` value to be used with the `sass-loader`.
29
- */
30
- get info(): string;
31
- /**
32
- * The synchronous render function is not used by the `sass-loader`.
33
- */
34
- renderSync(): never;
35
- /**
36
- * Asynchronously request a Sass stylesheet to be renderered.
37
- *
38
- * @param options The `dart-sass` options to use when rendering the stylesheet.
39
- * @param callback The function to execute when the rendering is complete.
40
- */
41
- render(options: Options<'async'>, callback: RenderCallback): void;
42
- /**
43
- * Shutdown the Sass render worker.
44
- * Executing this method will stop any pending render requests.
45
- */
46
- close(): void;
47
- private createWorker;
48
- private processImporters;
49
- private createRequest;
50
- }
51
- export {};
@@ -1,173 +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.SassLegacyWorkerImplementation = void 0;
11
- const path_1 = require("path");
12
- const worker_threads_1 = require("worker_threads");
13
- const environment_options_1 = require("../../utils/environment-options");
14
- /**
15
- * The maximum number of Workers that will be created to execute render requests.
16
- */
17
- const MAX_RENDER_WORKERS = environment_options_1.maxWorkers;
18
- /**
19
- * A Sass renderer implementation that provides an interface that can be used by Webpack's
20
- * `sass-loader`. The implementation uses a Worker thread to perform the Sass rendering
21
- * with the `dart-sass` package. The `dart-sass` synchronous render function is used within
22
- * the worker which can be up to two times faster than the asynchronous variant.
23
- */
24
- class SassLegacyWorkerImplementation {
25
- workers = [];
26
- availableWorkers = [];
27
- requests = new Map();
28
- workerPath = (0, path_1.join)(__dirname, './worker-legacy.js');
29
- idCounter = 1;
30
- nextWorkerIndex = 0;
31
- /**
32
- * Provides information about the Sass implementation.
33
- * This mimics enough of the `dart-sass` value to be used with the `sass-loader`.
34
- */
35
- get info() {
36
- return 'dart-sass\tworker';
37
- }
38
- /**
39
- * The synchronous render function is not used by the `sass-loader`.
40
- */
41
- renderSync() {
42
- throw new Error('Sass renderSync is not supported.');
43
- }
44
- /**
45
- * Asynchronously request a Sass stylesheet to be renderered.
46
- *
47
- * @param options The `dart-sass` options to use when rendering the stylesheet.
48
- * @param callback The function to execute when the rendering is complete.
49
- */
50
- render(options, callback) {
51
- // The `functions`, `logger` and `importer` options are JavaScript functions that cannot be transferred.
52
- // If any additional function options are added in the future, they must be excluded as well.
53
- const { functions, importer, logger, ...serializableOptions } = options;
54
- // The CLI's configuration does not use or expose the ability to defined custom Sass functions
55
- if (functions && Object.keys(functions).length > 0) {
56
- throw new Error('Sass custom functions are not supported.');
57
- }
58
- let workerIndex = this.availableWorkers.pop();
59
- if (workerIndex === undefined) {
60
- if (this.workers.length < MAX_RENDER_WORKERS) {
61
- workerIndex = this.workers.length;
62
- this.workers.push(this.createWorker());
63
- }
64
- else {
65
- workerIndex = this.nextWorkerIndex++;
66
- if (this.nextWorkerIndex >= this.workers.length) {
67
- this.nextWorkerIndex = 0;
68
- }
69
- }
70
- }
71
- const request = this.createRequest(workerIndex, callback, importer);
72
- this.requests.set(request.id, request);
73
- this.workers[workerIndex].postMessage({
74
- id: request.id,
75
- hasImporter: !!importer,
76
- options: serializableOptions,
77
- });
78
- }
79
- /**
80
- * Shutdown the Sass render worker.
81
- * Executing this method will stop any pending render requests.
82
- */
83
- close() {
84
- for (const worker of this.workers) {
85
- try {
86
- void worker.terminate();
87
- }
88
- catch { }
89
- }
90
- this.requests.clear();
91
- }
92
- createWorker() {
93
- const { port1: mainImporterPort, port2: workerImporterPort } = new worker_threads_1.MessageChannel();
94
- const importerSignal = new Int32Array(new SharedArrayBuffer(4));
95
- const worker = new worker_threads_1.Worker(this.workerPath, {
96
- workerData: { workerImporterPort, importerSignal },
97
- transferList: [workerImporterPort],
98
- });
99
- worker.on('message', (response) => {
100
- const request = this.requests.get(response.id);
101
- if (!request) {
102
- return;
103
- }
104
- this.requests.delete(response.id);
105
- this.availableWorkers.push(request.workerIndex);
106
- if (response.result) {
107
- // The results are expected to be Node.js `Buffer` objects but will each be transferred as
108
- // a Uint8Array that does not have the expected `toString` behavior of a `Buffer`.
109
- const { css, map, stats } = response.result;
110
- const result = {
111
- // This `Buffer.from` override will use the memory directly and avoid making a copy
112
- css: Buffer.from(css.buffer, css.byteOffset, css.byteLength),
113
- stats,
114
- };
115
- if (map) {
116
- // This `Buffer.from` override will use the memory directly and avoid making a copy
117
- result.map = Buffer.from(map.buffer, map.byteOffset, map.byteLength);
118
- }
119
- request.callback(undefined, result);
120
- }
121
- else {
122
- request.callback(response.error);
123
- }
124
- });
125
- mainImporterPort.on('message', ({ id, url, prev, fromImport, }) => {
126
- const request = this.requests.get(id);
127
- if (!request?.importers) {
128
- mainImporterPort.postMessage(null);
129
- Atomics.store(importerSignal, 0, 1);
130
- Atomics.notify(importerSignal, 0);
131
- return;
132
- }
133
- this.processImporters(request.importers, url, prev, fromImport)
134
- .then((result) => {
135
- mainImporterPort.postMessage(result);
136
- })
137
- .catch((error) => {
138
- mainImporterPort.postMessage(error);
139
- })
140
- .finally(() => {
141
- Atomics.store(importerSignal, 0, 1);
142
- Atomics.notify(importerSignal, 0);
143
- });
144
- });
145
- mainImporterPort.unref();
146
- return worker;
147
- }
148
- async processImporters(importers, url, prev, fromImport) {
149
- let result = null;
150
- for (const importer of importers) {
151
- result = await new Promise((resolve) => {
152
- // Importers can be both sync and async
153
- const innerResult = importer.call({ fromImport }, url, prev, resolve);
154
- if (innerResult !== undefined) {
155
- resolve(innerResult);
156
- }
157
- });
158
- if (result) {
159
- break;
160
- }
161
- }
162
- return result;
163
- }
164
- createRequest(workerIndex, callback, importer) {
165
- return {
166
- id: this.idCounter++,
167
- workerIndex,
168
- callback,
169
- importers: !importer || Array.isArray(importer) ? importer : [importer],
170
- };
171
- }
172
- }
173
- exports.SassLegacyWorkerImplementation = SassLegacyWorkerImplementation;
@@ -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,43 +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
- const sass_1 = require("sass");
11
- const worker_threads_1 = require("worker_threads");
12
- if (!worker_threads_1.parentPort || !worker_threads_1.workerData) {
13
- throw new Error('Sass worker must be executed as a Worker.');
14
- }
15
- // The importer variables are used to proxy import requests to the main thread
16
- const { workerImporterPort, importerSignal } = worker_threads_1.workerData;
17
- worker_threads_1.parentPort.on('message', ({ id, hasImporter, options }) => {
18
- try {
19
- if (hasImporter) {
20
- // When a custom importer function is present, the importer request must be proxied
21
- // back to the main thread where it can be executed.
22
- // This process must be synchronous from the perspective of dart-sass. The `Atomics`
23
- // functions combined with the shared memory `importSignal` and the Node.js
24
- // `receiveMessageOnPort` function are used to ensure synchronous behavior.
25
- options.importer = function (url, prev) {
26
- Atomics.store(importerSignal, 0, 0);
27
- const { fromImport } = this;
28
- workerImporterPort.postMessage({ id, url, prev, fromImport });
29
- Atomics.wait(importerSignal, 0, 0);
30
- return (0, worker_threads_1.receiveMessageOnPort)(workerImporterPort)?.message;
31
- };
32
- }
33
- // The synchronous Sass render function can be up to two times faster than the async variant
34
- const result = (0, sass_1.renderSync)(options);
35
- worker_threads_1.parentPort?.postMessage({ id, result });
36
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- }
38
- catch (error) {
39
- // Needed because V8 will only serialize the message and stack properties of an Error instance.
40
- const { formatted, file, line, column, message, stack } = error;
41
- worker_threads_1.parentPort?.postMessage({ id, error: { formatted, file, line, column, message, stack } });
42
- }
43
- });
@@ -1,10 +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
- /** Call the initialize hook when running on Node.js 18 */
9
- export declare function callInitializeIfNeeded(initialize: (typeof import('./loader-hooks'))['initialize']): void;
10
- export declare function getESMLoaderArgs(): string[];
@@ -1,39 +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.getESMLoaderArgs = exports.callInitializeIfNeeded = 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 semver_1 = require("semver");
15
- let SUPPORTS_IMPORT_FLAG;
16
- function supportsImportFlag() {
17
- return (SUPPORTS_IMPORT_FLAG ??= (0, semver_1.satisfies)(process.versions.node, '>= 18.19'));
18
- }
19
- /** Call the initialize hook when running on Node.js 18 */
20
- function callInitializeIfNeeded(initialize) {
21
- if (!supportsImportFlag()) {
22
- initialize(node_worker_threads_1.workerData);
23
- }
24
- }
25
- exports.callInitializeIfNeeded = callInitializeIfNeeded;
26
- function getESMLoaderArgs() {
27
- if (!supportsImportFlag()) {
28
- return [
29
- '--no-warnings', // Suppress `ExperimentalWarning: Custom ESM Loaders is an experimental feature...`.
30
- '--loader',
31
- (0, node_url_1.pathToFileURL)((0, node_path_1.join)(__dirname, 'loader-hooks.js')).href, // Loader cannot be an absolute path on Windows.
32
- ];
33
- }
34
- return [
35
- '--import',
36
- (0, node_url_1.pathToFileURL)((0, node_path_1.join)(__dirname, 'register-hooks.js')).href, // Loader cannot be an absolute path on Windows.
37
- ];
38
- }
39
- exports.getESMLoaderArgs = getESMLoaderArgs;