Skip to content

Commit

Permalink
feat: added support for adding additional rollup plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
prisis committed Sep 17, 2024
1 parent 862e223 commit d96ec64
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 193 deletions.
4 changes: 2 additions & 2 deletions packages/packem/__tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const installPackage = async (fixturePath: string, packageName: string):

export const createPackemConfig = async (
fixturePath: string,
config: BuildConfig | BuildConfig[] = {},
config: BuildConfig | string = {},
transformer: "esbuild" | "swc" | "sucrase" = "esbuild",
isolatedDeclarationTransformer: "swc" | "typescript" | "oxc" | undefined = undefined,
): Promise<void> => {
Expand All @@ -68,7 +68,7 @@ ${isolatedDeclarationTransformer ? `import isolatedDeclarationTransformer from "
export default defineConfig({
transformer,
${isolatedDeclarationTransformer ? `isolatedDeclarationTransformer,` : ""}
${JSON.stringify(config, null, 4).slice(1, -1)}
${typeof config === "string" ? config : JSON.stringify(config, null, 4).slice(1, -1)}
});
`,
{
Expand Down
71 changes: 71 additions & 0 deletions packages/packem/__tests__/intigration/packem.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { rm } from "node:fs/promises";

import { readFileSync, writeFileSync } from "@visulima/fs";
import type { Plugin } from "rollup";
import { temporaryDirectory } from "tempy";
import { afterEach, beforeEach, describe, expect, it } from "vitest";

import { createPackageJson, createPackemConfig, createTsConfig, execPackemSync, installPackage } from "../helpers";

describe("packem build --jit", () => {
let temporaryDirectoryPath: string;

beforeEach(async () => {
temporaryDirectoryPath = temporaryDirectory();
});

afterEach(async () => {
await rm(temporaryDirectoryPath, { recursive: true });
});

it("should append plugins before and after a named plugin", async () => {
expect.assertions(4);

await installPackage(temporaryDirectoryPath, "typescript");

writeFileSync(`${temporaryDirectoryPath}/src/index.ts`, `export default () => 'index';`);

createTsConfig(temporaryDirectoryPath, {});
createPackageJson(temporaryDirectoryPath, {
devDependencies: {
typescript: "*",
},
main: "./dist/index.cjs",
});
await createPackemConfig(
temporaryDirectoryPath,
`rollup: {
plugins: [
{
before: "packem:esbuild",
plugin: <Plugin>{
load() {
console.log("packem:test-plugin:before");
},
name: "packem:test-plugin:before"
}
},
{
after: "packem:esbuild",
plugin: <Plugin>{
load() {
console.log("packem:test-plugin:after");
},
name: "packem:test-plugin:after"
}
}
]
}`,
);

const binProcess = await execPackemSync("build", [], {
cwd: temporaryDirectoryPath,
});

expect(binProcess.stderr).toBe("");
expect(binProcess.exitCode).toBe(0);

expect(binProcess.stdout).toContain("packem:test-plugin:before");
expect(binProcess.stdout).toContain("packem:test-plugin:after");
});
});
Loading

0 comments on commit d96ec64

Please sign in to comment.