@jsenv/plugin-preact 1.2.26 → 1.2.27

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-preact",
3
- "version": "1.2.26",
3
+ "version": "1.2.27",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,7 +27,7 @@
27
27
  "babel-plugin-transform-hook-names": "1.0.2",
28
28
  "@babel/plugin-transform-react-jsx": "7.21.5",
29
29
  "@babel/plugin-transform-react-jsx-development": "7.18.6",
30
- "@jsenv/ast": "3.0.7",
30
+ "@jsenv/ast": "3.0.8",
31
31
  "@jsenv/sourcemap": "1.0.10",
32
32
  "@jsenv/url-meta": "8.1.0",
33
33
  "@prefresh/babel-plugin": "0.4.4",
@@ -1,34 +1,34 @@
1
- import "@prefresh/core"
2
- import { flush } from "@prefresh/utils"
1
+ import "@prefresh/core";
2
+ import { flush } from "@prefresh/utils";
3
3
 
4
4
  export const installPreactRefresh = (url) => {
5
- let prevRefreshReg = self.$RefreshReg$ || (() => {})
6
- let prevRefreshSig = self.$RefreshSig$ || (() => (type) => type)
5
+ let prevRefreshReg = self.$RefreshReg$ || (() => {});
6
+ let prevRefreshSig = self.$RefreshSig$ || (() => (type) => type);
7
7
  self.$RefreshReg$ = (type, id) => {
8
- self.__PREFRESH__.register(type, `${url} ${id}`)
9
- }
8
+ self.__PREFRESH__.register(type, `${url} ${id}`);
9
+ };
10
10
  self.$RefreshSig$ = () => {
11
- let status = "begin"
12
- let savedType
11
+ let status = "begin";
12
+ let savedType;
13
13
  return (type, key, forceReset, getCustomHooks) => {
14
- if (!savedType) savedType = type
14
+ if (!savedType) savedType = type;
15
15
  status = self.__PREFRESH__.sign(
16
16
  type || savedType,
17
17
  key,
18
18
  forceReset,
19
19
  getCustomHooks,
20
20
  status,
21
- )
22
- return type
23
- }
24
- }
21
+ );
22
+ return type;
23
+ };
24
+ };
25
25
  return {
26
26
  end: () => {
27
- self.$RefreshReg$ = prevRefreshReg
28
- self.$RefreshSig$ = prevRefreshSig
27
+ self.$RefreshReg$ = prevRefreshReg;
28
+ self.$RefreshSig$ = prevRefreshSig;
29
29
  },
30
30
  acceptCallback: () => {
31
- flush()
31
+ flush();
32
32
  },
33
- }
34
- }
33
+ };
34
+ };
@@ -3,15 +3,15 @@
3
3
  * - https://github.com/preactjs/prefresh/blob/main/packages/vite/src/index.js
4
4
  */
5
5
 
6
- import { URL_META } from "@jsenv/url-meta"
7
- import { createMagicSource, composeTwoSourcemaps } from "@jsenv/sourcemap"
6
+ import { URL_META } from "@jsenv/url-meta";
7
+ import { createMagicSource, composeTwoSourcemaps } from "@jsenv/sourcemap";
8
8
  import {
9
9
  applyBabelPlugins,
10
10
  parseHtmlString,
11
11
  stringifyHtmlAst,
12
12
  injectHtmlNodeAsEarlyAsPossible,
13
13
  createHtmlNode,
14
- } from "@jsenv/ast"
14
+ } from "@jsenv/ast";
15
15
 
