Skip to content

Commit 2bb227e

Browse files
dlehmhusDario Lehmhus
andauthored
fix: turbopack loader ipc field mapping (vercel#82112)
Co-authored-by: Dario Lehmhus <dario.lehmhus@ffw.com>
1 parent 189f971 commit 2bb227e

8 files changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ReactNode } from 'react'
2+
export default function Root({ children }: { children: ReactNode }) {
3+
return (
4+
<html>
5+
<body>{children}</body>
6+
</html>
7+
)
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { utilFn } from '../utils/file-to-transform'
2+
3+
export default function Page() {
4+
return <p>{utilFn()}</p>
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const path = require('node:path')
2+
3+
const loader = async function (content) {
4+
this.async()
5+
6+
if (!this.resourcePath.endsWith('file-to-transform.ts')) {
7+
return this.callback(null, content)
8+
}
9+
10+
const dependencyFile = './file-dependency.ts'
11+
const context = path.dirname(this.resourcePath)
12+
const resolve = this.getResolve({})
13+
const result = await resolve(context, dependencyFile)
14+
this.addDependency(result)
15+
16+
this.callback(
17+
null,
18+
`export const utilFn = () => 'Generated at ${new Date().toISOString()}';`
19+
)
20+
}
21+
22+
module.exports = loader
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const path = require('node:path')
2+
3+
/**
4+
* @type {import('next').NextConfig}
5+
*/
6+
const nextConfig = {
7+
turbopack: {
8+
rules: {
9+
'*.ts': {
10+
loaders: [path.resolve(__dirname, './loader.js')],
11+
},
12+
},
13+
},
14+
webpack: (config) => {
15+
config.module.rules.push({
16+
test: /\.ts$/,
17+
use: [path.resolve(__dirname, './loader.js')],
18+
})
19+
return config
20+
},
21+
}
22+
23+
module.exports = nextConfig
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
import { waitFor } from 'next-test-utils'
3+
4+
describe('turbopack-loader-file-dependencies', () => {
5+
const { next } = nextTestSetup({
6+
files: __dirname,
7+
})
8+
9+
it('should update when the dependency file changes', async () => {
10+
const $ = await next.render$('/')
11+
const initialText = await $('p').text()
12+
expect(initialText).toBeTruthy()
13+
14+
await next.patchFile(
15+
'utils/file-dependency.ts',
16+
'export const magicValue = "magic-value-2";'
17+
)
18+
19+
await waitFor(1000)
20+
21+
const $2 = await next.render$('/')
22+
const newText = await $2('p').text()
23+
expect(newText).not.toBe(initialText)
24+
})
25+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const magicValue = 'magic-value'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { magicValue } from './file-dependency'
2+
3+
export const utilFn = () => {
4+
return magicValue
5+
}

turbopack/crates/turbopack-node/src/transforms/webpack.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ pub enum InfoMessage {
362362
// Sent to inform Turbopack about the dependencies of the task.
363363
// All fields are `default` since it is ok for the client to
364364
// simply omit instead of sending empty arrays.
365+
#[serde(rename_all = "camelCase")]
365366
Dependencies {
366367
#[serde(default)]
367368
env_variables: Vec<RcStr>,

0 commit comments

Comments
 (0)