Duffer Derek
{"version":3,"sources":["../../src/build/load-entrypoint.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\n\n// NOTE: this should be updated if this loader file is moved.\nconst PACKAGE_ROOT = path.normalize(path.join(__dirname, '../../..'))\nconst TEMPLATE_FOLDER = path.join(__dirname, 'templates')\nconst TEMPLATES_ESM_FOLDER = path.normalize(\n path.join(__dirname, '../../dist/esm/build/templates')\n)\n\n/**\n * Load the entrypoint file from the ESM directory and performs string\n * replacements of the template variables specified in the `replacements`\n * argument.\n *\n * For non-string replacements, the template should use the\n * `declare const ${key}: ${type}` syntax. to ensure that the type is correct\n * and the typescript can compile. You may have to use `@ts-expect-error` to\n * handle replacement values that are related to imports.\n *\n * @param entrypoint the entrypoint to load\n * @param replacements string replacements to perform\n * @param injections code injections to perform\n * @param imports optional imports to insert or set to null\n * @returns the loaded file with the replacements\n */\nexport async function loadEntrypoint(\n entrypoint:\n | 'app-page'\n | 'app-route'\n | 'edge-app-route'\n | 'edge-ssr'\n | 'edge-ssr-app'\n | 'middleware'\n | 'pages'\n | 'pages-api',\n replacements: Record<`VAR_${string}`, string>,\n injections?: Record<string, string>,\n imports?: Record<string, string | null>\n): Promise<string> {\n const filepath = path.resolve(\n path.join(TEMPLATES_ESM_FOLDER, `${entrypoint}.js`)\n )\n\n let file = await fs.readFile(filepath, 'utf8')\n\n // Update the relative imports to be absolute. This will update any relative\n // imports to be relative to the root of the `next` package.\n let count = 0\n file = file.replaceAll(\n /from '(\\..*)'|import '(\\..*)'/g,\n function (_, fromRequest, importRequest) {\n count++\n\n const relative = path\n .relative(\n PACKAGE_ROOT,\n path.resolve(TEMPLATE_FOLDER, fromRequest ?? importRequest)\n )\n // Ensure that we use linux style path separators for node.\n .replace(/\\\\/g, '/')\n\n // Verify that the relative import is relative to the `next` package. This\n // will catch cases where the constants at the top of the file were not\n // updated after the file was moved.\n if (!relative.startsWith('next/')) {\n throw new Error(\n `Invariant: Expected relative import to start with \"next/\", found \"${relative}\"`\n )\n }\n\n return fromRequest\n ? `from ${JSON.stringify(relative)}`\n : `import ${JSON.stringify(relative)}`\n }\n )\n\n // Verify that at least one import was replaced. It's the case today where\n // every template file has at least one import to update, so this ensures that\n // we don't accidentally remove the import replacement code or use the wrong\n // template file.\n if (count === 0) {\n throw new Error('Invariant: Expected to replace at least one import')\n }\n\n const replaced = new Set<string>()\n\n // Replace all the template variables with the actual values. If a template\n // variable is missing, throw an error.\n file = file.replaceAll(\n new RegExp(\n `${Object.keys(replacements)\n .map((k) => `'${k}'`)\n .join('|')}`,\n 'g'\n ),\n (match) => {\n const key = JSON.parse(match.replace(/'/g, `\"`))\n\n if (!(key in replacements)) {\n throw new Error(`Invariant: Unexpected template variable ${key}`)\n }\n\n replaced.add(key)\n\n return JSON.stringify(replacements[key])\n }\n )\n\n // Check to see if there's any remaining template variables.\n let matches = file.match(/VAR_[A-Z_]+/g)\n if (matches) {\n throw new Error(\n `Invariant: Expected to replace all template variables, found ${matches.join(\n ', '\n )}`\n )\n }\n\n // Check to see if any template variable was provided but not used.\n if (replaced.size !== Object.keys(replacements).length) {\n // Find the difference between the provided replacements and the replaced\n // template variables. This will let us notify the user of any template\n // variables that were not used but were provided.\n const difference = Object.keys(replacements).filter(\n (key) => !replaced.has(key)\n )\n\n throw new Error(\n `Invariant: Expected to replace all template variables, missing ${difference.join(\n ', '\n )} in template`\n )\n }\n\n // Replace the injections.\n const injected = new Set<string>()\n if (injections) {\n // Track all the injections to ensure that we're not missing any.\n file = file.replaceAll(\n new RegExp(`// INJECT:(${Object.keys(injections).join('|')})`, 'g'),\n (_, key) => {\n if (!(key in injections)) {\n throw new Error(`Invariant: Unexpected injection ${key}`)\n }\n\n injected.add(key)\n\n return `const ${key} = ${injections[key]}`\n }\n )\n }\n\n // Check to see if there's any remaining injections.\n matches = file.match(/\\/\\/ INJECT:[A-Za-z0-9_]+/g)\n if (matches) {\n throw new Error(\n `Invariant: Expected to inject all injections, found ${matches.join(\n ', '\n )}`\n )\n }\n\n // Check to see if any injection was provided but not used.\n if (injected.size !== Object.keys(injections ?? {}).length) {\n // Find the difference between the provided injections and the injected\n // injections. This will let us notify the user of any injections that were\n // not used but were provided.\n const difference = Object.keys(injections ?? {}).filter(\n (key) => !injected.has(key)\n )\n\n throw new Error(\n `Invariant: Expected to inject all injections, missing ${difference.join(\n ', '\n )} in template`\n )\n }\n\n // Replace the optional imports.\n const importsAdded = new Set<string>()\n if (imports) {\n // Track all the imports to ensure that we're not missing any.\n file = file.replaceAll(\n new RegExp(\n `// OPTIONAL_IMPORT:(\\\\* as )?(${Object.keys(imports).join('|')})`,\n 'g'\n ),\n (_, asNamespace = '', key) => {\n if (!(key in imports)) {\n throw new Error(`Invariant: Unexpected optional import ${key}`)\n }\n\n importsAdded.add(key)\n\n if (imports[key]) {\n return `import ${asNamespace}${key} from ${JSON.stringify(\n imports[key]\n )}`\n } else {\n return `const ${key} = null`\n }\n }\n )\n }\n\n // Check to see if there's any remaining imports.\n matches = file.match(/\\/\\/ OPTIONAL_IMPORT:(\\* as )?[A-Za-z0-9_]+/g)\n if (matches) {\n throw new Error(\n `Invariant: Expected to inject all imports, found ${matches.join(', ')}`\n )\n }\n\n // Check to see if any import was provided but not used.\n if (importsAdded.size !== Object.keys(imports ?? {}).length) {\n // Find the difference between the provided imports and the injected\n // imports. This will let us notify the user of any imports that were\n // not used but were provided.\n const difference = Object.keys(imports ?? {}).filter(\n (key) => !importsAdded.has(key)\n )\n\n throw new Error(\n `Invariant: Expected to inject all imports, missing ${difference.join(\n ', '\n )} in template`\n )\n }\n\n return file\n}\n"],"names":["loadEntrypoint","PACKAGE_ROOT","path","normalize","join","__dirname","TEMPLATE_FOLDER","TEMPLATES_ESM_FOLDER","entrypoint","replacements","injections","imports","filepath","resolve","file","fs","readFile","count","replaceAll","_","fromRequest","importRequest","relative","replace","startsWith","Error","JSON","stringify","replaced","Set","RegExp","Object","keys","map","k","match","key","parse","add","matches","size","length","difference","filter","has","injected","importsAdded","asNamespace"],"mappings":";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