@astrojs/upgrade 0.7.1 → 0.7.3
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 +42 -23
- package/package.json +9 -6
- package/upgrade.mjs +1 -1
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 || stdout2 || `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);
|
|
@@ -562,11 +573,19 @@ async function runInstallCommand(ctx, dependencies, devDependencies, shellFn = s
|
|
|
562
573
|
)
|
|
563
574
|
].join(" ");
|
|
564
575
|
newline();
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
576
|
+
if (errorMessage.includes("MINIMUM_RELEASE_AGE")) {
|
|
577
|
+
error(
|
|
578
|
+
"error",
|
|
579
|
+
`pnpm's ${color2.bold("minimumReleaseAge")} policy blocked the installation. Run the following command manually to confirm the update:
|
|
580
|
+
${color2.bold(manualInstallCommand)}`
|
|
581
|
+
);
|
|
582
|
+
} else {
|
|
583
|
+
error(
|
|
584
|
+
"error",
|
|
585
|
+
`Dependencies failed to install, please run the following command manually:
|
|
568
586
|
${color2.bold(manualInstallCommand)}`
|
|
569
|
-
|
|
587
|
+
);
|
|
588
|
+
}
|
|
570
589
|
return ctx.exit(1);
|
|
571
590
|
}
|
|
572
591
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/upgrade",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
".": "./upgrade.mjs"
|
|
16
16
|
},
|
|
17
17
|
"main": "./upgrade.mjs",
|
|
18
|
-
"bin": "./upgrade.mjs",
|
|
19
18
|
"files": [
|
|
20
|
-
"dist",
|
|
21
|
-
"
|
|
19
|
+
"dist/**/*.js",
|
|
20
|
+
"dist/**/*.mjs",
|
|
21
|
+
"upgrade.mjs"
|
|
22
22
|
],
|
|
23
23
|
"//a": "MOST PACKAGES SHOULD GO IN DEV_DEPENDENCIES! THEY WILL BE BUNDLED.",
|
|
24
24
|
"//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES",
|
|
@@ -37,9 +37,12 @@
|
|
|
37
37
|
"node": ">=22.12.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build": "astro-scripts build \"src/index.ts\" --bundle && tsc",
|
|
40
|
+
"build": "astro-scripts build \"src/index.ts\" --bundle && tsc -b",
|
|
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
|
+
},
|
|
45
|
+
"bin": {
|
|
46
|
+
"upgrade": "./upgrade.mjs"
|
|
44
47
|
}
|
|
45
48
|
}
|
package/upgrade.mjs
CHANGED