@jsenv/plugin-preact 0.2.10 → 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 +2 -2
- package/src/jsenv_plugin_preact.js +22 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-preact",
|
|
3
|
-
"version": "0.2
|
|
3
|
+
"version": "0.3.2",
|
|
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.18.6",
|
|
29
29
|
"@babel/plugin-transform-react-jsx-development": "7.18.6",
|
|
30
|
-
"@jsenv/ast": "1.
|
|
30
|
+
"@jsenv/ast": "1.2.0",
|
|
31
31
|
"@jsenv/sourcemap": "1.0.4",
|
|
32
32
|
"@jsenv/url-meta": "7.0.0",
|
|
33
33
|
"@prefresh/babel-plugin": "0.4.3",
|
|
@@ -46,48 +46,45 @@ export const jsenvPluginPreact = ({
|
|
|
46
46
|
reference.specifier === "react-dom"
|
|
47
47
|
) {
|
|
48
48
|
reference.specifier = "preact/compat"
|
|
49
|
-
return context.resolveReference(reference).url
|
|
49
|
+
return context.resolveReference(reference)[0].url
|
|
50
50
|
}
|
|
51
51
|
return null
|
|
52
52
|
},
|
|
53
53
|
},
|
|
54
54
|
transformUrlContent: {
|
|
55
|
-
html: (
|
|
56
|
-
if (!preactDevtoolsDuringBuild &&
|
|
55
|
+
html: (urlInfo, context) => {
|
|
56
|
+
if (!preactDevtoolsDuringBuild && context.scenarios.build) {
|
|
57
57
|
return null
|
|
58
58
|
}
|
|
59
|
-
const htmlAst = parseHtmlString(content)
|
|
60
|
-
const [preactDevtoolsReference] = referenceUtils.inject({
|
|
59
|
+
const htmlAst = parseHtmlString(urlInfo.content)
|
|
60
|
+
const [preactDevtoolsReference] = context.referenceUtils.inject({
|
|
61
61
|
type: "js_import_export",
|
|
62
62
|
expectedType: "js_module",
|
|
63
|
-
specifier:
|
|
64
|
-
scenario === "dev" || scenario === "test"
|
|
65
|
-
? "preact/debug"
|
|
66
|
-
: "preact/devtools",
|
|
63
|
+
specifier: context.scenarios.dev ? "preact/debug" : "preact/devtools",
|
|
67
64
|
})
|
|
68
65
|
injectScriptNodeAsEarlyAsPossible(
|
|
69
66
|
htmlAst,
|
|
70
67
|
createHtmlNode({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
tagName: "script",
|
|
69
|
+
type: "module",
|
|
70
|
+
textContent: `
|
|
74
71
|
import ${preactDevtoolsReference.generatedSpecifier}
|
|
75
72
|
`,
|
|
76
|
-
"injected-by": "jsenv:preact",
|
|
77
73
|
}),
|
|
74
|
+
"jsenv:preact",
|
|
78
75
|
)
|
|
79
76
|
const htmlModified = stringifyHtmlAst(htmlAst)
|
|
80
77
|
return { content: htmlModified }
|
|
81
78
|
},
|
|
82
|
-
js_module: async (urlInfo,
|
|
79
|
+
js_module: async (urlInfo, context) => {
|
|
83
80
|
const urlMeta = URL_META.applyAssociations({
|
|
84
81
|
url: urlInfo.url,
|
|
85
82
|
associations,
|
|
86
83
|
})
|
|
87
84
|
const jsxEnabled = urlMeta.jsx
|
|
88
|
-
const refreshEnabled =
|
|
85
|
+
const refreshEnabled = context.scenarios.dev ? urlMeta.refresh : false
|
|
89
86
|
const hookNamesEnabled =
|
|
90
|
-
|
|
87
|
+
context.scenarios.dev &&
|
|
91
88
|
urlMeta.hookNames &&
|
|
92
89
|
(urlInfo.content.includes("useState") ||
|
|
93
90
|
urlInfo.content.includes("useReducer") ||
|
|
@@ -99,7 +96,7 @@ import ${preactDevtoolsReference.generatedSpecifier}
|
|
|
99
96
|
...(jsxEnabled
|
|
100
97
|
? [
|
|
101
98
|
[
|
|
102
|
-
|
|
99
|
+
context.scenarios.dev
|
|
103
100
|
? "@babel/plugin-transform-react-jsx-development"
|
|
104
101
|
: "@babel/plugin-transform-react-jsx",
|
|
105
102
|
{
|
|
@@ -133,7 +130,7 @@ import ${preactDevtoolsReference.generatedSpecifier}
|
|
|
133
130
|
let index = code.indexOf(importSpecifier)
|
|
134
131
|
while (index > -1) {
|
|
135
132
|
const specifier = importSpecifier.slice(1, -1)
|
|
136
|
-
const [injectedReference] = referenceUtils.inject({
|
|
133
|
+
const [injectedReference] = context.referenceUtils.inject({
|
|
137
134
|
type: "js_import_export",
|
|
138
135
|
expectedType: "js_module",
|
|
139
136
|
specifier,
|
|
@@ -151,11 +148,12 @@ import ${preactDevtoolsReference.generatedSpecifier}
|
|
|
151
148
|
const hasReg = /\$RefreshReg\$\(/.test(code)
|
|
152
149
|
const hasSig = /\$RefreshSig\$\(/.test(code)
|
|
153
150
|
if (hasReg || hasSig) {
|
|
154
|
-
const [preactRefreshClientReference] =
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
151
|
+
const [preactRefreshClientReference] =
|
|
152
|
+
context.referenceUtils.inject({
|
|
153
|
+
type: "js_import_export",
|
|
154
|
+
expectedType: "js_module",
|
|
155
|
+
specifier: "@jsenv/plugin-preact/src/client/preact_refresh.js",
|
|
156
|
+
})
|
|
159
157
|
magicSource.prepend(`import { installPreactRefresh } from ${
|
|
160
158
|
preactRefreshClientReference.generatedSpecifier
|
|
161
159
|
}
|
|
@@ -168,9 +166,7 @@ import.meta.hot.accept(__preact_refresh__.acceptCallback)`)
|
|
|
168
166
|
}
|
|
169
167
|
}
|
|
170
168
|
}
|
|
171
|
-
const result = magicSource.toContentAndSourcemap(
|
|
172
|
-
source: "jsenv:plugin_preact",
|
|
173
|
-
})
|
|
169
|
+
const result = magicSource.toContentAndSourcemap()
|
|
174
170
|
return {
|
|
175
171
|
content: result.content,
|
|
176
172
|
sourcemap: await composeTwoSourcemaps(map, result.sourcemap),
|