From fbdf70d620433871c0474ee6976b392bb2b75a26 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Mon, 15 Mar 2021 13:28:55 -0700 Subject: [PATCH] mention glob syntax in entry point errors (#976) --- CHANGELOG.md | 4 ++++ internal/bundler/bundler.go | 4 +++- scripts/js-api-tests.js | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a265a95dc8..11e7528a40f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/internal/bundler/bundler.go b/internal/bundler/bundler.go index 938267cbe6d..9a9c124358d 100644 --- a/internal/bundler/bundler.go +++ b/internal/bundler/bundler.go @@ -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)) } } diff --git a/scripts/js-api-tests.js b/scripts/js-api-tests.js index 27677d88f1c..875cd58916c 100644 --- a/scripts/js-api-tests.js +++ b/scripts/js-api-tests.js @@ -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');