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,21 @@
/**
* `app` -> app dir
* `pages` -> pages dir
* `root` -> middleware / instrumentation
* `assets` -> assets
*/
export type EntryKeyType = 'app' | 'pages' | 'root' | 'assets';
export type EntryKeySide = 'client' | 'server';
export type EntryKey = `{"type":"${EntryKeyType}","side":"${EntryKeyType}","page":"${string}"}`;
/**
* Get a key that's unique across all entrypoints.
*/
export declare function getEntryKey(type: EntryKeyType, side: EntryKeySide, page: string): EntryKey;
/**
* Split an `EntryKey` up into its components.
*/
export declare function splitEntryKey(key: EntryKey): {
type: EntryKeyType;
side: EntryKeySide;
page: string;
};

View File

@ -0,0 +1,39 @@
/**
* `app` -> app dir
* `pages` -> pages dir
* `root` -> middleware / instrumentation
* `assets` -> assets
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
getEntryKey: null,
splitEntryKey: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
getEntryKey: function() {
return getEntryKey;
},
splitEntryKey: function() {
return splitEntryKey;
}
});
function getEntryKey(type, side, page) {
return JSON.stringify({
type,
side,
page
});
}
function splitEntryKey(key) {
return JSON.parse(key);
}
//# sourceMappingURL=entry-key.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/server/dev/turbopack/entry-key.ts"],"names":["getEntryKey","splitEntryKey","type","side","page","JSON","stringify","key","parse"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;;;;;IAWeA,WAAW;eAAXA;;IAWAC,aAAa;eAAbA;;;AAXT,SAASD,YACdE,IAAkB,EAClBC,IAAkB,EAClBC,IAAY;IAEZ,OAAOC,KAAKC,SAAS,CAAC;QAAEJ;QAAMC;QAAMC;IAAK;AAC3C;AAKO,SAASH,cAAcM,GAAa;IAKzC,OAAOF,KAAKG,KAAK,CAACD;AACpB"}

View File

@ -0,0 +1,65 @@
import type { MiddlewareManifest } from '../../../build/webpack/plugins/middleware-plugin';
import type { SetupOpts } from '../../lib/router-utils/setup-dev-bundler';
import type { PageEntrypoints } from './types';
import { type EntryKey } from './entry-key';
interface InstrumentationDefinition {
files: string[];
name: 'instrumentation';
}
type TurbopackMiddlewareManifest = MiddlewareManifest & {
instrumentation?: InstrumentationDefinition;
};
export declare class TurbopackManifestLoader {
private actionManifests;
private appBuildManifests;
private appPathsManifests;
private buildManifests;
private fontManifests;
private loadableManifests;
private middlewareManifests;
private pagesManifests;
private encryptionKey;
private readonly distDir;
private readonly buildId;
constructor({ distDir, buildId, encryptionKey, }: {
buildId: string;
distDir: string;
encryptionKey: string;
});
delete(key: EntryKey): void;
loadActionManifest(pageName: string): Promise<void>;
private mergeActionManifests;
private writeActionManifest;
loadAppBuildManifest(pageName: string): Promise<void>;
private mergeAppBuildManifests;
private writeAppBuildManifest;
loadAppPathsManifest(pageName: string): Promise<void>;
private writeAppPathsManifest;
/**
* Turbopack doesn't support this functionality, so it writes an empty manifest.
*/
private writeAutomaticFontOptimizationManifest;
loadBuildManifest(pageName: string, type?: 'app' | 'pages'): Promise<void>;
private mergeBuildManifests;
private writeBuildManifest;
private writeFallbackBuildManifest;
loadFontManifest(pageName: string, type?: 'app' | 'pages'): Promise<void>;
private mergeFontManifests;
private writeNextFontManifest;
loadLoadableManifest(pageName: string, type?: 'app' | 'pages'): Promise<void>;
private mergeLoadableManifests;
private writeLoadableManifest;
loadMiddlewareManifest(pageName: string, type: 'pages' | 'app' | 'middleware' | 'instrumentation'): Promise<void>;
getMiddlewareManifest(key: EntryKey): TurbopackMiddlewareManifest | undefined;
deleteMiddlewareManifest(key: EntryKey): boolean;
private mergeMiddlewareManifests;
private writeMiddlewareManifest;
loadPagesManifest(pageName: string): Promise<void>;
private mergePagesManifests;
private writePagesManifest;
writeManifests({ rewrites, pageEntrypoints, }: {
rewrites: SetupOpts['fsChecker']['rewrites'];
pageEntrypoints: PageEntrypoints;
}): Promise<void>;
}
export {};

