Initial boiler plate project

This commit is contained in:
2024-09-24 03:52:46 +00:00
parent 6120b2d6c3
commit 154b93e267
10034 changed files with 2079352 additions and 2 deletions

View File

@ -0,0 +1,26 @@
import type webpack from 'webpack';
import type { SizeLimit } from '../../../../../types';
import type { PAGE_TYPES } from '../../../../lib/page-types';
export type EdgeSSRLoaderQuery = {
absolute500Path: string;
absoluteAppPath: string;
absoluteDocumentPath: string;
absoluteErrorPath: string;
absolutePagePath: string;
dev: boolean;
isServerComponent: boolean;
page: string;
stringifiedConfig: string;
appDirLoader?: string;
pagesType: PAGE_TYPES;
sriEnabled: boolean;
cacheHandler?: string;
preferredRegion: string | string[] | undefined;
middlewareConfig: string;
serverActions?: {
bodySizeLimit?: SizeLimit;
allowedOrigins?: string[];
};
};
declare const edgeSSRLoader: webpack.LoaderDefinitionFunction<EdgeSSRLoaderQuery>;
export default edgeSSRLoader;

View File

@ -0,0 +1,100 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _getmodulebuildinfo = require("../get-module-build-info");
const _constants = require("../../../../lib/constants");
const _routekind = require("../../../../server/future/route-kind");
const _normalizepagepath = require("../../../../shared/lib/page-path/normalize-page-path");
const _loadentrypoint = require("../../../load-entrypoint");
/*
For pages SSR'd at the edge, we bundle them with the ESM version of Next in order to
benefit from the better tree-shaking and thus, smaller bundle sizes.
The absolute paths for _app, _error and _document, used in this loader, link to the regular CJS modules.
They are generated in `createPagesMapping` where we don't have access to `isEdgeRuntime`,
so we have to do it here. It's not that bad because it keeps all references to ESM modules magic in this place.
*/ function swapDistFolderWithEsmDistFolder(path) {
return path.replace("next/dist/pages", "next/dist/esm/pages");
}
function getRouteModuleOptions(page) {
const options = {
definition: {
kind: _routekind.RouteKind.PAGES,
page: (0, _normalizepagepath.normalizePagePath)(page),
pathname: page,
// The following aren't used in production.
bundlePath: "",
filename: ""
}
};
return options;
}
const edgeSSRLoader = async function edgeSSRLoader() {
const { dev, page, absolutePagePath, absoluteAppPath, absoluteDocumentPath, absolute500Path, absoluteErrorPath, isServerComponent, stringifiedConfig: stringifiedConfigBase64, appDirLoader: appDirLoaderBase64, pagesType, sriEnabled, cacheHandler, preferredRegion, middlewareConfig: middlewareConfigBase64, serverActions } = this.getOptions();
const middlewareConfig = JSON.parse(Buffer.from(middlewareConfigBase64, "base64").toString());
const stringifiedConfig = Buffer.from(stringifiedConfigBase64 || "", "base64").toString();
const appDirLoader = Buffer.from(appDirLoaderBase64 || "", "base64").toString();
const isAppDir = pagesType === "app";
const buildInfo = (0, _getmodulebuildinfo.getModuleBuildInfo)(this._module);
buildInfo.nextEdgeSSR = {
isServerComponent,
page: page,
isAppDir
};
buildInfo.route = {
page,
absolutePagePath,
preferredRegion,
middlewareConfig
};
const pagePath = this.utils.contextify(this.context || this.rootContext, absolutePagePath);
const appPath = this.utils.contextify(this.context || this.rootContext, swapDistFolderWithEsmDistFolder(absoluteAppPath));
const errorPath = this.utils.contextify(this.context || this.rootContext, swapDistFolderWithEsmDistFolder(absoluteErrorPath));
const documentPath = this.utils.contextify(this.context || this.rootContext, swapDistFolderWithEsmDistFolder(absoluteDocumentPath));
const userland500Path = absolute500Path ? this.utils.contextify(this.context || this.rootContext, swapDistFolderWithEsmDistFolder(absolute500Path)) : null;
const stringifiedPagePath = JSON.stringify(pagePath);
const pageModPath = `${appDirLoader}${stringifiedPagePath.substring(1, stringifiedPagePath.length - 1)}${isAppDir ? `?${_constants.WEBPACK_RESOURCE_QUERIES.edgeSSREntry}` : ""}`;
if (isAppDir) {
return await (0, _loadentrypoint.loadEntrypoint)("edge-ssr-app", {
VAR_USERLAND: pageModPath,
VAR_PAGE: page
}, {
sriEnabled: JSON.stringify(sriEnabled),
nextConfig: stringifiedConfig,
isServerComponent: JSON.stringify(isServerComponent),
dev: JSON.stringify(dev),
serverActions: typeof serverActions === "undefined" ? "undefined" : JSON.stringify(serverActions)
}, {
incrementalCacheHandler: cacheHandler ?? null
});
} else {
return await (0, _loadentrypoint.loadEntrypoint)("edge-ssr", {
VAR_USERLAND: pageModPath,
VAR_PAGE: page,
VAR_MODULE_DOCUMENT: documentPath,
VAR_MODULE_APP: appPath,
VAR_MODULE_GLOBAL_ERROR: errorPath
}, {
pagesType: JSON.stringify(pagesType),
sriEnabled: JSON.stringify(sriEnabled),
nextConfig: stringifiedConfig,
dev: JSON.stringify(dev),
pageRouteModuleOptions: JSON.stringify(getRouteModuleOptions(page)),
errorRouteModuleOptions: JSON.stringify(getRouteModuleOptions("/_error")),
user500RouteModuleOptions: JSON.stringify(getRouteModuleOptions("/500"))
}, {
userland500Page: userland500Path,
incrementalCacheHandler: cacheHandler ?? null
});
}
};
const _default = edgeSSRLoader;
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/build/webpack/loaders/next-edge-ssr-loader/index.ts"],"names":["swapDistFolderWithEsmDistFolder","path","replace","getRouteModuleOptions","page","options","definition","kind","RouteKind","PAGES","normalizePagePath","pathname","bundlePath","filename","edgeSSRLoader","dev","absolutePagePath","absoluteAppPath","absoluteDocumentPath","absolute500Path","absoluteErrorPath","isServerComponent","stringifiedConfig","stringifiedConfigBase64","appDirLoader","appDirLoaderBase64","pagesType","sriEnabled","cacheHandler","preferredRegion","middlewareConfig","middlewareConfigBase64","serverActions","getOptions","JSON","parse","Buffer","from","toString","isAppDir","buildInfo","getModuleBuildInfo","_module","nextEdgeSSR","route","pagePath","utils","contextify","context","rootContext","appPath","errorPath","documentPath","userland500Path","stringifiedPagePath","stringify","pageModPath","substring","length","WEBPACK_RESOURCE_QUERIES","edgeSSREntry","loadEntrypoint","VAR_USERLAND","VAR_PAGE","nextConfig","incrementalCacheHandler","VAR_MODULE_DOCUMENT","VAR_MODULE_APP","VAR_MODULE_GLOBAL_ERROR","pageRouteModuleOptions","errorRouteModuleOptions","user500RouteModuleOptions","userland500Page"],"mappings":";;;;+BA8LA;;;eAAA;;;oCAzLmC;2BACM;2BACf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KqB,SAAS,CAAC5B;YAC3BqC,YAAY1C;YACZP,KAAKmB,KAAKqB,SAAS,CAACxC;YACpBsD,wBAAwBnC,KAAKqB,SAAS,CAACpD,sBAAsBC;YAC7DkE,yBAAyBpC,KAAKqB,SAAS,CACrCpD,sBAAsB;YAExBoE,2BAA2BrC,KAAKqB,SAAS,CACvCpD,sBAAsB;QAE1B,GACA;YACEqE,iBAAiBnB;YACjBY,yBAAyBrC,gBAAgB;QAC3C;IAEJ;AACF;MACF,WAAed"}

