@decohere/devkit 0.0.1-dev.126 → 0.0.1-dev.5
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/package.json +3 -12
- package/src/cli/action.ts +77 -0
- package/src/cli/command.ts +173 -0
- package/src/cli/index.ts +30 -0
- package/src/cli/module.type.ts +48 -0
- package/src/cli/options.ts +81 -0
- package/src/diagnostics/trace.ts +92 -0
- package/src/interop/docker/docker.ts +57 -0
- package/src/interop/errors/interop.error.ts +1 -0
- package/src/interop/git/git.ts +98 -0
- package/{types/src/interop/git/git.types.d.ts → src/interop/git/git.types.ts} +9 -6
- package/{es6/src/interop/index.js → src/interop/index.ts} +1 -0
- package/src/interop/node/node.ts +38 -0
- package/src/interop/npm/npm.ts +168 -0
- package/src/interop/npm/npm.types.ts +28 -0
- package/src/interop/pnpm/pnpm.ts +22 -0
- package/{types/src/interop/pnpm/pnpm.types.d.ts → src/interop/pnpm/pnpm.types.ts} +1 -1
- package/src/interop/shell/shell.argv.ts +31 -0
- package/src/interop/shell/shell.ts +100 -0
- package/src/interop/shell/shell.types.ts +9 -0
- package/src/interop/types/detect-package-manager.ts +45 -0
- package/src/interop/types/package-manager.ts +7 -0
- package/src/interop/yarn/yarn.ts +28 -0
- package/{types/src/interop/yarn/yarn.types.d.ts → src/interop/yarn/yarn.types.ts} +1 -1
- package/src/io/find-directories.ts +13 -0
- package/src/io/find-file.ts +37 -0
- package/src/io/watch.ts +290 -0
- package/tests/cli/command.model.spec.ts +91 -0
- package/tests/diagnostics/trace.spec.ts +319 -0
- package/tests/interop/detect-package-manager.spec.ts +70 -0
- package/tests/interop/npm.spec.ts +129 -0
- package/tests/interop/pnpm.spec.ts +30 -0
- package/tests/interop/shell.spec.ts +47 -0
- package/tests/interop/yarn.spec.ts +18 -0
- package/tests/io/find-file.spec.ts +188 -0
- package/tests/io/watch.real-fs.spec.ts +76 -0
- package/tests/io/watch.spec.ts +291 -0
- package/LICENSE +0 -15
- package/commonjs/src/cli/action.js +0 -65
- package/commonjs/src/cli/command.js +0 -127
- package/commonjs/src/cli/index.js +0 -61
- package/commonjs/src/cli/module.type.js +0 -18
- package/commonjs/src/cli/options.js +0 -115
- package/commonjs/src/diagnostics/index.js +0 -22
- package/commonjs/src/diagnostics/trace.js +0 -79
- package/commonjs/src/interop/docker/docker.js +0 -54
- package/commonjs/src/interop/errors/interop.error.js +0 -12
- package/commonjs/src/interop/git/git.js +0 -134
- package/commonjs/src/interop/git/git.types.js +0 -4
- package/commonjs/src/interop/index.js +0 -97
- package/commonjs/src/interop/node/index.js +0 -18
- package/commonjs/src/interop/node/node.js +0 -45
- package/commonjs/src/interop/npm/npm.js +0 -231
- package/commonjs/src/interop/npm/npm.types.js +0 -16
- package/commonjs/src/interop/pnpm/pnpm.js +0 -34
- package/commonjs/src/interop/pnpm/pnpm.types.js +0 -4
- package/commonjs/src/interop/shell/shell.argv.js +0 -45
- package/commonjs/src/interop/shell/shell.js +0 -105
- package/commonjs/src/interop/shell/shell.types.js +0 -4
- package/commonjs/src/interop/types/detect-package-manager.js +0 -71
- package/commonjs/src/interop/types/package-manager.js +0 -4
- package/commonjs/src/interop/yarn/yarn.js +0 -34
- package/commonjs/src/interop/yarn/yarn.types.js +0 -4
- package/commonjs/src/io/find-directories.js +0 -21
- package/commonjs/src/io/find-file.js +0 -45
- package/commonjs/src/io/index.js +0 -20
- package/commonjs/src/io/watch.js +0 -261
- package/es6/src/cli/action.js +0 -47
- package/es6/src/cli/command.js +0 -106
- package/es6/src/cli/index.js +0 -4
- package/es6/src/cli/module.type.js +0 -11
- package/es6/src/cli/options.js +0 -76
- package/es6/src/diagnostics/trace.js +0 -61
- package/es6/src/interop/docker/docker.js +0 -44
- package/es6/src/interop/errors/interop.error.js +0 -2
- package/es6/src/interop/git/git.js +0 -124
- package/es6/src/interop/git/git.types.js +0 -1
- package/es6/src/interop/node/node.js +0 -35
- package/es6/src/interop/npm/npm.js +0 -180
- package/es6/src/interop/npm/npm.types.js +0 -6
- package/es6/src/interop/pnpm/pnpm.js +0 -24
- package/es6/src/interop/pnpm/pnpm.types.js +0 -1
- package/es6/src/interop/shell/shell.argv.js +0 -35
- package/es6/src/interop/shell/shell.js +0 -95
- package/es6/src/interop/shell/shell.types.js +0 -1
- package/es6/src/interop/types/detect-package-manager.js +0 -50
- package/es6/src/interop/types/package-manager.js +0 -1
- package/es6/src/interop/yarn/yarn.js +0 -24
- package/es6/src/interop/yarn/yarn.types.js +0 -1
- package/es6/src/io/find-directories.js +0 -11
- package/es6/src/io/find-file.js +0 -27
- package/es6/src/io/watch.js +0 -238
- package/types/src/cli/action.d.ts +0 -36
- package/types/src/cli/command.d.ts +0 -34
- package/types/src/cli/index.d.ts +0 -7
- package/types/src/cli/module.type.d.ts +0 -36
- package/types/src/cli/options.d.ts +0 -28
- package/types/src/diagnostics/index.d.ts +0 -1
- package/types/src/diagnostics/trace.d.ts +0 -10
- package/types/src/interop/docker/docker.d.ts +0 -19
- package/types/src/interop/errors/interop.error.d.ts +0 -2
- package/types/src/interop/git/git.d.ts +0 -16
- package/types/src/interop/index.d.ts +0 -14
- package/types/src/interop/node/index.d.ts +0 -1
- package/types/src/interop/node/node.d.ts +0 -5
- package/types/src/interop/npm/npm.d.ts +0 -29
- package/types/src/interop/npm/npm.types.d.ts +0 -24
- package/types/src/interop/pnpm/pnpm.d.ts +0 -9
- package/types/src/interop/shell/shell.argv.d.ts +0 -5
- package/types/src/interop/shell/shell.d.ts +0 -6
- package/types/src/interop/shell/shell.types.d.ts +0 -9
- package/types/src/interop/types/detect-package-manager.d.ts +0 -4
- package/types/src/interop/types/package-manager.d.ts +0 -10
- package/types/src/interop/yarn/yarn.d.ts +0 -9
- package/types/src/io/find-directories.d.ts +0 -2
- package/types/src/io/find-file.d.ts +0 -9
- package/types/src/io/index.d.ts +0 -3
- package/types/src/io/watch.d.ts +0 -16
- /package/{es6/src/diagnostics/index.js → src/diagnostics/index.ts} +0 -0
- /package/{es6/src/interop/node/index.js → src/interop/node/index.ts} +0 -0
- /package/{es6/src/io/index.js → src/io/index.ts} +0 -0
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { InteropError } from "../errors/interop.error.js";
|
|
2
|
-
import { Shell } from "../shell/shell.js";
|
|
3
|
-
const Commands = {
|
|
4
|
-
stage: "stage",
|
|
5
|
-
tag: "tag",
|
|
6
|
-
add: "add",
|
|
7
|
-
commit: "commit",
|
|
8
|
-
push: "push",
|
|
9
|
-
listFiles: "ls-files"
|
|
10
|
-
};
|
|
11
|
-
const defaultOptions = {
|
|
12
|
-
cwd: "./"
|
|
13
|
-
};
|
|
14
|
-
export class Git extends Shell {
|
|
15
|
-
program = "git";
|
|
16
|
-
async getModifiedFiles(options = defaultOptions) {
|
|
17
|
-
const args = [
|
|
18
|
-
Commands.listFiles,
|
|
19
|
-
"--modified"
|
|
20
|
-
];
|
|
21
|
-
const { cwd } = options;
|
|
22
|
-
const result = await this.run({
|
|
23
|
-
cwd
|
|
24
|
-
}, ...args);
|
|
25
|
-
return result.data;
|
|
26
|
-
}
|
|
27
|
-
async getBranchName(options = defaultOptions) {
|
|
28
|
-
const { cwd } = options;
|
|
29
|
-
const args = [
|
|
30
|
-
"rev-parse",
|
|
31
|
-
"--symbolic-full-name",
|
|
32
|
-
"--abbrev-ref",
|
|
33
|
-
"HEAD"
|
|
34
|
-
];
|
|
35
|
-
const result = await this.run({
|
|
36
|
-
cwd
|
|
37
|
-
}, ...args);
|
|
38
|
-
return result.data[0];
|
|
39
|
-
}
|
|
40
|
-
async tag(tag, options = defaultOptions) {
|
|
41
|
-
const args = [
|
|
42
|
-
Commands.tag,
|
|
43
|
-
tag
|
|
44
|
-
];
|
|
45
|
-
const { cwd } = options;
|
|
46
|
-
const result = await this.run({
|
|
47
|
-
cwd
|
|
48
|
-
}, ...args);
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
async pushTag(tag, options = defaultOptions) {
|
|
52
|
-
const { cwd, remote = "origin" } = options;
|
|
53
|
-
const result = await this.run({
|
|
54
|
-
cwd
|
|
55
|
-
}, Commands.push, remote, tag);
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
async commit(message, options) {
|
|
59
|
-
const optionsAndDefaults = {
|
|
60
|
-
...defaultOptions,
|
|
61
|
-
...options
|
|
62
|
-
};
|
|
63
|
-
const { cwd, files = [], all } = optionsAndDefaults;
|
|
64
|
-
const args = [
|
|
65
|
-
Commands.commit
|
|
66
|
-
];
|
|
67
|
-
if (files.length > 0 && all) {
|
|
68
|
-
throw new InteropError("Cannot commit all and files at the same time");
|
|
69
|
-
}
|
|
70
|
-
if (files.length > 0) {
|
|
71
|
-
await this.stage({
|
|
72
|
-
files
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
if (options.all) {
|
|
76
|
-
args.push("-a");
|
|
77
|
-
}
|
|
78
|
-
args.push("-m", message);
|
|
79
|
-
const result = await this.run({
|
|
80
|
-
cwd
|
|
81
|
-
}, ...args);
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
async push(branch, options) {
|
|
85
|
-
const optionsAndDefaults = {
|
|
86
|
-
...defaultOptions,
|
|
87
|
-
...options
|
|
88
|
-
};
|
|
89
|
-
const { cwd, setUpstream } = optionsAndDefaults;
|
|
90
|
-
const args = [
|
|
91
|
-
Commands.push
|
|
92
|
-
];
|
|
93
|
-
args.push("--set-upstream", setUpstream ?? "origin");
|
|
94
|
-
args.push(branch);
|
|
95
|
-
const result = await this.run({
|
|
96
|
-
cwd
|
|
97
|
-
}, ...args);
|
|
98
|
-
return result;
|
|
99
|
-
}
|
|
100
|
-
async pull(branch, options = defaultOptions) {
|
|
101
|
-
const { cwd } = options;
|
|
102
|
-
return this.run({
|
|
103
|
-
cwd
|
|
104
|
-
}, "pull", "--rebase", "origin", branch);
|
|
105
|
-
}
|
|
106
|
-
async stage(options) {
|
|
107
|
-
const optionsAndDefaults = {
|
|
108
|
-
...defaultOptions,
|
|
109
|
-
...options
|
|
110
|
-
};
|
|
111
|
-
const { cwd, files = [], all } = optionsAndDefaults;
|
|
112
|
-
if (all) {
|
|
113
|
-
await this.run({
|
|
114
|
-
cwd
|
|
115
|
-
}, Commands.stage, "-a");
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
for (const file of files){
|
|
119
|
-
await this.run({
|
|
120
|
-
cwd
|
|
121
|
-
}, Commands.stage, file);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { Shell } from "../shell/shell.js";
|
|
3
|
-
export class Node extends Shell {
|
|
4
|
-
program = "node";
|
|
5
|
-
async runScript(script, ...args) {
|
|
6
|
-
const spawnOpt = {
|
|
7
|
-
cwd: ".",
|
|
8
|
-
stdio: "inherit",
|
|
9
|
-
env: {
|
|
10
|
-
...process.env
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
return new Promise((resolve, reject)=>{
|
|
14
|
-
const proc = spawn("node", [
|
|
15
|
-
script,
|
|
16
|
-
...args
|
|
17
|
-
], spawnOpt);
|
|
18
|
-
proc.on("exit", (code)=>{
|
|
19
|
-
if (code !== 0) {
|
|
20
|
-
reject();
|
|
21
|
-
}
|
|
22
|
-
resolve(null);
|
|
23
|
-
});
|
|
24
|
-
proc.on("close", (code)=>{
|
|
25
|
-
resolve(null);
|
|
26
|
-
if (code === 0) {
|
|
27
|
-
resolve({
|
|
28
|
-
message: `${script} completed`
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
reject(`Running '${script}' failed with code ${code}`);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { InteropError } from "../errors/interop.error.js";
|
|
2
|
-
import { Shell } from "../shell/shell.js";
|
|
3
|
-
const Commands = {
|
|
4
|
-
publish: "publish",
|
|
5
|
-
version: "version",
|
|
6
|
-
link: "link",
|
|
7
|
-
install: "install"
|
|
8
|
-
};
|
|
9
|
-
export class Npm extends Shell {
|
|
10
|
-
name = "npm";
|
|
11
|
-
program = "npm";
|
|
12
|
-
async publish(directory, options = {
|
|
13
|
-
channel: "beta"
|
|
14
|
-
}) {
|
|
15
|
-
const { cwd, dryRun, skipIfPublished, channel, authToken, otp, provenance } = options;
|
|
16
|
-
if (directory == null) {
|
|
17
|
-
throw new InteropError("Directory is required");
|
|
18
|
-
}
|
|
19
|
-
if (skipIfPublished && !dryRun) {
|
|
20
|
-
const alreadyPublished = await this.isPublished(directory, {
|
|
21
|
-
cwd
|
|
22
|
-
});
|
|
23
|
-
if (alreadyPublished) {
|
|
24
|
-
return {
|
|
25
|
-
message: `Skipping publish — version already exists on registry`,
|
|
26
|
-
data: []
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const args = [
|
|
31
|
-
Commands.publish,
|
|
32
|
-
directory
|
|
33
|
-
];
|
|
34
|
-
let tmpUserConfigPath;
|
|
35
|
-
args.push("--tag", channel ?? "beta");
|
|
36
|
-
if (provenance) {
|
|
37
|
-
args.push("--provenance");
|
|
38
|
-
}
|
|
39
|
-
// Explicit --token (local bootstrap). OIDC publish must not inherit cwd .npmrc / NODE_AUTH_TOKEN.
|
|
40
|
-
if (authToken?.trim()) {
|
|
41
|
-
tmpUserConfigPath = await this.createTempUserConfig(authToken.trim());
|
|
42
|
-
args.push("--userconfig", tmpUserConfigPath);
|
|
43
|
-
}
|
|
44
|
-
if (dryRun) {
|
|
45
|
-
args.push("--dry-run");
|
|
46
|
-
}
|
|
47
|
-
const env = {
|
|
48
|
-
...process.env
|
|
49
|
-
};
|
|
50
|
-
if (!authToken?.trim()) {
|
|
51
|
-
delete env.NODE_AUTH_TOKEN;
|
|
52
|
-
delete env.NPM_TOKEN;
|
|
53
|
-
env.NPM_CONFIG_USERCONFIG = "/dev/null";
|
|
54
|
-
}
|
|
55
|
-
if (otp) {
|
|
56
|
-
env.NPM_CONFIG_OTP = otp;
|
|
57
|
-
}
|
|
58
|
-
try {
|
|
59
|
-
return await this.run({
|
|
60
|
-
cwd,
|
|
61
|
-
env
|
|
62
|
-
}, ...args);
|
|
63
|
-
} catch (error) {
|
|
64
|
-
if (skipIfPublished && !dryRun && isAlreadyPublishedError(error)) {
|
|
65
|
-
return {
|
|
66
|
-
message: `Skipping publish — version already exists on registry`,
|
|
67
|
-
data: []
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
throw error;
|
|
71
|
-
} finally{
|
|
72
|
-
if (tmpUserConfigPath) {
|
|
73
|
-
await this.removeTempUserConfig(tmpUserConfigPath);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* @description Runs in the directory of the package
|
|
79
|
-
* @param options
|
|
80
|
-
* @returns
|
|
81
|
-
*/ async version(versionType, options) {
|
|
82
|
-
const { cwd, noTag, preid } = options;
|
|
83
|
-
const args = [
|
|
84
|
-
Commands.version,
|
|
85
|
-
versionType
|
|
86
|
-
];
|
|
87
|
-
if (noTag) {
|
|
88
|
-
args.push("--no-git-tag-version");
|
|
89
|
-
}
|
|
90
|
-
if (preid) {
|
|
91
|
-
args.push("--preid", preid);
|
|
92
|
-
}
|
|
93
|
-
return this.run({
|
|
94
|
-
cwd
|
|
95
|
-
}, ...args);
|
|
96
|
-
}
|
|
97
|
-
async link(directory, options = {
|
|
98
|
-
cwd: "./"
|
|
99
|
-
}) {
|
|
100
|
-
const { cwd } = options;
|
|
101
|
-
const args = [
|
|
102
|
-
Commands.link,
|
|
103
|
-
directory
|
|
104
|
-
];
|
|
105
|
-
return this.run({
|
|
106
|
-
cwd
|
|
107
|
-
}, ...args);
|
|
108
|
-
}
|
|
109
|
-
async install(options = {
|
|
110
|
-
cwd: "./"
|
|
111
|
-
}) {
|
|
112
|
-
const { cwd } = options;
|
|
113
|
-
return this.run({
|
|
114
|
-
cwd
|
|
115
|
-
}, Commands.install);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Install only `dependencies` as real folders: `--omit=dev` skips devDependencies and
|
|
119
|
-
* `--no-bin-links` skips the `.bin` symlinks, so the result holds no symlinks at all.
|
|
120
|
-
*/ async installProduction(options = {
|
|
121
|
-
cwd: "./"
|
|
122
|
-
}) {
|
|
123
|
-
const { cwd } = options;
|
|
124
|
-
return this.run({
|
|
125
|
-
cwd
|
|
126
|
-
}, Commands.install, "--omit=dev", "--no-bin-links", "--no-audit", "--no-fund", "--loglevel=error");
|
|
127
|
-
}
|
|
128
|
-
async syncLockFile(options = {
|
|
129
|
-
cwd: "./"
|
|
130
|
-
}) {
|
|
131
|
-
const { cwd } = options;
|
|
132
|
-
return this.run({
|
|
133
|
-
cwd
|
|
134
|
-
}, Commands.install, "--package-lock-only", "--ignore-scripts");
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* True when package@version exists on the registry.
|
|
138
|
-
* Uses ambient npm config (cwd `.npmrc`); do not pass tokens on argv.
|
|
139
|
-
*/ async isPublished(directory, options) {
|
|
140
|
-
const { readFileSync } = await import("node:fs");
|
|
141
|
-
const { join } = await import("node:path");
|
|
142
|
-
try {
|
|
143
|
-
const pkgJson = JSON.parse(readFileSync(join(directory, "package.json"), "utf8"));
|
|
144
|
-
const spec = `${pkgJson.name}@${pkgJson.version}`;
|
|
145
|
-
await this.run(options, "view", spec, "version");
|
|
146
|
-
return true;
|
|
147
|
-
} catch {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async createTempUserConfig(authToken) {
|
|
152
|
-
const { mkdtemp, writeFile } = await import("node:fs/promises");
|
|
153
|
-
const { tmpdir } = await import("node:os");
|
|
154
|
-
const { join } = await import("node:path");
|
|
155
|
-
const tempDir = await mkdtemp(join(tmpdir(), "decohere-npmrc-"));
|
|
156
|
-
const npmrcPath = join(tempDir, ".npmrc");
|
|
157
|
-
const npmrc = [
|
|
158
|
-
"registry=https://registry.npmjs.org/",
|
|
159
|
-
"always-auth=true",
|
|
160
|
-
`//registry.npmjs.org/:_authToken=${authToken}`
|
|
161
|
-
].join("\n");
|
|
162
|
-
await writeFile(npmrcPath, `${npmrc}\n`, {
|
|
163
|
-
mode: 0o600
|
|
164
|
-
});
|
|
165
|
-
return npmrcPath;
|
|
166
|
-
}
|
|
167
|
-
async removeTempUserConfig(npmrcPath) {
|
|
168
|
-
const { rm } = await import("node:fs/promises");
|
|
169
|
-
const { dirname } = await import("node:path");
|
|
170
|
-
const dir = dirname(npmrcPath);
|
|
171
|
-
await rm(dir, {
|
|
172
|
-
recursive: true,
|
|
173
|
-
force: true
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
function isAlreadyPublishedError(error) {
|
|
178
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
179
|
-
return /cannot publish over the previously published versions/i.test(message);
|
|
180
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Shell } from "../shell/shell.js";
|
|
2
|
-
const Commands = {
|
|
3
|
-
install: "install"
|
|
4
|
-
};
|
|
5
|
-
export class Pnpm extends Shell {
|
|
6
|
-
name = "pnpm";
|
|
7
|
-
program = "pnpm";
|
|
8
|
-
async install(options = {
|
|
9
|
-
cwd: "./"
|
|
10
|
-
}) {
|
|
11
|
-
const { cwd } = options;
|
|
12
|
-
return this.run({
|
|
13
|
-
cwd
|
|
14
|
-
}, Commands.install);
|
|
15
|
-
}
|
|
16
|
-
async syncLockFile(options = {
|
|
17
|
-
cwd: "./"
|
|
18
|
-
}) {
|
|
19
|
-
const { cwd } = options;
|
|
20
|
-
return this.run({
|
|
21
|
-
cwd
|
|
22
|
-
}, Commands.install, "--lockfile-only", "--ignore-scripts");
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
function fields(args) {
|
|
2
|
-
const positional = [];
|
|
3
|
-
const flags = {};
|
|
4
|
-
for(let i = 0; i < args.length; i++){
|
|
5
|
-
const arg = args[i];
|
|
6
|
-
if (arg === "--") {
|
|
7
|
-
positional.push(...args.slice(i + 1));
|
|
8
|
-
break;
|
|
9
|
-
}
|
|
10
|
-
if (arg.startsWith("--")) {
|
|
11
|
-
const body = arg.slice(2);
|
|
12
|
-
const eq = body.indexOf("=");
|
|
13
|
-
if (eq !== -1) {
|
|
14
|
-
flags[body.slice(0, eq)] = body.slice(eq + 1);
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
const next = args[i + 1];
|
|
18
|
-
if (next != null && !next.startsWith("-")) {
|
|
19
|
-
flags[body] = next;
|
|
20
|
-
i += 1;
|
|
21
|
-
} else {
|
|
22
|
-
flags[body] = true;
|
|
23
|
-
}
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
positional.push(arg);
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
_: positional,
|
|
30
|
-
...flags
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
export const shellArgv = {
|
|
34
|
-
fields
|
|
35
|
-
};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { scribe } from "@decohere/scribe";
|
|
3
|
-
import { InteropError } from "../errors/interop.error.js";
|
|
4
|
-
import { shellArgv } from "./shell.argv.js";
|
|
5
|
-
export class Shell {
|
|
6
|
-
async run(options, ...args) {
|
|
7
|
-
const logger = scribe.logger(Shell.name);
|
|
8
|
-
const argv = args ?? [];
|
|
9
|
-
const argvFields = shellArgv.fields(argv);
|
|
10
|
-
const positionals = Array.isArray(argvFields._) ? argvFields._ : [];
|
|
11
|
-
const commandName = [
|
|
12
|
-
this.program,
|
|
13
|
-
...positionals
|
|
14
|
-
].join(" ").trim();
|
|
15
|
-
logger.info("Running", {
|
|
16
|
-
program: this.program,
|
|
17
|
-
args: argvFields
|
|
18
|
-
});
|
|
19
|
-
return new Promise((resolve, reject)=>{
|
|
20
|
-
let settled = false;
|
|
21
|
-
const resolveOnce = (response)=>{
|
|
22
|
-
if (settled) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
settled = true;
|
|
26
|
-
resolve(response);
|
|
27
|
-
};
|
|
28
|
-
const rejectOnce = (error)=>{
|
|
29
|
-
if (settled) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
settled = true;
|
|
33
|
-
reject(error);
|
|
34
|
-
};
|
|
35
|
-
const { cwd, env } = options;
|
|
36
|
-
const spawnOpt = {
|
|
37
|
-
cwd: cwd ?? ".",
|
|
38
|
-
stdio: [
|
|
39
|
-
"inherit",
|
|
40
|
-
"pipe",
|
|
41
|
-
"pipe"
|
|
42
|
-
],
|
|
43
|
-
env: env ?? {
|
|
44
|
-
...process.env
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const proc = spawn(this.program, argv, spawnOpt);
|
|
48
|
-
const responseData = [];
|
|
49
|
-
const errorData = [];
|
|
50
|
-
proc.on("close", (code, signal)=>{
|
|
51
|
-
if (code === 0) {
|
|
52
|
-
resolveOnce({
|
|
53
|
-
message: `${commandName} completed`,
|
|
54
|
-
data: responseData
|
|
55
|
-
});
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const stderr = errorData.join("\n").trim();
|
|
59
|
-
const stdout = responseData.join("\n").trim();
|
|
60
|
-
const exitCodeText = code == null ? "unknown" : String(code);
|
|
61
|
-
const signalText = signal ? ` signal ${signal}` : "";
|
|
62
|
-
const base = `Running '${commandName}' failed with code ${exitCodeText}${signalText}`;
|
|
63
|
-
const details = [
|
|
64
|
-
stderr ? `stderr:\n${stderr}` : "",
|
|
65
|
-
!stderr && stdout ? `stdout:\n${stdout}` : ""
|
|
66
|
-
].filter(Boolean).join("\n");
|
|
67
|
-
rejectOnce(new InteropError(details ? `${base}\n${details}` : base));
|
|
68
|
-
});
|
|
69
|
-
proc.on("error", (err)=>{
|
|
70
|
-
rejectOnce(err);
|
|
71
|
-
});
|
|
72
|
-
proc.stdout.on("error", (err)=>{
|
|
73
|
-
rejectOnce(err);
|
|
74
|
-
});
|
|
75
|
-
proc.stdout.on("data", (data)=>{
|
|
76
|
-
const lines = this.parseStream(data);
|
|
77
|
-
console.log(data.toString());
|
|
78
|
-
responseData.push(...lines);
|
|
79
|
-
});
|
|
80
|
-
proc.stderr?.on("error", (err)=>{
|
|
81
|
-
rejectOnce(err);
|
|
82
|
-
});
|
|
83
|
-
proc.stderr?.on("data", (data)=>{
|
|
84
|
-
const lines = this.parseStream(data);
|
|
85
|
-
console.error(data.toString());
|
|
86
|
-
errorData.push(...lines);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
parseStream(data) {
|
|
91
|
-
const dataStr = data.toString();
|
|
92
|
-
const lines = dataStr.split("\n").filter((l)=>l !== "");
|
|
93
|
-
return lines;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { createInterface } from "node:readline/promises";
|
|
4
|
-
import { Npm } from "../npm/npm.js";
|
|
5
|
-
import { Pnpm } from "../pnpm/pnpm.js";
|
|
6
|
-
import { Yarn } from "../yarn/yarn.js";
|
|
7
|
-
const LOCKFILES = [
|
|
8
|
-
[
|
|
9
|
-
"pnpm-lock.yaml",
|
|
10
|
-
()=>new Pnpm()
|
|
11
|
-
],
|
|
12
|
-
[
|
|
13
|
-
"yarn.lock",
|
|
14
|
-
()=>new Yarn()
|
|
15
|
-
],
|
|
16
|
-
[
|
|
17
|
-
"package-lock.json",
|
|
18
|
-
()=>new Npm()
|
|
19
|
-
]
|
|
20
|
-
];
|
|
21
|
-
function fromLockfile(cwd) {
|
|
22
|
-
for (const [file, factory] of LOCKFILES){
|
|
23
|
-
if (existsSync(join(cwd, file))) return factory();
|
|
24
|
-
}
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
function fromUserAgent() {
|
|
28
|
-
const agent = process.env.npm_config_user_agent ?? "";
|
|
29
|
-
if (agent.startsWith("pnpm")) return new Pnpm();
|
|
30
|
-
if (agent.startsWith("yarn")) return new Yarn();
|
|
31
|
-
if (agent.startsWith("npm")) return new Npm();
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
export function detectPackageManager(cwd) {
|
|
35
|
-
return fromLockfile(cwd) ?? fromUserAgent();
|
|
36
|
-
}
|
|
37
|
-
export function packageManagerFromString(name) {
|
|
38
|
-
if (name === "yarn") return new Yarn();
|
|
39
|
-
if (name === "npm") return new Npm();
|
|
40
|
-
return new Pnpm();
|
|
41
|
-
}
|
|
42
|
-
export async function promptForPackageManager() {
|
|
43
|
-
const rl = createInterface({
|
|
44
|
-
input: process.stdin,
|
|
45
|
-
output: process.stdout
|
|
46
|
-
});
|
|
47
|
-
const answer = await rl.question("Package manager? [pnpm/yarn/npm] (default: pnpm): ");
|
|
48
|
-
rl.close();
|
|
49
|
-
return packageManagerFromString(answer.trim().toLowerCase());
|
|
50
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Shell } from "../shell/shell.js";
|
|
2
|
-
const Commands = {
|
|
3
|
-
install: "install"
|
|
4
|
-
};
|
|
5
|
-
export class Yarn extends Shell {
|
|
6
|
-
name = "yarn";
|
|
7
|
-
program = "yarn";
|
|
8
|
-
async install(options = {
|
|
9
|
-
cwd: "./"
|
|
10
|
-
}) {
|
|
11
|
-
const { cwd } = options;
|
|
12
|
-
return this.run({
|
|
13
|
-
cwd
|
|
14
|
-
}, Commands.install);
|
|
15
|
-
}
|
|
16
|
-
async syncLockFile(options = {
|
|
17
|
-
cwd: "./"
|
|
18
|
-
}) {
|
|
19
|
-
const { cwd } = options;
|
|
20
|
-
return this.run({
|
|
21
|
-
cwd
|
|
22
|
-
}, Commands.install, "--mode", "update-lockfile", "--ignore-scripts");
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { glob } from "glob";
|
|
2
|
-
export async function findDirectories(...pattern) {
|
|
3
|
-
const paths = await glob(pattern, {
|
|
4
|
-
withFileTypes: true
|
|
5
|
-
});
|
|
6
|
-
const dirs = paths.filter((p)=>p.isDirectory()).map((p)=>({
|
|
7
|
-
name: p.name,
|
|
8
|
-
parentPath: p.parentPath
|
|
9
|
-
}));
|
|
10
|
-
return dirs;
|
|
11
|
-
}
|
package/es6/src/io/find-file.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { glob } from "glob";
|
|
2
|
-
import { FileEx } from "@decohere/core/io";
|
|
3
|
-
export async function findFile(pattern) {
|
|
4
|
-
const files = await glob(pattern, {
|
|
5
|
-
includeChildMatches: false
|
|
6
|
-
});
|
|
7
|
-
if (files.length === 0) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
const file = {
|
|
11
|
-
relativePath: files.at(0)
|
|
12
|
-
};
|
|
13
|
-
return file;
|
|
14
|
-
}
|
|
15
|
-
export async function findFiles(patterns, options) {
|
|
16
|
-
const paths = await glob(patterns, {
|
|
17
|
-
...options,
|
|
18
|
-
withFileTypes: true
|
|
19
|
-
});
|
|
20
|
-
const files = paths.filter((p)=>p.isFile()).map((p)=>{
|
|
21
|
-
return new FileEx({
|
|
22
|
-
relativePath: p.relative(),
|
|
23
|
-
fullPath: p.fullpath()
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
return files;
|
|
27
|
-
}
|