Skip to content

Commit d039902

Browse files
committed
ignore for now
1 parent 18e0e46 commit d039902

File tree

20 files changed

+154
-2293
lines changed

20 files changed

+154
-2293
lines changed

package-lock.json

Lines changed: 20 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/next-on-pages/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,14 @@
5656
"dependencies": {
5757
"acorn": "^8.8.0",
5858
"ast-types": "^0.14.2",
59+
"build-output-router": "^0.0.1-d4ce9a1",
5960
"chalk": "^5.2.0",
6061
"chokidar": "^3.5.3",
6162
"commander": "^11.1.0",
62-
"cookie": "^0.5.0",
6363
"esbuild": "^0.15.3",
6464
"js-yaml": "^4.1.0",
6565
"miniflare": "^3.20231218.1",
6666
"package-manager-manager": "^0.2.0",
67-
"pcre-to-regexp": "^1.1.0",
6867
"semver": "^7.5.2"
6968
},
7069
"devDependencies": {
@@ -88,9 +87,9 @@
8887
"vitest-environment-miniflare": "^2.13.0"
8988
},
9089
"peerDependencies": {
90+
"@cloudflare/workers-types": "^4.20240208.0",
9191
"vercel": ">=30.0.0",
92-
"wrangler": "^3.28.2",
93-
"@cloudflare/workers-types": "^4.20240208.0"
92+
"wrangler": "^3.28.2"
9493
},
9594
"peerDependenciesMeta": {
9695
"@cloudflare/workers-types": {

packages/next-on-pages/src/buildApplication/buildWorkerFile.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { generateGlobalJs } from './generateGlobalJs';
66
import type { ProcessedVercelOutput } from './processVercelOutput';
77
import { getNodeEnv } from '../utils/getNodeEnv';
88
import { normalizePath } from '../utils';
9+
import { collectLocalesFromRoutes } from 'build-output-router/router';
910
import { cliLog } from '../cli';
1011

1112
/**
@@ -20,10 +21,6 @@ export function constructBuildOutputRecord(
2021
outputDir: string,
2122
) {
2223
if (item.type === 'static') {
23-
return `{ type: ${JSON.stringify(item.type)} }`;
24-
}
25-
26-
if (item.type === 'override') {
2724
return `{
2825
type: ${JSON.stringify(item.type)},
2926
path: ${item.path ? JSON.stringify(item.path) : undefined},
@@ -86,7 +83,7 @@ export async function buildWorkerFile(
8683
__CONFIG__: JSON.stringify(vercelConfig),
8784
__NODE_ENV__: JSON.stringify(getNodeEnv()),
8885
__BUILD_METADATA__: JSON.stringify({
89-
collectedLocales: collectLocales(vercelConfig.routes),
86+
collectedLocales: collectLocalesFromRoutes(vercelConfig.routes),
9087
}),
9188
},
9289
outfile: outputFile,
@@ -134,22 +131,3 @@ type BuildWorkerFileOpts = {
134131
customEntrypoint?: string;
135132
minify?: boolean;
136133
};
137-
138-
/**
139-
* Collects all the locales present in the processed Vercel routes
140-
*
141-
* @param routes The Vercel routes to collect the locales from
142-
* @returns an array containing all the found locales (without duplicates)
143-
*/
144-
function collectLocales(routes: ProcessedVercelRoutes): string[] {
145-
const locales = Object.values(routes)
146-
.flat()
147-
.flatMap(source => {
148-
if (source.locale?.redirect) {
149-
return Object.keys(source.locale.redirect);
150-
}
151-
return [];
152-
})
153-
.filter(Boolean);
154-
return [...new Set(locales)];
155-
}

packages/next-on-pages/src/buildApplication/processVercelOutput.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ function applyVercelOverrides(
230230
const assetPath = addLeadingSlash(rawAssetPath);
231231
const servedPath = addLeadingSlash(rawServedPath ?? '');
232232

233-
const newValue: BuildOutputStaticOverride = {
234-
type: 'override',
233+
const newValue: BuildOutputStaticAsset = {
234+
type: 'static',
235235
path: assetPath,
236236
headers: contentType ? { 'content-type': contentType } : undefined,
237237
};
@@ -270,14 +270,14 @@ function applyPrerenderedRoutes(
270270
const path = route?.path ?? stripFuncExtension(relativePath);
271271

272272
vercelOutput.set(path, {
273-
type: 'override',
273+
type: 'static',
274274
path,
275275
headers: route?.headers,
276276
});
277277

278278
route?.overrides?.forEach(overridenPath => {
279279
vercelOutput.set(overridenPath, {
280-
type: 'override',
280+
type: 'static',
281281
path,
282282
headers: route?.headers,
283283
});

packages/next-on-pages/templates/_worker.js/handleRequest.ts

Lines changed: 0 additions & 128 deletions
This file was deleted.

packages/next-on-pages/templates/_worker.js/index.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { SUSPENSE_CACHE_URL } from '../cache';
2-
import { handleRequest } from './handleRequest';
32
import { setupRoutesIsolation } from './routesIsolation';
43
import {
54
adjustRequestForVercel,
5+
getAssetsHandler,
66
handleImageResizingRequest,
77
patchFetch,
88
} from './utils';
99
import type { AsyncLocalStorage } from 'node:async_hooks';
10+
import { Router } from 'build-output-router';
1011

1112
declare const __NODE_ENV__: string;
1213

@@ -21,6 +22,11 @@ declare const __ALSes_PROMISE__: Promise<null | {
2122
requestContextAsyncLocalStorage: AsyncLocalStorage<unknown>;
2223
}>;
2324

25+
const router = new Router(__CONFIG__.routes, {
26+
locales: new Set(__BUILD_METADATA__.collectedLocales),
27+
wildcardConfig: __CONFIG__.wildcard,
28+
});
29+
2430
export default {
2531
async fetch(request, env, ctx) {
2632
setupRoutesIsolation();
@@ -60,16 +66,13 @@ export default {
6066

6167
const adjustedRequest = adjustRequestForVercel(request);
6268

63-
return handleRequest(
64-
{
65-
request: adjustedRequest,
66-
ctx,
67-
assetsFetcher: env.ASSETS,
68-
},
69-
__CONFIG__,
70-
__BUILD_OUTPUT__,
71-
__BUILD_METADATA__,
72-
);
69+
const assets = getAssetsHandler(__BUILD_OUTPUT__, {
70+
request: adjustedRequest,
71+
ctx,
72+
assetsFetcher: env.ASSETS,
73+
});
74+
75+
return router.fetch({ request: adjustedRequest, ctx, assets });
7376
},
7477
);
7578
},

0 commit comments

Comments
 (0)