From 9a2d585e62e8217e377eb18d69019282ec4d06fe Mon Sep 17 00:00:00 2001 From: Iku-turso Date: Wed, 31 May 2023 17:43:47 +0300 Subject: [PATCH] feat: Add support for lens-webpack-build --watch Co-authored-by: Janne Savolainen Signed-off-by: Mikko Aspiala Signed-off-by: Iku-turso --- .../infrastructure/webpack/bin/webpack-build | 2 +- .../infrastructure/webpack/do-webpack-build.ts | 4 ++-- .../src/scripts/do-webpack-build.test.ts | 18 +++++++++++++++--- .../webpack/src/scripts/do-webpack-build.ts | 8 ++++---- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/infrastructure/webpack/bin/webpack-build b/packages/infrastructure/webpack/bin/webpack-build index 30c4f8a78d..2b85d14de8 100755 --- a/packages/infrastructure/webpack/bin/webpack-build +++ b/packages/infrastructure/webpack/bin/webpack-build @@ -1,4 +1,4 @@ #!/usr/bin/env node const { doWebpackBuild } = require("../dist/index"); -doWebpackBuild(); +doWebpackBuild({ watch: process.argv.includes("--watch") }); diff --git a/packages/infrastructure/webpack/do-webpack-build.ts b/packages/infrastructure/webpack/do-webpack-build.ts index 1e2e91e3b4..84e57b4d3e 100644 --- a/packages/infrastructure/webpack/do-webpack-build.ts +++ b/packages/infrastructure/webpack/do-webpack-build.ts @@ -1,10 +1,10 @@ import { getDi } from "./src/scripts/get-di"; import { doWebpackBuildInjectable } from "./src/scripts/do-webpack-build"; -export const doWebpackBuild = () => { +export const doWebpackBuild = ({ watch }: { watch: boolean }) => { const di = getDi(); const doWebpackBuild = di.inject(doWebpackBuildInjectable); - doWebpackBuild(); + 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 d388c1fbb4..16a844410e 100644 --- a/packages/infrastructure/webpack/src/scripts/do-webpack-build.test.ts +++ b/packages/infrastructure/webpack/src/scripts/do-webpack-build.test.ts @@ -31,15 +31,27 @@ describe("do-webpack-build", () => { doWebpackBuild = di.inject(doWebpackBuildInjectable); }); - describe("when called", () => { + 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}); + + expect(execMock).toHaveBeenCalledWith("webpack"); + }); + + describe("normally, when called", () => { let actualPromise: Promise; beforeEach(() => { - actualPromise = doWebpackBuild(); + actualPromise = doWebpackBuild({ watch: true}); }); it("calls webpack", () => { - expect(execMock).toHaveBeenCalledWith("webpack"); + expect(execMock).toHaveBeenCalled(); }); it("data in stdout logs as success", () => { diff --git a/packages/infrastructure/webpack/src/scripts/do-webpack-build.ts b/packages/infrastructure/webpack/src/scripts/do-webpack-build.ts index 6252536f4c..ddbe6a153d 100644 --- a/packages/infrastructure/webpack/src/scripts/do-webpack-build.ts +++ b/packages/infrastructure/webpack/src/scripts/do-webpack-build.ts @@ -3,18 +3,18 @@ import { execInjectable } from "./exec.injectable"; import { logSuccessInjectable } from "./log-success.injectable"; import { logWarningInjectable } from "./log-warning.injectable"; -export type DoWebpackBuild = () => Promise; +export type DoWebpackBuild = ({ watch }: { watch: boolean }) => Promise; export const doWebpackBuildInjectable = getInjectable({ id: "do-webpack-build", - instantiate: (di) => { + instantiate: (di): DoWebpackBuild => { const exec = di.inject(execInjectable); const logSuccess = di.inject(logSuccessInjectable); const logWarning = di.inject(logWarningInjectable); - return async () => { - const execResult = exec("webpack"); + return async ({ watch }) => { + const execResult = exec(watch ? "webpack --watch" : "webpack"); execResult.stdout?.on("data", logSuccess); execResult.stderr?.on("data", logWarning);