View File

@ -0,0 +1,36 @@
import type { NextConfigComplete } from '../../../../server/config-shared';
import type { DocumentType } from '../../../../shared/lib/utils';
import type { BuildManifest } from '../../../../server/get-page-files';
import type { ReactLoadableManifest } from '../../../../server/load-components';
import type { ClientReferenceManifest } from '../../plugins/flight-manifest-plugin';
import type { NextFontManifest } from '../../plugins/next-font-manifest-plugin';
import type { NextFetchEvent } from '../../../../server/web/spec-extension/fetch-event';
import type { ManifestRewriteRoute } from '../../..';
import type { SizeLimit } from '../../../../../types';
import type { PAGE_TYPES } from '../../../../lib/page-types';
import type { NextRequestHint } from '../../../../server/web/adapter';
export declare function getRender({ dev, page, appMod, pageMod, errorMod, error500Mod, pagesType, Document, buildManifest, reactLoadableManifest, interceptionRouteRewrites, renderToHTML, clientReferenceManifest, subresourceIntegrityManifest, serverActionsManifest, serverActions, config, buildId, nextFontManifest, incrementalCacheHandler, }: {
pagesType: PAGE_TYPES;
dev: boolean;
page: string;
appMod: any;
pageMod: any;
errorMod: any;
error500Mod: any;
renderToHTML?: any;
Document: DocumentType;
buildManifest: BuildManifest;
reactLoadableManifest: ReactLoadableManifest;
subresourceIntegrityManifest?: Record<string, string>;
interceptionRouteRewrites?: ManifestRewriteRoute[];
clientReferenceManifest?: ClientReferenceManifest;
serverActionsManifest?: any;
serverActions?: {
bodySizeLimit?: SizeLimit;
allowedOrigins?: string[];
};
config: NextConfigComplete;
buildId: string;
nextFontManifest: NextFontManifest;
incrementalCacheHandler?: any;
}): (request: NextRequestHint, event?: NextFetchEvent) => Promise<Response>;

