vite-plugin-veloz 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Julio Carneiro and Veloz contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,18 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # vite-plugin-veloz
2
+
3
+ Vite plugin for [Veloz](https://github.com/juliocarneiro/veloz): configures JSX for `@velozjs/dom`, and during SSR (dev `ssrLoadModule` and `vite build --ssr`) resolves your app's imports of `@velozjs/dom` to `@velozjs/ssr`, so the same components render to HTML.
4
+
5
+ ```bash
6
+ npm install -D vite-plugin-veloz
7
+ ```
8
+
9
+ ```ts
10
+ import { defineConfig } from 'vite';
11
+ import veloz from 'vite-plugin-veloz';
12
+
13
+ export default defineConfig({ plugins: [veloz()] });
14
+ ```
15
+
16
+ Option: `exclude`, package names whose imports of `@velozjs/dom` should not be redirected during SSR (packages named `@velozjs/*` are always left alone).
17
+
18
+ Documentation and the other packages: [github.com/juliocarneiro/veloz](https://github.com/juliocarneiro/veloz). MIT license.
@@ -0,0 +1,17 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface VelozPluginOptions {
4
+ /**
5
+ * Package names whose imports of `@velozjs/dom` are left alone during SSR.
6
+ * Packages named `@velozjs/*` are always excluded.
7
+ */
8
+ exclude?: string[];
9
+ }
10
+ /**
11
+ * Veloz for Vite: compiles JSX with the `@velozjs/dom` runtime, and during SSR
12
+ * (dev `ssrLoadModule` and `vite build --ssr`) resolves app imports of
13
+ * `@velozjs/dom` to `@velozjs/ssr`, so the same components render to HTML.
14
+ */
15
+ declare function velozPlugin(options?: VelozPluginOptions): Plugin;
16
+
17
+ export { type VelozPluginOptions, velozPlugin as default, velozPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,66 @@
1
+ import { existsSync, readFileSync } from 'fs';
2
+ import { dirname, join } from 'path';
3
+
4
+ // src/index.ts
5
+ var SSR_REDIRECTS = {
6
+ "@velozjs/dom": "@velozjs/ssr",
7
+ "@velozjs/dom/jsx-runtime": "@velozjs/ssr/jsx-runtime",
8
+ "@velozjs/dom/jsx-dev-runtime": "@velozjs/ssr/jsx-dev-runtime"
9
+ };
10
+ var packageNameCache = /* @__PURE__ */ new Map();
11
+ function packageNameOf(file) {
12
+ const path = file.split("?")[0].replace(/^\0/, "");
13
+ let dir = dirname(path);
14
+ const visited = [];
15
+ let name = null;
16
+ for (; ; ) {
17
+ const cached = packageNameCache.get(dir);
18
+ if (cached !== void 0) {
19
+ name = cached;
20
+ break;
21
+ }
22
+ visited.push(dir);
23
+ const pkg = join(dir, "package.json");
24
+ if (existsSync(pkg)) {
25
+ try {
26
+ name = JSON.parse(readFileSync(pkg, "utf8")).name ?? null;
27
+ } catch {
28
+ name = null;
29
+ }
30
+ break;
31
+ }
32
+ const parent = dirname(dir);
33
+ if (parent === dir) break;
34
+ dir = parent;
35
+ }
36
+ for (const d of visited) packageNameCache.set(d, name);
37
+ return name;
38
+ }
39
+ function velozPlugin(options = {}) {
40
+ const exclude = new Set(options.exclude ?? []);
41
+ const isFrameworkModule = (importer) => {
42
+ if (!importer) return false;
43
+ const name = packageNameOf(importer);
44
+ return name != null && (name.startsWith("@velozjs/") || exclude.has(name));
45
+ };
46
+ return {
47
+ name: "vite-plugin-veloz",
48
+ enforce: "pre",
49
+ config() {
50
+ return {
51
+ esbuild: { jsx: "automatic", jsxImportSource: "@velozjs/dom" },
52
+ resolve: { dedupe: ["@velozjs/core", "@velozjs/dom", "@velozjs/css", "@velozjs/ssr"] }
53
+ };
54
+ },
55
+ async resolveId(source, importer, resolveOptions) {
56
+ if (!resolveOptions?.ssr) return null;
57
+ const target = SSR_REDIRECTS[source];
58
+ if (!target || isFrameworkModule(importer)) return null;
59
+ return this.resolve(target, importer, { ...resolveOptions, skipSelf: true });
60
+ }
61
+ };
62
+ }
63
+
64
+ export { velozPlugin as default, velozPlugin };
65
+ //# sourceMappingURL=index.js.map
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAaA,IAAM,aAAA,GAAwC;AAAA,EAC5C,cAAA,EAAgB,cAAA;AAAA,EAChB,0BAAA,EAA4B,0BAAA;AAAA,EAC5B,8BAAA,EAAgC;AAClC,CAAA;AAEA,IAAM,gBAAA,uBAAuB,GAAA,EAA2B;AAGxD,SAAS,cAAc,IAAA,EAA6B;AAClD,EAAA,MAAM,IAAA,GAAO,KAAK,KAAA,CAAM,GAAG,EAAE,CAAC,CAAA,CAAE,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AACjD,EAAA,IAAI,GAAA,GAAM,QAAQ,IAAI,CAAA;AACtB,EAAA,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,CAAA;AAAA,EAC1E,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,mBAAA;AAAA,IACN,OAAA,EAAS,KAAA;AAAA,IAET,MAAA,GAAS;AACP,MAAA,OAAO;AAAA,QACL,OAAA,EAAS,EAAE,GAAA,EAAK,WAAA,EAAa,iBAAiB,cAAA,EAAe;AAAA,QAC7D,OAAA,EAAS,EAAE,MAAA,EAAQ,CAAC,iBAAiB,cAAA,EAAgB,cAAA,EAAgB,cAAc,CAAA;AAAE,OACvF;AAAA,IACF,CAAA;AAAA,IAEA,MAAM,SAAA,CAAU,MAAA,EAAQ,QAAA,EAAU,cAAA,EAAgB;AAChD,MAAA,IAAI,CAAC,cAAA,EAAgB,GAAA,EAAK,OAAO,IAAA;AACjC,MAAA,MAAM,MAAA,GAAS,cAAc,MAAM,CAAA;AACnC,MAAA,IAAI,CAAC,MAAA,IAAU,iBAAA,CAAkB,QAAQ,GAAG,OAAO,IAAA;AACnD,MAAA,OAAO,IAAA,CAAK,QAAQ,MAAA,EAAQ,QAAA,EAAU,EAAE,GAAG,cAAA,EAAgB,QAAA,EAAU,IAAA,EAAM,CAAA;AAAA,IAC7E;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\r\nimport { dirname, join } from 'node:path';\r\nimport type { Plugin } from 'vite';\r\n\r\nexport interface VelozPluginOptions {\r\n /**\r\n * Package names whose imports of `@velozjs/dom` are left alone during SSR.\r\n * Packages named `@velozjs/*` are always excluded.\r\n */\r\n exclude?: string[];\r\n}\r\n\r\n/** During SSR, these client modules resolve to their server counterparts. */\r\nconst SSR_REDIRECTS: Record<string, string> = {\r\n '@velozjs/dom': '@velozjs/ssr',\r\n '@velozjs/dom/jsx-runtime': '@velozjs/ssr/jsx-runtime',\r\n '@velozjs/dom/jsx-dev-runtime': '@velozjs/ssr/jsx-dev-runtime',\r\n};\r\n\r\nconst packageNameCache = new Map<string, string | null>();\r\n\r\n/** Name of the nearest package.json above `file` (cached per directory). */\r\nfunction packageNameOf(file: string): string | null {\r\n const path = file.split('?')[0].replace(/^\\0/, '');\r\n let dir = dirname(path);\r\n const visited: string[] = [];\r\n let name: string | null = null;\r\n\r\n for (;;) {\r\n const cached = packageNameCache.get(dir);\r\n if (cached !== undefined) {\r\n name = cached;\r\n break;\r\n }\r\n visited.push(dir);\r\n const pkg = join(dir, 'package.json');\r\n if (existsSync(pkg)) {\r\n try {\r\n name = (JSON.parse(readFileSync(pkg, 'utf8')) as { name?: string }).name ?? null;\r\n } catch {\r\n name = null;\r\n }\r\n break;\r\n }\r\n const parent = dirname(dir);\r\n if (parent === dir) break;\r\n dir = parent;\r\n }\r\n\r\n for (const d of visited) packageNameCache.set(d, name);\r\n return name;\r\n}\r\n\r\n/**\r\n * Veloz for Vite: compiles JSX with the `@velozjs/dom` runtime, and during SSR\r\n * (dev `ssrLoadModule` and `vite build --ssr`) resolves app imports of\r\n * `@velozjs/dom` to `@velozjs/ssr`, so the same components render to HTML.\r\n */\r\nexport default function velozPlugin(options: VelozPluginOptions = {}): Plugin {\r\n const exclude = new Set(options.exclude ?? []);\r\n\r\n const isFrameworkModule = (importer: string | undefined): boolean => {\r\n if (!importer) return false;\r\n const name = packageNameOf(importer);\r\n return name != null && (name.startsWith('@velozjs/') || exclude.has(name));\r\n };\r\n\r\n return {\r\n name: 'vite-plugin-veloz',\r\n enforce: 'pre',\r\n\r\n config() {\r\n return {\r\n esbuild: { jsx: 'automatic', jsxImportSource: '@velozjs/dom' },\r\n resolve: { dedupe: ['@velozjs/core', '@velozjs/dom', '@velozjs/css', '@velozjs/ssr'] },\r\n };\r\n },\r\n\r\n async resolveId(source, importer, resolveOptions) {\r\n if (!resolveOptions?.ssr) return null;\r\n const target = SSR_REDIRECTS[source];\r\n if (!target || isFrameworkModule(importer)) return null;\r\n return this.resolve(target, importer, { ...resolveOptions, skipSelf: true });\r\n },\r\n };\r\n}\r\n\r\nexport { velozPlugin };\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "vite-plugin-veloz",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Vite plugin for Veloz: JSX setup and SSR module resolution.",
5
+ "keywords": [
6
+ "vite",
7
+ "vite-plugin",
8
+ "veloz",
9
+ "velozjs",
10
+ "jsx",
11
+ "ssr"
12
+ ],
13
+ "type": "module",
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "sideEffects": false,
29
+ "peerDependencies": {
30
+ "vite": ">=5.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "vite": "^7.0.0"
34
+ },
35
+ "engines": {
36
+ "node": ">=20"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "author": "Julio Carneiro (https://juliocarneiro.dev)",
42
+ "license": "MIT",
43
+ "homepage": "https://github.com/juliocarneiro/veloz#readme",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "git+https://github.com/juliocarneiro/veloz.git",
47
+ "directory": "packages/vite-plugin"
48
+ },
49
+ "bugs": {
50
+ "url": "https://github.com/juliocarneiro/veloz/issues"
51
+ },
52
+ "scripts": {
53
+ "build": "tsup",
54
+ "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\""
55
+ }
6
56
  }