@jsenv/core 29.4.5 → 29.6.0
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/script_type_module_supervisor.js +3 -2
- package/dist/js/supervisor.js +3 -2
- package/dist/main.js +196 -113
- package/package.json +2 -2
- package/src/build/build.js +100 -42
- package/src/build/build_urls_generator.js +12 -6
- package/src/build/inject_global_version_mappings.js +36 -15
- package/src/dev/start_dev_server.js +1 -1
- package/src/plugins/bundling/css/bundle_css.js +1 -1
- package/src/plugins/bundling/js_module/bundle_js_modules.js +7 -2
- package/src/plugins/importmap/jsenv_plugin_importmap.js +2 -4
- package/src/plugins/inline/jsenv_plugin_html_inline_content.js +11 -11
- package/src/plugins/plugins.js +1 -6
- package/src/plugins/ribbon/jsenv_plugin_ribbon.js +1 -5
- package/src/plugins/supervisor/client/script_type_module_supervisor.js +3 -2
- package/src/plugins/supervisor/client/supervisor.js +3 -2
- package/src/plugins/supervisor/jsenv_plugin_supervisor.js +6 -9
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_conversion.js +1 -0
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_library.js +1 -0
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +3 -0
- package/src/plugins/url_analysis/html/html_urls.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "29.
|
|
3
|
+
"version": "29.6.0",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"@c88/v8-coverage": "0.1.1",
|
|
68
68
|
"@financial-times/polyfill-useragent-normaliser": "1.10.2",
|
|
69
69
|
"@jsenv/abort": "4.2.4",
|
|
70
|
-
"@jsenv/ast": "1.4.
|
|
70
|
+
"@jsenv/ast": "1.4.4",
|
|
71
71
|
"@jsenv/babel-plugins": "1.0.9",
|
|
72
72
|
"@jsenv/filesystem": "4.1.5",
|
|
73
73
|
"@jsenv/importmap": "1.2.1",
|
package/src/build/build.js
CHANGED
|
@@ -48,6 +48,9 @@ import {
|
|
|
48
48
|
getHtmlNodeAttribute,
|
|
49
49
|
setHtmlNodeAttributes,
|
|
50
50
|
removeHtmlNode,
|
|
51
|
+
createHtmlNode,
|
|
52
|
+
insertHtmlNodeAfter,
|
|
53
|
+
findHtmlNode,
|
|
51
54
|
} from "@jsenv/ast"
|
|
52
55
|
|
|
53
56
|
import { createUrlGraph } from "../kitchen/url_graph.js"
|
|
@@ -61,7 +64,7 @@ import { jsenvPluginAsJsClassic } from "../plugins/transpilation/as_js_classic/j
|
|
|
61
64
|
import { getCorePlugins } from "../plugins/plugins.js"
|
|
62
65
|
|
|
63
66
|
import { GRAPH } from "./graph_utils.js"
|
|
64
|
-
import {
|
|
67
|
+
import { createBuildUrlsGenerator } from "./build_urls_generator.js"
|
|
65
68
|
import { injectVersionMappings } from "./inject_global_version_mappings.js"
|
|
66
69
|
import { createVersionGenerator } from "./version_generator.js"
|
|
67
70
|
|
|
@@ -90,8 +93,10 @@ export const defaultRuntimeCompat = {
|
|
|
90
93
|
* Describe entry point paths and control their names in the build directory
|
|
91
94
|
* @param {object} buildParameters.runtimeCompat
|
|
92
95
|
* Code generated will be compatible with these runtimes
|
|
93
|
-
* @param {string
|
|
94
|
-
*
|
|
96
|
+
* @param {string} [buildParameters.assetsDirectory=""]
|
|
97
|
+
* Directory where asset files will be written
|
|
98
|
+
* @param {string|url} [buildParameters.base=""]
|
|
99
|
+
* Urls in build file contents will be prefixed with this string
|
|
95
100
|
* @param {boolean|object} [buildParameters.minification=true]
|
|
96
101
|
* Minify build file contents
|
|
97
102
|
* @param {boolean} [buildParameters.versioning=true]
|
|
@@ -112,12 +117,13 @@ export const build = async ({
|
|
|
112
117
|
signal = new AbortController().signal,
|
|
113
118
|
handleSIGINT = true,
|
|
114
119
|
logLevel = "info",
|
|
120
|
+
runtimeCompat = defaultRuntimeCompat,
|
|
115
121
|
rootDirectoryUrl,
|
|
116
122
|
buildDirectoryUrl,
|
|
123
|
+
assetsDirectory = "",
|
|
124
|
+
base = runtimeCompat.node ? "./" : "/",
|
|
117
125
|
entryPoints = {},
|
|
118
|
-
baseUrl = "/",
|
|
119
126
|
|
|
120
|
-
runtimeCompat = defaultRuntimeCompat,
|
|
121
127
|
plugins = [],
|
|
122
128
|
sourcemaps = false,
|
|
123
129
|
sourcemapsSourcesContent,
|
|
@@ -127,11 +133,10 @@ export const build = async ({
|
|
|
127
133
|
directoryReferenceAllowed,
|
|
128
134
|
transpilation = {},
|
|
129
135
|
bundling = true,
|
|
130
|
-
minification =
|
|
131
|
-
versioning =
|
|
136
|
+
minification = !runtimeCompat.node,
|
|
137
|
+
versioning = !runtimeCompat.node,
|
|
132
138
|
versioningMethod = "search_param", // "filename", "search_param"
|
|
133
139
|
lineBreakNormalization = process.platform === "win32",
|
|
134
|
-
ribbon,
|
|
135
140
|
|
|
136
141
|
clientFiles = {
|
|
137
142
|
"./src/": true,
|
|
@@ -139,10 +144,10 @@ export const build = async ({
|
|
|
139
144
|
cooldownBetweenFileEvents,
|
|
140
145
|
watch = false,
|
|
141
146
|
|
|
142
|
-
|
|
147
|
+
directoryToClean,
|
|
143
148
|
writeOnFileSystem = true,
|
|
144
149
|
writeGeneratedFiles = false,
|
|
145
|
-
assetManifest =
|
|
150
|
+
assetManifest = versioningMethod === "filename",
|
|
146
151
|
assetManifestFileRelativeUrl = "asset-manifest.json",
|
|
147
152
|
}) => {
|
|
148
153
|
const operation = Abort.startOperation()
|
|
@@ -166,6 +171,36 @@ export const build = async ({
|
|
|
166
171
|
`Unexpected "versioningMethod": must be "filename", "search_param"; got ${versioning}`,
|
|
167
172
|
)
|
|
168
173
|
}
|
|
174
|
+
if (assetsDirectory && assetsDirectory[assetsDirectory.length - 1] !== "/") {
|
|
175
|
+
assetsDirectory = `${assetsDirectory}/`
|
|
176
|
+
}
|
|
177
|
+
if (directoryToClean === undefined) {
|
|
178
|
+
if (assetsDirectory === undefined) {
|
|
179
|
+
directoryToClean = buildDirectoryUrl
|
|
180
|
+
} else {
|
|
181
|
+
directoryToClean = new URL(assetsDirectory, buildDirectoryUrl).href
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const asFormattedBuildUrl = (generatedUrl, reference) => {
|
|
185
|
+
if (base === "./") {
|
|
186
|
+
const urlRelativeToParent = urlToRelativeUrl(
|
|
187
|
+
generatedUrl,
|
|
188
|
+
reference.parentUrl === rootDirectoryUrl
|
|
189
|
+
? buildDirectoryUrl
|
|
190
|
+
: reference.parentUrl,
|
|
191
|
+
)
|
|
192
|
+
if (urlRelativeToParent[0] !== ".") {
|
|
193
|
+
// ensure "./" on relative url (otherwise it could be a "bare specifier")
|
|
194
|
+
return `./${urlRelativeToParent}`
|
|
195
|
+
}
|
|
196
|
+
return urlRelativeToParent
|
|
197
|
+
}
|
|
198
|
+
const urlRelativeToBuildDirectory = urlToRelativeUrl(
|
|
199
|
+
generatedUrl,
|
|
200
|
+
buildDirectoryUrl,
|
|
201
|
+
)
|
|
202
|
+
return `${base}${urlRelativeToBuildDirectory}`
|
|
203
|
+
}
|
|
169
204
|
|
|
170
205
|
const runBuild = async ({ signal, logLevel }) => {
|
|
171
206
|
const logger = createLogger({ logLevel })
|
|
@@ -231,7 +266,6 @@ build ${entryPointKeys.length} entry points`)
|
|
|
231
266
|
},
|
|
232
267
|
minification,
|
|
233
268
|
bundling,
|
|
234
|
-
ribbon,
|
|
235
269
|
}),
|
|
236
270
|
],
|
|
237
271
|
sourcemaps,
|
|
@@ -240,8 +274,9 @@ build ${entryPointKeys.length} entry points`)
|
|
|
240
274
|
outDirectoryUrl: new URL(`.jsenv/build/`, rootDirectoryUrl),
|
|
241
275
|
})
|
|
242
276
|
|
|
243
|
-
const buildUrlsGenerator =
|
|
277
|
+
const buildUrlsGenerator = createBuildUrlsGenerator({
|
|
244
278
|
buildDirectoryUrl,
|
|
279
|
+
assetsDirectory,
|
|
245
280
|
})
|
|
246
281
|
const buildDirectoryRedirections = new Map()
|
|
247
282
|
|
|
@@ -288,8 +323,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
288
323
|
const parentRawUrl = buildDirectoryRedirections.get(
|
|
289
324
|
reference.parentUrl,
|
|
290
325
|
)
|
|
291
|
-
const
|
|
292
|
-
return new URL(reference.specifier,
|
|
326
|
+
const parentUrl = ensurePathnameTrailingSlash(parentRawUrl)
|
|
327
|
+
return new URL(reference.specifier, parentUrl).href
|
|
293
328
|
}
|
|
294
329
|
if (reference.specifier[0] === "/") {
|
|
295
330
|
return new URL(reference.specifier.slice(1), buildDirectoryUrl)
|
|
@@ -467,25 +502,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
467
502
|
generatedUrlObject.searchParams.delete("as_text_module")
|
|
468
503
|
generatedUrlObject.hash = ""
|
|
469
504
|
const generatedUrl = generatedUrlObject.href
|
|
470
|
-
|
|
471
|
-
if (baseUrl === "./") {
|
|
472
|
-
const relativeUrl = urlToRelativeUrl(
|
|
473
|
-
generatedUrl,
|
|
474
|
-
reference.parentUrl === rootDirectoryUrl
|
|
475
|
-
? buildDirectoryUrl
|
|
476
|
-
: reference.parentUrl,
|
|
477
|
-
)
|
|
478
|
-
// ensure "./" on relative url (otherwise it could be a "bare specifier")
|
|
479
|
-
specifier =
|
|
480
|
-
relativeUrl[0] === "." ? relativeUrl : `./${relativeUrl}`
|
|
481
|
-
} else {
|
|
482
|
-
// if a file is in the same directory we could prefer the relative notation
|
|
483
|
-
// but to keep things simple let's keep the "absolutely relative" to baseUrl for now
|
|
484
|
-
specifier = `${baseUrl}${urlToRelativeUrl(
|
|
485
|
-
generatedUrl,
|
|
486
|
-
buildDirectoryUrl,
|
|
487
|
-
)}`
|
|
488
|
-
}
|
|
505
|
+
const specifier = asFormattedBuildUrl(generatedUrl, reference)
|
|
489
506
|
buildUrls.set(specifier, reference.generatedUrl)
|
|
490
507
|
return specifier
|
|
491
508
|
},
|
|
@@ -592,6 +609,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
592
609
|
})
|
|
593
610
|
entryUrls.push(entryUrlInfo.url)
|
|
594
611
|
entryUrlInfo.filename = entryPoints[key]
|
|
612
|
+
entryUrlInfo.isEntryPoint = true
|
|
595
613
|
rawUrlGraphLoader.load(entryUrlInfo, { reference: entryReference })
|
|
596
614
|
})
|
|
597
615
|
await rawUrlGraphLoader.getAllLoadDonePromise(buildOperation)
|
|
@@ -740,6 +758,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
740
758
|
{
|
|
741
759
|
...rawGraphKitchen.kitchenContext,
|
|
742
760
|
buildDirectoryUrl,
|
|
761
|
+
assetsDirectory,
|
|
743
762
|
},
|
|
744
763
|
)
|
|
745
764
|
Object.keys(bundlerGeneratedUrlInfos).forEach((url) => {
|
|
@@ -789,7 +808,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
789
808
|
"bundle",
|
|
790
809
|
)
|
|
791
810
|
} else {
|
|
792
|
-
|
|
811
|
+
bundleUrlInfo.data.generatedToShareCode = true
|
|
793
812
|
}
|
|
794
813
|
} else {
|
|
795
814
|
associateBuildUrlAndRawUrl(buildUrl, url, "bundle")
|
|
@@ -1055,15 +1074,15 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1055
1074
|
const versionedUrl = versionedUrlMap.get(reference.url)
|
|
1056
1075
|
if (!versionedUrl) {
|
|
1057
1076
|
// happens for sourcemap
|
|
1058
|
-
return
|
|
1077
|
+
return urlToRelativeUrl(
|
|
1059
1078
|
referencedUrlInfo.url,
|
|
1060
|
-
|
|
1061
|
-
)
|
|
1079
|
+
reference.parentUrl,
|
|
1080
|
+
)
|
|
1062
1081
|
}
|
|
1063
|
-
const versionedSpecifier =
|
|
1082
|
+
const versionedSpecifier = asFormattedBuildUrl(
|
|
1064
1083
|
versionedUrl,
|
|
1065
|
-
|
|
1066
|
-
)
|
|
1084
|
+
reference,
|
|
1085
|
+
)
|
|
1067
1086
|
versionMappings[reference.specifier] = versionedSpecifier
|
|
1068
1087
|
versioningRedirections.set(reference.url, versionedUrl)
|
|
1069
1088
|
buildUrls.set(versionedSpecifier, versionedUrl)
|
|
@@ -1149,6 +1168,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1149
1168
|
urlInfo,
|
|
1150
1169
|
kitchen: finalGraphKitchen,
|
|
1151
1170
|
versionMappings: versionMappingsNeeded,
|
|
1171
|
+
minification,
|
|
1152
1172
|
})
|
|
1153
1173
|
})
|
|
1154
1174
|
}
|
|
@@ -1196,6 +1216,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1196
1216
|
storeOriginalPositions: false,
|
|
1197
1217
|
})
|
|
1198
1218
|
const mutations = []
|
|
1219
|
+
const hintsToInject = {}
|
|
1199
1220
|
visitHtmlNodes(htmlAst, {
|
|
1200
1221
|
link: (node) => {
|
|
1201
1222
|
const href = getHtmlNodeAttribute(node, "href")
|
|
@@ -1247,6 +1268,13 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1247
1268
|
href: buildSpecifierBeforeRedirect,
|
|
1248
1269
|
})
|
|
1249
1270
|
})
|
|
1271
|
+
for (const dependencyUrl of buildUrlInfo.dependencies) {
|
|
1272
|
+
const dependencyUrlInfo =
|
|
1273
|
+
finalGraph.urlInfoMap.get(dependencyUrl)
|
|
1274
|
+
if (dependencyUrlInfo.data.generatedToShareCode) {
|
|
1275
|
+
hintsToInject[dependencyUrl] = node
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1250
1278
|
}
|
|
1251
1279
|
if (href.startsWith("file:")) {
|
|
1252
1280
|
let url = href
|
|
@@ -1271,6 +1299,36 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1271
1299
|
}
|
|
1272
1300
|
},
|
|
1273
1301
|
})
|
|
1302
|
+
Object.keys(hintsToInject).forEach((urlToHint) => {
|
|
1303
|
+
const hintNode = hintsToInject[urlToHint]
|
|
1304
|
+
const urlFormatted =
|
|
1305
|
+
versioningRedirections.get(urlToHint) || urlToHint
|
|
1306
|
+
const specifierBeforeRedirect = findKey(buildUrls, urlFormatted)
|
|
1307
|
+
const found = findHtmlNode(htmlAst, (htmlNode) => {
|
|
1308
|
+
return (
|
|
1309
|
+
htmlNode.nodeName === "link" &&
|
|
1310
|
+
getHtmlNodeAttribute(htmlNode, "href") ===
|
|
1311
|
+
specifierBeforeRedirect
|
|
1312
|
+
)
|
|
1313
|
+
})
|
|
1314
|
+
if (!found) {
|
|
1315
|
+
mutations.push(() => {
|
|
1316
|
+
const nodeToInsert = createHtmlNode({
|
|
1317
|
+
tagName: "link",
|
|
1318
|
+
href: specifierBeforeRedirect,
|
|
1319
|
+
rel: getHtmlNodeAttribute(hintNode, "rel"),
|
|
1320
|
+
as: getHtmlNodeAttribute(hintNode, "as"),
|
|
1321
|
+
type: getHtmlNodeAttribute(hintNode, "type"),
|
|
1322
|
+
crossorigin: getHtmlNodeAttribute(hintNode, "crossorigin"),
|
|
1323
|
+
})
|
|
1324
|
+
insertHtmlNodeAfter(
|
|
1325
|
+
nodeToInsert,
|
|
1326
|
+
hintNode.parentNode,
|
|
1327
|
+
hintNode,
|
|
1328
|
+
)
|
|
1329
|
+
})
|
|
1330
|
+
}
|
|
1331
|
+
})
|
|
1274
1332
|
if (mutations.length > 0) {
|
|
1275
1333
|
mutations.forEach((mutation) => mutation())
|
|
1276
1334
|
await finalGraphKitchen.urlInfoTransformer.applyFinalTransformations(
|
|
@@ -1407,8 +1465,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1407
1465
|
}
|
|
1408
1466
|
})
|
|
1409
1467
|
if (writeOnFileSystem) {
|
|
1410
|
-
if (
|
|
1411
|
-
await ensureEmptyDirectory(
|
|
1468
|
+
if (directoryToClean) {
|
|
1469
|
+
await ensureEmptyDirectory(directoryToClean)
|
|
1412
1470
|
}
|
|
1413
1471
|
const buildRelativeUrls = Object.keys(buildFileContents)
|
|
1414
1472
|
buildRelativeUrls.forEach((buildRelativeUrl) => {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { urlToFilename, urlToRelativeUrl } from "@jsenv/urls"
|
|
2
2
|
import { memoizeByFirstArgument } from "@jsenv/utils/src/memoize/memoize_by_first_argument.js"
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const createBuildUrlsGenerator = ({
|
|
5
|
+
buildDirectoryUrl,
|
|
6
|
+
assetsDirectory,
|
|
7
|
+
}) => {
|
|
5
8
|
const cache = {}
|
|
6
9
|
|
|
7
10
|
const getUrlName = (url, urlInfo) => {
|
|
@@ -17,6 +20,7 @@ export const createBuilUrlsGenerator = ({ buildDirectoryUrl }) => {
|
|
|
17
20
|
const generate = memoizeByFirstArgument((url, { urlInfo, parentUrlInfo }) => {
|
|
18
21
|
const directoryPath = determineDirectoryPath({
|
|
19
22
|
buildDirectoryUrl,
|
|
23
|
+
assetsDirectory,
|
|
20
24
|
urlInfo,
|
|
21
25
|
parentUrlInfo,
|
|
22
26
|
})
|
|
@@ -71,6 +75,7 @@ const splitFileExtension = (filename) => {
|
|
|
71
75
|
|
|
72
76
|
const determineDirectoryPath = ({
|
|
73
77
|
buildDirectoryUrl,
|
|
78
|
+
assetsDirectory,
|
|
74
79
|
urlInfo,
|
|
75
80
|
parentUrlInfo,
|
|
76
81
|
}) => {
|
|
@@ -87,6 +92,7 @@ const determineDirectoryPath = ({
|
|
|
87
92
|
if (urlInfo.isInline) {
|
|
88
93
|
const parentDirectoryPath = determineDirectoryPath({
|
|
89
94
|
buildDirectoryUrl,
|
|
95
|
+
assetsDirectory,
|
|
90
96
|
urlInfo: parentUrlInfo,
|
|
91
97
|
})
|
|
92
98
|
return parentDirectoryPath
|
|
@@ -98,16 +104,16 @@ const determineDirectoryPath = ({
|
|
|
98
104
|
return ""
|
|
99
105
|
}
|
|
100
106
|
if (urlInfo.type === "html") {
|
|
101
|
-
return
|
|
107
|
+
return `${assetsDirectory}html/`
|
|
102
108
|
}
|
|
103
109
|
if (urlInfo.type === "css") {
|
|
104
|
-
return
|
|
110
|
+
return `${assetsDirectory}css/`
|
|
105
111
|
}
|
|
106
112
|
if (urlInfo.type === "js_module" || urlInfo.type === "js_classic") {
|
|
107
|
-
return
|
|
113
|
+
return `${assetsDirectory}js/`
|
|
108
114
|
}
|
|
109
115
|
if (urlInfo.type === "json") {
|
|
110
|
-
return
|
|
116
|
+
return `${assetsDirectory}json/`
|
|
111
117
|
}
|
|
112
|
-
return
|
|
118
|
+
return `${assetsDirectory}other/`
|
|
113
119
|
}
|
|
@@ -14,10 +14,14 @@ export const injectVersionMappings = async ({
|
|
|
14
14
|
urlInfo,
|
|
15
15
|
kitchen,
|
|
16
16
|
versionMappings,
|
|
17
|
+
minification,
|
|
17
18
|
}) => {
|
|
18
19
|
const injector = injectors[urlInfo.type]
|
|
19
20
|
if (injector) {
|
|
20
|
-
const { content, sourcemap } = await injector(urlInfo, {
|
|
21
|
+
const { content, sourcemap } = await injector(urlInfo, {
|
|
22
|
+
versionMappings,
|
|
23
|
+
minification,
|
|
24
|
+
})
|
|
21
25
|
kitchen.urlInfoTransformer.applyFinalTransformations(urlInfo, {
|
|
22
26
|
content,
|
|
23
27
|
sourcemap,
|
|
@@ -25,18 +29,8 @@ export const injectVersionMappings = async ({
|
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
const jsInjector = (urlInfo, { versionMappings }) => {
|
|
29
|
-
const magicSource = createMagicSource(urlInfo.content)
|
|
30
|
-
magicSource.prepend(
|
|
31
|
-
generateClientCodeForVersionMappings(versionMappings, {
|
|
32
|
-
globalName: isWebWorkerUrlInfo(urlInfo) ? "self" : "window",
|
|
33
|
-
}),
|
|
34
|
-
)
|
|
35
|
-
return magicSource.toContentAndSourcemap()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
32
|
const injectors = {
|
|
39
|
-
html: (urlInfo, { versionMappings }) => {
|
|
33
|
+
html: (urlInfo, { versionMappings, minification }) => {
|
|
40
34
|
// ideally we would inject an importmap but browser support is too low
|
|
41
35
|
// (even worse for worker/service worker)
|
|
42
36
|
// so for now we inject code into entry points
|
|
@@ -49,6 +43,7 @@ const injectors = {
|
|
|
49
43
|
tagName: "script",
|
|
50
44
|
textContent: generateClientCodeForVersionMappings(versionMappings, {
|
|
51
45
|
globalName: "window",
|
|
46
|
+
minify: minification || minification.js_classic,
|
|
52
47
|
}),
|
|
53
48
|
}),
|
|
54
49
|
"jsenv:versioning",
|
|
@@ -57,14 +52,40 @@ const injectors = {
|
|
|
57
52
|
content: stringifyHtmlAst(htmlAst),
|
|
58
53
|
}
|
|
59
54
|
},
|
|
60
|
-
js_classic:
|
|
61
|
-
|
|
55
|
+
js_classic: (urlInfo, { versionMappings, minification }) => {
|
|
56
|
+
return jsInjector(urlInfo, {
|
|
57
|
+
versionMappings,
|
|
58
|
+
minify: minification || minification.js_classic,
|
|
59
|
+
})
|
|
60
|
+
},
|
|
61
|
+
js_module: (urlInfo, { versionMappings, minification }) => {
|
|
62
|
+
return jsInjector(urlInfo, {
|
|
63
|
+
versionMappings,
|
|
64
|
+
minify: minification || minification.js_module,
|
|
65
|
+
})
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const jsInjector = (urlInfo, { versionMappings, minify }) => {
|
|
70
|
+
const magicSource = createMagicSource(urlInfo.content)
|
|
71
|
+
magicSource.prepend(
|
|
72
|
+
generateClientCodeForVersionMappings(versionMappings, {
|
|
73
|
+
globalName: isWebWorkerUrlInfo(urlInfo) ? "self" : "window",
|
|
74
|
+
minify,
|
|
75
|
+
}),
|
|
76
|
+
)
|
|
77
|
+
return magicSource.toContentAndSourcemap()
|
|
62
78
|
}
|
|
63
79
|
|
|
64
80
|
const generateClientCodeForVersionMappings = (
|
|
65
81
|
versionMappings,
|
|
66
|
-
{ globalName },
|
|
82
|
+
{ globalName, minify },
|
|
67
83
|
) => {
|
|
84
|
+
if (minify) {
|
|
85
|
+
return `;(function(){var m = ${JSON.stringify(
|
|
86
|
+
versionMappings,
|
|
87
|
+
)}; ${globalName}.__v__ = function (s) { return m[s] || s }; })();`
|
|
88
|
+
}
|
|
68
89
|
return `
|
|
69
90
|
;(function() {
|
|
70
91
|
|
|
@@ -21,7 +21,7 @@ export const bundleCss = async ({ cssUrlInfos, context }) => {
|
|
|
21
21
|
cssUrlInfos.forEach((cssUrlInfo) => {
|
|
22
22
|
bundledCssUrlInfos[cssUrlInfo.url] = {
|
|
23
23
|
data: {
|
|
24
|
-
|
|
24
|
+
bundlerName: "parcel",
|
|
25
25
|
},
|
|
26
26
|
contentType: "text/css",
|
|
27
27
|
content: cssBundleInfos[cssUrlInfo.url].bundleContent,
|
|
@@ -31,6 +31,7 @@ export const bundleJsModules = async ({
|
|
|
31
31
|
logger,
|
|
32
32
|
rootDirectoryUrl,
|
|
33
33
|
buildDirectoryUrl,
|
|
34
|
+
assetsDirectory,
|
|
34
35
|
urlGraph,
|
|
35
36
|
runtimeCompat,
|
|
36
37
|
sourcemaps,
|
|
@@ -46,6 +47,7 @@ export const bundleJsModules = async ({
|
|
|
46
47
|
logger,
|
|
47
48
|
rootDirectoryUrl,
|
|
48
49
|
buildDirectoryUrl,
|
|
50
|
+
assetsDirectory,
|
|
49
51
|
urlGraph,
|
|
50
52
|
jsModuleUrlInfos,
|
|
51
53
|
|
|
@@ -64,6 +66,7 @@ const rollupPluginJsenv = ({
|
|
|
64
66
|
// logger,
|
|
65
67
|
rootDirectoryUrl,
|
|
66
68
|
buildDirectoryUrl,
|
|
69
|
+
assetsDirectory,
|
|
67
70
|
urlGraph,
|
|
68
71
|
jsModuleUrlInfos,
|
|
69
72
|
sourcemaps,
|
|
@@ -159,7 +162,7 @@ const rollupPluginJsenv = ({
|
|
|
159
162
|
originalUrl,
|
|
160
163
|
type: format === "esm" ? "js_module" : "common_js",
|
|
161
164
|
data: {
|
|
162
|
-
|
|
165
|
+
bundlerName: "rollup",
|
|
163
166
|
bundleRelativeUrl: rollupFileInfo.fileName,
|
|
164
167
|
usesImport:
|
|
165
168
|
rollupFileInfo.imports.length > 0 ||
|
|
@@ -208,7 +211,7 @@ const rollupPluginJsenv = ({
|
|
|
208
211
|
}
|
|
209
212
|
}
|
|
210
213
|
const name = nameFromUrlInfo || `${chunkInfo.name}.js`
|
|
211
|
-
return insideJs ?
|
|
214
|
+
return insideJs ? `${assetsDirectory}js/${name}` : `${name}`
|
|
212
215
|
},
|
|
213
216
|
manualChunks: (id) => {
|
|
214
217
|
if (babelHelpersChunk) {
|
|
@@ -307,6 +310,7 @@ const buildWithRollup = async ({
|
|
|
307
310
|
logger,
|
|
308
311
|
rootDirectoryUrl,
|
|
309
312
|
buildDirectoryUrl,
|
|
313
|
+
assetsDirectory,
|
|
310
314
|
urlGraph,
|
|
311
315
|
jsModuleUrlInfos,
|
|
312
316
|
|
|
@@ -326,6 +330,7 @@ const buildWithRollup = async ({
|
|
|
326
330
|
logger,
|
|
327
331
|
rootDirectoryUrl,
|
|
328
332
|
buildDirectoryUrl,
|
|
333
|
+
assetsDirectory,
|
|
329
334
|
urlGraph,
|
|
330
335
|
jsModuleUrlInfos,
|
|
331
336
|
|
|
@@ -134,8 +134,7 @@ export const jsenvPluginImportmap = () => {
|
|
|
134
134
|
})
|
|
135
135
|
setHtmlNodeText(importmap, inlineImportmapUrlInfo.content)
|
|
136
136
|
setHtmlNodeAttributes(importmap, {
|
|
137
|
-
"jsenv-
|
|
138
|
-
"jsenv-plugin-action": "content_cooked",
|
|
137
|
+
"jsenv-cooked-by": "jsenv:importmap",
|
|
139
138
|
})
|
|
140
139
|
onHtmlImportmapParsed(
|
|
141
140
|
JSON.parse(inlineImportmapUrlInfo.content),
|
|
@@ -164,8 +163,7 @@ export const jsenvPluginImportmap = () => {
|
|
|
164
163
|
setHtmlNodeText(importmap, importmapUrlInfo.content)
|
|
165
164
|
setHtmlNodeAttributes(importmap, {
|
|
166
165
|
"src": undefined,
|
|
167
|
-
"jsenv-
|
|
168
|
-
"jsenv-plugin-action": "inlined",
|
|
166
|
+
"jsenv-inlined-by": "jsenv:importmap",
|
|
169
167
|
"inlined-from-src": src,
|
|
170
168
|
})
|
|
171
169
|
|
|
@@ -65,8 +65,7 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
|
65
65
|
mutations.push(() => {
|
|
66
66
|
setHtmlNodeText(styleNode, inlineStyleUrlInfo.content)
|
|
67
67
|
setHtmlNodeAttributes(styleNode, {
|
|
68
|
-
"jsenv-
|
|
69
|
-
"jsenv-plugin-action": "content_cooked",
|
|
68
|
+
"jsenv-cooked-by": "jsenv:html_inline_content",
|
|
70
69
|
})
|
|
71
70
|
})
|
|
72
71
|
},
|
|
@@ -78,17 +77,19 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
|
78
77
|
// If the inline script was already handled by an other plugin, ignore it
|
|
79
78
|
// - we want to preserve inline scripts generated by html supervisor during dev
|
|
80
79
|
// - we want to avoid cooking twice a script during build
|
|
81
|
-
const jsenvPluginOwner = getHtmlNodeAttribute(
|
|
82
|
-
scriptNode,
|
|
83
|
-
"jsenv-plugin-owner",
|
|
84
|
-
)
|
|
85
80
|
if (
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
!analyzeConvertedScripts &&
|
|
82
|
+
getHtmlNodeAttribute(scriptNode, "jsenv-injected-by") ===
|
|
83
|
+
"jsenv:as_js_classic_html"
|
|
88
84
|
) {
|
|
89
85
|
return
|
|
90
86
|
}
|
|
91
|
-
if (
|
|
87
|
+
if (
|
|
88
|
+
getHtmlNodeAttribute(scriptNode, "jsenv-cooked-by") ===
|
|
89
|
+
"jsenv:supervisor" ||
|
|
90
|
+
getHtmlNodeAttribute(scriptNode, "jsenv-injected-by") ===
|
|
91
|
+
"jsenv:supervisor"
|
|
92
|
+
) {
|
|
92
93
|
return
|
|
93
94
|
}
|
|
94
95
|
const { type, contentType, extension } =
|
|
@@ -131,8 +132,7 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
|
|
|
131
132
|
mutations.push(() => {
|
|
132
133
|
setHtmlNodeText(scriptNode, inlineScriptUrlInfo.content)
|
|
133
134
|
setHtmlNodeAttributes(scriptNode, {
|
|
134
|
-
"jsenv-
|
|
135
|
-
"jsenv-plugin-action": "content_cooked",
|
|
135
|
+
"jsenv-cooked-by": "jsenv:html_inline_content",
|
|
136
136
|
...(extension
|
|
137
137
|
? { type: type === "js_module" ? "module" : undefined }
|
|
138
138
|
: {}),
|
package/src/plugins/plugins.js
CHANGED
|
@@ -43,7 +43,7 @@ export const getCorePlugins = ({
|
|
|
43
43
|
clientFileChangeCallbackList,
|
|
44
44
|
clientFilesPruneCallbackList,
|
|
45
45
|
explorer,
|
|
46
|
-
ribbon =
|
|
46
|
+
ribbon = true,
|
|
47
47
|
} = {}) => {
|
|
48
48
|
if (explorer === true) {
|
|
49
49
|
explorer = {}
|
|
@@ -67,11 +67,6 @@ export const getCorePlugins = ({
|
|
|
67
67
|
if (ribbon === true) {
|
|
68
68
|
ribbon = {}
|
|
69
69
|
}
|
|
70
|
-
if (ribbon === "dev_and_build") {
|
|
71
|
-
ribbon = {
|
|
72
|
-
devAndBuild: true,
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
70
|
|
|
76
71
|
return [
|
|
77
72
|
jsenvPluginUrlAnalysis({ rootDirectoryUrl, ...urlAnalysis }),
|
|
@@ -10,7 +10,6 @@ import { asUrlWithoutSearch } from "@jsenv/urls"
|
|
|
10
10
|
export const jsenvPluginRibbon = ({
|
|
11
11
|
rootDirectoryUrl,
|
|
12
12
|
htmlInclude = "**/*.html",
|
|
13
|
-
devAndBuild = false,
|
|
14
13
|
}) => {
|
|
15
14
|
const ribbonClientFileUrl = new URL("./client/ribbon.js", import.meta.url)
|
|
16
15
|
const associations = URL_META.resolveAssociations(
|
|
@@ -21,12 +20,9 @@ export const jsenvPluginRibbon = ({
|
|
|
21
20
|
)
|
|
22
21
|
return {
|
|
23
22
|
name: "jsenv:ribbon",
|
|
24
|
-
appliesDuring: "
|
|
23
|
+
appliesDuring: "dev",
|
|
25
24
|
transformUrlContent: {
|
|
26
25
|
html: (urlInfo, context) => {
|
|
27
|
-
if (context.scenarios.build && !devAndBuild) {
|
|
28
|
-
return null
|
|
29
|
-
}
|
|
30
26
|
const { ribbon } = URL_META.applyAssociations({
|
|
31
27
|
url: asUrlWithoutSearch(urlInfo.url),
|
|
32
28
|
associations,
|
|
@@ -36,8 +36,9 @@ const createExecuteWithScript = ({ currentScript, src }) => {
|
|
|
36
36
|
nodeToReplace = currentScriptClone
|
|
37
37
|
currentScriptClone.src = urlObject.href
|
|
38
38
|
} else {
|
|
39
|
-
currentScriptClone.removeAttribute("jsenv-
|
|
40
|
-
currentScriptClone.removeAttribute("jsenv-
|
|
39
|
+
currentScriptClone.removeAttribute("jsenv-cooked-by")
|
|
40
|
+
currentScriptClone.removeAttribute("jsenv-inlined-by")
|
|
41
|
+
currentScriptClone.removeAttribute("jsenv-injected-by")
|
|
41
42
|
currentScriptClone.removeAttribute("inlined-from-src")
|
|
42
43
|
currentScriptClone.removeAttribute("original-position")
|
|
43
44
|
currentScriptClone.removeAttribute("original-src-position")
|
|
@@ -885,8 +885,9 @@ window.__supervisor__ = (() => {
|
|
|
885
885
|
nodeToReplace = currentScriptClone
|
|
886
886
|
currentScriptClone.src = urlObject.href
|
|
887
887
|
} else {
|
|
888
|
-
currentScriptClone.removeAttribute("jsenv-
|
|
889
|
-
currentScriptClone.removeAttribute("jsenv-
|
|
888
|
+
currentScriptClone.removeAttribute("jsenv-cooked-by")
|
|
889
|
+
currentScriptClone.removeAttribute("jsenv-inlined-by")
|
|
890
|
+
currentScriptClone.removeAttribute("jsenv-injected-by")
|
|
890
891
|
currentScriptClone.removeAttribute("inlined-from-src")
|
|
891
892
|
currentScriptClone.removeAttribute("original-position")
|
|
892
893
|
currentScriptClone.removeAttribute("original-src-position")
|