vite-hub 0.0.2 → 0.0.3
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/README.md +2 -3
- package/dist/index.d.ts +9 -1
- package/dist/index.js +1 -1121
- package/dist/nuxt.d.ts +18 -0
- package/dist/nuxt.js +83 -0
- package/dist/src-o6zB-soj.js +1135 -0
- package/package.json +24 -28
- package/dist/agent/harness/claude-code.d.ts +0 -1
- package/dist/agent/harness/claude-code.js +0 -2
- package/dist/agent/harness/codex.d.ts +0 -1
- package/dist/agent/harness/codex.js +0 -2
- package/dist/box/cloudflare.d.ts +0 -1
- package/dist/box/cloudflare.js +0 -2
- package/dist/box/crabbox.d.ts +0 -1
- package/dist/box/crabbox.js +0 -2
- package/dist/box/vercel.d.ts +0 -1
- package/dist/box/vercel.js +0 -2
package/dist/nuxt.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { vitehub } from "./index.js";
|
|
2
|
+
import { UserConfig } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/nuxt.d.ts
|
|
5
|
+
type NuxtLike = {
|
|
6
|
+
hook?: (name: "nitro:config", callback: (config: Record<string, unknown>) => Promise<void>) => void;
|
|
7
|
+
options: {
|
|
8
|
+
alias?: Record<string, string>;
|
|
9
|
+
dev?: boolean;
|
|
10
|
+
rootDir?: string;
|
|
11
|
+
serverDir?: string;
|
|
12
|
+
srcDir?: string;
|
|
13
|
+
vite?: UserConfig;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
declare function viteHubNuxtModule(options: Parameters<typeof vitehub>[0], nuxt?: NuxtLike): Promise<void>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { viteHubNuxtModule as default };
|
package/dist/nuxt.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { n as VITEHUB_NITRO_CONFIG_CONTEXT, r as VITEHUB_SERVER_DIRS, t as vitehub } from "./src-o6zB-soj.js";
|
|
2
|
+
import { hubDb } from "@vite-hub/database/nuxt";
|
|
3
|
+
import { mergeConfig } from "vite";
|
|
4
|
+
//#region src/nuxt.ts
|
|
5
|
+
function flattenPlugins(options) {
|
|
6
|
+
const plugins = [];
|
|
7
|
+
for (const option of options) if (Array.isArray(option)) plugins.push(...flattenPlugins(option));
|
|
8
|
+
else if (option && typeof option === "object" && "name" in option) plugins.push(option);
|
|
9
|
+
return plugins;
|
|
10
|
+
}
|
|
11
|
+
function configHandler(plugin) {
|
|
12
|
+
if (typeof plugin.config === "function") return plugin.config;
|
|
13
|
+
return plugin.config?.handler;
|
|
14
|
+
}
|
|
15
|
+
function queueNitroConfigHandler(plugin) {
|
|
16
|
+
return plugin.vitehub?.queue?.createNitroConfig;
|
|
17
|
+
}
|
|
18
|
+
function withoutDeploymentOutput(options) {
|
|
19
|
+
return options.flatMap((option) => {
|
|
20
|
+
if (Array.isArray(option)) return [withoutDeploymentOutput(option)];
|
|
21
|
+
if (option && typeof option === "object" && "name" in option && option.name === "vite-hub/deployment-output") return [];
|
|
22
|
+
return [option];
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async function applyNitroConfig(plugins, nitroConfig, nuxt) {
|
|
26
|
+
const environment = {
|
|
27
|
+
command: nuxt.options.dev ? "serve" : "build",
|
|
28
|
+
isPreview: false,
|
|
29
|
+
isSsrBuild: true,
|
|
30
|
+
mode: nuxt.options.dev ? "development" : "production"
|
|
31
|
+
};
|
|
32
|
+
const serverDirs = nuxt.options.serverDir ? [nuxt.options.serverDir] : void 0;
|
|
33
|
+
let config = mergeConfig({
|
|
34
|
+
resolve: { alias: nuxt.options.alias },
|
|
35
|
+
root: nuxt.options.srcDir || nuxt.options.rootDir || process.cwd()
|
|
36
|
+
}, nuxt.options.vite ?? {});
|
|
37
|
+
config[VITEHUB_NITRO_CONFIG_CONTEXT] = true;
|
|
38
|
+
if (serverDirs) config[VITEHUB_SERVER_DIRS] = serverDirs;
|
|
39
|
+
config.build ??= {};
|
|
40
|
+
config.nitro = nitroConfig;
|
|
41
|
+
config.server ??= {};
|
|
42
|
+
for (const plugin of plugins) {
|
|
43
|
+
const handler = configHandler(plugin);
|
|
44
|
+
if (handler) {
|
|
45
|
+
const result = await handler.call({}, config, environment);
|
|
46
|
+
if (result) {
|
|
47
|
+
const { nitro, ...viteConfig } = result;
|
|
48
|
+
config = mergeConfig(config, viteConfig);
|
|
49
|
+
if (nitro) config.nitro = nitro;
|
|
50
|
+
config[VITEHUB_NITRO_CONFIG_CONTEXT] = true;
|
|
51
|
+
if (serverDirs) config[VITEHUB_SERVER_DIRS] = serverDirs;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const createQueueNitroConfig = queueNitroConfigHandler(plugin);
|
|
55
|
+
if (createQueueNitroConfig) {
|
|
56
|
+
const projectRoot = nuxt.options.rootDir || process.cwd();
|
|
57
|
+
config.nitro = await createQueueNitroConfig({
|
|
58
|
+
nitro: config.nitro || {},
|
|
59
|
+
projectRoot,
|
|
60
|
+
root: nuxt.options.srcDir || projectRoot,
|
|
61
|
+
serverDirs: nuxt.options.serverDir ? [nuxt.options.serverDir] : void 0
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (config.nitro) Object.assign(nitroConfig, config.nitro);
|
|
66
|
+
}
|
|
67
|
+
async function viteHubNuxtModule(options, nuxt) {
|
|
68
|
+
if (!nuxt) return;
|
|
69
|
+
const plugins = flattenPlugins(vitehub(options)).filter((plugin) => plugin.name !== "vite-hub/deployment-output");
|
|
70
|
+
const existing = withoutDeploymentOutput(Array.isArray(nuxt.options.vite?.plugins) ? nuxt.options.vite.plugins : []);
|
|
71
|
+
const existingNames = new Set(flattenPlugins(existing).map((plugin) => plugin.name).filter(Boolean));
|
|
72
|
+
const existingPluginsByName = new Map(flattenPlugins(existing).filter((plugin) => plugin.name).map((plugin) => [plugin.name, plugin]));
|
|
73
|
+
const installedPlugins = [...plugins.map((plugin) => existingPluginsByName.get(plugin.name) || plugin), ...flattenPlugins(existing).filter((plugin) => (plugin.name.startsWith("@vite-hub/") || plugin.name.startsWith("vite-hub/")) && !plugins.some((candidate) => candidate.name === plugin.name))];
|
|
74
|
+
nuxt.options.vite ??= {};
|
|
75
|
+
const viteConfig = nuxt.options.vite;
|
|
76
|
+
viteConfig[VITEHUB_NITRO_CONFIG_CONTEXT] = true;
|
|
77
|
+
if (nuxt.options.serverDir) viteConfig[VITEHUB_SERVER_DIRS] = [nuxt.options.serverDir];
|
|
78
|
+
nuxt.options.vite.plugins = [...plugins.filter((plugin) => !existingNames.has(plugin.name)), ...existing];
|
|
79
|
+
nuxt.hook?.("nitro:config", (config) => applyNitroConfig(installedPlugins, config, nuxt));
|
|
80
|
+
if (options.database) await hubDb(options.database === true ? {} : options.database)(void 0, nuxt);
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { viteHubNuxtModule as default };
|