Skip to content

Commit 8b9feff

Browse files
author
Angular Builds
committed
6d2087b8f fix(@angular-devkit/build-angular): automatically purge stale build cache entries
1 parent 13711e6 commit 8b9feff

File tree

17 files changed

+107
-11
lines changed

17 files changed

+107
-11
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#cbe028e37",
11-
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#cbe028e37",
12-
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#cbe028e37",
10+
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#6d2087b8f",
11+
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#6d2087b8f",
12+
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#6d2087b8f",
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#cbe028e37",
23+
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#6d2087b8f",
2424
"ansi-colors": "4.1.1",
2525
"babel-loader": "8.2.3",
2626
"babel-plugin-istanbul": "6.1.1",

src/babel/webpack-loader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const remapping_1 = __importDefault(require("@ampproject/remapping"));
1414
const babel_loader_1 = require("babel-loader");
1515
const typescript_1 = require("typescript");
1616
const load_esm_1 = require("../utils/load-esm");
17+
const package_version_1 = require("../utils/package-version");
1718
/**
1819
* Cached instance of the compiler-cli linker's needsLinking function.
1920
*/
@@ -151,7 +152,7 @@ exports.default = (0, babel_loader_1.custom)(() => {
151152
...baseOptions,
152153
...rawOptions,
153154
cacheIdentifier: JSON.stringify({
154-
buildAngular: require('../../package.json').version,
155+
buildAngular: package_version_1.VERSION,
155156
customOptions,
156157
baseOptions,
157158
rawOptions,

src/builders/browser/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const index_html_generator_1 = require("../../utils/index-file/index-html-genera
4444
const normalize_cache_1 = require("../../utils/normalize-cache");
4545
const output_paths_1 = require("../../utils/output-paths");
4646
const package_chunk_sort_1 = require("../../utils/package-chunk-sort");
47+
const purge_cache_1 = require("../../utils/purge-cache");
4748
const service_worker_1 = require("../../utils/service-worker");
4849
const spinner_1 = require("../../utils/spinner");
4950
const supported_browsers_1 = require("../../utils/supported-browsers");
@@ -98,6 +99,8 @@ function buildWebpackBrowser(options, context, transforms = {}) {
9899
return (0, rxjs_1.from)(context.getProjectMetadata(projectName)).pipe((0, operators_1.switchMap)(async (projectMetadata) => {
99100
var _a;
100101
const sysProjectRoot = (0, core_1.getSystemPath)((0, core_1.resolve)((0, core_1.normalize)(context.workspaceRoot), (0, core_1.normalize)((_a = projectMetadata.root) !== null && _a !== void 0 ? _a : '')));
102+
// Purge old build disk cache.
103+
await (0, purge_cache_1.purgeStaleBuildCache)(context);
101104
checkInternetExplorerSupport(sysProjectRoot, context.logger);
102105
return {
103106
...(await initialize(options, context, transforms.webpackConfiguration)),

src/builders/dev-server/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const i18n_options_1 = require("../../utils/i18n-options");
4141
const load_translations_1 = require("../../utils/load-translations");
4242
const normalize_cache_1 = require("../../utils/normalize-cache");
4343
const package_chunk_sort_1 = require("../../utils/package-chunk-sort");
44+
const purge_cache_1 = require("../../utils/purge-cache");
4445
const version_1 = require("../../utils/version");
4546
const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
4647
const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
@@ -69,6 +70,8 @@ function serveWebpackBrowser(options, context, transforms = {}) {
6970
if (!projectName) {
7071
throw new Error('The builder requires a target.');
7172
}
73+
// Purge old build disk cache.
74+
await (0, purge_cache_1.purgeStaleBuildCache)(context);
7275
options.port = await (0, check_port_1.checkPort)((_b = options.port) !== null && _b !== void 0 ? _b : 4200, options.host || 'localhost');
7376
if (options.hmr) {
7477
logger.warn(core_1.tags.stripIndents `NOTICE: Hot Module Replacement (HMR) is enabled for the dev server.

src/builders/extract-i18n/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const path = __importStar(require("path"));
3737
const webpack_1 = __importDefault(require("webpack"));
3838
const i18n_options_1 = require("../../utils/i18n-options");
3939
const load_esm_1 = require("../../utils/load-esm");
40+
const purge_cache_1 = require("../../utils/purge-cache");
4041
const version_1 = require("../../utils/version");
4142
const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
4243
const configs_1 = require("../../webpack/configs");
@@ -119,6 +120,8 @@ async function execute(options, context, transforms) {
119120
var _a;
120121
// Check Angular version.
121122
(0, version_1.assertCompatibleAngularVersion)(context.workspaceRoot);
123+
// Purge old build disk cache.
124+
await (0, purge_cache_1.purgeStaleBuildCache)(context);
122125
const browserTarget = (0, architect_1.targetFromTargetString)(options.browserTarget);
123126
const browserOptions = await context.validateOptions(await context.getTargetOptions(browserTarget), await context.getBuilderNameForTarget(browserTarget));
124127
const format = normalizeFormatOption(options);

src/builders/karma/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ const core_1 = require("@angular-devkit/core");
3232
const path_1 = require("path");
3333
const rxjs_1 = require("rxjs");
3434
const operators_1 = require("rxjs/operators");
35+
const purge_cache_1 = require("../../utils/purge-cache");
3536
const version_1 = require("../../utils/version");
3637
const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
3738
const configs_1 = require("../../webpack/configs");
3839
const single_test_transform_1 = require("../../webpack/plugins/single-test-transform");
3940
const schema_1 = require("../browser/schema");
4041
const find_tests_1 = require("./find-tests");
4142
async function initialize(options, context, webpackConfigurationTransformer) {
43+
// Purge old build disk cache.
44+
await (0, purge_cache_1.purgeStaleBuildCache)(context);
4245
const { config } = await (0, webpack_browser_config_1.generateBrowserWebpackConfigFromContext)(
4346
// only two properties are missing:
4447
// * `outputPath` which is fixed for tests

src/builders/ng-packagr/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ const path_1 = require("path");
3232
const rxjs_1 = require("rxjs");
3333
const operators_1 = require("rxjs/operators");
3434
const normalize_cache_1 = require("../../utils/normalize-cache");
35+
const purge_cache_1 = require("../../utils/purge-cache");
3536
/**
3637
* @experimental Direct usage of this function is considered experimental.
3738
*/
3839
function execute(options, context) {
3940
return (0, rxjs_1.from)((async () => {
4041
var _a;
42+
// Purge old build disk cache.
43+
await (0, purge_cache_1.purgeStaleBuildCache)(context);
4144
const root = context.workspaceRoot;
4245
const packager = (await Promise.resolve().then(() => __importStar(require('ng-packagr')))).ngPackagr();
4346
packager.forProject((0, path_1.resolve)(root, options.project));

src/builders/server/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const typescript_1 = require("typescript");
3737
const utils_1 = require("../../utils");
3838
const i18n_inlining_1 = require("../../utils/i18n-inlining");
3939
const output_paths_1 = require("../../utils/output-paths");
40+
const purge_cache_1 = require("../../utils/purge-cache");
4041
const version_1 = require("../../utils/version");
4142
const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
4243
const configs_1 = require("../../webpack/configs");
@@ -103,6 +104,8 @@ function execute(options, context, transforms = {}) {
103104
exports.execute = execute;
104105
exports.default = (0, architect_1.createBuilder)(execute);
105106
async function initialize(options, context, webpackConfigurationTransform) {
107+
// Purge old build disk cache.
108+
await (0, purge_cache_1.purgeStaleBuildCache)(context);
106109
const originalOutputPath = options.outputPath;
107110
const { config, i18n, target } = await (0, webpack_browser_config_1.generateI18nBrowserWebpackConfigFromContext)({
108111
...options,

src/utils/index-file/inline-fonts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ const https = __importStar(require("https"));
3636
const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
3737
const path_1 = require("path");
3838
const url_1 = require("url");
39+
const package_version_1 = require("../package-version");
3940
const html_rewriting_stream_1 = require("./html-rewriting-stream");
40-
const packageVersion = require('../../../package.json').version;
4141
const SUPPORTED_PROVIDERS = {
4242
'fonts.googleapis.com': {
4343
preconnectUrl: 'https://fonts.gstatic.com',
@@ -146,7 +146,7 @@ class InlineFontsProcessor {
146146
}
147147
async getResponse(url) {
148148
var _a;
149-
const key = `${packageVersion}|${url}`;
149+
const key = `${package_version_1.VERSION}|${url}`;
150150
if (this.cachePath) {
151151
const entry = await cacache.get.info(this.cachePath, key);
152152
if (entry) {

src/utils/normalize-cache.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
*/
88
import { json } from '@angular-devkit/core';
99
export interface NormalizedCachedOptions {
10+
/** Whether disk cache is enabled. */
1011
enabled: boolean;
12+
/** Disk cache path. Example: `/.angular/cache/v12.0.0`. */
1113
path: string;
14+
/** Disk cache base path. Example: `/.angular/cache`. */
15+
basePath: string;
1216
}
1317
export declare function normalizeCacheOptions(metadata: json.JsonObject, worspaceRoot: string): NormalizedCachedOptions;

0 commit comments

Comments
 (0)