@tsrx/rspack-plugin-solid 0.0.82 → 0.0.84

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
@@ -34,6 +34,10 @@ when unset. In development mode it adds `solid-refresh/babel` unless you pass
34
34
  `true` unless Rspack is running in production mode.
35
35
  - `runtimeImports`: helper import mode (`'compiler'` by default, or `'direct'` for
36
36
  standalone runtime imports).
37
+ - `platform`: optional override/fallback for the compile-time platform. Normally
38
+ the plugin reads `tsrx.platform` from the project tsconfig (including
39
+ `resolve.tsConfig` and `extends`). An override must match tsconfig. The plugin
40
+ defines all three exact flags and rejects conflicting Rspack definitions.
37
41
 
38
42
  When using `runtimeImports: 'direct'`, install the runtime as a direct production
39
43
  dependency of the package that owns the compiled modules:
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Rspack plugin for @tsrx/solid",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.0.82",
6
+ "version": "0.0.84",
7
7
  "type": "module",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -25,7 +25,8 @@
25
25
  "babel-loader": "^10.1.1",
26
26
  "babel-preset-solid": "2.0.0-rc.3",
27
27
  "solid-refresh": "0.8.0-next.7",
28
- "@tsrx/solid": "0.1.69"
28
+ "@tsrx/core": "0.1.71",
29
+ "@tsrx/solid": "0.1.71"
29
30
  },
