@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,231 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "Npm", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return Npm;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _interoperror = require("../errors/interop.error.js");
|
|
12
|
-
const _shell = require("../shell/shell.js");
|
|
13
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
14
|
-
if (typeof WeakMap !== "function") return null;
|
|
15
|
-
var cacheBabelInterop = new WeakMap();
|
|
16
|
-
var cacheNodeInterop = new WeakMap();
|
|
17
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
18
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
19
|
-
})(nodeInterop);
|
|
20
|
-
}
|
|
21
|
-
function _interop_require_wildcard(obj, nodeInterop) {
|
|
22
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
23
|
-
return obj;
|
|
24
|
-
}
|
|
25
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
26
|
-
return {
|
|
27
|
-
default: obj
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
31
|
-
if (cache && cache.has(obj)) {
|
|
32
|
-
return cache.get(obj);
|
|
33
|
-
}
|
|
34
|
-
var newObj = {
|
|
35
|
-
__proto__: null
|
|
36
|
-
};
|
|
37
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
38
|
-
for(var key in obj){
|
|
39
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
40
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
41
|
-
if (desc && (desc.get || desc.set)) {
|
|
42
|
-
Object.defineProperty(newObj, key, desc);
|
|
43
|
-
} else {
|
|
44
|
-
newObj[key] = obj[key];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
newObj.default = obj;
|
|
49
|
-
if (cache) {
|
|
50
|
-
cache.set(obj, newObj);
|
|
51
|
-
}
|
|
52
|
-
return newObj;
|
|
53
|
-
}
|
|
54
|
-
const Commands = {
|
|
55
|
-
publish: "publish",
|
|
56
|
-
version: "version",
|
|
57
|
-
link: "link",
|
|
58
|
-
install: "install"
|
|
59
|
-
};
|
|
60
|
-
class Npm extends _shell.Shell {
|
|
61
|
-
name = "npm";
|
|
62
|
-
program = "npm";
|
|
63
|
-
async publish(directory, options = {
|
|
64
|
-
channel: "beta"
|
|
65
|
-
}) {
|
|
66
|
-
const { cwd, dryRun, skipIfPublished, channel, authToken, otp, provenance } = options;
|
|
67
|
-
if (directory == null) {
|
|
68
|
-
throw new _interoperror.InteropError("Directory is required");
|
|
69
|
-
}
|
|
70
|
-
if (skipIfPublished && !dryRun) {
|
|
71
|
-
const alreadyPublished = await this.isPublished(directory, {
|
|
72
|
-
cwd
|
|
73
|
-
});
|
|
74
|
-
if (alreadyPublished) {
|
|
75
|
-
return {
|
|
76
|
-
message: `Skipping publish — version already exists on registry`,
|
|
77
|
-
data: []
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const args = [
|
|
82
|
-
Commands.publish,
|
|
83
|
-
directory
|
|
84
|
-
];
|
|
85
|
-
let tmpUserConfigPath;
|
|
86
|
-
args.push("--tag", channel ?? "beta");
|
|
87
|
-
if (provenance) {
|
|
88
|
-
args.push("--provenance");
|
|
89
|
-
}
|
|
90
|
-
// Explicit --token (local bootstrap). OIDC publish must not inherit cwd .npmrc / NODE_AUTH_TOKEN.
|
|
91
|
-
if (authToken?.trim()) {
|
|
92
|
-
tmpUserConfigPath = await this.createTempUserConfig(authToken.trim());
|
|
93
|
-
args.push("--userconfig", tmpUserConfigPath);
|
|
94
|
-
}
|
|
95
|
-
if (dryRun) {
|
|
96
|
-
args.push("--dry-run");
|
|
97
|
-
}
|
|
98
|
-
const env = {
|
|
99
|
-
...process.env
|
|
100
|
-
};
|
|
101
|
-
if (!authToken?.trim()) {
|
|
102
|
-
delete env.NODE_AUTH_TOKEN;
|
|
103
|
-
delete env.NPM_TOKEN;
|
|
104
|
-
env.NPM_CONFIG_USERCONFIG = "/dev/null";
|
|
105
|
-
}
|
|
106
|
-
if (otp) {
|
|
107
|
-
env.NPM_CONFIG_OTP = otp;
|
|
108
|
-
}
|
|
109
|
-
try {
|
|
110
|
-
return await this.run({
|
|
111
|
-
cwd,
|
|
112
|
-
env
|
|
113
|
-
}, ...args);
|
|
114
|
-
} catch (error) {
|
|
115
|
-
if (skipIfPublished && !dryRun && isAlreadyPublishedError(error)) {
|
|
116
|
-
return {
|
|
117
|
-
message: `Skipping publish — version already exists on registry`,
|
|
118
|
-
data: []
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
throw error;
|
|
122
|
-
} finally{
|
|
123
|
-
if (tmpUserConfigPath) {
|
|
124
|
-
await this.removeTempUserConfig(tmpUserConfigPath);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* @description Runs in the directory of the package
|
|
130
|
-
* @param options
|
|
131
|
-
* @returns
|
|
132
|
-
*/ async version(versionType, options) {
|
|
133
|
-
const { cwd, noTag, preid } = options;
|
|
134
|
-
const args = [
|
|
135
|
-
Commands.version,
|
|
136
|
-
versionType
|
|
137
|
-
];
|
|
138
|
-
if (noTag) {
|
|
139
|
-
args.push("--no-git-tag-version");
|
|
140
|
-
}
|
|
141
|
-
if (preid) {
|
|
142
|
-
args.push("--preid", preid);
|
|
143
|
-
}
|
|
144
|
-
return this.run({
|
|
145
|
-
cwd
|
|
146
|
-
}, ...args);
|
|
147
|
-
}
|
|
148
|
-
async link(directory, options = {
|
|
149
|
-
cwd: "./"
|
|
150
|
-
}) {
|
|
151
|
-
const { cwd } = options;
|
|
152
|
-
const args = [
|
|
153
|
-
Commands.link,
|
|
154
|
-
directory
|
|
155
|
-
];
|
|
156
|
-
return this.run({
|
|
157
|
-
cwd
|
|
158
|
-
}, ...args);
|
|
159
|
-
}
|
|
160
|
-
async install(options = {
|
|
161
|
-
cwd: "./"
|
|
162
|
-
}) {
|
|
163
|
-
const { cwd } = options;
|
|
164
|
-
return this.run({
|
|
165
|
-
cwd
|
|
166
|
-
}, Commands.install);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Install only `dependencies` as real folders: `--omit=dev` skips devDependencies and
|
|
170
|
-
* `--no-bin-links` skips the `.bin` symlinks, so the result holds no symlinks at all.
|
|
171
|
-
*/ async installProduction(options = {
|
|
172
|
-
cwd: "./"
|
|
173
|
-
}) {
|
|
174
|
-
const { cwd } = options;
|
|
175
|
-
return this.run({
|
|
176
|
-
cwd
|
|
177
|
-
}, Commands.install, "--omit=dev", "--no-bin-links", "--no-audit", "--no-fund", "--loglevel=error");
|
|
178
|
-
}
|
|
179
|
-
async syncLockFile(options = {
|
|
180
|
-
cwd: "./"
|
|
181
|
-
}) {
|
|
182
|
-
const { cwd } = options;
|
|
183
|
-
return this.run({
|
|
184
|
-
cwd
|
|
185
|
-
}, Commands.install, "--package-lock-only", "--ignore-scripts");
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* True when package@version exists on the registry.
|
|
189
|
-
* Uses ambient npm config (cwd `.npmrc`); do not pass tokens on argv.
|
|
190
|
-
*/ async isPublished(directory, options) {
|
|
191
|
-
const { readFileSync } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("node:fs")));
|
|
192
|
-
const { join } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("node:path")));
|
|
193
|
-
try {
|
|
194
|
-
const pkgJson = JSON.parse(readFileSync(join(directory, "package.json"), "utf8"));
|
|
195
|
-
const spec = `${pkgJson.name}@${pkgJson.version}`;
|
|
196
|
-
await this.run(options, "view", spec, "version");
|
|
197
|
-
return true;
|
|
198
|
-
} catch {
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
async createTempUserConfig(authToken) {
|
|
203
|
-
const { mkdtemp, writeFile } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("node:fs/promises")));
|
|
204
|
-
const { tmpdir } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("node:os")));
|
|
205
|
-
const { join } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("node:path")));
|
|
206
|
-
const tempDir = await mkdtemp(join(tmpdir(), "decohere-npmrc-"));
|
|
207
|
-
const npmrcPath = join(tempDir, ".npmrc");
|
|
208
|
-
const npmrc = [
|
|
209
|
-
"registry=https://registry.npmjs.org/",
|
|
210
|
-
"always-auth=true",
|
|
211
|
-
`//registry.npmjs.org/:_authToken=${authToken}`
|
|
212
|
-
].join("\n");
|
|
213
|
-
await writeFile(npmrcPath, `${npmrc}\n`, {
|
|
214
|
-
mode: 0o600
|
|
215
|
-
});
|
|
216
|
-
return npmrcPath;
|
|
217
|
-
}
|
|
218
|
-
async removeTempUserConfig(npmrcPath) {
|
|
219
|
-
const { rm } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("node:fs/promises")));
|
|
220
|
-
const { dirname } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("node:path")));
|
|
221
|
-
const dir = dirname(npmrcPath);
|
|
222
|
-
await rm(dir, {
|
|
223
|
-
recursive: true,
|
|
224
|
-
force: true
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
function isAlreadyPublishedError(error) {
|
|
229
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
230
|
-
return /cannot publish over the previously published versions/i.test(message);
|
|
231
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "VersionTypes", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return VersionTypes;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const VersionTypes = {
|
|
12
|
-
major: "major",
|
|
13
|
-
minor: "minor",
|
|
14
|
-
patch: "patch",
|
|
15
|
-
prerelease: "prerelease"
|
|
16
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "Pnpm", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return Pnpm;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _shell = require("../shell/shell.js");
|
|
12
|
-
const Commands = {
|
|
13
|
-
install: "install"
|
|
14
|
-
};
|
|
15
|
-
class Pnpm extends _shell.Shell {
|
|
16
|
-
name = "pnpm";
|
|
17
|
-
program = "pnpm";
|
|
18
|
-
async install(options = {
|
|
19
|
-
cwd: "./"
|
|
20
|
-
}) {
|
|
21
|
-
const { cwd } = options;
|
|
22
|
-
return this.run({
|
|
23
|
-
cwd
|
|
24
|
-
}, Commands.install);
|
|
25
|
-
}
|
|
26
|
-
async syncLockFile(options = {
|
|
27
|
-
cwd: "./"
|
|
28
|
-
}) {
|
|
29
|
-
const { cwd } = options;
|
|
30
|
-
return this.run({
|
|
31
|
-
cwd
|
|
32
|
-
}, Commands.install, "--lockfile-only", "--ignore-scripts");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "shellArgv", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return shellArgv;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
function fields(args) {
|
|
12
|
-
const positional = [];
|
|
13
|
-
const flags = {};
|
|
14
|
-
for(let i = 0; i < args.length; i++){
|
|
15
|
-
const arg = args[i];
|
|
16
|
-
if (arg === "--") {
|
|
17
|
-
positional.push(...args.slice(i + 1));
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
if (arg.startsWith("--")) {
|
|
21
|
-
const body = arg.slice(2);
|
|
22
|
-
const eq = body.indexOf("=");
|
|
23
|
-
if (eq !== -1) {
|
|
24
|
-
flags[body.slice(0, eq)] = body.slice(eq + 1);
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
const next = args[i + 1];
|
|
28
|
-
if (next != null && !next.startsWith("-")) {
|
|
29
|
-
flags[body] = next;
|
|
30
|
-
i += 1;
|
|
31
|
-
} else {
|
|
32
|
-
flags[body] = true;
|
|
33
|
-
}
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
positional.push(arg);
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
_: positional,
|
|
40
|
-
...flags
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
const shellArgv = {
|
|
44
|
-
fields
|
|
45
|
-
};
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "Shell", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return Shell;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _nodechild_process = require("node:child_process");
|
|
12
|
-
const _scribe = require("@decohere/scribe");
|
|
13
|
-
const _interoperror = require("../errors/interop.error.js");
|
|
14
|
-
const _shellargv = require("./shell.argv.js");
|
|
15
|
-
class Shell {
|
|
16
|
-
async run(options, ...args) {
|
|
17
|
-
const logger = _scribe.scribe.logger(Shell.name);
|
|
18
|
-
const argv = args ?? [];
|
|
19
|
-
const argvFields = _shellargv.shellArgv.fields(argv);
|
|
20
|
-
const positionals = Array.isArray(argvFields._) ? argvFields._ : [];
|
|
21
|
-
const commandName = [
|
|
22
|
-
this.program,
|
|
23
|
-
...positionals
|
|
24
|
-
].join(" ").trim();
|
|
25
|
-
logger.info("Running", {
|
|
26
|
-
program: this.program,
|
|
27
|
-
args: argvFields
|
|
28
|
-
});
|
|
29
|
-
return new Promise((resolve, reject)=>{
|
|
30
|
-
let settled = false;
|
|
31
|
-
const resolveOnce = (response)=>{
|
|
32
|
-
if (settled) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
settled = true;
|
|
36
|
-
resolve(response);
|
|
37
|
-
};
|
|
38
|
-
const rejectOnce = (error)=>{
|
|
39
|
-
if (settled) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
settled = true;
|
|
43
|
-
reject(error);
|
|
44
|
-
};
|
|
45
|
-
const { cwd, env } = options;
|
|
46
|
-
const spawnOpt = {
|
|
47
|
-
cwd: cwd ?? ".",
|
|
48
|
-
stdio: [
|
|
49
|
-
"inherit",
|
|
50
|
-
"pipe",
|
|
51
|
-
"pipe"
|
|
52
|
-
],
|
|
53
|
-
env: env ?? {
|
|
54
|
-
...process.env
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const proc = (0, _nodechild_process.spawn)(this.program, argv, spawnOpt);
|
|
58
|
-
const responseData = [];
|
|
59
|
-
const errorData = [];
|
|
60
|
-
proc.on("close", (code, signal)=>{
|
|
61
|
-
if (code === 0) {
|
|
62
|
-
resolveOnce({
|
|
63
|
-
message: `${commandName} completed`,
|
|
64
|
-
data: responseData
|
|
65
|
-
});
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const stderr = errorData.join("\n").trim();
|
|
69
|
-
const stdout = responseData.join("\n").trim();
|
|
70
|
-
const exitCodeText = code == null ? "unknown" : String(code);
|
|
71
|
-
const signalText = signal ? ` signal ${signal}` : "";
|
|
72
|
-
const base = `Running '${commandName}' failed with code ${exitCodeText}${signalText}`;
|
|
73
|
-
const details = [
|
|
74
|
-
stderr ? `stderr:\n${stderr}` : "",
|
|
75
|
-
!stderr && stdout ? `stdout:\n${stdout}` : ""
|
|
76
|
-
].filter(Boolean).join("\n");
|
|
77
|
-
rejectOnce(new _interoperror.InteropError(details ? `${base}\n${details}` : base));
|
|
78
|
-
});
|
|
79
|
-
proc.on("error", (err)=>{
|
|
80
|
-
rejectOnce(err);
|
|
81
|
-
});
|
|
82
|
-
proc.stdout.on("error", (err)=>{
|
|
83
|
-
rejectOnce(err);
|
|
84
|
-
});
|
|
85
|
-
proc.stdout.on("data", (data)=>{
|
|
86
|
-
const lines = this.parseStream(data);
|
|
87
|
-
console.log(data.toString());
|
|
88
|
-
responseData.push(...lines);
|
|
89
|
-
});
|
|
90
|
-
proc.stderr?.on("error", (err)=>{
|
|
91
|
-
rejectOnce(err);
|
|
92
|
-
});
|
|
93
|
-
proc.stderr?.on("data", (data)=>{
|
|
94
|
-
const lines = this.parseStream(data);
|
|
95
|
-
console.error(data.toString());
|
|
96
|
-
errorData.push(...lines);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
parseStream(data) {
|
|
101
|
-
const dataStr = data.toString();
|
|
102
|
-
const lines = dataStr.split("\n").filter((l)=>l !== "");
|
|
103
|
-
return lines;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get detectPackageManager () {
|
|
13
|
-
return detectPackageManager;
|
|
14
|
-
},
|
|
15
|
-
get packageManagerFromString () {
|
|
16
|
-
return packageManagerFromString;
|
|
17
|
-
},
|
|
18
|
-
get promptForPackageManager () {
|
|
19
|
-
return promptForPackageManager;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
const _nodefs = require("node:fs");
|
|
23
|
-
const _nodepath = require("node:path");
|
|
24
|
-
const _promises = require("node:readline/promises");
|
|
25
|
-
const _npm = require("../npm/npm.js");
|
|
26
|
-
const _pnpm = require("../pnpm/pnpm.js");
|
|
27
|
-
const _yarn = require("../yarn/yarn.js");
|
|
28
|
-
const LOCKFILES = [
|
|
29
|
-
[
|
|
30
|
-
"pnpm-lock.yaml",
|
|
31
|
-
()=>new _pnpm.Pnpm()
|
|
32
|
-
],
|
|
33
|
-
[
|
|
34
|
-
"yarn.lock",
|
|
35
|
-
()=>new _yarn.Yarn()
|
|
36
|
-
],
|
|
37
|
-
[
|
|
38
|
-
"package-lock.json",
|
|
39
|
-
()=>new _npm.Npm()
|
|
40
|
-
]
|
|
41
|
-
];
|
|
42
|
-
function fromLockfile(cwd) {
|
|
43
|
-
for (const [file, factory] of LOCKFILES){
|
|
44
|
-
if ((0, _nodefs.existsSync)((0, _nodepath.join)(cwd, file))) return factory();
|
|
45
|
-
}
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
function fromUserAgent() {
|
|
49
|
-
const agent = process.env.npm_config_user_agent ?? "";
|
|
50
|
-
if (agent.startsWith("pnpm")) return new _pnpm.Pnpm();
|
|
51
|
-
if (agent.startsWith("yarn")) return new _yarn.Yarn();
|
|
52
|
-
if (agent.startsWith("npm")) return new _npm.Npm();
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
function detectPackageManager(cwd) {
|
|
56
|
-
return fromLockfile(cwd) ?? fromUserAgent();
|
|
57
|
-
}
|
|
58
|
-
function packageManagerFromString(name) {
|
|
59
|
-
if (name === "yarn") return new _yarn.Yarn();
|
|
60
|
-
if (name === "npm") return new _npm.Npm();
|
|
61
|
-
return new _pnpm.Pnpm();
|
|
62
|
-
}
|
|
63
|
-
async function promptForPackageManager() {
|
|
64
|
-
const rl = (0, _promises.createInterface)({
|
|
65
|
-
input: process.stdin,
|
|
66
|
-
output: process.stdout
|
|
67
|
-
});
|
|
68
|
-
const answer = await rl.question("Package manager? [pnpm/yarn/npm] (default: pnpm): ");
|
|
69
|
-
rl.close();
|
|
70
|
-
return packageManagerFromString(answer.trim().toLowerCase());
|
|
71
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "Yarn", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return Yarn;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _shell = require("../shell/shell.js");
|
|
12
|
-
const Commands = {
|
|
13
|
-
install: "install"
|
|
14
|
-
};
|
|
15
|
-
class Yarn extends _shell.Shell {
|
|
16
|
-
name = "yarn";
|
|
17
|
-
program = "yarn";
|
|
18
|
-
async install(options = {
|
|
19
|
-
cwd: "./"
|
|
20
|
-
}) {
|
|
21
|
-
const { cwd } = options;
|
|
22
|
-
return this.run({
|
|
23
|
-
cwd
|
|
24
|
-
}, Commands.install);
|
|
25
|
-
}
|
|
26
|
-
async syncLockFile(options = {
|
|
27
|
-
cwd: "./"
|
|
28
|
-
}) {
|
|
29
|
-
const { cwd } = options;
|
|
30
|
-
return this.run({
|
|
31
|
-
cwd
|
|
32
|
-
}, Commands.install, "--mode", "update-lockfile", "--ignore-scripts");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "findDirectories", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return findDirectories;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _glob = require("glob");
|
|
12
|
-
async function findDirectories(...pattern) {
|
|
13
|
-
const paths = await (0, _glob.glob)(pattern, {
|
|
14
|
-
withFileTypes: true
|
|
15
|
-
});
|
|
16
|
-
const dirs = paths.filter((p)=>p.isDirectory()).map((p)=>({
|
|
17
|
-
name: p.name,
|
|
18
|
-
parentPath: p.parentPath
|
|
19
|
-
}));
|
|
20
|
-
return dirs;
|
|
21
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get findFile () {
|
|
13
|
-
return findFile;
|
|
14
|
-
},
|
|
15
|
-
get findFiles () {
|
|
16
|
-
return findFiles;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const _glob = require("glob");
|
|
20
|
-
const _io = require("@decohere/core/io");
|
|
21
|
-
async function findFile(pattern) {
|
|
22
|
-
const files = await (0, _glob.glob)(pattern, {
|
|
23
|
-
includeChildMatches: false
|
|
24
|
-
});
|
|
25
|
-
if (files.length === 0) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
const file = {
|
|
29
|
-
relativePath: files.at(0)
|
|
30
|
-
};
|
|
31
|
-
return file;
|
|
32
|
-
}
|
|
33
|
-
async function findFiles(patterns, options) {
|
|
34
|
-
const paths = await (0, _glob.glob)(patterns, {
|
|
35
|
-
...options,
|
|
36
|
-
withFileTypes: true
|
|
37
|
-
});
|
|
38
|
-
const files = paths.filter((p)=>p.isFile()).map((p)=>{
|
|
39
|
-
return new _io.FileEx({
|
|
40
|
-
relativePath: p.relative(),
|
|
41
|
-
fullPath: p.fullpath()
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
return files;
|
|
45
|
-
}
|
package/commonjs/src/io/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
_export_star(require("./find-directories.js"), exports);
|
|
6
|
-
_export_star(require("./find-file.js"), exports);
|
|
7
|
-
_export_star(require("./watch.js"), exports);
|
|
8
|
-
function _export_star(from, to) {
|
|
9
|
-
Object.keys(from).forEach(function(k) {
|
|
10
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
11
|
-
Object.defineProperty(to, k, {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function() {
|
|
14
|
-
return from[k];
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return from;
|
|
20
|
-
}
|