diff --git a/packages/infrastructure/webpack/src/__snapshots__/get-multi-export-config.test.ts.snap b/packages/infrastructure/webpack/src/__snapshots__/get-multi-export-config.test.ts.snap index 16d3217aa3..e6e73d3f7f 100644 --- a/packages/infrastructure/webpack/src/__snapshots__/get-multi-export-config.test.ts.snap +++ b/packages/infrastructure/webpack/src/__snapshots__/get-multi-export-config.test.ts.snap @@ -25,7 +25,8 @@ exports[`get-multi-export-config given maximal package.json, when creating confi } } } - } + }, + LinkablePushPlugin {} ], output: { path: '/some-working-directory/dist', @@ -59,7 +60,8 @@ exports[`get-multi-export-config given maximal package.json, when creating confi } } } - } + }, + LinkablePushPlugin {} ], output: { path: '/some-working-directory/dist/some-entrypoint', @@ -94,6 +96,7 @@ exports[`get-multi-export-config given maximal package.json, when creating confi } } }, + LinkablePushPlugin {}, MiniCssExtractPlugin { _sortedModulesCache: WeakMap { }, options: { diff --git a/packages/infrastructure/webpack/src/get-node-config.ts b/packages/infrastructure/webpack/src/get-node-config.ts index adcfe7b5b2..ae1499b2b7 100644 --- a/packages/infrastructure/webpack/src/get-node-config.ts +++ b/packages/infrastructure/webpack/src/get-node-config.ts @@ -2,6 +2,7 @@ import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin"; import type { Configuration } from "webpack"; import { MakePeerDependenciesExternalPlugin } from "./plugins/make-peer-dependencies-external"; import { ProtectFromImportingNonDependencies } from "./plugins/protect-from-importing-non-dependencies"; +import { LinkablePushPlugin } from "./plugins/linkable-push-plugin"; export type Paths = { entrypointFilePath: string; @@ -44,6 +45,8 @@ export const getNodeConfig = ({ }, }, }), + + new LinkablePushPlugin(), ], output: { diff --git a/packages/infrastructure/webpack/src/plugins/linkable-push-plugin.ts b/packages/infrastructure/webpack/src/plugins/linkable-push-plugin.ts new file mode 100644 index 0000000000..33e18d4e97 --- /dev/null +++ b/packages/infrastructure/webpack/src/plugins/linkable-push-plugin.ts @@ -0,0 +1,10 @@ +import { pushLink } from "@ogre-tools/linkable"; +import type { Compiler } from "webpack"; + +export class LinkablePushPlugin { + apply(compiler: Compiler) { + compiler.hooks.afterEmit.tap("LinkablePushPlugin", async () => { + await pushLink(); + }); + } +} 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 c2abb22dbc..c428de1e21 100644 --- a/packages/infrastructure/webpack/src/scripts/do-webpack-build.test.ts +++ b/packages/infrastructure/webpack/src/scripts/do-webpack-build.test.ts @@ -51,68 +51,10 @@ describe("do-webpack-build", () => { expect(logSuccessMock).toHaveBeenCalledWith("some-stdout"); }); - it("makes the built package available for local packages in development that link to it", () => { - expect(execMock).toHaveBeenCalledWith("linkable-push"); - }); - - it("does not finish script yet", async () => { + it("script is done", async () => { const promiseStatus = await getPromiseStatus(actualPromise); - expect(promiseStatus.fulfilled).toBe(false); - }); - - describe("when linking resolves with stdout", () => { - beforeEach(async () => { - logSuccessMock.mockClear(); - - await execMock.resolve({ stdout: "some-other-stdout", stderr: "" }); - }); - - it("logs the stdout", () => { - expect(logSuccessMock).toHaveBeenCalledWith("some-other-stdout"); - }); - - it("script finishes", async () => { - const promiseStatus = await getPromiseStatus(actualPromise); - - expect(promiseStatus.fulfilled).toBe(true); - }); - }); - - describe("when linking resolves with stderr", () => { - beforeEach(() => { - logSuccessMock.mockClear(); - - execMock.resolve({ stdout: "", stderr: "some-other-stderr" }); - }); - - it("does not log success", () => { - actualPromise.catch(() => {}); - - expect(logSuccessMock).not.toHaveBeenCalled(); - }); - - it("logs a warning", () => { - expect(logWarningMock).toBeCalledWith("Warning while executing \"linkable-push\": some-other-stderr"); - }); - }); - - describe("when linking rejects", () => { - beforeEach(() => { - logSuccessMock.mockClear(); - - execMock.reject(new Error("some-other-error")); - }); - - it("does not log success", () => { - actualPromise.catch(() => {}); - - expect(logSuccessMock).not.toHaveBeenCalled(); - }); - - it("throws", () => { - return expect(actualPromise).rejects.toThrow("some-other-error"); - }); + expect(promiseStatus.fulfilled).toBe(true); }); }); diff --git a/packages/infrastructure/webpack/src/scripts/do-webpack-build.ts b/packages/infrastructure/webpack/src/scripts/do-webpack-build.ts index 01e8bf7087..d2118256f7 100644 --- a/packages/infrastructure/webpack/src/scripts/do-webpack-build.ts +++ b/packages/infrastructure/webpack/src/scripts/do-webpack-build.ts @@ -25,8 +25,6 @@ export const doWebpackBuildInjectable = getInjectable({ return async () => { await execWithResultHandling("webpack"); - - await execWithResultHandling("linkable-push"); }; }, });