@tsrx/rspack-plugin-vue 0.0.82 → 0.0.83

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
@@ -33,6 +33,10 @@ when unset. Editor typechecking should set `jsxImportSource: 'vue-jsx-vapor'`.
33
33
  macros and uses `runtimeModuleName: 'vue-jsx-vapor'`.
34
34
  - `runtimeImports`: helper import mode (`'compiler'` by default, or `'direct'` for
35
35
  standalone runtime imports).
36
+ - `platform`: optional override/fallback for the compile-time platform. Normally
37
+ the plugin reads `tsrx.platform` from the project tsconfig (including
38
+ `resolve.tsConfig` and `extends`). An override must match tsconfig. The plugin
39
+ defines all three exact flags and rejects conflicting Rspack definitions.
36
40
 
37
41
  When using `runtimeImports: 'direct'`, install the runtime as a direct production
38
42
  dependency of the package that owns the compiled modules:
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Rspack plugin for @tsrx/vue",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.0.82",
6
+ "version": "0.0.83",
7
7
  "type": "module",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -21,7 +21,8 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "source-map": "^0.7.6",
24
- "@tsrx/vue": "0.1.70"
24
+ "@tsrx/core": "0.1.71",
25
+ "@tsrx/vue": "0.1.71"
25
26
  },
