@vitejs/plugin-react 1.0.8 → 1.1.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/CHANGELOG.md CHANGED
@@ -1,13 +1,20 @@
1
- ## [1.0.8](https://github.com/vitejs/vite/compare/plugin-react@1.0.7...plugin-react@1.0.8) (2021-11-09)
1
+ # [1.1.0](https://github.com/vitejs/vite/compare/plugin-react@1.1.0-beta.1...plugin-react@1.1.0) (2021-11-22)
2
+
3
+
4
+
5
+ # [1.1.0-beta.1](https://github.com/vitejs/vite/compare/plugin-react@1.1.0-beta.0...plugin-react@1.1.0-beta.1) (2021-11-19)
2
6
 
3
7
 
4
8
  ### Bug Fixes
5
9
 
6
- * **plugin-react:** apply `babel.plugins` to project files only ([#5255](https://github.com/vitejs/vite/issues/5255)) ([93c0016](https://github.com/vitejs/vite/commit/93c0016c89cadfebeae8f113087b70b2a18a7d23))
10
+ * **plugin-react:** apply `babel.plugins` to project files only ([#5255](https://github.com/vitejs/vite/issues/5255)) ([377d0be](https://github.com/vitejs/vite/commit/377d0be5cf85a50240e160beaaafda77b7199452))
11
+ * **plugin-react:** remove querystring from sourcemap filename ([#5760](https://github.com/vitejs/vite/issues/5760)) ([d93a9fa](https://github.com/vitejs/vite/commit/d93a9fab8986f3659e79d7b0b065e99ef625a5dd))
12
+ * **plugin-react:** restore usage of extension instead of id ([#5761](https://github.com/vitejs/vite/issues/5761)) ([59471b1](https://github.com/vitejs/vite/commit/59471b186612d3da0083543e23d660747d3287f3))
13
+ * **plugin-react:** uncompiled JSX in linked pkgs ([#5669](https://github.com/vitejs/vite/issues/5669)) ([41a7c9c](https://github.com/vitejs/vite/commit/41a7c9ccfbc1a7bc60aec672056eac3966ddd036))
7
14
 
8
15
 
9
16
 
10
- ## [1.0.7](https://github.com/vitejs/vite/compare/plugin-react@1.0.6...plugin-react@1.0.7) (2021-10-28)
17
+ # [1.1.0-beta.0](https://github.com/vitejs/vite/compare/plugin-react@1.0.6...plugin-react@1.1.0-beta.0) (2021-10-28)
11
18
 
12
19
 
13
20
  ### Bug Fixes
package/dist/index.js CHANGED
@@ -358,15 +358,16 @@ function viteReact(opts = {}) {
358
358
  }
359
359
  config.plugins.forEach((plugin) => (plugin.name === "react-refresh" || plugin !== viteReactJsx && plugin.name === "vite:react-jsx") && config.logger.warn(`[@vitejs/plugin-react] You should stop using "${plugin.name}" since this plugin conflicts with it.`));
360
360
  },
361
- async transform(code, id, ssr) {
361
+ async transform(code, id, options) {
362
362
  var _a2, _b2, _c2, _d;
363
+ const ssr = typeof options === "boolean" ? options : (options == null ? void 0 : options.ssr) === true;
363
364
  const [filepath, querystring = ""] = id.split("?");
364
365
  const [extension = ""] = querystring.match(fileExtensionRE) || filepath.match(fileExtensionRE) || [];
365
366
  if (/\.(mjs|[tj]sx?)$/.test(extension)) {
366
367
  const isJSX = extension.endsWith("x");
367
368
  const isNodeModules = id.includes("/node_modules/");
368
369
  const isProjectFile = !isNodeModules && (id[0] === "\0" || id.startsWith(projectRoot + "/"));
369
- let plugins = isProjectFile ? [...userPlugins] : [];
370
+ const plugins = isProjectFile ? [...userPlugins] : [];
370
371
  let useFastRefresh = false;
371
372
  if (!skipFastRefresh && !ssr && !isNodeModules) {
372
373
  const isReactModule = isJSX || code.includes("react");
@@ -381,8 +382,8 @@ function viteReact(opts = {}) {
381
382
  let ast;
382
383
  if (!isProjectFile || isJSX) {
383
384
  if (useAutomaticRuntime) {
384
- const [restoredAst, isCommonJS] = !isProjectFile ? await restoreJSX(babel, code, id) : [null, false];
385
- if (isProjectFile || (ast = restoredAst)) {
385
+ const [restoredAst, isCommonJS] = !isProjectFile && !isJSX ? await restoreJSX(babel, code, id) : [null, false];
386
+ if (isJSX || (ast = restoredAst)) {
386
387
  plugins.push([
387
388
  await loadPlugin("@babel/plugin-transform-react-jsx" + (isProduction ? "" : "-development")),
388
389
  {
@@ -415,13 +416,13 @@ function viteReact(opts = {}) {
415
416
  "classPrivateProperties",
416
417
  "classPrivateMethods"
417
418
  ];
418
- if (!id.endsWith(".ts")) {
419
+ if (!extension.endsWith(".ts")) {
419
420
  parserPlugins.push("jsx");
420
421
  }
421
- if (/\.tsx?$/.test(id)) {
422
+ if (/\.tsx?$/.test(extension)) {
422
423
  parserPlugins.push("typescript");
423
424
  }
424
- const isReasonReact = id.endsWith(".bs.js");
425
+ const isReasonReact = extension.endsWith(".bs.js");
425
426
  const babelOpts = __spreadProps(__spreadValues({
426
427
  babelrc: false,
427
428
  configFile: false
@@ -429,7 +430,7 @@ function viteReact(opts = {}) {
429
430
  ast: !isReasonReact,
430
431
  root: projectRoot,
431
432
  filename: id,
432
- sourceFileName: id,
433
+ sourceFileName: filepath,
433
434
  parserOpts: __spreadProps(__spreadValues({}, (_c2 = opts.babel) == null ? void 0 : _c2.parserOpts), {
434
435
  sourceType: "module",
435
436
  allowAwaitOutsideFunction: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-react",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "license": "MIT",
5
5
  "author": "Evan You",
6
6
  "contributors": [
@@ -33,13 +33,13 @@
33
33
  },
34
34
  "homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-react#readme",
35
35
  "dependencies": {
36
- "@babel/core": "^7.15.5",
37
- "@babel/plugin-transform-react-jsx": "^7.14.9",
38
- "@babel/plugin-transform-react-jsx-development": "^7.14.5",
39
- "@babel/plugin-transform-react-jsx-self": "^7.14.9",
40
- "@babel/plugin-transform-react-jsx-source": "^7.14.5",
36
+ "@babel/core": "^7.16.0",
37
+ "@babel/plugin-transform-react-jsx": "^7.16.0",
38
+ "@babel/plugin-transform-react-jsx-development": "^7.16.0",
39
+ "@babel/plugin-transform-react-jsx-self": "^7.16.0",
40
+ "@babel/plugin-transform-react-jsx-source": "^7.16.0",
41
41
  "@rollup/pluginutils": "^4.1.1",
42
- "react-refresh": "^0.10.0",
42
+ "react-refresh": "^0.11.0",
43
43
  "resolve": "^1.20.0"
44
44
  }
45
45
  }
package/src/index.ts CHANGED
@@ -98,7 +98,8 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
98
98
  )
99
99
  )
100
100
  },
101
- async transform(code, id, ssr) {
101
+ async transform(code, id, options) {
102
+ const ssr = typeof options === 'boolean' ? options : options?.ssr === true
102
103
  // File extension could be mocked/overriden in querystring.
103
104
  const [filepath, querystring = ''] = id.split('?')
104
105
  const [extension = ''] =
@@ -112,7 +113,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
112
113
  const isProjectFile =
113
114
  !isNodeModules && (id[0] === '\0' || id.startsWith(projectRoot + '/'))
114
115
 
115
- let plugins = isProjectFile ? [...userPlugins] : []
116
+ const plugins = isProjectFile ? [...userPlugins] : []
116
117
 
117
118
  let useFastRefresh = false
118
119
  if (!skipFastRefresh && !ssr && !isNodeModules) {
@@ -133,11 +134,12 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
133
134
  // By reverse-compiling "React.createElement" calls into JSX,
134
135
  // React elements provided by dependencies will also use the
135
136
  // automatic runtime!
136
- const [restoredAst, isCommonJS] = !isProjectFile
137
- ? await restoreJSX(babel, code, id)
138
- : [null, false]
137
+ const [restoredAst, isCommonJS] =
138
+ !isProjectFile && !isJSX
139
+ ? await restoreJSX(babel, code, id)
140
+ : [null, false]
139
141
 
140
- if (isProjectFile || (ast = restoredAst)) {
142
+ if (isJSX || (ast = restoredAst)) {
141
143
  plugins.push([
142
144
  await loadPlugin(
143
145
  '@babel/plugin-transform-react-jsx' +
@@ -196,15 +198,15 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
196
198
  'classPrivateMethods'
197
199
  ]
198
200
 
199
- if (!id.endsWith('.ts')) {
201
+ if (!extension.endsWith('.ts')) {
200
202
  parserPlugins.push('jsx')
201
203
  }
202
204
 
203
- if (/\.tsx?$/.test(id)) {
205
+ if (/\.tsx?$/.test(extension)) {
204
206
  parserPlugins.push('typescript')
205
207
  }
206
208
 
207
- const isReasonReact = id.endsWith('.bs.js')
209
+ const isReasonReact = extension.endsWith('.bs.js')
208
210
 
209
211
  const babelOpts: TransformOptions = {
210
212
  babelrc: false,
@@ -213,7 +215,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
213
215
  ast: !isReasonReact,
214
216
  root: projectRoot,
215
217
  filename: id,
216
- sourceFileName: id,
218
+ sourceFileName: filepath,
217
219
  parserOpts: {
218
220
  ...opts.babel?.parserOpts,
219
221
  sourceType: 'module',