Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore for now #887

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions packages/next-on-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@
"dependencies": {
"acorn": "^8.8.0",
"ast-types": "^0.14.2",
"build-output-router": "0.0.1-defb153",
"chalk": "^5.2.0",
"chokidar": "^3.5.3",
"commander": "^11.1.0",
"cookie": "^0.5.0",
"esbuild": "^0.15.3",
"js-yaml": "^4.1.0",
"miniflare": "^3.20231218.1",
"package-manager-manager": "^0.2.0",
"pcre-to-regexp": "^1.1.0",
"semver": "^7.5.2"
},
"devDependencies": {
Expand All @@ -88,9 +87,9 @@
"vitest-environment-miniflare": "^2.13.0"
},
"peerDependencies": {
"@cloudflare/workers-types": "^4.20240208.0",
"vercel": ">=30.0.0",
"wrangler": "^3.28.2",
"@cloudflare/workers-types": "^4.20240208.0"
"wrangler": "^3.28.2"
},
"peerDependenciesMeta": {
"@cloudflare/workers-types": {
Expand Down
26 changes: 2 additions & 24 deletions packages/next-on-pages/src/buildApplication/buildWorkerFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { generateGlobalJs } from './generateGlobalJs';
import type { ProcessedVercelOutput } from './processVercelOutput';
import { getNodeEnv } from '../utils/getNodeEnv';
import { normalizePath } from '../utils';
import { collectLocalesFromRoutes } from 'build-output-router/router';
import { cliLog } from '../cli';

/**
Expand All @@ -20,10 +21,6 @@ export function constructBuildOutputRecord(
outputDir: string,
) {
if (item.type === 'static') {
return `{ type: ${JSON.stringify(item.type)} }`;
}

if (item.type === 'override') {
return `{
type: ${JSON.stringify(item.type)},
path: ${item.path ? JSON.stringify(item.path) : undefined},
Expand Down Expand Up @@ -86,7 +83,7 @@ export async function buildWorkerFile(
__CONFIG__: JSON.stringify(vercelConfig),
__NODE_ENV__: JSON.stringify(getNodeEnv()),
__BUILD_METADATA__: JSON.stringify({
collectedLocales: collectLocales(vercelConfig.routes),
collectedLocales: [...collectLocalesFromRoutes(vercelConfig.routes)],
}),
},
outfile: outputFile,
Expand Down Expand Up @@ -134,22 +131,3 @@ type BuildWorkerFileOpts = {
customEntrypoint?: string;
minify?: boolean;
};

/**
* Collects all the locales present in the processed Vercel routes
*
* @param routes The Vercel routes to collect the locales from
* @returns an array containing all the found locales (without duplicates)
*/
function collectLocales(routes: ProcessedVercelRoutes): string[] {
const locales = Object.values(routes)
.flat()
.flatMap(source => {
if (source.locale?.redirect) {
return Object.keys(source.locale.redirect);
}
return [];
})
.filter(Boolean);
return [...new Set(locales)];
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ function applyVercelOverrides(
const assetPath = addLeadingSlash(rawAssetPath);
const servedPath = addLeadingSlash(rawServedPath ?? '');

const newValue: BuildOutputStaticOverride = {
type: 'override',
const newValue: BuildOutputStaticAsset = {
type: 'static',
path: assetPath,
headers: contentType ? { 'content-type': contentType } : undefined,
};
Expand Down Expand Up @@ -270,14 +270,14 @@ function applyPrerenderedRoutes(
const path = route?.path ?? stripFuncExtension(relativePath);

vercelOutput.set(path, {
type: 'override',
type: 'static',
path,
headers: route?.headers,
});

route?.overrides?.forEach(overridenPath => {
vercelOutput.set(overridenPath, {
type: 'override',
type: 'static',
path,
headers: route?.headers,
});
Expand Down
128 changes: 0 additions & 128 deletions packages/next-on-pages/templates/_worker.js/handleRequest.ts

This file was deleted.

25 changes: 14 additions & 11 deletions packages/next-on-pages/templates/_worker.js/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { SUSPENSE_CACHE_URL } from '../cache';
import { handleRequest } from './handleRequest';
import { setupRoutesIsolation } from './routesIsolation';
import {
adjustRequestForVercel,
getAssetsHandler,
handleImageResizingRequest,
patchFetch,
} from './utils';
import type { AsyncLocalStorage } from 'node:async_hooks';
import { Router } from 'build-output-router';

declare const __NODE_ENV__: string;

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

const router = new Router(__CONFIG__.routes, {
locales: new Set(__BUILD_METADATA__.collectedLocales),
wildcardConfig: __CONFIG__.wildcard,
});

export default {
async fetch(request, env, ctx) {
setupRoutesIsolation();
Expand Down Expand Up @@ -60,16 +66,13 @@ export default {

const adjustedRequest = adjustRequestForVercel(request);

return handleRequest(
{
request: adjustedRequest,
ctx,
assetsFetcher: env.ASSETS,
},
__CONFIG__,
__BUILD_OUTPUT__,
__BUILD_METADATA__,
);
const assets = getAssetsHandler(__BUILD_OUTPUT__, {
request: adjustedRequest,
ctx,
assetsFetcher: env.ASSETS,
});

return router.fetch({ request: adjustedRequest, ctx, assets });
},
);
},
Expand Down
Loading
Loading