-
Notifications
You must be signed in to change notification settings - Fork 27.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turbopack + app router: always use externals for predefined packages (#…
…56440) This applies the predefined list of packages in server-external-packages.json as always external when used by app router in Turbopack Test Plan: Added integration tests Closes WEB-1709
- Loading branch information
1 parent
c4c60b3
commit 3c326ea
Showing
11 changed files
with
135 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Root({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
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,5 @@ | ||
import { foo } from 'external-package' | ||
|
||
export default function Page() { | ||
return <div>{foo}</div> | ||
} |
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,5 @@ | ||
import { foo } from 'sqlite3' | ||
|
||
export default function Predefined() { | ||
return <div>{foo}</div> | ||
} |
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,71 @@ | ||
import fs from 'fs/promises' | ||
import path from 'path' | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
async function getAppPageChunkPaths(appDir: string, pageName?: string) { | ||
const rscPath = path.join(appDir, '.next/server/chunks/rsc') | ||
const pageRegex = new RegExp( | ||
`app${pageName ? '_' + pageName : ''}_page_tsx_[0-9a-f]+._.js$` | ||
) | ||
|
||
return (await fs.readdir(rscPath)) | ||
.filter((p) => p.match(pageRegex)) | ||
.map((basename) => path.join(rscPath, basename)) | ||
} | ||
|
||
createNextDescribe( | ||
'externals-app', | ||
{ | ||
files: __dirname, | ||
}, | ||
({ next, isNextDev, isTurbopack }) => { | ||
it('should have externals for those in config.experimental.serverComponentsExternalPackages', async () => { | ||
await next.render$('/') | ||
|
||
if (isTurbopack) { | ||
const appBundles = await getAppPageChunkPaths(next.testDir) | ||
const bundleTexts = await Promise.all( | ||
appBundles.map((b) => fs.readFile(b, 'utf8')) | ||
) | ||
expect( | ||
bundleTexts.find((t) => | ||
t.includes( | ||
'__turbopack_external_require__("external-package", true)' | ||
) | ||
) | ||
).not.toBeUndefined() | ||
} else { | ||
const output = await fs.readFile( | ||
path.join(next.testDir, '.next/server/app/page.js'), | ||
'utf8' | ||
) | ||
expect(output).toContain('require("external-package")') | ||
} | ||
}) | ||
|
||
it('uses externals for predefined list in server-external-packages.json', async () => { | ||
await next.render$('/predefined') | ||
|
||
if (isTurbopack) { | ||
const appBundles = await getAppPageChunkPaths( | ||
next.testDir, | ||
'predefined' | ||
) | ||
const bundleTexts = await Promise.all( | ||
appBundles.map((b) => fs.readFile(b, 'utf8')) | ||
) | ||
expect( | ||
bundleTexts.find((t) => | ||
t.includes('__turbopack_external_require__("sqlite3", true)') | ||
) | ||
).not.toBeUndefined() | ||
} else { | ||
const output = await fs.readFile( | ||
path.join(next.testDir, '.next/server/app/predefined/page.js'), | ||
'utf8' | ||
) | ||
expect(output).toContain('require("sqlite3")') | ||
} | ||
}) | ||
} | ||
) |
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,10 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = { | ||
experimental: { | ||
serverComponentsExternalPackages: ['external-package'], | ||
}, | ||
} | ||
|
||
module.exports = nextConfig |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/externals/node_modules/external-package/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
test/e2e/app-dir/externals/node_modules/external-package/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.