@tsrx/vite-plugin-vue 0.0.103 → 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/package.json +6 -6
- package/src/index.js +82 -29
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.1.0",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -20,18 +20,18 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@tsrx/core": "0.
|
|
24
|
-
"@tsrx/vue": "0.
|
|
23
|
+
"@tsrx/core": "0.6.0",
|
|
24
|
+
"@tsrx/vue": "0.4.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"vite": "*",
|
|
28
|
-
"vue-jsx-vapor": ">=3.2.
|
|
28
|
+
"vue-jsx-vapor": ">=3.2.27"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"typescript": "^5.9.3",
|
|
32
32
|
"vite": "^8.1.5",
|
|
33
|
-
"vue": "3.6.0-
|
|
34
|
-
"vue-jsx-vapor": "^3.2.
|
|
33
|
+
"vue": "3.6.0-rc.14",
|
|
34
|
+
"vue-jsx-vapor": "^3.2.29"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"src",
|
package/src/index.js
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
import { readFile } from 'node:fs/promises';
|
|
6
6
|
import { existsSync } from 'node:fs';
|
|
7
7
|
import { isAbsolute, resolve as pathResolve } from 'node:path';
|
|
8
|
+
import { normalizePath, parseSync } from 'vite';
|
|
8
9
|
import { compile } from '@tsrx/vue';
|
|
9
10
|
import { mergePlatformDefinitions, validatePlatform } from '@tsrx/core';
|
|
10
11
|
import { resolveBuildPlatform } from '@tsrx/core/config';
|
|
11
12
|
import { createDepScanLoadPlugin } from '@tsrx/core/vite/dep-scan';
|
|
13
|
+
import { findUnconfiguredPlatformFlag, restartOnPlatformChange } from '@tsrx/core/vite/platform';
|
|
12
14
|
import { createWorkerEntryMiddleware, stripWorkerEntryQuery } from '@tsrx/core/vite/worker';
|
|
13
15
|
import vueJsxVaporModule from 'vue-jsx-vapor/vite';
|
|
14
16
|
import { createVaporInteropPlugin } from './interop.js';
|
|
@@ -94,16 +96,20 @@ function create_tsrx_vue_plugin(options) {
|
|
|
94
96
|
const includePattern = options.include ?? DEFAULT_TSRX_PATTERN;
|
|
95
97
|
const compile_options = { runtimeImports: options.runtimeImports, platform };
|
|
96
98
|
|
|
99
|
+
/** @type {import('@tsrx/core/config').BuildPlatformResolutionOptions} */
|
|
100
|
+
let platform_resolution = {};
|
|
101
|
+
|
|
97
102
|
/** @param {import('vite').UserConfig} config */
|
|
98
103
|
function resolve_platform(config) {
|
|
99
|
-
|
|
104
|
+
platform_resolution = {
|
|
100
105
|
root: config.root ?? process.cwd(),
|
|
101
106
|
tsconfig:
|
|
102
107
|
options.tsconfig ??
|
|
103
108
|
/** @type {{ tsconfig?: string }} */ (/** @type {unknown} */ (config)).tsconfig,
|
|
104
109
|
platform: explicit_platform,
|
|
105
110
|
integration: '@tsrx/vite-plugin-vue',
|
|
106
|
-
}
|
|
111
|
+
};
|
|
112
|
+
platform = resolveBuildPlatform(platform_resolution);
|
|
107
113
|
compile_options.platform = platform;
|
|
108
114
|
}
|
|
109
115
|
|
|
@@ -141,33 +147,36 @@ function create_tsrx_vue_plugin(options) {
|
|
|
141
147
|
name: '@tsrx/vite-plugin-vue',
|
|
142
148
|
enforce: 'pre',
|
|
143
149
|
|
|
144
|
-
config
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
config: {
|
|
151
|
+
order: 'post',
|
|
152
|
+
handler(config = /** @type {import('vite').UserConfig} */ ({})) {
|
|
153
|
+
resolve_platform(config);
|
|
154
|
+
return {
|
|
155
|
+
...(platform === undefined
|
|
156
|
+
? {}
|
|
157
|
+
: {
|
|
158
|
+
define: mergePlatformDefinitions(config.define, platform, {
|
|
159
|
+
integration: 'Vite',
|
|
160
|
+
}),
|
|
152
161
|
}),
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
dedupe: ['vue', 'vue-jsx-vapor'],
|
|
156
|
-
},
|
|
157
|
-
optimizeDeps: {
|
|
158
|
-
rolldownOptions: {
|
|
159
|
-
// The scan runs its own jsx transform over the tsx the
|
|
160
|
-
// dep-scan plugin hands back, and it defaults to react's
|
|
161
|
-
// automatic runtime — which no Vue project has installed, so
|
|
162
|
-
// the scan would fail on an unresolvable
|
|
163
|
-
// `react/jsx-dev-runtime`. Vue's own jsx handling belongs to
|
|
164
|
-
// `vue-jsx-vapor` downstream; the scan only needs the
|
|
165
|
-
// imports, so leave the jsx alone.
|
|
166
|
-
transform: { jsx: 'preserve' },
|
|
167
|
-
plugins: [create_tsrx_vue_scan_plugin(isVirtual, toRealPath, compile_options)],
|
|
162
|
+
resolve: {
|
|
163
|
+
dedupe: ['vue', 'vue-jsx-vapor'],
|
|
168
164
|
},
|
|
169
|
-
|
|
170
|
-
|
|
165
|
+
optimizeDeps: {
|
|
166
|
+
rolldownOptions: {
|
|
167
|
+
// The scan runs its own jsx transform over the tsx the
|
|
168
|
+
// dep-scan plugin hands back, and it defaults to react's
|
|
169
|
+
// automatic runtime — which no Vue project has installed, so
|
|
170
|
+
// the scan would fail on an unresolvable
|
|
171
|
+
// `react/jsx-dev-runtime`. Vue's own jsx handling belongs to
|
|
172
|
+
// `vue-jsx-vapor` downstream; the scan only needs the
|
|
173
|
+
// imports, so leave the jsx alone.
|
|
174
|
+
transform: { jsx: 'preserve' },
|
|
175
|
+
plugins: [create_tsrx_vue_scan_plugin(isVirtual, toRealPath, compile_options)],
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
},
|
|
171
180
|
},
|
|
172
181
|
|
|
173
182
|
configEnvironment(name, config = /** @type {import('vite').EnvironmentOptions} */ ({})) {
|
|
@@ -184,6 +193,7 @@ function create_tsrx_vue_plugin(options) {
|
|
|
184
193
|
},
|
|
185
194
|
|
|
186
195
|
configureServer(server) {
|
|
196
|
+
restartOnPlatformChange(server, platform_resolution, () => platform);
|
|
187
197
|
server.middlewares.use(createWorkerEntryMiddleware(isTsrxSource));
|
|
188
198
|
},
|
|
189
199
|
|
|
@@ -197,6 +207,16 @@ function create_tsrx_vue_plugin(options) {
|
|
|
197
207
|
const workerQuery = source.slice(path.length);
|
|
198
208
|
|
|
199
209
|
if (isVirtual(path)) {
|
|
210
|
+
// Vitest can ask for a module by its root-relative URL. Anchor the
|
|
211
|
+
// id to the file, or imports from the module resolve against the
|
|
212
|
+
// root. Vite's resolver spells it (real path, `/` separators), so
|
|
213
|
+
// the file has one module id however it is reached.
|
|
214
|
+
const realPath = toRealPath(path);
|
|
215
|
+
if (realPath !== path.slice(0, -VIRTUAL_TSX_SUFFIX.length)) {
|
|
216
|
+
const resolved = await this.resolve(realPath, importer, { ...options, skipSelf: true });
|
|
217
|
+
const id = resolved && !resolved.external ? resolved.id : realPath;
|
|
218
|
+
return normalizePath(id) + VIRTUAL_TSX_SUFFIX + workerQuery;
|
|
219
|
+
}
|
|
200
220
|
return isAbsolute(source) ? source : pathResolve(rootDir, source.replace(/^\/+/, ''));
|
|
201
221
|
}
|
|
202
222
|
|
|
@@ -220,7 +240,20 @@ function create_tsrx_vue_plugin(options) {
|
|
|
220
240
|
return absoluteSource + VIRTUAL_TSX_SUFFIX + workerQuery;
|
|
221
241
|
}
|
|
222
242
|
|
|
223
|
-
|
|
243
|
+
// A package export or an extensionless import can still resolve to
|
|
244
|
+
// a `.tsrx` file.
|
|
245
|
+
if (source.startsWith('\0') || source.includes('?')) return null;
|
|
246
|
+
const resolved = await this.resolve(source, importer, { ...options, skipSelf: true });
|
|
247
|
+
if (
|
|
248
|
+
resolved &&
|
|
249
|
+
!resolved.id.startsWith('\0') &&
|
|
250
|
+
!resolved.id.includes('?') &&
|
|
251
|
+
isTsrxSource(resolved.id)
|
|
252
|
+
) {
|
|
253
|
+
return { ...resolved, id: resolved.id + VIRTUAL_TSX_SUFFIX };
|
|
254
|
+
}
|
|
255
|
+
// Hand the resolution over, so Vite does not resolve the import again.
|
|
256
|
+
return resolved;
|
|
224
257
|
},
|
|
225
258
|
|
|
226
259
|
async load(id) {
|
|
@@ -248,8 +281,28 @@ function create_tsrx_vue_plugin(options) {
|
|
|
248
281
|
return { code, map };
|
|
249
282
|
},
|
|
250
283
|
|
|
251
|
-
|
|
284
|
+
transform(code, id) {
|
|
285
|
+
if (platform !== undefined) return null;
|
|
286
|
+
const flag = findUnconfiguredPlatformFlag(code, id, parseSync);
|
|
287
|
+
if (flag) this.error(flag, flag.pos);
|
|
288
|
+
return null;
|
|
289
|
+
},
|
|
290
|
+
|
|
291
|
+
async handleHotUpdate(ctx) {
|
|
252
292
|
if (!isTsrxSource(ctx.file)) return;
|
|
293
|
+
// CSS can reload before the virtual JS, so refresh its selector hash first.
|
|
294
|
+
// A file that doesn't compile keeps its last good CSS, and the reloaded
|
|
295
|
+
// module's `load` reports the error, as before this refresh.
|
|
296
|
+
try {
|
|
297
|
+
const { css } = compile(await ctx.read(), ctx.file, compile_options);
|
|
298
|
+
if (css) {
|
|
299
|
+
cssCache.set(ctx.file, css);
|
|
300
|
+
} else {
|
|
301
|
+
cssCache.delete(ctx.file);
|
|
302
|
+
}
|
|
303
|
+
} catch {
|
|
304
|
+
// Keep the last good CSS.
|
|
305
|
+
}
|
|
253
306
|
|
|
254
307
|
// Look the virtual modules up by file to include a worker entry's
|
|
255
308
|
// query-suffixed id.
|