-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: apply type: module only to runtime modules (#2549)
* test: add integration and e2e test for requiring CJS .js module in serverless runtime * fix: apply type: module only to runtime modules
- Loading branch information
Showing
8 changed files
with
71 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
tests/fixtures/simple/app/api/cjs-file-with-js-extension/bundled.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { parse: pathParse } = require('node:path') | ||
|
||
const fileBase = pathParse(__filename).base | ||
|
||
module.exports = { | ||
fileBase, | ||
// if fileBase is not the same as this module name, it was bundled | ||
isBundled: fileBase !== 'bundled.cjs', | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/fixtures/simple/app/api/cjs-file-with-js-extension/route.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { NextResponse } from 'next/server' | ||
import { resolve } from 'node:path' | ||
|
||
export async function GET() { | ||
return NextResponse.json({ | ||
notBundledCJSModule: __non_webpack_require__(resolve('./cjs-file-with-js-extension.js')), | ||
bundledCJSModule: require('./bundled.cjs'), | ||
}) | ||
} | ||
|
||
export const dynamic = 'force-dynamic' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { parse: pathParse } = require('node:path') | ||
|
||
const fileBase = pathParse(__filename).base | ||
|
||
module.exports = { | ||
fileBase, | ||
// if fileBase is not the same as this module name, it was bundled | ||
isBundled: fileBase !== 'cjs-file-with-js-extension.js', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters