@angular-devkit/build-angular 14.2.8 → 14.2.10

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.
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@angular-devkit/build-angular",
3
- "version": "14.2.8",
3
+ "version": "14.2.10",
4
4
  "description": "Angular Webpack Build Facade",
5
5
  "main": "src/index.js",
6
6
  "typings": "src/index.d.ts",
7
7
  "builders": "builders.json",
8
8
  "dependencies": {
9
9
  "@ampproject/remapping": "2.2.0",
10
- "@angular-devkit/architect": "0.1402.8",
11
- "@angular-devkit/build-webpack": "0.1402.8",
12
- "@angular-devkit/core": "14.2.8",
10
+ "@angular-devkit/architect": "0.1402.10",
11
+ "@angular-devkit/build-webpack": "0.1402.10",
12
+ "@angular-devkit/core": "14.2.10",
13
13
  "@babel/core": "7.18.10",
14
14
  "@babel/generator": "7.18.12",
15
15
  "@babel/helper-annotate-as-pure": "7.18.6",
@@ -20,7 +20,7 @@
20
20
  "@babel/runtime": "7.18.9",
21
21
  "@babel/template": "7.18.10",
22
22
  "@discoveryjs/json-ext": "0.5.7",
23
- "@ngtools/webpack": "14.2.8",
23
+ "@ngtools/webpack": "14.2.10",
24
24
  "ansi-colors": "4.1.3",
25
25
  "babel-loader": "8.2.5",
26
26
  "babel-plugin-istanbul": "6.1.1",
@@ -38,7 +38,7 @@
38
38
  "less": "4.1.3",
39
39
  "less-loader": "11.0.0",
40
40
  "license-webpack-plugin": "4.0.2",
41
- "loader-utils": "3.2.0",
41
+ "loader-utils": "3.2.1",
42
42
  "mini-css-extract-plugin": "2.6.1",
43
43
  "minimatch": "5.1.0",
44
44
  "open": "8.4.0",
@@ -29,10 +29,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
29
29
  __setModuleDefault(result, mod);
30
30
  return result;
31
31
  };
32
+ var __importDefault = (this && this.__importDefault) || function (mod) {
33
+ return (mod && mod.__esModule) ? mod : { "default": mod };
34
+ };
32
35
  Object.defineProperty(exports, "__esModule", { value: true });
33
36
  const architect_1 = require("@angular-devkit/architect");
34
37
  const fs = __importStar(require("fs"));
35
38
  const path = __importStar(require("path"));
39
+ const piscina_1 = __importDefault(require("piscina"));
36
40
  const utils_1 = require("../../utils");
37
41
  const error_1 = require("../../utils/error");
38
42
  const inline_critical_css_1 = require("../../utils/index-file/inline-critical-css");
