diff --git a/internal/bundler/bundler.go b/internal/bundler/bundler.go index 62c34313166..733ac9ad826 100644 --- a/internal/bundler/bundler.go +++ b/internal/bundler/bundler.go @@ -703,7 +703,7 @@ func runOnResolvePlugins( result := res.Resolve(absResolveDir, path, kind) // Warn when the case used for importing differs from the actual file name - if result != nil && result.DifferentCase != nil { + if result != nil && result.DifferentCase != nil && !resolver.IsInsideNodeModules(absResolveDir) { diffCase := *result.DifferentCase log.AddRangeWarning(importSource, importPathRange, fmt.Sprintf( "Use %q instead of %q to avoid issues with case-sensitive file systems", @@ -935,7 +935,7 @@ func (s *scanner) maybeParseFile( } // Don't emit warnings for code inside a "node_modules" directory - if resolver.IsInsideNodeModules(s.fs, path.Text) { + if resolver.IsInsideNodeModules(path.Text) { optionsClone.SuppressWarningsAboutWeirdCode = true } diff --git a/internal/resolver/resolver.go b/internal/resolver/resolver.go index 2b5ec0b9995..872569080a6 100644 --- a/internal/resolver/resolver.go +++ b/internal/resolver/resolver.go @@ -282,7 +282,7 @@ func (r *resolver) ProbeResolvePackageAsRelative(sourceDir string, importPath st return nil } -func IsInsideNodeModules(fs fs.FS, path string) bool { +func IsInsideNodeModules(path string) bool { for { // This is written in a platform-independent manner because it's run on // user-specified paths which can be arbitrary non-file-system things. So @@ -730,7 +730,7 @@ func (r *resolver) parseTSConfig(file string, visited map[string]bool) (*TSConfi } // Suppress warnings about missing base config files inside "node_modules" - if !IsInsideNodeModules(r.fs, file) { + if !IsInsideNodeModules(file) { r.log.AddRangeWarning(&source, extendsRange, fmt.Sprintf("Cannot find base config file %q", extends)) } diff --git a/scripts/end-to-end-tests.js b/scripts/end-to-end-tests.js index b77077c5c24..de42f2627b2 100644 --- a/scripts/end-to-end-tests.js +++ b/scripts/end-to-end-tests.js @@ -2471,33 +2471,69 @@ tests.push( test(['in.js', '--bundle', '--outfile=node.js'], { 'in.js': ` - import x from "./File1.js" - import y from "./file2.js" - if (x !== 123 || y !== 234) throw 'fail' - `, + import x from "./File1.js" + import y from "./file2.js" + if (x !== 123 || y !== 234) throw 'fail' + `, 'file1.js': `export default 123`, 'File2.js': `export default 234`, }, { expectedStderr: ` > in.js: warning: Use "file1.js" instead of "File1.js" to avoid issues with case-sensitive file systems - 2 │ import x from "./File1.js" - ╵ ~~~~~~~~~~~~ + 2 │ import x from "./File1.js" + ╵ ~~~~~~~~~~~~ > in.js: warning: Use "File2.js" instead of "file2.js" to avoid issues with case-sensitive file systems - 3 │ import y from "./file2.js" - ╵ ~~~~~~~~~~~~ + 3 │ import y from "./file2.js" + ╵ ~~~~~~~~~~~~ 2 warnings `, }), test(['in.js', '--bundle', '--outfile=node.js'], { 'in.js': ` - import x from "./Dir1/file.js" - import y from "./dir2/file.js" - if (x !== 123 || y !== 234) throw 'fail' - `, + import x from "./Dir1/file.js" + import y from "./dir2/file.js" + if (x !== 123 || y !== 234) throw 'fail' + `, 'dir1/file.js': `export default 123`, 'Dir2/file.js': `export default 234`, }), + + // Warn when importing something inside node_modules + test(['in.js', '--bundle', '--outfile=node.js'], { + 'in.js': ` + import x from "pkg/File1.js" + import y from "pkg/file2.js" + if (x !== 123 || y !== 234) throw 'fail' + `, + 'node_modules/pkg/file1.js': `export default 123`, + 'node_modules/pkg/File2.js': `export default 234`, + }, { + expectedStderr: ` > in.js: warning: Use "node_modules/pkg/file1.js" instead of "node_modules/pkg/File1.js" to avoid issues with case-sensitive file systems + 2 │ import x from "pkg/File1.js" + ╵ ~~~~~~~~~~~~~~ + + > in.js: warning: Use "node_modules/pkg/File2.js" instead of "node_modules/pkg/file2.js" to avoid issues with case-sensitive file systems + 3 │ import y from "pkg/file2.js" + ╵ ~~~~~~~~~~~~~~ + +2 warnings +`, + }), + + // Don't warn when the importer is inside node_modules + test(['in.js', '--bundle', '--outfile=node.js'], { + 'in.js': ` + import {x, y} from "pkg" + if (x !== 123 || y !== 234) throw 'fail' + `, + 'node_modules/pkg/index.js': ` + export {default as x} from "./File1.js" + export {default as y} from "./file2.js" + `, + 'node_modules/pkg/file1.js': `export default 123`, + 'node_modules/pkg/File2.js': `export default 234`, + }), ) }