@jsenv/core 24.2.2 → 24.3.1
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/{license → LICENSE} +0 -0
- package/dist/browser_runtime/browser_runtime-fbd309a1.js +5137 -0
- package/dist/browser_runtime/browser_runtime-fbd309a1.js.map +1064 -0
- package/dist/{jsenv_browser_system.js → browser_system/browser_system-29eda202.js} +12 -12
- package/dist/{jsenv_browser_system.js.map → browser_system/browser_system-29eda202.js.map} +64 -64
- package/dist/build_manifest.js +12 -0
- package/dist/compile_proxy/assets/s.js-749702e8.map +242 -0
- package/dist/compile_proxy/compile_proxy-405777e6.html +2074 -0
- package/dist/compile_proxy/compile_proxy.html__inline__20-39c0801c.js.map +385 -0
- package/dist/{jsenv_event_source_client.js → event_source_client/event_source_client-9f14c8b9.js} +39 -21
- package/dist/event_source_client/event_source_client-9f14c8b9.js.map +127 -0
- package/dist/redirector/assets/s.js-749702e8.map +242 -0
- package/dist/redirector/redirector-237cd168.html +2118 -0
- package/dist/redirector/redirector.html__inline__15-33acb0b9.js.map +390 -0
- package/dist/toolbar/assets/compilation.css-209d68b4.map +12 -0
- package/dist/toolbar/assets/eventsource.css-38cd0a36.map +12 -0
- package/dist/toolbar/assets/execution.css-0ebe522f.map +12 -0
- package/dist/toolbar/assets/focus.css-3f9c156d.map +12 -0
- package/dist/toolbar/assets/light-theme.css-78b19a80.map +12 -0
- package/dist/toolbar/assets/overflow-menu.css-d9688a1c.map +12 -0
- package/dist/toolbar/assets/s.js-749702e8.map +242 -0
- package/dist/toolbar/assets/settings.css-2b81b245.map +12 -0
- package/dist/toolbar/assets/toolbar.main.css-846920e9.map +28 -0
- package/dist/toolbar/assets/tooltip.css-03395ee6.map +12 -0
- package/dist/toolbar/toolbar-d3d98c2e.html +4778 -0
- package/dist/toolbar/toolbar.main-cab36c15.js.map +795 -0
- package/dist/toolbar_injector/assets/jsenv-logo-188b9ca6.svg +95 -0
- package/dist/{jsenv_toolbar_injector.js → toolbar_injector/toolbar_injector-01f71ce3.js} +85 -65
- package/dist/toolbar_injector/toolbar_injector-01f71ce3.js.map +294 -0
- package/main.js +0 -1
- package/package.json +4 -2
- package/readme.md +10 -7
- package/src/buildProject.js +6 -2
- package/src/dev_server.js +22 -130
- package/src/importUsingChildProcess.js +1 -1
- package/src/internal/{runtime/detectBrowser/detectBrowser.js → browser_detection/browser_detection.js} +0 -0
- package/src/internal/{runtime/detectBrowser → browser_detection}/detectAndroid.js +0 -0
- package/src/internal/{runtime/detectBrowser → browser_detection}/detectChrome.js +0 -0
- package/src/internal/{runtime/detectBrowser → browser_detection}/detectEdge.js +0 -0
- package/src/internal/{runtime/detectBrowser → browser_detection}/detectElectron.js +0 -0
- package/src/internal/{runtime/detectBrowser → browser_detection}/detectFirefox.js +0 -0
- package/src/internal/{runtime/detectBrowser → browser_detection}/detectIOS.js +0 -0
- package/src/internal/{runtime/detectBrowser → browser_detection}/detectInternetExplorer.js +0 -0
- package/src/internal/{runtime/detectBrowser → browser_detection}/detectOpera.js +0 -0
- package/src/internal/{runtime/detectBrowser → browser_detection}/detectSafari.js +0 -0
- package/src/internal/{runtime/detectBrowser → browser_detection}/util.js +0 -0
- package/src/internal/{runtime/createBrowserRuntime/scanBrowserRuntimeFeatures.js → browser_feature_detection/browser_feature_detection.js} +116 -81
- package/src/internal/browser_feature_detection/compile_proxy.html +27 -0
- package/src/internal/{browser-launcher → browser_launcher}/createSharing.js +0 -0
- package/src/internal/{browser-launcher → browser_launcher}/executeHtmlFile.js +7 -4
- package/src/internal/{browser-launcher → browser_launcher}/trackPageToNotify.js +0 -0
- package/src/internal/{browser-launcher/jsenv-browser-system.js → browser_runtime/browser_runtime.js} +4 -4
- package/src/internal/{runtime/createBrowserRuntime/createBrowserSystem.js → browser_runtime/browser_system.js} +3 -2
- package/src/internal/{runtime/createBrowserRuntime → browser_runtime}/createBrowserRuntime.js +7 -5
- package/src/internal/{browser-launcher → browser_runtime}/displayErrorInDocument.js +0 -0
- package/src/internal/{browser-launcher → browser_runtime}/displayErrorNotification.js +2 -4
- package/src/internal/{runtime/createBrowserRuntime → browser_runtime}/evalSource.js +2 -0
- package/src/internal/{runtime/createBrowserRuntime → browser_runtime}/makeNamespaceTransferable.js +0 -0
- package/src/internal/{browser-utils → browser_utils}/fetch-browser.js +2 -0
- package/src/internal/{browser-utils → browser_utils}/fetchAndEvalUsingFetch.js +3 -0
- package/src/internal/{browser-utils → browser_utils}/fetchAndEvalUsingScript.js +2 -0
- package/src/internal/{browser-utils → browser_utils}/fetchJson.js +0 -0
- package/src/internal/{browser-utils → browser_utils}/fetchUsingXHR.js +4 -4
- package/src/internal/building/buildUsingRollup.js +4 -0
- package/src/internal/building/createJsenvRollupPlugin.js +19 -9
- package/src/internal/building/css/applyPostCss.js +19 -8
- package/src/internal/building/css/moveCssUrls.js +44 -0
- package/src/internal/building/css/parseCssRessource.js +67 -17
- package/src/internal/building/css/parseCssUrls.js +29 -23
- package/src/internal/building/css/postcss_plugin_url_visitor.js +11 -20
- package/src/internal/building/css/replaceCssUrls.js +38 -19
- package/src/internal/building/css_module.js +6 -10
- package/src/internal/building/html/parseHtmlRessource.js +37 -11
- package/src/internal/building/parseRessource.js +3 -0
- package/src/internal/building/ressource_builder.js +12 -3
- package/src/internal/compiling/babel_plugin_import_assertions.js +1 -2
- package/src/internal/compiling/html_source_file_service.js +23 -21
- package/src/internal/compiling/jsenvCompilerForHtml.js +15 -22
- package/src/internal/compiling/startCompileServer.js +34 -32
- package/src/internal/dev_server/event_source_client/event_source_connection.js +28 -19
- package/src/internal/dev_server/exploring/exploring.html +7 -2
- package/src/internal/dev_server/exploring/fetchExploringJson.js +4 -9
- package/src/internal/dev_server/redirector/redirector.html +37 -2
- package/src/internal/dev_server/toolbar/compilation/toolbar.compilation.js +4 -7
- package/src/internal/dev_server/toolbar/eventsource/toolbar.eventsource.js +2 -2
- package/src/internal/dev_server/toolbar/notification/toolbar.notification.js +75 -44
- package/src/internal/dev_server/toolbar/toolbar.html +31 -5
- package/src/internal/dev_server/toolbar/toolbar.injector.js +53 -36
- package/src/internal/dev_server/toolbar/toolbar.main.js +44 -31
- package/src/internal/dev_server/toolbar/util/fetching.js +1 -1
- package/src/internal/generateGroupMap/one_runtime_compat.js +1 -1
- package/src/internal/generateGroupMap/runtime_compat_composition.js +1 -1
- package/src/internal/generateGroupMap/runtime_support.js +1 -1
- package/src/internal/jsenvInternalFiles.js +0 -26
- package/src/internal/jsenv_builds.js +19 -0
- package/src/internal/{runtime/node-feature-detect/feature-detect-dynamic-import.mjs → node_feature_detection/feature_detect_dynamic_import.mjs} +0 -0
- package/src/internal/{runtime/node-feature-detect/feature-detect-top-level-await.mjs → node_feature_detection/feature_detect_top_level_await.mjs} +0 -0
- package/src/internal/{runtime/node-feature-detect → node_feature_detection}/nodeSupportsDynamicImport.js +0 -0
- package/src/internal/node_feature_detection/nodeSupportsTopLevelAwait.js +16 -0
- package/src/internal/{runtime/createNodeRuntime/scanNodeRuntimeFeatures.js → node_feature_detection/node_feature_detection.js} +12 -13
- package/src/internal/{node-launcher → node_launcher}/createChildProcessOptions.js +0 -0
- package/src/internal/{node-launcher → node_launcher}/createControllableNodeProcess.js +9 -14
- package/src/internal/{node-launcher → node_launcher}/kill_process_tree.js +0 -0
- package/src/internal/{node-launcher → node_launcher}/processOptions.js +0 -0
- package/src/internal/{runtime/detectNode → node_runtime}/detectNode.js +0 -0
- package/src/internal/{runtime/createNodeRuntime → node_runtime}/evalSource.js +1 -1
- package/src/internal/{runtime/createNodeRuntime → node_runtime}/fetchSource.js +1 -1
- package/src/internal/{node-launcher → node_runtime}/nodeControllableFile.mjs +14 -11
- package/src/internal/{runtime/createNodeRuntime/createNodeExecutionWithDynamicImport.js → node_runtime/node_execution_dynamic_import.js} +34 -6
- package/src/internal/node_runtime/node_execution_performance.js +67 -0
- package/src/internal/{runtime/createNodeRuntime/createNodeExecutionWithSystemJs.js → node_runtime/node_execution_systemjs.js} +38 -24
- package/src/internal/{runtime/createNodeRuntime/createNodeSystem.js → node_runtime/node_system.js} +4 -4
- package/src/internal/runtime/computeCompileIdFromGroupId.js +1 -0
- package/src/internal/runtime/resolveGroup.js +1 -1
- package/src/internal/runtime/resolveRuntimeGroup.js +2 -2
- package/src/internal/{semantic-versioning → semantic_versioning}/findHighestVersion.js +0 -0
- package/src/internal/{semantic-versioning → semantic_versioning}/findLowestVersion.js +0 -0
- package/src/internal/{semantic-versioning → semantic_versioning}/index.js +0 -0
- package/src/internal/{semantic-versioning → semantic_versioning}/valueToVersion.js +0 -0
- package/src/internal/{semantic-versioning → semantic_versioning}/versionCompare.js +0 -0
- package/src/internal/{semantic-versioning → semantic_versioning}/versionIsAbove.js +0 -0
- package/src/internal/{semantic-versioning → semantic_versioning}/versionIsBelow.js +0 -0
- package/src/internal/{semantic-versioning → semantic_versioning}/versionIsEqual.js +0 -0
- package/src/launchBrowser.js +3 -3
- package/src/launchNode.js +33 -7
- package/src/requireUsingChildProcess.js +1 -1
- package/dist/jsenv_compile_proxy.js +0 -1339
- package/dist/jsenv_compile_proxy.js.map +0 -378
- package/dist/jsenv_event_source_client.js.map +0 -126
- package/dist/jsenv_exploring_index.js +0 -1092
- package/dist/jsenv_exploring_index.js.map +0 -353
- package/dist/jsenv_exploring_redirector.js +0 -1386
- package/dist/jsenv_exploring_redirector.js.map +0 -384
- package/dist/jsenv_redirector.js +0 -1388
- package/dist/jsenv_redirector.js.map +0 -384
- package/dist/jsenv_toolbar.js +0 -2880
- package/dist/jsenv_toolbar.js.map +0 -771
- package/dist/jsenv_toolbar_injector.js.map +0 -301
- package/src/internal/browser-launcher/jsenv_compile_proxy.html +0 -13
- package/src/internal/browser-launcher/jsenv_compile_proxy.js +0 -5
- package/src/internal/dev_server/event_source_client/event_source_client_file_info.js +0 -17
- package/src/internal/dev_server/exploring/exploring_file_info.js +0 -21
- package/src/internal/dev_server/redirector/redirector.js +0 -30
- package/src/internal/dev_server/redirector/redirector_file_info.js +0 -24
- package/src/internal/dev_server/toolbar/backtolist/toolbar.backtolist.js +0 -33
- package/src/internal/dev_server/toolbar/toolbar_file_info.js +0 -37
- package/src/internal/node-launcher/node-js-file.js +0 -110
- package/src/internal/runtime/createNodeRuntime/createNodeRuntime.js +0 -32
- package/src/internal/runtime/node-feature-detect/nodeSupportsTopLevelAwait.js +0 -18
- package/src/nodeRuntime.js +0 -5
|
@@ -3,10 +3,8 @@ const { Notification } = window
|
|
|
3
3
|
|
|
4
4
|
const displayErrorNotificationNotAvailable = () => {}
|
|
5
5
|
|
|
6
|
-
const displayErrorNotificationImplementation =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (permission === "granted") {
|
|
6
|
+
const displayErrorNotificationImplementation = (error, { icon } = {}) => {
|
|
7
|
+
if (Notification.permission === "granted") {
|
|
10
8
|
const notification = new Notification("An error occured", {
|
|
11
9
|
lang: "en",
|
|
12
10
|
body: error.stack,
|
package/src/internal/{runtime/createBrowserRuntime → browser_runtime}/makeNamespaceTransferable.js
RENAMED
|
File without changes
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-env browser */
|
|
2
2
|
|
|
3
3
|
export const fetchUsingXHR = async (
|
|
4
4
|
url,
|
|
@@ -206,9 +206,9 @@ const hasSearchParams = typeof window.URLSearchParams === "function"
|
|
|
206
206
|
|
|
207
207
|
const createRequestError = (error, { url }) => {
|
|
208
208
|
return new Error(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
`error during xhr request on ${url}.
|
|
210
|
+
--- error stack ---
|
|
211
|
+
${error.stack}`,
|
|
212
212
|
)
|
|
213
213
|
}
|
|
214
214
|
|
|
@@ -50,8 +50,10 @@ export const buildUsingRollup = async ({
|
|
|
50
50
|
importPaths,
|
|
51
51
|
|
|
52
52
|
urlVersioning,
|
|
53
|
+
urlVersionningForEntryPoints,
|
|
53
54
|
lineBreakNormalization,
|
|
54
55
|
jsConcatenation,
|
|
56
|
+
cssConcatenation,
|
|
55
57
|
useImportMapToMaximizeCacheReuse,
|
|
56
58
|
preserveEntrySignatures,
|
|
57
59
|
treeshake,
|
|
@@ -121,8 +123,10 @@ export const buildUsingRollup = async ({
|
|
|
121
123
|
importPaths,
|
|
122
124
|
|
|
123
125
|
urlVersioning,
|
|
126
|
+
urlVersionningForEntryPoints,
|
|
124
127
|
lineBreakNormalization,
|
|
125
128
|
jsConcatenation,
|
|
129
|
+
cssConcatenation,
|
|
126
130
|
useImportMapToMaximizeCacheReuse,
|
|
127
131
|
|
|
128
132
|
minify,
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
urlIsInsideOf,
|
|
13
13
|
normalizeStructuredMetaMap,
|
|
14
14
|
urlToMeta,
|
|
15
|
+
urlToBasename,
|
|
15
16
|
} from "@jsenv/filesystem"
|
|
16
17
|
import { UNICODE } from "@jsenv/log"
|
|
17
18
|
|
|
@@ -72,8 +73,10 @@ export const createJsenvRollupPlugin = async ({
|
|
|
72
73
|
importAssertionsSupport,
|
|
73
74
|
|
|
74
75
|
urlVersioning,
|
|
76
|
+
urlVersionningForEntryPoints,
|
|
75
77
|
lineBreakNormalization,
|
|
76
78
|
jsConcatenation,
|
|
79
|
+
cssConcatenation,
|
|
77
80
|
useImportMapToMaximizeCacheReuse,
|
|
78
81
|
|
|
79
82
|
minify,
|
|
@@ -468,6 +471,7 @@ export const createJsenvRollupPlugin = async ({
|
|
|
468
471
|
minifyJs,
|
|
469
472
|
minifyHtml,
|
|
470
473
|
minifyCssOptions,
|
|
474
|
+
cssConcatenation,
|
|
471
475
|
})
|
|
472
476
|
},
|
|
473
477
|
},
|
|
@@ -586,9 +590,10 @@ export const createJsenvRollupPlugin = async ({
|
|
|
586
590
|
atleastOneChunkEmitted = true
|
|
587
591
|
emitChunk({
|
|
588
592
|
id: ensureRelativeUrlNotation(entryProjectRelativeUrl),
|
|
589
|
-
name: entryBuildRelativeUrl,
|
|
590
|
-
|
|
591
|
-
|
|
593
|
+
name: urlToBasename(`file:///${entryBuildRelativeUrl}`),
|
|
594
|
+
...(urlVersionningForEntryPoints
|
|
595
|
+
? {}
|
|
596
|
+
: { fileName: entryBuildRelativeUrl }),
|
|
592
597
|
})
|
|
593
598
|
return
|
|
594
599
|
}
|
|
@@ -601,15 +606,16 @@ export const createJsenvRollupPlugin = async ({
|
|
|
601
606
|
`Unusual content type for entry point, got "${entryContentType}" for ${entryProjectRelativeUrl}`,
|
|
602
607
|
)
|
|
603
608
|
}
|
|
604
|
-
const entryUrl =
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
609
|
+
const entryUrl =
|
|
610
|
+
entryContentType === "text/html"
|
|
611
|
+
? resolveUrl(entryProjectRelativeUrl, compileServerOrigin)
|
|
612
|
+
: resolveUrl(entryProjectRelativeUrl, compileDirectoryRemoteUrl)
|
|
608
613
|
await ressourceBuilder.createReferenceForEntryPoint({
|
|
609
614
|
entryContentType,
|
|
610
615
|
entryUrl,
|
|
611
616
|
entryBuffer,
|
|
612
617
|
entryBuildRelativeUrl,
|
|
618
|
+
urlVersionningForEntryPoints,
|
|
613
619
|
})
|
|
614
620
|
},
|
|
615
621
|
),
|
|
@@ -1015,6 +1021,9 @@ export const createJsenvRollupPlugin = async ({
|
|
|
1015
1021
|
return id
|
|
1016
1022
|
}
|
|
1017
1023
|
outputOptions.entryFileNames = () => {
|
|
1024
|
+
if (urlVersionningForEntryPoints) {
|
|
1025
|
+
return `[name]-[hash]${outputExtension}`
|
|
1026
|
+
}
|
|
1018
1027
|
return `[name]${outputExtension}`
|
|
1019
1028
|
}
|
|
1020
1029
|
outputOptions.chunkFileNames = () => {
|
|
@@ -1097,7 +1106,9 @@ export const createJsenvRollupPlugin = async ({
|
|
|
1097
1106
|
const file = jsChunks[fileName]
|
|
1098
1107
|
let buildRelativeUrl
|
|
1099
1108
|
const canBeVersioned =
|
|
1100
|
-
asRollupUrl(file.url) in jsModulesFromEntry ||
|
|
1109
|
+
asRollupUrl(file.url) in jsModulesFromEntry ||
|
|
1110
|
+
urlVersionningForEntryPoints ||
|
|
1111
|
+
!file.isEntry
|
|
1101
1112
|
|
|
1102
1113
|
if (urlVersioning) {
|
|
1103
1114
|
if (canBeVersioned && useImportMapToMaximizeCacheReuse) {
|
|
@@ -1133,7 +1144,6 @@ export const createJsenvRollupPlugin = async ({
|
|
|
1133
1144
|
buildInlineFileContents[buildRelativeUrl] = file.code
|
|
1134
1145
|
} else {
|
|
1135
1146
|
markBuildRelativeUrlAsUsedByJs(buildRelativeUrl)
|
|
1136
|
-
buildManifest[fileName] = buildRelativeUrl
|
|
1137
1147
|
buildMappings[originalProjectRelativeUrl] = buildRelativeUrl
|
|
1138
1148
|
}
|
|
1139
1149
|
})
|
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
import { urlToFileSystemPath } from "@jsenv/filesystem"
|
|
2
2
|
|
|
3
|
-
export const applyPostCss = async (
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export const applyPostCss = async ({
|
|
4
|
+
code,
|
|
5
|
+
url,
|
|
6
|
+
map,
|
|
7
|
+
sourcemapMethod = "comment",
|
|
6
8
|
plugins,
|
|
7
9
|
// https://github.com/postcss/postcss#options
|
|
8
10
|
options = {},
|
|
9
|
-
) => {
|
|
11
|
+
}) => {
|
|
10
12
|
const { default: postcss } = await import("postcss")
|
|
11
13
|
|
|
12
|
-
let result
|
|
13
14
|
try {
|
|
14
|
-
const cssFileUrl = urlToFileUrl(
|
|
15
|
-
result = await postcss(plugins).process(
|
|
15
|
+
const cssFileUrl = urlToFileUrl(url)
|
|
16
|
+
const result = await postcss(plugins).process(code, {
|
|
16
17
|
collectUrls: true,
|
|
17
18
|
from: urlToFileSystemPath(cssFileUrl),
|
|
18
19
|
to: urlToFileSystemPath(cssFileUrl),
|
|
20
|
+
map: {
|
|
21
|
+
annotation: sourcemapMethod === "comment",
|
|
22
|
+
inline: sourcemapMethod === "inline",
|
|
23
|
+
// https://postcss.org/api/#sourcemapoptions
|
|
24
|
+
...(map ? { prev: JSON.stringify(map) } : {}),
|
|
25
|
+
},
|
|
19
26
|
...options,
|
|
20
27
|
})
|
|
28
|
+
return {
|
|
29
|
+
code: result.css,
|
|
30
|
+
map: result.map.toJSON(),
|
|
31
|
+
postCssMessages: result.messages,
|
|
32
|
+
}
|
|
21
33
|
} catch (error) {
|
|
22
34
|
if (error.name === "CssSyntaxError") {
|
|
23
35
|
console.error(String(error))
|
|
@@ -25,7 +37,6 @@ export const applyPostCss = async (
|
|
|
25
37
|
}
|
|
26
38
|
throw error
|
|
27
39
|
}
|
|
28
|
-
return result
|
|
29
40
|
}
|
|
30
41
|
|
|
31
42
|
// the goal of this function is to take an url that is likely an http url
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { urlToRelativeUrl } from "@jsenv/filesystem"
|
|
2
|
+
|
|
3
|
+
import { applyPostCss } from "./applyPostCss.js"
|
|
4
|
+
import { postCssPluginUrlVisitor } from "./postcss_plugin_url_visitor.js"
|
|
5
|
+
|
|
6
|
+
export const moveCssUrls = async ({
|
|
7
|
+
code,
|
|
8
|
+
from,
|
|
9
|
+
to,
|
|
10
|
+
map,
|
|
11
|
+
sourcemapMethod,
|
|
12
|
+
} = {}) => {
|
|
13
|
+
const fromDirectoryUrl = new URL("./", from).href
|
|
14
|
+
const toDirectoryUrl = new URL("./", to).href
|
|
15
|
+
// same directory, nothing to do
|
|
16
|
+
if (fromDirectoryUrl === toDirectoryUrl) {
|
|
17
|
+
return { code, map }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const result = await applyPostCss({
|
|
21
|
+
code,
|
|
22
|
+
url: from,
|
|
23
|
+
map,
|
|
24
|
+
sourcemapMethod,
|
|
25
|
+
plugins: [
|
|
26
|
+
postCssPluginUrlVisitor({
|
|
27
|
+
urlVisitor: ({ specifier }) => {
|
|
28
|
+
if (specifier[0] === "#") {
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
const url = new URL(specifier, fromDirectoryUrl).href
|
|
32
|
+
const relativeUrl = urlToRelativeUrl(url, toDirectoryUrl)
|
|
33
|
+
return relativeUrl
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
],
|
|
37
|
+
})
|
|
38
|
+
code = result.code
|
|
39
|
+
map = result.map
|
|
40
|
+
return {
|
|
41
|
+
code,
|
|
42
|
+
map,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
urlToFilename,
|
|
3
|
+
urlToRelativeUrl,
|
|
4
|
+
resolveUrl,
|
|
5
|
+
fileSystemPathToUrl,
|
|
6
|
+
} from "@jsenv/filesystem"
|
|
2
7
|
|
|
3
8
|
import {
|
|
4
9
|
getCssSourceMappingUrl,
|
|
@@ -7,14 +12,18 @@ import {
|
|
|
7
12
|
import { getRessourceAsBase64Url } from "../ressource_builder_util.js"
|
|
8
13
|
import { parseCssUrls } from "./parseCssUrls.js"
|
|
9
14
|
import { replaceCssUrls } from "./replaceCssUrls.js"
|
|
15
|
+
import { moveCssUrls } from "./moveCssUrls.js"
|
|
10
16
|
|
|
11
17
|
export const parseCssRessource = async (
|
|
12
18
|
cssRessource,
|
|
13
19
|
{ notifyReferenceFound },
|
|
14
|
-
{ asProjectUrl, asOriginalUrl, minify, minifyCssOptions },
|
|
20
|
+
{ asProjectUrl, asOriginalUrl, minify, minifyCssOptions, cssConcatenation },
|
|
15
21
|
) => {
|
|
16
22
|
const cssString = String(cssRessource.bufferBeforeBuild)
|
|
17
23
|
const cssSourcemapUrl = getCssSourceMappingUrl(cssString)
|
|
24
|
+
const url = cssRessource.url
|
|
25
|
+
let code = cssString
|
|
26
|
+
let map
|
|
18
27
|
let sourcemapReference
|
|
19
28
|
if (cssSourcemapUrl) {
|
|
20
29
|
sourcemapReference = notifyReferenceFound({
|
|
@@ -26,6 +35,8 @@ export const parseCssRessource = async (
|
|
|
26
35
|
referenceColumn: 0,
|
|
27
36
|
isSourcemap: true,
|
|
28
37
|
})
|
|
38
|
+
await sourcemapReference.ressource.getBufferAvailablePromise()
|
|
39
|
+
map = JSON.parse(String(sourcemapReference.ressource.bufferBeforeBuild))
|
|
29
40
|
} else {
|
|
30
41
|
sourcemapReference = notifyReferenceFound({
|
|
31
42
|
contentType: "application/octet-stream",
|
|
@@ -35,20 +46,25 @@ export const parseCssRessource = async (
|
|
|
35
46
|
})
|
|
36
47
|
}
|
|
37
48
|
|
|
38
|
-
const { atImports, urlDeclarations } = await parseCssUrls(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
)
|
|
42
|
-
|
|
49
|
+
const { atImports, urlDeclarations } = await parseCssUrls({
|
|
50
|
+
code,
|
|
51
|
+
url,
|
|
52
|
+
})
|
|
43
53
|
const urlNodeReferenceMapping = new Map()
|
|
54
|
+
const atImportReferences = []
|
|
44
55
|
atImports.forEach((atImport) => {
|
|
45
56
|
const importReference = notifyReferenceFound({
|
|
46
57
|
ressourceSpecifier: atImport.specifier,
|
|
47
58
|
...cssNodeToReferenceLocation(atImport.urlDeclarationNode),
|
|
48
59
|
})
|
|
49
60
|
urlNodeReferenceMapping.set(atImport.urlNode, importReference)
|
|
61
|
+
atImportReferences.push(importReference)
|
|
50
62
|
})
|
|
51
63
|
urlDeclarations.forEach((urlDeclaration) => {
|
|
64
|
+
if (urlDeclaration.specifier[0] === "#") {
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
52
68
|
const urlReference = notifyReferenceFound({
|
|
53
69
|
ressourceSpecifier: urlDeclaration.specifier,
|
|
54
70
|
...cssNodeToReferenceLocation(urlDeclaration.urlDeclarationNode),
|
|
@@ -56,22 +72,20 @@ export const parseCssRessource = async (
|
|
|
56
72
|
urlNodeReferenceMapping.set(urlDeclaration.urlNode, urlReference)
|
|
57
73
|
})
|
|
58
74
|
|
|
59
|
-
return async ({
|
|
75
|
+
return async ({
|
|
76
|
+
getUrlRelativeToImporter,
|
|
77
|
+
precomputeBuildRelativeUrl,
|
|
78
|
+
buildDirectoryUrl,
|
|
79
|
+
}) => {
|
|
60
80
|
const sourcemapRessource = sourcemapReference.ressource
|
|
61
|
-
|
|
62
|
-
let code = cssString
|
|
63
|
-
let map = sourcemapRessource.isPlaceholder
|
|
64
|
-
? undefined
|
|
65
|
-
: JSON.parse(String(sourcemapRessource.bufferBeforeBuild))
|
|
66
|
-
|
|
67
81
|
const cssCompiledUrl = cssRessource.url
|
|
68
82
|
const cssOriginalUrl = asOriginalUrl(cssCompiledUrl)
|
|
69
83
|
|
|
70
84
|
const replaceCssResult = await replaceCssUrls({
|
|
71
|
-
url:
|
|
72
|
-
code
|
|
85
|
+
url: asProjectUrl(cssCompiledUrl),
|
|
86
|
+
code,
|
|
73
87
|
map,
|
|
74
|
-
|
|
88
|
+
urlVisitor: ({ urlNode }) => {
|
|
75
89
|
const nodeCandidates = Array.from(urlNodeReferenceMapping.keys())
|
|
76
90
|
const urlNodeFound = nodeCandidates.find((urlNodeCandidate) =>
|
|
77
91
|
isSameCssDocumentUrlNode(urlNodeCandidate, urlNode),
|
|
@@ -95,6 +109,42 @@ export const parseCssRessource = async (
|
|
|
95
109
|
}
|
|
96
110
|
return getUrlRelativeToImporter(cssUrlRessource)
|
|
97
111
|
},
|
|
112
|
+
cssConcatenation,
|
|
113
|
+
loadCssImport: async (path) => {
|
|
114
|
+
// const cssFileUrl = asProjectUrl(url)
|
|
115
|
+
const importedCssFileUrl = fileSystemPathToUrl(path)
|
|
116
|
+
const atImportReference = atImportReferences.find(
|
|
117
|
+
(atImportReference) => {
|
|
118
|
+
return (
|
|
119
|
+
asProjectUrl(atImportReference.ressource.url) ===
|
|
120
|
+
importedCssFileUrl
|
|
121
|
+
)
|
|
122
|
+
},
|
|
123
|
+
)
|
|
124
|
+
atImportReference.inlinedCallback()
|
|
125
|
+
let code = String(atImportReference.ressource.bufferAfterBuild)
|
|
126
|
+
const moveResult = await moveCssUrls({
|
|
127
|
+
code,
|
|
128
|
+
from: resolveUrl(
|
|
129
|
+
atImportReference.ressource.buildRelativeUrl,
|
|
130
|
+
buildDirectoryUrl,
|
|
131
|
+
),
|
|
132
|
+
to: resolveUrl(
|
|
133
|
+
precomputeBuildRelativeUrl(cssRessource),
|
|
134
|
+
buildDirectoryUrl,
|
|
135
|
+
),
|
|
136
|
+
// moveCssUrls will change the css source code
|
|
137
|
+
// Ideally we should update the sourcemap referenced by css
|
|
138
|
+
// to target the one after css urls are moved.
|
|
139
|
+
// It means we should force sourcemap ressource to the new one
|
|
140
|
+
// until it's supported we prevent postcss from updating the
|
|
141
|
+
// sourcemap comment, othwise css would reference a sourcemap
|
|
142
|
+
// that won't by in the build directory
|
|
143
|
+
sourcemapMethod: null,
|
|
144
|
+
})
|
|
145
|
+
code = moveResult.code
|
|
146
|
+
return code
|
|
147
|
+
},
|
|
98
148
|
cssMinification: minify,
|
|
99
149
|
cssMinificationOptions: minifyCssOptions,
|
|
100
150
|
})
|
|
@@ -1,32 +1,38 @@
|
|
|
1
1
|
import { applyPostCss } from "./applyPostCss.js"
|
|
2
2
|
import { postCssPluginUrlVisitor } from "./postcss_plugin_url_visitor.js"
|
|
3
3
|
|
|
4
|
-
export const parseCssUrls = async (
|
|
4
|
+
export const parseCssUrls = async ({ code, url = "file:///file.css" }) => {
|
|
5
5
|
const atImports = []
|
|
6
6
|
const urlDeclarations = []
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (type === "import") {
|
|
15
|
-
atImports.push({
|
|
7
|
+
await applyPostCss({
|
|
8
|
+
code,
|
|
9
|
+
url,
|
|
10
|
+
plugins: [
|
|
11
|
+
postCssPluginUrlVisitor({
|
|
12
|
+
urlVisitor: ({
|
|
13
|
+
type,
|
|
16
14
|
specifier,
|
|
15
|
+
atImportNode,
|
|
16
|
+
declarationNode,
|
|
17
17
|
urlNode,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
}) => {
|
|
19
|
+
if (type === "import") {
|
|
20
|
+
atImports.push({
|
|
21
|
+
specifier,
|
|
22
|
+
urlNode,
|
|
23
|
+
urlDeclarationNode: atImportNode,
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
if (type === "asset") {
|
|
27
|
+
urlDeclarations.push({
|
|
28
|
+
specifier,
|
|
29
|
+
urlNode,
|
|
30
|
+
urlDeclarationNode: declarationNode,
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
],
|
|
36
|
+
})
|
|
31
37
|
return { atImports, urlDeclarations }
|
|
32
38
|
}
|
|
@@ -14,18 +14,14 @@ hence sourcemap cannot point the original source location
|
|
|
14
14
|
import { fileSystemPathToUrl, resolveUrl } from "@jsenv/filesystem"
|
|
15
15
|
import { require } from "@jsenv/core/src/internal/require.js"
|
|
16
16
|
|
|
17
|
-
export const postCssPluginUrlVisitor = () => {
|
|
17
|
+
export const postCssPluginUrlVisitor = ({ urlVisitor = () => null }) => {
|
|
18
18
|
const parseCssValue = require("postcss-value-parser")
|
|
19
19
|
const stringifyCssNodes = parseCssValue.stringify
|
|
20
20
|
|
|
21
21
|
return {
|
|
22
22
|
postcssPlugin: "url_visitor",
|
|
23
23
|
prepare: (result) => {
|
|
24
|
-
const {
|
|
25
|
-
from,
|
|
26
|
-
collectUrls = false,
|
|
27
|
-
getUrlReplacementValue = () => undefined,
|
|
28
|
-
} = result.opts
|
|
24
|
+
const { from } = result.opts
|
|
29
25
|
const fromUrl = fileSystemPathToUrl(from)
|
|
30
26
|
const mutations = []
|
|
31
27
|
return {
|
|
@@ -109,9 +105,12 @@ export const postCssPluginUrlVisitor = () => {
|
|
|
109
105
|
atImportNode,
|
|
110
106
|
urlNode,
|
|
111
107
|
}
|
|
112
|
-
const
|
|
113
|
-
if (
|
|
114
|
-
|
|
108
|
+
const urlVisitorReturnValue = urlVisitor(urlReference)
|
|
109
|
+
if (
|
|
110
|
+
urlVisitorReturnValue &&
|
|
111
|
+
urlVisitorReturnValue !== urlNode.value
|
|
112
|
+
) {
|
|
113
|
+
urlNode.value = urlVisitorReturnValue
|
|
115
114
|
const newParams = parsed.toString()
|
|
116
115
|
const newAtImportRule = new AtRule({
|
|
117
116
|
name: "import",
|
|
@@ -120,10 +119,6 @@ export const postCssPluginUrlVisitor = () => {
|
|
|
120
119
|
})
|
|
121
120
|
atImportNode.replaceWith(newAtImportRule)
|
|
122
121
|
}
|
|
123
|
-
|
|
124
|
-
if (collectUrls) {
|
|
125
|
-
result.messages.push(urlReference)
|
|
126
|
-
}
|
|
127
122
|
},
|
|
128
123
|
},
|
|
129
124
|
Declaration: (declarationNode) => {
|
|
@@ -158,14 +153,10 @@ export const postCssPluginUrlVisitor = () => {
|
|
|
158
153
|
urlNode,
|
|
159
154
|
}
|
|
160
155
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const urlNewValue = getUrlReplacementValue(urlReference)
|
|
166
|
-
if (urlNewValue) {
|
|
156
|
+
const urlVisitorReturnValue = urlVisitor(urlReference)
|
|
157
|
+
if (urlVisitorReturnValue) {
|
|
167
158
|
urlMutations.push(() => {
|
|
168
|
-
urlNode.value =
|
|
159
|
+
urlNode.value = urlVisitorReturnValue
|
|
169
160
|
})
|
|
170
161
|
}
|
|
171
162
|
},
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertAndNormalizeDirectoryUrl,
|
|
3
|
+
urlToFileSystemPath,
|
|
4
|
+
} from "@jsenv/filesystem"
|
|
5
|
+
|
|
1
6
|
import { require } from "@jsenv/core/src/internal/require.js"
|
|
2
7
|
import { applyPostCss } from "./applyPostCss.js"
|
|
3
8
|
import { postCssPluginUrlVisitor } from "./postcss_plugin_url_visitor.js"
|
|
@@ -6,32 +11,46 @@ export const replaceCssUrls = async ({
|
|
|
6
11
|
url,
|
|
7
12
|
code,
|
|
8
13
|
map,
|
|
9
|
-
|
|
14
|
+
urlVisitor,
|
|
15
|
+
cssConcatenation = false,
|
|
16
|
+
loadCssImport,
|
|
10
17
|
cssMinification = false,
|
|
11
18
|
cssMinificationOptions,
|
|
12
19
|
} = {}) => {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
const result = await applyPostCss({
|
|
21
|
+
code,
|
|
22
|
+
url,
|
|
23
|
+
plugins: [
|
|
24
|
+
postCssPluginUrlVisitor({ urlVisitor }),
|
|
25
|
+
...(cssConcatenation
|
|
26
|
+
? [await getCssConcatenationPlugin({ url, loadCssImport })]
|
|
27
|
+
: []),
|
|
28
|
+
...(cssMinification
|
|
29
|
+
? [await getCssMinificationPlugin(cssMinificationOptions)]
|
|
30
|
+
: []),
|
|
31
|
+
],
|
|
32
|
+
})
|
|
33
|
+
code = result.code
|
|
34
|
+
map = result.map
|
|
29
35
|
return {
|
|
30
|
-
code
|
|
31
|
-
map
|
|
36
|
+
code,
|
|
37
|
+
map,
|
|
32
38
|
}
|
|
33
39
|
}
|
|
34
40
|
|
|
41
|
+
const getCssConcatenationPlugin = async ({ loadCssImport }) => {
|
|
42
|
+
const postcssImport = require("postcss-import")
|
|
43
|
+
return postcssImport({
|
|
44
|
+
resolve: (id, basedir) => {
|
|
45
|
+
const url = new URL(id, assertAndNormalizeDirectoryUrl(basedir)).href
|
|
46
|
+
return urlToFileSystemPath(url)
|
|
47
|
+
},
|
|
48
|
+
load: (id) => {
|
|
49
|
+
return loadCssImport(id)
|
|
50
|
+
},
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
35
54
|
const getCssMinificationPlugin = async (cssMinificationOptions = {}) => {
|
|
36
55
|
const cssnano = require("cssnano")
|
|
37
56
|
const cssnanoDefaultPreset = require("cssnano-preset-default")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveUrl, urlToRelativeUrl } from "@jsenv/filesystem"
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { moveCssUrls } from "@jsenv/core/src/internal/building/css/moveCssUrls.js"
|
|
4
4
|
import { escapeTemplateStringSpecialCharacters } from "@jsenv/core/src/internal/escapeTemplateStringSpecialCharacters.js"
|
|
5
5
|
import {
|
|
6
6
|
getCssSourceMappingUrl,
|
|
@@ -16,18 +16,14 @@ export const convertCssTextToJavascriptModule = async ({
|
|
|
16
16
|
const directoryUrl = resolveUrl("./", cssUrl)
|
|
17
17
|
const jsDirectoryUrl = resolveUrl("./", jsUrl)
|
|
18
18
|
if (directoryUrl !== jsDirectoryUrl) {
|
|
19
|
-
const
|
|
20
|
-
|
|
19
|
+
const moveUrlResult = await moveCssUrls({
|
|
20
|
+
from: cssUrl,
|
|
21
|
+
to: jsUrl,
|
|
21
22
|
code,
|
|
22
23
|
map,
|
|
23
|
-
getUrlReplacementValue: ({ specifier }) => {
|
|
24
|
-
const urlForCss = resolveUrl(specifier, cssUrl)
|
|
25
|
-
const urlForJs = urlToRelativeUrl(urlForCss, jsUrl)
|
|
26
|
-
return urlForJs
|
|
27
|
-
},
|
|
28
24
|
})
|
|
29
|
-
code =
|
|
30
|
-
map =
|
|
25
|
+
code = moveUrlResult.code
|
|
26
|
+
map = moveUrlResult.map
|
|
31
27
|
const sourcemapUrlSpecifier = getCssSourceMappingUrl(code)
|
|
32
28
|
const sourcemapUrlForCss = resolveUrl(sourcemapUrlSpecifier, cssUrl)
|
|
33
29
|
const sourcemapUrlForJs = urlToRelativeUrl(sourcemapUrlForCss, jsUrl)
|