@tsrx/vite-plugin-vue 0.0.25 → 0.0.27
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/package.json +7 -6
- package/src/index.js +111 -12
- package/src/interop.js +30 -0
- package/types/index.d.ts +10 -1
- package/src/vapor.js +0 -27
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Vite plugin for @tsrx/vue (.tsrx modules)",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.27",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -20,17 +20,18 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@tsrx/vue": "0.1.
|
|
23
|
+
"@tsrx/vue": "0.1.11"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"vite": "*"
|
|
26
|
+
"vite": "*",
|
|
27
|
+
"vue-jsx-vapor": ">=3.2.14"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"typescript": "^5.9.3",
|
|
30
31
|
"vite": "^8.0.12",
|
|
31
|
-
"vue": "3.6.0-beta.
|
|
32
|
-
"vue-jsx-vapor": "^3.2.
|
|
33
|
-
"@tsrx/core": "0.1.
|
|
32
|
+
"vue": "3.6.0-beta.12",
|
|
33
|
+
"vue-jsx-vapor": "^3.2.14",
|
|
34
|
+
"@tsrx/core": "0.1.11"
|
|
34
35
|
},
|
|
35
36
|
"files": [
|
|
36
37
|
"src",
|
package/src/index.js
CHANGED
|
@@ -4,22 +4,76 @@ import { readFile } from 'node:fs/promises';
|
|
|
4
4
|
import { existsSync } from 'node:fs';
|
|
5
5
|
import { isAbsolute, resolve as pathResolve } from 'node:path';
|
|
6
6
|
import { compile } from '@tsrx/vue';
|
|
7
|
+
import vueJsxVaporModule from 'vue-jsx-vapor/vite';
|
|
8
|
+
import { createVaporInteropPlugin } from './interop.js';
|
|
7
9
|
|
|
8
10
|
const DEFAULT_TSRX_PATTERN = /\.tsrx$/;
|
|
9
11
|
const VIRTUAL_TSX_SUFFIX = '.tsx';
|
|
10
12
|
const CSS_QUERY = '?tsrx-vue-css&lang.css';
|
|
13
|
+
const DEFAULT_VAPOR_OPTIONS = {
|
|
14
|
+
macros: true,
|
|
15
|
+
compiler: {
|
|
16
|
+
runtimeModuleName: 'vue-jsx-vapor',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {(options: {
|
|
22
|
+
* macros?: boolean | object;
|
|
23
|
+
* compiler?: { runtimeModuleName?: string };
|
|
24
|
+
* }) => Plugin[]} VueJsxVaporPlugin
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const vueJsxVaporModuleInterop = /** @type {VueJsxVaporPlugin | { default: VueJsxVaporPlugin }} */ (
|
|
28
|
+
/** @type {unknown} */ (vueJsxVaporModule)
|
|
29
|
+
);
|
|
30
|
+
const vueJsxVapor =
|
|
31
|
+
typeof vueJsxVaporModuleInterop === 'function'
|
|
32
|
+
? vueJsxVaporModuleInterop
|
|
33
|
+
: vueJsxVaporModuleInterop.default;
|
|
11
34
|
|
|
12
35
|
/**
|
|
13
36
|
* Vite plugin that compiles `.tsrx` files to Vue-flavoured TSX via
|
|
14
|
-
* `@tsrx/vue
|
|
15
|
-
*
|
|
37
|
+
* `@tsrx/vue`, then runs the downstream `vue-jsx-vapor` transform. It rewrites
|
|
38
|
+
* module ids to a virtual `<path>.tsx` form so the Vapor JSX plugin can handle
|
|
39
|
+
* the Vue JSX runtime stage.
|
|
16
40
|
* Per-component `<style>` blocks become virtual CSS modules that the compiled
|
|
17
41
|
* JS imports.
|
|
18
42
|
*
|
|
19
43
|
* @param {import('../types/index.js').TsrxVueOptions} [options]
|
|
20
|
-
* @returns {Plugin}
|
|
44
|
+
* @returns {Plugin[]}
|
|
21
45
|
*/
|
|
22
46
|
export function tsrxVue(options = {}) {
|
|
47
|
+
return [
|
|
48
|
+
createVaporInteropPlugin(),
|
|
49
|
+
create_tsrx_vue_plugin(options),
|
|
50
|
+
...vueJsxVapor(resolve_vapor_options(options.vapor)),
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {import('../types/index.js').TsrxVueOptions['vapor']} options
|
|
56
|
+
*/
|
|
57
|
+
function resolve_vapor_options(options) {
|
|
58
|
+
const { interop: _interop, ...rest } =
|
|
59
|
+
/** @type {{ interop?: boolean, macros?: boolean | object, compiler?: { runtimeModuleName?: string } }} */ (
|
|
60
|
+
options ?? {}
|
|
61
|
+
);
|
|
62
|
+
return {
|
|
63
|
+
...DEFAULT_VAPOR_OPTIONS,
|
|
64
|
+
...rest,
|
|
65
|
+
compiler: {
|
|
66
|
+
...DEFAULT_VAPOR_OPTIONS.compiler,
|
|
67
|
+
...rest.compiler,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {import('../types/index.js').TsrxVueOptions} options
|
|
74
|
+
* @returns {Plugin}
|
|
75
|
+
*/
|
|
76
|
+
function create_tsrx_vue_plugin(options) {
|
|
23
77
|
/** @type {Map<string, string>} */
|
|
24
78
|
const cssCache = new Map();
|
|
25
79
|
|
|
@@ -62,6 +116,19 @@ export function tsrxVue(options = {}) {
|
|
|
62
116
|
name: '@tsrx/vite-plugin-vue',
|
|
63
117
|
enforce: 'pre',
|
|
64
118
|
|
|
119
|
+
config() {
|
|
120
|
+
return {
|
|
121
|
+
resolve: {
|
|
122
|
+
dedupe: ['vue', 'vue-jsx-vapor'],
|
|
123
|
+
},
|
|
124
|
+
optimizeDeps: {
|
|
125
|
+
rolldownOptions: {
|
|
126
|
+
plugins: [create_tsrx_vue_scan_plugin(isVirtual, toRealPath)],
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
|
|
65
132
|
configResolved(config) {
|
|
66
133
|
rootDir = config.root;
|
|
67
134
|
},
|
|
@@ -72,12 +139,17 @@ export function tsrxVue(options = {}) {
|
|
|
72
139
|
return '\0' + source;
|
|
73
140
|
}
|
|
74
141
|
|
|
75
|
-
if (isVirtual(source))
|
|
142
|
+
if (isVirtual(source)) {
|
|
143
|
+
return isAbsolute(source) ? source : pathResolve(rootDir, source.replace(/^\/+/, ''));
|
|
144
|
+
}
|
|
76
145
|
|
|
77
146
|
if (isTsrxSource(source)) {
|
|
78
147
|
const resolved = await this.resolve(source, importer, { ...options, skipSelf: true });
|
|
79
148
|
if (resolved && !isVirtual(resolved.id)) {
|
|
80
|
-
|
|
149
|
+
const resolvedId = isAbsolute(resolved.id)
|
|
150
|
+
? resolved.id
|
|
151
|
+
: pathResolve(rootDir, resolved.id.replace(/^\/+/, ''));
|
|
152
|
+
return { ...resolved, id: resolvedId + VIRTUAL_TSX_SUFFIX };
|
|
81
153
|
}
|
|
82
154
|
if (resolved) return resolved;
|
|
83
155
|
// Re-anchor the fallback virtual id to an absolute path so
|
|
@@ -104,21 +176,19 @@ export function tsrxVue(options = {}) {
|
|
|
104
176
|
|
|
105
177
|
const realPath = toRealPath(id.split('?')[0]);
|
|
106
178
|
const source = await readFile(realPath, 'utf-8');
|
|
107
|
-
|
|
179
|
+
let { code, css, map } = compile(source, realPath);
|
|
108
180
|
|
|
109
|
-
let finalCode = code;
|
|
110
|
-
let finalMap = /** @type {any} */ (map);
|
|
111
181
|
if (css) {
|
|
112
182
|
cssCache.set(realPath, css);
|
|
113
|
-
|
|
114
|
-
if (
|
|
115
|
-
|
|
183
|
+
code = `import ${JSON.stringify(realPath + CSS_QUERY)};\n${code}`;
|
|
184
|
+
if (map && typeof map.mappings === 'string') {
|
|
185
|
+
map = { ...map, mappings: ';' + map.mappings };
|
|
116
186
|
}
|
|
117
187
|
} else {
|
|
118
188
|
cssCache.delete(realPath);
|
|
119
189
|
}
|
|
120
190
|
|
|
121
|
-
return { code
|
|
191
|
+
return { code, map };
|
|
122
192
|
},
|
|
123
193
|
|
|
124
194
|
handleHotUpdate(ctx) {
|
|
@@ -137,4 +207,33 @@ export function tsrxVue(options = {}) {
|
|
|
137
207
|
};
|
|
138
208
|
}
|
|
139
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Vite's dependency scanner runs through Rolldown and does not call Vite
|
|
212
|
+
* `load()` hooks for virtual ids. Teach the scan pass how to read the same
|
|
213
|
+
* `<path>.tsrx.tsx` modules so dev pre-bundling can crawl their imports.
|
|
214
|
+
*
|
|
215
|
+
* @param {(id: string) => boolean} isVirtual
|
|
216
|
+
* @param {(id: string) => string} toRealPath
|
|
217
|
+
*/
|
|
218
|
+
function create_tsrx_vue_scan_plugin(isVirtual, toRealPath) {
|
|
219
|
+
return {
|
|
220
|
+
name: '@tsrx/vite-plugin-vue:dep-scan',
|
|
221
|
+
/**
|
|
222
|
+
* @param {string} id
|
|
223
|
+
*/
|
|
224
|
+
async load(id) {
|
|
225
|
+
if (!isVirtual(id)) return null;
|
|
226
|
+
|
|
227
|
+
const realPath = toRealPath(id.split('?')[0]);
|
|
228
|
+
const source = await readFile(realPath, 'utf-8');
|
|
229
|
+
const { code } = compile(source, realPath);
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
code,
|
|
233
|
+
moduleType: 'tsx',
|
|
234
|
+
};
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
140
239
|
export default tsrxVue;
|
package/src/interop.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** @import { Plugin } from 'vite' */
|
|
2
|
+
|
|
3
|
+
import { addVaporInteropToCreateVaporApp } from '@tsrx/vue/interop';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Vue's built-in renderer primitives, including `Suspense`, need Vapor/VDOM
|
|
7
|
+
* interop when mounted from a Vapor app. TSRX can emit `Suspense` for
|
|
8
|
+
* `try/pending`, so make Vapor app creation install the interop plugin without
|
|
9
|
+
* every app entry point needing to remember it.
|
|
10
|
+
*
|
|
11
|
+
* @returns {Plugin}
|
|
12
|
+
*/
|
|
13
|
+
export function createVaporInteropPlugin() {
|
|
14
|
+
return {
|
|
15
|
+
name: '@tsrx/vite-plugin-vue:vapor-interop',
|
|
16
|
+
enforce: 'pre',
|
|
17
|
+
transform(code) {
|
|
18
|
+
if (!/\bcreateVaporApp\b/.test(code) || !/\bfrom\s*['"]vue['"]/.test(code)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const transformed = addVaporInteropToCreateVaporApp(code);
|
|
23
|
+
if (transformed === code) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return { code: transformed, map: null };
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -6,7 +6,16 @@ export interface TsrxVueOptions {
|
|
|
6
6
|
* the plugin should compile as tsrx sources. Defaults to `/\.tsrx$/`.
|
|
7
7
|
*/
|
|
8
8
|
include?: RegExp;
|
|
9
|
+
/**
|
|
10
|
+
* Options forwarded to `vue-jsx-vapor/vite`.
|
|
11
|
+
*/
|
|
12
|
+
vapor?: {
|
|
13
|
+
macros?: boolean | object;
|
|
14
|
+
compiler?: {
|
|
15
|
+
runtimeModuleName?: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
9
18
|
}
|
|
10
19
|
|
|
11
|
-
export function tsrxVue(options?: TsrxVueOptions): Plugin;
|
|
20
|
+
export function tsrxVue(options?: TsrxVueOptions): Plugin[];
|
|
12
21
|
export default tsrxVue;
|
package/src/vapor.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/** @import { Plugin } from 'vite' */
|
|
2
|
-
|
|
3
|
-
import vueJsxVaporModule from 'vue-jsx-vapor/vite';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @typedef {(options: {
|
|
7
|
-
* macros: boolean;
|
|
8
|
-
* compiler: { runtimeModuleName: string };
|
|
9
|
-
* }) => Plugin[]} VueJsxVaporPlugin
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const vueJsxVaporModuleInterop = /** @type {VueJsxVaporPlugin | { default: VueJsxVaporPlugin }} */ (
|
|
13
|
-
/** @type {unknown} */ (vueJsxVaporModule)
|
|
14
|
-
);
|
|
15
|
-
const vueJsxVapor =
|
|
16
|
-
typeof vueJsxVaporModuleInterop === 'function'
|
|
17
|
-
? vueJsxVaporModuleInterop
|
|
18
|
-
: vueJsxVaporModuleInterop.default;
|
|
19
|
-
|
|
20
|
-
export function tsrxVueVapor() {
|
|
21
|
-
return vueJsxVapor({
|
|
22
|
-
macros: true,
|
|
23
|
-
compiler: {
|
|
24
|
-
runtimeModuleName: 'vue-jsx-vapor',
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
}
|