fix: isolate plugin index loader env

This commit is contained in:
Shakker
2026-06-20 20:12:29 +01:00
parent 81abc2b21b
commit 6a3f990140
+3 -12
View File
@@ -5,24 +5,15 @@ import path from "node:path";
import { DatabaseSync } from "node:sqlite";
import { pathToFileURL } from "node:url";
import { describe, expect, it } from "vitest";
import { withEnvAsync } from "../../src/test-utils/env.js";
const MODULE_URL = pathToFileURL(path.resolve("scripts/e2e/lib/plugin-index-sqlite.mjs")).href;
let importCounter = 0;
async function loadPluginIndex(env: Record<string, string> = {}) {
const previous = new Map(Object.keys(env).map((key) => [key, process.env[key]]));
Object.assign(process.env, env);
try {
return await withEnvAsync(env, async () => {
return await import(`${MODULE_URL}?case=${importCounter++}`);
} finally {
for (const [key, value] of previous) {
if (value === undefined) {
delete process.env[key];
} else {
process.env[key] = value;
}
}
}
});
}
function writeLegacyIndex(root: string, text: string) {