@typed/virtual-modules-vite 1.0.0-beta.1 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"vitePlugin.d.ts","sourceRoot":"","sources":["../src/vitePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAK9F,MAAM,WAAW,+BAA+B;IAC9C;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IACzC;;OAEG;IACH,QAAQ,CAAC,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;IAC7D;;OAEG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;CAChC;AAUD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAoDzF"}
1
+ {"version":3,"file":"vitePlugin.d.ts","sourceRoot":"","sources":["../src/vitePlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAK9F,MAAM,WAAW,+BAA+B;IAC9C;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IACzC;;OAEG;IACH,QAAQ,CAAC,wBAAwB,CAAC,EAAE,wBAAwB,CAAC;IAC7D;;OAEG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;CAChC;AAUD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CA2DzF"}
@@ -23,13 +23,20 @@ export function virtualModulesVitePlugin(options) {
23
23
  if (!importer) {
24
24
  return null;
25
25
  }
26
+ let effectiveImporter = importer;
27
+ if (isVirtualId(importer)) {
28
+ const decoded = decodeVirtualId(importer);
29
+ if (decoded && validateDecodedPayload(decoded.id, decoded.importer)) {
30
+ effectiveImporter = decoded.importer;
31
+ }
32
+ }
26
33
  const result = resolver.resolveModule({
27
34
  id,
28
- importer,
35
+ importer: effectiveImporter,
29
36
  createTypeInfoApiSession,
30
37
  });
31
38
  if (result.status === "resolved") {
32
- return encodeVirtualId(id, importer);
39
+ return encodeVirtualId(id, effectiveImporter);
33
40
  }
34
41
  if (result.status === "error" && warnOnError) {
35
42
  console.warn(`[${PLUGIN_NAME}] ${result.diagnostic.pluginName}: ${result.diagnostic.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typed/virtual-modules-vite",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -11,19 +11,15 @@
11
11
  "publishConfig": {
12
12
  "access": "public"
13
13
  },
14
- "scripts": {
15
- "build": "[ -d dist ] || rm -f tsconfig.tsbuildinfo; tsc",
16
- "test": "vitest run --passWithNoTests"
17
- },
18
14
  "dependencies": {
19
- "@typed/virtual-modules": "workspace:*"
15
+ "@typed/virtual-modules": "1.0.0-beta.2"
20
16
  },
21
17
  "devDependencies": {
22
- "@typed/virtual-modules": "workspace:*",
23
18
  "@types/node": "^25.3.0",
24
- "typescript": "catalog:",
19
+ "typescript": "5.9.3",
25
20
  "vite": "^7.3.1",
26
- "vitest": "catalog:"
21
+ "vitest": "4.0.18",
22
+ "@typed/virtual-modules": "1.0.0-beta.2"
27
23
  },
28
24
  "peerDependencies": {
29
25
  "vite": ">=5.0.0"
@@ -31,5 +27,9 @@
31
27
  "files": [
32
28
  "dist",
33
29
  "src"
34
- ]
35
- }
30
+ ],
31
+ "scripts": {
32
+ "build": "[ -d dist ] || rm -f tsconfig.tsbuildinfo; tsc",
33
+ "test": "vitest run --passWithNoTests"
34
+ }
35
+ }
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { PluginManager } from "@typed/virtual-modules";
3
+ import { encodeVirtualId } from "./encodeVirtualId.js";
3
4
  import { virtualModulesVitePlugin } from "./vitePlugin.js";
4
5
 
5
6
  type ResolveId = (specifier: string, importer: string | undefined) => string | null;
@@ -58,4 +59,29 @@ describe("virtualModulesVitePlugin", () => {
58
59
  const code = typeof result === "string" ? result : result?.code;
59
60
  expect(code).toBe("export const x = 1;");
60
61
  });
62
+
63
+ it("resolveId with encoded virtual id as importer resolves virtual-to-virtual import", () => {
64
+ const manager = new PluginManager([
65
+ {
66
+ name: "virtual-a",
67
+ shouldResolve: (id) => id === "virtual:a",
68
+ build: () => `import { x } from "virtual:b"; export { x };`,
69
+ },
70
+ {
71
+ name: "virtual-b",
72
+ shouldResolve: (id) => id === "virtual:b",
73
+ build: () => "export const x = 1;",
74
+ },
75
+ ]);
76
+ const plugin = virtualModulesVitePlugin({ resolver: manager });
77
+ const resolveId = plugin.resolveId! as ResolveId;
78
+ const load = plugin.load! as Load;
79
+ const rootImporter = "/app/main.ts";
80
+ const encodedA = encodeVirtualId("virtual:a", rootImporter);
81
+ const resolvedB = resolveId("virtual:b", encodedA);
82
+ expect(resolvedB).not.toBeNull();
83
+ const result = load(resolvedB as string);
84
+ const code = typeof result === "string" ? result : result?.code;
85
+ expect(code).toBe("export const x = 1;");
86
+ });
61
87
  });
package/src/vitePlugin.ts CHANGED
@@ -42,13 +42,20 @@ export function virtualModulesVitePlugin(options: VirtualModulesVitePluginOption
42
42
  if (!importer) {
43
43
  return null;
44
44
  }
45
+ let effectiveImporter = importer;
46
+ if (isVirtualId(importer)) {
47
+ const decoded = decodeVirtualId(importer);
48
+ if (decoded && validateDecodedPayload(decoded.id, decoded.importer)) {
49
+ effectiveImporter = decoded.importer;
50
+ }
51
+ }
45
52
  const result = resolver.resolveModule({
46
53
  id,
47
- importer,
54
+ importer: effectiveImporter,
48
55
  createTypeInfoApiSession,
49
56
  });
50
57
  if (result.status === "resolved") {
51
- return encodeVirtualId(id, importer);
58
+ return encodeVirtualId(id, effectiveImporter);
52
59
  }
53
60
  if (result.status === "error" && warnOnError) {
54
61
  console.warn(