1
0
mirror of https://github.com/lensapp/lens.git synced 2024-08-16 04:40:24 +03:00

feat: Make webpack configuration trigger linkable-push

Previously this was done by lens-webpack-build, which is awkward for
build-scripts that watch.

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Mikko Aspiala <mikko.aspiala@gmail.com>
Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-turso 2023-05-31 14:35:37 +03:00 committed by Janne Savolainen
parent 0c1e822788
commit 0c2cc25b5b
5 changed files with 20 additions and 64 deletions

View File

@ -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 { <items unknown> },
options: {

View File

@ -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: {

View File

@ -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();
});
}
}

View File

@ -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);
});
});

View File

@ -25,8 +25,6 @@ export const doWebpackBuildInjectable = getInjectable({
return async () => {
await execWithResultHandling("webpack");
await execWithResultHandling("linkable-push");
};
},
});