@astrojs/upgrade 0.7.0 → 0.7.2
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/dist/index.js +30 -19
- package/package.json +4 -3
- package/upgrade.mjs +1 -3
package/dist/index.js
CHANGED
|
@@ -211,38 +211,49 @@ import terminalLink from "terminal-link";
|
|
|
211
211
|
// src/shell.ts
|
|
212
212
|
import { spawn } from "node:child_process";
|
|
213
213
|
import { text as textFromStream } from "node:stream/consumers";
|
|
214
|
+
var WINDOWS_CMD_SHIMS = /* @__PURE__ */ new Set(["npm", "npx", "pnpm", "pnpx", "yarn", "yarnpkg"]);
|
|
215
|
+
var WINDOWS_EXE_SHIMS = /* @__PURE__ */ new Set(["bun", "bunx"]);
|
|
214
216
|
var text = (stream) => stream ? textFromStream(stream).then((t) => t.trimEnd()) : "";
|
|
215
|
-
|
|
217
|
+
function resolveCommand(command, flags) {
|
|
218
|
+
if (process.platform !== "win32") return [command, flags];
|
|
219
|
+
if (command.includes("/") || command.includes("\\") || command.includes(".")) {
|
|
220
|
+
return [command, flags];
|
|
221
|
+
}
|
|
222
|
+
const cmd = command.toLowerCase();
|
|
223
|
+
if (WINDOWS_CMD_SHIMS.has(cmd)) {
|
|
224
|
+
return ["cmd.exe", ["/d", "/s", "/c", `${command}.cmd`, ...flags]];
|
|
225
|
+
}
|
|
226
|
+
if (WINDOWS_EXE_SHIMS.has(cmd)) {
|
|
227
|
+
return [`${command}.exe`, flags];
|
|
228
|
+
}
|
|
229
|
+
return [command, flags];
|
|
230
|
+
}
|
|
216
231
|
async function shell(command, flags, opts = {}) {
|
|
217
232
|
let child;
|
|
218
233
|
let stdout2 = "";
|
|
219
234
|
let stderr = "";
|
|
220
|
-
if (!signal) {
|
|
221
|
-
const controller = new AbortController();
|
|
222
|
-
process.once("beforeexit", () => controller.abort());
|
|
223
|
-
process.once("exit", () => controller.abort());
|
|
224
|
-
signal = controller.signal;
|
|
225
|
-
}
|
|
226
235
|
try {
|
|
227
|
-
|
|
236
|
+
const [resolvedCommand, resolvedFlags] = resolveCommand(command, flags);
|
|
237
|
+
child = spawn(resolvedCommand, resolvedFlags, {
|
|
228
238
|
cwd: opts.cwd,
|
|
229
|
-
shell: true,
|
|
230
239
|
stdio: opts.stdio,
|
|
231
|
-
timeout: opts.timeout
|
|
232
|
-
signal
|
|
240
|
+
timeout: opts.timeout
|
|
233
241
|
});
|
|
234
|
-
const done2 = new Promise((resolve) =>
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
242
|
+
const done2 = new Promise((resolve, reject) => {
|
|
243
|
+
child.once("error", reject);
|
|
244
|
+
child.once("close", () => resolve());
|
|
245
|
+
});
|
|
246
|
+
[stdout2, stderr] = await Promise.all([text(child.stdout), text(child.stderr), done2]);
|
|
247
|
+
} catch (e) {
|
|
248
|
+
const message = e instanceof Error ? e.message : stderr || "Unknown error";
|
|
249
|
+
throw new Error(message);
|
|
239
250
|
}
|
|
240
251
|
const { exitCode } = child;
|
|
241
252
|
if (exitCode === null) {
|
|
242
253
|
throw new Error("Timeout");
|
|
243
254
|
}
|
|
244
255
|
if (exitCode !== 0) {
|
|
245
|
-
throw new Error(stderr);
|
|
256
|
+
throw new Error(stderr || `Process exited with code ${exitCode}`);
|
|
246
257
|
}
|
|
247
258
|
return { stdout: stdout2, stderr, exitCode };
|
|
248
259
|
}
|
|
@@ -438,7 +449,7 @@ import path from "node:path";
|
|
|
438
449
|
import { fileURLToPath } from "node:url";
|
|
439
450
|
import { color as color2, say } from "@astrojs/cli-kit";
|
|
440
451
|
import { random, sleep } from "@astrojs/cli-kit/utils";
|
|
441
|
-
import { resolveCommand } from "package-manager-detector";
|
|
452
|
+
import { resolveCommand as resolveCommand2 } from "package-manager-detector";
|
|
442
453
|
async function install(ctx, shellFn = shell) {
|
|
443
454
|
await banner();
|
|
444
455
|
newline();
|
|
@@ -516,7 +527,7 @@ function sortPackages(a, b) {
|
|
|
516
527
|
async function runInstallCommand(ctx, dependencies, devDependencies, shellFn = shell) {
|
|
517
528
|
const cwd = fileURLToPath(ctx.cwd);
|
|
518
529
|
if (ctx.packageManager.name === "yarn") await ensureYarnLock({ cwd });
|
|
519
|
-
const installCommand =
|
|
530
|
+
const installCommand = resolveCommand2(ctx.packageManager.agent, "add", []);
|
|
520
531
|
if (!installCommand) {
|
|
521
532
|
error("error", `Unable to find install command for ${ctx.packageManager.name}.`);
|
|
522
533
|
return ctx.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/upgrade",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,12 +34,13 @@
|
|
|
34
34
|
"astro-scripts": "0.0.14"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
|
-
"node": "
|
|
37
|
+
"node": ">=22.12.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "astro-scripts build \"src/index.ts\" --bundle && tsc",
|
|
41
41
|
"build:ci": "astro-scripts build \"src/index.ts\" --bundle",
|
|
42
42
|
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
|
43
|
-
"test": "astro-scripts test \"test/**/*.test.
|
|
43
|
+
"test": "astro-scripts test \"test/**/*.test.ts\"",
|
|
44
|
+
"typecheck:tests": "tsc --build tsconfig.test.json"
|
|
44
45
|
}
|
|
45
46
|
}
|
package/upgrade.mjs
CHANGED
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
const currentVersion = process.versions.node;
|
|
6
6
|
const requiredMajorVersion = Number.parseInt(currentVersion.split('.')[0], 10);
|
|
7
|
-
|
|
8
|
-
const IS_STACKBLITZ = !!process.versions.webcontainer;
|
|
9
|
-
const minimumMajorVersion = IS_STACKBLITZ ? 20 : 22;
|
|
7
|
+
const minimumMajorVersion = 22;
|
|
10
8
|
|
|
11
9
|
if (requiredMajorVersion < minimumMajorVersion) {
|
|
12
10
|
console.error(`Node.js v${currentVersion} is out-of-date and unsupported!`);
|