Skip to content

Commit

Permalink
omit case warning inside "node_modules"
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Feb 17, 2021
1 parent 5776b21 commit 12edc1b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
4 changes: 2 additions & 2 deletions internal/bundler/bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
Expand Down
60 changes: 48 additions & 12 deletions scripts/end-to-end-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
}),
)
}

Expand Down

0 comments on commit 12edc1b

Please sign in to comment.