26
27
  "peerDependencies": {
27
28
  "@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/vue' */
3
+ /** @import { Platform, RuntimeImportMode } from '@tsrx/vue' */
4
4
 
5
5
  import { compile } from '@tsrx/vue';
6
6
 
@@ -9,7 +9,7 @@ import { compile } from '@tsrx/vue';
9
9
  * scoped CSS emitted by its `<style>` block. Invoked when rspack resolves the
10
10
  * 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,8 +1,10 @@
1
1
  /** @import { Compiler, RspackPluginInstance } from '@rspack/core' */
2
- /** @import { RuntimeImportMode } from '@tsrx/vue' */
2
+ /** @import { Platform, RuntimeImportMode } from '@tsrx/vue' */
3
3
 
4
4
  import path from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
+ import { createPlatformDefinitions, mergePlatformDefinitions, validatePlatform } from '@tsrx/core';
7
+ import { resolveBuildPlatform } from '@tsrx/core/config';
6
8
 
7
9
  const __filename = fileURLToPath(import.meta.url);
8
10
  const __dirname = path.dirname(__filename);
@@ -16,6 +18,37 @@ const TSRX_EXTENSION_PATTERN = /\.tsrx$/;
16
18
  const CSS_QUERY_PATTERN = /tsrx-css/;
17
19
  const SOURCE_EXTENSION_PATTERN = /\.[cm]?[jt]sx?$/;
18
20
 
21
+ /** @param {any} plugin @returns {Record<string, unknown> | undefined} */
22
+ function get_define_plugin_definitions(plugin) {
23
+ if (plugin == null || typeof plugin !== 'object') return undefined;
24
+ if ((plugin.name ?? plugin.constructor?.name) !== 'DefinePlugin') return undefined;
25
+ if (plugin.definitions && typeof plugin.definitions === 'object') return plugin.definitions;
26
+ if (Array.isArray(plugin._args) && plugin._args[0] && typeof plugin._args[0] === 'object') {
27
+ return plugin._args[0];
28
+ }
29
+ if (plugin.options && typeof plugin.options === 'object' && !Array.isArray(plugin.options)) {
30
+ return plugin.options;
31
+ }
32
+ return undefined;
33
+ }
34
+
35
+ /** @param {Compiler} compiler @param {Platform | undefined} platform */
36
+ function apply_platform_definitions(compiler, platform) {
37
+ if (platform === undefined) return;
38
+ const compiler_with_definitions = /** @type {any} */ (compiler);
39
+ for (const plugin of compiler_with_definitions.options.plugins ?? []) {
40
+ const definitions = get_define_plugin_definitions(plugin);
41
+ if (definitions) {
42
+ mergePlatformDefinitions(definitions, platform, { integration: 'Rspack' });
43
+ }
44
+ }
45
+ const DefinePlugin = compiler_with_definitions.webpack?.DefinePlugin;
46
+ if (typeof DefinePlugin !== 'function') {
47
+ throw new Error('Rspack compiler does not expose DefinePlugin for TSRX platform flags.');
48
+ }
49
+ new DefinePlugin(createPlatformDefinitions(platform)).apply(compiler);
50
+ }
51
+
19
52
  /**
20
53
  * Rspack plugin for `.tsrx` files that compiles them via `@tsrx/vue`, runs the
21
54
  * result through `vue-jsx-vapor`, and finally strips the remaining TypeScript
@@ -27,12 +60,14 @@ const SOURCE_EXTENSION_PATTERN = /\.[cm]?[jt]sx?$/;
27
60
  */
28
61
  export class TsrxVueRspackPlugin {
29
62
  /**
30
- * @param {{ vapor?: { macros?: boolean | object, compiler?: { runtimeModuleName?: string } }, runtimeImports?: RuntimeImportMode }} [options]
63
+ * @param {{ vapor?: { macros?: boolean | object, compiler?: { runtimeModuleName?: string } }, runtimeImports?: RuntimeImportMode, platform?: Platform }} [options]
31
64
  */
32
65
  constructor(options = {}) {
66
+ this.explicit_platform = validatePlatform(options.platform);
33
67
  this.options = {
34
68
  vapor: options.vapor,
35
69
  runtimeImports: options.runtimeImports ?? 'compiler',
70
+ platform: this.explicit_platform,
36
71
  };
37
72
  }
38
73
 
@@ -41,6 +76,16 @@ export class TsrxVueRspackPlugin {
41
76
  * @returns {void}
42
77
  */
43
78
  apply(compiler) {
79
+ const compiler_options = /** @type {any} */ (compiler).options;
80
+ const resolve_tsconfig = compiler_options.resolve?.tsConfig;
81
+ this.options.platform = resolveBuildPlatform({
82
+ root: /** @type {any} */ (compiler).context ?? process.cwd(),
83
+ tsconfig:
84
+ typeof resolve_tsconfig === 'string' ? resolve_tsconfig : resolve_tsconfig?.configFile,
85
+ platform: this.explicit_platform,
86
+ integration: '@tsrx/rspack-plugin-vue',
87
+ });
88
+ apply_platform_definitions(compiler, this.options.platform);
44
89
  const resolve = compiler.options.resolve;
45
90
  if (resolve.extensions && !resolve.extensions.includes('.tsrx')) {
46
91
  resolve.extensions.push('.tsrx');
@@ -96,6 +141,7 @@ export class TsrxVueRspackPlugin {
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 TsrxVueRspackPlugin {
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/vue' */
3
+ /** @import { Platform, RuntimeImportMode } from '@tsrx/vue' */
4
4
 
5
5
  import { compile } from '@tsrx/vue';
6
6
 
@@ -9,7 +9,7 @@ import { compile } from '@tsrx/vue';
9
9
  * present, 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,5 +1,5 @@
1
1
  import type { Compiler, RspackPluginInstance } from '@rspack/core';
2
- import type { RuntimeImportMode } from '@tsrx/vue';
2
+ import type { Platform, RuntimeImportMode } from '@tsrx/vue';
3
3
 
4
4
  export interface TsrxVueRspackVaporOptions {
5
5
  macros?: boolean | object;
@@ -12,11 +12,13 @@ export interface TsrxVueRspackPluginOptions {
12
12
  vapor?: TsrxVueRspackVaporOptions;
13
13
  /** Direct mode requires `@tsrx/vue-runtime` as a direct production dependency. */
14
14
  runtimeImports?: RuntimeImportMode;
15
+ /** Optional override; inferred from tsconfig by default and must agree when both exist. */
16
+ platform?: Platform;
15
17
  }
16
18
 
17
19
  export declare class TsrxVueRspackPlugin implements RspackPluginInstance {
18
20
  constructor(options?: TsrxVueRspackPluginOptions);
19
- options: Pick<TsrxVueRspackPluginOptions, 'vapor'> &
21
+ options: Pick<TsrxVueRspackPluginOptions, 'vapor' | 'platform'> &
20
22
  Required<Pick<TsrxVueRspackPluginOptions, 'runtimeImports'>>;
21
23
  apply(compiler: Compiler): void;
22
24
  }