Skip to content

Commit ae26119

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular-devkit/build-angular): support writing large Webpack stat outputs
When using the `statsJson` browser builder option, the resulting JSON data is now streamed into a file instead of written in one large block. This mitigates crashes due to the generated string exceeded the Node.js limit. (cherry picked from commit d564567)
1 parent 8c7ebb6 commit ae26119

File tree

8 files changed

+48
-23
lines changed

8 files changed

+48
-23
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"@bazel/buildifier": "4.0.0",
9090
"@bazel/jasmine": "3.2.1",
9191
"@bazel/typescript": "3.2.1",
92+
"@discoveryjs/json-ext": "0.5.2",
9293
"@jsdevtools/coverage-istanbul-loader": "3.0.5",
9394
"@types/babel__core": "7.1.12",
9495
"@types/babel__template": "7.4.0",

packages/angular_devkit/build_angular/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ ts_library(
113113
"@npm//@babel/preset-env",
114114
"@npm//@babel/runtime",
115115
"@npm//@babel/template",
116+
"@npm//@discoveryjs/json-ext",
116117
"@npm//@jsdevtools/coverage-istanbul-loader",
117118
"@npm//@types/babel__core",
118119
"@npm//@types/babel__template",

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@babel/preset-env": "7.12.11",
1919
"@babel/runtime": "7.12.5",
2020
"@babel/template": "7.12.7",
21+
"@discoveryjs/json-ext": "0.5.2",
2122
"@jsdevtools/coverage-istanbul-loader": "3.0.5",
2223
"@ngtools/webpack": "0.0.0",
2324
"ansi-colors": "4.1.1",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. 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+
// Workaround for https://github.com/bazelbuild/rules_nodejs/issues/1033
10+
// Alternative approach instead of https://github.com/angular/angular/pull/33226
11+
declare module '@babel/core' {
12+
export * from '@types/babel__core';
13+
}
14+
declare module '@babel/generator' {
15+
export { default } from '@types/babel__generator';
16+
}
17+
declare module '@babel/traverse' {
18+
export { default } from '@types/babel__traverse';
19+
}
20+
declare module '@babel/template' {
21+
export { default } from '@types/babel__template';
22+
}

packages/angular_devkit/build_angular/src/typings.d.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
9-
// Workaround for https://github.com/bazelbuild/rules_nodejs/issues/1033
10-
// Alternative approach instead of https://github.com/angular/angular/pull/33226
11-
declare module '@babel/core' {
12-
export * from '@types/babel__core';
13-
}
14-
declare module '@babel/generator' {
15-
export { default } from '@types/babel__generator';
16-
}
17-
declare module '@babel/traverse' {
18-
export { default } from '@types/babel__traverse';
19-
}
20-
declare module '@babel/template' {
21-
export { default } from '@types/babel__template';
8+
declare module '@discoveryjs/json-ext' {
9+
export function stringifyStream(value: unknown): import('stream').Readable;
2210
}

packages/angular_devkit/build_angular/src/webpack/configs/common.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
buildOptimizerLoaderPath,
1111
} from '@angular-devkit/build-optimizer';
1212
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
13-
import { existsSync } from 'fs';
13+
import { createWriteStream, existsSync } from 'fs';
1414
import * as path from 'path';
1515
import { RollupOptions } from 'rollup';
1616
import { ScriptTarget } from 'typescript';
@@ -23,7 +23,6 @@ import {
2323
compilation,
2424
debug,
2525
} from 'webpack';
26-
import { RawSource } from 'webpack-sources';
2726
import { AssetPatternClass } from '../../browser/schema';
2827
import { BuildBrowserFeatures, maxWorkers } from '../../utils';
2928
import { WebpackConfigOptions } from '../../utils/build-options';
@@ -339,9 +338,17 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
339338
extraPlugins.push(
340339
new (class {
341340
apply(compiler: Compiler) {
342-
compiler.hooks.emit.tap('angular-cli-stats', compilation => {
343-
const data = JSON.stringify(compilation.getStats().toJson('verbose'), undefined, 2);
344-
compilation.assets['stats.json'] = new RawSource(data);
341+
compiler.hooks.done.tapPromise('angular-cli-stats', async (stats) => {
342+
const { stringifyStream } = await import('@discoveryjs/json-ext');
343+
const data = stats.toJson('verbose');
344+
const statsOutputPath = path.join(stats.compilation.outputOptions.path, 'stats.json');
345+
346+
return new Promise<void>((resolve, reject) =>
347+
stringifyStream(data)
348+
.pipe(createWriteStream(statsOutputPath))
349+
.on('close', resolve)
350+
.on('error', reject),
351+
);
345352
});
346353
}
347354
})(),

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"suppressTsconfigOverrideWarnings": true
5858
},
5959
"exclude": [
60-
"packages/angular_devkit/build_angular/src/typings.d.ts",
60+
"packages/angular_devkit/build_angular/src/bazel-babel.d.ts",
6161
"bazel-out/**/*",
6262
"dist/**/*",
6363
"dist-schema/**",

yarn.lock

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787

8888
"@angular/dev-infra-private@https://github.com/angular/dev-infra-private-builds.git#0fd0f441648577e8c3966e9b59a88fefe350f514":
8989
version "0.0.0"
90-
resolved "https://github.com/angular/dev-infra-private-builds.git#0fd0f441648577e8c3966e9b59a88fefe350f514"
90+
resolved "https://github.com/angular/dev-infra-private-builds.git#a6b42dabedcf7c724bd36a614ebe9fa99c777e62"
9191
dependencies:
9292
"@angular/benchpress" "0.2.1"
9393
"@bazel/buildifier" "^0.29.0"
@@ -103,13 +103,13 @@
103103
inquirer-autocomplete-prompt "^1.0.2"
104104
minimatch "^3.0.4"
105105
multimatch "^4.0.0"
106-
node-fetch "^2.6.0"
106+
node-fetch "^2.6.1"
107107
node-uuid "1.4.8"
108108
ora "^5.0.0"
109109
protractor "^5.4.2"
110110
selenium-webdriver "3.5.0"
111111
semver "^6.3.0"
112-
shelljs "^0.8.3"
112+
shelljs "^0.8.4"
113113
ts-node "^8.6.2"
114114
tslib "^2.0.0"
115115
typed-graphqlify "^2.3.0"
@@ -1076,6 +1076,11 @@
10761076
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
10771077
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
10781078

1079+
"@discoveryjs/[email protected]":
1080+
version "0.5.2"
1081+
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.2.tgz#8f03a22a04de437254e8ce8cc84ba39689288752"
1082+
integrity sha512-HyYEUDeIj5rRQU2Hk5HTB2uHsbRQpF70nvMhVzi+VJR0X+xNEhjPui4/kBf3VeH/wqD28PT4sVOm8qqLjBrSZg==
1083+
10791084
"@istanbuljs/schema@^0.1.2":
10801085
version "0.1.2"
10811086
resolved "https://registry.yarnpkg.com/@istanbuljs/schema/-/schema-0.1.2.tgz#26520bf09abe4a5644cd5414e37125a8954241dd"

0 commit comments

Comments
 (0)