View File

@ -0,0 +1,327 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "TurbopackManifestLoader", {
enumerable: true,
get: function() {
return TurbopackManifestLoader;
}
});
const _pathtoregexp = require("next/dist/compiled/path-to-regexp");
const _constants = require("../../../shared/lib/constants");
const _path = require("path");
const _promises = require("fs/promises");
const _nextjsrequirecachehotreloader = require("../../../build/webpack/plugins/nextjs-require-cache-hot-reloader");
const _writeatomic = require("../../../lib/fs/write-atomic");
const _generateinterceptionroutesrewrites = require("../../../lib/generate-interception-routes-rewrites");
const _buildmanifestplugin = require("../../../build/webpack/plugins/build-manifest-plugin");
const _getassetpathfromroute = /*#__PURE__*/ _interop_require_default(require("../../../shared/lib/router/utils/get-asset-path-from-route"));
const _entrykey = require("./entry-key");
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
async function readPartialManifest(distDir, name, pageName, type = "pages") {
const manifestPath = _path.posix.join(distDir, `server`, type, type === "middleware" || type === "instrumentation" ? "" : type === "app" ? pageName : (0, _getassetpathfromroute.default)(pageName), name);
return JSON.parse(await (0, _promises.readFile)(_path.posix.join(manifestPath), "utf-8"));
}
class TurbopackManifestLoader {
constructor({ distDir, buildId, encryptionKey }){
this.actionManifests = new Map();
this.appBuildManifests = new Map();
this.appPathsManifests = new Map();
this.buildManifests = new Map();
this.fontManifests = new Map();
this.loadableManifests = new Map();
this.middlewareManifests = new Map();
this.pagesManifests = new Map();
this.distDir = distDir;
this.buildId = buildId;
this.encryptionKey = encryptionKey;
}
delete(key) {
this.actionManifests.delete(key);
this.appBuildManifests.delete(key);
this.appPathsManifests.delete(key);
this.buildManifests.delete(key);
this.fontManifests.delete(key);
this.loadableManifests.delete(key);
this.middlewareManifests.delete(key);
this.pagesManifests.delete(key);
}
async loadActionManifest(pageName) {
this.actionManifests.set((0, _entrykey.getEntryKey)("app", "server", pageName), await readPartialManifest(this.distDir, `${_constants.SERVER_REFERENCE_MANIFEST}.json`, pageName, "app"));
}
async mergeActionManifests(manifests) {
const manifest = {
node: {},
edge: {},
encryptionKey: this.encryptionKey
};
function mergeActionIds(actionEntries, other) {
for(const key in other){
const action = actionEntries[key] ??= {
workers: {},
layer: {}
};
Object.assign(action.workers, other[key].workers);
Object.assign(action.layer, other[key].layer);
}
}
for (const m of manifests){
mergeActionIds(manifest.node, m.node);
mergeActionIds(manifest.edge, m.edge);
}
return manifest;
}
async writeActionManifest() {
const actionManifest = await this.mergeActionManifests(this.actionManifests.values());
const actionManifestJsonPath = (0, _path.join)(this.distDir, "server", `${_constants.SERVER_REFERENCE_MANIFEST}.json`);
const actionManifestJsPath = (0, _path.join)(this.distDir, "server", `${_constants.SERVER_REFERENCE_MANIFEST}.js`);
const json = JSON.stringify(actionManifest, null, 2);
(0, _nextjsrequirecachehotreloader.deleteCache)(actionManifestJsonPath);
(0, _nextjsrequirecachehotreloader.deleteCache)(actionManifestJsPath);
await (0, _promises.writeFile)(actionManifestJsonPath, json, "utf-8");
await (0, _promises.writeFile)(actionManifestJsPath, `self.__RSC_SERVER_MANIFEST=${JSON.stringify(json)}`, "utf-8");
}
async loadAppBuildManifest(pageName) {
this.appBuildManifests.set((0, _entrykey.getEntryKey)("app", "server", pageName), await readPartialManifest(this.distDir, _constants.APP_BUILD_MANIFEST, pageName, "app"));
}
mergeAppBuildManifests(manifests) {
const manifest = {
pages: {}
};
for (const m of manifests){
Object.assign(manifest.pages, m.pages);
}
return manifest;
}
async writeAppBuildManifest() {
const appBuildManifest = this.mergeAppBuildManifests(this.appBuildManifests.values());
const appBuildManifestPath = (0, _path.join)(this.distDir, _constants.APP_BUILD_MANIFEST);
(0, _nextjsrequirecachehotreloader.deleteCache)(appBuildManifestPath);
await (0, _writeatomic.writeFileAtomic)(appBuildManifestPath, JSON.stringify(appBuildManifest, null, 2));
}
async loadAppPathsManifest(pageName) {
this.appPathsManifests.set((0, _entrykey.getEntryKey)("app", "server", pageName), await readPartialManifest(this.distDir, _constants.APP_PATHS_MANIFEST, pageName, "app"));
}
async writeAppPathsManifest() {
const appPathsManifest = this.mergePagesManifests(this.appPathsManifests.values());
const appPathsManifestPath = (0, _path.join)(this.distDir, "server", _constants.APP_PATHS_MANIFEST);
(0, _nextjsrequirecachehotreloader.deleteCache)(appPathsManifestPath);
await (0, _writeatomic.writeFileAtomic)(appPathsManifestPath, JSON.stringify(appPathsManifest, null, 2));
}
/**
* Turbopack doesn't support this functionality, so it writes an empty manifest.
*/ async writeAutomaticFontOptimizationManifest() {
const manifestPath = (0, _path.join)(this.distDir, "server", _constants.AUTOMATIC_FONT_OPTIMIZATION_MANIFEST);
await (0, _writeatomic.writeFileAtomic)(manifestPath, JSON.stringify([]));
}
async loadBuildManifest(pageName, type = "pages") {
this.buildManifests.set((0, _entrykey.getEntryKey)(type, "server", pageName), await readPartialManifest(this.distDir, _constants.BUILD_MANIFEST, pageName, type));
}
mergeBuildManifests(manifests) {
const manifest = {
pages: {
"/_app": []
},
// Something in next.js depends on these to exist even for app dir rendering
devFiles: [],
ampDevFiles: [],
polyfillFiles: [],
lowPriorityFiles: [
"static/development/_ssgManifest.js",
"static/development/_buildManifest.js"
],
rootMainFiles: [],
ampFirstPages: []
};
for (const m of manifests){
Object.assign(manifest.pages, m.pages);
if (m.rootMainFiles.length) manifest.rootMainFiles = m.rootMainFiles;
}
return manifest;
}
async writeBuildManifest(pageEntrypoints, rewrites) {
const buildManifest = this.mergeBuildManifests(this.buildManifests.values());
const buildManifestPath = (0, _path.join)(this.distDir, _constants.BUILD_MANIFEST);
const middlewareBuildManifestPath = (0, _path.join)(this.distDir, "server", `${_constants.MIDDLEWARE_BUILD_MANIFEST}.js`);
const interceptionRewriteManifestPath = (0, _path.join)(this.distDir, "server", `${_constants.INTERCEPTION_ROUTE_REWRITE_MANIFEST}.js`);
(0, _nextjsrequirecachehotreloader.deleteCache)(buildManifestPath);
(0, _nextjsrequirecachehotreloader.deleteCache)(middlewareBuildManifestPath);
(0, _nextjsrequirecachehotreloader.deleteCache)(interceptionRewriteManifestPath);
await (0, _writeatomic.writeFileAtomic)(buildManifestPath, JSON.stringify(buildManifest, null, 2));
await (0, _writeatomic.writeFileAtomic)(middlewareBuildManifestPath, `self.__BUILD_MANIFEST=${JSON.stringify(buildManifest)};`);
const interceptionRewrites = JSON.stringify(rewrites.beforeFiles.filter(_generateinterceptionroutesrewrites.isInterceptionRouteRewrite));
await (0, _writeatomic.writeFileAtomic)(interceptionRewriteManifestPath, `self.__INTERCEPTION_ROUTE_REWRITE_MANIFEST=${JSON.stringify(interceptionRewrites)};`);
const content = {
__rewrites: rewrites ? (0, _buildmanifestplugin.normalizeRewritesForBuildManifest)(rewrites) : {
afterFiles: [],
beforeFiles: [],
fallback: []
},
...Object.fromEntries([
...pageEntrypoints.keys()
].map((pathname)=>[
pathname,
`static/chunks/pages${pathname === "/" ? "/index" : pathname}.js`
])),
sortedPages: [
...pageEntrypoints.keys()
]
};
const buildManifestJs = `self.__BUILD_MANIFEST = ${JSON.stringify(content)};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()`;
await (0, _writeatomic.writeFileAtomic)((0, _path.join)(this.distDir, "static", this.buildId, "_buildManifest.js"), buildManifestJs);
await (0, _writeatomic.writeFileAtomic)((0, _path.join)(this.distDir, "static", this.buildId, "_ssgManifest.js"), _buildmanifestplugin.srcEmptySsgManifest);
}
async writeFallbackBuildManifest() {
const fallbackBuildManifest = this.mergeBuildManifests([
this.buildManifests.get((0, _entrykey.getEntryKey)("pages", "server", "_app")),
this.buildManifests.get((0, _entrykey.getEntryKey)("pages", "server", "_error"))
].filter(Boolean));
const fallbackBuildManifestPath = (0, _path.join)(this.distDir, `fallback-${_constants.BUILD_MANIFEST}`);
(0, _nextjsrequirecachehotreloader.deleteCache)(fallbackBuildManifestPath);
await (0, _writeatomic.writeFileAtomic)(fallbackBuildManifestPath, JSON.stringify(fallbackBuildManifest, null, 2));
}
async loadFontManifest(pageName, type = "pages") {
this.fontManifests.set((0, _entrykey.getEntryKey)(type, "server", pageName), await readPartialManifest(this.distDir, `${_constants.NEXT_FONT_MANIFEST}.json`, pageName, type));
}
mergeFontManifests(manifests) {
const manifest = {
app: {},
appUsingSizeAdjust: false,
pages: {},
pagesUsingSizeAdjust: false
};
for (const m of manifests){
Object.assign(manifest.app, m.app);
Object.assign(manifest.pages, m.pages);
manifest.appUsingSizeAdjust = manifest.appUsingSizeAdjust || m.appUsingSizeAdjust;
manifest.pagesUsingSizeAdjust = manifest.pagesUsingSizeAdjust || m.pagesUsingSizeAdjust;
}
return manifest;
}
async writeNextFontManifest() {
const fontManifest = this.mergeFontManifests(this.fontManifests.values());
const json = JSON.stringify(fontManifest, null, 2);
const fontManifestJsonPath = (0, _path.join)(this.distDir, "server", `${_constants.NEXT_FONT_MANIFEST}.json`);
const fontManifestJsPath = (0, _path.join)(this.distDir, "server", `${_constants.NEXT_FONT_MANIFEST}.js`);
(0, _nextjsrequirecachehotreloader.deleteCache)(fontManifestJsonPath);
(0, _nextjsrequirecachehotreloader.deleteCache)(fontManifestJsPath);
await (0, _writeatomic.writeFileAtomic)(fontManifestJsonPath, json);
await (0, _writeatomic.writeFileAtomic)(fontManifestJsPath, `self.__NEXT_FONT_MANIFEST=${JSON.stringify(json)}`);
}
async loadLoadableManifest(pageName, type = "pages") {
this.loadableManifests.set((0, _entrykey.getEntryKey)(type, "server", pageName), await readPartialManifest(this.distDir, _constants.REACT_LOADABLE_MANIFEST, pageName, type));
}
mergeLoadableManifests(manifests) {
const manifest = {};
for (const m of manifests){
Object.assign(manifest, m);
}
return manifest;
}
async writeLoadableManifest() {
const loadableManifest = this.mergeLoadableManifests(this.loadableManifests.values());
const loadableManifestPath = (0, _path.join)(this.distDir, _constants.REACT_LOADABLE_MANIFEST);
const middlewareloadableManifestPath = (0, _path.join)(this.distDir, "server", `${_constants.MIDDLEWARE_REACT_LOADABLE_MANIFEST}.js`);
const json = JSON.stringify(loadableManifest, null, 2);
(0, _nextjsrequirecachehotreloader.deleteCache)(loadableManifestPath);
(0, _nextjsrequirecachehotreloader.deleteCache)(middlewareloadableManifestPath);
await (0, _writeatomic.writeFileAtomic)(loadableManifestPath, json);
await (0, _writeatomic.writeFileAtomic)(middlewareloadableManifestPath, `self.__REACT_LOADABLE_MANIFEST=${JSON.stringify(json)}`);
}
async loadMiddlewareManifest(pageName, type) {
this.middlewareManifests.set((0, _entrykey.getEntryKey)(type === "middleware" || type === "instrumentation" ? "root" : type, "server", pageName), await readPartialManifest(this.distDir, _constants.MIDDLEWARE_MANIFEST, pageName, type));
}
getMiddlewareManifest(key) {
return this.middlewareManifests.get(key);
}
deleteMiddlewareManifest(key) {
return this.middlewareManifests.delete(key);
}
mergeMiddlewareManifests(manifests) {
const manifest = {
version: 3,
middleware: {},
sortedMiddleware: [],
functions: {}
};
let instrumentation = undefined;
for (const m of manifests){
Object.assign(manifest.functions, m.functions);
Object.assign(manifest.middleware, m.middleware);
if (m.instrumentation) {
instrumentation = m.instrumentation;
}
}
const updateFunctionDefinition = (fun)=>{
return {
...fun,
files: [
...(instrumentation == null ? void 0 : instrumentation.files) ?? [],
...fun.files
]
};
};
for (const key of Object.keys(manifest.middleware)){
const value = manifest.middleware[key];
manifest.middleware[key] = updateFunctionDefinition(value);
}
for (const key of Object.keys(manifest.functions)){
const value = manifest.functions[key];
manifest.functions[key] = updateFunctionDefinition(value);
}
for (const fun of Object.values(manifest.functions).concat(Object.values(manifest.middleware))){
for (const matcher of fun.matchers){
if (!matcher.regexp) {
matcher.regexp = (0, _pathtoregexp.pathToRegexp)(matcher.originalSource, [], {
delimiter: "/",
sensitive: false,
strict: true
}).source.replaceAll("\\/", "/");
}
}
}
manifest.sortedMiddleware = Object.keys(manifest.middleware);
return manifest;
}
async writeMiddlewareManifest() {
const middlewareManifest = this.mergeMiddlewareManifests(this.middlewareManifests.values());
const middlewareManifestPath = (0, _path.join)(this.distDir, "server", _constants.MIDDLEWARE_MANIFEST);
(0, _nextjsrequirecachehotreloader.deleteCache)(middlewareManifestPath);
await (0, _writeatomic.writeFileAtomic)(middlewareManifestPath, JSON.stringify(middlewareManifest, null, 2));
}
async loadPagesManifest(pageName) {
this.pagesManifests.set((0, _entrykey.getEntryKey)("pages", "server", pageName), await readPartialManifest(this.distDir, _constants.PAGES_MANIFEST, pageName));
}
mergePagesManifests(manifests) {
const manifest = {};
for (const m of manifests){
Object.assign(manifest, m);
}
return manifest;
}
async writePagesManifest() {
const pagesManifest = this.mergePagesManifests(this.pagesManifests.values());
const pagesManifestPath = (0, _path.join)(this.distDir, "server", _constants.PAGES_MANIFEST);
(0, _nextjsrequirecachehotreloader.deleteCache)(pagesManifestPath);
await (0, _writeatomic.writeFileAtomic)(pagesManifestPath, JSON.stringify(pagesManifest, null, 2));
}
async writeManifests({ rewrites, pageEntrypoints }) {
await this.writeActionManifest();
await this.writeAppBuildManifest();
await this.writeAppPathsManifest();
await this.writeAutomaticFontOptimizationManifest();
await this.writeBuildManifest(pageEntrypoints, rewrites);
await this.writeFallbackBuildManifest();
await this.writeLoadableManifest();
await this.writeMiddlewareManifest();
await this.writeNextFontManifest();
await this.writePagesManifest();
}
}
//# sourceMappingURL=manifest-loader.js.map

File diff suppressed because one or more lines are too long

31
node_modules/next/dist/server/dev/turbopack/types.d.ts generated vendored Normal file
View File

@ -0,0 +1,31 @@
import type { Endpoint, Instrumentation, Middleware } from '../../../build/swc';
export interface GlobalEntrypoints {
app: Endpoint | undefined;
document: Endpoint | undefined;
error: Endpoint | undefined;
middleware: Middleware | undefined;
instrumentation: Instrumentation | undefined;
}
export type PageRoute = {
type: 'page';
htmlEndpoint: Endpoint;
dataEndpoint: Endpoint;
} | {
type: 'page-api';
endpoint: Endpoint;
};
export type AppRoute = {
type: 'app-page';
htmlEndpoint: Endpoint;
rscEndpoint: Endpoint;
} | {
type: 'app-route';
endpoint: Endpoint;
};
export type PageEntrypoints = Map<string, PageRoute>;
export type AppEntrypoints = Map<string, AppRoute>;
export type Entrypoints = {
global: GlobalEntrypoints;
page: PageEntrypoints;
app: AppEntrypoints;
};

6
node_modules/next/dist/server/dev/turbopack/types.js generated vendored Normal file
View File

@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=types.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":""}