@angular-devkit/build-angular 12.2.0-next.0 → 12.2.0

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 (40) hide show
  1. package/package.json +33 -32
  2. package/src/app-shell/index.js +3 -5
  3. package/src/babel/plugins/adjust-static-class-members.js +22 -1
  4. package/src/babel/presets/application.d.ts +0 -1
  5. package/src/babel/presets/application.js +3 -2
  6. package/src/babel/webpack-loader.js +0 -9
  7. package/src/browser/index.js +13 -3
  8. package/src/browser/schema.d.ts +1 -1
  9. package/src/browser/schema.json +1 -1
  10. package/src/dev-server/index.js +2 -2
  11. package/src/extract-i18n/index.js +1 -1
  12. package/src/extract-i18n/ivy-extract-loader.d.ts +6 -1
  13. package/src/extract-i18n/ivy-extract-loader.js +8 -12
  14. package/src/karma/index.js +1 -1
  15. package/src/server/index.js +1 -1
  16. package/src/server/tests/setup.d.ts +18 -0
  17. package/src/server/tests/setup.js +27 -0
  18. package/src/utils/action-executor.d.ts +3 -8
  19. package/src/utils/action-executor.js +19 -73
  20. package/src/utils/delete-output-dir.js +28 -2
  21. package/src/utils/index-file/inline-fonts.d.ts +3 -1
  22. package/src/utils/index-file/inline-fonts.js +112 -55
  23. package/src/utils/process-bundle.d.ts +0 -5
  24. package/src/utils/process-bundle.js +50 -140
  25. package/src/utils/version.d.ts +1 -2
  26. package/src/utils/version.js +5 -4
  27. package/src/webpack/configs/browser.js +0 -16
  28. package/src/webpack/configs/common.js +56 -67
  29. package/src/webpack/configs/server.js +0 -1
  30. package/src/webpack/configs/styles.js +92 -75
  31. package/src/webpack/plugins/builder-watch-plugin.d.ts +1 -26
  32. package/src/webpack/plugins/hmr/hmr-accept.js +1 -0
  33. package/src/webpack/plugins/javascript-optimizer-plugin.d.ts +59 -0
  34. package/src/webpack/plugins/javascript-optimizer-plugin.js +150 -0
  35. package/src/webpack/plugins/javascript-optimizer-worker.d.ts +37 -0
  36. package/src/webpack/plugins/javascript-optimizer-worker.js +74 -0
  37. package/src/webpack/plugins/postcss-cli-resources.d.ts +1 -1
  38. package/src/webpack/plugins/postcss-cli-resources.js +2 -1
  39. package/src/webpack/plugins/single-test-transform.d.ts +1 -1
  40. package/src/webpack/plugins/single-test-transform.js +1 -2
