@jsenv/core 29.4.4 → 29.5.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/babel_helpers/wrapRegExp/wrapRegExp.js +16 -3
- package/dist/js/ws.js +10 -10
- package/dist/main.js +124 -70
- package/package.json +8 -8
- package/src/build/build.js +58 -41
- 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/js_module/bundle_js_modules.js +6 -1
- package/src/plugins/plugins.js +1 -6
- package/src/plugins/ribbon/jsenv_plugin_ribbon.js +1 -5
|
@@ -15,14 +15,19 @@ export default function _wrapRegExp() {
|
|
|
15
15
|
inherits(BabelRegExp, RegExp);
|
|
16
16
|
BabelRegExp.prototype.exec = function (str) {
|
|
17
17
|
var result = _super.exec.call(this, str);
|
|
18
|
-
if (result)
|
|
18
|
+
if (result) {
|
|
19
|
+
result.groups = buildGroups(result, this);
|
|
20
|
+
var indices = result.indices;
|
|
21
|
+
if (indices) indices.groups = buildGroups(indices, this);
|
|
22
|
+
}
|
|
19
23
|
return result;
|
|
20
24
|
};
|
|
21
25
|
BabelRegExp.prototype[Symbol.replace] = function (str, substitution) {
|
|
22
26
|
if (typeof substitution === "string") {
|
|
23
27
|
var groups = _groups.get(this);
|
|
24
28
|
return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) {
|
|
25
|
-
|
|
29
|
+
var group = groups[name];
|
|
30
|
+
return "$" + (Array.isArray(group) ? group.join("$") : group);
|
|
26
31
|
}));
|
|
27
32
|
} else if (typeof substitution === "function") {
|
|
28
33
|
var _this = this;
|
|
@@ -45,7 +50,15 @@ export default function _wrapRegExp() {
|
|
|
45
50
|
|
|
46
51
|
var g = _groups.get(re);
|
|
47
52
|
return Object.keys(g).reduce(function (groups, name) {
|
|
48
|
-
|
|
53
|
+
var i = g[name];
|
|
54
|
+
if (typeof i === "number") groups[name] = result[i];else {
|
|
55
|
+
// i is an array of indexes
|
|
56
|
+
var k = 0;
|
|
57
|
+
// if no group matched, we stop at k = i.length - 1 and then
|
|
58
|
+
// we store result[i[i.length - 1]] which is undefined.
|
|
59
|
+
while (result[i[k]] === undefined && k + 1 < i.length) k++;
|
|
60
|
+
groups[name] = result[i[k]];
|
|
61
|
+
}
|
|
49
62
|
return groups;
|
|
50
63
|
}, Object.create(null));
|
|
51
64
|
}
|
package/dist/js/ws.js
CHANGED
|
@@ -283,7 +283,7 @@ const kRun = Symbol('kRun');
|
|
|
283
283
|
* A very simple job queue with adjustable concurrency. Adapted from
|
|
284
284
|
* https://github.com/STRML/async-limiter
|
|
285
285
|
*/
|
|
286
|
-
|
|
286
|
+
let Limiter$1 = class Limiter {
|
|
287
287
|
/**
|
|
288
288
|
* Creates a new `Limiter`.
|
|
289
289
|
*
|
|
@@ -324,7 +324,7 @@ class Limiter$1 {
|
|
|
324
324
|
job(this[kDone]);
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
-
}
|
|
327
|
+
};
|
|
328
328
|
var limiter = Limiter$1;
|
|
329
329
|
const zlib = require$$0$1;
|
|
330
330
|
const bufferUtil = bufferUtil$1.exports;
|
|
@@ -351,7 +351,7 @@ let zlibLimiter;
|
|
|
351
351
|
/**
|
|
352
352
|
* permessage-deflate implementation.
|
|
353
353
|
*/
|
|
354
|
-
|
|
354
|
+
let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
355
355
|
/**
|
|
356
356
|
* Creates a PerMessageDeflate instance.
|
|
357
357
|
*
|
|
@@ -685,7 +685,7 @@ class PerMessageDeflate$4 {
|
|
|
685
685
|
callback(null, data);
|
|
686
686
|
});
|
|
687
687
|
}
|
|
688
|
-
}
|
|
688
|
+
};
|
|
689
689
|
var permessageDeflate = PerMessageDeflate$4;
|
|
690
690
|
|
|
691
691
|
/**
|
|
@@ -873,7 +873,7 @@ const INFLATING = 5;
|
|
|
873
873
|
*
|
|
874
874
|
* @extends Writable
|
|
875
875
|
*/
|
|
876
|
-
|
|
876
|
+
let Receiver$1 = class Receiver extends Writable {
|
|
877
877
|
/**
|
|
878
878
|
* Creates a Receiver instance.
|
|
879
879
|
*
|
|
@@ -1264,7 +1264,7 @@ class Receiver$1 extends Writable {
|
|
|
1264
1264
|
}
|
|
1265
1265
|
this._state = GET_INFO;
|
|
1266
1266
|
}
|
|
1267
|
-
}
|
|
1267
|
+
};
|
|
1268
1268
|
var receiver = Receiver$1;
|
|
1269
1269
|
|
|
1270
1270
|
/**
|
|
@@ -1308,7 +1308,7 @@ const maskBuffer = Buffer.alloc(4);
|
|
|
1308
1308
|
/**
|
|
1309
1309
|
* HyBi Sender implementation.
|
|
1310
1310
|
*/
|
|
1311
|
-
|
|
1311
|
+
let Sender$1 = class Sender {
|
|
1312
1312
|
/**
|
|
1313
1313
|
* Creates a Sender instance.
|
|
1314
1314
|
*
|
|
@@ -1700,7 +1700,7 @@ class Sender$1 {
|
|
|
1700
1700
|
this._socket.write(list[0], cb);
|
|
1701
1701
|
}
|
|
1702
1702
|
}
|
|
1703
|
-
}
|
|
1703
|
+
};
|
|
1704
1704
|
var sender = Sender$1;
|
|
1705
1705
|
const {
|
|
1706
1706
|
kForOnEventAttribute: kForOnEventAttribute$1,
|
|
@@ -2199,7 +2199,7 @@ const subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
|
2199
2199
|
*
|
|
2200
2200
|
* @extends EventEmitter
|
|
2201
2201
|
*/
|
|
2202
|
-
|
|
2202
|
+
let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
2203
2203
|
/**
|
|
2204
2204
|
* Create a new `WebSocket`.
|
|
2205
2205
|
*
|
|
@@ -2590,7 +2590,7 @@ class WebSocket$1 extends EventEmitter$1 {
|
|
|
2590
2590
|
this._socket.destroy();
|
|
2591
2591
|
}
|
|
2592
2592
|
}
|
|
2593
|
-
}
|
|
2593
|
+
};
|
|
2594
2594
|
|
|
2595
2595
|
/**
|
|
2596
2596
|
* @constant {Number} CONNECTING
|
package/dist/main.js
CHANGED
|
@@ -8579,8 +8579,18 @@ const analyzeUrlNodeType = (secondArgNode, {
|
|
|
8579
8579
|
if (!isJsModule && isContextMetaUrlFromSystemJs(secondArgNode)) {
|
|
8580
8580
|
return "context.meta.url";
|
|
8581
8581
|
}
|
|
8582
|
-
if (!isJsModule
|
|
8583
|
-
|
|
8582
|
+
if (!isJsModule) {
|
|
8583
|
+
if (isDocumentCurrentScriptSrc(secondArgNode)) {
|
|
8584
|
+
return "document.currentScript.src";
|
|
8585
|
+
}
|
|
8586
|
+
// new URL('specifier', document.currentScript.src)
|
|
8587
|
+
// becomes
|
|
8588
|
+
// var _currentUrl = document.currentScript.src
|
|
8589
|
+
// new URL('specifier', currentUrl)
|
|
8590
|
+
// (search for scope.generateUidIdentifier("currentUrl")
|
|
8591
|
+
if (secondArgNode.type === "Identifier") {
|
|
8592
|
+
return "document.currentScript.src";
|
|
8593
|
+
}
|
|
8584
8594
|
}
|
|
8585
8595
|
return null;
|
|
8586
8596
|
};
|
|
@@ -16812,6 +16822,7 @@ const bundleJsModules = async ({
|
|
|
16812
16822
|
logger,
|
|
16813
16823
|
rootDirectoryUrl,
|
|
16814
16824
|
buildDirectoryUrl,
|
|
16825
|
+
assetsDirectory,
|
|
16815
16826
|
urlGraph,
|
|
16816
16827
|
runtimeCompat,
|
|
16817
16828
|
sourcemaps
|
|
@@ -16829,6 +16840,7 @@ const bundleJsModules = async ({
|
|
|
16829
16840
|
logger,
|
|
16830
16841
|
rootDirectoryUrl,
|
|
16831
16842
|
buildDirectoryUrl,
|
|
16843
|
+
assetsDirectory,
|
|
16832
16844
|
urlGraph,
|
|
16833
16845
|
jsModuleUrlInfos,
|
|
16834
16846
|
runtimeCompat,
|
|
@@ -16844,6 +16856,7 @@ const rollupPluginJsenv = ({
|
|
|
16844
16856
|
// logger,
|
|
16845
16857
|
rootDirectoryUrl,
|
|
16846
16858
|
buildDirectoryUrl,
|
|
16859
|
+
assetsDirectory,
|
|
16847
16860
|
urlGraph,
|
|
16848
16861
|
jsModuleUrlInfos,
|
|
16849
16862
|
sourcemaps,
|
|
@@ -16968,7 +16981,7 @@ const rollupPluginJsenv = ({
|
|
|
16968
16981
|
}
|
|
16969
16982
|
}
|
|
16970
16983
|
const name = nameFromUrlInfo || `${chunkInfo.name}.js`;
|
|
16971
|
-
return insideJs ?
|
|
16984
|
+
return insideJs ? `${assetsDirectory}js/${name}` : `${name}`;
|
|
16972
16985
|
},
|
|
16973
16986
|
manualChunks: id => {
|
|
16974
16987
|
if (babelHelpersChunk) {
|
|
@@ -17076,6 +17089,7 @@ const buildWithRollup = async ({
|
|
|
17076
17089
|
logger,
|
|
17077
17090
|
rootDirectoryUrl,
|
|
17078
17091
|
buildDirectoryUrl,
|
|
17092
|
+
assetsDirectory,
|
|
17079
17093
|
urlGraph,
|
|
17080
17094
|
jsModuleUrlInfos,
|
|
17081
17095
|
runtimeCompat,
|
|
@@ -17094,6 +17108,7 @@ const buildWithRollup = async ({
|
|
|
17094
17108
|
logger,
|
|
17095
17109
|
rootDirectoryUrl,
|
|
17096
17110
|
buildDirectoryUrl,
|
|
17111
|
+
assetsDirectory,
|
|
17097
17112
|
urlGraph,
|
|
17098
17113
|
jsModuleUrlInfos,
|
|
17099
17114
|
runtimeCompat,
|
|
@@ -22444,8 +22459,7 @@ const jsenvPluginExplorer = ({
|
|
|
22444
22459
|
|
|
22445
22460
|
const jsenvPluginRibbon = ({
|
|
22446
22461
|
rootDirectoryUrl,
|
|
22447
|
-
htmlInclude = "**/*.html"
|
|
22448
|
-
devAndBuild = false
|
|
22462
|
+
htmlInclude = "**/*.html"
|
|
22449
22463
|
}) => {
|
|
22450
22464
|
const ribbonClientFileUrl = new URL("./js/ribbon.js", import.meta.url);
|
|
22451
22465
|
const associations = URL_META.resolveAssociations({
|
|
@@ -22455,12 +22469,9 @@ const jsenvPluginRibbon = ({
|
|
|
22455
22469
|
}, rootDirectoryUrl);
|
|
22456
22470
|
return {
|
|
22457
22471
|
name: "jsenv:ribbon",
|
|
22458
|
-
appliesDuring: "
|
|
22472
|
+
appliesDuring: "dev",
|
|
22459
22473
|
transformUrlContent: {
|
|
22460
22474
|
html: (urlInfo, context) => {
|
|
22461
|
-
if (context.scenarios.build && !devAndBuild) {
|
|
22462
|
-
return null;
|
|
22463
|
-
}
|
|
22464
22475
|
const {
|
|
22465
22476
|
ribbon
|
|
22466
22477
|
} = URL_META.applyAssociations({
|
|
@@ -22511,7 +22522,7 @@ const getCorePlugins = ({
|
|
|
22511
22522
|
clientFileChangeCallbackList,
|
|
22512
22523
|
clientFilesPruneCallbackList,
|
|
22513
22524
|
explorer,
|
|
22514
|
-
ribbon =
|
|
22525
|
+
ribbon = true
|
|
22515
22526
|
} = {}) => {
|
|
22516
22527
|
if (explorer === true) {
|
|
22517
22528
|
explorer = {};
|
|
@@ -22533,11 +22544,6 @@ const getCorePlugins = ({
|
|
|
22533
22544
|
if (ribbon === true) {
|
|
22534
22545
|
ribbon = {};
|
|
22535
22546
|
}
|
|
22536
|
-
if (ribbon === "dev_and_build") {
|
|
22537
|
-
ribbon = {
|
|
22538
|
-
devAndBuild: true
|
|
22539
|
-
};
|
|
22540
|
-
}
|
|
22541
22547
|
return [jsenvPluginUrlAnalysis({
|
|
22542
22548
|
rootDirectoryUrl,
|
|
22543
22549
|
...urlAnalysis
|
|
@@ -22619,8 +22625,9 @@ const memoizeByFirstArgument = compute => {
|
|
|
22619
22625
|
return fnWithMemoization;
|
|
22620
22626
|
};
|
|
22621
22627
|
|
|
22622
|
-
const
|
|
22623
|
-
buildDirectoryUrl
|
|
22628
|
+
const createBuildUrlsGenerator = ({
|
|
22629
|
+
buildDirectoryUrl,
|
|
22630
|
+
assetsDirectory
|
|
22624
22631
|
}) => {
|
|
22625
22632
|
const cache = {};
|
|
22626
22633
|
const getUrlName = (url, urlInfo) => {
|
|
@@ -22638,6 +22645,7 @@ const createBuilUrlsGenerator = ({
|
|
|
22638
22645
|
}) => {
|
|
22639
22646
|
const directoryPath = determineDirectoryPath({
|
|
22640
22647
|
buildDirectoryUrl,
|
|
22648
|
+
assetsDirectory,
|
|
22641
22649
|
urlInfo,
|
|
22642
22650
|
parentUrlInfo
|
|
22643
22651
|
});
|
|
@@ -22692,6 +22700,7 @@ const splitFileExtension = filename => {
|
|
|
22692
22700
|
};
|
|
22693
22701
|
const determineDirectoryPath = ({
|
|
22694
22702
|
buildDirectoryUrl,
|
|
22703
|
+
assetsDirectory,
|
|
22695
22704
|
urlInfo,
|
|
22696
22705
|
parentUrlInfo
|
|
22697
22706
|
}) => {
|
|
@@ -22705,6 +22714,7 @@ const determineDirectoryPath = ({
|
|
|
22705
22714
|
if (urlInfo.isInline) {
|
|
22706
22715
|
const parentDirectoryPath = determineDirectoryPath({
|
|
22707
22716
|
buildDirectoryUrl,
|
|
22717
|
+
assetsDirectory,
|
|
22708
22718
|
urlInfo: parentUrlInfo
|
|
22709
22719
|
});
|
|
22710
22720
|
return parentDirectoryPath;
|
|
@@ -22716,25 +22726,26 @@ const determineDirectoryPath = ({
|
|
|
22716
22726
|
return "";
|
|
22717
22727
|
}
|
|
22718
22728
|
if (urlInfo.type === "html") {
|
|
22719
|
-
return
|
|
22729
|
+
return `${assetsDirectory}html/`;
|
|
22720
22730
|
}
|
|
22721
22731
|
if (urlInfo.type === "css") {
|
|
22722
|
-
return
|
|
22732
|
+
return `${assetsDirectory}css/`;
|
|
22723
22733
|
}
|
|
22724
22734
|
if (urlInfo.type === "js_module" || urlInfo.type === "js_classic") {
|
|
22725
|
-
return
|
|
22735
|
+
return `${assetsDirectory}js/`;
|
|
22726
22736
|
}
|
|
22727
22737
|
if (urlInfo.type === "json") {
|
|
22728
|
-
return
|
|
22738
|
+
return `${assetsDirectory}json/`;
|
|
22729
22739
|
}
|
|
22730
|
-
return
|
|
22740
|
+
return `${assetsDirectory}other/`;
|
|
22731
22741
|
};
|
|
22732
22742
|
|
|
22733
22743
|
// https://bundlers.tooling.report/hashing/avoid-cascade/
|
|
22734
22744
|
const injectVersionMappings = async ({
|
|
22735
22745
|
urlInfo,
|
|
22736
22746
|
kitchen,
|
|
22737
|
-
versionMappings
|
|
22747
|
+
versionMappings,
|
|
22748
|
+
minification
|
|
22738
22749
|
}) => {
|
|
22739
22750
|
const injector = injectors[urlInfo.type];
|
|
22740
22751
|
if (injector) {
|
|
@@ -22742,7 +22753,8 @@ const injectVersionMappings = async ({
|
|
|
22742
22753
|
content,
|
|
22743
22754
|
sourcemap
|
|
22744
22755
|
} = await injector(urlInfo, {
|
|
22745
|
-
versionMappings
|
|
22756
|
+
versionMappings,
|
|
22757
|
+
minification
|
|
22746
22758
|
});
|
|
22747
22759
|
kitchen.urlInfoTransformer.applyFinalTransformations(urlInfo, {
|
|
22748
22760
|
content,
|
|
@@ -22750,18 +22762,10 @@ const injectVersionMappings = async ({
|
|
|
22750
22762
|
});
|
|
22751
22763
|
}
|
|
22752
22764
|
};
|
|
22753
|
-
const jsInjector = (urlInfo, {
|
|
22754
|
-
versionMappings
|
|
22755
|
-
}) => {
|
|
22756
|
-
const magicSource = createMagicSource(urlInfo.content);
|
|
22757
|
-
magicSource.prepend(generateClientCodeForVersionMappings(versionMappings, {
|
|
22758
|
-
globalName: isWebWorkerUrlInfo(urlInfo) ? "self" : "window"
|
|
22759
|
-
}));
|
|
22760
|
-
return magicSource.toContentAndSourcemap();
|
|
22761
|
-
};
|
|
22762
22765
|
const injectors = {
|
|
22763
22766
|
html: (urlInfo, {
|
|
22764
|
-
versionMappings
|
|
22767
|
+
versionMappings,
|
|
22768
|
+
minification
|
|
22765
22769
|
}) => {
|
|
22766
22770
|
// ideally we would inject an importmap but browser support is too low
|
|
22767
22771
|
// (even worse for worker/service worker)
|
|
@@ -22772,19 +22776,51 @@ const injectors = {
|
|
|
22772
22776
|
injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
|
|
22773
22777
|
tagName: "script",
|
|
22774
22778
|
textContent: generateClientCodeForVersionMappings(versionMappings, {
|
|
22775
|
-
globalName: "window"
|
|
22779
|
+
globalName: "window",
|
|
22780
|
+
minify: minification || minification.js_classic
|
|
22776
22781
|
})
|
|
22777
22782
|
}), "jsenv:versioning");
|
|
22778
22783
|
return {
|
|
22779
22784
|
content: stringifyHtmlAst(htmlAst)
|
|
22780
22785
|
};
|
|
22781
22786
|
},
|
|
22782
|
-
js_classic:
|
|
22783
|
-
|
|
22787
|
+
js_classic: (urlInfo, {
|
|
22788
|
+
versionMappings,
|
|
22789
|
+
minification
|
|
22790
|
+
}) => {
|
|
22791
|
+
return jsInjector(urlInfo, {
|
|
22792
|
+
versionMappings,
|
|
22793
|
+
minify: minification || minification.js_classic
|
|
22794
|
+
});
|
|
22795
|
+
},
|
|
22796
|
+
js_module: (urlInfo, {
|
|
22797
|
+
versionMappings,
|
|
22798
|
+
minification
|
|
22799
|
+
}) => {
|
|
22800
|
+
return jsInjector(urlInfo, {
|
|
22801
|
+
versionMappings,
|
|
22802
|
+
minify: minification || minification.js_module
|
|
22803
|
+
});
|
|
22804
|
+
}
|
|
22805
|
+
};
|
|
22806
|
+
const jsInjector = (urlInfo, {
|
|
22807
|
+
versionMappings,
|
|
22808
|
+
minify
|
|
22809
|
+
}) => {
|
|
22810
|
+
const magicSource = createMagicSource(urlInfo.content);
|
|
22811
|
+
magicSource.prepend(generateClientCodeForVersionMappings(versionMappings, {
|
|
22812
|
+
globalName: isWebWorkerUrlInfo(urlInfo) ? "self" : "window",
|
|
22813
|
+
minify
|
|
22814
|
+
}));
|
|
22815
|
+
return magicSource.toContentAndSourcemap();
|
|
22784
22816
|
};
|
|
22785
22817
|
const generateClientCodeForVersionMappings = (versionMappings, {
|
|
22786
|
-
globalName
|
|
22818
|
+
globalName,
|
|
22819
|
+
minify
|
|
22787
22820
|
}) => {
|
|
22821
|
+
if (minify) {
|
|
22822
|
+
return `;(function(){var m = ${JSON.stringify(versionMappings)}; ${globalName}.__v__ = function (s) { return m[s] || s }; })();`;
|
|
22823
|
+
}
|
|
22788
22824
|
return `
|
|
22789
22825
|
;(function() {
|
|
22790
22826
|
|
|
@@ -22886,8 +22922,10 @@ const defaultRuntimeCompat = {
|
|
|
22886
22922
|
* Describe entry point paths and control their names in the build directory
|
|
22887
22923
|
* @param {object} buildParameters.runtimeCompat
|
|
22888
22924
|
* Code generated will be compatible with these runtimes
|
|
22889
|
-
* @param {string
|
|
22890
|
-
*
|
|
22925
|
+
* @param {string} [buildParameters.assetsDirectory=""]
|
|
22926
|
+
* Directory where asset files will be written
|
|
22927
|
+
* @param {string|url} [buildParameters.base=""]
|
|
22928
|
+
* Urls in build file contents will be prefixed with this string
|
|
22891
22929
|
* @param {boolean|object} [buildParameters.minification=true]
|
|
22892
22930
|
* Minify build file contents
|
|
22893
22931
|
* @param {boolean} [buildParameters.versioning=true]
|
|
@@ -22908,11 +22946,12 @@ const build = async ({
|
|
|
22908
22946
|
signal = new AbortController().signal,
|
|
22909
22947
|
handleSIGINT = true,
|
|
22910
22948
|
logLevel = "info",
|
|
22949
|
+
runtimeCompat = defaultRuntimeCompat,
|
|
22911
22950
|
rootDirectoryUrl,
|
|
22912
22951
|
buildDirectoryUrl,
|
|
22952
|
+
assetsDirectory = "",
|
|
22953
|
+
base = runtimeCompat.node ? "./" : "/",
|
|
22913
22954
|
entryPoints = {},
|
|
22914
|
-
baseUrl = "/",
|
|
22915
|
-
runtimeCompat = defaultRuntimeCompat,
|
|
22916
22955
|
plugins = [],
|
|
22917
22956
|
sourcemaps = false,
|
|
22918
22957
|
sourcemapsSourcesContent,
|
|
@@ -22922,21 +22961,20 @@ const build = async ({
|
|
|
22922
22961
|
directoryReferenceAllowed,
|
|
22923
22962
|
transpilation = {},
|
|
22924
22963
|
bundling = true,
|
|
22925
|
-
minification =
|
|
22926
|
-
versioning =
|
|
22964
|
+
minification = !runtimeCompat.node,
|
|
22965
|
+
versioning = !runtimeCompat.node,
|
|
22927
22966
|
versioningMethod = "search_param",
|
|
22928
22967
|
// "filename", "search_param"
|
|
22929
22968
|
lineBreakNormalization = process.platform === "win32",
|
|
22930
|
-
ribbon,
|
|
22931
22969
|
clientFiles = {
|
|
22932
22970
|
"./src/": true
|
|
22933
22971
|
},
|
|
22934
22972
|
cooldownBetweenFileEvents,
|
|
22935
22973
|
watch = false,
|
|
22936
|
-
|
|
22974
|
+
directoryToClean,
|
|
22937
22975
|
writeOnFileSystem = true,
|
|
22938
22976
|
writeGeneratedFiles = false,
|
|
22939
|
-
assetManifest =
|
|
22977
|
+
assetManifest = versioningMethod === "filename",
|
|
22940
22978
|
assetManifestFileRelativeUrl = "asset-manifest.json"
|
|
22941
22979
|
}) => {
|
|
22942
22980
|
const operation = Abort.startOperation();
|
|
@@ -22956,6 +22994,28 @@ const build = async ({
|
|
|
22956
22994
|
if (!["filename", "search_param"].includes(versioningMethod)) {
|
|
22957
22995
|
throw new Error(`Unexpected "versioningMethod": must be "filename", "search_param"; got ${versioning}`);
|
|
22958
22996
|
}
|
|
22997
|
+
if (assetsDirectory && assetsDirectory[assetsDirectory.length - 1] !== "/") {
|
|
22998
|
+
assetsDirectory = `${assetsDirectory}/`;
|
|
22999
|
+
}
|
|
23000
|
+
if (directoryToClean === undefined) {
|
|
23001
|
+
if (assetsDirectory === undefined) {
|
|
23002
|
+
directoryToClean = buildDirectoryUrl;
|
|
23003
|
+
} else {
|
|
23004
|
+
directoryToClean = new URL(assetsDirectory, buildDirectoryUrl).href;
|
|
23005
|
+
}
|
|
23006
|
+
}
|
|
23007
|
+
const asFormattedBuildUrl = (generatedUrl, reference) => {
|
|
23008
|
+
if (base === "./") {
|
|
23009
|
+
const urlRelativeToParent = urlToRelativeUrl(generatedUrl, reference.parentUrl === rootDirectoryUrl ? buildDirectoryUrl : reference.parentUrl);
|
|
23010
|
+
if (urlRelativeToParent[0] !== ".") {
|
|
23011
|
+
// ensure "./" on relative url (otherwise it could be a "bare specifier")
|
|
23012
|
+
return `./${urlRelativeToParent}`;
|
|
23013
|
+
}
|
|
23014
|
+
return urlRelativeToParent;
|
|
23015
|
+
}
|
|
23016
|
+
const urlRelativeToBuildDirectory = urlToRelativeUrl(generatedUrl, buildDirectoryUrl);
|
|
23017
|
+
return `${base}${urlRelativeToBuildDirectory}`;
|
|
23018
|
+
};
|
|
22959
23019
|
const runBuild = async ({
|
|
22960
23020
|
signal,
|
|
22961
23021
|
logLevel
|
|
@@ -23017,16 +23077,16 @@ build ${entryPointKeys.length} entry points`);
|
|
|
23017
23077
|
jsClassicFallback: false
|
|
23018
23078
|
},
|
|
23019
23079
|
minification,
|
|
23020
|
-
bundling
|
|
23021
|
-
ribbon
|
|
23080
|
+
bundling
|
|
23022
23081
|
})],
|
|
23023
23082
|
sourcemaps,
|
|
23024
23083
|
sourcemapsSourcesContent,
|
|
23025
23084
|
writeGeneratedFiles,
|
|
23026
23085
|
outDirectoryUrl: new URL(`.jsenv/build/`, rootDirectoryUrl)
|
|
23027
23086
|
});
|
|
23028
|
-
const buildUrlsGenerator =
|
|
23029
|
-
buildDirectoryUrl
|
|
23087
|
+
const buildUrlsGenerator = createBuildUrlsGenerator({
|
|
23088
|
+
buildDirectoryUrl,
|
|
23089
|
+
assetsDirectory
|
|
23030
23090
|
});
|
|
23031
23091
|
const buildDirectoryRedirections = new Map();
|
|
23032
23092
|
const associateBuildUrlAndRawUrl = (buildUrl, rawUrl, reason) => {
|
|
@@ -23068,8 +23128,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
23068
23128
|
const getUrl = () => {
|
|
23069
23129
|
if (reference.type === "filesystem") {
|
|
23070
23130
|
const parentRawUrl = buildDirectoryRedirections.get(reference.parentUrl);
|
|
23071
|
-
const
|
|
23072
|
-
return new URL(reference.specifier,
|
|
23131
|
+
const parentUrl = ensurePathnameTrailingSlash(parentRawUrl);
|
|
23132
|
+
return new URL(reference.specifier, parentUrl).href;
|
|
23073
23133
|
}
|
|
23074
23134
|
if (reference.specifier[0] === "/") {
|
|
23075
23135
|
return new URL(reference.specifier.slice(1), buildDirectoryUrl).href;
|
|
@@ -23220,16 +23280,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
23220
23280
|
generatedUrlObject.searchParams.delete("as_text_module");
|
|
23221
23281
|
generatedUrlObject.hash = "";
|
|
23222
23282
|
const generatedUrl = generatedUrlObject.href;
|
|
23223
|
-
|
|
23224
|
-
if (baseUrl === "./") {
|
|
23225
|
-
const relativeUrl = urlToRelativeUrl(generatedUrl, reference.parentUrl === rootDirectoryUrl ? buildDirectoryUrl : reference.parentUrl);
|
|
23226
|
-
// ensure "./" on relative url (otherwise it could be a "bare specifier")
|
|
23227
|
-
specifier = relativeUrl[0] === "." ? relativeUrl : `./${relativeUrl}`;
|
|
23228
|
-
} else {
|
|
23229
|
-
// if a file is in the same directory we could prefer the relative notation
|
|
23230
|
-
// but to keep things simple let's keep the "absolutely relative" to baseUrl for now
|
|
23231
|
-
specifier = `${baseUrl}${urlToRelativeUrl(generatedUrl, buildDirectoryUrl)}`;
|
|
23232
|
-
}
|
|
23283
|
+
const specifier = asFormattedBuildUrl(generatedUrl, reference);
|
|
23233
23284
|
buildUrls.set(specifier, reference.generatedUrl);
|
|
23234
23285
|
return specifier;
|
|
23235
23286
|
},
|
|
@@ -23326,6 +23377,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
23326
23377
|
});
|
|
23327
23378
|
entryUrls.push(entryUrlInfo.url);
|
|
23328
23379
|
entryUrlInfo.filename = entryPoints[key];
|
|
23380
|
+
entryUrlInfo.isEntryPoint = true;
|
|
23329
23381
|
rawUrlGraphLoader.load(entryUrlInfo, {
|
|
23330
23382
|
reference: entryReference
|
|
23331
23383
|
});
|
|
@@ -23457,7 +23509,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
23457
23509
|
value: bundler.bundleFunction
|
|
23458
23510
|
}, urlInfosToBundle, {
|
|
23459
23511
|
...rawGraphKitchen.kitchenContext,
|
|
23460
|
-
buildDirectoryUrl
|
|
23512
|
+
buildDirectoryUrl,
|
|
23513
|
+
assetsDirectory
|
|
23461
23514
|
});
|
|
23462
23515
|
Object.keys(bundlerGeneratedUrlInfos).forEach(url => {
|
|
23463
23516
|
const rawUrlInfo = rawGraph.getUrlInfo(url);
|
|
@@ -23730,9 +23783,9 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
23730
23783
|
const versionedUrl = versionedUrlMap.get(reference.url);
|
|
23731
23784
|
if (!versionedUrl) {
|
|
23732
23785
|
// happens for sourcemap
|
|
23733
|
-
return
|
|
23786
|
+
return urlToRelativeUrl(referencedUrlInfo.url, reference.parentUrl);
|
|
23734
23787
|
}
|
|
23735
|
-
const versionedSpecifier =
|
|
23788
|
+
const versionedSpecifier = asFormattedBuildUrl(versionedUrl, reference);
|
|
23736
23789
|
versionMappings[reference.specifier] = versionedSpecifier;
|
|
23737
23790
|
versioningRedirections.set(reference.url, versionedUrl);
|
|
23738
23791
|
buildUrls.set(versionedSpecifier, versionedUrl);
|
|
@@ -23795,7 +23848,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
23795
23848
|
await injectVersionMappings({
|
|
23796
23849
|
urlInfo,
|
|
23797
23850
|
kitchen: finalGraphKitchen,
|
|
23798
|
-
versionMappings: versionMappingsNeeded
|
|
23851
|
+
versionMappings: versionMappingsNeeded,
|
|
23852
|
+
minification
|
|
23799
23853
|
});
|
|
23800
23854
|
});
|
|
23801
23855
|
}
|
|
@@ -24002,8 +24056,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
24002
24056
|
}
|
|
24003
24057
|
});
|
|
24004
24058
|
if (writeOnFileSystem) {
|
|
24005
|
-
if (
|
|
24006
|
-
await ensureEmptyDirectory(
|
|
24059
|
+
if (directoryToClean) {
|
|
24060
|
+
await ensureEmptyDirectory(directoryToClean);
|
|
24007
24061
|
}
|
|
24008
24062
|
const buildRelativeUrls = Object.keys(buildFileContents);
|
|
24009
24063
|
buildRelativeUrls.forEach(buildRelativeUrl => {
|
|
@@ -24762,7 +24816,7 @@ const startDevServer = async ({
|
|
|
24762
24816
|
transpilation,
|
|
24763
24817
|
explorer = true,
|
|
24764
24818
|
// see jsenv_plugin_explorer.js
|
|
24765
|
-
ribbon =
|
|
24819
|
+
ribbon = true,
|
|
24766
24820
|
// toolbar = false,
|
|
24767
24821
|
|
|
24768
24822
|
sourcemaps = "inline",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "29.
|
|
3
|
+
"version": "29.5.0",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -62,19 +62,19 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@babel/plugin-proposal-dynamic-import": "7.18.6",
|
|
65
|
-
"@babel/plugin-transform-modules-systemjs": "7.19.
|
|
65
|
+
"@babel/plugin-transform-modules-systemjs": "7.19.6",
|
|
66
66
|
"@babel/plugin-transform-modules-umd": "7.18.6",
|
|
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.
|
|
71
|
-
"@jsenv/babel-plugins": "1.0.
|
|
70
|
+
"@jsenv/ast": "1.4.3",
|
|
71
|
+
"@jsenv/babel-plugins": "1.0.9",
|
|
72
72
|
"@jsenv/filesystem": "4.1.5",
|
|
73
73
|
"@jsenv/importmap": "1.2.1",
|
|
74
74
|
"@jsenv/integrity": "0.0.1",
|
|
75
75
|
"@jsenv/log": "3.3.1",
|
|
76
76
|
"@jsenv/node-esm-resolution": "0.2.0",
|
|
77
|
-
"@jsenv/server": "14.1.
|
|
77
|
+
"@jsenv/server": "14.1.9",
|
|
78
78
|
"@jsenv/sourcemap": "1.0.6",
|
|
79
79
|
"@jsenv/uneval": "1.6.0",
|
|
80
80
|
"@jsenv/url-meta": "7.0.0",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"istanbul-reports": "3.1.5",
|
|
91
91
|
"launch-editor": "2.6.0",
|
|
92
92
|
"pidtree": "0.6.0",
|
|
93
|
-
"rollup": "3.2.
|
|
93
|
+
"rollup": "3.2.5",
|
|
94
94
|
"string-width": "5.1.2",
|
|
95
95
|
"strip-ansi": "7.0.1",
|
|
96
96
|
"terser": "5.15.1",
|
|
@@ -99,14 +99,14 @@
|
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
101
|
"@babel/eslint-parser": "7.19.1",
|
|
102
|
-
"@babel/plugin-syntax-import-assertions": "7.
|
|
102
|
+
"@babel/plugin-syntax-import-assertions": "7.20.0",
|
|
103
103
|
"@jsenv/assert": "./packages/assert/",
|
|
104
104
|
"@jsenv/eslint-config": "./packages/eslint-config/",
|
|
105
105
|
"@jsenv/file-size-impact": "13.0.1",
|
|
106
106
|
"@jsenv/https-local": "3.0.1",
|
|
107
107
|
"@jsenv/package-workspace": "0.5.0",
|
|
108
108
|
"@jsenv/performance-impact": "3.0.1",
|
|
109
|
-
"eslint": "8.
|
|
109
|
+
"eslint": "8.26.0",
|
|
110
110
|
"eslint-plugin-html": "7.1.0",
|
|
111
111
|
"eslint-plugin-import": "2.26.0",
|
|
112
112
|
"eslint-plugin-react": "7.31.10",
|
package/src/build/build.js
CHANGED
|
@@ -61,7 +61,7 @@ import { jsenvPluginAsJsClassic } from "../plugins/transpilation/as_js_classic/j
|
|
|
61
61
|
import { getCorePlugins } from "../plugins/plugins.js"
|
|
62
62
|
|
|
63
63
|
import { GRAPH } from "./graph_utils.js"
|
|
64
|
-
import {
|
|
64
|
+
import { createBuildUrlsGenerator } from "./build_urls_generator.js"
|
|
65
65
|
import { injectVersionMappings } from "./inject_global_version_mappings.js"
|
|
66
66
|
import { createVersionGenerator } from "./version_generator.js"
|
|
67
67
|
|
|
@@ -90,8 +90,10 @@ export const defaultRuntimeCompat = {
|
|
|
90
90
|
* Describe entry point paths and control their names in the build directory
|
|
91
91
|
* @param {object} buildParameters.runtimeCompat
|
|
92
92
|
* Code generated will be compatible with these runtimes
|
|
93
|
-
* @param {string
|
|
94
|
-
*
|
|
93
|
+
* @param {string} [buildParameters.assetsDirectory=""]
|
|
94
|
+
* Directory where asset files will be written
|
|
95
|
+
* @param {string|url} [buildParameters.base=""]
|
|
96
|
+
* Urls in build file contents will be prefixed with this string
|
|
95
97
|
* @param {boolean|object} [buildParameters.minification=true]
|
|
96
98
|
* Minify build file contents
|
|
97
99
|
* @param {boolean} [buildParameters.versioning=true]
|
|
@@ -112,12 +114,13 @@ export const build = async ({
|
|
|
112
114
|
signal = new AbortController().signal,
|
|
113
115
|
handleSIGINT = true,
|
|
114
116
|
logLevel = "info",
|
|
117
|
+
runtimeCompat = defaultRuntimeCompat,
|
|
115
118
|
rootDirectoryUrl,
|
|
116
119
|
buildDirectoryUrl,
|
|
120
|
+
assetsDirectory = "",
|
|
121
|
+
base = runtimeCompat.node ? "./" : "/",
|
|
117
122
|
entryPoints = {},
|
|
118
|
-
baseUrl = "/",
|
|
119
123
|
|
|
120
|
-
runtimeCompat = defaultRuntimeCompat,
|
|
121
124
|
plugins = [],
|
|
122
125
|
sourcemaps = false,
|
|
123
126
|
sourcemapsSourcesContent,
|
|
@@ -127,11 +130,10 @@ export const build = async ({
|
|
|
127
130
|
directoryReferenceAllowed,
|
|
128
131
|
transpilation = {},
|
|
129
132
|
bundling = true,
|
|
130
|
-
minification =
|
|
131
|
-
versioning =
|
|
133
|
+
minification = !runtimeCompat.node,
|
|
134
|
+
versioning = !runtimeCompat.node,
|
|
132
135
|
versioningMethod = "search_param", // "filename", "search_param"
|
|
133
136
|
lineBreakNormalization = process.platform === "win32",
|
|
134
|
-
ribbon,
|
|
135
137
|
|
|
136
138
|
clientFiles = {
|
|
137
139
|
"./src/": true,
|
|
@@ -139,10 +141,10 @@ export const build = async ({
|
|
|
139
141
|
cooldownBetweenFileEvents,
|
|
140
142
|
watch = false,
|
|
141
143
|
|
|
142
|
-
|
|
144
|
+
directoryToClean,
|
|
143
145
|
writeOnFileSystem = true,
|
|
144
146
|
writeGeneratedFiles = false,
|
|
145
|
-
assetManifest =
|
|
147
|
+
assetManifest = versioningMethod === "filename",
|
|
146
148
|
assetManifestFileRelativeUrl = "asset-manifest.json",
|
|
147
149
|
}) => {
|
|
148
150
|
const operation = Abort.startOperation()
|
|
@@ -166,6 +168,36 @@ export const build = async ({
|
|
|
166
168
|
`Unexpected "versioningMethod": must be "filename", "search_param"; got ${versioning}`,
|
|
167
169
|
)
|
|
168
170
|
}
|
|
171
|
+
if (assetsDirectory && assetsDirectory[assetsDirectory.length - 1] !== "/") {
|
|
172
|
+
assetsDirectory = `${assetsDirectory}/`
|
|
173
|
+
}
|
|
174
|
+
if (directoryToClean === undefined) {
|
|
175
|
+
if (assetsDirectory === undefined) {
|
|
176
|
+
directoryToClean = buildDirectoryUrl
|
|
177
|
+
} else {
|
|
178
|
+
directoryToClean = new URL(assetsDirectory, buildDirectoryUrl).href
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const asFormattedBuildUrl = (generatedUrl, reference) => {
|
|
182
|
+
if (base === "./") {
|
|
183
|
+
const urlRelativeToParent = urlToRelativeUrl(
|
|
184
|
+
generatedUrl,
|
|
185
|
+
reference.parentUrl === rootDirectoryUrl
|
|
186
|
+
? buildDirectoryUrl
|
|
187
|
+
: reference.parentUrl,
|
|
188
|
+
)
|
|
189
|
+
if (urlRelativeToParent[0] !== ".") {
|
|
190
|
+
// ensure "./" on relative url (otherwise it could be a "bare specifier")
|
|
191
|
+
return `./${urlRelativeToParent}`
|
|
192
|
+
}
|
|
193
|
+
return urlRelativeToParent
|
|
194
|
+
}
|
|
195
|
+
const urlRelativeToBuildDirectory = urlToRelativeUrl(
|
|
196
|
+
generatedUrl,
|
|
197
|
+
buildDirectoryUrl,
|
|
198
|
+
)
|
|
199
|
+
return `${base}${urlRelativeToBuildDirectory}`
|
|
200
|
+
}
|
|
169
201
|
|
|
170
202
|
const runBuild = async ({ signal, logLevel }) => {
|
|
171
203
|
const logger = createLogger({ logLevel })
|
|
@@ -231,7 +263,6 @@ build ${entryPointKeys.length} entry points`)
|
|
|
231
263
|
},
|
|
232
264
|
minification,
|
|
233
265
|
bundling,
|
|
234
|
-
ribbon,
|
|
235
266
|
}),
|
|
236
267
|
],
|
|
237
268
|
sourcemaps,
|
|
@@ -240,8 +271,9 @@ build ${entryPointKeys.length} entry points`)
|
|
|
240
271
|
outDirectoryUrl: new URL(`.jsenv/build/`, rootDirectoryUrl),
|
|
241
272
|
})
|
|
242
273
|
|
|
243
|
-
const buildUrlsGenerator =
|
|
274
|
+
const buildUrlsGenerator = createBuildUrlsGenerator({
|
|
244
275
|
buildDirectoryUrl,
|
|
276
|
+
assetsDirectory,
|
|
245
277
|
})
|
|
246
278
|
const buildDirectoryRedirections = new Map()
|
|
247
279
|
|
|
@@ -288,8 +320,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
288
320
|
const parentRawUrl = buildDirectoryRedirections.get(
|
|
289
321
|
reference.parentUrl,
|
|
290
322
|
)
|
|
291
|
-
const
|
|
292
|
-
return new URL(reference.specifier,
|
|
323
|
+
const parentUrl = ensurePathnameTrailingSlash(parentRawUrl)
|
|
324
|
+
return new URL(reference.specifier, parentUrl).href
|
|
293
325
|
}
|
|
294
326
|
if (reference.specifier[0] === "/") {
|
|
295
327
|
return new URL(reference.specifier.slice(1), buildDirectoryUrl)
|
|
@@ -467,25 +499,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
467
499
|
generatedUrlObject.searchParams.delete("as_text_module")
|
|
468
500
|
generatedUrlObject.hash = ""
|
|
469
501
|
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
|
-
}
|
|
502
|
+
const specifier = asFormattedBuildUrl(generatedUrl, reference)
|
|
489
503
|
buildUrls.set(specifier, reference.generatedUrl)
|
|
490
504
|
return specifier
|
|
491
505
|
},
|
|
@@ -592,6 +606,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
592
606
|
})
|
|
593
607
|
entryUrls.push(entryUrlInfo.url)
|
|
594
608
|
entryUrlInfo.filename = entryPoints[key]
|
|
609
|
+
entryUrlInfo.isEntryPoint = true
|
|
595
610
|
rawUrlGraphLoader.load(entryUrlInfo, { reference: entryReference })
|
|
596
611
|
})
|
|
597
612
|
await rawUrlGraphLoader.getAllLoadDonePromise(buildOperation)
|
|
@@ -740,6 +755,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
740
755
|
{
|
|
741
756
|
...rawGraphKitchen.kitchenContext,
|
|
742
757
|
buildDirectoryUrl,
|
|
758
|
+
assetsDirectory,
|
|
743
759
|
},
|
|
744
760
|
)
|
|
745
761
|
Object.keys(bundlerGeneratedUrlInfos).forEach((url) => {
|
|
@@ -1055,15 +1071,15 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1055
1071
|
const versionedUrl = versionedUrlMap.get(reference.url)
|
|
1056
1072
|
if (!versionedUrl) {
|
|
1057
1073
|
// happens for sourcemap
|
|
1058
|
-
return
|
|
1074
|
+
return urlToRelativeUrl(
|
|
1059
1075
|
referencedUrlInfo.url,
|
|
1060
|
-
|
|
1061
|
-
)
|
|
1076
|
+
reference.parentUrl,
|
|
1077
|
+
)
|
|
1062
1078
|
}
|
|
1063
|
-
const versionedSpecifier =
|
|
1079
|
+
const versionedSpecifier = asFormattedBuildUrl(
|
|
1064
1080
|
versionedUrl,
|
|
1065
|
-
|
|
1066
|
-
)
|
|
1081
|
+
reference,
|
|
1082
|
+
)
|
|
1067
1083
|
versionMappings[reference.specifier] = versionedSpecifier
|
|
1068
1084
|
versioningRedirections.set(reference.url, versionedUrl)
|
|
1069
1085
|
buildUrls.set(versionedSpecifier, versionedUrl)
|
|
@@ -1149,6 +1165,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1149
1165
|
urlInfo,
|
|
1150
1166
|
kitchen: finalGraphKitchen,
|
|
1151
1167
|
versionMappings: versionMappingsNeeded,
|
|
1168
|
+
minification,
|
|
1152
1169
|
})
|
|
1153
1170
|
})
|
|
1154
1171
|
}
|
|
@@ -1407,8 +1424,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
|
|
|
1407
1424
|
}
|
|
1408
1425
|
})
|
|
1409
1426
|
if (writeOnFileSystem) {
|
|
1410
|
-
if (
|
|
1411
|
-
await ensureEmptyDirectory(
|
|
1427
|
+
if (directoryToClean) {
|
|
1428
|
+
await ensureEmptyDirectory(directoryToClean)
|
|
1412
1429
|
}
|
|
1413
1430
|
const buildRelativeUrls = Object.keys(buildFileContents)
|
|
1414
1431
|
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
|
|
|
@@ -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,
|
|
@@ -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
|
|
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,
|