16
16
  export const jsenvPluginPreact = ({
17
17
  jsxTranspilation = true,
@@ -23,22 +23,22 @@ export const jsenvPluginPreact = ({
23
23
  jsxTranspilation = {
24
24
  "./**/*.jsx": true,
25
25
  "./**/*.tsx": true,
26
- }
26
+ };
27
27
  } else if (jsxTranspilation === false) {
28
- jsxTranspilation = {}
28
+ jsxTranspilation = {};
29
29
  }
30
30
  if (refreshInstrumentation === true) {
31
31
  refreshInstrumentation = {
32
32
  "./**/*.jsx": true,
33
33
  "./**/*.tsx": true,
34
- }
34
+ };
35
35
  } else if (refreshInstrumentation === false) {
36
- refreshInstrumentation = {}
36
+ refreshInstrumentation = {};
37
37
  }
38
38
  if (hookNamesInstrumentation === true) {
39
- hookNamesInstrumentation = { "./**": true }
39
+ hookNamesInstrumentation = { "./**": true };
40
40
  } else {
41
- hookNamesInstrumentation = {}
41
+ hookNamesInstrumentation = {};
42
42
  }
43
43
  const associations = URL_META.resolveAssociations(
44
44
  {
@@ -47,7 +47,7 @@ export const jsenvPluginPreact = ({
47
47
  hookNamesInstrumentation,
48
48
  },
49
49
  "file://",
50
- )
50
+ );
51
51
 
52
52
  return {
53
53
  name: "jsenv:preact",
@@ -58,26 +58,26 @@ export const jsenvPluginPreact = ({
58
58
  reference.specifier === "react" ||
59
59
  reference.specifier === "react-dom"
60
60
  ) {
61
- reference.specifier = "preact/compat"
62
- return context.resolveReference(reference)[0].url
61
+ reference.specifier = "preact/compat";
62
+ return context.resolveReference(reference)[0].url;
63
63
  }
64
- return null
64
+ return null;
65
65
  },
66
66
  },
67
67
  transformUrlContent: {
68
68
  html: (urlInfo, context) => {
69
69
  if (!preactDevtools) {
70
- return null
70
+ return null;
71
71
  }
72
72
  if (context.build && preactDevtools !== "dev_and_build") {
73
- return null
73
+ return null;
74
74
  }
75
- const htmlAst = parseHtmlString(urlInfo.content)
75
+ const htmlAst = parseHtmlString(urlInfo.content);
76
76
  const [preactDevtoolsReference] = context.referenceUtils.inject({
77
77
  type: "js_import",
78
78
  expectedType: "js_module",
79
79
  specifier: context.dev ? "preact/debug" : "preact/devtools",
80
- })
80
+ });
81
81
  injectHtmlNodeAsEarlyAsPossible(
82
82
  htmlAst,
83
83
  createHtmlNode({
@@ -86,27 +86,27 @@ export const jsenvPluginPreact = ({
86
86
  textContent: `import ${preactDevtoolsReference.generatedSpecifier}`,
87
87
  }),
88
88
  "jsenv:preact",
89
- )
90
- const htmlModified = stringifyHtmlAst(htmlAst)
91
- return { content: htmlModified }
89
+ );
90
+ const htmlModified = stringifyHtmlAst(htmlAst);
91
+ return { content: htmlModified };
92
92
  },
93
93
  js_module: async (urlInfo, context) => {
94
94
  const urlMeta = URL_META.applyAssociations({
95
95
  url: urlInfo.url,
96
96
  associations,
97
- })
98
- const jsxEnabled = urlMeta.jsxTranspilation
97
+ });
98
+ const jsxEnabled = urlMeta.jsxTranspilation;
99
99
  const refreshEnabled = context.dev
100
100
  ? urlMeta.refreshInstrumentation &&
101
101
  !urlInfo.content.includes("import.meta.hot.decline()")
102
- : false
102
+ : false;
103
103
  const hookNamesEnabled =
104
104
  context.dev &&
105
105
  urlMeta.hookNamesInstrumentation &&
106
106
  (urlInfo.content.includes("useState") ||
107
107
  urlInfo.content.includes("useReducer") ||
108
108
  urlInfo.content.includes("useRef") ||
109
- urlInfo.content.includes("useMemo"))
109
+ urlInfo.content.includes("useMemo"));
110
110
  const { code, map } = await applyBabelPlugins({
111
111
  babelPlugins: [
112
112
  ...(jsxEnabled
@@ -126,8 +126,8 @@ export const jsenvPluginPreact = ({
126
126
  ...(refreshEnabled ? ["@prefresh/babel-plugin"] : []),
127
127
  ],
128
128
  urlInfo,
129
- })
130
- const magicSource = createMagicSource(code)
129
+ });
130
+ const magicSource = createMagicSource(code);
131
131
  if (jsxEnabled) {
132
132
  // "@babel/plugin-transform-react-jsx" is injecting some of these 3 imports into the code:
133
133
  // 1. import { jsx } from "preact/jsx-runtime"
@@ -141,50 +141,50 @@ export const jsenvPluginPreact = ({
141
141
  `"preact"`,
142
142
  `"preact/jsx-dev-runtime"`,
143
143
  `"preact/jsx-runtime"`,
144
- ]
144
+ ];
145
145
  for (const importSpecifier of injectedSpecifiers) {
146
- let index = code.indexOf(importSpecifier)
146
+ let index = code.indexOf(importSpecifier);
147
147
  while (index > -1) {
148
- const specifier = importSpecifier.slice(1, -1)
148
+ const specifier = importSpecifier.slice(1, -1);
149
149
  const [injectedReference] = context.referenceUtils.inject({
150
150
  type: "js_import",
151
151
  expectedType: "js_module",
152
152
  specifier,
153
- })
153
+ });
154
154
  magicSource.replace({
155
155
  start: index,
156
156
  end: index + importSpecifier.length,
157
157
  replacement: injectedReference.generatedSpecifier,
158
- })
159
- index = code.indexOf(importSpecifier, index + 1)
158
+ });
159
+ index = code.indexOf(importSpecifier, index + 1);
160
160
  }
