




















@@ -153,6 +153,44 @@ async function waitForFilesystemTimestampTick(): Promise<void> {
153153await new Promise((resolve) => setTimeout(resolve, 50));
154154}
155155156+function snapshotRuntimeMirrorTree(root: string): Record<string, unknown> {
157+const snapshot: Record<string, unknown> = {};
158+const visit = (directory: string) => {
159+for (const entry of fs
160+.readdirSync(directory, { withFileTypes: true })
161+.toSorted((left, right) => left.name.localeCompare(right.name))) {
162+const entryPath = path.join(directory, entry.name);
163+const relativePath = path.relative(root, entryPath).replaceAll(path.sep, "/");
164+const stat = fs.lstatSync(entryPath);
165+if (entry.isDirectory()) {
166+snapshot[relativePath] = {
167+kind: "directory",
168+mtimeMs: stat.mtimeMs,
169+};
170+visit(entryPath);
171+continue;
172+}
173+if (entry.isSymbolicLink()) {
174+snapshot[relativePath] = {
175+kind: "symlink",
176+link: fs.readlinkSync(entryPath),
177+mtimeMs: stat.mtimeMs,
178+};
179+continue;
180+}
181+if (entry.isFile()) {
182+snapshot[relativePath] = {
183+kind: "file",
184+mtimeMs: stat.mtimeMs,
185+size: stat.size,
186+};
187+}
188+}
189+};
190+visit(root);
191+return snapshot;
192+}
193+156194function writeBundledPlugin(params: {
157195id: string;
158196body?: string;
@@ -2033,7 +2071,7 @@ module.exports = {
20332071expect(registry.plugins.find((entry) => entry.id === "discord")?.status).toBe("loaded");
20342072});
203520732036-it("loads dist-runtime wrappers from an external stage dir", async () => {
2074+it("loads dist-runtime wrappers from an external stage dir without rewriting mirrors on reload", async () => {
20372075const packageRoot = makeTempDir();
20382076const stageDir = makeTempDir();
20392077const bundledDir = path.join(packageRoot, "dist-runtime", "extensions");
@@ -2156,22 +2194,12 @@ module.exports = {
21562194false,
21572195);
215821962159-const runtimeMirrorEntry = path.join(
2160-actualInstallRoot,
2161-"dist-runtime",
2162-"extensions",
2163-"acpx",
2164-"index.js",
2165-);
2166-const canonicalMirrorEntry = path.join(
2167-actualInstallRoot,
2168-"dist",
2169-"extensions",
2170-"acpx",
2171-"index.js",
2172-);
2173-const runtimeMirrorStat = fs.statSync(runtimeMirrorEntry);
2174-const canonicalMirrorStat = fs.statSync(canonicalMirrorEntry);
2197+const runtimeMirrorRoot = path.join(actualInstallRoot, "dist-runtime", "extensions", "acpx");
2198+const canonicalMirrorRoot = path.join(actualInstallRoot, "dist", "extensions", "acpx");
2199+const mirrorSnapshot = {
2200+runtime: snapshotRuntimeMirrorTree(runtimeMirrorRoot),
2201+canonical: snapshotRuntimeMirrorTree(canonicalMirrorRoot),
2202+};
2175220321762204await waitForFilesystemTimestampTick();
21772205@@ -2187,8 +2215,10 @@ module.exports = {
21872215const reloadedRecord = reloadedRegistry.plugins.find((entry) => entry.id === "acpx");
21882216expect(reloadedRecord?.error).toBeUndefined();
21892217expect(reloadedRecord?.status).toBe("loaded");
2190-expect(fs.statSync(runtimeMirrorEntry).mtimeMs).toBe(runtimeMirrorStat.mtimeMs);
2191-expect(fs.statSync(canonicalMirrorEntry).mtimeMs).toBe(canonicalMirrorStat.mtimeMs);
2218+expect({
2219+runtime: snapshotRuntimeMirrorTree(runtimeMirrorRoot),
2220+canonical: snapshotRuntimeMirrorTree(canonicalMirrorRoot),
2221+}).toEqual(mirrorSnapshot);
21922222});
2193222321942224it("loads native ESM deps from a layered baseline stage dir", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。