30
31
  "peerDependencies": {
31
32
  "@rspack/core": ">=1.6.0"
package/src/css-loader.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /** @import { LoaderContext } from '@rspack/core' */
2
2
 
3
- /** @import { RuntimeImportMode } from '@tsrx/solid' */
3
+ /** @import { Platform, RuntimeImportMode } from '@tsrx/solid' */
4
4
 
5
5
  import { compile } from '@tsrx/solid';
6
6
 
@@ -9,7 +9,7 @@ import { compile } from '@tsrx/solid';
9
9
  * the scoped CSS emitted by its `<style>` block. Invoked when rspack resolves
10
10
  * the sibling `?tsrx-css&lang.css` import emitted by the JS loader.
11
11
  *
12
- * @this {LoaderContext<{ runtimeImports?: RuntimeImportMode }>}
12
+ * @this {LoaderContext<{ runtimeImports?: RuntimeImportMode, platform?: Platform }>}
13
13
  * @param {string} source
14
14
  * @returns {void}
15
15
  */
package/src/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  /** @import { Compiler, RspackPluginInstance } from '@rspack/core' */
2
- /** @import { RuntimeImportMode } from '@tsrx/solid' */
2
+ /** @import { Platform, RuntimeImportMode } from '@tsrx/solid' */
3
3
 
4
4
  import { createRequire } from 'node:module';
5
5
  import path from 'node:path';
6
6
  import { fileURLToPath } from 'node:url';
7
+ import { createPlatformDefinitions, mergePlatformDefinitions, validatePlatform } from '@tsrx/core';
8
+ import { resolveBuildPlatform } from '@tsrx/core/config';
7
9
 
8
10
  const require = createRequire(import.meta.url);
9
11
 
@@ -20,6 +22,37 @@ const SOLID_REFRESH_BABEL = require.resolve('solid-refresh/babel');
20
22
  const TSRX_EXTENSION_PATTERN = /\.tsrx$/;
21
23
  const CSS_QUERY_PATTERN = /tsrx-css/;
22
24
 
25
+ /** @param {any} plugin @returns {Record<string, unknown> | undefined} */
26
+ function get_define_plugin_definitions(plugin) {
27
+ if (plugin == null || typeof plugin !== 'object') return undefined;
28
+ if ((plugin.name ?? plugin.constructor?.name) !== 'DefinePlugin') return undefined;
29
+ if (plugin.definitions && typeof plugin.definitions === 'object') return plugin.definitions;
30
+ if (Array.isArray(plugin._args) && plugin._args[0] && typeof plugin._args[0] === 'object') {
31
+ return plugin._args[0];
32
+ }
33
+ if (plugin.options && typeof plugin.options === 'object' && !Array.isArray(plugin.options)) {
34
+ return plugin.options;
35
+ }
36
+ return undefined;
37
+ }
38
+
39
+ /** @param {Compiler} compiler @param {Platform | undefined} platform */
40
+ function apply_platform_definitions(compiler, platform) {
41
+ if (platform === undefined) return;
42
+ const compiler_with_definitions = /** @type {any} */ (compiler);
43
+ for (const plugin of compiler_with_definitions.options.plugins ?? []) {
44
+ const definitions = get_define_plugin_definitions(plugin);
45
+ if (definitions) {
46
+ mergePlatformDefinitions(definitions, platform, { integration: 'Rspack' });
47
+ }
48
+ }
49
+ const DefinePlugin = compiler_with_definitions.webpack?.DefinePlugin;
50
+ if (typeof DefinePlugin !== 'function') {
51
+ throw new Error('Rspack compiler does not expose DefinePlugin for TSRX platform flags.');
52
+ }
53
+ new DefinePlugin(createPlatformDefinitions(platform)).apply(compiler);
54
+ }
55
+
23
56
  /**
24
57
  * Rspack plugin for `.tsrx` files that compiles them via `@tsrx/solid` and
25
58
  * then delegates the final TSX + JSX transform to `babel-loader` with Solid's
@@ -30,12 +63,14 @@ const CSS_QUERY_PATTERN = /tsrx-css/;
30
63
  */
31
64
  export class TsrxSolidRspackPlugin {
32
65
  /**
33
- * @param {{ hot?: boolean, runtimeImports?: RuntimeImportMode }} [options]
66
+ * @param {{ hot?: boolean, runtimeImports?: RuntimeImportMode, platform?: Platform }} [options]
34
67
  */
35
68
  constructor(options = {}) {
69
+ this.explicit_platform = validatePlatform(options.platform);
36
70
  this.options = {
37
71
  hot: options.hot,
38
72
  runtimeImports: options.runtimeImports ?? 'compiler',
73
+ platform: this.explicit_platform,
39
74
  };
40
75
  }
41
76
 
@@ -44,7 +79,17 @@ export class TsrxSolidRspackPlugin {
44
79
  * @returns {void}
45
80
  */
46
81
  apply(compiler) {
82
+ const compiler_options = /** @type {any} */ (compiler).options;
83
+ const resolve_tsconfig = compiler_options.resolve?.tsConfig;
84
+ this.options.platform = resolveBuildPlatform({
85
+ root: /** @type {any} */ (compiler).context ?? process.cwd(),
86
+ tsconfig:
87
+ typeof resolve_tsconfig === 'string' ? resolve_tsconfig : resolve_tsconfig?.configFile,
88
+ platform: this.explicit_platform,
89
+ integration: '@tsrx/rspack-plugin-solid',
90
+ });
47
91
  const hot = this.options.hot ?? compiler.options.mode !== 'production';
92
+ apply_platform_definitions(compiler, this.options.platform);
48
93
 
49
94
  const resolve = compiler.options.resolve;
50
95
  if (resolve.extensions && !resolve.extensions.includes('.tsrx')) {
@@ -96,6 +141,7 @@ export class TsrxSolidRspackPlugin {
96
141
  loader: JS_LOADER,
97
142
  options: {
98
143
  runtimeImports: this.options.runtimeImports,
144
+ platform: this.options.platform,
99
145
  },
100
146
  },
101
147
  ],
@@ -109,6 +155,7 @@ export class TsrxSolidRspackPlugin {
109
155
  loader: CSS_LOADER,
110
156
  options: {
111
157
  runtimeImports: this.options.runtimeImports,
158
+ platform: this.options.platform,
112
159
  },
113
160
  },
114
161
  ],
package/src/js-loader.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /** @import { LoaderContext } from '@rspack/core' */
2
2
 
3
- /** @import { RuntimeImportMode } from '@tsrx/solid' */
3
+ /** @import { Platform, RuntimeImportMode } from '@tsrx/solid' */
4
4
 
5
5
  import { compile } from '@tsrx/solid';
6
6
 
@@ -9,7 +9,7 @@ import { compile } from '@tsrx/solid';
9
9
  * appends an `import` of the sibling virtual CSS module so rspack can
10
10
  * include the styles in the asset graph.
11
11
  *
12
- * @this {LoaderContext<{ runtimeImports?: RuntimeImportMode }>}
12
+ * @this {LoaderContext<{ runtimeImports?: RuntimeImportMode, platform?: Platform }>}
13
13
  * @param {string} source
14
14
  * @returns {void}
15
15
  */
package/types/index.d.ts CHANGED
@@ -1,15 +1,17 @@
1
1
  import type { Compiler, RspackPluginInstance } from '@rspack/core';
2
- import type { RuntimeImportMode } from '@tsrx/solid';
2
+ import type { Platform, RuntimeImportMode } from '@tsrx/solid';
3
3
 
4
4
  export interface TsrxSolidRspackPluginOptions {
5
5
  hot?: boolean;
6
6
  /** Direct mode requires `@tsrx/solid-runtime` as a direct production dependency. */
7
7
  runtimeImports?: RuntimeImportMode;
8
+ /** Optional override; inferred from tsconfig by default and must agree when both exist. */
9
+ platform?: Platform;
8
10
  }
9
11
 
10
12
  export declare class TsrxSolidRspackPlugin implements RspackPluginInstance {
11
13
  constructor(options?: TsrxSolidRspackPluginOptions);
12
- options: Pick<TsrxSolidRspackPluginOptions, 'hot'> &
14
+ options: Pick<TsrxSolidRspackPluginOptions, 'hot' | 'platform'> &
13
15
  Required<Pick<TsrxSolidRspackPluginOptions, 'runtimeImports'>>;
14
16
  apply(compiler: Compiler): void;
15
17
  }