























@@ -43,6 +43,7 @@ describe("getCachedPluginJitiLoader", () => {
4343const second = getCachedPluginJitiLoader(params);
44444545expect(second).toBe(first);
46+first("/repo/extensions/demo/index.ts");
4647expect(createJiti).toHaveBeenCalledTimes(1);
4748expect(cache.size).toBe(1);
4849});
@@ -70,6 +71,8 @@ describe("getCachedPluginJitiLoader", () => {
7071});
71727273expect(second).not.toBe(first);
74+first("/repo/dist/extensions/demo/api.ts");
75+second("/repo/dist/extensions/demo/api.ts");
7376expect(createJiti).toHaveBeenNthCalledWith(
74771,
7578"file:///repo/src/plugins/public-surface-loader.ts",
@@ -119,6 +122,7 @@ describe("getCachedPluginJitiLoader", () => {
119122});
120123121124expect(second).toBe(first);
125+first("/repo/extensions/demo/index.ts");
122126expect(createJiti).toHaveBeenCalledTimes(1);
123127expect(createJiti).toHaveBeenCalledWith(
124128"file:///repo/src/plugins/loader.ts",
@@ -161,6 +165,7 @@ describe("getCachedPluginJitiLoader", () => {
161165});
162166163167expect(second).toBe(first);
168+second("/repo/dist/extensions/demo-b/api.js");
164169expect(createJiti).toHaveBeenCalledTimes(1);
165170expect(cache.size).toBe(1);
166171});
@@ -193,6 +198,29 @@ describe("getCachedPluginJitiLoader", () => {
193198tryNative: false,
194199});
195200201+getCachedPluginJitiLoader({
202+ cache,
203+modulePath: "/repo/extensions/demo-a/index.ts",
204+importerUrl: "file:///repo/src/plugins/loader.ts",
205+jitiFilename: "/repo/extensions/demo-a/index.ts",
206+aliasMap: {
207+alpha: "/repo/alpha",
208+beta: "alpha/sub",
209+},
210+tryNative: false,
211+})("/repo/extensions/demo-a/index.ts");
212+getCachedPluginJitiLoader({
213+ cache,
214+modulePath: "/repo/extensions/demo-b/index.ts",
215+importerUrl: "file:///repo/src/plugins/loader.ts",
216+jitiFilename: "/repo/extensions/demo-b/index.ts",
217+aliasMap: {
218+beta: "alpha/sub",
219+alpha: "/repo/alpha",
220+},
221+tryNative: false,
222+})("/repo/extensions/demo-b/index.ts");
223+196224const marker = Symbol.for("pathe:normalizedAlias");
197225const firstAlias = (createJiti.mock.calls[0]?.[1] as { alias?: Record<string, string> }).alias;
198226const secondAlias = (createJiti.mock.calls[1]?.[1] as { alias?: Record<string, string> }).alias;
@@ -231,8 +259,9 @@ describe("getCachedPluginJitiLoader", () => {
231259232260const result = loader("/repo/dist/extensions/demo/api.js") as { loadedFrom: string };
233261expect(result.loadedFrom).toBe("/repo/dist/extensions/demo/api.js");
234-// jiti is created eagerly, but its loader must NOT be invoked for .js
235-// targets that `tryNativeRequireJavaScriptModule` resolves.
262+// Jiti should not be constructed or invoked for .js targets that
263+// `tryNativeRequireJavaScriptModule` resolves.
264+expect(createJiti).not.toHaveBeenCalled();
236265expect(jitiLoader).not.toHaveBeenCalled();
237266// allowWindows must be passed so the native fast path works on Windows too.
238267expect(nativeStub).toHaveBeenCalledWith("/repo/dist/extensions/demo/api.js", {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。