Unverified Commit c70b96b3 authored by Jimmy Miller's avatar Jimmy Miller Committed by GitHub

Fix addMissingDependency (#98588)

While before this change we had addMissingDependency, we didn't properly
respond when the file for that missing dep was added.

The way webpack does this internally is not the exact same shape as the
IPC here, it has them as a separate field. I could not find any reason
not to just add them to the filePaths here. So that's what I did to keep
things simple.
parent 95d3d8ec
const path = require('node:path') const path = require('node:path')
const fs = require('node:fs')
const loader = async function (content) { const loader = async function (content) {
this.async() this.async()
...@@ -12,10 +13,12 @@ const loader = async function (content) { ...@@ -12,10 +13,12 @@ const loader = async function (content) {
const resolve = this.getResolve({}) const resolve = this.getResolve({})
const result = await resolve(context, dependencyFile) const result = await resolve(context, dependencyFile)
this.addDependency(result) this.addDependency(result)
const missingDependency = path.join(context, 'missing-dependency.ts')
this.addMissingDependency(missingDependency)
this.callback( this.callback(
null, null,
`export const utilFn = () => 'Generated at ${new Date().toISOString()}';` `export const utilFn = () => 'Generated at ${new Date().toISOString()}, missing dependency: ${fs.existsSync(missingDependency)}';`
) )
} }
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { waitFor } from 'next-test-utils' import { retry, waitFor } from 'next-test-utils'
describe('turbopack-loader-file-dependencies', () => { describe('turbopack-loader-file-dependencies', () => {
const { next } = nextTestSetup({ const { next } = nextTestSetup({
...@@ -22,4 +22,21 @@ describe('turbopack-loader-file-dependencies', () => { ...@@ -22,4 +22,21 @@ describe('turbopack-loader-file-dependencies', () => {
const newText = await $2('p').text() const newText = await $2('p').text()
expect(newText).not.toBe(initialText) expect(newText).not.toBe(initialText)
}) })
it('should update when a missing dependency is created', async () => {
const $ = await next.render$('/')
const initialText = $('p').text()
expect(initialText).toContain('missing dependency: false')
await next.patchFile(
'utils/missing-dependency.ts',
'export const value = "created"',
async () => {
await retry(async () => {
const $2 = await next.render$('/')
expect($2('p').text()).toContain('missing dependency: true')
})
}
)
})
}) })
import 'loader-runner'
declare module 'loader-runner' {
// @types/loader-runner is out of date and omits missingDependencies.
interface RunLoaderResult {
missingDependencies: string[]
}
}
...@@ -554,7 +554,10 @@ const transform = ( ...@@ -554,7 +554,10 @@ const transform = (
ipc.sendInfo({ ipc.sendInfo({
type: 'dependencies', type: 'dependencies',
envVariables: getReadEnvVariables(), envVariables: getReadEnvVariables(),
filePaths: result.fileDependencies.map(toPath), filePaths: [
...result.fileDependencies,
...result.missingDependencies,
].map(toPath),
directories: result.contextDependencies.map((dep) => [ directories: result.contextDependencies.map((dep) => [
toPath(dep), toPath(dep),
'**', '**',
......
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