@jsenv/core 27.0.0-alpha.82 → 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 +208 -4
- package/dist/js/s.js +2 -2
- package/dist/main.js +1430 -615
- package/dist/s.js +2 -2
- package/dist/s.js.map +2 -1
- package/package.json +6 -2
- package/src/build/build.js +5 -8
- package/src/build/build_urls_generator.js +1 -2
- package/src/build/inject_global_version_mappings.js +4 -4
- package/src/build/inject_service_worker_urls.js +2 -2
- package/src/build/resync_ressource_hints.js +17 -18
- package/src/build/start_build_server.js +33 -26
- package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +1 -2
- package/src/dev/plugins/toolbar/client/util/fetching.js +1 -1
- package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +3 -3
- package/src/dev/start_dev_server.js +38 -30
- package/src/execute/runtimes/browsers/from_playwright.js +5 -4
- package/src/execute/runtimes/node/node_process.js +2 -2
- package/src/helpers/command/command.js +73 -0
- package/src/helpers/event_source/event_source.js +197 -0
- package/src/helpers/event_source/sse_service.js +53 -0
- package/src/helpers/worker_reload.js +57 -0
- package/src/omega/compat/runtime_compat.js +2 -1
- package/src/omega/kitchen.js +4 -1
- package/src/omega/server/user_agent.js +2 -1
- package/src/omega/url_graph/sort_by_dependencies.js +27 -0
- package/src/omega/url_graph/url_info_transformations.js +24 -14
- package/src/plugins/autoreload/dev_sse/client/event_source_client.js +1 -1
- 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/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js +1 -1
- package/src/plugins/bundling/css/bundle_css.js +4 -4
- package/src/plugins/bundling/js_module/bundle_js_module.js +86 -67
- package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +2 -2
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +4 -5
- 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 +3 -3
- package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +2 -2
- package/src/plugins/importmap/jsenv_plugin_importmap.js +25 -27
- package/src/plugins/inject_globals/inject_globals.js +4 -4
- package/src/plugins/inline/jsenv_plugin_data_urls.js +1 -1
- package/src/plugins/inline/jsenv_plugin_html_inline_content.js +41 -43
- package/src/plugins/inline/jsenv_plugin_js_inline_content.js +4 -4
- 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 -4
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +45 -67
- 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 +3 -4
- 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 -3
- package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +2 -3
- package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +1 -1
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +1 -1
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +2 -1
- package/src/plugins/url_analysis/css/css_urls.js +2 -3
- package/src/plugins/url_analysis/html/html_urls.js +98 -113
- package/src/plugins/url_analysis/js/js_urls.js +3 -2
- package/src/test/coverage/babel_plugin_instrument.js +82 -0
- package/src/test/coverage/coverage_reporter_html_directory.js +36 -0
- package/src/test/coverage/coverage_reporter_json_file.js +22 -0
- package/src/test/coverage/coverage_reporter_text_log.js +19 -0
- package/src/test/coverage/empty_coverage_factory.js +52 -0
- package/src/test/coverage/file_by_file_coverage.js +25 -0
- package/src/test/coverage/istanbul_coverage_composition.js +28 -0
- package/src/test/coverage/istanbul_coverage_map_from_coverage.js +16 -0
- package/src/test/coverage/list_files_not_covered.js +15 -0
- package/src/test/coverage/missing_coverage.js +41 -0
- package/src/test/coverage/report_to_coverage.js +196 -0
- package/src/test/coverage/v8_and_istanbul.js +37 -0
- package/src/test/coverage/v8_coverage_composition.js +24 -0
- package/src/test/coverage/v8_coverage_from_directory.js +87 -0
- package/src/test/coverage/v8_coverage_to_istanbul.js +99 -0
- package/src/test/execute_plan.js +2 -2
- package/src/test/execute_test_plan.js +3 -3
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
parseSrcSet,
|
|
3
|
+
stringifySrcSet,
|
|
4
|
+
} from "@jsenv/ast/src/html/html_src_set.js"
|
|
2
5
|
|
|
3
6
|
import { injectQuery, compareTwoUrlPaths } from "./url_helpers.js"
|
|
4
7
|
|
|
@@ -57,7 +60,7 @@ export const reloadDOMNodesUsingUrl = (urlToReload) => {
|
|
|
57
60
|
visitNodeAttributeAsUrl(img, "src")
|
|
58
61
|
const srcset = img.srcset
|
|
59
62
|
if (srcset) {
|
|
60
|
-
const srcCandidates =
|
|
63
|
+
const srcCandidates = parseSrcSet(srcset)
|
|
61
64
|
srcCandidates.forEach((srcCandidate) => {
|
|
62
65
|
const url = new URL(srcCandidate.specifier, `${window.location.href}`)
|
|
63
66
|
if (shouldReloadUrl(url)) {
|
|
@@ -65,7 +68,7 @@ export const reloadDOMNodesUsingUrl = (urlToReload) => {
|
|
|
65
68
|
}
|
|
66
69
|
})
|
|
67
70
|
mutations.push(() => {
|
|
68
|
-
img.srcset =
|
|
71
|
+
img.srcset = stringifySrcSet(srcCandidates)
|
|
69
72
|
})
|
|
70
73
|
}
|
|
71
74
|
})
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
parseHtmlString,
|
|
3
3
|
stringifyHtmlAst,
|
|
4
|
-
|
|
4
|
+
injectScriptNodeAsEarlyAsPossible,
|
|
5
5
|
createHtmlNode,
|
|
6
|
-
} from "@jsenv/
|
|
6
|
+
} from "@jsenv/ast"
|
|
7
7
|
|
|
8
8
|
export const jsenvPluginDevSSEClient = () => {
|
|
9
9
|
const eventSourceClientFileUrl = new URL(
|
|
@@ -22,7 +22,7 @@ export const jsenvPluginDevSSEClient = () => {
|
|
|
22
22
|
expectedType: "js_module",
|
|
23
23
|
specifier: eventSourceClientFileUrl,
|
|
24
24
|
})
|
|
25
|
-
|
|
25
|
+
injectScriptNodeAsEarlyAsPossible(
|
|
26
26
|
htmlAst,
|
|
27
27
|
createHtmlNode({
|
|
28
28
|
"tagName": "script",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { urlToRelativeUrl } from "@jsenv/urls"
|
|
2
2
|
import { createCallbackList } from "@jsenv/abort"
|
|
3
3
|
|
|
4
|
-
import { createSSEService } from "@jsenv/
|
|
4
|
+
import { createSSEService } from "@jsenv/core/src/helpers/event_source/sse_service.js"
|
|
5
5
|
|
|
6
6
|
export const jsenvPluginDevSSEServer = ({
|
|
7
7
|
rootDirectoryUrl,
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* It can be quite challenging, see "bundle_sourcemap.js"
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import { postCssPluginUrlVisitor } from "@jsenv/
|
|
11
|
-
|
|
12
|
-
import { sortByDependencies } from "@jsenv/
|
|
9
|
+
import { createMagicSource } from "@jsenv/sourcemap"
|
|
10
|
+
import { applyPostCss, postCssPluginUrlVisitor } from "@jsenv/ast"
|
|
11
|
+
|
|
12
|
+
import { sortByDependencies } from "@jsenv/core/src/omega/url_graph/sort_by_dependencies.js"
|
|
13
13
|
|
|
14
14
|
// Do not use until https://github.com/parcel-bundler/parcel-css/issues/181
|
|
15
15
|
export const bundleCss = async ({ cssUrlInfos, context }) => {
|
|
@@ -4,8 +4,8 @@ import { URL_META } from "@jsenv/url-meta"
|
|
|
4
4
|
import { isFileSystemPath } from "@jsenv/urls"
|
|
5
5
|
import { createDetailedMessage } from "@jsenv/log"
|
|
6
6
|
import { babelHelperNameFromUrl } from "@jsenv/babel-plugins"
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import { sourcemapConverter } from "@jsenv/sourcemap"
|
|
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,
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* - global
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { createMagicSource } from "@jsenv/sourcemap"
|
|
11
|
+
import { applyBabelPlugins } from "@jsenv/ast"
|
|
12
12
|
|
|
13
13
|
export const jsenvPluginCommonJsGlobals = () => {
|
|
14
14
|
const transformCommonJsGlobals = async (urlInfo, { scenario }) => {
|
|
@@ -6,17 +6,16 @@ import {
|
|
|
6
6
|
urlToFilename,
|
|
7
7
|
ensurePathnameTrailingSlash,
|
|
8
8
|
} from "@jsenv/urls"
|
|
9
|
-
|
|
10
9
|
import {
|
|
11
10
|
applyFileSystemMagicResolution,
|
|
12
11
|
getExtensionsToTry,
|
|
13
12
|
} from "@jsenv/node-esm-resolution"
|
|
14
|
-
import { CONTENT_TYPE } from "@jsenv/utils/content_type/content_type.js"
|
|
13
|
+
import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"
|
|
15
14
|
|
|
16
15
|
export const jsenvPluginFileUrls = ({
|
|
17
16
|
magicExtensions = ["inherit", ".js"],
|
|
18
17
|
magicDirectoryIndex = true,
|
|
19
|
-
|
|
18
|
+
preserveSymlinks = false,
|
|
20
19
|
directoryReferenceAllowed = false,
|
|
21
20
|
}) => {
|
|
22
21
|
return [
|
|
@@ -61,7 +60,7 @@ export const jsenvPluginFileUrls = ({
|
|
|
61
60
|
if (foundADirectory && directoryReferenceAllowed) {
|
|
62
61
|
reference.data.foundADirectory = true
|
|
63
62
|
const directoryFacadeUrl = urlObject.href
|
|
64
|
-
const directoryUrlRaw =
|
|
63
|
+
const directoryUrlRaw = preserveSymlinks
|
|
65
64
|
? directoryFacadeUrl
|
|
66
65
|
: resolveSymlink(directoryFacadeUrl)
|
|
67
66
|
const directoryUrl = `${directoryUrlRaw}${search}${hash}`
|
|
@@ -82,7 +81,7 @@ export const jsenvPluginFileUrls = ({
|
|
|
82
81
|
}
|
|
83
82
|
reference.data.foundADirectory = filesystemResolution.isDirectory
|
|
84
83
|
const fileFacadeUrl = filesystemResolution.url
|
|
85
|
-
const fileUrlRaw =
|
|
84
|
+
const fileUrlRaw = preserveSymlinks
|
|
86
85
|
? fileFacadeUrl
|
|
87
86
|
: resolveSymlink(fileFacadeUrl)
|
|
88
87
|
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
|
)
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getHtmlNodeAttributeByName,
|
|
3
|
-
parseLinkNode,
|
|
4
|
-
} from "@jsenv/utils/html_ast/html_ast.js"
|
|
5
|
-
import { htmlAttributeSrcSet } from "@jsenv/utils/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,6 @@
|
|
|
1
|
-
import { createMagicSource } from "@jsenv/
|
|
2
|
-
import { parseHtmlString } from "@jsenv/
|
|
3
|
-
|
|
1
|
+
import { createMagicSource } from "@jsenv/sourcemap"
|
|
2
|
+
import { parseHtmlString, applyBabelPlugins } from "@jsenv/ast"
|
|
3
|
+
|
|
4
4
|
import { collectHotDataFromHtmlAst } from "./html_hot_dependencies.js"
|
|
5
5
|
import { babelPluginMetadataImportMetaHot } from "./babel_plugin_metadata_import_meta_hot.js"
|
|
6
6
|
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* - replaced by undefined (import.meta.dev but it's build; the goal is to ensure it's tree-shaked)
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { createMagicSource } from "@jsenv/sourcemap"
|
|
13
|
+
import { applyBabelPlugins } from "@jsenv/ast"
|
|
14
14
|
|
|
15
15
|
export const jsenvPluginImportMetaScenarios = () => {
|
|
16
16
|
return {
|