-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurge-cache.js
39 lines (39 loc) · 1.5 KB
/
purge-cache.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.purgeStaleBuildCache = purgeStaleBuildCache;
const promises_1 = require("node:fs/promises");
const node_path_1 = require("node:path");
const normalize_cache_1 = require("./normalize-cache");
/** Delete stale cache directories used by previous versions of build-angular. */
async function purgeStaleBuildCache(context) {
const projectName = context.target?.project;
if (!projectName) {
return;
}
const metadata = await context.getProjectMetadata(projectName);
const { basePath, path, enabled } = (0, normalize_cache_1.normalizeCacheOptions)(metadata, context.workspaceRoot);
if (!enabled) {
return;
}
let baseEntries;
try {
baseEntries = await (0, promises_1.readdir)(basePath, { withFileTypes: true });
}
catch {
// No purging possible if base path does not exist or cannot otherwise be accessed
return;
}
const entriesToDelete = baseEntries
.filter((d) => d.isDirectory())
.map((d) => (0, node_path_1.join)(basePath, d.name))
.filter((cachePath) => cachePath !== path)
.map((stalePath) => (0, promises_1.rm)(stalePath, { force: true, recursive: true, maxRetries: 3 }));
await Promise.allSettled(entriesToDelete);
}