@jsenv/core 27.0.0-alpha.84 → 27.0.0-alpha.85
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/dist/js/event_source_client.js +3 -3
- package/dist/js/s.js +2 -2
- package/dist/main.js +355 -380
- package/dist/s.js +2 -2
- package/dist/s.js.map +1 -1
- package/package.json +5 -2
- package/src/build/build.js +1 -4
- package/src/build/inject_global_version_mappings.js +3 -3
- package/src/build/resync_ressource_hints.js +17 -18
- package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +3 -3
- package/src/omega/kitchen.js +2 -0
- package/src/plugins/autoreload/dev_sse/client/reload.js +6 -3
- package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +3 -3
- package/src/plugins/bundling/css/bundle_css.js +1 -2
- package/src/plugins/bundling/js_module/bundle_js_module.js +85 -66
- package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +1 -1
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +3 -3
- package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +62 -74
- package/src/plugins/import_meta_hot/html_hot_dependencies.js +9 -15
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +1 -2
- package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +1 -1
- package/src/plugins/importmap/jsenv_plugin_importmap.js +24 -25
- package/src/plugins/inject_globals/inject_globals.js +3 -3
- package/src/plugins/inline/jsenv_plugin_html_inline_content.js +39 -41
- package/src/plugins/inline/jsenv_plugin_js_inline_content.js +1 -1
- package/src/plugins/minification/css/minify_css.js +1 -1
- package/src/plugins/transpilation/as_js_classic/client/s.js +2 -2
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +2 -2
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +41 -63
- package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +2 -3
- package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +2 -2
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +1 -1
- package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +2 -2
- package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +2 -2
- package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +1 -1
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +1 -1
- package/src/plugins/url_analysis/css/css_urls.js +1 -2
- package/src/plugins/url_analysis/html/html_urls.js +98 -113
- package/src/plugins/url_analysis/js/js_urls.js +1 -1
- package/src/test/coverage/empty_coverage_factory.js +1 -1
|
@@ -7,17 +7,17 @@
|
|
|
7
7
|
import {
|
|
8
8
|
parseHtmlString,
|
|
9
9
|
stringifyHtmlAst,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
visitHtmlNodes,
|
|
11
|
+
getHtmlNodeAttribute,
|
|
12
|
+
setHtmlNodeAttributes,
|
|
13
|
+
analyzeScriptNode,
|
|
14
|
+
injectScriptNodeAsEarlyAsPossible,
|
|
15
15
|
createHtmlNode,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
getHtmlNodePosition,
|
|
17
|
+
getHtmlNodeText,
|
|
18
18
|
removeHtmlNodeText,
|
|
19
|
-
|
|
20
|
-
} from "@jsenv/
|
|
19
|
+
setHtmlNodeText,
|
|
20
|
+
} from "@jsenv/ast"
|
|
21
21
|
import { generateInlineContentUrl } from "@jsenv/urls"
|
|
22
22
|
|
|
23
23
|
export const jsenvPluginHtmlSupervisor = ({
|
|
@@ -45,10 +45,10 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
45
45
|
const htmlAst = parseHtmlString(content)
|
|
46
46
|
const scriptsToSupervise = []
|
|
47
47
|
|
|
48
|
-
const handleInlineScript = (node,
|
|
49
|
-
const scriptCategory =
|
|
48
|
+
const handleInlineScript = (node, htmlNodeText) => {
|
|
49
|
+
const scriptCategory = analyzeScriptNode(node)
|
|
50
50
|
const { line, column, lineEnd, columnEnd, isOriginal } =
|
|
51
|
-
|
|
51
|
+
getHtmlNodePosition(node, {
|
|
52
52
|
preferOriginal: true,
|
|
53
53
|
})
|
|
54
54
|
let inlineScriptUrl = generateInlineContentUrl({
|
|
@@ -69,7 +69,7 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
69
69
|
specifierColumn: column,
|
|
70
70
|
specifier: inlineScriptUrl,
|
|
71
71
|
contentType: "text/javascript",
|
|
72
|
-
content:
|
|
72
|
+
content: htmlNodeText,
|
|
73
73
|
})
|
|
74
74
|
removeHtmlNodeText(node)
|
|
75
75
|
scriptsToSupervise.push({
|
|
@@ -79,76 +79,61 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
79
79
|
src: inlineScriptReference.generatedSpecifier,
|
|
80
80
|
})
|
|
81
81
|
}
|
|
82
|
-
const handleScriptWithSrc = (node,
|
|
83
|
-
const scriptCategory =
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
"
|
|
87
|
-
)
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
: undefined
|
|
91
|
-
|
|
92
|
-
node,
|
|
93
|
-
"crossorigin",
|
|
94
|
-
)
|
|
95
|
-
const crossorigin = crossoriginAttribute
|
|
96
|
-
? crossoriginAttribute.value
|
|
97
|
-
: undefined
|
|
98
|
-
const deferAttribute = getHtmlNodeAttributeByName(node, "crossorigin")
|
|
99
|
-
const defer = deferAttribute ? deferAttribute.value : undefined
|
|
100
|
-
const asyncAttribute = getHtmlNodeAttributeByName(node, "crossorigin")
|
|
101
|
-
const async = asyncAttribute ? asyncAttribute.value : undefined
|
|
102
|
-
removeHtmlNodeAttributeByName(node, "src")
|
|
82
|
+
const handleScriptWithSrc = (node, src) => {
|
|
83
|
+
const scriptCategory = analyzeScriptNode(node)
|
|
84
|
+
const integrity = getHtmlNodeAttribute(node, "integrity")
|
|
85
|
+
const crossorigin =
|
|
86
|
+
getHtmlNodeAttribute(node, "crossorigin") !== undefined
|
|
87
|
+
const defer = getHtmlNodeAttribute(node, "defer") !== undefined
|
|
88
|
+
const async = getHtmlNodeAttribute(node, "async") !== undefined
|
|
89
|
+
setHtmlNodeAttributes(node, {
|
|
90
|
+
src: undefined,
|
|
91
|
+
})
|
|
103
92
|
scriptsToSupervise.push({
|
|
104
93
|
node,
|
|
105
94
|
type: scriptCategory,
|
|
106
|
-
src
|
|
95
|
+
src,
|
|
107
96
|
defer,
|
|
108
97
|
async,
|
|
109
98
|
integrity,
|
|
110
99
|
crossorigin,
|
|
111
100
|
})
|
|
112
101
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (srcAttribute) {
|
|
142
|
-
handleScriptWithSrc(node, srcAttribute)
|
|
143
|
-
return
|
|
144
|
-
}
|
|
102
|
+
visitHtmlNodes(htmlAst, {
|
|
103
|
+
script: (node) => {
|
|
104
|
+
const scriptCategory = analyzeScriptNode(node)
|
|
105
|
+
if (scriptCategory !== "classic" && scriptCategory !== "module") {
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
const injectedBy = getHtmlNodeAttribute(node, "injected-by")
|
|
109
|
+
if (injectedBy !== undefined) {
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
const noHtmlSupervisor = getHtmlNodeAttribute(
|
|
113
|
+
node,
|
|
114
|
+
"no-html-supervisor",
|
|
115
|
+
)
|
|
116
|
+
if (noHtmlSupervisor !== undefined) {
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
const htmlNodeText = getHtmlNodeText(node)
|
|
120
|
+
if (htmlNodeText) {
|
|
121
|
+
handleInlineScript(node, htmlNodeText)
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
const src = getHtmlNodeAttribute(node, "src")
|
|
125
|
+
if (src) {
|
|
126
|
+
handleScriptWithSrc(node, src)
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
},
|
|
145
130
|
})
|
|
146
131
|
const [htmlSupervisorInstallerFileReference] = referenceUtils.inject({
|
|
147
132
|
type: "js_import_export",
|
|
148
133
|
expectedType: "js_module",
|
|
149
134
|
specifier: htmlSupervisorInstallerFileUrl,
|
|
150
135
|
})
|
|
151
|
-
|
|
136
|
+
injectScriptNodeAsEarlyAsPossible(
|
|
152
137
|
htmlAst,
|
|
153
138
|
createHtmlNode({
|
|
154
139
|
"tagName": "script",
|
|
@@ -173,7 +158,7 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
173
158
|
expectedType: "js_classic",
|
|
174
159
|
specifier: htmlSupervisorSetupFileUrl,
|
|
175
160
|
})
|
|
176
|
-
|
|
161
|
+
injectScriptNodeAsEarlyAsPossible(
|
|
177
162
|
htmlAst,
|
|
178
163
|
createHtmlNode({
|
|
179
164
|
"tagName": "script",
|
|
@@ -192,8 +177,9 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
192
177
|
integrity,
|
|
193
178
|
crossorigin,
|
|
194
179
|
}) => {
|
|
195
|
-
|
|
196
|
-
|
|
180
|
+
setHtmlNodeText(
|
|
181
|
+
node,
|
|
182
|
+
generateCodeToSuperviseScript({
|
|
197
183
|
type,
|
|
198
184
|
src,
|
|
199
185
|
isInline,
|
|
@@ -204,9 +190,11 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
204
190
|
htmlSupervisorInstallerSpecifier:
|
|
205
191
|
htmlSupervisorInstallerFileReference.generatedSpecifier,
|
|
206
192
|
}),
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
193
|
+
)
|
|
194
|
+
setHtmlNodeAttributes(node, {
|
|
195
|
+
"generated-by": "jsenv:html_supervisor",
|
|
196
|
+
...(src ? { "generated-from-src": src } : {}),
|
|
197
|
+
...(isInline ? { "generated-from-inline-content": "" } : {}),
|
|
210
198
|
})
|
|
211
199
|
},
|
|
212
200
|
)
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getHtmlNodeAttributeByName,
|
|
3
|
-
parseLinkNode,
|
|
4
|
-
} from "@jsenv/utils/src/html_ast/html_ast.js"
|
|
5
|
-
import { htmlAttributeSrcSet } from "@jsenv/utils/src/html_ast/html_attribute_src_set.js"
|
|
1
|
+
import { getHtmlNodeAttribute, analyzeLinkNode, parseSrcSet } from "@jsenv/ast"
|
|
6
2
|
|
|
7
3
|
// Some "smart" default applied to decide what should hot reload / fullreload:
|
|
8
4
|
// By default:
|
|
@@ -28,8 +24,7 @@ export const collectHotDataFromHtmlAst = (htmlAst) => {
|
|
|
28
24
|
}
|
|
29
25
|
|
|
30
26
|
const visitUrlSpecifierAttribute = ({ node, attributeName, hotAccepted }) => {
|
|
31
|
-
const
|
|
32
|
-
const value = attribute ? attribute.value : undefined
|
|
27
|
+
const value = getHtmlNodeAttribute(node, attributeName)
|
|
33
28
|
if (value) {
|
|
34
29
|
onSpecifier({
|
|
35
30
|
specifier: value,
|
|
@@ -70,10 +65,9 @@ export const collectHotDataFromHtmlAst = (htmlAst) => {
|
|
|
70
65
|
})
|
|
71
66
|
}
|
|
72
67
|
if (nodeNamesWithSrcset.includes(node.nodeName)) {
|
|
73
|
-
const
|
|
74
|
-
const srcset = srcsetAttribute ? srcsetAttribute.value : undefined
|
|
68
|
+
const srcset = getHtmlNodeAttribute(node, "srcset")
|
|
75
69
|
if (srcset) {
|
|
76
|
-
const srcCandidates =
|
|
70
|
+
const srcCandidates = parseSrcSet(srcset)
|
|
77
71
|
srcCandidates.forEach((srcCandidate) => {
|
|
78
72
|
onSpecifier({
|
|
79
73
|
node,
|
|
@@ -112,12 +106,12 @@ const nodeNamesWithSrcset = ["img", "source"]
|
|
|
112
106
|
|
|
113
107
|
const getNodeContext = (node) => {
|
|
114
108
|
const context = {}
|
|
115
|
-
const
|
|
116
|
-
if (
|
|
109
|
+
const hotAccept = getHtmlNodeAttribute(node, "hot-accept")
|
|
110
|
+
if (hotAccept !== undefined) {
|
|
117
111
|
context.hotAccepted = true
|
|
118
112
|
}
|
|
119
|
-
const
|
|
120
|
-
if (
|
|
113
|
+
const hotDecline = getHtmlNodeAttribute(node, "hot-decline")
|
|
114
|
+
if (hotDecline !== undefined) {
|
|
121
115
|
context.hotAccepted = false
|
|
122
116
|
}
|
|
123
117
|
return context
|
|
@@ -125,7 +119,7 @@ const getNodeContext = (node) => {
|
|
|
125
119
|
|
|
126
120
|
const htmlNodeCanHotReload = (node) => {
|
|
127
121
|
if (node.nodeName === "link") {
|
|
128
|
-
const { isStylesheet, isRessourceHint, rel } =
|
|
122
|
+
const { isStylesheet, isRessourceHint, rel } = analyzeLinkNode(node)
|
|
129
123
|
if (isStylesheet) {
|
|
130
124
|
// stylesheets can be hot replaced by default
|
|
131
125
|
return true
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createMagicSource } from "@jsenv/sourcemap"
|
|
2
|
-
import { parseHtmlString } from "@jsenv/
|
|
3
|
-
import { applyBabelPlugins } from "@jsenv/utils/src/js_ast/apply_babel_plugins.js"
|
|
2
|
+
import { parseHtmlString, applyBabelPlugins } from "@jsenv/ast"
|
|
4
3
|
|
|
5
4
|
import { collectHotDataFromHtmlAst } from "./html_hot_dependencies.js"
|
|
6
5
|
import { babelPluginMetadataImportMetaHot } from "./babel_plugin_metadata_import_meta_hot.js"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { createMagicSource } from "@jsenv/sourcemap"
|
|
13
|
-
import { applyBabelPlugins } from "@jsenv/
|
|
13
|
+
import { applyBabelPlugins } from "@jsenv/ast"
|
|
14
14
|
|
|
15
15
|
export const jsenvPluginImportMetaScenarios = () => {
|
|
16
16
|
return {
|
|
@@ -26,14 +26,14 @@ import { generateInlineContentUrl } from "@jsenv/urls"
|
|
|
26
26
|
import {
|
|
27
27
|
parseHtmlString,
|
|
28
28
|
stringifyHtmlAst,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
findHtmlNode,
|
|
30
|
+
getHtmlNodeAttribute,
|
|
31
|
+
setHtmlNodeAttributes,
|
|
32
|
+
getHtmlNodePosition,
|
|
33
|
+
getHtmlNodeText,
|
|
34
|
+
setHtmlNodeText,
|
|
35
35
|
removeHtmlNode,
|
|
36
|
-
} from "@jsenv/
|
|
36
|
+
} from "@jsenv/ast"
|
|
37
37
|
|
|
38
38
|
export const jsenvPluginImportmap = () => {
|
|
39
39
|
let finalImportmap = null
|
|
@@ -92,12 +92,12 @@ export const jsenvPluginImportmap = () => {
|
|
|
92
92
|
transformUrlContent: {
|
|
93
93
|
html: async (htmlUrlInfo, context) => {
|
|
94
94
|
const htmlAst = parseHtmlString(htmlUrlInfo.content)
|
|
95
|
-
const importmap =
|
|
95
|
+
const importmap = findHtmlNode(htmlAst, (node) => {
|
|
96
96
|
if (node.nodeName !== "script") {
|
|
97
97
|
return false
|
|
98
98
|
}
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
99
|
+
const type = getHtmlNodeAttribute(node, "type")
|
|
100
|
+
if (type === undefined || type !== "importmap") {
|
|
101
101
|
return false
|
|
102
102
|
}
|
|
103
103
|
return true
|
|
@@ -108,7 +108,7 @@ export const jsenvPluginImportmap = () => {
|
|
|
108
108
|
}
|
|
109
109
|
const handleInlineImportmap = async (importmap, textNode) => {
|
|
110
110
|
const { line, column, lineEnd, columnEnd, isOriginal } =
|
|
111
|
-
|
|
111
|
+
getHtmlNodePosition(importmap, {
|
|
112
112
|
preferOriginal: true,
|
|
113
113
|
})
|
|
114
114
|
const inlineImportmapUrl = generateInlineContentUrl({
|
|
@@ -132,9 +132,9 @@ export const jsenvPluginImportmap = () => {
|
|
|
132
132
|
await context.cook(inlineImportmapUrlInfo, {
|
|
133
133
|
reference: inlineImportmapReference,
|
|
134
134
|
})
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
setHtmlNodeText(importmap, inlineImportmapUrlInfo.content)
|
|
136
|
+
setHtmlNodeAttributes(importmap, {
|
|
137
|
+
"generated-by": "jsenv:importmap",
|
|
138
138
|
})
|
|
139
139
|
onHtmlImportmapParsed(
|
|
140
140
|
JSON.parse(inlineImportmapUrlInfo.content),
|
|
@@ -159,15 +159,15 @@ export const jsenvPluginImportmap = () => {
|
|
|
159
159
|
JSON.parse(importmapUrlInfo.content),
|
|
160
160
|
htmlUrlInfo.url,
|
|
161
161
|
)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
162
|
+
setHtmlNodeText(importmap, importmapUrlInfo.content)
|
|
163
|
+
setHtmlNodeAttributes(importmap, {
|
|
164
|
+
"src": undefined,
|
|
165
|
+
"generated-by": "jsenv:importmap",
|
|
166
|
+
"generated-from-src": src,
|
|
167
167
|
})
|
|
168
168
|
|
|
169
169
|
const { line, column, lineEnd, columnEnd, isOriginal } =
|
|
170
|
-
|
|
170
|
+
getHtmlNodePosition(importmap, {
|
|
171
171
|
preferOriginal: true,
|
|
172
172
|
})
|
|
173
173
|
const inlineImportmapUrl = generateInlineContentUrl({
|
|
@@ -188,14 +188,13 @@ export const jsenvPluginImportmap = () => {
|
|
|
188
188
|
})
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
const
|
|
192
|
-
const src = srcAttribute ? srcAttribute.value : undefined
|
|
191
|
+
const src = getHtmlNodeAttribute(importmap, "src")
|
|
193
192
|
if (src) {
|
|
194
193
|
await handleImportmapWithSrc(importmap, src)
|
|
195
194
|
} else {
|
|
196
|
-
const
|
|
197
|
-
if (
|
|
198
|
-
await handleInlineImportmap(importmap,
|
|
195
|
+
const htmlNodeText = getHtmlNodeText(importmap)
|
|
196
|
+
if (htmlNodeText) {
|
|
197
|
+
await handleInlineImportmap(importmap, htmlNodeText)
|
|
199
198
|
}
|
|
200
199
|
}
|
|
201
200
|
// once this plugin knows the importmap, it will use it
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createMagicSource } from "@jsenv/sourcemap"
|
|
2
2
|
import {
|
|
3
3
|
parseHtmlString,
|
|
4
|
-
|
|
4
|
+
injectScriptNodeAsEarlyAsPossible,
|
|
5
5
|
createHtmlNode,
|
|
6
6
|
stringifyHtmlAst,
|
|
7
|
-
} from "@jsenv/
|
|
7
|
+
} from "@jsenv/ast"
|
|
8
8
|
|
|
9
9
|
export const injectGlobals = (urlInfo, globals) => {
|
|
10
10
|
if (urlInfo.type === "html") {
|
|
@@ -27,7 +27,7 @@ const globalInjectorOnHtml = async (urlInfo, globals) => {
|
|
|
27
27
|
globals,
|
|
28
28
|
isWebWorker: false,
|
|
29
29
|
})
|
|
30
|
-
|
|
30
|
+
injectScriptNodeAsEarlyAsPossible(
|
|
31
31
|
htmlAst,
|
|
32
32
|
createHtmlNode({
|
|
33
33
|
"tagName": "script",
|
|
@@ -2,13 +2,14 @@ import { generateInlineContentUrl } from "@jsenv/urls"
|
|
|
2
2
|
import {
|
|
3
3
|
parseHtmlString,
|
|
4
4
|
stringifyHtmlAst,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
visitHtmlNodes,
|
|
6
|
+
getHtmlNodeText,
|
|
7
|
+
getHtmlNodePosition,
|
|
8
|
+
analyzeScriptNode,
|
|
9
|
+
setHtmlNodeAttributes,
|
|
10
|
+
setHtmlNodeText,
|
|
11
|
+
getHtmlNodeAttribute,
|
|
12
|
+
} from "@jsenv/ast"
|
|
12
13
|
import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"
|
|
13
14
|
|
|
14
15
|
export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
@@ -20,16 +21,13 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
|
20
21
|
const htmlAst = parseHtmlString(urlInfo.content)
|
|
21
22
|
const actions = []
|
|
22
23
|
const handleInlineStyle = (node) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
const textNode = getHtmlNodeTextNode(node)
|
|
27
|
-
if (!textNode) {
|
|
24
|
+
const htmlNodeText = getHtmlNodeText(node)
|
|
25
|
+
if (!htmlNodeText) {
|
|
28
26
|
return
|
|
29
27
|
}
|
|
30
28
|
actions.push(async () => {
|
|
31
29
|
const { line, column, lineEnd, columnEnd, isOriginal } =
|
|
32
|
-
|
|
30
|
+
getHtmlNodePosition(node, {
|
|
33
31
|
preferOriginal: true,
|
|
34
32
|
})
|
|
35
33
|
const inlineStyleUrl = generateInlineContentUrl({
|
|
@@ -52,43 +50,39 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
|
52
50
|
specifierColumn: column,
|
|
53
51
|
specifier: inlineStyleUrl,
|
|
54
52
|
contentType: "text/css",
|
|
55
|
-
content:
|
|
53
|
+
content: htmlNodeText,
|
|
56
54
|
})
|
|
57
55
|
await context.cook(inlineStyleUrlInfo, {
|
|
58
56
|
reference: inlineStyleReference,
|
|
59
57
|
})
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
setHtmlNodeText(node, inlineStyleUrlInfo.content)
|
|
59
|
+
setHtmlNodeAttributes(node, {
|
|
60
|
+
"generated-by": "jsenv:html_inline_content",
|
|
63
61
|
})
|
|
64
62
|
})
|
|
65
63
|
}
|
|
66
64
|
const handleInlineScript = (node) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
const textNode = getHtmlNodeTextNode(node)
|
|
71
|
-
if (!textNode) {
|
|
65
|
+
const htmlNodeText = getHtmlNodeText(node)
|
|
66
|
+
if (!htmlNodeText) {
|
|
72
67
|
return
|
|
73
68
|
}
|
|
74
69
|
// If the inline script was already handled by an other plugin, ignore it
|
|
75
70
|
// - we want to preserve inline scripts generated by html supervisor during dev
|
|
76
71
|
// - we want to avoid cooking twice a script during build
|
|
77
|
-
const generatedBy =
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
72
|
+
const generatedBy = getHtmlNodeAttribute(node, "generated-by")
|
|
73
|
+
if (
|
|
74
|
+
generatedBy === "jsenv:as_js_classic_html" &&
|
|
75
|
+
!analyzeConvertedScripts
|
|
76
|
+
) {
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
if (generatedBy === "jsenv:html_supervisor") {
|
|
80
|
+
return
|
|
87
81
|
}
|
|
88
82
|
actions.push(async () => {
|
|
89
|
-
const scriptCategory =
|
|
83
|
+
const scriptCategory = analyzeScriptNode(node)
|
|
90
84
|
const { line, column, lineEnd, columnEnd, isOriginal } =
|
|
91
|
-
|
|
85
|
+
getHtmlNodePosition(node, {
|
|
92
86
|
preferOriginal: true,
|
|
93
87
|
})
|
|
94
88
|
// from MDN about [type] attribute:
|
|
@@ -131,21 +125,25 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
|
131
125
|
isOriginalPosition: isOriginal,
|
|
132
126
|
specifier: inlineScriptUrl,
|
|
133
127
|
contentType,
|
|
134
|
-
content:
|
|
128
|
+
content: htmlNodeText,
|
|
135
129
|
})
|
|
136
130
|
|
|
137
131
|
await context.cook(inlineScriptUrlInfo, {
|
|
138
132
|
reference: inlineScriptReference,
|
|
139
133
|
})
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
134
|
+
setHtmlNodeText(node, inlineScriptUrlInfo.content)
|
|
135
|
+
setHtmlNodeAttributes(node, {
|
|
136
|
+
"generated-by": "jsenv:html_inline_content",
|
|
143
137
|
})
|
|
144
138
|
})
|
|
145
139
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
140
|
+
visitHtmlNodes(htmlAst, {
|
|
141
|
+
style: (node) => {
|
|
142
|
+
handleInlineStyle(node)
|
|
143
|
+
},
|
|
144
|
+
script: (node) => {
|
|
145
|
+
handleInlineScript(node)
|
|
146
|
+
},
|
|
149
147
|
})
|
|
150
148
|
if (actions.length === 0) {
|
|
151
149
|
return null
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { generateInlineContentUrl } from "@jsenv/urls"
|
|
2
2
|
import { createMagicSource } from "@jsenv/sourcemap"
|
|
3
|
+
import { applyBabelPlugins } from "@jsenv/ast"
|
|
3
4
|
import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"
|
|
4
5
|
import { JS_QUOTES } from "@jsenv/utils/src/string/js_quotes.js"
|
|
5
|
-
import { applyBabelPlugins } from "@jsenv/utils/src/js_ast/apply_babel_plugins.js"
|
|
6
6
|
|
|
7
7
|
export const jsenvPluginJsInlineContent = ({ allowEscapeForVersioning }) => {
|
|
8
8
|
const parseAndTransformInlineContentCalls = async (urlInfo, context) => {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
}
|
|
44
44
|
System.register = (deps, declare) => {
|
|
45
45
|
if (!document.currentScript) {
|
|
46
|
-
throw new Error("unexpected call")
|
|
46
|
+
throw new Error("unexpected call to System.register (document.currentScript is undefined)")
|
|
47
47
|
}
|
|
48
48
|
if (document.currentScript.__s__) {
|
|
49
49
|
registerRegistry[document.currentScript.src] = [deps, declare]
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
|
|
170
170
|
System.register = async (deps, declare) => {
|
|
171
171
|
System.register = () => {
|
|
172
|
-
throw new Error("unexpected call")
|
|
172
|
+
throw new Error("unexpected call to System.register (called outside url instantiation)")
|
|
173
173
|
}
|
|
174
174
|
const url = self.location.href
|
|
175
175
|
registerRegistry[url] = [deps, declare]
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
import { urlToFilename, injectQueryParams } from "@jsenv/urls"
|
|
15
15
|
import { readFileSync } from "@jsenv/filesystem"
|
|
16
16
|
import { createMagicSource, composeTwoSourcemaps } from "@jsenv/sourcemap"
|
|
17
|
-
import {
|
|
18
|
-
import { applyBabelPlugins } from "@jsenv/utils/src/js_ast/apply_babel_plugins.js"
|
|
17
|
+
import { applyBabelPlugins } from "@jsenv/ast"
|
|
19
18
|
|
|
19
|
+
import { requireFromJsenv } from "@jsenv/core/src/require_from_jsenv.js"
|
|
20
20
|
import { requireBabelPlugin } from "../babel/require_babel_plugin.js"
|
|
21
21
|
import { babelPluginTransformImportMetaUrl } from "./helpers/babel_plugin_transform_import_meta_url.js"
|
|
22
22
|
import { jsenvPluginAsJsClassicHtml } from "./jsenv_plugin_as_js_classic_html.js"
|