























@@ -406,7 +406,6 @@ describe("getCachedPluginModuleLoader", () => {
406406// allowWindows must be passed so the native fast path works on Windows too.
407407expect(nativeStub).toHaveBeenCalledWith("/repo/dist/extensions/demo/api.js", {
408408allowWindows: true,
409-fallbackOnMissingDependency: true,
410409});
411410expect(getPluginModuleLoaderStats()).toMatchObject({
412411calls: 1,
@@ -417,6 +416,48 @@ describe("getCachedPluginModuleLoader", () => {
417416});
418417});
419418419+it("does not source-transform fallback after native loading reaches a missing dependency", async () => {
420+const fromSourceTransformer = vi.fn();
421+const createJiti = vi.fn(() => fromSourceTransformer);
422+vi.doMock("jiti", () => ({ createJiti }));
423+const missingDependency = Object.assign(new Error("Cannot find module 'missing-dep'"), {
424+code: "MODULE_NOT_FOUND",
425+});
426+const nativeStub = vi.fn(() => {
427+throw missingDependency;
428+});
429+vi.doMock("./native-module-require.js", () => ({
430+isJavaScriptModulePath: () => true,
431+tryNativeRequireJavaScriptModule: nativeStub,
432+}));
433+const { getCachedPluginModuleLoader, getPluginModuleLoaderStats } = await importFreshModule<
434+typeof import("./plugin-module-loader-cache.js")
435+>(import.meta.url, "./plugin-module-loader-cache.js?scope=native-missing-dependency");
436+437+const cache = new Map();
438+const loader = getCachedPluginModuleLoader({
439+ cache,
440+modulePath: "/repo/dist/extensions/demo/api.js",
441+importerUrl: "file:///repo/src/plugins/public-surface-loader.ts",
442+loaderFilename: "file:///repo/src/plugins/public-surface-loader.ts",
443+createLoader: asPluginModuleLoaderFactory(createJiti),
444+});
445+446+expect(() => loader("/repo/dist/extensions/demo/api.js")).toThrow("missing-dep");
447+expect(createJiti).not.toHaveBeenCalled();
448+expect(fromSourceTransformer).not.toHaveBeenCalled();
449+expect(nativeStub).toHaveBeenCalledWith("/repo/dist/extensions/demo/api.js", {
450+allowWindows: true,
451+});
452+expect(getPluginModuleLoaderStats()).toMatchObject({
453+calls: 1,
454+nativeHits: 0,
455+nativeMisses: 0,
456+sourceTransformFallbacks: 0,
457+sourceTransformForced: 0,
458+});
459+});
460+420461it("falls back to source transform when the native-require helper declines", async () => {
421462const fromSourceTransformer = vi.fn(() => ({ fromSourceTransform: true }));
422463const createJiti = vi.fn(() => fromSourceTransformer);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。