-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Turbopack: write symlinks to access transitive serverExternalPackages
#86375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4d7c393
d49d13f
9fde191
3d7ea13
62549af
d15616f
6cc0461
a7c3a4a
4a9dc6b
96f8ee9
b9239b0
2fec9be
c7e8405
d924263
8e32d12
fa58fb4
81eb3af
55413b8
51316e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export default function Root({ children }) { | ||
| return ( | ||
| <html> | ||
| <head></head> | ||
| <body>{children}</body> | ||
| </html> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import depA from 'dep-a' | ||
| import depB from 'dep-b' | ||
mischnic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export default function page() { | ||
| return ( | ||
| <body> | ||
| <p> | ||
| depA: {depA}, depB: {depB.join(', ')} | ||
| </p> | ||
| </body> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import lodash from 'lodash' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also test nested imports It would also be cool to have a package with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does an |
||
|
|
||
| export default lodash.VERSION | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "name": "dep-a", | ||
| "version": "1.0.0", | ||
| "dependencies": { | ||
| "lodash": "3.10.1" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import lodash from 'lodash' | ||
| import pkg from 'lodash/package.json' | ||
|
|
||
| export default [lodash.VERSION, pkg.version] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "name": "dep-b", | ||
| "version": "1.0.0", | ||
| "dependencies": { | ||
| "lodash": "4.17.21" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import glob from 'glob' | ||
| import path from 'path' | ||
| import fs from 'fs/promises' | ||
| import { nextTestSetup } from 'e2e-utils' | ||
|
|
||
| describe('externals-transitive', () => { | ||
| const { next, isTurbopack, isNextDeploy, isNextStart } = nextTestSetup({ | ||
| files: __dirname, | ||
| dependencies: require('./package.json').dependencies, | ||
| }) | ||
|
|
||
| it('uses the right version of transitive externals', async () => { | ||
| const $ = await next.render$('/') | ||
| const body = $('body > p').text().trim() | ||
| expect(body).toEqual(`depA: 3.10.1, depB: 4.17.21, 4.17.21`) | ||
|
|
||
| if (!isNextDeploy) { | ||
| const files = glob.sync('**/*.js', { | ||
| cwd: path.join(next.testDir, next.distDir, 'server'), | ||
| }) | ||
| let isLodashBundled = false | ||
| for (const file of files) { | ||
| const content = await next.readFile( | ||
| path.join(next.distDir, 'server', file) | ||
| ) | ||
| isLodashBundled = | ||
| isLodashBundled || | ||
| // Code | ||
| content.includes('__lodash_hash_undefined__') || | ||
| // Package.json | ||
| content.includes('Lodash modular utilities.') | ||
| } | ||
|
|
||
| if (isTurbopack) { | ||
| // Assert that lodash wasn't bundled. Turbopack creates symlinks to be able to access | ||
| // transitive dependencies at runtime. | ||
| expect(isLodashBundled).toBe(false) | ||
|
|
||
| let symlinks = ( | ||
| await fs.readdir( | ||
| path.join(next.testDir, next.distDir, 'node_modules') | ||
| ) | ||
| ).filter((file) => file.startsWith('lodash-')) | ||
|
|
||
| expect(symlinks.length).toBeGreaterThanOrEqual(2) | ||
|
|
||
| if (isNextStart) { | ||
| // Lists the two symlinks in the NFT | ||
| const trace = (await next.readJSON( | ||
| '.next/server/app/page.js.nft.json' | ||
| )) as { files: string[] } | ||
|
|
||
| for (let symlink of symlinks) { | ||
| expect(trace.files).toContain(`../../node_modules/${symlink}`) | ||
| } | ||
| } | ||
| } else { | ||
| // Webpack ends up bundling lodash in dep-a | ||
| expect(isLodashBundled).toBe(true) | ||
| } | ||
| } | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| module.exports = { | ||
| serverExternalPackages: ['lodash'], | ||
| experimental: { | ||
| turbopackModuleIds: 'named', | ||
| turbopackMinify: false, | ||
| turbopackScopeHoisting: false, | ||
| }, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "dependencies": { | ||
| "dep-a": "file:./dep-a", | ||
| "dep-b": "file:./dep-b", | ||
| "lodash": "3.10.1" | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.