Unverified Commit 2bb227eb authored by Dario Lehmhus's avatar Dario Lehmhus Committed by GitHub

fix: turbopack loader ipc field mapping (#82112)

Co-authored-by: 's avatarDario Lehmhus <dario.lehmhus@ffw.com>
parent 189f971f
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import { utilFn } from '../utils/file-to-transform'
export default function Page() {
return <p>{utilFn()}</p>
}
const path = require('node:path')
const loader = async function (content) {
this.async()
if (!this.resourcePath.endsWith('file-to-transform.ts')) {
return this.callback(null, content)
}
const dependencyFile = './file-dependency.ts'
const context = path.dirname(this.resourcePath)
const resolve = this.getResolve({})
const result = await resolve(context, dependencyFile)
this.addDependency(result)
this.callback(
null,
`export const utilFn = () => 'Generated at ${new Date().toISOString()}';`
)
}
module.exports = loader
const path = require('node:path')
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
turbopack: {
rules: {
'*.ts': {
loaders: [path.resolve(__dirname, './loader.js')],
},
},
},
webpack: (config) => {
config.module.rules.push({
test: /\.ts$/,
use: [path.resolve(__dirname, './loader.js')],
})
return config
},
}
module.exports = nextConfig
import { nextTestSetup } from 'e2e-utils'
import { waitFor } from 'next-test-utils'
describe('turbopack-loader-file-dependencies', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should update when the dependency file changes', async () => {
const $ = await next.render$('/')
const initialText = await $('p').text()
expect(initialText).toBeTruthy()
await next.patchFile(
'utils/file-dependency.ts',
'export const magicValue = "magic-value-2";'
)
await waitFor(1000)
const $2 = await next.render$('/')
const newText = await $2('p').text()
expect(newText).not.toBe(initialText)
})
})
import { magicValue } from './file-dependency'
export const utilFn = () => {
return magicValue
}
......@@ -362,6 +362,7 @@ pub enum InfoMessage {
// Sent to inform Turbopack about the dependencies of the task.
// All fields are `default` since it is ok for the client to
// simply omit instead of sending empty arrays.
#[serde(rename_all = "camelCase")]
Dependencies {
#[serde(default)]
env_variables: Vec<RcStr>,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment