@jsenv/plugin-react 1.5.54 → 1.5.55

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": "1.5.54",
3
+ "version": "1.5.55",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,6 +23,7 @@
23
23
  "dependencies": {
24
24
  "@babel/plugin-transform-react-jsx": "7.25.9",
25
25
  "@babel/plugin-transform-react-jsx-development": "7.25.9",
26
+ "@babel/plugin-transform-react-jsx-source": "7.25.9",
26
27
  "@jsenv/ast": "6.4.1",
27
28
  "@jsenv/plugin-commonjs": "2.9.11",
28
29
  "@jsenv/sourcemap": "1.2.29",
@@ -99,11 +99,14 @@ const jsenvPluginJsxAndRefresh = ({
99
99
  ],
100
100
  ]
101
101
  : []),
102
+ ...(jsxEnabled && urlInfo.context.dev
103
+ ? ["@babel/plugin-transform-react-jsx-source"]
104
+ : []),
102
105
  ...(refreshEnabled
103
106
  ? [["react-refresh/babel", { skipEnvCheck: true }]]
104
107
  : []),
105
108
  ];
106
- const { code, map } = await applyBabelPlugins({
109
+ let { code, map } = await applyBabelPlugins({
107
110
  babelPlugins,
108
111
  input: urlInfo.content,
109
112
  inputIsJsModule: true,
@@ -141,6 +144,13 @@ const jsenvPluginJsxAndRefresh = ({
141
144
  index = code.indexOf(importSpecifier, index + 1);
142
145
  }
143
146
  }
147
+ const afterJsxReplace = magicSource.toContentAndSourcemap({
148
+ source: "jsenv_preact",
149
+ });
150
+ code = afterJsxReplace.content;
151
+ // can't compose import maps: the resulting sourcemap is wrong by a few lines
152
+ // (3-4) and would makes debugging experience close to horrible
153
+ // map = await composeTwoSourcemaps(map, afterJsxReplace.sourcemap);
144
154
  }
145
155
  if (refreshEnabled) {
146
156
  const hasReg = /\$RefreshReg\$\(/.test(code);
@@ -151,26 +161,27 @@ const jsenvPluginJsxAndRefresh = ({
151
161
  expectedType: "js_module",
152
162
  specifier: "@jsenv/plugin-react/src/client/react_refresh.js",
153
163
  });
154
- magicSource.prepend(`import { installReactRefresh } from ${
164
+ const prelude = `import { installReactRefresh } from ${
155
165
  reactRefreshClientReference.generatedSpecifier
156
- }
166
+ };
157
167
  const __react_refresh__ = installReactRefresh(${JSON.stringify(urlInfo.url)});
158
- `);
168
+ `;
169
+ code = `${prelude.replace(/\n/g, "")}${code}`;
159
170
  if (hasReg) {
160
- magicSource.append(`
171
+ code = `${code}
172
+
161
173
  __react_refresh__.end();
162
- import.meta.hot.accept(__react_refresh__.acceptCallback);`);
174
+ import.meta.hot.accept(__react_refresh__.acceptCallback);`;
163
175
  }
164
176
  }
165
177
  }
166
- const result = magicSource.toContentAndSourcemap();
167
178
  return {
168
- content: result.content,
179
+ content: code,
169
180
  sourcemap: map,
170
181
  // "no sourcemap is better than wrong sourcemap":
171
182
  // I don't know exactly what is resulting in bad sourcemaps
172
183
  // but I suspect hooknames or prefresh to be responsible
173
- sourcemapIsWrong: jsxEnabled && refreshEnabled,
184
+ // sourcemapIsWrong: jsxEnabled && refreshEnabled,
174
185
  };
175
186
  },
176
187
  },