Files
Luke SandbergandGitHub e0b2cebde5 Improve the NFT error message and ignore comment handling (#95144)
Fixes #95125 in two ways

The OP admits that they misread the message in a few ways, but we can
fix all of them

1. Be specific about what function might need an annotation in the error
message. A user with a nearby `path.join` might think that that is where
the annotation belongs instead of on the function with the warning.

2. Be more flexible with how these `ignore` comments are interpreted
`fs.readFileSync(path.join(process.cwd(), someVar))` shouldn't require 2
annotations. Handle this by checking for and detecting `turbopackIgnore`
comments in all expressions! This will then bubble up through the linker
and just cause us to ignore corresponding fs access apis.
2026-07-14 08:13:12 +02:00

19 lines
681 B
JavaScript

import fs from 'fs'
import path from 'path'
// `turbopackIgnore` on the first argument of the fs call silences the
// dynamic-fs tracing warning. This is the placement the warning recommends.
export function readBareArg(dynamicPath) {
return fs.readFileSync(/* turbopackIgnore: true */ dynamicPath, 'utf8')
}
// The comment also works when placed on a nested `path.join(...)` argument of
// the fs call (issue #95125): ignoring the `path.join` bubbles up and silences
// the enclosing `fs.readFileSync` whole-project tracing warning too.
export function readJoinedArg(f) {
return fs.readFileSync(
path.join(/* turbopackIgnore: true */ process.cwd(), f),
'utf8'
)
}