@dword-design/nuxt-custom-cli 2.0.4 → 2.0.5
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/module.d.ts +1 -0
- package/dist/module.js +9 -2
- package/package.json +1 -1
package/dist/module.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare const CUSTOM_CLI_ERROR_MESSAGE = "Default export from server/cli.ts must be wrapped with defineCustomCli(...).";
|
|
2
|
+
export declare const PROD_NITRO_PATCH_ERROR_MESSAGE = "Failed to patch Nitro server startup code. Nuxt internals may have changed and nuxt-custom-cli needs an update.";
|
|
2
3
|
declare const _default: import("@nuxt/schema").NuxtModule<import("@nuxt/schema").ModuleOptions, import("@nuxt/schema").ModuleOptions, false>;
|
|
3
4
|
export default _default;
|
package/dist/module.js
CHANGED
|
@@ -2,6 +2,7 @@ import pathLib from "node:path";
|
|
|
2
2
|
import { addServerImports, addServerPlugin, addTemplate, defineNuxtModule } from "@nuxt/kit";
|
|
3
3
|
import endent from "endent";
|
|
4
4
|
export const CUSTOM_CLI_ERROR_MESSAGE = "Default export from server/cli.ts must be wrapped with defineCustomCli(...).";
|
|
5
|
+
export const PROD_NITRO_PATCH_ERROR_MESSAGE = "Failed to patch Nitro server startup code. Nuxt internals may have changed and nuxt-custom-cli needs an update.";
|
|
5
6
|
const DEFINE_WRAPPER_USED_MARKER = "__defineCustomCliUsed";
|
|
6
7
|
const TEMPLATE_FOLDER = "custom-cli";
|
|
7
8
|
export default defineNuxtModule({
|
|
@@ -112,8 +113,14 @@ export default defineNuxtModule({
|
|
|
112
113
|
if (!chunk.fileName.endsWith("/nitro/nitro.mjs")) {
|
|
113
114
|
return null;
|
|
114
115
|
}
|
|
115
|
-
const
|
|
116
|
-
|
|
116
|
+
const listenSnippet = "const listener = server.listen(path ? { path } : { port, host }, (err) => {";
|
|
117
|
+
const shutdownSnippet = "setupGracefulShutdown(listener, nitroApp);";
|
|
118
|
+
const listenReplacement = "const isCliEntry = (process.argv[1] || '').replaceAll('\\\\', '/').endsWith('/cli.mjs');\nconst listener = isCliEntry ? null : server.listen(path ? { path } : { port, host }, (err) => {";
|
|
119
|
+
const shutdownReplacement = "if (listener) {\n setupGracefulShutdown(listener, nitroApp);\n}";
|
|
120
|
+
if (!code.includes(listenSnippet) || !code.includes(shutdownSnippet)) {
|
|
121
|
+
throw new Error(PROD_NITRO_PATCH_ERROR_MESSAGE);
|
|
122
|
+
}
|
|
123
|
+
return code.replace(listenSnippet, listenReplacement).replace(shutdownSnippet, shutdownReplacement);
|
|
117
124
|
}
|
|
118
125
|
};
|
|
119
126
|
rollupConfig.plugins = Array.isArray(rollupConfig.plugins) ? [...rollupConfig.plugins, noListenPlugin] : rollupConfig.plugins ? [rollupConfig.plugins, noListenPlugin] : [noListenPlugin];
|