vinext 1.1.0 → 1.2.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 +22 -10
- package/dist/build/client-build-config.d.ts +10 -0
- package/dist/build/client-build-config.js +18 -2
- package/dist/build/output-root-externals.d.ts +21 -0
- package/dist/build/output-root-externals.js +40 -0
- package/dist/build/pages-client-assets-module.d.ts +8 -0
- package/dist/build/pages-client-assets-module.js +21 -1
- package/dist/build/prerender-paths.js +6 -4
- package/dist/build/prerender.js +1 -1
- package/dist/build/run-prerender.js +1 -1
- package/dist/build/ssr-manifest.d.ts +2 -0
- package/dist/build/ssr-manifest.js +6 -2
- package/dist/check.js +12 -12
- package/dist/cli-dev-config.js +3 -3
- package/dist/cli.js +3 -2
- package/dist/client/client-redirect-matcher.d.ts +14 -0
- package/dist/client/client-redirect-matcher.js +37 -0
- package/dist/client/client-redirects.d.ts +27 -0
- package/dist/client/client-redirects.js +28 -0
- package/dist/client/client-rewrites.d.ts +2 -1
- package/dist/client/client-rewrites.js +1 -1
- package/dist/config/config-matchers.d.ts +26 -11
- package/dist/config/config-matchers.js +90 -88
- package/dist/config/destination-params.d.ts +47 -0
- package/dist/config/destination-params.js +116 -0
- package/dist/config/next-config.d.ts +7 -0
- package/dist/config/next-config.js +3 -0
- package/dist/entries/app-rsc-entry.d.ts +4 -0
- package/dist/entries/app-rsc-entry.js +20 -6
- package/dist/entries/pages-client-entry.js +3 -1
- package/dist/entries/pages-server-entry.js +13 -37
- package/dist/index.d.ts +3 -1
- package/dist/index.js +246 -136
- package/dist/init-cloudflare.d.ts +9 -0
- package/dist/init-cloudflare.js +107 -31
- package/dist/init-platform.d.ts +4 -0
- package/dist/init-platform.js +27 -2
- package/dist/init.d.ts +2 -1
- package/dist/init.js +153 -9
- package/dist/plugins/ast-scope.d.ts +7 -0
- package/dist/plugins/ast-scope.js +59 -3
- package/dist/plugins/ast-utils.d.ts +53 -2
- package/dist/plugins/ast-utils.js +90 -2
- package/dist/plugins/cloudflare-dev-module-urls.d.ts +41 -0
- package/dist/plugins/cloudflare-dev-module-urls.js +271 -0
- package/dist/plugins/commonjs-esm-facade.js +2 -2
- package/dist/plugins/css-module-imports.js +13 -20
- package/dist/plugins/dynamic-preload-metadata.d.ts +1 -1
- package/dist/plugins/dynamic-preload-metadata.js +11 -11
- package/dist/plugins/extensionless-dynamic-import.js +2 -3
- package/dist/plugins/fonts.d.ts +1 -1
- package/dist/plugins/fonts.js +3 -3
- package/dist/plugins/ignore-dynamic-requests.d.ts +1 -1
- package/dist/plugins/ignore-dynamic-requests.js +5 -7
- package/dist/plugins/import-meta-url.js +3 -4
- package/dist/plugins/instrumentation-client.js +3 -2
- package/dist/plugins/middleware-export-validation.js +2 -3
- package/dist/plugins/middleware-server-only.d.ts +5 -4
- package/dist/plugins/middleware-server-only.js +8 -5
- package/dist/plugins/og-harfbuzz.js +2 -3
- package/dist/plugins/optimize-imports.js +3 -4
- package/dist/plugins/pages-node-externals.js +3 -4
- package/dist/plugins/remove-console.js +2 -18
- package/dist/plugins/require-condition-resolution.js +3 -3
- package/dist/plugins/require-context.js +2 -3
- package/dist/plugins/rsc-scan-glob-imports.d.ts +19 -0
- package/dist/plugins/rsc-scan-glob-imports.js +50 -0
- package/dist/plugins/strip-server-exports.js +265 -102
- package/dist/plugins/styled-jsx.js +2 -3
- package/dist/plugins/transform-result.d.ts +9 -5
- package/dist/plugins/transitive-externals.js +1 -1
- package/dist/plugins/typeof-window.d.ts +2 -2
- package/dist/plugins/use-cache-callable.d.ts +21 -2
- package/dist/plugins/use-cache-callable.js +84 -35
- package/dist/plugins/worker-image-imports.js +30 -33
- package/dist/plugins/worker-server-only-imports.d.ts +20 -0
- package/dist/plugins/worker-server-only-imports.js +31 -0
- package/dist/plugins/worker-use-server.d.ts +25 -0
- package/dist/plugins/worker-use-server.js +153 -0
- package/dist/server/api-handler.d.ts +1 -0
- package/dist/server/api-handler.js +3 -2
- package/dist/server/app-action-forwarding.js +2 -2
- package/dist/server/app-browser-action-result.d.ts +1 -1
- package/dist/server/app-browser-action-result.js +9 -2
- package/dist/server/app-browser-entry.js +3 -3
- package/dist/server/app-browser-interception-context.js +1 -1
- package/dist/server/app-browser-navigation-controller.js +1 -1
- package/dist/server/app-browser-prefetch-response.js +2 -2
- package/dist/server/app-browser-server-action-client.js +1 -1
- package/dist/server/app-browser-state.js +1 -1
- package/dist/server/app-browser-supplemental-refresh.js +1 -1
- package/dist/server/app-middleware.d.ts +11 -0
- package/dist/server/app-middleware.js +17 -2
- package/dist/server/app-optimistic-routing.js +1 -1
- package/dist/server/app-page-cache.d.ts +1 -1
- package/dist/server/app-page-cache.js +1 -1
- package/dist/server/app-page-dispatch.d.ts +3 -1
- package/dist/server/app-page-dispatch.js +5 -4
- package/dist/server/app-page-ppr-runtime.js +1 -1
- package/dist/server/app-page-render-observation.js +1 -1
- package/dist/server/app-page-render.js +1 -1
- package/dist/server/app-page-request.js +53 -15
- package/dist/server/app-page-route-wiring.js +2 -2
- package/dist/server/app-pages-bridge.d.ts +1 -1
- package/dist/server/app-pages-bridge.js +3 -4
- package/dist/server/app-prerender-endpoints.js +9 -6
- package/dist/server/app-render-abort-error.d.ts +19 -0
- package/dist/server/app-render-abort-error.js +31 -1
- package/dist/server/app-request-stage-dispatch.js +6 -2
- package/dist/server/app-request-stage-independent-entry.js +29 -9
- package/dist/server/app-response-stage-entry.js +11 -3
- package/dist/server/app-route-handler-cache.d.ts +1 -0
- package/dist/server/app-route-handler-cache.js +1 -0
- package/dist/server/app-route-handler-dispatch.d.ts +1 -0
- package/dist/server/app-route-handler-dispatch.js +5 -2
- package/dist/server/app-route-handler-execution.d.ts +1 -0
- package/dist/server/app-route-handler-execution.js +1 -0
- package/dist/server/app-route-handler-runtime.d.ts +4 -1
- package/dist/server/app-route-handler-runtime.js +46 -25
- package/dist/server/app-router-entry.js +29 -10
- package/dist/server/app-rsc-cache-busting.d.ts +16 -0
- package/dist/server/app-rsc-cache-busting.js +30 -13
- package/dist/server/app-rsc-errors.js +20 -16
- package/dist/server/app-rsc-handler.d.ts +7 -0
- package/dist/server/app-rsc-handler.js +89 -39
- package/dist/server/app-rsc-request-normalization.js +3 -3
- package/dist/server/app-rsc-response-stage.js +5 -3
- package/dist/server/app-segment-config.d.ts +2 -1
- package/dist/server/app-server-action-execution.d.ts +2 -1
- package/dist/server/app-server-action-execution.js +62 -23
- package/dist/server/app-ssr-entry.js +7 -5
- package/dist/server/app-visited-response-cache.js +2 -2
- package/dist/server/app-worker-stages.d.ts +5 -0
- package/dist/server/app-worker-stages.js +1 -1
- package/dist/server/cacheability-request.js +2 -2
- package/dist/server/client-build-files.d.ts +16 -0
- package/dist/server/client-build-files.js +36 -0
- package/dist/server/client-reuse-manifest.js +1 -1
- package/dist/server/config-headers.js +1 -1
- package/dist/server/defer-until-stream-consumed.d.ts +2 -1
- package/dist/server/defer-until-stream-consumed.js +3 -1
- package/dist/server/dev-server.js +39 -28
- package/dist/server/dev-stack-sourcemap.js +18 -23
- package/dist/server/document-initial-head.d.ts +0 -11
- package/dist/server/document-initial-head.js +1 -1
- package/dist/server/forwarded-middleware-context.d.ts +5 -0
- package/dist/server/forwarded-middleware-context.js +22 -0
- package/dist/server/headers.d.ts +4 -1
- package/dist/server/headers.js +4 -1
- package/dist/server/http-conditional.d.ts +11 -0
- package/dist/server/http-conditional.js +10 -1
- package/dist/server/http-error-responses.d.ts +1 -1
- package/dist/server/image-optimization.d.ts +38 -0
- package/dist/server/image-optimization.js +94 -4
- package/dist/server/isr-cache.d.ts +10 -0
- package/dist/server/isr-cache.js +41 -6
- package/dist/server/metadata-route-response.js +11 -10
- package/dist/server/middleware-matcher.d.ts +2 -0
- package/dist/server/middleware-matcher.js +23 -2
- package/dist/server/middleware-path-to-regexp.js +1 -1
- package/dist/server/middleware-runtime.d.ts +13 -0
- package/dist/server/middleware-runtime.js +38 -25
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.js +3 -1
- package/dist/server/multi-stage.d.ts +11 -0
- package/dist/server/navigation-planner.js +1 -1
- package/dist/server/normalize-path.d.ts +0 -13
- package/dist/server/normalize-path.js +1 -34
- package/dist/server/open-redirect.d.ts +11 -4
- package/dist/server/open-redirect.js +11 -4
- package/dist/server/pages-api-route.d.ts +3 -2
- package/dist/server/pages-api-route.js +6 -5
- package/dist/server/pages-cache-tag.d.ts +12 -0
- package/dist/server/pages-cache-tag.js +19 -0
- package/dist/server/pages-client-assets.d.ts +2 -0
- package/dist/server/pages-data-route.d.ts +10 -0
- package/dist/server/pages-data-route.js +21 -3
- package/dist/server/pages-document-asset-props.d.ts +5 -1
- package/dist/server/pages-document-asset-props.js +13 -5
- package/dist/server/pages-document-splice.d.ts +19 -0
- package/dist/server/pages-document-splice.js +55 -0
- package/dist/server/pages-i18n.d.ts +12 -1
- package/dist/server/pages-i18n.js +18 -4
- package/dist/server/pages-node-compat.d.ts +16 -5
- package/dist/server/pages-node-compat.js +20 -12
- package/dist/server/pages-page-data.d.ts +32 -24
- package/dist/server/pages-page-data.js +51 -121
- package/dist/server/pages-page-handler.d.ts +0 -6
- package/dist/server/pages-page-handler.js +189 -127
- package/dist/server/pages-page-response.d.ts +12 -6
- package/dist/server/pages-page-response.js +42 -35
- package/dist/server/pages-request-pipeline.d.ts +10 -2
- package/dist/server/pages-request-pipeline.js +41 -22
- package/dist/server/pages-request-stage-entry.d.ts +6 -0
- package/dist/server/pages-request-stage-entry.js +75 -16
- package/dist/server/pages-response-stage-entry.js +4 -0
- package/dist/server/pages-revalidate.js +3 -3
- package/dist/server/pages-router-entry.js +5 -4
- package/dist/server/prerender-manifest.d.ts +3 -3
- package/dist/server/prerender-manifest.js +4 -3
- package/dist/server/prerender-work-unit-setup.js +4 -0
- package/dist/server/prod-server.d.ts +12 -0
- package/dist/server/prod-server.js +204 -74
- package/dist/server/proper-error.d.ts +4 -0
- package/dist/server/proper-error.js +31 -0
- package/dist/server/request-pipeline.d.ts +4 -1
- package/dist/server/request-pipeline.js +3 -2
- package/dist/server/revalidation-request.d.ts +1 -0
- package/dist/server/revalidation-request.js +1 -1
- package/dist/server/rsc-stream-hints.d.ts +1 -1
- package/dist/server/rsc-stream-hints.js +52 -5
- package/dist/server/seed-cache.d.ts +1 -0
- package/dist/server/seed-cache.js +5 -4
- package/dist/server/server-reference-loader.d.ts +4 -0
- package/dist/server/server-reference-loader.js +29 -0
- package/dist/server/socket-error-backstop.d.ts +9 -1
- package/dist/server/socket-error-backstop.js +46 -17
- package/dist/server/static-file-signal.d.ts +15 -4
- package/dist/server/static-file-signal.js +46 -12
- package/dist/server/worker-image-optimization.d.ts +34 -0
- package/dist/server/worker-image-optimization.js +99 -0
- package/dist/server/worker-stages.d.ts +1 -1
- package/dist/server/worker-stages.js +2 -2
- package/dist/server/worker-utils.d.ts +8 -3
- package/dist/server/worker-utils.js +12 -7
- package/dist/shims/app-router-scroll.js +4 -1
- package/dist/shims/app-router-tree-context.d.ts +5 -0
- package/dist/shims/app-router-tree-context.js +27 -0
- package/dist/shims/cache-callable-runtime.d.ts +4 -2
- package/dist/shims/cache-callable-runtime.js +21 -12
- package/dist/shims/cache-handler.js +1 -9
- package/dist/shims/cache-runtime.d.ts +6 -1
- package/dist/shims/cache-runtime.js +2 -1
- package/dist/shims/cache.d.ts +2 -2
- package/dist/shims/cache.js +40 -13
- package/dist/shims/cdn-cache.d.ts +8 -0
- package/dist/shims/cdn-cache.js +17 -1
- package/dist/shims/disable-smooth-scroll.d.ts +3 -0
- package/dist/shims/disable-smooth-scroll.js +36 -0
- package/dist/shims/document-placeholders.d.ts +19 -0
- package/dist/shims/document-placeholders.js +45 -0
- package/dist/shims/document.js +21 -5
- package/dist/shims/dynamic-preload-chunks.d.ts +1 -0
- package/dist/shims/dynamic-preload-chunks.js +13 -9
- package/dist/shims/dynamic.d.ts +1 -1
- package/dist/shims/dynamic.js +60 -8
- package/dist/shims/fetch-cache-state.d.ts +66 -0
- package/dist/shims/fetch-cache-state.js +92 -0
- package/dist/shims/fetch-cache.d.ts +3 -67
- package/dist/shims/fetch-cache.js +160 -125
- package/dist/shims/head.d.ts +10 -6
- package/dist/shims/head.js +16 -14
- package/dist/shims/headers.js +2 -2
- package/dist/shims/image.js +2 -1
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +1 -1
- package/dist/shims/internal/hybrid-client-route-owner.js +1 -0
- package/dist/shims/internal/work-store-scope.d.ts +5 -0
- package/dist/shims/internal/work-store-scope.js +24 -0
- package/dist/shims/link-prefetch.js +5 -4
- package/dist/shims/link.js +2 -2
- package/dist/shims/navigation.js +34 -9
- package/dist/shims/request-context.d.ts +2 -0
- package/dist/shims/request-state-types.d.ts +2 -1
- package/dist/shims/router.js +21 -32
- package/dist/shims/server.d.ts +27 -4
- package/dist/shims/server.js +65 -9
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/url-utils.d.ts +9 -0
- package/dist/shims/url-utils.js +15 -4
- package/dist/utils/client-runtime-metadata.js +1 -1
- package/dist/utils/domain-locale.js +1 -1
- package/dist/utils/hash.d.ts +7 -0
- package/dist/utils/hash.js +11 -1
- package/dist/utils/package-name.d.ts +6 -0
- package/dist/utils/package-name.js +12 -1
- package/dist/utils/plugin-rsc-version.d.ts +6 -0
- package/dist/utils/plugin-rsc-version.js +41 -0
- package/dist/utils/prerender-output-paths.js +15 -4
- package/dist/utils/public-file-path.d.ts +10 -2
- package/dist/utils/public-file-path.js +13 -9
- package/dist/utils/public-routes.js +2 -2
- package/dist/utils/react-version.d.ts +10 -0
- package/dist/utils/react-version.js +39 -16
- package/package.json +11 -7
- package/dist/build/nitro-route-rules.d.ts +0 -47
- package/dist/build/nitro-route-rules.js +0 -79
- package/dist/plugins/cache-flight-codec.d.ts +0 -19
- package/dist/plugins/cache-flight-codec.js +0 -68
|
@@ -6,6 +6,8 @@ export type CloudflareProjectInfo = {
|
|
|
6
6
|
isAppRouter: boolean;
|
|
7
7
|
hasISR: boolean;
|
|
8
8
|
hasMDX: boolean;
|
|
9
|
+
/** The effective Next.js config sets `output: "export"`. */
|
|
10
|
+
isStaticExport?: boolean;
|
|
9
11
|
nativeModulesToStub: string[];
|
|
10
12
|
};
|
|
11
13
|
export type CloudflarePlatformSetupContext = {
|
|
@@ -13,6 +15,7 @@ export type CloudflarePlatformSetupContext = {
|
|
|
13
15
|
isAppRouter: boolean;
|
|
14
16
|
existingViteConfigPath?: string;
|
|
15
17
|
hasCssModules?: boolean;
|
|
18
|
+
isStaticExport?: boolean;
|
|
16
19
|
packageManager?: string;
|
|
17
20
|
today?: string;
|
|
18
21
|
};
|
|
@@ -25,11 +28,17 @@ export type CloudflarePlatformSetupResult = {
|
|
|
25
28
|
};
|
|
26
29
|
export declare function validateCloudflarePlatformSetup(context: CloudflarePlatformSetupContext, cloudflare: CloudflareInitOptions): void;
|
|
27
30
|
export declare function setupCloudflarePlatform(context: CloudflarePlatformSetupContext, cloudflare: CloudflareInitOptions): CloudflarePlatformSetupResult;
|
|
31
|
+
/**
|
|
32
|
+
* The existing config that keeps its own Worker name, if `--name` was given.
|
|
33
|
+
* Init doesn't rename the Worker in an existing config, so callers warn instead.
|
|
34
|
+
*/
|
|
35
|
+
export declare function findConfigKeepingWorkerName(root: string, cloudflare: CloudflareInitOptions): string | undefined;
|
|
28
36
|
export declare function generateWranglerConfig(info: CloudflareProjectInfo, options?: CloudflareInitOptions, today?: string): string;
|
|
29
37
|
export declare function compactResourceName(name: string, suffix: string, maxLength: number): string;
|
|
30
38
|
export declare function generateResponseStoreWranglerConfig(appWranglerCode: string, root: string): string;
|
|
31
39
|
export declare function updateWranglerConfigForCloudflare(code: string, options: CloudflareInitOptions, context?: {
|
|
32
40
|
root?: string;
|
|
41
|
+
isStaticExport?: boolean;
|
|
33
42
|
}): string;
|
|
34
43
|
export declare function getWranglerImagesBinding(code: string): string;
|
|
35
44
|
export declare function getWranglerVersionMetadataBinding(code: string): string;
|
package/dist/init-cloudflare.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "./deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
2
|
import { detectProject } from "./utils/project.js";
|
|
3
|
+
import { validateWorkerName } from "./init-platform.js";
|
|
3
4
|
import { isUnknownRecord } from "./utils/record.js";
|
|
4
5
|
import { createRequire } from "node:module";
|
|
5
6
|
import fs from "node:fs";
|
|
@@ -13,6 +14,10 @@ const DEFAULT_CLOUDFLARE_INIT_OPTIONS = {
|
|
|
13
14
|
imageOptimization: "cloudflare-images"
|
|
14
15
|
};
|
|
15
16
|
const DEFAULT_VERSION_METADATA_BINDING = "CF_VERSION_METADATA";
|
|
17
|
+
const BUILD_OUTPUT_EXCLUSIONS = ["!/_next/static/*", "!/*/_next/static/*"];
|
|
18
|
+
const DEFAULT_RUN_WORKER_FIRST = ["/*", ...BUILD_OUTPUT_EXCLUSIONS];
|
|
19
|
+
const HTML_HANDLING = "none";
|
|
20
|
+
const STATIC_ASSETS_CACHE_ROUTE = "/_vinext/static-cache/*";
|
|
16
21
|
const RESPONSE_STORE_WRANGLER_CONFIG = "wrangler.response-store.jsonc";
|
|
17
22
|
const RESPONSE_STORE_BINDING = "RESPONSE_STORE";
|
|
18
23
|
const RESPONSE_STORE_ENTRYPOINT = "ResponseStoreService";
|
|
@@ -26,6 +31,7 @@ const CACHE_METADATA_EXPORT = {
|
|
|
26
31
|
};
|
|
27
32
|
const CTX_EXPORTS_DEFAULT_DATE = "2025-11-17";
|
|
28
33
|
function validateCloudflarePlatformSetup(context, cloudflare) {
|
|
34
|
+
if (cloudflare.name !== void 0) validateWorkerName(cloudflare.name);
|
|
29
35
|
if (!cloudflare.legacyWrangler) {
|
|
30
36
|
const existingWrangler = [
|
|
31
37
|
"wrangler.toml",
|
|
@@ -54,7 +60,10 @@ function validateCloudflarePlatformSetup(context, cloudflare) {
|
|
|
54
60
|
const wranglerPath = ["wrangler.jsonc", "wrangler.json"].map((fileName) => path.join(context.root, fileName)).find((candidate) => fs.existsSync(candidate));
|
|
55
61
|
const wranglerCode = wranglerPath ? fs.readFileSync(wranglerPath, "utf-8") : void 0;
|
|
56
62
|
if (!wranglerCode && cloudflare.cdnCache === "response-store" && (cloudflare.responseStoreMode ?? "service-binding") === "service-binding" && fs.existsSync(path.join(context.root, RESPONSE_STORE_WRANGLER_CONFIG))) readResponseStoreServiceName(context.root, {});
|
|
57
|
-
const updatedWranglerCode = wranglerCode ? updateWranglerConfigForCloudflare(wranglerCode, cloudflare, {
|
|
63
|
+
const updatedWranglerCode = wranglerCode ? updateWranglerConfigForCloudflare(wranglerCode, cloudflare, {
|
|
64
|
+
root: context.root,
|
|
65
|
+
isStaticExport: context.isStaticExport
|
|
66
|
+
}) : void 0;
|
|
58
67
|
const imagesBinding = updatedWranglerCode ? getWranglerImagesBinding(updatedWranglerCode) : "IMAGES";
|
|
59
68
|
const assetsBinding = updatedWranglerCode ? getWranglerAssetsBinding(updatedWranglerCode) : "ASSETS";
|
|
60
69
|
const assetsDirectory = updatedWranglerCode ? getWranglerAssetsDirectory(updatedWranglerCode) : "dist/client";
|
|
@@ -74,10 +83,13 @@ function validateCloudflarePlatformSetup(context, cloudflare) {
|
|
|
74
83
|
}
|
|
75
84
|
function setupCloudflarePlatform(context, cloudflare) {
|
|
76
85
|
if (!cloudflare.legacyWrangler) return setupCfPlatform(context, cloudflare);
|
|
77
|
-
const projectInfo =
|
|
86
|
+
const projectInfo = detectCloudflareProject(context.root, cloudflare);
|
|
78
87
|
const wranglerPath = ["wrangler.jsonc", "wrangler.json"].map((fileName) => path.join(context.root, fileName)).find((candidate) => fs.existsSync(candidate));
|
|
79
88
|
const wranglerCode = wranglerPath ? fs.readFileSync(wranglerPath, "utf-8") : void 0;
|
|
80
|
-
const updatedWranglerCode = wranglerCode ? updateWranglerConfigForCloudflare(wranglerCode, cloudflare, {
|
|
89
|
+
const updatedWranglerCode = wranglerCode ? updateWranglerConfigForCloudflare(wranglerCode, cloudflare, {
|
|
90
|
+
root: context.root,
|
|
91
|
+
isStaticExport: context.isStaticExport
|
|
92
|
+
}) : void 0;
|
|
81
93
|
const imagesBinding = updatedWranglerCode ? getWranglerImagesBinding(updatedWranglerCode) : "IMAGES";
|
|
82
94
|
const assetsBinding = updatedWranglerCode ? getWranglerAssetsBinding(updatedWranglerCode) : "ASSETS";
|
|
83
95
|
const assetsDirectory = updatedWranglerCode ? getWranglerAssetsDirectory(updatedWranglerCode) : "dist/client";
|
|
@@ -112,7 +124,10 @@ function setupCloudflarePlatform(context, cloudflare) {
|
|
|
112
124
|
}
|
|
113
125
|
const generatedPlatformFiles = [];
|
|
114
126
|
if (!wranglerPath) {
|
|
115
|
-
fs.writeFileSync(path.join(context.root, "wrangler.jsonc"), generateWranglerConfig(
|
|
127
|
+
fs.writeFileSync(path.join(context.root, "wrangler.jsonc"), generateWranglerConfig({
|
|
128
|
+
...projectInfo,
|
|
129
|
+
isStaticExport: context.isStaticExport
|
|
130
|
+
}, cloudflare, context.today), "utf-8");
|
|
116
131
|
generatedPlatformFiles.push("wrangler.jsonc");
|
|
117
132
|
} else if (wranglerCode && updatedWranglerCode) {
|
|
118
133
|
if (updatedWranglerCode !== wranglerCode) {
|
|
@@ -139,8 +154,23 @@ function setupCloudflarePlatform(context, cloudflare) {
|
|
|
139
154
|
preservedExistingGenerateScopedName
|
|
140
155
|
};
|
|
141
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* The existing config that keeps its own Worker name, if `--name` was given.
|
|
159
|
+
* Init doesn't rename the Worker in an existing config, so callers warn instead.
|
|
160
|
+
*/
|
|
161
|
+
function findConfigKeepingWorkerName(root, cloudflare) {
|
|
162
|
+
if (cloudflare.name === void 0) return void 0;
|
|
163
|
+
return (cloudflare.legacyWrangler ? ["wrangler.jsonc", "wrangler.json"] : ["cloudflare.config.ts"]).find((name) => fs.existsSync(path.join(root, name)));
|
|
164
|
+
}
|
|
165
|
+
function detectCloudflareProject(root, cloudflare) {
|
|
166
|
+
const projectInfo = detectProject(root);
|
|
167
|
+
return cloudflare.name ? {
|
|
168
|
+
...projectInfo,
|
|
169
|
+
projectName: cloudflare.name
|
|
170
|
+
} : projectInfo;
|
|
171
|
+
}
|
|
142
172
|
function setupCfPlatform(context, cloudflare) {
|
|
143
|
-
const projectInfo =
|
|
173
|
+
const projectInfo = detectCloudflareProject(context.root, cloudflare);
|
|
144
174
|
const serviceBinding = cloudflare.cdnCache === "response-store" && (cloudflare.responseStoreMode ?? "service-binding") === "service-binding";
|
|
145
175
|
let generatedViteConfig = false;
|
|
146
176
|
let preservedExistingGenerateScopedName = false;
|
|
@@ -168,7 +198,10 @@ function setupCfPlatform(context, cloudflare) {
|
|
|
168
198
|
const configPath = path.join(context.root, "cloudflare.config.ts");
|
|
169
199
|
const generatedPlatformFiles = [];
|
|
170
200
|
if (!fs.existsSync(configPath)) {
|
|
171
|
-
fs.writeFileSync(configPath, generateTypedCloudflareConfig(
|
|
201
|
+
fs.writeFileSync(configPath, generateTypedCloudflareConfig({
|
|
202
|
+
...projectInfo,
|
|
203
|
+
isStaticExport: context.isStaticExport
|
|
204
|
+
}, cloudflare, context.today));
|
|
172
205
|
generatedPlatformFiles.push("cloudflare.config.ts");
|
|
173
206
|
}
|
|
174
207
|
const nextSteps = [];
|
|
@@ -215,6 +248,12 @@ export const responseStoreServiceBinding = responseStore.serviceBindingWorker;
|
|
|
215
248
|
...options.imageOptimization === "cloudflare-images" ? ["IMAGES: bindings.images()"] : [],
|
|
216
249
|
...options.dataCache === "kv" ? ["VINEXT_KV_CACHE: bindings.kv()"] : []
|
|
217
250
|
];
|
|
251
|
+
const routing = defaultAssetRouting(info, options);
|
|
252
|
+
const assetLines = [
|
|
253
|
+
...routing.htmlHandling ? [`htmlHandling: ${JSON.stringify(routing.htmlHandling)}`] : [],
|
|
254
|
+
"notFoundHandling: \"none\"",
|
|
255
|
+
...routing.runWorkerFirst ? [`runWorkerFirst: [${routing.runWorkerFirst.map((pattern) => JSON.stringify(pattern)).join(", ")}]`] : []
|
|
256
|
+
];
|
|
218
257
|
return `${imports.join("\n")}
|
|
219
258
|
|
|
220
259
|
${shared}export default defineConfig({
|
|
@@ -223,7 +262,9 @@ ${shared}export default defineConfig({
|
|
|
223
262
|
entrypoint: ${JSON.stringify(resolveWorkerEntry(info.root))},
|
|
224
263
|
compatibilityDate: ${JSON.stringify(today)},
|
|
225
264
|
compatibilityFlags: ["nodejs_compat"],
|
|
226
|
-
assets: {
|
|
265
|
+
assets: {
|
|
266
|
+
${assetLines.join(",\n ")},
|
|
267
|
+
},
|
|
227
268
|
env: {
|
|
228
269
|
${envBindings.join(",\n ")},
|
|
229
270
|
},
|
|
@@ -242,8 +283,21 @@ function resolveWorkerEntry(root) {
|
|
|
242
283
|
if (fs.existsSync(path.join(root, "worker", "index.js"))) return "./worker/index.js";
|
|
243
284
|
return "vinext/server/fetch-handler";
|
|
244
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Next.js runs no middleware for a static export, and an export with
|
|
288
|
+
* `trailingSlash` relies on the default html_handling to serve `/about/` from
|
|
289
|
+
* `about/index.html`, so export apps keep asset-first serving.
|
|
290
|
+
*/
|
|
291
|
+
function defaultAssetRouting(info, options) {
|
|
292
|
+
if (!info.isStaticExport) return {
|
|
293
|
+
htmlHandling: HTML_HANDLING,
|
|
294
|
+
runWorkerFirst: DEFAULT_RUN_WORKER_FIRST
|
|
295
|
+
};
|
|
296
|
+
return options.cdnCache === "static-assets" ? { runWorkerFirst: [STATIC_ASSETS_CACHE_ROUTE] } : {};
|
|
297
|
+
}
|
|
245
298
|
function generateWranglerConfig(info, options = DEFAULT_CLOUDFLARE_INIT_OPTIONS, today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0]) {
|
|
246
299
|
const workerEntry = resolveWorkerEntry(info.root);
|
|
300
|
+
const routing = defaultAssetRouting(info, options);
|
|
247
301
|
const config = {
|
|
248
302
|
$schema: "node_modules/wrangler/config-schema.json",
|
|
249
303
|
name: info.projectName,
|
|
@@ -252,15 +306,13 @@ function generateWranglerConfig(info, options = DEFAULT_CLOUDFLARE_INIT_OPTIONS,
|
|
|
252
306
|
main: workerEntry,
|
|
253
307
|
assets: {
|
|
254
308
|
directory: "dist/client",
|
|
309
|
+
...routing.htmlHandling ? { html_handling: routing.htmlHandling } : {},
|
|
255
310
|
not_found_handling: "none",
|
|
256
311
|
binding: "ASSETS",
|
|
257
|
-
...
|
|
312
|
+
...routing.runWorkerFirst ? { run_worker_first: routing.runWorkerFirst } : {}
|
|
258
313
|
}
|
|
259
314
|
};
|
|
260
|
-
if (options.cdnCache === "workers-cache") {
|
|
261
|
-
config.cache = { enabled: true };
|
|
262
|
-
config.version_metadata = { binding: DEFAULT_VERSION_METADATA_BINDING };
|
|
263
|
-
}
|
|
315
|
+
if (options.cdnCache === "workers-cache") config.version_metadata = { binding: DEFAULT_VERSION_METADATA_BINDING };
|
|
264
316
|
if (options.imageOptimization === "cloudflare-images") config.images = { binding: "IMAGES" };
|
|
265
317
|
if (options.dataCache === "kv") config.kv_namespaces = [{ binding: "VINEXT_KV_CACHE" }];
|
|
266
318
|
const code = `${JSON.stringify(config, null, 2)}\n`;
|
|
@@ -305,6 +357,19 @@ function stripJsonComments(code) {
|
|
|
305
357
|
}
|
|
306
358
|
return output.replace(/,\s*([}\]])/g, "$1");
|
|
307
359
|
}
|
|
360
|
+
/** Offset of the first JSONC token in `code`, after whitespace and comments. */
|
|
361
|
+
function skipJsonWhitespaceAndComments(code) {
|
|
362
|
+
let index = 0;
|
|
363
|
+
while (index < code.length) if (/\s/.test(code[index])) index++;
|
|
364
|
+
else if (code.startsWith("//", index)) {
|
|
365
|
+
const lineEnd = code.indexOf("\n", index);
|
|
366
|
+
index = lineEnd === -1 ? code.length : lineEnd;
|
|
367
|
+
} else if (code.startsWith("/*", index)) {
|
|
368
|
+
const commentEnd = code.indexOf("*/", index + 2);
|
|
369
|
+
index = commentEnd === -1 ? code.length : commentEnd + 2;
|
|
370
|
+
} else break;
|
|
371
|
+
return index;
|
|
372
|
+
}
|
|
308
373
|
function findTopLevelJsonProperty(code, name) {
|
|
309
374
|
let depth = 0;
|
|
310
375
|
let inString = false;
|
|
@@ -457,7 +522,7 @@ function readResponseStoreServiceName(root, appConfig) {
|
|
|
457
522
|
const durableBindings = isUnknownRecord(responseStoreConfig.durable_objects) ? responseStoreConfig.durable_objects.bindings : void 0;
|
|
458
523
|
const hasCacheMetadata = Array.isArray(durableBindings) && durableBindings.some((binding) => isUnknownRecord(binding) && binding.name === CACHE_METADATA_BINDING && binding.class_name === CACHE_METADATA_CLASS && binding.script_name === void 0);
|
|
459
524
|
const hasNoMigrations = responseStoreConfig.migrations === void 0 || Array.isArray(responseStoreConfig.migrations) && responseStoreConfig.migrations.length === 0;
|
|
460
|
-
if (!isUnknownRecord(responseStoreConfig.cache) || responseStoreConfig.cache.enabled !==
|
|
525
|
+
if (responseStoreConfig.cache !== void 0 && (!isUnknownRecord(responseStoreConfig.cache) || typeof responseStoreConfig.cache.enabled !== "boolean") || !isUnknownRecord(responseStoreExport) || !isUnknownRecord(responseStoreExport.cache) || responseStoreExport.cache.enabled !== true || !hasCacheBodies || !hasCacheMetadata || !isCacheMetadataExport(cacheMetadataExport) || !hasNoMigrations) throw new Error(`${RESPONSE_STORE_WRANGLER_CONFIG} is missing required Response Store bindings.`);
|
|
461
526
|
const compatibilityFlags = responseStoreConfig.compatibility_flags;
|
|
462
527
|
if (compatibilityFlags !== void 0 && (!Array.isArray(compatibilityFlags) || compatibilityFlags.some((flag) => typeof flag !== "string"))) throw new Error(`${RESPONSE_STORE_WRANGLER_CONFIG} has invalid compatibility flags.`);
|
|
463
528
|
const flags = compatibilityFlags ?? [];
|
|
@@ -481,7 +546,7 @@ function configureResponseStoreWrangler(code, config, mode, root) {
|
|
|
481
546
|
if (cache !== void 0 && !isUnknownRecord(cache)) throw new Error("The existing Wrangler config has an invalid cache value.");
|
|
482
547
|
code = setTopLevelJsonProperty(code, "cache", {
|
|
483
548
|
...cache,
|
|
484
|
-
enabled:
|
|
549
|
+
enabled: false
|
|
485
550
|
});
|
|
486
551
|
const exportsConfig = config.exports;
|
|
487
552
|
if (exportsConfig !== void 0 && !isUnknownRecord(exportsConfig)) throw new Error("The existing Wrangler config has an invalid exports value.");
|
|
@@ -593,7 +658,7 @@ function generateResponseStoreWranglerConfig(appWranglerCode, root) {
|
|
|
593
658
|
compatibility_flags: compatibilityFlags,
|
|
594
659
|
workers_dev: false,
|
|
595
660
|
preview_urls: false,
|
|
596
|
-
cache: { enabled:
|
|
661
|
+
cache: { enabled: false },
|
|
597
662
|
exports: {
|
|
598
663
|
default: {
|
|
599
664
|
type: "worker",
|
|
@@ -629,15 +694,25 @@ function updateWranglerConfigForCloudflare(code, options, context = {}) {
|
|
|
629
694
|
const workerEntry = resolveWorkerEntry(context.root ?? process.cwd());
|
|
630
695
|
output = appendTopLevelJsonProperty(output, ` "main": ${JSON.stringify(workerEntry)}`);
|
|
631
696
|
}
|
|
632
|
-
if (!findTopLevelJsonProperty(output, "assets"))
|
|
697
|
+
if (!findTopLevelJsonProperty(output, "assets")) {
|
|
698
|
+
const routing = defaultAssetRouting(context, {});
|
|
699
|
+
const assets = JSON.stringify({
|
|
700
|
+
directory: "dist/client",
|
|
701
|
+
...routing.htmlHandling ? { html_handling: routing.htmlHandling } : {},
|
|
702
|
+
not_found_handling: "none",
|
|
703
|
+
binding: "ASSETS",
|
|
704
|
+
...routing.runWorkerFirst ? { run_worker_first: routing.runWorkerFirst } : {}
|
|
705
|
+
}, null, 2).replaceAll("\n", "\n ");
|
|
706
|
+
output = appendTopLevelJsonProperty(output, ` "assets": ${assets}`);
|
|
707
|
+
}
|
|
633
708
|
if (options.cdnCache === "static-assets") {
|
|
634
709
|
const assetsProperty = findTopLevelJsonProperty(output, "assets");
|
|
635
710
|
const assets = JSON.parse(stripJsonComments(output.slice(assetsProperty.valueStart, assetsProperty.valueEnd)));
|
|
636
711
|
if (!assets || typeof assets !== "object" || Array.isArray(assets)) throw new Error("The existing Wrangler config has an invalid assets value.");
|
|
637
712
|
const workerFirst = assets.run_worker_first;
|
|
638
713
|
if (workerFirst !== void 0 && typeof workerFirst !== "boolean" && !Array.isArray(workerFirst)) throw new Error("The existing Wrangler config has an invalid assets.run_worker_first value.");
|
|
639
|
-
if (Array.isArray(workerFirst) && workerFirst.some((pattern) => typeof pattern !== "string" || pattern.startsWith("!"))) throw new Error(
|
|
640
|
-
const protectedRouting = workerFirst === true ? true : [.../* @__PURE__ */ new Set([...Array.isArray(workerFirst) ? workerFirst : [],
|
|
714
|
+
if (Array.isArray(workerFirst) && workerFirst.some((pattern) => typeof pattern !== "string" || pattern.startsWith("!") && !BUILD_OUTPUT_EXCLUSIONS.includes(pattern))) throw new Error(`Static Assets cache requires run_worker_first without exclusion patterns other than ${BUILD_OUTPUT_EXCLUSIONS.join(" and ")}. Use an array of positive path patterns, optionally with those exclusions.`);
|
|
715
|
+
const protectedRouting = workerFirst === true ? true : Array.isArray(workerFirst) && workerFirst.includes("/*") ? workerFirst : [.../* @__PURE__ */ new Set([...Array.isArray(workerFirst) ? workerFirst : [], STATIC_ASSETS_CACHE_ROUTE])];
|
|
641
716
|
if (typeof assets.directory !== "string" || assets.directory.length === 0 || typeof assets.binding !== "string" || assets.binding.length === 0 || JSON.stringify(workerFirst) !== JSON.stringify(protectedRouting)) {
|
|
642
717
|
const updatedAssets = JSON.stringify({
|
|
643
718
|
...assets,
|
|
@@ -649,18 +724,6 @@ function updateWranglerConfigForCloudflare(code, options, context = {}) {
|
|
|
649
724
|
}
|
|
650
725
|
}
|
|
651
726
|
if (options.cdnCache === "workers-cache") {
|
|
652
|
-
const cacheProperty = findTopLevelJsonProperty(output, "cache");
|
|
653
|
-
if (!cacheProperty) output = appendTopLevelJsonProperty(output, " \"cache\": { \"enabled\": true }");
|
|
654
|
-
else {
|
|
655
|
-
const cache = JSON.parse(stripJsonComments(output.slice(cacheProperty.valueStart, cacheProperty.valueEnd)));
|
|
656
|
-
if (!cache || cache.enabled !== true) {
|
|
657
|
-
const updatedCache = JSON.stringify({
|
|
658
|
-
...cache,
|
|
659
|
-
enabled: true
|
|
660
|
-
});
|
|
661
|
-
output = `${output.slice(0, cacheProperty.valueStart)}${updatedCache}${output.slice(cacheProperty.valueEnd)}`;
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
727
|
const versionMetadataProperty = findTopLevelJsonProperty(output, "version_metadata");
|
|
665
728
|
if (!versionMetadataProperty) output = appendTopLevelJsonProperty(output, ` "version_metadata": { "binding": "${DEFAULT_VERSION_METADATA_BINDING}" }`);
|
|
666
729
|
else {
|
|
@@ -668,6 +731,19 @@ function updateWranglerConfigForCloudflare(code, options, context = {}) {
|
|
|
668
731
|
if (!versionMetadata || typeof versionMetadata.binding !== "string" || versionMetadata.binding.length === 0) output = `${output.slice(0, versionMetadataProperty.valueStart)}{ "binding": "${DEFAULT_VERSION_METADATA_BINDING}" }${output.slice(versionMetadataProperty.valueEnd)}`;
|
|
669
732
|
}
|
|
670
733
|
}
|
|
734
|
+
if (options.cdnCache !== "response-store") {
|
|
735
|
+
const cacheProperty = findTopLevelJsonProperty(output, "cache");
|
|
736
|
+
if (cacheProperty) {
|
|
737
|
+
const cacheCode = output.slice(cacheProperty.valueStart, cacheProperty.valueEnd);
|
|
738
|
+
const cache = JSON.parse(stripJsonComments(cacheCode));
|
|
739
|
+
const enabledProperty = findTopLevelJsonProperty(cacheCode, "enabled");
|
|
740
|
+
const enabledToken = enabledProperty ? enabledProperty.valueStart + skipJsonWhitespaceAndComments(cacheCode.slice(enabledProperty.valueStart, enabledProperty.valueEnd)) : -1;
|
|
741
|
+
if (isUnknownRecord(cache) && cache.enabled === true && cacheCode.startsWith("true", enabledToken)) {
|
|
742
|
+
const enabledStart = cacheProperty.valueStart + enabledToken;
|
|
743
|
+
output = `${output.slice(0, enabledStart)}false${output.slice(enabledStart + 4)}`;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
671
747
|
if (options.imageOptimization === "cloudflare-images") {
|
|
672
748
|
const imagesProperty = findTopLevelJsonProperty(output, "images");
|
|
673
749
|
if (!imagesProperty) output = appendTopLevelJsonProperty(output, " \"images\": { \"binding\": \"IMAGES\" }");
|
|
@@ -1540,4 +1616,4 @@ function usesCommonJsViteConfig(filePath, code) {
|
|
|
1540
1616
|
return parseViteConfig(filePath, code).body.some((statement) => statement.type === "ExpressionStatement" && statement.expression.type === "AssignmentExpression" && statement.expression.left.type === "MemberExpression" && statement.expression.left.object.type === "Identifier" && statement.expression.left.object.name === "module" && statement.expression.left.property.type === "Identifier" && statement.expression.left.property.name === "exports");
|
|
1541
1617
|
}
|
|
1542
1618
|
//#endregion
|
|
1543
|
-
export { compactResourceName, cssModulesConfigSource, generateAppRouterViteConfig, generatePagesRouterViteConfig, generateResponseStoreWranglerConfig, generateWranglerConfig, getWranglerImagesBinding, getWranglerVersionMetadataBinding, setupCloudflarePlatform, updateViteConfigForCloudflare, updateViteConfigForCssModules, updateWranglerConfigForCloudflare, usesCommonJsViteConfig, validateCloudflarePlatformSetup };
|
|
1619
|
+
export { compactResourceName, cssModulesConfigSource, findConfigKeepingWorkerName, generateAppRouterViteConfig, generatePagesRouterViteConfig, generateResponseStoreWranglerConfig, generateWranglerConfig, getWranglerImagesBinding, getWranglerVersionMetadataBinding, setupCloudflarePlatform, updateViteConfigForCloudflare, updateViteConfigForCssModules, updateWranglerConfigForCloudflare, usesCommonJsViteConfig, validateCloudflarePlatformSetup };
|
package/dist/init-platform.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export type CloudflareInitOptions = {
|
|
|
13
13
|
warmCdnCache?: boolean;
|
|
14
14
|
legacyWrangler?: boolean;
|
|
15
15
|
prerender?: boolean;
|
|
16
|
+
/** Worker name for generated config, instead of one derived from package.json. */
|
|
17
|
+
name?: string;
|
|
16
18
|
};
|
|
17
19
|
export declare const INIT_PLATFORMS: {
|
|
18
20
|
cloudflare: {
|
|
@@ -38,6 +40,8 @@ export type ResolvedInitOptions = {
|
|
|
38
40
|
};
|
|
39
41
|
export declare function isAgentEnvironment(env?: Record<string, string | undefined>): boolean;
|
|
40
42
|
export declare function parsePlatformArg(args: string[]): InitPlatform | undefined;
|
|
43
|
+
export declare function parseNameArg(args: string[]): string | undefined;
|
|
44
|
+
export declare function validateWorkerName(value: string): void;
|
|
41
45
|
export declare function parseDataCacheArg(args: string[]): InitDataCache | undefined;
|
|
42
46
|
export declare function parseCdnCacheArg(args: string[]): InitCdnCache | undefined;
|
|
43
47
|
export declare function parseImageOptimizationArg(args: string[]): InitImageOptimization | undefined;
|
package/dist/init-platform.js
CHANGED
|
@@ -31,6 +31,28 @@ function parsePlatformArg(args) {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
const WORKER_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
|
|
35
|
+
const WORKER_NAME_MAX_LENGTH = 63;
|
|
36
|
+
function parseNameArg(args) {
|
|
37
|
+
for (let index = 0; index < args.length; index++) {
|
|
38
|
+
const arg = args[index];
|
|
39
|
+
let value;
|
|
40
|
+
if (arg === "--name") {
|
|
41
|
+
value = args[index + 1];
|
|
42
|
+
if (!value || value.startsWith("-")) throw new Error("--name requires a Worker name.");
|
|
43
|
+
} else if (arg.startsWith("--name=")) {
|
|
44
|
+
value = arg.slice(7);
|
|
45
|
+
if (!value) throw new Error("--name requires a Worker name.");
|
|
46
|
+
}
|
|
47
|
+
if (value) {
|
|
48
|
+
validateWorkerName(value);
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function validateWorkerName(value) {
|
|
54
|
+
if (value.length > WORKER_NAME_MAX_LENGTH || !WORKER_NAME_PATTERN.test(value)) throw new Error(`Invalid --name value "${value}". Worker names must be at most ${WORKER_NAME_MAX_LENGTH} characters of lowercase letters, numbers, and dashes, and cannot start or end with a dash.`);
|
|
55
|
+
}
|
|
34
56
|
function parseChoiceArg(args, flag, choices, displayedChoices = choices) {
|
|
35
57
|
for (let index = 0; index < args.length; index++) {
|
|
36
58
|
const arg = args[index];
|
|
@@ -115,10 +137,12 @@ async function resolveInitPlatform(args, options = {}) {
|
|
|
115
137
|
}
|
|
116
138
|
async function resolveInitOptions(args, options = {}) {
|
|
117
139
|
const legacyWrangler = parseBooleanArg(args, "--legacy-wrangler-cloudflare-init", void 0, "--legacy-wrangler-cloudflare-init expects true or false when using the \"--legacy-wrangler-cloudflare-init=value\" form.");
|
|
140
|
+
const name = parseNameArg(args);
|
|
118
141
|
const platform = legacyWrangler && !parsePlatformArg(args) ? "cloudflare" : await resolveInitPlatform(args, options);
|
|
119
142
|
const platformOptions = await INIT_PLATFORMS[platform].options(args, options);
|
|
120
143
|
const explicitWarmCdnCache = parseWarmCdnCacheArg(args);
|
|
121
144
|
if (legacyWrangler && platform !== "cloudflare") throw new Error("--legacy-wrangler-cloudflare-init requires --platform=cloudflare.");
|
|
145
|
+
if (name && platform !== "cloudflare") throw new Error("--name requires --platform=cloudflare.");
|
|
122
146
|
const explicitPrerender = parsePrerenderArg(args);
|
|
123
147
|
if (platform === "cloudflare" && platformOptions?.cdnCache === "static-assets" && explicitPrerender === false) throw new Error("--no-prerender cannot be used with --cdn-cache=static-assets, which requires build-time prerendering.");
|
|
124
148
|
const supportsWarmCdnCache = platformOptions?.cdnCache === "response-store" || platformOptions?.cdnCache === "workers-cache";
|
|
@@ -134,7 +158,8 @@ async function resolveInitOptions(args, options = {}) {
|
|
|
134
158
|
...platformOptions,
|
|
135
159
|
warmCdnCache,
|
|
136
160
|
...legacyWrangler ? { legacyWrangler } : {},
|
|
137
|
-
...prerender ? { prerender: true } : {}
|
|
161
|
+
...prerender ? { prerender: true } : {},
|
|
162
|
+
...name ? { name } : {}
|
|
138
163
|
} : void 0
|
|
139
164
|
};
|
|
140
165
|
}
|
|
@@ -314,4 +339,4 @@ async function resolveCloudflareInitOptions(args, options = {}) {
|
|
|
314
339
|
}
|
|
315
340
|
}
|
|
316
341
|
//#endregion
|
|
317
|
-
export { INIT_PLATFORMS, isAgentEnvironment, parseCdnCacheArg, parseDataCacheArg, parseImageOptimizationArg, parsePlatformArg, parsePrerenderArg, parseResponseStoreModeArg, parseWarmCdnCacheArg, resolveCloudflareInitOptions, resolveInitOptions, resolveInitPlatform, resolveInitPrerender, resolveInitWarmCdnCache };
|
|
342
|
+
export { INIT_PLATFORMS, isAgentEnvironment, parseCdnCacheArg, parseDataCacheArg, parseImageOptimizationArg, parseNameArg, parsePlatformArg, parsePrerenderArg, parseResponseStoreModeArg, parseWarmCdnCacheArg, resolveCloudflareInitOptions, resolveInitOptions, resolveInitPlatform, resolveInitPrerender, resolveInitWarmCdnCache, validateWorkerName };
|
package/dist/init.d.ts
CHANGED
|
@@ -64,12 +64,13 @@ export declare function addScripts(root: string, port?: number | false, platform
|
|
|
64
64
|
warmCdnCache?: boolean;
|
|
65
65
|
legacyWrangler?: boolean;
|
|
66
66
|
scriptNames?: "namespaced" | "standard";
|
|
67
|
+
workerName?: string;
|
|
67
68
|
}): string[];
|
|
68
69
|
export type InitDependencyGroups = {
|
|
69
70
|
dependencies: string[];
|
|
70
71
|
devDependencies: string[];
|
|
71
72
|
};
|
|
72
|
-
export declare function getInitDependencyGroups(isAppRouter: boolean, platform: InitPlatform, cloudflare?: CloudflareInitOptions, hasCssModules?: boolean): InitDependencyGroups;
|
|
73
|
+
export declare function getInitDependencyGroups(isAppRouter: boolean, platform: InitPlatform, cloudflare?: CloudflareInitOptions, hasCssModules?: boolean, tailwindPostcss?: boolean): InitDependencyGroups;
|
|
73
74
|
export declare function getInitDeps(isAppRouter: boolean, platform: InitPlatform, cloudflare?: CloudflareInitOptions, hasCssModules?: boolean): string[];
|
|
74
75
|
export declare function isDepInstalled(root: string, dep: string): boolean;
|
|
75
76
|
/**
|