Skip to content

Make a default overridable adapter in core - #35

Open
conico974 wants to merge 15 commits into
mainfrom
conico/share-build
Open

Make a default overridable adapter in core#35
conico974 wants to merge 15 commits into
mainfrom
conico/share-build

Conversation

@conico974

@conico974 conico974 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

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.


Open in Devin Review

@pkg-pr-new

pkg-pr-new Bot commented Jun 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/opennextjs/adapters-api/@opennextjs/aws@cd8f83e
npm i https://pkg.pr.new/opennextjs/adapters-api/@opennextjs/cloudflare@cd8f83e
npm i https://pkg.pr.new/opennextjs/adapters-api/@opennextjs/core@cd8f83e

commit: cd8f83e

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 3 potential issues.

Open in Devin Review

Comment thread packages/cloudflare/src/cli/adapter.ts
Comment thread packages/core/src/build/adapter.ts
Comment thread packages/cloudflare/src/api/config.ts Outdated
Comment thread packages/cloudflare/src/cli/adapter.ts Outdated
Comment thread packages/core/src/build/adapter.ts
Comment thread packages/core/src/build/adapter.ts Outdated
Comment thread packages/core/src/build/adapter.ts Outdated
Comment thread packages/core/src/build/createServerBundle.ts Outdated
Comment thread packages/core/src/plugins/resolve.ts
@conico974
conico974 deleted the branch main August 1, 2026 09:06
@conico974 conico974 closed this Aug 1, 2026
@conico974 conico974 reopened this Aug 1, 2026
@conico974
conico974 changed the base branch from conico/core-rewrite to main August 1, 2026 09:14
@conico974
conico974 force-pushed the conico/share-build branch from d1b99ee to f2de8e2 Compare August 1, 2026 09:23
Copilot AI review requested due to automatic review settings August 1, 2026 10:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 buildAdapter orchestrator 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 useTagCacheshouldUseTagCache 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 when wrapper is not an IncludedWrapper key (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.

Comment thread packages/cloudflare/src/cli/adapter.ts
Comment thread packages/core/src/build/validateConfig.ts
@evanlong-me

Copy link
Copy Markdown

Heads-up from the Node/proxy.ts side: #38 (Cloudflare node middleware / Next 16 proxy.ts) is stacked on this branch and currently dirty against it.

I independently verified #38 build+runtime works for the e2e proxy.ts app once built from source. Landing this PR (or rebasing the stack) is the critical path for unblocking Next 16 proxy.ts on Cloudflare — released @opennextjs/cloudflare still hard-errors with Node.js middleware is not currently supported.

…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
…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.
@conico974
conico974 force-pushed the conico/share-build branch from 4e9a367 to cd8f83e Compare August 2, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants