Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
a732739
fix: fail build/deploy when using unsupported Node.js Midleware
pieh Jul 28, 2025
fc55e71
[wip] feat: support node middleware
pieh Jul 30, 2025
2e1f698
shim otel, so things work when deploying from outside of this repo
pieh Jul 30, 2025
661496b
test: deploy no longer fail, so ignore this test
pieh Jul 30, 2025
3c2789b
test: try running existing tests against node middleware
pieh Jul 30, 2025
2203640
test: skip force chunking in middleware fixture
pieh Jul 30, 2025
182b683
Merge branch 'main' into feat/node-middleware-support
pieh Jul 31, 2025
b5a3269
fix: nft reading to work in integration tests
pieh Jul 31, 2025
2031077
test: make sure to use appropiate edge handler name
pieh Jul 31, 2025
de3a81a
use virtual CJS modules
pieh Aug 5, 2025
a6f1ac3
chore: remove dev/debug logs
pieh Aug 18, 2025
e0b5143
Merge remote-tracking branch 'origin/main' into feat/node-middleware-…
pieh Aug 18, 2025
487b0db
test: initial build variants setup
pieh Aug 20, 2025
91bb19d
Merge remote-tracking branch 'origin/main' into feat/node-middleware-…
pieh Aug 20, 2025
9ea923b
fix: shim global process
pieh Aug 20, 2025
dd6a383
fix: add additional context on CJS module compilation failures to poi…
pieh Aug 20, 2025
c5773b5
Merge remote-tracking branch 'origin/main' into feat/node-middleware-…
pieh Aug 20, 2025
e74af04
ci: move back to using latest now that node middleware landed as stable
pieh Aug 20, 2025
5a1dea1
chore: enable node middleware tests in stable
pieh Aug 20, 2025
4a17111
test: specify distDir in variants config
pieh Aug 20, 2025
31f83f5
test: comment out test checking expected deploy failure with node mid…
pieh Aug 20, 2025
1a0ab5c
test: move middleware-src to test variants
pieh Aug 20, 2025
abd729f
test: update hasNodeMiddlewareSupport check
pieh Aug 20, 2025
c1efaf1
tmp: run latest and canary for now
pieh Aug 20, 2025
3e7238c
test: remove .only
pieh Aug 21, 2025
99df488
test: move middleware-conditions to test variants
pieh Aug 21, 2025
5c0c948
test: move middleware-trailing-slash to test variants
pieh Aug 21, 2025
65209f6
test: adjust rest of middleware e2e
pieh Aug 21, 2025
8b5579f
test: move middleware-pages to test variants
pieh Aug 21, 2025
aec3a71
chore: don't throw immediately on failed build and instead allow for …
pieh Aug 21, 2025
45dacbb
Merge remote-tracking branch 'origin/main' into feat/node-middleware-…
pieh Aug 21, 2025
b04d1ca
test: move middleware-i18n to test variants
pieh Aug 21, 2025
55d1722
chore: remove debug log
pieh Aug 21, 2025
38a2f3b
test: move middleware-i18n-skip-normalize to test variants
pieh Aug 21, 2025
7492aac
test: add x-runtime res header to middleware-conditions
pieh Aug 21, 2025
6069a74
test: skip runtime check on some tests
pieh Aug 21, 2025
3d996dd
test: move middleware-i18n-exluded-path to test variants
pieh Aug 21, 2025
e974d7f
test: skip prebuilding some fixtures that are not used in integration…
pieh Aug 21, 2025
61d261e
test: subrequest vuln test is not applicable to node middleware
pieh Aug 21, 2025
8669b58
test: move middleware-i18n-static-asset-matcher to test variants
pieh Aug 21, 2025
db4f02d
refactor: adjust node middleware handling to share common handling wi…
pieh Aug 21, 2025
1276559
test: make sure to return middleware response in middleware-i18n
pieh Aug 21, 2025
2a5bdff
fix: duplicate type import
pieh Aug 21, 2025
9c302c0
chore: remove debug logs
pieh Aug 21, 2025
bfacdf8
Merge remote-tracking branch 'origin/main' into feat/node-middleware-…
pieh Aug 21, 2025
2782f43
test fixes
pieh Aug 21, 2025
bc6dc50
fix: don't pass unused manifest
pieh Aug 22, 2025
9a52755
fix: static html blobs if distDir is different than default .next
pieh Aug 22, 2025
cbf47e5
test: don't assert middleware runtime on tests that assert that middl…
pieh Aug 22, 2025
f5d32d4
test: fix expected redirect status
pieh Aug 22, 2025
37bb7da
test: convert middleware-conditions fixture to page router, as app ro…
pieh Aug 22, 2025
0eae894
test: adjust for /_global-error
pieh Aug 22, 2025
959afb4
test: add node.js runtime specific middleware tests checking availabi…
pieh Aug 22, 2025
ece6b5d
test: rename edge-handler to middleware now that node middleware is t…
pieh Aug 22, 2025
b217456
test: add fixture hitting limitation
pieh Aug 22, 2025
9cabcc2
fix: support package.json#main in CJS simulation
pieh Aug 22, 2025
57e8166
test: add test for intentional deploy failure when C++ addons / .node…
pieh Aug 22, 2025
dd9d0ee
test: add virtual cjs test
pieh Aug 25, 2025
9764e3e
Merge remote-tracking branch 'origin/main' into feat/node-middleware-…
pieh Aug 25, 2025
c541414
fix: support exports maps
pieh Aug 25, 2025
1bac8dd
fix: drop debug log
pieh Aug 25, 2025
0e6406c
test: relax assertion on bcrypt.node to work crossplatform, while sti…
pieh Aug 25, 2025
e55448f
Merge remote-tracking branch 'origin/main' into feat/node-middleware-…
pieh Aug 25, 2025
ecb849a
test: restore chunk splitting in middleware for Edge Runtime case
pieh Aug 25, 2025
74f96a6
test: add missing ts-expect-error for x-runtime
pieh Aug 25, 2025
cbb6a1d
test: expand CJS tests with some edge cases
pieh Aug 26, 2025
645a2da
revert ci changes
pieh Aug 26, 2025
2034df6
fix: use posix pathing when constructing edge functions
pieh Aug 26, 2025
560bf4c
fix: force posix pathing when simulating cjs
pieh Aug 26, 2025
56113a0
fix: drop unused function
pieh Aug 26, 2025
231b8c3
Merge branch 'main' into feat/node-middleware-support
pieh Aug 26, 2025
a168f68
Merge branch 'main' into feat/node-middleware-support
pieh Aug 27, 2025
16301c0
Merge branch 'main' into feat/node-middleware-support
pieh Aug 27, 2025
798217a
Merge branch 'main' into feat/node-middleware-support
pieh Aug 27, 2025
d64e3fb
Merge branch 'main' into feat/node-middleware-support
pieh Aug 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules/
dist/
.next
.next-node-middleware
edge-runtime/vendor
# deno.json is ephemeral and generated for the purpose of vendoring remote modules in CI
tools/deno/deno.json
Expand Down
106 changes: 106 additions & 0 deletions edge-runtime/lib/cjs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { createRequire } from 'node:module'
import { join, dirname, relative } from 'node:path'
import { fileURLToPath } from 'node:url'

import { assertEquals } from 'https://deno.land/[email protected]/testing/asserts.ts'

import { registerCJSModules } from './cjs.ts'

type RequireResult = Record<string, string>

const localRequire = createRequire(import.meta.url)
const realRequireResult = localRequire('./fixture/cjs/entry.js') as RequireResult

const fixtureRoot = new URL('./fixture/cjs/', import.meta.url)
const virtualRoot = new URL('file:///virtual-root/index.mjs')

const fixtureRootPath = fileURLToPath(fixtureRoot)
const virtualRootPath = dirname(fileURLToPath(virtualRoot))

// load fixture into virtual CJS
const virtualModules = new Map<string, string>()
const decoder = new TextDecoder('utf-8')
async function addVirtualModulesFromDir(dir: string) {
const dirUrl = new URL('./' + dir, fixtureRoot)

for await (const dirEntry of Deno.readDir(dirUrl)) {
const relPath = join(dir, dirEntry.name)
if (dirEntry.isDirectory) {
await addVirtualModulesFromDir(relPath + '/')
} else if (dirEntry.isFile) {
const fileURL = new URL('./' + dirEntry.name, dirUrl)
virtualModules.set(relPath, decoder.decode(await Deno.readFile(fileURL)))
}
}
}

await addVirtualModulesFromDir('')
registerCJSModules(virtualRoot, virtualModules)

