vite-plugin-vanjs 0.1.11 → 0.1.13

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
@@ -4,11 +4,6 @@
4
4
  [![ci](https://github.com/thednp/vite-plugin-vanjs/actions/workflows/ci.yml/badge.svg)](https://github.com/thednp/vite-plugin-vanjs/actions/workflows/ci.yml)
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
- [![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.6.0-brightgreen)](https://github.com/vanjs-org/van)
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
- [![vitest version](https://img.shields.io/badge/vitest-3.2.4-brightgreen)](https://www.vitest.dev/)
11
- [![vite version](https://img.shields.io/badge/vite-6.4.1-brightgreen)](https://vite.dev)
12
7
 
13
8
  A mini meta-framework for [VanJS](https://vanjs.org/) developed around the awesome [vite](https://vite.dev) and tested with [vitest](https://vitest.dev). The plugin comes with a set of modules to streamline your workflow:
14
9
  * ***@vanjs/router*** - one of the most important part of an application which allows you to split code and lazy load page like components with ease, handles both Client Side Rendering (SSR) and Server Side Rendering (CSR) and makes it really easy to work with;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-vanjs",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "author": "thednp",
5
5
  "license": "MIT",
6
6
  "description": "A mini meta-framework for VanJS powered by Vite",
@@ -87,14 +87,14 @@
87
87
  "vanjs-ext": "^0.6.3"
88
88
  },
89
89
  "devDependencies": {
90
- "@types/node": "^22.19.15",
91
- "@vitest/browser": "^3.2.4",
92
- "@vitest/coverage-istanbul": "^3.2.4",
93
- "@vitest/ui": "^3.2.4",
94
- "happy-dom": "^16.8.1",
95
- "typescript": "5.6.2",
96
- "vite": "^6.4.1",
97
- "vitest": "^3.2.4"
90
+ "@types/node": "^25.5.0",
91
+ "@vitest/browser": "^4.1.2",
92
+ "@vitest/coverage-istanbul": "^4.1.2",
93
+ "@vitest/ui": "^4.1.2",
94
+ "happy-dom": "^20.8.9",
95
+ "typescript": "6.0.2",
96
+ "vite": "^8.0.3",
97
+ "vitest": "^4.1.2"
98
98
  },
99
99
  "engines": {
100
100
  "node": ">=20",
package/plugin/index.mjs CHANGED
@@ -1,11 +1,16 @@
1
+ /** @typedef {typeof import("./types").VitePluginVanJS} VitePluginVanJS */
2
+ /** @typedef {import("./types").VanJSPluginOptions} VanJSPluginOptions */
1
3
  /** @typedef {import("vite").ResolvedConfig} ResolvedConfig */
2
4
  /** @typedef {import("./types").PageFile} PageFile */
3
5
  /** @typedef {import("./types").RouteFile} RouteFile */
6
+ /** @typedef {import("vite").BuildAppHook} BuildAppHook */
7
+ /** @typedef {import("vite").TransformResult} TransformResult */
8
+ /** @typedef {import("vite").Plugin} Plugin */
9
+ /** @typedef {ThisParameterType<BuildAppHook>} PluginContext */
4
10
 
5
11
  import { fileURLToPath } from "node:url";
6
12
  import { dirname, join, resolve } from "node:path";
7
13
  import process from "node:process";
8
- import { transformWithEsbuild } from "vite";
9
14
  import { routes } from "../router/routes.mjs";
10
15
  import { generateRoute, getRoutes } from "./helpers.mjs";
11
16
 
@@ -49,6 +54,7 @@ const debugModuleAliases = {
49
54
  "@vanjs/setup": "../setup/index-debug",
50
55
  };
51
56
 
57
+ /** @type {VitePluginVanJS} */
52
58
  export default function VitePluginVanJS(options = {}) {
53
59
  const pluginConfig = { ...pluginDefaults, ...options };
54
60
  const { routesDir } = pluginConfig;
@@ -57,6 +63,10 @@ export default function VitePluginVanJS(options = {}) {
57
63
  let config;
58
64
  /** @type {RouteFile[] | null} */
59
65
  let routeCache = null;
66
+ /** @type {PluginContext} */
67
+ let context;
68
+ let viteVersion = "8.0.0";
69
+ let isOxc = true;
60
70
 
61
71
  const virtualModuleId = "virtual:@vanjs/routes";
62
72
  const resolvedVirtualModuleId = "\0" + virtualModuleId;
@@ -64,6 +74,12 @@ export default function VitePluginVanJS(options = {}) {
64
74
  return {
65
75
  name: "vanjs",
66
76
  enforce: "pre",
77
+ buildStart() {
78
+ context = this;
79
+ viteVersion = context.meta?.viteVersion[0];
80
+ isOxc = Number(viteVersion) >= 8;
81
+ },
82
+ // @ts-expect-error - this is temporary esbuild will be
67
83
  config() {
68
84
  return {
69
85
  optimizeDeps: {
@@ -89,17 +105,29 @@ export default function VitePluginVanJS(options = {}) {
89
105
  "@vanjs/jsx": toAbsolute("../jsx"),
90
106
  },
91
107
  },
92
- esbuild: {
93
- jsx: "automatic",
94
- jsxImportSource: "@vanjs/jsx",
95
- },
108
+ ...(
109
+ isOxc
110
+ ? {
111
+ oxc: {
112
+ include: /\.(jsx?|tsx?)$/,
113
+ jsx: {
114
+ runtime: "preserve", // Options: 'automatic', 'classic', 'preserve'
115
+ importSource: "@vanjs/jsx", // Default import source
116
+ },
117
+ },
118
+ }
119
+ : {
120
+ esbuild: {
121
+ jsx: "automatic",
122
+ jsxImportSource: "@vanjs/jsx",
123
+ },
124
+ }
125
+ ),
96
126
  };
97
127
  },
98
- /** @param {import("vite").ResolvedConfig} resolvedConfig */
99
128
  configResolved(resolvedConfig) {
100
129
  config = resolvedConfig;
101
130
  },
102
- /** @param {import("vite").ViteDevServer} server */
103
131
  configureServer(server) {
104
132
  // Watch routes directory
105
133
  const pagesPath = join(config.root, routesDir);
@@ -129,7 +157,6 @@ export default function VitePluginVanJS(options = {}) {
129
157
  server.watcher.on("unlinkDir", changeHandler);
130
158
  server.watcher.on("change", changeHandler);
131
159
  },
132
- /** @type {(source: string, importer: string | undefined, ops: { ssr: boolean }) => string | null} */
133
160
  resolveId(source, importer, { ssr }) {
134
161
  // Handle virtual module
135
162
  if (source === virtualModuleId) {
@@ -171,11 +198,12 @@ export default function VitePluginVanJS(options = {}) {
171
198
  aliases = { ...aliases, ...debugModuleAliases };
172
199
  }
173
200
  // Check if the source is a known module
201
+ /* istanbul ignore next @preserve */
174
202
  const matchedSource =
175
203
  isResolvedVanFile || (source === "vanjs-core" && !isSetupFile)
176
204
  ? "@vanjs/van"
177
205
  : isResolvedVanXFile ||
178
- (source === "vanjs-ext" && /* istanbul ignore next */
206
+ (source === "vanjs-ext" &&
179
207
  !isImportedVanXFile)
180
208
  ? "@vanjs/vanX"
181
209
  : isResolvedSetupFile && (!ssr && isSetupFile || ssr && !isSetupFile)
@@ -189,7 +217,6 @@ export default function VitePluginVanJS(options = {}) {
189
217
 
190
218
  return null;
191
219
  },
192
- /** @type {(id: string, ops: { ssr: boolean }) => Promise<({ code: string, map: null } | null)>} */
193
220
  async load(id, ops) {
194
221
  // istanbul ignore else
195
222
  if (id === resolvedVirtualModuleId) {
@@ -212,21 +239,31 @@ routes.length = 0;
212
239
  // Register routes
213
240
  ${currentRoutes.map(generateRoute).join("\n")}
214
241
  ${
215
- ops.ssr && currentRoutes.length
242
+ (ops && ops.ssr && currentRoutes.length)
216
243
  ? `console.log(\`🍦 @vanjs/router registered ${currentRoutes.length} routes.\`)`
217
- : /* istanbul ignore next - satisfied */ ""
244
+ : /* istanbul ignore next @preserve */ ""
218
245
  }
219
246
  `;
220
247
 
221
- const result = await transformWithEsbuild(
222
- routesScript,
223
- id,
224
- { loader: "js" },
225
- );
248
+ const vite = await import("vite");
249
+ const transformer = isOxc ? "transformWithOxc" : "transformWithEsbuild";
250
+ const langProp = isOxc ? "lang" : "loader";
251
+ // const mapProp = isOxc ? "source_map" : "sourcemap";
252
+
253
+ const result = await vite[transformer](routesScript, id, {
254
+ [langProp]: "js",
255
+ sourcemap: true,
256
+ });
226
257
 
227
258
  return {
228
259
  code: result.code,
229
- map: null,
260
+ map: result.map
261
+ ? (
262
+ typeof result.map === "string"
263
+ ? JSON.parse(result.map)
264
+ : /* istanbul ignore next @preserve */ result.map
265
+ )
266
+ : /* istanbul ignore next @preserve */ null,
230
267
  };
231
268
  }
232
269
  return null;
package/plugin/types.d.ts CHANGED
@@ -5,15 +5,15 @@ export * from "../router/types.d.ts";
5
5
  export * from "../meta/types.d.ts";
6
6
  export * from "../server/types.d.ts";
7
7
  export * from "../client/types.d.ts";
8
- import type { PluginOption } from "vite";
8
+ import type { Plugin } from "vite";
9
9
 
10
10
  export type VanJSPluginOptions = {
11
- routesDir: string;
12
- extensions: string[];
11
+ routesDir?: string;
12
+ extensions?: string[];
13
13
  };
14
14
 
15
15
  export declare const VitePluginVanJS: (
16
16
  config?: VanJSPluginOptions,
17
- ) => PluginOption<VanJSPluginOptions>;
17
+ ) => Plugin<VanJSPluginOptions>;
18
18
 
19
19
  export default VitePluginVanJS;
package/tsconfig.json CHANGED
@@ -2,8 +2,6 @@
2
2
  // https://janessagarrow.com/blog/typescript-and-esbuild/
3
3
  "compilerOptions": {
4
4
  "lib": ["DOM", "ESNext", "DOM.Iterable"],
5
- "rootDir": "./",
6
- "baseUrl": "./",
7
5
  "module": "ESNext",
8
6
  "target": "ESNext",
9
7
  "moduleResolution": "Bundler",