@tsrx/vite-plugin-react 0.0.14 → 0.0.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 +2 -2
- package/src/index.js +27 -6
- package/types/index.d.ts +21 -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.15",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@tsrx/react": "0.1.
|
|
23
|
+
"@tsrx/react": "0.1.7"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"vite": "*"
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
/** @import { Plugin } from 'vite' */
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {{ code: string, map: unknown }} TsrxReactTransformResult
|
|
5
|
+
* @typedef {{
|
|
6
|
+
* (code: string, id: `${string}.tsrx`): Promise<TsrxReactTransformResult>,
|
|
7
|
+
* (code: string, id: string): Promise<TsrxReactTransformResult | null>,
|
|
8
|
+
* }} TsrxReactTransform
|
|
9
|
+
* @typedef {{
|
|
10
|
+
* (source: `${string}?tsrx-css&lang.css`): `\0${string}?tsrx-css&lang.css`,
|
|
11
|
+
* (source: string): string | null,
|
|
12
|
+
* }} TsrxReactResolveId
|
|
13
|
+
* @typedef {{
|
|
14
|
+
* (id: `\0${string}?tsrx-css&lang.css`): string,
|
|
15
|
+
* (id: string): string | null,
|
|
16
|
+
* }} TsrxReactLoad
|
|
17
|
+
* @typedef {Omit<Plugin, 'transform' | 'resolveId' | 'load'> & {
|
|
18
|
+
* transform: TsrxReactTransform,
|
|
19
|
+
* resolveId: TsrxReactResolveId,
|
|
20
|
+
* load: TsrxReactLoad,
|
|
21
|
+
* }} TsrxReactPlugin
|
|
22
|
+
*/
|
|
23
|
+
|
|
3
24
|
import { transformWithOxc } from 'vite';
|
|
4
25
|
import { compile } from '@tsrx/react';
|
|
5
26
|
|
|
@@ -13,7 +34,7 @@ const CSS_QUERY = '?tsrx-css&lang.css';
|
|
|
13
34
|
* modules that are imported by the compiled JS output.
|
|
14
35
|
*
|
|
15
36
|
* @param {{ jsxImportSource?: string }} [options]
|
|
16
|
-
* @returns {
|
|
37
|
+
* @returns {TsrxReactPlugin}
|
|
17
38
|
*/
|
|
18
39
|
export function tsrxReact(options = {}) {
|
|
19
40
|
const jsxImportSource = options.jsxImportSource ?? 'react';
|
|
@@ -21,24 +42,24 @@ export function tsrxReact(options = {}) {
|
|
|
21
42
|
/** @type {Map<string, string>} */
|
|
22
43
|
const css_cache = new Map();
|
|
23
44
|
|
|
24
|
-
return {
|
|
45
|
+
return /** @type {TsrxReactPlugin} */ ({
|
|
25
46
|
name: '@tsrx/vite-plugin-react',
|
|
26
47
|
enforce: 'pre',
|
|
27
48
|
|
|
28
|
-
resolveId(source) {
|
|
49
|
+
resolveId(/** @type {string} */ source) {
|
|
29
50
|
if (!source.includes(CSS_QUERY)) return null;
|
|
30
51
|
if (source.startsWith('\0')) return source;
|
|
31
52
|
return '\0' + source;
|
|
32
53
|
},
|
|
33
54
|
|
|
34
|
-
load(id) {
|
|
55
|
+
load(/** @type {string} */ id) {
|
|
35
56
|
if (!id.startsWith('\0') || !id.includes(CSS_QUERY)) return null;
|
|
36
57
|
const key = id.slice(1).split('?')[0];
|
|
37
58
|
const css = css_cache.get(key);
|
|
38
59
|
return css ?? '';
|
|
39
60
|
},
|
|
40
61
|
|
|
41
|
-
async transform(code, id) {
|
|
62
|
+
async transform(/** @type {string} */ code, /** @type {string} */ id) {
|
|
42
63
|
if (!TSRX_EXTENSION_PATTERN.test(id)) return null;
|
|
43
64
|
|
|
44
65
|
const { code: tsx_code, css } = compile(code, id);
|
|
@@ -63,7 +84,7 @@ export function tsrxReact(options = {}) {
|
|
|
63
84
|
|
|
64
85
|
return { code: result.code, map: result.map };
|
|
65
86
|
},
|
|
66
|
-
};
|
|
87
|
+
});
|
|
67
88
|
}
|
|
68
89
|
|
|
69
90
|
export default tsrxReact;
|
package/types/index.d.ts
CHANGED
|
@@ -4,5 +4,25 @@ export interface TsrxReactPluginOptions {
|
|
|
4
4
|
jsxImportSource?: string;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export
|
|
7
|
+
export interface TsrxReactTransformResult {
|
|
8
|
+
code: string;
|
|
9
|
+
map: unknown;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface TsrxReactPlugin extends Omit<Plugin, 'transform' | 'resolveId' | 'load'> {
|
|
13
|
+
transform: {
|
|
14
|
+
(code: string, id: `${string}.tsrx`): Promise<TsrxReactTransformResult>;
|
|
15
|
+
(code: string, id: string): Promise<TsrxReactTransformResult | null>;
|
|
16
|
+
};
|
|
17
|
+
resolveId: {
|
|
18
|
+
(source: `${string}?tsrx-css&lang.css`): `\0${string}?tsrx-css&lang.css`;
|
|
19
|
+
(source: string): string | null;
|
|
20
|
+
};
|
|
21
|
+
load: {
|
|
22
|
+
(id: `\0${string}?tsrx-css&lang.css`): string;
|
|
23
|
+
(id: string): string | null;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function tsrxReact(options?: TsrxReactPluginOptions): TsrxReactPlugin;
|
|
8
28
|
export default tsrxReact;
|