@lage-run/cli 0.19.2 → 0.20.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,103 @@
2
2
  "name": "@lage-run/cli",
3
3
  "entries": [
4
4
  {
5
- "date": "Wed, 11 Sep 2024 20:30:17 GMT",
5
+ "date": "Fri, 13 Sep 2024 18:04:33 GMT",
6
+ "version": "0.20.0",
7
+ "tag": "@lage-run/cli_v0.20.0",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "author": "kchau@microsoft.com",
12
+ "package": "@lage-run/cli",
13
+ "commit": "924b93e66ae3cc60effa7cfc1f5254e1e59e9969",
14
+ "comment": "adds a lage-server binary that listens and executes and auto shutsdown"
15
+ },
16
+ {
17
+ "author": "beachball",
18
+ "package": "@lage-run/cli",
19
+ "comment": "Bump @lage-run/cache to v1.3.3",
20
+ "commit": "not available"
21
+ },
22
+ {
23
+ "author": "beachball",
24
+ "package": "@lage-run/cli",
25
+ "comment": "Bump @lage-run/config to v0.4.2",
26
+ "commit": "not available"
27
+ },
28
+ {
29
+ "author": "beachball",
30
+ "package": "@lage-run/cli",
31
+ "comment": "Bump @lage-run/hasher to v1.3.4",
32
+ "commit": "not available"
33
+ },
34
+ {
35
+ "author": "beachball",
36
+ "package": "@lage-run/cli",
37
+ "comment": "Bump @lage-run/reporters to v1.2.10",
38
+ "commit": "not available"
39
+ },
40
+ {
41
+ "author": "beachball",
42
+ "package": "@lage-run/cli",
43
+ "comment": "Bump @lage-run/rpc to v1.2.0",
44
+ "commit": "not available"
45
+ },
46
+ {
47
+ "author": "beachball",
48
+ "package": "@lage-run/cli",
49
+ "comment": "Bump @lage-run/runners to v1.0.2",
50
+ "commit": "not available"
51
+ },
52
+ {
53
+ "author": "beachball",
54
+ "package": "@lage-run/cli",
55
+ "comment": "Bump @lage-run/scheduler to v1.2.14",
56
+ "commit": "not available"
57
+ },
58
+ {
59
+ "author": "beachball",
60
+ "package": "@lage-run/cli",
61
+ "comment": "Bump @lage-run/scheduler-types to v0.3.15",
62
+ "commit": "not available"
63
+ },
64
+ {
65
+ "author": "beachball",
66
+ "package": "@lage-run/cli",
67
+ "comment": "Bump @lage-run/target-graph to v0.8.10",
68
+ "commit": "not available"
69
+ }
70
+ ]
71
+ }
72
+ },
73
+ {
74
+ "date": "Wed, 11 Sep 2024 20:52:15 GMT",
75
+ "version": "0.19.3",
76
+ "tag": "@lage-run/cli_v0.19.3",
77
+ "comments": {
78
+ "patch": [
79
+ {
80
+ "author": "renovate@whitesourcesoftware.com",
81
+ "package": "@lage-run/cli",
82
+ "commit": "9ce7c7fcd8001c4c1ec3141097aa5b89f8bf7b37",
83
+ "comment": "Update dependency fast-glob to v3.3.2"
84
+ },
85
+ {
86
+ "author": "beachball",
87
+ "package": "@lage-run/cli",
88
+ "comment": "Bump @lage-run/hasher to v1.3.3",
89
+ "commit": "not available"
90
+ },
91
+ {
92
+ "author": "beachball",
93
+ "package": "@lage-run/cli",
94
+ "comment": "Bump @lage-run/scheduler to v1.2.13",
95
+ "commit": "not available"
96
+ }
97
+ ]
98
+ }
99
+ },
100
+ {
101
+ "date": "Wed, 11 Sep 2024 20:30:48 GMT",
6
102
  "version": "0.19.2",
7
103
  "tag": "@lage-run/cli_v0.19.2",
8
104
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,39 @@
1
1
  # Change Log - @lage-run/cli
2
2
 
3
- This log was last generated on Wed, 11 Sep 2024 20:30:17 GMT and should not be manually modified.
3
+ <!-- This log was last generated on Fri, 13 Sep 2024 18:04:33 GMT and should not be manually modified. -->
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.20.0
8
+
9
+ Fri, 13 Sep 2024 18:04:33 GMT
10
+
11
+ ### Minor changes
12
+
13
+ - adds a lage-server binary that listens and executes and auto shutsdown (kchau@microsoft.com)
14
+ - Bump @lage-run/cache to v1.3.3
15
+ - Bump @lage-run/config to v0.4.2
16
+ - Bump @lage-run/hasher to v1.3.4
17
+ - Bump @lage-run/reporters to v1.2.10
18
+ - Bump @lage-run/rpc to v1.2.0
19
+ - Bump @lage-run/runners to v1.0.2
20
+ - Bump @lage-run/scheduler to v1.2.14
21
+ - Bump @lage-run/scheduler-types to v0.3.15
22
+ - Bump @lage-run/target-graph to v0.8.10
23
+
24
+ ## 0.19.3
25
+
26
+ Wed, 11 Sep 2024 20:52:15 GMT
27
+
28
+ ### Patches
29
+
30
+ - Update dependency fast-glob to v3.3.2 (renovate@whitesourcesoftware.com)
31
+ - Bump @lage-run/hasher to v1.3.3
32
+ - Bump @lage-run/scheduler to v1.2.13
33
+
7
34
  ## 0.19.2
8
35
 
9
- Wed, 11 Sep 2024 20:30:17 GMT
36
+ Wed, 11 Sep 2024 20:30:48 GMT
10
37
 
11
38
  ### Patches
12
39
 
package/lib/cli.js CHANGED
@@ -10,7 +10,6 @@ const _index2 = require("./commands/affected/index.js");
10
10
  const _index3 = require("./commands/init/index.js");
11
11
  const _index4 = require("./commands/info/index.js");
12
12
  const _index5 = require("./commands/exec/index.js");
13
- const _index6 = require("./commands/server/index.js");
14
13
  async function main() {
15
14
  const program = new _commander.Command();
16
15
  program.addCommand(_index.runCommand, {
@@ -21,7 +20,6 @@ async function main() {
21
20
  program.addCommand(_index3.initCommand);
22
21
  program.addCommand(_index4.infoCommand);
23
22
  program.addCommand(_index5.execCommand);
24
- program.addCommand(_index6.serverCommand);
25
23
  await program.parseAsync(process.argv);
26
24
  }
27
25
  main().catch((err)=>{
@@ -11,7 +11,6 @@ Object.defineProperty(exports, "execAction", {
11
11
  const _logger = /*#__PURE__*/ _interop_require_default(require("@lage-run/logger"));
12
12
  const _initializeReporters = require("../initializeReporters.js");
13
13
  const _executeInProcess = require("./executeInProcess.js");
14
- const _executeRemotely = require("./executeRemotely.js");
15
14
  function _interop_require_default(obj) {
16
15
  return obj && obj.__esModule ? obj : {
17
16
  default: obj
@@ -22,18 +21,10 @@ async function execAction(options, command) {
22
21
  options.logLevel = options.logLevel ?? "info";
23
22
  options.reporter = options.reporter ?? "json";
24
23
  (0, _initializeReporters.initializeReporters)(logger, options);
25
- if (options.server) {
26
- await (0, _executeRemotely.executeRemotely)({
27
- server: typeof options.server === "boolean" ? "localhost:5332" : options.server,
28
- logger,
29
- args: command.args
30
- });
31
- } else {
32
- await (0, _executeInProcess.executeInProcess)({
33
- logger,
34
- args: command.args,
35
- cwd: options.cwd,
36
- nodeArg: options.nodeArg
37
- });
38
- }
24
+ await (0, _executeInProcess.executeInProcess)({
25
+ logger,
26
+ args: command.args,
27
+ cwd: options.cwd,
28
+ nodeArg: options.nodeArg
29
+ });
39
30
  }
@@ -12,5 +12,4 @@ const _commander = require("commander");
12
12
  const _action = require("./action.js");
13
13
  const _addLoggerOptions = require("../addLoggerOptions.js");
14
14
  const execCommand = new _commander.Command("exec");
15
- execCommand.option("--server [server:port]", "Execute on lage server via RPC", "localhost:5332");
16
15
  (0, _addLoggerOptions.addLoggerOptions)(execCommand).action(_action.execAction);
@@ -4,6 +4,8 @@ interface WorkerOptions extends ReporterInitOptions {
4
4
  nodeArg?: string[];
5
5
  port?: number;
6
6
  host?: string;
7
+ timeout?: number;
8
+ shutdown: boolean;
7
9
  }
8
- export declare function workerAction(options: WorkerOptions, command: Command): Promise<void>;
10
+ export declare function serverAction(options: WorkerOptions, command: Command): Promise<void>;
9
11
  export {};
@@ -2,68 +2,96 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "workerAction", {
5
+ Object.defineProperty(exports, "serverAction", {
6
6
  enumerable: true,
7
7
  get: function() {
8
- return workerAction;
8
+ return serverAction;
9
9
  }
10
10
  });
11
- const _config = require("@lage-run/config");
12
11
  const _logger = /*#__PURE__*/ _interop_require_default(require("@lage-run/logger"));
13
12
  const _initializeReporters = require("../initializeReporters.js");
14
13
  const _lageService = require("./lageService.js");
15
- const _workspacetools = require("workspace-tools");
16
- const _createTargetGraph = require("../run/createTargetGraph.js");
17
- const _targetId = require("@lage-run/target-graph/lib/targetId.js");
14
+ const _filterArgsForTasks = require("../run/filterArgsForTasks.js");
15
+ const _rpc = require("@lage-run/rpc");
18
16
  function _interop_require_default(obj) {
19
17
  return obj && obj.__esModule ? obj : {
20
18
  default: obj
21
19
  };
22
20
  }
23
- function findAllTasks(pipeline) {
24
- const tasks = new Set();
25
- for (const key of Object.keys(pipeline)){
26
- if (key.includes("#") || key.startsWith("#") || key.endsWith("//")) {
27
- const { task } = (0, _targetId.getPackageAndTask)(key);
28
- tasks.add(task);
29
- } else {
30
- tasks.add(key);
21
+ async function tryCreateClient(host, port) {
22
+ const client = (0, _rpc.createClient)({
23
+ baseUrl: `http://${host}:${port}`,
24
+ httpVersion: "1.1"
25
+ });
26
+ try {
27
+ const success = await client.ping({});
28
+ if (success.pong) {
29
+ return client;
30
+ }
31
+ } catch (e) {
32
+ if (e instanceof _rpc.ConnectError) {
33
+ return undefined;
31
34
  }
35
+ throw e;
36
+ }
37
+ return undefined;
38
+ }
39
+ async function executeOnServer(args, client, logger) {
40
+ const task = args.length === 1 ? args[0] : args[1];
41
+ const packageName = args.length > 1 ? args[0] : undefined;
42
+ if (!task) {
43
+ throw new Error("No task provided");
32
44
  }
33
- return Array.from(tasks);
45
+ const { taskArgs } = (0, _filterArgsForTasks.filterArgsForTasks)(args ?? []);
46
+ const response = await client.runTarget({
47
+ packageName,
48
+ task,
49
+ taskArgs
50
+ });
51
+ logger.info(`Task ${response.packageName} #${response.task} exited with code ${response.exitCode} `);
52
+ process.exitCode = response.exitCode;
34
53
  }
35
- async function workerAction(options, command) {
36
- const { port =5332 , host ="localhost" } = options;
37
- const cwd = process.cwd();
54
+ async function serverAction(options, command) {
55
+ const { port =5332 , host ="localhost" , timeout =1 } = options;
38
56
  const logger = (0, _logger.default)();
39
57
  options.logLevel = options.logLevel ?? "info";
40
58
  options.reporter = options.reporter ?? "json";
41
59
  (0, _initializeReporters.initializeReporters)(logger, options);
42
- const rpc = (await import("@lage-run/rpc")).default;
43
- const config = await (0, _config.getConfig)(cwd);
44
- const { pipeline } = config;
45
- const root = (0, _workspacetools.getWorkspaceRoot)(cwd);
46
- const packageInfos = (0, _workspacetools.getPackageInfos)(root);
47
- const tasks = findAllTasks(pipeline);
48
- const targetGraph = (0, _createTargetGraph.createTargetGraph)({
49
- logger,
50
- root,
51
- dependencies: false,
52
- dependents: false,
53
- ignore: [],
54
- pipeline,
55
- repoWideChanges: config.repoWideChanges,
56
- scope: [],
57
- since: "",
58
- outputs: config.cacheOptions.outputGlob,
59
- tasks,
60
- packageInfos
61
- });
62
- const lageService = await (0, _lageService.createLageService)(targetGraph, logger, config.npmClient, options.concurrency ?? config.concurrency);
63
- const server = await rpc.createServer(lageService);
64
- logger.info(`Server listening on http://${host}:${port}`);
65
- await server.listen({
66
- host,
67
- port
68
- });
60
+ const client = await tryCreateClient(host, port);
61
+ if (client) {
62
+ logger.info(`Executing on server http://${host}:${port}`);
63
+ const args = command.args;
64
+ await executeOnServer(args, client, logger);
65
+ } else {
66
+ logger.info(`Starting server on http://${host}:${port}`);
67
+ const abortController = new AbortController();
68
+ const lageService = await (0, _lageService.createLageService)(process.cwd(), abortController, logger, options.concurrency);
69
+ const server = await (0, _rpc.createServer)(lageService, abortController);
70
+ server.addHook("onRequest", (req, res, next)=>{
71
+ resetTimer(logger, timeout, abortController, server);
72
+ next();
73
+ });
74
+ await server.listen({
75
+ host,
76
+ port
77
+ });
78
+ logger.info(`Server listening on http://${host}:${port}, timeout in ${timeout} seconds`);
79
+ const client = await tryCreateClient(host, port);
80
+ if (!client) {
81
+ throw new Error("Server could not be reached");
82
+ }
83
+ const args = command.args;
84
+ await executeOnServer(args, client, logger);
85
+ }
86
+ }
87
+ let timeoutHandle;
88
+ function resetTimer(logger, timeout, abortController, server) {
89
+ if (timeoutHandle) {
90
+ clearTimeout(timeoutHandle);
91
+ }
92
+ timeoutHandle = setTimeout(()=>{
93
+ logger.info(`Server timed out after ${timeout} seconds`);
94
+ abortController.abort();
95
+ server.close();
96
+ }, timeout * 1000);
69
97
  }
@@ -21,4 +21,5 @@ const serverCommand = new _commander.Command("server");
21
21
  serverCommand.option("-c|--concurrency <number>", "max jobs to run at a time", (v)=>parseInt(v), _os.default.cpus().length - 1);
22
22
  serverCommand.option("-h|--host <host>", "lage server host", "localhost");
23
23
  serverCommand.option("-p|--port <port>", "lage worker server port", (v)=>parseInt(v), 5332);
24
- (0, _addLoggerOptions.addLoggerOptions)(serverCommand).action(_action.workerAction);
24
+ serverCommand.option("-t|--timeout <seconds>", "lage server autoshutoff timeout", (v)=>parseInt(v), 1 * 60);
25
+ (0, _addLoggerOptions.addLoggerOptions)(serverCommand).action(_action.serverAction);
@@ -1,4 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import type { Logger } from "@lage-run/logger";
2
3
  import type { ILageService } from "@lage-run/rpc";
3
- import { type TargetGraph } from "@lage-run/target-graph";
4
- export declare function createLageService(targetGraph: TargetGraph, logger: Logger, npmClient: string, maxWorkers?: number): Promise<ILageService>;
4
+ export declare function createLageService(cwd: string, abortController: AbortController, logger: Logger, maxWorkers?: number): Promise<ILageService>;
@@ -8,23 +8,79 @@ Object.defineProperty(exports, "createLageService", {
8
8
  return createLageService;
9
9
  }
10
10
  });
11
+ const _config = require("@lage-run/config");
11
12
  const _targetgraph = require("@lage-run/target-graph");
12
- async function createLageService(targetGraph, logger, npmClient, maxWorkers) {
13
+ const _workspacetools = require("workspace-tools");
14
+ const _createTargetGraph = require("../run/createTargetGraph.js");
15
+ const _workerthreadspool = require("@lage-run/worker-threads-pool");
16
+ function findAllTasks(pipeline) {
17
+ const tasks = new Set();
18
+ for (const key of Object.keys(pipeline)){
19
+ if (key.includes("#") || key.startsWith("#") || key.endsWith("//")) {
20
+ const { task } = (0, _targetgraph.getPackageAndTask)(key);
21
+ tasks.add(task);
22
+ } else {
23
+ tasks.add(key);
24
+ }
25
+ }
26
+ return Array.from(tasks);
27
+ }
28
+ let targetGraph;
29
+ let config;
30
+ async function initializeOnce(cwd, logger) {
31
+ if (!config) {
32
+ config = await (0, _config.getConfig)(cwd);
33
+ }
34
+ if (!targetGraph) {
35
+ const { pipeline } = config;
36
+ const root = (0, _workspacetools.getWorkspaceRoot)(cwd);
37
+ const packageInfos = (0, _workspacetools.getPackageInfos)(root);
38
+ const tasks = findAllTasks(pipeline);
39
+ targetGraph = (0, _createTargetGraph.createTargetGraph)({
40
+ logger,
41
+ root,
42
+ dependencies: false,
43
+ dependents: false,
44
+ ignore: [],
45
+ pipeline,
46
+ repoWideChanges: config.repoWideChanges,
47
+ scope: [],
48
+ since: "",
49
+ outputs: config.cacheOptions.outputGlob,
50
+ tasks,
51
+ packageInfos
52
+ });
53
+ }
54
+ return {
55
+ config,
56
+ targetGraph
57
+ };
58
+ }
59
+ let pool;
60
+ async function createLageService(cwd, abortController, logger, maxWorkers) {
13
61
  logger.info(`Server started with ${maxWorkers} workers`);
14
- const poolModule = (await import("@lage-run/worker-threads-pool")).default;
15
- const pool = new poolModule.WorkerPool({
62
+ pool = new _workerthreadspool.WorkerPool({
16
63
  script: require.resolve("./singleTargetWorker.js"),
17
64
  maxWorkers
18
65
  });
66
+ abortController.signal.addEventListener("abort", ()=>{
67
+ pool?.close();
68
+ });
19
69
  return {
70
+ async ping () {
71
+ return {
72
+ pong: true
73
+ };
74
+ },
20
75
  async runTarget (request) {
76
+ const { config , targetGraph } = await initializeOnce(cwd, logger);
21
77
  const runners = {
22
78
  npmScript: {
23
79
  script: require.resolve("../run/runners/NpmScriptRunner.js"),
24
80
  options: {
25
81
  nodeOptions: request.nodeOptions,
26
82
  taskArgs: request.taskArgs,
27
- npmCmd: npmClient
83
+ npmCmd: config.npmClient
28
84
  }
29
85
  },
30
86
  worker: {
@@ -51,13 +107,19 @@ async function createLageService(targetGraph, logger, npmClient, maxWorkers) {
51
107
  target,
52
108
  runners
53
109
  };
110
+ let pipedStdout;
111
+ let pipedStderr;
54
112
  try {
55
113
  await pool.exec(task, 0, (worker, stdout, stderr)=>{
56
114
  logger.info(`[${worker.threadId}] ${request.packageName}#${request.task} start`);
115
+ pipedStdout = stdout;
116
+ pipedStderr = stderr;
57
117
  stdout.pipe(process.stdout);
58
118
  stderr.pipe(process.stderr);
59
119
  }, (worker)=>{
60
120
  logger.info(`[${worker.threadId}] ${request.packageName}#${request.task} end`);
121
+ pipedStdout.unpipe(process.stdout);
122
+ pipedStderr.unpipe(process.stderr);
61
123
  });
62
124
  return {
63
125
  packageName: request.packageName,
@@ -0,0 +1 @@
1
+ export {};
package/lib/server.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _commander = require("commander");
6
+ const _errors = require("./types/errors.js");
7
+ const _index = require("./commands/server/index.js");
8
+ async function main() {
9
+ const program = new _commander.Command();
10
+ program.addCommand(_index.serverCommand, {
11
+ isDefault: true
12
+ });
13
+ await program.parseAsync(process.argv);
14
+ }
15
+ main().catch((err)=>{
16
+ /* eslint-disable no-console */ switch(err){
17
+ case _errors.NoTargetFoundError:
18
+ console.log("lage: no targets found that matches the given scope.");
19
+ break;
20
+ default:
21
+ console.error(err);
22
+ break;
23
+ }
24
+ /* eslint-enable no-console */ process.exitCode = 1;
25
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lage-run/cli",
3
- "version": "0.19.2",
3
+ "version": "0.20.0",
4
4
  "description": "Command Line Interface for Lage",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,21 +20,21 @@
20
20
  "lint": "monorepo-scripts lint"
21
21
  },
22
22
  "dependencies": {
23
- "@lage-run/cache": "^1.3.2",
24
- "@lage-run/config": "^0.4.1",
25
- "@lage-run/hasher": "^1.3.2",
23
+ "@lage-run/cache": "^1.3.3",
24
+ "@lage-run/config": "^0.4.2",
25
+ "@lage-run/hasher": "^1.3.4",
26
26
  "@lage-run/logger": "^1.3.1",
27
- "@lage-run/reporters": "^1.2.9",
28
- "@lage-run/rpc": "^1.1.0",
29
- "@lage-run/runners": "^1.0.1",
30
- "@lage-run/scheduler": "^1.2.12",
31
- "@lage-run/scheduler-types": "^0.3.14",
32
- "@lage-run/target-graph": "^0.8.9",
27
+ "@lage-run/reporters": "^1.2.10",
28
+ "@lage-run/rpc": "^1.2.0",
29
+ "@lage-run/runners": "^1.0.2",
30
+ "@lage-run/scheduler": "^1.2.14",
31
+ "@lage-run/scheduler-types": "^0.3.15",
32
+ "@lage-run/target-graph": "^0.8.10",
33
33
  "@lage-run/worker-threads-pool": "^0.8.1",
34
34
  "chokidar": "3.5.3",
35
35
  "commander": "9.5.0",
36
36
  "execa": "5.1.1",
37
- "fast-glob": "3.3.1",
37
+ "fast-glob": "3.3.2",
38
38
  "workspace-tools": "0.36.4"
39
39
  },
40
40
  "devDependencies": {