.
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
import { join } from 'node:path';
|
||||
import { writeFile } from 'node:fs/promises';
|
||||
export async function createEnvDefinitions({ distDir, loadedEnvFiles }) {
|
||||
const envLines = [];
|
||||
const seenKeys = new Set();
|
||||
// env files are in order of priority
|
||||
for (const { path, env } of loadedEnvFiles){
|
||||
for(const key in env){
|
||||
if (!seenKeys.has(key)) {
|
||||
envLines.push(` /** Loaded from \`${path}\` */`);
|
||||
envLines.push(` ${key}?: string`);
|
||||
seenKeys.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
const envStr = envLines.join('\n');
|
||||
const definitionStr = `// Type definitions for Next.js environment variables
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
interface ProcessEnv {
|
||||
${envStr}
|
||||
}
|
||||
}
|
||||
}
|
||||
export {}`;
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
return definitionStr;
|
||||
}
|
||||
try {
|
||||
// we expect the types directory to already exist
|
||||
const envDtsPath = join(distDir, 'types', 'env.d.ts');
|
||||
await writeFile(envDtsPath, definitionStr, 'utf-8');
|
||||
} catch (e) {
|
||||
console.error('Failed to write env.d.ts:', e);
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=create-env-definitions.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/server/lib/experimental/create-env-definitions.ts"],"sourcesContent":["import type { LoadedEnvFiles } from '@next/env'\nimport { join } from 'node:path'\nimport { writeFile } from 'node:fs/promises'\n\nexport async function createEnvDefinitions({\n distDir,\n loadedEnvFiles,\n}: {\n distDir: string\n loadedEnvFiles: LoadedEnvFiles\n}) {\n const envLines = []\n const seenKeys = new Set()\n // env files are in order of priority\n for (const { path, env } of loadedEnvFiles) {\n for (const key in env) {\n if (!seenKeys.has(key)) {\n envLines.push(` /** Loaded from \\`${path}\\` */`)\n envLines.push(` ${key}?: string`)\n seenKeys.add(key)\n }\n }\n }\n const envStr = envLines.join('\\n')\n\n const definitionStr = `// Type definitions for Next.js environment variables\ndeclare global {\n namespace NodeJS {\n interface ProcessEnv {\n${envStr}\n }\n }\n}\nexport {}`\n\n if (process.env.NODE_ENV === 'test') {\n return definitionStr\n }\n\n try {\n // we expect the types directory to already exist\n const envDtsPath = join(distDir, 'types', 'env.d.ts')\n await writeFile(envDtsPath, definitionStr, 'utf-8')\n } catch (e) {\n console.error('Failed to write env.d.ts:', e)\n }\n}\n"],"names":["join","writeFile","createEnvDefinitions","distDir","loadedEnvFiles","envLines","seenKeys","Set","path","env","key","has","push","add","envStr","definitionStr","process","NODE_ENV","envDtsPath","e","console","error"],"mappings":"AACA,SAASA,IAAI,QAAQ,YAAW;AAChC,SAASC,SAAS,QAAQ,mBAAkB;AAE5C,OAAO,eAAeC,qBAAqB,EACzCC,OAAO,EACPC,cAAc,EAIf;IACC,MAAMC,WAAW,EAAE;IACnB,MAAMC,WAAW,IAAIC;IACrB,qCAAqC;IACrC,KAAK,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAE,IAAIL,eAAgB;QAC1C,IAAK,MAAMM,OAAOD,IAAK;YACrB,IAAI,CAACH,SAASK,GAAG,CAACD,MAAM;gBACtBL,SAASO,IAAI,CAAC,CAAC,wBAAwB,EAAEJ,KAAK,KAAK,CAAC;gBACpDH,SAASO,IAAI,CAAC,CAAC,MAAM,EAAEF,IAAI,SAAS,CAAC;gBACrCJ,SAASO,GAAG,CAACH;YACf;QACF;IACF;IACA,MAAMI,SAAST,SAASL,IAAI,CAAC;IAE7B,MAAMe,gBAAgB,CAAC;;;;AAIzB,EAAED,OAAO;;;;SAIA,CAAC;IAER,IAAIE,QAAQP,GAAG,CAACQ,QAAQ,KAAK,QAAQ;QACnC,OAAOF;IACT;IAEA,IAAI;QACF,iDAAiD;QACjD,MAAMG,aAAalB,KAAKG,SAAS,SAAS;QAC1C,MAAMF,UAAUiB,YAAYH,eAAe;IAC7C,EAAE,OAAOI,GAAG;QACVC,QAAQC,KAAK,CAAC,6BAA6BF;IAC7C;AACF","ignoreList":[0]}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* If set to `incremental`, only those leaf pages that export
|
||||
* `experimental_ppr = true` will have partial prerendering enabled. If any
|
||||
* page exports this value as `false` or does not export it at all will not
|
||||
* have partial prerendering enabled. If set to a boolean, the options for
|
||||
* `experimental_ppr` will be ignored.
|
||||
*/ /**
|
||||
* Returns true if partial prerendering is enabled for the application. It does
|
||||
* not tell you if a given route has PPR enabled, as that requires analysis of
|
||||
* the route's configuration.
|
||||
*
|
||||
* @see {@link checkIsRoutePPREnabled} - for checking if a specific route has PPR enabled.
|
||||
*/ export function checkIsAppPPREnabled(config) {
|
||||
// If the config is undefined, partial prerendering is disabled.
|
||||
if (typeof config === 'undefined') return false;
|
||||
// If the config is a boolean, use it directly.
|
||||
if (typeof config === 'boolean') return config;
|
||||
// If the config is a string, it must be 'incremental' to enable partial
|
||||
// prerendering.
|
||||
if (config === 'incremental') return true;
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Returns true if partial prerendering is supported for the current page with
|
||||
* the provided app configuration. If the application doesn't have partial
|
||||
* prerendering enabled, this function will always return false. If you want to
|
||||
* check if the application has partial prerendering enabled
|
||||
*
|
||||
* @see {@link checkIsAppPPREnabled} for checking if the application has PPR enabled.
|
||||
*/ export function checkIsRoutePPREnabled(config) {
|
||||
// If the config is undefined, partial prerendering is disabled.
|
||||
if (typeof config === 'undefined') return false;
|
||||
// If the config is a boolean, use it directly.
|
||||
if (typeof config === 'boolean') return config;
|
||||
return false;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=ppr.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../../../src/server/lib/experimental/ppr.ts"],"sourcesContent":["/**\n * If set to `incremental`, only those leaf pages that export\n * `experimental_ppr = true` will have partial prerendering enabled. If any\n * page exports this value as `false` or does not export it at all will not\n * have partial prerendering enabled. If set to a boolean, the options for\n * `experimental_ppr` will be ignored.\n */\n\nexport type ExperimentalPPRConfig = boolean | 'incremental'\n\n/**\n * Returns true if partial prerendering is enabled for the application. It does\n * not tell you if a given route has PPR enabled, as that requires analysis of\n * the route's configuration.\n *\n * @see {@link checkIsRoutePPREnabled} - for checking if a specific route has PPR enabled.\n */\nexport function checkIsAppPPREnabled(\n config: ExperimentalPPRConfig | undefined\n): boolean {\n // If the config is undefined, partial prerendering is disabled.\n if (typeof config === 'undefined') return false\n\n // If the config is a boolean, use it directly.\n if (typeof config === 'boolean') return config\n\n // If the config is a string, it must be 'incremental' to enable partial\n // prerendering.\n if (config === 'incremental') return true\n\n return false\n}\n\n/**\n * Returns true if partial prerendering is supported for the current page with\n * the provided app configuration. If the application doesn't have partial\n * prerendering enabled, this function will always return false. If you want to\n * check if the application has partial prerendering enabled\n *\n * @see {@link checkIsAppPPREnabled} for checking if the application has PPR enabled.\n */\nexport function checkIsRoutePPREnabled(\n config: ExperimentalPPRConfig | undefined\n): boolean {\n // If the config is undefined, partial prerendering is disabled.\n if (typeof config === 'undefined') return false\n\n // If the config is a boolean, use it directly.\n if (typeof config === 'boolean') return config\n\n return false\n}\n"],"names":["checkIsAppPPREnabled","config","checkIsRoutePPREnabled"],"mappings":"AAAA;;;;;;CAMC,GAID;;;;;;CAMC,GACD,OAAO,SAASA,qBACdC,MAAyC;IAEzC,gEAAgE;IAChE,IAAI,OAAOA,WAAW,aAAa,OAAO;IAE1C,+CAA+C;IAC/C,IAAI,OAAOA,WAAW,WAAW,OAAOA;IAExC,wEAAwE;IACxE,gBAAgB;IAChB,IAAIA,WAAW,eAAe,OAAO;IAErC,OAAO;AACT;AAEA;;;;;;;CAOC,GACD,OAAO,SAASC,uBACdD,MAAyC;IAEzC,gEAAgE;IAChE,IAAI,OAAOA,WAAW,aAAa,OAAO;IAE1C,+CAA+C;IAC/C,IAAI,OAAOA,WAAW,WAAW,OAAOA;IAExC,OAAO;AACT","ignoreList":[0]}
|
||||
Reference in New Issue
Block a user