@jsenv/plugin-react 1.9.0 → 1.9.2
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 +2 -2
- package/src/jsenv_plugin_react.js +22 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-react",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@babel/plugin-transform-react-jsx": "8.0.1",
|
|
28
28
|
"@babel/plugin-transform-react-jsx-development": "8.0.1",
|
|
29
|
-
"@jsenv/ast": "6.10.
|
|
29
|
+
"@jsenv/ast": "6.10.1",
|
|
30
30
|
"@jsenv/plugin-commonjs": "2.11.22",
|
|
31
31
|
"@jsenv/sourcemap": "1.4.3",
|
|
32
32
|
"@jsenv/url-meta": "8.5.7",
|
|
@@ -6,8 +6,24 @@ import { applyBabelPlugins } from "@jsenv/ast";
|
|
|
6
6
|
import { jsenvPluginCommonJs } from "@jsenv/plugin-commonjs";
|
|
7
7
|
import { createMagicSource } from "@jsenv/sourcemap";
|
|
8
8
|
import { URL_META } from "@jsenv/url-meta";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
9
10
|
import { jsenvPluginReactRefreshPreamble } from "./jsenv_plugin_react_refresh_preamble.js";
|
|
10
11
|
|
|
12
|
+
// Babel resolves bare plugin names from the project root, where our own
|
|
13
|
+
// dependencies are not guaranteed to be installed (they are hoisted only when
|
|
14
|
+
// the app happens to depend on them too). Resolving them from here and handing
|
|
15
|
+
// babel an absolute path makes it work whatever the node_modules layout is.
|
|
16
|
+
const babelPluginFileCache = new Map();
|
|
17
|
+
const babelPluginFile = (specifier) => {
|
|
18
|
+
const fromCache = babelPluginFileCache.get(specifier);
|
|
19
|
+
if (fromCache) {
|
|
20
|
+
return fromCache;
|
|
21
|
+
}
|
|
22
|
+
const file = fileURLToPath(import.meta.resolve(specifier));
|
|
23
|
+
babelPluginFileCache.set(specifier, file);
|
|
24
|
+
return file;
|
|
25
|
+
};
|
|
26
|
+
|
|
11
27
|
export const jsenvPluginReact = ({
|
|
12
28
|
asJsModuleLogLevel,
|
|
13
29
|
jsxTranspilation = true,
|
|
@@ -89,9 +105,11 @@ const jsenvPluginJsxAndRefresh = ({
|
|
|
89
105
|
...(jsxEnabled
|
|
90
106
|
? [
|
|
91
107
|
[
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
108
|
+
babelPluginFile(
|
|
109
|
+
urlInfo.context.dev
|
|
110
|
+
? "@babel/plugin-transform-react-jsx-development"
|
|
111
|
+
: "@babel/plugin-transform-react-jsx",
|
|
112
|
+
),
|
|
95
113
|
{
|
|
96
114
|
runtime: "automatic",
|
|
97
115
|
importSource: "react",
|
|
@@ -103,7 +121,7 @@ const jsenvPluginJsxAndRefresh = ({
|
|
|
103
121
|
]
|
|
104
122
|
: []),
|
|
105
123
|
...(refreshEnabled
|
|
106
|
-
? [["react-refresh/babel", { skipEnvCheck: true }]]
|
|
124
|
+
? [[babelPluginFile("react-refresh/babel"), { skipEnvCheck: true }]]
|
|
107
125
|
: []),
|
|
108
126
|
];
|
|
109
127
|
let { code, map } = await applyBabelPlugins({
|