@lage-run/cli 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +43 -1
- package/CHANGELOG.md +20 -2
- package/lib/cli.js +2 -0
- package/lib/commands/exec/action.d.ts +1 -0
- package/lib/commands/exec/action.js +13 -132
- package/lib/commands/exec/executeInProcess.d.ts +9 -0
- package/lib/commands/exec/executeInProcess.js +140 -0
- package/lib/commands/exec/executeRemotely.d.ts +8 -0
- package/lib/commands/exec/executeRemotely.js +32 -0
- package/lib/commands/exec/expandTargetDefinition.d.ts +7 -0
- package/lib/commands/exec/expandTargetDefinition.js +25 -0
- package/lib/commands/exec/index.js +1 -0
- package/lib/commands/server/action.d.ts +9 -0
- package/lib/commands/server/action.js +69 -0
- package/lib/commands/server/index.d.ts +3 -0
- package/lib/commands/server/index.js +17 -0
- package/lib/commands/server/lageService.d.ts +4 -0
- package/lib/commands/server/lageService.js +71 -0
- package/package.json +4 -3
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,49 @@
|
|
|
2
2
|
"name": "@lage-run/cli",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "Fri,
|
|
5
|
+
"date": "Fri, 06 Sep 2024 20:02:51 GMT",
|
|
6
|
+
"version": "0.19.0",
|
|
7
|
+
"tag": "@lage-run/cli_v0.19.0",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"author": "kchau@microsoft.com",
|
|
12
|
+
"package": "@lage-run/cli",
|
|
13
|
+
"commit": "0d2a6f936b7250959f5a42f3c79908b8a475d28d",
|
|
14
|
+
"comment": "remote execution RPC server and client for Lage"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"author": "beachball",
|
|
18
|
+
"package": "@lage-run/cli",
|
|
19
|
+
"comment": "Bump @lage-run/rpc to v1.1.0",
|
|
20
|
+
"commit": "not available"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"date": "Wed, 04 Sep 2024 23:25:05 GMT",
|
|
27
|
+
"version": "0.18.1",
|
|
28
|
+
"tag": "@lage-run/cli_v0.18.1",
|
|
29
|
+
"comments": {
|
|
30
|
+
"patch": [
|
|
31
|
+
{
|
|
32
|
+
"author": "beachball",
|
|
33
|
+
"package": "@lage-run/cli",
|
|
34
|
+
"comment": "Bump @lage-run/hasher to v1.3.1",
|
|
35
|
+
"commit": "not available"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"author": "beachball",
|
|
39
|
+
"package": "@lage-run/cli",
|
|
40
|
+
"comment": "Bump @lage-run/scheduler to v1.2.10",
|
|
41
|
+
"commit": "not available"
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"date": "Fri, 30 Aug 2024 18:40:09 GMT",
|
|
6
48
|
"version": "0.18.0",
|
|
7
49
|
"tag": "@lage-run/cli_v0.18.0",
|
|
8
50
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
# Change Log - @lage-run/cli
|
|
2
2
|
|
|
3
|
-
This log was last generated on Fri,
|
|
3
|
+
This log was last generated on Fri, 06 Sep 2024 20:02:51 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.19.0
|
|
8
|
+
|
|
9
|
+
Fri, 06 Sep 2024 20:02:51 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- remote execution RPC server and client for Lage (kchau@microsoft.com)
|
|
14
|
+
- Bump @lage-run/rpc to v1.1.0
|
|
15
|
+
|
|
16
|
+
## 0.18.1
|
|
17
|
+
|
|
18
|
+
Wed, 04 Sep 2024 23:25:05 GMT
|
|
19
|
+
|
|
20
|
+
### Patches
|
|
21
|
+
|
|
22
|
+
- Bump @lage-run/hasher to v1.3.1
|
|
23
|
+
- Bump @lage-run/scheduler to v1.2.10
|
|
24
|
+
|
|
7
25
|
## 0.18.0
|
|
8
26
|
|
|
9
|
-
Fri, 30 Aug 2024 18:
|
|
27
|
+
Fri, 30 Aug 2024 18:40:09 GMT
|
|
10
28
|
|
|
11
29
|
### Minor changes
|
|
12
30
|
|
package/lib/cli.js
CHANGED
|
@@ -10,6 +10,7 @@ const _index2 = require("./commands/affected/index.js");
|
|
|
10
10
|
const _index3 = require("./commands/init/index.js");
|
|
11
11
|
const _index4 = require("./commands/info/index.js");
|
|
12
12
|
const _index5 = require("./commands/exec/index.js");
|
|
13
|
+
const _index6 = require("./commands/server/index.js");
|
|
13
14
|
async function main() {
|
|
14
15
|
const program = new _commander.Command();
|
|
15
16
|
program.addCommand(_index.runCommand, {
|
|
@@ -20,6 +21,7 @@ async function main() {
|
|
|
20
21
|
program.addCommand(_index3.initCommand);
|
|
21
22
|
program.addCommand(_index4.infoCommand);
|
|
22
23
|
program.addCommand(_index5.execCommand);
|
|
24
|
+
program.addCommand(_index6.serverCommand);
|
|
23
25
|
await program.parseAsync(process.argv);
|
|
24
26
|
}
|
|
25
27
|
main().catch((err)=>{
|
|
@@ -2,6 +2,7 @@ import type { Command } from "commander";
|
|
|
2
2
|
import type { ReporterInitOptions } from "../../types/ReporterInitOptions.js";
|
|
3
3
|
interface ExecOptions extends ReporterInitOptions {
|
|
4
4
|
cwd?: string;
|
|
5
|
+
server?: string | boolean;
|
|
5
6
|
nodeArg?: string[];
|
|
6
7
|
}
|
|
7
8
|
export declare function execAction(options: ExecOptions, command: Command): Promise<void>;
|
|
@@ -8,151 +8,32 @@ Object.defineProperty(exports, "execAction", {
|
|
|
8
8
|
return execAction;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _filterArgsForTasks = require("../run/filterArgsForTasks.js");
|
|
12
|
-
const _config = require("@lage-run/config");
|
|
13
|
-
const _workspacetools = require("workspace-tools");
|
|
14
11
|
const _logger = /*#__PURE__*/ _interop_require_default(require("@lage-run/logger"));
|
|
15
|
-
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
16
|
-
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
17
|
-
const _targetgraph = require("@lage-run/target-graph");
|
|
18
12
|
const _initializeReporters = require("../initializeReporters.js");
|
|
19
|
-
const
|
|
20
|
-
const
|
|
13
|
+
const _executeInProcess = require("./executeInProcess.js");
|
|
14
|
+
const _executeRemotely = require("./executeRemotely.js");
|
|
21
15
|
function _interop_require_default(obj) {
|
|
22
16
|
return obj && obj.__esModule ? obj : {
|
|
23
17
|
default: obj
|
|
24
18
|
};
|
|
25
19
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Parses the package and task from the command as quickly as possible:
|
|
28
|
-
*
|
|
29
|
-
* 1. if cwd overridden in args, use it to read the package.json directly
|
|
30
|
-
* 2. if cwd not overridden and root is not cwd, use the cwd to read the package.json directly
|
|
31
|
-
* 3. if root is cwd, assume the task is global
|
|
32
|
-
*
|
|
33
|
-
* @param options
|
|
34
|
-
* @param command
|
|
35
|
-
* @returns
|
|
36
|
-
*/ function parsePackageInfoFromArgs(root, options, command) {
|
|
37
|
-
const { packageName , task } = (0, _targetId.getPackageAndTask)(command.args[0]);
|
|
38
|
-
if (packageName) {
|
|
39
|
-
const packageInfos = (0, _workspacetools.getPackageInfos)(root);
|
|
40
|
-
const info = packageInfos[packageName];
|
|
41
|
-
return {
|
|
42
|
-
info,
|
|
43
|
-
task,
|
|
44
|
-
isGlobal: false
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
if (options.cwd) {
|
|
48
|
-
const packageJsonPath = _path.default.join(options.cwd, "package.json");
|
|
49
|
-
const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, "utf-8"));
|
|
50
|
-
return {
|
|
51
|
-
info: {
|
|
52
|
-
...packageJson,
|
|
53
|
-
packageJsonPath
|
|
54
|
-
},
|
|
55
|
-
task,
|
|
56
|
-
isGlobal: false
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
if (root !== process.cwd()) {
|
|
60
|
-
const packageJsonPath = _path.default.join(process.cwd(), "package.json");
|
|
61
|
-
if (_fs.default.existsSync(packageJsonPath)) {
|
|
62
|
-
const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, "utf-8"));
|
|
63
|
-
return {
|
|
64
|
-
info: {
|
|
65
|
-
...packageJson,
|
|
66
|
-
packageJsonPath
|
|
67
|
-
},
|
|
68
|
-
task,
|
|
69
|
-
isGlobal: false
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const packageJsonPath = _path.default.join(root, "package.json");
|
|
74
|
-
const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, "utf-8"));
|
|
75
|
-
return {
|
|
76
|
-
info: {
|
|
77
|
-
...packageJson,
|
|
78
|
-
packageJsonPath
|
|
79
|
-
},
|
|
80
|
-
task,
|
|
81
|
-
isGlobal: true
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function expandTargetDefinition(packageName, task, pipeline, outputs) {
|
|
85
|
-
const id = packageName ? `${packageName}#${task}` : task;
|
|
86
|
-
const emptyDefinition = {
|
|
87
|
-
cache: false,
|
|
88
|
-
dependsOn: [],
|
|
89
|
-
options: {},
|
|
90
|
-
outputs
|
|
91
|
-
};
|
|
92
|
-
const definition = id in pipeline ? pipeline[id] : `#${task}` in pipeline ? pipeline[`#${task}`] : `//${task}` in pipeline ? pipeline[`//${task}`] : task in pipeline ? pipeline[task] : emptyDefinition;
|
|
93
|
-
if (Array.isArray(definition)) {
|
|
94
|
-
return emptyDefinition;
|
|
95
|
-
} else {
|
|
96
|
-
return definition;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
20
|
async function execAction(options, command) {
|
|
100
|
-
const cwd = process.cwd();
|
|
101
|
-
const config = await (0, _config.getConfig)(cwd);
|
|
102
|
-
const { pipeline } = config;
|
|
103
21
|
const logger = (0, _logger.default)();
|
|
104
22
|
options.logLevel = options.logLevel ?? "info";
|
|
105
23
|
options.reporter = options.reporter ?? "json";
|
|
106
24
|
(0, _initializeReporters.initializeReporters)(logger, options);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const resolve = ()=>{
|
|
113
|
-
return _path.default.dirname(info.packageJsonPath).replace(/\\/g, "/");
|
|
114
|
-
};
|
|
115
|
-
const { taskArgs } = (0, _filterArgsForTasks.filterArgsForTasks)(command.args);
|
|
116
|
-
const factory = new _targetgraph.TargetFactory({
|
|
117
|
-
root,
|
|
118
|
-
resolve,
|
|
119
|
-
packageInfos
|
|
120
|
-
});
|
|
121
|
-
const definition = expandTargetDefinition(isGlobal ? undefined : info.name, task, pipeline, config.cacheOptions.outputGlob ?? []);
|
|
122
|
-
const target = isGlobal ? factory.createGlobalTarget(task, definition) : factory.createPackageTarget(info.name, task, definition);
|
|
123
|
-
const pickerOptions = {
|
|
124
|
-
npmScript: {
|
|
125
|
-
script: require.resolve("../run/runners/NpmScriptRunner.js"),
|
|
126
|
-
options: {
|
|
127
|
-
nodeArg: options.nodeArg,
|
|
128
|
-
taskArgs,
|
|
129
|
-
npmCmd: config.npmClient
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
worker: {
|
|
133
|
-
script: require.resolve("../run/runners/WorkerRunner.js"),
|
|
134
|
-
options: {
|
|
135
|
-
taskArgs
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
noop: {
|
|
139
|
-
script: require.resolve("../run/runners/NoOpRunner.js"),
|
|
140
|
-
options: {}
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
const runnerPicker = new _runners.TargetRunnerPicker(pickerOptions);
|
|
144
|
-
const runner = await runnerPicker.pick(target);
|
|
145
|
-
if (await runner.shouldRun(target)) {
|
|
146
|
-
logger.info("Running target", {
|
|
147
|
-
target
|
|
148
|
-
});
|
|
149
|
-
await runner.run({
|
|
150
|
-
target,
|
|
151
|
-
weight: 1,
|
|
152
|
-
abortSignal: new AbortController().signal
|
|
25
|
+
if (options.server) {
|
|
26
|
+
await (0, _executeRemotely.executeRemotely)({
|
|
27
|
+
server: typeof options.server === "boolean" ? "localhost:5332" : options.server,
|
|
28
|
+
logger,
|
|
29
|
+
args: command.args
|
|
153
30
|
});
|
|
154
|
-
|
|
155
|
-
|
|
31
|
+
} else {
|
|
32
|
+
await (0, _executeInProcess.executeInProcess)({
|
|
33
|
+
logger,
|
|
34
|
+
args: command.args,
|
|
35
|
+
cwd: options.cwd,
|
|
36
|
+
nodeArg: options.nodeArg
|
|
156
37
|
});
|
|
157
38
|
}
|
|
158
39
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Logger } from "@lage-run/logger";
|
|
2
|
+
interface ExecuteInProcessOptions {
|
|
3
|
+
cwd?: string;
|
|
4
|
+
nodeArg?: string[];
|
|
5
|
+
args?: string[];
|
|
6
|
+
logger: Logger;
|
|
7
|
+
}
|
|
8
|
+
export declare function executeInProcess({ cwd, args, nodeArg, logger }: ExecuteInProcessOptions): Promise<void>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "executeInProcess", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return executeInProcess;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _config = require("@lage-run/config");
|
|
12
|
+
const _targetgraph = require("@lage-run/target-graph");
|
|
13
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
14
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
15
|
+
const _workspacetools = require("workspace-tools");
|
|
16
|
+
const _filterArgsForTasks = require("../run/filterArgsForTasks.js");
|
|
17
|
+
const _expandTargetDefinition = require("./expandTargetDefinition.js");
|
|
18
|
+
const _runners = require("@lage-run/runners");
|
|
19
|
+
function _interop_require_default(obj) {
|
|
20
|
+
return obj && obj.__esModule ? obj : {
|
|
21
|
+
default: obj
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parses the package and task from the command as quickly as possible:
|
|
26
|
+
*
|
|
27
|
+
* 1. if cwd overridden in args, use it to read the package.json directly
|
|
28
|
+
* 2. if cwd not overridden and root is not cwd, use the cwd to read the package.json directly
|
|
29
|
+
* 3. if root is cwd, assume the task is global
|
|
30
|
+
*
|
|
31
|
+
* @param options
|
|
32
|
+
* @param command
|
|
33
|
+
* @returns
|
|
34
|
+
*/ function parsePackageInfoFromArgs(root, cwd, packageName, task) {
|
|
35
|
+
if (packageName && task) {
|
|
36
|
+
const packageInfos = (0, _workspacetools.getPackageInfos)(root);
|
|
37
|
+
const info = packageInfos[packageName];
|
|
38
|
+
return {
|
|
39
|
+
info,
|
|
40
|
+
task,
|
|
41
|
+
isGlobal: false
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (cwd) {
|
|
45
|
+
const packageJsonPath = _path.default.join(cwd, "package.json");
|
|
46
|
+
const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, "utf-8"));
|
|
47
|
+
return {
|
|
48
|
+
info: {
|
|
49
|
+
...packageJson,
|
|
50
|
+
packageJsonPath
|
|
51
|
+
},
|
|
52
|
+
task,
|
|
53
|
+
isGlobal: false
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (root !== process.cwd()) {
|
|
57
|
+
const packageJsonPath = _path.default.join(process.cwd(), "package.json");
|
|
58
|
+
if (_fs.default.existsSync(packageJsonPath)) {
|
|
59
|
+
const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, "utf-8"));
|
|
60
|
+
return {
|
|
61
|
+
info: {
|
|
62
|
+
...packageJson,
|
|
63
|
+
packageJsonPath
|
|
64
|
+
},
|
|
65
|
+
task,
|
|
66
|
+
isGlobal: false
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const packageJsonPath = _path.default.join(root, "package.json");
|
|
71
|
+
const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, "utf-8"));
|
|
72
|
+
return {
|
|
73
|
+
info: {
|
|
74
|
+
...packageJson,
|
|
75
|
+
packageJsonPath
|
|
76
|
+
},
|
|
77
|
+
task,
|
|
78
|
+
isGlobal: true
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async function executeInProcess({ cwd , args , nodeArg , logger }) {
|
|
82
|
+
const root = (0, _workspacetools.getWorkspaceRoot)(process.cwd());
|
|
83
|
+
const config = await (0, _config.getConfig)(root);
|
|
84
|
+
const { pipeline } = config;
|
|
85
|
+
const taskArg = args?.length === 1 ? args?.[0] : args?.[1];
|
|
86
|
+
const packageName = args?.length ?? 0 > 1 ? args?.[0] : undefined;
|
|
87
|
+
if (!taskArg) {
|
|
88
|
+
throw new Error("No task provided");
|
|
89
|
+
}
|
|
90
|
+
const { info , task , isGlobal } = parsePackageInfoFromArgs(root, cwd, packageName, taskArg);
|
|
91
|
+
const packageInfos = {
|
|
92
|
+
[info.name]: info
|
|
93
|
+
};
|
|
94
|
+
const resolve = ()=>{
|
|
95
|
+
return _path.default.dirname(info.packageJsonPath).replace(/\\/g, "/");
|
|
96
|
+
};
|
|
97
|
+
const { taskArgs } = (0, _filterArgsForTasks.filterArgsForTasks)(args ?? []);
|
|
98
|
+
const factory = new _targetgraph.TargetFactory({
|
|
99
|
+
root,
|
|
100
|
+
resolve,
|
|
101
|
+
packageInfos
|
|
102
|
+
});
|
|
103
|
+
const definition = (0, _expandTargetDefinition.expandTargetDefinition)(isGlobal ? undefined : info.name, task, pipeline, config.cacheOptions.outputGlob ?? []);
|
|
104
|
+
const target = isGlobal ? factory.createGlobalTarget(task, definition) : factory.createPackageTarget(info.name, task, definition);
|
|
105
|
+
const pickerOptions = {
|
|
106
|
+
npmScript: {
|
|
107
|
+
script: require.resolve("../run/runners/NpmScriptRunner.js"),
|
|
108
|
+
options: {
|
|
109
|
+
nodeArg,
|
|
110
|
+
taskArgs,
|
|
111
|
+
npmCmd: config.npmClient
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
worker: {
|
|
115
|
+
script: require.resolve("../run/runners/WorkerRunner.js"),
|
|
116
|
+
options: {
|
|
117
|
+
taskArgs
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
noop: {
|
|
121
|
+
script: require.resolve("../run/runners/NoOpRunner.js"),
|
|
122
|
+
options: {}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const runnerPicker = new _runners.TargetRunnerPicker(pickerOptions);
|
|
126
|
+
const runner = await runnerPicker.pick(target);
|
|
127
|
+
if (await runner.shouldRun(target)) {
|
|
128
|
+
logger.info("Running target", {
|
|
129
|
+
target
|
|
130
|
+
});
|
|
131
|
+
await runner.run({
|
|
132
|
+
target,
|
|
133
|
+
weight: 1,
|
|
134
|
+
abortSignal: new AbortController().signal
|
|
135
|
+
});
|
|
136
|
+
logger.info("Finished", {
|
|
137
|
+
target
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "executeRemotely", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return executeRemotely;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _filterArgsForTasks = require("../run/filterArgsForTasks.js");
|
|
12
|
+
async function executeRemotely({ logger , server , args }) {
|
|
13
|
+
const task = args?.length === 1 ? args?.[0] : args?.[1];
|
|
14
|
+
const packageName = args?.length ?? 0 > 1 ? args?.[0] : undefined;
|
|
15
|
+
if (!task) {
|
|
16
|
+
throw new Error("No task provided");
|
|
17
|
+
}
|
|
18
|
+
const { taskArgs } = (0, _filterArgsForTasks.filterArgsForTasks)(args ?? []);
|
|
19
|
+
const rpc = (await import("@lage-run/rpc")).default;
|
|
20
|
+
const baseUrl = server.startsWith("http") ? server : `http://${server}`;
|
|
21
|
+
const client = rpc.createClient({
|
|
22
|
+
baseUrl,
|
|
23
|
+
httpVersion: baseUrl.startsWith("https") ? "2" : "1.1"
|
|
24
|
+
});
|
|
25
|
+
const response = await client.runTarget({
|
|
26
|
+
packageName,
|
|
27
|
+
task,
|
|
28
|
+
taskArgs
|
|
29
|
+
});
|
|
30
|
+
logger.info(`Task ${response.packageName}#${response.task} exited with code ${response.exitCode}`);
|
|
31
|
+
process.exitCode = response.exitCode;
|
|
32
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type PipelineDefinition } from "@lage-run/config";
|
|
2
|
+
export declare function expandTargetDefinition(packageName: string | undefined, task: string, pipeline: PipelineDefinition, outputs: string[]): import("@lage-run/target-graph").TargetConfig | {
|
|
3
|
+
cache: boolean;
|
|
4
|
+
dependsOn: never[];
|
|
5
|
+
options: {};
|
|
6
|
+
outputs: string[];
|
|
7
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "expandTargetDefinition", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return expandTargetDefinition;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function expandTargetDefinition(packageName, task, pipeline, outputs) {
|
|
12
|
+
const id = packageName ? `${packageName}#${task}` : task;
|
|
13
|
+
const emptyDefinition = {
|
|
14
|
+
cache: false,
|
|
15
|
+
dependsOn: [],
|
|
16
|
+
options: {},
|
|
17
|
+
outputs
|
|
18
|
+
};
|
|
19
|
+
const definition = id in pipeline ? pipeline[id] : `#${task}` in pipeline ? pipeline[`#${task}`] : `//${task}` in pipeline ? pipeline[`//${task}`] : task in pipeline ? pipeline[task] : emptyDefinition;
|
|
20
|
+
if (Array.isArray(definition)) {
|
|
21
|
+
return emptyDefinition;
|
|
22
|
+
} else {
|
|
23
|
+
return definition;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -12,4 +12,5 @@ const _commander = require("commander");
|
|
|
12
12
|
const _action = require("./action.js");
|
|
13
13
|
const _addLoggerOptions = require("../addLoggerOptions.js");
|
|
14
14
|
const execCommand = new _commander.Command("exec");
|
|
15
|
+
execCommand.option("--server [server:port]", "Execute on lage server via RPC", "localhost:5332");
|
|
15
16
|
(0, _addLoggerOptions.addLoggerOptions)(execCommand).action(_action.execAction);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ReporterInitOptions } from "../../types/ReporterInitOptions.js";
|
|
2
|
+
import type { Command } from "commander";
|
|
3
|
+
interface WorkerOptions extends ReporterInitOptions {
|
|
4
|
+
nodeArg?: string[];
|
|
5
|
+
port?: number;
|
|
6
|
+
host?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function workerAction(options: WorkerOptions, command: Command): Promise<void>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "workerAction", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return workerAction;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _config = require("@lage-run/config");
|
|
12
|
+
const _logger = /*#__PURE__*/ _interop_require_default(require("@lage-run/logger"));
|
|
13
|
+
const _initializeReporters = require("../initializeReporters.js");
|
|
14
|
+
const _lageService = require("./lageService.js");
|
|
15
|
+
const _workspacetools = require("workspace-tools");
|
|
16
|
+
const _createTargetGraph = require("../run/createTargetGraph.js");
|
|
17
|
+
const _targetId = require("@lage-run/target-graph/lib/targetId.js");
|
|
18
|
+
function _interop_require_default(obj) {
|
|
19
|
+
return obj && obj.__esModule ? obj : {
|
|
20
|
+
default: obj
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function findAllTasks(pipeline) {
|
|
24
|
+
const tasks = new Set();
|
|
25
|
+
for (const key of Object.keys(pipeline)){
|
|
26
|
+
if (key.includes("#") || key.startsWith("#") || key.endsWith("//")) {
|
|
27
|
+
const { task } = (0, _targetId.getPackageAndTask)(key);
|
|
28
|
+
tasks.add(task);
|
|
29
|
+
} else {
|
|
30
|
+
tasks.add(key);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return Array.from(tasks);
|
|
34
|
+
}
|
|
35
|
+
async function workerAction(options, command) {
|
|
36
|
+
const { port =5332 , host ="localhost" } = options;
|
|
37
|
+
const cwd = process.cwd();
|
|
38
|
+
const logger = (0, _logger.default)();
|
|
39
|
+
options.logLevel = options.logLevel ?? "info";
|
|
40
|
+
options.reporter = options.reporter ?? "json";
|
|
41
|
+
(0, _initializeReporters.initializeReporters)(logger, options);
|
|
42
|
+
const rpc = (await import("@lage-run/rpc")).default;
|
|
43
|
+
const config = await (0, _config.getConfig)(cwd);
|
|
44
|
+
const { pipeline } = config;
|
|
45
|
+
const root = (0, _workspacetools.getWorkspaceRoot)(cwd);
|
|
46
|
+
const packageInfos = (0, _workspacetools.getPackageInfos)(root);
|
|
47
|
+
const tasks = findAllTasks(pipeline);
|
|
48
|
+
const targetGraph = (0, _createTargetGraph.createTargetGraph)({
|
|
49
|
+
logger,
|
|
50
|
+
root,
|
|
51
|
+
dependencies: false,
|
|
52
|
+
dependents: false,
|
|
53
|
+
ignore: [],
|
|
54
|
+
pipeline,
|
|
55
|
+
repoWideChanges: config.repoWideChanges,
|
|
56
|
+
scope: [],
|
|
57
|
+
since: "",
|
|
58
|
+
outputs: config.cacheOptions.outputGlob,
|
|
59
|
+
tasks,
|
|
60
|
+
packageInfos
|
|
61
|
+
});
|
|
62
|
+
const lageService = await (0, _lageService.createLageService)(targetGraph, logger, config.npmClient);
|
|
63
|
+
const server = await rpc.createServer(lageService);
|
|
64
|
+
logger.info(`Server listening on http://${host}:${port}`);
|
|
65
|
+
await server.listen({
|
|
66
|
+
host,
|
|
67
|
+
port
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "serverCommand", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return serverCommand;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _commander = require("commander");
|
|
12
|
+
const _action = require("./action.js");
|
|
13
|
+
const _addLoggerOptions = require("../addLoggerOptions.js");
|
|
14
|
+
const serverCommand = new _commander.Command("server");
|
|
15
|
+
serverCommand.option("-h|--host <host>", "lage server host", "localhost");
|
|
16
|
+
serverCommand.option("-p|--port <port>", "lage worker server port", (v)=>parseInt(v), 5332);
|
|
17
|
+
(0, _addLoggerOptions.addLoggerOptions)(serverCommand).action(_action.workerAction);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Logger } from "@lage-run/logger";
|
|
2
|
+
import type { ILageService } from "@lage-run/rpc";
|
|
3
|
+
import { type TargetGraph } from "@lage-run/target-graph";
|
|
4
|
+
export declare function createLageService(targetGraph: TargetGraph, logger: Logger, npmClient: string): Promise<ILageService>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createLageService", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createLageService;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _runners = require("@lage-run/runners");
|
|
12
|
+
const _targetgraph = require("@lage-run/target-graph");
|
|
13
|
+
async function createLageService(targetGraph, logger, npmClient) {
|
|
14
|
+
return {
|
|
15
|
+
async runTarget (request) {
|
|
16
|
+
const pickerOptions = {
|
|
17
|
+
npmScript: {
|
|
18
|
+
script: require.resolve("../run/runners/NpmScriptRunner.js"),
|
|
19
|
+
options: {
|
|
20
|
+
nodeOptions: request.nodeOptions,
|
|
21
|
+
taskArgs: request.taskArgs,
|
|
22
|
+
npmCmd: npmClient
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
worker: {
|
|
26
|
+
script: require.resolve("../run/runners/WorkerRunner.js"),
|
|
27
|
+
options: {
|
|
28
|
+
taskArgs: request.taskArgs
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
noop: {
|
|
32
|
+
script: require.resolve("../run/runners/NoOpRunner.js"),
|
|
33
|
+
options: {}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const runnerPicker = new _runners.TargetRunnerPicker(pickerOptions);
|
|
37
|
+
if (!targetGraph.targets.has((0, _targetgraph.getTargetId)(request.packageName, request.task))) {
|
|
38
|
+
logger.error(`Target not found: ${request.packageName}#${request.task}`);
|
|
39
|
+
return {
|
|
40
|
+
packageName: request.packageName,
|
|
41
|
+
task: request.task,
|
|
42
|
+
exitCode: 1
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const target = targetGraph.targets.get((0, _targetgraph.getTargetId)(request.packageName, request.task));
|
|
46
|
+
const runner = await runnerPicker.pick(target);
|
|
47
|
+
try {
|
|
48
|
+
if (await runner.shouldRun(target)) {
|
|
49
|
+
logger.info(`Running target ${request.packageName}#${request.task}`);
|
|
50
|
+
await runner.run({
|
|
51
|
+
target,
|
|
52
|
+
weight: 0,
|
|
53
|
+
abortSignal: new AbortController().signal
|
|
54
|
+
});
|
|
55
|
+
logger.info(`Finished target ${request.packageName}#${request.task}`);
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
packageName: request.packageName,
|
|
59
|
+
task: request.task,
|
|
60
|
+
exitCode: 0
|
|
61
|
+
};
|
|
62
|
+
} catch (e) {
|
|
63
|
+
return {
|
|
64
|
+
packageName: request.packageName,
|
|
65
|
+
task: request.task,
|
|
66
|
+
exitCode: 1
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lage-run/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Command Line Interface for Lage",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,11 +22,12 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@lage-run/cache": "^1.3.1",
|
|
24
24
|
"@lage-run/config": "^0.3.7",
|
|
25
|
-
"@lage-run/hasher": "^1.3.
|
|
25
|
+
"@lage-run/hasher": "^1.3.1",
|
|
26
26
|
"@lage-run/logger": "^1.3.0",
|
|
27
27
|
"@lage-run/reporters": "^1.2.8",
|
|
28
|
+
"@lage-run/rpc": "^1.1.0",
|
|
28
29
|
"@lage-run/runners": "^1.0.1",
|
|
29
|
-
"@lage-run/scheduler": "^1.2.
|
|
30
|
+
"@lage-run/scheduler": "^1.2.10",
|
|
30
31
|
"@lage-run/scheduler-types": "^0.3.14",
|
|
31
32
|
"@lage-run/target-graph": "^0.8.9",
|
|
32
33
|
"chokidar": "3.5.3",
|