lage 1.6.4 → 1.6.7

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 (74) hide show
  1. package/CHANGELOG.json +46 -1
  2. package/CHANGELOG.md +26 -2
  3. package/package.json +14 -14
  4. package/src/args.ts +0 -107
  5. package/src/cache/RemoteFallbackCacheProvider.ts +0 -100
  6. package/src/cache/backfill.ts +0 -93
  7. package/src/cache/cacheConfig.ts +0 -33
  8. package/src/cache/cacheTasks.ts +0 -9
  9. package/src/cache/salt.ts +0 -52
  10. package/src/cli.ts +0 -47
  11. package/src/command/cache.ts +0 -81
  12. package/src/command/info.ts +0 -108
  13. package/src/command/init.ts +0 -129
  14. package/src/command/run.ts +0 -70
  15. package/src/command/version.ts +0 -8
  16. package/src/command/worker.ts +0 -148
  17. package/src/config/getConfig.ts +0 -86
  18. package/src/context.ts +0 -43
  19. package/src/displayReportAndExit.ts +0 -17
  20. package/src/index.ts +0 -1
  21. package/src/logger/LogEntry.ts +0 -40
  22. package/src/logger/LogLevel.ts +0 -7
  23. package/src/logger/Logger.ts +0 -47
  24. package/src/logger/TaskLogWritable.ts +0 -35
  25. package/src/logger/TaskLogger.ts +0 -34
  26. package/src/logger/index.ts +0 -3
  27. package/src/logger/initReporters.ts +0 -35
  28. package/src/logger/reporters/AdoReporter.ts +0 -41
  29. package/src/logger/reporters/DgmlReporter.ts +0 -66
  30. package/src/logger/reporters/JsonReporter.ts +0 -39
  31. package/src/logger/reporters/NpmLogReporter.ts +0 -212
  32. package/src/logger/reporters/Reporter.ts +0 -7
  33. package/src/logger/reporters/formatDuration.ts +0 -16
  34. package/src/paths.ts +0 -37
  35. package/src/showHelp.ts +0 -15
  36. package/src/task/DistributedTask.ts +0 -68
  37. package/src/task/NpmScriptTask.ts +0 -80
  38. package/src/task/Pipeline.ts +0 -496
  39. package/src/task/WorkerQueue.ts +0 -148
  40. package/src/task/WrappedTarget.ts +0 -178
  41. package/src/task/abortSignal.ts +0 -6
  42. package/src/task/filterPackages.ts +0 -72
  43. package/src/task/getDepsForTarget.ts +0 -27
  44. package/src/task/getNpmCommand.ts +0 -9
  45. package/src/task/getPipelinePackages.ts +0 -65
  46. package/src/task/taskId.ts +0 -12
  47. package/src/types/CacheOptions.ts +0 -8
  48. package/src/types/CliOptions.ts +0 -200
  49. package/src/types/Config.ts +0 -9
  50. package/src/types/ConfigOptions.ts +0 -68
  51. package/src/types/LoggerOptions.ts +0 -15
  52. package/src/types/PipelineDefinition.ts +0 -88
  53. package/src/types/Priority.ts +0 -10
  54. package/src/types/RunContext.ts +0 -18
  55. package/src/types/TargetStatus.ts +0 -1
  56. package/src/types/TaskId.ts +0 -1
  57. package/src/types/TopologicalGraph.ts +0 -6
  58. package/src/types/Workspace.ts +0 -8
  59. package/src/workspace/findNpmClient.ts +0 -28
  60. package/src/workspace/generateTopologicalGraph.ts +0 -24
  61. package/src/workspace/getPackagePipelines.ts +0 -36
  62. package/src/workspace/getWorkspace.ts +0 -28
  63. package/tests/e2e/__snapshots__/info.test.ts.snap +0 -5
  64. package/tests/e2e/basic.test.ts +0 -60
  65. package/tests/e2e/basicFailure.test.ts +0 -132
  66. package/tests/e2e/bigapp.test.ts +0 -94
  67. package/tests/e2e/info.test.ts +0 -43
  68. package/tests/e2e/parseNdJson.ts +0 -11
  69. package/tests/e2e/remoteFallback.test.ts +0 -245
  70. package/tests/e2e/transitiveTaskDeps.test.ts +0 -224
  71. package/tests/mock/monorepo.ts +0 -180
  72. package/tests/res.txt +0 -3537
  73. package/tests/tsconfig.json +0 -4
  74. package/tests/unit/filterPackages.test.ts +0 -126
