@tsrx/vite-plugin-hono 0.1.13 → 0.1.15
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 +4 -4
- package/src/index.js +35 -13
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.
|
|
6
|
+
"version": "0.1.15",
|
|
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/hono": "0.
|
|
23
|
+
"@tsrx/core": "0.6.0",
|
|
24
|
+
"@tsrx/hono": "0.3.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"vite": "^8.0.0"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"hono": "^4.13.7",
|
|
31
31
|
"typescript": "7.1.0-dev.20260930.4",
|
|
32
32
|
"vite": "^8.1.5",
|
|
33
|
-
"@tsrx/content-mapper": "0.1.
|
|
33
|
+
"@tsrx/content-mapper": "0.1.3"
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
36
36
|
"src",
|
package/src/index.js
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
/** @import { DepScanTransformPlugin } from '@tsrx/core/types/vite/dep-scan' */
|
|
3
3
|
/** @import { Platform, RuntimeImportMode } from '@tsrx/hono' */
|
|
4
4
|
|
|
5
|
-
import { perEnvironmentState, transformWithOxc } from 'vite';
|
|
5
|
+
import { parseSync, perEnvironmentState, transformWithOxc } from 'vite';
|
|
6
6
|
import { mergePlatformDefinitions, validatePlatform } from '@tsrx/core';
|
|
7
7
|
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 { findUnconfiguredPlatformFlag, restartOnPlatformChange } from '@tsrx/core/vite/platform';
|
|
11
12
|
import { createWorkerEntryMiddleware, stripWorkerEntryQuery } from '@tsrx/core/vite/worker';
|
|
12
13
|
|
|
13
14
|
const TSRX_EXTENSION_PATTERN = /\.tsrx$/;
|
|
@@ -47,16 +48,20 @@ export function tsrxHono(options = {}) {
|
|
|
47
48
|
let platform = explicit_platform;
|
|
48
49
|
const compile_options = { runtimeImports: options.runtimeImports, platform };
|
|
49
50
|
|
|
51
|
+
/** @type {import('@tsrx/core/config').BuildPlatformResolutionOptions} */
|
|
52
|
+
let platform_resolution = {};
|
|
53
|
+
|
|
50
54
|
/** @param {import('vite').UserConfig} config */
|
|
51
55
|
function resolve_platform(config) {
|
|
52
|
-
|
|
56
|
+
platform_resolution = {
|
|
53
57
|
root: config.root ?? process.cwd(),
|
|
54
58
|
tsconfig:
|
|
55
59
|
options.tsconfig ??
|
|
56
60
|
/** @type {{ tsconfig?: string }} */ (/** @type {unknown} */ (config)).tsconfig,
|
|
57
61
|
platform: explicit_platform,
|
|
58
62
|
integration: '@tsrx/vite-plugin-hono',
|
|
59
|
-
}
|
|
63
|
+
};
|
|
64
|
+
platform = resolveBuildPlatform(platform_resolution);
|
|
60
65
|
compile_options.platform = platform;
|
|
61
66
|
}
|
|
62
67
|
|
|
@@ -106,14 +111,17 @@ export function tsrxHono(options = {}) {
|
|
|
106
111
|
perEnvironmentStartEndDuringDev: true,
|
|
107
112
|
perEnvironmentWatchChangeDuringDev: true,
|
|
108
113
|
|
|
109
|
-
config
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
config: {
|
|
115
|
+
order: 'post',
|
|
116
|
+
handler(config = /** @type {import('vite').UserConfig} */ ({})) {
|
|
117
|
+
resolve_platform(config);
|
|
118
|
+
if (platform === undefined) return;
|
|
119
|
+
return {
|
|
120
|
+
define: mergePlatformDefinitions(config.define, platform, {
|
|
121
|
+
integration: 'Vite',
|
|
122
|
+
}),
|
|
123
|
+
};
|
|
124
|
+
},
|
|
117
125
|
},
|
|
118
126
|
|
|
119
127
|
configEnvironment(name, config = /** @type {import('vite').EnvironmentOptions} */ ({})) {
|
|
@@ -144,6 +152,7 @@ export function tsrxHono(options = {}) {
|
|
|
144
152
|
},
|
|
145
153
|
|
|
146
154
|
configureServer(server) {
|
|
155
|
+
restartOnPlatformChange(server, platform_resolution, () => platform);
|
|
147
156
|
server.middlewares.use(
|
|
148
157
|
createWorkerEntryMiddleware((path) => TSRX_EXTENSION_PATTERN.test(path)),
|
|
149
158
|
);
|
|
@@ -173,7 +182,12 @@ export function tsrxHono(options = {}) {
|
|
|
173
182
|
// A dev worker entry arrives as `<path>?worker_file&type=<type>`.
|
|
174
183
|
// Compile it under its file path, as a plain import would be.
|
|
175
184
|
const file = stripWorkerEntryQuery(id);
|
|
176
|
-
if (!TSRX_EXTENSION_PATTERN.test(file))
|
|
185
|
+
if (!TSRX_EXTENSION_PATTERN.test(file)) {
|
|
186
|
+
const flag =
|
|
187
|
+
platform === undefined ? findUnconfiguredPlatformFlag(code, id, parseSync) : null;
|
|
188
|
+
if (flag) this.error(flag, flag.pos);
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
177
191
|
|
|
178
192
|
const result = compile(code, file, compile_options);
|
|
179
193
|
const source = append_css_import(css_cache_for(this), result.code, file, result.css);
|
|
@@ -203,7 +217,15 @@ export function tsrxHono(options = {}) {
|
|
|
203
217
|
const css_module = this.environment.moduleGraph.getModuleById(options.file + CSS_QUERY);
|
|
204
218
|
if (!css_module) return options.modules;
|
|
205
219
|
|
|
206
|
-
|
|
220
|
+
const source = await options.read();
|
|
221
|
+
try {
|
|
222
|
+
update_css_cache(css_cache_for(this), source, options.file);
|
|
223
|
+
} catch {
|
|
224
|
+
// Vite keeps the stylesheet module after the last component import is
|
|
225
|
+
// gone, so the file may now be imported only as `?raw`. Keep the last
|
|
226
|
+
// good css; a component import reports the error when it transforms.
|
|
227
|
+
return options.modules;
|
|
228
|
+
}
|
|
207
229
|
|
|
208
230
|
this.environment.moduleGraph.invalidateModule(css_module);
|
|
209
231
|
// Vite usually lists the CSS module already, under the component's file.
|