@tsrx/bun-plugin-react 0.1.93 → 0.1.95

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 CHANGED
@@ -38,6 +38,10 @@ Bun.plugin(tsrxReact());
38
38
  - `jsxImportSource`: automatic JSX runtime import source (default: `'react'`).
39
39
  - `runtimeImports`: helper import mode (`'compiler'` by default, or `'direct'` for
40
40
  standalone runtime imports).
41
+ - `platform`: optional override/fallback for the compile-time platform. Normally
42
+ the plugin reads `tsrx.platform` from Bun's selected/nearest tsconfig, including
43
+ `extends`. An override must match tsconfig. For `Bun.build`, all three exact
44
+ flags are defined and conflicting definitions are rejected.
41
45
  - `emitCss`: whether to emit virtual CSS imports (default: `true`).
42
46
  - `include`, `exclude`: regex filters for source files.
43
47
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Bun plugin for @tsrx/react (.tsrx modules)",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.1.93",
6
+ "version": "0.1.95",
7
7
  "type": "module",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -20,7 +20,8 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "@tsrx/react": "0.2.70"
23
+ "@tsrx/core": "0.2.0",
24
+ "@tsrx/react": "0.3.0"
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/react' */
2
+ /** @import { Platform, RuntimeImportMode } from '@tsrx/react' */
3
3
 
4
4
  import { readFile } from 'node:fs/promises';
5
5
  import { compile } from '@tsrx/react';
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
  * emitCss?: boolean,
17
19
  * runtimeImports?: RuntimeImportMode,
20
+ * platform?: Platform,
18
21
  * }} TsrxReactBunPluginOptions
19
22
  */
20
23
 
@@ -90,9 +93,9 @@ function create_transpiler(jsx_import_source, target) {
90
93
  * @returns {BunPlugin}
91
94
  */
92
95
  export function tsrxReact(options = {}) {
96
+ const explicit_platform = validatePlatform(options.platform);
93
97
  const jsx_import_source = options.jsxImportSource ?? 'react';
94
98
  const emit_css = options.emitCss ?? true;
95
- const compile_options = { runtimeImports: options.runtimeImports };
96
99
 
97
100
  /** @type {Map<string, string>} */
98
101
  const css_cache = new Map();
@@ -104,6 +107,21 @@ export function tsrxReact(options = {}) {
104
107
  // build.config is only present for Bun.build(); runtime registration
105
108
  // via Bun.plugin(), including bun:test preloads, does not provide it.
106
109
  const build_config = build.config ?? {};
110
+ const platform = resolveBuildPlatform({
111
+ root: build_config.root ?? process.cwd(),
112
+ tsconfig: typeof build_config.tsconfig === 'string' ? build_config.tsconfig : undefined,
113
+ platform: explicit_platform,
114
+ integration: '@tsrx/bun-plugin-react',
115
+ });
116
+ const compile_options = { runtimeImports: options.runtimeImports, platform };
117
+ if (platform !== undefined && build.config) {
118
+ build.config.define = /** @type {Record<string, string>} */ (
119
+ mergePlatformDefinitions(build.config.define, platform, {
120
+ integration: 'Bun',
121
+ serialize: true,
122
+ })
123
+ );
124
+ }
107
125
  const transpiler = create_transpiler(jsx_import_source, build_config.target);
108
126
 
109
127
  build.onResolve({ filter: CSS_QUERY_PATTERN }, (args) => ({
package/types/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import type { BunPlugin } from 'bun';
2
- import type { RuntimeImportMode } from '@tsrx/react';
2
+ import type { Platform, RuntimeImportMode } from '@tsrx/react';
3
3
 
4
4
  export interface TsrxReactBunPluginOptions {
5
5
  /** Direct mode requires `@tsrx/react-runtime` as a direct production dependency. */
6
6
  runtimeImports?: RuntimeImportMode;
7
+ /** Optional override; inferred from tsconfig by default and must agree when both exist. */
8
+ platform?: Platform;
7
9
  include?: RegExp;
8
10
  exclude?: RegExp | RegExp[];
9
11
  jsxImportSource?: string;