Skip to content

Commit

Permalink
mention glob syntax in entry point errors (#976)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Mar 15, 2021
1 parent 29b7c3f commit fbdf70d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@

This problem occurs because this package doesn't provide an import path for ESM code using the `import` condition and also doesn't provide a fallback import path using the `default` condition.

* Mention glob syntax in entry point error messages ([#976](https://github.com/evanw/esbuild/issues/976))

In this release, including a `*` in the entry point path now causes the failure message to tell you that glob syntax must be expanded first before passing the paths to esbuild. People that hit this are usually converting an existing CLI command to a JavaScript API call and don't know that glob expansion is done by their shell instead of by esbuild. An appropriate fix is to use a library such as [`glob`](https://www.npmjs.com/package/glob) to expand the glob pattern first before passing the paths to esbuild.

* Raise certain VM versions in the JavaScript feature compatibility table

JavaScript VM feature compatibility data is derived from this dataset: https://kangax.github.io/compat-table/. The scripts that process the dataset expand the data to include all VM versions that support a given feature (e.g. `chrome44`, `chrome45`, `chrome46`, ...) so esbuild takes the minimum observed version as the first version for which the feature is supported.
Expand Down
4 changes: 3 additions & 1 deletion internal/bundler/bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,9 @@ func (s *scanner) addEntryPoints(entryPoints []string) []uint32 {
} else if !didLogError {
hint := ""
if !s.fs.IsAbs(path) {
if query := s.res.ProbeResolvePackageAsRelative(entryPointAbsResolveDir, path, ast.ImportEntryPoint); query != nil {
if strings.ContainsRune(path, '*') {
hint = " (glob syntax must be expanded first before passing the paths to esbuild)"
} else if query := s.res.ProbeResolvePackageAsRelative(entryPointAbsResolveDir, path, ast.ImportEntryPoint); query != nil {
hint = fmt.Sprintf(" (use %q to reference the file %q)", "./"+path, s.res.PrettyPath(query.PathPair.Primary))
}
}
Expand Down
16 changes: 16 additions & 0 deletions scripts/js-api-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ let buildTests = {
}
},

async errorIfGlob({ esbuild }) {
try {
await esbuild.build({
entryPoints: ['./src/*.js'],
logLevel: 'silent',
write: false,
})
throw new Error('Expected build failure');
} catch (e) {
if (!e.errors || !e.errors[0] || e.errors[0].text !== 'Could not resolve "./src/*.js" ' +
'(glob syntax must be expanded first before passing the paths to esbuild)') {
throw e;
}
}
},

async workingDirTest({ esbuild, testDir }) {
let aDir = path.join(testDir, 'a');
let bDir = path.join(testDir, 'b');
Expand Down

0 comments on commit fbdf70d

Please sign in to comment.