@jsenv/core 27.0.0-alpha.84 → 27.0.0-alpha.87
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/html/explorer.html +1 -1
- package/dist/js/controllable_file.mjs +1 -1
- package/dist/js/event_source_client.js +3 -3
- package/dist/js/html_supervisor_installer.js +1 -1
- package/dist/js/s.js +2 -2
- package/dist/js/uneval.js +804 -0
- package/dist/main.js +11910 -1028
- package/dist/s.js +2 -2
- package/dist/s.js.map +1 -1
- package/package.json +17 -13
- package/src/build/build.js +2 -14
- package/src/build/inject_global_version_mappings.js +3 -3
- package/src/build/inject_service_worker_urls.js +1 -1
- package/src/build/resync_ressource_hints.js +17 -18
- package/src/build/version_generator.js +60 -0
- package/src/dev/plugins/explorer/client/explorer.html +1 -1
- package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +1 -1
- 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 +11 -3
- package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +62 -74
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +10 -6
- 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/plugins/url_analysis/jsenv_plugin_url_analysis.js +13 -6
- package/src/test/coverage/empty_coverage_factory.js +1 -1
|
@@ -5,7 +5,7 @@ import { isFileSystemPath } from "@jsenv/urls"
|
|
|
5
5
|
import { createDetailedMessage } from "@jsenv/log"
|
|
6
6
|
import { babelHelperNameFromUrl } from "@jsenv/babel-plugins"
|
|
7
7
|
import { sourcemapConverter } from "@jsenv/sourcemap"
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
import { fileUrlConverter } from "@jsenv/core/src/omega/file_url_converter.js"
|
|
10
10
|
|
|
11
11
|
const globalThisClientFileUrl = new URL(
|
|
@@ -53,71 +53,6 @@ export const bundleJsModule = async ({
|
|
|
53
53
|
return jsModuleBundleUrlInfos
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
export const buildWithRollup = async ({
|
|
57
|
-
signal,
|
|
58
|
-
logger,
|
|
59
|
-
rootDirectoryUrl,
|
|
60
|
-
buildDirectoryUrl,
|
|
61
|
-
urlGraph,
|
|
62
|
-
jsModuleUrlInfos,
|
|
63
|
-
|
|
64
|
-
runtimeCompat,
|
|
65
|
-
sourcemaps,
|
|
66
|
-
|
|
67
|
-
include,
|
|
68
|
-
babelHelpersChunk,
|
|
69
|
-
}) => {
|
|
70
|
-
const resultRef = { current: null }
|
|
71
|
-
try {
|
|
72
|
-
await applyRollupPlugins({
|
|
73
|
-
rollupPlugins: [
|
|
74
|
-
rollupPluginJsenv({
|
|
75
|
-
signal,
|
|
76
|
-
logger,
|
|
77
|
-
rootDirectoryUrl,
|
|
78
|
-
buildDirectoryUrl,
|
|
79
|
-
urlGraph,
|
|
80
|
-
jsModuleUrlInfos,
|
|
81
|
-
|
|
82
|
-
runtimeCompat,
|
|
83
|
-
sourcemaps,
|
|
84
|
-
include,
|
|
85
|
-
babelHelpersChunk,
|
|
86
|
-
resultRef,
|
|
87
|
-
}),
|
|
88
|
-
],
|
|
89
|
-
inputOptions: {
|
|
90
|
-
input: [],
|
|
91
|
-
onwarn: (warning) => {
|
|
92
|
-
if (warning.code === "CIRCULAR_DEPENDENCY") {
|
|
93
|
-
return
|
|
94
|
-
}
|
|
95
|
-
if (
|
|
96
|
-
warning.code === "THIS_IS_UNDEFINED" &&
|
|
97
|
-
pathToFileURL(warning.id).href === globalThisClientFileUrl
|
|
98
|
-
) {
|
|
99
|
-
return
|
|
100
|
-
}
|
|
101
|
-
if (warning.code === "EVAL") {
|
|
102
|
-
// ideally we should disable only for jsenv files
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
|
-
logger.warn(String(warning))
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
})
|
|
109
|
-
return resultRef.current
|
|
110
|
-
} catch (e) {
|
|
111
|
-
if (e.code === "MISSING_EXPORT") {
|
|
112
|
-
const detailedMessage = createDetailedMessage(e.message, {
|
|
113
|
-
frame: e.frame,
|
|
114
|
-
})
|
|
115
|
-
throw new Error(detailedMessage, { cause: e })
|
|
116
|
-
}
|
|
117
|
-
throw e
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
56
|
const rollupPluginJsenv = ({
|
|
122
57
|
// logger,
|
|
123
58
|
rootDirectoryUrl,
|
|
@@ -311,6 +246,90 @@ const rollupPluginJsenv = ({
|
|
|
311
246
|
}
|
|
312
247
|
}
|
|
313
248
|
|
|
249
|
+
const buildWithRollup = async ({
|
|
250
|
+
signal,
|
|
251
|
+
logger,
|
|
252
|
+
rootDirectoryUrl,
|
|
253
|
+
buildDirectoryUrl,
|
|
254
|
+
urlGraph,
|
|
255
|
+
jsModuleUrlInfos,
|
|
256
|
+
|
|
257
|
+
runtimeCompat,
|
|
258
|
+
sourcemaps,
|
|
259
|
+
|
|
260
|
+
include,
|
|
261
|
+
babelHelpersChunk,
|
|
262
|
+
}) => {
|
|
263
|
+
const resultRef = { current: null }
|
|
264
|
+
try {
|
|
265
|
+
await applyRollupPlugins({
|
|
266
|
+
rollupPlugins: [
|
|
267
|
+
rollupPluginJsenv({
|
|
268
|
+
signal,
|
|
269
|
+
logger,
|
|
270
|
+
rootDirectoryUrl,
|
|
271
|
+
buildDirectoryUrl,
|
|
272
|
+
urlGraph,
|
|
273
|
+
jsModuleUrlInfos,
|
|
274
|
+
|
|
275
|
+
runtimeCompat,
|
|
276
|
+
sourcemaps,
|
|
277
|
+
include,
|
|
278
|
+
babelHelpersChunk,
|
|
279
|
+
resultRef,
|
|
280
|
+
}),
|
|
281
|
+
],
|
|
282
|
+
inputOptions: {
|
|
283
|
+
input: [],
|
|
284
|
+
onwarn: (warning) => {
|
|
285
|
+
if (warning.code === "CIRCULAR_DEPENDENCY") {
|
|
286
|
+
return
|
|
287
|
+
}
|
|
288
|
+
if (
|
|
289
|
+
warning.code === "THIS_IS_UNDEFINED" &&
|
|
290
|
+
pathToFileURL(warning.id).href === globalThisClientFileUrl
|
|
291
|
+
) {
|
|
292
|
+
return
|
|
293
|
+
}
|
|
294
|
+
if (warning.code === "EVAL") {
|
|
295
|
+
// ideally we should disable only for jsenv files
|
|
296
|
+
return
|
|
297
|
+
}
|
|
298
|
+
logger.warn(String(warning))
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
})
|
|
302
|
+
return resultRef.current
|
|
303
|
+
} catch (e) {
|
|
304
|
+
if (e.code === "MISSING_EXPORT") {
|
|
305
|
+
const detailedMessage = createDetailedMessage(e.message, {
|
|
306
|
+
frame: e.frame,
|
|
307
|
+
})
|
|
308
|
+
throw new Error(detailedMessage, { cause: e })
|
|
309
|
+
}
|
|
310
|
+
throw e
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const applyRollupPlugins = async ({
|
|
315
|
+
rollupPlugins,
|
|
316
|
+
inputOptions = {},
|
|
317
|
+
outputOptions = {},
|
|
318
|
+
}) => {
|
|
319
|
+
const { rollup } = await import("rollup")
|
|
320
|
+
const { importAssertions } = await import("acorn-import-assertions")
|
|
321
|
+
const rollupReturnValue = await rollup({
|
|
322
|
+
...inputOptions,
|
|
323
|
+
plugins: rollupPlugins,
|
|
324
|
+
acornInjectPlugins: [
|
|
325
|
+
importAssertions,
|
|
326
|
+
...(inputOptions.acornInjectPlugins || []),
|
|
327
|
+
],
|
|
328
|
+
})
|
|
329
|
+
const rollupOutputArray = await rollupReturnValue.generate(outputOptions)
|
|
330
|
+
return rollupOutputArray
|
|
331
|
+
}
|
|
332
|
+
|
|
314
333
|
const willBeInsideJsDirectory = ({
|
|
315
334
|
chunkInfo,
|
|
316
335
|
fileUrlConverter,
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { createMagicSource } from "@jsenv/sourcemap"
|
|
11
|
-
import { applyBabelPlugins } from "@jsenv/
|
|
11
|
+
import { applyBabelPlugins } from "@jsenv/ast"
|
|
12
12
|
|
|
13
13
|
export const jsenvPluginCommonJsGlobals = () => {
|
|
14
14
|
const transformCommonJsGlobals = async (urlInfo, { scenario }) => {
|
|
@@ -15,7 +15,7 @@ import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"
|
|
|
15
15
|
export const jsenvPluginFileUrls = ({
|
|
16
16
|
magicExtensions = ["inherit", ".js"],
|
|
17
17
|
magicDirectoryIndex = true,
|
|
18
|
-
|
|
18
|
+
preserveSymlinks = false,
|
|
19
19
|
directoryReferenceAllowed = false,
|
|
20
20
|
}) => {
|
|
21
21
|
return [
|
|
@@ -58,9 +58,17 @@ export const jsenvPluginFileUrls = ({
|
|
|
58
58
|
urlObject.pathname = pathname.slice(0, -1)
|
|
59
59
|
}
|
|
60
60
|
if (foundADirectory && directoryReferenceAllowed) {
|
|
61
|
+
if (
|
|
62
|
+
// ignore new URL second arg
|
|
63
|
+
reference.subtype === "new_url_second_arg" ||
|
|
64
|
+
// ignore root file url
|
|
65
|
+
reference.url === "file:///"
|
|
66
|
+
) {
|
|
67
|
+
reference.shouldHandle = false
|
|
68
|
+
}
|
|
61
69
|
reference.data.foundADirectory = true
|
|
62
70
|
const directoryFacadeUrl = urlObject.href
|
|
63
|
-
const directoryUrlRaw =
|
|
71
|
+
const directoryUrlRaw = preserveSymlinks
|
|
64
72
|
? directoryFacadeUrl
|
|
65
73
|
: resolveSymlink(directoryFacadeUrl)
|
|
66
74
|
const directoryUrl = `${directoryUrlRaw}${search}${hash}`
|
|
@@ -81,7 +89,7 @@ export const jsenvPluginFileUrls = ({
|
|
|
81
89
|
}
|
|
82
90
|
reference.data.foundADirectory = filesystemResolution.isDirectory
|
|
83
91
|
const fileFacadeUrl = filesystemResolution.url
|
|
84
|
-
const fileUrlRaw =
|
|
92
|
+
const fileUrlRaw = preserveSymlinks
|
|
85
93
|
? fileFacadeUrl
|
|
86
94
|
: resolveSymlink(fileFacadeUrl)
|
|
87
95
|
const fileUrl = `${fileUrlRaw}${search}${hash}`
|
|
@@ -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
|
)
|
|
@@ -2,11 +2,15 @@ export const jsenvPluginHttpUrls = () => {
|
|
|
2
2
|
return {
|
|
3
3
|
name: "jsenv:http_urls",
|
|
4
4
|
appliesDuring: "*",
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
redirectUrl: (reference) => {
|
|
6
|
+
if (
|
|
7
|
+
reference.url.startsWith("http:") ||
|
|
8
|
+
reference.url.startsWith("https:")
|
|
9
|
+
) {
|
|
10
|
+
reference.shouldHandle = false
|
|
11
|
+
}
|
|
12
|
+
// TODO: according to some pattern matching jsenv could be allowed
|
|
13
|
+
// to fetch and transform http urls
|
|
14
|
+
},
|
|
11
15
|
}
|
|
12
16
|
}
|
|
@@ -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",
|