Skip to content

Commit 4844d4b

Browse files
committed
fix #4420, close #4418: metafile JSON regression
1 parent edbdce8 commit 4844d4b

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
* Fix a regression when `metafile` is enabled ([#4420](https://github.com/evanw/esbuild/issues/4420), [#4418](https://github.com/evanw/esbuild/pull/4418))
6+
7+
This release fixes a regression introduced by the previous release. When `metafile: true` was enabled in esbuild's JavaScript API, builds with build errors were incorrectly throwing an error about an empty JSON string instead of an object containing the build errors.
8+
59
* Allow `es2025` as a target in `tsconfig.json` ([#4432](https://github.com/evanw/esbuild/issues/4432))
610

711
TypeScript recently [added `es2025`](https://devblogs.microsoft.com/typescript/announcing-typescript-6-0/#es2025-option-for-target-and-lib) as a compilation target, so esbuild now supports this in the `target` field of `tsconfig.json` files, such as in the following configuration file:

lib/shared/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ function buildOrContextImpl(
953953
const originalErrors = result.errors.slice()
954954
const originalWarnings = result.warnings.slice()
955955
if (response!.outputFiles) result.outputFiles = response!.outputFiles.map(convertOutputFiles)
956-
if (response!.metafile) result.metafile = parseJSON(response!.metafile)
956+
if (response!.metafile && response!.metafile.length) result.metafile = parseJSON(response!.metafile)
957957
if (response!.mangleCache) result.mangleCache = response!.mangleCache
958958
if (response!.writeToStdout !== void 0) console.log(protocol.decodeUTF8(response!.writeToStdout).replace(/\n$/, ''))
959959
runOnEndCallbacks(result, (onEndErrors, onEndWarnings) => {

scripts/js-api-tests.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,35 @@ body {
17001700
assert.deepStrictEqual(json.outputs[fileKey].inputs, { [makePath(file)]: { bytesInOutput: 14 } })
17011701
},
17021702

1703+
// See: https://github.com/evanw/esbuild/issues/4420
1704+
async metafileEmpty({ esbuild, testDir }) {
1705+
const entry = path.join(testDir, 'entry.ts')
1706+
const unknown = path.join(testDir, 'a.unknown')
1707+
await writeFileAsync(entry, `
1708+
import contents from "./a.unknown";
1709+
console.log(contents);
1710+
`)
1711+
await writeFileAsync(unknown, '')
1712+
1713+
// Generate a build with an empty metafile JSON string due to an error
1714+
let error
1715+
try {
1716+
await esbuild.build({
1717+
entryPoints: [entry],
1718+
bundle: true,
1719+
outdir: testDir,
1720+
metafile: true,
1721+
logLevel: 'silent',
1722+
})
1723+
} catch (e) {
1724+
error = e
1725+
}
1726+
1727+
// Make sure we get an error message about the unknown file extension
1728+
assert.strictEqual(error.errors.length, 1)
1729+
assert(error.errors[0].text.includes('.unknown'))
1730+
},
1731+
17031732
// Test in-memory output files
17041733
async writeFalse({ esbuild, testDir }) {
17051734
const input = path.join(testDir, 'in.js')

0 commit comments

Comments
 (0)