@astrojs/upgrade 0.3.0 → 0.3.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 +37 -221
- package/package.json +5 -6
package/dist/index.js
CHANGED
|
@@ -1,189 +1,22 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
|
-
|
|
27
|
-
// ../../node_modules/.pnpm/arg@5.0.2/node_modules/arg/index.js
|
|
28
|
-
var require_arg = __commonJS({
|
|
29
|
-
"../../node_modules/.pnpm/arg@5.0.2/node_modules/arg/index.js"(exports, module) {
|
|
30
|
-
var flagSymbol = Symbol("arg flag");
|
|
31
|
-
var ArgError = class _ArgError extends Error {
|
|
32
|
-
constructor(msg, code) {
|
|
33
|
-
super(msg);
|
|
34
|
-
this.name = "ArgError";
|
|
35
|
-
this.code = code;
|
|
36
|
-
Object.setPrototypeOf(this, _ArgError.prototype);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
function arg2(opts, {
|
|
40
|
-
argv = process.argv.slice(2),
|
|
41
|
-
permissive = false,
|
|
42
|
-
stopAtPositional = false
|
|
43
|
-
} = {}) {
|
|
44
|
-
if (!opts) {
|
|
45
|
-
throw new ArgError(
|
|
46
|
-
"argument specification object is required",
|
|
47
|
-
"ARG_CONFIG_NO_SPEC"
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
const result = { _: [] };
|
|
51
|
-
const aliases = {};
|
|
52
|
-
const handlers = {};
|
|
53
|
-
for (const key of Object.keys(opts)) {
|
|
54
|
-
if (!key) {
|
|
55
|
-
throw new ArgError(
|
|
56
|
-
"argument key cannot be an empty string",
|
|
57
|
-
"ARG_CONFIG_EMPTY_KEY"
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
if (key[0] !== "-") {
|
|
61
|
-
throw new ArgError(
|
|
62
|
-
`argument key must start with '-' but found: '${key}'`,
|
|
63
|
-
"ARG_CONFIG_NONOPT_KEY"
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
if (key.length === 1) {
|
|
67
|
-
throw new ArgError(
|
|
68
|
-
`argument key must have a name; singular '-' keys are not allowed: ${key}`,
|
|
69
|
-
"ARG_CONFIG_NONAME_KEY"
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
if (typeof opts[key] === "string") {
|
|
73
|
-
aliases[key] = opts[key];
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
let type = opts[key];
|
|
77
|
-
let isFlag = false;
|
|
78
|
-
if (Array.isArray(type) && type.length === 1 && typeof type[0] === "function") {
|
|
79
|
-
const [fn] = type;
|
|
80
|
-
type = (value, name, prev = []) => {
|
|
81
|
-
prev.push(fn(value, name, prev[prev.length - 1]));
|
|
82
|
-
return prev;
|
|
83
|
-
};
|
|
84
|
-
isFlag = fn === Boolean || fn[flagSymbol] === true;
|
|
85
|
-
} else if (typeof type === "function") {
|
|
86
|
-
isFlag = type === Boolean || type[flagSymbol] === true;
|
|
87
|
-
} else {
|
|
88
|
-
throw new ArgError(
|
|
89
|
-
`type missing or not a function or valid array type: ${key}`,
|
|
90
|
-
"ARG_CONFIG_VAD_TYPE"
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
if (key[1] !== "-" && key.length > 2) {
|
|
94
|
-
throw new ArgError(
|
|
95
|
-
`short argument keys (with a single hyphen) must have only one character: ${key}`,
|
|
96
|
-
"ARG_CONFIG_SHORTOPT_TOOLONG"
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
handlers[key] = [type, isFlag];
|
|
100
|
-
}
|
|
101
|
-
for (let i = 0, len = argv.length; i < len; i++) {
|
|
102
|
-
const wholeArg = argv[i];
|
|
103
|
-
if (stopAtPositional && result._.length > 0) {
|
|
104
|
-
result._ = result._.concat(argv.slice(i));
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
if (wholeArg === "--") {
|
|
108
|
-
result._ = result._.concat(argv.slice(i + 1));
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
if (wholeArg.length > 1 && wholeArg[0] === "-") {
|
|
112
|
-
const separatedArguments = wholeArg[1] === "-" || wholeArg.length === 2 ? [wholeArg] : wholeArg.slice(1).split("").map((a) => `-${a}`);
|
|
113
|
-
for (let j = 0; j < separatedArguments.length; j++) {
|
|
114
|
-
const arg3 = separatedArguments[j];
|
|
115
|
-
const [originalArgName, argStr] = arg3[1] === "-" ? arg3.split(/=(.*)/, 2) : [arg3, void 0];
|
|
116
|
-
let argName = originalArgName;
|
|
117
|
-
while (argName in aliases) {
|
|
118
|
-
argName = aliases[argName];
|
|
119
|
-
}
|
|
120
|
-
if (!(argName in handlers)) {
|
|
121
|
-
if (permissive) {
|
|
122
|
-
result._.push(arg3);
|
|
123
|
-
continue;
|
|
124
|
-
} else {
|
|
125
|
-
throw new ArgError(
|
|
126
|
-
`unknown or unexpected option: ${originalArgName}`,
|
|
127
|
-
"ARG_UNKNOWN_OPTION"
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
const [type, isFlag] = handlers[argName];
|
|
132
|
-
if (!isFlag && j + 1 < separatedArguments.length) {
|
|
133
|
-
throw new ArgError(
|
|
134
|
-
`option requires argument (but was followed by another short argument): ${originalArgName}`,
|
|
135
|
-
"ARG_MISSING_REQUIRED_SHORTARG"
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
if (isFlag) {
|
|
139
|
-
result[argName] = type(true, argName, result[argName]);
|
|
140
|
-
} else if (argStr === void 0) {
|
|
141
|
-
if (argv.length < i + 2 || argv[i + 1].length > 1 && argv[i + 1][0] === "-" && !(argv[i + 1].match(/^-?\d*(\.(?=\d))?\d*$/) && (type === Number || // eslint-disable-next-line no-undef
|
|
142
|
-
typeof BigInt !== "undefined" && type === BigInt))) {
|
|
143
|
-
const extended = originalArgName === argName ? "" : ` (alias for ${argName})`;
|
|
144
|
-
throw new ArgError(
|
|
145
|
-
`option requires argument: ${originalArgName}${extended}`,
|
|
146
|
-
"ARG_MISSING_REQUIRED_LONGARG"
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
result[argName] = type(argv[i + 1], argName, result[argName]);
|
|
150
|
-
++i;
|
|
151
|
-
} else {
|
|
152
|
-
result[argName] = type(argStr, argName, result[argName]);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
} else {
|
|
156
|
-
result._.push(wholeArg);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return result;
|
|
160
|
-
}
|
|
161
|
-
arg2.flag = (fn) => {
|
|
162
|
-
fn[flagSymbol] = true;
|
|
163
|
-
return fn;
|
|
164
|
-
};
|
|
165
|
-
arg2.COUNT = arg2.flag((v, name, existingCount) => (existingCount || 0) + 1);
|
|
166
|
-
arg2.ArgError = ArgError;
|
|
167
|
-
module.exports = arg2;
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
|
|
171
1
|
// src/actions/context.ts
|
|
172
|
-
var import_arg = __toESM(require_arg(), 1);
|
|
173
2
|
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
174
4
|
import { prompt } from "@astrojs/cli-kit";
|
|
175
|
-
import detectPackageManager from "
|
|
5
|
+
import detectPackageManager from "preferred-pm";
|
|
176
6
|
async function getContext(argv) {
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const
|
|
7
|
+
const args = parseArgs({
|
|
8
|
+
args: argv,
|
|
9
|
+
allowPositionals: true,
|
|
10
|
+
strict: false,
|
|
11
|
+
options: {
|
|
12
|
+
"dry-run": { type: "boolean" },
|
|
13
|
+
help: { type: "boolean", short: "h" }
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const packageManager = (await detectPackageManager(process.cwd()))?.name ?? "npm";
|
|
17
|
+
const version = args.positionals[0] ?? "latest";
|
|
18
|
+
const help2 = !!args.values.help;
|
|
19
|
+
const dryRun = !!args.values["dry-run"];
|
|
187
20
|
return {
|
|
188
21
|
help: help2,
|
|
189
22
|
prompt,
|
|
@@ -201,8 +34,8 @@ async function getContext(argv) {
|
|
|
201
34
|
// src/messages.ts
|
|
202
35
|
import { color, label, spinner as load } from "@astrojs/cli-kit";
|
|
203
36
|
import { align } from "@astrojs/cli-kit/utils";
|
|
37
|
+
import detectPackageManager2 from "preferred-pm";
|
|
204
38
|
import terminalLink from "terminal-link";
|
|
205
|
-
import detectPackageManager2 from "which-pm-runs";
|
|
206
39
|
|
|
207
40
|
// src/shell.ts
|
|
208
41
|
import { spawn } from "node:child_process";
|
|
@@ -230,7 +63,7 @@ async function shell(command, flags, opts = {}) {
|
|
|
230
63
|
const done2 = new Promise((resolve) => child.on("close", resolve));
|
|
231
64
|
[stdout2, stderr] = await Promise.all([text(child.stdout), text(child.stderr)]);
|
|
232
65
|
await done2;
|
|
233
|
-
} catch
|
|
66
|
+
} catch {
|
|
234
67
|
throw { stdout: stdout2, stderr, exitCode: 1 };
|
|
235
68
|
}
|
|
236
69
|
const { exitCode } = child;
|
|
@@ -246,16 +79,14 @@ async function shell(command, flags, opts = {}) {
|
|
|
246
79
|
// src/messages.ts
|
|
247
80
|
var _registry;
|
|
248
81
|
async function getRegistry() {
|
|
249
|
-
if (_registry)
|
|
250
|
-
return _registry;
|
|
82
|
+
if (_registry) return _registry;
|
|
251
83
|
const fallback = "https://registry.npmjs.org";
|
|
252
|
-
const packageManager = detectPackageManager2()?.name || "npm";
|
|
84
|
+
const packageManager = (await detectPackageManager2(process.cwd()))?.name || "npm";
|
|
253
85
|
try {
|
|
254
86
|
const { stdout: stdout2 } = await shell(packageManager, ["config", "get", "registry"]);
|
|
255
87
|
_registry = stdout2?.trim()?.replace(/\/$/, "") || fallback;
|
|
256
|
-
if (!new URL(_registry).host)
|
|
257
|
-
|
|
258
|
-
} catch (e) {
|
|
88
|
+
if (!new URL(_registry).host) _registry = fallback;
|
|
89
|
+
} catch {
|
|
259
90
|
_registry = fallback;
|
|
260
91
|
}
|
|
261
92
|
return _registry;
|
|
@@ -269,8 +100,7 @@ async function spinner(args) {
|
|
|
269
100
|
}
|
|
270
101
|
function pluralize(word, n) {
|
|
271
102
|
const [singular, plural] = Array.isArray(word) ? word : [word, word + "s"];
|
|
272
|
-
if (n === 1)
|
|
273
|
-
return singular;
|
|
103
|
+
if (n === 1) return singular;
|
|
274
104
|
return plural;
|
|
275
105
|
}
|
|
276
106
|
var celebrations = [
|
|
@@ -502,24 +332,17 @@ function filterPackages(ctx) {
|
|
|
502
332
|
return { current, dependencies, devDependencies };
|
|
503
333
|
}
|
|
504
334
|
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;
|
|
335
|
+
if (a.isMajor && !b.isMajor) return 1;
|
|
336
|
+
if (b.isMajor && !a.isMajor) return -1;
|
|
337
|
+
if (a.name === "astro") return -1;
|
|
338
|
+
if (b.name === "astro") return 1;
|
|
339
|
+
if (a.name.startsWith("@astrojs") && !b.name.startsWith("@astrojs")) return -1;
|
|
340
|
+
if (b.name.startsWith("@astrojs") && !a.name.startsWith("@astrojs")) return 1;
|
|
517
341
|
return a.name.localeCompare(b.name);
|
|
518
342
|
}
|
|
519
343
|
async function runInstallCommand(ctx, dependencies, devDependencies) {
|
|
520
344
|
const cwd = fileURLToPath(ctx.cwd);
|
|
521
|
-
if (ctx.packageManager === "yarn")
|
|
522
|
-
await ensureYarnLock({ cwd });
|
|
345
|
+
if (ctx.packageManager === "yarn") await ensureYarnLock({ cwd });
|
|
523
346
|
const installCmd = ctx.packageManager === "yarn" || ctx.packageManager === "pnpm" ? "add" : "install";
|
|
524
347
|
await spinner({
|
|
525
348
|
start: `Installing dependencies with ${ctx.packageManager}...`,
|
|
@@ -569,8 +392,7 @@ ${color2.bold(
|
|
|
569
392
|
}
|
|
570
393
|
async function ensureYarnLock({ cwd }) {
|
|
571
394
|
const yarnLock = path.join(cwd, "yarn.lock");
|
|
572
|
-
if (fs.existsSync(yarnLock))
|
|
573
|
-
return;
|
|
395
|
+
if (fs.existsSync(yarnLock)) return;
|
|
574
396
|
return fs.promises.writeFile(yarnLock, "", { encoding: "utf-8" });
|
|
575
397
|
}
|
|
576
398
|
|
|
@@ -619,14 +441,11 @@ function safeJSONParse(value) {
|
|
|
619
441
|
}
|
|
620
442
|
async function verifyAstroProject(ctx) {
|
|
621
443
|
const packageJson = new URL("./package.json", ctx.cwd);
|
|
622
|
-
if (!existsSync(packageJson))
|
|
623
|
-
return false;
|
|
444
|
+
if (!existsSync(packageJson)) return false;
|
|
624
445
|
const contents = await readFile(packageJson, { encoding: "utf-8" });
|
|
625
|
-
if (!contents.includes("astro"))
|
|
626
|
-
return false;
|
|
446
|
+
if (!contents.includes("astro")) return false;
|
|
627
447
|
const { dependencies = {}, devDependencies = {} } = safeJSONParse(contents);
|
|
628
|
-
if (dependencies["astro"] === void 0 && devDependencies["astro"] === void 0)
|
|
629
|
-
return false;
|
|
448
|
+
if (dependencies["astro"] === void 0 && devDependencies["astro"] === void 0) return false;
|
|
630
449
|
collectPackageInfo(ctx, dependencies, devDependencies);
|
|
631
450
|
return true;
|
|
632
451
|
}
|
|
@@ -641,15 +460,13 @@ function isValidVersion(_name, version) {
|
|
|
641
460
|
}
|
|
642
461
|
function isSupportedPackage(name, version) {
|
|
643
462
|
for (const validator of [isAstroPackage, isAllowedPackage, isValidVersion]) {
|
|
644
|
-
if (!validator(name, version))
|
|
645
|
-
return false;
|
|
463
|
+
if (!validator(name, version)) return false;
|
|
646
464
|
}
|
|
647
465
|
return true;
|
|
648
466
|
}
|
|
649
467
|
function collectPackageInfo(ctx, dependencies = {}, devDependencies = {}) {
|
|
650
468
|
for (const [name, currentVersion] of Object.entries(dependencies)) {
|
|
651
|
-
if (!isSupportedPackage(name, currentVersion))
|
|
652
|
-
continue;
|
|
469
|
+
if (!isSupportedPackage(name, currentVersion)) continue;
|
|
653
470
|
ctx.packages.push({
|
|
654
471
|
name,
|
|
655
472
|
currentVersion,
|
|
@@ -657,8 +474,7 @@ function collectPackageInfo(ctx, dependencies = {}, devDependencies = {}) {
|
|
|
657
474
|
});
|
|
658
475
|
}
|
|
659
476
|
for (const [name, currentVersion] of Object.entries(devDependencies)) {
|
|
660
|
-
if (!isSupportedPackage(name, currentVersion))
|
|
661
|
-
continue;
|
|
477
|
+
if (!isSupportedPackage(name, currentVersion)) continue;
|
|
662
478
|
ctx.packages.push({
|
|
663
479
|
name,
|
|
664
480
|
currentVersion,
|
|
@@ -740,7 +556,7 @@ var exit = () => process.exit(0);
|
|
|
740
556
|
process.on("SIGINT", exit);
|
|
741
557
|
process.on("SIGTERM", exit);
|
|
742
558
|
async function main() {
|
|
743
|
-
const cleanArgv = process.argv.slice(2).filter((
|
|
559
|
+
const cleanArgv = process.argv.slice(2).filter((arg) => arg !== "--");
|
|
744
560
|
const ctx = await getContext(cleanArgv);
|
|
745
561
|
if (ctx.help) {
|
|
746
562
|
help();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/upgrade",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,14 +23,13 @@
|
|
|
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.3",
|
|
28
|
+
"preferred-pm": "^4.0.0",
|
|
29
29
|
"terminal-link": "^3.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/semver": "^7.5.
|
|
33
|
-
"@types/which-pm-runs": "^1.0.0",
|
|
32
|
+
"@types/semver": "^7.5.8",
|
|
34
33
|
"arg": "^5.0.2",
|
|
35
34
|
"strip-ansi": "^7.1.0",
|
|
36
35
|
"astro-scripts": "0.0.14"
|