Implement HTTP HEAD requests in serve mode (#2851)
Previously esbuild's serve mode only responded to HTTP GET requests. With this release, esbuild's serve mode will also respond to HTTP HEAD requests, which are just like HTTP GET requests except that the body of the response is omitted.
Permit top-level await in dead code branches (#2853)
Adding top-level await to a file has a few consequences with esbuild:
It causes esbuild to assume that the input module format is ESM, since top-level await is only syntactically valid in ESM. That prevents you from using module and exports for exports and also enables strict mode, which disables certain syntax and changes how function hoisting works (among other things).
This will cause esbuild to fail the build if either top-level await isn't supported by your language target (e.g. it's not supported in ES2021) or if top-level await isn't supported by the chosen output format (e.g. it's not supported with CommonJS).
Doing this will prevent you from using require() on this file or on any file that imports this file (even indirectly), since the require() function doesn't return a promise and so can't represent top-level await.
This release relaxes these rules slightly: rules 2 and 3 will now no longer apply when esbuild has identified the code branch as dead code, such as when it's behind an if (false) check. This should make it possible to use esbuild to convert code into different output formats that only uses top-level await conditionally. This release does not relax rule 1. Top-level await will still cause esbuild to unconditionally consider the input module format to be ESM, even when the top-level await is in a dead code branch. This is necessary because whether the input format is ESM or not affects the whole file, not just the dead code branch.
Fix entry points where the entire file name is the extension (#2861)
Previously if you passed esbuild an entry point where the file extension is the entire file name, esbuild would use the parent directory name to derive the name of the output file. For example, if you passed esbuild a file ./src/.ts then the output name would be src.js. This bug happened because esbuild first strips the file extension to get ./src/ and then joins the path with the working directory to get the absolute path (e.g. join("/working/dir", "./src/") gives /working/dir/src). However, the join operation also canonicalizes the path which strips the trailing /. Later esbuild uses the "base name" operation to extract the name of the output file. Since there is no trailing /, esbuild returns "src" as the base name instead of "", which causes esbuild to incorrectly include the directory name in the output file name. This release fixes this bug by deferring the stripping of the file extension until after all path manipulations have been completed. So now the file ./src/.ts will generate an output file named .js.
Support replacing property access expressions with inject
At a high level, this change means the inject feature can now replace all of the same kinds of names as the define feature. So inject is basically now a more powerful version of define, instead of previously only being able to do some of the things that define could do.
Soem background is necessary to understand this change if you aren't already familiar with the inject feature. The inject feature lets you replace references to global variable with a shim. It works like this:
Put the shim in its own file
Export the shim as the name of the global variable you intend to replace
Pass the file to esbuild using the inject feature
For example, if you inject the following file using --inject:./injected.js:
// injected.js
let processShim = { cwd: () => '/' }
export { processShim as process }
Then esbuild will replace all references to process with the processShim variable, which will cause process.cwd() to return '/'. This feature is sort of abusing the ESM export alias syntax to specify the mapping of global variables to shims. But esbuild works this way because using this syntax for that purpose is convenient and terse.
However, if you wanted to replace a property access expression, the process was more complicated and not as nice. You would have to:
Put the shim in its own file
Export the shim as some random name
Pass the file to esbuild using the inject feature
Use esbuild's define feature to map the property access expression to the random name you made in step 2
For example, if you inject the following file using --inject:./injected2.js --define:process.cwd=someRandomName:
Implement HTTP HEAD requests in serve mode (#2851)
Previously esbuild's serve mode only responded to HTTP GET requests. With this release, esbuild's serve mode will also respond to HTTP HEAD requests, which are just like HTTP GET requests except that the body of the response is omitted.
Permit top-level await in dead code branches (#2853)
Adding top-level await to a file has a few consequences with esbuild:
It causes esbuild to assume that the input module format is ESM, since top-level await is only syntactically valid in ESM. That prevents you from using module and exports for exports and also enables strict mode, which disables certain syntax and changes how function hoisting works (among other things).
This will cause esbuild to fail the build if either top-level await isn't supported by your language target (e.g. it's not supported in ES2021) or if top-level await isn't supported by the chosen output format (e.g. it's not supported with CommonJS).
Doing this will prevent you from using require() on this file or on any file that imports this file (even indirectly), since the require() function doesn't return a promise and so can't represent top-level await.
This release relaxes these rules slightly: rules 2 and 3 will now no longer apply when esbuild has identified the code branch as dead code, such as when it's behind an if (false) check. This should make it possible to use esbuild to convert code into different output formats that only uses top-level await conditionally. This release does not relax rule 1. Top-level await will still cause esbuild to unconditionally consider the input module format to be ESM, even when the top-level await is in a dead code branch. This is necessary because whether the input format is ESM or not affects the whole file, not just the dead code branch.
Fix entry points where the entire file name is the extension (#2861)
Previously if you passed esbuild an entry point where the file extension is the entire file name, esbuild would use the parent directory name to derive the name of the output file. For example, if you passed esbuild a file ./src/.ts then the output name would be src.js. This bug happened because esbuild first strips the file extension to get ./src/ and then joins the path with the working directory to get the absolute path (e.g. join("/working/dir", "./src/") gives /working/dir/src). However, the join operation also canonicalizes the path which strips the trailing /. Later esbuild uses the "base name" operation to extract the name of the output file. Since there is no trailing /, esbuild returns "src" as the base name instead of "", which causes esbuild to incorrectly include the directory name in the output file name. This release fixes this bug by deferring the stripping of the file extension until after all path manipulations have been completed. So now the file ./src/.ts will generate an output file named .js.
Support replacing property access expressions with inject
At a high level, this change means the inject feature can now replace all of the same kinds of names as the define feature. So inject is basically now a more powerful version of define, instead of previously only being able to do some of the things that define could do.
Soem background is necessary to understand this change if you aren't already familiar with the inject feature. The inject feature lets you replace references to global variable with a shim. It works like this:
Put the shim in its own file
Export the shim as the name of the global variable you intend to replace
Pass the file to esbuild using the inject feature
For example, if you inject the following file using --inject:./injected.js:
// injected.js
let processShim = { cwd: () => '/' }
export { processShim as process }
Then esbuild will replace all references to process with the processShim variable, which will cause process.cwd() to return '/'. This feature is sort of abusing the ESM export alias syntax to specify the mapping of global variables to shims. But esbuild works this way because using this syntax for that purpose is convenient and terse.
However, if you wanted to replace a property access expression, the process was more complicated and not as nice. You would have to:
Put the shim in its own file
Export the shim as some random name
Pass the file to esbuild using the inject feature
Use esbuild's define feature to map the property access expression to the random name you made in step 2
For example, if you inject the following file using --inject:./injected2.js --define:process.cwd=someRandomName:
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Bumps esbuild from 0.17.3 to 0.17.4.
Release notes
Sourced from esbuild's releases.
... (truncated)
Changelog
Sourced from esbuild's changelog.
... (truncated)
Commits
3c83a84
publish 0.17.4 to npm2252232
support replacing dot identifier names with inject1f99267
add test for inject + define6c25c9e
fix #2861: bug with extension-only entry points5fe2125
fix #2853: permit top-level await in dead codef48391a
fix #2851: implement HTTPHEAD
requests7c0526e
js tests: convert fetch header to named argument31fb452
optimizer: mark somenew Date
expressions pureDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)