161
161
  }
162
162
  }
163
163
  if (refreshEnabled) {
164
- const hasReg = /\$RefreshReg\$\(/.test(code)
165
- const hasSig = /\$RefreshSig\$\(/.test(code)
164
+ const hasReg = /\$RefreshReg\$\(/.test(code);
165
+ const hasSig = /\$RefreshSig\$\(/.test(code);
166
166
  if (hasReg || hasSig) {
167
167
  const [preactRefreshClientReference] =
168
168
  context.referenceUtils.inject({
169
169
  type: "js_import",
170
170
  expectedType: "js_module",
171
171
  specifier: "@jsenv/plugin-preact/src/client/preact_refresh.js",
172
- })
172
+ });
173
173
  magicSource.prepend(`import { installPreactRefresh } from ${
174
174
  preactRefreshClientReference.generatedSpecifier
175
175
  }
176
176
  const __preact_refresh__ = installPreactRefresh(${JSON.stringify(urlInfo.url)})
177
- `)
177
+ `);
178
178
  if (hasReg) {
179
179
  magicSource.append(`
180
180
  __preact_refresh__.end()
181
- import.meta.hot.accept(__preact_refresh__.acceptCallback)`)
181
+ import.meta.hot.accept(__preact_refresh__.acceptCallback)`);
182
182
  }
183
183
  }
184
184
  }
185
185
  const result = magicSource.toContentAndSourcemap({
186
186
  source: "jsenv_preact",
187
- })
187
+ });
188
188
  return {
189
189
  content: result.content,
190
190
  sourcemap: await composeTwoSourcemaps(map, result.sourcemap),
@@ -192,8 +192,8 @@ import.meta.hot.accept(__preact_refresh__.acceptCallback)`)
192
192
  // I don't know exactly what is resulting in bad sourcemaps
193
193
  // but I suspect hooknames or prefresh to be responsible
194
194
  sourcemapIsWrong: jsxEnabled && refreshEnabled,
195
- }
195
+ };
196
196
  },
197
197
  },
198
- }
199
- }
198
+ };
199
+ };
package/src/main.js CHANGED
@@ -1 +1 @@
1
- export { jsenvPluginPreact } from "./jsenv_plugin_preact.js"
1
+ export { jsenvPluginPreact } from "./jsenv_plugin_preact.js";