Make a default overridable adapter in core - #35
Conversation
commit: |
d1b99ee to
f2de8e2
Compare
There was a problem hiding this comment.
Pull request overview
This PR centralizes platform adapter build orchestration in @opennextjs/core via a new buildAdapter API, and extends core override resolution to support adapter-provided default overrides (including full-path specifiers) that can be overridden by user config. It also adds vitest-based unit tests around the new behavior and refactors Cloudflare/AWS adapters to consume the shared core pipeline.
Changes:
- Add a core
buildAdapterorchestrator and migrate Cloudflare/AWS adapters to use it instead of duplicating build logic. - Upgrade the resolve plugin to support per-bundle default overrides + full-path override specifiers (plus tests).
- Refactor config validation and output generation for better testability (new return types, extracted
buildOpenNextOutput, added tests).
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds lockfile entries for new tooling used in core (rimraf, vitest). |
| packages/core/tsconfig.json | Excludes spec files/dist from tsc build to support added unit tests. |
| packages/core/src/plugins/resolve.ts | Adds support for default overrides and full-path override specifiers when rewriting core/resolve.js imports. |
| packages/core/src/plugins/resolve.spec.ts | New esbuild+vitest tests validating override rewriting behavior (default + user overrides). |
| packages/core/src/core/resolve.ts | Formatting-only change for dynamic import typing blocks. |
| packages/core/src/build/validateConfig.ts | Refactors validation to return structured results instead of logging/throwing directly. |
| packages/core/src/build/validateConfig.spec.ts | New tests for validateConfig structured results. |
| packages/core/src/build/middleware/buildNodeMiddleware.ts | Threads defaultOverrides into resolve plugin usage for external node middleware. |
| packages/core/src/build/generateOutput.ts | Extracts buildOpenNextOutput and keeps generateOutput as a legacy wrapper that writes JSON. |
| packages/core/src/build/generateOutput.spec.ts | New tests ensuring buildOpenNextOutput doesn’t write files and legacy wrapper does. |
| packages/core/src/build/edge/createEdgeBundle.ts | Threads defaultOverrides through edge bundle builds and defaults converter to a string specifier. |
| packages/core/src/build/createWarmerBundle.ts | Threads defaultOverrides into warmer bundle resolve behavior. |
| packages/core/src/build/createServerBundle.ts | Makes server bundle customization explicit (mandatory externals, banner, bundle defaults) and threads defaults into resolve. |
| packages/core/src/build/createRevalidationBundle.ts | Threads defaultOverrides into revalidation bundle resolve behavior. |
| packages/core/src/build/createMiddleware.ts | Adds defaultOverrides plumbing into middleware build paths. |
| packages/core/src/build/createImageOptimizationBundle.ts | Threads defaultOverrides into image optimization resolve behavior. |
| packages/core/src/build/createAssets.ts | Renames useTagCache → shouldUseTagCache in cache asset creation return value. |
| packages/core/src/build/compileTagCacheProvider.ts | Threads defaultOverrides into initialization/tag-cache-provider compilation bundle. |
| packages/core/src/build/compileConfig.ts | Updates compile pipeline to act on structured validation results (throw vs log). |
| packages/core/src/build/adapter.ts | New core buildAdapter implementation (shared adapter pipeline + default overrides + hooks). |
| packages/core/src/build/adapter.spec.ts | New tests for the buildAdapter orchestration behavior. |
| packages/core/src/adapters/cache.ts | Tightens a generic call-site type argument for hasBeenRevalidated. |
| packages/core/package.json | Adds rimraf/vitest and introduces clean/build/test scripts for core. |
| packages/cloudflare/src/cli/build/open-next/createServerBundle.ts | Removes Cloudflare’s duplicate server bundling implementation in favor of core. |
| packages/cloudflare/src/cli/adapter.ts | Migrates Cloudflare adapter to core buildAdapter and moves platform-specific work into hooks/plugins. |
| packages/aws/src/build.ts | Removes now-redundant direct build pipeline imports (core pipeline is centralized). |
| packages/aws/src/adapter.ts | Migrates AWS adapter to core buildAdapter and defines per-bundle default overrides. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Suppressed comments (1)
packages/core/src/build/validateConfig.ts:64
compatibilityMatrix[wrapper].includes(...)will throw whenwrapperis not anIncludedWrapperkey (e.g. a typo, or any unrecognized string). This turns a config error into a runtime crash. Guard the lookup and return a structured validation error instead of throwing a TypeError.
const isCustomWrapper = typeof fnOptions.override?.wrapper === "function";
const isCustomConverter = typeof fnOptions.override?.converter === "function";
// Check if the wrapper and converter are compatible
// Only check if using one of the included converters or wrapper
if (!compatibilityMatrix[wrapper].includes(converter) && !isCustomWrapper && !isCustomConverter) {
return {
success: false,
shouldThrow: false,
level: "error",
message: `Wrapper ${wrapper} and converter ${converter} are not compatible. For the wrapper ${wrapper} you should only use the following converters: ${compatibilityMatrix[
wrapper
].join(", ")}`,
};
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Heads-up from the Node/ I independently verified #38 build+runtime works for the e2e |
…y into core adapter feat: enhance build process with additional server bundle customization options chore: update package.json scripts for improved build and testing workflow test: add unit tests for adapter build process and server bundle generation fix: ensure proper handling of external dependencies and edge configuration in server bundle
…ests for resolve plugin
…specific overrides
…udflare specific overrides" This reverts commit 37c4d90.
…ad of throwing - Extract ValidateConfigResult type with success/message/shouldThrow/level - Convert validateFunctionOptions and validateSplittedFunctionOptions to return result objects - Remove logger dependency from validateConfig.ts - Preserve compatibilityMatrix, TODO comment, @ts-expect-error pragmas - Add 5 characterization tests in validateConfig.spec.ts - No caller impact: compileConfig.ts is the sole importer (updated in T3)
- Export OpenNextOutput interface (was internal) - Extract buildOpenNextOutput(buildOpts) for construction-only (no fs write) - Keep legacy generateOutput as thin wrapper (construction + file write) - Preserve all construction logic verbatim, including @ts-expect-error - Add 3 characterization tests in generateOutput.spec.ts - Backward compatible: byte-equivalent output to today
- Replace bare validateConfig(config) call with result-handling block - Throw on shouldThrow:true (bad routes — preserves existing behavior) - Log at appropriate level on shouldThrow:false (level field from T1) - All 3 export signatures and edge-runtime detection block unchanged - Direct callers (aws/build.ts, cloudflare/utils.ts) unaffected
…OpenNextAdapterOptions - Make OpenNextAdapterOptions<T = OpenNextOutput> and buildAdapter<T> generic - Add validateConfig override hook (runs after callback in modifyConfig) - Add generateOutput override hook (returns T, gated by skipGenerateOutput) - buildAdapter serializes override return via fs.writeFileSync (override never touches fs) - Default path uses buildOpenNextOutput (extracted in T2) - Add 5 new tests covering override behaviors + default path + skipGenerateOutput - All 16 existing adapter tests preserved; AWS/Cloudflare adapters compile with default T
When an adapter config specifies full package-specifier paths (e.g., @opennextjs/aws/overrides/wrappers/aws-lambda.js), esbuild cannot resolve them during bundling. Use createRequire(args.path).resolve() in the openNextResolvePlugin to convert package specifiers to filesystem-relative paths at build time, falling back to the original value if resolution fails. This fixes the openbuild:local build error: ERROR: Could not resolve "@opennextjs/aws/overrides/wrappers/aws-lambda.js" ERROR: Could not resolve "@opennextjs/aws/overrides/tagCache/dynamodb.js" Added test I verifying resolution of a mock package in node_modules.
…solution and improve path handling
4e9a367 to
cd8f83e
Compare
Make a default overridable adapter in core.
Remove unused files and dependencies related to AWS, improve build processes, and update TypeScript and Node versions.
Enhance the AWS adapter with default overrides and integrate Cloudflare-specific configurations.
Clean up the codebase by removing outdated examples and unnecessary utilities. Fix various build and CI issues.