@jsenv/plugin-react 0.0.10 → 0.0.13

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-react",
3
- "version": "0.0.10",
3
+ "version": "0.0.13",
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/cjs-to-esm": "0.0.3",
31
+ "@jsenv/plugin-commonjs": "0.0.5",
32
32
  "@jsenv/url-meta": "6.2.0",
33
- "@jsenv/utils": "1.7.5",
33
+ "@jsenv/utils": "1.8.0",
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 { injectQueryParams } from "@jsenv/utils/urls/url_utils.js"
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,15 @@ export const jsenvPluginReact = ({
18
16
  hotRefreshPatterns,
19
17
  } = {}) => {
20
18
  return [
21
- jsenvPluginReactAsJsModule({
22
- asJsModuleLogLevel,
19
+ jsenvPluginCommonJs({
20
+ logLevel: asJsModuleLogLevel,
21
+ include: {
22
+ "**/node_modules/react/": true,
23
+ "**/node_modules/react-dom/": { external: ["react"] },
24
+ "**/node_modules/react/jsx-runtime/": { external: ["react"] },
25
+ "**/node_modules/react/jsx-dev-runtime": { external: ["react"] },
26
+ "**/react-refresh/": { external: ["react"] },
27
+ },
23
28
  }),
24
29
  jsenvPluginReactRefreshPreamble(),
25
30
  jsenvPluginJsxAndRefresh({
@@ -28,76 +33,20 @@ export const jsenvPluginReact = ({
28
33
  ]
29
34
  }
30
35
 
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
- })
71
- return {
72
- type: "js_module",
73
- contentType: "text/javascript",
74
- content,
75
- sourcemap,
76
- }
77
- },
78
- }
79
- }
80
-
81
36
  const jsenvPluginJsxAndRefresh = ({
82
- jsxPatterns = {
37
+ jsxInclude = {
83
38
  "./**/*.jsx": true,
84
39
  "./**/*.tsx": true,
85
- "./**/node_modules/": false,
86
40
  },
87
- refreshPatterns = {
41
+ refreshInclude = {
88
42
  "./**/*.jsx": true,
89
43
  "./**/*.tsx": true,
90
- "./**/node_modules/": false,
91
44
  },
92
45
  }) => {
93
46
  const structuredMetaMap = normalizeStructuredMetaMap(
94
47
  {
95
- jsx: jsxPatterns,
96
- refresh: refreshPatterns,
97
- hookNames: {
98
- "./**/*": true,
99
- "./**/node_modules": false,
100
- },
48
+ jsx: jsxInclude,
49
+ refresh: refreshInclude,
101
50
  },
102
51
  "file://",
103
52
  )