Skip to content

Commit

Permalink
feat: ✨ ref pnpm-workspace.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
gracefullight committed Jun 17, 2024
1 parent 04255f7 commit ec7a199
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion vitest.workspace.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
import { readFileSync } from "node:fs";
import { resolve } from "node:path";

import { defineWorkspace } from "vitest/config";

export default defineWorkspace(["apps/*", "packages/*"]);
const workspaceFilePath = resolve(__dirname, "pnpm-workspace.yaml");

function getPackagesFromWorkspace(): string[] {
const fileContents = readFileSync(workspaceFilePath, "utf8");

const packagePattern = /-\s*'(.*?)'/g;
const matches = [...fileContents.matchAll(packagePattern)];

if (!matches) {
throw new Error("packages field not found in pnpm-workspace.yaml");
}

const packages = matches.map((match) => match[1]);
return packages;
}

const packages = getPackagesFromWorkspace();

export default defineWorkspace(packages);

0 comments on commit ec7a199

Please sign in to comment.