@tsrx/vite-plugin-react 0.0.82 → 0.0.84
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 +51 -1
- package/types/index.d.ts +14 -1
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Vite plugin for @tsrx/react (.tsrx modules)",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.84",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@tsrx/
|
|
23
|
+
"@tsrx/core": "0.1.52",
|
|
24
|
+
"@tsrx/react": "0.2.52"
|
|
24
25
|
},
|
|
25
26
|
"peerDependencies": {
|
|
26
27
|
"vite": "*"
|
|
@@ -34,8 +35,7 @@
|
|
|
34
35
|
"react-dom": "^19.2.0",
|
|
35
36
|
"react-router": "^7.15.0",
|
|
36
37
|
"typescript": "^5.9.3",
|
|
37
|
-
"vite": "^8.1.5"
|
|
38
|
-
"@tsrx/core": "0.1.50"
|
|
38
|
+
"vite": "^8.1.5"
|
|
39
39
|
},
|
|
40
40
|
"files": [
|
|
41
41
|
"src",
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** @import { Plugin } from 'vite' */
|
|
2
|
+
/** @import { DepScanTransformPlugin } from '@tsrx/core/types/vite/dep-scan' */
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @typedef {{ code: string, map: unknown }} TsrxReactTransformResult
|
|
@@ -14,7 +15,17 @@
|
|
|
14
15
|
* (id: `\0${string}?tsrx-css&lang.css`): string,
|
|
15
16
|
* (id: string): string | null,
|
|
16
17
|
* }} TsrxReactLoad
|
|
17
|
-
* @typedef {
|
|
18
|
+
* @typedef {() => {
|
|
19
|
+
* optimizeDeps: {
|
|
20
|
+
* extensions: string[],
|
|
21
|
+
* rolldownOptions: {
|
|
22
|
+
* transform: { jsx: { importSource: string } },
|
|
23
|
+
* plugins: [DepScanTransformPlugin],
|
|
24
|
+
* },
|
|
25
|
+
* },
|
|
26
|
+
* }} TsrxReactConfigHook
|
|
27
|
+
* @typedef {Omit<Plugin, 'config' | 'transform' | 'resolveId' | 'load'> & {
|
|
28
|
+
* config: TsrxReactConfigHook,
|
|
18
29
|
* transform: TsrxReactTransform,
|
|
19
30
|
* resolveId: TsrxReactResolveId,
|
|
20
31
|
* load: TsrxReactLoad,
|
|
@@ -23,6 +34,7 @@
|
|
|
23
34
|
|
|
24
35
|
import { transformWithOxc } from 'vite';
|
|
25
36
|
import { compile } from '@tsrx/react';
|
|
37
|
+
import { createDepScanTransformPlugin } from '@tsrx/core/vite/dep-scan';
|
|
26
38
|
|
|
27
39
|
const TSRX_EXTENSION_PATTERN = /\.tsrx$/;
|
|
28
40
|
const CSS_QUERY = '?tsrx-css&lang.css';
|
|
@@ -60,6 +72,26 @@ export function tsrxReact(options = {}) {
|
|
|
60
72
|
name: '@tsrx/vite-plugin-react',
|
|
61
73
|
enforce: 'pre',
|
|
62
74
|
|
|
75
|
+
config() {
|
|
76
|
+
return {
|
|
77
|
+
optimizeDeps: {
|
|
78
|
+
// The scanner externalizes anything that is not a known JS
|
|
79
|
+
// type unless its extension is listed here, so without this
|
|
80
|
+
// entry the dep-scan plugin below never runs.
|
|
81
|
+
extensions: ['.tsrx'],
|
|
82
|
+
rolldownOptions: {
|
|
83
|
+
// The scan runs its own jsx transform over the tsx the
|
|
84
|
+
// dep-scan plugin hands back, and that transform defaults to
|
|
85
|
+
// react's runtime. Point it at the configured source, or the
|
|
86
|
+
// scan fails outright on an unresolvable
|
|
87
|
+
// `react/jsx-dev-runtime` in a project that has no react.
|
|
88
|
+
transform: { jsx: { importSource: jsxImportSource } },
|
|
89
|
+
plugins: [create_dep_scan_plugin(jsxImportSource)],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
|
|
63
95
|
resolveId(/** @type {string} */ source) {
|
|
64
96
|
if (!source.includes(CSS_QUERY)) return null;
|
|
65
97
|
if (source.startsWith('\0')) return source;
|
|
@@ -121,4 +153,22 @@ export function tsrxReact(options = {}) {
|
|
|
121
153
|
});
|
|
122
154
|
}
|
|
123
155
|
|
|
156
|
+
/**
|
|
157
|
+
* @param {string} jsxImportSource
|
|
158
|
+
* @returns {DepScanTransformPlugin}
|
|
159
|
+
*/
|
|
160
|
+
function create_dep_scan_plugin(jsxImportSource) {
|
|
161
|
+
return createDepScanTransformPlugin({
|
|
162
|
+
name: '@tsrx/vite-plugin-react:dep-scan',
|
|
163
|
+
filter: TSRX_EXTENSION_PATTERN,
|
|
164
|
+
compile,
|
|
165
|
+
// The main transform always emits automatic-runtime JSX, so the jsx
|
|
166
|
+
// runtime module is a dependency of every compiled `.tsrx` file. Import
|
|
167
|
+
// it explicitly so the scanner records it no matter how the scan's own
|
|
168
|
+
// jsx transform is configured — in dev it resolves `jsx-dev-runtime`,
|
|
169
|
+
// while the transform below emits plain `jsx-runtime`.
|
|
170
|
+
imports: [jsxImportSource + '/jsx-runtime'],
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
124
174
|
export default tsrxReact;
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
+
import type { DepScanTransformPlugin } from '@tsrx/core/types/vite/dep-scan';
|
|
2
3
|
|
|
3
4
|
export interface TsrxReactPluginOptions {
|
|
4
5
|
jsxImportSource?: string;
|
|
@@ -9,7 +10,19 @@ export interface TsrxReactTransformResult {
|
|
|
9
10
|
map: unknown;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export interface TsrxReactPlugin extends Omit<
|
|
13
|
+
export interface TsrxReactPlugin extends Omit<
|
|
14
|
+
Plugin,
|
|
15
|
+
'config' | 'transform' | 'resolveId' | 'load'
|
|
16
|
+
> {
|
|
17
|
+
config: () => {
|
|
18
|
+
optimizeDeps: {
|
|
19
|
+
extensions: string[];
|
|
20
|
+
rolldownOptions: {
|
|
21
|
+
transform: { jsx: { importSource: string } };
|
|
22
|
+
plugins: [DepScanTransformPlugin];
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
13
26
|
transform: {
|
|
14
27
|
(code: string, id: `${string}.tsrx`): Promise<TsrxReactTransformResult>;
|
|
15
28
|
(code: string, id: string): Promise<TsrxReactTransformResult | null>;
|