@lage-run/cli 0.5.6 → 0.6.0

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.
package/CHANGELOG.json CHANGED
@@ -2,7 +2,76 @@
2
2
  "name": "@lage-run/cli",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 08 Dec 2022 00:49:16 GMT",
5
+ "date": "Wed, 18 Jan 2023 18:18:13 GMT",
6
+ "tag": "@lage-run/cli_v0.6.0",
7
+ "version": "0.6.0",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "author": "kchau@microsoft.com",
12
+ "package": "@lage-run/cli",
13
+ "commit": "71b5b1452ee25148a637894d1bf99cf1cc6a80a7",
14
+ "comment": "Using lage for prune and clear on cache and get reporter in shape for ADO"
15
+ },
16
+ {
17
+ "author": "beachball",
18
+ "package": "@lage-run/cli",
19
+ "comment": "Bump @lage-run/scheduler to v0.8.0",
20
+ "commit": "71b5b1452ee25148a637894d1bf99cf1cc6a80a7"
21
+ },
22
+ {
23
+ "author": "beachball",
24
+ "package": "@lage-run/cli",
25
+ "comment": "Bump @lage-run/scheduler-types to v0.3.0",
26
+ "commit": "71b5b1452ee25148a637894d1bf99cf1cc6a80a7"
27
+ },
28
+ {
29
+ "author": "beachball",
30
+ "package": "@lage-run/cli",
31
+ "comment": "Bump @lage-run/reporters to v0.3.0",
32
+ "commit": "71b5b1452ee25148a637894d1bf99cf1cc6a80a7"
33
+ }
34
+ ]
35
+ }
36
+ },
37
+ {
38
+ "date": "Thu, 05 Jan 2023 00:40:50 GMT",
39
+ "tag": "@lage-run/cli_v0.5.7",
40
+ "version": "0.5.7",
41
+ "comments": {
42
+ "patch": [
43
+ {
44
+ "author": "beachball",
45
+ "package": "@lage-run/cli",
46
+ "comment": "Bump @lage-run/scheduler to v0.7.3",
47
+ "commit": "961843bef658c51312e02498554ad338e467e1a7"
48
+ },
49
+ {
50
+ "author": "beachball",
51
+ "package": "@lage-run/cli",
52
+ "comment": "Bump @lage-run/reporters to v0.2.44",
53
+ "commit": "961843bef658c51312e02498554ad338e467e1a7"
54
+ }
55
+ ]
56
+ }
57
+ },
58
+ {
59
+ "date": "Fri, 16 Dec 2022 03:09:11 GMT",
60
+ "tag": "@lage-run/cli_v0.5.6",
61
+ "version": "0.5.6",
62
+ "comments": {
63
+ "none": [
64
+ {
65
+ "author": "email not defined",
66
+ "package": "@lage-run/cli",
67
+ "commit": "4031d034338244c2947152486a6dffd3d1917a29",
68
+ "comment": "Update devDependency backfill-config to v6.3.1"
69
+ }
70
+ ]
71
+ }
72
+ },
73
+ {
74
+ "date": "Thu, 08 Dec 2022 00:49:28 GMT",
6
75
  "tag": "@lage-run/cli_v0.5.6",
7
76
  "version": "0.5.6",
8
77
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,32 @@
1
1
  # Change Log - @lage-run/cli
2
2
 
3
- This log was last generated on Thu, 08 Dec 2022 00:49:16 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 18 Jan 2023 18:18:13 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.6.0
8
+
9
+ Wed, 18 Jan 2023 18:18:13 GMT
10
+
11
+ ### Minor changes
12
+
13
+ - Using lage for prune and clear on cache and get reporter in shape for ADO (kchau@microsoft.com)
14
+ - Bump @lage-run/scheduler to v0.8.0
15
+ - Bump @lage-run/scheduler-types to v0.3.0
16
+ - Bump @lage-run/reporters to v0.3.0
17
+
18
+ ## 0.5.7
19
+
20
+ Thu, 05 Jan 2023 00:40:50 GMT
21
+
22
+ ### Patches
23
+
24
+ - Bump @lage-run/scheduler to v0.7.3
25
+ - Bump @lage-run/reporters to v0.2.44
26
+
7
27
  ## 0.5.6
8
28
 
9
- Thu, 08 Dec 2022 00:49:16 GMT
29
+ Thu, 08 Dec 2022 00:49:28 GMT
10
30
 
11
31
  ### Patches
12
32
 
@@ -22,9 +22,20 @@ async function cacheAction(options, command) {
22
22
  const logger = (0, _logger.default)();
23
23
  (0, _reporters.initializeReporters)(logger, options);
24
24
  if (options.clear) {
25
- return await (0, _clearCacheJs.clearCache)(process.cwd(), config.cacheOptions.internalCacheFolder, logger);
25
+ return await (0, _clearCacheJs.clearCache)({
26
+ cwd: process.cwd(),
27
+ internalCacheFolder: config.cacheOptions.internalCacheFolder,
28
+ logger,
29
+ concurrency: options.concurrency
30
+ });
26
31
  } else if (options.prune) {
27
- return await (0, _pruneCacheJs.pruneCache)(options.prune, process.cwd(), config.cacheOptions.internalCacheFolder, logger);
32
+ return await (0, _pruneCacheJs.pruneCache)({
33
+ pruneDays: options.prune,
34
+ cwd: process.cwd(),
35
+ internalCacheFolder: config.cacheOptions.internalCacheFolder,
36
+ logger,
37
+ concurrency: options.concurrency
38
+ });
28
39
  }
29
40
  command.help();
30
41
  }
@@ -1,2 +1,8 @@
1
1
  import type { Logger } from "@lage-run/logger";
2
- export declare function clearCache(cwd: string, internalCacheFolder: string, logger: Logger): Promise<void>;
2
+ export interface ClearCacheOptions {
3
+ cwd: string;
4
+ internalCacheFolder: string;
5
+ logger: Logger;
6
+ concurrency: number;
7
+ }
8
+ export declare function clearCache(options: ClearCacheOptions): Promise<void>;
@@ -7,38 +7,67 @@ Object.defineProperty(exports, "clearCache", {
7
7
  get: ()=>clearCache
8
8
  });
9
9
  const _cacheDirJs = require("./cacheDir.js");
10
+ const _getConfigJs = require("../../config/getConfig.js");
10
11
  const _workspaceTools = require("workspace-tools");
11
- const _promises = require("fs/promises");
12
- const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
12
+ const _scheduler = require("@lage-run/scheduler");
13
+ const _targetGraph = require("@lage-run/target-graph");
13
14
  const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
15
+ const _getConcurrencyJs = require("../../config/getConcurrency.js");
14
16
  function _interopRequireDefault(obj) {
15
17
  return obj && obj.__esModule ? obj : {
16
18
  default: obj
17
19
  };
18
20
  }
19
- async function clearCache(cwd, internalCacheFolder, logger) {
21
+ async function clearCache(options) {
22
+ const { logger , cwd , internalCacheFolder } = options;
23
+ const config = await (0, _getConfigJs.getConfig)(cwd);
20
24
  const workspaceRoot = (0, _workspaceTools.getWorkspaceRoot)(cwd);
25
+ const concurrency = (0, _getConcurrencyJs.getConcurrency)(options.concurrency, config.concurrency);
21
26
  if (!workspaceRoot) {
22
27
  return;
23
28
  }
29
+ const graphBuilder = new _targetGraph.TargetGraphBuilder();
24
30
  const workspaces = (0, _workspaceTools.getWorkspaces)(workspaceRoot);
25
31
  for (const workspace of workspaces){
26
- logger.info(`clear cache for ${workspace.name}`);
27
32
  const cachePath = (0, _cacheDirJs.getCacheDir)(workspace.path, internalCacheFolder);
28
33
  const logOutputCachePath = _path.default.join(workspace.path, "node_modules/.cache/lage/output/");
29
- await Promise.all([
30
- clearPath(cachePath),
31
- clearPath(logOutputCachePath)
32
- ]);
33
- }
34
- }
35
- async function clearPath(cachePath) {
36
- if (_fs.default.existsSync(cachePath)) {
37
- const entries = _fs.default.readdirSync(cachePath);
38
- for (const entry of entries){
39
- const entryPath = _path.default.join(cachePath, entry);
40
- const entryStat = await (0, _promises.stat)(entryPath);
41
- await (0, _cacheDirJs.removeCacheEntry)(entryPath, entryStat);
42
- }
34
+ graphBuilder.addTarget({
35
+ packageName: workspace.name,
36
+ cwd: workspace.path,
37
+ dependencies: [],
38
+ dependents: [],
39
+ id: `${workspace.name}#clearCache`,
40
+ label: `Clearing Cache for ${workspace.name}`,
41
+ task: "clearCache",
42
+ type: "worker",
43
+ depSpecs: [],
44
+ options: {
45
+ clearPaths: [
46
+ cachePath,
47
+ logOutputCachePath
48
+ ]
49
+ }
50
+ });
43
51
  }
52
+ const graph = graphBuilder.build();
53
+ const scheduler = new _scheduler.SimpleScheduler({
54
+ logger,
55
+ concurrency,
56
+ continueOnError: true,
57
+ shouldCache: false,
58
+ shouldResetCache: false,
59
+ maxWorkersPerTask: new Map(),
60
+ runners: {
61
+ worker: {
62
+ script: require.resolve("./runners/ClearCacheRunner.js"),
63
+ options: {}
64
+ }
65
+ },
66
+ workerIdleMemoryLimit: config.workerIdleMemoryLimit
67
+ });
68
+ const summary = await scheduler.run(workspaceRoot, graph);
69
+ await scheduler.cleanup();
70
+ logger.reporters.forEach((reporter)=>{
71
+ reporter.summarize(summary);
72
+ });
44
73
  }
@@ -1,2 +1,9 @@
1
1
  import type { Logger } from "@lage-run/logger";
2
- export declare function pruneCache(pruneDays: number, cwd: string, internalCacheFolder: string, logger: Logger): Promise<void>;
2
+ export interface PruneCacheOptions {
3
+ cwd: string;
4
+ internalCacheFolder: string;
5
+ logger: Logger;
6
+ concurrency: number;
7
+ pruneDays: number;
8
+ }
9
+ export declare function pruneCache(options: PruneCacheOptions): Promise<void>;
@@ -6,40 +6,72 @@ Object.defineProperty(exports, "pruneCache", {
6
6
  enumerable: true,
7
7
  get: ()=>pruneCache
8
8
  });
9
- const _promises = require("fs/promises");
10
- const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
11
9
  const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
12
10
  const _cacheDirJs = require("./cacheDir.js");
13
11
  const _workspaceTools = require("workspace-tools");
12
+ const _getConfigJs = require("../../config/getConfig.js");
13
+ const _getConcurrencyJs = require("../../config/getConcurrency.js");
14
+ const _targetGraph = require("@lage-run/target-graph");
15
+ const _scheduler = require("@lage-run/scheduler");
14
16
  function _interopRequireDefault(obj) {
15
17
  return obj && obj.__esModule ? obj : {
16
18
  default: obj
17
19
  };
18
20
  }
19
- const MS_IN_A_DAY = 1000 * 60 * 60 * 24;
20
- async function pruneCache(pruneDays, cwd, internalCacheFolder, logger) {
21
+ async function pruneCache(options) {
22
+ const { logger , cwd , pruneDays , internalCacheFolder } = options;
23
+ const config = await (0, _getConfigJs.getConfig)(cwd);
24
+ const workspaceRoot = (0, _workspaceTools.getWorkspaceRoot)(cwd);
25
+ const concurrency = (0, _getConcurrencyJs.getConcurrency)(options.concurrency, config.concurrency);
26
+ if (!workspaceRoot) {
27
+ return;
28
+ }
29
+ const graphBuilder = new _targetGraph.TargetGraphBuilder();
30
+ const workspaces = (0, _workspaceTools.getWorkspaces)(workspaceRoot);
21
31
  const prunePeriod = pruneDays || 30;
22
32
  const now = new Date().getTime();
23
- const workspaces = (0, _workspaceTools.getWorkspaces)(cwd);
24
33
  for (const workspace of workspaces){
25
- logger.info(`prune cache for ${workspace.name} older than ${prunePeriod} days`);
26
34
  const cachePath = (0, _cacheDirJs.getCacheDir)(workspace.path, internalCacheFolder);
27
35
  const logOutputCachePath = _path.default.join(workspace.path, "node_modules/.cache/lage/output/");
28
- await Promise.all([
29
- prunePath(cachePath, prunePeriod, now),
30
- prunePath(logOutputCachePath, prunePeriod, now)
31
- ]);
32
- }
33
- }
34
- async function prunePath(cachePath, days, now) {
35
- if (_fs.default.existsSync(cachePath)) {
36
- const entries = _fs.default.readdirSync(cachePath);
37
- for (const entry of entries){
38
- const entryPath = _path.default.join(cachePath, entry);
39
- const entryStat = await (0, _promises.stat)(entryPath);
40
- if (now - entryStat.mtime.getTime() > days * MS_IN_A_DAY) {
41
- await (0, _cacheDirJs.removeCacheEntry)(entryPath, entryStat);
36
+ graphBuilder.addTarget({
37
+ packageName: workspace.name,
38
+ cwd: workspace.path,
39
+ dependencies: [],
40
+ dependents: [],
41
+ id: `${workspace.name}#pruneCache`,
42
+ label: `Pruning Cache for ${workspace.name}`,
43
+ task: "pruneCache",
44
+ type: "worker",
45
+ depSpecs: [],
46
+ options: {
47
+ clearPaths: [
48
+ cachePath,
49
+ logOutputCachePath
50
+ ],
51
+ now,
52
+ prunePeriod
42
53
  }
43
- }
54
+ });
44
55
  }
56
+ const graph = graphBuilder.build();
57
+ const scheduler = new _scheduler.SimpleScheduler({
58
+ logger,
59
+ concurrency,
60
+ continueOnError: true,
61
+ shouldCache: false,
62
+ shouldResetCache: false,
63
+ maxWorkersPerTask: new Map(),
64
+ runners: {
65
+ worker: {
66
+ script: require.resolve("./runners/PruneCacheRunner.js"),
67
+ options: {}
68
+ }
69
+ },
70
+ workerIdleMemoryLimit: config.workerIdleMemoryLimit
71
+ });
72
+ const summary = await scheduler.run(workspaceRoot, graph);
73
+ await scheduler.cleanup();
74
+ logger.reporters.forEach((reporter)=>{
75
+ reporter.summarize(summary);
76
+ });
45
77
  }
@@ -0,0 +1,5 @@
1
+ import type { TargetRunner, TargetRunnerOptions } from "@lage-run/scheduler-types";
2
+ export declare class ClearCacheRunner implements TargetRunner {
3
+ shouldRun(): Promise<boolean>;
4
+ run(runOptions: TargetRunnerOptions): Promise<void>;
5
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "ClearCacheRunner", {
6
+ enumerable: true,
7
+ get: ()=>ClearCacheRunner
8
+ });
9
+ const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
10
+ const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
11
+ const _promises = require("fs/promises");
12
+ const _cacheDirJs = require("../cacheDir.js");
13
+ function _interopRequireDefault(obj) {
14
+ return obj && obj.__esModule ? obj : {
15
+ default: obj
16
+ };
17
+ }
18
+ class ClearCacheRunner {
19
+ async shouldRun() {
20
+ return true;
21
+ }
22
+ async run(runOptions) {
23
+ const { target } = runOptions;
24
+ const { clearPaths } = target.options;
25
+ for (const cachePath of clearPaths){
26
+ if (_fs.default.existsSync(cachePath)) {
27
+ const entries = _fs.default.readdirSync(cachePath);
28
+ for (const entry of entries){
29
+ const entryPath = _path.default.join(cachePath, entry);
30
+ const entryStat = await (0, _promises.stat)(entryPath);
31
+ await (0, _cacheDirJs.removeCacheEntry)(entryPath, entryStat);
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,5 @@
1
+ import type { TargetRunner, TargetRunnerOptions } from "@lage-run/scheduler-types";
2
+ export declare class PruneCacheRunner implements TargetRunner {
3
+ shouldRun(): Promise<boolean>;
4
+ run(runOptions: TargetRunnerOptions): Promise<void>;
5
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "PruneCacheRunner", {
6
+ enumerable: true,
7
+ get: ()=>PruneCacheRunner
8
+ });
9
+ const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
10
+ const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
11
+ const _promises = require("fs/promises");
12
+ const _cacheDirJs = require("../cacheDir.js");
13
+ function _interopRequireDefault(obj) {
14
+ return obj && obj.__esModule ? obj : {
15
+ default: obj
16
+ };
17
+ }
18
+ const MS_IN_A_DAY = 1000 * 60 * 60 * 24;
19
+ class PruneCacheRunner {
20
+ async shouldRun() {
21
+ return true;
22
+ }
23
+ async run(runOptions) {
24
+ const { target } = runOptions;
25
+ const { clearPaths , prunePeriod , now } = target.options;
26
+ for (const cachePath of clearPaths){
27
+ if (_fs.default.existsSync(cachePath)) {
28
+ const entries = _fs.default.readdirSync(cachePath);
29
+ for (const entry of entries){
30
+ const entryPath = _path.default.join(cachePath, entry);
31
+ const entryStat = await (0, _promises.stat)(entryPath);
32
+ if (now - entryStat.mtime.getTime() > prunePeriod * MS_IN_A_DAY) {
33
+ await (0, _cacheDirJs.removeCacheEntry)(entryPath, entryStat);
34
+ }
35
+ }
36
+ }
37
+ }
38
+ }
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lage-run/cli",
3
- "version": "0.5.6",
3
+ "version": "0.6.0",
4
4
  "description": "Command Line Interface for Lage",
5
5
  "repository": {
6
6
  "url": "https://github.com/microsoft/lage"
@@ -20,11 +20,11 @@
20
20
  "dependencies": {
21
21
  "@lage-run/find-npm-client": "^0.1.4",
22
22
  "@lage-run/logger": "^1.2.2",
23
- "@lage-run/scheduler": "^0.7.2",
24
- "@lage-run/scheduler-types": "^0.2.10",
23
+ "@lage-run/scheduler": "^0.8.0",
24
+ "@lage-run/scheduler-types": "^0.3.0",
25
25
  "@lage-run/target-graph": "^0.6.1",
26
26
  "@lage-run/cache": "^0.2.3",
27
- "@lage-run/reporters": "^0.2.43",
27
+ "@lage-run/reporters": "^0.3.0",
28
28
  "commander": "^9.4.0",
29
29
  "workspace-tools": "^0.29.0",
30
30
  "chokidar": "3.5.3",
@@ -34,7 +34,7 @@
34
34
  "devDependencies": {
35
35
  "monorepo-scripts": "*",
36
36
  "@lage-run/monorepo-fixture": "*",
37
- "backfill-config": "6.3.0"
37
+ "backfill-config": "6.3.1"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"