@vitejs/plugin-react-swc 3.7.2 → 3.8.0

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
@@ -93,6 +93,20 @@ react({
93
93
  });
94
94
  ```
95
95
 
96
+ ### useAtYourOwnRisk_mutateSwcOptions
97
+
98
+ The future of Vite is with OXC, and from the beginning this was a design choice to not exposed too many specialties from SWC so that Vite React users can move to another transformer later.
99
+ Also debugging why some specific version of decorators with some other unstable/legacy feature doesn't work is not fun, so we won't provide support for it, hence the name `useAtYourOwnRisk`.
100
+
101
+ ```ts
102
+ react({
103
+ useAtYourOwnRisk_mutateSwcOptions(options) {
104
+ options.jsc.parser.decorators = true;
105
+ options.jsc.transform.decoratorVersion = "2022-03";
106
+ },
107
+ });
108
+ ```
109
+
96
110
  ## Consistent components exports
97
111
 
98
112
  For React refresh to work correctly, your file should only export React components. The best explanation I've read is the one from the [Gatsby docs](https://www.gatsbyjs.com/docs/reference/local-development/fast-refresh/#how-it-works).
@@ -100,9 +114,3 @@ For React refresh to work correctly, your file should only export React componen
100
114
  If an incompatible change in exports is found, the module will be invalidated and HMR will propagate. To make it easier to export simple constants alongside your component, the module is only invalidated when their value changes.
101
115
 
102
116
  You can catch mistakes and get more detailed warning with this [eslint rule](https://github.com/ArnaudBarre/eslint-plugin-react-refresh).
103
-
104
- ## Migrating from `vite-plugin-swc-react-refresh`
105
-
106
- The documentation for the previous version of the plugin is available in the [v2 branch](https://github.com/vitejs/vite-plugin-react-swc/tree/v2)
107
-
108
- To migrate, see this [changelog](https://github.com/vitejs/vite-plugin-react-swc/releases/tag/v3.0.0-beta.0)
package/index.cjs CHANGED
@@ -17,7 +17,7 @@ var resolve = (0, import_module.createRequire)(
17
17
  var reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
18
18
  var refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
19
19
  var _a, _b;
20
- var isWebContainer = (_b = (_a = globalThis.process) == null ? void 0 : _a.versions) == null ? void 0 : _b.webcontainer;
20
+ var isWebContainer = (_b = (_a = globalThis.process) == null ? void 0 : _a.versions) == null ? void 0 : _b["webcontainer"];
21
21
  var react = (_options) => {
22
22
  let hmrDisabled = false;
23
23
  const options = {
@@ -25,7 +25,8 @@ var react = (_options) => {
25
25
  tsDecorators: _options == null ? void 0 : _options.tsDecorators,
26
26
  plugins: (_options == null ? void 0 : _options.plugins) ? _options == null ? void 0 : _options.plugins.map((el) => [resolve(el[0]), el[1]]) : void 0,
27
27
  devTarget: (_options == null ? void 0 : _options.devTarget) ?? "es2020",
28
- parserConfig: _options == null ? void 0 : _options.parserConfig
28
+ parserConfig: _options == null ? void 0 : _options.parserConfig,
29
+ useAtYourOwnRisk_mutateSwcOptions: _options == null ? void 0 : _options.useAtYourOwnRisk_mutateSwcOptions
29
30
  };
30
31
  return [
31
32
  {
@@ -160,7 +161,7 @@ var transformWithOptions = async (id, code, target, options, reactConfig) => {
160
161
  if (!parser) return;
161
162
  let result;
162
163
  try {
163
- result = await (0, import_core.transform)(code, {
164
+ const swcOptions = {
164
165
  filename: id,
165
166
  swcrc: false,
166
167
  configFile: false,
@@ -174,7 +175,11 @@ var transformWithOptions = async (id, code, target, options, reactConfig) => {
174
175
  react: reactConfig
175
176
  }
176
177
  }
177
- });
178
+ };
179
+ if (options.useAtYourOwnRisk_mutateSwcOptions) {
180
+ options.useAtYourOwnRisk_mutateSwcOptions(swcOptions);
181
+ }
182
+ result = await (0, import_core.transform)(code, swcOptions);
178
183
  } catch (e) {
179
184
  const message = e.message;
180
185
  const fileStartIndex = message.indexOf("\u256D\u2500[");
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ParserConfig, JscTarget } from "@swc/core";
2
- import { PluginOption } from "vite";
1
+ import { type ParserConfig, type JscTarget, type Options as SWCOptions } from "@swc/core";
2
+ import type { PluginOption } from "vite";
3
3
  type Options = {
4
4
  /**
5
5
  * Control where the JSX factory is imported from.
@@ -29,6 +29,14 @@ type Options = {
29
29
  * Exclusion of node_modules should be handled by the function if needed.
30
30
  */
31
31
  parserConfig?: (id: string) => ParserConfig | undefined;
32
+ /**
33
+ * The future of Vite is with OXC, and from the beginning this was a design choice
34
+ * to not exposed too many specialties from SWC so that Vite React users can move to
35
+ * another transformer later.
36
+ * Also debugging why some specific version of decorators with some other unstable/legacy
37
+ * feature doesn't work is not fun, so we won't provide support for it, hence the name `useAtYourOwnRisk`
38
+ */
39
+ useAtYourOwnRisk_mutateSwcOptions?: (options: SWCOptions) => void;
32
40
  };
33
41
  declare const react: (_options?: Options) => PluginOption[];
34
42
  export default react;
package/index.mjs CHANGED
@@ -18,7 +18,7 @@ var resolve = createRequire(
18
18
  var reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
19
19
  var refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
20
20
  var _a, _b;
21
- var isWebContainer = (_b = (_a = globalThis.process) == null ? void 0 : _a.versions) == null ? void 0 : _b.webcontainer;
21
+ var isWebContainer = (_b = (_a = globalThis.process) == null ? void 0 : _a.versions) == null ? void 0 : _b["webcontainer"];
22
22
  var react = (_options) => {
23
23
  let hmrDisabled = false;
24
24
  const options = {
@@ -26,7 +26,8 @@ var react = (_options) => {
26
26
  tsDecorators: _options == null ? void 0 : _options.tsDecorators,
27
27
  plugins: (_options == null ? void 0 : _options.plugins) ? _options == null ? void 0 : _options.plugins.map((el) => [resolve(el[0]), el[1]]) : void 0,
28
28
  devTarget: (_options == null ? void 0 : _options.devTarget) ?? "es2020",
29
- parserConfig: _options == null ? void 0 : _options.parserConfig
29
+ parserConfig: _options == null ? void 0 : _options.parserConfig,
30
+ useAtYourOwnRisk_mutateSwcOptions: _options == null ? void 0 : _options.useAtYourOwnRisk_mutateSwcOptions
30
31
  };
31
32
  return [
32
33
  {
@@ -161,7 +162,7 @@ var transformWithOptions = async (id, code, target, options, reactConfig) => {
161
162
  if (!parser) return;
162
163
  let result;
163
164
  try {
164
- result = await transform(code, {
165
+ const swcOptions = {
165
166
  filename: id,
166
167
  swcrc: false,
167
168
  configFile: false,
@@ -175,7 +176,11 @@ var transformWithOptions = async (id, code, target, options, reactConfig) => {
175
176
  react: reactConfig
176
177
  }
177
178
  }
178
- });
179
+ };
180
+ if (options.useAtYourOwnRisk_mutateSwcOptions) {
181
+ options.useAtYourOwnRisk_mutateSwcOptions(swcOptions);
182
+ }
183
+ result = await transform(code, swcOptions);
179
184
  } catch (e) {
180
185
  const message = e.message;
181
186
  const fileStartIndex = message.indexOf("\u256D\u2500[");
@@ -208,7 +213,7 @@ var silenceUseClientWarning = (userConfig) => ({
208
213
  }
209
214
  }
210
215
  });
211
- var src_default = react;
216
+ var index_default = react;
212
217
  export {
213
- src_default as default
218
+ index_default as default
214
219
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-react-swc",
3
3
  "description": "Speed up your Vite dev server with SWC",
4
- "version": "3.7.2",
4
+ "version": "3.8.0",
5
5
  "author": "Arnaud Barré (https://github.com/ArnaudBarre)",
6
6
  "license": "MIT",
7
7
  "repository": "github:vitejs/vite-plugin-react-swc",
@@ -28,6 +28,6 @@
28
28
  "vite": "^4 || ^5 || ^6"
29
29
  },
30
30
  "dependencies": {
31
- "@swc/core": "^1.7.26"
31
+ "@swc/core": "^1.10.15"
32
32
  }
33
33
  }