@qzsy/vinext 0.1.12 → 0.1.80
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 +19 -5
- package/dist/build/inject-pregenerated-paths.d.ts +4 -0
- package/dist/build/inject-pregenerated-paths.js +18 -0
- package/dist/build/pages-client-assets-module.d.ts +11 -0
- package/dist/build/pages-client-assets-module.js +27 -0
- package/dist/build/prerender.d.ts +2 -1
- package/dist/build/prerender.js +11 -4
- package/dist/build/report.d.ts +2 -1
- package/dist/build/report.js +2 -1
- package/dist/build/run-prerender.d.ts +7 -0
- package/dist/build/run-prerender.js +9 -0
- package/dist/build/standalone.js +2 -0
- package/dist/check.d.ts +18 -0
- package/dist/check.js +77 -19
- package/dist/cli-dev-config.d.ts +12 -0
- package/dist/cli-dev-config.js +23 -0
- package/dist/cli.js +64 -28
- package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay-store.js +1 -1
- package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay.js +2 -2
- package/dist/cloudflare/deploy-config.d.ts +51 -0
- package/dist/cloudflare/deploy-config.js +153 -0
- package/dist/cloudflare/index.d.ts +1 -1
- package/dist/cloudflare/index.js +1 -1
- package/dist/cloudflare/project.d.ts +41 -0
- package/dist/cloudflare/project.js +243 -0
- package/dist/cloudflare/tpr.js +1 -1
- package/dist/config/config-matchers.js +14 -10
- package/dist/config/next-config.d.ts +6 -3
- package/dist/config/next-config.js +47 -1
- package/dist/config/server-external-packages.d.ts +4 -0
- package/dist/config/server-external-packages.js +91 -0
- package/dist/deploy.d.ts +2 -122
- package/dist/deploy.js +20 -793
- package/dist/entries/app-rsc-entry.d.ts +2 -1
- package/dist/entries/app-rsc-entry.js +70 -12
- package/dist/entries/app-rsc-manifest.js +8 -0
- package/dist/entries/pages-client-entry.d.ts +1 -0
- package/dist/entries/pages-client-entry.js +2 -1
- package/dist/entries/pages-server-entry.js +6 -2
- package/dist/image/image-adapters-virtual.d.ts +59 -0
- package/dist/image/image-adapters-virtual.js +50 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +158 -109
- package/dist/init-cloudflare.d.ts +43 -0
- package/dist/init-cloudflare.js +1000 -0
- package/dist/init-platform.d.ts +38 -0
- package/dist/init-platform.js +150 -0
- package/dist/init.d.ts +14 -37
- package/dist/init.js +205 -95
- package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
- package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
- package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +1 -1
- package/dist/plugins/ast-scope.d.ts +16 -0
- package/dist/plugins/ast-scope.js +62 -0
- package/dist/plugins/ast-utils.js +3 -0
- package/dist/plugins/css-module-imports.d.ts +14 -0
- package/dist/plugins/css-module-imports.js +59 -0
- package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +530 -0
- package/dist/plugins/middleware-server-only.d.ts +8 -6
- package/dist/plugins/middleware-server-only.js +8 -7
- package/dist/plugins/optimize-imports.js +1 -1
- package/dist/plugins/typeof-window.d.ts +1 -1
- package/dist/plugins/typeof-window.js +28 -56
- package/dist/routing/app-route-graph.d.ts +13 -2
- package/dist/routing/app-route-graph.js +116 -32
- package/dist/routing/app-router.d.ts +5 -0
- package/dist/routing/app-router.js +5 -0
- package/dist/routing/file-matcher.d.ts +8 -0
- package/dist/routing/file-matcher.js +10 -1
- package/dist/routing/pages-router.js +2 -2
- package/dist/server/app-browser-action-result.d.ts +2 -1
- package/dist/server/app-browser-action-result.js +5 -1
- package/dist/server/app-browser-entry.js +17 -12
- package/dist/server/app-browser-history-controller.d.ts +2 -1
- package/dist/server/app-browser-history-controller.js +6 -2
- package/dist/server/app-browser-interception-context.d.ts +1 -0
- package/dist/server/app-browser-interception-context.js +4 -2
- package/dist/server/app-browser-navigation-controller.js +1 -0
- package/dist/server/app-browser-server-action-client.js +2 -3
- package/dist/server/app-browser-state.d.ts +1 -0
- package/dist/server/app-browser-state.js +3 -2
- package/dist/server/app-fallback-renderer.d.ts +3 -2
- package/dist/server/app-fallback-renderer.js +12 -7
- package/dist/server/app-middleware.d.ts +2 -3
- package/dist/server/app-middleware.js +3 -2
- package/dist/server/app-optimistic-routing.js +1 -1
- package/dist/server/app-page-boundary-render.d.ts +1 -0
- package/dist/server/app-page-boundary-render.js +12 -3
- package/dist/server/app-page-cache-finalizer.d.ts +1 -0
- package/dist/server/app-page-cache-finalizer.js +10 -3
- package/dist/server/app-page-cache-render.d.ts +1 -0
- package/dist/server/app-page-cache-render.js +8 -4
- package/dist/server/app-page-cache.d.ts +1 -0
- package/dist/server/app-page-cache.js +4 -1
- package/dist/server/app-page-dispatch.d.ts +11 -3
- package/dist/server/app-page-dispatch.js +55 -15
- package/dist/server/app-page-element-builder.d.ts +5 -1
- package/dist/server/app-page-element-builder.js +57 -20
- package/dist/server/app-page-head.d.ts +12 -0
- package/dist/server/app-page-head.js +42 -19
- package/dist/server/app-page-params.d.ts +2 -1
- package/dist/server/app-page-params.js +8 -1
- package/dist/server/app-page-probe.d.ts +1 -0
- package/dist/server/app-page-probe.js +6 -1
- package/dist/server/app-page-render-identity.d.ts +1 -0
- package/dist/server/app-page-render-identity.js +1 -1
- package/dist/server/app-page-render.d.ts +4 -1
- package/dist/server/app-page-render.js +8 -3
- package/dist/server/app-page-request.d.ts +22 -1
- package/dist/server/app-page-request.js +89 -13
- package/dist/server/app-page-route-wiring.d.ts +6 -1
- package/dist/server/app-page-route-wiring.js +31 -15
- package/dist/server/app-page-search-params-observation.d.ts +4 -2
- package/dist/server/app-page-search-params-observation.js +11 -7
- package/dist/server/app-page-segment-state.js +2 -0
- package/dist/server/app-route-handler-dispatch.js +1 -0
- package/dist/server/app-route-handler-execution.js +7 -2
- package/dist/server/app-route-handler-response.js +1 -0
- package/dist/server/app-route-handler-runtime.js +1 -1
- package/dist/server/app-route-module-loader.d.ts +2 -0
- package/dist/server/app-route-module-loader.js +1 -0
- package/dist/server/app-router-entry.d.ts +12 -0
- package/dist/server/app-router-entry.js +22 -8
- package/dist/server/app-router-image-optimization.d.ts +37 -0
- package/dist/server/app-router-image-optimization.js +40 -0
- package/dist/server/app-rsc-errors.js +7 -1
- package/dist/server/app-rsc-handler.js +27 -14
- package/dist/server/app-rsc-route-matching.d.ts +7 -0
- package/dist/server/app-rsc-route-matching.js +36 -3
- package/dist/server/app-segment-config.d.ts +12 -0
- package/dist/server/app-segment-config.js +91 -5
- package/dist/server/app-server-action-execution.d.ts +5 -0
- package/dist/server/app-server-action-execution.js +94 -33
- package/dist/server/app-ssr-entry.js +12 -1
- package/dist/server/app-static-generation.d.ts +1 -0
- package/dist/server/app-static-generation.js +1 -0
- package/dist/server/client-trace-metadata.js +26 -0
- package/dist/server/default-global-not-found-module.d.ts +14 -0
- package/dist/server/default-global-not-found-module.js +14 -0
- package/dist/server/dev-server.js +8 -15
- package/dist/server/dev-stack-sourcemap.d.ts +1 -1
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/headers.d.ts +5 -15
- package/dist/server/headers.js +4 -15
- package/dist/server/image-optimization.d.ts +51 -1
- package/dist/server/image-optimization.js +52 -2
- package/dist/server/isr-cache.d.ts +1 -1
- package/dist/server/isr-cache.js +2 -2
- package/dist/server/middleware-runtime.js +6 -1
- package/dist/server/navigation-planner.d.ts +1 -0
- package/dist/server/navigation-planner.js +14 -3
- package/dist/server/pages-asset-tags.d.ts +4 -6
- package/dist/server/pages-asset-tags.js +12 -12
- package/dist/server/pages-client-assets.d.ts +12 -0
- package/dist/server/pages-client-assets.js +10 -0
- package/dist/server/pages-page-data.d.ts +23 -1
- package/dist/server/pages-page-data.js +43 -24
- package/dist/server/pages-page-handler.d.ts +2 -1
- package/dist/server/pages-page-handler.js +10 -4
- package/dist/server/pages-request-pipeline.d.ts +2 -0
- package/dist/server/pages-request-pipeline.js +25 -1
- package/dist/server/prerender-manifest.d.ts +3 -1
- package/dist/server/prerender-route-params.js +1 -1
- package/dist/server/prod-server.d.ts +1 -1
- package/dist/server/prod-server.js +47 -25
- package/dist/server/request-pipeline.js +1 -0
- package/dist/server/seed-cache.js +4 -4
- package/dist/server/worker-utils.d.ts +2 -1
- package/dist/server/worker-utils.js +7 -1
- package/dist/shims/app-router-scroll-state.d.ts +1 -0
- package/dist/shims/app-router-scroll-state.js +1 -0
- package/dist/shims/app-router-scroll.js +2 -1
- package/dist/shims/cache.js +19 -15
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/dynamic-preload-chunks.js +2 -1
- package/dist/shims/error-boundary.d.ts +19 -1
- package/dist/shims/error-boundary.js +11 -1
- package/dist/shims/form.d.ts +3 -1
- package/dist/shims/form.js +37 -43
- package/dist/shims/headers.d.ts +9 -1
- package/dist/shims/headers.js +31 -6
- package/dist/shims/image-optimization-url.d.ts +4 -0
- package/dist/shims/image-optimization-url.js +33 -1
- package/dist/shims/image.js +46 -13
- package/dist/shims/internal/app-route-detection.d.ts +2 -17
- package/dist/shims/internal/app-route-detection.js +4 -17
- package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
- package/dist/shims/internal/hybrid-client-route-owner.d.ts +2 -5
- package/dist/shims/internal/hybrid-client-route-owner.js +9 -60
- package/dist/shims/internal/pages-router-components.d.ts +7 -0
- package/dist/shims/internal/pages-router-components.js +13 -0
- package/dist/shims/link.js +23 -16
- package/dist/shims/metadata.d.ts +3 -2
- package/dist/shims/metadata.js +8 -4
- package/dist/shims/navigation.js +4 -2
- package/dist/shims/root-params.d.ts +15 -1
- package/dist/shims/root-params.js +21 -1
- package/dist/shims/router.d.ts +2 -5
- package/dist/shims/router.js +41 -22
- package/dist/shims/server.js +3 -2
- package/dist/typegen.js +6 -5
- package/dist/utils/client-runtime-metadata.d.ts +2 -18
- package/dist/utils/client-runtime-metadata.js +31 -22
- package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
- package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
- package/dist/utils/domain-locale.d.ts +6 -3
- package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
- package/dist/{server → utils}/middleware-request-headers.js +2 -2
- package/dist/utils/path.d.ts +2 -1
- package/dist/utils/path.js +1 -1
- package/dist/utils/project.d.ts +9 -1
- package/dist/utils/project.js +21 -4
- package/dist/utils/protocol-headers.d.ts +17 -0
- package/dist/utils/protocol-headers.js +17 -0
- package/dist/utils/react-version.d.ts +4 -0
- package/dist/utils/react-version.js +44 -0
- package/package.json +6 -1
- package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
- /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Readable, Writable } from "node:stream";
|
|
2
|
+
|
|
3
|
+
//#region src/init-platform.d.ts
|
|
4
|
+
type InitPlatform = "cloudflare" | "node";
|
|
5
|
+
type InitDataCache = "kv" | "none";
|
|
6
|
+
type InitCdnCache = "data-cache" | "workers-cache";
|
|
7
|
+
type InitImageOptimization = "cloudflare-images" | "none";
|
|
8
|
+
type CloudflareInitOptions = {
|
|
9
|
+
dataCache: InitDataCache;
|
|
10
|
+
cdnCache: InitCdnCache;
|
|
11
|
+
imageOptimization: InitImageOptimization;
|
|
12
|
+
};
|
|
13
|
+
declare const INIT_PLATFORMS: {
|
|
14
|
+
cloudflare: {
|
|
15
|
+
name: string;
|
|
16
|
+
options: typeof resolveCloudflareInitOptions;
|
|
17
|
+
};
|
|
18
|
+
node: {
|
|
19
|
+
name: string;
|
|
20
|
+
options: () => Promise<undefined>;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
type PlatformPromptOptions = {
|
|
24
|
+
env?: Record<string, string | undefined>;
|
|
25
|
+
input?: Readable;
|
|
26
|
+
output?: Writable;
|
|
27
|
+
isInteractive?: boolean;
|
|
28
|
+
question?: (prompt: string) => Promise<string>;
|
|
29
|
+
};
|
|
30
|
+
declare function isAgentEnvironment(env?: Record<string, string | undefined>): boolean;
|
|
31
|
+
declare function parsePlatformArg(args: string[]): InitPlatform | undefined;
|
|
32
|
+
declare function parseDataCacheArg(args: string[]): InitDataCache | undefined;
|
|
33
|
+
declare function parseCdnCacheArg(args: string[]): InitCdnCache | undefined;
|
|
34
|
+
declare function parseImageOptimizationArg(args: string[]): InitImageOptimization | undefined;
|
|
35
|
+
declare function resolveInitPlatform(args: string[], options?: PlatformPromptOptions): Promise<InitPlatform>;
|
|
36
|
+
declare function resolveCloudflareInitOptions(args: string[], options?: PlatformPromptOptions): Promise<CloudflareInitOptions>;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { CloudflareInitOptions, INIT_PLATFORMS, InitCdnCache, InitDataCache, InitImageOptimization, InitPlatform, isAgentEnvironment, parseCdnCacheArg, parseDataCacheArg, parseImageOptimizationArg, parsePlatformArg, resolveCloudflareInitOptions, resolveInitPlatform };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { isAgent } from "./node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js";
|
|
2
|
+
import { createInterface } from "node:readline/promises";
|
|
3
|
+
//#region src/init-platform.ts
|
|
4
|
+
const INIT_PLATFORMS = {
|
|
5
|
+
cloudflare: {
|
|
6
|
+
name: "Cloudflare",
|
|
7
|
+
options: resolveCloudflareInitOptions
|
|
8
|
+
},
|
|
9
|
+
node: {
|
|
10
|
+
name: "Node",
|
|
11
|
+
options: async () => void 0
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
function isAgentEnvironment(env = process.env) {
|
|
15
|
+
return isAgent({ env });
|
|
16
|
+
}
|
|
17
|
+
function parsePlatformArg(args) {
|
|
18
|
+
for (let index = 0; index < args.length; index++) {
|
|
19
|
+
const arg = args[index];
|
|
20
|
+
let value;
|
|
21
|
+
if (arg === "--platform") {
|
|
22
|
+
value = args[index + 1];
|
|
23
|
+
if (!value || value.startsWith("-")) throw new Error("--platform requires a value (cloudflare or node).");
|
|
24
|
+
} else if (arg.startsWith("--platform=")) {
|
|
25
|
+
value = arg.slice(11);
|
|
26
|
+
if (!value) throw new Error("--platform requires a value (cloudflare or node).");
|
|
27
|
+
}
|
|
28
|
+
if (value) {
|
|
29
|
+
if (value === "cloudflare" || value === "node") return value;
|
|
30
|
+
throw new Error(`Unsupported platform "${value}". Expected cloudflare or node.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function parseChoiceArg(args, flag, choices, displayedChoices = choices) {
|
|
35
|
+
for (let index = 0; index < args.length; index++) {
|
|
36
|
+
const arg = args[index];
|
|
37
|
+
let value;
|
|
38
|
+
if (arg === flag) {
|
|
39
|
+
value = args[index + 1];
|
|
40
|
+
if (!value || value.startsWith("-")) throw new Error(`${flag} requires a value (${displayedChoices.join(" or ")}).`);
|
|
41
|
+
} else if (arg.startsWith(`${flag}=`)) {
|
|
42
|
+
value = arg.slice(flag.length + 1);
|
|
43
|
+
if (!value) throw new Error(`${flag} requires a value (${displayedChoices.join(" or ")}).`);
|
|
44
|
+
}
|
|
45
|
+
if (value) {
|
|
46
|
+
if (choices.includes(value)) return value;
|
|
47
|
+
throw new Error(`Unsupported ${flag} value "${value}". Expected ${displayedChoices.join(" or ")}.`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function parseDataCacheArg(args) {
|
|
52
|
+
return parseChoiceArg(args, "--data-cache", ["kv", "none"]);
|
|
53
|
+
}
|
|
54
|
+
function parseCdnCacheArg(args) {
|
|
55
|
+
return parseChoiceArg(args, "--cdn-cache", ["data-cache", "workers-cache"], ["data-cache"]);
|
|
56
|
+
}
|
|
57
|
+
function parseImageOptimizationArg(args) {
|
|
58
|
+
return parseChoiceArg(args, "--image-optimization", ["cloudflare-images", "none"]);
|
|
59
|
+
}
|
|
60
|
+
async function resolveInitPlatform(args, options = {}) {
|
|
61
|
+
const explicitPlatform = parsePlatformArg(args);
|
|
62
|
+
if (explicitPlatform) return explicitPlatform;
|
|
63
|
+
if (isAgentEnvironment(options.env ?? process.env)) throw new Error("vinext init needs a deployment target. Ask the user whether they want Cloudflare or Node, then re-run the command with --platform=cloudflare or --platform=node.");
|
|
64
|
+
const input = options.input ?? process.stdin;
|
|
65
|
+
const output = options.output ?? process.stdout;
|
|
66
|
+
if (!(options.isInteractive ?? Boolean(process.stdin.isTTY && process.stdout.isTTY))) return "cloudflare";
|
|
67
|
+
const readline = options.question ? void 0 : createInterface({
|
|
68
|
+
input,
|
|
69
|
+
output
|
|
70
|
+
});
|
|
71
|
+
const question = options.question ?? ((prompt) => readline.question(prompt));
|
|
72
|
+
try {
|
|
73
|
+
while (true) {
|
|
74
|
+
const answer = (await question(` Choose a deployment platform:
|
|
75
|
+
1. ${INIT_PLATFORMS.cloudflare.name} (default)\n 2. ${INIT_PLATFORMS.node.name}\n Platform [1]: `)).trim().toLowerCase();
|
|
76
|
+
if (answer === "" || answer === "1" || answer === "cloudflare") {
|
|
77
|
+
output.write("\n");
|
|
78
|
+
return "cloudflare";
|
|
79
|
+
}
|
|
80
|
+
if (answer === "2" || answer === "node") {
|
|
81
|
+
output.write("\n");
|
|
82
|
+
return "node";
|
|
83
|
+
}
|
|
84
|
+
output.write(" Please choose Cloudflare (1) or Node (2).\n");
|
|
85
|
+
}
|
|
86
|
+
} finally {
|
|
87
|
+
readline?.close();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function resolveCloudflareInitOptions(args, options = {}) {
|
|
91
|
+
const explicitDataCache = parseDataCacheArg(args);
|
|
92
|
+
const explicitCdnCache = parseCdnCacheArg(args);
|
|
93
|
+
const explicitImageOptimization = parseImageOptimizationArg(args);
|
|
94
|
+
if (explicitDataCache && explicitImageOptimization) return {
|
|
95
|
+
dataCache: explicitDataCache,
|
|
96
|
+
cdnCache: explicitCdnCache ?? "data-cache",
|
|
97
|
+
imageOptimization: explicitImageOptimization
|
|
98
|
+
};
|
|
99
|
+
if (isAgentEnvironment(options.env ?? process.env)) throw new Error("vinext init needs Cloudflare cache and image choices. Ask the user which data cache (kv or none) and image optimization (cloudflare-images or none) they want, then re-run with --data-cache=... and --image-optimization=....");
|
|
100
|
+
const input = options.input ?? process.stdin;
|
|
101
|
+
const output = options.output ?? process.stdout;
|
|
102
|
+
if (!(options.isInteractive ?? Boolean(process.stdin.isTTY && process.stdout.isTTY))) return {
|
|
103
|
+
dataCache: explicitDataCache ?? "kv",
|
|
104
|
+
cdnCache: explicitCdnCache ?? "data-cache",
|
|
105
|
+
imageOptimization: explicitImageOptimization ?? "cloudflare-images"
|
|
106
|
+
};
|
|
107
|
+
const readline = options.question ? void 0 : createInterface({
|
|
108
|
+
input,
|
|
109
|
+
output
|
|
110
|
+
});
|
|
111
|
+
const question = options.question ?? ((prompt) => readline.question(prompt));
|
|
112
|
+
try {
|
|
113
|
+
const promptChoice = async (current, prompt, values, defaultValue, error) => {
|
|
114
|
+
if (current) return current;
|
|
115
|
+
while (true) {
|
|
116
|
+
const answer = (await question(prompt)).trim().toLowerCase();
|
|
117
|
+
if (answer === "") {
|
|
118
|
+
output.write("\n");
|
|
119
|
+
return defaultValue;
|
|
120
|
+
}
|
|
121
|
+
const value = values[answer];
|
|
122
|
+
if (value) {
|
|
123
|
+
output.write("\n");
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
output.write(` ${error}\n`);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
return {
|
|
130
|
+
dataCache: await promptChoice(explicitDataCache, " Choose a data cache:\n 1. Cloudflare KV (default)\n 2. None\n Data cache [1]: ", {
|
|
131
|
+
"1": "kv",
|
|
132
|
+
kv: "kv",
|
|
133
|
+
"2": "none",
|
|
134
|
+
none: "none"
|
|
135
|
+
}, "kv", "Please choose Cloudflare KV (1) or None (2)."),
|
|
136
|
+
cdnCache: explicitCdnCache ?? "data-cache",
|
|
137
|
+
imageOptimization: await promptChoice(explicitImageOptimization, " Choose image optimization:\n 1. Cloudflare Images (default)\n 2. None\n Image optimization [1]: ", {
|
|
138
|
+
"1": "cloudflare-images",
|
|
139
|
+
"cloudflare-images": "cloudflare-images",
|
|
140
|
+
images: "cloudflare-images",
|
|
141
|
+
"2": "none",
|
|
142
|
+
none: "none"
|
|
143
|
+
}, "cloudflare-images", "Please choose Cloudflare Images (1) or None (2).")
|
|
144
|
+
};
|
|
145
|
+
} finally {
|
|
146
|
+
readline?.close();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
export { INIT_PLATFORMS, isAgentEnvironment, parseCdnCacheArg, parseDataCacheArg, parseImageOptimizationArg, parsePlatformArg, resolveCloudflareInitOptions, resolveInitPlatform };
|
package/dist/init.d.ts
CHANGED
|
@@ -1,30 +1,20 @@
|
|
|
1
|
+
import { CloudflareInitOptions, InitPlatform } from "./init-platform.js";
|
|
2
|
+
import { getReactUpgradeDeps } from "./utils/react-version.js";
|
|
3
|
+
|
|
1
4
|
//#region src/init.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* vinext init — one-command project migration for Next.js apps.
|
|
4
|
-
*
|
|
5
|
-
* Automates the steps needed to run a Next.js app under vinext:
|
|
6
|
-
*
|
|
7
|
-
* 1. Run `vinext check` to show compatibility report
|
|
8
|
-
* 2. Install dependencies (vite, @vitejs/plugin-react, and App Router deps)
|
|
9
|
-
* 3. Add "type": "module" to package.json
|
|
10
|
-
* 4. Rename CJS config files to .cjs
|
|
11
|
-
* 5. Add vinext scripts to package.json
|
|
12
|
-
* 6. Generate vite.config.ts
|
|
13
|
-
* 7. Update .gitignore to include /dist/ and .vinext/
|
|
14
|
-
* 8. Print summary
|
|
15
|
-
*
|
|
16
|
-
* Non-destructive: does NOT modify next.config, tsconfig, or source files.
|
|
17
|
-
* The project should work with both Next.js and vinext simultaneously.
|
|
18
|
-
*/
|
|
19
5
|
type InitOptions = {
|
|
20
6
|
/** Project root directory */root: string; /** Dev server port (default: 3001) */
|
|
21
7
|
port?: number; /** Skip the compatibility check step */
|
|
22
8
|
skipCheck?: boolean; /** Force overwrite even if vite.config.ts exists */
|
|
23
|
-
force?: boolean; /**
|
|
9
|
+
force?: boolean; /** Deployment target selected by the user */
|
|
10
|
+
platform?: InitPlatform; /** Cloudflare cache and image choices. */
|
|
11
|
+
cloudflare?: CloudflareInitOptions; /** @internal — override exec for testing (avoids ESM spy issues) */
|
|
24
12
|
_exec?: (cmd: string, opts: {
|
|
25
13
|
cwd: string;
|
|
26
14
|
stdio: string;
|
|
27
|
-
}) => void
|
|
15
|
+
}) => string | void | Promise<string | void>; /** @internal — override pnpm ignored-builds inspection for testing */
|
|
16
|
+
_inspectPnpmIgnoredBuilds?: (root: string) => string; /** @internal — stable compatibility date for snapshot tests */
|
|
17
|
+
_today?: string;
|
|
28
18
|
};
|
|
29
19
|
type InitResult = {
|
|
30
20
|
/** Whether dependencies were installed */installedDeps: string[]; /** Whether "type": "module" was added */
|
|
@@ -33,7 +23,9 @@ type InitResult = {
|
|
|
33
23
|
addedScripts: string[]; /** Whether vite.config.ts was generated */
|
|
34
24
|
generatedViteConfig: boolean; /** Whether vite.config.ts generation was skipped (already exists) */
|
|
35
25
|
skippedViteConfig: boolean; /** Whether .gitignore was updated to include vinext-generated output */
|
|
36
|
-
updatedGitignore: boolean;
|
|
26
|
+
updatedGitignore: boolean; /** Deployment target configured by init */
|
|
27
|
+
platform: InitPlatform; /** Platform-specific deployment files generated by init */
|
|
28
|
+
generatedPlatformFiles: string[];
|
|
37
29
|
};
|
|
38
30
|
declare function generateViteConfig(_isAppRouter: boolean): string;
|
|
39
31
|
/**
|
|
@@ -41,29 +33,14 @@ declare function generateViteConfig(_isAppRouter: boolean): string;
|
|
|
41
33
|
* Returns the list of script names that were added.
|
|
42
34
|
*/
|
|
43
35
|
declare function addScripts(root: string, port: number): string[];
|
|
44
|
-
declare function getInitDeps(isAppRouter: boolean): string[];
|
|
36
|
+
declare function getInitDeps(isAppRouter: boolean, platform: InitPlatform): string[];
|
|
45
37
|
declare function isDepInstalled(root: string, dep: string): boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Check if react/react-dom need upgrading for react-server-dom-webpack compatibility.
|
|
48
|
-
*
|
|
49
|
-
* react-server-dom-webpack versions are pinned to match their React version
|
|
50
|
-
* (e.g. rsdw@19.2.6 requires react@^19.2.6). When a project has an older
|
|
51
|
-
* React (e.g. create-next-app ships react@19.2.3), we need to upgrade
|
|
52
|
-
* react/react-dom BEFORE installing rsdw to avoid peer-dep conflicts.
|
|
53
|
-
*
|
|
54
|
-
* Uses createRequire to resolve react's package.json through Node's module
|
|
55
|
-
* resolution, which works correctly across all package managers (npm, pnpm,
|
|
56
|
-
* yarn, Yarn PnP) and monorepo layouts with hoisting/symlinking.
|
|
57
|
-
*
|
|
58
|
-
* Returns ["react@latest", "react-dom@latest"] if upgrade is needed, [] otherwise.
|
|
59
|
-
*/
|
|
60
|
-
declare function getReactUpgradeDeps(root: string): string[];
|
|
61
38
|
/**
|
|
62
39
|
* Ensure vinext-generated output directories are listed in .gitignore.
|
|
63
40
|
* Creates the file if it doesn't exist. Returns true if the file was modified
|
|
64
41
|
* (or created), false if all entries were already present.
|
|
65
42
|
*/
|
|
66
|
-
declare function updateGitignore(root: string): boolean;
|
|
43
|
+
declare function updateGitignore(root: string, platform?: InitPlatform): boolean;
|
|
67
44
|
declare function init(options: InitOptions): Promise<InitResult>;
|
|
68
45
|
//#endregion
|
|
69
46
|
export { InitOptions, addScripts, generateViteConfig, getInitDeps, getReactUpgradeDeps, init, isDepInstalled, updateGitignore };
|
package/dist/init.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { detectPackageManager, detectPackageManagerName, ensureESModule,
|
|
1
|
+
import { detectPackageManager, detectPackageManagerName, ensureESModule, findViteConfigPath, hasViteConfig, renameCJSConfigs } from "./utils/project.js";
|
|
2
2
|
import { formatReport, runCheck } from "./check.js";
|
|
3
|
-
import {
|
|
3
|
+
import { detectProject } from "./cloudflare/project.js";
|
|
4
|
+
import { setupCloudflarePlatform, usesCommonJsViteConfig, validateCloudflarePlatformSetup } from "./init-cloudflare.js";
|
|
5
|
+
import { getReactUpgradeDeps } from "./utils/react-version.js";
|
|
4
6
|
import fs from "node:fs";
|
|
5
7
|
import path from "node:path";
|
|
6
|
-
import {
|
|
8
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
7
9
|
//#region src/init.ts
|
|
8
10
|
/**
|
|
9
11
|
* vinext init — one-command project migration for Next.js apps.
|
|
@@ -11,17 +13,52 @@ import { execFileSync } from "node:child_process";
|
|
|
11
13
|
* Automates the steps needed to run a Next.js app under vinext:
|
|
12
14
|
*
|
|
13
15
|
* 1. Run `vinext check` to show compatibility report
|
|
14
|
-
* 2.
|
|
15
|
-
* 3.
|
|
16
|
-
* 4.
|
|
17
|
-
* 5.
|
|
18
|
-
* 6.
|
|
19
|
-
* 7.
|
|
16
|
+
* 2. Add "type": "module" to package.json
|
|
17
|
+
* 3. Rename CJS config files to .cjs
|
|
18
|
+
* 4. Add vinext scripts to package.json
|
|
19
|
+
* 5. Generate vite.config.ts and platform files
|
|
20
|
+
* 6. Update .gitignore to include /dist/ and .vinext/
|
|
21
|
+
* 7. Install dependencies (vite, @vitejs/plugin-react, and App Router deps)
|
|
20
22
|
* 8. Print summary
|
|
21
23
|
*
|
|
22
24
|
* Non-destructive: does NOT modify next.config, tsconfig, or source files.
|
|
23
25
|
* The project should work with both Next.js and vinext simultaneously.
|
|
24
26
|
*/
|
|
27
|
+
const terminalStyle = {
|
|
28
|
+
bold: (value) => process.stdout.isTTY ? `\x1b[1m${value}\x1b[0m` : value,
|
|
29
|
+
cyan: (value) => process.stdout.isTTY ? `\x1b[36m${value}\x1b[0m` : value,
|
|
30
|
+
green: (value) => process.stdout.isTTY ? `\x1b[32m${value}\x1b[0m` : value,
|
|
31
|
+
yellow: (value) => process.stdout.isTTY ? `\x1b[33m${value}\x1b[0m` : value
|
|
32
|
+
};
|
|
33
|
+
function formatList(items, indent) {
|
|
34
|
+
return items.map((item) => `${indent}- ${item}`).join("\n");
|
|
35
|
+
}
|
|
36
|
+
function isApproveBuildsError(error) {
|
|
37
|
+
const details = [
|
|
38
|
+
error instanceof Error ? error.message : String(error),
|
|
39
|
+
typeof error === "object" && error && "output" in error ? String(error.output) : "",
|
|
40
|
+
typeof error === "object" && error && "stdout" in error ? String(error.stdout) : "",
|
|
41
|
+
typeof error === "object" && error && "stderr" in error ? String(error.stderr) : ""
|
|
42
|
+
].join("\n");
|
|
43
|
+
return /approve-builds|ignored build scripts|blocked build scripts|ERR_PNPM_.*BUILD/i.test(details);
|
|
44
|
+
}
|
|
45
|
+
function hasAutomaticallyIgnoredBuilds(output) {
|
|
46
|
+
const automaticallyIgnored = output.match(/Automatically ignored builds during installation:\s*\n([\s\S]*?)(?:\n\s*\n|$)/i)?.[1];
|
|
47
|
+
if (!automaticallyIgnored) return false;
|
|
48
|
+
return automaticallyIgnored.split("\n").map((line) => line.trim()).some((line) => line.length > 0 && !/^none\.?$/i.test(line) && !/^cannot identify\b/i.test(line));
|
|
49
|
+
}
|
|
50
|
+
function inspectPnpmIgnoredBuilds(root) {
|
|
51
|
+
const result = spawnSync("pnpm", ["ignored-builds"], {
|
|
52
|
+
cwd: root,
|
|
53
|
+
encoding: "utf-8",
|
|
54
|
+
stdio: [
|
|
55
|
+
"ignore",
|
|
56
|
+
"pipe",
|
|
57
|
+
"pipe"
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
return `${result.stdout ?? ""}\n${result.stderr ?? ""}`;
|
|
61
|
+
}
|
|
25
62
|
function generateViteConfig(_isAppRouter) {
|
|
26
63
|
return `import vinext from "vinext";
|
|
27
64
|
import { defineConfig } from "vite";
|
|
@@ -61,7 +98,7 @@ function addScripts(root, port) {
|
|
|
61
98
|
return [];
|
|
62
99
|
}
|
|
63
100
|
}
|
|
64
|
-
function getInitDeps(isAppRouter) {
|
|
101
|
+
function getInitDeps(isAppRouter, platform) {
|
|
65
102
|
const deps = [
|
|
66
103
|
"vinext",
|
|
67
104
|
"vite",
|
|
@@ -71,6 +108,7 @@ function getInitDeps(isAppRouter) {
|
|
|
71
108
|
deps.push("@vitejs/plugin-rsc");
|
|
72
109
|
deps.push("react-server-dom-webpack");
|
|
73
110
|
}
|
|
111
|
+
if (platform === "cloudflare") deps.push("@cloudflare/vite-plugin", "@vinext/cloudflare", "wrangler");
|
|
74
112
|
return deps;
|
|
75
113
|
}
|
|
76
114
|
function isDepInstalled(root, dep) {
|
|
@@ -101,68 +139,50 @@ function isDepInstalled(root, dep) {
|
|
|
101
139
|
*
|
|
102
140
|
* Returns ["react@latest", "react-dom@latest"] if upgrade is needed, [] otherwise.
|
|
103
141
|
*/
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
const version = findPackageVersion(createRequire(path.join(root, "package.json")).resolve("react"), "react");
|
|
107
|
-
if (!version) return [];
|
|
108
|
-
const parts = version.split(".");
|
|
109
|
-
const major = parseInt(parts[0], 10);
|
|
110
|
-
const minor = parseInt(parts[1], 10);
|
|
111
|
-
const patch = parseInt(parts[2], 10);
|
|
112
|
-
if (major < 19 || major === 19 && minor < 2 || major === 19 && minor === 2 && patch < 6) return ["react@latest", "react-dom@latest"];
|
|
113
|
-
return [];
|
|
114
|
-
} catch {
|
|
115
|
-
return [];
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Walk up from a resolved module entry to find its package.json and return
|
|
120
|
-
* the version field. Uses the same approach as PR #18's findReactServerPackages.
|
|
121
|
-
*/
|
|
122
|
-
function findPackageVersion(resolvedEntry, packageName) {
|
|
123
|
-
let dir = path.dirname(resolvedEntry);
|
|
124
|
-
while (dir !== path.dirname(dir)) {
|
|
125
|
-
const candidate = path.join(dir, "package.json");
|
|
126
|
-
try {
|
|
127
|
-
const pkg = JSON.parse(fs.readFileSync(candidate, "utf-8"));
|
|
128
|
-
if (pkg.name === packageName) return pkg.version ?? null;
|
|
129
|
-
} catch {}
|
|
130
|
-
dir = path.dirname(dir);
|
|
131
|
-
}
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
function installDeps(root, deps, exec, { dev = true } = {}) {
|
|
135
|
-
if (deps.length === 0) return;
|
|
142
|
+
async function installDeps(root, deps, exec, { dev = true } = {}) {
|
|
143
|
+
if (deps.length === 0) return "";
|
|
136
144
|
const baseCmd = detectPackageManager(root);
|
|
137
|
-
exec(`${dev ? baseCmd : baseCmd.replace(/ -D$/, "")} ${deps.join(" ")}`, {
|
|
145
|
+
return await exec(`${dev ? baseCmd : baseCmd.replace(/ -D$/, "")} ${deps.join(" ")}`, {
|
|
138
146
|
cwd: root,
|
|
139
147
|
stdio: "inherit"
|
|
140
|
-
});
|
|
148
|
+
}) ?? "";
|
|
141
149
|
}
|
|
142
150
|
/**
|
|
143
151
|
* Ensure vinext-generated output directories are listed in .gitignore.
|
|
144
152
|
* Creates the file if it doesn't exist. Returns true if the file was modified
|
|
145
153
|
* (or created), false if all entries were already present.
|
|
146
154
|
*/
|
|
147
|
-
function updateGitignore(root) {
|
|
155
|
+
function updateGitignore(root, platform = "node") {
|
|
148
156
|
const gitignorePath = path.join(root, ".gitignore");
|
|
149
|
-
const entries = [
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
"
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
157
|
+
const entries = [
|
|
158
|
+
{
|
|
159
|
+
entry: "/dist/",
|
|
160
|
+
coveredBy: new Set([
|
|
161
|
+
"/dist/",
|
|
162
|
+
"/dist",
|
|
163
|
+
"dist/",
|
|
164
|
+
"dist"
|
|
165
|
+
])
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
entry: ".vinext/",
|
|
169
|
+
coveredBy: new Set([
|
|
170
|
+
"/.vinext/",
|
|
171
|
+
"/.vinext",
|
|
172
|
+
".vinext/",
|
|
173
|
+
".vinext"
|
|
174
|
+
])
|
|
175
|
+
},
|
|
176
|
+
...platform === "cloudflare" ? [{
|
|
177
|
+
entry: ".wrangler/",
|
|
178
|
+
coveredBy: new Set([
|
|
179
|
+
"/.wrangler/",
|
|
180
|
+
"/.wrangler",
|
|
181
|
+
".wrangler/",
|
|
182
|
+
".wrangler"
|
|
183
|
+
])
|
|
184
|
+
}] : []
|
|
185
|
+
];
|
|
166
186
|
let content = "";
|
|
167
187
|
let lines = [];
|
|
168
188
|
if (fs.existsSync(gitignorePath)) {
|
|
@@ -175,78 +195,168 @@ function updateGitignore(root) {
|
|
|
175
195
|
fs.writeFileSync(gitignorePath, content + separator + missingEntries.join("\n") + "\n", "utf-8");
|
|
176
196
|
return true;
|
|
177
197
|
}
|
|
198
|
+
function setupNodePlatform(context) {
|
|
199
|
+
if (context.viteConfigExists && !context.force) return {
|
|
200
|
+
generatedViteConfig: false,
|
|
201
|
+
skippedViteConfig: true,
|
|
202
|
+
generatedPlatformFiles: [],
|
|
203
|
+
nextSteps: []
|
|
204
|
+
};
|
|
205
|
+
fs.writeFileSync(context.existingViteConfigPath ?? path.join(context.root, "vite.config.ts"), generateViteConfig(context.isAppRouter), "utf-8");
|
|
206
|
+
return {
|
|
207
|
+
generatedViteConfig: true,
|
|
208
|
+
skippedViteConfig: false,
|
|
209
|
+
generatedPlatformFiles: [],
|
|
210
|
+
nextSteps: []
|
|
211
|
+
};
|
|
212
|
+
}
|
|
178
213
|
async function init(options) {
|
|
179
214
|
const root = path.resolve(options.root);
|
|
180
215
|
const port = options.port ?? 3001;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
216
|
+
if (!options.platform) throw new Error("A deployment platform must be selected before running vinext init.");
|
|
217
|
+
const platform = options.platform;
|
|
218
|
+
if (platform === "cloudflare" && !options.cloudflare) throw new Error("Cloudflare init options must be resolved before running vinext init.");
|
|
219
|
+
const exec = options._exec ?? ((cmd, opts) => new Promise((resolve, reject) => {
|
|
220
|
+
const child = spawn(cmd, {
|
|
221
|
+
cwd: opts.cwd,
|
|
222
|
+
shell: true,
|
|
223
|
+
stdio: [
|
|
224
|
+
"inherit",
|
|
225
|
+
"pipe",
|
|
226
|
+
"pipe"
|
|
227
|
+
]
|
|
186
228
|
});
|
|
187
|
-
|
|
229
|
+
let output = "";
|
|
230
|
+
child.stdout.on("data", (chunk) => {
|
|
231
|
+
const text = chunk.toString();
|
|
232
|
+
output += text;
|
|
233
|
+
process.stdout.write(text);
|
|
234
|
+
});
|
|
235
|
+
child.stderr.on("data", (chunk) => {
|
|
236
|
+
const text = chunk.toString();
|
|
237
|
+
output += text;
|
|
238
|
+
process.stderr.write(text);
|
|
239
|
+
});
|
|
240
|
+
child.on("error", (error) => reject(Object.assign(error, { output })));
|
|
241
|
+
child.on("close", (status) => {
|
|
242
|
+
if (status === 0) resolve(output);
|
|
243
|
+
else reject(Object.assign(/* @__PURE__ */ new Error(`Command failed with exit code ${status}: ${cmd}`), {
|
|
244
|
+
status,
|
|
245
|
+
output
|
|
246
|
+
}));
|
|
247
|
+
});
|
|
248
|
+
}));
|
|
188
249
|
const pkgPath = path.join(root, "package.json");
|
|
189
250
|
if (!fs.existsSync(pkgPath)) {
|
|
190
251
|
console.error(" Error: No package.json found in the current directory.");
|
|
191
252
|
console.error(" Run this command from the root of a Next.js project.\n");
|
|
192
253
|
process.exit(1);
|
|
193
254
|
}
|
|
255
|
+
let existingViteConfigPath = findViteConfigPath(root);
|
|
256
|
+
if (existingViteConfigPath?.endsWith("vite.config.js")) {
|
|
257
|
+
const existingConfig = fs.readFileSync(existingViteConfigPath, "utf-8");
|
|
258
|
+
const cjsPath = existingViteConfigPath.replace(/\.js$/, ".cjs");
|
|
259
|
+
if (usesCommonJsViteConfig(existingViteConfigPath, existingConfig) && fs.existsSync(cjsPath)) throw new Error("Cannot rename CommonJS vite.config.js because vite.config.cjs already exists. Remove or consolidate one of the files, then rerun vinext init.");
|
|
260
|
+
}
|
|
194
261
|
const viteConfigExists = hasViteConfig(root);
|
|
195
|
-
const isApp =
|
|
262
|
+
const isApp = detectProject(root).isAppRouter;
|
|
196
263
|
const pmName = detectPackageManagerName(root);
|
|
264
|
+
if (platform === "cloudflare") validateCloudflarePlatformSetup({
|
|
265
|
+
root,
|
|
266
|
+
isAppRouter: isApp,
|
|
267
|
+
existingViteConfigPath,
|
|
268
|
+
today: options._today
|
|
269
|
+
}, options.cloudflare);
|
|
197
270
|
if (!options.skipCheck) {
|
|
198
271
|
console.log(" Running compatibility check...\n");
|
|
199
272
|
const checkResult = runCheck(root);
|
|
200
273
|
console.log(formatReport(checkResult, { calledFromInit: true }));
|
|
201
274
|
console.log();
|
|
202
275
|
}
|
|
203
|
-
const
|
|
276
|
+
const renamedConfigs = renameCJSConfigs(root);
|
|
277
|
+
if (existingViteConfigPath?.endsWith("vite.config.js") && usesCommonJsViteConfig(existingViteConfigPath, fs.readFileSync(existingViteConfigPath, "utf-8"))) {
|
|
278
|
+
const renamedPath = existingViteConfigPath.replace(/\.js$/, ".cjs");
|
|
279
|
+
fs.renameSync(existingViteConfigPath, renamedPath);
|
|
280
|
+
renamedConfigs.push([path.basename(existingViteConfigPath), path.basename(renamedPath)]);
|
|
281
|
+
existingViteConfigPath = renamedPath;
|
|
282
|
+
}
|
|
283
|
+
const addedTypeModule = ensureESModule(root);
|
|
284
|
+
const addedScripts = addScripts(root, port);
|
|
285
|
+
const setupContext = {
|
|
286
|
+
root,
|
|
287
|
+
isAppRouter: isApp,
|
|
288
|
+
existingViteConfigPath,
|
|
289
|
+
viteConfigExists,
|
|
290
|
+
force: options.force ?? false,
|
|
291
|
+
today: options._today
|
|
292
|
+
};
|
|
293
|
+
const platformSetup = platform === "cloudflare" ? setupCloudflarePlatform(setupContext, options.cloudflare) : setupNodePlatform(setupContext);
|
|
294
|
+
const { generatedViteConfig, skippedViteConfig, generatedPlatformFiles } = platformSetup;
|
|
295
|
+
const updatedGitignore = updateGitignore(root, platform);
|
|
296
|
+
const missingDeps = getInitDeps(isApp, platform).filter((dep) => !isDepInstalled(root, dep));
|
|
297
|
+
let dependencyInstallNeedsApproval = false;
|
|
298
|
+
let dependenciesAdded = false;
|
|
204
299
|
if (isApp && missingDeps.includes("react-server-dom-webpack")) {
|
|
205
300
|
const reactUpgrade = getReactUpgradeDeps(root);
|
|
206
301
|
if (reactUpgrade.length > 0) {
|
|
207
|
-
console.log(`
|
|
208
|
-
|
|
302
|
+
console.log(` ${terminalStyle.cyan(terminalStyle.bold("Upgrading dependencies:"))}`);
|
|
303
|
+
console.log(formatList(reactUpgrade.map((dep) => dep.replace(/@latest$/, "")), " "));
|
|
304
|
+
try {
|
|
305
|
+
if (isApproveBuildsError(await installDeps(root, reactUpgrade, exec, { dev: false }))) dependencyInstallNeedsApproval = true;
|
|
306
|
+
} catch (error) {
|
|
307
|
+
if (pmName !== "pnpm" || !isApproveBuildsError(error)) throw error;
|
|
308
|
+
dependencyInstallNeedsApproval = true;
|
|
309
|
+
}
|
|
209
310
|
}
|
|
210
311
|
}
|
|
211
312
|
if (missingDeps.length > 0) {
|
|
212
|
-
console.log(`
|
|
213
|
-
|
|
313
|
+
console.log(` ${terminalStyle.cyan(terminalStyle.bold("Installing dependencies:"))}`);
|
|
314
|
+
console.log(formatList(missingDeps, " "));
|
|
315
|
+
try {
|
|
316
|
+
const installOutput = await installDeps(root, missingDeps, exec);
|
|
317
|
+
dependenciesAdded = true;
|
|
318
|
+
if (isApproveBuildsError(installOutput)) dependencyInstallNeedsApproval = true;
|
|
319
|
+
} catch (error) {
|
|
320
|
+
if (pmName !== "pnpm" || !isApproveBuildsError(error)) throw error;
|
|
321
|
+
dependencyInstallNeedsApproval = true;
|
|
322
|
+
}
|
|
214
323
|
console.log();
|
|
215
324
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
const configContent = generateViteConfig(isApp);
|
|
223
|
-
fs.writeFileSync(path.join(root, "vite.config.ts"), configContent, "utf-8");
|
|
224
|
-
generatedViteConfig = true;
|
|
325
|
+
if (pmName === "pnpm" && !dependencyInstallNeedsApproval && !options._exec && hasAutomaticallyIgnoredBuilds(inspectPnpmIgnoredBuilds(root))) dependencyInstallNeedsApproval = true;
|
|
326
|
+
else if (pmName === "pnpm" && !dependencyInstallNeedsApproval && options._inspectPnpmIgnoredBuilds && hasAutomaticallyIgnoredBuilds(options._inspectPnpmIgnoredBuilds(root))) dependencyInstallNeedsApproval = true;
|
|
327
|
+
console.log(` ${terminalStyle.green(terminalStyle.bold("vinext init complete!"))}\n`);
|
|
328
|
+
if (dependenciesAdded) {
|
|
329
|
+
console.log(` ${terminalStyle.green("✓")} Added dependencies to devDependencies:`);
|
|
330
|
+
console.log(formatList(missingDeps, " "));
|
|
225
331
|
}
|
|
226
|
-
|
|
227
|
-
console.log("
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
for (const
|
|
232
|
-
if (
|
|
233
|
-
if (
|
|
234
|
-
|
|
332
|
+
if (dependencyInstallNeedsApproval) console.log(` ${terminalStyle.yellow("!")} Dependency installation is waiting for build-script approval`);
|
|
333
|
+
if (addedTypeModule) console.log(` ${terminalStyle.green("✓")} Added "type": "module" to package.json`);
|
|
334
|
+
for (const [oldName, newName] of renamedConfigs) console.log(` ${terminalStyle.green("✓")} Renamed ${oldName} \u2192 ${newName}`);
|
|
335
|
+
for (const script of addedScripts) console.log(` ${terminalStyle.green("✓")} Added ${script} script`);
|
|
336
|
+
if (generatedViteConfig) console.log(` ${terminalStyle.green("✓")} Generated vite.config.ts`);
|
|
337
|
+
for (const file of generatedPlatformFiles) console.log(` ${terminalStyle.green("✓")} Generated ${file}`);
|
|
338
|
+
if (skippedViteConfig) console.log(` ${terminalStyle.yellow("-")} Skipped vite.config.ts (already exists, use --force to overwrite)`);
|
|
339
|
+
if (updatedGitignore) console.log(` ${terminalStyle.green("✓")} Added vinext output directories to .gitignore`);
|
|
340
|
+
const nextSteps = [...platformSetup.nextSteps];
|
|
341
|
+
if (dependencyInstallNeedsApproval) nextSteps.push("Dependency installation is incomplete because pnpm blocked dependency build scripts:", "1. Review and approve the required build scripts:", " pnpm approve-builds", "2. Finish installing dependencies:", " pnpm install");
|
|
235
342
|
console.log(`
|
|
236
|
-
Next steps:
|
|
343
|
+
${terminalStyle.cyan(terminalStyle.bold("Next steps:"))}
|
|
344
|
+
${nextSteps.map((step) => ` ${step}`).join("\n")}${nextSteps.length > 0 ? "\n" : ""}
|
|
237
345
|
${pmName} run dev:vinext Start the vinext dev server
|
|
238
346
|
${pmName} run build:vinext Build production output
|
|
239
347
|
${pmName} run start:vinext Start vinext production server
|
|
240
348
|
${pmName} run dev Start Next.js (still works as before)
|
|
241
349
|
`);
|
|
242
350
|
return {
|
|
243
|
-
installedDeps: missingDeps,
|
|
351
|
+
installedDeps: dependenciesAdded ? missingDeps : [],
|
|
244
352
|
addedTypeModule,
|
|
245
353
|
renamedConfigs,
|
|
246
354
|
addedScripts,
|
|
247
355
|
generatedViteConfig,
|
|
248
356
|
skippedViteConfig,
|
|
249
|
-
updatedGitignore
|
|
357
|
+
updatedGitignore,
|
|
358
|
+
platform,
|
|
359
|
+
generatedPlatformFiles
|
|
250
360
|
};
|
|
251
361
|
}
|
|
252
362
|
//#endregion
|