@vite-hub/codemods 0.5.0 → 0.5.1
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 +18 -8
- package/dist/{cli-main-aLhc0Eyq.js → cli-main-BPr3LL6y.js} +1153 -361
- package/dist/cli.js +2 -3
- package/dist/index.d.ts +14 -18
- package/dist/index.js +1 -2
- package/package.json +12 -12
|
@@ -9,12 +9,12 @@ import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
|
9
9
|
import { createJiti } from "jiti";
|
|
10
10
|
import { parse as parse$1 } from "@vue/compiler-sfc";
|
|
11
11
|
import { isMap, isScalar, isSeq, parseDocument, stringify } from "yaml";
|
|
12
|
-
import { intersects, subset, validRange } from "semver";
|
|
12
|
+
import { Range, intersects, lt, minVersion, parse as parse$2, satisfies, subset, validRange } from "semver";
|
|
13
13
|
import { camelCase, snakeCase } from "scule";
|
|
14
14
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
15
15
|
import { tmpdir } from "node:os";
|
|
16
16
|
import { createTwoFilesPatch } from "diff";
|
|
17
|
-
|
|
17
|
+
// ../internal/dist/invariant.js
|
|
18
18
|
const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
19
19
|
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
20
20
|
codes: { INTERNAL_INVARIANT_FAILED: {
|
|
@@ -33,8 +33,7 @@ function invariantError(what) {
|
|
|
33
33
|
function invariant(condition, what) {
|
|
34
34
|
if (!condition) throw invariantError(what);
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
//#region ../internal/dist/ast.js
|
|
36
|
+
// ../internal/dist/ast.js
|
|
38
37
|
/** Parses JavaScript or TypeScript. `jsx` adds JSX syntax. */
|
|
39
38
|
function parseProgram(code, options = {}) {
|
|
40
39
|
const plugins = [];
|
|
@@ -153,8 +152,7 @@ function quoteString(value, style) {
|
|
|
153
152
|
if (style.quote === "\"") return json;
|
|
154
153
|
return `'${json.slice(1, -1).replaceAll("\\\"", "\"").replaceAll("'", "\\'")}'`;
|
|
155
154
|
}
|
|
156
|
-
|
|
157
|
-
//#region src/shared/binding-resolver.ts
|
|
155
|
+
// src/shared/binding-resolver.ts
|
|
158
156
|
/** Resolve identifiers to declarations, including block bindings, parameters, and hoisted var declarations. */
|
|
159
157
|
function bindingResolver(program) {
|
|
160
158
|
const scopes = /* @__PURE__ */ new Map();
|
|
@@ -206,6 +204,10 @@ const codemodsErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
206
204
|
why: ({ problem }) => problem,
|
|
207
205
|
fix: "Change the file, the option, or the argument that the message names, then run the codemod again. Add `--dry-run` to see the edits before it writes them."
|
|
208
206
|
},
|
|
207
|
+
CODEMODS_NUXT_UNSUPPORTED: {
|
|
208
|
+
why: ({ codemods, nuxt, source }) => `${codemods.join(", ")} add${codemods.length === 1 ? "s" : ""} vite-hub/nuxt, which needs Nitro 3. Nitro 3 runs on Nuxt 4.7 with the nitro package, or on Nuxt 5. package.json requires nuxt "${nuxt}"${source}, which allows a Nuxt version before 4.7, so the build of the migrated app would fail. No file was written.`,
|
|
209
|
+
fix: "Upgrade to Nuxt 4.7 and add Nitro 3 with `pnpm add nuxt@^4.7.0 nitro`, then run the command again. Or run the command again with `--nuxt-nightly`: it sets `\"nuxt\": \"npm:nuxt-nightly@5x\"` in package.json and migrates the app."
|
|
210
|
+
},
|
|
209
211
|
CODEMODS_UNKNOWN: {
|
|
210
212
|
why: ({ available, name }) => `Unknown codemod "${name}". Available: ${available.join(", ")}.`,
|
|
211
213
|
fix: "Pass one of the codemod names that the message lists."
|
|
@@ -220,10 +222,9 @@ function codemodError(problem) {
|
|
|
220
222
|
function isCodemodError(error) {
|
|
221
223
|
if (!(error instanceof Error)) return false;
|
|
222
224
|
const code = Reflect.get(error, "code");
|
|
223
|
-
return code === "CODEMODS_BLOCKED" || code === "CODEMODS_UNKNOWN";
|
|
225
|
+
return code === "CODEMODS_BLOCKED" || code === "CODEMODS_NUXT_UNSUPPORTED" || code === "CODEMODS_UNKNOWN";
|
|
224
226
|
}
|
|
225
|
-
|
|
226
|
-
//#region src/shared/nuxt-config.ts
|
|
227
|
+
// src/shared/nuxt-config.ts
|
|
227
228
|
const configNames = [
|
|
228
229
|
"nuxt.config.ts",
|
|
229
230
|
"nuxt.config.mts",
|
|
@@ -366,8 +367,7 @@ function nitroPreset(config) {
|
|
|
366
367
|
property
|
|
367
368
|
};
|
|
368
369
|
}
|
|
369
|
-
|
|
370
|
-
//#region src/access-spellings/index.ts
|
|
370
|
+
// src/access-spellings/index.ts
|
|
371
371
|
/** The define functions whose options object changed its access key, by the modules that export them. */
|
|
372
372
|
const defines = new Map([["defineRealtime", {
|
|
373
373
|
kind: "realtime",
|
|
@@ -552,8 +552,7 @@ const accessSpellings = {
|
|
|
552
552
|
},
|
|
553
553
|
run: migrate$33
|
|
554
554
|
};
|
|
555
|
-
|
|
556
|
-
//#region src/shared/bindings.ts
|
|
555
|
+
// src/shared/bindings.ts
|
|
557
556
|
/** Collect declarations conservatively across the block, including nested patterns. */
|
|
558
557
|
function blockBindings(program) {
|
|
559
558
|
const bindings = /* @__PURE__ */ new Map();
|
|
@@ -577,8 +576,7 @@ function blockBindings(program) {
|
|
|
577
576
|
});
|
|
578
577
|
return bindings;
|
|
579
578
|
}
|
|
580
|
-
|
|
581
|
-
//#region src/shared/detect.ts
|
|
579
|
+
// src/shared/detect.ts
|
|
582
580
|
/** Names in `dependencies` and `devDependencies` of the project's package.json. */
|
|
583
581
|
async function readDependencies(cwd) {
|
|
584
582
|
const path = join(cwd, "package.json");
|
|
@@ -613,8 +611,7 @@ async function detectNuxtModule(cwd, moduleName, configKeys = []) {
|
|
|
613
611
|
}
|
|
614
612
|
if (dependencies.has(moduleName)) return { reason: `package.json depends on ${moduleName}` };
|
|
615
613
|
}
|
|
616
|
-
|
|
617
|
-
//#region src/agent-surface/index.ts
|
|
614
|
+
// src/agent-surface/index.ts
|
|
618
615
|
const roots = /* @__PURE__ */ new Set(["vite-hub/agent", "@vite-hub/agent"]);
|
|
619
616
|
/** Agent subpaths that merged into one entry. */
|
|
620
617
|
const movedSubpaths = /* @__PURE__ */ new Map([
|
|
@@ -1049,7 +1046,7 @@ function rewriteBlock$4(context) {
|
|
|
1049
1046
|
}
|
|
1050
1047
|
return context.output.toString() !== before;
|
|
1051
1048
|
}
|
|
1052
|
-
async function sourceFiles(cwd) {
|
|
1049
|
+
async function sourceFiles$1(cwd) {
|
|
1053
1050
|
return (await glob(sourcePatterns$18, {
|
|
1054
1051
|
cwd,
|
|
1055
1052
|
ignore: ignoredPatterns$20,
|
|
@@ -1059,7 +1056,7 @@ async function sourceFiles(cwd) {
|
|
|
1059
1056
|
async function migrate$32({ cwd }) {
|
|
1060
1057
|
const edits = [];
|
|
1061
1058
|
const followUps = [];
|
|
1062
|
-
for (const file of await sourceFiles(cwd)) {
|
|
1059
|
+
for (const file of await sourceFiles$1(cwd)) {
|
|
1063
1060
|
const source = await readFile(join(cwd, file), "utf8");
|
|
1064
1061
|
if (!needles$2.test(source)) continue;
|
|
1065
1062
|
const output = new MagicString(source);
|
|
@@ -1126,7 +1123,7 @@ const agentSurface = {
|
|
|
1126
1123
|
detect: async ({ cwd }) => {
|
|
1127
1124
|
const dependencies = await readDependencies(cwd);
|
|
1128
1125
|
if (!dependencies.has("vite-hub") && !dependencies.has("@vite-hub/agent")) return void 0;
|
|
1129
|
-
for (const file of await sourceFiles(cwd)) {
|
|
1126
|
+
for (const file of await sourceFiles$1(cwd)) {
|
|
1130
1127
|
const source = await readFile(join(cwd, file), "utf8");
|
|
1131
1128
|
if (/\b(?:actor|workflow)\b/.test(source) && /["'](?:vite-hub\/agent|@vite-hub\/agent)["']/.test(source) || /AgentActor|AgentInvokerProfile|getAgentFromRegistry|agent\/(?:process-host|runtime\/process|invocations\/(?:d1|sqlite)|state\/sqlite)|\bpresets\s*:\s*\{/.test(source)) return { reason: `${file} uses an Agent API that was renamed` };
|
|
1132
1129
|
if (/\b(?:state|scheduler|sandbox)\s*:\s*\{\s*provider\s*:/.test(source)) return { reason: `${file} selects an Agent provider with \`provider\`` };
|
|
@@ -1134,8 +1131,7 @@ const agentSurface = {
|
|
|
1134
1131
|
},
|
|
1135
1132
|
run: migrate$32
|
|
1136
1133
|
};
|
|
1137
|
-
|
|
1138
|
-
//#region src/auth-accessors/index.ts
|
|
1134
|
+
// src/auth-accessors/index.ts
|
|
1139
1135
|
/** The modules that exported `auth` and `getAuth`. */
|
|
1140
1136
|
const serverModules = /* @__PURE__ */ new Set([
|
|
1141
1137
|
"vite-hub/auth/server",
|
|
@@ -1420,8 +1416,7 @@ const authAccessors = {
|
|
|
1420
1416
|
},
|
|
1421
1417
|
run: migrate$31
|
|
1422
1418
|
};
|
|
1423
|
-
|
|
1424
|
-
//#region src/auth-sign-in/index.ts
|
|
1419
|
+
// src/auth-sign-in/index.ts
|
|
1425
1420
|
const configPatterns$2 = ["{vite,nuxt}.config.{ts,mts,cts,js,mjs,cjs}"];
|
|
1426
1421
|
const definitionPatterns = ["server/auth.{ts,mts,cts,js,mjs,cjs}", "server.auth.{ts,mts,cts,js,mjs,cjs}"];
|
|
1427
1422
|
const ignored$7 = [
|
|
@@ -1431,7 +1426,7 @@ const ignored$7 = [
|
|
|
1431
1426
|
"**/.vitehub/**",
|
|
1432
1427
|
"**/dist/**"
|
|
1433
1428
|
];
|
|
1434
|
-
function parse$
|
|
1429
|
+
function parse$5(code, file) {
|
|
1435
1430
|
try {
|
|
1436
1431
|
return {
|
|
1437
1432
|
code,
|
|
@@ -1607,7 +1602,7 @@ async function migrate$30({ cwd }) {
|
|
|
1607
1602
|
})).sort()) {
|
|
1608
1603
|
const code = await readFile(join(cwd, file), "utf8");
|
|
1609
1604
|
if (!/\bredirects\b/.test(code)) continue;
|
|
1610
|
-
const parsed = parse$
|
|
1605
|
+
const parsed = parse$5(code, file);
|
|
1611
1606
|
if (!parsed) continue;
|
|
1612
1607
|
configFiles.set(file, code);
|
|
1613
1608
|
for (const auth of new Set(authOptionProperties(parsed.program))) {
|
|
@@ -1671,7 +1666,7 @@ async function migrate$30({ cwd }) {
|
|
|
1671
1666
|
});
|
|
1672
1667
|
} else if (definition) {
|
|
1673
1668
|
const code = await readFile(join(cwd, definition), "utf8");
|
|
1674
|
-
const parsed = /\bdefineAuth\b/.test(code) ? parse$
|
|
1669
|
+
const parsed = /\bdefineAuth\b/.test(code) ? parse$5(code, definition) : void 0;
|
|
1675
1670
|
if (!parsed && redirects.length) followUps.push({
|
|
1676
1671
|
file: definition,
|
|
1677
1672
|
message: "Move `auth.redirects` by hand: the codemod could not read the Auth Definition."
|
|
@@ -1715,8 +1710,7 @@ const authSignIn = {
|
|
|
1715
1710
|
},
|
|
1716
1711
|
run: migrate$30
|
|
1717
1712
|
};
|
|
1718
|
-
|
|
1719
|
-
//#region src/shared/module-source.ts
|
|
1713
|
+
// src/shared/module-source.ts
|
|
1720
1714
|
/** The literal module reference in ESM, CommonJS, and TypeScript imports. */
|
|
1721
1715
|
function moduleSource(node) {
|
|
1722
1716
|
if (node.type === "ImportDeclaration" || node.type === "ExportAllDeclaration") return node.source;
|
|
@@ -1724,10 +1718,9 @@ function moduleSource(node) {
|
|
|
1724
1718
|
if (node.type === "ImportExpression") return node.source.type === "StringLiteral" ? node.source : void 0;
|
|
1725
1719
|
if (node.type === "CallExpression" && (node.callee.type === "Import" || node.callee.type === "Identifier" && node.callee.name === "require")) return node.arguments[0]?.type === "StringLiteral" ? node.arguments[0] : void 0;
|
|
1726
1720
|
if (node.type === "TSExternalModuleReference") return node.expression;
|
|
1727
|
-
if (node.type === "TSImportType") return node.
|
|
1721
|
+
if (node.type === "TSImportType") return node.source;
|
|
1728
1722
|
}
|
|
1729
|
-
|
|
1730
|
-
//#region src/channels/index.ts
|
|
1723
|
+
// src/channels/index.ts
|
|
1731
1724
|
/** Modules that exported `http()`. `http(options)` is now `channelAdapter("http", options)`. */
|
|
1732
1725
|
const httpModules = /* @__PURE__ */ new Set(["vite-hub/agent/channels", "@vite-hub/agent/channels"]);
|
|
1733
1726
|
const movedPath = "vite-hub/agent/channels";
|
|
@@ -1833,7 +1826,7 @@ function reportIndirectUses(context) {
|
|
|
1833
1826
|
return;
|
|
1834
1827
|
}
|
|
1835
1828
|
if (node.type === "ExportNamedDeclaration" && node.source && httpModules.has(node.source.value)) {
|
|
1836
|
-
if (node.specifiers.some((specifier) => specifier.type === "ExportNamespaceSpecifier" || specifier.type === "ExportSpecifier" && specifier.local.name === "http")) followUp$6(context, node, manualHttp);
|
|
1829
|
+
if (node.specifiers.some((specifier) => specifier.type === "ExportNamespaceSpecifier" || specifier.type === "ExportSpecifier" && (specifier.local.type === "Identifier" ? specifier.local.name : specifier.local.value) === "http")) followUp$6(context, node, manualHttp);
|
|
1837
1830
|
return;
|
|
1838
1831
|
}
|
|
1839
1832
|
if (node.type === "ImportDeclaration" && httpModules.has(node.source.value) && node.specifiers.some((specifier) => specifier.type === "ImportNamespaceSpecifier")) {
|
|
@@ -1856,7 +1849,7 @@ function reportIndirectUses(context) {
|
|
|
1856
1849
|
return mocked;
|
|
1857
1850
|
}
|
|
1858
1851
|
function isSimpleCall(call) {
|
|
1859
|
-
if (call.
|
|
1852
|
+
if (call.typeArguments) return false;
|
|
1860
1853
|
const [options] = call.arguments;
|
|
1861
1854
|
if (!options) return true;
|
|
1862
1855
|
return call.arguments.length === 1 && options.type === "ObjectExpression" && options.properties.every((property) => property.type === "ObjectProperty" && !property.computed && (property.key.type === "Identifier" || property.key.type === "StringLiteral") && (property.key.type === "Identifier" ? property.key.name : property.key.value) === "route" && property.value.type === "BooleanLiteral");
|
|
@@ -2215,7 +2208,7 @@ function moveImports(context, changed) {
|
|
|
2215
2208
|
if (node.type === "TSImportType" && node.qualifier) {
|
|
2216
2209
|
let qualifier = node.qualifier;
|
|
2217
2210
|
while (qualifier.type === "TSQualifiedName") qualifier = qualifier.left;
|
|
2218
|
-
usage = nameUsage(qualifier.name);
|
|
2211
|
+
usage = nameUsage(qualifier.type === "Identifier" ? qualifier.name : void 0);
|
|
2219
2212
|
} else usage = parent?.type === "AwaitExpression" && parent.argument === node ? adapterUsage(parent, ancestors.at(-2)) : adapterUsage(node, parent);
|
|
2220
2213
|
if (usage === "adapters") moveSource(context, source, `${source.value}/adapters`);
|
|
2221
2214
|
else if (usage === "unknown") reportAdapterSplit(context, node, source.value);
|
|
@@ -2291,8 +2284,7 @@ const channels = {
|
|
|
2291
2284
|
},
|
|
2292
2285
|
run: migrate$29
|
|
2293
2286
|
};
|
|
2294
|
-
|
|
2295
|
-
//#region src/choices-package/index.ts
|
|
2287
|
+
// src/choices-package/index.ts
|
|
2296
2288
|
const sourcePatterns$15 = ["**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,vue}", "**/package.json"];
|
|
2297
2289
|
const ignoredPatterns$17 = [
|
|
2298
2290
|
"**/node_modules/**",
|
|
@@ -2475,8 +2467,7 @@ const choicesPackage = {
|
|
|
2475
2467
|
},
|
|
2476
2468
|
run: migrate$28
|
|
2477
2469
|
};
|
|
2478
|
-
|
|
2479
|
-
//#region src/shared/cli-calls.ts
|
|
2470
|
+
// src/shared/cli-calls.ts
|
|
2480
2471
|
/** Files that call the `vitehub` CLI: package scripts, CI workflows, and shell scripts. */
|
|
2481
2472
|
const callerPatterns$1 = [
|
|
2482
2473
|
"**/package.json",
|
|
@@ -2552,7 +2543,7 @@ function rewriteShell$1(source, posix, rewrite) {
|
|
|
2552
2543
|
}
|
|
2553
2544
|
return after + source.slice(offset);
|
|
2554
2545
|
}
|
|
2555
|
-
function isRecord$
|
|
2546
|
+
function isRecord$7(value) {
|
|
2556
2547
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2557
2548
|
}
|
|
2558
2549
|
function rewriteWorkflow(source, transform, report) {
|
|
@@ -2619,7 +2610,7 @@ async function rewriteCliCalls$1(cwd, rewrite, manual) {
|
|
|
2619
2610
|
report(before);
|
|
2620
2611
|
continue;
|
|
2621
2612
|
}
|
|
2622
|
-
if (!isRecord$
|
|
2613
|
+
if (!isRecord$7(manifest) || !isRecord$7(manifest.scripts)) continue;
|
|
2623
2614
|
let changed = false;
|
|
2624
2615
|
for (const [name, script] of Object.entries(manifest.scripts)) {
|
|
2625
2616
|
if (typeof script !== "string") continue;
|
|
@@ -2649,8 +2640,7 @@ async function rewriteCliCalls$1(cwd, rewrite, manual) {
|
|
|
2649
2640
|
followUps
|
|
2650
2641
|
};
|
|
2651
2642
|
}
|
|
2652
|
-
|
|
2653
|
-
//#region src/cli-agent-tree/index.ts
|
|
2643
|
+
// src/cli-agent-tree/index.ts
|
|
2654
2644
|
const renames$1 = [
|
|
2655
2645
|
[
|
|
2656
2646
|
"agents",
|
|
@@ -2762,8 +2752,7 @@ const cliAgentTree = {
|
|
|
2762
2752
|
},
|
|
2763
2753
|
run: migrate$27
|
|
2764
2754
|
};
|
|
2765
|
-
|
|
2766
|
-
//#region src/cli-get-list/cli-calls.ts
|
|
2755
|
+
// src/cli-get-list/cli-calls.ts
|
|
2767
2756
|
const callerPatterns = [
|
|
2768
2757
|
"**/package.json",
|
|
2769
2758
|
".github/workflows/*.{yml,yaml}",
|
|
@@ -2922,8 +2911,7 @@ async function rewriteCliCalls(cwd, rewrite) {
|
|
|
2922
2911
|
followUps
|
|
2923
2912
|
};
|
|
2924
2913
|
}
|
|
2925
|
-
|
|
2926
|
-
//#region src/cli-get-list/index.ts
|
|
2914
|
+
// src/cli-get-list/index.ts
|
|
2927
2915
|
/** `get` reads one record and `list` reads many. Each entry rewrites the start of the arguments after `vitehub `. */
|
|
2928
2916
|
const renames = [
|
|
2929
2917
|
[/^agent\s+invocations\s+show(?=\s|$)/, "agent invocations get"],
|
|
@@ -3025,8 +3013,7 @@ const cliGetList = {
|
|
|
3025
3013
|
},
|
|
3026
3014
|
run: migrate$26
|
|
3027
3015
|
};
|
|
3028
|
-
|
|
3029
|
-
//#region src/cli-url-flag/index.ts
|
|
3016
|
+
// src/cli-url-flag/index.ts
|
|
3030
3017
|
function serverOptions({ words }) {
|
|
3031
3018
|
const [group, action, ...args] = words;
|
|
3032
3019
|
const name = `${group?.text} ${action?.text}`;
|
|
@@ -3123,8 +3110,7 @@ const cliUrlFlag = {
|
|
|
3123
3110
|
},
|
|
3124
3111
|
run: migrate$25
|
|
3125
3112
|
};
|
|
3126
|
-
|
|
3127
|
-
//#region src/cli-yes-flag/index.ts
|
|
3113
|
+
// src/cli-yes-flag/index.ts
|
|
3128
3114
|
function literal$1(text) {
|
|
3129
3115
|
return text?.replace(/^(['"])(.*)\1$/, "$2");
|
|
3130
3116
|
}
|
|
@@ -3188,8 +3174,7 @@ const cliYesFlag = {
|
|
|
3188
3174
|
},
|
|
3189
3175
|
run: migrate$24
|
|
3190
3176
|
};
|
|
3191
|
-
|
|
3192
|
-
//#region src/cms-roles/index.ts
|
|
3177
|
+
// src/cms-roles/index.ts
|
|
3193
3178
|
const sourcePatterns$14 = ["**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}"];
|
|
3194
3179
|
const ignoredPatterns$14 = [
|
|
3195
3180
|
"**/node_modules/**",
|
|
@@ -3312,8 +3297,7 @@ const cmsRoles = {
|
|
|
3312
3297
|
},
|
|
3313
3298
|
run: migrate$23
|
|
3314
3299
|
};
|
|
3315
|
-
|
|
3316
|
-
//#region src/define-forms/shared.ts
|
|
3300
|
+
// src/define-forms/shared.ts
|
|
3317
3301
|
const sourcePatterns$13 = ["**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}"];
|
|
3318
3302
|
const ignoredPatterns$13 = [
|
|
3319
3303
|
"**/node_modules/**",
|
|
@@ -3401,8 +3385,7 @@ function countReferences$1(program, name) {
|
|
|
3401
3385
|
});
|
|
3402
3386
|
return count;
|
|
3403
3387
|
}
|
|
3404
|
-
|
|
3405
|
-
//#region src/define-forms/content.ts
|
|
3388
|
+
// src/define-forms/content.ts
|
|
3406
3389
|
/** `server/content.ts` of the app or of a Nuxt layer. */
|
|
3407
3390
|
const contentFilePattern = /(?:^|\/)server\/content\.(?:c|m)?[jt]s$/;
|
|
3408
3391
|
function exportedName(specifier) {
|
|
@@ -3496,8 +3479,7 @@ function rewriteContentImports(file, parsed, contentFiles, output, followUps) {
|
|
|
3496
3479
|
});
|
|
3497
3480
|
return count;
|
|
3498
3481
|
}
|
|
3499
|
-
|
|
3500
|
-
//#region src/define-forms/database.ts
|
|
3482
|
+
// src/define-forms/database.ts
|
|
3501
3483
|
const configFile$1 = /^config\.(?:c|m)?[jt]s$/;
|
|
3502
3484
|
const indexFile = /^index\.(?:c|m)?[jt]s$/;
|
|
3503
3485
|
const scriptFile = /\.(?:c|m)?[jt]sx?$/;
|
|
@@ -3676,7 +3658,7 @@ function rewriteDatabaseReferences(file, plan, followUps) {
|
|
|
3676
3658
|
else if (node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "require") source = node.arguments[0];
|
|
3677
3659
|
else if (node.type === "TSExternalModuleReference") source = node.expression;
|
|
3678
3660
|
else if (node.type === "CallExpression" && node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" && moduleCalls$3.has(node.callee.property.name)) source = node.arguments[0];
|
|
3679
|
-
else if (node.type === "TSImportType") source = node.
|
|
3661
|
+
else if (node.type === "TSImportType") source = node.source;
|
|
3680
3662
|
if (source && typeof source === "object" && "type" in source && source.type === "StringLiteral" && "value" in source && typeof source.value === "string") {
|
|
3681
3663
|
sources.add(source);
|
|
3682
3664
|
replace(source, !required);
|
|
@@ -3697,8 +3679,7 @@ function rewriteDatabaseReferences(file, plan, followUps) {
|
|
|
3697
3679
|
});
|
|
3698
3680
|
return output.toString();
|
|
3699
3681
|
}
|
|
3700
|
-
|
|
3701
|
-
//#region src/define-forms/queue.ts
|
|
3682
|
+
// src/define-forms/queue.ts
|
|
3702
3683
|
const queueModules$1 = /* @__PURE__ */ new Set(["vite-hub/queue", "@vite-hub/queue"]);
|
|
3703
3684
|
const queueOptions = /* @__PURE__ */ new Set([
|
|
3704
3685
|
"cache",
|
|
@@ -3782,8 +3763,7 @@ function rewriteQueues(file, parsed, output, followUps) {
|
|
|
3782
3763
|
});
|
|
3783
3764
|
return count;
|
|
3784
3765
|
}
|
|
3785
|
-
|
|
3786
|
-
//#region src/define-forms/sandbox-task.ts
|
|
3766
|
+
// src/define-forms/sandbox-task.ts
|
|
3787
3767
|
const sandboxTaskModules$1 = /* @__PURE__ */ new Set(["vite-hub/sandbox/task", "@vite-hub/sandbox/task"]);
|
|
3788
3768
|
/** Renames the `run` option of `defineSandboxTask()` to `handler`. */
|
|
3789
3769
|
function rewriteSandboxTasks(file, parsed, output, followUps) {
|
|
@@ -3813,8 +3793,7 @@ function rewriteSandboxTasks(file, parsed, output, followUps) {
|
|
|
3813
3793
|
});
|
|
3814
3794
|
return count;
|
|
3815
3795
|
}
|
|
3816
|
-
|
|
3817
|
-
//#region src/define-forms/schedule.ts
|
|
3796
|
+
// src/define-forms/schedule.ts
|
|
3818
3797
|
const scheduleModules$1 = /* @__PURE__ */ new Set(["vite-hub/schedule", "@vite-hub/schedule"]);
|
|
3819
3798
|
/** The text of a property: `cron` for `cron: cron`, else `cron: <value>`. */
|
|
3820
3799
|
function property$1(key, value) {
|
|
@@ -3850,8 +3829,7 @@ function rewriteSchedules(file, parsed, output, followUps) {
|
|
|
3850
3829
|
});
|
|
3851
3830
|
return count;
|
|
3852
3831
|
}
|
|
3853
|
-
|
|
3854
|
-
//#region src/define-forms/workflow.ts
|
|
3832
|
+
// src/define-forms/workflow.ts
|
|
3855
3833
|
const workflowModules$1 = /* @__PURE__ */ new Set(["vite-hub/workflow", "@vite-hub/workflow"]);
|
|
3856
3834
|
function isFunction$1(node) {
|
|
3857
3835
|
return node?.type === "ArrowFunctionExpression" || node?.type === "FunctionExpression";
|
|
@@ -3926,7 +3904,7 @@ function rewriteHandlerParams(code, handler) {
|
|
|
3926
3904
|
}
|
|
3927
3905
|
/** The type arguments of a call, such as `<"onboard", Payload>`, as text. */
|
|
3928
3906
|
function typeArguments(code, call) {
|
|
3929
|
-
const node = call.
|
|
3907
|
+
const node = call.typeArguments;
|
|
3930
3908
|
if (!node) return void 0;
|
|
3931
3909
|
return {
|
|
3932
3910
|
node,
|
|
@@ -4036,8 +4014,7 @@ function rewriteWorkflows(file, parsed, output, followUps) {
|
|
|
4036
4014
|
});
|
|
4037
4015
|
return count;
|
|
4038
4016
|
}
|
|
4039
|
-
|
|
4040
|
-
//#region src/define-forms/index.ts
|
|
4017
|
+
// src/define-forms/index.ts
|
|
4041
4018
|
/** Files that name Database paths but that the codemod does not parse. */
|
|
4042
4019
|
const configPatterns$1 = ["**/{package.json,wrangler.json,wrangler.jsonc,wrangler.toml,netlify.toml,vercel.json}"];
|
|
4043
4020
|
async function databaseFiles(cwd) {
|
|
@@ -4226,11 +4203,9 @@ const defineForms = {
|
|
|
4226
4203
|
},
|
|
4227
4204
|
run: migrate$22
|
|
4228
4205
|
};
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
//#endregion
|
|
4233
|
-
//#region src/shared/config-editor.ts
|
|
4206
|
+
// package.json
|
|
4207
|
+
var version = "0.5.1";
|
|
4208
|
+
// src/shared/config-editor.ts
|
|
4234
4209
|
const vitehubModule = "vite-hub/nuxt";
|
|
4235
4210
|
const nitroPresetHosts = {
|
|
4236
4211
|
"cloudflare-module": "cloudflare",
|
|
@@ -4566,14 +4541,526 @@ function removeModuleEntry(editor, config, moduleName) {
|
|
|
4566
4541
|
editor.removeItem(entry.element);
|
|
4567
4542
|
return true;
|
|
4568
4543
|
}
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4544
|
+
// ../internal/dist/features.js
|
|
4545
|
+
const noHostLimit = "No host limit in ViteHub.";
|
|
4546
|
+
function native(driver, display, detail, guarantee = "native") {
|
|
4547
|
+
return {
|
|
4548
|
+
detail,
|
|
4549
|
+
display,
|
|
4550
|
+
driver,
|
|
4551
|
+
guarantee,
|
|
4552
|
+
level: "native"
|
|
4553
|
+
};
|
|
4554
|
+
}
|
|
4555
|
+
function explicit(option, display, detail) {
|
|
4556
|
+
return {
|
|
4557
|
+
detail,
|
|
4558
|
+
display,
|
|
4559
|
+
level: "explicit",
|
|
4560
|
+
option
|
|
4561
|
+
};
|
|
4562
|
+
}
|
|
4563
|
+
function unsupported(detail) {
|
|
4564
|
+
return {
|
|
4565
|
+
detail,
|
|
4566
|
+
level: "unsupported"
|
|
4567
|
+
};
|
|
4568
|
+
}
|
|
4569
|
+
function everywhere(driver, display, detail = noHostLimit) {
|
|
4570
|
+
const support = native(driver, display, detail);
|
|
4571
|
+
return {
|
|
4572
|
+
cloudflare: support,
|
|
4573
|
+
deno: support,
|
|
4574
|
+
dev: support,
|
|
4575
|
+
netlify: support,
|
|
4576
|
+
node: support,
|
|
4577
|
+
vercel: support
|
|
4578
|
+
};
|
|
4579
|
+
}
|
|
4580
|
+
function feature(definition) {
|
|
4581
|
+
return {
|
|
4582
|
+
devPackages: [],
|
|
4583
|
+
enabledByDefault: false,
|
|
4584
|
+
implies: [],
|
|
4585
|
+
packages: [],
|
|
4586
|
+
...definition
|
|
4587
|
+
};
|
|
4588
|
+
}
|
|
4589
|
+
const sourceExtensions = [
|
|
4590
|
+
"ts",
|
|
4591
|
+
"mts",
|
|
4592
|
+
"js",
|
|
4593
|
+
"mjs",
|
|
4594
|
+
"cts",
|
|
4595
|
+
"cjs"
|
|
4596
|
+
];
|
|
4597
|
+
/** `<base>.<ext>` for each source extension. */
|
|
4598
|
+
function sourceFiles(base) {
|
|
4599
|
+
return sourceExtensions.map((extension) => `${base}.${extension}`);
|
|
4600
|
+
}
|
|
4601
|
+
/**
|
|
4602
|
+
* A starter for Definitions in `dir`, one `<name>.ts` file each. With `suffix`, the owner also discovers the Vite
|
|
4603
|
+
* form `src/<name>.<suffix>.ts`, and a Definition folder `<dir>/<name>/` when `folder` names its entry file.
|
|
4604
|
+
*/
|
|
4605
|
+
function starter(dir, template, options = {}) {
|
|
4606
|
+
return {
|
|
4607
|
+
conflicts: (name) => [
|
|
4608
|
+
...sourceFiles(`${dir}/${name}`).slice(1),
|
|
4609
|
+
...options.folder ? sourceFiles(`${dir}/${name}/${options.folder}`) : [],
|
|
4610
|
+
...options.suffix ? [...sourceFiles(`src/${name}.${options.suffix}`), ...sourceFiles(`${name}.${options.suffix}`)] : []
|
|
4611
|
+
],
|
|
4612
|
+
dir,
|
|
4613
|
+
file: (name) => `${dir}/${name}.ts`,
|
|
4614
|
+
template
|
|
4615
|
+
};
|
|
4616
|
+
}
|
|
4617
|
+
const features = {
|
|
4618
|
+
agent: feature({
|
|
4619
|
+
definition: starter("server/agents", (name) => `import { defineAgent } from "vite-hub/agent"
|
|
4620
|
+
|
|
4621
|
+
export default defineAgent({
|
|
4622
|
+
driver: { run: () => ({ text: "Hello from ${name}." }) },
|
|
4623
|
+
})
|
|
4624
|
+
`, {
|
|
4625
|
+
folder: "agent",
|
|
4626
|
+
suffix: "agent"
|
|
4627
|
+
}),
|
|
4628
|
+
docs: "/docs/agents",
|
|
4629
|
+
enabledByDiscovery: ["agents"],
|
|
4630
|
+
hosts: {
|
|
4631
|
+
...everywhere("nitro", "Nitro"),
|
|
4632
|
+
deno: native("nitro", "Nitro", "Agent routes run in the Nitro output. The Agent Deno runtime is not supported on this host."),
|
|
4633
|
+
netlify: native("nitro", "Nitro", "Agent HTTP routes run in generated functions. `agent.invocations` is not supported, so `agent: true` fails the build. Set `agent: { invocations: false }` and configure invocations on each Agent Definition.")
|
|
4634
|
+
},
|
|
4635
|
+
id: "agent",
|
|
4636
|
+
packages: ["@vite-hub/agent"],
|
|
4637
|
+
summary: "Agents in `server/agents/` with tools, Capabilities, channels, and invocations.",
|
|
4638
|
+
title: "Agent"
|
|
4639
|
+
}),
|
|
4640
|
+
auth: feature({
|
|
4641
|
+
docs: "/docs/auth",
|
|
4642
|
+
enabledByDiscovery: sourceFiles("auth"),
|
|
4643
|
+
hosts: everywhere("better-auth", "Better Auth"),
|
|
4644
|
+
id: "auth",
|
|
4645
|
+
packages: [
|
|
4646
|
+
"@vite-hub/auth",
|
|
4647
|
+
"better-auth",
|
|
4648
|
+
"drizzle-orm"
|
|
4649
|
+
],
|
|
4650
|
+
summary: "Better Auth sign-in, sessions, and organizations, with tables that ViteHub owns.",
|
|
4651
|
+
title: "Auth"
|
|
4652
|
+
}),
|
|
4653
|
+
blob: feature({
|
|
4654
|
+
docs: "/docs/blob",
|
|
4655
|
+
hosts: {
|
|
4656
|
+
cloudflare: native("cloudflare", "R2", "Cloudflare R2 binding or S3-compatible HTTP access."),
|
|
4657
|
+
deno: explicit("blob.driver", "S3", "Use a remote S3-compatible store. No Deno-native Blob driver is provided."),
|
|
4658
|
+
dev: native("fs", "fs", "Local filesystem storage for development.", "single-host"),
|
|
4659
|
+
netlify: native("netlify-blobs", "Netlify Blobs", "Netlify Blobs selected from the detected host."),
|
|
4660
|
+
node: native("fs", "fs / S3", "Filesystem, S3-compatible, MinIO, or files-sdk drivers.", "single-host"),
|
|
4661
|
+
vercel: native("vercel", "Vercel Blob", "Vercel Blob through the vercel driver.")
|
|
4662
|
+
},
|
|
4663
|
+
id: "blob",
|
|
4664
|
+
packages: ["@vite-hub/blob"],
|
|
4665
|
+
providerPackages: { driver: { s3: [
|
|
4666
|
+
"@aws-sdk/client-s3",
|
|
4667
|
+
"@aws-sdk/lib-storage",
|
|
4668
|
+
"@aws-sdk/s3-presigned-post",
|
|
4669
|
+
"@aws-sdk/s3-request-presigner"
|
|
4670
|
+
] } },
|
|
4671
|
+
service: "blob",
|
|
4672
|
+
summary: "Object storage for files and uploads, with one API on every host.",
|
|
4673
|
+
title: "Blob"
|
|
4674
|
+
}),
|
|
4675
|
+
browser: feature({
|
|
4676
|
+
docs: "/docs/browser",
|
|
4677
|
+
enabledByDiscovery: ["browsers"],
|
|
4678
|
+
hosts: {
|
|
4679
|
+
cloudflare: native("cloudflare", "Browser Run", "Cloudflare Browser Run binding and provider output."),
|
|
4680
|
+
deno: unsupported("Browser Definitions do not have a Deno provider."),
|
|
4681
|
+
dev: unsupported("Browser Definitions need the Cloudflare host. Use createBrowser({ driver: localBrowser({ executablePath }) }) from code for a trusted local process."),
|
|
4682
|
+
netlify: unsupported("Browser Definitions do not have a Netlify provider."),
|
|
4683
|
+
node: unsupported("The Node host has no built-in Browser Provider. Use localBrowser() from code for a trusted process."),
|
|
4684
|
+
vercel: unsupported("Browser Definitions do not have a Vercel provider.")
|
|
4685
|
+
},
|
|
4686
|
+
id: "browser",
|
|
4687
|
+
packages: ["@vite-hub/browser"],
|
|
4688
|
+
service: "browser",
|
|
4689
|
+
summary: "Headless browser sessions for Agents and server code.",
|
|
4690
|
+
title: "Browser"
|
|
4691
|
+
}),
|
|
4692
|
+
cache: feature({
|
|
4693
|
+
developmentOverrides: [
|
|
4694
|
+
"cloudflare",
|
|
4695
|
+
"deno",
|
|
4696
|
+
"vercel"
|
|
4697
|
+
],
|
|
4698
|
+
docs: "/docs/reference/config-options",
|
|
4699
|
+
hosts: {
|
|
4700
|
+
cloudflare: native("cloudflare", "Workers KV", "Workers KV binding `CACHE`."),
|
|
4701
|
+
deno: native("deno-kv", "Deno KV", "Native Deno KV."),
|
|
4702
|
+
dev: native("fs-lite", "fs-lite", "`.vitehub/data/cache` during development.", "single-host"),
|
|
4703
|
+
netlify: explicit("cache.driver", "KV", "`cache: true` has no default store on Netlify. Set `cache: { driver: \"kv\" }` and enable `kv`."),
|
|
4704
|
+
node: native("fs-lite", "fs-lite", "`.vitehub/data/cache` on the server disk.", "single-host"),
|
|
4705
|
+
vercel: native("vercel", "Runtime Cache", "Vercel Runtime Cache.")
|
|
4706
|
+
},
|
|
4707
|
+
id: "cache",
|
|
4708
|
+
summary: "Storage for Nitro's cache mount, used by defineCachedFunction() and defineCachedEventHandler().",
|
|
4709
|
+
title: "Cache"
|
|
4710
|
+
}),
|
|
4711
|
+
channels: feature({
|
|
4712
|
+
docs: "/docs/channels",
|
|
4713
|
+
enabledByDiscovery: ["channels"],
|
|
4714
|
+
hosts: everywhere("nitro", "Nitro"),
|
|
4715
|
+
id: "channels",
|
|
4716
|
+
packages: ["@vite-hub/channels"],
|
|
4717
|
+
summary: "Chat channels such as Slack, Discord, and GitHub that deliver messages to Agents.",
|
|
4718
|
+
title: "Channels"
|
|
4719
|
+
}),
|
|
4720
|
+
comments: feature({
|
|
4721
|
+
docs: "/docs/comments",
|
|
4722
|
+
enabledByDiscovery: [
|
|
4723
|
+
"comments.ts",
|
|
4724
|
+
"comments.mts",
|
|
4725
|
+
"comments.js",
|
|
4726
|
+
"comments.mjs"
|
|
4727
|
+
],
|
|
4728
|
+
hosts: everywhere("database", "Database"),
|
|
4729
|
+
id: "comments",
|
|
4730
|
+
implies: [{ feature: "database" }],
|
|
4731
|
+
packages: ["@vite-hub/comments"],
|
|
4732
|
+
summary: "Comments on the app's pages, stored in a ViteHub Database.",
|
|
4733
|
+
title: "Comments"
|
|
4734
|
+
}),
|
|
4735
|
+
connections: feature({
|
|
4736
|
+
docs: "/docs/connections",
|
|
4737
|
+
enabledByDiscovery: ["connections"],
|
|
4738
|
+
hosts: everywhere("database", "Database"),
|
|
4739
|
+
id: "connections",
|
|
4740
|
+
implies: [{ feature: "database" }],
|
|
4741
|
+
packages: [
|
|
4742
|
+
"@vite-hub/connections",
|
|
4743
|
+
"@vite-hub/database",
|
|
4744
|
+
"drizzle-orm"
|
|
4745
|
+
],
|
|
4746
|
+
summary: "OAuth and API key Connections in `server/connections/`, with grants stored in a Database.",
|
|
4747
|
+
title: "Connections"
|
|
4748
|
+
}),
|
|
4749
|
+
console: feature({
|
|
4750
|
+
docs: "/docs/console",
|
|
4751
|
+
hosts: everywhere("nitro", "Nitro"),
|
|
4752
|
+
id: "console",
|
|
4753
|
+
packages: [],
|
|
4754
|
+
summary: "The Operations endpoint and MCP at `/_vitehub`, which the hosted Console at console.vitehub.dev and the CLI call.",
|
|
4755
|
+
title: "Console"
|
|
4756
|
+
}),
|
|
4757
|
+
database: feature({
|
|
4758
|
+
definition: {
|
|
4759
|
+
conflicts: (name) => [
|
|
4760
|
+
...sourceFiles(`server/databases/${name}`).slice(1),
|
|
4761
|
+
...sourceFiles(`server/databases/${name}/index`),
|
|
4762
|
+
...name === "default" ? ["src/database.ts"] : [...sourceFiles(`src/${name}.database`), "src/database.ts"]
|
|
4763
|
+
],
|
|
4764
|
+
dir: "server/databases",
|
|
4765
|
+
file: (name) => `server/databases/${name}.ts`,
|
|
4766
|
+
template: (name) => `import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core"
|
|
4767
|
+
import { defineDatabase } from "vite-hub/database"
|
|
4768
|
+
|
|
4769
|
+
export default defineDatabase({
|
|
4770
|
+
${name === "default" ? "" : ` name: ${JSON.stringify(name)},\n`} schema: {
|
|
4771
|
+
notes: sqliteTable("notes", {
|
|
4772
|
+
id: integer("id").primaryKey(),
|
|
4773
|
+
title: text("title").notNull(),
|
|
4774
|
+
}),
|
|
4775
|
+
},
|
|
4776
|
+
})
|
|
4777
|
+
`
|
|
4778
|
+
},
|
|
4779
|
+
developmentOverrides: [
|
|
4780
|
+
"deno",
|
|
4781
|
+
"netlify",
|
|
4782
|
+
"vercel"
|
|
4783
|
+
],
|
|
4784
|
+
devPackages: ["drizzle-kit"],
|
|
4785
|
+
docs: "/docs/database",
|
|
4786
|
+
hosts: {
|
|
4787
|
+
cloudflare: native("cloudflare", "D1", "Cloudflare D1 binding, with authenticated HTTP available for development. A PostgreSQL Database Definition connects through Hyperdrive or `connection.url`."),
|
|
4788
|
+
deno: explicit("database.connection", "libSQL / D1 / Postgres", "Configure hosted libSQL, D1 over authenticated HTTP, or a PostgreSQL Database Definition. No Deno-native database driver is provided."),
|
|
4789
|
+
dev: native("sqlite", "SQLite", "Local SQLite through libSQL and Drizzle.", "single-host"),
|
|
4790
|
+
netlify: explicit("database.connection", "libSQL / D1 / Postgres", "Configure hosted libSQL, D1 over authenticated HTTP, or a PostgreSQL Database Definition. No Netlify-native database driver is provided."),
|
|
4791
|
+
node: native("sqlite", "SQLite / libSQL / Postgres", "SQLite or hosted libSQL through the selected Database connection, or a PostgreSQL Database Definition. Several servers can share Postgres and migrate on start under one advisory lock.", "single-host"),
|
|
4792
|
+
vercel: explicit("database.connection", "libSQL / D1 / Postgres", "Configure hosted libSQL, D1 over authenticated HTTP, or a PostgreSQL Database Definition. The default local SQLite file is not supported in Vercel functions.")
|
|
4793
|
+
},
|
|
4794
|
+
id: "database",
|
|
4795
|
+
packages: ["@vite-hub/database", "drizzle-orm"],
|
|
4796
|
+
summary: "Drizzle Databases in `server/databases/` with migrations and a local SQLite in development.",
|
|
4797
|
+
title: "Database"
|
|
4798
|
+
}),
|
|
4799
|
+
email: feature({
|
|
4800
|
+
docs: "/docs/email",
|
|
4801
|
+
hosts: {
|
|
4802
|
+
cloudflare: native("cloudflare", "Cloudflare Email", "The Cloudflare Email driver is the default. Resend is also supported."),
|
|
4803
|
+
deno: explicit("email.driver", "Resend", "Configure the built-in fetch-based Resend driver."),
|
|
4804
|
+
dev: native("log", "Log", "`email: true` keeps each message in the development outbox and sends nothing. Set `email.driver` for a production build.", "process-local"),
|
|
4805
|
+
netlify: explicit("email.driver", "Resend", "Configure the built-in Resend driver."),
|
|
4806
|
+
node: explicit("email.driver", "Resend / SMTP / custom", "Configure Resend, `smtp` with the `nodemailer` package, or a driver module for another provider."),
|
|
4807
|
+
vercel: explicit("email.driver", "Resend", "Configure the built-in Resend driver.")
|
|
4808
|
+
},
|
|
4809
|
+
developmentOverrides: [
|
|
4810
|
+
"deno",
|
|
4811
|
+
"netlify",
|
|
4812
|
+
"vercel"
|
|
4813
|
+
],
|
|
4814
|
+
id: "email",
|
|
4815
|
+
packages: ["@vite-hub/email"],
|
|
4816
|
+
summary: "Send email from server code and Agents, with a development outbox.",
|
|
4817
|
+
title: "Email"
|
|
4818
|
+
}),
|
|
4819
|
+
env: feature({
|
|
4820
|
+
docs: "/docs/env",
|
|
4821
|
+
enabledByDefault: true,
|
|
4822
|
+
hosts: everywhere("nitro", "Nitro"),
|
|
4823
|
+
id: "env",
|
|
4824
|
+
summary: "Typed environment variables and secrets, validated at build and at runtime.",
|
|
4825
|
+
title: "Env"
|
|
4826
|
+
}),
|
|
4827
|
+
i18n: feature({
|
|
4828
|
+
docs: "/docs/i18n",
|
|
4829
|
+
hosts: everywhere("nitro", "Nitro 3", "Requires Nitro 3 with request async context: Nuxt 4.7 or newer with the nitro package, Nuxt 5, or Vite with Nitro 3. On Nuxt 4, use i18n without i18n.workspace. Nitro 2 and Nuxt before 4.7 are unsupported."),
|
|
4830
|
+
id: "i18n",
|
|
4831
|
+
packages: ["@vite-hub/i18n"],
|
|
4832
|
+
requiredOptions: [{
|
|
4833
|
+
option: "i18n.locales",
|
|
4834
|
+
detail: "Pass a nonempty JSON array of locale names or set locales in your I18n config."
|
|
4835
|
+
}],
|
|
4836
|
+
summary: "Messages with translation records for each locale and a locale for each request.",
|
|
4837
|
+
title: "I18n"
|
|
4838
|
+
}),
|
|
4839
|
+
kv: feature({
|
|
4840
|
+
developmentOverrides: ["netlify"],
|
|
4841
|
+
docs: "/docs/kv",
|
|
4842
|
+
hosts: {
|
|
4843
|
+
cloudflare: native("cloudflare", "Workers KV", "Cloudflare Workers KV binding."),
|
|
4844
|
+
deno: native("deno-kv", "Deno KV", "Native Deno KV through Deno.openKv()."),
|
|
4845
|
+
dev: native("fs-lite", "fs-lite", "Local filesystem-backed KV for development.", "single-host"),
|
|
4846
|
+
netlify: explicit("kv.driver", "Upstash / Redis", "Set `kv.driver` (or `kv.stores.default.driver` when using multiple stores) to `upstash`, `redis`, or `database`, or set Upstash REST credentials at build time. No Netlify-native KV output is provided. Without them, KV uses a Postgres Default Database, else `fs-lite` files that other function instances cannot read."),
|
|
4847
|
+
node: native("fs-lite", "Redis / Postgres / fs-lite", "A table in a Postgres Default Database, else local files. Redis requires kv: { driver: 'redis' }; REDIS_URL supplies its URL on every server. Upstash with REST credentials at build time.", "single-host"),
|
|
4848
|
+
vercel: native("upstash", "Upstash", "Upstash Redis with KV REST credentials.")
|
|
4849
|
+
},
|
|
4850
|
+
id: "kv",
|
|
4851
|
+
packages: ["@vite-hub/kv"],
|
|
4852
|
+
providerPackages: { driver: { upstash: ["@upstash/redis"] } },
|
|
4853
|
+
summary: "Key-value storage with one API on every host.",
|
|
4854
|
+
title: "KV"
|
|
4855
|
+
}),
|
|
4856
|
+
mcp: feature({
|
|
4857
|
+
docs: "/docs/mcp",
|
|
4858
|
+
hosts: everywhere("nitro", "Nitro"),
|
|
4859
|
+
id: "mcp",
|
|
4860
|
+
packages: ["@vite-hub/mcp"],
|
|
4861
|
+
requiredOptions: [{
|
|
4862
|
+
option: "mcp.auth",
|
|
4863
|
+
detail: "Choose an access mode when Auth is disabled. With Auth enabled, MCP requires sign-in by default. The optional mode requires Auth and lets anyone call public tools. Set false only when anyone may call every tool."
|
|
4864
|
+
}],
|
|
4865
|
+
summary: "The app's own MCP server, with one tool per file in `server/mcp/tools/`.",
|
|
4866
|
+
title: "MCP server"
|
|
4867
|
+
}),
|
|
4868
|
+
observability: feature({
|
|
4869
|
+
docs: "/docs/agents/observability",
|
|
4870
|
+
hosts: everywhere("evlog", "Evlog"),
|
|
4871
|
+
id: "observability",
|
|
4872
|
+
packages: ["evlog"],
|
|
4873
|
+
summary: "Request logs through Evlog, the logs that the Console reads, and Agent telemetry with a service name.",
|
|
4874
|
+
title: "Observability"
|
|
4875
|
+
}),
|
|
4876
|
+
queue: feature({
|
|
4877
|
+
definition: starter("server/queues", (name) => `import { defineQueue } from "vite-hub/queue"
|
|
4878
|
+
|
|
4879
|
+
export default defineQueue<{ id: string }>({
|
|
4880
|
+
handler: async ({ payload }) => {
|
|
4881
|
+
console.log("${name}", payload.id)
|
|
4882
|
+
},
|
|
4883
|
+
})
|
|
4884
|
+
`, { suffix: "queue" }),
|
|
4885
|
+
docs: "/docs/queue",
|
|
4886
|
+
enabledByDiscovery: ["queues"],
|
|
4887
|
+
hosts: {
|
|
4888
|
+
cloudflare: native("cloudflare", "Queues", "Cloudflare Queues bindings and consumers."),
|
|
4889
|
+
deno: unsupported("No Deno Queue driver is provided."),
|
|
4890
|
+
dev: native("local", "Local driver", "The local driver stores jobs in .vitehub/data/queue and runs them in the dev server process.", "single-host"),
|
|
4891
|
+
netlify: unsupported("Netlify has no Queue driver, so `vitehub({ queue })` fails on Netlify."),
|
|
4892
|
+
node: native("local", "Postgres / local driver", "With a Postgres Default Database, the postgres driver keeps jobs in Postgres and every instance runs them. Else the local driver keeps jobs on the disk of one host.", "single-host"),
|
|
4893
|
+
vercel: native("vercel", "Vercel Queues", "Vercel Queues callbacks and runtime client.")
|
|
4894
|
+
},
|
|
4895
|
+
id: "queue",
|
|
4896
|
+
packages: ["@vite-hub/queue"],
|
|
4897
|
+
providerPackages: { driver: { postgres: ["postgres"] } },
|
|
4898
|
+
service: "queue",
|
|
4899
|
+
summary: "Background jobs in `server/queues/` with retries and delivery on every supported host.",
|
|
4900
|
+
title: "Queue"
|
|
4901
|
+
}),
|
|
4902
|
+
rateLimit: feature({
|
|
4903
|
+
developmentOverrides: ["cloudflare"],
|
|
4904
|
+
docs: "/docs/rate-limit",
|
|
4905
|
+
hosts: {
|
|
4906
|
+
cloudflare: native("cloudflare", "Cloudflare", "Native Cloudflare Rate Limiting binding."),
|
|
4907
|
+
deno: unsupported("ViteHub has no native Deno Rate Limit driver."),
|
|
4908
|
+
dev: native("memory", "memory", "Process-local memory driver for development and tests.", "process-local"),
|
|
4909
|
+
netlify: unsupported("ViteHub has no native Netlify Rate Limit driver."),
|
|
4910
|
+
node: native("memory", "memory, or KV", "Without KV, each process counts alone. With KV on, ViteHub selects the kv provider, which shares the counts when KV uses Redis or a Postgres Database.", "process-local"),
|
|
4911
|
+
vercel: unsupported("ViteHub has no native Vercel Rate Limit driver.")
|
|
4912
|
+
},
|
|
4913
|
+
id: "rateLimit",
|
|
4914
|
+
packages: ["@vite-hub/rate-limit"],
|
|
4915
|
+
service: "rateLimit",
|
|
4916
|
+
summary: "Rate limits in `server/rate-limits/` that protect routes and Agent tools.",
|
|
4917
|
+
title: "Rate Limit"
|
|
4918
|
+
}),
|
|
4919
|
+
realtime: feature({
|
|
4920
|
+
definition: starter("server/realtime", (name) => `import { defineRealtime } from "vite-hub/realtime"
|
|
4921
|
+
|
|
4922
|
+
export default defineRealtime({
|
|
4923
|
+
authorize: true,
|
|
4924
|
+
document: { workspace: "${name}" },
|
|
4925
|
+
})
|
|
4926
|
+
`),
|
|
4927
|
+
developmentOverrides: [
|
|
4928
|
+
"cloudflare",
|
|
4929
|
+
"deno",
|
|
4930
|
+
"netlify",
|
|
4931
|
+
"vercel"
|
|
4932
|
+
],
|
|
4933
|
+
docs: "/docs/realtime",
|
|
4934
|
+
enabledByDiscovery: ["realtime"],
|
|
4935
|
+
hosts: {
|
|
4936
|
+
cloudflare: native("cloudflare", "Durable Objects", "Cloudflare Durable Objects run the production rooms."),
|
|
4937
|
+
deno: unsupported("Realtime has no distributed Deno driver, and process memory is rejected for the Deno host."),
|
|
4938
|
+
dev: native("memory", "memory", "Process-memory driver for local development.", "process-local"),
|
|
4939
|
+
netlify: unsupported("Realtime has no distributed Netlify driver, and process memory is rejected for the Netlify host."),
|
|
4940
|
+
node: native("node", "Postgres or Redis", "Each instance keeps its rooms in memory and shares them through Redis with REDIS_URL, else Postgres on a Postgres Default Database. Without either, rooms stay in one process."),
|
|
4941
|
+
vercel: unsupported("Realtime has no distributed Vercel driver, and process memory is rejected for the Vercel host.")
|
|
4942
|
+
},
|
|
4943
|
+
id: "realtime",
|
|
4944
|
+
packages: ["@vite-hub/realtime"],
|
|
4945
|
+
service: "realtime",
|
|
4946
|
+
summary: "Shared rooms with presence and Yjs documents.",
|
|
4947
|
+
title: "Realtime"
|
|
4948
|
+
}),
|
|
4949
|
+
sandboxTask: feature({
|
|
4950
|
+
docs: "/docs/sandbox",
|
|
4951
|
+
hosts: {
|
|
4952
|
+
cloudflare: native("cloudflare", "CF Sandbox", "Cloudflare Sandbox execution provider."),
|
|
4953
|
+
deno: unsupported("No Deno Sandbox driver is provided."),
|
|
4954
|
+
dev: unsupported("The default Node host has no Sandbox Provider. With the Cloudflare or Vercel host, `vite dev` runs each Sandbox Task as a process on this machine, with no isolation and no provider account. `sandboxTask: { remote: true }` uses the host's Sandbox instead."),
|
|
4955
|
+
netlify: explicit("sandboxTask.driver", "Vercel Sandbox", "The Netlify host has no Sandbox, so `sandboxTask: true` fails. Set `sandboxTask: { driver: \"vercel\" }` and Vercel credentials to use Vercel Sandbox."),
|
|
4956
|
+
node: explicit("sandboxTask.driver", "Vercel Sandbox", "The Node host has no Sandbox, so `sandboxTask: true` fails. Set `sandboxTask: { driver: \"vercel\" }` and Vercel credentials to use Vercel Sandbox."),
|
|
4957
|
+
vercel: native("vercel", "Vercel Sandbox", "Vercel Sandbox execution provider.")
|
|
4958
|
+
},
|
|
4959
|
+
id: "sandboxTask",
|
|
4960
|
+
packages: ["@vite-hub/sandbox"],
|
|
4961
|
+
service: "sandbox",
|
|
4962
|
+
summary: "Sandbox Tasks in `server/sandbox-tasks/`. Each run starts an isolated Cloudflare or Vercel Sandbox.",
|
|
4963
|
+
title: "Sandbox"
|
|
4964
|
+
}),
|
|
4965
|
+
schedule: feature({
|
|
4966
|
+
definition: starter("server/schedules", (name) => `import { defineSchedule } from "vite-hub/schedule"
|
|
4967
|
+
|
|
4968
|
+
export default defineSchedule({
|
|
4969
|
+
cron: "0 * * * *",
|
|
4970
|
+
handler: () => {
|
|
4971
|
+
console.log("${name}")
|
|
4972
|
+
},
|
|
4973
|
+
})
|
|
4974
|
+
`, { suffix: "schedule" }),
|
|
4975
|
+
developmentOverrides: [
|
|
4976
|
+
"cloudflare",
|
|
4977
|
+
"netlify",
|
|
4978
|
+
"vercel"
|
|
4979
|
+
],
|
|
4980
|
+
docs: "/docs/schedule",
|
|
4981
|
+
enabledByDiscovery: ["schedules"],
|
|
4982
|
+
hosts: {
|
|
4983
|
+
cloudflare: native("cloudflare", "Cron triggers", "Cloudflare scheduled events and Nitro Provider Wake."),
|
|
4984
|
+
deno: native("deno", "Deno.cron", "`Deno.cron` output that the generated `.output/main.ts` loads before the Nitro server."),
|
|
4985
|
+
dev: native("local", "Local / process", "Local development runner and the explicit process runtime.", "single-host"),
|
|
4986
|
+
netlify: native("netlify", "Scheduled fn", "One generated Netlify scheduled function per static Schedule."),
|
|
4987
|
+
node: native("process", "process", "Process runtime in the server process. `schedule: true` uses it. Set `providerOutput: false` to wake Schedules yourself. With a Postgres or remote libSQL Default Database, servers claim occurrences in `vitehub_leases`. A run can repeat if its lease expires. Without a shared lease store, run one server.", "single-host"),
|
|
4988
|
+
vercel: native("vercel", "Vercel Cron", "Vercel Cron Jobs provider output.")
|
|
4989
|
+
},
|
|
4990
|
+
id: "schedule",
|
|
4991
|
+
packages: ["@vite-hub/schedule"],
|
|
4992
|
+
summary: "Cron Schedules in `server/schedules/` that run on the host's scheduler.",
|
|
4993
|
+
title: "Schedule"
|
|
4994
|
+
}),
|
|
4995
|
+
workflow: feature({
|
|
4996
|
+
definition: starter("server/workflows", () => `import { defineWorkflow } from "vite-hub/workflow"
|
|
4997
|
+
|
|
4998
|
+
export default defineWorkflow<{ id: string }>({
|
|
4999
|
+
handler: async ({ payload }) => {
|
|
5000
|
+
return { id: payload.id }
|
|
5001
|
+
},
|
|
5002
|
+
})
|
|
5003
|
+
`, {
|
|
5004
|
+
folder: "index",
|
|
5005
|
+
suffix: "workflow"
|
|
5006
|
+
}),
|
|
5007
|
+
docs: "/docs/workflows",
|
|
5008
|
+
enabledByDiscovery: ["workflows"],
|
|
5009
|
+
hosts: {
|
|
5010
|
+
cloudflare: native("cloudflare", "CF Workflows", "Cloudflare Workflows provider."),
|
|
5011
|
+
deno: explicit("workflow.driver", "OpenWorkflow", "Set `workflow.driver` to \"openworkflow\" with `workflow.postgres.url`, and start its worker. A build without a driver fails."),
|
|
5012
|
+
dev: native("openworkflow", "OpenWorkflow", "The Node host runs OpenWorkflow and its worker in the dev server, on .vitehub/data/openworkflow.sqlite.db. workflow.remote lets it use the Postgres Default Database or OPENWORKFLOW_POSTGRES_URL."),
|
|
5013
|
+
netlify: explicit("workflow.driver", "OpenWorkflow", "Use OpenWorkflow explicitly. No Netlify-native Workflow driver is provided."),
|
|
5014
|
+
node: {
|
|
5015
|
+
...native("openworkflow", "OpenWorkflow", "OpenWorkflow is the default, and each server runs its worker. It uses OPENWORKFLOW_POSTGRES_URL or the Postgres Default Database. Without them, runs use a SQLite file on one host.", "single-host"),
|
|
5016
|
+
envOverrides: ["OPENWORKFLOW_POSTGRES_URL"].map((env) => ({
|
|
5017
|
+
env,
|
|
5018
|
+
support: native("openworkflow", "OpenWorkflow (Postgres)", `${env} selects Postgres. Several servers can run the worker on the same database, and each run executes once.`)
|
|
5019
|
+
}))
|
|
5020
|
+
},
|
|
5021
|
+
vercel: native("vercel", "Vercel Workflow", "Vercel Workflow provider and Workflow DevKit output.")
|
|
5022
|
+
},
|
|
5023
|
+
id: "workflow",
|
|
5024
|
+
packages: ["@vite-hub/workflow"],
|
|
5025
|
+
summary: "Durable Workflows in `server/workflows/` with steps and driver retries.",
|
|
5026
|
+
title: "Workflow"
|
|
5027
|
+
}),
|
|
5028
|
+
workspace: feature({
|
|
5029
|
+
developmentOverrides: [
|
|
5030
|
+
"cloudflare",
|
|
5031
|
+
"deno",
|
|
5032
|
+
"netlify",
|
|
5033
|
+
"vercel"
|
|
5034
|
+
],
|
|
5035
|
+
docs: "/docs/workspace",
|
|
5036
|
+
enabledByDiscovery: ["workspaces"],
|
|
5037
|
+
hosts: {
|
|
5038
|
+
cloudflare: native("memory", "Artifacts / GitHub", "Memory by default, or Cloudflare Artifacts beta and GitHub for durable state.", "process-local"),
|
|
5039
|
+
deno: explicit("workspace.store", "GitHub", "Select the GitHub Workspace Store explicitly for durable state."),
|
|
5040
|
+
dev: native("local", "local / memory", "Local filesystem or in-memory Workspace Store.", "single-host"),
|
|
5041
|
+
netlify: explicit("workspace.store", "GitHub", "Select the GitHub Workspace Store explicitly for durable state."),
|
|
5042
|
+
node: native("local", "local / GitHub", "Local filesystem, memory, or GitHub Workspace Store.", "single-host"),
|
|
5043
|
+
vercel: {
|
|
5044
|
+
...native("memory", "memory / Blob / GitHub", "Process-local memory by default. BLOB_READ_WRITE_TOKEN selects Vercel Blob; GitHub can be selected explicitly for durable state.", "process-local"),
|
|
5045
|
+
envOverrides: [{
|
|
5046
|
+
env: "BLOB_READ_WRITE_TOKEN",
|
|
5047
|
+
support: native("vercel", "Blob / GitHub", "BLOB_READ_WRITE_TOKEN selects durable Vercel Blob storage by default.")
|
|
5048
|
+
}]
|
|
5049
|
+
}
|
|
5050
|
+
},
|
|
5051
|
+
id: "workspace",
|
|
5052
|
+
packages: ["@vite-hub/workspace"],
|
|
5053
|
+
summary: "File workspaces that Agents read and edit, backed by local, Blob, or GitHub stores.",
|
|
5054
|
+
title: "Workspace"
|
|
5055
|
+
})
|
|
5056
|
+
};
|
|
5057
|
+
// src/shared/package-json.ts
|
|
5058
|
+
const sections$1 = ["dependencies", "devDependencies"];
|
|
5059
|
+
function isRecord$6(value) {
|
|
4573
5060
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4574
5061
|
}
|
|
4575
5062
|
function isDependencyMap(value) {
|
|
4576
|
-
return isRecord$
|
|
5063
|
+
return isRecord$6(value) && Object.values(value).every((entry) => typeof entry === "string");
|
|
4577
5064
|
}
|
|
4578
5065
|
function detectInstallCommand(cwd) {
|
|
4579
5066
|
for (let directory = cwd, depth = 0; depth < 8; depth++) {
|
|
@@ -4587,7 +5074,12 @@ function detectInstallCommand(cwd) {
|
|
|
4587
5074
|
}
|
|
4588
5075
|
return "npm install";
|
|
4589
5076
|
}
|
|
4590
|
-
|
|
5077
|
+
function featurePackageSpecifier(name, viteHub) {
|
|
5078
|
+
if (validRange(viteHub) !== null) return viteHub;
|
|
5079
|
+
const preview = /^(?<base>https:\/\/pkg\.pr\.new(?:\/vite-hub\/vitehub)?)\/vite-hub@(?<ref>[^/?#]+)$/.exec(viteHub)?.groups;
|
|
5080
|
+
if (preview) return `${preview.base}/${name}@${preview.ref}`;
|
|
5081
|
+
throw codemodError(`Cannot match ${name} to vite-hub@${viteHub}. Update vite-hub in package.json to a version, a version range, or a pkg.pr.new preview from vite-hub/vitehub, then run the codemod again.`);
|
|
5082
|
+
}
|
|
4591
5083
|
function outside(range, supported) {
|
|
4592
5084
|
return validRange(range) !== null && !subset(range, supported, { includePrerelease: true });
|
|
4593
5085
|
}
|
|
@@ -4598,7 +5090,14 @@ function outside(range, supported) {
|
|
|
4598
5090
|
async function editPackageJson(cwd, version, change) {
|
|
4599
5091
|
const path = join(cwd, "package.json");
|
|
4600
5092
|
const command = detectInstallCommand(cwd);
|
|
4601
|
-
|
|
5093
|
+
const owners = new Set((change.features ?? []).flatMap((id) => features[id].packages).filter((name) => name.startsWith("@vite-hub/")));
|
|
5094
|
+
const add = /* @__PURE__ */ new Set([...change.add, ...owners]);
|
|
5095
|
+
const names = new Set(add);
|
|
5096
|
+
const installList = new Intl.ListFormat("en", { type: "conjunction" });
|
|
5097
|
+
if (!existsSync(path)) return {
|
|
5098
|
+
installCommand: command,
|
|
5099
|
+
installs: installList.format(names)
|
|
5100
|
+
};
|
|
4602
5101
|
const before = await readFile(path, "utf8");
|
|
4603
5102
|
let manifest;
|
|
4604
5103
|
try {
|
|
@@ -4606,12 +5105,14 @@ async function editPackageJson(cwd, version, change) {
|
|
|
4606
5105
|
} catch (error) {
|
|
4607
5106
|
throw codemodError(`Cannot parse package.json: ${error instanceof Error ? error.message : String(error)}`);
|
|
4608
5107
|
}
|
|
4609
|
-
if (!isRecord$
|
|
5108
|
+
if (!isRecord$6(manifest)) throw codemodError("package.json must contain an object.");
|
|
4610
5109
|
const range = `^${version}`;
|
|
5110
|
+
let viteHub;
|
|
4611
5111
|
let target = "dependencies";
|
|
4612
|
-
for (const section of sections) {
|
|
5112
|
+
for (const section of sections$1) {
|
|
4613
5113
|
const dependencies = manifest[section];
|
|
4614
5114
|
if (dependencies !== void 0 && !isDependencyMap(dependencies)) throw codemodError(`package.json ${section} must map names to version strings.`);
|
|
5115
|
+
viteHub ??= dependencies?.["vite-hub"];
|
|
4615
5116
|
if (dependencies && change.remove.some((name) => name in dependencies)) {
|
|
4616
5117
|
target = section;
|
|
4617
5118
|
manifest[section] = Object.fromEntries(Object.entries(dependencies).filter(([name]) => !change.remove.includes(name)));
|
|
@@ -4619,19 +5120,23 @@ async function editPackageJson(cwd, version, change) {
|
|
|
4619
5120
|
}
|
|
4620
5121
|
const current = manifest[target];
|
|
4621
5122
|
const dependencies = isDependencyMap(current) ? { ...current } : {};
|
|
4622
|
-
const installed = (name) => sections.some((section) => {
|
|
5123
|
+
const installed = (name) => sections$1.some((section) => {
|
|
4623
5124
|
const map = manifest[section];
|
|
4624
5125
|
return isDependencyMap(map) && name in map;
|
|
4625
5126
|
});
|
|
4626
|
-
for (const name of
|
|
5127
|
+
for (const name of add) if (!installed(name)) dependencies[name] = owners.has(name) && viteHub !== void 0 ? featurePackageSpecifier(name, viteHub) : range;
|
|
4627
5128
|
for (const [name, supported] of Object.entries(change.within ?? {})) {
|
|
4628
5129
|
if (!installed(name)) {
|
|
4629
5130
|
dependencies[name] = supported;
|
|
5131
|
+
names.add(name);
|
|
4630
5132
|
continue;
|
|
4631
5133
|
}
|
|
4632
|
-
for (const section of sections) {
|
|
5134
|
+
for (const section of sections$1) {
|
|
4633
5135
|
const map = section === target ? dependencies : manifest[section];
|
|
4634
|
-
if (isDependencyMap(map) && typeof map[name] === "string" && outside(map[name], supported))
|
|
5136
|
+
if (isDependencyMap(map) && typeof map[name] === "string" && outside(map[name], supported)) {
|
|
5137
|
+
map[name] = supported;
|
|
5138
|
+
names.add(name);
|
|
5139
|
+
}
|
|
4635
5140
|
}
|
|
4636
5141
|
}
|
|
4637
5142
|
manifest[target] = Object.fromEntries(Object.entries(dependencies).sort(([left], [right]) => left.localeCompare(right)));
|
|
@@ -4643,19 +5148,18 @@ async function editPackageJson(cwd, version, change) {
|
|
|
4643
5148
|
before,
|
|
4644
5149
|
after
|
|
4645
5150
|
},
|
|
4646
|
-
installCommand: command
|
|
5151
|
+
installCommand: command,
|
|
5152
|
+
installs: installList.format(names)
|
|
4647
5153
|
};
|
|
4648
5154
|
}
|
|
4649
|
-
|
|
4650
|
-
//#region src/shared/removed-module.ts
|
|
5155
|
+
// src/shared/removed-module.ts
|
|
4651
5156
|
function assertModuleRemoved(file, code, ...packages) {
|
|
4652
5157
|
walk(parseProgram(code, { typescript: !/\.m?js$/.test(file) }), (node) => {
|
|
4653
5158
|
const text = node.type === "StringLiteral" ? node.value : node.type === "TemplateElement" ? node.value.cooked : void 0;
|
|
4654
5159
|
if (text && packages.some((name) => text === name || text.startsWith(`${name}/`))) throw codemodError(`${file}:${line(node)}: Remove the remaining ${text} reference before migrating.`);
|
|
4655
5160
|
});
|
|
4656
5161
|
}
|
|
4657
|
-
|
|
4658
|
-
//#region src/docus/content.ts
|
|
5162
|
+
// src/docus/content.ts
|
|
4659
5163
|
const pageFields = /* @__PURE__ */ new Set([
|
|
4660
5164
|
"title",
|
|
4661
5165
|
"description",
|
|
@@ -4863,8 +5367,7 @@ function moveSection(file, code, order) {
|
|
|
4863
5367
|
followUps
|
|
4864
5368
|
};
|
|
4865
5369
|
}
|
|
4866
|
-
|
|
4867
|
-
//#region src/docus/index.ts
|
|
5370
|
+
// src/docus/index.ts
|
|
4868
5371
|
const layerName = "docus";
|
|
4869
5372
|
const docsModule = "@vite-hub/docs/nuxt";
|
|
4870
5373
|
/** `@vite-hub/docs` peers, at the ranges it supports. `nuxt` and `vue` stay as the app has them. */
|
|
@@ -5289,8 +5792,7 @@ const docus = {
|
|
|
5289
5792
|
detect: detect$2,
|
|
5290
5793
|
run: migrate$21
|
|
5291
5794
|
};
|
|
5292
|
-
|
|
5293
|
-
//#region src/shared/config-imports.ts
|
|
5795
|
+
// src/shared/config-imports.ts
|
|
5294
5796
|
const extensions = [
|
|
5295
5797
|
".ts",
|
|
5296
5798
|
".mts",
|
|
@@ -5506,8 +6008,7 @@ function optionsAt(program, positions) {
|
|
|
5506
6008
|
});
|
|
5507
6009
|
return options;
|
|
5508
6010
|
}
|
|
5509
|
-
|
|
5510
|
-
//#region src/vitehub-options/transform.ts
|
|
6011
|
+
// src/vitehub-options/transform.ts
|
|
5511
6012
|
/** Top-level Vite keys that owner plugins read before `vitehub()` became the only config place. */
|
|
5512
6013
|
const removedViteKeys = [
|
|
5513
6014
|
"agent",
|
|
@@ -5941,8 +6442,7 @@ function migrateViteHubOptions(file, code, findOptions) {
|
|
|
5941
6442
|
notes
|
|
5942
6443
|
} : unchanged;
|
|
5943
6444
|
}
|
|
5944
|
-
|
|
5945
|
-
//#region src/driver-key/index.ts
|
|
6445
|
+
// src/driver-key/index.ts
|
|
5946
6446
|
/** The old key that picked the backend of a feature. The new key is always `driver`. */
|
|
5947
6447
|
const renamedKeys$1 = {
|
|
5948
6448
|
queue: "provider",
|
|
@@ -6323,8 +6823,7 @@ const driverKey = {
|
|
|
6323
6823
|
},
|
|
6324
6824
|
run: migrate$20
|
|
6325
6825
|
};
|
|
6326
|
-
|
|
6327
|
-
//#region src/kv-list-prefix/index.ts
|
|
6826
|
+
// src/kv-list-prefix/index.ts
|
|
6328
6827
|
const sourcePatterns$11 = ["**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,vue}"];
|
|
6329
6828
|
const ignoredPatterns$11 = [
|
|
6330
6829
|
"**/node_modules/**",
|
|
@@ -6494,8 +6993,7 @@ const kvListPrefix = {
|
|
|
6494
6993
|
},
|
|
6495
6994
|
run: migrate$19
|
|
6496
6995
|
};
|
|
6497
|
-
|
|
6498
|
-
//#region src/nuxt-better-auth/call-sites.ts
|
|
6996
|
+
// src/nuxt-better-auth/call-sites.ts
|
|
6499
6997
|
/** Server helpers of the module with no ViteHub helper of the same shape. */
|
|
6500
6998
|
const serverFollowUps = {
|
|
6501
6999
|
ensureServerAuth: "ViteHub Auth has no ensureServerAuth(). Use useAuth(event) in a request, or getAuth() outside one.",
|
|
@@ -6604,10 +7102,9 @@ function clientFollowUpsFor(file, code) {
|
|
|
6604
7102
|
});
|
|
6605
7103
|
return followUps;
|
|
6606
7104
|
}
|
|
6607
|
-
|
|
6608
|
-
//#region src/nuxt-better-auth/definitions.ts
|
|
7105
|
+
// src/nuxt-better-auth/definitions.ts
|
|
6609
7106
|
const moduleConfigSource = "@nuxtjs/better-auth/config";
|
|
6610
|
-
function parse$
|
|
7107
|
+
function parse$4(file, code) {
|
|
6611
7108
|
try {
|
|
6612
7109
|
return parseProgram(code, { typescript: !/\.[cm]?js$/.test(file) });
|
|
6613
7110
|
} catch {
|
|
@@ -6693,7 +7190,7 @@ function moveServerDefinition(input) {
|
|
|
6693
7190
|
...node ? { line: line(node) } : {},
|
|
6694
7191
|
message
|
|
6695
7192
|
});
|
|
6696
|
-
const program = parse$
|
|
7193
|
+
const program = parse$4(file, code);
|
|
6697
7194
|
if (!program) {
|
|
6698
7195
|
follow(void 0, "The codemod could not parse this file. Move it to server/auth.ts with defineAuth() from vite-hub/auth by hand.");
|
|
6699
7196
|
return {
|
|
@@ -6835,7 +7332,7 @@ function moveClientDefinition(file, code) {
|
|
|
6835
7332
|
...node ? { line: line(node) } : {},
|
|
6836
7333
|
message
|
|
6837
7334
|
});
|
|
6838
|
-
const program = parse$
|
|
7335
|
+
const program = parse$4(file, code);
|
|
6839
7336
|
if (!program) {
|
|
6840
7337
|
follow(void 0, "The codemod could not parse this file. Move the client plugins to app/auth.client.ts with defineAuthClient() from vite-hub/auth/vue by hand.");
|
|
6841
7338
|
return {
|
|
@@ -6870,8 +7367,7 @@ function moveClientDefinition(file, code) {
|
|
|
6870
7367
|
moved: true
|
|
6871
7368
|
};
|
|
6872
7369
|
}
|
|
6873
|
-
|
|
6874
|
-
//#region src/nuxt-better-auth/pages.ts
|
|
7370
|
+
// src/nuxt-better-auth/pages.ts
|
|
6875
7371
|
/** Source text of the ViteHub page meta for a module `auth` value, and what it drops. */
|
|
6876
7372
|
function pageMeta(code, node, style) {
|
|
6877
7373
|
const value = unwrapExpression(node);
|
|
@@ -7020,8 +7516,7 @@ function editPage(file, source, rule, style, typescript) {
|
|
|
7020
7516
|
followUps
|
|
7021
7517
|
};
|
|
7022
7518
|
}
|
|
7023
|
-
|
|
7024
|
-
//#region src/nuxt-better-auth/index.ts
|
|
7519
|
+
// src/nuxt-better-auth/index.ts
|
|
7025
7520
|
const moduleName$6 = "@nuxtjs/better-auth";
|
|
7026
7521
|
/** The Better Auth range that ViteHub Auth supports. */
|
|
7027
7522
|
const betterAuthRange = "^1.7.15";
|
|
@@ -7440,7 +7935,8 @@ async function migrate$18({ cwd }) {
|
|
|
7440
7935
|
});
|
|
7441
7936
|
const packageResult = await editPackageJson(cwd, version, {
|
|
7442
7937
|
remove: [moduleName$6],
|
|
7443
|
-
add: ["vite-hub"
|
|
7938
|
+
add: ["vite-hub"],
|
|
7939
|
+
features: ["auth"],
|
|
7444
7940
|
within: { "better-auth": betterAuthRange }
|
|
7445
7941
|
});
|
|
7446
7942
|
if (packageResult.edit) edits.push(packageResult.edit);
|
|
@@ -7449,10 +7945,11 @@ async function migrate$18({ cwd }) {
|
|
|
7449
7945
|
return {
|
|
7450
7946
|
summary: `moved ${servers} Auth config${servers === 1 ? "" : "s"} to server/auth.ts and ${pageRules.length} auth route rule${pageRules.length === 1 ? "" : "s"} to page meta${host ? `, host "${host}"` : ""}.`,
|
|
7451
7947
|
edits,
|
|
7948
|
+
requiresNitro3: true,
|
|
7452
7949
|
followUps,
|
|
7453
7950
|
notes,
|
|
7454
7951
|
nextSteps: [
|
|
7455
|
-
`Run \`${packageResult.installCommand}\` to install
|
|
7952
|
+
`Run \`${packageResult.installCommand}\` to install ${packageResult.installs} and remove ${moduleName$6}.`,
|
|
7456
7953
|
"Run `npx nuxi prepare`, then type-check the app.",
|
|
7457
7954
|
"Sign up, sign in, and open a guarded page to check the migration."
|
|
7458
7955
|
]
|
|
@@ -7476,8 +7973,7 @@ const nuxtBetterAuth = {
|
|
|
7476
7973
|
detect: detect$1,
|
|
7477
7974
|
run: migrate$18
|
|
7478
7975
|
};
|
|
7479
|
-
|
|
7480
|
-
//#region src/nuxt-content/index.ts
|
|
7976
|
+
// src/nuxt-content/index.ts
|
|
7481
7977
|
const moduleName$5 = "@nuxt/content";
|
|
7482
7978
|
const ignored$5 = [
|
|
7483
7979
|
"**/node_modules/**",
|
|
@@ -7743,6 +8239,7 @@ async function migrate$17({ cwd }) {
|
|
|
7743
8239
|
return {
|
|
7744
8240
|
summary: `moved ${collections.length} collection${collections.length === 1 ? "" : "s"} from ${file} to ${target}${added.host ? `, host "${added.host}"` : ""}.`,
|
|
7745
8241
|
edits,
|
|
8242
|
+
requiresNitro3: true,
|
|
7746
8243
|
followUps,
|
|
7747
8244
|
notes: ["Each collection became a read-only glob() Source with the same files and paths. Content serves them at /api/content and reads them with content.get(path) and content.list().", `The codemod does not rewrite queryCollection() calls or <ContentRenderer>: the read API differs. See ${guide$1}.`],
|
|
7748
8245
|
nextSteps: [`Run \`${packageResult.installCommand}\` to install vite-hub and @vite-hub/content and remove ${moduleName$5}.`, "Run `npx nuxi prepare`, then replace the reads that the report lists."]
|
|
@@ -7759,8 +8256,7 @@ const nuxtContent = {
|
|
|
7759
8256
|
},
|
|
7760
8257
|
run: migrate$17
|
|
7761
8258
|
};
|
|
7762
|
-
|
|
7763
|
-
//#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
8259
|
+
// ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
7764
8260
|
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
7765
8261
|
function normalizeWindowsPath(input = "") {
|
|
7766
8262
|
if (!input) return input;
|
|
@@ -7851,8 +8347,7 @@ const relative$1 = function(from, to) {
|
|
|
7851
8347
|
}
|
|
7852
8348
|
return [..._from.map(() => ".."), ..._to].join("/");
|
|
7853
8349
|
};
|
|
7854
|
-
|
|
7855
|
-
//#region ../internal/dist/definition-catalog.js
|
|
8350
|
+
// ../internal/dist/definition-catalog.js
|
|
7856
8351
|
const sourceFilePattern = /\.(?:c|m)?[jt]sx?$/i;
|
|
7857
8352
|
const declarationFilePattern = /\.d\.(?:c|m)?[jt]sx?$/i;
|
|
7858
8353
|
const testFilePattern = /\.(?:test|spec)\.(?:c|m)?[jt]sx?$/i;
|
|
@@ -7902,8 +8397,7 @@ function listSourceFiles(root, options = {}) {
|
|
|
7902
8397
|
function normalizePathDefinitionName(rootDir, file) {
|
|
7903
8398
|
return relative$1(rootDir, file).replace(sourceFilePattern, "").replace(/\/index$/i, "");
|
|
7904
8399
|
}
|
|
7905
|
-
|
|
7906
|
-
//#region src/nuxt-cron/index.ts
|
|
8400
|
+
// src/nuxt-cron/index.ts
|
|
7907
8401
|
const moduleName$4 = "nuxt-cron";
|
|
7908
8402
|
/** nuxt-cron presets, from its runtime. `everySecond` has six fields, which Schedule cannot run. */
|
|
7909
8403
|
const cronPresets = {
|
|
@@ -8160,7 +8654,8 @@ async function migrate$16({ cwd }) {
|
|
|
8160
8654
|
});
|
|
8161
8655
|
const packageResult = await editPackageJson(cwd, version, {
|
|
8162
8656
|
remove: kept ? [] : [moduleName$4],
|
|
8163
|
-
add: ["vite-hub"]
|
|
8657
|
+
add: ["vite-hub"],
|
|
8658
|
+
features: processDriver ? ["schedule", "kv"] : ["schedule"]
|
|
8164
8659
|
});
|
|
8165
8660
|
edits.unshift({
|
|
8166
8661
|
path: config.fileName,
|
|
@@ -8173,9 +8668,10 @@ async function migrate$16({ cwd }) {
|
|
|
8173
8668
|
return {
|
|
8174
8669
|
summary: `moved ${migrated} cron job${migrated === 1 ? "" : "s"} from ${jobsDirectory} to server/schedules${added ? `, host "${added}"` : ""}.`,
|
|
8175
8670
|
edits,
|
|
8671
|
+
requiresNitro3: true,
|
|
8176
8672
|
followUps: [...configFollowUps, ...followUps],
|
|
8177
8673
|
notes,
|
|
8178
|
-
nextSteps: [`Run \`${packageResult.installCommand}\` to install
|
|
8674
|
+
nextSteps: [`Run \`${packageResult.installCommand}\` to install ${packageResult.installs}${kept ? "" : ` and remove ${moduleName$4}`}.`, "Run `npx nuxi prepare`, then type-check the app."]
|
|
8179
8675
|
};
|
|
8180
8676
|
}
|
|
8181
8677
|
const nuxtCron = {
|
|
@@ -8185,14 +8681,12 @@ const nuxtCron = {
|
|
|
8185
8681
|
detect: ({ cwd }) => detectNuxtModule(cwd, moduleName$4, ["cron"]),
|
|
8186
8682
|
run: migrate$16
|
|
8187
8683
|
};
|
|
8188
|
-
|
|
8189
|
-
//#region ../internal/dist/object.js
|
|
8684
|
+
// ../internal/dist/object.js
|
|
8190
8685
|
/** A non-null object that is not an array. Functions do not pass. */
|
|
8191
|
-
function isRecord$
|
|
8686
|
+
function isRecord$5(value) {
|
|
8192
8687
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8193
8688
|
}
|
|
8194
|
-
|
|
8195
|
-
//#region src/nuxt-safe-runtime-config/fields.ts
|
|
8689
|
+
// src/nuxt-safe-runtime-config/fields.ts
|
|
8196
8690
|
/** Nuxt's rule: `NUXT_` and the upper snake case path. Public paths start with `PUBLIC`. */
|
|
8197
8691
|
function nuxtVariableName(section, configPath) {
|
|
8198
8692
|
const path = section === "public" ? ["public", ...configPath] : configPath;
|
|
@@ -8249,8 +8743,7 @@ function looksSecret(path) {
|
|
|
8249
8743
|
function pathLabel(field) {
|
|
8250
8744
|
return [...field.section === "public" ? ["public"] : [], ...field.configPath].join(".");
|
|
8251
8745
|
}
|
|
8252
|
-
|
|
8253
|
-
//#region src/nuxt-safe-runtime-config/call-sites.ts
|
|
8746
|
+
// src/nuxt-safe-runtime-config/call-sites.ts
|
|
8254
8747
|
const serverImport$1 = "vite-hub/env";
|
|
8255
8748
|
const publicImport$1 = "#vitehub/env/public";
|
|
8256
8749
|
function classify$1(file) {
|
|
@@ -8879,8 +9372,7 @@ async function rewriteCallSites(input) {
|
|
|
8879
9372
|
}
|
|
8880
9373
|
return result;
|
|
8881
9374
|
}
|
|
8882
|
-
|
|
8883
|
-
//#region src/nuxt-safe-runtime-config/nuxt-config.ts
|
|
9375
|
+
// src/nuxt-safe-runtime-config/nuxt-config.ts
|
|
8884
9376
|
const moduleName$3 = "nuxt-safe-runtime-config";
|
|
8885
9377
|
function readStaticPaths(node) {
|
|
8886
9378
|
if (!node) return {};
|
|
@@ -8896,7 +9388,7 @@ function readStaticPaths(node) {
|
|
|
8896
9388
|
}
|
|
8897
9389
|
return paths;
|
|
8898
9390
|
}
|
|
8899
|
-
/** Reads
|
|
9391
|
+
/** Reads the schema and validation options without running code. */
|
|
8900
9392
|
function readStaticOptions(options) {
|
|
8901
9393
|
const result = {
|
|
8902
9394
|
inlineSchema: false,
|
|
@@ -8914,6 +9406,12 @@ function readStaticOptions(options) {
|
|
|
8914
9406
|
continue;
|
|
8915
9407
|
}
|
|
8916
9408
|
const key = keyName(property.key, property.computed);
|
|
9409
|
+
if (key === "onError" || key === "validateAtBuild" || key === "validateAtRuntime") {
|
|
9410
|
+
const value = literalValue(property.value);
|
|
9411
|
+
if (key === "onError" && typeof value === "string") result.onError = value;
|
|
9412
|
+
else if (key !== "onError" && typeof value === "boolean") result[key] = value;
|
|
9413
|
+
else result.dynamic = true;
|
|
9414
|
+
}
|
|
8917
9415
|
if (key === "envSchema") {
|
|
8918
9416
|
const literal = literalValue(property.value);
|
|
8919
9417
|
const value = unwrapExpression(property.value);
|
|
@@ -9019,8 +9517,7 @@ async function loadSchemaModule(cwd, specifier) {
|
|
|
9019
9517
|
throw codemodError(`Cannot load the $schema module ${specifier}: ${error instanceof Error ? error.message : String(error)}`);
|
|
9020
9518
|
}
|
|
9021
9519
|
}
|
|
9022
|
-
|
|
9023
|
-
//#region src/nuxt-safe-runtime-config/config-edit.ts
|
|
9520
|
+
// src/nuxt-safe-runtime-config/config-edit.ts
|
|
9024
9521
|
function declarationCode(field, envName, style) {
|
|
9025
9522
|
const options = [];
|
|
9026
9523
|
if (field.default !== void 0) options.push(`default: ${literal(field.default, style)}`);
|
|
@@ -9122,8 +9619,7 @@ function editNuxtConfig(input) {
|
|
|
9122
9619
|
lineOf: createLineResolver(code)
|
|
9123
9620
|
};
|
|
9124
9621
|
}
|
|
9125
|
-
|
|
9126
|
-
//#region src/nuxt-safe-runtime-config/env-file.ts
|
|
9622
|
+
// src/nuxt-safe-runtime-config/env-file.ts
|
|
9127
9623
|
/**
|
|
9128
9624
|
* Reads the keys and sensitivity of an env-spec `.env.example`. The build validates the whole file with `envSchema()`;
|
|
9129
9625
|
* the codemod needs only names and sensitivity to rewrite call sites.
|
|
@@ -9210,19 +9706,123 @@ function planFromEnvFile(keys, nuxtPaths, file) {
|
|
|
9210
9706
|
}
|
|
9211
9707
|
return plan;
|
|
9212
9708
|
}
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9709
|
+
// src/nuxt-safe-runtime-config/field-schema.ts
|
|
9710
|
+
function isFieldSchema(value) {
|
|
9711
|
+
const standard = isRecord$5(value) ? value["~standard"] : void 0;
|
|
9712
|
+
return isRecord$5(standard) && typeof standard.vendor === "string" && typeof standard.validate === "function";
|
|
9713
|
+
}
|
|
9714
|
+
function valibotObject(schema, seen = /* @__PURE__ */ new Set()) {
|
|
9715
|
+
if (seen.has(schema)) return void 0;
|
|
9716
|
+
seen.add(schema);
|
|
9717
|
+
if (isRecord$5(schema.entries)) return schema.entries;
|
|
9718
|
+
const inner = schema.type === "lazy" && typeof schema.getter === "function" ? Reflect.apply(schema.getter, schema, [void 0]) : schema.wrapped;
|
|
9719
|
+
return isRecord$5(inner) ? valibotObject(inner, seen) : void 0;
|
|
9720
|
+
}
|
|
9721
|
+
function zodObject(schema, seen = /* @__PURE__ */ new Set()) {
|
|
9722
|
+
if (seen.has(schema)) return void 0;
|
|
9723
|
+
seen.add(schema);
|
|
9724
|
+
const definition = isRecord$5(schema._zod) && isRecord$5(schema._zod.def) ? schema._zod.def : void 0;
|
|
9725
|
+
if (!definition) return void 0;
|
|
9726
|
+
if (definition.type === "object" && isRecord$5(definition.shape)) return definition.shape;
|
|
9727
|
+
let inner = definition.type === "pipe" ? definition.in : definition.innerType;
|
|
9728
|
+
if (definition.type === "lazy" && typeof definition.getter === "function") inner = Reflect.apply(definition.getter, definition, []);
|
|
9729
|
+
return isRecord$5(inner) ? zodObject(inner, seen) : void 0;
|
|
9730
|
+
}
|
|
9731
|
+
const zod3Wrappers = {
|
|
9732
|
+
ZodBranded: "type",
|
|
9733
|
+
ZodCatch: "innerType",
|
|
9734
|
+
ZodDefault: "innerType",
|
|
9735
|
+
ZodEffects: "schema",
|
|
9736
|
+
ZodNullable: "innerType",
|
|
9737
|
+
ZodOptional: "innerType",
|
|
9738
|
+
ZodPipeline: "in",
|
|
9739
|
+
ZodReadonly: "innerType"
|
|
9740
|
+
};
|
|
9741
|
+
function zod3Object(schema) {
|
|
9742
|
+
const definition = isRecord$5(schema._def) && typeof schema._def.typeName === "string" ? schema._def : void 0;
|
|
9743
|
+
if (!definition) return void 0;
|
|
9744
|
+
if (definition.typeName === "ZodObject") {
|
|
9745
|
+
const shape = typeof definition.shape === "function" ? Reflect.apply(definition.shape, definition, []) : definition.shape;
|
|
9746
|
+
return isRecord$5(shape) ? shape : void 0;
|
|
9747
|
+
}
|
|
9748
|
+
const inner = zod3Wrappers[String(definition.typeName)];
|
|
9749
|
+
const wrapped = inner ? definition[inner] : void 0;
|
|
9750
|
+
return isRecord$5(wrapped) ? zod3Object(wrapped) : void 0;
|
|
9751
|
+
}
|
|
9752
|
+
function childSchema(schema, key) {
|
|
9753
|
+
const vendor = isFieldSchema(schema) ? schema["~standard"].vendor : void 0;
|
|
9754
|
+
const entries = vendor === "valibot" ? valibotObject(schema) : vendor === "zod" ? zodObject(schema) ?? zod3Object(schema) : void 0;
|
|
9755
|
+
return entries && Object.hasOwn(entries, key) ? entries[key] : void 0;
|
|
9756
|
+
}
|
|
9757
|
+
/**
|
|
9758
|
+
* The Standard Schema of one `runtimeConfig` field in the `$schema` object, by its path in `runtimeConfig`,
|
|
9759
|
+
* such as `["public", "apiBase"]`. Returns `undefined` when the vendor's object shape cannot be read.
|
|
9760
|
+
*/
|
|
9761
|
+
function fieldSchema(schema, path) {
|
|
9762
|
+
let current = schema;
|
|
9763
|
+
for (const key of path) current = isRecord$5(current) ? childSchema(current, key) : void 0;
|
|
9764
|
+
return isFieldSchema(current) ? current : void 0;
|
|
9765
|
+
}
|
|
9766
|
+
async function standardRejection(schema, value) {
|
|
9767
|
+
try {
|
|
9768
|
+
const result = await schema["~standard"].validate(value);
|
|
9769
|
+
if (!isRecord$5(result)) return void 0;
|
|
9770
|
+
if (!Array.isArray(result.issues) || !result.issues.length) return false;
|
|
9771
|
+
const issue = result.issues[0];
|
|
9772
|
+
return isRecord$5(issue) && typeof issue.message === "string" && issue.message ? issue.message : "the value is not valid";
|
|
9773
|
+
} catch {
|
|
9774
|
+
return;
|
|
9775
|
+
}
|
|
9776
|
+
}
|
|
9777
|
+
const formatPatterns = {
|
|
9778
|
+
email: /^[^\s@]+@[^\s@]+$/,
|
|
9779
|
+
uuid: /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i
|
|
9780
|
+
};
|
|
9781
|
+
function stringRejection(node, value) {
|
|
9782
|
+
const length = [...value].length;
|
|
9783
|
+
if (typeof node.minLength === "number" && length < node.minLength) return `minimum length ${node.minLength}`;
|
|
9784
|
+
if (typeof node.maxLength === "number" && length > node.maxLength) return `maximum length ${node.maxLength}`;
|
|
9785
|
+
if (typeof node.pattern === "string") try {
|
|
9786
|
+
if (!new RegExp(node.pattern, "u").test(value)) return `the pattern ${node.pattern}`;
|
|
9787
|
+
} catch {}
|
|
9788
|
+
if (typeof node.format === "string") {
|
|
9789
|
+
const format = node.format;
|
|
9790
|
+
if (!(format === "uri" || format === "url" ? URL.canParse(value) : formatPatterns[format]?.test(value) ?? value !== "")) return `the ${format === "uri" || format === "url" ? "URL" : format} format`;
|
|
9791
|
+
}
|
|
9792
|
+
}
|
|
9793
|
+
function provesNotMultiple(value, divisor) {
|
|
9794
|
+
return Number.isSafeInteger(value) && Number.isSafeInteger(divisor) && divisor > 0 && value % divisor !== 0;
|
|
9795
|
+
}
|
|
9796
|
+
function numberRejection(node, value) {
|
|
9797
|
+
if (node.type === "integer" && !Number.isInteger(value)) return "the integer rule";
|
|
9798
|
+
if (typeof node.minimum === "number" && value < node.minimum) return `minimum ${node.minimum}`;
|
|
9799
|
+
if (typeof node.maximum === "number" && value > node.maximum) return `maximum ${node.maximum}`;
|
|
9800
|
+
if (typeof node.exclusiveMinimum === "number" && value <= node.exclusiveMinimum) return `exclusive minimum ${node.exclusiveMinimum}`;
|
|
9801
|
+
if (typeof node.exclusiveMaximum === "number" && value >= node.exclusiveMaximum) return `exclusive maximum ${node.exclusiveMaximum}`;
|
|
9802
|
+
if (typeof node.multipleOf === "number" && provesNotMultiple(value, node.multipleOf)) return `multiple of ${node.multipleOf}`;
|
|
9803
|
+
}
|
|
9804
|
+
/**
|
|
9805
|
+
* Why the field's schema rejects the default, or `undefined` when it accepts it. Runs the field's Standard Schema
|
|
9806
|
+
* on `input`, and checks `value` against the JSON Schema rules when the field has no schema that runs.
|
|
9807
|
+
*/
|
|
9808
|
+
async function defaultRejection(check) {
|
|
9809
|
+
const standard = check.schema ? await standardRejection(check.schema, check.input) : void 0;
|
|
9810
|
+
if (standard !== void 0) return standard || void 0;
|
|
9811
|
+
if (typeof check.value === "string") return stringRejection(check.node, check.value);
|
|
9812
|
+
if (typeof check.value === "number") return numberRejection(check.node, check.value);
|
|
9813
|
+
}
|
|
9814
|
+
// src/nuxt-safe-runtime-config/schema.ts
|
|
9815
|
+
function isRecord$4(value) {
|
|
9216
9816
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9217
9817
|
}
|
|
9218
9818
|
function errorText(error) {
|
|
9219
9819
|
return error instanceof Error ? error.message : String(error);
|
|
9220
9820
|
}
|
|
9221
9821
|
function isValibotSchema(value) {
|
|
9222
|
-
return isRecord$
|
|
9822
|
+
return isRecord$4(value) && value.kind === "schema" && isRecord$4(value["~standard"]) && value["~standard"].vendor === "valibot";
|
|
9223
9823
|
}
|
|
9224
9824
|
function zod3Definition(schema) {
|
|
9225
|
-
return isRecord$
|
|
9825
|
+
return isRecord$4(schema) && isRecord$4(schema._def) && typeof schema._def.typeName === "string" ? schema._def : void 0;
|
|
9226
9826
|
}
|
|
9227
9827
|
function zod3OptionalInput(schema) {
|
|
9228
9828
|
const definition = zod3Definition(schema);
|
|
@@ -9242,7 +9842,7 @@ function zod3OptionalInput(schema) {
|
|
|
9242
9842
|
function zod3ToJsonSchema(schema) {
|
|
9243
9843
|
const definition = zod3Definition(schema);
|
|
9244
9844
|
if (!definition) return {};
|
|
9245
|
-
const checks = Array.isArray(definition.checks) ? definition.checks.filter(isRecord$
|
|
9845
|
+
const checks = Array.isArray(definition.checks) ? definition.checks.filter(isRecord$4) : [];
|
|
9246
9846
|
switch (definition.typeName) {
|
|
9247
9847
|
case "ZodString": {
|
|
9248
9848
|
const node = { type: "string" };
|
|
@@ -9269,7 +9869,7 @@ function zod3ToJsonSchema(schema) {
|
|
|
9269
9869
|
} : {};
|
|
9270
9870
|
case "ZodNativeEnum": {
|
|
9271
9871
|
const values = definition.values;
|
|
9272
|
-
if (!isRecord$
|
|
9872
|
+
if (!isRecord$4(values)) return {};
|
|
9273
9873
|
return { enum: Object.values(values).filter((value) => (typeof value === "string" || typeof value === "number") && typeof values[value] !== "number") };
|
|
9274
9874
|
}
|
|
9275
9875
|
case "ZodLiteral": return { const: definition.value };
|
|
@@ -9291,7 +9891,7 @@ function zod3ToJsonSchema(schema) {
|
|
|
9291
9891
|
case "ZodArray": return { type: "array" };
|
|
9292
9892
|
case "ZodObject": {
|
|
9293
9893
|
const shape = typeof definition.shape === "function" ? Reflect.apply(definition.shape, void 0, []) : definition.shape;
|
|
9294
|
-
if (!isRecord$
|
|
9894
|
+
if (!isRecord$4(shape)) return { type: "object" };
|
|
9295
9895
|
const required = Object.entries(shape).filter(([, child]) => !zod3OptionalInput(child)).map(([key]) => key);
|
|
9296
9896
|
return {
|
|
9297
9897
|
type: "object",
|
|
@@ -9307,13 +9907,13 @@ function zodPackageJsonSchema(schema, cwd) {
|
|
|
9307
9907
|
if (!cwd || !zodDefinition(schema)) return void 0;
|
|
9308
9908
|
try {
|
|
9309
9909
|
const zod = createRequire(join(cwd, "package.json"))("zod");
|
|
9310
|
-
const convert = isRecord$
|
|
9910
|
+
const convert = isRecord$4(zod) ? zod.toJSONSchema : void 0;
|
|
9311
9911
|
if (typeof convert !== "function") return void 0;
|
|
9312
9912
|
const output = Reflect.apply(convert, zod, [schema, {
|
|
9313
9913
|
io: "input",
|
|
9314
9914
|
unrepresentable: "any"
|
|
9315
9915
|
}]);
|
|
9316
|
-
return isRecord$
|
|
9916
|
+
return isRecord$4(output) ? output : void 0;
|
|
9317
9917
|
} catch {
|
|
9318
9918
|
return;
|
|
9319
9919
|
}
|
|
@@ -9323,14 +9923,14 @@ function zodPackageJsonSchema(schema, cwd) {
|
|
|
9323
9923
|
* the converter load the app's own Zod for Zod 4 versions before 4.2.
|
|
9324
9924
|
*/
|
|
9325
9925
|
async function schemaToJsonSchema(schema, cwd) {
|
|
9326
|
-
const standard = isRecord$
|
|
9327
|
-
if (!isRecord$
|
|
9926
|
+
const standard = isRecord$4(schema) ? schema["~standard"] : void 0;
|
|
9927
|
+
if (!isRecord$4(schema) || !isRecord$4(standard)) throw codemodError("The $schema is not a Standard Schema. Use a Valibot, Zod, or ArkType schema.");
|
|
9328
9928
|
const vendor = typeof standard.vendor === "string" ? standard.vendor : "unknown";
|
|
9329
9929
|
let nativeError;
|
|
9330
|
-
const converter = isRecord$
|
|
9930
|
+
const converter = isRecord$4(standard.jsonSchema) ? standard.jsonSchema.input : void 0;
|
|
9331
9931
|
if (typeof converter === "function") try {
|
|
9332
9932
|
const output = await Reflect.apply(converter, standard.jsonSchema, [{ target: "draft-2020-12" }]);
|
|
9333
|
-
if (isRecord$
|
|
9933
|
+
if (isRecord$4(output)) return output;
|
|
9334
9934
|
} catch (error) {
|
|
9335
9935
|
nativeError = error;
|
|
9336
9936
|
}
|
|
@@ -9341,7 +9941,7 @@ async function schemaToJsonSchema(schema, cwd) {
|
|
|
9341
9941
|
const arkConverter = schema.toJsonSchema;
|
|
9342
9942
|
if (typeof arkConverter === "function") try {
|
|
9343
9943
|
const output = Reflect.apply(arkConverter, schema, []);
|
|
9344
|
-
if (isRecord$
|
|
9944
|
+
if (isRecord$4(output)) return output;
|
|
9345
9945
|
} catch (error) {
|
|
9346
9946
|
nativeError = error;
|
|
9347
9947
|
}
|
|
@@ -9414,13 +10014,13 @@ function addIssue(issues, path, issue) {
|
|
|
9414
10014
|
issues.set(key, [...issues.get(key) ?? [], issue]);
|
|
9415
10015
|
}
|
|
9416
10016
|
function valibotIssues(schema, path, issues) {
|
|
9417
|
-
if (!isRecord$
|
|
10017
|
+
if (!isRecord$4(schema)) return;
|
|
9418
10018
|
if (Array.isArray(schema.pipe)) for (const action of schema.pipe.slice(1)) {
|
|
9419
|
-
if (!isRecord$
|
|
10019
|
+
if (!isRecord$4(action) || typeof action.type !== "string") continue;
|
|
9420
10020
|
if (action.kind === "transformation") addIssue(issues, path, `the Valibot ${action.type} action`);
|
|
9421
10021
|
else if (action.kind === "validation" && !valibotJsonValidations.has(action.type)) addIssue(issues, path, `the Valibot ${action.type} check`);
|
|
9422
10022
|
}
|
|
9423
|
-
if (isRecord$
|
|
10023
|
+
if (isRecord$4(schema.entries) && [
|
|
9424
10024
|
"object",
|
|
9425
10025
|
"loose_object",
|
|
9426
10026
|
"strict_object",
|
|
@@ -9430,7 +10030,7 @@ function valibotIssues(schema, path, issues) {
|
|
|
9430
10030
|
else if (schema.type === "custom" || schema.type === "lazy") addIssue(issues, path, `a Valibot ${schema.type} schema`);
|
|
9431
10031
|
}
|
|
9432
10032
|
function zodDefinition(schema) {
|
|
9433
|
-
return isRecord$
|
|
10033
|
+
return isRecord$4(schema) && isRecord$4(schema._zod) && isRecord$4(schema._zod.def) ? schema._zod.def : void 0;
|
|
9434
10034
|
}
|
|
9435
10035
|
function zodIssues(schema, path, issues) {
|
|
9436
10036
|
const definition = zodDefinition(schema);
|
|
@@ -9441,7 +10041,7 @@ function zodIssues(schema, path, issues) {
|
|
|
9441
10041
|
if (kind === "overwrite") addIssue(issues, path, "a Zod overwrite");
|
|
9442
10042
|
}
|
|
9443
10043
|
const type = definition.type;
|
|
9444
|
-
if (type === "object" && isRecord$
|
|
10044
|
+
if (type === "object" && isRecord$4(definition.shape)) for (const [key, entry] of Object.entries(definition.shape)) zodIssues(entry, [...path, key], issues);
|
|
9445
10045
|
else if (type === "pipe") {
|
|
9446
10046
|
addIssue(issues, path, zodDefinition(definition.out)?.type === "transform" ? "a Zod transform" : "a Zod pipe");
|
|
9447
10047
|
zodIssues(definition.in, path, issues);
|
|
@@ -9463,7 +10063,7 @@ function zod3Issues(schema, path, issues) {
|
|
|
9463
10063
|
const definition = zod3Definition(schema);
|
|
9464
10064
|
if (!definition) return;
|
|
9465
10065
|
for (const check of Array.isArray(definition.checks) ? definition.checks : []) {
|
|
9466
|
-
if (!isRecord$
|
|
10066
|
+
if (!isRecord$4(check) || typeof check.kind !== "string") continue;
|
|
9467
10067
|
if ([
|
|
9468
10068
|
"trim",
|
|
9469
10069
|
"toLowerCase",
|
|
@@ -9477,7 +10077,7 @@ function zod3Issues(schema, path, issues) {
|
|
|
9477
10077
|
addIssue(issues, path, `z.coerce.${String(type).slice(3).toLowerCase()}()${detail}`);
|
|
9478
10078
|
}
|
|
9479
10079
|
if (type === "ZodEffects") {
|
|
9480
|
-
const effect = isRecord$
|
|
10080
|
+
const effect = isRecord$4(definition.effect) ? definition.effect.type : void 0;
|
|
9481
10081
|
addIssue(issues, path, effect === "refinement" ? "a Zod refinement" : effect === "preprocess" ? "a Zod preprocess" : "a Zod transform");
|
|
9482
10082
|
zod3Issues(definition.schema, path, issues);
|
|
9483
10083
|
} else if (type === "ZodPipeline") {
|
|
@@ -9486,7 +10086,7 @@ function zod3Issues(schema, path, issues) {
|
|
|
9486
10086
|
} else if (type === "ZodUnion") for (const option of Array.isArray(definition.options) ? definition.options : []) zod3Issues(option, path, issues);
|
|
9487
10087
|
else if (type === "ZodObject") {
|
|
9488
10088
|
const shape = typeof definition.shape === "function" ? Reflect.apply(definition.shape, void 0, []) : definition.shape;
|
|
9489
|
-
if (isRecord$
|
|
10089
|
+
if (isRecord$4(shape)) for (const [key, child] of Object.entries(shape)) zod3Issues(child, [...path, key], issues);
|
|
9490
10090
|
} else if (type === "ZodLazy" || type === "ZodAny" || type === "ZodUnknown") addIssue(issues, path, `a Zod ${type.slice(3).toLowerCase()} schema`);
|
|
9491
10091
|
else if (type === "ZodBranded") zod3Issues(definition.type, path, issues);
|
|
9492
10092
|
else if (type === "ZodOptional" || type === "ZodNullable" || type === "ZodDefault" || type === "ZodReadonly") zod3Issues(definition.innerType, path, issues);
|
|
@@ -9501,15 +10101,15 @@ function schemaIssues(schema) {
|
|
|
9501
10101
|
return issues;
|
|
9502
10102
|
}
|
|
9503
10103
|
function resolveReference(root, node) {
|
|
9504
|
-
if (!isRecord$
|
|
10104
|
+
if (!isRecord$4(node)) return {};
|
|
9505
10105
|
const reference = node.$ref;
|
|
9506
10106
|
if (typeof reference !== "string" || !reference.startsWith("#/")) return node;
|
|
9507
10107
|
let current = root;
|
|
9508
|
-
for (const segment of reference.slice(2).split("/")) current = isRecord$
|
|
9509
|
-
return isRecord$
|
|
10108
|
+
for (const segment of reference.slice(2).split("/")) current = isRecord$4(current) ? current[segment] : void 0;
|
|
10109
|
+
return isRecord$4(current) ? resolveReference(root, current) : {};
|
|
9510
10110
|
}
|
|
9511
10111
|
function stringValues(nodes) {
|
|
9512
|
-
const values = nodes.map((node) => isRecord$
|
|
10112
|
+
const values = nodes.map((node) => isRecord$4(node) && typeof node.const === "string" ? node.const : void 0);
|
|
9513
10113
|
return values.every((value) => value !== void 0) ? values : void 0;
|
|
9514
10114
|
}
|
|
9515
10115
|
/** The Env kind of one JSON Schema node, with `null` folded into `nullable`. */
|
|
@@ -9624,11 +10224,31 @@ function coerceDefault(value, field) {
|
|
|
9624
10224
|
function literalText(value) {
|
|
9625
10225
|
return typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
9626
10226
|
}
|
|
10227
|
+
function coerceRuntimeInput(value, leaf) {
|
|
10228
|
+
const kind = leaf.kind === "integer" ? "number" : leaf.kind;
|
|
10229
|
+
if (kind === "array" || kind === "object" || kind === "union" || kind === "unknown") return value;
|
|
10230
|
+
const normalized = typeof value === "string" && kind === "boolean" ? value.trim().toLowerCase() : value;
|
|
10231
|
+
if ((kind === "string" || kind === "enum") && typeof value === "number" && !Number.isSafeInteger(value)) return value;
|
|
10232
|
+
const coerced = coerceDefault(normalized, {
|
|
10233
|
+
kind,
|
|
10234
|
+
values: leaf.values
|
|
10235
|
+
});
|
|
10236
|
+
if (coerced === void 0 || leaf.kind === "integer" && !Number.isInteger(coerced)) return value;
|
|
10237
|
+
return coerced;
|
|
10238
|
+
}
|
|
10239
|
+
function leafAtPath(jsonSchema, path) {
|
|
10240
|
+
let node = resolveReference(jsonSchema, jsonSchema);
|
|
10241
|
+
for (const key of path) {
|
|
10242
|
+
const properties = describeLeaf(jsonSchema, node).node.properties;
|
|
10243
|
+
node = isRecord$4(properties) ? resolveReference(jsonSchema, properties[key]) : {};
|
|
10244
|
+
}
|
|
10245
|
+
return describeLeaf(jsonSchema, node);
|
|
10246
|
+
}
|
|
9627
10247
|
/** Plans Env declarations from the JSON Schema of `runtimeConfig` and the values in nuxt.config. */
|
|
9628
|
-
function planFromJsonSchema(input) {
|
|
10248
|
+
async function planFromJsonSchema(input) {
|
|
9629
10249
|
const root = resolveReference(input.jsonSchema, input.jsonSchema);
|
|
9630
10250
|
const properties = root.properties;
|
|
9631
|
-
if (root.type !== "object" || !isRecord$
|
|
10251
|
+
if (root.type !== "object" || !isRecord$4(properties)) throw codemodError("The $schema must describe the runtimeConfig object, for example `v.object({ ... })`.");
|
|
9632
10252
|
const plan = {
|
|
9633
10253
|
fields: [],
|
|
9634
10254
|
unmigrated: [],
|
|
@@ -9640,19 +10260,25 @@ function planFromJsonSchema(input) {
|
|
|
9640
10260
|
});
|
|
9641
10261
|
for (const issue of input.issues.get("") ?? []) follow(`The $schema has ${issue} on the whole runtimeConfig, such as a cross-field rule. Env does not run it. Check it in server code.`, { schema: "" });
|
|
9642
10262
|
const requiredOf = (node) => new Set(Array.isArray(node.required) ? node.required.filter((key) => typeof key === "string") : []);
|
|
9643
|
-
const
|
|
10263
|
+
const validateAtRuntime = input.validateAtRuntime ?? false;
|
|
10264
|
+
const validateAtBuild = input.validateAtBuild ?? !validateAtRuntime;
|
|
10265
|
+
const coercionSchema = validateAtRuntime && isValibotSchema(input.schema) ? Object.fromEntries(Object.entries(toJsonSchema(input.schema, {
|
|
10266
|
+
errorMode: "ignore",
|
|
10267
|
+
typeMode: "input"
|
|
10268
|
+
}))) : void 0;
|
|
10269
|
+
const visit = async (section, configPath, node, required) => {
|
|
9644
10270
|
const label = pathLabel({
|
|
9645
10271
|
section,
|
|
9646
10272
|
configPath
|
|
9647
10273
|
});
|
|
9648
10274
|
const runtimeValue = input.runtimeConfig.get(label);
|
|
9649
|
-
const leaf = describeLeaf(input.jsonSchema, isRecord$
|
|
10275
|
+
const leaf = describeLeaf(input.jsonSchema, isRecord$4(node) ? node : {});
|
|
9650
10276
|
const objectProperties = leaf.node.properties;
|
|
9651
|
-
if (leaf.kind === "object" && isRecord$
|
|
10277
|
+
if (leaf.kind === "object" && isRecord$4(objectProperties) && Object.keys(objectProperties).length) {
|
|
9652
10278
|
const childRequired = requiredOf(leaf.node);
|
|
9653
10279
|
if (!required) follow(`${label} is an optional group. Its Env fields are optional too.`, { schema: label });
|
|
9654
10280
|
for (const issue of input.issues.get(label) ?? []) follow(`${label} has ${issue}, such as a cross-field rule. Env does not run it. Check it in server code.`, { schema: label });
|
|
9655
|
-
for (const [key, child] of Object.entries(objectProperties)) visit(section, [...configPath, key], child, required && childRequired.has(key));
|
|
10281
|
+
for (const [key, child] of Object.entries(objectProperties)) await visit(section, [...configPath, key], child, required && childRequired.has(key));
|
|
9656
10282
|
return;
|
|
9657
10283
|
}
|
|
9658
10284
|
if (leaf.kind === "array" || leaf.kind === "object" || leaf.kind === "union" || leaf.kind === "unknown") {
|
|
@@ -9679,19 +10305,39 @@ function planFromJsonSchema(input) {
|
|
|
9679
10305
|
if (section === "public" && looksSecret(configPath)) follow(`${label} looks like a credential. Public Env is bundled into client code. Move it to the server section if it is secret.`, { env: field });
|
|
9680
10306
|
if (leaf.nullable) follow(`${label} accepts null. Env has no null value, so the field is optional and is undefined when the variable is not set.`, { env: field });
|
|
9681
10307
|
if (section === "public" && configPath.length > 1) follow(`${label} is nested. Public Env is flat, so read it as usePublicEnv().${field.envPath[0]}.`, { env: field });
|
|
9682
|
-
|
|
10308
|
+
const moduleInput = runtimeValue?.literal ?? runtimeValue?.processEnv?.fallback;
|
|
10309
|
+
const schemaPath = section === "public" ? ["public", ...configPath] : configPath;
|
|
10310
|
+
const runtimeInput = moduleInput !== void 0 && validateAtRuntime ? coerceRuntimeInput(moduleInput, coercionSchema ? leafAtPath(coercionSchema, schemaPath) : leaf) : moduleInput;
|
|
10311
|
+
let defaultValue = runtimeInput === void 0 ? void 0 : coerceDefault(runtimeInput, field);
|
|
9683
10312
|
if (runtimeValue?.literal !== void 0) {
|
|
9684
|
-
defaultValue = coerceDefault(runtimeValue.literal, field);
|
|
9685
10313
|
if (defaultValue === void 0) follow(`runtimeConfig.${label} has the value ${literalText(runtimeValue.literal)}, which is not a valid ${kind}. It was not kept as a default.`, { env: field });
|
|
9686
10314
|
} else if (runtimeValue?.processEnv) {
|
|
9687
10315
|
field.extraVariables = [runtimeValue.processEnv.name];
|
|
9688
|
-
if (runtimeValue.processEnv.fallback !== void 0) defaultValue = coerceDefault(runtimeValue.processEnv.fallback, field);
|
|
9689
10316
|
follow(`runtimeConfig.${label} read process.env.${runtimeValue.processEnv.name} when Nuxt loaded the config. Env now reads ${field.variable === runtimeValue.processEnv.name ? field.variable : `${field.variable}, then ${runtimeValue.processEnv.name}`}, ${section === "public" ? "during the build" : "when the server runs"}. Env treats an empty variable as unset.`, { env: field });
|
|
9690
10317
|
} else if (runtimeValue?.expression) follow(`runtimeConfig.${label} is computed (${runtimeValue.expression}). It was not kept as a default. Set ${field.variable} or add a default by hand.`, { env: field });
|
|
9691
10318
|
if (defaultValue === void 0) {
|
|
9692
10319
|
const schemaDefault = leaf.node.default;
|
|
9693
10320
|
if (typeof schemaDefault === "string" || typeof schemaDefault === "number" || typeof schemaDefault === "boolean") defaultValue = coerceDefault(schemaDefault, field);
|
|
9694
10321
|
}
|
|
10322
|
+
let rejection;
|
|
10323
|
+
if (defaultValue !== void 0 && input.rejectInvalidDefaults !== false && (validateAtRuntime || validateAtBuild)) {
|
|
10324
|
+
const check = {
|
|
10325
|
+
schema: fieldSchema(input.schema, schemaPath),
|
|
10326
|
+
node: leaf.node,
|
|
10327
|
+
input: validateAtBuild ? moduleInput : runtimeInput,
|
|
10328
|
+
value: defaultValue
|
|
10329
|
+
};
|
|
10330
|
+
rejection = await defaultRejection(check);
|
|
10331
|
+
if (rejection === void 0 && validateAtBuild && runtimeInput !== moduleInput) rejection = await defaultRejection({
|
|
10332
|
+
...check,
|
|
10333
|
+
input: runtimeInput
|
|
10334
|
+
});
|
|
10335
|
+
}
|
|
10336
|
+
if (defaultValue !== void 0 && rejection !== void 0) {
|
|
10337
|
+
follow(`${label} had the value ${literalText(defaultValue)}, which its $schema rejects: ${rejection}. The module treats this validation failure as fatal, so the codemod kept no default and Env requires ${field.variable}.`, { env: field });
|
|
10338
|
+
field.required = true;
|
|
10339
|
+
defaultValue = void 0;
|
|
10340
|
+
}
|
|
9695
10341
|
if (defaultValue !== void 0 && defaultValue !== "" && field.secret) {
|
|
9696
10342
|
follow(`${label} is secret, so its value ${literalText(defaultValue)} was not kept as a default. Defaults are written into the server build. Set ${field.variable} instead.`, { env: field });
|
|
9697
10343
|
defaultValue = void 0;
|
|
@@ -9704,15 +10350,15 @@ function planFromJsonSchema(input) {
|
|
|
9704
10350
|
const rootRequired = requiredOf(root);
|
|
9705
10351
|
for (const [key, node] of Object.entries(properties)) {
|
|
9706
10352
|
if (key === "public") {
|
|
9707
|
-
const publicNode = describeLeaf(input.jsonSchema, isRecord$
|
|
10353
|
+
const publicNode = describeLeaf(input.jsonSchema, isRecord$4(node) ? node : {});
|
|
9708
10354
|
const publicProperties = publicNode.node.properties;
|
|
9709
|
-
if (!isRecord$
|
|
10355
|
+
if (!isRecord$4(publicProperties)) {
|
|
9710
10356
|
plan.unmigrated.push("public");
|
|
9711
10357
|
follow("public has no object shape in the $schema. It stays in runtimeConfig.", { runtimeConfig: "public" });
|
|
9712
10358
|
continue;
|
|
9713
10359
|
}
|
|
9714
10360
|
const publicRequired = requiredOf(publicNode.node);
|
|
9715
|
-
for (const [publicKey, child] of Object.entries(publicProperties)) visit("public", [publicKey], child, rootRequired.has("public") && publicRequired.has(publicKey));
|
|
10361
|
+
for (const [publicKey, child] of Object.entries(publicProperties)) await visit("public", [publicKey], child, rootRequired.has("public") && publicRequired.has(publicKey));
|
|
9716
10362
|
continue;
|
|
9717
10363
|
}
|
|
9718
10364
|
if (key === "app" || key === "nitro") {
|
|
@@ -9720,7 +10366,7 @@ function planFromJsonSchema(input) {
|
|
|
9720
10366
|
follow(`${key} is a reserved Nuxt runtimeConfig key. The codemod left it and its schema rules alone.`, { runtimeConfig: key });
|
|
9721
10367
|
continue;
|
|
9722
10368
|
}
|
|
9723
|
-
visit("server", [key], node, rootRequired.has(key));
|
|
10369
|
+
await visit("server", [key], node, rootRequired.has(key));
|
|
9724
10370
|
}
|
|
9725
10371
|
const publicPaths = /* @__PURE__ */ new Map();
|
|
9726
10372
|
for (const field of plan.fields.filter((field) => field.section === "public")) {
|
|
@@ -9737,12 +10383,14 @@ function planFromJsonSchema(input) {
|
|
|
9737
10383
|
}
|
|
9738
10384
|
return plan;
|
|
9739
10385
|
}
|
|
9740
|
-
|
|
9741
|
-
//#region src/nuxt-safe-runtime-config/index.ts
|
|
10386
|
+
// src/nuxt-safe-runtime-config/index.ts
|
|
9742
10387
|
function mergeStatic(top, inline) {
|
|
9743
10388
|
return {
|
|
9744
10389
|
envSchema: inline.envSchema ?? top.envSchema,
|
|
9745
10390
|
schemaPath: inline.schemaPath ?? (inline.inlineSchema ? void 0 : top.schemaPath),
|
|
10391
|
+
onError: inline.onError ?? top.onError,
|
|
10392
|
+
validateAtBuild: inline.validateAtBuild ?? top.validateAtBuild,
|
|
10393
|
+
validateAtRuntime: inline.validateAtRuntime ?? top.validateAtRuntime,
|
|
9746
10394
|
inlineSchema: inline.inlineSchema || !inline.schemaPath && top.inlineSchema,
|
|
9747
10395
|
dynamic: inline.dynamic || top.dynamic
|
|
9748
10396
|
};
|
|
@@ -9752,30 +10400,59 @@ function evaluatedEnvSchema(value) {
|
|
|
9752
10400
|
file: value,
|
|
9753
10401
|
paths: {}
|
|
9754
10402
|
};
|
|
9755
|
-
if (!isRecord$
|
|
9756
|
-
const paths = isRecord$
|
|
10403
|
+
if (!isRecord$5(value) || typeof value.file !== "string") return void 0;
|
|
10404
|
+
const paths = isRecord$5(value.paths) ? Object.fromEntries(Object.entries(value.paths).filter((entry) => typeof entry[1] === "string")) : {};
|
|
9757
10405
|
return {
|
|
9758
10406
|
file: value.file,
|
|
9759
10407
|
paths
|
|
9760
10408
|
};
|
|
9761
10409
|
}
|
|
10410
|
+
async function moduleVersion(cwd) {
|
|
10411
|
+
const installed = join(cwd, "node_modules", moduleName$3, "package.json");
|
|
10412
|
+
const manifest = existsSync(installed) ? parseJson(await readFile(installed, "utf8")) : void 0;
|
|
10413
|
+
if (isRecord$5(manifest) && typeof manifest.version === "string") return manifest.version;
|
|
10414
|
+
return (await readDependencies(cwd)).get(moduleName$3);
|
|
10415
|
+
}
|
|
10416
|
+
function parseJson(text) {
|
|
10417
|
+
try {
|
|
10418
|
+
return JSON.parse(text);
|
|
10419
|
+
} catch {
|
|
10420
|
+
return;
|
|
10421
|
+
}
|
|
10422
|
+
}
|
|
10423
|
+
function before040(version) {
|
|
10424
|
+
return version !== void 0 && validRange(version) !== null && subset(version, "<0.4.0");
|
|
10425
|
+
}
|
|
10426
|
+
function validationChecks(options, version) {
|
|
10427
|
+
if (before040(version)) {
|
|
10428
|
+
const validateAtRuntime = options.validateAtRuntime ?? false;
|
|
10429
|
+
return {
|
|
10430
|
+
validateAtBuild: options.validateAtBuild ?? !validateAtRuntime,
|
|
10431
|
+
validateAtRuntime
|
|
10432
|
+
};
|
|
10433
|
+
}
|
|
10434
|
+
return {
|
|
10435
|
+
validateAtBuild: options.validateAtBuild !== false,
|
|
10436
|
+
validateAtRuntime: options.validateAtRuntime ?? true
|
|
10437
|
+
};
|
|
10438
|
+
}
|
|
9762
10439
|
/** Reads the module options statically, and runs nuxt.config only when an inline schema or a dynamic option needs it. */
|
|
9763
10440
|
async function resolveOptions(config, staticOptions) {
|
|
9764
|
-
if (!staticOptions.inlineSchema && !staticOptions.dynamic) return
|
|
9765
|
-
envSchema: staticOptions.envSchema,
|
|
9766
|
-
schemaPath: staticOptions.schemaPath
|
|
9767
|
-
};
|
|
10441
|
+
if (!staticOptions.inlineSchema && !staticOptions.dynamic) return staticOptions;
|
|
9768
10442
|
const evaluated = await loadNuxtConfig(config.path);
|
|
9769
10443
|
const tuple = (Array.isArray(evaluated.modules) ? evaluated.modules : []).find((entry) => Array.isArray(entry) && entry[0] === "nuxt-safe-runtime-config");
|
|
9770
10444
|
const options = {
|
|
9771
|
-
...isRecord$
|
|
9772
|
-
...tuple && isRecord$
|
|
10445
|
+
...isRecord$5(evaluated.safeRuntimeConfig) ? evaluated.safeRuntimeConfig : {},
|
|
10446
|
+
...tuple && isRecord$5(tuple[1]) ? tuple[1] : {}
|
|
9773
10447
|
};
|
|
9774
10448
|
const schema = options.$schema;
|
|
9775
10449
|
return {
|
|
9776
10450
|
envSchema: evaluatedEnvSchema(options.envSchema) ?? staticOptions.envSchema,
|
|
9777
10451
|
schemaPath: typeof schema === "string" ? schema : void 0,
|
|
9778
|
-
schema: typeof schema === "string" ? void 0 : schema
|
|
10452
|
+
schema: typeof schema === "string" ? void 0 : schema,
|
|
10453
|
+
onError: typeof options.onError === "string" ? options.onError : void 0,
|
|
10454
|
+
validateAtBuild: typeof options.validateAtBuild === "boolean" ? options.validateAtBuild : void 0,
|
|
10455
|
+
validateAtRuntime: typeof options.validateAtRuntime === "boolean" ? options.validateAtRuntime : void 0
|
|
9779
10456
|
};
|
|
9780
10457
|
}
|
|
9781
10458
|
/** Line of each object property in a schema module, by its dotted path of property keys. */
|
|
@@ -9923,10 +10600,13 @@ async function migrate$15({ cwd }) {
|
|
|
9923
10600
|
}
|
|
9924
10601
|
const runtime = readRuntimeConfig(config);
|
|
9925
10602
|
if (findProperty(config.root, "runtimeConfig") && !runtime.object) planned.push({ message: "runtimeConfig is not an object literal, so the codemod kept its values and removed no keys. Move the migrated values to Env defaults by hand." });
|
|
9926
|
-
const plan = planFromJsonSchema({
|
|
10603
|
+
const plan = await planFromJsonSchema({
|
|
10604
|
+
schema,
|
|
9927
10605
|
jsonSchema: await schemaToJsonSchema(schema, cwd),
|
|
9928
10606
|
issues: schemaIssues(schema),
|
|
9929
|
-
runtimeConfig: runtime.values
|
|
10607
|
+
runtimeConfig: runtime.values,
|
|
10608
|
+
...validationChecks(options, await moduleVersion(cwd)),
|
|
10609
|
+
rejectInvalidDefaults: (options.onError ?? "throw") === "throw"
|
|
9930
10610
|
});
|
|
9931
10611
|
fields = plan.fields;
|
|
9932
10612
|
unmigrated = plan.unmigrated;
|
|
@@ -10034,6 +10714,7 @@ async function migrate$15({ cwd }) {
|
|
|
10034
10714
|
return {
|
|
10035
10715
|
summary: `migrated ${fields.length} Env declaration${fields.length === 1 ? "" : "s"} (${publicCount} public, ${fields.length - publicCount} server) from ${sourceLabel} to vite-hub/nuxt.`,
|
|
10036
10716
|
edits,
|
|
10717
|
+
requiresNitro3: true,
|
|
10037
10718
|
followUps: [
|
|
10038
10719
|
...configFollowUps,
|
|
10039
10720
|
...calls.followUps,
|
|
@@ -10094,8 +10775,7 @@ const nuxtSafeRuntimeConfig = {
|
|
|
10094
10775
|
detect: ({ cwd }) => detectNuxtModule(cwd, moduleName$3, ["safeRuntimeConfig"]),
|
|
10095
10776
|
run: migrate$15
|
|
10096
10777
|
};
|
|
10097
|
-
|
|
10098
|
-
//#region src/shared/nuxt-server-layout.ts
|
|
10778
|
+
// src/shared/nuxt-server-layout.ts
|
|
10099
10779
|
const unknownSetting = Symbol("unknown Nuxt setting");
|
|
10100
10780
|
function setting(root, ...keys) {
|
|
10101
10781
|
let value = root;
|
|
@@ -10181,8 +10861,148 @@ async function nuxtServerLayout(cwd, config) {
|
|
|
10181
10861
|
state
|
|
10182
10862
|
};
|
|
10183
10863
|
}
|
|
10184
|
-
|
|
10185
|
-
|
|
10864
|
+
// src/shared/nuxt-version.ts
|
|
10865
|
+
const nuxtNightlyRange = "npm:nuxt-nightly@5x";
|
|
10866
|
+
/** The `nitro` range that `vite-hub` accepts. With `nitro` in package.json, Nuxt 4.7 builds the server with Nitro 3. */
|
|
10867
|
+
const nitroRange = "^3.0.261103-rc";
|
|
10868
|
+
const firstNitro3Nuxt = "4.7.0";
|
|
10869
|
+
const firstNuxt5 = "5.0.0-0";
|
|
10870
|
+
const sections = ["dependencies", "devDependencies"];
|
|
10871
|
+
function isRecord$3(value) {
|
|
10872
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10873
|
+
}
|
|
10874
|
+
function catalogEntry(value, key) {
|
|
10875
|
+
return value instanceof Map ? value.get(key) : void 0;
|
|
10876
|
+
}
|
|
10877
|
+
async function readPnpmCatalogVersion(cwd, name, catalog) {
|
|
10878
|
+
let directory = cwd;
|
|
10879
|
+
while (!existsSync(join(directory, "pnpm-workspace.yaml"))) {
|
|
10880
|
+
if (dirname(directory) === directory) return;
|
|
10881
|
+
directory = dirname(directory);
|
|
10882
|
+
}
|
|
10883
|
+
const workspace = parseDocument(await readFile(join(directory, "pnpm-workspace.yaml"), "utf8")).toJS({ mapAsMap: true });
|
|
10884
|
+
const fallback = catalog === "default" ? catalogEntry(catalogEntry(workspace, "catalog"), name) : void 0;
|
|
10885
|
+
const version = catalogEntry(catalogEntry(catalogEntry(workspace, "catalogs"), catalog), name) ?? fallback;
|
|
10886
|
+
if (typeof version === "string") return version;
|
|
10887
|
+
}
|
|
10888
|
+
function admitsNuxt5(range) {
|
|
10889
|
+
if (intersects(range, ">=5.0.0")) return true;
|
|
10890
|
+
return new Range(range).set.some((comparators) => {
|
|
10891
|
+
const clause = comparators.map((comparator) => comparator.value).join(" ");
|
|
10892
|
+
return comparators.some(({ value }) => {
|
|
10893
|
+
const version = parse$2(value.replace(/^[<>=]+/, ""));
|
|
10894
|
+
if (!version || version.major < 5 || !version.prerelease.length) return false;
|
|
10895
|
+
const release = `${version.major}.${version.minor}.${version.patch}`;
|
|
10896
|
+
return minVersion(`${clause} >=${release}-0 <${release}`) !== null;
|
|
10897
|
+
});
|
|
10898
|
+
});
|
|
10899
|
+
}
|
|
10900
|
+
async function resolveCatalog(cwd, name, value) {
|
|
10901
|
+
const catalog = /^catalog:(.*)$/.exec(value)?.[1];
|
|
10902
|
+
return catalog === void 0 ? value : await readPnpmCatalogVersion(cwd, name, catalog.trim() || "default");
|
|
10903
|
+
}
|
|
10904
|
+
async function readNuxtRange(cwd) {
|
|
10905
|
+
const nuxt = (await readDependencies(cwd)).get("nuxt");
|
|
10906
|
+
if (!nuxt) return;
|
|
10907
|
+
const version = await resolveCatalog(cwd, "nuxt", nuxt);
|
|
10908
|
+
if (!version) return;
|
|
10909
|
+
const range = validRange(version.replace(/^npm:nuxt(?:-nightly)?@/, ""));
|
|
10910
|
+
if (!range) return;
|
|
10911
|
+
return {
|
|
10912
|
+
nuxt,
|
|
10913
|
+
range,
|
|
10914
|
+
source: version === nuxt ? "" : `, which pnpm-workspace.yaml sets to "${version}"`
|
|
10915
|
+
};
|
|
10916
|
+
}
|
|
10917
|
+
function fitsNitro3(version) {
|
|
10918
|
+
const alias = /^npm:(@?[^@]+)@(.*)$/.exec(version);
|
|
10919
|
+
if (alias && alias[1] !== "nitro") return false;
|
|
10920
|
+
const range = validRange(alias?.[2] ?? version);
|
|
10921
|
+
if (!range) return;
|
|
10922
|
+
return range.split("||").every((clause) => {
|
|
10923
|
+
const exact = parse$2(clause.trim());
|
|
10924
|
+
return exact ? satisfies(exact, nitroRange) : subset(clause, nitroRange);
|
|
10925
|
+
});
|
|
10926
|
+
}
|
|
10927
|
+
/** False when package.json requires a Nuxt version before 5, directly or through a pnpm `catalog:`. */
|
|
10928
|
+
async function allowsNuxt5(cwd) {
|
|
10929
|
+
const found = await readNuxtRange(cwd);
|
|
10930
|
+
return !found || admitsNuxt5(found.range);
|
|
10931
|
+
}
|
|
10932
|
+
function rewriteManifest(packageJson, change) {
|
|
10933
|
+
let manifest;
|
|
10934
|
+
try {
|
|
10935
|
+
manifest = JSON.parse(packageJson);
|
|
10936
|
+
} catch (error) {
|
|
10937
|
+
throw codemodError(`Cannot parse package.json: ${error instanceof Error ? error.message : String(error)}`);
|
|
10938
|
+
}
|
|
10939
|
+
if (!isRecord$3(manifest)) throw codemodError("package.json must contain an object.");
|
|
10940
|
+
change(manifest);
|
|
10941
|
+
const indent = /^[ \t]+/m.exec(packageJson)?.[0] ?? " ";
|
|
10942
|
+
return `${JSON.stringify(manifest, null, indent)}${packageJson.endsWith("\n") ? "\n" : ""}`;
|
|
10943
|
+
}
|
|
10944
|
+
/** Sets `nuxt` to Nuxt 5 nightly in each package.json section that lists it. */
|
|
10945
|
+
function setNuxtNightly(packageJson) {
|
|
10946
|
+
return rewriteManifest(packageJson, (manifest) => {
|
|
10947
|
+
for (const section of sections) {
|
|
10948
|
+
const dependencies = manifest[section];
|
|
10949
|
+
if (isRecord$3(dependencies) && "nuxt" in dependencies) dependencies.nuxt = nuxtNightlyRange;
|
|
10950
|
+
}
|
|
10951
|
+
});
|
|
10952
|
+
}
|
|
10953
|
+
/** Sets `nitro` to the range that Nuxt 4.7 builds with, in each section that lists it, or in `dependencies`. */
|
|
10954
|
+
function setNitro(packageJson) {
|
|
10955
|
+
return rewriteManifest(packageJson, (manifest) => {
|
|
10956
|
+
let listed = false;
|
|
10957
|
+
for (const section of sections) {
|
|
10958
|
+
const dependencies = manifest[section];
|
|
10959
|
+
if (!isRecord$3(dependencies) || !("nitro" in dependencies)) continue;
|
|
10960
|
+
dependencies.nitro = nitroRange;
|
|
10961
|
+
listed = true;
|
|
10962
|
+
}
|
|
10963
|
+
if (listed) return;
|
|
10964
|
+
const dependencies = isRecord$3(manifest.dependencies) ? manifest.dependencies : {};
|
|
10965
|
+
manifest.dependencies = Object.fromEntries(Object.entries({
|
|
10966
|
+
...dependencies,
|
|
10967
|
+
nitro: nitroRange
|
|
10968
|
+
}).sort(([left], [right]) => left.localeCompare(right)));
|
|
10969
|
+
});
|
|
10970
|
+
}
|
|
10971
|
+
/**
|
|
10972
|
+
* Checks that the app builds its server with Nitro 3 before a codemod adds `vite-hub/nuxt`. On a Nuxt range that allows a
|
|
10973
|
+
* version before 4.7, it throws `CODEMODS_NUXT_UNSUPPORTED`, or, with `nuxtNightly`, plans to move the app to Nuxt 5
|
|
10974
|
+
* nightly. On a range that allows Nuxt 4.7, it plans to add `nitro`, or to replace a `nitro` range that Nuxt 4.7 cannot
|
|
10975
|
+
* build with.
|
|
10976
|
+
*/
|
|
10977
|
+
async function planNitro3(cwd, codemods, nuxtNightly) {
|
|
10978
|
+
const found = await readNuxtRange(cwd);
|
|
10979
|
+
const lowest = found && minVersion(found.range);
|
|
10980
|
+
if (!found || !lowest || !lt(lowest, firstNuxt5)) return;
|
|
10981
|
+
if (!lt(lowest, firstNitro3Nuxt)) {
|
|
10982
|
+
const declared = (await readDependencies(cwd)).get("nitro");
|
|
10983
|
+
if (declared === void 0) return {
|
|
10984
|
+
update: setNitro,
|
|
10985
|
+
note: `package.json now lists nitro "${nitroRange}" in dependencies. With it, Nuxt 4.7 builds the server with Nitro 3 and H3 2, which vite-hub/nuxt needs. Install it with the other packages.`
|
|
10986
|
+
};
|
|
10987
|
+
const version = await resolveCatalog(cwd, "nitro", declared);
|
|
10988
|
+
if (version === void 0 || fitsNitro3(version) !== false) return;
|
|
10989
|
+
return {
|
|
10990
|
+
update: setNitro,
|
|
10991
|
+
note: `package.json listed nitro "${declared}"${version === declared ? "" : `, which pnpm-workspace.yaml sets to "${version}"`}, and Nuxt 4.7 builds the server only with nitro "${nitroRange}". package.json now lists nitro "${nitroRange}". Install it with the other packages.`
|
|
10992
|
+
};
|
|
10993
|
+
}
|
|
10994
|
+
const { nuxt, source } = found;
|
|
10995
|
+
if (!nuxtNightly) throw codemodsErrorDiagnostics.CODEMODS_NUXT_UNSUPPORTED({
|
|
10996
|
+
codemods,
|
|
10997
|
+
nuxt,
|
|
10998
|
+
source
|
|
10999
|
+
});
|
|
11000
|
+
return {
|
|
11001
|
+
update: setNuxtNightly,
|
|
11002
|
+
note: `package.json now requires nuxt "${nuxtNightlyRange}" in place of "${nuxt}", because vite-hub/nuxt needs Nitro 3, and a Nuxt version before 4.7 runs Nitro 2. Nuxt 5 stops auto-importing Nitro helpers such as defineEventHandler in server code. Set experimental: { nitroAutoImports: true } to keep them while you migrate, or import them as the Nuxt 5 build error lists.`
|
|
11003
|
+
};
|
|
11004
|
+
}
|
|
11005
|
+
// ../internal/dist/nuxt-server-imports.js
|
|
10186
11006
|
/**
|
|
10187
11007
|
* The server helpers that `vite-hub/nuxt` auto-imports in Nitro code, per ViteHub feature, when the app turns on
|
|
10188
11008
|
* Nuxt's server auto-imports. This table is the only list: the Nuxt module adds these auto-imports, and the
|
|
@@ -10271,8 +11091,7 @@ const viteHubServerImportSources = new Map(serverImportTables().flatMap((sources
|
|
|
10271
11091
|
function serverImportTables() {
|
|
10272
11092
|
return Object.values(viteHubServerImports);
|
|
10273
11093
|
}
|
|
10274
|
-
|
|
10275
|
-
//#region src/shared/server-imports.ts
|
|
11094
|
+
// src/shared/server-imports.ts
|
|
10276
11095
|
const valueReadingTypeParents = /* @__PURE__ */ new Set([
|
|
10277
11096
|
"TSAsExpression",
|
|
10278
11097
|
"TSSatisfiesExpression",
|
|
@@ -10516,8 +11335,7 @@ function defaultExportName(file) {
|
|
|
10516
11335
|
const name = basename(file, extname(file));
|
|
10517
11336
|
return (name === "index" ? basename(dirname(file)) : name).replace(/[-_.\s]+(\w)/g, (_, letter) => letter.toUpperCase());
|
|
10518
11337
|
}
|
|
10519
|
-
|
|
10520
|
-
//#region src/nuxt-server-imports/index.ts
|
|
11338
|
+
// src/nuxt-server-imports/index.ts
|
|
10521
11339
|
const moduleName$2 = "vite-hub/nuxt";
|
|
10522
11340
|
const ignoredPatterns$9 = [
|
|
10523
11341
|
"**/node_modules/**",
|
|
@@ -10573,7 +11391,7 @@ async function readProject(cwd) {
|
|
|
10573
11391
|
serverFiles: files.sort()
|
|
10574
11392
|
};
|
|
10575
11393
|
}
|
|
10576
|
-
function parse$
|
|
11394
|
+
function parse$3(file, code) {
|
|
10577
11395
|
return parseProgram(code, {
|
|
10578
11396
|
jsx: file.endsWith("x"),
|
|
10579
11397
|
typescript: /\.[cm]?tsx?$/.test(file)
|
|
@@ -10619,7 +11437,7 @@ async function migrate$14({ cwd }) {
|
|
|
10619
11437
|
if (!helpers && ![...reportedNitroHelpers].some((name) => source.includes(name))) continue;
|
|
10620
11438
|
let program;
|
|
10621
11439
|
try {
|
|
10622
|
-
program = parse$
|
|
11440
|
+
program = parse$3(file, source);
|
|
10623
11441
|
} catch (error) {
|
|
10624
11442
|
if (helpers) followUps.push({
|
|
10625
11443
|
file,
|
|
@@ -10658,7 +11476,7 @@ async function migrate$14({ cwd }) {
|
|
|
10658
11476
|
const from = viteHubServerImportSources.get(name);
|
|
10659
11477
|
notes.push(`${appNames.get(name)} gives \`${name}\`, and Nuxt still auto-imports it, so ${files.size} file(s) keep the app's \`${name}\`. Import ViteHub's from "${from}" where you need it.`);
|
|
10660
11478
|
}
|
|
10661
|
-
if (nitroFiles.length) notes.push(`Nuxt 5 also stops auto-importing the Nitro and H3 helpers, such as defineEventHandler, in ${nitroFiles.length} server file(s), for example ${nitroFiles[0]}. Import each one from the module that the Nuxt 5 build error names: "nitro/h3" or "nuxt/server".`);
|
|
11479
|
+
if (nitroFiles.length && await allowsNuxt5(cwd)) notes.push(`Nuxt 5 also stops auto-importing the Nitro and H3 helpers, such as defineEventHandler, in ${nitroFiles.length} server file(s), for example ${nitroFiles[0]}. Import each one from the module that the Nuxt 5 build error names: "nitro/h3" or "nuxt/server".`);
|
|
10662
11480
|
return {
|
|
10663
11481
|
summary: edits.length ? `added ${added} vite-hub import(s) to ${edits.length} server file(s)` : followUps.length ? "left server files that need a manual check" : "found no server file that uses a ViteHub helper without an import",
|
|
10664
11482
|
edits,
|
|
@@ -10684,7 +11502,7 @@ const nuxtServerImports = {
|
|
|
10684
11502
|
if (!helperPattern.test(source)) continue;
|
|
10685
11503
|
let program;
|
|
10686
11504
|
try {
|
|
10687
|
-
program = parse$
|
|
11505
|
+
program = parse$3(file, source);
|
|
10688
11506
|
} catch {
|
|
10689
11507
|
continue;
|
|
10690
11508
|
}
|
|
@@ -10694,8 +11512,7 @@ const nuxtServerImports = {
|
|
|
10694
11512
|
},
|
|
10695
11513
|
run: migrate$14
|
|
10696
11514
|
};
|
|
10697
|
-
|
|
10698
|
-
//#region src/nuxthub/config.ts
|
|
11515
|
+
// src/nuxthub/config.ts
|
|
10699
11516
|
const moduleName$1 = "@nuxthub/core";
|
|
10700
11517
|
const featureKeys = [
|
|
10701
11518
|
"kv",
|
|
@@ -10797,7 +11614,7 @@ function readDatabase(config, value, notes) {
|
|
|
10797
11614
|
function featureNote(config, feature, value) {
|
|
10798
11615
|
return {
|
|
10799
11616
|
path: [feature],
|
|
10800
|
-
message: `hub.${feature} was ${optionText(config, value)}. The codemod set ${feature}: true, which uses the default driver of the host. NuxtHub and ViteHub name drivers differently, so set the driver options under vitehub.${feature} by hand. See https://vitehub.dev/docs/${feature === "cache" ? "
|
|
11617
|
+
message: `hub.${feature} was ${optionText(config, value)}. The codemod set ${feature}: true, which uses the default driver of the host. NuxtHub and ViteHub name drivers differently, so set the driver options under vitehub.${feature} by hand. See https://vitehub.dev/docs/${feature === "cache" ? "compare/nuxthub#keep-the-cache" : feature}.`
|
|
10801
11618
|
};
|
|
10802
11619
|
}
|
|
10803
11620
|
/** Reads `hub` into features. Options that do not map 1:1 become notes. */
|
|
@@ -10973,8 +11790,7 @@ function editConfig(config, plan, wranglerFile, resources = {}) {
|
|
|
10973
11790
|
}))
|
|
10974
11791
|
};
|
|
10975
11792
|
}
|
|
10976
|
-
|
|
10977
|
-
//#region src/nuxthub/database.ts
|
|
11793
|
+
// src/nuxthub/database.ts
|
|
10978
11794
|
const scriptExtension = /\.(?:ts|mts|js|mjs)$/;
|
|
10979
11795
|
const definitionFile = "server/databases/default/index.ts";
|
|
10980
11796
|
/** Every relative import or export source in a module, with the node that holds it. */
|
|
@@ -11315,8 +12131,7 @@ function casingFollowUp(options, dialect) {
|
|
|
11315
12131
|
message: `hub.db.casing was "${options.casing}". Drizzle 1.0 has no casing for a database, so declare each table with ${helper}.table() from drizzle-orm/${dialect === "postgresql" ? "pg-core" : "sqlite-core"}. Without it, the column names change. See https://vitehub.dev/docs/database/configure#name-columns-in-snake_case.`
|
|
11316
12132
|
}];
|
|
11317
12133
|
}
|
|
11318
|
-
|
|
11319
|
-
//#region src/nuxthub/kv-env.ts
|
|
12134
|
+
// src/nuxthub/kv-env.ts
|
|
11320
12135
|
const upstashPairs = [["KV_REST_API_URL", "KV_REST_API_TOKEN"], ["UPSTASH_REDIS_REST_URL", "UPSTASH_REDIS_REST_TOKEN"]];
|
|
11321
12136
|
/**
|
|
11322
12137
|
* NuxtHub selects Redis for `hub.kv: true` when the build has `REDIS_URL`, or a `KV_URL` that starts with `rediss://`,
|
|
@@ -11351,8 +12166,7 @@ async function findRedisKVSource(cwd, configFile, configCode) {
|
|
|
11351
12166
|
file: configFile
|
|
11352
12167
|
};
|
|
11353
12168
|
}
|
|
11354
|
-
|
|
11355
|
-
//#region src/nuxthub/sources.ts
|
|
12169
|
+
// src/nuxthub/sources.ts
|
|
11356
12170
|
/** NuxtHub import paths and the ViteHub path that replaces each one. */
|
|
11357
12171
|
const replacedSources = {
|
|
11358
12172
|
"hub:db": "vite-hub/database",
|
|
@@ -11780,8 +12594,7 @@ async function rewriteSources(input) {
|
|
|
11780
12594
|
}
|
|
11781
12595
|
return result;
|
|
11782
12596
|
}
|
|
11783
|
-
|
|
11784
|
-
//#region src/shared/layers.ts
|
|
12597
|
+
// src/shared/layers.ts
|
|
11785
12598
|
/** The app root (`.`) and its local Nuxt layers: `layers/*` and relative `extends` paths. */
|
|
11786
12599
|
async function localLayerDirectories(cwd, config) {
|
|
11787
12600
|
const layers = await glob(["layers/*"], {
|
|
@@ -11800,9 +12613,8 @@ async function localLayerDirectories(cwd, config) {
|
|
|
11800
12613
|
}
|
|
11801
12614
|
return [...directories];
|
|
11802
12615
|
}
|
|
11803
|
-
|
|
11804
|
-
|
|
11805
|
-
const guide = "https://vitehub.dev/docs/getting-started/migrate-from-nuxthub#modules-that-expect-nuxthub";
|
|
12616
|
+
// src/nuxthub/modules.ts
|
|
12617
|
+
const guide = "https://vitehub.dev/docs/compare/nuxthub#modules-that-expect-nuxthub";
|
|
11806
12618
|
const contributions = "https://vitehub.dev/docs/database/configure#contribute-tables-from-a-nuxt-module";
|
|
11807
12619
|
const customMigration = "Put the SQL in a migration that you write by hand with `vitehub database generate --custom`.";
|
|
11808
12620
|
const hookMessages = new Map(Object.entries({
|
|
@@ -11843,7 +12655,7 @@ async function findHooks(cwd, config) {
|
|
|
11843
12655
|
}
|
|
11844
12656
|
const seen = /* @__PURE__ */ new Set();
|
|
11845
12657
|
walk(program, (node) => {
|
|
11846
|
-
const value = node.type === "StringLiteral" ? node.value : node.type === "TemplateLiteral" && node.expressions.length === 0 ? node.quasis[0]?.value.cooked : void 0;
|
|
12658
|
+
const value = node.type === "StringLiteral" ? node.value : node.type === "TemplateLiteral" && node.expressions.length === 0 ? node.quasis[0]?.value.cooked ?? void 0 : void 0;
|
|
11847
12659
|
const message = value === void 0 ? void 0 : hookMessages.get(value);
|
|
11848
12660
|
if (!value || !message || seen.has(value)) return;
|
|
11849
12661
|
seen.add(value);
|
|
@@ -11912,8 +12724,7 @@ async function findNuxtHubModuleFollowUps(cwd, config, dependencyRoot = cwd) {
|
|
|
11912
12724
|
...await findNuxtHubDependents(cwd, dependencyRoot)
|
|
11913
12725
|
];
|
|
11914
12726
|
}
|
|
11915
|
-
|
|
11916
|
-
//#region src/nuxthub/overrides.ts
|
|
12727
|
+
// src/nuxthub/overrides.ts
|
|
11917
12728
|
const scopeFix = "vite-hub/nuxt imports h3 2, so Nuxt cannot load it while every package gets h3 1 (ERR_PACKAGE_PATH_NOT_EXPORTED). Scope the override to the package that needs h3 1, for example `'nuxt-csurf>h3': 1.15.11`.";
|
|
11918
12729
|
/** An h3 1 range or version, such as `1.15.11`, `^1.15.0`, or `~1`. */
|
|
11919
12730
|
const h3One = /^[\^~]?1(?:\.|$)/;
|
|
@@ -11962,8 +12773,7 @@ async function findGlobalH3Overrides(cwd) {
|
|
|
11962
12773
|
}
|
|
11963
12774
|
return followUps;
|
|
11964
12775
|
}
|
|
11965
|
-
|
|
11966
|
-
//#region src/nuxthub/wrangler.ts
|
|
12776
|
+
// src/nuxthub/wrangler.ts
|
|
11967
12777
|
const wranglerFiles = [
|
|
11968
12778
|
"wrangler.jsonc",
|
|
11969
12779
|
"wrangler.json",
|
|
@@ -12175,13 +12985,12 @@ async function planWrangler(cwd, file, features, cloudflare, bindings, written =
|
|
|
12175
12985
|
d1
|
|
12176
12986
|
};
|
|
12177
12987
|
}
|
|
12178
|
-
|
|
12179
|
-
//#region src/nuxthub/index.ts
|
|
12988
|
+
// src/nuxthub/index.ts
|
|
12180
12989
|
/**
|
|
12181
12990
|
* The Drizzle ORM and Kit versions that `@vite-hub/database` accepts. Not `^1.0.0-rc.5`: Drizzle publishes snapshot
|
|
12182
12991
|
* builds such as `1.0.0-rc.5-ab785fc`, which that range allows and which sort above the release.
|
|
12183
12992
|
*/
|
|
12184
|
-
const drizzleRange = "1.0.0-rc.5 || ^1.0.0";
|
|
12993
|
+
const drizzleRange = "1.0.0-rc.5 || 1.0.0-rc.6 || ^1.0.0";
|
|
12185
12994
|
/** The command that runs a package binary, from the install command. */
|
|
12186
12995
|
function runner(installCommand) {
|
|
12187
12996
|
if (installCommand.startsWith("pnpm")) return "pnpm";
|
|
@@ -12225,14 +13034,16 @@ async function migrate$13({ cwd, dependencyRoot = cwd }) {
|
|
|
12225
13034
|
skip,
|
|
12226
13035
|
layout: await nuxtServerLayout(cwd, config)
|
|
12227
13036
|
});
|
|
12228
|
-
const
|
|
12229
|
-
|
|
12230
|
-
|
|
12231
|
-
|
|
12232
|
-
|
|
13037
|
+
const enabled = [
|
|
13038
|
+
"database",
|
|
13039
|
+
"kv",
|
|
13040
|
+
"blob",
|
|
13041
|
+
"cache"
|
|
13042
|
+
].filter((id) => Boolean(features[id]));
|
|
12233
13043
|
const packageResult = await editPackageJson(cwd, version, {
|
|
12234
13044
|
remove: [moduleName$1],
|
|
12235
|
-
add: ["vite-hub"
|
|
13045
|
+
add: ["vite-hub"],
|
|
13046
|
+
features: enabled,
|
|
12236
13047
|
within: features.database ? {
|
|
12237
13048
|
"drizzle-orm": drizzleRange,
|
|
12238
13049
|
"drizzle-kit": drizzleRange
|
|
@@ -12248,19 +13059,13 @@ async function migrate$13({ cwd, dependencyRoot = cwd }) {
|
|
|
12248
13059
|
if (packageResult.edit) edits.push(packageResult.edit);
|
|
12249
13060
|
if (wrangler.edit) edits.push(wrangler.edit);
|
|
12250
13061
|
edits.push(...schema?.edits ?? [], ...sources.edits);
|
|
12251
|
-
const
|
|
12252
|
-
features.database && "database",
|
|
12253
|
-
features.kv && "kv",
|
|
12254
|
-
features.blob && "blob",
|
|
12255
|
-
features.cache && "cache"
|
|
12256
|
-
].filter(Boolean);
|
|
12257
|
-
const notes = ["NuxtHub auto-imported kv, blob, db, and schema in server code. Nuxt 5 turns server auto-imports off, so the codemod imports them from vite-hub/* in each server file. Set experimental: { nitroAutoImports: true } in nuxt.config to auto-import them again.", "Local data stays in .data/. ViteHub reads .vitehub/data/. The follow-ups list the commands that copy it."];
|
|
13062
|
+
const notes = [await allowsNuxt5(cwd) ? "NuxtHub auto-imported kv, blob, db, and schema in server code. Nuxt 5 turns server auto-imports off, so the codemod imports them from vite-hub/* in each server file. Set experimental: { nitroAutoImports: true } in nuxt.config to auto-import them again." : "NuxtHub auto-imported kv, blob, db, and schema in server code. The codemod imports them from vite-hub/* in each server file, so the files keep working on Nuxt 5, which turns server auto-imports off.", "Local data stays in .data/. ViteHub reads .vitehub/data/. The follow-ups list the commands that copy it."];
|
|
12258
13063
|
if (features.database) notes.push("NuxtHub's server/db/migrations/ stays in place for reference. ViteHub writes new migrations to server/databases/default/migrations/ and does not apply them during dev or build. Delete the old folder after the baseline.");
|
|
12259
13064
|
if (features.cache) notes.push("Cached handlers come from Nitro and use the cache store of cache: true. In Nitro 3, import defineCachedHandler() (formerly cachedEventHandler()) and defineCachedFunction() from nitro/cache.");
|
|
12260
|
-
const installed = new Intl.ListFormat("en", { type: "conjunction" }).format(["vite-hub", ...featurePackages]);
|
|
12261
13065
|
return {
|
|
12262
13066
|
summary: `moved ${enabled.length ? enabled.join(", ") : "no features"} from hub to vitehub${configResult.host ? ` with host "${configResult.host}"` : ""}, rewrote ${sources.imports} import${sources.imports === 1 ? "" : "s"} and ${sources.calls} KV and Blob call${sources.calls === 1 ? "" : "s"}${schema?.moved.size ? `, and moved the schema to server/databases/default/` : ""}.`,
|
|
12263
13067
|
edits,
|
|
13068
|
+
requiresNitro3: true,
|
|
12264
13069
|
followUps: [
|
|
12265
13070
|
...configResult.followUps,
|
|
12266
13071
|
...await findGlobalH3Overrides(cwd),
|
|
@@ -12280,7 +13085,7 @@ async function migrate$13({ cwd, dependencyRoot = cwd }) {
|
|
|
12280
13085
|
],
|
|
12281
13086
|
notes,
|
|
12282
13087
|
nextSteps: [
|
|
12283
|
-
`Run \`${packageResult.installCommand}\` to install ${
|
|
13088
|
+
`Run \`${packageResult.installCommand}\` to install ${packageResult.installs} and remove ${moduleName$1}.`,
|
|
12284
13089
|
"Run `npx nuxi prepare`, then type-check the app.",
|
|
12285
13090
|
`Run \`${run} nuxt build\` and \`${run} vitehub inspect output --json\` to check the resources and bindings.`
|
|
12286
13091
|
]
|
|
@@ -12293,8 +13098,7 @@ const nuxthub = {
|
|
|
12293
13098
|
detect: ({ cwd }) => detectNuxtModule(cwd, moduleName$1, ["hub"]),
|
|
12294
13099
|
run: migrate$13
|
|
12295
13100
|
};
|
|
12296
|
-
|
|
12297
|
-
//#region src/root-accessors/index.ts
|
|
13101
|
+
// src/root-accessors/index.ts
|
|
12298
13102
|
const removedDatabaseNames = /* @__PURE__ */ new Map([["databases", "`databases` is no longer public. Use `useDatabase(name)` from the Database root for a named Database."], ["agentDb", "`agentDb` is no longer public. Generated Agent routes pass the Database Capability its handle."]]);
|
|
12299
13103
|
const runScheduleNames = /* @__PURE__ */ new Set(["runSchedule", "RunScheduleOptions"]);
|
|
12300
13104
|
/**
|
|
@@ -12850,8 +13654,7 @@ const rootAccessors = {
|
|
|
12850
13654
|
},
|
|
12851
13655
|
run: migrate$12
|
|
12852
13656
|
};
|
|
12853
|
-
|
|
12854
|
-
//#region src/one-entry-imports/index.ts
|
|
13657
|
+
// src/one-entry-imports/index.ts
|
|
12855
13658
|
/** Subpaths that moved into another entry of the same package, without `vite-hub/` or `@vite-hub/`. */
|
|
12856
13659
|
const subpathMoves = [
|
|
12857
13660
|
...[
|
|
@@ -13054,7 +13857,7 @@ function rewriteBlock$2(context) {
|
|
|
13054
13857
|
else if (node.type === "ImportExpression") source = node.source;
|
|
13055
13858
|
else if (node.type === "CallExpression" && node.callee.type === "Import") source = node.arguments[0];
|
|
13056
13859
|
else if (node.type === "CallExpression" && node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" && moduleCalls$1.has(node.callee.property.name)) source = node.arguments[0];
|
|
13057
|
-
else if (node.type === "TSImportType") source = node.
|
|
13860
|
+
else if (node.type === "TSImportType") source = node.source;
|
|
13058
13861
|
if (source?.type !== "StringLiteral" || context.rewritten.has(source)) return;
|
|
13059
13862
|
const to = movedTo(source.value, context.file);
|
|
13060
13863
|
if (!to) return;
|
|
@@ -13155,8 +13958,7 @@ const oneEntryImports = {
|
|
|
13155
13958
|
},
|
|
13156
13959
|
run: migrate$11
|
|
13157
13960
|
};
|
|
13158
|
-
|
|
13159
|
-
//#region src/queue-durations/index.ts
|
|
13961
|
+
// src/queue-durations/index.ts
|
|
13160
13962
|
const queueModules = /* @__PURE__ */ new Set(["vite-hub/queue", "@vite-hub/queue"]);
|
|
13161
13963
|
/**
|
|
13162
13964
|
* Queue exports by what they do. The old verbs are here too: `vitehub migrate` detects every codemod before
|
|
@@ -13503,8 +14305,7 @@ const queueDurations = {
|
|
|
13503
14305
|
},
|
|
13504
14306
|
run: migrate$10
|
|
13505
14307
|
};
|
|
13506
|
-
|
|
13507
|
-
//#region src/queue-workflow-verbs/index.ts
|
|
14308
|
+
// src/queue-workflow-verbs/index.ts
|
|
13508
14309
|
const primitiveModules = /* @__PURE__ */ new Map([
|
|
13509
14310
|
["vite-hub/queue", "queue"],
|
|
13510
14311
|
["@vite-hub/queue", "queue"],
|
|
@@ -13990,8 +14791,7 @@ const queueWorkflowVerbs = {
|
|
|
13990
14791
|
detect,
|
|
13991
14792
|
run: migrate$9
|
|
13992
14793
|
};
|
|
13993
|
-
|
|
13994
|
-
//#region src/renamed-apis/index.ts
|
|
14794
|
+
// src/renamed-apis/index.ts
|
|
13995
14795
|
/** Exports that ViteHub renamed, by the module that exports them. */
|
|
13996
14796
|
const renamedExports$1 = /* @__PURE__ */ new Map([
|
|
13997
14797
|
["@vite-hub/database/vite", /* @__PURE__ */ new Map([["hubDb", "hubDatabase"]])],
|
|
@@ -14459,8 +15259,7 @@ const renamedApis = {
|
|
|
14459
15259
|
},
|
|
14460
15260
|
run: migrate$8
|
|
14461
15261
|
};
|
|
14462
|
-
|
|
14463
|
-
//#region src/resend/call-sites.ts
|
|
15262
|
+
// src/resend/call-sites.ts
|
|
14464
15263
|
const emailImport = "vite-hub/email";
|
|
14465
15264
|
/** Message fields that the ViteHub Resend driver sends. Resend's `reply_to` becomes `replyTo`. */
|
|
14466
15265
|
const portableFields = /* @__PURE__ */ new Set([
|
|
@@ -14841,8 +15640,7 @@ async function rewriteResendCallSites(cwd) {
|
|
|
14841
15640
|
}
|
|
14842
15641
|
return result;
|
|
14843
15642
|
}
|
|
14844
|
-
|
|
14845
|
-
//#region src/resend/index.ts
|
|
15643
|
+
// src/resend/index.ts
|
|
14846
15644
|
const moduleName = "nuxt-resend";
|
|
14847
15645
|
const ignored$3 = [
|
|
14848
15646
|
"**/node_modules/**",
|
|
@@ -14976,7 +15774,8 @@ async function migrate$7({ cwd }) {
|
|
|
14976
15774
|
const remove = [...keepModule ? [] : [moduleName], ...resendImported || keepModule ? [] : ["resend"]].filter((name) => dependencies.has(name));
|
|
14977
15775
|
const packageResult = await editPackageJson(cwd, version, {
|
|
14978
15776
|
remove,
|
|
14979
|
-
add: ["vite-hub"]
|
|
15777
|
+
add: ["vite-hub"],
|
|
15778
|
+
features: ["email"]
|
|
14980
15779
|
});
|
|
14981
15780
|
const edits = [{
|
|
14982
15781
|
path: config.fileName,
|
|
@@ -14987,6 +15786,7 @@ async function migrate$7({ cwd }) {
|
|
|
14987
15786
|
return {
|
|
14988
15787
|
summary: `moved ${calls.sends} emails.send() call${calls.sends === 1 ? "" : "s"} to email.send() with the ViteHub Resend driver${host ? `, host "${host}"` : ""}.`,
|
|
14989
15788
|
edits,
|
|
15789
|
+
requiresNitro3: true,
|
|
14990
15790
|
followUps: [...followUps, ...calls.followUps],
|
|
14991
15791
|
notes: [
|
|
14992
15792
|
`The API key is Secret Env read from ${sources.join(", then ")}. It resolves on each send, so builds do not need it.`,
|
|
@@ -14994,7 +15794,7 @@ async function migrate$7({ cwd }) {
|
|
|
14994
15794
|
...resendImported ? ["Some files still import the resend package, so it stays in package.json."] : [],
|
|
14995
15795
|
...keepModule ? [`${moduleName} stays because ${calls.useResendRemaining.join(", ")} still call useResend(). Remove it after those follow-ups.`] : []
|
|
14996
15796
|
],
|
|
14997
|
-
nextSteps: [`Run \`${packageResult.installCommand}\` to install
|
|
15797
|
+
nextSteps: [`Run \`${packageResult.installCommand}\` to install ${packageResult.installs}${remove.length ? ` and remove ${remove.join(" and ")}` : ""}.`, "Run `npx nuxi prepare`, then type-check the app."]
|
|
14998
15798
|
};
|
|
14999
15799
|
}
|
|
15000
15800
|
const resend = {
|
|
@@ -15012,8 +15812,7 @@ const resend = {
|
|
|
15012
15812
|
},
|
|
15013
15813
|
run: migrate$7
|
|
15014
15814
|
};
|
|
15015
|
-
|
|
15016
|
-
//#region src/shared/result-calls.ts
|
|
15815
|
+
// src/shared/result-calls.ts
|
|
15017
15816
|
function scriptBlocks$1(file, source) {
|
|
15018
15817
|
if (!file.endsWith(".vue")) return [{
|
|
15019
15818
|
code: source,
|
|
@@ -15187,8 +15986,7 @@ function rewriteResultCalls(context, match, unsupported) {
|
|
|
15187
15986
|
});
|
|
15188
15987
|
return rewritten;
|
|
15189
15988
|
}
|
|
15190
|
-
|
|
15191
|
-
//#region src/result-tuples/index.ts
|
|
15989
|
+
// src/result-tuples/index.ts
|
|
15192
15990
|
const workflowModules = /* @__PURE__ */ new Set(["vite-hub/workflow", "@vite-hub/workflow"]);
|
|
15193
15991
|
const scheduleModules = /* @__PURE__ */ new Set([
|
|
15194
15992
|
"vite-hub/schedule",
|
|
@@ -15384,7 +16182,7 @@ function migrateBlock(context) {
|
|
|
15384
16182
|
if (statement.declaration?.type === "VariableDeclaration") {
|
|
15385
16183
|
for (const { id } of statement.declaration.declarations) if (id.type === "Identifier") addExport(id);
|
|
15386
16184
|
}
|
|
15387
|
-
for (const specifier of statement.specifiers) if (specifier.type === "ExportSpecifier" && specifier.exportKind !== "type") addExport(specifier.local);
|
|
16185
|
+
for (const specifier of statement.specifiers) if (specifier.type === "ExportSpecifier" && specifier.exportKind !== "type" && specifier.local.type === "Identifier") addExport(specifier.local);
|
|
15388
16186
|
} else if (statement.type === "ExportDefaultDeclaration") {
|
|
15389
16187
|
const declaration = statement.declaration;
|
|
15390
16188
|
if (declaration.type === "Identifier") addExport(declaration);
|
|
@@ -15560,8 +16358,7 @@ const resultTuples = {
|
|
|
15560
16358
|
},
|
|
15561
16359
|
run: migrate$6
|
|
15562
16360
|
};
|
|
15563
|
-
|
|
15564
|
-
//#region src/runtime-contracts/index.ts
|
|
16361
|
+
// src/runtime-contracts/index.ts
|
|
15565
16362
|
const h3Renames = /* @__PURE__ */ new Map([["H3RuntimeContext", "RequestRuntimeContext"], ["H3RuntimeContextOptions", "RuntimeContextOptions"]]);
|
|
15566
16363
|
const h3Removed = /* @__PURE__ */ new Map([["installStandardContext", "`installStandardContext` is no longer public. ViteHub sets `event[\"~standard\"]` on each request, and the primitives set it for an event that Nitro did not create. Remove the import and its calls."]]);
|
|
15567
16364
|
const nodeNames = /* @__PURE__ */ new Set(["nodeRuntimeResources", "NodeRuntimeResourceInspectorOptions"]);
|
|
@@ -16090,8 +16887,7 @@ const runtimeContracts = {
|
|
|
16090
16887
|
},
|
|
16091
16888
|
run: migrate$5
|
|
16092
16889
|
};
|
|
16093
|
-
|
|
16094
|
-
//#region src/shell-driver/index.ts
|
|
16890
|
+
// src/shell-driver/index.ts
|
|
16095
16891
|
const shellModules = ["@vite-hub/shell", "vite-hub/shell"];
|
|
16096
16892
|
const justBashModules = ["@vite-hub/shell/providers/just-bash", "vite-hub/shell/providers/just-bash"];
|
|
16097
16893
|
const workspaceModules = ["@vite-hub/workspace", "vite-hub/workspace"];
|
|
@@ -16355,8 +17151,7 @@ const shellDriver = {
|
|
|
16355
17151
|
},
|
|
16356
17152
|
run: migrate$4
|
|
16357
17153
|
};
|
|
16358
|
-
|
|
16359
|
-
//#region src/t3-env/call-sites.ts
|
|
17154
|
+
// src/t3-env/call-sites.ts
|
|
16360
17155
|
const serverImport = "vite-hub/env";
|
|
16361
17156
|
const publicImport = "#vitehub/env/public";
|
|
16362
17157
|
const appFolders = /* @__PURE__ */ new Set([
|
|
@@ -16593,8 +17388,7 @@ async function rewriteT3CallSites(cwd, module, fields, skip) {
|
|
|
16593
17388
|
}
|
|
16594
17389
|
return result;
|
|
16595
17390
|
}
|
|
16596
|
-
|
|
16597
|
-
//#region src/t3-env/load.ts
|
|
17391
|
+
// src/t3-env/load.ts
|
|
16598
17392
|
const marker = "__vitehubT3EnvOptions";
|
|
16599
17393
|
/**
|
|
16600
17394
|
* Imports the env module with a `createEnv()` stub, so the schemas load without validating the current
|
|
@@ -16621,11 +17415,11 @@ async function loadT3EnvOptions(cwd, file) {
|
|
|
16621
17415
|
} catch (error) {
|
|
16622
17416
|
throw codemodError(`Cannot load ${file} to read its schemas: ${error instanceof Error ? error.message : String(error)}. Install the app dependencies, then run the codemod again.`);
|
|
16623
17417
|
}
|
|
16624
|
-
if (!isRecord$
|
|
17418
|
+
if (!isRecord$5(loaded)) throw codemodError(`${file} exports no createEnv() result.`);
|
|
16625
17419
|
for (const [exportName, value] of Object.entries(loaded)) {
|
|
16626
|
-
if (!isRecord$
|
|
17420
|
+
if (!isRecord$5(value) || !isRecord$5(value[marker])) continue;
|
|
16627
17421
|
const options = value[marker];
|
|
16628
|
-
const section = (name) => isRecord$
|
|
17422
|
+
const section = (name) => isRecord$5(options[name]) ? options[name] : {};
|
|
16629
17423
|
return {
|
|
16630
17424
|
exportName,
|
|
16631
17425
|
server: section("server"),
|
|
@@ -16646,19 +17440,18 @@ async function loadT3EnvOptions(cwd, file) {
|
|
|
16646
17440
|
});
|
|
16647
17441
|
}
|
|
16648
17442
|
}
|
|
16649
|
-
|
|
16650
|
-
//#region src/t3-env/plan.ts
|
|
17443
|
+
// src/t3-env/plan.ts
|
|
16651
17444
|
/** Runs the schema on a missing value: optional schemas pass, and a schema with a default returns it. */
|
|
16652
17445
|
async function validateMissing(schema) {
|
|
16653
|
-
const standard = isRecord$
|
|
16654
|
-
const validate = isRecord$
|
|
17446
|
+
const standard = isRecord$5(schema) ? schema["~standard"] : void 0;
|
|
17447
|
+
const validate = isRecord$5(standard) ? standard.validate : void 0;
|
|
16655
17448
|
if (typeof validate !== "function") return { passes: false };
|
|
16656
17449
|
try {
|
|
16657
17450
|
const result = await Reflect.apply(validate, standard, [void 0]);
|
|
16658
|
-
if (isRecord$
|
|
17451
|
+
if (isRecord$5(result) && Array.isArray(result.issues) && result.issues.length) return { passes: false };
|
|
16659
17452
|
return {
|
|
16660
17453
|
passes: true,
|
|
16661
|
-
value: isRecord$
|
|
17454
|
+
value: isRecord$5(result) ? result.value : void 0
|
|
16662
17455
|
};
|
|
16663
17456
|
} catch {
|
|
16664
17457
|
return { passes: false };
|
|
@@ -16744,8 +17537,7 @@ async function planT3Env(options, cwd) {
|
|
|
16744
17537
|
}
|
|
16745
17538
|
return plan;
|
|
16746
17539
|
}
|
|
16747
|
-
|
|
16748
|
-
//#region src/t3-env/index.ts
|
|
17540
|
+
// src/t3-env/index.ts
|
|
16749
17541
|
const packageName = "@t3-oss/env-nuxt";
|
|
16750
17542
|
const sourceGlobs = ["**/*.{ts,mts,cts,js,mjs,cjs,tsx,jsx}"];
|
|
16751
17543
|
const ignored$2 = [
|
|
@@ -16889,6 +17681,7 @@ async function migrate$3({ cwd }) {
|
|
|
16889
17681
|
return {
|
|
16890
17682
|
summary: `migrated ${fields.length} variable${fields.length === 1 ? "" : "s"} from ${envFile} to vite-hub/nuxt Env (${fields.filter((field) => field.section === "public").length} public, ${fields.filter((field) => field.section === "server").length} server)${host ? `, host "${host}"` : ""}.`,
|
|
16891
17683
|
edits,
|
|
17684
|
+
requiresNitro3: true,
|
|
16892
17685
|
followUps: [
|
|
16893
17686
|
...configFollowUps,
|
|
16894
17687
|
...planFollowUps,
|
|
@@ -16909,8 +17702,7 @@ const t3Env = {
|
|
|
16909
17702
|
},
|
|
16910
17703
|
run: migrate$3
|
|
16911
17704
|
};
|
|
16912
|
-
|
|
16913
|
-
//#region src/tsconfig-paths/index.ts
|
|
17705
|
+
// src/tsconfig-paths/index.ts
|
|
16914
17706
|
const tsconfigPatterns = ["**/tsconfig.json", "**/tsconfig.*.json"];
|
|
16915
17707
|
const ignored$1 = [
|
|
16916
17708
|
"**/node_modules/**",
|
|
@@ -17030,8 +17822,7 @@ const tsconfigPaths = {
|
|
|
17030
17822
|
},
|
|
17031
17823
|
run: migrate$2
|
|
17032
17824
|
};
|
|
17033
|
-
|
|
17034
|
-
//#region src/vitehub-options/index.ts
|
|
17825
|
+
// src/vitehub-options/index.ts
|
|
17035
17826
|
const configPatterns = ["**/{vite,nuxt}.config.{ts,mts,cts,js,mjs,cjs}"];
|
|
17036
17827
|
const sourcePatterns$1 = ["**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,vue}"];
|
|
17037
17828
|
const ignored = [
|
|
@@ -17156,8 +17947,7 @@ const vitehubOptions = {
|
|
|
17156
17947
|
},
|
|
17157
17948
|
run: migrate$1
|
|
17158
17949
|
};
|
|
17159
|
-
|
|
17160
|
-
//#region src/workspace-repo/index.ts
|
|
17950
|
+
// src/workspace-repo/index.ts
|
|
17161
17951
|
const sourcePatterns = ["**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,vue}"];
|
|
17162
17952
|
const ignoredPatterns = [
|
|
17163
17953
|
"**/node_modules/**",
|
|
@@ -17289,8 +18079,7 @@ const workspaceRepo = {
|
|
|
17289
18079
|
},
|
|
17290
18080
|
run: migrate
|
|
17291
18081
|
};
|
|
17292
|
-
|
|
17293
|
-
//#region src/registry.ts
|
|
18082
|
+
// src/registry.ts
|
|
17294
18083
|
/**
|
|
17295
18084
|
* Every available codemod. Add a new codemod here to make the CLI list and run it. NuxtHub runs first: it renames
|
|
17296
18085
|
* hub to vitehub in place and picks the host from the Wrangler config, and the others add to that vitehub key.
|
|
@@ -17369,8 +18158,12 @@ const upgradeCodemods = [
|
|
|
17369
18158
|
cliAgentTree,
|
|
17370
18159
|
nuxtServerImports
|
|
17371
18160
|
];
|
|
17372
|
-
|
|
17373
|
-
|
|
18161
|
+
/** Tells that the migrated app cannot run on this Node.js version, or returns `undefined` when it can. */
|
|
18162
|
+
function nodeVersionNote(version = process.versions.node) {
|
|
18163
|
+
if (!lt(version, "24.15.0")) return;
|
|
18164
|
+
return `vite-hub needs Node 24.15+; this shell runs ${version}. Switch to Node 24.15 or later before you install and run the migrated app.`;
|
|
18165
|
+
}
|
|
18166
|
+
// src/runner.ts
|
|
17374
18167
|
/**
|
|
17375
18168
|
* Rejects an edit outside `root` or through a symbolic link, such as a linked config or a file inside a linked
|
|
17376
18169
|
* directory. Writing it would change a file outside the project.
|
|
@@ -17404,7 +18197,8 @@ function findCodemod(name) {
|
|
|
17404
18197
|
}
|
|
17405
18198
|
/**
|
|
17406
18199
|
* Runs one codemod. Writes its edits unless `dryRun` is set. Throws `CODEMODS_BLOCKED` when it cannot migrate, also when an
|
|
17407
|
-
* edit is a symbolic link or is inside one
|
|
18200
|
+
* edit is a symbolic link or is inside one, and `CODEMODS_NUXT_UNSUPPORTED` when it adds `vite-hub/nuxt` to an app on a
|
|
18201
|
+
* Nuxt version before 4.7 without `nuxtNightly`. On Nuxt 4.7 without `nitro`, it adds `nitro` to package.json.
|
|
17408
18202
|
*/
|
|
17409
18203
|
async function runCodemod(name, options = {}) {
|
|
17410
18204
|
const codemod = findCodemod(name);
|
|
@@ -17414,7 +18208,14 @@ async function runCodemod(name, options = {}) {
|
|
|
17414
18208
|
});
|
|
17415
18209
|
const cwd = resolve(options.cwd ?? process.cwd());
|
|
17416
18210
|
const dryRun = options.dryRun ?? false;
|
|
17417
|
-
const
|
|
18211
|
+
const planned = await codemod.run({ cwd });
|
|
18212
|
+
const nitro3 = planned.requiresNitro3 ? await planNitro3(cwd, [codemod.name], options.nuxtNightly ?? false) : void 0;
|
|
18213
|
+
const upgraded = nitro3 ? await withNitro3(cwd, planned, nitro3) : planned;
|
|
18214
|
+
const nodeNote = nodeVersionNote();
|
|
18215
|
+
const result = nodeNote ? {
|
|
18216
|
+
...upgraded,
|
|
18217
|
+
notes: [...upgraded.notes, nodeNote]
|
|
18218
|
+
} : upgraded;
|
|
17418
18219
|
for (const edit of result.edits) await checkEditPath(cwd, edit.path);
|
|
17419
18220
|
if (!dryRun) for (const edit of result.edits) await applyEdit(cwd, edit);
|
|
17420
18221
|
return {
|
|
@@ -17424,6 +18225,26 @@ async function runCodemod(name, options = {}) {
|
|
|
17424
18225
|
result
|
|
17425
18226
|
};
|
|
17426
18227
|
}
|
|
18228
|
+
async function withNitro3(cwd, result, plan) {
|
|
18229
|
+
const path = "package.json";
|
|
18230
|
+
const edits = result.edits.map((edit) => edit.path === path && edit.after !== null ? {
|
|
18231
|
+
...edit,
|
|
18232
|
+
after: plan.update(edit.after)
|
|
18233
|
+
} : edit);
|
|
18234
|
+
if (!result.edits.some((edit) => edit.path === path)) {
|
|
18235
|
+
const before = await readFile(join(cwd, path), "utf8");
|
|
18236
|
+
edits.push({
|
|
18237
|
+
path,
|
|
18238
|
+
before,
|
|
18239
|
+
after: plan.update(before)
|
|
18240
|
+
});
|
|
18241
|
+
}
|
|
18242
|
+
return {
|
|
18243
|
+
...result,
|
|
18244
|
+
edits,
|
|
18245
|
+
notes: [plan.note, ...result.notes]
|
|
18246
|
+
};
|
|
18247
|
+
}
|
|
17427
18248
|
/** Marks a new or deleted file in a file list. */
|
|
17428
18249
|
function editLabel(edit) {
|
|
17429
18250
|
if (edit.after === null) return " (deleted)";
|
|
@@ -17460,9 +18281,7 @@ function formatReport(run) {
|
|
|
17460
18281
|
}
|
|
17461
18282
|
return `${lines.join("\n")}\n`;
|
|
17462
18283
|
}
|
|
17463
|
-
|
|
17464
|
-
//#region src/migrate.ts
|
|
17465
|
-
/** Folders that the migration does not copy into its scratch directory. */
|
|
18284
|
+
// src/migrate.ts
|
|
17466
18285
|
const skippedFolders = /* @__PURE__ */ new Set([
|
|
17467
18286
|
".git",
|
|
17468
18287
|
".nuxt",
|
|
@@ -17475,50 +18294,6 @@ const skippedFolders = /* @__PURE__ */ new Set([
|
|
|
17475
18294
|
]);
|
|
17476
18295
|
/** Scratch directory prefix inside the project, so packages and the lockfile resolve as they do from the project. */
|
|
17477
18296
|
const scratchFolder = ".vitehub-migrate";
|
|
17478
|
-
/**
|
|
17479
|
-
* Reads the version of a package in a pnpm catalog, such as `catalog:` or `catalog:frameworks`, from the nearest
|
|
17480
|
-
* pnpm-workspace.yaml. Reads the block form that pnpm writes, as `catalog:` and `catalogs:` keys at the root.
|
|
17481
|
-
*/
|
|
17482
|
-
async function readPnpmCatalogVersion(cwd, name, catalog) {
|
|
17483
|
-
let directory = cwd;
|
|
17484
|
-
while (!existsSync(join(directory, "pnpm-workspace.yaml"))) {
|
|
17485
|
-
if (dirname(directory) === directory) return;
|
|
17486
|
-
directory = dirname(directory);
|
|
17487
|
-
}
|
|
17488
|
-
const code = await readFile(join(directory, "pnpm-workspace.yaml"), "utf8");
|
|
17489
|
-
let section;
|
|
17490
|
-
let current;
|
|
17491
|
-
let catalogIndent;
|
|
17492
|
-
for (const line of code.split(/\r?\n/)) {
|
|
17493
|
-
const entry = /^( *)(["']?)([^"'#:]+?)\2[ \t]*:(?:[ \t]+(.*))?$/.exec(line);
|
|
17494
|
-
if (!entry) continue;
|
|
17495
|
-
const [, indent = "", , key = ""] = entry;
|
|
17496
|
-
const value = entry[4]?.replace(/(?:^|[ \t]+)#.*$/, "").trim().replace(/^(["'])(.*)\1$/, "$2");
|
|
17497
|
-
if (!indent) {
|
|
17498
|
-
section = key;
|
|
17499
|
-
current = section === "catalog" ? "default" : void 0;
|
|
17500
|
-
catalogIndent = void 0;
|
|
17501
|
-
continue;
|
|
17502
|
-
}
|
|
17503
|
-
if (section === "catalogs" && (catalogIndent === void 0 || indent.length <= catalogIndent)) {
|
|
17504
|
-
catalogIndent = indent.length;
|
|
17505
|
-
current = key;
|
|
17506
|
-
continue;
|
|
17507
|
-
}
|
|
17508
|
-
if (current === catalog && key === name && value) return value;
|
|
17509
|
-
}
|
|
17510
|
-
}
|
|
17511
|
-
async function projectWarnings(cwd) {
|
|
17512
|
-
const nuxt = (await readDependencies(cwd)).get("nuxt");
|
|
17513
|
-
if (!nuxt) return [];
|
|
17514
|
-
const catalog = /^catalog:(.*)$/.exec(nuxt)?.[1];
|
|
17515
|
-
const version = catalog === void 0 ? nuxt : await readPnpmCatalogVersion(cwd, "nuxt", catalog.trim() || "default");
|
|
17516
|
-
if (!version) return [];
|
|
17517
|
-
const options = { includePrerelease: true };
|
|
17518
|
-
const range = validRange(version.replace(/^npm:nuxt(?:-nightly)?@/, ""), options);
|
|
17519
|
-
if (range && !intersects(range, ">=5.0.0-0", options)) return [`ViteHub supports Nuxt 5 and Nitro 3 only, and package.json requires nuxt "${nuxt}"${version === nuxt ? "" : `, which pnpm-workspace.yaml sets to "${version}"`}. The migration does not upgrade Nuxt. Move the app to Nuxt 5 before you build it, for example with "nuxt": "npm:nuxt-nightly@5x" until Nuxt 5 is released. Nuxt 5 also stops auto-importing Nitro helpers such as defineEventHandler in server code. Set experimental: { nitroAutoImports: true } to keep them while you migrate, or import them as the Nuxt 5 build error lists.`];
|
|
17520
|
-
return [];
|
|
17521
|
-
}
|
|
17522
18297
|
/** Lists every codemod of `candidates` that applies to the project, in their order. */
|
|
17523
18298
|
async function detectCodemods(cwd, candidates = codemods) {
|
|
17524
18299
|
const found = [];
|
|
@@ -17537,7 +18312,9 @@ async function readOptional(path) {
|
|
|
17537
18312
|
/**
|
|
17538
18313
|
* Detects every supported module in the project and runs its codemod. The codemods run one after another on a
|
|
17539
18314
|
* scratch copy, so each one sees the edits of the ones before it. A codemod that fails adds an error and changes
|
|
17540
|
-
* nothing; the others still run. Writes the combined edits unless `dryRun` is set.
|
|
18315
|
+
* nothing; the others still run. Writes the combined edits unless `dryRun` is set. When a successful plan adds
|
|
18316
|
+
* `vite-hub/nuxt`, it adds `nitro` to package.json on Nuxt 4.7, and throws `CODEMODS_NUXT_UNSUPPORTED` before it
|
|
18317
|
+
* changes project files on a Nuxt version before 4.7, unless `nuxtNightly` is set.
|
|
17541
18318
|
*/
|
|
17542
18319
|
async function runMigration(options = {}) {
|
|
17543
18320
|
const cwd = resolve(options.cwd ?? process.cwd());
|
|
@@ -17545,8 +18322,9 @@ async function runMigration(options = {}) {
|
|
|
17545
18322
|
if (!existsSync(cwd)) throw codemodError(`Cannot find the directory ${cwd}.`);
|
|
17546
18323
|
const candidates = options.codemods ?? codemods;
|
|
17547
18324
|
const supported = candidates.map((codemod) => codemod.name);
|
|
17548
|
-
const warnings = await projectWarnings(cwd);
|
|
17549
18325
|
const found = await detectCodemods(cwd, candidates);
|
|
18326
|
+
const nodeNote = nodeVersionNote();
|
|
18327
|
+
const notes = nodeNote ? [nodeNote] : [];
|
|
17550
18328
|
const initialDetections = new Map(found.map(({ codemod, detection }) => [codemod, detection]));
|
|
17551
18329
|
const steps = [];
|
|
17552
18330
|
if (!found.length) {
|
|
@@ -17557,7 +18335,7 @@ async function runMigration(options = {}) {
|
|
|
17557
18335
|
dryRun,
|
|
17558
18336
|
steps,
|
|
17559
18337
|
edits: [],
|
|
17560
|
-
|
|
18338
|
+
notes,
|
|
17561
18339
|
supported
|
|
17562
18340
|
};
|
|
17563
18341
|
}
|
|
@@ -17612,6 +18390,20 @@ async function runMigration(options = {}) {
|
|
|
17612
18390
|
});
|
|
17613
18391
|
}
|
|
17614
18392
|
}
|
|
18393
|
+
const needsNitro3 = steps.filter(({ result }) => result?.requiresNitro3).map(({ codemod }) => codemod.name);
|
|
18394
|
+
const nitro3 = needsNitro3.length ? await planNitro3(cwd, needsNitro3, options.nuxtNightly ?? false) : void 0;
|
|
18395
|
+
if (nitro3) {
|
|
18396
|
+
const path = "package.json";
|
|
18397
|
+
await checkEditPath(scratch, path);
|
|
18398
|
+
const manifest = await readFile(join(scratch, path), "utf8");
|
|
18399
|
+
await applyEdit(scratch, {
|
|
18400
|
+
path,
|
|
18401
|
+
before: manifest,
|
|
18402
|
+
after: nitro3.update(manifest)
|
|
18403
|
+
});
|
|
18404
|
+
touched.add(path);
|
|
18405
|
+
notes.push(nitro3.note);
|
|
18406
|
+
}
|
|
17615
18407
|
const edits = [];
|
|
17616
18408
|
for (const path of [...touched].sort()) {
|
|
17617
18409
|
const before = await readOptional(join(cwd, path));
|
|
@@ -17628,7 +18420,7 @@ async function runMigration(options = {}) {
|
|
|
17628
18420
|
dryRun,
|
|
17629
18421
|
steps,
|
|
17630
18422
|
edits,
|
|
17631
|
-
|
|
18423
|
+
notes,
|
|
17632
18424
|
supported
|
|
17633
18425
|
};
|
|
17634
18426
|
} finally {
|
|
@@ -17659,10 +18451,6 @@ function formatMigrationReport(migration, nextSteps = []) {
|
|
|
17659
18451
|
lines.push("", `${step.codemod.name} (${step.detection.reason})`);
|
|
17660
18452
|
lines.push(step.result ? ` ${step.result.summary}` : ` Not migrated: ${step.error}`);
|
|
17661
18453
|
}
|
|
17662
|
-
if (migration.warnings.length) {
|
|
17663
|
-
lines.push("", "Warnings:");
|
|
17664
|
-
for (const warning of migration.warnings) lines.push(` - ${warning}`);
|
|
17665
|
-
}
|
|
17666
18454
|
if (steps.length) {
|
|
17667
18455
|
lines.push("", `${dryRun ? "Files to change" : "Files changed"} (${edits.length}):`);
|
|
17668
18456
|
for (const edit of edits) lines.push(` ${edit.path}${editLabel(edit)}`);
|
|
@@ -17677,7 +18465,7 @@ function formatMigrationReport(migration, nextSteps = []) {
|
|
|
17677
18465
|
followUps.forEach(({ name, followUp }, index) => lines.push(` ${index + 1}. [${name}] ${formatLocation(followUp)}${followUp.message}`));
|
|
17678
18466
|
if (!followUps.length) lines.push(" none");
|
|
17679
18467
|
}
|
|
17680
|
-
const notes = steps.flatMap((step) => (step.result?.notes ?? []).map((note) => `[${step.codemod.name}] ${note}`));
|
|
18468
|
+
const notes = [...migration.notes, ...steps.flatMap((step) => (step.result?.notes ?? []).map((note) => `[${step.codemod.name}] ${note}`))];
|
|
17681
18469
|
if (notes.length) {
|
|
17682
18470
|
lines.push("", "Notes:");
|
|
17683
18471
|
for (const note of notes) lines.push(` - ${note}`);
|
|
@@ -17689,8 +18477,7 @@ function formatMigrationReport(migration, nextSteps = []) {
|
|
|
17689
18477
|
}
|
|
17690
18478
|
return `${lines.join("\n")}\n`;
|
|
17691
18479
|
}
|
|
17692
|
-
|
|
17693
|
-
//#region src/cli-main.ts
|
|
18480
|
+
// src/cli-main.ts
|
|
17694
18481
|
const defaultOutput = {
|
|
17695
18482
|
stdout: (text) => process.stdout.write(text),
|
|
17696
18483
|
stderr: (text) => process.stderr.write(text)
|
|
@@ -17698,8 +18485,8 @@ const defaultOutput = {
|
|
|
17698
18485
|
function helpText() {
|
|
17699
18486
|
const width = Math.max(...codemods.map((codemod) => codemod.name.length));
|
|
17700
18487
|
return [
|
|
17701
|
-
"Usage: npx @vite-hub/codemods [dir] [--dry-run]",
|
|
17702
|
-
" npx @vite-hub/codemods <codemod> [dir] [--dry-run]",
|
|
18488
|
+
"Usage: npx @vite-hub/codemods [dir] [--dry-run] [--nuxt-nightly]",
|
|
18489
|
+
" npx @vite-hub/codemods <codemod> [dir] [--dry-run] [--nuxt-nightly]",
|
|
17703
18490
|
"",
|
|
17704
18491
|
"Without a codemod name, it detects every supported module in the app and migrates them all.",
|
|
17705
18492
|
"",
|
|
@@ -17707,8 +18494,10 @@ function helpText() {
|
|
|
17707
18494
|
...codemods.map((codemod) => ` ${codemod.name.padEnd(width)} ${codemod.description}`),
|
|
17708
18495
|
"",
|
|
17709
18496
|
"Options:",
|
|
17710
|
-
" --dry-run
|
|
17711
|
-
" --
|
|
18497
|
+
" --dry-run Print the planned edits and write nothing.",
|
|
18498
|
+
" --nuxt-nightly Set nuxt to npm:nuxt-nightly@5x in package.json if a planned migration needs vite-hub/nuxt and the app is on a Nuxt version before 4.7.",
|
|
18499
|
+
" Without it, the command stops without changing project files.",
|
|
18500
|
+
" --help Show this list.",
|
|
17712
18501
|
""
|
|
17713
18502
|
].join("\n");
|
|
17714
18503
|
}
|
|
@@ -17718,6 +18507,7 @@ async function runCli(argv, output = defaultOutput) {
|
|
|
17718
18507
|
const positionals = argv.filter((arg) => !arg.startsWith("-"));
|
|
17719
18508
|
const unknownFlag = flags.find((flag) => ![
|
|
17720
18509
|
"--dry-run",
|
|
18510
|
+
"--nuxt-nightly",
|
|
17721
18511
|
"--help",
|
|
17722
18512
|
"-h"
|
|
17723
18513
|
].includes(flag));
|
|
@@ -17730,6 +18520,7 @@ async function runCli(argv, output = defaultOutput) {
|
|
|
17730
18520
|
return 0;
|
|
17731
18521
|
}
|
|
17732
18522
|
const dryRun = flags.includes("--dry-run");
|
|
18523
|
+
const nuxtNightly = flags.includes("--nuxt-nightly");
|
|
17733
18524
|
const [first, ...rest] = positionals;
|
|
17734
18525
|
const single = first !== void 0 && codemods.some((codemod) => codemod.name === first);
|
|
17735
18526
|
const extra = single ? rest.slice(1) : rest;
|
|
@@ -17741,7 +18532,8 @@ async function runCli(argv, output = defaultOutput) {
|
|
|
17741
18532
|
if (single) {
|
|
17742
18533
|
const run = await runCodemod(first, {
|
|
17743
18534
|
cwd: rest[0],
|
|
17744
|
-
dryRun
|
|
18535
|
+
dryRun,
|
|
18536
|
+
nuxtNightly
|
|
17745
18537
|
});
|
|
17746
18538
|
if (run.dryRun && run.result.edits.length) output.stdout(`${formatDiff(run.result)}\n`);
|
|
17747
18539
|
output.stdout(formatReport(run));
|
|
@@ -17749,7 +18541,8 @@ async function runCli(argv, output = defaultOutput) {
|
|
|
17749
18541
|
}
|
|
17750
18542
|
const migration = await runMigration({
|
|
17751
18543
|
cwd: first,
|
|
17752
|
-
dryRun
|
|
18544
|
+
dryRun,
|
|
18545
|
+
nuxtNightly
|
|
17753
18546
|
});
|
|
17754
18547
|
if (migration.dryRun && migration.edits.length) output.stdout(`${formatDiff({ edits: migration.edits })}\n`);
|
|
17755
18548
|
output.stdout(formatMigrationReport(migration));
|
|
@@ -17763,5 +18556,4 @@ async function runCli(argv, output = defaultOutput) {
|
|
|
17763
18556
|
return 1;
|
|
17764
18557
|
}
|
|
17765
18558
|
}
|
|
17766
|
-
//#endregion
|
|
17767
18559
|
export { findCodemod as a, runCodemod as c, isCodemodError as d, runMigration as i, codemods as l, detectCodemods as n, formatDiff as o, formatMigrationReport as r, formatReport as s, runCli as t, upgradeCodemods as u };
|