@jsenv/plugin-react 0.0.12 → 0.0.15
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 +3 -3
- package/src/jsenv_plugin_react.js +15 -69
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/plugin-transform-react-jsx": "7.17.3",
|
|
30
30
|
"@babel/plugin-transform-react-jsx-development": "7.16.7",
|
|
31
|
-
"@jsenv/
|
|
31
|
+
"@jsenv/plugin-commonjs": "0.0.5",
|
|
32
32
|
"@jsenv/url-meta": "6.2.0",
|
|
33
|
-
"@jsenv/utils": "1.
|
|
33
|
+
"@jsenv/utils": "1.8.2",
|
|
34
34
|
"react-refresh": "0.13.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
@@ -7,9 +7,7 @@ import { normalizeStructuredMetaMap, urlToMeta } from "@jsenv/url-meta"
|
|
|
7
7
|
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
8
8
|
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
9
9
|
import { composeTwoSourcemaps } from "@jsenv/utils/sourcemap/sourcemap_composition_v3.js"
|
|
10
|
-
import {
|
|
11
|
-
import { commonJsToJsModule } from "@jsenv/cjs-to-esm"
|
|
12
|
-
import { fetchOriginalUrlInfo } from "@jsenv/core/src/plugins/transpilation/fetch_original_url_info.js"
|
|
10
|
+
import { jsenvPluginCommonJs } from "@jsenv/plugin-commonjs"
|
|
13
11
|
|
|
14
12
|
import { jsenvPluginReactRefreshPreamble } from "./jsenv_plugin_react_refresh_preamble.js"
|
|
15
13
|
|
|
@@ -18,8 +16,16 @@ export const jsenvPluginReact = ({
|
|
|
18
16
|
hotRefreshPatterns,
|
|
19
17
|
} = {}) => {
|
|
20
18
|
return [
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
jsenvPluginCommonJs({
|
|
20
|
+
name: "jsenv:react_commonjs",
|
|
21
|
+
logLevel: asJsModuleLogLevel,
|
|
22
|
+
include: {
|
|
23
|
+
"**/node_modules/react/": true,
|
|
24
|
+
"**/node_modules/react-dom/": { external: ["react"] },
|
|
25
|
+
"**/node_modules/react/jsx-runtime/": { external: ["react"] },
|
|
26
|
+
"**/node_modules/react/jsx-dev-runtime": { external: ["react"] },
|
|
27
|
+
"**/react-refresh/": { external: ["react"] },
|
|
28
|
+
},
|
|
23
29
|
}),
|
|
24
30
|
jsenvPluginReactRefreshPreamble(),
|
|
25
31
|
jsenvPluginJsxAndRefresh({
|
|
@@ -28,80 +34,20 @@ export const jsenvPluginReact = ({
|
|
|
28
34
|
]
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
const jsenvPluginReactAsJsModule = ({ asJsModuleLogLevel }) => {
|
|
32
|
-
return {
|
|
33
|
-
name: "jsenv:react_as_js_module",
|
|
34
|
-
appliesDuring: "*",
|
|
35
|
-
redirectUrl: {
|
|
36
|
-
js_import_export: (reference) => {
|
|
37
|
-
if (
|
|
38
|
-
[
|
|
39
|
-
"react",
|
|
40
|
-
"react-dom",
|
|
41
|
-
"react/jsx-runtime",
|
|
42
|
-
"react/jsx-dev-runtime",
|
|
43
|
-
"react-refresh",
|
|
44
|
-
].includes(reference.specifier)
|
|
45
|
-
) {
|
|
46
|
-
return injectQueryParams(reference.url, {
|
|
47
|
-
react_as_js_module: "",
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
return null
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
fetchUrlContent: async (urlInfo, context) => {
|
|
54
|
-
const originalUrlInfo = await fetchOriginalUrlInfo({
|
|
55
|
-
urlInfo,
|
|
56
|
-
context,
|
|
57
|
-
searchParam: "react_as_js_module",
|
|
58
|
-
// during this fetch we don't want to alter the original file
|
|
59
|
-
// so we consider it as text
|
|
60
|
-
expectedType: "text",
|
|
61
|
-
})
|
|
62
|
-
if (!originalUrlInfo) {
|
|
63
|
-
return null
|
|
64
|
-
}
|
|
65
|
-
const { content, sourcemap } = await commonJsToJsModule({
|
|
66
|
-
logLevel: asJsModuleLogLevel,
|
|
67
|
-
rootDirectoryUrl: context.rootDirectoryUrl,
|
|
68
|
-
sourceFileUrl: originalUrlInfo.url,
|
|
69
|
-
external: ["react"],
|
|
70
|
-
processEnvNodeEnv:
|
|
71
|
-
context.scenario === "dev" || context.scenario === "test"
|
|
72
|
-
? "development"
|
|
73
|
-
: "production",
|
|
74
|
-
})
|
|
75
|
-
return {
|
|
76
|
-
type: "js_module",
|
|
77
|
-
contentType: "text/javascript",
|
|
78
|
-
content,
|
|
79
|
-
sourcemap,
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
37
|
const jsenvPluginJsxAndRefresh = ({
|
|
86
|
-
|
|
38
|
+
jsxInclude = {
|
|
87
39
|
"./**/*.jsx": true,
|
|
88
40
|
"./**/*.tsx": true,
|
|
89
|
-
"./**/node_modules/": false,
|
|
90
41
|
},
|
|
91
|
-
|
|
42
|
+
refreshInclude = {
|
|
92
43
|
"./**/*.jsx": true,
|
|
93
44
|
"./**/*.tsx": true,
|
|
94
|
-
"./**/node_modules/": false,
|
|
95
45
|
},
|
|
96
46
|
}) => {
|
|
97
47
|
const structuredMetaMap = normalizeStructuredMetaMap(
|
|
98
48
|
{
|
|
99
|
-
jsx:
|
|
100
|
-
refresh:
|
|
101
|
-
hookNames: {
|
|
102
|
-
"./**/*": true,
|
|
103
|
-
"./**/node_modules": false,
|
|
104
|
-
},
|
|
49
|
+
jsx: jsxInclude,
|
|
50
|
+
refresh: refreshInclude,
|
|
105
51
|
},
|
|
106
52
|
"file://",
|
|
107
53
|
)
|