/** * ESBuild plugin resolving packages from the installed `node_modules`, preferring the traced copies. * * The outputs of the server functions (`.open-next/server-functions/default`) and of the Node.js * middleware (`.open-next/middleware`) only contain the files traced by Next.js, with the Node.js * conditions. They are bundled with the `workerd` condition, so the files only reachable through it * (the `workerd` build of a package, its dependencies, the files of a partially traced dependency * it uses) are not in the output. * * The output is used as an overlay on top of the app: * - Bare specifiers (`pkg`, `pkg/sub`, `#imports`) of packages declaring a `workerd` condition are * resolved from the installed tree, from the location of the importer in the app, with a map keeping * only that condition, so that it wins over `node` (added by the `node` platform). * Other packages imported from the output are resolved by esbuild, as Next.js traced them with the * conditions esbuild uses. * - Imports from a file of the installed tree are resolved from the installed tree. * - The resolved file is replaced with its copy in the output when it exists, so that a module is * bundled only once and that the code patches applied to the traced files are kept. * * Nothing has to be copied: a file missing from the output is read from the installed tree. */ import { type BuildOptions } from "@opennextjs/aws/build/helper.js"; import type { PluginBuild } from "esbuild"; /** * Creates the plugin resolving packages from the installed `node_modules`. * * @param buildOpts Build options, uses `outputDir`, `appBuildOutputPath` and `monorepoRoot` * @param outputRoot The output the traced files are copied to, i.e. `.open-next/server-functions/default` * @returns The esbuild plugin */ export declare function resolvePackages(buildOpts: BuildOptions, outputRoot: string): { name: string; setup: (build: PluginBuild) => void; }; /** * Keeps only a condition of an `exports` or `imports` map. * * In a conditions object with the condition, the other keys are dropped, except the subtrees that * contain the condition. Arrays of alternative targets are kept, their objects are transformed. * The subtrees without the condition are not copied, they are shared with `map`. * * @param map The `exports` or `imports` of a `package.json` * @param condition The condition to keep, i.e. `workerd` * @returns The transformed map, `undefined` when the map does not have the condition */ export declare function keepCondition(map: unknown, condition: string): { [key: string]: unknown; } | undefined; /** * Returns the package name of a bare specifier. * * @param specifier `pkg`, `pkg/sub/path`, `@scope/pkg` or `@scope/pkg/sub/path` * @returns `pkg` or `@scope/pkg` */ export declare function packageName(specifier: string): string; /** * Whether a target of an `exports` or `imports` map is a file of the package. * * As Node.js requires, the target starts with `./` and has no empty, `.`, `..` or `node_modules` segment. * `resolve.exports` does not validate the targets. * * @param target The target returned by `resolve.exports` * @returns Whether the target is valid */ export declare function isPackageTarget(target: string): boolean;