@lage-run/cli 0.24.4 → 0.24.6
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 +55 -1
- package/CHANGELOG.md +22 -2
- package/lib/commands/exec/action.d.ts +1 -0
- package/lib/commands/exec/action.js +3 -0
- package/lib/commands/exec/action.js.map +1 -1
- package/lib/commands/exec/executeRemotely.d.ts +4 -1
- package/lib/commands/exec/executeRemotely.js +13 -79
- package/lib/commands/exec/executeRemotely.js.map +1 -1
- package/lib/commands/exec/index.js +3 -1
- package/lib/commands/exec/index.js.map +1 -1
- package/lib/commands/info/action.js +6 -4
- package/lib/commands/info/action.js.map +1 -1
- package/lib/commands/launchServerInBackground.d.ts +12 -0
- package/lib/commands/launchServerInBackground.js +103 -0
- package/lib/commands/launchServerInBackground.js.map +1 -0
- package/lib/commands/server/action.d.ts +1 -0
- package/lib/commands/server/action.js +3 -2
- package/lib/commands/server/action.js.map +1 -1
- package/lib/commands/server/index.js +4 -8
- package/lib/commands/server/index.js.map +1 -1
- package/lib/commands/server/lageService.d.ts +5 -3
- package/lib/commands/server/lageService.js +128 -103
- package/lib/commands/server/lageService.js.map +1 -1
- package/lib/getBinPaths.d.ts +4 -0
- package/lib/getBinPaths.js +31 -3
- package/lib/getBinPaths.js.map +1 -1
- package/package.json +4 -3
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,61 @@
|
|
|
2
2
|
"name": "@lage-run/cli",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Sun, 08 Dec 2024 00:07:13 GMT",
|
|
6
|
+
"version": "0.24.6",
|
|
7
|
+
"tag": "@lage-run/cli_v0.24.6",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "kchau@microsoft.com",
|
|
12
|
+
"package": "@lage-run/cli",
|
|
13
|
+
"commit": "e6eaba8d27f25d746caed332198519a7dc4a218e",
|
|
14
|
+
"comment": "adds the ability to do workerIdleMemoryLimit"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"author": "beachball",
|
|
18
|
+
"package": "@lage-run/cli",
|
|
19
|
+
"comment": "Bump @lage-run/scheduler to v1.4.2",
|
|
20
|
+
"commit": "not available"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"author": "beachball",
|
|
24
|
+
"package": "@lage-run/cli",
|
|
25
|
+
"comment": "Bump @lage-run/worker-threads-pool to v0.8.6",
|
|
26
|
+
"commit": "not available"
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"date": "Wed, 04 Dec 2024 23:50:15 GMT",
|
|
33
|
+
"version": "0.24.5",
|
|
34
|
+
"tag": "@lage-run/cli_v0.24.5",
|
|
35
|
+
"comments": {
|
|
36
|
+
"patch": [
|
|
37
|
+
{
|
|
38
|
+
"author": "kchau@microsoft.com",
|
|
39
|
+
"package": "@lage-run/cli",
|
|
40
|
+
"commit": "a512ef3dffa4e87edcd33a762e10418e0579ca02",
|
|
41
|
+
"comment": "Fixes the server worker model to use aggregated pool"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"author": "beachball",
|
|
45
|
+
"package": "@lage-run/cli",
|
|
46
|
+
"comment": "Bump @lage-run/scheduler to v1.4.1",
|
|
47
|
+
"commit": "not available"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"author": "beachball",
|
|
51
|
+
"package": "@lage-run/cli",
|
|
52
|
+
"comment": "Bump @lage-run/worker-threads-pool to v0.8.5",
|
|
53
|
+
"commit": "not available"
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"date": "Mon, 02 Dec 2024 17:23:22 GMT",
|
|
6
60
|
"version": "0.24.4",
|
|
7
61
|
"tag": "@lage-run/cli_v0.24.4",
|
|
8
62
|
"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
|
|
3
|
+
<!-- This log was last generated on Sun, 08 Dec 2024 00:07:13 GMT and should not be manually modified. -->
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.24.6
|
|
8
|
+
|
|
9
|
+
Sun, 08 Dec 2024 00:07:13 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- adds the ability to do workerIdleMemoryLimit (kchau@microsoft.com)
|
|
14
|
+
- Bump @lage-run/scheduler to v1.4.2
|
|
15
|
+
- Bump @lage-run/worker-threads-pool to v0.8.6
|
|
16
|
+
|
|
17
|
+
## 0.24.5
|
|
18
|
+
|
|
19
|
+
Wed, 04 Dec 2024 23:50:15 GMT
|
|
20
|
+
|
|
21
|
+
### Patches
|
|
22
|
+
|
|
23
|
+
- Fixes the server worker model to use aggregated pool (kchau@microsoft.com)
|
|
24
|
+
- Bump @lage-run/scheduler to v1.4.1
|
|
25
|
+
- Bump @lage-run/worker-threads-pool to v0.8.5
|
|
26
|
+
|
|
7
27
|
## 0.24.4
|
|
8
28
|
|
|
9
|
-
Mon, 02 Dec 2024 17:22
|
|
29
|
+
Mon, 02 Dec 2024 17:23:22 GMT
|
|
10
30
|
|
|
11
31
|
### Patches
|
|
12
32
|
|
|
@@ -26,6 +26,9 @@ async function execAction(options, command) {
|
|
|
26
26
|
const { server } = options;
|
|
27
27
|
if (server) {
|
|
28
28
|
logger.info("Running in server mode");
|
|
29
|
+
if (typeof options.tasks === "undefined") {
|
|
30
|
+
throw new Error("No tasks specified, this is required for when running in server mode");
|
|
31
|
+
}
|
|
29
32
|
await (0, _executeRemotely.executeRemotely)(options, command);
|
|
30
33
|
} else {
|
|
31
34
|
await (0, _executeInProcess.executeInProcess)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/exec/action.ts"],"sourcesContent":["import type { Command } from \"commander\";\nimport createLogger from \"@lage-run/logger\";\nimport type { ReporterInitOptions } from \"../../types/ReporterInitOptions.js\";\nimport { initializeReporters } from \"../initializeReporters.js\";\nimport { executeInProcess } from \"./executeInProcess.js\";\nimport { executeRemotely } from \"./executeRemotely.js\";\n\ninterface ExecOptions extends ReporterInitOptions {\n cwd?: string;\n server?: boolean | string;\n timeout?: number;\n nodeArg?: string;\n}\n\nexport async function execAction(options: ExecOptions, command: Command) {\n const logger = createLogger();\n options.cwd = options.cwd ?? process.cwd();\n options.logLevel = options.logLevel ?? \"info\";\n options.reporter = options.reporter ?? \"json\";\n initializeReporters(logger, options);\n\n const { server } = options;\n if (server) {\n logger.info(\"Running in server mode\");\n await executeRemotely(options, command);\n } else {\n await executeInProcess({ logger, args: command.args, cwd: options.cwd, nodeArg: options.nodeArg });\n }\n}\n"],"names":["execAction","options","command","logger","createLogger","cwd","process","logLevel","reporter","initializeReporters","server","info","executeRemotely","executeInProcess","args","nodeArg"],"mappings":";;;;+
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/exec/action.ts"],"sourcesContent":["import type { Command } from \"commander\";\nimport createLogger from \"@lage-run/logger\";\nimport type { ReporterInitOptions } from \"../../types/ReporterInitOptions.js\";\nimport { initializeReporters } from \"../initializeReporters.js\";\nimport { executeInProcess } from \"./executeInProcess.js\";\nimport { executeRemotely } from \"./executeRemotely.js\";\n\ninterface ExecOptions extends ReporterInitOptions {\n cwd?: string;\n server?: boolean | string;\n timeout?: number;\n nodeArg?: string;\n tasks?: string[];\n}\n\ninterface ExecRemoteOptions extends ExecOptions {\n tasks: string[];\n}\n\nexport async function execAction(options: ExecOptions, command: Command) {\n const logger = createLogger();\n options.cwd = options.cwd ?? process.cwd();\n options.logLevel = options.logLevel ?? \"info\";\n options.reporter = options.reporter ?? \"json\";\n initializeReporters(logger, options);\n\n const { server } = options;\n if (server) {\n logger.info(\"Running in server mode\");\n\n if (typeof options.tasks === \"undefined\") {\n throw new Error(\"No tasks specified, this is required for when running in server mode\");\n }\n\n await executeRemotely(options as ExecRemoteOptions, command);\n } else {\n await executeInProcess({ logger, args: command.args, cwd: options.cwd, nodeArg: options.nodeArg });\n }\n}\n"],"names":["execAction","options","command","logger","createLogger","cwd","process","logLevel","reporter","initializeReporters","server","info","tasks","Error","executeRemotely","executeInProcess","args","nodeArg"],"mappings":";;;;+BAmBsBA;;;eAAAA;;;+DAlBG;qCAEW;kCACH;iCACD;;;;;;AAczB,eAAeA,WAAWC,OAAoB,EAAEC,OAAgB;IACrE,MAAMC,SAASC,IAAAA,eAAY;IAC3BH,QAAQI,GAAG,GAAGJ,QAAQI,GAAG,IAAIC,QAAQD,GAAG;IACxCJ,QAAQM,QAAQ,GAAGN,QAAQM,QAAQ,IAAI;IACvCN,QAAQO,QAAQ,GAAGP,QAAQO,QAAQ,IAAI;IACvCC,IAAAA,wCAAmB,EAACN,QAAQF;IAE5B,MAAM,EAAES,MAAM,EAAE,GAAGT;IACnB,IAAIS,QAAQ;QACVP,OAAOQ,IAAI,CAAC;QAEZ,IAAI,OAAOV,QAAQW,KAAK,KAAK,aAAa;YACxC,MAAM,IAAIC,MAAM;QAClB;QAEA,MAAMC,IAAAA,gCAAe,EAACb,SAA8BC;IACtD,OAAO;QACL,MAAMa,IAAAA,kCAAgB,EAAC;YAAEZ;YAAQa,MAAMd,QAAQc,IAAI;YAAEX,KAAKJ,QAAQI,GAAG;YAAEY,SAAShB,QAAQgB,OAAO;QAAC;IAClG;AACF"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { ReporterInitOptions } from "../../types/ReporterInitOptions.js";
|
|
2
|
+
import type { Command } from "commander";
|
|
2
3
|
interface ExecRemotelyOptions extends ReporterInitOptions {
|
|
3
4
|
cwd?: string;
|
|
4
5
|
server?: string | boolean;
|
|
5
6
|
timeout?: number;
|
|
7
|
+
tasks: string[];
|
|
8
|
+
nodeArg?: string;
|
|
6
9
|
}
|
|
7
|
-
export declare function executeRemotely(options: ExecRemotelyOptions, command:
|
|
10
|
+
export declare function executeRemotely(options: ExecRemotelyOptions, command: Command): Promise<void>;
|
|
8
11
|
export {};
|
|
@@ -13,13 +13,9 @@ const _initializeReporters = require("../initializeReporters.js");
|
|
|
13
13
|
const _rpc = require("@lage-run/rpc");
|
|
14
14
|
const _filterArgsForTasks = require("../run/filterArgsForTasks.js");
|
|
15
15
|
const _simulateFileAccess = require("./simulateFileAccess.js");
|
|
16
|
-
const _execa = /*#__PURE__*/ _interop_require_default(require("execa"));
|
|
17
|
-
const _getBinPaths = require("../../getBinPaths.js");
|
|
18
16
|
const _parseServerOption = require("../parseServerOption.js");
|
|
19
|
-
const _properlockfile = /*#__PURE__*/ _interop_require_default(require("proper-lockfile"));
|
|
20
|
-
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
21
|
-
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
22
17
|
const _workspacetools = require("workspace-tools");
|
|
18
|
+
const _launchServerInBackground = require("../launchServerInBackground.js");
|
|
23
19
|
function _interop_require_default(obj) {
|
|
24
20
|
return obj && obj.__esModule ? obj : {
|
|
25
21
|
default: obj
|
|
@@ -88,93 +84,31 @@ async function executeOnServer(args, client, logger) {
|
|
|
88
84
|
}
|
|
89
85
|
}
|
|
90
86
|
}
|
|
91
|
-
function isAlive(pid) {
|
|
92
|
-
try {
|
|
93
|
-
return process.kill(pid, 0);
|
|
94
|
-
} catch {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
function ensurePidFile(lockfilePath) {
|
|
99
|
-
if (!_fs.default.existsSync(_path.default.dirname(lockfilePath))) {
|
|
100
|
-
_fs.default.mkdirSync(_path.default.dirname(lockfilePath), {
|
|
101
|
-
recursive: true
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
if (!_fs.default.existsSync(lockfilePath)) {
|
|
105
|
-
try {
|
|
106
|
-
const fd = _fs.default.openSync(lockfilePath, "w");
|
|
107
|
-
_fs.default.closeSync(fd);
|
|
108
|
-
} catch {
|
|
109
|
-
// ignore
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
87
|
async function executeRemotely(options, command) {
|
|
114
88
|
// launch a 'lage-server.js' process, detached if it is not already running
|
|
115
89
|
// send the command to the server process
|
|
116
|
-
const { server } = options;
|
|
117
|
-
const timeout = options.timeout ??
|
|
90
|
+
const { server, tasks, nodeArg } = options;
|
|
91
|
+
const timeout = options.timeout ?? 5 * 60;
|
|
118
92
|
const { host, port } = (0, _parseServerOption.parseServerOption)(server);
|
|
119
93
|
const logger = (0, _logger.default)();
|
|
120
94
|
options.logLevel = options.logLevel ?? "info";
|
|
121
95
|
options.reporter = options.reporter ?? "json";
|
|
122
96
|
(0, _initializeReporters.initializeReporters)(logger, options);
|
|
123
97
|
const root = (0, _workspacetools.getWorkspaceRoot)(options.cwd ?? process.cwd());
|
|
124
|
-
const lockfilePath = _path.default.join(root, `node_modules/.cache/lage/.lage-server-${host}-${port}.pid`);
|
|
125
98
|
let client = await tryCreateClient(host, port);
|
|
126
99
|
const args = command.args;
|
|
100
|
+
logger.info(`Command args ${command.args.join(" ")}`);
|
|
127
101
|
if (!client) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
maxTimeout: 60 * 1000,
|
|
138
|
-
randomize: true
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
const pid = parseInt(_fs.default.readFileSync(lockfilePath, "utf-8"));
|
|
142
|
-
const isServerRunning = pid && isAlive(pid);
|
|
143
|
-
logger.info("Checking if server is already running", {
|
|
144
|
-
pid,
|
|
145
|
-
isServerRunning
|
|
102
|
+
await (0, _launchServerInBackground.launchServerInBackground)({
|
|
103
|
+
host,
|
|
104
|
+
port,
|
|
105
|
+
tasks,
|
|
106
|
+
args,
|
|
107
|
+
timeout,
|
|
108
|
+
logger,
|
|
109
|
+
root,
|
|
110
|
+
nodeArg
|
|
146
111
|
});
|
|
147
|
-
if (pid && isServerRunning) {
|
|
148
|
-
logger.info("Server already running", {
|
|
149
|
-
pid
|
|
150
|
-
});
|
|
151
|
-
} else {
|
|
152
|
-
const binPaths = (0, _getBinPaths.getBinPaths)();
|
|
153
|
-
const lageServerBinPath = binPaths["lage-server"];
|
|
154
|
-
const lageServerArgs = [
|
|
155
|
-
"--host",
|
|
156
|
-
host,
|
|
157
|
-
"--port",
|
|
158
|
-
port,
|
|
159
|
-
"--timeout",
|
|
160
|
-
timeout,
|
|
161
|
-
...args
|
|
162
|
-
];
|
|
163
|
-
logger.info(`Launching lage-server with these parameters: ${lageServerArgs.join(" ")}`);
|
|
164
|
-
const child = (0, _execa.default)(lageServerBinPath, lageServerArgs, {
|
|
165
|
-
cwd: root,
|
|
166
|
-
detached: true,
|
|
167
|
-
stdio: "ignore"
|
|
168
|
-
});
|
|
169
|
-
if (child && child.pid) {
|
|
170
|
-
_fs.default.writeFileSync(lockfilePath, child.pid.toString());
|
|
171
|
-
}
|
|
172
|
-
child.unref();
|
|
173
|
-
logger.info("Server started", {
|
|
174
|
-
pid: child.pid
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
await releaseLock();
|
|
178
112
|
logger.info("Creating a client to connect to the background services");
|
|
179
113
|
client = await tryCreateClientWithRetries(host, port, logger);
|
|
180
114
|
if (!client) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/exec/executeRemotely.ts"],"sourcesContent":["import type { Logger } from \"@lage-run/logger\";\nimport createLogger from \"@lage-run/logger\";\nimport { initializeReporters } from \"../initializeReporters.js\";\nimport type { ReporterInitOptions } from \"../../types/ReporterInitOptions.js\";\nimport type { LageClient } from \"@lage-run/rpc\";\nimport { ConnectError, createClient } from \"@lage-run/rpc\";\nimport { filterArgsForTasks } from \"../run/filterArgsForTasks.js\";\nimport { simulateFileAccess } from \"./simulateFileAccess.js\";\nimport execa from \"execa\";\nimport { getBinPaths } from \"../../getBinPaths.js\";\nimport { parseServerOption } from \"../parseServerOption.js\";\nimport lockfile from \"proper-lockfile\";\nimport path from \"path\";\nimport fs from \"fs\";\nimport { getWorkspaceRoot } from \"workspace-tools\";\n\ninterface ExecRemotelyOptions extends ReporterInitOptions {\n cwd?: string;\n server?: string | boolean;\n timeout?: number;\n}\n\nasync function tryCreateClient(host: string, port: number) {\n const client = createClient({\n baseUrl: `http://${host}:${port}`,\n httpVersion: \"2\",\n });\n\n try {\n const success = await client.ping({});\n if (success.pong) {\n return client;\n }\n } catch (e) {\n if (e instanceof ConnectError) {\n return undefined;\n }\n\n throw e;\n }\n\n return undefined;\n}\n\nasync function tryCreateClientWithRetries(host: string, port: number, logger: Logger) {\n let client: ReturnType<typeof createClient> | undefined;\n\n const start = Date.now();\n while (Date.now() - start < 5 * 1000) {\n try {\n client = await tryCreateClient(host, port);\n\n if (client) {\n return client;\n }\n } catch (e) {\n if (e instanceof ConnectError) {\n logger.error(\"Error connecting to server\", e);\n }\n }\n\n await new Promise((resolve) => setTimeout(resolve, 1000));\n }\n\n return undefined;\n}\n\nasync function executeOnServer(args: string[], client: LageClient, logger: Logger) {\n const task = args.length === 1 ? args[0] : args[1];\n const packageName = args.length > 1 ? args[0] : undefined;\n\n if (!task) {\n throw new Error(\"No task provided\");\n }\n\n const { taskArgs } = filterArgsForTasks(args ?? []);\n\n try {\n const response = await client.runTarget({\n packageName,\n task,\n taskArgs,\n });\n logger.info(`Task ${response.packageName} ${response.task} exited with code ${response.exitCode} `);\n return response;\n } catch (error) {\n if (error instanceof ConnectError) {\n logger.error(\"Error connecting to server\", { error });\n } else {\n logger.error(\"Error running task\", { error });\n }\n }\n}\n\nfunction isAlive(pid: number) {\n try {\n return process.kill(pid, 0);\n } catch {\n return false;\n }\n}\n\nfunction ensurePidFile(lockfilePath: string) {\n if (!fs.existsSync(path.dirname(lockfilePath))) {\n fs.mkdirSync(path.dirname(lockfilePath), { recursive: true });\n }\n\n if (!fs.existsSync(lockfilePath)) {\n try {\n const fd = fs.openSync(lockfilePath, \"w\");\n fs.closeSync(fd);\n } catch {\n // ignore\n }\n }\n}\n\nexport async function executeRemotely(options: ExecRemotelyOptions, command) {\n // launch a 'lage-server.js' process, detached if it is not already running\n // send the command to the server process\n const { server } = options;\n const timeout = options.timeout ?? 120;\n\n const { host, port } = parseServerOption(server);\n\n const logger = createLogger();\n options.logLevel = options.logLevel ?? \"info\";\n options.reporter = options.reporter ?? \"json\";\n initializeReporters(logger, options);\n\n const root = getWorkspaceRoot(options.cwd ?? process.cwd())!;\n\n const lockfilePath = path.join(root, `node_modules/.cache/lage/.lage-server-${host}-${port}.pid`);\n\n let client = await tryCreateClient(host, port);\n const args = command.args;\n\n if (!client) {\n logger.info(`Starting server on http://${host}:${port}`);\n logger.info(`acquiring lock: ${lockfilePath}`);\n\n ensurePidFile(lockfilePath);\n\n const releaseLock = await lockfile.lock(lockfilePath, {\n stale: 1000 * 60 * 1,\n retries: {\n retries: 10,\n factor: 3,\n minTimeout: 0.5 * 1000,\n maxTimeout: 60 * 1000,\n randomize: true,\n },\n });\n\n const pid = parseInt(fs.readFileSync(lockfilePath, \"utf-8\"));\n const isServerRunning = pid && isAlive(pid);\n logger.info(\"Checking if server is already running\", { pid, isServerRunning });\n if (pid && isServerRunning) {\n logger.info(\"Server already running\", { pid });\n } else {\n const binPaths = getBinPaths();\n const lageServerBinPath = binPaths[\"lage-server\"];\n const lageServerArgs = [\"--host\", host, \"--port\", port, \"--timeout\", timeout, ...args];\n\n logger.info(`Launching lage-server with these parameters: ${lageServerArgs.join(\" \")}`);\n const child = execa(lageServerBinPath, lageServerArgs, {\n cwd: root,\n detached: true,\n stdio: \"ignore\",\n });\n\n if (child && child.pid) {\n fs.writeFileSync(lockfilePath, child.pid.toString());\n }\n\n child.unref();\n logger.info(\"Server started\", { pid: child.pid });\n }\n\n await releaseLock();\n\n logger.info(\"Creating a client to connect to the background services\");\n client = await tryCreateClientWithRetries(host, port, logger);\n\n if (!client) {\n throw new Error(\"Server could not be started\");\n }\n }\n\n logger.info(`Executing on server http://${host}:${port}`);\n const response = await executeOnServer(args, client, logger);\n\n if (response) {\n process.stdout.write(response.stdout);\n process.stderr.write(response.stderr);\n process.exitCode = response.exitCode;\n\n if (response.exitCode === 0) {\n await simulateFileAccess(logger, response.inputs, response.outputs);\n }\n } else {\n process.exitCode = 1;\n }\n\n logger.info(\"Task execution finished\");\n}\n"],"names":["executeRemotely","tryCreateClient","host","port","client","createClient","baseUrl","httpVersion","success","ping","pong","e","ConnectError","undefined","tryCreateClientWithRetries","logger","start","Date","now","error","Promise","resolve","setTimeout","executeOnServer","args","task","length","packageName","Error","taskArgs","filterArgsForTasks","response","runTarget","info","exitCode","isAlive","pid","process","kill","ensurePidFile","lockfilePath","fs","existsSync","path","dirname","mkdirSync","recursive","fd","openSync","closeSync","options","command","server","timeout","parseServerOption","createLogger","logLevel","reporter","initializeReporters","root","getWorkspaceRoot","cwd","join","releaseLock","lockfile","lock","stale","retries","factor","minTimeout","maxTimeout","randomize","parseInt","readFileSync","isServerRunning","binPaths","getBinPaths","lageServerBinPath","lageServerArgs","child","execa","detached","stdio","writeFileSync","toString","unref","stdout","write","stderr","simulateFileAccess","inputs","outputs"],"mappings":";;;;+BAqHsBA;;;eAAAA;;;+DApHG;qCACW;qBAGO;oCACR;oCACA;8DACjB;6BACU;mCACM;uEACb;6DACJ;2DACF;gCACkB;;;;;;AAQjC,eAAeC,gBAAgBC,IAAY,EAAEC,IAAY;IACvD,MAAMC,SAASC,IAAAA,iBAAY,EAAC;QAC1BC,SAAS,CAAC,OAAO,EAAEJ,KAAK,CAAC,EAAEC,MAAM;QACjCI,aAAa;IACf;IAEA,IAAI;QACF,MAAMC,UAAU,MAAMJ,OAAOK,IAAI,CAAC,CAAC;QACnC,IAAID,QAAQE,IAAI,EAAE;YAChB,OAAON;QACT;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A,MAAM2B;QAENhD,OAAOkB,IAAI,CAAC;QACZ7B,SAAS,MAAMU,2BAA2BZ,MAAMC,MAAMY;QAEtD,IAAI,CAACX,QAAQ;YACX,MAAM,IAAIwB,MAAM;QAClB;IACF;IAEAb,OAAOkB,IAAI,CAAC,CAAC,2BAA2B,EAAE/B,KAAK,CAAC,EAAEC,MAAM;IACxD,MAAM4B,WAAW,MAAMR,gBAAgBC,MAAMpB,QAAQW;IAErD,IAAIgB,UAAU;QACZM,QAAQiD,MAAM,CAACC,KAAK,CAACxD,SAASuD,MAAM;QACpCjD,QAAQmD,MAAM,CAACD,KAAK,CAACxD,SAASyD,MAAM;QACpCnD,QAAQH,QAAQ,GAAGH,SAASG,QAAQ;QAEpC,IAAIH,SAASG,QAAQ,KAAK,GAAG;YAC3B,MAAMuD,IAAAA,sCAAkB,EAAC1E,QAAQgB,SAAS2D,MAAM,EAAE3D,SAAS4D,OAAO;QACpE;IACF,OAAO;QACLtD,QAAQH,QAAQ,GAAG;IACrB;IAEAnB,OAAOkB,IAAI,CAAC;AACd"}
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/exec/executeRemotely.ts"],"sourcesContent":["import type { Logger } from \"@lage-run/logger\";\nimport createLogger from \"@lage-run/logger\";\nimport { initializeReporters } from \"../initializeReporters.js\";\nimport type { ReporterInitOptions } from \"../../types/ReporterInitOptions.js\";\nimport type { LageClient } from \"@lage-run/rpc\";\nimport { ConnectError, createClient } from \"@lage-run/rpc\";\nimport { filterArgsForTasks } from \"../run/filterArgsForTasks.js\";\nimport { simulateFileAccess } from \"./simulateFileAccess.js\";\nimport { parseServerOption } from \"../parseServerOption.js\";\nimport { getWorkspaceRoot } from \"workspace-tools\";\nimport type { Command } from \"commander\";\nimport { launchServerInBackground } from \"../launchServerInBackground.js\";\n\ninterface ExecRemotelyOptions extends ReporterInitOptions {\n cwd?: string;\n server?: string | boolean;\n timeout?: number;\n tasks: string[];\n nodeArg?: string;\n}\n\nasync function tryCreateClient(host: string, port: number) {\n const client = createClient({\n baseUrl: `http://${host}:${port}`,\n httpVersion: \"2\",\n });\n\n try {\n const success = await client.ping({});\n if (success.pong) {\n return client;\n }\n } catch (e) {\n if (e instanceof ConnectError) {\n return undefined;\n }\n\n throw e;\n }\n\n return undefined;\n}\n\nasync function tryCreateClientWithRetries(host: string, port: number, logger: Logger) {\n let client: ReturnType<typeof createClient> | undefined;\n\n const start = Date.now();\n while (Date.now() - start < 5 * 1000) {\n try {\n client = await tryCreateClient(host, port);\n\n if (client) {\n return client;\n }\n } catch (e) {\n if (e instanceof ConnectError) {\n logger.error(\"Error connecting to server\", e);\n }\n }\n\n await new Promise((resolve) => setTimeout(resolve, 1000));\n }\n\n return undefined;\n}\n\nasync function executeOnServer(args: string[], client: LageClient, logger: Logger) {\n const task = args.length === 1 ? args[0] : args[1];\n const packageName = args.length > 1 ? args[0] : undefined;\n\n if (!task) {\n throw new Error(\"No task provided\");\n }\n\n const { taskArgs } = filterArgsForTasks(args ?? []);\n\n try {\n const response = await client.runTarget({\n packageName,\n task,\n taskArgs,\n });\n logger.info(`Task ${response.packageName} ${response.task} exited with code ${response.exitCode} `);\n return response;\n } catch (error) {\n if (error instanceof ConnectError) {\n logger.error(\"Error connecting to server\", { error });\n } else {\n logger.error(\"Error running task\", { error });\n }\n }\n}\n\nexport async function executeRemotely(options: ExecRemotelyOptions, command: Command) {\n // launch a 'lage-server.js' process, detached if it is not already running\n // send the command to the server process\n const { server, tasks, nodeArg } = options;\n const timeout = options.timeout ?? 5 * 60;\n\n const { host, port } = parseServerOption(server);\n\n const logger = createLogger();\n options.logLevel = options.logLevel ?? \"info\";\n options.reporter = options.reporter ?? \"json\";\n initializeReporters(logger, options);\n\n const root = getWorkspaceRoot(options.cwd ?? process.cwd())!;\n\n let client = await tryCreateClient(host, port);\n const args = command.args;\n\n logger.info(`Command args ${command.args.join(\" \")}`);\n\n if (!client) {\n await launchServerInBackground({\n host,\n port,\n tasks,\n args,\n timeout,\n logger,\n root,\n nodeArg,\n });\n\n logger.info(\"Creating a client to connect to the background services\");\n client = await tryCreateClientWithRetries(host, port, logger);\n\n if (!client) {\n throw new Error(\"Server could not be started\");\n }\n }\n\n logger.info(`Executing on server http://${host}:${port}`);\n const response = await executeOnServer(args, client, logger);\n\n if (response) {\n process.stdout.write(response.stdout);\n process.stderr.write(response.stderr);\n process.exitCode = response.exitCode;\n\n if (response.exitCode === 0) {\n await simulateFileAccess(logger, response.inputs, response.outputs);\n }\n } else {\n process.exitCode = 1;\n }\n\n logger.info(\"Task execution finished\");\n}\n"],"names":["executeRemotely","tryCreateClient","host","port","client","createClient","baseUrl","httpVersion","success","ping","pong","e","ConnectError","undefined","tryCreateClientWithRetries","logger","start","Date","now","error","Promise","resolve","setTimeout","executeOnServer","args","task","length","packageName","Error","taskArgs","filterArgsForTasks","response","runTarget","info","exitCode","options","command","server","tasks","nodeArg","timeout","parseServerOption","createLogger","logLevel","reporter","initializeReporters","root","getWorkspaceRoot","cwd","process","join","launchServerInBackground","stdout","write","stderr","simulateFileAccess","inputs","outputs"],"mappings":";;;;+BA6FsBA;;;eAAAA;;;+DA5FG;qCACW;qBAGO;oCACR;oCACA;mCACD;gCACD;0CAEQ;;;;;;AAUzC,eAAeC,gBAAgBC,IAAY,EAAEC,IAAY;IACvD,MAAMC,SAASC,IAAAA,iBAAY,EAAC;QAC1BC,SAAS,CAAC,OAAO,EAAEJ,KAAK,CAAC,EAAEC,MAAM;QACjCI,aAAa;IACf;IAEA,IAAI;QACF,MAAMC,UAAU,MAAMJ,OAAOK,IAAI,CAAC,CAAC;QACnC,IAAID,QAAQE,IAAI,EAAE;YAChB,OAAON;QACT;IACF,EAAE,OAAOO,GAAG;QACV,IAAIA,aAAaC,iBAAY,EAAE;YAC7B,OAAOC;QACT;QAEA,MAAMF;IACR;IAEA,OAAOE;AACT;AAEA,eAAeC,2BAA2BZ,IAAY,EAAEC,IAAY,EAAEY,MAAc;IAClF,IAAIX;IAEJ,MAAMY,QAAQC,KAAKC,GAAG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B,SAAS0B,OAAO;QACpE;IACF,OAAO;QACLR,QAAQf,QAAQ,GAAG;IACrB;IAEAnB,OAAOkB,IAAI,CAAC;AACd"}
|
|
@@ -18,7 +18,9 @@ function _interop_require_default(obj) {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
const execCommand = new _commander.Command("exec");
|
|
21
|
+
execCommand.option("-n|--node-arg <arg>", "node argument to pass to worker, just a single string to be passed into node like a NODE_OPTIONS setting");
|
|
21
22
|
execCommand.option("-c|--concurrency <number>", "max jobs to run at a time", (v)=>parseInt(v), _os.default.cpus().length - 1);
|
|
22
23
|
execCommand.option("-s|--server [host:port]", "lage server host");
|
|
23
|
-
execCommand.option("-t|--timeout <seconds>", "lage server autoshutoff timeout", (v)=>parseInt(v),
|
|
24
|
+
execCommand.option("-t|--timeout <seconds>", "lage server autoshutoff timeout", (v)=>parseInt(v), 5 * 60);
|
|
25
|
+
execCommand.option("--tasks [tasks...]", "A list of tasks to run, separated by space e.g. 'build test', used with --server");
|
|
24
26
|
(0, _addLoggerOptions.addLoggerOptions)(execCommand).action(_action.execAction);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/exec/index.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { execAction } from \"./action.js\";\nimport { addLoggerOptions } from \"../addLoggerOptions.js\";\nimport os from \"os\";\n\nconst execCommand = new Command(\"exec\");\nexecCommand.option(\"-c|--concurrency <number>\", \"max jobs to run at a time\", (v) => parseInt(v), os.cpus().length - 1);\nexecCommand.option(\"-s|--server [host:port]\", \"lage server host\");\nexecCommand.option<number>(\"-t|--timeout <seconds>\", \"lage server autoshutoff timeout\", (v) => parseInt(v),
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/exec/index.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { execAction } from \"./action.js\";\nimport { addLoggerOptions } from \"../addLoggerOptions.js\";\nimport os from \"os\";\n\nconst execCommand = new Command(\"exec\");\nexecCommand.option(\n \"-n|--node-arg <arg>\",\n \"node argument to pass to worker, just a single string to be passed into node like a NODE_OPTIONS setting\"\n);\nexecCommand.option(\"-c|--concurrency <number>\", \"max jobs to run at a time\", (v) => parseInt(v), os.cpus().length - 1);\nexecCommand.option(\"-s|--server [host:port]\", \"lage server host\");\nexecCommand.option<number>(\"-t|--timeout <seconds>\", \"lage server autoshutoff timeout\", (v) => parseInt(v), 5 * 60);\nexecCommand.option(\"--tasks [tasks...]\", \"A list of tasks to run, separated by space e.g. 'build test', used with --server\");\naddLoggerOptions(execCommand).action(execAction);\nexport { execCommand };\n"],"names":["execCommand","Command","option","v","parseInt","os","cpus","length","addLoggerOptions","action","execAction"],"mappings":";;;;+BAeSA;;;eAAAA;;;2BAfe;wBACG;kCACM;2DAClB;;;;;;AAEf,MAAMA,cAAc,IAAIC,kBAAO,CAAC;AAChCD,YAAYE,MAAM,CAChB,uBACA;AAEFF,YAAYE,MAAM,CAAC,6BAA6B,6BAA6B,CAACC,IAAMC,SAASD,IAAIE,WAAE,CAACC,IAAI,GAAGC,MAAM,GAAG;AACpHP,YAAYE,MAAM,CAAC,2BAA2B;AAC9CF,YAAYE,MAAM,CAAS,0BAA0B,mCAAmC,CAACC,IAAMC,SAASD,IAAI,IAAI;AAChHH,YAAYE,MAAM,CAAC,sBAAsB;AACzCM,IAAAA,kCAAgB,EAACR,aAAaS,MAAM,CAACC,kBAAU"}
|
|
@@ -67,15 +67,15 @@ async function infoAction(options, command) {
|
|
|
67
67
|
const runnerPicker = new _runners.TargetRunnerPicker(pickerOptions);
|
|
68
68
|
const optimizedTargets = await (0, _optimizeTargetGraph.optimizeTargetGraph)(targetGraph, runnerPicker);
|
|
69
69
|
const binPaths = (0, _getBinPaths.getBinPaths)();
|
|
70
|
-
const packageTasks = optimizedTargets.map((target)=>generatePackageTask(target, taskArgs, config, options, binPaths, packageInfos));
|
|
70
|
+
const packageTasks = optimizedTargets.map((target)=>generatePackageTask(target, taskArgs, config, options, binPaths, packageInfos, tasks));
|
|
71
71
|
logger.info("info", {
|
|
72
72
|
command: command.args,
|
|
73
73
|
scope,
|
|
74
74
|
packageTasks
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
-
function generatePackageTask(target, taskArgs, config, options, binPaths, packageInfos) {
|
|
78
|
-
const command = generateCommand(target, taskArgs, config, options, binPaths, packageInfos);
|
|
77
|
+
function generatePackageTask(target, taskArgs, config, options, binPaths, packageInfos, tasks) {
|
|
78
|
+
const command = generateCommand(target, taskArgs, config, options, binPaths, packageInfos, tasks);
|
|
79
79
|
const workingDirectory = getWorkingDirectory(target);
|
|
80
80
|
const packageTask = {
|
|
81
81
|
id: target.id,
|
|
@@ -87,7 +87,7 @@ function generatePackageTask(target, taskArgs, config, options, binPaths, packag
|
|
|
87
87
|
};
|
|
88
88
|
return packageTask;
|
|
89
89
|
}
|
|
90
|
-
function generateCommand(target, taskArgs, config, options, binPaths, packageInfos) {
|
|
90
|
+
function generateCommand(target, taskArgs, config, options, binPaths, packageInfos, tasks) {
|
|
91
91
|
const shouldRunWorkersAsService = typeof process.env.LAGE_WORKER_SERVER === "string" && process.env.LAGE_WORKER_SERVER !== "false" || !!options.server;
|
|
92
92
|
if (target.type === "npmScript") {
|
|
93
93
|
const script = target.packageName !== undefined ? packageInfos[target.packageName]?.scripts?.[target.task] : undefined;
|
|
@@ -113,6 +113,8 @@ function generateCommand(target, taskArgs, config, options, binPaths, packageInf
|
|
|
113
113
|
const command = [
|
|
114
114
|
binPaths["lage"],
|
|
115
115
|
"exec",
|
|
116
|
+
"--tasks",
|
|
117
|
+
...tasks,
|
|
116
118
|
"--server",
|
|
117
119
|
`${host}:${port}`
|
|
118
120
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/info/action.ts"],"sourcesContent":["import type { Command } from \"commander\";\nimport { createTargetGraph } from \"../run/createTargetGraph.js\";\nimport { filterArgsForTasks } from \"../run/filterArgsForTasks.js\";\nimport type { ConfigOptions } from \"@lage-run/config\";\nimport { getConfig } from \"@lage-run/config\";\nimport { type PackageInfos, getPackageInfos, getWorkspaceRoot } from \"workspace-tools\";\nimport { getFilteredPackages } from \"../../filter/getFilteredPackages.js\";\nimport createLogger from \"@lage-run/logger\";\nimport path from \"path\";\nimport { parse } from \"shell-quote\";\n\nimport type { ReporterInitOptions } from \"../../types/ReporterInitOptions.js\";\nimport type { Target } from \"@lage-run/target-graph\";\nimport { initializeReporters } from \"../initializeReporters.js\";\nimport { TargetRunnerPicker } from \"@lage-run/runners\";\nimport { getBinPaths } from \"../../getBinPaths.js\";\nimport { runnerPickerOptions } from \"../../runnerPickerOptions.js\";\nimport { parseServerOption } from \"../parseServerOption.js\";\nimport { optimizeTargetGraph } from \"../../optimizeTargetGraph.js\";\n\ninterface InfoActionOptions extends ReporterInitOptions {\n dependencies: boolean;\n dependents: boolean;\n since: string;\n scope: string[];\n to: string[];\n cache: boolean;\n nodeArg: string;\n ignore: string[];\n server: string;\n}\n\ninterface PackageTask {\n id: string;\n command: string[];\n dependencies: string[];\n workingDirectory: string;\n package: string;\n task: string;\n}\n\n/**\n * The info command displays information about a target graph in a workspace.\n * The generated output can be read and used by other task runners, such as BuildXL.\n *\n * Expected format:\n * [\n * {\n * \"id\": \"bar##build\",\n * \"package\": \"bar\",\n * \"task\": \"build\",\n * \"command\": \"npm run build --blah\",\n * \"workingDirectory\": \"packages/bar\",\n * \"dependencies\": []\n * },\n * {\n * \"id\": \"foo##build\",\n * \"package\": \"foo\",\n * \"task\": \"build\",\n * \"command\": \"npm run build --blah\",\n * \"workingDirectory\": \"packages/foo\",\n * \"dependencies\": [\n * \"bar##build\"\n * ]\n * },\n * {\n * \"id\": \"foo##test\",\n * \"package\": \"foo\",\n * \"task\": \"test\",\n * \"command\": \"npm run test --blah\",\n * \"workingDirectory\": \"packages/foo\",\n * \"dependencies\": [\n * \"foo##build\"\n * ]\n * },\n * ...\n * ]\n */\nexport async function infoAction(options: InfoActionOptions, command: Command) {\n const cwd = process.cwd();\n const config = await getConfig(cwd);\n const logger = createLogger();\n options.logLevel = options.logLevel ?? \"info\";\n options.reporter = options.reporter ?? \"json\";\n options.server = typeof options.server === \"boolean\" && options.server ? \"localhost:5332\" : options.server;\n initializeReporters(logger, options);\n const root = getWorkspaceRoot(cwd)!;\n\n const packageInfos = getPackageInfos(root);\n\n const { tasks, taskArgs } = filterArgsForTasks(command.args);\n\n const targetGraph = await createTargetGraph({\n logger,\n root,\n dependencies: options.dependencies,\n dependents: options.dependents && !options.to, // --to is a short hand for --scope + --no-dependents\n ignore: options.ignore.concat(config.ignore),\n pipeline: config.pipeline,\n repoWideChanges: config.repoWideChanges,\n scope: (options.scope ?? []).concat(options.to ?? []), // --to is a short hand for --scope + --no-dependents\n since: options.since,\n outputs: config.cacheOptions.outputGlob,\n tasks,\n packageInfos,\n });\n\n const scope = getFilteredPackages({\n root,\n packageInfos,\n logger,\n includeDependencies: options.dependencies,\n includeDependents: options.dependents && !options.to, // --to is a short hand for --scope + --no-dependents\n since: options.since,\n scope: (options.scope ?? []).concat(options.to ?? []), // --to is a short hand for --scope + --no-dependents\n repoWideChanges: config.repoWideChanges,\n sinceIgnoreGlobs: options.ignore.concat(config.ignore),\n });\n\n const pickerOptions = runnerPickerOptions(options.nodeArg, config.npmClient, taskArgs);\n\n const runnerPicker = new TargetRunnerPicker(pickerOptions);\n\n const optimizedTargets = await optimizeTargetGraph(targetGraph, runnerPicker);\n const binPaths = getBinPaths();\n const packageTasks = optimizedTargets.map((target) => generatePackageTask(target, taskArgs, config, options, binPaths, packageInfos));\n\n logger.info(\"info\", {\n command: command.args,\n scope,\n packageTasks,\n });\n}\n\nfunction generatePackageTask(\n target: Target,\n taskArgs: string[],\n config: ConfigOptions,\n options: InfoActionOptions,\n binPaths: { lage: string; \"lage-server\": string },\n packageInfos: PackageInfos\n): PackageTask {\n const command = generateCommand(target, taskArgs, config, options, binPaths, packageInfos);\n const workingDirectory = getWorkingDirectory(target);\n\n const packageTask: PackageTask = {\n id: target.id,\n command,\n dependencies: target.dependencies,\n workingDirectory,\n package: target.packageName ?? \"\",\n task: target.task,\n };\n\n return packageTask;\n}\n\nfunction generateCommand(\n target: Target,\n taskArgs: string[],\n config: ConfigOptions,\n options: InfoActionOptions,\n binPaths: { lage: string; \"lage-server\": string },\n packageInfos: PackageInfos\n) {\n const shouldRunWorkersAsService =\n (typeof process.env.LAGE_WORKER_SERVER === \"string\" && process.env.LAGE_WORKER_SERVER !== \"false\") || !!options.server;\n\n if (target.type === \"npmScript\") {\n const script = target.packageName !== undefined ? packageInfos[target.packageName]?.scripts?.[target.task] : undefined;\n\n // If the script is a node script, and that it does not have any shell operators (&&, ||, etc)\n // then we can simply pass this along to info command rather than using npm client to run it.\n if (script && script.startsWith(\"node\")) {\n const parsed = parse(script);\n if (parsed.length > 0 && parsed.every((entry) => typeof entry === \"string\")) {\n return [...(parsed as string[]), ...taskArgs];\n }\n }\n\n const npmClient = config.npmClient ?? \"npm\";\n const command = [npmClient, ...getNpmArgs(target.task, taskArgs)];\n return command;\n } else if (target.type === \"worker\" && shouldRunWorkersAsService) {\n const { host, port } = parseServerOption(options.server);\n const command = [binPaths[\"lage\"], \"exec\", \"--server\", `${host}:${port}`];\n if (options.concurrency) {\n command.push(\"--concurrency\", options.concurrency.toString());\n }\n\n if (target.packageName) {\n command.push(target.packageName);\n }\n\n if (target.task) {\n command.push(target.task);\n }\n\n command.push(...taskArgs);\n return command;\n } else if (target.type === \"worker\") {\n const command = [binPaths.lage, \"exec\"];\n command.push(target.packageName ?? \"\");\n command.push(target.task);\n command.push(...taskArgs);\n return command;\n }\n\n return [];\n}\n\nfunction getWorkingDirectory(target) {\n const cwd = process.cwd();\n const workingDirectory = path.relative(getWorkspaceRoot(cwd) ?? \"\", target.cwd).replace(/\\\\/g, \"/\");\n return workingDirectory;\n}\n\nfunction getNpmArgs(task: string, taskTargs: string[]) {\n const extraArgs = taskTargs != undefined && taskTargs.length > 0 ? [\"--\", ...taskTargs] : [];\n return [\"run\", task, ...extraArgs];\n}\n"],"names":["infoAction","options","command","cwd","process","config","getConfig","logger","createLogger","logLevel","reporter","server","initializeReporters","root","getWorkspaceRoot","packageInfos","getPackageInfos","tasks","taskArgs","filterArgsForTasks","args","targetGraph","createTargetGraph","dependencies","dependents","to","ignore","concat","pipeline","repoWideChanges","scope","since","outputs","cacheOptions","outputGlob","getFilteredPackages","includeDependencies","includeDependents","sinceIgnoreGlobs","pickerOptions","runnerPickerOptions","nodeArg","npmClient","runnerPicker","TargetRunnerPicker","optimizedTargets","optimizeTargetGraph","binPaths","getBinPaths","packageTasks","map","target","generatePackageTask","info","generateCommand","workingDirectory","getWorkingDirectory","packageTask","id","package","packageName","task","shouldRunWorkersAsService","env","LAGE_WORKER_SERVER","type","script","undefined","scripts","startsWith","parsed","parse","length","every","entry","getNpmArgs","host","port","parseServerOption","concurrency","push","toString","lage","path","relative","replace","taskTargs","extraArgs"],"mappings":";;;;+BA8EsBA;;;eAAAA;;;mCA7EY;oCACC;wBAET;gCAC2C;qCACjC;+DACX;6DACR;4BACK;qCAIc;yBACD;6BACP;qCACQ;mCACF;qCACE;;;;;;AA4D7B,eAAeA,WAAWC,OAA0B,EAAEC,OAAgB;IAC3E,MAAMC,MAAMC,QAAQD,GAAG;IACvB,MAAME,SAAS,MAAMC,IAAAA,iBAAS,EAACH;IAC/B,MAAMI,SAASC,IAAAA,eAAY;IAC3BP,QAAQQ,QAAQ,GAAGR,QAAQQ,QAAQ,IAAI;IACvCR,QAAQS,QAAQ,GAAGT,QAAQS,QAAQ,IAAI;IACvCT,QAAQU,MAAM,GAAG,OAAOV,QAAQU,MAAM,KAAK,aAAaV,QAAQU,MAAM,GAAG,mBAAmBV,QAAQU,MAAM;IAC1GC,IAAAA,wCAAmB,EAACL,QAAQN;IAC5B,MAAMY,OAAOC,IAAAA,gCAAgB,EAACX;IAE9B,MAAMY,eAAeC,IAAAA,+BAAe,EAACH;IAErC,MAAM,EAAEI,KAAK,EAAEC,QAAQ,EAAE,GAAGC,I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,MAAM,GAAG,IAAI;QAAC;WAASc;KAAU,GAAG,EAAE;IAC5F,OAAO;QAAC;QAAOzB;WAAS0B;KAAU;AACpC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/info/action.ts"],"sourcesContent":["import type { Command } from \"commander\";\nimport { createTargetGraph } from \"../run/createTargetGraph.js\";\nimport { filterArgsForTasks } from \"../run/filterArgsForTasks.js\";\nimport type { ConfigOptions } from \"@lage-run/config\";\nimport { getConfig } from \"@lage-run/config\";\nimport { type PackageInfos, getPackageInfos, getWorkspaceRoot } from \"workspace-tools\";\nimport { getFilteredPackages } from \"../../filter/getFilteredPackages.js\";\nimport createLogger from \"@lage-run/logger\";\nimport path from \"path\";\nimport { parse } from \"shell-quote\";\n\nimport type { ReporterInitOptions } from \"../../types/ReporterInitOptions.js\";\nimport type { Target } from \"@lage-run/target-graph\";\nimport { initializeReporters } from \"../initializeReporters.js\";\nimport { TargetRunnerPicker } from \"@lage-run/runners\";\nimport { getBinPaths } from \"../../getBinPaths.js\";\nimport { runnerPickerOptions } from \"../../runnerPickerOptions.js\";\nimport { parseServerOption } from \"../parseServerOption.js\";\nimport { optimizeTargetGraph } from \"../../optimizeTargetGraph.js\";\n\ninterface InfoActionOptions extends ReporterInitOptions {\n dependencies: boolean;\n dependents: boolean;\n since: string;\n scope: string[];\n to: string[];\n cache: boolean;\n nodeArg: string;\n ignore: string[];\n server: string;\n}\n\ninterface PackageTask {\n id: string;\n command: string[];\n dependencies: string[];\n workingDirectory: string;\n package: string;\n task: string;\n}\n\n/**\n * The info command displays information about a target graph in a workspace.\n * The generated output can be read and used by other task runners, such as BuildXL.\n *\n * Expected format:\n * [\n * {\n * \"id\": \"bar##build\",\n * \"package\": \"bar\",\n * \"task\": \"build\",\n * \"command\": \"npm run build --blah\",\n * \"workingDirectory\": \"packages/bar\",\n * \"dependencies\": []\n * },\n * {\n * \"id\": \"foo##build\",\n * \"package\": \"foo\",\n * \"task\": \"build\",\n * \"command\": \"npm run build --blah\",\n * \"workingDirectory\": \"packages/foo\",\n * \"dependencies\": [\n * \"bar##build\"\n * ]\n * },\n * {\n * \"id\": \"foo##test\",\n * \"package\": \"foo\",\n * \"task\": \"test\",\n * \"command\": \"npm run test --blah\",\n * \"workingDirectory\": \"packages/foo\",\n * \"dependencies\": [\n * \"foo##build\"\n * ]\n * },\n * ...\n * ]\n */\nexport async function infoAction(options: InfoActionOptions, command: Command) {\n const cwd = process.cwd();\n const config = await getConfig(cwd);\n const logger = createLogger();\n options.logLevel = options.logLevel ?? \"info\";\n options.reporter = options.reporter ?? \"json\";\n options.server = typeof options.server === \"boolean\" && options.server ? \"localhost:5332\" : options.server;\n initializeReporters(logger, options);\n const root = getWorkspaceRoot(cwd)!;\n\n const packageInfos = getPackageInfos(root);\n\n const { tasks, taskArgs } = filterArgsForTasks(command.args);\n\n const targetGraph = await createTargetGraph({\n logger,\n root,\n dependencies: options.dependencies,\n dependents: options.dependents && !options.to, // --to is a short hand for --scope + --no-dependents\n ignore: options.ignore.concat(config.ignore),\n pipeline: config.pipeline,\n repoWideChanges: config.repoWideChanges,\n scope: (options.scope ?? []).concat(options.to ?? []), // --to is a short hand for --scope + --no-dependents\n since: options.since,\n outputs: config.cacheOptions.outputGlob,\n tasks,\n packageInfos,\n });\n\n const scope = getFilteredPackages({\n root,\n packageInfos,\n logger,\n includeDependencies: options.dependencies,\n includeDependents: options.dependents && !options.to, // --to is a short hand for --scope + --no-dependents\n since: options.since,\n scope: (options.scope ?? []).concat(options.to ?? []), // --to is a short hand for --scope + --no-dependents\n repoWideChanges: config.repoWideChanges,\n sinceIgnoreGlobs: options.ignore.concat(config.ignore),\n });\n\n const pickerOptions = runnerPickerOptions(options.nodeArg, config.npmClient, taskArgs);\n\n const runnerPicker = new TargetRunnerPicker(pickerOptions);\n\n const optimizedTargets = await optimizeTargetGraph(targetGraph, runnerPicker);\n const binPaths = getBinPaths();\n const packageTasks = optimizedTargets.map((target) =>\n generatePackageTask(target, taskArgs, config, options, binPaths, packageInfos, tasks)\n );\n\n logger.info(\"info\", {\n command: command.args,\n scope,\n packageTasks,\n });\n}\n\nfunction generatePackageTask(\n target: Target,\n taskArgs: string[],\n config: ConfigOptions,\n options: InfoActionOptions,\n binPaths: { lage: string; \"lage-server\": string },\n packageInfos: PackageInfos,\n tasks: string[]\n): PackageTask {\n const command = generateCommand(target, taskArgs, config, options, binPaths, packageInfos, tasks);\n const workingDirectory = getWorkingDirectory(target);\n\n const packageTask: PackageTask = {\n id: target.id,\n command,\n dependencies: target.dependencies,\n workingDirectory,\n package: target.packageName ?? \"\",\n task: target.task,\n };\n\n return packageTask;\n}\n\nfunction generateCommand(\n target: Target,\n taskArgs: string[],\n config: ConfigOptions,\n options: InfoActionOptions,\n binPaths: { lage: string; \"lage-server\": string },\n packageInfos: PackageInfos,\n tasks: string[]\n) {\n const shouldRunWorkersAsService =\n (typeof process.env.LAGE_WORKER_SERVER === \"string\" && process.env.LAGE_WORKER_SERVER !== \"false\") || !!options.server;\n\n if (target.type === \"npmScript\") {\n const script = target.packageName !== undefined ? packageInfos[target.packageName]?.scripts?.[target.task] : undefined;\n\n // If the script is a node script, and that it does not have any shell operators (&&, ||, etc)\n // then we can simply pass this along to info command rather than using npm client to run it.\n if (script && script.startsWith(\"node\")) {\n const parsed = parse(script);\n if (parsed.length > 0 && parsed.every((entry) => typeof entry === \"string\")) {\n return [...(parsed as string[]), ...taskArgs];\n }\n }\n\n const npmClient = config.npmClient ?? \"npm\";\n const command = [npmClient, ...getNpmArgs(target.task, taskArgs)];\n return command;\n } else if (target.type === \"worker\" && shouldRunWorkersAsService) {\n const { host, port } = parseServerOption(options.server);\n const command = [binPaths[\"lage\"], \"exec\", \"--tasks\", ...tasks, \"--server\", `${host}:${port}`];\n if (options.concurrency) {\n command.push(\"--concurrency\", options.concurrency.toString());\n }\n\n if (target.packageName) {\n command.push(target.packageName);\n }\n\n if (target.task) {\n command.push(target.task);\n }\n\n command.push(...taskArgs);\n return command;\n } else if (target.type === \"worker\") {\n const command = [binPaths.lage, \"exec\"];\n command.push(target.packageName ?? \"\");\n command.push(target.task);\n command.push(...taskArgs);\n return command;\n }\n\n return [];\n}\n\nfunction getWorkingDirectory(target) {\n const cwd = process.cwd();\n const workingDirectory = path.relative(getWorkspaceRoot(cwd) ?? \"\", target.cwd).replace(/\\\\/g, \"/\");\n return workingDirectory;\n}\n\nfunction getNpmArgs(task: string, taskTargs: string[]) {\n const extraArgs = taskTargs != undefined && taskTargs.length > 0 ? [\"--\", ...taskTargs] : [];\n return [\"run\", task, ...extraArgs];\n}\n"],"names":["infoAction","options","command","cwd","process","config","getConfig","logger","createLogger","logLevel","reporter","server","initializeReporters","root","getWorkspaceRoot","packageInfos","getPackageInfos","tasks","taskArgs","filterArgsForTasks","args","targetGraph","createTargetGraph","dependencies","dependents","to","ignore","concat","pipeline","repoWideChanges","scope","since","outputs","cacheOptions","outputGlob","getFilteredPackages","includeDependencies","includeDependents","sinceIgnoreGlobs","pickerOptions","runnerPickerOptions","nodeArg","npmClient","runnerPicker","TargetRunnerPicker","optimizedTargets","optimizeTargetGraph","binPaths","getBinPaths","packageTasks","map","target","generatePackageTask","info","generateCommand","workingDirectory","getWorkingDirectory","packageTask","id","package","packageName","task","shouldRunWorkersAsService","env","LAGE_WORKER_SERVER","type","script","undefined","scripts","startsWith","parsed","parse","length","every","entry","getNpmArgs","host","port","parseServerOption","concurrency","push","toString","lage","path","relative","replace","taskTargs","extraArgs"],"mappings":";;;;+BA8EsBA;;;eAAAA;;;mCA7EY;oCACC;wBAET;gCAC2C;qCACjC;+DACX;6DACR;4BACK;qCAIc;yBACD;6BACP;qCACQ;mCACF;qCACE;;;;;;AA4D7B,eAAeA,WAAWC,OAA0B,EAAEC,OAAgB;IAC3E,MAAMC,MAAMC,QAAQD,GAAG;IACvB,MAAME,SAAS,MAAMC,IAAAA,iBAAS,EAACH;IAC/B,MAAMI,SAASC,IAAAA,eAAY;IAC3BP,QAAQQ,QAAQ,GAAGR,QAAQQ,QAAQ,I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C7B,OAAOU,IAAI;QACxB3D,QAAQ8E,IAAI,IAAI9D;QAChB,OAAOhB;IACT;IAEA,OAAO,EAAE;AACX;AAEA,SAASsD,oBAAoBL,MAAM;IACjC,MAAMhD,MAAMC,QAAQD,GAAG;IACvB,MAAMoD,mBAAmB4B,aAAI,CAACC,QAAQ,CAACtE,IAAAA,gCAAgB,EAACX,QAAQ,IAAIgD,OAAOhD,GAAG,EAAEkF,OAAO,CAAC,OAAO;IAC/F,OAAO9B;AACT;AAEA,SAASoB,WAAWd,IAAY,EAAEyB,SAAmB;IACnD,MAAMC,YAAYD,aAAanB,aAAamB,UAAUd,MAAM,GAAG,IAAI;QAAC;WAASc;KAAU,GAAG,EAAE;IAC5F,OAAO;QAAC;QAAOzB;WAAS0B;KAAU;AACpC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Logger } from "@lage-run/logger";
|
|
2
|
+
export interface launchServerInBackgroundOptions {
|
|
3
|
+
logger: Logger;
|
|
4
|
+
root: string;
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
tasks: string[];
|
|
8
|
+
timeout: number;
|
|
9
|
+
args: string[];
|
|
10
|
+
nodeArg?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function launchServerInBackground({ logger, root, host, port, tasks, timeout, args, nodeArg, }: launchServerInBackgroundOptions): Promise<void>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "launchServerInBackground", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return launchServerInBackground;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
+
const _properlockfile = /*#__PURE__*/ _interop_require_default(require("proper-lockfile"));
|
|
14
|
+
const _execa = /*#__PURE__*/ _interop_require_default(require("execa"));
|
|
15
|
+
const _getBinPaths = require("../getBinPaths.js");
|
|
16
|
+
function _interop_require_default(obj) {
|
|
17
|
+
return obj && obj.__esModule ? obj : {
|
|
18
|
+
default: obj
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async function launchServerInBackground({ logger, root, host, port, tasks, timeout, args, nodeArg }) {
|
|
22
|
+
const lockfilePath = _path.default.join(root, `node_modules/.cache/lage/.lage-server-${host}-${port}.pid`);
|
|
23
|
+
logger.info(`Starting server on http://${host}:${port}`);
|
|
24
|
+
logger.info(`acquiring lock: ${lockfilePath}`);
|
|
25
|
+
ensurePidFile(lockfilePath);
|
|
26
|
+
const releaseLock = await _properlockfile.default.lock(lockfilePath, {
|
|
27
|
+
stale: 1000 * 60 * 1,
|
|
28
|
+
retries: {
|
|
29
|
+
retries: 10,
|
|
30
|
+
factor: 3,
|
|
31
|
+
minTimeout: 0.5 * 1000,
|
|
32
|
+
maxTimeout: 60 * 1000,
|
|
33
|
+
randomize: true
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const pid = parseInt(_fs.default.readFileSync(lockfilePath, "utf-8"));
|
|
37
|
+
const isServerRunning = pid && isAlive(pid);
|
|
38
|
+
logger.info("Checking if server is already running", {
|
|
39
|
+
pid,
|
|
40
|
+
isServerRunning
|
|
41
|
+
});
|
|
42
|
+
if (pid && isServerRunning) {
|
|
43
|
+
logger.info("Server already running", {
|
|
44
|
+
pid
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
const binScripts = (0, _getBinPaths.getBinScripts)();
|
|
48
|
+
const lageServerBinPath = binScripts["lage-server"];
|
|
49
|
+
const lageServerArgs = [
|
|
50
|
+
...nodeArg ? [
|
|
51
|
+
"--node-arg",
|
|
52
|
+
nodeArg
|
|
53
|
+
] : [],
|
|
54
|
+
lageServerBinPath,
|
|
55
|
+
"--tasks",
|
|
56
|
+
...tasks,
|
|
57
|
+
"--host",
|
|
58
|
+
host,
|
|
59
|
+
"--port",
|
|
60
|
+
`${port}`,
|
|
61
|
+
"--timeout",
|
|
62
|
+
`${timeout}`,
|
|
63
|
+
...args
|
|
64
|
+
];
|
|
65
|
+
logger.info(`Launching lage-server with these parameters: ${lageServerArgs.join(" ")}`);
|
|
66
|
+
const child = (0, _execa.default)("node", lageServerArgs, {
|
|
67
|
+
cwd: root,
|
|
68
|
+
detached: true,
|
|
69
|
+
stdio: "ignore",
|
|
70
|
+
maxBuffer: 1024 * 1024 * 100
|
|
71
|
+
});
|
|
72
|
+
if (child && child.pid) {
|
|
73
|
+
_fs.default.writeFileSync(lockfilePath, child.pid.toString());
|
|
74
|
+
}
|
|
75
|
+
child.unref();
|
|
76
|
+
logger.info("Server started", {
|
|
77
|
+
pid: child.pid
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
await releaseLock();
|
|
81
|
+
}
|
|
82
|
+
function ensurePidFile(lockfilePath) {
|
|
83
|
+
if (!_fs.default.existsSync(_path.default.dirname(lockfilePath))) {
|
|
84
|
+
_fs.default.mkdirSync(_path.default.dirname(lockfilePath), {
|
|
85
|
+
recursive: true
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (!_fs.default.existsSync(lockfilePath)) {
|
|
89
|
+
try {
|
|
90
|
+
const fd = _fs.default.openSync(lockfilePath, "w");
|
|
91
|
+
_fs.default.closeSync(fd);
|
|
92
|
+
} catch {
|
|
93
|
+
// ignore
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function isAlive(pid) {
|
|
98
|
+
try {
|
|
99
|
+
return process.kill(pid, 0);
|
|
100
|
+
} catch {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/commands/launchServerInBackground.ts"],"sourcesContent":["import type { Logger } from \"@lage-run/logger\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport lockfile from \"proper-lockfile\";\nimport execa from \"execa\";\nimport { getBinPaths, getBinScripts } from \"../getBinPaths.js\";\n\nexport interface launchServerInBackgroundOptions {\n logger: Logger;\n root: string;\n host: string;\n port: number;\n tasks: string[];\n timeout: number;\n args: string[];\n nodeArg?: string;\n}\n\nexport async function launchServerInBackground({\n logger,\n root,\n host,\n port,\n tasks,\n timeout,\n args,\n nodeArg,\n}: launchServerInBackgroundOptions) {\n const lockfilePath = path.join(root, `node_modules/.cache/lage/.lage-server-${host}-${port}.pid`);\n\n logger.info(`Starting server on http://${host}:${port}`);\n logger.info(`acquiring lock: ${lockfilePath}`);\n\n ensurePidFile(lockfilePath);\n\n const releaseLock = await lockfile.lock(lockfilePath, {\n stale: 1000 * 60 * 1,\n retries: {\n retries: 10,\n factor: 3,\n minTimeout: 0.5 * 1000,\n maxTimeout: 60 * 1000,\n randomize: true,\n },\n });\n\n const pid = parseInt(fs.readFileSync(lockfilePath, \"utf-8\"));\n const isServerRunning = pid && isAlive(pid);\n logger.info(\"Checking if server is already running\", { pid, isServerRunning });\n if (pid && isServerRunning) {\n logger.info(\"Server already running\", { pid });\n } else {\n const binScripts = getBinScripts();\n\n const lageServerBinPath = binScripts[\"lage-server\"];\n const lageServerArgs = [\n ...(nodeArg ? [\"--node-arg\", nodeArg] : []),\n lageServerBinPath,\n \"--tasks\",\n ...tasks,\n \"--host\",\n host,\n \"--port\",\n `${port}`,\n \"--timeout\",\n `${timeout}`,\n ...args,\n ];\n\n logger.info(`Launching lage-server with these parameters: ${lageServerArgs.join(\" \")}`);\n const child = execa(\"node\", lageServerArgs, {\n cwd: root,\n detached: true,\n stdio: \"ignore\",\n maxBuffer: 1024 * 1024 * 100,\n });\n\n if (child && child.pid) {\n fs.writeFileSync(lockfilePath, child.pid.toString());\n }\n\n child.unref();\n logger.info(\"Server started\", { pid: child.pid });\n }\n\n await releaseLock();\n}\n\nfunction ensurePidFile(lockfilePath: string) {\n if (!fs.existsSync(path.dirname(lockfilePath))) {\n fs.mkdirSync(path.dirname(lockfilePath), { recursive: true });\n }\n\n if (!fs.existsSync(lockfilePath)) {\n try {\n const fd = fs.openSync(lockfilePath, \"w\");\n fs.closeSync(fd);\n } catch {\n // ignore\n }\n }\n}\n\nfunction isAlive(pid: number) {\n try {\n return process.kill(pid, 0);\n } catch {\n return false;\n }\n}\n"],"names":["launchServerInBackground","logger","root","host","port","tasks","timeout","args","nodeArg","lockfilePath","path","join","info","ensurePidFile","releaseLock","lockfile","lock","stale","retries","factor","minTimeout","maxTimeout","randomize","pid","parseInt","fs","readFileSync","isServerRunning","isAlive","binScripts","getBinScripts","lageServerBinPath","lageServerArgs","child","execa","cwd","detached","stdio","maxBuffer","writeFileSync","toString","unref","existsSync","dirname","mkdirSync","recursive","fd","openSync","closeSync","process","kill"],"mappings":";;;;+BAkBsBA;;;eAAAA;;;2DAjBP;6DACE;uEACI;8DACH;6BACyB;;;;;;AAapC,eAAeA,yBAAyB,EAC7CC,MAAM,EACNC,IAAI,EACJC,IAAI,EACJC,IAAI,EACJC,KAAK,EACLC,OAAO,EACPC,IAAI,EACJC,OAAO,EACyB;IAChC,MAAMC,eAAeC,aAAI,CAACC,IAAI,CAACT,MAAM,CAAC,sCAAsC,EAAEC,KAAK,CAAC,EAAEC,KAAK,IAAI,CAAC;IAEhGH,OAAOW,IAAI,CAAC,CAAC,0BAA0B,EAAET,KAAK,CAAC,EAAEC,MAAM;IACvDH,OAAOW,IAAI,CAAC,CAAC,gBAAgB,EAAEH,cAAc;IAE7CI,cAAcJ;IAEd,MAAMK,cAAc,MAAMC,uBAAQ,CAACC,IAAI,CAACP,cAAc;QACpDQ,OAAO,OAAO,KAAK;QACnBC,SAAS;YACPA,SAAS;YACTC,QAAQ;YACRC,YAAY,MAAM;YAClBC,YAAY,KAAK;YACjBC,WAAW;QACb;IACF;IAEA,MAAMC,MAAMC,SAASC,WAAE,CAACC,YAAY,CAACjB,cAAc;IACnD,MAAMkB,kBAAkBJ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F;AACF;AAEA,SAASlB,QAAQL,GAAW;IAC1B,IAAI;QACF,OAAO0B,QAAQC,IAAI,CAAC3B,KAAK;IAC3B,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
|
|
@@ -18,7 +18,7 @@ function _interop_require_default(obj) {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
async function serverAction(options) {
|
|
21
|
-
const { port = 5332, host = "localhost", timeout = 1 } = options;
|
|
21
|
+
const { port = 5332, host = "localhost", timeout = 1, tasks } = options;
|
|
22
22
|
const logger = (0, _logger.default)();
|
|
23
23
|
options.logLevel = options.logLevel ?? "info";
|
|
24
24
|
options.logFile = options.logFile ?? "node_modules/.cache/lage/server.log";
|
|
@@ -34,7 +34,8 @@ async function serverAction(options) {
|
|
|
34
34
|
clearCountdown: clearTimer
|
|
35
35
|
},
|
|
36
36
|
logger,
|
|
37
|
-
|
|
37
|
+
concurrency: options.concurrency,
|
|
38
|
+
tasks
|
|
38
39
|
});
|
|
39
40
|
const server = await (0, _rpc.createServer)(lageService, abortController);
|
|
40
41
|
await server.listen({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/server/action.ts"],"sourcesContent":["import createLogger, { type Logger } from \"@lage-run/logger\";\nimport type { ReporterInitOptions } from \"../../types/ReporterInitOptions.js\";\nimport { initializeReporters } from \"../initializeReporters.js\";\nimport { createLageService } from \"./lageService.js\";\nimport { createServer } from \"@lage-run/rpc\";\n\ninterface WorkerOptions extends ReporterInitOptions {\n nodeArg?: string[];\n port?: number;\n host?: string;\n timeout?: number;\n shutdown: boolean;\n}\n\nexport async function serverAction(options: WorkerOptions) {\n const { port = 5332, host = \"localhost\", timeout = 1 } = options;\n\n const logger = createLogger();\n options.logLevel = options.logLevel ?? \"info\";\n options.logFile = options.logFile ?? \"node_modules/.cache/lage/server.log\";\n options.reporter = options.reporter ?? \"verboseFileLog\";\n initializeReporters(logger, options);\n\n logger.info(`Starting server on http://${host}:${port}`);\n\n const abortController = new AbortController();\n\n const lageService = await createLageService({\n cwd: process.cwd(),\n serverControls: {\n abortController,\n countdownToShutdown: () => resetTimer(logger, timeout, abortController, server),\n clearCountdown: clearTimer,\n },\n logger,\n
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/server/action.ts"],"sourcesContent":["import createLogger, { type Logger } from \"@lage-run/logger\";\nimport type { ReporterInitOptions } from \"../../types/ReporterInitOptions.js\";\nimport { initializeReporters } from \"../initializeReporters.js\";\nimport { createLageService } from \"./lageService.js\";\nimport { createServer } from \"@lage-run/rpc\";\n\ninterface WorkerOptions extends ReporterInitOptions {\n nodeArg?: string[];\n port?: number;\n host?: string;\n timeout?: number;\n shutdown: boolean;\n tasks: string[];\n}\n\nexport async function serverAction(options: WorkerOptions) {\n const { port = 5332, host = \"localhost\", timeout = 1, tasks } = options;\n\n const logger = createLogger();\n options.logLevel = options.logLevel ?? \"info\";\n options.logFile = options.logFile ?? \"node_modules/.cache/lage/server.log\";\n options.reporter = options.reporter ?? \"verboseFileLog\";\n initializeReporters(logger, options);\n\n logger.info(`Starting server on http://${host}:${port}`);\n\n const abortController = new AbortController();\n\n const lageService = await createLageService({\n cwd: process.cwd(),\n serverControls: {\n abortController,\n countdownToShutdown: () => resetTimer(logger, timeout, abortController, server),\n clearCountdown: clearTimer,\n },\n logger,\n concurrency: options.concurrency,\n tasks,\n });\n const server = await createServer(lageService, abortController);\n\n await server.listen({ host, port });\n logger.info(`Server listening on http://${host}:${port}, timeout in ${timeout} seconds`);\n}\n\nlet timeoutHandle: NodeJS.Timeout | undefined;\nfunction resetTimer(logger: Logger, timeout: number, abortController: AbortController, server: any) {\n clearTimer();\n\n timeoutHandle = globalThis.setTimeout(() => {\n logger.info(`Server timed out after ${timeout} seconds`);\n abortController.abort();\n server.close();\n }, timeout * 1000);\n}\n\nfunction clearTimer() {\n if (timeoutHandle) {\n globalThis.clearTimeout(timeoutHandle);\n }\n}\n"],"names":["serverAction","options","port","host","timeout","tasks","logger","createLogger","logLevel","logFile","reporter","initializeReporters","info","abortController","AbortController","lageService","createLageService","cwd","process","serverControls","countdownToShutdown","resetTimer","server","clearCountdown","clearTimer","concurrency","createServer","listen","timeoutHandle","globalThis","setTimeout","abort","close","clearTimeout"],"mappings":";;;;+BAesBA;;;eAAAA;;;+DAfoB;qCAEN;6BACF;qBACL;;;;;;AAWtB,eAAeA,aAAaC,OAAsB;IACvD,MAAM,EAAEC,OAAO,IAAI,EAAEC,OAAO,WAAW,EAAEC,UAAU,CAAC,EAAEC,KAAK,EAAE,GAAGJ;IAEhE,MAAMK,SAASC,IAAAA,eAAY;IAC3BN,QAAQO,QAAQ,GAAGP,QAAQO,QAAQ,IAAI;IACvCP,QAAQQ,OAAO,GAAGR,QAAQQ,OAAO,IAAI;IACrCR,QAAQS,QAAQ,GAAGT,QAAQS,QAAQ,IAAI;IACvCC,IAAAA,wCAAmB,EAACL,QAAQL;IAE5BK,OAAOM,IAAI,CAAC,CAAC,0BAA0B,EAAET,KAAK,CAAC,EAAED,MAAM;IAEvD,MAAMW,kBAAkB,IAAIC;IAE5B,MAAMC,cAAc,MAAMC,IAAAA,8BAAiB,EAAC;QAC1CC,KAAKC,QAAQD,GAAG;QAChBE,gBAAgB;YACdN;YACAO,qBAAqB,IAAMC,WAAWf,QAAQF,SAASS,iBAAiBS;YACxEC,gBAAgBC;QAClB;QACAlB;QACAmB,aAAaxB,QAAQwB,WAAW;QAChCpB;IACF;IACA,MAAMiB,SAAS,MAAMI,IAAAA,iBAAY,EAACX,aAAaF;IAE/C,MAAMS,OAAOK,MAAM,CAAC;QAAExB;QAAMD;IAAK;IACjCI,OAAOM,IAAI,CAAC,CAAC,2BAA2B,EAAET,KAAK,CAAC,EAAED,KAAK,aAAa,EAAEE,QAAQ,QAAQ,CAAC;AACzF;AAEA,IAAIwB;AACJ,SAASP,WAAWf,MAAc,EAAEF,OAAe,EAAES,eAAgC,EAAES,MAAW;IAChGE;IAEAI,gBAAgBC,WAAWC,UAAU,CAAC;QACpCxB,OAAOM,IAAI,CAAC,CAAC,uBAAuB,EAAER,QAAQ,QAAQ,CAAC;QACvDS,gBAAgBkB,KAAK;QACrBT,OAAOU,KAAK;IACd,GAAG5B,UAAU;AACf;AAEA,SAASoB;IACP,IAAII,eAAe;QACjBC,WAAWI,YAAY,CAACL;IAC1B;AACF"}
|
|
@@ -8,18 +8,14 @@ Object.defineProperty(exports, "serverCommand", {
|
|
|
8
8
|
return serverCommand;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _os = /*#__PURE__*/ _interop_require_default(require("os"));
|
|
12
11
|
const _commander = require("commander");
|
|
13
12
|
const _action = require("./action.js");
|
|
14
13
|
const _addLoggerOptions = require("../addLoggerOptions.js");
|
|
15
|
-
function _interop_require_default(obj) {
|
|
16
|
-
return obj && obj.__esModule ? obj : {
|
|
17
|
-
default: obj
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
14
|
const serverCommand = new _commander.Command("server");
|
|
21
|
-
serverCommand.option("-
|
|
15
|
+
serverCommand.option("-n|--node-arg <arg>", "node argument to pass to worker, just a single string to be passed into node like a NODE_OPTIONS setting");
|
|
16
|
+
serverCommand.option("-c|--concurrency <number>", "max jobs to run at a time", (v)=>parseInt(v));
|
|
22
17
|
serverCommand.option("-h|--host <host>", "lage server host", "localhost");
|
|
23
18
|
serverCommand.option("-p|--port <port>", "lage worker server port", (v)=>parseInt(v), 5332);
|
|
24
|
-
serverCommand.option("-t|--timeout <seconds>", "lage server autoshutoff timeout", (v)=>parseInt(v),
|
|
19
|
+
serverCommand.option("-t|--timeout <seconds>", "lage server autoshutoff timeout", (v)=>parseInt(v), 5 * 60);
|
|
20
|
+
serverCommand.option("--tasks <tasks...>", "A list of tasks to run, separated by space e.g. 'build test'");
|
|
25
21
|
(0, _addLoggerOptions.addLoggerOptions)(serverCommand).action(_action.serverAction);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/server/index.ts"],"sourcesContent":["import os from \"os\";\nimport { Command } from \"commander\";\nimport { serverAction } from \"./action.js\";\nimport { addLoggerOptions } from \"../addLoggerOptions.js\";\n\nconst serverCommand = new Command(\"server\");\nserverCommand.option(\"-c|--concurrency <number>\", \"max jobs to run at a time\", (v) => parseInt(v)
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/server/index.ts"],"sourcesContent":["import os from \"os\";\nimport { Command } from \"commander\";\nimport { serverAction } from \"./action.js\";\nimport { addLoggerOptions } from \"../addLoggerOptions.js\";\n\nconst serverCommand = new Command(\"server\");\nserverCommand.option(\n \"-n|--node-arg <arg>\",\n \"node argument to pass to worker, just a single string to be passed into node like a NODE_OPTIONS setting\"\n);\nserverCommand.option(\"-c|--concurrency <number>\", \"max jobs to run at a time\", (v) => parseInt(v));\nserverCommand.option(\"-h|--host <host>\", \"lage server host\", \"localhost\");\nserverCommand.option<number>(\"-p|--port <port>\", \"lage worker server port\", (v) => parseInt(v), 5332);\nserverCommand.option<number>(\"-t|--timeout <seconds>\", \"lage server autoshutoff timeout\", (v) => parseInt(v), 5 * 60);\nserverCommand.option(\"--tasks <tasks...>\", \"A list of tasks to run, separated by space e.g. 'build test'\");\n\naddLoggerOptions(serverCommand).action(serverAction);\n\nexport { serverCommand };\n"],"names":["serverCommand","Command","option","v","parseInt","addLoggerOptions","action","serverAction"],"mappings":";;;;+BAkBSA;;;eAAAA;;;2BAjBe;wBACK;kCACI;AAEjC,MAAMA,gBAAgB,IAAIC,kBAAO,CAAC;AAClCD,cAAcE,MAAM,CAClB,uBACA;AAEFF,cAAcE,MAAM,CAAC,6BAA6B,6BAA6B,CAACC,IAAMC,SAASD;AAC/FH,cAAcE,MAAM,CAAC,oBAAoB,oBAAoB;AAC7DF,cAAcE,MAAM,CAAS,oBAAoB,2BAA2B,CAACC,IAAMC,SAASD,IAAI;AAChGH,cAAcE,MAAM,CAAS,0BAA0B,mCAAmC,CAACC,IAAMC,SAASD,IAAI,IAAI;AAClHH,cAAcE,MAAM,CAAC,sBAAsB;AAE3CG,IAAAA,kCAAgB,EAACL,eAAeM,MAAM,CAACC,oBAAY"}
|
|
@@ -6,10 +6,12 @@ interface ServiceControls {
|
|
|
6
6
|
countdownToShutdown: () => void;
|
|
7
7
|
clearCountdown: () => void;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
interface CreateLageServiceOptions {
|
|
10
10
|
cwd: string;
|
|
11
11
|
serverControls: ServiceControls;
|
|
12
12
|
logger: Logger;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
concurrency?: number;
|
|
14
|
+
tasks: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare function createLageService({ cwd, serverControls, logger, concurrency, tasks, }: CreateLageServiceOptions): Promise<ILageService>;
|
|
15
17
|
export {};
|
|
@@ -14,99 +14,101 @@ const _workspacetools = require("workspace-tools");
|
|
|
14
14
|
const _createTargetGraph = require("../run/createTargetGraph.js");
|
|
15
15
|
const _workerthreadspool = require("@lage-run/worker-threads-pool");
|
|
16
16
|
const _hasher = require("@lage-run/hasher");
|
|
17
|
-
const _getOutputFiles = require("./getOutputFiles.js");
|
|
18
|
-
const _globby = require("@lage-run/globby");
|
|
19
17
|
const _MemoryStream = require("./MemoryStream.js");
|
|
20
18
|
const _runnerPickerOptions = require("../../runnerPickerOptions.js");
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
const _filterPipelineDefinitions = require("../run/filterPipelineDefinitions.js");
|
|
20
|
+
const _formathrtime = require("@lage-run/format-hrtime");
|
|
21
|
+
let initializedPromise;
|
|
22
|
+
function formatBytes(bytes) {
|
|
23
|
+
return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
|
|
24
|
+
}
|
|
25
|
+
async function createInitializedPromise({ cwd, logger, serverControls, nodeArg, taskArgs, concurrency, tasks }) {
|
|
26
|
+
if (initializedPromise) {
|
|
27
|
+
return initializedPromise;
|
|
30
28
|
}
|
|
31
|
-
|
|
29
|
+
const config = await (0, _config.getConfig)(cwd);
|
|
30
|
+
const root = (0, _workspacetools.getWorkspaceRoot)(cwd);
|
|
31
|
+
const maxWorkers = (0, _config.getConcurrency)(concurrency, config.concurrency);
|
|
32
|
+
logger.info(`Initializing with ${maxWorkers} workers, tasks: ${tasks.join(", ")}`);
|
|
33
|
+
const { pipeline } = config;
|
|
34
|
+
const packageInfos = (0, _workspacetools.getPackageInfos)(root);
|
|
35
|
+
const targetGraph = await (0, _createTargetGraph.createTargetGraph)({
|
|
36
|
+
logger,
|
|
37
|
+
root,
|
|
38
|
+
dependencies: false,
|
|
39
|
+
dependents: false,
|
|
40
|
+
ignore: [],
|
|
41
|
+
pipeline,
|
|
42
|
+
repoWideChanges: config.repoWideChanges,
|
|
43
|
+
scope: undefined,
|
|
44
|
+
since: undefined,
|
|
45
|
+
outputs: config.cacheOptions.outputGlob,
|
|
46
|
+
tasks,
|
|
47
|
+
packageInfos
|
|
48
|
+
});
|
|
49
|
+
const dependencyMap = (0, _workspacetools.createDependencyMap)(packageInfos, {
|
|
50
|
+
withDevDependencies: true,
|
|
51
|
+
withPeerDependencies: false
|
|
52
|
+
});
|
|
53
|
+
const packageTree = new _hasher.PackageTree({
|
|
54
|
+
root,
|
|
55
|
+
packageInfos,
|
|
56
|
+
includeUntracked: true
|
|
57
|
+
});
|
|
58
|
+
logger.info("Initializing Package Tree");
|
|
59
|
+
await packageTree.initialize();
|
|
60
|
+
const filteredPipeline = (0, _filterPipelineDefinitions.filterPipelineDefinitions)(targetGraph.targets.values(), config.pipeline);
|
|
61
|
+
const pool = new _workerthreadspool.AggregatedPool({
|
|
62
|
+
logger,
|
|
63
|
+
maxWorkersByGroup: new Map([
|
|
64
|
+
...(0, _config.getMaxWorkersPerTask)(filteredPipeline, maxWorkers)
|
|
65
|
+
]),
|
|
66
|
+
groupBy: ({ target })=>target.task,
|
|
67
|
+
maxWorkers,
|
|
68
|
+
script: require.resolve("./singleTargetWorker.js"),
|
|
69
|
+
workerOptions: {
|
|
70
|
+
stdout: true,
|
|
71
|
+
stderr: true,
|
|
72
|
+
workerData: {
|
|
73
|
+
runners: {
|
|
74
|
+
...(0, _runnerPickerOptions.runnerPickerOptions)(nodeArg, config.npmClient, taskArgs),
|
|
75
|
+
...config.runners,
|
|
76
|
+
shouldCache: false,
|
|
77
|
+
shouldResetCache: false
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
workerIdleMemoryLimit: config.workerIdleMemoryLimit
|
|
82
|
+
});
|
|
83
|
+
serverControls.abortController.signal.addEventListener("abort", ()=>{
|
|
84
|
+
pool?.close();
|
|
85
|
+
});
|
|
86
|
+
pool?.on("freedWorker", ()=>{
|
|
87
|
+
logger.silly(`Max Worker Memory Usage: ${formatBytes(pool?.stats().maxWorkerMemoryUsage)}`);
|
|
88
|
+
});
|
|
89
|
+
pool?.on("idle", ()=>{
|
|
90
|
+
logger.info("All workers are idle, shutting down after timeout");
|
|
91
|
+
serverControls.countdownToShutdown();
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
config,
|
|
95
|
+
targetGraph,
|
|
96
|
+
packageTree,
|
|
97
|
+
dependencyMap,
|
|
98
|
+
root,
|
|
99
|
+
pool
|
|
100
|
+
};
|
|
32
101
|
}
|
|
33
|
-
let initializedPromise;
|
|
34
102
|
/**
|
|
35
103
|
* Initializes the lageService: the extra "initializePromise" ensures only one initialization is done at a time across threads
|
|
36
104
|
* @param cwd
|
|
37
105
|
* @param logger
|
|
38
106
|
* @returns
|
|
39
|
-
*/ async function initialize(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
async function createInitializedPromise() {
|
|
44
|
-
logger.info("Initializing context");
|
|
45
|
-
const config = await (0, _config.getConfig)(cwd);
|
|
46
|
-
const root = (0, _workspacetools.getWorkspaceRoot)(cwd);
|
|
47
|
-
const { pipeline } = config;
|
|
48
|
-
const packageInfos = (0, _workspacetools.getPackageInfos)(root);
|
|
49
|
-
const tasks = findAllTasks(pipeline);
|
|
50
|
-
const targetGraph = await (0, _createTargetGraph.createTargetGraph)({
|
|
51
|
-
logger,
|
|
52
|
-
root,
|
|
53
|
-
dependencies: false,
|
|
54
|
-
dependents: false,
|
|
55
|
-
ignore: [],
|
|
56
|
-
pipeline,
|
|
57
|
-
repoWideChanges: config.repoWideChanges,
|
|
58
|
-
scope: undefined,
|
|
59
|
-
since: undefined,
|
|
60
|
-
outputs: config.cacheOptions.outputGlob,
|
|
61
|
-
tasks,
|
|
62
|
-
packageInfos
|
|
63
|
-
});
|
|
64
|
-
const dependencyMap = (0, _workspacetools.createDependencyMap)(packageInfos, {
|
|
65
|
-
withDevDependencies: true,
|
|
66
|
-
withPeerDependencies: false
|
|
67
|
-
});
|
|
68
|
-
const packageTree = new _hasher.PackageTree({
|
|
69
|
-
root,
|
|
70
|
-
packageInfos,
|
|
71
|
-
includeUntracked: true
|
|
72
|
-
});
|
|
73
|
-
logger.info("Initializing Package Tree");
|
|
74
|
-
await packageTree.initialize();
|
|
75
|
-
const pool = new _workerthreadspool.WorkerPool({
|
|
76
|
-
script: require.resolve("./singleTargetWorker.js"),
|
|
77
|
-
maxWorkers,
|
|
78
|
-
workerOptions: {
|
|
79
|
-
stderr: true,
|
|
80
|
-
stdout: true,
|
|
81
|
-
workerData: {
|
|
82
|
-
runners: {
|
|
83
|
-
...(0, _runnerPickerOptions.runnerPickerOptions)(nodeArg, config.npmClient, taskArgs),
|
|
84
|
-
...config.runners
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
serverControls.abortController.signal.addEventListener("abort", ()=>{
|
|
90
|
-
pool?.close();
|
|
91
|
-
});
|
|
92
|
-
pool?.on("idle", ()=>{
|
|
93
|
-
logger.info("All workers are idle, shutting down after timeout");
|
|
94
|
-
serverControls.countdownToShutdown();
|
|
95
|
-
});
|
|
96
|
-
return {
|
|
97
|
-
config,
|
|
98
|
-
targetGraph,
|
|
99
|
-
packageTree,
|
|
100
|
-
dependencyMap,
|
|
101
|
-
root,
|
|
102
|
-
pool
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
initializedPromise = createInitializedPromise();
|
|
106
|
-
return await initializedPromise;
|
|
107
|
+
*/ async function initialize(options) {
|
|
108
|
+
initializedPromise = createInitializedPromise(options);
|
|
109
|
+
return initializedPromise;
|
|
107
110
|
}
|
|
108
|
-
async function createLageService({ cwd, serverControls, logger,
|
|
109
|
-
logger.info(`Server started with ${maxWorkers} workers`);
|
|
111
|
+
async function createLageService({ cwd, serverControls, logger, concurrency, tasks }) {
|
|
110
112
|
return {
|
|
111
113
|
async ping () {
|
|
112
114
|
return {
|
|
@@ -114,6 +116,9 @@ async function createLageService({ cwd, serverControls, logger, maxWorkers }) {
|
|
|
114
116
|
};
|
|
115
117
|
},
|
|
116
118
|
async runTarget (request) {
|
|
119
|
+
if (global.gc) {
|
|
120
|
+
global.gc();
|
|
121
|
+
}
|
|
117
122
|
serverControls.clearCountdown();
|
|
118
123
|
// THIS IS A BIG ASSUMPTION; TODO: memoize based on the parameters of the initialize() call
|
|
119
124
|
// The first request sets up the nodeArg and taskArgs - we are assuming that all requests to run this target are coming from the same
|
|
@@ -124,9 +129,9 @@ async function createLageService({ cwd, serverControls, logger, maxWorkers }) {
|
|
|
124
129
|
nodeArg: request.nodeOptions,
|
|
125
130
|
taskArgs: request.taskArgs,
|
|
126
131
|
serverControls,
|
|
127
|
-
|
|
132
|
+
concurrency,
|
|
133
|
+
tasks
|
|
128
134
|
});
|
|
129
|
-
logger.info("Running target", request);
|
|
130
135
|
const runners = (0, _runnerPickerOptions.runnerPickerOptions)(request.nodeOptions, config.npmClient, request.taskArgs);
|
|
131
136
|
const id = (0, _targetgraph.getTargetId)(request.packageName, request.task);
|
|
132
137
|
if (!targetGraph.targets.has(id)) {
|
|
@@ -137,9 +142,6 @@ async function createLageService({ cwd, serverControls, logger, maxWorkers }) {
|
|
|
137
142
|
exitCode: 1
|
|
138
143
|
};
|
|
139
144
|
}
|
|
140
|
-
logger.info("Target found", {
|
|
141
|
-
id
|
|
142
|
-
});
|
|
143
145
|
const target = targetGraph.targets.get(id);
|
|
144
146
|
const task = {
|
|
145
147
|
target,
|
|
@@ -149,6 +151,20 @@ async function createLageService({ cwd, serverControls, logger, maxWorkers }) {
|
|
|
149
151
|
const writableStderr = new _MemoryStream.MemoryStream();
|
|
150
152
|
let pipedStdout;
|
|
151
153
|
let pipedStderr;
|
|
154
|
+
const targetRun = {
|
|
155
|
+
queueTime: process.hrtime(),
|
|
156
|
+
target,
|
|
157
|
+
duration: [
|
|
158
|
+
0,
|
|
159
|
+
0
|
|
160
|
+
],
|
|
161
|
+
startTime: [
|
|
162
|
+
0,
|
|
163
|
+
0
|
|
164
|
+
],
|
|
165
|
+
status: "queued",
|
|
166
|
+
threadId: 0
|
|
167
|
+
};
|
|
152
168
|
try {
|
|
153
169
|
await pool.exec(task, 0, (worker, stdout, stderr)=>{
|
|
154
170
|
logger.info(`[${worker.threadId}] ${request.packageName}#${request.task} start`);
|
|
@@ -156,30 +172,39 @@ async function createLageService({ cwd, serverControls, logger, maxWorkers }) {
|
|
|
156
172
|
pipedStderr = stderr;
|
|
157
173
|
stdout.pipe(writableStdout);
|
|
158
174
|
stderr.pipe(writableStderr);
|
|
175
|
+
targetRun.threadId = worker.threadId;
|
|
176
|
+
targetRun.status = "running";
|
|
177
|
+
targetRun.startTime = process.hrtime();
|
|
159
178
|
}, (worker)=>{
|
|
160
|
-
logger.info(`
|
|
179
|
+
logger.info(`Max Worker Memory Usage: ${formatBytes(pool.stats().maxWorkerMemoryUsage)}`);
|
|
180
|
+
// logger.info the main process memory usage
|
|
181
|
+
const memoryUsage = process.memoryUsage();
|
|
182
|
+
logger.info(`Main Process Memory Usage: RSS: ${formatBytes(memoryUsage.rss)} Heap Total: ${formatBytes(memoryUsage.heapTotal)} Heap Used: ${formatBytes(memoryUsage.heapUsed)}`);
|
|
183
|
+
targetRun.status = "success";
|
|
184
|
+
targetRun.duration = (0, _formathrtime.hrtimeDiff)(targetRun.startTime, process.hrtime());
|
|
185
|
+
logger.info(`[${worker.threadId}] ${request.packageName}#${request.task} end: ${(0, _formathrtime.formatDuration)((0, _formathrtime.hrToSeconds)(targetRun.duration))}`);
|
|
161
186
|
pipedStdout.unpipe(writableStdout);
|
|
162
187
|
pipedStderr.unpipe(writableStderr);
|
|
163
188
|
});
|
|
164
|
-
const globalInputs = target.environmentGlob
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}) : [
|
|
171
|
-
"lage.config.js"
|
|
172
|
-
];
|
|
173
|
-
const inputs = ((0, _hasher.getInputFiles)(target, dependencyMap, packageTree) ?? []).concat(globalInputs);
|
|
189
|
+
// const globalInputs = target.environmentGlob
|
|
190
|
+
// ? glob(target.environmentGlob, { cwd: root, gitignore: true })
|
|
191
|
+
// : config.cacheOptions?.environmentGlob
|
|
192
|
+
// ? glob(config.cacheOptions?.environmentGlob, { cwd: root, gitignore: true })
|
|
193
|
+
// : ["lage.config.js"];
|
|
194
|
+
// const inputs = (getInputFiles(target, dependencyMap, packageTree) ?? []).concat(globalInputs);
|
|
174
195
|
return {
|
|
175
196
|
packageName: request.packageName,
|
|
176
197
|
task: request.task,
|
|
177
198
|
exitCode: 0,
|
|
178
199
|
hash: "",
|
|
179
|
-
inputs,
|
|
180
|
-
outputs:
|
|
181
|
-
stdout: writableStdout.toString(),
|
|
182
|
-
stderr: writableStderr.toString(),
|
|
200
|
+
// inputs,
|
|
201
|
+
// outputs: getOutputFiles(root, target, config.cacheOptions?.outputGlob, packageTree),
|
|
202
|
+
// stdout: writableStdout.toString(),
|
|
203
|
+
// stderr: writableStderr.toString(),
|
|
204
|
+
inputs: [],
|
|
205
|
+
outputs: [],
|
|
206
|
+
stdout: "",
|
|
207
|
+
stderr: "",
|
|
183
208
|
id
|
|
184
209
|
};
|
|
185
210
|
} catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/server/lageService.ts"],"sourcesContent":["import { type ConfigOptions, getConfig, type PipelineDefinition } from \"@lage-run/config\";\nimport type { Logger } from \"@lage-run/logger\";\nimport type { ILageService } from \"@lage-run/rpc\";\nimport { getTargetId, type TargetGraph } from \"@lage-run/target-graph\";\nimport { type DependencyMap, getPackageInfos, getWorkspaceRoot } from \"workspace-tools\";\nimport { createTargetGraph } from \"../run/createTargetGraph.js\";\nimport { getPackageAndTask } from \"@lage-run/target-graph\";\nimport { type Readable } from \"stream\";\nimport { type Pool, WorkerPool } from \"@lage-run/worker-threads-pool\";\nimport { getInputFiles, PackageTree } from \"@lage-run/hasher\";\nimport { createDependencyMap } from \"workspace-tools\";\nimport { getOutputFiles } from \"./getOutputFiles.js\";\nimport { glob } from \"@lage-run/globby\";\nimport { MemoryStream } from \"./MemoryStream.js\";\nimport { runnerPickerOptions } from \"../../runnerPickerOptions.js\";\n\nfunction findAllTasks(pipeline: PipelineDefinition) {\n const tasks = new Set<string>();\n for (const key of Object.keys(pipeline)) {\n if (key.includes(\"#\") || key.startsWith(\"#\") || key.endsWith(\"//\")) {\n const { task } = getPackageAndTask(key);\n tasks.add(task);\n } else {\n tasks.add(key);\n }\n }\n return Array.from(tasks);\n}\n\ninterface LageServiceContext {\n config: ConfigOptions;\n targetGraph: TargetGraph;\n packageTree: PackageTree;\n dependencyMap: DependencyMap;\n root: string;\n pool: Pool;\n}\n\nlet initializedPromise: Promise<LageServiceContext> | undefined;\ninterface ServiceControls {\n abortController: AbortController;\n countdownToShutdown: () => void;\n clearCountdown: () => void;\n}\ninterface InitializeOptions {\n cwd: string;\n logger: Logger;\n serverControls: ServiceControls;\n maxWorkers?: number;\n nodeArg?: string;\n taskArgs: string[];\n}\n/**\n * Initializes the lageService: the extra \"initializePromise\" ensures only one initialization is done at a time across threads\n * @param cwd\n * @param logger\n * @returns\n */\nasync function initialize({ cwd, logger, serverControls, nodeArg, taskArgs, maxWorkers }: InitializeOptions): Promise<LageServiceContext> {\n if (initializedPromise) {\n return await initializedPromise;\n }\n\n async function createInitializedPromise() {\n logger.info(\"Initializing context\");\n const config = await getConfig(cwd);\n const root = getWorkspaceRoot(cwd)!;\n\n const { pipeline } = config;\n\n const packageInfos = getPackageInfos(root);\n const tasks = findAllTasks(pipeline);\n\n const targetGraph = await createTargetGraph({\n logger,\n root,\n dependencies: false,\n dependents: false,\n ignore: [],\n pipeline,\n repoWideChanges: config.repoWideChanges,\n scope: undefined,\n since: undefined,\n outputs: config.cacheOptions.outputGlob,\n tasks,\n packageInfos,\n });\n\n const dependencyMap = createDependencyMap(packageInfos, { withDevDependencies: true, withPeerDependencies: false });\n const packageTree = new PackageTree({\n root,\n packageInfos,\n includeUntracked: true,\n });\n\n logger.info(\"Initializing Package Tree\");\n await packageTree.initialize();\n\n const pool = new WorkerPool({\n script: require.resolve(\"./singleTargetWorker.js\"),\n maxWorkers,\n workerOptions: {\n stderr: true,\n stdout: true,\n workerData: {\n runners: {\n ...runnerPickerOptions(nodeArg, config.npmClient, taskArgs),\n ...config.runners,\n },\n },\n },\n });\n\n serverControls.abortController.signal.addEventListener(\"abort\", () => {\n pool?.close();\n });\n\n pool?.on(\"idle\", () => {\n logger.info(\"All workers are idle, shutting down after timeout\");\n serverControls.countdownToShutdown();\n });\n\n return { config, targetGraph, packageTree, dependencyMap, root, pool };\n }\n\n initializedPromise = createInitializedPromise();\n\n return await initializedPromise;\n}\n\nexport async function createLageService({\n cwd,\n serverControls,\n logger,\n maxWorkers,\n}: {\n cwd: string;\n serverControls: ServiceControls;\n logger: Logger;\n maxWorkers?: number;\n}): Promise<ILageService> {\n logger.info(`Server started with ${maxWorkers} workers`);\n\n return {\n async ping() {\n return { pong: true };\n },\n\n async runTarget(request) {\n serverControls.clearCountdown();\n\n // THIS IS A BIG ASSUMPTION; TODO: memoize based on the parameters of the initialize() call\n // The first request sets up the nodeArg and taskArgs - we are assuming that all requests to run this target are coming from the same\n // `lage info` call\n const { config, targetGraph, dependencyMap, packageTree, root, pool } = await initialize({\n cwd,\n logger,\n nodeArg: request.nodeOptions,\n taskArgs: request.taskArgs,\n serverControls,\n maxWorkers,\n });\n\n logger.info(\"Running target\", request);\n\n const runners = runnerPickerOptions(request.nodeOptions, config.npmClient, request.taskArgs);\n\n const id = getTargetId(request.packageName, request.task);\n\n if (!targetGraph.targets.has(id)) {\n logger.info(`Target not found: ${request.packageName}#${request.task}`);\n return {\n packageName: request.packageName,\n task: request.task,\n exitCode: 1,\n };\n }\n\n logger.info(\"Target found\", { id });\n\n const target = targetGraph.targets.get(id)!;\n const task = {\n target,\n runners,\n };\n\n const writableStdout = new MemoryStream();\n const writableStderr = new MemoryStream();\n let pipedStdout: Readable;\n let pipedStderr: Readable;\n\n try {\n await pool.exec(\n task,\n 0,\n (worker, stdout, stderr) => {\n logger.info(`[${worker.threadId}] ${request.packageName}#${request.task} start`);\n\n pipedStdout = stdout;\n pipedStderr = stderr;\n\n stdout.pipe(writableStdout);\n stderr.pipe(writableStderr);\n },\n (worker) => {\n logger.info(`[${worker.threadId}] ${request.packageName}#${request.task} end`);\n pipedStdout.unpipe(writableStdout);\n pipedStderr.unpipe(writableStderr);\n }\n );\n\n const globalInputs = target.environmentGlob\n ? glob(target.environmentGlob, { cwd: root, gitignore: true })\n : config.cacheOptions?.environmentGlob\n ? glob(config.cacheOptions?.environmentGlob, { cwd: root, gitignore: true })\n : [\"lage.config.js\"];\n const inputs = (getInputFiles(target, dependencyMap, packageTree) ?? []).concat(globalInputs);\n\n return {\n packageName: request.packageName,\n task: request.task,\n exitCode: 0,\n hash: \"\",\n inputs,\n outputs: getOutputFiles(root, target, config.cacheOptions?.outputGlob, packageTree),\n stdout: writableStdout.toString(),\n stderr: writableStderr.toString(),\n id,\n };\n } catch (e) {\n return {\n packageName: request.packageName,\n task: request.task,\n exitCode: 1,\n hash: \"\",\n inputs: [],\n outputs: [],\n stdout: \"\",\n stderr: e instanceof Error ? e.toString() : \"\",\n id,\n };\n }\n },\n };\n}\n"],"names":["createLageService","findAllTasks","pipeline","tasks","Set","key","Object","keys","includes","startsWith","endsWith","task","getPackageAndTask","add","Array","from","initializedPromise","initialize","cwd","logger","serverControls","nodeArg","taskArgs","maxWorkers","createInitializedPromise","info","config","getConfig","root","getWorkspaceRoot","packageInfos","getPackageInfos","targetGraph","createTargetGraph","dependencies","dependents","ignore","repoWideChanges","scope","undefined","since","outputs","cacheOptions","outputGlob","dependencyMap","createDependencyMap","withDevDependencies","withPeerDependencies","packageTree","PackageTree","includeUntracked","pool","WorkerPool","script","require","resolve","workerOptions","stderr","stdout","workerData","runners","runnerPickerOptions","npmClient","abortController","signal","addEventListener","close","on","countdownToShutdown","ping","pong","runTarget","request","clearCountdown","nodeOptions","id","getTargetId","packageName","targets","has","exitCode","target","get","writableStdout","MemoryStream","writableStderr","pipedStdout","pipedStderr","exec","worker","threadId","pipe","unpipe","globalInputs","environmentGlob","glob","gitignore","inputs","getInputFiles","concat","hash","getOutputFiles","toString","e","Error"],"mappings":";;;;+BAkIsBA;;;eAAAA;;;wBAlIiD;6BAGzB;gCACwB;mCACpC;mCAGI;wBACK;gCAEZ;wBACV;8BACQ;qCACO;AAEpC,SAASC,aAAaC,QAA4B;IAChD,MAAMC,QAAQ,IAAIC;IAClB,KAAK,MAAMC,OAAOC,OAAOC,IAAI,CAACL,UAAW;QACvC,IAAIG,IAAIG,QAAQ,CAAC,QAAQH,IAAII,UAAU,CAAC,QAAQJ,IAAIK,QAAQ,CAAC,OAAO;YAClE,MAAM,EAAEC,IAAI,EAAE,GAAGC,IAAAA,8BAAiB,EAACP;YACnCF,MAAMU,GAAG,CAACF;QACZ,OAAO;YACLR,MAAMU,GAAG,CAACR;QACZ;IACF;IACA,OAAOS,MAAMC,IAAI,CAACZ;AACpB;AAWA,IAAIa;AAcJ;;;;;CAKC,GACD,eAAeC,WAAW,EAAEC,GAAG,EAAEC,MAAM,EAAEC,cAAc,EAAEC,OAAO,EAAEC,QAAQ,EA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AOgB,YAAY,EAAEC,YAAYK;oBACvEU,QAAQyB,eAAemB,QAAQ;oBAC/B7C,QAAQ4B,eAAeiB,QAAQ;oBAC/B3B;gBACF;YACF,EAAE,OAAO4B,GAAG;gBACV,OAAO;oBACL1B,aAAaL,QAAQK,WAAW;oBAChClE,MAAM6D,QAAQ7D,IAAI;oBAClBqE,UAAU;oBACVoB,MAAM;oBACNH,QAAQ,EAAE;oBACVxD,SAAS,EAAE;oBACXiB,QAAQ;oBACRD,QAAQ8C,aAAaC,QAAQD,EAAED,QAAQ,KAAK;oBAC5C3B;gBACF;YACF;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/server/lageService.ts"],"sourcesContent":["import { type ConfigOptions, getConfig, getConcurrency, getMaxWorkersPerTask } from \"@lage-run/config\";\nimport type { Logger } from \"@lage-run/logger\";\nimport type { ILageService } from \"@lage-run/rpc\";\nimport { getTargetId, type TargetGraph } from \"@lage-run/target-graph\";\nimport { type DependencyMap, getPackageInfos, getWorkspaceRoot } from \"workspace-tools\";\nimport { createTargetGraph } from \"../run/createTargetGraph.js\";\nimport { type Readable } from \"stream\";\nimport { type Pool, AggregatedPool } from \"@lage-run/worker-threads-pool\";\nimport { getInputFiles, PackageTree } from \"@lage-run/hasher\";\nimport { createDependencyMap } from \"workspace-tools\";\nimport { getOutputFiles } from \"./getOutputFiles.js\";\nimport { glob } from \"@lage-run/globby\";\nimport { MemoryStream } from \"./MemoryStream.js\";\nimport { runnerPickerOptions } from \"../../runnerPickerOptions.js\";\nimport { filterPipelineDefinitions } from \"../run/filterPipelineDefinitions.js\";\nimport type { TargetRun } from \"@lage-run/scheduler-types\";\nimport { formatDuration, hrToSeconds, hrtimeDiff } from \"@lage-run/format-hrtime\";\n\ninterface LageServiceContext {\n config: ConfigOptions;\n targetGraph: TargetGraph;\n packageTree: PackageTree;\n dependencyMap: DependencyMap;\n root: string;\n pool: Pool;\n}\n\nlet initializedPromise: Promise<LageServiceContext> | undefined;\ninterface ServiceControls {\n abortController: AbortController;\n countdownToShutdown: () => void;\n clearCountdown: () => void;\n}\ninterface InitializeOptions {\n cwd: string;\n logger: Logger;\n serverControls: ServiceControls;\n concurrency?: number;\n nodeArg?: string;\n taskArgs: string[];\n tasks: string[];\n}\n\nfunction formatBytes(bytes: number) {\n return `${(bytes / 1024 / 1024).toFixed(2)} MB`;\n}\n\nasync function createInitializedPromise({ cwd, logger, serverControls, nodeArg, taskArgs, concurrency, tasks }: InitializeOptions) {\n if (initializedPromise) {\n return initializedPromise;\n }\n\n const config = await getConfig(cwd);\n const root = getWorkspaceRoot(cwd)!;\n const maxWorkers = getConcurrency(concurrency, config.concurrency);\n\n logger.info(`Initializing with ${maxWorkers} workers, tasks: ${tasks.join(\", \")}`);\n\n const { pipeline } = config;\n\n const packageInfos = getPackageInfos(root);\n\n const targetGraph = await createTargetGraph({\n logger,\n root,\n dependencies: false,\n dependents: false,\n ignore: [],\n pipeline,\n repoWideChanges: config.repoWideChanges,\n scope: undefined,\n since: undefined,\n outputs: config.cacheOptions.outputGlob,\n tasks,\n packageInfos,\n });\n\n const dependencyMap = createDependencyMap(packageInfos, { withDevDependencies: true, withPeerDependencies: false });\n const packageTree = new PackageTree({\n root,\n packageInfos,\n includeUntracked: true,\n });\n\n logger.info(\"Initializing Package Tree\");\n await packageTree.initialize();\n\n const filteredPipeline = filterPipelineDefinitions(targetGraph.targets.values(), config.pipeline);\n\n const pool = new AggregatedPool({\n logger,\n maxWorkersByGroup: new Map([...getMaxWorkersPerTask(filteredPipeline, maxWorkers)]),\n groupBy: ({ target }) => target.task,\n maxWorkers,\n script: require.resolve(\"./singleTargetWorker.js\"),\n workerOptions: {\n stdout: true,\n stderr: true,\n workerData: {\n runners: {\n ...runnerPickerOptions(nodeArg, config.npmClient, taskArgs),\n ...config.runners,\n shouldCache: false,\n shouldResetCache: false,\n },\n },\n },\n workerIdleMemoryLimit: config.workerIdleMemoryLimit,\n });\n\n serverControls.abortController.signal.addEventListener(\"abort\", () => {\n pool?.close();\n });\n\n pool?.on(\"freedWorker\", () => {\n logger.silly(`Max Worker Memory Usage: ${formatBytes(pool?.stats().maxWorkerMemoryUsage)}`);\n });\n\n pool?.on(\"idle\", () => {\n logger.info(\"All workers are idle, shutting down after timeout\");\n serverControls.countdownToShutdown();\n });\n\n return { config, targetGraph, packageTree, dependencyMap, root, pool };\n}\n\n/**\n * Initializes the lageService: the extra \"initializePromise\" ensures only one initialization is done at a time across threads\n * @param cwd\n * @param logger\n * @returns\n */\nasync function initialize(options: InitializeOptions): Promise<LageServiceContext> {\n initializedPromise = createInitializedPromise(options);\n return initializedPromise;\n}\n\ninterface CreateLageServiceOptions {\n cwd: string;\n serverControls: ServiceControls;\n logger: Logger;\n concurrency?: number;\n tasks: string[];\n}\n\nexport async function createLageService({\n cwd,\n serverControls,\n logger,\n concurrency,\n tasks,\n}: CreateLageServiceOptions): Promise<ILageService> {\n return {\n async ping() {\n return { pong: true };\n },\n\n async runTarget(request) {\n if (global.gc) {\n global.gc();\n }\n\n serverControls.clearCountdown();\n\n // THIS IS A BIG ASSUMPTION; TODO: memoize based on the parameters of the initialize() call\n // The first request sets up the nodeArg and taskArgs - we are assuming that all requests to run this target are coming from the same\n // `lage info` call\n const { config, targetGraph, dependencyMap, packageTree, root, pool } = await initialize({\n cwd,\n logger,\n nodeArg: request.nodeOptions,\n taskArgs: request.taskArgs,\n serverControls,\n concurrency,\n tasks,\n });\n\n const runners = runnerPickerOptions(request.nodeOptions, config.npmClient, request.taskArgs);\n\n const id = getTargetId(request.packageName, request.task);\n\n if (!targetGraph.targets.has(id)) {\n logger.info(`Target not found: ${request.packageName}#${request.task}`);\n return {\n packageName: request.packageName,\n task: request.task,\n exitCode: 1,\n };\n }\n\n const target = targetGraph.targets.get(id)!;\n const task = {\n target,\n runners,\n };\n\n const writableStdout = new MemoryStream();\n const writableStderr = new MemoryStream();\n let pipedStdout: Readable;\n let pipedStderr: Readable;\n\n const targetRun: TargetRun = {\n queueTime: process.hrtime(),\n target,\n duration: [0, 0],\n startTime: [0, 0],\n status: \"queued\",\n threadId: 0,\n };\n\n try {\n await pool.exec(\n task,\n 0,\n (worker, stdout, stderr) => {\n logger.info(`[${worker.threadId}] ${request.packageName}#${request.task} start`);\n\n pipedStdout = stdout;\n pipedStderr = stderr;\n\n stdout.pipe(writableStdout);\n stderr.pipe(writableStderr);\n\n targetRun.threadId = worker.threadId;\n targetRun.status = \"running\";\n targetRun.startTime = process.hrtime();\n },\n (worker) => {\n logger.info(`Max Worker Memory Usage: ${formatBytes(pool.stats().maxWorkerMemoryUsage)}`);\n\n // logger.info the main process memory usage\n const memoryUsage = process.memoryUsage();\n logger.info(\n `Main Process Memory Usage: RSS: ${formatBytes(memoryUsage.rss)} Heap Total: ${formatBytes(\n memoryUsage.heapTotal\n )} Heap Used: ${formatBytes(memoryUsage.heapUsed)}`\n );\n\n targetRun.status = \"success\";\n targetRun.duration = hrtimeDiff(targetRun.startTime, process.hrtime());\n\n logger.info(\n `[${worker.threadId}] ${request.packageName}#${request.task} end: ${formatDuration(hrToSeconds(targetRun.duration))}`\n );\n pipedStdout.unpipe(writableStdout);\n pipedStderr.unpipe(writableStderr);\n }\n );\n\n // const globalInputs = target.environmentGlob\n // ? glob(target.environmentGlob, { cwd: root, gitignore: true })\n // : config.cacheOptions?.environmentGlob\n // ? glob(config.cacheOptions?.environmentGlob, { cwd: root, gitignore: true })\n // : [\"lage.config.js\"];\n // const inputs = (getInputFiles(target, dependencyMap, packageTree) ?? []).concat(globalInputs);\n\n return {\n packageName: request.packageName,\n task: request.task,\n exitCode: 0,\n hash: \"\",\n // inputs,\n // outputs: getOutputFiles(root, target, config.cacheOptions?.outputGlob, packageTree),\n // stdout: writableStdout.toString(),\n // stderr: writableStderr.toString(),\n inputs: [],\n outputs: [],\n stdout: \"\",\n stderr: \"\",\n id,\n };\n } catch (e) {\n return {\n packageName: request.packageName,\n task: request.task,\n exitCode: 1,\n hash: \"\",\n inputs: [],\n outputs: [],\n stdout: \"\",\n stderr: e instanceof Error ? e.toString() : \"\",\n id,\n };\n }\n },\n };\n}\n"],"names":["createLageService","initializedPromise","formatBytes","bytes","toFixed","createInitializedPromise","cwd","logger","serverControls","nodeArg","taskArgs","concurrency","tasks","config","getConfig","root","getWorkspaceRoot","maxWorkers","getConcurrency","info","join","pipeline","packageInfos","getPackageInfos","targetGraph","createTargetGraph","dependencies","dependents","ignore","repoWideChanges","scope","undefined","since","outputs","cacheOptions","outputGlob","dependencyMap","createDependencyMap","withDevDependencies","withPeerDependencies","packageTree","PackageTree","includeUntracked","initialize","filteredPipeline","filterPipelineDefinitions","targets","values","pool","AggregatedPool","maxWorkersByGroup","Map","getMaxWorkersPerTask","groupBy","target","task","script","require","resolve","workerOptions","stdout","stderr","workerData","runners","runnerPickerOptions","npmClient","shouldCache","shouldResetCache","workerIdleMemoryLimit","abortController","signal","addEventListener","close","on","silly","stats","maxWorkerMemoryUsage","countdownToShutdown","options","ping","pong","runTarget","request","global","gc","clearCountdown","nodeOptions","id","getTargetId","packageName","has","exitCode","get","writableStdout","MemoryStream","writableStderr","pipedStdout","pipedStderr","targetRun","queueTime","process","hrtime","duration","startTime","status","threadId","exec","worker","pipe","memoryUsage","rss","heapTotal","heapUsed","hrtimeDiff","formatDuration","hrToSeconds","unpipe","hash","inputs","e","Error","toString"],"mappings":";;;;+BAiJsBA;;;eAAAA;;;wBAjJ8D;6BAGtC;gCACwB;mCACpC;mCAEQ;wBACC;8BAId;qCACO;2CACM;8BAEc;AAWxD,IAAIC;AAgBJ,SAASC,YAAYC,KAAa;IAChC,OAAO,GAAG,AAACA,CAAAA,QAAQ,OAAO,IAAG,EAAGC,OAAO,CAAC,GAAG,GAAG,CAAC;AACjD;AAEA,eAAeC,yBAAyB,EAAEC,GAAG,EAAEC,MAAM,EAAEC,cAAc,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,KAAK,EAAqB;IAC/H,IAAIX,oBAAoB;QACtB,OAAOA;IACT;IAEA,MAA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ACF;IACF;AACF"}
|
package/lib/getBinPaths.d.ts
CHANGED
package/lib/getBinPaths.js
CHANGED
|
@@ -2,10 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
getBinPaths: function() {
|
|
8
13
|
return getBinPaths;
|
|
14
|
+
},
|
|
15
|
+
getBinScripts: function() {
|
|
16
|
+
return getBinScripts;
|
|
9
17
|
}
|
|
10
18
|
});
|
|
11
19
|
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
@@ -44,3 +52,23 @@ function getBinPaths() {
|
|
|
44
52
|
"lage-server": binPaths[1]
|
|
45
53
|
};
|
|
46
54
|
}
|
|
55
|
+
function getBinScripts() {
|
|
56
|
+
const thisPackageJsonPath = findUp("package.json", __dirname);
|
|
57
|
+
if (!thisPackageJsonPath) {
|
|
58
|
+
throw new Error("Could not find package.json of this packageF");
|
|
59
|
+
}
|
|
60
|
+
const thisPackagePath = _path.default.dirname(thisPackageJsonPath);
|
|
61
|
+
if (_fs.default.existsSync(_path.default.join(thisPackagePath, "dist", "lage.js"))) {
|
|
62
|
+
// the case for CLI package after build
|
|
63
|
+
return {
|
|
64
|
+
lage: _path.default.join(thisPackagePath, "dist", "lage.js"),
|
|
65
|
+
"lage-server": _path.default.join(thisPackagePath, "dist", "lage-server.js")
|
|
66
|
+
};
|
|
67
|
+
} else {
|
|
68
|
+
// the case for CLI package during development
|
|
69
|
+
return {
|
|
70
|
+
lage: _path.default.join(thisPackagePath, "bin", "lage.js"),
|
|
71
|
+
"lage-server": _path.default.join(thisPackagePath, "bin", "lage-server.js")
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
package/lib/getBinPaths.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/getBinPaths.ts"],"sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport os from \"os\";\n\nfunction findUp(name: string, dir: string) {\n let currentDir = dir;\n while (currentDir !== \"/\") {\n const fullPath = path.join(currentDir, name);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n currentDir = path.dirname(currentDir);\n }\n return undefined;\n}\n\nexport function getBinPaths() {\n const bins = os.platform() === \"win32\" ? [\"lage.cmd\", \"lage-server.cmd\"] : [\"lage\", \"lage-server\"];\n const binPaths = bins.map((bin) => findUp(\"node_modules/.bin/\" + bin, __dirname));\n\n if (binPaths.some((binPath) => binPath === undefined)) {\n throw new Error(\"Could not find bin paths for lage or lage-server\");\n }\n\n return { lage: binPaths[0]!, \"lage-server\": binPaths[1]! };\n}\n"],"names":["getBinPaths","findUp","name","dir","currentDir","fullPath","path","join","fs","existsSync","dirname","undefined","bins","os","platform","binPaths","map","bin","__dirname","some","binPath","Error","lage"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/getBinPaths.ts"],"sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\nimport os from \"os\";\n\nfunction findUp(name: string, dir: string) {\n let currentDir = dir;\n while (currentDir !== \"/\") {\n const fullPath = path.join(currentDir, name);\n if (fs.existsSync(fullPath)) {\n return fullPath;\n }\n currentDir = path.dirname(currentDir);\n }\n return undefined;\n}\n\nexport function getBinPaths() {\n const bins = os.platform() === \"win32\" ? [\"lage.cmd\", \"lage-server.cmd\"] : [\"lage\", \"lage-server\"];\n const binPaths = bins.map((bin) => findUp(\"node_modules/.bin/\" + bin, __dirname));\n\n if (binPaths.some((binPath) => binPath === undefined)) {\n throw new Error(\"Could not find bin paths for lage or lage-server\");\n }\n\n return { lage: binPaths[0]!, \"lage-server\": binPaths[1]! };\n}\n\nexport function getBinScripts() {\n const thisPackageJsonPath = findUp(\"package.json\", __dirname);\n\n if (!thisPackageJsonPath) {\n throw new Error(\"Could not find package.json of this packageF\");\n }\n\n const thisPackagePath = path.dirname(thisPackageJsonPath);\n\n if (fs.existsSync(path.join(thisPackagePath, \"dist\", \"lage.js\"))) {\n // the case for CLI package after build\n return {\n lage: path.join(thisPackagePath, \"dist\", \"lage.js\"),\n \"lage-server\": path.join(thisPackagePath, \"dist\", \"lage-server.js\"),\n };\n } else {\n // the case for CLI package during development\n return {\n lage: path.join(thisPackagePath, \"bin\", \"lage.js\"),\n \"lage-server\": path.join(thisPackagePath, \"bin\", \"lage-server.js\"),\n };\n }\n}\n"],"names":["getBinPaths","getBinScripts","findUp","name","dir","currentDir","fullPath","path","join","fs","existsSync","dirname","undefined","bins","os","platform","binPaths","map","bin","__dirname","some","binPath","Error","lage","thisPackageJsonPath","thisPackagePath"],"mappings":";;;;;;;;;;;IAgBgBA,WAAW;eAAXA;;IAWAC,aAAa;eAAbA;;;6DA3BC;2DACF;2DACA;;;;;;AAEf,SAASC,OAAOC,IAAY,EAAEC,GAAW;IACvC,IAAIC,aAAaD;IACjB,MAAOC,eAAe,IAAK;QACzB,MAAMC,WAAWC,aAAI,CAACC,IAAI,CAACH,YAAYF;QACvC,IAAIM,WAAE,CAACC,UAAU,CAACJ,WAAW;YAC3B,OAAOA;QACT;QACAD,aAAaE,aAAI,CAACI,OAAO,CAACN;IAC5B;IACA,OAAOO;AACT;AAEO,SAASZ;IACd,MAAMa,OAAOC,WAAE,CAACC,QAAQ,OAAO,UAAU;QAAC;QAAY;KAAkB,GAAG;QAAC;QAAQ;KAAc;IAClG,MAAMC,WAAWH,KAAKI,GAAG,CAAC,CAACC,MAAQhB,OAAO,uBAAuBgB,KAAKC;IAEtE,IAAIH,SAASI,IAAI,CAAC,CAACC,UAAYA,YAAYT,YAAY;QACrD,MAAM,IAAIU,MAAM;IAClB;IAEA,OAAO;QAAEC,MAAMP,QAAQ,CAAC,EAAE;QAAG,eAAeA,QAAQ,CAAC,EAAE;IAAE;AAC3D;AAEO,SAASf;IACd,MAAMuB,sBAAsBtB,OAAO,gBAAgBiB;IAEnD,IAAI,CAACK,qBAAqB;QACxB,MAAM,IAAIF,MAAM;IAClB;IAEA,MAAMG,kBAAkBlB,aAAI,CAACI,OAAO,CAACa;IAErC,IAAIf,WAAE,CAACC,UAAU,CAACH,aAAI,CAACC,IAAI,CAACiB,iBAAiB,QAAQ,aAAa;QAChE,uCAAuC;QACvC,OAAO;YACLF,MAAMhB,aAAI,CAACC,IAAI,CAACiB,iBAAiB,QAAQ;YACzC,eAAelB,aAAI,CAACC,IAAI,CAACiB,iBAAiB,QAAQ;QACpD;IACF,OAAO;QACL,8CAA8C;QAC9C,OAAO;YACLF,MAAMhB,aAAI,CAACC,IAAI,CAACiB,iBAAiB,OAAO;YACxC,eAAelB,aAAI,CAACC,IAAI,CAACiB,iBAAiB,OAAO;QACnD;IACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lage-run/cli",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.6",
|
|
4
4
|
"description": "Command Line Interface for Lage",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,16 +23,17 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@lage-run/cache": "^1.3.10",
|
|
25
25
|
"@lage-run/config": "^0.4.11",
|
|
26
|
+
"@lage-run/format-hrtime": "^0.1.6",
|
|
26
27
|
"@lage-run/globby": "^14.2.0",
|
|
27
28
|
"@lage-run/hasher": "^1.6.7",
|
|
28
29
|
"@lage-run/logger": "^1.3.1",
|
|
29
30
|
"@lage-run/reporters": "^1.2.18",
|
|
30
31
|
"@lage-run/rpc": "^1.2.3",
|
|
31
32
|
"@lage-run/runners": "^1.2.0",
|
|
32
|
-
"@lage-run/scheduler": "^1.4.
|
|
33
|
+
"@lage-run/scheduler": "^1.4.2",
|
|
33
34
|
"@lage-run/scheduler-types": "^0.3.22",
|
|
34
35
|
"@lage-run/target-graph": "^0.11.0",
|
|
35
|
-
"@lage-run/worker-threads-pool": "^0.8.
|
|
36
|
+
"@lage-run/worker-threads-pool": "^0.8.6",
|
|
36
37
|
"chokidar": "3.5.3",
|
|
37
38
|
"commander": "9.5.0",
|
|
38
39
|
"execa": "5.1.1",
|