mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
7c366e61be
Track exact existing files and warn when loaders register unsupported build dependency inputs. I'm going to take this bit by bit so it is nice and reviewable. Does add some noise. But the final fully supported thing was just too large. So I will keep removing error cases on each commit.
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
const path = require('node:path')
|
|
const fs = require('node:fs')
|
|
|
|
const loader = async function (content) {
|
|
this.async()
|
|
|
|
if (this.resourcePath.endsWith('unsupported-build-dependency.ts')) {
|
|
this.addBuildDependency(path.join(__dirname, 'utils'))
|
|
return this.callback(
|
|
null,
|
|
`export const utilFn = () => 'unsupported build dependency';`
|
|
)
|
|
}
|
|
|
|
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)
|
|
const missingDependency = path.join(context, 'missing-dependency.ts')
|
|
this.addMissingDependency(missingDependency)
|
|
const buildDependency = path.join(context, 'build-dependency.js')
|
|
this.addBuildDependency(buildDependency)
|
|
const buildDependencyValue = fs
|
|
.readFileSync(buildDependency, 'utf8')
|
|
.match(/'([^']+)'/)[1]
|
|
|
|
this.callback(
|
|
null,
|
|
`export const utilFn = () => 'Generated at ${new Date().toISOString()}, missing dependency: ${fs.existsSync(missingDependency)}, build dependency: ${buildDependencyValue}';`
|
|
)
|
|
}
|
|
|
|
module.exports = loader
|