@jsenv/core 38.3.0 → 38.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/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# @jsenv/core [](https://www.npmjs.com/package/@jsenv/core)
|
|
2
2
|
|
|
3
|
-
Jsenv is a tool to develop test and build projects using JavaScript. Jsenv
|
|
4
|
-
|
|
5
|
-
Jsenv cares a lot about the developper experience, especially when it comes to tests.
|
|
3
|
+
Jsenv is a tool to develop test and build projects using JavaScript. Jsenv encourages standards and simplicity.
|
|
6
4
|
|
|
7
5
|
The pillars of jsenv are:
|
|
8
6
|
|
|
@@ -11,6 +9,8 @@ The pillars of jsenv are:
|
|
|
11
9
|
3. A build server serving build files
|
|
12
10
|
4. A test runner executing test files in web browser(s)
|
|
13
11
|
|
|
12
|
+
Jsenv cares a lot about the developer experience. As a result it can be enjoyed by people without much experience in tooling. Or by people wanting to use a simple tool, without hidden complexities.
|
|
13
|
+
|
|
14
14
|
[Link to documentation](<https://github.com/jsenv/core/wiki/A)-directory-structure>)
|
|
15
15
|
|
|
16
16
|
# The best parts
|
package/dist/jsenv_core.js
CHANGED
|
@@ -15759,22 +15759,39 @@ const jsenvPluginHtmlReferenceAnalysis = ({
|
|
|
15759
15759
|
|
|
15760
15760
|
let globalImportmap = null;
|
|
15761
15761
|
const importmaps = {};
|
|
15762
|
-
|
|
15763
|
-
|
|
15764
|
-
|
|
15765
|
-
|
|
15766
|
-
|
|
15767
|
-
|
|
15768
|
-
|
|
15769
|
-
|
|
15770
|
-
|
|
15771
|
-
|
|
15762
|
+
let importmapLoadingCount = 0;
|
|
15763
|
+
const allImportmapLoadedCallbackSet = new Set();
|
|
15764
|
+
const startLoadingImportmap = (htmlUrlInfo) => {
|
|
15765
|
+
importmapLoadingCount++;
|
|
15766
|
+
return (importmapUrlInfo) => {
|
|
15767
|
+
const htmlUrl = htmlUrlInfo.url;
|
|
15768
|
+
if (importmapUrlInfo) {
|
|
15769
|
+
// importmap was found in this HTML file and is known
|
|
15770
|
+
const importmap = JSON.parse(importmapUrlInfo.content);
|
|
15771
|
+
importmaps[htmlUrl] = normalizeImportMap(importmap, htmlUrl);
|
|
15772
|
+
} else {
|
|
15773
|
+
// no importmap in this HTML file
|
|
15774
|
+
importmaps[htmlUrl] = null;
|
|
15772
15775
|
}
|
|
15773
|
-
|
|
15774
|
-
|
|
15776
|
+
globalImportmap = Object.keys(importmaps).reduce((previous, url) => {
|
|
15777
|
+
const importmap = importmaps[url];
|
|
15778
|
+
if (!previous) {
|
|
15779
|
+
return importmap;
|
|
15780
|
+
}
|
|
15781
|
+
if (!importmap) {
|
|
15782
|
+
return previous;
|
|
15783
|
+
}
|
|
15784
|
+
return composeTwoImportMaps(previous, importmap);
|
|
15785
|
+
}, null);
|
|
15786
|
+
|
|
15787
|
+
importmapLoadingCount--;
|
|
15788
|
+
if (importmapLoadingCount === 0) {
|
|
15789
|
+
allImportmapLoadedCallbackSet.forEach((callback) => {
|
|
15790
|
+
callback();
|
|
15791
|
+
});
|
|
15792
|
+
allImportmapLoadedCallbackSet.clear();
|
|
15775
15793
|
}
|
|
15776
|
-
|
|
15777
|
-
}, null);
|
|
15794
|
+
};
|
|
15778
15795
|
};
|
|
15779
15796
|
|
|
15780
15797
|
return {
|
|
@@ -15813,16 +15830,18 @@ const jsenvPluginHtmlReferenceAnalysis = ({
|
|
|
15813
15830
|
},
|
|
15814
15831
|
},
|
|
15815
15832
|
transformUrlContent: {
|
|
15833
|
+
js_module: async () => {
|
|
15834
|
+
// wait for importmap if any
|
|
15835
|
+
// so that resolveReference can happen with importmap
|
|
15836
|
+
if (importmapLoadingCount) {
|
|
15837
|
+
await new Promise((resolve) => {
|
|
15838
|
+
allImportmapLoadedCallbackSet.add(resolve);
|
|
15839
|
+
});
|
|
15840
|
+
}
|
|
15841
|
+
},
|
|
15816
15842
|
html: async (urlInfo) => {
|
|
15817
15843
|
let importmapFound = false;
|
|
15818
|
-
|
|
15819
|
-
const onImportmapReady = (importmap) => {
|
|
15820
|
-
onImportmapParsed(urlInfo.url, importmap);
|
|
15821
|
-
importmapParsedCallbackSet.forEach((callback) => {
|
|
15822
|
-
callback();
|
|
15823
|
-
});
|
|
15824
|
-
importmapParsedCallbackSet.clear();
|
|
15825
|
-
};
|
|
15844
|
+
const importmapLoaded = startLoadingImportmap(urlInfo);
|
|
15826
15845
|
|
|
15827
15846
|
const content = urlInfo.content;
|
|
15828
15847
|
const htmlAst = parseHtmlString(content);
|
|
@@ -15962,11 +15981,6 @@ const jsenvPluginHtmlReferenceAnalysis = ({
|
|
|
15962
15981
|
});
|
|
15963
15982
|
|
|
15964
15983
|
actions.push(async () => {
|
|
15965
|
-
if (expectedType === "js_module" && importmapFound) {
|
|
15966
|
-
await new Promise((resolve) => {
|
|
15967
|
-
importmapParsedCallbackSet.add(resolve);
|
|
15968
|
-
});
|
|
15969
|
-
}
|
|
15970
15984
|
await inlineReference.urlInfo.cook();
|
|
15971
15985
|
mutations.push(() => {
|
|
15972
15986
|
if (hotAccept) {
|
|
@@ -16078,7 +16092,7 @@ const jsenvPluginHtmlReferenceAnalysis = ({
|
|
|
16078
16092
|
importmapReferenceInlined.urlInfo;
|
|
16079
16093
|
actions.push(async () => {
|
|
16080
16094
|
await importmapInlineUrlInfo.cook();
|
|
16081
|
-
|
|
16095
|
+
importmapLoaded(importmapInlineUrlInfo);
|
|
16082
16096
|
mutations.push(() => {
|
|
16083
16097
|
setHtmlNodeText(
|
|
16084
16098
|
scriptNode,
|
|
@@ -16109,9 +16123,7 @@ const jsenvPluginHtmlReferenceAnalysis = ({
|
|
|
16109
16123
|
const inlineImportmapUrlInfo = importmapReference.urlInfo;
|
|
16110
16124
|
actions.push(async () => {
|
|
16111
16125
|
await inlineImportmapUrlInfo.cook();
|
|
16112
|
-
|
|
16113
|
-
JSON.parse(inlineImportmapUrlInfo.content),
|
|
16114
|
-
);
|
|
16126
|
+
importmapLoaded(inlineImportmapUrlInfo);
|
|
16115
16127
|
mutations.push(() => {
|
|
16116
16128
|
setHtmlNodeText(
|
|
16117
16129
|
scriptNode,
|
|
@@ -16227,7 +16239,7 @@ const jsenvPluginHtmlReferenceAnalysis = ({
|
|
|
16227
16239
|
},
|
|
16228
16240
|
});
|
|
16229
16241
|
if (!importmapFound) {
|
|
16230
|
-
|
|
16242
|
+
importmapLoaded();
|
|
16231
16243
|
}
|
|
16232
16244
|
finalizeCallbacks.forEach((finalizeCallback) => {
|
|
16233
16245
|
finalizeCallback();
|
package/package.json
CHANGED
|
@@ -45,22 +45,39 @@ export const jsenvPluginHtmlReferenceAnalysis = ({
|
|
|
45
45
|
|
|
46
46
|
let globalImportmap = null;
|
|
47
47
|
const importmaps = {};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
let importmapLoadingCount = 0;
|
|
49
|
+
const allImportmapLoadedCallbackSet = new Set();
|
|
50
|
+
const startLoadingImportmap = (htmlUrlInfo) => {
|
|
51
|
+
importmapLoadingCount++;
|
|
52
|
+
return (importmapUrlInfo) => {
|
|
53
|
+
const htmlUrl = htmlUrlInfo.url;
|
|
54
|
+
if (importmapUrlInfo) {
|
|
55
|
+
// importmap was found in this HTML file and is known
|
|
56
|
+
const importmap = JSON.parse(importmapUrlInfo.content);
|
|
57
|
+
importmaps[htmlUrl] = normalizeImportMap(importmap, htmlUrl);
|
|
58
|
+
} else {
|
|
59
|
+
// no importmap in this HTML file
|
|
60
|
+
importmaps[htmlUrl] = null;
|
|
58
61
|
}
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
globalImportmap = Object.keys(importmaps).reduce((previous, url) => {
|
|
63
|
+
const importmap = importmaps[url];
|
|
64
|
+
if (!previous) {
|
|
65
|
+
return importmap;
|
|
66
|
+
}
|
|
67
|
+
if (!importmap) {
|
|
68
|
+
return previous;
|
|
69
|
+
}
|
|
70
|
+
return composeTwoImportMaps(previous, importmap);
|
|
71
|
+
}, null);
|
|
72
|
+
|
|
73
|
+
importmapLoadingCount--;
|
|
74
|
+
if (importmapLoadingCount === 0) {
|
|
75
|
+
allImportmapLoadedCallbackSet.forEach((callback) => {
|
|
76
|
+
callback();
|
|
77
|
+
});
|
|
78
|
+
allImportmapLoadedCallbackSet.clear();
|
|
61
79
|
}
|
|
62
|
-
|
|
63
|
-
}, null);
|
|
80
|
+
};
|
|
64
81
|
};
|
|
65
82
|
|
|
66
83
|
return {
|
|
@@ -99,16 +116,18 @@ export const jsenvPluginHtmlReferenceAnalysis = ({
|
|
|
99
116
|
},
|
|
100
117
|
},
|
|
101
118
|
transformUrlContent: {
|
|
119
|
+
js_module: async () => {
|
|
120
|
+
// wait for importmap if any
|
|
121
|
+
// so that resolveReference can happen with importmap
|
|
122
|
+
if (importmapLoadingCount) {
|
|
123
|
+
await new Promise((resolve) => {
|
|
124
|
+
allImportmapLoadedCallbackSet.add(resolve);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
},
|
|
102
128
|
html: async (urlInfo) => {
|
|
103
129
|
let importmapFound = false;
|
|
104
|
-
|
|
105
|
-
const onImportmapReady = (importmap) => {
|
|
106
|
-
onImportmapParsed(urlInfo.url, importmap);
|
|
107
|
-
importmapParsedCallbackSet.forEach((callback) => {
|
|
108
|
-
callback();
|
|
109
|
-
});
|
|
110
|
-
importmapParsedCallbackSet.clear();
|
|
111
|
-
};
|
|
130
|
+
const importmapLoaded = startLoadingImportmap(urlInfo);
|
|
112
131
|
|
|
113
132
|
const content = urlInfo.content;
|
|
114
133
|
const htmlAst = parseHtmlString(content);
|
|
@@ -248,11 +267,6 @@ export const jsenvPluginHtmlReferenceAnalysis = ({
|
|
|
248
267
|
});
|
|
249
268
|
|
|
250
269
|
actions.push(async () => {
|
|
251
|
-
if (expectedType === "js_module" && importmapFound) {
|
|
252
|
-
await new Promise((resolve) => {
|
|
253
|
-
importmapParsedCallbackSet.add(resolve);
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
270
|
await inlineReference.urlInfo.cook();
|
|
257
271
|
mutations.push(() => {
|
|
258
272
|
if (hotAccept) {
|
|
@@ -366,7 +380,7 @@ export const jsenvPluginHtmlReferenceAnalysis = ({
|
|
|
366
380
|
importmapReferenceInlined.urlInfo;
|
|
367
381
|
actions.push(async () => {
|
|
368
382
|
await importmapInlineUrlInfo.cook();
|
|
369
|
-
|
|
383
|
+
importmapLoaded(importmapInlineUrlInfo);
|
|
370
384
|
mutations.push(() => {
|
|
371
385
|
setHtmlNodeText(
|
|
372
386
|
scriptNode,
|
|
@@ -397,9 +411,7 @@ export const jsenvPluginHtmlReferenceAnalysis = ({
|
|
|
397
411
|
const inlineImportmapUrlInfo = importmapReference.urlInfo;
|
|
398
412
|
actions.push(async () => {
|
|
399
413
|
await inlineImportmapUrlInfo.cook();
|
|
400
|
-
|
|
401
|
-
JSON.parse(inlineImportmapUrlInfo.content),
|
|
402
|
-
);
|
|
414
|
+
importmapLoaded(inlineImportmapUrlInfo);
|
|
403
415
|
mutations.push(() => {
|
|
404
416
|
setHtmlNodeText(
|
|
405
417
|
scriptNode,
|
|
@@ -515,7 +527,7 @@ export const jsenvPluginHtmlReferenceAnalysis = ({
|
|
|
515
527
|
},
|
|
516
528
|
});
|
|
517
529
|
if (!importmapFound) {
|
|
518
|
-
|
|
530
|
+
importmapLoaded();
|
|
519
531
|
}
|
|
520
532
|
finalizeCallbacks.forEach((finalizeCallback) => {
|
|
521
533
|
finalizeCallback();
|