@jsenv/plugin-react 0.2.11 → 0.3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-react",
3
- "version": "0.2.11",
3
+ "version": "0.3.2",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,8 +26,8 @@
26
26
  "dependencies": {
27
27
  "@babel/plugin-transform-react-jsx": "7.18.6",
28
28
  "@babel/plugin-transform-react-jsx-development": "7.18.6",
29
- "@jsenv/ast": "1.1.3",
30
- "@jsenv/plugin-commonjs": "0.4.0",
29
+ "@jsenv/ast": "1.2.0",
30
+ "@jsenv/plugin-commonjs": "1.0.2",
31
31
  "@jsenv/sourcemap": "1.0.4",
32
32
  "@jsenv/url-meta": "7.0.0",
33
33
  "react-refresh": "0.14.0"
@@ -56,18 +56,18 @@ const jsenvPluginJsxAndRefresh = ({
56
56
  name: "jsenv:jsx_and_refresh",
57
57
  appliesDuring: "*",
58
58
  transformUrlContent: {
59
- js_module: async (urlInfo, { scenario, referenceUtils }) => {
59
+ js_module: async (urlInfo, context) => {
60
60
  const urlMeta = URL_META.applyAssociations({
61
61
  url: urlInfo.url,
62
62
  associations,
63
63
  })
64
64
  const jsxEnabled = urlMeta.jsx
65
- const refreshEnabled = scenario === "dev" ? urlMeta.refresh : false
65
+ const refreshEnabled = context.scenarios.dev ? urlMeta.refresh : false
66
66
  const babelPlugins = [
67
67
  ...(jsxEnabled
68
68
  ? [
69
69
  [
70
- scenario === "dev"
70
+ context.scenarios.dev
71
71
  ? "@babel/plugin-transform-react-jsx-development"
72
72
  : "@babel/plugin-transform-react-jsx",
73
73
  {
@@ -103,7 +103,7 @@ const jsenvPluginJsxAndRefresh = ({
103
103
  let index = code.indexOf(importSpecifier)
104
104
  while (index > -1) {
105
105
  const specifier = importSpecifier.slice(1, -1)
106
- const [injectedReference] = referenceUtils.inject({
106
+ const [injectedReference] = context.referenceUtils.inject({
107
107
  type: "js_import_export",
108
108
  expectedType: "js_module",
109
109
  specifier,
@@ -121,11 +121,13 @@ const jsenvPluginJsxAndRefresh = ({
121
121
  const hasReg = /\$RefreshReg\$\(/.test(code)
122
122
  const hasSig = /\$RefreshSig\$\(/.test(code)
123
123
  if (hasReg || hasSig) {
124
- const [reactRefreshClientReference] = referenceUtils.inject({
125
- type: "js_import_export",
126
- expectedType: "js_module",
127
- specifier: "@jsenv/plugin-react/src/client/react_refresh.js",
128
- })
124
+ const [reactRefreshClientReference] = context.referenceUtils.inject(
125
+ {
126
+ type: "js_import_export",
127
+ expectedType: "js_module",
128
+ specifier: "@jsenv/plugin-react/src/client/react_refresh.js",
129
+ },
130
+ )
129
131
  magicSource.prepend(`import { installReactRefresh } from ${
130
132
  reactRefreshClientReference.generatedSpecifier
131
133
  }
@@ -13,23 +13,24 @@ export const jsenvPluginReactRefreshPreamble = () => {
13
13
 
14
14
  return {
15
15
  name: "jsenv:react_refresh_preamble",
16
- appliesDuring: { dev: true },
16
+ appliesDuring: "dev",
17
17
  transformUrlContent: {
18
18
  html: (urlInfo, context) => {
19
19
  const htmlAst = parseHtmlString(urlInfo.content)
20
20
  const [reactRefreshPreambleReference] = context.referenceUtils.inject({
21
21
  type: "script_src",
22
+ subtype: "js_module",
22
23
  expectedType: "js_module",
23
24
  specifier: reactRefreshPreambleClientFileUrl,
24
25
  })
25
26
  injectScriptNodeAsEarlyAsPossible(
26
27
  htmlAst,
27
28
  createHtmlNode({
28
- "tagName": "script",
29
- "type": "module",
30
- "src": reactRefreshPreambleReference.generatedSpecifier,
31
- "injected-by": "jsenv:react_refresh_preamble",
29
+ tagName: "script",
30
+ type: "module",
31
+ src: reactRefreshPreambleReference.generatedSpecifier,
32
32
  }),
33
+ "jsenv:react_refresh_preamble",
33
34
  )
34
35
  const htmlModified = stringifyHtmlAst(htmlAst)
35
36
  return htmlModified