@tsrx/turbopack-plugin-react 0.1.80 → 0.1.82
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/css-loader.js +4 -1
- package/src/index.js +35 -10
- package/src/loader.js +4 -1
- package/types/index.d.ts +24 -5
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Turbopack integration for @tsrx/react",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.82",
|
|
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.2.
|
|
23
|
+
"@tsrx/react": "0.2.59"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"next": ">=15.3.0"
|
package/src/css-loader.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
/** @import { RuntimeImportMode } from '@tsrx/react' */
|
|
2
|
+
|
|
1
3
|
import { compile } from '@tsrx/react';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* @typedef {{
|
|
5
7
|
* resourcePath: string,
|
|
8
|
+
* getOptions?: () => { runtimeImports?: RuntimeImportMode },
|
|
6
9
|
* async: () => (err: unknown, output?: string | null, map?: unknown) => void,
|
|
7
10
|
* }} LoaderContext
|
|
8
11
|
*/
|
|
@@ -20,7 +23,7 @@ export default function tsrx_react_turbopack_css_loader(source) {
|
|
|
20
23
|
const callback = this.async();
|
|
21
24
|
|
|
22
25
|
try {
|
|
23
|
-
const { css } = compile(source, this.resourcePath);
|
|
26
|
+
const { css } = compile(source, this.resourcePath, this.getOptions?.());
|
|
24
27
|
callback(null, css);
|
|
25
28
|
} catch (/** @type {any} */ err) {
|
|
26
29
|
callback(err);
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** @import { RuntimeImportMode } from '@tsrx/react' */
|
|
2
|
+
|
|
1
3
|
import path from 'node:path';
|
|
2
4
|
import { fileURLToPath } from 'node:url';
|
|
3
5
|
|
|
@@ -23,31 +25,49 @@ const CSS_QUERY = '?tsrx-css&lang.css';
|
|
|
23
25
|
*/
|
|
24
26
|
|
|
25
27
|
/**
|
|
26
|
-
* @
|
|
28
|
+
* @typedef {{ runtimeImports?: RuntimeImportMode }} TsrxReactTurbopackOptions
|
|
27
29
|
*/
|
|
28
|
-
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {TsrxReactTurbopackOptions} [options]
|
|
33
|
+
* @returns {{ condition: { all: any[] }, loaders: Array<string | { loader: string, options: TsrxReactTurbopackOptions }>, as: string }}
|
|
34
|
+
*/
|
|
35
|
+
export function create_tsrx_react_turbopack_rule(options = {}) {
|
|
29
36
|
return {
|
|
30
37
|
condition: {
|
|
31
38
|
all: [{ not: 'foreign' }, { not: { query: CSS_QUERY } }],
|
|
32
39
|
},
|
|
33
|
-
loaders: [TURBOPACK_JS_LOADER],
|
|
40
|
+
loaders: [with_loader_options(TURBOPACK_JS_LOADER, options)],
|
|
34
41
|
as: '*.tsx',
|
|
35
42
|
};
|
|
36
43
|
}
|
|
37
44
|
|
|
38
45
|
/**
|
|
39
|
-
* @
|
|
46
|
+
* @param {TsrxReactTurbopackOptions} [options]
|
|
47
|
+
* @returns {{ condition: { all: any[] }, loaders: Array<string | { loader: string, options: TsrxReactTurbopackOptions }>, type: string }}
|
|
40
48
|
*/
|
|
41
|
-
export function create_tsrx_react_turbopack_css_rule() {
|
|
49
|
+
export function create_tsrx_react_turbopack_css_rule(options = {}) {
|
|
42
50
|
return {
|
|
43
51
|
condition: {
|
|
44
52
|
all: [{ not: 'foreign' }, { query: CSS_QUERY }],
|
|
45
53
|
},
|
|
46
|
-
loaders: [TURBOPACK_CSS_LOADER],
|
|
54
|
+
loaders: [with_loader_options(TURBOPACK_CSS_LOADER, options)],
|
|
47
55
|
type: 'css',
|
|
48
56
|
};
|
|
49
57
|
}
|
|
50
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Preserve the original string loader shape unless the caller has compiler
|
|
61
|
+
* options that Turbopack needs to pass into the loader.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} loader
|
|
64
|
+
* @param {TsrxReactTurbopackOptions} options
|
|
65
|
+
* @returns {string | { loader: string, options: TsrxReactTurbopackOptions }}
|
|
66
|
+
*/
|
|
67
|
+
function with_loader_options(loader, options) {
|
|
68
|
+
return options.runtimeImports === undefined ? loader : { loader, options };
|
|
69
|
+
}
|
|
70
|
+
|
|
51
71
|
/**
|
|
52
72
|
* @param {string[] | undefined} resolve_extensions
|
|
53
73
|
* @returns {string[]}
|
|
@@ -62,10 +82,14 @@ function merge_resolve_extensions(resolve_extensions) {
|
|
|
62
82
|
|
|
63
83
|
/**
|
|
64
84
|
* @param {any} existing_rule
|
|
85
|
+
* @param {TsrxReactTurbopackOptions} options
|
|
65
86
|
* @returns {any}
|
|
66
87
|
*/
|
|
67
|
-
function merge_tsrx_rule(existing_rule) {
|
|
68
|
-
const rules = [
|
|
88
|
+
function merge_tsrx_rule(existing_rule, options) {
|
|
89
|
+
const rules = [
|
|
90
|
+
create_tsrx_react_turbopack_rule(options),
|
|
91
|
+
create_tsrx_react_turbopack_css_rule(options),
|
|
92
|
+
];
|
|
69
93
|
if (!existing_rule) return rules;
|
|
70
94
|
return Array.isArray(existing_rule) ? [...rules, ...existing_rule] : [...rules, existing_rule];
|
|
71
95
|
}
|
|
@@ -80,12 +104,13 @@ function merge_tsrx_rule(existing_rule) {
|
|
|
80
104
|
* finish the JSX transform.
|
|
81
105
|
*
|
|
82
106
|
* @param {NextTurbopackConfig} [next_config]
|
|
107
|
+
* @param {TsrxReactTurbopackOptions} [options]
|
|
83
108
|
* @returns {NextTurbopackConfig}
|
|
84
109
|
*/
|
|
85
|
-
export function tsrxReactTurbopack(next_config = {}) {
|
|
110
|
+
export function tsrxReactTurbopack(next_config = {}, options = {}) {
|
|
86
111
|
const turbopack = next_config.turbopack ?? {};
|
|
87
112
|
const rules = { ...(turbopack.rules ?? {}) };
|
|
88
|
-
rules['*.tsrx'] = merge_tsrx_rule(rules['*.tsrx']);
|
|
113
|
+
rules['*.tsrx'] = merge_tsrx_rule(rules['*.tsrx'], options);
|
|
89
114
|
|
|
90
115
|
return {
|
|
91
116
|
...next_config,
|
package/src/loader.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** @import { RuntimeImportMode } from '@tsrx/react' */
|
|
2
|
+
|
|
1
3
|
import { compile } from '@tsrx/react';
|
|
2
4
|
|
|
3
5
|
const CSS_QUERY = '?tsrx-css&lang.css';
|
|
@@ -99,6 +101,7 @@ function prepend_css_import(code, resource_path) {
|
|
|
99
101
|
/**
|
|
100
102
|
* @typedef {{
|
|
101
103
|
* resourcePath: string,
|
|
104
|
+
* getOptions?: () => { runtimeImports?: RuntimeImportMode },
|
|
102
105
|
* async: () => (err: unknown, output?: string | null, map?: unknown) => void,
|
|
103
106
|
* }} LoaderContext
|
|
104
107
|
*/
|
|
@@ -117,7 +120,7 @@ export default function tsrx_react_turbopack_loader(source) {
|
|
|
117
120
|
const callback = this.async();
|
|
118
121
|
|
|
119
122
|
try {
|
|
120
|
-
const { code, map, css } = compile(source, this.resourcePath);
|
|
123
|
+
const { code, map, css } = compile(source, this.resourcePath, this.getOptions?.());
|
|
121
124
|
const output = css ? prepend_css_import(code, this.resourcePath) : code;
|
|
122
125
|
const output_map = css ? null : map;
|
|
123
126
|
|
package/types/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { RuntimeImportMode } from '@tsrx/react';
|
|
2
|
+
|
|
1
3
|
export interface NextTurbopackConfig {
|
|
2
4
|
turbopack?: {
|
|
3
5
|
root?: string;
|
|
@@ -9,11 +11,21 @@ export interface NextTurbopackConfig {
|
|
|
9
11
|
[key: string]: unknown;
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
export interface TsrxReactTurbopackOptions {
|
|
15
|
+
/** Direct mode requires `@tsrx/react-runtime` as a direct production dependency. */
|
|
16
|
+
runtimeImports?: RuntimeImportMode;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface TsrxReactTurbopackLoader {
|
|
20
|
+
loader: string;
|
|
21
|
+
options: TsrxReactTurbopackOptions;
|
|
22
|
+
}
|
|
23
|
+
|
|
12
24
|
export interface TsrxReactTurbopackRule {
|
|
13
25
|
condition: {
|
|
14
26
|
all: Array<unknown>;
|
|
15
27
|
};
|
|
16
|
-
loaders: string
|
|
28
|
+
loaders: Array<string | TsrxReactTurbopackLoader>;
|
|
17
29
|
as: '*.tsx';
|
|
18
30
|
}
|
|
19
31
|
|
|
@@ -21,14 +33,21 @@ export interface TsrxReactTurbopackCssRule {
|
|
|
21
33
|
condition: {
|
|
22
34
|
all: Array<unknown>;
|
|
23
35
|
};
|
|
24
|
-
loaders: string
|
|
36
|
+
loaders: Array<string | TsrxReactTurbopackLoader>;
|
|
25
37
|
type: 'css';
|
|
26
38
|
}
|
|
27
39
|
|
|
28
|
-
export declare function create_tsrx_react_turbopack_rule(
|
|
40
|
+
export declare function create_tsrx_react_turbopack_rule(
|
|
41
|
+
options?: TsrxReactTurbopackOptions,
|
|
42
|
+
): TsrxReactTurbopackRule;
|
|
29
43
|
|
|
30
|
-
export declare function create_tsrx_react_turbopack_css_rule(
|
|
44
|
+
export declare function create_tsrx_react_turbopack_css_rule(
|
|
45
|
+
options?: TsrxReactTurbopackOptions,
|
|
46
|
+
): TsrxReactTurbopackCssRule;
|
|
31
47
|
|
|
32
|
-
export declare function tsrxReactTurbopack(
|
|
48
|
+
export declare function tsrxReactTurbopack(
|
|
49
|
+
next_config?: NextTurbopackConfig,
|
|
50
|
+
options?: TsrxReactTurbopackOptions,
|
|
51
|
+
): NextTurbopackConfig;
|
|
33
52
|
|
|
34
53
|
export default tsrxReactTurbopack;
|