@tsrx/vite-plugin-preact 0.0.94 → 0.0.96

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Vite plugin for @tsrx/preact (.tsrx modules)",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.0.94",
6
+ "version": "0.0.96",
7
7
  "type": "module",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -20,8 +20,8 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "@tsrx/core": "0.1.69",
24
- "@tsrx/preact": "0.1.69"
23
+ "@tsrx/core": "0.1.71",
24
+ "@tsrx/preact": "0.1.71"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "vite": "*"
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /** @import { Plugin } from 'vite' */
2
2
  /** @import { DepScanTransformPlugin } from '@tsrx/core/types/vite/dep-scan' */
3
- /** @import { RuntimeImportMode } from '@tsrx/preact' */
3
+ /** @import { Platform, RuntimeImportMode } from '@tsrx/preact' */
4
4
 
5
5
  /**
6
6
  * @typedef {{ code: string, map: unknown }} TsrxPreactTransformResult
@@ -35,6 +35,8 @@
35
35
 
36
36
  import { transformWithOxc } from 'vite';
37
37
  import { compile } from '@tsrx/preact';
38
+ import { mergePlatformDefinitions, validatePlatform } from '@tsrx/core';
39
+ import { resolveBuildPlatform } from '@tsrx/core/config';
38
40
  import { createDepScanTransformPlugin } from '@tsrx/core/vite/dep-scan';
39
41
 
40
42
  const TSRX_EXTENSION_PATTERN = /\.tsrx$/;
@@ -50,16 +52,34 @@ const CSS_QUERY = '?tsrx-css&lang.css';
50
52
  * jsxImportSource?: string,
51
53
  * suspenseSource?: string,
52
54
  * runtimeImports?: RuntimeImportMode,
55
+ * platform?: Platform,
56
+ * tsconfig?: string,
53
57
  * }} [options]
54
58
  * @returns {TsrxPreactPlugin}
55
59
  */
56
60
  export function tsrxPreact(options = {}) {
61
+ const explicit_platform = validatePlatform(options.platform);
62
+ let platform = explicit_platform;
57
63
  const jsxImportSource = options.jsxImportSource ?? 'preact';
58
64
  const compile_options = {
59
65
  suspenseSource: options.suspenseSource,
60
66
  runtimeImports: options.runtimeImports,
67
+ platform,
61
68
  };
62
69
 
70
+ /** @param {import('vite').UserConfig} config */
71
+ function resolve_platform(config) {
72
+ platform = resolveBuildPlatform({
73
+ root: config.root ?? process.cwd(),
74
+ tsconfig:
75
+ options.tsconfig ??
76
+ /** @type {{ tsconfig?: string }} */ (/** @type {unknown} */ (config)).tsconfig,
77
+ platform: explicit_platform,
78
+ integration: '@tsrx/vite-plugin-preact',
79
+ });
80
+ compile_options.platform = platform;
81
+ }
82
+
63
83
  /** @type {Map<string, string>} */
64
84
  const css_cache = new Map();
65
85
 
@@ -81,8 +101,16 @@ export function tsrxPreact(options = {}) {
81
101
  name: '@tsrx/vite-plugin-preact',
82
102
  enforce: 'pre',
83
103
 
84
- config() {
104
+ config(config = /** @type {import('vite').UserConfig} */ ({})) {
105
+ resolve_platform(config);
85
106
  return {
107
+ ...(platform === undefined
108
+ ? {}
109
+ : {
110
+ define: mergePlatformDefinitions(config.define, platform, {
111
+ integration: 'Vite',
112
+ }),
113
+ }),
86
114
  optimizeDeps: {
87
115
  // The scanner externalizes anything that is not a known JS
88
116
  // type unless its extension is listed here, so without this
@@ -101,6 +129,15 @@ export function tsrxPreact(options = {}) {
101
129
  };
102
130
  },
103
131
 
132
+ configEnvironment(name, config = /** @type {import('vite').EnvironmentOptions} */ ({})) {
133
+ if (platform === undefined) return;
134
+ return {
135
+ define: mergePlatformDefinitions(config.define, platform, {
136
+ integration: `Vite environment ${JSON.stringify(name)}`,
137
+ }),
138
+ };
139
+ },
140
+
104
141
  resolveId(/** @type {string} */ source) {
105
142
  if (!source.includes(CSS_QUERY)) return null;
106
143
  if (source.startsWith('\0')) return source;
@@ -163,7 +200,7 @@ export function tsrxPreact(options = {}) {
163
200
 
164
201
  /**
165
202
  * @param {string} jsxImportSource
166
- * @param {{ suspenseSource?: string, runtimeImports?: RuntimeImportMode }} compile_options
203
+ * @param {{ suspenseSource?: string, runtimeImports?: RuntimeImportMode, platform?: Platform }} compile_options
167
204
  * @returns {DepScanTransformPlugin}
168
205
  */
169
206
  function create_dep_scan_plugin(jsxImportSource, compile_options) {
package/types/index.d.ts CHANGED
@@ -1,11 +1,15 @@
1
1
  import type { Plugin } from 'vite';
2
- import type { RuntimeImportMode } from '@tsrx/preact';
2
+ import type { Platform, RuntimeImportMode } from '@tsrx/preact';
3
3
 
4
4
  export interface TsrxPreactPluginOptions {
5
5
  jsxImportSource?: string;
6
6
  suspenseSource?: string;
7
7
  /** Direct mode requires `@tsrx/preact-runtime` as a direct production dependency. */
8
8
  runtimeImports?: RuntimeImportMode;
9
+ /** Optional override; inferred from tsconfig by default and must agree when both exist. */
10
+ platform?: Platform;
11
+ /** Optional tsconfig path override, resolved from Vite's project root. */
12
+ tsconfig?: string;
9
13
  }
10
14
 
11
15
  export function tsrxPreact(options?: TsrxPreactPluginOptions): Plugin;