@@ -45,10 +49,9 @@ async function _renderUniversal(options, context, browserResult, serverResult, s
45
49
  const rawBrowserOptions = (await context.getTargetOptions(browserTarget));
46
50
  const browserBuilderName = await context.getBuilderNameForTarget(browserTarget);
47
51
  const browserOptions = await context.validateOptions(rawBrowserOptions, browserBuilderName);
48
- // Initialize zone.js
52
+ // Locate zone.js to load in the render worker
49
53
  const root = context.workspaceRoot;
50
54
  const zonePackage = require.resolve('zone.js', { paths: [root] });
51
- await Promise.resolve().then(() => __importStar(require(zonePackage)));
52
55
  const projectName = context.target && context.target.project;
53
56
  if (!projectName) {
54
57
  throw new Error('The builder requires a target.');
@@ -62,42 +65,46 @@ async function _renderUniversal(options, context, browserResult, serverResult, s
62
65
  deployUrl: browserOptions.deployUrl,
63
66
  })
64
67
  : undefined;
65
- for (const { path: outputPath, baseHref } of browserResult.outputs) {
66
- const localeDirectory = path.relative(browserResult.baseOutputPath, outputPath);
67
- const browserIndexOutputPath = path.join(outputPath, 'index.html');
68
- const indexHtml = await fs.promises.readFile(browserIndexOutputPath, 'utf8');
69
- const serverBundlePath = await _getServerModuleBundlePath(options, context, serverResult, localeDirectory);
70
- const { AppServerModule, renderModule } = await Promise.resolve().then(() => __importStar(require(serverBundlePath)));
71
- const renderModuleFn = renderModule;
72
- if (!(renderModuleFn && AppServerModule)) {
73
- throw new Error(`renderModule method and/or AppServerModule were not exported from: ${serverBundlePath}.`);
74
- }
75
- // Load platform server module renderer
76
- const renderOpts = {
77
- document: indexHtml,
78
- url: options.route,
79
- };
80
- let html = await renderModuleFn(AppServerModule, renderOpts);
81
- // Overwrite the client index file.
82
- const outputIndexPath = options.outputIndexPath
83
- ? path.join(root, options.outputIndexPath)
84
- : browserIndexOutputPath;
85
- if (inlineCriticalCssProcessor) {
86
- const { content, warnings, errors } = await inlineCriticalCssProcessor.process(html, {
87
- outputPath,
68
+ const renderWorker = new piscina_1.default({
69
+ filename: require.resolve('./render-worker'),
70
+ maxThreads: 1,
71
+ workerData: { zonePackage },
72
+ });
73
+ try {
74
+ for (const { path: outputPath, baseHref } of browserResult.outputs) {
75
+ const localeDirectory = path.relative(browserResult.baseOutputPath, outputPath);
76
+ const browserIndexOutputPath = path.join(outputPath, 'index.html');
77
+ const indexHtml = await fs.promises.readFile(browserIndexOutputPath, 'utf8');
78
+ const serverBundlePath = await _getServerModuleBundlePath(options, context, serverResult, localeDirectory);
79
+ let html = await renderWorker.run({
80
+ serverBundlePath,
81
+ document: indexHtml,
82
+ url: options.route,
88
83
  });
89
- html = content;
90
- if (warnings.length || errors.length) {
91
- spinner.stop();
92
- warnings.forEach((m) => context.logger.warn(m));
93
- errors.forEach((m) => context.logger.error(m));
94
- spinner.start();
84
+ // Overwrite the client index file.
85
+ const outputIndexPath = options.outputIndexPath
86
+ ? path.join(root, options.outputIndexPath)
87
+ : browserIndexOutputPath;
88
+ if (inlineCriticalCssProcessor) {
89
+ const { content, warnings, errors } = await inlineCriticalCssProcessor.process(html, {
90
+ outputPath,
91
+ });
92
+ html = content;
93
+ if (warnings.length || errors.length) {
94
+ spinner.stop();
95
+ warnings.forEach((m) => context.logger.warn(m));
96
+ errors.forEach((m) => context.logger.error(m));
97
+ spinner.start();
98
+ }
99
+ }
100
+ await fs.promises.writeFile(outputIndexPath, html);
101
+ if (browserOptions.serviceWorker) {
102
+ await (0, service_worker_1.augmentAppWithServiceWorker)(projectRoot, root, outputPath, baseHref !== null && baseHref !== void 0 ? baseHref : '/', browserOptions.ngswConfigPath);
95
103
  }
96
104
  }
97
- await fs.promises.writeFile(outputIndexPath, html);
98
- if (browserOptions.serviceWorker) {
99
- await (0, service_worker_1.augmentAppWithServiceWorker)(projectRoot, root, outputPath, baseHref !== null && baseHref !== void 0 ? baseHref : '/', browserOptions.ngswConfigPath);
100
- }
105
+ }
106
+ finally {
107
+ await renderWorker.destroy();
101
108
  }
102
109
  return browserResult;
103
110
  }
@@ -0,0 +1,36 @@
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
+ /**
9
+ * A request to render a Server bundle generate by the universal server builder.
10
+ */
11
+ interface RenderRequest {
12
+ /**
13
+ * The path to the server bundle that should be loaded and rendered.
14
+ */
15
+ serverBundlePath: string;
16
+ /**
17
+ * The existing HTML document as a string that will be augmented with the rendered application.
18
+ */
19
+ document: string;
20
+ /**
21
+ * An optional URL path that represents the Angular route that should be rendered.
22
+ */
23
+ url: string | undefined;
24
+ }
25
+ /**
26
+ * Renders an application based on a provided server bundle path, initial document, and optional URL route.
27
+ * @param param0 A request to render a server bundle.
28
+ * @returns A promise that resolves to the render HTML document for the application.
29
+ */
30
+ declare function render({ serverBundlePath, document, url }: RenderRequest): Promise<string>;
31
+ /**
32
+ * The default export will be the promise returned by the initialize function.
33
+ * This is awaited by piscina prior to using the Worker.
34
+ */
35
+ declare const _default: Promise<typeof render>;
36
+ export default _default;
@@ -0,0 +1,75 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ var __importDefault = (this && this.__importDefault) || function (mod) {
33
+ return (mod && mod.__esModule) ? mod : { "default": mod };
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const assert_1 = __importDefault(require("assert"));
37
+ const worker_threads_1 = require("worker_threads");
38
+ /**
39
+ * The fully resolved path to the zone.js package that will be loaded during worker initialization.
40
+ * This is passed as workerData when setting up the worker via the `piscina` package.
41
+ */
42
+ const { zonePackage } = worker_threads_1.workerData;
43
+ /**
44
+ * Renders an application based on a provided server bundle path, initial document, and optional URL route.
45
+ * @param param0 A request to render a server bundle.
46
+ * @returns A promise that resolves to the render HTML document for the application.
47
+ */
48
+ async function render({ serverBundlePath, document, url }) {
49
+ const { AppServerModule, renderModule } = (await Promise.resolve().then(() => __importStar(require(serverBundlePath))));
50
+ (0, assert_1.default)(renderModule, `renderModule was not exported from: ${serverBundlePath}.`);
51
+ (0, assert_1.default)(AppServerModule, `AppServerModule was not exported from: ${serverBundlePath}.`);
52
+ // Render platform server module
53
+ const html = await renderModule(AppServerModule, {
54
+ document,
55
+ url,
56
+ });
57
+ return html;
58
+ }
59
+ /**
60
+ * Initializes the worker when it is first created by loading the Zone.js package
61
+ * into the worker instance.
62
+ *
63
+ * @returns A promise resolving to the render function of the worker.
64
+ */
65
+ async function initialize() {
66
+ // Setup Zone.js
67
+ await Promise.resolve().then(() => __importStar(require(zonePackage)));
68
+ // Return the render function for use
69
+ return render;
70
+ }
71
+ /**
72
+ * The default export will be the promise returned by the initialize function.
73
+ * This is awaited by piscina prior to using the Worker.
74
+ */
75
+ exports.default = initialize();