@tsrx/vite-plugin-react 0.0.90 → 0.0.92
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 +12 -8
- package/types/index.d.ts +3 -0
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.92",
|
|
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.1.
|
|
24
|
-
"@tsrx/react": "0.2.
|
|
23
|
+
"@tsrx/core": "0.1.59",
|
|
24
|
+
"@tsrx/react": "0.2.59"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"vite": "*"
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** @import { Plugin } from 'vite' */
|
|
2
2
|
/** @import { DepScanTransformPlugin } from '@tsrx/core/types/vite/dep-scan' */
|
|
3
|
+
/** @import { RuntimeImportMode } from '@tsrx/react' */
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @typedef {{ code: string, map: unknown }} TsrxReactTransformResult
|
|
@@ -49,11 +50,12 @@ const CSS_QUERY = '?tsrx-css&lang.css';
|
|
|
49
50
|
* `jsx-runtime`. Per-component `<style>` blocks are emitted as virtual CSS
|
|
50
51
|
* modules that are imported by the compiled JS output.
|
|
51
52
|
*
|
|
52
|
-
* @param {{ jsxImportSource?: string }} [options]
|
|
53
|
+
* @param {{ jsxImportSource?: string, runtimeImports?: RuntimeImportMode }} [options]
|
|
53
54
|
* @returns {TsrxReactPlugin}
|
|
54
55
|
*/
|
|
55
56
|
export function tsrxReact(options = {}) {
|
|
56
57
|
const jsxImportSource = options.jsxImportSource ?? 'react';
|
|
58
|
+
const compile_options = { runtimeImports: options.runtimeImports };
|
|
57
59
|
|
|
58
60
|
/** @type {Map<string, string>} */
|
|
59
61
|
const css_cache = new Map();
|
|
@@ -64,7 +66,7 @@ export function tsrxReact(options = {}) {
|
|
|
64
66
|
* @returns {void}
|
|
65
67
|
*/
|
|
66
68
|
function update_css_cache(source, id) {
|
|
67
|
-
const { css } = compile(source, id);
|
|
69
|
+
const { css } = compile(source, id, compile_options);
|
|
68
70
|
if (css) {
|
|
69
71
|
css_cache.set(id, css);
|
|
70
72
|
} else {
|
|
@@ -83,7 +85,7 @@ export function tsrxReact(options = {}) {
|
|
|
83
85
|
return;
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
return create_dep_scan_config(jsxImportSource);
|
|
88
|
+
return create_dep_scan_config(jsxImportSource, compile_options);
|
|
87
89
|
},
|
|
88
90
|
|
|
89
91
|
resolveId(/** @type {string} */ source) {
|
|
@@ -102,7 +104,7 @@ export function tsrxReact(options = {}) {
|
|
|
102
104
|
async transform(/** @type {string} */ code, /** @type {string} */ id) {
|
|
103
105
|
if (!TSRX_EXTENSION_PATTERN.test(id)) return null;
|
|
104
106
|
|
|
105
|
-
let { code: tsx_code, css, map } = compile(code, id);
|
|
107
|
+
let { code: tsx_code, css, map } = compile(code, id, compile_options);
|
|
106
108
|
|
|
107
109
|
let source = tsx_code;
|
|
108
110
|
if (css) {
|
|
@@ -149,9 +151,10 @@ export function tsrxReact(options = {}) {
|
|
|
149
151
|
|
|
150
152
|
/**
|
|
151
153
|
* @param {string} jsxImportSource
|
|
154
|
+
* @param {{ runtimeImports?: RuntimeImportMode }} compile_options
|
|
152
155
|
* @returns {TsrxReactEnvironmentConfig}
|
|
153
156
|
*/
|
|
154
|
-
function create_dep_scan_config(jsxImportSource) {
|
|
157
|
+
function create_dep_scan_config(jsxImportSource, compile_options) {
|
|
155
158
|
return {
|
|
156
159
|
optimizeDeps: {
|
|
157
160
|
// The scanner externalizes anything that is not a known JS type
|
|
@@ -164,7 +167,7 @@ function create_dep_scan_config(jsxImportSource) {
|
|
|
164
167
|
// Point it at the configured source, or the scan fails outright on
|
|
165
168
|
// an unresolvable `react/jsx-dev-runtime` in a project without react.
|
|
166
169
|
transform: { jsx: { importSource: jsxImportSource } },
|
|
167
|
-
plugins: [create_dep_scan_plugin(jsxImportSource)],
|
|
170
|
+
plugins: [create_dep_scan_plugin(jsxImportSource, compile_options)],
|
|
168
171
|
},
|
|
169
172
|
},
|
|
170
173
|
};
|
|
@@ -172,13 +175,14 @@ function create_dep_scan_config(jsxImportSource) {
|
|
|
172
175
|
|
|
173
176
|
/**
|
|
174
177
|
* @param {string} jsxImportSource
|
|
178
|
+
* @param {{ runtimeImports?: RuntimeImportMode }} compile_options
|
|
175
179
|
* @returns {DepScanTransformPlugin}
|
|
176
180
|
*/
|
|
177
|
-
function create_dep_scan_plugin(jsxImportSource) {
|
|
181
|
+
function create_dep_scan_plugin(jsxImportSource, compile_options) {
|
|
178
182
|
return createDepScanTransformPlugin({
|
|
179
183
|
name: '@tsrx/vite-plugin-react:dep-scan',
|
|
180
184
|
filter: TSRX_EXTENSION_PATTERN,
|
|
181
|
-
compile,
|
|
185
|
+
compile: (code, id) => compile(code, id, compile_options),
|
|
182
186
|
// The main transform always emits automatic-runtime JSX, so the jsx
|
|
183
187
|
// runtime module is a dependency of every compiled `.tsrx` file. Import
|
|
184
188
|
// it explicitly so the scanner records it no matter how the scan's own
|
package/types/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { EnvironmentOptions, Plugin } from 'vite';
|
|
2
|
+
import type { RuntimeImportMode } from '@tsrx/react';
|
|
2
3
|
import type { DepScanTransformPlugin } from '@tsrx/core/types/vite/dep-scan';
|
|
3
4
|
|
|
4
5
|
export interface TsrxReactPluginOptions {
|
|
5
6
|
jsxImportSource?: string;
|
|
7
|
+
/** Direct mode requires `@tsrx/react-runtime` as a direct production dependency. */
|
|
8
|
+
runtimeImports?: RuntimeImportMode;
|
|
6
9
|
}
|
|
7
10
|
|
|
8
11
|
export interface TsrxReactTransformResult {
|