@tsrx/vite-plugin-hono 0.1.3 → 0.1.4

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.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/src/index.js +22 -11
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Vite plugin for the TSRX Hono JSX targets",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.1.3",
6
+ "version": "0.1.4",
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.2.4",
24
- "@tsrx/hono": "0.1.3"
23
+ "@tsrx/core": "0.3.0",
24
+ "@tsrx/hono": "0.1.4"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "vite": "^8.0.0"
@@ -30,7 +30,7 @@
30
30
  "hono": "^4.13.7",
31
31
  "typescript": "^5.9.3",
32
32
  "vite": "^8.1.5",
33
- "@tsrx/typescript-plugin": "0.4.6"
33
+ "@tsrx/typescript-plugin": "0.4.8"
34
34
  },
35
35
  "files": [
36
36
  "src",
package/src/index.js CHANGED
@@ -8,8 +8,12 @@ import { compile as compileServer } from '@tsrx/hono';
8
8
  import { compile as compileDom } from '@tsrx/hono/dom';
9
9
  import { resolveBuildPlatform } from '@tsrx/core/config';
10
10
  import { createDepScanTransformPlugin } from '@tsrx/core/vite/dep-scan';
11
+ import { createWorkerEntryMiddleware, stripWorkerEntryQuery } from '@tsrx/core/vite/worker';
11
12
 
12
13
  const TSRX_EXTENSION_PATTERN = /\.tsrx$/;
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-css&lang.css';
14
18
 
15
19
  /**
@@ -77,7 +81,7 @@ export function tsrxHono(options = {}) {
77
81
  /** @param {Map<string, string>} css_cache @param {string} id */
78
82
  function css_owner(css_cache, id) {
79
83
  if (!id.endsWith(CSS_QUERY)) return null;
80
- const owner = id.slice(id.startsWith('\0') ? 1 : 0, -CSS_QUERY.length);
84
+ const owner = id.slice(0, -CSS_QUERY.length);
81
85
  return css_cache.has(owner) ? owner : null;
82
86
  }
83
87
 
@@ -139,15 +143,19 @@ export function tsrxHono(options = {}) {
139
143
  };
140
144
  },
141
145
 
146
+ configureServer(server) {
147
+ server.middlewares.use(
148
+ createWorkerEntryMiddleware((path) => TSRX_EXTENSION_PATTERN.test(path)),
149
+ );
150
+ },
151
+
142
152
  resolveId(source) {
143
153
  const css_cache = css_cache_for(this);
144
154
  if (css_owner(css_cache, source) === null) return null;
145
- if (source.startsWith('\0')) return source;
146
- return '\0' + source;
155
+ return source;
147
156
  },
148
157
 
149
158
  load(id) {
150
- if (!id.startsWith('\0')) return null;
151
159
  const css_cache = css_cache_for(this);
152
160
  const owner = css_owner(css_cache, id);
153
161
  return owner === null ? null : css_cache.get(owner);
@@ -162,14 +170,17 @@ export function tsrxHono(options = {}) {
162
170
  },
163
171
 
164
172
  async transform(code, id) {
165
- if (!TSRX_EXTENSION_PATTERN.test(id)) return null;
173
+ // A dev worker entry arrives as `<path>?worker_file&type=<type>`.
174
+ // Compile it under its file path, as a plain import would be.
175
+ const file = stripWorkerEntryQuery(id);
176
+ if (!TSRX_EXTENSION_PATTERN.test(file)) return null;
166
177
 
167
- const result = compile(code, id, compile_options);
168
- const source = append_css_import(css_cache_for(this), result.code, id, result.css);
178
+ const result = compile(code, file, compile_options);
179
+ const source = append_css_import(css_cache_for(this), result.code, file, result.css);
169
180
 
170
181
  const transformed = await transformWithOxc(
171
182
  source,
172
- id,
183
+ file,
173
184
  {
174
185
  lang: 'tsx',
175
186
  sourcemap: true,
@@ -189,14 +200,14 @@ export function tsrxHono(options = {}) {
189
200
  if (!TSRX_EXTENSION_PATTERN.test(options.file)) return;
190
201
  // Deleted files cannot be read. watchChange already removed their CSS.
191
202
  if (options.type === 'delete') return options.modules;
192
- const css_module = this.environment.moduleGraph.getModuleById(
193
- '\0' + options.file + CSS_QUERY,
194
- );
203
+ const css_module = this.environment.moduleGraph.getModuleById(options.file + CSS_QUERY);
195
204
  if (!css_module) return options.modules;
196
205
 
197
206
  update_css_cache(css_cache_for(this), await options.read(), options.file);
198
207
 
199
208
  this.environment.moduleGraph.invalidateModule(css_module);
209
+ // Vite usually lists the CSS module already, under the component's file.
210
+ if (options.modules.includes(css_module)) return options.modules;
200
211
  return [...options.modules, css_module];
201
212
  },
202
213
  });