vinext 1.0.0-beta.1 → 1.0.0-beta.2
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 +4 -1
- package/dist/build/client-build-config.js +1 -0
- package/dist/build/report.d.ts +8 -1
- package/dist/build/report.js +12 -2
- package/dist/check.js +15 -2
- package/dist/cli.js +3 -2
- package/dist/config/config-matchers.d.ts +13 -37
- package/dist/config/config-matchers.js +31 -121
- package/dist/config/next-config.d.ts +3 -2
- package/dist/config/next-config.js +3 -1
- package/dist/config/request-context.d.ts +14 -0
- package/dist/config/request-context.js +26 -0
- package/dist/entries/app-rsc-entry.js +27 -9
- package/dist/entries/app-rsc-manifest.js +17 -0
- package/dist/entries/pages-server-entry.js +3 -2
- package/dist/index.js +82 -58
- package/dist/init.d.ts +6 -4
- package/dist/init.js +20 -22
- package/dist/plugins/og-assets.js +1 -1
- package/dist/routing/app-route-graph.d.ts +13 -5
- package/dist/routing/app-route-graph.js +59 -13
- package/dist/routing/app-router.js +12 -6
- package/dist/routing/file-matcher.d.ts +11 -22
- package/dist/routing/file-matcher.js +21 -33
- package/dist/routing/pages-router.js +23 -29
- package/dist/routing/route-matching.d.ts +14 -1
- package/dist/routing/route-matching.js +13 -1
- package/dist/routing/route-pattern.d.ts +2 -1
- package/dist/routing/route-pattern.js +7 -4
- package/dist/routing/route-trie.d.ts +5 -1
- package/dist/routing/route-trie.js +5 -2
- package/dist/server/app-browser-entry.js +7 -6
- package/dist/server/app-browser-history-controller.d.ts +1 -1
- package/dist/server/app-browser-history-controller.js +3 -3
- package/dist/server/app-browser-navigation-controller.js +1 -1
- package/dist/server/app-browser-state.js +1 -1
- package/dist/server/app-browser-visible-commit.js +1 -1
- package/dist/server/app-fallback-renderer.d.ts +3 -0
- package/dist/server/app-fallback-renderer.js +4 -2
- package/dist/server/app-middleware.js +2 -1
- package/dist/server/app-page-boundary-render.d.ts +12 -1
- package/dist/server/app-page-boundary-render.js +84 -2
- package/dist/server/app-page-cache-finalizer.d.ts +1 -1
- package/dist/server/app-page-cache.d.ts +1 -1
- package/dist/server/app-page-dispatch.d.ts +11 -2
- package/dist/server/app-page-dispatch.js +14 -17
- package/dist/server/app-page-element-builder.d.ts +7 -2
- package/dist/server/app-page-element-builder.js +112 -27
- package/dist/server/app-page-head.d.ts +54 -2
- package/dist/server/app-page-head.js +164 -78
- package/dist/server/app-page-http-access-fallback-metadata.d.ts +29 -0
- package/dist/server/app-page-http-access-fallback-metadata.js +106 -0
- package/dist/server/app-page-render.d.ts +2 -2
- package/dist/server/app-page-render.js +1 -1
- package/dist/server/app-page-request.d.ts +12 -0
- package/dist/server/app-page-request.js +133 -13
- package/dist/server/app-page-route-wiring.d.ts +9 -0
- package/dist/server/app-page-route-wiring.js +43 -3
- package/dist/server/app-post-middleware-context.d.ts +1 -1
- package/dist/server/app-post-middleware-context.js +1 -1
- package/dist/server/app-route-handler-dispatch.js +31 -17
- package/dist/server/app-route-handler-execution.d.ts +6 -1
- package/dist/server/app-route-handler-execution.js +42 -16
- package/dist/server/app-route-handler-policy.d.ts +2 -0
- package/dist/server/app-route-handler-policy.js +3 -3
- package/dist/server/app-route-module-loader.d.ts +3 -1
- package/dist/server/app-route-module-loader.js +1 -0
- package/dist/server/app-rsc-cache-busting.d.ts +1 -1
- package/dist/server/app-rsc-errors.d.ts +1 -1
- package/dist/server/app-rsc-errors.js +12 -2
- package/dist/server/app-rsc-handler.d.ts +10 -5
- package/dist/server/app-rsc-handler.js +52 -24
- package/dist/server/app-rsc-request-normalization.d.ts +3 -2
- package/dist/server/app-rsc-request-normalization.js +8 -2
- package/dist/server/app-rsc-response-finalizer.d.ts +2 -2
- package/dist/server/app-rsc-response-finalizer.js +5 -11
- package/dist/server/app-rsc-route-matching.d.ts +20 -0
- package/dist/server/app-rsc-route-matching.js +87 -11
- package/dist/server/app-segment-config.js +13 -3
- package/dist/server/app-server-action-execution.d.ts +3 -1
- package/dist/server/app-server-action-execution.js +9 -7
- package/dist/server/app-ssr-entry.js +2 -2
- package/dist/server/app-ssr-stream.d.ts +1 -7
- package/dist/server/app-ssr-stream.js +2 -10
- package/dist/server/config-headers.d.ts +24 -0
- package/dist/server/config-headers.js +52 -0
- package/dist/server/dev-initial-server-error.d.ts +1 -1
- package/dist/server/dev-server.js +29 -13
- package/dist/server/isr-cache.d.ts +1 -1
- package/dist/server/middleware-matcher-pattern.d.ts +22 -0
- package/dist/server/middleware-matcher-pattern.js +219 -0
- package/dist/server/middleware-matcher.d.ts +2 -7
- package/dist/server/middleware-matcher.js +13 -60
- package/dist/server/middleware-path-to-regexp.d.ts +14 -0
- package/dist/server/middleware-path-to-regexp.js +228 -0
- package/dist/server/middleware-runtime.js +4 -3
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.js +2 -1
- package/dist/server/pages-data-route.d.ts +11 -1
- package/dist/server/pages-data-route.js +16 -1
- package/dist/server/pages-get-initial-props.d.ts +15 -2
- package/dist/server/pages-get-initial-props.js +16 -6
- package/dist/server/pages-page-data.d.ts +3 -1
- package/dist/server/pages-page-data.js +16 -7
- package/dist/server/pages-page-handler.d.ts +4 -2
- package/dist/server/pages-page-handler.js +16 -17
- package/dist/server/pages-page-response.js +1 -1
- package/dist/server/pages-readiness.d.ts +3 -3
- package/dist/server/pages-request-pipeline.d.ts +1 -0
- package/dist/server/pages-request-pipeline.js +25 -11
- package/dist/server/pages-router-entry.js +6 -0
- package/dist/server/prerender-route-params.js +2 -2
- package/dist/server/prod-server.d.ts +1 -4
- package/dist/server/prod-server.js +36 -23
- package/dist/server/request-pipeline.d.ts +15 -29
- package/dist/server/request-pipeline.js +24 -59
- package/dist/server/rsc-stream-hints.js +122 -18
- package/dist/shims/app.d.ts +1 -1
- package/dist/shims/cache-request-state.d.ts +27 -1
- package/dist/shims/cache-request-state.js +60 -1
- package/dist/shims/cache-runtime.d.ts +12 -1
- package/dist/shims/cache-runtime.js +22 -7
- package/dist/shims/cache.d.ts +5 -5
- package/dist/shims/cache.js +26 -10
- package/dist/shims/document.d.ts +42 -83
- package/dist/shims/document.js +62 -53
- package/dist/shims/dynamic.d.ts +5 -25
- package/dist/shims/dynamic.js +29 -8
- package/dist/shims/error.d.ts +1 -1
- package/dist/shims/error.js +1 -1
- package/dist/shims/fetch-cache.js +12 -3
- package/dist/shims/font-google-base.d.ts +11 -4
- package/dist/shims/font-local.d.ts +10 -3
- package/dist/shims/head.d.ts +13 -2
- package/dist/shims/head.js +3 -3
- package/dist/shims/headers.d.ts +28 -31
- package/dist/shims/headers.js +109 -49
- package/dist/shims/image.d.ts +27 -37
- package/dist/shims/image.js +21 -14
- package/dist/shims/internal/cookie-serialize.d.ts +3 -1
- package/dist/shims/internal/cookie-serialize.js +3 -1
- package/dist/shims/internal/hybrid-client-route-owner.js +3 -1
- package/dist/shims/internal/utils.d.ts +3 -3
- package/dist/shims/legacy-image.d.ts +3 -37
- package/dist/shims/legacy-image.js +6 -16
- package/dist/shims/link.d.ts +15 -22
- package/dist/shims/link.js +20 -11
- package/dist/shims/navigation-context-state.d.ts +1 -1
- package/dist/shims/navigation.d.ts +7 -3
- package/dist/shims/navigation.js +24 -13
- package/dist/shims/navigation.react-server.js +1 -1
- package/dist/shims/next-shims-augmentations.d.ts +1 -0
- package/dist/shims/next-shims-public.d.ts +1 -0
- package/dist/shims/public-shim-map.json.js +103 -0
- package/dist/shims/readonly-url-search-params.d.ts +3 -3
- package/dist/shims/readonly-url-search-params.js +3 -3
- package/dist/shims/request-state-types.d.ts +1 -1
- package/dist/shims/router.d.ts +55 -21
- package/dist/shims/router.js +162 -37
- package/dist/shims/script.d.ts +6 -10
- package/dist/shims/script.js +6 -3
- package/dist/shims/server.d.ts +45 -22
- package/dist/shims/server.js +44 -5
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/unified-request-context.js +2 -0
- package/dist/shims/url-safety.d.ts +1 -1
- package/dist/shims/url-safety.js +2 -2
- package/dist/typegen.d.ts +8 -2
- package/dist/typegen.js +76 -15
- package/dist/utils/domain-locale.d.ts +2 -2
- package/dist/utils/external-url.d.ts +5 -0
- package/dist/utils/external-url.js +7 -0
- package/dist/utils/regex-safety.d.ts +8 -0
- package/dist/utils/regex-safety.js +737 -0
- package/package.json +13 -2
package/dist/shims/server.js
CHANGED
|
@@ -17,6 +17,10 @@ import { assertSafeNavigationUrl } from "./url-safety.js";
|
|
|
17
17
|
* This is a pragmatic subset — we implement the most commonly used APIs
|
|
18
18
|
* rather than bug-for-bug parity with Next.js internals.
|
|
19
19
|
*/
|
|
20
|
+
/** @deprecated Import ImageResponse from `next/og` instead. */
|
|
21
|
+
function ImageResponse() {
|
|
22
|
+
throw new Error("ImageResponse has moved from next/server to next/og");
|
|
23
|
+
}
|
|
20
24
|
const _USE_CACHE_ALS_KEY = Symbol.for("vinext.cacheRuntime.contextAls");
|
|
21
25
|
const _UNSTABLE_CACHE_ALS_KEY = Symbol.for("vinext.unstableCache.als");
|
|
22
26
|
const _g = globalThis;
|
|
@@ -60,10 +64,18 @@ var NextRequest = class extends Request {
|
|
|
60
64
|
});
|
|
61
65
|
} else super(input, requestInit);
|
|
62
66
|
const url = typeof input === "string" ? new URL(input, "http://localhost") : input instanceof URL ? input : new URL(input.url, "http://localhost");
|
|
67
|
+
const i18n = _nextConfig?.i18n ? {
|
|
68
|
+
locales: [..._nextConfig.i18n.locales],
|
|
69
|
+
defaultLocale: _nextConfig.i18n.defaultLocale,
|
|
70
|
+
domains: _nextConfig.i18n.domains?.map((domain) => ({
|
|
71
|
+
...domain,
|
|
72
|
+
locales: domain.locales ? [...domain.locales] : void 0
|
|
73
|
+
}))
|
|
74
|
+
} : void 0;
|
|
63
75
|
const urlConfig = _nextConfig ? {
|
|
64
76
|
basePath: _nextConfig.basePath,
|
|
65
77
|
nextConfig: {
|
|
66
|
-
i18n
|
|
78
|
+
i18n,
|
|
67
79
|
trailingSlash: _nextConfig.trailingSlash
|
|
68
80
|
}
|
|
69
81
|
} : void 0;
|
|
@@ -80,6 +92,12 @@ var NextRequest = class extends Request {
|
|
|
80
92
|
get cookies() {
|
|
81
93
|
return this._cookies;
|
|
82
94
|
}
|
|
95
|
+
get page() {
|
|
96
|
+
throw new Error("NextRequest.page has been removed; use URLPattern instead");
|
|
97
|
+
}
|
|
98
|
+
get ua() {
|
|
99
|
+
throw new Error("NextRequest.ua has been removed; use userAgent() instead");
|
|
100
|
+
}
|
|
83
101
|
/**
|
|
84
102
|
* Client IP address. Prefers Cloudflare's trusted CF-Connecting-IP header
|
|
85
103
|
* over the spoofable X-Forwarded-For. Returns undefined if unavailable.
|
|
@@ -407,6 +425,9 @@ var NextURL = class NextURL {
|
|
|
407
425
|
toString() {
|
|
408
426
|
return this.href;
|
|
409
427
|
}
|
|
428
|
+
toJSON() {
|
|
429
|
+
return this.href;
|
|
430
|
+
}
|
|
410
431
|
/**
|
|
411
432
|
* The build ID of the Next.js application.
|
|
412
433
|
* Set from `generateBuildId` in next.config.js, or a random UUID if not configured.
|
|
@@ -489,7 +510,7 @@ var RequestCookies = class {
|
|
|
489
510
|
else this._headers.set("cookie", this._serialize());
|
|
490
511
|
}
|
|
491
512
|
[Symbol.iterator]() {
|
|
492
|
-
return this.getAll().map((
|
|
513
|
+
return new Map(this.getAll().map((cookie) => [cookie.name, cookie])).entries();
|
|
493
514
|
}
|
|
494
515
|
};
|
|
495
516
|
var ReadonlyRequestCookiesError = class ReadonlyRequestCookiesError extends Error {
|
|
@@ -557,7 +578,12 @@ var ResponseCookies = class {
|
|
|
557
578
|
set(...args) {
|
|
558
579
|
const [name, value, opts] = parseCookieSetArgs(args);
|
|
559
580
|
validateCookieName(name);
|
|
560
|
-
const
|
|
581
|
+
const sameSite = opts?.sameSite === true ? "Strict" : typeof opts?.sameSite === "string" ? opts.sameSite[0].toUpperCase() + opts.sameSite.slice(1) : void 0;
|
|
582
|
+
const serialized = serializeSetCookie(name, value, {
|
|
583
|
+
...opts,
|
|
584
|
+
expires: typeof opts?.expires === "number" ? new Date(opts.expires) : opts?.expires,
|
|
585
|
+
sameSite
|
|
586
|
+
});
|
|
561
587
|
this._parsed.set(name, {
|
|
562
588
|
serialized,
|
|
563
589
|
entry: {
|
|
@@ -595,7 +621,7 @@ var ResponseCookies = class {
|
|
|
595
621
|
});
|
|
596
622
|
}
|
|
597
623
|
[Symbol.iterator]() {
|
|
598
|
-
return [...this._parsed.values()].map((
|
|
624
|
+
return new Map([...this._parsed.values()].map(({ entry }) => [entry.name, entry])).entries();
|
|
599
625
|
}
|
|
600
626
|
/** Delete all Set-Cookie headers and re-append from the internal map. */
|
|
601
627
|
_syncHeaders() {
|
|
@@ -655,8 +681,21 @@ var NextFetchEvent = class {
|
|
|
655
681
|
_waitUntilPromises = [];
|
|
656
682
|
constructor(params) {
|
|
657
683
|
this.sourcePage = params.page;
|
|
684
|
+
if (params.context) this._externalWaitUntil = params.context.waitUntil.bind(params.context);
|
|
685
|
+
}
|
|
686
|
+
_externalWaitUntil;
|
|
687
|
+
get request() {
|
|
688
|
+
throw new Error(`The middleware signature for ${this.sourcePage} no longer exposes event.request`);
|
|
658
689
|
}
|
|
690
|
+
respondWith() {
|
|
691
|
+
throw new Error(`The middleware signature for ${this.sourcePage} no longer uses respondWith()`);
|
|
692
|
+
}
|
|
693
|
+
passThroughOnException() {}
|
|
659
694
|
waitUntil(promise) {
|
|
695
|
+
if (this._externalWaitUntil) {
|
|
696
|
+
this._externalWaitUntil(promise);
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
660
699
|
this._waitUntilPromises.push(promise);
|
|
661
700
|
}
|
|
662
701
|
get waitUntilPromises() {
|
|
@@ -727,4 +766,4 @@ const URLPattern = globalThis.URLPattern ?? (() => {
|
|
|
727
766
|
throw new Error("URLPattern is not available in this runtime. Install the `urlpattern-polyfill` package or upgrade to Node 20+.");
|
|
728
767
|
});
|
|
729
768
|
//#endregion
|
|
730
|
-
export { NextFetchEvent, NextRequest, NextResponse, NextURL, RequestCookies, ResponseCookies, URLPattern, after, connection, sealRequestCookies, sealRequestHeaders, userAgent, userAgentFromString };
|
|
769
|
+
export { ImageResponse, NextFetchEvent, NextRequest, NextResponse, NextURL, RequestCookies, ResponseCookies, URLPattern, after, connection, sealRequestCookies, sealRequestHeaders, userAgent, userAgentFromString };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RootParamsState } from "./root-params.js";
|
|
2
1
|
import { CacheState } from "./cache-request-state.js";
|
|
2
|
+
import { RootParamsState } from "./root-params.js";
|
|
3
3
|
import { ExecutionContextLike } from "./request-context.js";
|
|
4
4
|
import { FetchCacheState } from "./fetch-cache.js";
|
|
5
5
|
import { VinextHeadersShimState } from "./headers.js";
|
|
@@ -16,6 +16,8 @@ function createRequestContext(opts) {
|
|
|
16
16
|
return {
|
|
17
17
|
headersContext: null,
|
|
18
18
|
actionRevalidationKind: 0,
|
|
19
|
+
pendingRevalidatedTags: /* @__PURE__ */ new Set(),
|
|
20
|
+
pendingRevalidations: /* @__PURE__ */ new Set(),
|
|
19
21
|
dynamicUsageDetected: false,
|
|
20
22
|
renderRequestApiUsage: /* @__PURE__ */ new Set(),
|
|
21
23
|
connectionProbe: null,
|
|
@@ -29,6 +29,6 @@ declare function isDangerousScheme(url: string): boolean;
|
|
|
29
29
|
* packages/next/src/shared/lib/router/router.ts:1025,1057
|
|
30
30
|
*/
|
|
31
31
|
declare function reportBlockedDangerousNavigation(): void;
|
|
32
|
-
declare function assertSafeNavigationUrl(url: string): void;
|
|
32
|
+
declare function assertSafeNavigationUrl(url: string, ErrorConstructor?: new (message: string) => Error): void;
|
|
33
33
|
//#endregion
|
|
34
34
|
export { DANGEROUS_URL_BLOCK_MESSAGE, assertSafeNavigationUrl, isDangerousScheme, reportBlockedDangerousNavigation };
|
package/dist/shims/url-safety.js
CHANGED
|
@@ -60,10 +60,10 @@ function isDangerousScheme(url) {
|
|
|
60
60
|
function reportBlockedDangerousNavigation() {
|
|
61
61
|
console.error(DANGEROUS_URL_BLOCK_MESSAGE);
|
|
62
62
|
}
|
|
63
|
-
function assertSafeNavigationUrl(url) {
|
|
63
|
+
function assertSafeNavigationUrl(url, ErrorConstructor = Error) {
|
|
64
64
|
if (isDangerousScheme(url)) {
|
|
65
65
|
reportBlockedDangerousNavigation();
|
|
66
|
-
throw new
|
|
66
|
+
throw new ErrorConstructor(DANGEROUS_URL_BLOCK_MESSAGE);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
//#endregion
|
package/dist/typegen.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ type GenerateRouteTypesOptions = {
|
|
|
4
4
|
appDir?: string | null;
|
|
5
5
|
pageExtensions?: readonly string[];
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
type GenerateRouteTypesResult = {
|
|
8
|
+
routeTypesPath: string;
|
|
9
|
+
nextEnvPath: string;
|
|
10
|
+
nextEnvStatus: "created" | "updated" | "unchanged";
|
|
11
|
+
};
|
|
12
|
+
declare function nextEnvFileContent(hasNext: boolean, hasAppDir: boolean, eol?: string): string;
|
|
13
|
+
declare function generateRouteTypes(options: GenerateRouteTypesOptions): Promise<GenerateRouteTypesResult>;
|
|
8
14
|
//#endregion
|
|
9
|
-
export { generateRouteTypes };
|
|
15
|
+
export { GenerateRouteTypesResult, generateRouteTypes, nextEnvFileContent };
|
package/dist/typegen.js
CHANGED
|
@@ -4,34 +4,82 @@ import { decodeRouteSegment, isInvisibleSegment } from "./routing/utils.js";
|
|
|
4
4
|
import { patternToNextFormat } from "./routing/route-validation.js";
|
|
5
5
|
import { compareStrings } from "./utils/compare.js";
|
|
6
6
|
import { appRouteGraph } from "./routing/app-router.js";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
7
8
|
import fsp from "node:fs/promises";
|
|
9
|
+
import os from "node:os";
|
|
8
10
|
//#region src/typegen.ts
|
|
9
|
-
|
|
11
|
+
function nextEnvFileContent(hasNext, hasAppDir, eol = "\n") {
|
|
12
|
+
return `${hasNext ? `/// <reference types="next" />
|
|
10
13
|
/// <reference types="next/image-types/global" />
|
|
11
|
-
import "
|
|
14
|
+
import "vinext/types/augmentations";
|
|
15
|
+
` : `import "vinext/types";
|
|
16
|
+
`}import "./.next/types/routes.d.ts";
|
|
12
17
|
|
|
13
18
|
// NOTE: This file should not be edited
|
|
14
|
-
// see https://nextjs.org/docs
|
|
15
|
-
|
|
19
|
+
// see https://nextjs.org/docs/${hasAppDir ? "app" : "pages"}/api-reference/config/typescript for more information.
|
|
20
|
+
`.replaceAll("\n", eol);
|
|
21
|
+
}
|
|
16
22
|
async function generateRouteTypes(options) {
|
|
17
23
|
const root = path.resolve(options.root);
|
|
18
|
-
const appDir = options.appDir ? path.resolve(options.appDir) : findDir(root, "app", "src/app");
|
|
24
|
+
const appDir = options.appDir === null ? null : options.appDir ? path.resolve(options.appDir) : findDir(root, "app", "src/app");
|
|
19
25
|
const outPath = path.join(root, ".next", "types", "routes.d.ts");
|
|
20
|
-
const
|
|
26
|
+
const pagesDir = findDir(root, "pages", "src/pages");
|
|
27
|
+
const content = appDir ? renderRouteTypes(await collectRouteTypeModel(appDir, options.pageExtensions), pagesDir !== null) : renderRouteTypes(emptyRouteTypeModel(), false);
|
|
21
28
|
await fsp.mkdir(path.dirname(outPath), { recursive: true });
|
|
22
29
|
await fsp.writeFile(outPath, content, "utf-8");
|
|
23
|
-
await ensureNextEnvFile(root);
|
|
24
|
-
return
|
|
30
|
+
const nextEnv = await ensureNextEnvFile(root, appDir !== null);
|
|
31
|
+
return {
|
|
32
|
+
routeTypesPath: outPath,
|
|
33
|
+
nextEnvPath: nextEnv.path,
|
|
34
|
+
nextEnvStatus: nextEnv.status
|
|
35
|
+
};
|
|
25
36
|
}
|
|
26
|
-
async function ensureNextEnvFile(root) {
|
|
37
|
+
async function ensureNextEnvFile(root, hasAppDir) {
|
|
27
38
|
const envPath = path.join(root, "next-env.d.ts");
|
|
39
|
+
let eol = os.EOL;
|
|
40
|
+
let existing;
|
|
28
41
|
try {
|
|
29
|
-
await fsp.
|
|
30
|
-
|
|
31
|
-
|
|
42
|
+
existing = await fsp.readFile(envPath, "utf-8");
|
|
43
|
+
const newline = existing.indexOf("\n", 1);
|
|
44
|
+
if (newline !== -1) eol = existing[newline - 1] === "\r" ? "\r\n" : "\n";
|
|
45
|
+
} catch (error) {
|
|
46
|
+
if (error.code !== "ENOENT") throw error;
|
|
47
|
+
}
|
|
48
|
+
const content = nextEnvFileContent(await hasNextPackage(root), hasAppDir, eol);
|
|
49
|
+
if (existing === content) return {
|
|
50
|
+
path: envPath,
|
|
51
|
+
status: "unchanged"
|
|
52
|
+
};
|
|
53
|
+
await fsp.writeFile(envPath, content, "utf-8");
|
|
54
|
+
return {
|
|
55
|
+
path: envPath,
|
|
56
|
+
status: existing === void 0 ? "created" : "updated"
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async function hasNextPackage(root) {
|
|
60
|
+
const manifestPath = path.join(root, "package.json");
|
|
61
|
+
let declaresNext;
|
|
62
|
+
try {
|
|
63
|
+
const manifest = JSON.parse(await fsp.readFile(manifestPath, "utf-8"));
|
|
64
|
+
declaresNext = [
|
|
65
|
+
"dependencies",
|
|
66
|
+
"devDependencies",
|
|
67
|
+
"peerDependencies",
|
|
68
|
+
"optionalDependencies"
|
|
69
|
+
].some((field) => {
|
|
70
|
+
const dependencies = manifest[field];
|
|
71
|
+
return typeof dependencies === "object" && dependencies !== null && Object.hasOwn(dependencies, "next");
|
|
32
72
|
});
|
|
33
73
|
} catch (error) {
|
|
34
|
-
if (error.code !== "
|
|
74
|
+
if (error.code !== "ENOENT") throw error;
|
|
75
|
+
}
|
|
76
|
+
if (declaresNext === false) return false;
|
|
77
|
+
try {
|
|
78
|
+
const packageJsonPath = createRequire(manifestPath).resolve("next/package.json");
|
|
79
|
+
await fsp.access(packageJsonPath);
|
|
80
|
+
return true;
|
|
81
|
+
} catch {
|
|
82
|
+
return false;
|
|
35
83
|
}
|
|
36
84
|
}
|
|
37
85
|
function emptyRouteTypeModel() {
|
|
@@ -84,12 +132,23 @@ async function collectRouteTypeModel(appDir, pageExtensions) {
|
|
|
84
132
|
for (const slotNames of model.layoutSlots.values()) slotNames.sort(compareStrings);
|
|
85
133
|
return model;
|
|
86
134
|
}
|
|
87
|
-
function renderRouteTypes(model) {
|
|
135
|
+
function renderRouteTypes(model, hasPagesCompat) {
|
|
88
136
|
const allRoutes = uniqueSorted([
|
|
89
137
|
...model.pageRoutes,
|
|
90
138
|
...model.layoutRoutes,
|
|
91
139
|
...model.routeHandlerRoutes
|
|
92
140
|
]);
|
|
141
|
+
const navigationCompat = hasPagesCompat ? `
|
|
142
|
+
declare module "next/navigation" {
|
|
143
|
+
function useSearchParams(): import("next/navigation").ReadonlyURLSearchParams | null;
|
|
144
|
+
function usePathname(): string | null;
|
|
145
|
+
function useParams<
|
|
146
|
+
T extends Record<string, string | string[]> = Record<string, string | string[]>,
|
|
147
|
+
>(): T | null;
|
|
148
|
+
function useSelectedLayoutSegments(): string[] | null;
|
|
149
|
+
function useSelectedLayoutSegment(): string | null;
|
|
150
|
+
}
|
|
151
|
+
` : "";
|
|
93
152
|
return `// This file is generated by vinext. Do not edit.
|
|
94
153
|
import type * as React from "react";
|
|
95
154
|
|
|
@@ -126,6 +185,8 @@ ${renderLayoutSlotMap(model.layoutRoutes, model.layoutSlots)}
|
|
|
126
185
|
}
|
|
127
186
|
}
|
|
128
187
|
|
|
188
|
+
${navigationCompat}
|
|
189
|
+
|
|
129
190
|
export {};
|
|
130
191
|
`;
|
|
131
192
|
}
|
|
@@ -224,4 +285,4 @@ function quote(value) {
|
|
|
224
285
|
return JSON.stringify(value);
|
|
225
286
|
}
|
|
226
287
|
//#endregion
|
|
227
|
-
export { generateRouteTypes };
|
|
288
|
+
export { generateRouteTypes, nextEnvFileContent };
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
type DomainLocale = {
|
|
3
3
|
domain: string;
|
|
4
4
|
defaultLocale: string;
|
|
5
|
-
locales?: string[];
|
|
6
|
-
http?:
|
|
5
|
+
locales?: readonly string[];
|
|
6
|
+
http?: true;
|
|
7
7
|
};
|
|
8
8
|
declare function normalizeDomainHostname(hostname: string | null | undefined): string | undefined;
|
|
9
9
|
/**
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/utils/regex-safety.d.ts
|
|
2
|
+
type RegexSafetyIssue = "nested repetition" | "ambiguous alternatives under repetition" | "ambiguous sequence expansion" | "overlapping sequential repetition" | "analysis budget exceeded";
|
|
3
|
+
declare function analyzeRegexSafety(pattern: string, options?: {
|
|
4
|
+
ignoreCase?: boolean;
|
|
5
|
+
}): RegexSafetyIssue | null;
|
|
6
|
+
declare function regexAtomsMayOverlap(left: string, right: string, ignoreCase?: boolean): boolean;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { RegexSafetyIssue, analyzeRegexSafety, regexAtomsMayOverlap };
|