Skip to content

Commit 12042cc

Browse files
author
Angular Builds
committed
0d68ed547 fix(@angular-devkit/build-angular): localized bundle generation fails in watch mode
1 parent 18d2e28 commit 12042cc

File tree

6 files changed

+35
-26
lines changed

6 files changed

+35
-26
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"builders": "builders.json",
88
"dependencies": {
99
"@ampproject/remapping": "1.0.2",
10-
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#50167a36b",
11-
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#50167a36b",
12-
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#50167a36b",
10+
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#0d68ed547",
11+
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#0d68ed547",
12+
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#0d68ed547",
1313
"@babel/core": "7.16.7",
1414
"@babel/generator": "7.16.7",
1515
"@babel/helper-annotate-as-pure": "7.16.7",
@@ -20,7 +20,7 @@
2020
"@babel/runtime": "7.16.7",
2121
"@babel/template": "7.16.7",
2222
"@discoveryjs/json-ext": "0.5.6",
23-
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#50167a36b",
23+
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#0d68ed547",
2424
"ansi-colors": "4.1.1",
2525
"babel-loader": "8.2.3",
2626
"babel-plugin-istanbul": "6.1.1",

src/builders/browser/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export declare type BrowserBuilderOutput = json.JsonObject & BuilderOutput & {
2424
*/
2525
outputPath: string;
2626
};
27+
/**
28+
* Maximum time in milliseconds for single build/rebuild
29+
* This accounts for CI variability.
30+
*/
31+
export declare const BUILD_TIMEOUT = 30000;
2732
/**
2833
* @experimental Direct usage of this function is considered experimental.
2934
*/

src/builders/browser/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
2626
return result;
2727
};
2828
Object.defineProperty(exports, "__esModule", { value: true });
29-
exports.buildWebpackBrowser = void 0;
29+
exports.buildWebpackBrowser = exports.BUILD_TIMEOUT = void 0;
3030
const architect_1 = require("@angular-devkit/architect");
3131
const build_webpack_1 = require("@angular-devkit/build-webpack");
3232
const core_1 = require("@angular-devkit/core");
@@ -54,6 +54,11 @@ const configs_1 = require("../../webpack/configs");
5454
const async_chunks_1 = require("../../webpack/utils/async-chunks");
5555
const helpers_1 = require("../../webpack/utils/helpers");
5656
const stats_1 = require("../../webpack/utils/stats");
57+
/**
58+
* Maximum time in milliseconds for single build/rebuild
59+
* This accounts for CI variability.
60+
*/
61+
exports.BUILD_TIMEOUT = 30000;
5762
async function initialize(options, context, webpackConfigurationTransform) {
5863
var _a, _b;
5964
const originalOutputPath = options.outputPath;

src/utils/i18n-inlining.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,10 @@ function emittedFilesToInlineOptions(emittedFiles, scriptsEntryPointName, emitte
5151
setLocale: emittedFile.name === 'main' || emittedFile.name === 'vendor',
5252
};
5353
originalFiles.push(originalPath);
54-
// Remove temporary original file as the content has now been read
55-
try {
56-
fs.unlinkSync(originalPath);
57-
}
58-
catch (e) {
59-
context.logger.debug(`Unable to delete i18n temporary file [${originalPath}]: ${e.toString()}`);
60-
}
6154
try {
6255
const originalMapPath = originalPath + '.map';
6356
action.map = fs.readFileSync(originalMapPath, 'utf8');
6457
originalFiles.push(originalMapPath);
65-
// Remove temporary original map file as the content has now been read
66-
try {
67-
fs.unlinkSync(originalMapPath);
68-
}
69-
catch (e) {
70-
context.logger.debug(`Unable to delete i18n temporary file [${originalMapPath}]: ${e.toString()}`);
71-
}
7258
}
7359
catch (err) {
7460
if (err.code !== 'ENOENT') {

src/utils/i18n-options.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,11 @@ async function configureI18nBuild(context, options) {
177177
if (i18n.shouldInline) {
178178
const tempPath = fs_1.default.mkdtempSync(path_1.default.join(fs_1.default.realpathSync(os_1.default.tmpdir()), 'angular-cli-i18n-'));
179179
buildOptions.outputPath = tempPath;
180-
// Remove temporary directory used for i18n processing
181-
process.on('exit', () => {
182-
try {
183-
fs_1.default.rmdirSync(tempPath, { recursive: true, maxRetries: 3 });
184-
}
185-
catch { }
180+
process.on('exit', () => deleteTempDirectory(tempPath));
181+
process.once('SIGINT', () => {
182+
deleteTempDirectory(tempPath);
183+
// Needed due to `ora` as otherwise process will not terminate.
184+
process.kill(process.pid, 'SIGINT');
186185
});
187186
}
188187
return { buildOptions, i18n };
@@ -202,6 +201,20 @@ function findLocaleDataPath(locale, resolver) {
202201
return null;
203202
}
204203
}
204+
/** Remove temporary directory used for i18n processing. */
205+
function deleteTempDirectory(tempPath) {
206+
// The below should be removed and replaced with just `rmSync` when support for Node.Js 12 is removed.
207+
const { rmSync, rmdirSync } = fs_1.default;
208+
try {
209+
if (rmSync) {
210+
rmSync(tempPath, { force: true, recursive: true, maxRetries: 3 });
211+
}
212+
else {
213+
rmdirSync(tempPath, { recursive: true, maxRetries: 3 });
214+
}
215+
}
216+
catch { }
217+
}
205218
function loadTranslations(locale, desc, workspaceRoot, loader, logger, usedFormats, duplicateTranslation) {
206219
for (const file of desc.files) {
207220
const loadResult = loader(path_1.default.join(workspaceRoot, file.path));

uniqueId

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Wed Jan 12 2022 18:48:46 GMT+0000 (Coordinated Universal Time)
1+
Wed Jan 12 2022 18:49:07 GMT+0000 (Coordinated Universal Time)

0 commit comments

Comments
 (0)