vite-plugin-vanjs 0.1.2 → 0.1.3

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.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![NPM Version](https://img.shields.io/npm/v/vite-plugin-vanjs.svg)](https://www.npmjs.com/package/vite-plugin-vanjs)
6
6
  [![NPM Downloads](https://img.shields.io/npm/dm/vite-plugin-vanjs.svg)](http://npm-stat.com/charts.html?package=vite-plugin-vanjs)
7
7
  [![typescript version](https://img.shields.io/badge/typescript-5.6.2-brightgreen)](https://www.typescriptlang.org/)
8
- [![vanjs-core version](https://img.shields.io/badge/vanjs--core-1.5.3-brightgreen)](https://github.com/vanjs-org/van)
8
+ [![vanjs-core version](https://img.shields.io/badge/vanjs--core-1.5.5-brightgreen)](https://github.com/vanjs-org/van)
9
9
  [![mini-van-plate version](https://img.shields.io/badge/mini--van--plate-0.6.3-brightgreen)](https://github.com/vanjs-org/mini-van-plate)
10
10
  [![vitest version](https://img.shields.io/badge/vitest-3.1.2-brightgreen)](https://www.vitest.dev/)
11
11
  [![vite version](https://img.shields.io/badge/vite-6.3.3-brightgreen)](https://vite.dev)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vanjs",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "author": "thednp",
5
5
  "license": "MIT",
6
6
  "description": "A mini meta-framework for VanJS powered by Vite",
@@ -83,11 +83,11 @@
83
83
  "dependencies": {
84
84
  "csstype": "^3.1.3",
85
85
  "mini-van-plate": "^0.6.3",
86
- "vanjs-core": "^1.5.3",
86
+ "vanjs-core": "^1.5.5",
87
87
  "vanjs-ext": "^0.6.2"
88
88
  },
89
89
  "devDependencies": {
90
- "@types/node": "^22.15.2",
90
+ "@types/node": "^22.15.3",
91
91
  "@vitest/browser": "^3.1.2",
92
92
  "@vitest/coverage-istanbul": "^3.1.2",
93
93
  "@vitest/ui": "^3.1.2",
package/plugin/index.mjs CHANGED
@@ -19,6 +19,49 @@ const pluginDefaults = {
19
19
  extensions: [".tsx", ".jsx", ".ts", ".js"],
20
20
  };
21
21
 
22
+ // Aliases coming from plugin.config()
23
+ // const resolvedVan = toAbsolute("../setup/van");
24
+ // const resolvedVanX = toAbsolute("../setup/vanX");
25
+ // const resolvedSetup = toAbsolute("../setup/index");
26
+
27
+ // Define module mapping configuration
28
+ const moduleAliases = {
29
+ // Core modules
30
+ "@vanjs/van": "../setup/van",
31
+ // [resolvedVan]: "../setup/van",
32
+ "@vanjs/vanX": "../setup/vanX",
33
+ // [resolvedVanX]: "../setup/vanX",
34
+
35
+ // Setup modules
36
+ "@vanjs/setup": "../setup/index",
37
+ // [resolvedSetup]: "../setup/index",
38
+
39
+ // Other modules
40
+ "@vanjs/client": "../client",
41
+ "@vanjs/server": "../server",
42
+ "@vanjs/meta": "../meta",
43
+ "@vanjs/router": "../router",
44
+ "@vanjs/jsx": "../jsx",
45
+ };
46
+
47
+ // SSR specific module mappings
48
+ const ssrModuleAliases = {
49
+ "@vanjs/van": "../setup/van-ssr",
50
+ // [resolvedVan]: "../setup/van-ssr",
51
+ "@vanjs/vanX": "../setup/vanX-ssr",
52
+ // [resolvedVanX]: "../setup/vanX-ssr",
53
+ "@vanjs/setup": "../setup/index-ssr",
54
+ // [resolvedSetup]: "../setup/index-ssr",
55
+ };
56
+
57
+ // Debug specific module mappings (development only)
58
+ const debugModuleAliases = {
59
+ "@vanjs/van": "../setup/van-debug",
60
+ // [resolvedVan]: "../setup/van-debug",
61
+ "@vanjs/setup": "../setup/index-debug",
62
+ // [resolvedSetup]: "../setup/index-debug",
63
+ };
64
+
22
65
  export default function VitePluginVanJS(options = {}) {
23
66
  const pluginConfig = { ...pluginDefaults, ...options };
24
67
  const { routesDir } = pluginConfig;
@@ -101,71 +144,67 @@ export default function VitePluginVanJS(options = {}) {
101
144
  server.watcher.on("change", changeHandler);
102
145
  },
103
146
  /** @type {(source: string, importer: string | undefined, ops: { ssr: boolean }) => string | null} */
104
- resolveId(source, importer, ops) {
105
- // istanbul ignore else
147
+ resolveId(source, importer, { ssr }) {
148
+ // Handle virtual module
106
149
  if (source === virtualModuleId) {
107
150
  return resolvedVirtualModuleId;
108
151
  }
109
- const isVanXFile = importer &&
110
- /vanjs-ext[\/\\]src[\/\\]van-x/.test(importer);
111
- const isSetupFile = importer &&
112
- /vite-plugin-vanjs[\/\\]setup/.test(importer);
152
+
153
+ // Get the appropriate module aliases based on environment
113
154
  const isProduction = process.env.NODE_ENV === "production";
114
155
  const isTest = process.env.NODE_ENV === "test";
115
- const isJSXImport = source.includes("/vite-plugin-vanjs/jsx/jsx") ||
116
- importer?.includes("/vite-plugin-vanjs/jsx/jsx.mjs");
117
-
118
- const resolvedVan = toAbsolute(
119
- ops.ssr ? "../setup/van-ssr.mjs" : (isJSXImport || isProduction ||
120
- isTest)
121
- ? "../setup/van.mjs"
122
- : "../setup/van-debug.mjs",
123
- );
124
- const resolvedVanX = toAbsolute(
125
- ops.ssr ? "../setup/vanX-ssr.mjs" : "../setup/vanX.mjs",
156
+ const isSetupFile = typeof importer === "string" &&
157
+ importer.includes("vite-plugin-vanjs/setup");
158
+ // const isVanXFile = typeof importer === "string" &&
159
+ // importer.includes("vanjs-ext/src/van-x");
160
+ const isImportedVanXFile = typeof importer === "string" &&
161
+ importer.includes("vite-plugin-vanjs/setup/vanX");
162
+ // const isImportedVanFile = !isImportedVanXFile && typeof importer === "string" &&
163
+ // importer.includes("vite-plugin-vanjs/setup/van");
164
+ // const isImportedSetupFile = typeof importer === "string" &&
165
+ // importer.includes("vite-plugin-vanjs/setup/index");
166
+ const isResolvedVanXFile = source.includes(
167
+ "vite-plugin-vanjs/setup/vanX",
126
168
  );
127
- const setupResolved = toAbsolute(
128
- ops.ssr
129
- ? "../setup/index-ssr.mjs"
130
- : (isProduction || isTest)
131
- ? "../setup/index.mjs"
132
- : "../setup/index-debug.mjs",
169
+ const isResolvedVanFile = !isResolvedVanXFile &&
170
+ source.includes("vite-plugin-vanjs/setup/van");
171
+ const isResolvedSetupFile = source.includes(
172
+ "vite-plugin-vanjs/setup/index",
133
173
  );
134
-
135
- // Resolve early when source already resolved. EG: @vanjs/van
136
- if (
137
- (ops.ssr || isTest) &&
138
- (source === setupResolved || setupResolved.includes(source))
139
- ) {
140
- return setupResolved;
141
- }
142
- if (
143
- (ops.ssr || isTest) &&
144
- (source === resolvedVan || resolvedVan.includes(source))
145
- ) {
146
- return resolvedVan;
147
- }
148
- if (
149
- (ops.ssr || isTest) &&
150
- (source === resolvedVanX || resolvedVanX.includes(source))
151
- ) {
152
- return resolvedVanX;
174
+ const isJSXImport = source.includes("/vite-plugin-vanjs/jsx/jsx") ||
175
+ (typeof importer === "string" &&
176
+ importer.includes("/vite-plugin-vanjs/jsx/jsx.mjs"));
177
+ const isDebugImport = !ssr && typeof importer === "string" &&
178
+ importer.includes("/src/van.debug.js") &&
179
+ source.includes("/van.js");
180
+ let aliases = moduleAliases;
181
+
182
+ // Handle special case for debug
183
+ if (isDebugImport) {
184
+ return toAbsolute("../setup/van.mjs");
153
185
  }
154
186
 
155
- // istanbul ignore else
156
- if (!isSetupFile && !isVanXFile) {
157
- if (source === "@vanjs/setup") {
158
- return setupResolved;
159
- }
160
- if (importer?.endsWith("debug.js") && source.endsWith("/van.js")) {
161
- return toAbsolute("../setup/van.mjs");
162
- }
163
- if (source === "vanjs-core" || source === "@vanjs/van") {
164
- return resolvedVan;
165
- }
166
- if (source === "vanjs-ext" || source === "@vanjs/vanX") {
167
- return resolvedVanX;
168
- }
187
+ // Select appropriate aliases based on environment
188
+ if (ssr) {
189
+ aliases = { ...aliases, ...ssrModuleAliases };
190
+ } else if (!isProduction && !isTest && !isJSXImport) {
191
+ aliases = { ...aliases, ...debugModuleAliases };
192
+ }
193
+ // Check if the source is a known module
194
+ const matchedSource =
195
+ isResolvedVanFile || (source === "vanjs-core" && !isSetupFile)
196
+ ? "@vanjs/van"
197
+ : isResolvedVanXFile ||
198
+ (source === "vanjs-ext" && /* istanbul ignore next */
199
+ !isImportedVanXFile)
200
+ ? "@vanjs/vanX"
201
+ : isResolvedSetupFile && (!ssr && isSetupFile || ssr && !isSetupFile)
202
+ ? "@vanjs/setup"
203
+ : null;
204
+ const resolvedPath = matchedSource ? aliases[matchedSource] : null;
205
+
206
+ if (resolvedPath) {
207
+ return toAbsolute(resolvedPath + ".mjs");
169
208
  }
170
209
 
171
210
  return null;