diff --git a/CHANGELOG.md b/CHANGELOG.md index 6853ab73..72ed562a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +* Expose `metafile` to `onRebuild` in watch mode ([#1057](https://github.com/evanw/esbuild/issues/1057)) + + Previously the build results returned to the watch mode `onRebuild` callback was missing the `metafile` property when the `metafile: true` option was present. This bug has been fixed. + ## 0.10.0 **This release contains backwards-incompatible changes.** Since esbuild is before version 1.0.0, these changes have been released as a new minor version to reflect this (as [recommended by npm](https://docs.npmjs.com/cli/v6/using-npm/semver/)). You should either be pinning the exact version of `esbuild` in your `package.json` file or be using a version range syntax that only accepts patch upgrades such as `~0.9.0`. See the documentation about [semver](https://docs.npmjs.com/cli/v6/using-npm/semver/) for more information. diff --git a/lib/common.ts b/lib/common.ts index 8a6db1f3..0ffeb61c 100644 --- a/lib/common.ts +++ b/lib/common.ts @@ -863,6 +863,11 @@ export function createChannel(streamIn: StreamIn): StreamOut { // Factor out response handling so it can be reused for rebuilds let rebuild: types.BuildResult['rebuild'] | undefined; let stop: types.BuildResult['stop'] | undefined; + let copyResponseToResult = (response: protocol.BuildResponse, result: types.BuildResult) => { + if (response.outputFiles) result.outputFiles = response!.outputFiles.map(convertOutputFiles); + if (response.metafile) result.metafile = JSON.parse(response!.metafile); + if (response.writeToStdout !== void 0) console.log(protocol.decodeUTF8(response!.writeToStdout).replace(/\n$/, '')); + }; let buildResponseToResult = ( response: protocol.BuildResponse | null, callback: (error: Error | null, result: types.BuildResult | null) => void, @@ -871,9 +876,7 @@ export function createChannel(streamIn: StreamIn): StreamOut { let warnings = replaceDetailsInMessages(response!.warnings, details); if (errors.length > 0) return callback(failureErrorWithLog('Build failed', errors, warnings), null); let result: types.BuildResult = { warnings }; - if (response!.outputFiles) result.outputFiles = response!.outputFiles.map(convertOutputFiles); - if (response!.metafile) result.metafile = JSON.parse(response!.metafile); - if (response!.writeToStdout !== void 0) console.log(protocol.decodeUTF8(response!.writeToStdout).replace(/\n$/, '')); + copyResponseToResult(response!, result); // Handle incremental rebuilds if (response!.rebuildID !== void 0) { @@ -924,7 +927,7 @@ export function createChannel(streamIn: StreamIn): StreamOut { let warnings = replaceDetailsInMessages(watchResponse.warnings, details); if (errors.length > 0) return watch!.onRebuild!(failureErrorWithLog('Build failed', errors, warnings), null); let result: types.BuildResult = { warnings }; - if (watchResponse.outputFiles) result.outputFiles = watchResponse.outputFiles.map(convertOutputFiles); + copyResponseToResult(watchResponse, result); if (watchResponse.rebuildID !== void 0) result.rebuild = rebuild; result.stop = stop; watch!.onRebuild!(null, result);