v0.8.15
-
Allow
pathswithoutbaseUrlintsconfig.jsonThis feature was recently released in TypeScript 4.1. The
pathsfeature intsconfig.jsonallows you to do custom import path rewriting. For example, you can map paths matching@namespace/*to the path./namespace/src/*relative to thetsconfig.jsonfile. Previously using thepathsfeature required you to additionally specifybaseUrlso that the compiler could know which directory the path aliases were supposed to be relative to.However, specifying
baseUrlhas the potentially-problematic side effect of causing all import paths to be looked up relative to thebaseUrldirectory, which could potentially cause package paths to accidentally be redirected to non-package files. SpecifyingbaseUrlalso causes Visual Studio Code's auto-import feature to generate paths relative to thebaseUrldirectory instead of relative to the directory containing the current file. There is more information about the problems this causes here: microsoft/TypeScript#31869.With TypeScript 4.1, you can now omit
baseUrlwhen usingpaths. When you do this, it as if you had written"baseUrl": "."instead for the purpose of thepathsfeature, but thebaseUrlvalue is not actually set and does not affect path resolution. Thesetsconfig.jsonfiles are now supported by esbuild. -
Fix evaluation order issue with import cycles and CommonJS-style output formats (#542)
Previously entry points involved in an import cycle could cause evaluation order issues if the output format was
iifeorcjsinstead ofesm. This happened because this edge case was handled by treating the entry point file as a CommonJS file, which extracted the code into a CommonJS wrapper. Here's an example:Input files:
// index.js import { test } from './lib' export function fn() { return 42 } if (test() !== 42) throw 'failure'
// lib.js import { fn } from './index' export let test = fn
Previous output (problematic):
// index.js var require_esbuild = __commonJS((exports) => { __export(exports, { fn: () => fn2 }); function fn2() { return 42; } if (test() !== 42) throw "failure"; }); // lib.js var index = __toModule(require_esbuild()); var test = index.fn; module.exports = require_esbuild();
This approach changed the evaluation order because the CommonJS wrapper conflates both binding and evaluation. Binding and evaluation need to be separated to correctly handle this edge case. This edge case is now handled by inlining what would have been the contents of the CommonJS wrapper into the entry point location itself.
Current output (fixed):
// index.js __export(exports, { fn: () => fn }); // lib.js var test = fn; // index.js function fn() { return 42; } if (test() !== 42) throw "failure";