@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,134 @@
|
|
|
1
|
+
import { promises } from 'node:fs';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { defineCommand } from 'citty';
|
|
4
|
+
import { defu } from 'defu';
|
|
5
|
+
import { createApp, eventHandler, toNodeListener, lazyEventHandler } from 'h3';
|
|
6
|
+
import { listen } from 'listhen';
|
|
7
|
+
import { resolve, join } from 'pathe';
|
|
8
|
+
import { o as overrideEnv } from '../shared/cli-nightly.cDY7IcTr.mjs';
|
|
9
|
+
import { c as clearDir } from '../shared/cli-nightly.7lipAIIb.mjs';
|
|
10
|
+
import { l as loadKit } from '../shared/cli-nightly.DlcAx0De.mjs';
|
|
11
|
+
import { c as cwdArgs, l as logLevelArgs, b as legacyRootDirArgs, d as dotEnvArgs, a as logger } from '../shared/cli-nightly.CnY_9Zvw.mjs';
|
|
12
|
+
import 'jiti';
|
|
13
|
+
import 'node:path';
|
|
14
|
+
import 'std-env';
|
|
15
|
+
import 'consola';
|
|
16
|
+
import 'node:url';
|
|
17
|
+
|
|
18
|
+
const analyze = defineCommand({
|
|
19
|
+
meta: {
|
|
20
|
+
name: "analyze",
|
|
21
|
+
description: "Build nuxt and analyze production bundle (experimental)"
|
|
22
|
+
},
|
|
23
|
+
args: {
|
|
24
|
+
...cwdArgs,
|
|
25
|
+
...logLevelArgs,
|
|
26
|
+
...legacyRootDirArgs,
|
|
27
|
+
...dotEnvArgs,
|
|
28
|
+
name: {
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "Name of the analysis",
|
|
31
|
+
default: "default"
|
|
32
|
+
},
|
|
33
|
+
serve: {
|
|
34
|
+
type: "boolean",
|
|
35
|
+
description: "Serve the analysis results",
|
|
36
|
+
default: true
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
async run(ctx) {
|
|
40
|
+
overrideEnv("production");
|
|
41
|
+
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir);
|
|
42
|
+
const name = ctx.args.name || "default";
|
|
43
|
+
const slug = name.trim().replace(/[^\w-]/g, "_");
|
|
44
|
+
const startTime = Date.now();
|
|
45
|
+
const { loadNuxt, buildNuxt } = await loadKit(cwd);
|
|
46
|
+
const nuxt = await loadNuxt({
|
|
47
|
+
cwd,
|
|
48
|
+
dotenv: {
|
|
49
|
+
cwd,
|
|
50
|
+
fileName: ctx.args.dotenv
|
|
51
|
+
},
|
|
52
|
+
overrides: defu(ctx.data?.overrides, {
|
|
53
|
+
build: {
|
|
54
|
+
analyze: {
|
|
55
|
+
enabled: true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
vite: {
|
|
59
|
+
build: {
|
|
60
|
+
rollupOptions: {
|
|
61
|
+
output: {
|
|
62
|
+
chunkFileNames: "_nuxt/[name].js",
|
|
63
|
+
entryFileNames: "_nuxt/[name].js"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
logLevel: ctx.args.logLevel
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
const analyzeDir = nuxt.options.analyzeDir;
|
|
72
|
+
const buildDir = nuxt.options.buildDir;
|
|
73
|
+
const outDir = nuxt.options.nitro.output?.dir || join(nuxt.options.rootDir, ".output");
|
|
74
|
+
nuxt.options.build.analyze = defu(nuxt.options.build.analyze, {
|
|
75
|
+
filename: join(analyzeDir, "client.html")
|
|
76
|
+
});
|
|
77
|
+
await clearDir(analyzeDir);
|
|
78
|
+
await buildNuxt(nuxt);
|
|
79
|
+
const endTime = Date.now();
|
|
80
|
+
const meta = {
|
|
81
|
+
name,
|
|
82
|
+
slug,
|
|
83
|
+
startTime,
|
|
84
|
+
endTime,
|
|
85
|
+
analyzeDir,
|
|
86
|
+
buildDir,
|
|
87
|
+
outDir
|
|
88
|
+
};
|
|
89
|
+
await nuxt.callHook("build:analyze:done", meta);
|
|
90
|
+
await promises.writeFile(
|
|
91
|
+
join(analyzeDir, "meta.json"),
|
|
92
|
+
JSON.stringify(meta, null, 2),
|
|
93
|
+
"utf-8"
|
|
94
|
+
);
|
|
95
|
+
logger.info(`Analyze results are available at: \`${analyzeDir}\``);
|
|
96
|
+
logger.warn("Do not deploy analyze results! Use `nuxi build` before deploying.");
|
|
97
|
+
if (ctx.args.serve !== false && !process.env.CI) {
|
|
98
|
+
const app = createApp();
|
|
99
|
+
const serveFile = (filePath) => lazyEventHandler(async () => {
|
|
100
|
+
const contents = await promises.readFile(filePath, "utf-8");
|
|
101
|
+
return eventHandler((event) => {
|
|
102
|
+
event.node.res.end(contents);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
logger.info("Starting stats server...");
|
|
106
|
+
app.use("/client", serveFile(join(analyzeDir, "client.html")));
|
|
107
|
+
app.use("/nitro", serveFile(join(analyzeDir, "nitro.html")));
|
|
108
|
+
app.use(
|
|
109
|
+
eventHandler(
|
|
110
|
+
() => `<!DOCTYPE html>
|
|
111
|
+
<html lang="en">
|
|
112
|
+
<head>
|
|
113
|
+
<meta charset="utf-8">
|
|
114
|
+
<title>Nuxt Bundle Stats (experimental)</title>
|
|
115
|
+
</head>
|
|
116
|
+
<h1>Nuxt Bundle Stats (experimental)</h1>
|
|
117
|
+
<ul>
|
|
118
|
+
<li>
|
|
119
|
+
<a href="/nitro">Nitro server bundle stats</a>
|
|
120
|
+
</li>
|
|
121
|
+
<li>
|
|
122
|
+
<a href="/client">Client bundle stats</a>
|
|
123
|
+
</li>
|
|
124
|
+
</ul>
|
|
125
|
+
</html>
|
|
126
|
+
`
|
|
127
|
+
)
|
|
128
|
+
);
|
|
129
|
+
await listen(toNodeListener(app));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
export { analyze as default };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { defineCommand } from 'citty';
|
|
3
|
+
import { resolve, relative } from 'pathe';
|
|
4
|
+
import { s as showVersions } from '../shared/cli-nightly.CGRrR0sp.mjs';
|
|
5
|
+
import { o as overrideEnv } from '../shared/cli-nightly.cDY7IcTr.mjs';
|
|
6
|
+
import { a as clearBuildDir } from '../shared/cli-nightly.7lipAIIb.mjs';
|
|
7
|
+
import { l as loadKit } from '../shared/cli-nightly.DlcAx0De.mjs';
|
|
8
|
+
import { c as cwdArgs, l as logLevelArgs, d as dotEnvArgs, e as envNameArgs, b as legacyRootDirArgs, a as logger } from '../shared/cli-nightly.CnY_9Zvw.mjs';
|
|
9
|
+
import 'consola/utils';
|
|
10
|
+
import 'pkg-types';
|
|
11
|
+
import 'node:fs';
|
|
12
|
+
import 'jiti';
|
|
13
|
+
import 'node:path';
|
|
14
|
+
import 'std-env';
|
|
15
|
+
import 'consola';
|
|
16
|
+
import 'node:url';
|
|
17
|
+
|
|
18
|
+
const buildCommand = defineCommand({
|
|
19
|
+
meta: {
|
|
20
|
+
name: "build",
|
|
21
|
+
description: "Build Nuxt for production deployment"
|
|
22
|
+
},
|
|
23
|
+
args: {
|
|
24
|
+
...cwdArgs,
|
|
25
|
+
...logLevelArgs,
|
|
26
|
+
prerender: {
|
|
27
|
+
type: "boolean",
|
|
28
|
+
description: "Build Nuxt and prerender static routes"
|
|
29
|
+
},
|
|
30
|
+
preset: {
|
|
31
|
+
type: "string",
|
|
32
|
+
description: "Nitro server preset"
|
|
33
|
+
},
|
|
34
|
+
...dotEnvArgs,
|
|
35
|
+
...envNameArgs,
|
|
36
|
+
...legacyRootDirArgs
|
|
37
|
+
},
|
|
38
|
+
async run(ctx) {
|
|
39
|
+
overrideEnv("production");
|
|
40
|
+
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir);
|
|
41
|
+
await showVersions(cwd);
|
|
42
|
+
const kit = await loadKit(cwd);
|
|
43
|
+
const nuxt = await kit.loadNuxt({
|
|
44
|
+
cwd,
|
|
45
|
+
dotenv: {
|
|
46
|
+
cwd,
|
|
47
|
+
fileName: ctx.args.dotenv
|
|
48
|
+
},
|
|
49
|
+
envName: ctx.args.envName,
|
|
50
|
+
// c12 will fall back to NODE_ENV
|
|
51
|
+
overrides: {
|
|
52
|
+
logLevel: ctx.args.logLevel,
|
|
53
|
+
// TODO: remove in 3.8
|
|
54
|
+
_generate: ctx.args.prerender,
|
|
55
|
+
nitro: {
|
|
56
|
+
static: ctx.args.prerender,
|
|
57
|
+
preset: ctx.args.preset || process.env.NITRO_PRESET || process.env.SERVER_PRESET
|
|
58
|
+
},
|
|
59
|
+
...ctx.data?.overrides
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
let nitro;
|
|
63
|
+
try {
|
|
64
|
+
nitro = kit.useNitro?.();
|
|
65
|
+
logger.info(`Building for Nitro preset: \`${nitro.options.preset}\``);
|
|
66
|
+
} catch {
|
|
67
|
+
}
|
|
68
|
+
await clearBuildDir(nuxt.options.buildDir);
|
|
69
|
+
await kit.writeTypes(nuxt);
|
|
70
|
+
nuxt.hook("build:error", (err) => {
|
|
71
|
+
logger.error("Nuxt Build Error:", err);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
});
|
|
74
|
+
await kit.buildNuxt(nuxt);
|
|
75
|
+
if (ctx.args.prerender) {
|
|
76
|
+
if (!nuxt.options.ssr) {
|
|
77
|
+
logger.warn(
|
|
78
|
+
"HTML content not prerendered because `ssr: false` was set. You can read more in `https://nuxt.com/docs/getting-started/deployment#static-hosting`."
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
const dir = nitro?.options.output.publicDir;
|
|
82
|
+
const publicDir = dir ? relative(process.cwd(), dir) : ".output/public";
|
|
83
|
+
logger.success(
|
|
84
|
+
`You can now deploy \`${publicDir}\` to any static hosting!`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export { buildCommand as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import { resolve } from 'pathe';
|
|
3
|
+
import { l as loadKit } from '../shared/cli-nightly.DlcAx0De.mjs';
|
|
4
|
+
import { c as cleanupNuxtDirs } from '../shared/cli-nightly.CPUttwQp.mjs';
|
|
5
|
+
import { c as cwdArgs, b as legacyRootDirArgs } from '../shared/cli-nightly.CnY_9Zvw.mjs';
|
|
6
|
+
import 'jiti';
|
|
7
|
+
import 'node:fs';
|
|
8
|
+
import 'ohash';
|
|
9
|
+
import '../shared/cli-nightly.7lipAIIb.mjs';
|
|
10
|
+
import 'node:path';
|
|
11
|
+
import 'node:process';
|
|
12
|
+
import 'std-env';
|
|
13
|
+
import 'consola';
|
|
14
|
+
import 'node:url';
|
|
15
|
+
|
|
16
|
+
const cleanup = defineCommand({
|
|
17
|
+
meta: {
|
|
18
|
+
name: "cleanup",
|
|
19
|
+
description: "Clean up generated Nuxt files and caches"
|
|
20
|
+
},
|
|
21
|
+
args: {
|
|
22
|
+
...cwdArgs,
|
|
23
|
+
...legacyRootDirArgs
|
|
24
|
+
},
|
|
25
|
+
async run(ctx) {
|
|
26
|
+
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir);
|
|
27
|
+
const { loadNuxtConfig } = await loadKit(cwd);
|
|
28
|
+
const nuxtOptions = await loadNuxtConfig({ cwd, overrides: { dev: true } });
|
|
29
|
+
await cleanupNuxtDirs(nuxtOptions.rootDir, nuxtOptions.buildDir);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export { cleanup as default };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { defineCommand } from 'citty';
|
|
3
|
+
import { resolve } from 'pathe';
|
|
4
|
+
import { isTest } from 'std-env';
|
|
5
|
+
import { createNuxtDevServer } from './dev2.mjs';
|
|
6
|
+
import { o as overrideEnv } from '../shared/cli-nightly.cDY7IcTr.mjs';
|
|
7
|
+
import { c as cwdArgs, l as logLevelArgs, e as envNameArgs, b as legacyRootDirArgs, a as logger } from '../shared/cli-nightly.CnY_9Zvw.mjs';
|
|
8
|
+
import 'node:events';
|
|
9
|
+
import 'chokidar';
|
|
10
|
+
import 'h3';
|
|
11
|
+
import 'jiti';
|
|
12
|
+
import 'listhen';
|
|
13
|
+
import 'perfect-debounce';
|
|
14
|
+
import 'ufo';
|
|
15
|
+
import '../shared/cli-nightly.7lipAIIb.mjs';
|
|
16
|
+
import 'node:fs';
|
|
17
|
+
import '../shared/cli-nightly.DlcAx0De.mjs';
|
|
18
|
+
import '../shared/cli-nightly.CPUttwQp.mjs';
|
|
19
|
+
import 'ohash';
|
|
20
|
+
import 'node:path';
|
|
21
|
+
import 'consola';
|
|
22
|
+
import 'node:url';
|
|
23
|
+
|
|
24
|
+
const devChild = defineCommand({
|
|
25
|
+
meta: {
|
|
26
|
+
name: "_dev",
|
|
27
|
+
description: "Run Nuxt development server (internal command to start child process)"
|
|
28
|
+
},
|
|
29
|
+
args: {
|
|
30
|
+
...cwdArgs,
|
|
31
|
+
...logLevelArgs,
|
|
32
|
+
...envNameArgs,
|
|
33
|
+
...legacyRootDirArgs
|
|
34
|
+
},
|
|
35
|
+
async run(ctx) {
|
|
36
|
+
if (!process.send && !isTest) {
|
|
37
|
+
logger.warn(
|
|
38
|
+
"`nuxi _dev` is an internal command and should not be used directly. Please use `nuxi dev` instead."
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
overrideEnv("development");
|
|
42
|
+
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir);
|
|
43
|
+
const devContext = JSON.parse(process.env.__NUXT_DEV__ || "null") || {};
|
|
44
|
+
function sendIPCMessage(message) {
|
|
45
|
+
if (process.send) {
|
|
46
|
+
process.send(message);
|
|
47
|
+
} else {
|
|
48
|
+
logger.info(
|
|
49
|
+
"Dev server event:",
|
|
50
|
+
Object.entries(message).map((e) => `${e[0]}=${JSON.stringify(e[1])}`).join(" ")
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
process.once("unhandledRejection", (reason) => {
|
|
55
|
+
sendIPCMessage({ type: "nuxt:internal:dev:rejection", message: reason instanceof Error ? reason.toString() : "Unhandled Rejection" });
|
|
56
|
+
process.exit();
|
|
57
|
+
});
|
|
58
|
+
const nuxtDev = await createNuxtDevServer({
|
|
59
|
+
cwd,
|
|
60
|
+
overrides: ctx.data?.overrides,
|
|
61
|
+
logLevel: ctx.args.logLevel,
|
|
62
|
+
clear: !!ctx.args.clear,
|
|
63
|
+
dotenv: !!ctx.args.dotenv,
|
|
64
|
+
envName: ctx.args.envName,
|
|
65
|
+
port: process.env._PORT ?? undefined,
|
|
66
|
+
devContext
|
|
67
|
+
});
|
|
68
|
+
nuxtDev.on("loading", (message) => {
|
|
69
|
+
sendIPCMessage({ type: "nuxt:internal:dev:loading", message });
|
|
70
|
+
});
|
|
71
|
+
nuxtDev.on("restart", () => {
|
|
72
|
+
sendIPCMessage({ type: "nuxt:internal:dev:restart" });
|
|
73
|
+
});
|
|
74
|
+
nuxtDev.on("ready", (payload) => {
|
|
75
|
+
sendIPCMessage({ type: "nuxt:internal:dev:ready", port: payload.port });
|
|
76
|
+
});
|
|
77
|
+
await nuxtDev.init();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export { devChild as default };
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { fork } from 'node:child_process';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { setupDotenv } from 'c12';
|
|
4
|
+
import { defineCommand } from 'citty';
|
|
5
|
+
import { createJiti } from 'jiti';
|
|
6
|
+
import { getArgs, parseArgs } from 'listhen/cli';
|
|
7
|
+
import { resolve } from 'pathe';
|
|
8
|
+
import { isBun, isTest } from 'std-env';
|
|
9
|
+
import { s as showVersions } from '../shared/cli-nightly.CGRrR0sp.mjs';
|
|
10
|
+
import { o as overrideEnv } from '../shared/cli-nightly.cDY7IcTr.mjs';
|
|
11
|
+
import { l as loadKit } from '../shared/cli-nightly.DlcAx0De.mjs';
|
|
12
|
+
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';
|
|
13
|
+
import 'consola/utils';
|
|
14
|
+
import 'pkg-types';
|
|
15
|
+
import 'node:path';
|
|
16
|
+
import 'consola';
|
|
17
|
+
import 'node:url';
|
|
18
|
+
|
|
19
|
+
const forkSupported = !isBun && !isTest;
|
|
20
|
+
const command = defineCommand({
|
|
21
|
+
meta: {
|
|
22
|
+
name: "dev",
|
|
23
|
+
description: "Run Nuxt development server"
|
|
24
|
+
},
|
|
25
|
+
args: {
|
|
26
|
+
...cwdArgs,
|
|
27
|
+
...logLevelArgs,
|
|
28
|
+
...envNameArgs,
|
|
29
|
+
...legacyRootDirArgs,
|
|
30
|
+
...getArgs(),
|
|
31
|
+
...dotEnvArgs,
|
|
32
|
+
clear: {
|
|
33
|
+
type: "boolean",
|
|
34
|
+
description: "Clear console on restart"
|
|
35
|
+
},
|
|
36
|
+
fork: {
|
|
37
|
+
type: "boolean",
|
|
38
|
+
description: forkSupported ? "Disable forked mode" : "Enable forked mode",
|
|
39
|
+
default: forkSupported
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
async run(ctx) {
|
|
43
|
+
overrideEnv("development");
|
|
44
|
+
const cwd = resolve(ctx.args.cwd || ctx.args.rootDir);
|
|
45
|
+
await showVersions(cwd);
|
|
46
|
+
await setupDotenv({ cwd, fileName: ctx.args.dotenv });
|
|
47
|
+
const { loadNuxtConfig } = await loadKit(cwd);
|
|
48
|
+
const nuxtOptions = await loadNuxtConfig({
|
|
49
|
+
cwd,
|
|
50
|
+
envName: ctx.args.envName,
|
|
51
|
+
// c12 will fall back to NODE_ENV
|
|
52
|
+
overrides: {
|
|
53
|
+
dev: true,
|
|
54
|
+
logLevel: ctx.args.logLevel,
|
|
55
|
+
...ctx.data?.overrides
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const listenOptions = _resolveListenOptions(nuxtOptions, ctx.args);
|
|
59
|
+
if (ctx.args.fork) {
|
|
60
|
+
const devProxy = await _createDevProxy(nuxtOptions, listenOptions);
|
|
61
|
+
await _startSubprocess(devProxy, ctx.rawArgs);
|
|
62
|
+
return { listener: devProxy?.listener };
|
|
63
|
+
} else {
|
|
64
|
+
const { createNuxtDevServer } = await import('./dev2.mjs');
|
|
65
|
+
const devServer = await createNuxtDevServer(
|
|
66
|
+
{
|
|
67
|
+
cwd,
|
|
68
|
+
overrides: ctx.data?.overrides,
|
|
69
|
+
logLevel: ctx.args.logLevel,
|
|
70
|
+
clear: ctx.args.clear,
|
|
71
|
+
dotenv: !!ctx.args.dotenv,
|
|
72
|
+
envName: ctx.args.envName,
|
|
73
|
+
loadingTemplate: nuxtOptions.devServer.loadingTemplate,
|
|
74
|
+
devContext: {}
|
|
75
|
+
},
|
|
76
|
+
listenOptions
|
|
77
|
+
);
|
|
78
|
+
await devServer.init();
|
|
79
|
+
return { listener: devServer?.listener };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
async function _createDevProxy(nuxtOptions, listenOptions) {
|
|
84
|
+
const jiti = createJiti(nuxtOptions.rootDir);
|
|
85
|
+
let loadingMessage = "Nuxt dev server is starting...";
|
|
86
|
+
let loadingTemplate = nuxtOptions.devServer.loadingTemplate;
|
|
87
|
+
for (const url of nuxtOptions.modulesDir) {
|
|
88
|
+
if (loadingTemplate) {
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
loadingTemplate = await jiti.import("@nuxt/ui-templates", { parentURL: url }).then((r) => r.loading);
|
|
92
|
+
}
|
|
93
|
+
const { createProxyServer } = await import('httpxy');
|
|
94
|
+
const proxy = createProxyServer({});
|
|
95
|
+
let address;
|
|
96
|
+
const handler = (req, res) => {
|
|
97
|
+
if (!address) {
|
|
98
|
+
res.statusCode = 503;
|
|
99
|
+
res.setHeader("Content-Type", "text/html");
|
|
100
|
+
res.end(loadingTemplate({ loading: loadingMessage }));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
return proxy.web(req, res, { target: address });
|
|
104
|
+
};
|
|
105
|
+
const wsHandler = (req, socket, head) => {
|
|
106
|
+
if (!address) {
|
|
107
|
+
socket.destroy();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
return proxy.ws(req, socket, { target: address }, head);
|
|
111
|
+
};
|
|
112
|
+
const { listen } = await import('listhen');
|
|
113
|
+
const listener = await listen(handler, listenOptions);
|
|
114
|
+
listener.server.on("upgrade", wsHandler);
|
|
115
|
+
return {
|
|
116
|
+
listener,
|
|
117
|
+
handler,
|
|
118
|
+
wsHandler,
|
|
119
|
+
setAddress: (_addr) => {
|
|
120
|
+
address = _addr;
|
|
121
|
+
},
|
|
122
|
+
setLoadingMessage: (_msg) => {
|
|
123
|
+
loadingMessage = _msg;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async function _startSubprocess(devProxy, rawArgs) {
|
|
128
|
+
let childProc;
|
|
129
|
+
const kill = (signal) => {
|
|
130
|
+
if (childProc) {
|
|
131
|
+
childProc.kill(signal);
|
|
132
|
+
childProc = undefined;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const restart = async () => {
|
|
136
|
+
if (process.platform === "win32") {
|
|
137
|
+
kill("SIGTERM");
|
|
138
|
+
} else {
|
|
139
|
+
kill("SIGHUP");
|
|
140
|
+
}
|
|
141
|
+
childProc = fork(globalThis.__nuxt_cli__.entry, ["_dev", ...rawArgs], {
|
|
142
|
+
execArgv: [
|
|
143
|
+
"--enable-source-maps",
|
|
144
|
+
process.argv.find((a) => a.includes("--inspect"))
|
|
145
|
+
].filter(Boolean),
|
|
146
|
+
env: {
|
|
147
|
+
...process.env,
|
|
148
|
+
__NUXT_DEV__: JSON.stringify({
|
|
149
|
+
proxy: {
|
|
150
|
+
url: devProxy.listener.url,
|
|
151
|
+
urls: await devProxy.listener.getURLs(),
|
|
152
|
+
https: devProxy.listener.https
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
childProc.on("close", (errorCode) => {
|
|
158
|
+
if (errorCode) {
|
|
159
|
+
process.exit(errorCode);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
childProc.on("message", (message) => {
|
|
163
|
+
if (message.type === "nuxt:internal:dev:ready") {
|
|
164
|
+
devProxy.setAddress(`http://127.0.0.1:${message.port}`);
|
|
165
|
+
} else if (message.type === "nuxt:internal:dev:loading") {
|
|
166
|
+
devProxy.setAddress(undefined);
|
|
167
|
+
devProxy.setLoadingMessage(message.message);
|
|
168
|
+
} else if (message.type === "nuxt:internal:dev:restart") {
|
|
169
|
+
restart();
|
|
170
|
+
} else if (message.type === "nuxt:internal:dev:rejection") {
|
|
171
|
+
logger.withTag("nuxi").info(`Restarting Nuxt due to error: \`${message.message}\``);
|
|
172
|
+
restart();
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
for (const signal of [
|
|
177
|
+
"exit",
|
|
178
|
+
"SIGTERM",
|
|
179
|
+
"SIGINT",
|
|
180
|
+
"SIGQUIT"
|
|
181
|
+
]) {
|
|
182
|
+
process.once(signal, () => {
|
|
183
|
+
kill(signal === "exit" ? 0 : signal);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
await restart();
|
|
187
|
+
return {
|
|
188
|
+
restart,
|
|
189
|
+
kill
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function _resolveListenOptions(nuxtOptions, args) {
|
|
193
|
+
const _port = args.port ?? args.p ?? process.env.NUXT_PORT ?? process.env.NITRO_PORT ?? process.env.PORT ?? nuxtOptions.devServer.port;
|
|
194
|
+
const _hostname = typeof args.host === "string" ? args.host : (args.host === true ? "" : undefined) ?? process.env.NUXT_HOST ?? process.env.NITRO_HOST ?? process.env.HOST ?? nuxtOptions._layers?.[0]?.config?.devServer?.host ?? undefined;
|
|
195
|
+
const _public = args.public ?? (_hostname && !["localhost", "127.0.0.1", "::1"].includes(_hostname)) ? true : undefined;
|
|
196
|
+
const _httpsCert = args["https.cert"] || args.sslCert || process.env.NUXT_SSL_CERT || process.env.NITRO_SSL_CERT || typeof nuxtOptions.devServer.https !== "boolean" && nuxtOptions.devServer.https && "cert" in nuxtOptions.devServer.https && nuxtOptions.devServer.https.cert || "";
|
|
197
|
+
const _httpsKey = args["https.key"] || args.sslKey || process.env.NUXT_SSL_KEY || process.env.NITRO_SSL_KEY || typeof nuxtOptions.devServer.https !== "boolean" && nuxtOptions.devServer.https && "key" in nuxtOptions.devServer.https && nuxtOptions.devServer.https.key || "";
|
|
198
|
+
const _httpsPfx = args["https.pfx"] || typeof nuxtOptions.devServer.https !== "boolean" && nuxtOptions.devServer.https && "pfx" in nuxtOptions.devServer.https && nuxtOptions.devServer.https.pfx || "";
|
|
199
|
+
const _httpsPassphrase = args["https.passphrase"] || typeof nuxtOptions.devServer.https !== "boolean" && nuxtOptions.devServer.https && "passphrase" in nuxtOptions.devServer.https && nuxtOptions.devServer.https.passphrase || "";
|
|
200
|
+
const httpsEnabled = !!(args.https ?? nuxtOptions.devServer.https);
|
|
201
|
+
const _listhenOptions = parseArgs({
|
|
202
|
+
...args,
|
|
203
|
+
"open": args.o || args.open,
|
|
204
|
+
"https": httpsEnabled,
|
|
205
|
+
"https.cert": _httpsCert,
|
|
206
|
+
"https.key": _httpsKey,
|
|
207
|
+
"https.pfx": _httpsPfx,
|
|
208
|
+
"https.passphrase": _httpsPassphrase
|
|
209
|
+
});
|
|
210
|
+
const httpsOptions = httpsEnabled && {
|
|
211
|
+
...nuxtOptions.devServer.https,
|
|
212
|
+
..._listhenOptions.https
|
|
213
|
+
};
|
|
214
|
+
return {
|
|
215
|
+
..._listhenOptions,
|
|
216
|
+
port: _port,
|
|
217
|
+
hostname: _hostname,
|
|
218
|
+
public: _public,
|
|
219
|
+
https: httpsOptions,
|
|
220
|
+
baseURL: nuxtOptions.app.baseURL.startsWith("./") ? nuxtOptions.app.baseURL.slice(1) : nuxtOptions.app.baseURL
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export { command as default };
|