@tsrx/vite-plugin-solid 0.0.105 → 0.0.107
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 +3 -3
- package/src/index.js +34 -23
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Vite plugin for @tsrx/solid (.tsrx modules) targeting Solid 2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.107",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@tsrx/core": "0.
|
|
24
|
-
"@tsrx/solid": "0.2.
|
|
23
|
+
"@tsrx/core": "0.3.0",
|
|
24
|
+
"@tsrx/solid": "0.2.5"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"vite": "*"
|
package/src/index.js
CHANGED
|
@@ -7,9 +7,13 @@ import { compile } from '@tsrx/solid';
|
|
|
7
7
|
import { mergePlatformDefinitions, validatePlatform } from '@tsrx/core';
|
|
8
8
|
import { resolveBuildPlatform } from '@tsrx/core/config';
|
|
9
9
|
import { createDepScanLoadPlugin } from '@tsrx/core/vite/dep-scan';
|
|
10
|
+
import { createWorkerEntryMiddleware, stripWorkerEntryQuery } from '@tsrx/core/vite/worker';
|
|
10
11
|
|
|
11
12
|
const DEFAULT_TSRX_PATTERN = /\.tsrx$/;
|
|
12
13
|
const VIRTUAL_TSX_SUFFIX = '.tsx';
|
|
14
|
+
// CSS ids stay the component path plus this query, with no `\0` prefix, so
|
|
15
|
+
// Vite resolves relative `@import` and `url()` references in the extracted
|
|
16
|
+
// CSS from the component's directory.
|
|
13
17
|
const CSS_QUERY = '?tsrx-solid-css&lang.css';
|
|
14
18
|
|
|
15
19
|
/**
|
|
@@ -139,22 +143,28 @@ export function tsrxSolid(options = {}) {
|
|
|
139
143
|
root_dir = config.root;
|
|
140
144
|
},
|
|
141
145
|
|
|
146
|
+
configureServer(server) {
|
|
147
|
+
server.middlewares.use(createWorkerEntryMiddleware(is_tsrx_source));
|
|
148
|
+
},
|
|
149
|
+
|
|
142
150
|
async resolveId(source, importer, options) {
|
|
143
151
|
// Intercept virtual CSS imports.
|
|
144
|
-
if (source.includes(CSS_QUERY))
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
152
|
+
if (source.includes(CSS_QUERY)) return source;
|
|
153
|
+
// A dev worker entry arrives as `<path>?worker_file&type=<type>`.
|
|
154
|
+
// Resolve the path, then keep the query on the virtual id: Vite's
|
|
155
|
+
// worker plugin reads it back to set the entry up as a worker.
|
|
156
|
+
const path = stripWorkerEntryQuery(source);
|
|
157
|
+
const worker_query = source.slice(path.length);
|
|
158
|
+
if (is_virtual(path)) return source;
|
|
149
159
|
|
|
150
160
|
// Rewrite tsrx source imports to their virtual `<path>.tsx` form
|
|
151
161
|
// so downstream extension-based plugins pick the module up as TSX.
|
|
152
|
-
if (is_tsrx_source(
|
|
153
|
-
const resolved = await this.resolve(
|
|
162
|
+
if (is_tsrx_source(path)) {
|
|
163
|
+
const resolved = await this.resolve(path, importer, { ...options, skipSelf: true });
|
|
154
164
|
if (resolved && !is_virtual(resolved.id)) {
|
|
155
|
-
return { ...resolved, id: resolved.id + VIRTUAL_TSX_SUFFIX };
|
|
165
|
+
return { ...resolved, id: resolved.id + VIRTUAL_TSX_SUFFIX + worker_query };
|
|
156
166
|
}
|
|
157
|
-
if (resolved) return resolved;
|
|
167
|
+
if (resolved) return { ...resolved, id: resolved.id + worker_query };
|
|
158
168
|
// Fallback: when `this.resolve` can't resolve (e.g. an absolute
|
|
159
169
|
// path coming in as a root entry such as a vitest test file),
|
|
160
170
|
// still rewrite to the virtual `.tsx` id directly so `load`
|
|
@@ -163,22 +173,23 @@ export function tsrxSolid(options = {}) {
|
|
|
163
173
|
// correct `node_modules` chain — leaving it relative makes
|
|
164
174
|
// vite walk up from the workspace root and miss package
|
|
165
175
|
// dependencies declared inside `packages/<pkg>/node_modules`.
|
|
166
|
-
const absolute_source = isAbsolute(
|
|
167
|
-
?
|
|
168
|
-
: path_resolve(root_dir,
|
|
169
|
-
return absolute_source + VIRTUAL_TSX_SUFFIX;
|
|
176
|
+
const absolute_source = isAbsolute(path)
|
|
177
|
+
? path
|
|
178
|
+
: path_resolve(root_dir, path.replace(/^\/+/, ''));
|
|
179
|
+
return absolute_source + VIRTUAL_TSX_SUFFIX + worker_query;
|
|
170
180
|
}
|
|
171
181
|
return null;
|
|
172
182
|
},
|
|
173
183
|
|
|
174
184
|
async load(id) {
|
|
175
|
-
if (id.
|
|
176
|
-
const key = id.
|
|
185
|
+
if (id.includes(CSS_QUERY)) {
|
|
186
|
+
const key = id.split('?')[0];
|
|
177
187
|
return css_cache.get(key) ?? '';
|
|
178
188
|
}
|
|
179
|
-
|
|
189
|
+
const path = stripWorkerEntryQuery(id);
|
|
190
|
+
if (!is_virtual(path)) return null;
|
|
180
191
|
|
|
181
|
-
const real_path = to_real_path(
|
|
192
|
+
const real_path = to_real_path(path);
|
|
182
193
|
const source = await readFile(real_path, 'utf-8');
|
|
183
194
|
let { code, css, map } = compile(source, real_path, compile_options);
|
|
184
195
|
|
|
@@ -196,18 +207,18 @@ export function tsrxSolid(options = {}) {
|
|
|
196
207
|
|
|
197
208
|
handleHotUpdate(ctx) {
|
|
198
209
|
if (!is_tsrx_source(ctx.file)) return;
|
|
199
|
-
// Invalidate the virtual `<path>.tsx`
|
|
210
|
+
// Invalidate the virtual `<path>.tsx` modules so Vite re-runs `load`,
|
|
211
|
+
// looked up by file to include a worker entry's query-suffixed id.
|
|
200
212
|
// Also invalidate the virtual CSS module — Vite doesn't cascade
|
|
201
213
|
// invalidation from importer to importee, so without this the CSS
|
|
202
214
|
// module keeps serving the cached content and `<style>` edits in
|
|
203
215
|
// `.tsrx` files wouldn't hot-reload.
|
|
204
216
|
const virtual_id = ctx.file + VIRTUAL_TSX_SUFFIX;
|
|
205
|
-
const css_virtual_id =
|
|
206
|
-
const extra = [];
|
|
207
|
-
const mod = ctx.server.moduleGraph.getModuleById(virtual_id);
|
|
208
|
-
if (mod) extra.push(mod);
|
|
217
|
+
const css_virtual_id = ctx.file + CSS_QUERY;
|
|
218
|
+
const extra = [...(ctx.server.moduleGraph.getModulesByFile(virtual_id) ?? [])];
|
|
209
219
|
const css_mod = ctx.server.moduleGraph.getModuleById(css_virtual_id);
|
|
210
|
-
|
|
220
|
+
// Vite usually lists the CSS module already, under the component's file.
|
|
221
|
+
if (css_mod && !ctx.modules.includes(css_mod)) extra.push(css_mod);
|
|
211
222
|
if (extra.length > 0) return [...extra, ...ctx.modules];
|
|
212
223
|
return ctx.modules;
|
|
213
224
|
},
|