View File

@ -0,0 +1,114 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getRender", {
enumerable: true,
get: function() {
return getRender;
}
});
const _webserver = /*#__PURE__*/ _interop_require_default(require("../../../../server/web-server"));
const _web = require("../../../../server/base-http/web");
const _constants = require("../../../../lib/constants");
const _apppaths = require("../../../../shared/lib/router/utils/app-paths");
const _internaledgewaituntil = require("../../../../server/web/internal-edge-wait-until");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function getRender({ dev, page, appMod, pageMod, errorMod, error500Mod, pagesType, Document, buildManifest, reactLoadableManifest, interceptionRouteRewrites, renderToHTML, clientReferenceManifest, subresourceIntegrityManifest, serverActionsManifest, serverActions, config, buildId, nextFontManifest, incrementalCacheHandler }) {
const isAppPath = pagesType === "app";
const baseLoadComponentResult = {
dev,
buildManifest,
reactLoadableManifest,
subresourceIntegrityManifest,
Document,
App: appMod == null ? void 0 : appMod.default,
clientReferenceManifest
};
const server = new _webserver.default({
dev,
conf: config,
minimalMode: true,
webServerConfig: {
page,
pathname: isAppPath ? (0, _apppaths.normalizeAppPath)(page) : page,
pagesType,
interceptionRouteRewrites,
extendRenderOpts: {
buildId,
runtime: _constants.SERVER_RUNTIME.experimentalEdge,
supportsDynamicResponse: true,
disableOptimizedLoading: true,
serverActionsManifest,
serverActions,
nextFontManifest
},
renderToHTML,
incrementalCacheHandler,
loadComponent: async (inputPage)=>{
if (inputPage === page) {
return {
...baseLoadComponentResult,
Component: pageMod.default,
pageConfig: pageMod.config || {},
getStaticProps: pageMod.getStaticProps,
getServerSideProps: pageMod.getServerSideProps,
getStaticPaths: pageMod.getStaticPaths,
ComponentMod: pageMod,
isAppPath: !!pageMod.__next_app__,
page: inputPage,
routeModule: pageMod.routeModule
};
}
// If there is a custom 500 page, we need to handle it separately.
if (inputPage === "/500" && error500Mod) {
return {
...baseLoadComponentResult,
Component: error500Mod.default,
pageConfig: error500Mod.config || {},
getStaticProps: error500Mod.getStaticProps,
getServerSideProps: error500Mod.getServerSideProps,
getStaticPaths: error500Mod.getStaticPaths,
ComponentMod: error500Mod,
page: inputPage,
routeModule: error500Mod.routeModule
};
}
if (inputPage === "/_error") {
return {
...baseLoadComponentResult,
Component: errorMod.default,
pageConfig: errorMod.config || {},
getStaticProps: errorMod.getStaticProps,
getServerSideProps: errorMod.getServerSideProps,
getStaticPaths: errorMod.getStaticPaths,
ComponentMod: errorMod,
page: inputPage,
routeModule: errorMod.routeModule
};
}
return null;
}
}
});
const handler = server.getRequestHandler();
return async function render(request, event) {
const extendedReq = new _web.WebNextRequest(request);
const extendedRes = new _web.WebNextResponse();
handler(extendedReq, extendedRes);
const result = await extendedRes.toResponse();
if (event == null ? void 0 : event.waitUntil) {
const waitUntilPromise = (0, _internaledgewaituntil.internal_getCurrentFunctionWaitUntil)();
if (waitUntilPromise) {
event.waitUntil(waitUntilPromise);
}
}
return result;
};
}
//# sourceMappingURL=render.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../../../src/build/webpack/loaders/next-edge-ssr-loader/render.ts"],"names":["getRender","dev","page","appMod","pageMod","errorMod","error500Mod","pagesType","Document","buildManifest","reactLoadableManifest","interceptionRouteRewrites","renderToHTML","clientReferenceManifest","subresourceIntegrityManifest","serverActionsManifest","serverActions","config","buildId","nextFontManifest","incrementalCacheHandler","isAppPath","baseLoadComponentResult","App","default","server","WebServer","conf","minimalMode","webServerConfig","pathname","normalizeAppPath","extendRenderOpts","runtime","SERVER_RUNTIME","experimentalEdge","supportsDynamicResponse","disableOptimizedLoading","loadComponent","inputPage","Component","pageConfig","getStaticProps","getServerSideProps","getStaticPaths","ComponentMod","__next_app__","routeModule","handler","getRequestHandler","render","request","event","extendedReq","WebNextRequest","extendedRes","WebNextResponse","result","toResponse","waitUntil","waitUntilPromise","internal_getCurrentFunctionWaitUntil"],"mappings":";;;;+BAsBgBA;;;eAAAA;;;kEAbM;qBA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