v0.8.15
-
Allow
paths
withoutbaseUrl
intsconfig.json
This feature was recently released in TypeScript 4.1. The
paths
feature intsconfig.json
allows you to do custom import path rewriting. For example, you can map paths matching@namespace/*
to the path./namespace/src/*
relative to thetsconfig.json
file. Previously using thepaths
feature required you to additionally specifybaseUrl
so that the compiler could know which directory the path aliases were supposed to be relative to.However, specifying
baseUrl
has the potentially-problematic side effect of causing all import paths to be looked up relative to thebaseUrl
directory, which could potentially cause package paths to accidentally be redirected to non-package files. SpecifyingbaseUrl
also causes Visual Studio Code's auto-import feature to generate paths relative to thebaseUrl
directory 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
baseUrl
when usingpaths
. When you do this, it as if you had written"baseUrl": "."
instead for the purpose of thepaths
feature, but thebaseUrl
value is not actually set and does not affect path resolution. Thesetsconfig.json
files 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
iife
orcjs
instead 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";