@nuxt/cli-nightly 0.0.0 → 3.20.0-20250109-193455-6ea36ef
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/LICENSE +21 -0
- package/README.md +27 -0
- package/bin/nuxi.mjs +11 -0
- package/dist/chunks/add.mjs +317 -0
- package/dist/chunks/add2.mjs +320 -0
- package/dist/chunks/analyze.mjs +134 -0
- package/dist/chunks/build.mjs +90 -0
- package/dist/chunks/cleanup.mjs +33 -0
- package/dist/chunks/dev-child.mjs +81 -0
- package/dist/chunks/dev.mjs +224 -0
- package/dist/chunks/dev2.mjs +250 -0
- package/dist/chunks/devtools.mjs +44 -0
- package/dist/chunks/generate.mjs +40 -0
- package/dist/chunks/index.mjs +15 -0
- package/dist/chunks/info.mjs +146 -0
- package/dist/chunks/init.mjs +189 -0
- package/dist/chunks/prepare.mjs +54 -0
- package/dist/chunks/preview.mjs +102 -0
- package/dist/chunks/search.mjs +110 -0
- package/dist/chunks/test.mjs +61 -0
- package/dist/chunks/typecheck.mjs +73 -0
- package/dist/chunks/upgrade.mjs +187 -0
- package/dist/index.d.mts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.mjs +7 -0
- package/dist/shared/cli-nightly.7lipAIIb.mjs +49 -0
- package/dist/shared/cli-nightly.BSm0_9Hr.mjs +7 -0
- package/dist/shared/cli-nightly.C935N1ss.mjs +29 -0
- package/dist/shared/cli-nightly.CGRrR0sp.mjs +26 -0
- package/dist/shared/cli-nightly.CPUttwQp.mjs +52 -0
- package/dist/shared/cli-nightly.CnY_9Zvw.mjs +307 -0
- package/dist/shared/cli-nightly.DlcAx0De.mjs +38 -0
- package/dist/shared/cli-nightly.cDY7IcTr.mjs +14 -0
- package/package.json +91 -2
- package/dist/.gitkeep +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { defineCommand } from 'citty';
|
|
3
|
+
import { resolve, relative } from 'pathe';
|
|
4
|
+
import { a as clearBuildDir } from '../shared/cli-nightly.7lipAIIb.mjs';
|
|
5
|
+
import { l as loadKit } from '../shared/cli-nightly.DlcAx0De.mjs';
|
|
6
|
+
import { d as dotEnvArgs, c as cwdArgs, l as logLevelArgs, e as envNameArgs, b as legacyRootDirArgs, a as logger } from '../shared/cli-nightly.CnY_9Zvw.mjs';
|
|
7
|
+
import 'node:fs';
|
|
8
|
+
import 'jiti';
|
|
9
|
+
import 'node:path';
|
|
10
|
+
import 'std-env';
|
|
11
|
+
import 'consola';
|
|
12
|
+
import 'node:url';
|
|
13
|
+
|
|
14
|
+
const prepare = defineCommand({
|
|
15
|
+
meta: {
|
|
16
|
+
name: "prepare",
|
|
17
|
+
description: "Prepare Nuxt for development/build"
|
|
18
|
+
},
|
|
19
|
+
args: {
|
|
20
|
+
...dotEnvArgs,
|
|
21
|
+
...cwdArgs,
|
|
22
|
+
...logLevelArgs,
|
|
23
|
+
...envNameArgs,
|
|
24
|
+
...legacyRootDirArgs
|
|
25
|
+
},
|
|
26
|
+
async run(ctx) {
|
|
27
|
+
process.env.NODE_ENV = process.env.NODE_ENV || "production";
|
|
28
|
+
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir);
|
|
29
|
+
const { loadNuxt, buildNuxt, writeTypes } = await loadKit(cwd);
|
|
30
|
+
const nuxt = await loadNuxt({
|
|
31
|
+
cwd,
|
|
32
|
+
dotenv: {
|
|
33
|
+
cwd,
|
|
34
|
+
fileName: ctx.args.dotenv
|
|
35
|
+
},
|
|
36
|
+
envName: ctx.args.envName,
|
|
37
|
+
// c12 will fall back to NODE_ENV
|
|
38
|
+
overrides: {
|
|
39
|
+
_prepare: true,
|
|
40
|
+
logLevel: ctx.args.logLevel,
|
|
41
|
+
...ctx.data?.overrides
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
await clearBuildDir(nuxt.options.buildDir);
|
|
45
|
+
await buildNuxt(nuxt);
|
|
46
|
+
await writeTypes(nuxt);
|
|
47
|
+
logger.success(
|
|
48
|
+
"Types generated in",
|
|
49
|
+
relative(process.cwd(), nuxt.options.buildDir)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export { prepare as default };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { existsSync, promises } from 'node:fs';
|
|
2
|
+
import { dirname, relative } from 'node:path';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
import { setupDotenv } from 'c12';
|
|
5
|
+
import { defineCommand } from 'citty';
|
|
6
|
+
import { box, colors } from 'consola/utils';
|
|
7
|
+
import { resolve } from 'pathe';
|
|
8
|
+
import { x } from 'tinyexec';
|
|
9
|
+
import { l as loadKit } from '../shared/cli-nightly.DlcAx0De.mjs';
|
|
10
|
+
import { c as cwdArgs, l as logLevelArgs, e as envNameArgs, b as legacyRootDirArgs, d as dotEnvArgs, a as logger } from '../shared/cli-nightly.CnY_9Zvw.mjs';
|
|
11
|
+
import 'jiti';
|
|
12
|
+
import 'std-env';
|
|
13
|
+
import 'consola';
|
|
14
|
+
import 'node:url';
|
|
15
|
+
|
|
16
|
+
const preview = defineCommand({
|
|
17
|
+
meta: {
|
|
18
|
+
name: "preview",
|
|
19
|
+
description: "Launches Nitro server for local testing after `nuxi build`."
|
|
20
|
+
},
|
|
21
|
+
args: {
|
|
22
|
+
...cwdArgs,
|
|
23
|
+
...logLevelArgs,
|
|
24
|
+
...envNameArgs,
|
|
25
|
+
...legacyRootDirArgs,
|
|
26
|
+
...dotEnvArgs
|
|
27
|
+
},
|
|
28
|
+
async run(ctx) {
|
|
29
|
+
process.env.NODE_ENV = process.env.NODE_ENV || "production";
|
|
30
|
+
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir);
|
|
31
|
+
const { loadNuxtConfig } = await loadKit(cwd);
|
|
32
|
+
const config = await loadNuxtConfig({
|
|
33
|
+
cwd,
|
|
34
|
+
envName: ctx.args.envName,
|
|
35
|
+
// c12 will fall back to NODE_ENV
|
|
36
|
+
overrides: (
|
|
37
|
+
/* ctx.options?.overrides || */
|
|
38
|
+
{}
|
|
39
|
+
)
|
|
40
|
+
});
|
|
41
|
+
const resolvedOutputDir = resolve(
|
|
42
|
+
config.srcDir || cwd,
|
|
43
|
+
config.nitro.output?.dir || ".output",
|
|
44
|
+
"nitro.json"
|
|
45
|
+
);
|
|
46
|
+
const defaultOutput = resolve(cwd, ".output", "nitro.json");
|
|
47
|
+
const nitroJSONPaths = [resolvedOutputDir, defaultOutput];
|
|
48
|
+
const nitroJSONPath = nitroJSONPaths.find((p) => existsSync(p));
|
|
49
|
+
if (!nitroJSONPath) {
|
|
50
|
+
logger.error(
|
|
51
|
+
"Cannot find `nitro.json`. Did you run `nuxi build` first? Search path:\n",
|
|
52
|
+
nitroJSONPaths
|
|
53
|
+
);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
const outputPath = dirname(nitroJSONPath);
|
|
57
|
+
const nitroJSON = JSON.parse(await promises.readFile(nitroJSONPath, "utf-8"));
|
|
58
|
+
if (!nitroJSON.commands.preview) {
|
|
59
|
+
logger.error("Preview is not supported for this build.");
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
const info = [
|
|
63
|
+
["Node.js:", `v${process.versions.node}`],
|
|
64
|
+
["Nitro Preset:", nitroJSON.preset],
|
|
65
|
+
["Working directory:", relative(process.cwd(), outputPath)]
|
|
66
|
+
];
|
|
67
|
+
const _infoKeyLen = Math.max(...info.map(([label]) => label.length));
|
|
68
|
+
logger.log(
|
|
69
|
+
box(
|
|
70
|
+
[
|
|
71
|
+
"You are running Nuxt production build in preview mode.",
|
|
72
|
+
`For production deployments, please directly use ${colors.cyan(
|
|
73
|
+
nitroJSON.commands.preview
|
|
74
|
+
)} command.`,
|
|
75
|
+
"",
|
|
76
|
+
...info.map(
|
|
77
|
+
([label, value]) => `${label.padEnd(_infoKeyLen, " ")} ${colors.cyan(value)}`
|
|
78
|
+
)
|
|
79
|
+
].join("\n"),
|
|
80
|
+
{
|
|
81
|
+
title: colors.yellow("Preview Mode"),
|
|
82
|
+
style: {
|
|
83
|
+
borderColor: "yellow"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
const envExists = ctx.args.dotenv ? existsSync(resolve(cwd, ctx.args.dotenv)) : existsSync(cwd);
|
|
89
|
+
if (envExists) {
|
|
90
|
+
logger.info(
|
|
91
|
+
`Loading \`${ctx.args.dotenv || ".env"}\`. This will not be loaded when running the server in production.`
|
|
92
|
+
);
|
|
93
|
+
await setupDotenv({ cwd, fileName: ctx.args.dotenv });
|
|
94
|
+
}
|
|
95
|
+
logger.info(`Starting preview command: \`${nitroJSON.commands.preview}\``);
|
|
96
|
+
const [command, ...commandArgs] = nitroJSON.commands.preview.split(" ");
|
|
97
|
+
logger.log("");
|
|
98
|
+
await x(command, commandArgs, { nodeOptions: { stdio: "inherit", cwd: outputPath } });
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
export { preview as default };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import { colors } from 'consola/utils';
|
|
3
|
+
import Fuse from 'fuse.js';
|
|
4
|
+
import { upperFirst, kebabCase } from 'scule';
|
|
5
|
+
import { c as cwdArgs, a as logger } from '../shared/cli-nightly.CnY_9Zvw.mjs';
|
|
6
|
+
import { g as getNuxtVersion, f as fetchModules, c as checkNuxtCompatibility } from '../shared/cli-nightly.C935N1ss.mjs';
|
|
7
|
+
import 'node:path';
|
|
8
|
+
import 'node:process';
|
|
9
|
+
import 'std-env';
|
|
10
|
+
import 'consola';
|
|
11
|
+
import 'node:url';
|
|
12
|
+
import 'ofetch';
|
|
13
|
+
import 'pkg-types';
|
|
14
|
+
import 'semver';
|
|
15
|
+
|
|
16
|
+
const { format: formatNumber } = Intl.NumberFormat("en-GB", {
|
|
17
|
+
notation: "compact",
|
|
18
|
+
maximumFractionDigits: 1
|
|
19
|
+
});
|
|
20
|
+
const search = defineCommand({
|
|
21
|
+
meta: {
|
|
22
|
+
name: "search",
|
|
23
|
+
description: "Search in Nuxt modules"
|
|
24
|
+
},
|
|
25
|
+
args: {
|
|
26
|
+
...cwdArgs,
|
|
27
|
+
query: {
|
|
28
|
+
type: "positional",
|
|
29
|
+
description: "keywords to search for",
|
|
30
|
+
required: true
|
|
31
|
+
},
|
|
32
|
+
nuxtVersion: {
|
|
33
|
+
type: "string",
|
|
34
|
+
description: "Filter by Nuxt version and list compatible modules only (auto detected by default)",
|
|
35
|
+
required: false
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
async setup(ctx) {
|
|
39
|
+
const nuxtVersion = await getNuxtVersion(ctx.args.cwd);
|
|
40
|
+
return findModuleByKeywords(ctx.args._.join(" "), nuxtVersion);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
async function findModuleByKeywords(query, nuxtVersion) {
|
|
44
|
+
const allModules = await fetchModules();
|
|
45
|
+
const compatibleModules = allModules.filter(
|
|
46
|
+
(m) => checkNuxtCompatibility(m, nuxtVersion)
|
|
47
|
+
);
|
|
48
|
+
const fuse = new Fuse(compatibleModules, {
|
|
49
|
+
threshold: 0.1,
|
|
50
|
+
keys: [
|
|
51
|
+
{ name: "name", weight: 1 },
|
|
52
|
+
{ name: "npm", weight: 1 },
|
|
53
|
+
{ name: "repo", weight: 1 },
|
|
54
|
+
{ name: "tags", weight: 1 },
|
|
55
|
+
{ name: "category", weight: 1 },
|
|
56
|
+
{ name: "description", weight: 0.5 },
|
|
57
|
+
{ name: "maintainers.name", weight: 0.5 },
|
|
58
|
+
{ name: "maintainers.github", weight: 0.5 }
|
|
59
|
+
]
|
|
60
|
+
});
|
|
61
|
+
const { bold, green, magenta, cyan, gray, yellow } = colors;
|
|
62
|
+
const results = fuse.search(query).map((result) => {
|
|
63
|
+
const res = {
|
|
64
|
+
name: bold(result.item.name),
|
|
65
|
+
homepage: cyan(result.item.website),
|
|
66
|
+
compatibility: `nuxt: ${result.item.compatibility?.nuxt || "*"}`,
|
|
67
|
+
repository: gray(result.item.github),
|
|
68
|
+
description: gray(result.item.description),
|
|
69
|
+
package: gray(result.item.npm),
|
|
70
|
+
install: cyan(`npx nuxi module add ${result.item.name}`),
|
|
71
|
+
stars: yellow(formatNumber(result.item.stats.stars)),
|
|
72
|
+
monthlyDownloads: yellow(formatNumber(result.item.stats.downloads))
|
|
73
|
+
};
|
|
74
|
+
if (result.item.github === result.item.website) {
|
|
75
|
+
delete res.homepage;
|
|
76
|
+
}
|
|
77
|
+
if (result.item.name === result.item.npm) {
|
|
78
|
+
delete res.packageName;
|
|
79
|
+
}
|
|
80
|
+
return res;
|
|
81
|
+
});
|
|
82
|
+
if (!results.length) {
|
|
83
|
+
logger.info(
|
|
84
|
+
`No Nuxt modules found matching query ${magenta(query)} for Nuxt ${cyan(nuxtVersion)}`
|
|
85
|
+
);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
logger.success(
|
|
89
|
+
`Found ${results.length} Nuxt ${results.length > 1 ? "modules" : "module"} matching ${cyan(query)} ${nuxtVersion ? `for Nuxt ${cyan(nuxtVersion)}` : ""}:
|
|
90
|
+
`
|
|
91
|
+
);
|
|
92
|
+
for (const foundModule of results) {
|
|
93
|
+
let maxLength = 0;
|
|
94
|
+
const entries = Object.entries(foundModule).map(([key, val]) => {
|
|
95
|
+
const label = upperFirst(kebabCase(key)).replace(/-/g, " ");
|
|
96
|
+
if (label.length > maxLength) {
|
|
97
|
+
maxLength = label.length;
|
|
98
|
+
}
|
|
99
|
+
return [label, val || "-"];
|
|
100
|
+
});
|
|
101
|
+
let infoStr = "";
|
|
102
|
+
for (const [label, value] of entries) {
|
|
103
|
+
infoStr += `${bold(label === "Install" ? "\u2192 " : "- ") + green(label.padEnd(maxLength + 2)) + value}
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
logger.log(infoStr);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { search as default };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { defineCommand } from 'citty';
|
|
3
|
+
import { resolve } from 'pathe';
|
|
4
|
+
import { c as cwdArgs, l as logLevelArgs, b as legacyRootDirArgs, a as logger } from '../shared/cli-nightly.CnY_9Zvw.mjs';
|
|
5
|
+
import 'node:path';
|
|
6
|
+
import 'std-env';
|
|
7
|
+
import 'consola';
|
|
8
|
+
import 'node:url';
|
|
9
|
+
|
|
10
|
+
const test = defineCommand({
|
|
11
|
+
meta: {
|
|
12
|
+
name: "test",
|
|
13
|
+
description: "Run tests"
|
|
14
|
+
},
|
|
15
|
+
args: {
|
|
16
|
+
...cwdArgs,
|
|
17
|
+
...logLevelArgs,
|
|
18
|
+
...legacyRootDirArgs,
|
|
19
|
+
dev: {
|
|
20
|
+
type: "boolean",
|
|
21
|
+
description: "Run in dev mode"
|
|
22
|
+
},
|
|
23
|
+
watch: {
|
|
24
|
+
type: "boolean",
|
|
25
|
+
description: "Watch mode"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
async run(ctx) {
|
|
29
|
+
process.env.NODE_ENV = process.env.NODE_ENV || "test";
|
|
30
|
+
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir);
|
|
31
|
+
const { runTests } = await importTestUtils();
|
|
32
|
+
await runTests({
|
|
33
|
+
rootDir: cwd,
|
|
34
|
+
dev: ctx.args.dev,
|
|
35
|
+
watch: ctx.args.watch,
|
|
36
|
+
...{}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
async function importTestUtils() {
|
|
41
|
+
let err;
|
|
42
|
+
for (const pkg of [
|
|
43
|
+
"@nuxt/test-utils-nightly",
|
|
44
|
+
"@nuxt/test-utils-edge",
|
|
45
|
+
"@nuxt/test-utils"
|
|
46
|
+
]) {
|
|
47
|
+
try {
|
|
48
|
+
const exports = await import(pkg);
|
|
49
|
+
if (!exports.runTests) {
|
|
50
|
+
throw new Error("Invalid version of `@nuxt/test-utils` is installed!");
|
|
51
|
+
}
|
|
52
|
+
return exports;
|
|
53
|
+
} catch (_err) {
|
|
54
|
+
err = _err;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
logger.error(err);
|
|
58
|
+
throw new Error("`@nuxt/test-utils` seems missing. Run `npm i -D @nuxt/test-utils` or `yarn add -D @nuxt/test-utils` to install.");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { test as default };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { defineCommand } from 'citty';
|
|
4
|
+
import { createJiti } from 'jiti';
|
|
5
|
+
import { resolve } from 'pathe';
|
|
6
|
+
import { isBun } from 'std-env';
|
|
7
|
+
import { x } from 'tinyexec';
|
|
8
|
+
import { l as loadKit } from '../shared/cli-nightly.DlcAx0De.mjs';
|
|
9
|
+
import { c as cwdArgs, l as logLevelArgs, b as legacyRootDirArgs } from '../shared/cli-nightly.CnY_9Zvw.mjs';
|
|
10
|
+
import 'node:path';
|
|
11
|
+
import 'consola';
|
|
12
|
+
|
|
13
|
+
const typecheck = defineCommand({
|
|
14
|
+
meta: {
|
|
15
|
+
name: "typecheck",
|
|
16
|
+
description: "Runs `vue-tsc` to check types throughout your app."
|
|
17
|
+
},
|
|
18
|
+
args: {
|
|
19
|
+
...cwdArgs,
|
|
20
|
+
...logLevelArgs,
|
|
21
|
+
...legacyRootDirArgs
|
|
22
|
+
},
|
|
23
|
+
async run(ctx) {
|
|
24
|
+
process.env.NODE_ENV = process.env.NODE_ENV || "production";
|
|
25
|
+
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir);
|
|
26
|
+
const { loadNuxt, buildNuxt, writeTypes } = await loadKit(cwd);
|
|
27
|
+
const nuxt = await loadNuxt({
|
|
28
|
+
cwd,
|
|
29
|
+
overrides: {
|
|
30
|
+
_prepare: true,
|
|
31
|
+
logLevel: ctx.args.logLevel
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
await writeTypes(nuxt);
|
|
35
|
+
await buildNuxt(nuxt);
|
|
36
|
+
await nuxt.close();
|
|
37
|
+
const jiti = createJiti(cwd);
|
|
38
|
+
const [resolvedTypeScript, resolvedVueTsc] = await Promise.all([
|
|
39
|
+
jiti.esmResolve("typescript", { try: true }),
|
|
40
|
+
jiti.esmResolve("vue-tsc/bin/vue-tsc.js", { try: true })
|
|
41
|
+
]);
|
|
42
|
+
if (resolvedTypeScript && resolvedVueTsc) {
|
|
43
|
+
await x(fileURLToPath(resolvedVueTsc), ["--noEmit"], {
|
|
44
|
+
nodeOptions: {
|
|
45
|
+
stdio: "inherit",
|
|
46
|
+
cwd
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
} else {
|
|
50
|
+
if (isBun) {
|
|
51
|
+
await x(
|
|
52
|
+
"bun",
|
|
53
|
+
"install typescript vue-tsc --global --silent".split(" "),
|
|
54
|
+
{ nodeOptions: { stdio: "inherit", cwd } }
|
|
55
|
+
);
|
|
56
|
+
await x("bunx", "vue-tsc --noEmit".split(" "), {
|
|
57
|
+
nodeOptions: {
|
|
58
|
+
stdio: "inherit",
|
|
59
|
+
cwd
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
await x(
|
|
64
|
+
"npx",
|
|
65
|
+
"-p vue-tsc -p typescript vue-tsc --noEmit".split(" "),
|
|
66
|
+
{ nodeOptions: { stdio: "inherit", cwd } }
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export { typecheck as default };
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { defineCommand } from 'citty';
|
|
4
|
+
import { colors } from 'consola/utils';
|
|
5
|
+
import { detectPackageManager, addDependency } from 'nypm';
|
|
6
|
+
import { resolve } from 'pathe';
|
|
7
|
+
import { readPackageJSON } from 'pkg-types';
|
|
8
|
+
import { r as rmRecursive, t as touchFile } from '../shared/cli-nightly.7lipAIIb.mjs';
|
|
9
|
+
import { l as loadKit } from '../shared/cli-nightly.DlcAx0De.mjs';
|
|
10
|
+
import { c as cwdArgs, l as logLevelArgs, b as legacyRootDirArgs, a as logger } from '../shared/cli-nightly.CnY_9Zvw.mjs';
|
|
11
|
+
import { c as cleanupNuxtDirs, n as nuxtVersionToGitIdentifier } from '../shared/cli-nightly.CPUttwQp.mjs';
|
|
12
|
+
import { g as getPackageManagerVersion } from '../shared/cli-nightly.BSm0_9Hr.mjs';
|
|
13
|
+
import 'jiti';
|
|
14
|
+
import 'node:path';
|
|
15
|
+
import 'std-env';
|
|
16
|
+
import 'consola';
|
|
17
|
+
import 'node:url';
|
|
18
|
+
import 'ohash';
|
|
19
|
+
import 'node:child_process';
|
|
20
|
+
|
|
21
|
+
async function getNuxtVersion(path) {
|
|
22
|
+
try {
|
|
23
|
+
const pkg = await readPackageJSON("nuxt", { url: path });
|
|
24
|
+
if (!pkg.version) {
|
|
25
|
+
logger.warn("Cannot find any installed Nuxt versions in ", path);
|
|
26
|
+
}
|
|
27
|
+
return pkg.version || null;
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function checkNuxtDependencyType(pkg) {
|
|
33
|
+
if (pkg.dependencies?.nuxt) {
|
|
34
|
+
return "dependencies";
|
|
35
|
+
}
|
|
36
|
+
if (pkg.devDependencies?.nuxt) {
|
|
37
|
+
return "devDependencies";
|
|
38
|
+
}
|
|
39
|
+
return "dependencies";
|
|
40
|
+
}
|
|
41
|
+
const nuxtVersionTags = {
|
|
42
|
+
"3.x": "3x",
|
|
43
|
+
"4.x": "latest"
|
|
44
|
+
};
|
|
45
|
+
async function getNightlyVersion(packageNames) {
|
|
46
|
+
const result = await logger.prompt(
|
|
47
|
+
"Which nightly Nuxt release channel do you want to install? (3.x or 4.x)",
|
|
48
|
+
{
|
|
49
|
+
type: "select",
|
|
50
|
+
options: ["3.x", "4.x"],
|
|
51
|
+
default: "3.x"
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
const nuxtVersion = typeof result === "string" ? result : "3.x";
|
|
55
|
+
const npmPackages = packageNames.map((p) => `${p}@npm:${p}-nightly@${nuxtVersionTags[nuxtVersion]}`);
|
|
56
|
+
return { npmPackages, nuxtVersion };
|
|
57
|
+
}
|
|
58
|
+
async function getRequiredNewVersion(packageNames, channel) {
|
|
59
|
+
if (channel === "nightly") {
|
|
60
|
+
return getNightlyVersion(packageNames);
|
|
61
|
+
}
|
|
62
|
+
return { npmPackages: packageNames.map((p) => `${p}@latest`), nuxtVersion: "3" };
|
|
63
|
+
}
|
|
64
|
+
const upgrade = defineCommand({
|
|
65
|
+
meta: {
|
|
66
|
+
name: "upgrade",
|
|
67
|
+
description: "Upgrade Nuxt"
|
|
68
|
+
},
|
|
69
|
+
args: {
|
|
70
|
+
...cwdArgs,
|
|
71
|
+
...logLevelArgs,
|
|
72
|
+
...legacyRootDirArgs,
|
|
73
|
+
force: {
|
|
74
|
+
type: "boolean",
|
|
75
|
+
alias: "f",
|
|
76
|
+
description: "Force upgrade to recreate lockfile and node_modules"
|
|
77
|
+
},
|
|
78
|
+
channel: {
|
|
79
|
+
type: "string",
|
|
80
|
+
alias: "ch",
|
|
81
|
+
default: "stable",
|
|
82
|
+
description: "Specify a channel to install from (nightly or stable)"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
async run(ctx) {
|
|
86
|
+
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir);
|
|
87
|
+
const packageManager = await detectPackageManager(cwd);
|
|
88
|
+
if (!packageManager) {
|
|
89
|
+
logger.error(
|
|
90
|
+
`Unable to determine the package manager used by this project.
|
|
91
|
+
|
|
92
|
+
No lock files found in \`${cwd}\`, and no \`packageManager\` field specified in \`package.json\`.
|
|
93
|
+
|
|
94
|
+
Please either add the \`packageManager\` field to \`package.json\` or execute the installation command for your package manager. For example, you can use \`pnpm i\`, \`npm i\`, \`bun i\`, or \`yarn i\`, and then try again.`
|
|
95
|
+
);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
const { name: packageManagerName, lockFile: lockFileCandidates } = packageManager;
|
|
99
|
+
const packageManagerVersion = getPackageManagerVersion(packageManagerName);
|
|
100
|
+
logger.info("Package manager:", packageManagerName, packageManagerVersion);
|
|
101
|
+
const currentVersion = await getNuxtVersion(cwd) || "[unknown]";
|
|
102
|
+
logger.info("Current Nuxt version:", currentVersion);
|
|
103
|
+
const pkg = await readPackageJSON(cwd).catch(() => null);
|
|
104
|
+
const nuxtDependencyType = pkg ? checkNuxtDependencyType(pkg) : "dependencies";
|
|
105
|
+
const corePackages = ["@nuxt/kit", "@nuxt/schema", "@nuxt/vite-builder", "@nuxt/webpack-builder", "@nuxt/rspack-builder"];
|
|
106
|
+
const packagesToUpdate = pkg ? corePackages.filter((p) => pkg.dependencies?.[p] || pkg.devDependencies?.[p]) : [];
|
|
107
|
+
const { npmPackages, nuxtVersion } = await getRequiredNewVersion(["nuxt", ...packagesToUpdate], ctx.args.channel);
|
|
108
|
+
const toRemove = ["node_modules"];
|
|
109
|
+
const lockFile = normaliseLockFile(cwd, lockFileCandidates);
|
|
110
|
+
if (lockFile) {
|
|
111
|
+
toRemove.push(lockFile);
|
|
112
|
+
}
|
|
113
|
+
const forceRemovals = toRemove.map((p) => colors.cyan(p)).join(" and ");
|
|
114
|
+
if (ctx.args.force === undefined) {
|
|
115
|
+
ctx.args.force = await logger.prompt(
|
|
116
|
+
`Would you like to recreate ${forceRemovals} to fix problems with hoisted dependency versions and ensure you have the most up-to-date dependencies?`,
|
|
117
|
+
{
|
|
118
|
+
type: "confirm",
|
|
119
|
+
default: true
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
if (ctx.args.force) {
|
|
124
|
+
logger.info(
|
|
125
|
+
`Recreating ${forceRemovals}. If you encounter any issues, revert the changes and try with \`--no-force\``
|
|
126
|
+
);
|
|
127
|
+
await rmRecursive(toRemove.map((file) => resolve(cwd, file)));
|
|
128
|
+
if (lockFile) {
|
|
129
|
+
await touchFile(resolve(cwd, lockFile));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const versionType = ctx.args.channel === "nightly" ? "nightly" : "latest stable";
|
|
133
|
+
logger.info(`Installing ${versionType} Nuxt ${nuxtVersion} release...`);
|
|
134
|
+
await addDependency(npmPackages, {
|
|
135
|
+
cwd,
|
|
136
|
+
packageManager,
|
|
137
|
+
dev: nuxtDependencyType === "devDependencies"
|
|
138
|
+
});
|
|
139
|
+
let buildDir = ".nuxt";
|
|
140
|
+
try {
|
|
141
|
+
const { loadNuxtConfig } = await loadKit(cwd);
|
|
142
|
+
const nuxtOptions = await loadNuxtConfig({ cwd });
|
|
143
|
+
buildDir = nuxtOptions.buildDir;
|
|
144
|
+
} catch {
|
|
145
|
+
}
|
|
146
|
+
await cleanupNuxtDirs(cwd, buildDir);
|
|
147
|
+
const upgradedVersion = await getNuxtVersion(cwd) || "[unknown]";
|
|
148
|
+
logger.info("Upgraded Nuxt version:", upgradedVersion);
|
|
149
|
+
if (upgradedVersion === "[unknown]") {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (upgradedVersion === currentVersion) {
|
|
153
|
+
logger.success("You're already using the latest version of Nuxt.");
|
|
154
|
+
} else {
|
|
155
|
+
logger.success(
|
|
156
|
+
"Successfully upgraded Nuxt from",
|
|
157
|
+
currentVersion,
|
|
158
|
+
"to",
|
|
159
|
+
upgradedVersion
|
|
160
|
+
);
|
|
161
|
+
if (currentVersion === "[unknown]") {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const commitA = nuxtVersionToGitIdentifier(currentVersion);
|
|
165
|
+
const commitB = nuxtVersionToGitIdentifier(upgradedVersion);
|
|
166
|
+
if (commitA && commitB) {
|
|
167
|
+
logger.info(
|
|
168
|
+
"Changelog:",
|
|
169
|
+
`https://github.com/nuxt/nuxt/compare/${commitA}...${commitB}`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
function normaliseLockFile(cwd, lockFiles) {
|
|
176
|
+
if (typeof lockFiles === "string") {
|
|
177
|
+
lockFiles = [lockFiles];
|
|
178
|
+
}
|
|
179
|
+
const lockFile = lockFiles?.find((file) => existsSync(resolve(cwd, file)));
|
|
180
|
+
if (lockFile === undefined) {
|
|
181
|
+
logger.error(`Unable to find any lock files in ${cwd}`);
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
return lockFile;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export { upgrade as default };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as citty from 'citty';
|
|
2
|
+
|
|
3
|
+
declare const main: citty.CommandDef<{
|
|
4
|
+
command: {
|
|
5
|
+
type: "positional";
|
|
6
|
+
required: false;
|
|
7
|
+
};
|
|
8
|
+
cwd: {
|
|
9
|
+
readonly type: "string";
|
|
10
|
+
readonly description: "Specify the working directory";
|
|
11
|
+
readonly valueHint: "directory";
|
|
12
|
+
readonly default: ".";
|
|
13
|
+
};
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
declare const runMain: () => Promise<void>;
|
|
17
|
+
declare function runCommand(name: string, argv?: string[], data?: {
|
|
18
|
+
overrides?: Record<string, any>;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
result: unknown;
|
|
21
|
+
}>;
|
|
22
|
+
|
|
23
|
+
export { main, runCommand, runMain };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as citty from 'citty';
|
|
2
|
+
|
|
3
|
+
declare const main: citty.CommandDef<{
|
|
4
|
+
command: {
|
|
5
|
+
type: "positional";
|
|
6
|
+
required: false;
|
|
7
|
+
};
|
|
8
|
+
cwd: {
|
|
9
|
+
readonly type: "string";
|
|
10
|
+
readonly description: "Specify the working directory";
|
|
11
|
+
readonly valueHint: "directory";
|
|
12
|
+
readonly default: ".";
|
|
13
|
+
};
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
declare const runMain: () => Promise<void>;
|
|
17
|
+
declare function runCommand(name: string, argv?: string[], data?: {
|
|
18
|
+
overrides?: Record<string, any>;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
result: unknown;
|
|
21
|
+
}>;
|
|
22
|
+
|
|
23
|
+
export { main, runCommand, runMain };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { promises, existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'pathe';
|
|
3
|
+
import { a as logger } from './cli-nightly.CnY_9Zvw.mjs';
|
|
4
|
+
|
|
5
|
+
async function exists(path) {
|
|
6
|
+
try {
|
|
7
|
+
await promises.access(path);
|
|
8
|
+
return true;
|
|
9
|
+
} catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async function clearDir(path, exclude) {
|
|
14
|
+
if (!exclude) {
|
|
15
|
+
await promises.rm(path, { recursive: true, force: true });
|
|
16
|
+
} else if (existsSync(path)) {
|
|
17
|
+
const files = await promises.readdir(path);
|
|
18
|
+
await Promise.all(
|
|
19
|
+
files.map(async (name) => {
|
|
20
|
+
if (!exclude.includes(name)) {
|
|
21
|
+
await promises.rm(join(path, name), { recursive: true, force: true });
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
await promises.mkdir(path, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
function clearBuildDir(path) {
|
|
29
|
+
return clearDir(path, ["cache", "analyze"]);
|
|
30
|
+
}
|
|
31
|
+
async function rmRecursive(paths) {
|
|
32
|
+
await Promise.all(
|
|
33
|
+
paths.filter((p) => typeof p === "string").map(async (path) => {
|
|
34
|
+
logger.debug("Removing recursive path", path);
|
|
35
|
+
await promises.rm(path, { recursive: true, force: true }).catch(() => {
|
|
36
|
+
});
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
async function touchFile(path) {
|
|
41
|
+
if (await exists(path)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
await promises.writeFile(path, "").catch(() => {
|
|
45
|
+
logger.error(`Failed to create file: ${path}`);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { clearBuildDir as a, clearDir as c, rmRecursive as r, touchFile as t };
|