const virtualRequire = createRequire(virtualRoot)
const virtualRequireResult = virtualRequire('./entry.js') as RequireResult

const expectedVirtualRequireResult = {
entry: '/virtual-root/entry.js',

packageExportsConditionsExportedModule:
'/virtual-root/node_modules/package-exports-conditions/dist/exported-module.js',
packageExportsConditionsRoot:
'/virtual-root/node_modules/package-exports-conditions/root-export.js',
packageExportsConditionsWildcardModuleNoExt:
'/virtual-root/node_modules/package-exports-conditions/dist/wildcard/module.js',
packageExportsConditionsWildcardModuleWithExt:
'/virtual-root/node_modules/package-exports-conditions/dist/wildcard/module.js',
packageExportsExportedModule:
'/virtual-root/node_modules/package-exports/dist/exported-module.js',
packageExportsMainRoot: '/virtual-root/node_modules/package-exports-main/root-export.js',
packageExportsNotAllowedBecauseNotInExportMap: 'ERROR',
packageExportsRoot: '/virtual-root/node_modules/package-exports/root-export.js',
packageExportsSugarRoot: '/virtual-root/node_modules/package-exports-sugar/root-export.js',
packageExportsWildcardModuleNoExt:
'/virtual-root/node_modules/package-exports/dist/wildcard/module.js',
packageExportsWildcardModuleWithExt:
'/virtual-root/node_modules/package-exports/dist/wildcard/module.js',
packageRoot: '/virtual-root/node_modules/package/index.js',
packageInternalModule: '/virtual-root/node_modules/package/internal-module.js',
packageMainRoot: '/virtual-root/node_modules/package-main/main.js',
packageMainInternalModule: '/virtual-root/node_modules/package-main/internal-module.js',
} as RequireResult

Deno.test('Virtual CJS Module loader matches real CJS Module loader', async (t) => {
// make sure we collect all the possible keys to spot any cases of potentially missing keys in one of the objects
const allTheKeys = [
...new Set([
...Object.keys(expectedVirtualRequireResult),
...Object.keys(realRequireResult),
...Object.keys(virtualRequireResult),
]),
]

function normalizeValue(value: string, basePath: string) {
if (value === 'ERROR') {
return value
}

return relative(basePath, value)
}

for (const key of allTheKeys) {
const virtualValue = virtualRequireResult[key]
const realValue = realRequireResult[key]

// values are filepaths or "ERROR" strings, "real" require has actual file system paths, virtual ones has virtual paths starting with file:///virtual-root/
// we compare remaining paths to ensure same relative paths are reported indicating that resolution works the same in
// in real CommonJS and simulated one
assertEquals(
normalizeValue(realValue, fixtureRootPath),
normalizeValue(virtualValue, virtualRootPath),
)
}
})

Deno.test('Virtual CJS Module loader matches expected results', async (t) => {
// the main portion of testing functionality is in above assertions that compare real require and virtual one
// below is additional explicit assertion mostly to make sure that test setup is correct
assertEquals(virtualRequireResult, expectedVirtualRequireResult)
})
Loading
Loading