package/package.json CHANGED
@@ -1,84 +1,85 @@
1
1
  {
2
2
  "name": "@angular-devkit/build-angular",
3
- "version": "12.2.0-next.0",
3
+ "version": "12.2.0",
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
- "@angular-devkit/architect": "0.1202.0-next.0",
10
- "@angular-devkit/build-optimizer": "0.1202.0-next.0",
11
- "@angular-devkit/build-webpack": "0.1202.0-next.0",
12
- "@angular-devkit/core": "12.2.0-next.0",
13
- "@babel/core": "7.14.6",
14
- "@babel/generator": "7.14.5",
9
+ "@ampproject/remapping": "1.0.1",
10
+ "@angular-devkit/architect": "0.1202.0",
11
+ "@angular-devkit/build-optimizer": "0.1202.0",
12
+ "@angular-devkit/build-webpack": "0.1202.0",
13
+ "@angular-devkit/core": "12.2.0",
14
+ "@babel/core": "7.14.8",
15
+ "@babel/generator": "7.14.8",
15
16
  "@babel/helper-annotate-as-pure": "7.14.5",
17
+ "@babel/plugin-proposal-async-generator-functions": "7.14.7",
16
18
  "@babel/plugin-transform-async-to-generator": "7.14.5",
17
19
  "@babel/plugin-transform-runtime": "7.14.5",
18
- "@babel/preset-env": "7.14.7",
19
- "@babel/runtime": "7.14.6",
20
+ "@babel/preset-env": "7.14.8",
21
+ "@babel/runtime": "7.14.8",
20
22
  "@babel/template": "7.14.5",
21
23
  "@discoveryjs/json-ext": "0.5.3",
22
24
  "@jsdevtools/coverage-istanbul-loader": "3.0.5",
23
- "@ngtools/webpack": "12.2.0-next.0",
25
+ "@ngtools/webpack": "12.2.0",
24
26
  "ansi-colors": "4.1.1",
25
27
  "babel-loader": "8.2.2",
26
28
  "browserslist": "^4.9.1",
27
29
  "cacache": "15.2.0",
28
30
  "caniuse-lite": "^1.0.30001032",
29
31
  "circular-dependency-plugin": "5.2.2",
30
- "copy-webpack-plugin": "9.0.0",
31
- "core-js": "3.15.1",
32
+ "copy-webpack-plugin": "9.0.1",
33
+ "core-js": "3.16.0",
32
34
  "critters": "0.0.10",
33
- "css-loader": "5.2.6",
34
- "css-minimizer-webpack-plugin": "3.0.1",
35
+ "css-loader": "6.2.0",
36
+ "css-minimizer-webpack-plugin": "3.0.2",
37
+ "esbuild": "0.12.17",
35
38
  "find-cache-dir": "3.3.1",
36
39
  "glob": "7.1.7",
37
40
  "https-proxy-agent": "5.0.0",
38
- "inquirer": "8.1.1",
39
- "jest-worker": "27.0.2",
41
+ "inquirer": "8.1.2",
40
42
  "karma-source-map-support": "1.4.0",
41
43
  "less": "4.1.1",
42
- "less-loader": "10.0.0",
43
- "license-webpack-plugin": "2.3.19",
44
+ "less-loader": "10.0.1",
45
+ "license-webpack-plugin": "2.3.20",
44
46
  "loader-utils": "2.0.0",
45
- "mini-css-extract-plugin": "1.6.0",
47
+ "mini-css-extract-plugin": "2.1.0",
46
48
  "minimatch": "3.0.4",
47
49
  "open": "8.2.1",
48
50
  "ora": "5.4.1",
49
51
  "parse5-html-rewriting-stream": "6.0.1",
50
- "postcss": "8.3.5",
52
+ "piscina": "3.1.0",
53
+ "postcss": "8.3.6",
51
54
  "postcss-import": "14.0.2",
52
- "postcss-loader": "6.1.0",
55
+ "postcss-loader": "6.1.1",
53
56
  "postcss-preset-env": "6.7.0",
54
- "raw-loader": "4.0.2",
55
- "regenerator-runtime": "0.13.7",
57
+ "regenerator-runtime": "0.13.9",
56
58
  "resolve-url-loader": "4.0.0",
57
59
  "rxjs": "6.6.7",
58
- "sass": "1.35.1",
60
+ "sass": "1.36.0",
59
61
  "sass-loader": "12.1.0",
60
62
  "semver": "7.3.5",
61
- "source-map": "0.7.3",
62
63
  "source-map-loader": "3.0.0",
63
64
  "source-map-support": "0.5.19",
64
- "style-loader": "2.0.0",
65
+ "style-loader": "3.2.1",
65
66
  "stylus": "0.54.8",
66
67
  "stylus-loader": "6.1.0",
67
- "terser": "5.7.0",
68
- "terser-webpack-plugin": "5.1.3",
68
+ "terser": "5.7.1",
69
+ "terser-webpack-plugin": "5.1.4",
69
70
  "text-table": "0.2.0",
70
71
  "tree-kill": "1.2.2",
71
72
  "tslib": "2.3.0",
72
- "webpack": "5.40.0",
73
+ "webpack": "5.47.1",
73
74
  "webpack-dev-middleware": "5.0.0",
74
75
  "webpack-dev-server": "3.11.2",
75
76
  "webpack-merge": "5.8.0",
76
77
  "webpack-subresource-integrity": "1.5.2"
77
78
  },
