@astrojs/upgrade 0.3.0 → 0.3.1
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 +26 -39
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -172,7 +172,7 @@ var require_arg = __commonJS({
|
|
|
172
172
|
var import_arg = __toESM(require_arg(), 1);
|
|
173
173
|
import { pathToFileURL } from "node:url";
|
|
174
174
|
import { prompt } from "@astrojs/cli-kit";
|
|
175
|
-
import detectPackageManager from "
|
|
175
|
+
import detectPackageManager from "preferred-pm";
|
|
176
176
|
async function getContext(argv) {
|
|
177
177
|
const flags = (0, import_arg.default)(
|
|
178
178
|
{
|
|
@@ -182,8 +182,12 @@ async function getContext(argv) {
|
|
|
182
182
|
},
|
|
183
183
|
{ argv, permissive: true }
|
|
184
184
|
);
|
|
185
|
-
const packageManager = detectPackageManager()?.name ?? "npm";
|
|
186
|
-
const {
|
|
185
|
+
const packageManager = (await detectPackageManager(process.cwd()))?.name ?? "npm";
|
|
186
|
+
const {
|
|
187
|
+
_: [version = "latest"] = [],
|
|
188
|
+
"--help": help2 = false,
|
|
189
|
+
"--dry-run": dryRun
|
|
190
|
+
} = flags;
|
|
187
191
|
return {
|
|
188
192
|
help: help2,
|
|
189
193
|
prompt,
|
|
@@ -201,8 +205,8 @@ async function getContext(argv) {
|
|
|
201
205
|
// src/messages.ts
|
|
202
206
|
import { color, label, spinner as load } from "@astrojs/cli-kit";
|
|
203
207
|
import { align } from "@astrojs/cli-kit/utils";
|
|
208
|
+
import detectPackageManager2 from "preferred-pm";
|
|
204
209
|
import terminalLink from "terminal-link";
|
|
205
|
-
import detectPackageManager2 from "which-pm-runs";
|
|
206
210
|
|
|
207
211
|
// src/shell.ts
|
|
208
212
|
import { spawn } from "node:child_process";
|
|
@@ -246,15 +250,13 @@ async function shell(command, flags, opts = {}) {
|
|
|
246
250
|
// src/messages.ts
|
|
247
251
|
var _registry;
|
|
248
252
|
async function getRegistry() {
|
|
249
|
-
if (_registry)
|
|
250
|
-
return _registry;
|
|
253
|
+
if (_registry) return _registry;
|
|
251
254
|
const fallback = "https://registry.npmjs.org";
|
|
252
|
-
const packageManager = detectPackageManager2()?.name || "npm";
|
|
255
|
+
const packageManager = (await detectPackageManager2(process.cwd()))?.name || "npm";
|
|
253
256
|
try {
|
|
254
257
|
const { stdout: stdout2 } = await shell(packageManager, ["config", "get", "registry"]);
|
|
255
258
|
_registry = stdout2?.trim()?.replace(/\/$/, "") || fallback;
|
|
256
|
-
if (!new URL(_registry).host)
|
|
257
|
-
_registry = fallback;
|
|
259
|
+
if (!new URL(_registry).host) _registry = fallback;
|
|
258
260
|
} catch (e) {
|
|
259
261
|
_registry = fallback;
|
|
260
262
|
}
|
|
@@ -269,8 +271,7 @@ async function spinner(args) {
|
|
|
269
271
|
}
|
|
270
272
|
function pluralize(word, n) {
|
|
271
273
|
const [singular, plural] = Array.isArray(word) ? word : [word, word + "s"];
|
|
272
|
-
if (n === 1)
|
|
273
|
-
return singular;
|
|
274
|
+
if (n === 1) return singular;
|
|
274
275
|
return plural;
|
|
275
276
|
}
|
|
276
277
|
var celebrations = [
|
|
@@ -502,24 +503,17 @@ function filterPackages(ctx) {
|
|
|
502
503
|
return { current, dependencies, devDependencies };
|
|
503
504
|
}
|
|
504
505
|
function sortPackages(a, b) {
|
|
505
|
-
if (a.isMajor && !b.isMajor)
|
|
506
|
-
|
|
507
|
-
if (
|
|
508
|
-
|
|
509
|
-
if (a.name
|
|
510
|
-
|
|
511
|
-
if (b.name === "astro")
|
|
512
|
-
return 1;
|
|
513
|
-
if (a.name.startsWith("@astrojs") && !b.name.startsWith("@astrojs"))
|
|
514
|
-
return -1;
|
|
515
|
-
if (b.name.startsWith("@astrojs") && !a.name.startsWith("@astrojs"))
|
|
516
|
-
return 1;
|
|
506
|
+
if (a.isMajor && !b.isMajor) return 1;
|
|
507
|
+
if (b.isMajor && !a.isMajor) return -1;
|
|
508
|
+
if (a.name === "astro") return -1;
|
|
509
|
+
if (b.name === "astro") return 1;
|
|
510
|
+
if (a.name.startsWith("@astrojs") && !b.name.startsWith("@astrojs")) return -1;
|
|
511
|
+
if (b.name.startsWith("@astrojs") && !a.name.startsWith("@astrojs")) return 1;
|
|
517
512
|
return a.name.localeCompare(b.name);
|
|
518
513
|
}
|
|
519
514
|
async function runInstallCommand(ctx, dependencies, devDependencies) {
|
|
520
515
|
const cwd = fileURLToPath(ctx.cwd);
|
|
521
|
-
if (ctx.packageManager === "yarn")
|
|
522
|
-
await ensureYarnLock({ cwd });
|
|
516
|
+
if (ctx.packageManager === "yarn") await ensureYarnLock({ cwd });
|
|
523
517
|
const installCmd = ctx.packageManager === "yarn" || ctx.packageManager === "pnpm" ? "add" : "install";
|
|
524
518
|
await spinner({
|
|
525
519
|
start: `Installing dependencies with ${ctx.packageManager}...`,
|
|
@@ -569,8 +563,7 @@ ${color2.bold(
|
|
|
569
563
|
}
|
|
570
564
|
async function ensureYarnLock({ cwd }) {
|
|
571
565
|
const yarnLock = path.join(cwd, "yarn.lock");
|
|
572
|
-
if (fs.existsSync(yarnLock))
|
|
573
|
-
return;
|
|
566
|
+
if (fs.existsSync(yarnLock)) return;
|
|
574
567
|
return fs.promises.writeFile(yarnLock, "", { encoding: "utf-8" });
|
|
575
568
|
}
|
|
576
569
|
|
|
@@ -619,14 +612,11 @@ function safeJSONParse(value) {
|
|
|
619
612
|
}
|
|
620
613
|
async function verifyAstroProject(ctx) {
|
|
621
614
|
const packageJson = new URL("./package.json", ctx.cwd);
|
|
622
|
-
if (!existsSync(packageJson))
|
|
623
|
-
return false;
|
|
615
|
+
if (!existsSync(packageJson)) return false;
|
|
624
616
|
const contents = await readFile(packageJson, { encoding: "utf-8" });
|
|
625
|
-
if (!contents.includes("astro"))
|
|
626
|
-
return false;
|
|
617
|
+
if (!contents.includes("astro")) return false;
|
|
627
618
|
const { dependencies = {}, devDependencies = {} } = safeJSONParse(contents);
|
|
628
|
-
if (dependencies["astro"] === void 0 && devDependencies["astro"] === void 0)
|
|
629
|
-
return false;
|
|
619
|
+
if (dependencies["astro"] === void 0 && devDependencies["astro"] === void 0) return false;
|
|
630
620
|
collectPackageInfo(ctx, dependencies, devDependencies);
|
|
631
621
|
return true;
|
|
632
622
|
}
|
|
@@ -641,15 +631,13 @@ function isValidVersion(_name, version) {
|
|
|
641
631
|
}
|
|
642
632
|
function isSupportedPackage(name, version) {
|
|
643
633
|
for (const validator of [isAstroPackage, isAllowedPackage, isValidVersion]) {
|
|
644
|
-
if (!validator(name, version))
|
|
645
|
-
return false;
|
|
634
|
+
if (!validator(name, version)) return false;
|
|
646
635
|
}
|
|
647
636
|
return true;
|
|
648
637
|
}
|
|
649
638
|
function collectPackageInfo(ctx, dependencies = {}, devDependencies = {}) {
|
|
650
639
|
for (const [name, currentVersion] of Object.entries(dependencies)) {
|
|
651
|
-
if (!isSupportedPackage(name, currentVersion))
|
|
652
|
-
continue;
|
|
640
|
+
if (!isSupportedPackage(name, currentVersion)) continue;
|
|
653
641
|
ctx.packages.push({
|
|
654
642
|
name,
|
|
655
643
|
currentVersion,
|
|
@@ -657,8 +645,7 @@ function collectPackageInfo(ctx, dependencies = {}, devDependencies = {}) {
|
|
|
657
645
|
});
|
|
658
646
|
}
|
|
659
647
|
for (const [name, currentVersion] of Object.entries(devDependencies)) {
|
|
660
|
-
if (!isSupportedPackage(name, currentVersion))
|
|
661
|
-
continue;
|
|
648
|
+
if (!isSupportedPackage(name, currentVersion)) continue;
|
|
662
649
|
ctx.packages.push({
|
|
663
650
|
name,
|
|
664
651
|
currentVersion,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/upgrade",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"//a": "MOST PACKAGES SHOULD GO IN DEV_DEPENDENCIES! THEY WILL BE BUNDLED.",
|
|
24
24
|
"//b": "DEPENDENCIES IS FOR UNBUNDLED PACKAGES",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@astrojs/cli-kit": "^0.
|
|
27
|
-
"semver": "^7.
|
|
28
|
-
"
|
|
26
|
+
"@astrojs/cli-kit": "^0.4.1",
|
|
27
|
+
"semver": "^7.6.2",
|
|
28
|
+
"preferred-pm": "^3.1.3",
|
|
29
29
|
"terminal-link": "^3.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/semver": "^7.5.
|
|
33
|
-
"@types/
|
|
32
|
+
"@types/semver": "^7.5.8",
|
|
33
|
+
"@types/preferred-pm": "^3.0.0",
|
|
34
34
|
"arg": "^5.0.2",
|
|
35
35
|
"strip-ansi": "^7.1.0",
|
|
36
36
|
"astro-scripts": "0.0.14"
|