diff --git a/packages/infrastructure/webpack/bin/webpack-build b/packages/infrastructure/webpack/bin/webpack-build index 2b85d14de8..36a12cebc8 100755 --- a/packages/infrastructure/webpack/bin/webpack-build +++ b/packages/infrastructure/webpack/bin/webpack-build @@ -1,4 +1,8 @@ #!/usr/bin/env node const { doWebpackBuild } = require("../dist/index"); -doWebpackBuild({ watch: process.argv.includes("--watch") }); +doWebpackBuild({ + watch: process.argv.includes("--watch"), +}).then(({ statusCode }) => { + process.exit(statusCode); +}); diff --git a/packages/infrastructure/webpack/do-webpack-build.ts b/packages/infrastructure/webpack/do-webpack-build.ts index 84e57b4d3e..2b3e4072e7 100644 --- a/packages/infrastructure/webpack/do-webpack-build.ts +++ b/packages/infrastructure/webpack/do-webpack-build.ts @@ -6,5 +6,5 @@ export const doWebpackBuild = ({ watch }: { watch: boolean }) => { const doWebpackBuild = di.inject(doWebpackBuildInjectable); - doWebpackBuild({ watch }); + return doWebpackBuild({ watch }); }; diff --git a/packages/infrastructure/webpack/src/scripts/do-webpack-build.test.ts b/packages/infrastructure/webpack/src/scripts/do-webpack-build.test.ts index 16a844410e..d9c0795046 100644 --- a/packages/infrastructure/webpack/src/scripts/do-webpack-build.test.ts +++ b/packages/infrastructure/webpack/src/scripts/do-webpack-build.test.ts @@ -1,7 +1,11 @@ import { getDi } from "./get-di"; import { execInjectable } from "./exec.injectable"; import asyncFn, { AsyncFnMock } from "@async-fn/jest"; -import { DoWebpackBuild, doWebpackBuildInjectable } from "./do-webpack-build"; +import { + DoWebpackBuild, + doWebpackBuildInjectable, + DoWebpackBuildResult, +} from "./do-webpack-build"; import { getPromiseStatus } from "@ogre-tools/test-utils"; import { LogSuccess, logSuccessInjectable } from "./log-success.injectable"; import { LogWarning, logWarningInjectable } from "./log-warning.injectable"; @@ -31,23 +35,23 @@ describe("do-webpack-build", () => { doWebpackBuild = di.inject(doWebpackBuildInjectable); }); - it('given watching, when called, calls webpack with watch', () => { - doWebpackBuild({ watch: true}); + it("given watching, when called, calls webpack with watch", () => { + doWebpackBuild({ watch: true }); expect(execMock).toHaveBeenCalledWith("webpack --watch"); }); - it('given not watching, when called, calls webpack without watch', () => { - doWebpackBuild({ watch: false}); + it("given not watching, when called, calls webpack without watch", () => { + doWebpackBuild({ watch: false }); expect(execMock).toHaveBeenCalledWith("webpack"); }); describe("normally, when called", () => { - let actualPromise: Promise; + let actualPromise: Promise; beforeEach(() => { - actualPromise = doWebpackBuild({ watch: true}); + actualPromise = doWebpackBuild({ watch: true }); }); it("calls webpack", () => { @@ -72,14 +76,13 @@ describe("do-webpack-build", () => { expect(promiseStatus.fulfilled).toBe(false); }); - it("when execution of webpack exits, script is done", async () => { + it("when execution of webpack exits with a status-code, script resolves with the status-code", async () => { const [[eventName, finishWebpack]] = execResultStub.on.mock.calls; - eventName === "exit" && finishWebpack(); + const withoutError = 42; + eventName === "exit" && finishWebpack(withoutError); - const promiseStatus = await getPromiseStatus(actualPromise); - - expect(promiseStatus.fulfilled).toBe(true); + expect(await actualPromise).toEqual({ statusCode: 42 }); }); }); }); diff --git a/packages/infrastructure/webpack/src/scripts/do-webpack-build.ts b/packages/infrastructure/webpack/src/scripts/do-webpack-build.ts index ddbe6a153d..c4d33747be 100644 --- a/packages/infrastructure/webpack/src/scripts/do-webpack-build.ts +++ b/packages/infrastructure/webpack/src/scripts/do-webpack-build.ts @@ -3,7 +3,13 @@ import { execInjectable } from "./exec.injectable"; import { logSuccessInjectable } from "./log-success.injectable"; import { logWarningInjectable } from "./log-warning.injectable"; -export type DoWebpackBuild = ({ watch }: { watch: boolean }) => Promise; +export type DoWebpackBuildResult = { statusCode: number }; + +export type DoWebpackBuild = ({ + watch, +}: { + watch: boolean; +}) => Promise; export const doWebpackBuildInjectable = getInjectable({ id: "do-webpack-build", @@ -19,8 +25,10 @@ export const doWebpackBuildInjectable = getInjectable({ execResult.stdout?.on("data", logSuccess); execResult.stderr?.on("data", logWarning); - return new Promise((resolve) => { - execResult.on("exit", resolve); + return new Promise((resolve) => { + execResult.on("exit", (statusCode: number) => { + resolve({ statusCode }); + }); }); }; },