78
79
  "peerDependencies": {
79
- "@angular/compiler-cli": "^12.0.0 || ^12.1.0-next",
80
- "@angular/localize": "^12.0.0 || ^12.1.0-next",
81
- "@angular/service-worker": "^12.0.0 || ^12.1.0-next",
80
+ "@angular/compiler-cli": "^12.0.0 || ^12.2.0-next",
81
+ "@angular/localize": "^12.0.0 || ^12.2.0-next",
82
+ "@angular/service-worker": "^12.0.0 || ^12.2.0-next",
82
83
  "karma": "^6.3.0",
83
84
  "ng-packagr": "^12.0.0 || ^12.1.0-next",
84
85
  "protractor": "^7.0.0",
@@ -130,10 +130,9 @@ async function _appShellBuilder(options, context) {
130
130
  });
131
131
  let spinner;
132
132
  try {
133
- // Using `.result` instead of `.output` causes Webpack FS cache not to be created.
134
133
  const [browserResult, serverResult] = await Promise.all([
135
- browserTargetRun.output.toPromise(),
136
- serverTargetRun.output.toPromise(),
134
+ browserTargetRun.result,
135
+ serverTargetRun.result,
137
136
  ]);
138
137
  if (browserResult.success === false || browserResult.baseOutputPath === undefined) {
139
138
  return browserResult;
@@ -152,8 +151,7 @@ async function _appShellBuilder(options, context) {
152
151
  return { success: false, error: err.message };
153
152
  }
154
153
  finally {
155
- // workaround for [tsetse] All Promises in async functions must either be awaited or used in an expression.
156
- const _ = Promise.all([browserTargetRun.stop(), serverTargetRun.stop()]);
154
+ await Promise.all([browserTargetRun.stop(), serverTargetRun.stop()]);
157
155
  }
158
156
  }
159
157
  exports.default = architect_1.createBuilder(_appShellBuilder);
@@ -57,6 +57,27 @@ function getKeywords() {
57
57
  return ['class'];
58
58
  }
59
59
  exports.getKeywords = getKeywords;
60
+ /**
61
+ * Determines whether a property and its initializer value can be safely wrapped in a pure
62
+ * annotated IIFE. Values that may cause side effects are not considered safe to wrap.
63
+ * Wrapping such values may cause runtime errors and/or incorrect runtime behavior.
64
+ *
65
+ * @param propertyName The name of the property to analyze.
66
+ * @param assignmentValue The initializer value that will be assigned to the property.
67
+ * @returns If the property can be safely wrapped, then true; otherwise, false.
68
+ */
69
+ function canWrapProperty(propertyName, assignmentValue) {
70
+ if (angularStaticsToWrap.has(propertyName)) {
71
+ return true;
72
+ }
73
+ const { leadingComments } = assignmentValue.node;
74
+ if (leadingComments === null || leadingComments === void 0 ? void 0 : leadingComments.some(
75
+ // `@pureOrBreakMyCode` is used by closure and is present in Angular code
76
+ ({ value }) => value.includes('#__PURE__') || value.includes('@pureOrBreakMyCode'))) {
77
+ return true;
78
+ }
79
+ return assignmentValue.isPure();
80
+ }
60
81
  /**
61
82
  * Analyze the sibling nodes of a class to determine if any downlevel elements should be
62
83
  * wrapped in a pure annotated IIFE. Also determines if any elements have potential side
@@ -130,7 +151,7 @@ function analyzeClassSiblings(origin, classIdentifier, allowWrappingDecorators)
130
151
  nextStatement.remove();
131
152
  --i;
132
153
  }
133
- else if (angularStaticsToWrap.has(propertyName) || assignmentValue.isPure()) {
154
+ else if (canWrapProperty(propertyName, assignmentValue)) {
134
155
  wrapStatementPaths.push(nextStatement);
135
156
  }
136
157
  else {
@@ -15,7 +15,6 @@ export interface ApplicationPresetOptions {
15
15
  angularLinker?: {
16
16
  shouldLink: boolean;
17
17
  jitMode: boolean;
18
- sourcemap: boolean;
19
18
  };
20
19
  forceES5?: boolean;
21
20
  forceAsyncTransformation?: boolean;
@@ -102,7 +102,8 @@ function default_1(api, options) {
102
102
  const { createEs2015LinkerPlugin } = require('@angular/compiler-cli/linker/babel');
103
103
  plugins.push(createEs2015LinkerPlugin({
104
104
  linkerJitMode: options.angularLinker.jitMode,
105
- sourceMapping: options.angularLinker.sourcemap,
105
+ // This is a workaround until https://github.com/angular/angular/issues/42769 is fixed.
106
+ sourceMapping: false,
106
107
  logger: createNgtscLogger(options.diagnosticReporter),
107
108
  fileSystem: {
108
109
  resolve: path.resolve,
@@ -135,7 +136,7 @@ function default_1(api, options) {
135
136
  }
136
137
  if (options.forceAsyncTransformation) {
137
138
  // Always transform async/await to support Zone.js
138
- plugins.push(require('@babel/plugin-transform-async-to-generator').default);
139
+ plugins.push(require('@babel/plugin-transform-async-to-generator').default, require('@babel/plugin-proposal-async-generator-functions').default);
139
140
  needRuntimeTransform = true;
140
141
  }
141
142
  if (needRuntimeTransform) {
@@ -43,7 +43,6 @@ exports.default = babel_loader_1.custom(() => {
43
43
  customOptions.angularLinker = {
44
44
  shouldLink: true,
45
45
  jitMode: aot !== true,
46
- sourcemap: false,
47
46
  };
48
47
  shouldProcess = true;
49
48
  }
@@ -113,14 +112,6 @@ exports.default = babel_loader_1.custom(() => {
113
112
  { wrapDecorators: customOptions.optimize.wrapDecorators },
114
113
  ]);
115
114
  }
116
- // Only enable linker template sourcemapping if linker is enabled and Webpack provides
117
- // a sourcemap. This logic allows the linker sourcemap behavior to be controlled by the
118
- // Webpack sourcemap configuration. For example, if a vendor file is being processed
119
- // and vendor sourcemaps are disabled, the `inputSourceMap` property will be `undefined`
120
- // which will effectively disable linker sourcemapping for vendor files.
121
- if (customOptions.angularLinker && configuration.options.inputSourceMap) {
122
- customOptions.angularLinker.sourcemap = true;
123
- }
124
115
  return {
125
116
  ...configuration.options,
126
117
  // Workaround for https://github.com/babel/babel-loader/pull/896 is available
@@ -101,7 +101,7 @@ function buildWebpackBrowser(options, context, transforms = {}) {
101
101
  const baseOutputPath = path.resolve(context.workspaceRoot, options.outputPath);
102
102
  let outputPaths;
103
103
  // Check Angular version.
104
- version_1.assertCompatibleAngularVersion(context.workspaceRoot, context.logger);
104
+ version_1.assertCompatibleAngularVersion(context.workspaceRoot);
105
105
  return rxjs_1.from(context.getProjectMetadata(projectName)).pipe(operators_1.switchMap(async (projectMetadata) => {
106
106
  var _a;
107
107
  const sysProjectRoot = core_1.getSystemPath(core_1.resolve(core_1.normalize(context.workspaceRoot), core_1.normalize((_a = projectMetadata.root) !== null && _a !== void 0 ? _a : '')));
@@ -462,6 +462,7 @@ function buildWebpackBrowser(options, context, transforms = {}) {
462
462
  crossOrigin: options.crossOrigin,
463
463
  postTransform: transforms.indexHtml,
464
464
  });
465
+ let hasErrors = false;
465
466
  for (const [locale, outputPath] of outputPaths.entries()) {
466
467
  try {
467
468
  const { content, warnings, errors } = await indexHtmlGenerator.process({
@@ -476,7 +477,10 @@ function buildWebpackBrowser(options, context, transforms = {}) {
476
477
  if (warnings.length || errors.length) {
477
478
  spinner.stop();
478
479
  warnings.forEach((m) => context.logger.warn(m));
479
- errors.forEach((m) => context.logger.error(m));
480
+ errors.forEach((m) => {
481
+ context.logger.error(m);
482
+ hasErrors = true;
483
+ });
480
484
  spinner.start();
481
485
  }
482
486
  const indexOutput = path.join(outputPath, webpack_browser_config_1.getIndexOutputFile(options.index));
@@ -488,7 +492,13 @@ function buildWebpackBrowser(options, context, transforms = {}) {
488
492
  return { success: false, error: mapErrorToMessage(error) };
489
493
  }
490
494
  }
491
- spinner.succeed('Index html generation complete.');
495
+ if (hasErrors) {
496
+ spinner.fail('Index html generation failed.');
497
+ return { success: false };
498
+ }
499
+ else {
500
+ spinner.succeed('Index html generation complete.');
501
+ }
492
502
  }
493
503
  if (options.serviceWorker) {
494
504
  spinner.start('Generating service worker...');
@@ -334,7 +334,7 @@ export interface OptimizationClass {
334
334
  export declare type FontsUnion = boolean | FontsClass;
335
335
  export interface FontsClass {
336
336
  /**
337
- * Reduce render blocking requests by inlining external Google fonts and icons CSS
337
+ * Reduce render blocking requests by inlining external Google Fonts and Adobe Fonts CSS
338
338
  * definitions in the application's HTML index file. This option requires internet access.
339
339
  * `HTTPS_PROXY` environment variable can be used to specify a proxy server.
340
340
  */
@@ -108,7 +108,7 @@
108
108
  "properties": {
109
109
  "inline": {
110
110
  "type": "boolean",
111
- "description": "Reduce render blocking requests by inlining external Google fonts and icons CSS definitions in the application's HTML index file. This option requires internet access. `HTTPS_PROXY` environment variable can be used to specify a proxy server.",
111
+ "description": "Reduce render blocking requests by inlining external Google Fonts and Adobe Fonts CSS definitions in the application's HTML index file. This option requires internet access. `HTTPS_PROXY` environment variable can be used to specify a proxy server.",
112
112
  "default": true
113
113
  }
114
114
  },
@@ -77,7 +77,7 @@ const devServerBuildOverriddenKeys = [
77
77
  function serveWebpackBrowser(options, context, transforms = {}) {
78
78
  // Check Angular version.
79
79
  const { logger, workspaceRoot } = context;
80
- version_1.assertCompatibleAngularVersion(workspaceRoot, logger);
80
+ version_1.assertCompatibleAngularVersion(workspaceRoot);
81
81
  const browserTarget = architect_1.targetFromTargetString(options.browserTarget);
82
82
  async function setup() {
83
83
  var _a, _b;
@@ -119,7 +119,7 @@ function serveWebpackBrowser(options, context, transforms = {}) {
119
119
 
120
120
  Binding this server to an open connection can result in compromising your application or
121
121
  computer. Using a different host than the one passed to the "--host" flag might result in
122
- websocket connection issues. You might need to use "--disableHostCheck" if that's the
122
+ websocket connection issues. You might need to use "--disable-host-check" if that's the
123
123
  case.
124
124
  `);
125
125
  }
@@ -122,7 +122,7 @@ class NoEmitPlugin {
122
122
  async function execute(options, context, transforms) {
123
123
  var _a;
124
124
  // Check Angular version.
125
- version_1.assertCompatibleAngularVersion(context.workspaceRoot, context.logger);
125
+ version_1.assertCompatibleAngularVersion(context.workspaceRoot);
126
126
  const browserTarget = architect_1.targetFromTargetString(options.browserTarget);
127
127
  const browserOptions = await context.validateOptions(await context.getTargetOptions(browserTarget), await context.getBuilderNameForTarget(browserTarget));
128
128
  const format = normalizeFormatOption(options);
@@ -5,4 +5,9 @@
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
- export default function localizeExtractLoader(this: any, content: string, map: any): void;
8
+ declare type LoaderSourceMap = Parameters<import('webpack').LoaderDefinitionFunction>[1];
9
+ interface LocalizeExtractLoaderOptions {
10
+ messageHandler: (messages: import('@angular/localize').ɵParsedMessage[]) => void;
11
+ }
12
+ export default function localizeExtractLoader(this: import('webpack').LoaderContext<LocalizeExtractLoaderOptions>, content: string, map: LoaderSourceMap): void;
13
+ export {};
@@ -27,16 +27,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const extraction_1 = require("@angular/localize/src/tools/src/extract/extraction");
30
- const loader_utils_1 = require("loader-utils");
31
30
  const nodePath = __importStar(require("path"));
32
- function localizeExtractLoader(content,
33
- // Source map types are broken in the webpack type definitions
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- map) {
31
+ function localizeExtractLoader(content, map) {
36
32
  // eslint-disable-next-line @typescript-eslint/no-this-alias
37
33
  const loaderContext = this;
38
- // Casts are needed to workaround the loader-utils typings limited support for option values
39
- const options = loader_utils_1.getOptions(this);
34
+ const options = this.getOptions();
40
35
  // Setup a Webpack-based logger instance
41
36
  const logger = {
42
37
  // level 2 is warnings
@@ -46,19 +41,20 @@ map) {
46
41
  console.debug(...args);
47
42
  },
48
43
  info(...args) {
49
- loaderContext.emitWarning(args.join(''));
44
+ loaderContext.emitWarning(new Error(args.join('')));
50
45
  },
51
46
  warn(...args) {
52
- loaderContext.emitWarning(args.join(''));
47
+ loaderContext.emitWarning(new Error(args.join('')));
53
48
  },
54
49
  error(...args) {
55
- loaderContext.emitError(args.join(''));
50
+ loaderContext.emitError(new Error(args.join('')));
56
51
  },
57
52
  };
58
53
  let filename = loaderContext.resourcePath;
59
- if (map === null || map === void 0 ? void 0 : map.file) {
54
+ const mapObject = typeof map === 'string' ? JSON.parse(map) : map;
55
+ if (mapObject === null || mapObject === void 0 ? void 0 : mapObject.file) {
60
56
  // The extractor's internal sourcemap handling expects the filenames to match
61
- filename = nodePath.join(loaderContext.context, map.file);
57
+ filename = nodePath.join(loaderContext.context, mapObject.file);
62
58
  }
63
59
  // Setup a virtual file system instance for the extractor
64
60
  // * MessageExtractor itself uses readFile, relative and resolve
@@ -78,7 +78,7 @@ async function initialize(options, context, webpackConfigurationTransformer) {
78
78
  */
79
79
  function execute(options, context, transforms = {}) {
80
80
  // Check Angular version.
81
- version_1.assertCompatibleAngularVersion(context.workspaceRoot, context.logger);
81
+ version_1.assertCompatibleAngularVersion(context.workspaceRoot);
82
82
  let singleRun;
83
83
  if (options.watch !== undefined) {
84
84
  singleRun = !options.watch;
@@ -48,7 +48,7 @@ const stats_1 = require("../webpack/utils/stats");
48
48
  function execute(options, context, transforms = {}) {
49
49
  const root = context.workspaceRoot;
50
50
  // Check Angular version.
51
- version_1.assertCompatibleAngularVersion(root, context.logger);
51
+ version_1.assertCompatibleAngularVersion(root);
52
52
  const tsConfig = read_tsconfig_1.readTsconfig(options.tsConfig, root);
53
53
  const target = tsConfig.options.target || typescript_1.ScriptTarget.ES5;
54
54
  const baseOutputPath = path.resolve(root, options.outputPath);
@@ -0,0 +1,18 @@
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 { Schema } from '../schema';
9
+ export { describeBuilder } from '../../testing';
10
+ export declare const SERVER_BUILDER_INFO: Readonly<{
11
+ name: string;
12
+ schemaPath: string;
13
+ }>;
14
+ /**
15
+ * Contains all required Server builder fields.
16
+ * Also disables progress reporting to minimize logging output.
17
+ */
18
+ export declare const BASE_OPTIONS: Readonly<Schema>;
@@ -0,0 +1,27 @@
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.BASE_OPTIONS = exports.SERVER_BUILDER_INFO = exports.describeBuilder = void 0;
11
+ var testing_1 = require("../../testing");
12
+ Object.defineProperty(exports, "describeBuilder", { enumerable: true, get: function () { return testing_1.describeBuilder; } });
13
+ exports.SERVER_BUILDER_INFO = Object.freeze({
14
+ name: '@angular-devkit/build-angular:server',
15
+ schemaPath: __dirname + '/../schema.json',
16
+ });
17
+ /**
18
+ * Contains all required Server builder fields.
19
+ * Also disables progress reporting to minimize logging output.
20
+ */
21
+ exports.BASE_OPTIONS = Object.freeze({
22
+ main: 'src/main.server.ts',
23
+ tsConfig: 'src/tsconfig.server.json',
24
+ progress: false,
25
+ watch: false,
26
+ outputPath: 'dist',
27
+ });
@@ -9,18 +9,13 @@ import { I18nOptions } from './i18n-options';
9
9
  import { InlineOptions, ProcessBundleOptions, ProcessBundleResult } from './process-bundle';
10
10
  export declare class BundleActionExecutor {
11
11
  private workerOptions;
12
- private readonly sizeThreshold;
13
- private largeWorker?;
14
- private smallWorker?;
12
+ private workerPool?;
15
13
  private cache?;
16
14
  constructor(workerOptions: {
17
15
  cachePath?: string;
18
16
  i18n: I18nOptions;
19
- }, integrityAlgorithm?: string, sizeThreshold?: number);
20
- private static executeMethod;
21
- private ensureLarge;
22
- private ensureSmall;
23
- private executeAction;
17
+ }, integrityAlgorithm?: string);
18
+ private ensureWorkerPool;
24
19
  process(action: ProcessBundleOptions): Promise<ProcessBundleResult>;
25
20
  processAll(actions: Iterable<ProcessBundleOptions>): AsyncIterable<ProcessBundleResult>;
26
21
  inline(action: InlineOptions): Promise<{
@@ -6,79 +6,33 @@
6
6
  * Use of this source code is governed by an MIT-style license that can be
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
12
- }) : (function(o, m, k, k2) {
13
- if (k2 === undefined) k2 = k;
14
- o[k2] = m[k];
15
- }));
16
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
- Object.defineProperty(o, "default", { enumerable: true, value: v });
18
- }) : function(o, v) {
19
- o["default"] = v;
20
- });
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
11
  };
28
12
  Object.defineProperty(exports, "__esModule", { value: true });
29
13
  exports.BundleActionExecutor = void 0;
30
- const jest_worker_1 = require("jest-worker");
31
- const os = __importStar(require("os"));
32
- const path = __importStar(require("path"));
33
- const v8_1 = require("v8");
14
+ const piscina_1 = __importDefault(require("piscina"));
34
15
  const action_cache_1 = require("./action-cache");
35
16
  const environment_options_1 = require("./environment-options");
36
- let workerFile = require.resolve('./process-bundle');
37
- workerFile =
38
- path.extname(workerFile) === '.ts' ? require.resolve('./process-bundle-bootstrap') : workerFile;
17
+ const workerFile = require.resolve('./process-bundle');
39
18
  class BundleActionExecutor {
40
- constructor(workerOptions, integrityAlgorithm, sizeThreshold = 32 * 1024) {
19
+ constructor(workerOptions, integrityAlgorithm) {
41
20
  this.workerOptions = workerOptions;
42
- this.sizeThreshold = sizeThreshold;
43
21
  if (workerOptions.cachePath) {
44
22
  this.cache = new action_cache_1.BundleActionCache(workerOptions.cachePath, integrityAlgorithm);
45
23
  }
46
24
  }
47
- static executeMethod(worker, method, input) {
48
- return worker[method](input);
49
- }
50
- ensureLarge() {
51
- if (this.largeWorker) {
52
- return this.largeWorker;
53
- }
54
- // larger files are processed in a separate process to limit memory usage in the main process
55
- return (this.largeWorker = new jest_worker_1.Worker(workerFile, {
56
- exposedMethods: ['process', 'inlineLocales'],
57
- setupArgs: [[...v8_1.serialize(this.workerOptions)]],
58
- numWorkers: environment_options_1.maxWorkers,
59
- }));
60
- }
61
- ensureSmall() {
62
- if (this.smallWorker) {
63
- return this.smallWorker;
64
- }
65
- // small files are processed in a limited number of threads to improve speed
66
- // The limited number also prevents a large increase in memory usage for an otherwise short operation
67
- return (this.smallWorker = new jest_worker_1.Worker(workerFile, {
68
- exposedMethods: ['process', 'inlineLocales'],
69
- setupArgs: [this.workerOptions],
70
- numWorkers: os.cpus().length < 2 ? 1 : 2,
71
- enableWorkerThreads: true,
72
- }));
73
- }
74
- executeAction(method, action) {
75
- // code.length is not an exact byte count but close enough for this
76
- if (action.code.length > this.sizeThreshold) {
77
- return BundleActionExecutor.executeMethod(this.ensureLarge(), method, action);
78
- }
79
- else {
80
- return BundleActionExecutor.executeMethod(this.ensureSmall(), method, action);
25
+ ensureWorkerPool() {
26
+ if (this.workerPool) {
27
+ return this.workerPool;
81
28
  }
29
+ this.workerPool = new piscina_1.default({
30
+ filename: workerFile,
31
+ name: 'process',
32
+ workerData: this.workerOptions,
33
+ maxThreads: environment_options_1.maxWorkers,
34
+ });
35
+ return this.workerPool;
82
36
  }
83
37
  async process(action) {
84
38
  if (this.cache) {
@@ -93,13 +47,13 @@ class BundleActionExecutor {
93
47
  }
94
48
  catch { }
95
49
  }
96
- return this.executeAction('process', action);
50
+ return this.ensureWorkerPool().run(action, { name: 'process' });
97
51
  }
98
52
  processAll(actions) {
99
53
  return BundleActionExecutor.executeAll(actions, (action) => this.process(action));
100
54
  }
101
55
  async inline(action) {
102
- return this.executeAction('inlineLocales', action);
56
+ return this.ensureWorkerPool().run(action, { name: 'inlineLocales' });
103
57
  }
104
58
  inlineAll(actions) {
105
59
  return BundleActionExecutor.executeAll(actions, (action) => this.inline(action));
@@ -118,16 +72,8 @@ class BundleActionExecutor {
118
72
  }
119
73
  }
120
74
  stop() {
121
- // Floating promises are intentional here
122
- // https://github.com/facebook/jest/tree/56079a5aceacf32333089cea50c64385885fee26/packages/jest-worker#end
123
- if (this.largeWorker) {
124
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
125
- this.largeWorker.end();
126
- }
127
- if (this.smallWorker) {
128
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
129
- this.smallWorker.end();
130
- }
75
+ var _a;
76
+ void ((_a = this.workerPool) === null || _a === void 0 ? void 0 : _a.destroy());
131
77
  }
132
78
  }
133
79
  exports.BundleActionExecutor = BundleActionExecutor;