vite-plugin-vanjs 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/plugin/index.mjs +22 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vanjs",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "author": "thednp",
5
5
  "license": "MIT",
6
6
  "description": "A mini meta-framework for VanJS powered by Vite",
package/plugin/index.mjs CHANGED
@@ -41,7 +41,8 @@ export default function VitePluginVanJS(options = {}) {
41
41
  include: [
42
42
  "vanjs-core",
43
43
  "vanjs-ext",
44
- "mini-van-plate",
44
+ "mini-van-plate/van-plate",
45
+ "mini-van-plate/shared",
45
46
  ],
46
47
  },
47
48
  ssr: {
@@ -101,17 +102,22 @@ export default function VitePluginVanJS(options = {}) {
101
102
  },
102
103
  /** @type {(source: string, importer: string | undefined, ops: { ssr: boolean }) => string | null} */
103
104
  resolveId(source, importer, ops) {
105
+ // istanbul ignore else
106
+ if (source === virtualModuleId) {
107
+ return resolvedVirtualModuleId;
108
+ }
104
109
  const isVanXFile = importer &&
105
110
  /vanjs-ext[\/\\]src[\/\\]van-x/.test(importer);
106
111
  const isSetupFile = importer &&
107
112
  /vite-plugin-vanjs[\/\\]setup/.test(importer);
108
113
  const isProduction = process.env.NODE_ENV === "production";
114
+ const isTest = process.env.NODE_ENV === "test";
109
115
  const isJSXImport = source.includes("/vite-plugin-vanjs/jsx/jsx") ||
110
116
  importer?.includes("/vite-plugin-vanjs/jsx/jsx.mjs");
111
117
 
112
118
  const resolvedVan = toAbsolute(
113
119
  ops.ssr ? "../setup/van-ssr.mjs" : (isJSXImport || isProduction ||
114
- config.mode === "test")
120
+ isTest)
115
121
  ? "../setup/van.mjs"
116
122
  : "../setup/van-debug.mjs",
117
123
  );
@@ -121,19 +127,28 @@ export default function VitePluginVanJS(options = {}) {
121
127
  const setupResolved = toAbsolute(
122
128
  ops.ssr
123
129
  ? "../setup/index-ssr.mjs"
124
- : (isProduction || config.mode === "test")
130
+ : (isProduction || isTest)
125
131
  ? "../setup/index.mjs"
126
132
  : "../setup/index-debug.mjs",
127
133
  );
128
134
 
129
135
  // Resolve early when source already resolved. EG: @vanjs/van
130
- if (source === setupResolved || setupResolved.includes(source)) {
136
+ if (
137
+ (ops.ssr || isTest) &&
138
+ (source === setupResolved || setupResolved.includes(source))
139
+ ) {
131
140
  return setupResolved;
132
141
  }
133
- if (source === resolvedVan || resolvedVan.includes(source)) {
142
+ if (
143
+ (ops.ssr || isTest) &&
144
+ (source === resolvedVan || resolvedVan.includes(source))
145
+ ) {
134
146
  return resolvedVan;
135
147
  }
136
- if (source === resolvedVanX || resolvedVanX.includes(source)) {
148
+ if (
149
+ (ops.ssr || isTest) &&
150
+ (source === resolvedVanX || resolvedVanX.includes(source))
151
+ ) {
137
152
  return resolvedVanX;
138
153
  }
139
154
 
@@ -152,10 +167,7 @@ export default function VitePluginVanJS(options = {}) {
152
167
  return resolvedVanX;
153
168
  }
154
169
  }
155
- // istanbul ignore else
156
- if (source === virtualModuleId) {
157
- return resolvedVirtualModuleId;
158
- }
170
+
159
171
  return null;
160
172
  },
161
173
  /** @type {(id: string, ops: { ssr: boolean }) => Promise<({ code: string, map: null } | null)>} */