package/CHANGELOG.json CHANGED
@@ -2,7 +2,52 @@
2
2
  "name": "lage",
3
3
  "entries": [
4
4
  {
5
- "date": "Fri, 01 Jul 2022 16:00:36 GMT",
5
+ "date": "Fri, 01 Jul 2022 16:25:06 GMT",
6
+ "tag": "lage_v1.6.7",
7
+ "version": "1.6.7",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "renovate@whitesourcesoftware.com",
12
+ "package": "lage",
13
+ "commit": "3cee217a37ec7d80a90f9434f39826e758bbdd2a",
14
+ "comment": "Update dependency @types/node to v12.20.55"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Fri, 01 Jul 2022 16:15:39 GMT",
21
+ "tag": "lage_v1.6.6",
22
+ "version": "1.6.6",
23
+ "comments": {
24
+ "patch": [
25
+ {
26
+ "author": "email not defined",
27
+ "package": "lage",
28
+ "commit": "7ecee913b1cd4e6427aeb2c5f6f1e0e1f3225713",
29
+ "comment": "Pin dependencies"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Fri, 01 Jul 2022 16:11:45 GMT",
36
+ "tag": "lage_v1.6.5",
37
+ "version": "1.6.5",
38
+ "comments": {
39
+ "patch": [
40
+ {
41
+ "author": "renovate@whitesourcesoftware.com",
42
+ "package": "lage",
43
+ "commit": "d849123a63fd58a413980f4be7937dddf40d3bc2",
44
+ "comment": "Update dependency workspace-tools to ^0.21.0"
45
+ }
46
+ ]
47
+ }
48
+ },
49
+ {
50
+ "date": "Fri, 01 Jul 2022 16:00:40 GMT",
6
51
  "tag": "lage_v1.6.4",
7
52
  "version": "1.6.4",
8
53
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,36 @@
1
1
  # Change Log - lage
2
2
 
3
- This log was last generated on Fri, 01 Jul 2022 16:00:36 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 01 Jul 2022 16:25:06 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 1.6.7
8
+
9
+ Fri, 01 Jul 2022 16:25:06 GMT
10
+
11
+ ### Patches
12
+
13
+ - Update dependency @types/node to v12.20.55 (renovate@whitesourcesoftware.com)
14
+
15
+ ## 1.6.6
16
+
17
+ Fri, 01 Jul 2022 16:15:39 GMT
18
+
19
+ ### Patches
20
+
21
+ - Pin dependencies (email not defined)
22
+
23
+ ## 1.6.5
24
+
25
+ Fri, 01 Jul 2022 16:11:45 GMT
26
+
27
+ ### Patches
28
+
29
+ - Update dependency workspace-tools to ^0.21.0 (renovate@whitesourcesoftware.com)
30
+
7
31
  ## 1.6.4
8
32
 
9
- Fri, 01 Jul 2022 16:00:36 GMT
33
+ Fri, 01 Jul 2022 16:00:40 GMT
10
34
 
11
35
  ### Patches
12
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lage",
3
- "version": "1.6.4",
3
+ "version": "1.6.7",
4
4
  "description": "A monorepo task runner",
5
5
  "repository": {
6
6
  "url": "https://github.com/microsoft/lage"
@@ -47,26 +47,26 @@
47
47
  "p-graph": "^1.1.1",
48
48
  "p-limit": "^3.1.0",
49
49
  "p-profiler": "^0.2.1",
50
- "workspace-tools": "^0.18.4",
50
+ "workspace-tools": "^0.21.0",
51
51
  "yargs-parser": "^18.1.3"
52
52
  },
53
53
  "devDependencies": {
54
- "@marp-team/marp-cli": "^0.20.0",
55
- "@types/chalk": "^2.2.0",
56
- "@types/cosmiconfig": "^6.0.0",
57
- "@types/execa": "^2.0.0",
58
- "@types/git-url-parse": "^9.0.0",
59
- "@types/ioredis": "^4.27.7",
54
+ "@marp-team/marp-cli": "0.20.0",
55
+ "@types/chalk": "2.2.0",
56
+ "@types/cosmiconfig": "6.0.0",
57
+ "@types/execa": "2.0.0",
58
+ "@types/git-url-parse": "9.0.1",
59
+ "@types/ioredis": "4.28.10",
60
60
  "@types/jest": "^27.0.1",
61
- "@types/node": "^12.0.0",
62
- "@types/npmlog": "^4.1.2",
63
- "@types/p-queue": "^3.2.1",
64
- "@types/yargs-parser": "^15.0.0",
61
+ "@types/node": "12.20.55",
62
+ "@types/npmlog": "4.1.4",
63
+ "@types/p-queue": "3.2.1",
64
+ "@types/yargs-parser": "15.0.0",
65
65
  "beachball": "2.23.0",
66
- "gh-pages": "^2.2.0",
66
+ "gh-pages": "2.2.0",
67
67
  "jest": "^27.2.0",
68
68
  "ts-jest": "^27.0.5",
69
- "ts-node": "^8.10.2",
69
+ "ts-node": "8.10.2",
70
70
  "typescript": "^4.4.4"
71
71
  }
72
72
  }
package/src/args.ts DELETED
@@ -1,107 +0,0 @@
1
- import yargsParser, { Arguments } from "yargs-parser";
2
-
3
- export function arrifyArgs(args: { [key: string]: string | string[] }) {
4
- const argsArray: string[] = [];
5
- for (const [key, val] of Object.entries(args)) {
6
- if (key === "--" && Array.isArray(val)) {
7
- val.forEach((arg) => argsArray.push(arg));
8
- } else if (Array.isArray(val)) {
9
- for (const item of val) {
10
- pushValue(key, item);
11
- }
12
- } else {
13
- pushValue(key, val);
14
- }
15
- }
16
-
17
- return argsArray;
18
-
19
- function pushValue(key: string, value: string) {
20
- let keyArg = "";
21
-
22
- if (typeof value === "boolean") {
23
- if (key.length === 1 && value) {
24
- keyArg = `-${key}`;
25
- } else if (value) {
26
- keyArg = `--${key}`;
27
- } else {
28
- keyArg = `--no-${key}`;
29
- }
30
-
31
- argsArray.push(keyArg);
32
- } else {
33
- if (key.length === 1 && value) {
34
- keyArg = `-${key}`;
35
- } else if (value) {
36
- keyArg = `--${key}`;
37
- }
38
-
39
- argsArray.push(keyArg, value);
40
- }
41
- }
42
- }
43
-
44
- export function getPassThroughArgs(
45
- command: string[],
46
- args: { [key: string]: string | string[] }
47
- ) {
48
- let result: string[] = [];
49
-
50
- let lageArgs = [
51
- "node",
52
- "scope",
53
- "since",
54
- "cache",
55
- "deps",
56
- "resetCache",
57
- "ignore",
58
- "verbose",
59
- "only",
60
- "concurrency",
61
- "profile",
62
- "grouped",
63
- "reporter",
64
- "to",
65
- "parallel",
66
- "continue",
67
- "safeExit",
68
- "includeDependencies",
69
- "logLevel",
70
- "cacheKey",
71
- "dist",
72
- "experimentDist",
73
- "skipLocalCache",
74
- "_",
75
- ];
76
-
77
- if (command[0] === "cache") {
78
- lageArgs = [...lageArgs, "clear", "prune"];
79
- }
80
-
81
- const filtered: { [key: string]: string | string[] } = {};
82
-
83
- for (let [key, value] of Object.entries(args)) {
84
- if (!lageArgs.includes(key)) {
85
- filtered[key] = value;
86
- }
87
- }
88
-
89
- result = result.concat(arrifyArgs(filtered));
90
-
91
- return result;
92
- }
93
-
94
- export function parseArgs() {
95
- return yargsParser(process.argv.slice(2), {
96
- array: ["scope", "node", "ignore", "to"],
97
- configuration: {
98
- "populate--": true,
99
- "strip-dashed": true,
100
- },
101
- string: ["cacheKey"],
102
- });
103
- }
104
-
105
- export function validateInput(parsedArgs: Arguments) {
106
- return parsedArgs._ && parsedArgs._.length > 0;
107
- }
@@ -1,100 +0,0 @@
1
- import { ICacheStorage } from "backfill-config";
2
- import { getCacheStorageProvider, isCustomProvider } from "backfill-cache";
3
- import { Logger } from "backfill-logger";
4
- import { CacheOptions } from "../types/CacheOptions";
5
- import { logger } from "../logger";
6
-
7
- export type RemoteFallbackCacheProviderOptions = Pick<
8
- CacheOptions,
9
- "internalCacheFolder" | "cacheStorageConfig" | "writeRemoteCache" | "skipLocalCache"
10
- >;
11
-
12
- /**
13
- * Remote Fallback Cache Provider
14
- *
15
- * This backfill cache provider will fallback to a remote cache provider if the local cache does not contain the item.
16
- * It will also automatically populate the local cache with the remote cache.
17
- */
18
- export class RemoteFallbackCacheProvider implements ICacheStorage {
19
- private localCacheStorageProvider: ICacheStorage;
20
- private remoteCacheStorageProvider?: ICacheStorage;
21
-
22
- private static localHits: { [hash: string]: boolean } = {};
23
- private static remoteHits: { [hash: string]: boolean } = {};
24
-
25
- constructor(private cacheOptions: RemoteFallbackCacheProviderOptions, logger: Logger, cwd: string) {
26
- this.localCacheStorageProvider = getCacheStorageProvider(
27
- {
28
- provider: "local",
29
- },
30
- cacheOptions.internalCacheFolder,
31
- logger,
32
- cwd
33
- );
34
-
35
- // Remote providers should have a provider name of something other than "local" OR it is
36
- // a custom provider (currently S3 would be a custom provider)
37
- const isRemoteProvider =
38
- isCustomProvider(cacheOptions.cacheStorageConfig) ||
39
- (typeof cacheOptions.cacheStorageConfig.provider === "string" &&
40
- !cacheOptions.cacheStorageConfig.provider.includes("local"));
41
-
42
- if (isRemoteProvider) {
43
- logger.silly("remote provider enabled");
44
-
45
- this.remoteCacheStorageProvider = getCacheStorageProvider(
46
- cacheOptions.cacheStorageConfig,
47
- cacheOptions.internalCacheFolder,
48
- logger,
49
- cwd
50
- );
51
- }
52
- }
53
-
54
- async fetch(hash: string) {
55
- if (!this.cacheOptions.skipLocalCache) {
56
- RemoteFallbackCacheProvider.localHits[hash] = await this.localCacheStorageProvider.fetch(hash);
57
- logger.silly(`local cache fetch: ${hash} ${RemoteFallbackCacheProvider.localHits[hash]}`);
58
- }
59
-
60
- if (!RemoteFallbackCacheProvider.localHits[hash] && this.remoteCacheStorageProvider) {
61
- RemoteFallbackCacheProvider.remoteHits[hash] = await this.remoteCacheStorageProvider.fetch(hash);
62
- logger.silly(`remote fallback fetch: ${hash} ${RemoteFallbackCacheProvider.remoteHits[hash]}`);
63
- return RemoteFallbackCacheProvider.remoteHits[hash];
64
- }
65
-
66
- return RemoteFallbackCacheProvider.localHits[hash];
67
- }
68
-
69
- async put(hash: string, filesToCache: string[]) {
70
- const putPromises: Promise<void>[] = [];
71
-
72
- // Write local cache if it doesn't already exist, or if the the hash isn't in the localHits
73
- const shouldWriteLocalCache = !this.isLocalHit(hash) && !this.cacheOptions.skipLocalCache;
74
-
75
- if (shouldWriteLocalCache) {
76
- logger.silly(`local cache put: ${hash}`);
77
- putPromises.push(this.localCacheStorageProvider.put(hash, filesToCache));
78
- }
79
-
80
- // Write to remote if there is a no hit in the remote cache, and remote cache storage provider, and that the "writeRemoteCache" config flag is set to true
81
- const shouldWriteRemoteCache =
82
- !this.isRemoteHit(hash) && !!this.remoteCacheStorageProvider && this.cacheOptions.writeRemoteCache;
83
-
84
- if (shouldWriteRemoteCache) {
85
- logger.silly(`remote fallback put: ${hash}`);
86
- const remotePut = this.remoteCacheStorageProvider!.put(hash, filesToCache);
87
- putPromises.push(remotePut);
88
- }
89
-
90
- await Promise.all(putPromises);
91
- }
92
-
93
- private isRemoteHit(hash) {
94
- return hash in RemoteFallbackCacheProvider.remoteHits && RemoteFallbackCacheProvider.remoteHits[hash];
95
- }
96
-
97
- private isLocalHit(hash) {
98
- return hash in RemoteFallbackCacheProvider.localHits && RemoteFallbackCacheProvider.localHits[hash];
99
- }
100
- }
@@ -1,93 +0,0 @@
1
- import { getCacheConfig } from "./cacheConfig";
2
- import { logger } from "../logger";
3
- import { salt } from "./salt";
4
- import * as backfill from "backfill/lib/api";
5
- import { CacheOptions } from "../types/CacheOptions";
6
-
7
- export async function cacheHash(
8
- id: string,
9
- cwd: string,
10
- root: string,
11
- cacheOptions: CacheOptions,
12
- args: any
13
- ) {
14
- const cacheConfig = getCacheConfig(cwd, cacheOptions);
15
-
16
- const backfillLogger = backfill.makeLogger(
17
- "error",
18
- process.stdout,
19
- process.stderr
20
- );
21
-
22
- const hashKey = salt(
23
- cacheOptions.environmentGlob || ["lage.config.js"],
24
- `${id}|${JSON.stringify(args)}`,
25
- root,
26
- cacheOptions.cacheKey
27
- );
28
-
29
- backfillLogger.setName(id);
30
-
31
- try {
32
- return await backfill.computeHash(
33
- cwd,
34
- backfillLogger,
35
- hashKey,
36
- cacheConfig
37
- );
38
- } catch {
39
- // computeHash can throw exception when git is not installed or the repo hashes cannot be calculated with a staged file that is deleted
40
- // lage will continue as if this package cannot be cached
41
- }
42
-
43
- return null;
44
- }
45
-
46
- export async function cacheFetch(
47
- hash: string | null,
48
- id: string,
49
- cwd: string,
50
- cacheOptions: CacheOptions
51
- ) {
52
- if (!hash) {
53
- return false;
54
- }
55
-
56
- const cacheConfig = getCacheConfig(cwd, cacheOptions);
57
- const backfillLogger = backfill.makeLogger(
58
- "error",
59
- process.stdout,
60
- process.stderr
61
- );
62
-
63
- try {
64
- return await backfill.fetch(cwd, hash, backfillLogger, cacheConfig);
65
- } catch (e) {
66
- logger.error(`${id} fetchBackfill ${e && (e as any).stack || e && (e as any).message || e}`);
67
- }
68
-
69
- return false;
70
- }
71
-
72
- export async function cachePut(
73
- hash: string | null,
74
- cwd: string,
75
- cacheOptions: CacheOptions
76
- ) {
77
- if (!hash) {
78
- return;
79
- }
80
-
81
- const cacheConfig = getCacheConfig(cwd, cacheOptions);
82
- const backfillLogger = backfill.makeLogger(
83
- "warn",
84
- process.stdout,
85
- process.stderr
86
- );
87
-
88
- try {
89
- await backfill.put(cwd, hash, backfillLogger, cacheConfig);
90
- } catch (e) {
91
- // sometimes outputGlob don't match any files, so skipping this
92
- }
93
- }
@@ -1,33 +0,0 @@
1
- import { getEnvConfig, createDefaultConfig } from "backfill-config";
2
- import { Logger, makeLogger } from "backfill-logger";
3
- import { CacheOptions } from "../types/CacheOptions";
4
- import { RemoteFallbackCacheProvider } from "./RemoteFallbackCacheProvider";
5
-
6
- export function getCacheConfig(cwd: string, cacheOptions: CacheOptions) {
7
- const defaultCacheConfig = createDefaultConfig(cwd);
8
-
9
- // in lage, default mode is to CACHE locally
10
- defaultCacheConfig.cacheStorageConfig.provider = "local";
11
-
12
-
13
- const logger = makeLogger("warn");
14
- const envConfig = getEnvConfig(logger);
15
-
16
- const configWithEnvOverrides: CacheOptions = {
17
- ...defaultCacheConfig,
18
- ...cacheOptions,
19
- ...envConfig,
20
- writeRemoteCache: cacheOptions.writeRemoteCache || !!process.env.LAGE_WRITE_REMOTE_CACHE
21
- };
22
-
23
- const configWithFallback: CacheOptions = {
24
- ...configWithEnvOverrides,
25
- cacheStorageConfig: {
26
- ...configWithEnvOverrides.cacheStorageConfig,
27
- provider: (logger: Logger, cwd: string) => new RemoteFallbackCacheProvider(configWithEnvOverrides, logger, cwd),
28
- name: "remote-fallback-provider"
29
- },
30
- };
31
-
32
- return configWithFallback;
33
- }
@@ -1,9 +0,0 @@
1
- export const CacheHashTask = "backfillHash";
2
- export const CacheFetchTask = "backfillFetch";
3
- export const CachePutTask = "backfillPut";
4
-
5
- export function isCacheTask(task: string) {
6
- return (
7
- task === CacheHashTask || task === CacheFetchTask || task === CachePutTask
8
- );
9
- }
package/src/cache/salt.ts DELETED
@@ -1,52 +0,0 @@
1
- import * as path from "path";
2
- import * as crypto from "crypto";
3
- import * as fg from "fast-glob";
4
- import * as fs from "fs";
5
-
6
- let envHash: string[];
7
-
8
- export function salt(
9
- environmentGlobFiles: string[],
10
- command: string,
11
- repoRoot: string,
12
- customKey: string = ""
13
- ): string {
14
- return hashStrings([...getEnvHash(environmentGlobFiles, repoRoot), command, customKey]);
15
- }
16
-
17
- function getEnvHash(environmentGlobFiles: string[], repoRoot: string) {
18
- if (!envHash) {
19
- const newline = /\r\n|\r|\n/g;
20
- const LF = "\n";
21
- const files = fg.sync(environmentGlobFiles, {
22
- cwd: repoRoot,
23
- });
24
-
25
- files.sort((a, b) => a.localeCompare(b));
26
-
27
- const hashes = files.map((file) => {
28
- const hasher = crypto.createHash("sha1");
29
- hasher.update(file);
30
-
31
- const fileBuffer = fs.readFileSync(path.join(repoRoot, file));
32
- const data = fileBuffer.toString().replace(newline, LF);
33
- hasher.update(data);
34
-
35
- return hasher.digest("hex");
36
- });
37
-
38
- envHash = hashes;
39
- }
40
-
41
- return envHash;
42
- }
43
-
44
- function hashStrings(strings: string | string[]): string {
45
- const hasher = crypto.createHash("sha1");
46
- const anArray = typeof strings === "string" ? [strings] : strings;
47
- const elements = [...anArray];
48
- elements.sort((a, b) => a.localeCompare(b));
49
- elements.forEach((element) => hasher.update(element));
50
-
51
- return hasher.digest("hex");
52
- }
package/src/cli.ts DELETED
@@ -1,47 +0,0 @@
1
- import { getConfig } from "./config/getConfig";
2
- import { init } from "./command/init";
3
- import { run } from "./command/run";
4
- import { showHelp } from "./showHelp";
5
- import { logger } from "./logger";
6
- import { info } from "./command/info";
7
- import { initReporters } from "./logger/initReporters";
8
- import { version } from "./command/version";
9
- import { cache } from "./command/cache";
10
- import { worker } from "./command/worker";
11
-
12
- // Parse CLI args
13
- const cwd = process.cwd();
14
- try {
15
- const config = getConfig(cwd);
16
- const reporters = initReporters(config);
17
-
18
- switch (config.command[0]) {
19
- case "cache":
20
- cache(cwd, config);
21
- break;
22
-
23
- case "init":
24
- init(cwd);
25
- break;
26
-
27
- case "info":
28
- info(cwd, config);
29
- break;
30
-
31
- case "version":
32
- version();
33
- break;
34
-
35
- case "experiment-worker":
36
- logger.info(`Lage worker - let's make it`);
37
- worker(cwd, config);
38
- break;
39
-
40
- default:
41
- logger.info(`Lage task runner - let's make it`);
42
- run(cwd, config, reporters);
43
- break;
44
- }
45
- } catch (e) {
46
- showHelp(e && (e as any).message);
47
- }
@@ -1,81 +0,0 @@
1
- import fs, { Stats } from "fs";
2
- import path from "path";
3
- import { PackageInfo } from "workspace-tools";
4
- import { logger } from "../logger";
5
- import { Config } from "../types/Config";
6
- import { getWorkspace } from "../workspace/getWorkspace";
7
-
8
- const MS_IN_A_DAY = 1000 * 60 * 60 * 24;
9
-
10
- export async function cache(cwd: string, config: Config) {
11
- if (config.clear) {
12
- logger.info("clearing cache, this may take a while");
13
- clearCache(cwd, config);
14
- logger.info("done!");
15
- } else if (config.prune) {
16
- logger.info("pruning cache, this may take a while");
17
- pruneCache(cwd, config);
18
- logger.info("done!");
19
- } else {
20
- logger.info("No options given to cache command. Try --clear or --prune");
21
- }
22
- }
23
-
24
- function clearCache(cwd: string, config: Config) {
25
- const workspace = getWorkspace(cwd, config);
26
- const { allPackages } = workspace;
27
- for (const info of Object.values(allPackages)) {
28
- const cachePath = getCachePath(info);
29
-
30
- if (fs.existsSync(cachePath)) {
31
- const entries = fs.readdirSync(cachePath);
32
- for (const entry of entries) {
33
- logger.verbose(`clearing cache for ${info.name}`);
34
-
35
- const entryPath = path.join(cachePath, entry);
36
- const entryStat = fs.statSync(entryPath);
37
- remove(entryPath, entryStat);
38
- }
39
- }
40
- }
41
- }
42
-
43
- function pruneCache(cwd: string, config: Config) {
44
- const prunePeriod = parseInt(config.prune) || 30;
45
- const now = new Date();
46
- const workspace = getWorkspace(cwd, config);
47
- const { allPackages } = workspace;
48
- for (const info of Object.values(allPackages)) {
49
- const cachePath = getCachePath(info);
50
-
51
- if (fs.existsSync(cachePath)) {
52
- const entries = fs.readdirSync(cachePath);
53
-
54
- for (const entry of entries) {
55
- const entryPath = path.join(cachePath, entry);
56
- const entryStat = fs.statSync(entryPath);
57
-
58
- logger.verbose(`clearing cache for ${info.name}`);
59
-
60
- if (
61
- now.getTime() - entryStat.mtime.getTime() >
62
- prunePeriod * MS_IN_A_DAY
63
- ) {
64
- remove(entryPath, entryStat);
65
- }
66
- }
67
- }
68
- }
69
- }
70
-
71
- function getCachePath(info: PackageInfo) {
72
- return path.join(info.packageJsonPath, "../node_modules/.cache/backfill");
73
- }
74
-
75
- function remove(entryPath: string, entryStat: Stats) {
76
- if (entryStat.isDirectory()) {
77
- fs.rmdirSync(entryPath, { recursive: true });
78
- } else {
79
- fs.unlinkSync(entryPath);
80
- }
81
- }