@tsrx/bun-plugin-preact 0.0.92 → 0.0.94
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/README.md +4 -0
- package/package.json +3 -2
- package/src/index.js +24 -5
- package/types/index.d.ts +3 -1
package/README.md
CHANGED
|
@@ -39,6 +39,10 @@ Bun.plugin(tsrxPreact());
|
|
|
39
39
|
- `suspenseSource`: module used by the compiler for Suspense imports.
|
|
40
40
|
- `runtimeImports`: helper import mode (`'compiler'` by default, or `'direct'` for
|
|
41
41
|
standalone runtime imports).
|
|
42
|
+
- `platform`: optional override/fallback for the compile-time platform. Normally
|
|
43
|
+
the plugin reads `tsrx.platform` from Bun's selected/nearest tsconfig, including
|
|
44
|
+
`extends`. An override must match tsconfig. For `Bun.build`, all three exact
|
|
45
|
+
flags are defined and conflicting definitions are rejected.
|
|
42
46
|
- `emitCss`: whether to emit virtual CSS imports (default: `true`).
|
|
43
47
|
- `include`, `exclude`: regex filters for source files.
|
|
44
48
|
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Bun plugin for @tsrx/preact (.tsrx modules)",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.94",
|
|
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.71",
|
|
24
|
+
"@tsrx/preact": "0.1.71"
|
|
24
25
|
},
|
|
25
26
|
"peerDependencies": {
|
|
26
27
|
"bun": "^1.0.0",
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/** @import { BunPlugin, Target, Transpiler } from 'bun' */
|
|
2
|
-
/** @import { RuntimeImportMode } from '@tsrx/preact' */
|
|
2
|
+
/** @import { Platform, RuntimeImportMode } from '@tsrx/preact' */
|
|
3
3
|
|
|
4
4
|
import { readFile } from 'node:fs/promises';
|
|
5
5
|
import { compile } from '@tsrx/preact';
|
|
6
|
+
import { mergePlatformDefinitions, validatePlatform } from '@tsrx/core';
|
|
7
|
+
import { resolveBuildPlatform } from '@tsrx/core/config';
|
|
6
8
|
|
|
7
9
|
const DEFAULT_INCLUDE = /\.tsrx$/;
|
|
8
10
|
const CSS_QUERY = '?tsrx-css&lang.css';
|
|
@@ -15,6 +17,7 @@ const CSS_QUERY_PATTERN = /\?tsrx-css&lang\.css$/;
|
|
|
15
17
|
* jsxImportSource?: string,
|
|
16
18
|
* suspenseSource?: string,
|
|
17
19
|
* runtimeImports?: RuntimeImportMode,
|
|
20
|
+
* platform?: Platform,
|
|
18
21
|
* emitCss?: boolean,
|
|
19
22
|
* }} TsrxPreactBunPluginOptions
|
|
20
23
|
*/
|
|
@@ -91,12 +94,9 @@ function create_transpiler(jsx_import_source, target) {
|
|
|
91
94
|
* @returns {BunPlugin}
|
|
92
95
|
*/
|
|
93
96
|
export function tsrxPreact(options = {}) {
|
|
97
|
+
const explicit_platform = validatePlatform(options.platform);
|
|
94
98
|
const jsx_import_source = options.jsxImportSource ?? 'preact';
|
|
95
99
|
const emit_css = options.emitCss ?? true;
|
|
96
|
-
const compile_options = {
|
|
97
|
-
suspenseSource: options.suspenseSource,
|
|
98
|
-
runtimeImports: options.runtimeImports,
|
|
99
|
-
};
|
|
100
100
|
|
|
101
101
|
/** @type {Map<string, string>} */
|
|
102
102
|
const css_cache = new Map();
|
|
@@ -108,6 +108,25 @@ export function tsrxPreact(options = {}) {
|
|
|
108
108
|
// build.config is only present for Bun.build(); runtime registration
|
|
109
109
|
// via Bun.plugin(), including bun:test preloads, does not provide it.
|
|
110
110
|
const build_config = build.config ?? {};
|
|
111
|
+
const platform = resolveBuildPlatform({
|
|
112
|
+
root: build_config.root ?? process.cwd(),
|
|
113
|
+
tsconfig: typeof build_config.tsconfig === 'string' ? build_config.tsconfig : undefined,
|
|
114
|
+
platform: explicit_platform,
|
|
115
|
+
integration: '@tsrx/bun-plugin-preact',
|
|
116
|
+
});
|
|
117
|
+
const compile_options = {
|
|
118
|
+
suspenseSource: options.suspenseSource,
|
|
119
|
+
runtimeImports: options.runtimeImports,
|
|
120
|
+
platform,
|
|
121
|
+
};
|
|
122
|
+
if (platform !== undefined && build.config) {
|
|
123
|
+
build.config.define = /** @type {Record<string, string>} */ (
|
|
124
|
+
mergePlatformDefinitions(build.config.define, platform, {
|
|
125
|
+
integration: 'Bun',
|
|
126
|
+
serialize: true,
|
|
127
|
+
})
|
|
128
|
+
);
|
|
129
|
+
}
|
|
111
130
|
const transpiler = create_transpiler(jsx_import_source, build_config.target);
|
|
112
131
|
|
|
113
132
|
build.onResolve({ filter: CSS_QUERY_PATTERN }, (args) => ({
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BunPlugin } from 'bun';
|
|
2
|
-
import type { RuntimeImportMode } from '@tsrx/preact';
|
|
2
|
+
import type { Platform, RuntimeImportMode } from '@tsrx/preact';
|
|
3
3
|
|
|
4
4
|
export interface TsrxPreactBunPluginOptions {
|
|
5
5
|
include?: RegExp;
|
|
@@ -8,6 +8,8 @@ export interface TsrxPreactBunPluginOptions {
|
|
|
8
8
|
suspenseSource?: string;
|
|
9
9
|
/** Direct mode requires `@tsrx/preact-runtime` as a direct production dependency. */
|
|
10
10
|
runtimeImports?: RuntimeImportMode;
|
|
11
|
+
/** Optional override; inferred from tsconfig by default and must agree when both exist. */
|
|
12
|
+
platform?: Platform;
|
|
11
13
|
emitCss?: boolean;
|
|
12
14
|
}
|
|
13
15
|
|