@jsenv/plugin-as-js-classic 1.0.14 → 1.1.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/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-as-js-classic",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/jsenv/core",
|
|
8
|
-
"directory": "packages/jsenv-plugin-as-js-classic"
|
|
8
|
+
"directory": "packages/plugins/jsenv-plugin-as-js-classic"
|
|
9
9
|
},
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
@@ -24,10 +24,8 @@
|
|
|
24
24
|
"test": "node --conditions=development ./scripts/test.mjs"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@jsenv/
|
|
27
|
+
"@jsenv/urls": "2.0.0",
|
|
28
|
+
"@jsenv/js-module-fallback": "1.0.1",
|
|
28
29
|
"@jsenv/plugin-bundling": "2.1.10"
|
|
29
|
-
},
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@jsenv/core": "../../"
|
|
32
30
|
}
|
|
33
31
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { urlToFilename } from "@jsenv/urls";
|
|
2
|
+
import { convertJsModuleToJsClassic } from "@jsenv/js-module-fallback";
|
|
2
3
|
import { bundleJsModules } from "@jsenv/plugin-bundling";
|
|
3
4
|
|
|
4
|
-
import { createUrlGraphLoader } from "
|
|
5
|
-
import { convertJsModuleToJsClassic } from "@jsenv/core/src/plugins/transpilation/js_module_fallback/convert_js_module_to_js_classic.js";
|
|
5
|
+
import { createUrlGraphLoader } from "./url_graph_loader.js";
|
|
6
6
|
|
|
7
7
|
export const jsenvPluginAsJsClassic = ({
|
|
8
8
|
systemJsInjection = true,
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// copy pasted from @jsenv/core to avoid dependency
|
|
2
|
+
|
|
3
|
+
export const createUrlGraphLoader = (context) => {
|
|
4
|
+
const promises = [];
|
|
5
|
+
const promiseMap = new Map();
|
|
6
|
+
const load = (
|
|
7
|
+
urlInfo,
|
|
8
|
+
dishContext,
|
|
9
|
+
{ ignoreRessourceHint = true, ignoreDynamicImport = false } = {},
|
|
10
|
+
) => {
|
|
11
|
+
const promiseFromData = promiseMap.get(urlInfo);
|
|
12
|
+
if (promiseFromData) return promiseFromData;
|
|
13
|
+
const promise = (async () => {
|
|
14
|
+
await context.cook(urlInfo, {
|
|
15
|
+
cookDuringCook: load,
|
|
16
|
+
...dishContext,
|
|
17
|
+
});
|
|
18
|
+
loadReferencedUrlInfos(urlInfo, {
|
|
19
|
+
ignoreRessourceHint,
|
|
20
|
+
ignoreDynamicImport,
|
|
21
|
+
});
|
|
22
|
+
})();
|
|
23
|
+
promises.push(promise);
|
|
24
|
+
promiseMap.set(urlInfo, promise);
|
|
25
|
+
return promise;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const loadReferencedUrlInfos = (
|
|
29
|
+
urlInfo,
|
|
30
|
+
{ ignoreRessourceHint, ignoreDynamicImport },
|
|
31
|
+
) => {
|
|
32
|
+
const { references } = urlInfo;
|
|
33
|
+
references.forEach((reference) => {
|
|
34
|
+
// we don't cook resource hints
|
|
35
|
+
// because they might refer to resource that will be modified during build
|
|
36
|
+
// It also means something else have to reference that url in order to cook it
|
|
37
|
+
// so that the preload is deleted by "resync_resource_hints.js" otherwise
|
|
38
|
+
if (ignoreRessourceHint && reference.isResourceHint) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (ignoreDynamicImport && reference.subtype === "import_dynamic") {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
// we use reference.generatedUrl to mimic what a browser would do:
|
|
45
|
+
// do a fetch to the specifier as found in the file
|
|
46
|
+
const referencedUrlInfo = context.urlGraph.reuseOrCreateUrlInfo(
|
|
47
|
+
reference.generatedUrl,
|
|
48
|
+
);
|
|
49
|
+
load(referencedUrlInfo, {
|
|
50
|
+
reference,
|
|
51
|
+
ignoreRessourceHint,
|
|
52
|
+
ignoreDynamicImport,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const getAllLoadDonePromise = async (operation) => {
|
|
58
|
+
const waitAll = async () => {
|
|
59
|
+
if (operation) {
|
|
60
|
+
operation.throwIfAborted();
|
|
61
|
+
}
|
|
62
|
+
if (promises.length === 0) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const promisesToWait = promises.slice();
|
|
66
|
+
promises.length = 0;
|
|
67
|
+
await Promise.all(promisesToWait);
|
|
68
|
+
await waitAll();
|
|
69
|
+
};
|
|
70
|
+
await waitAll();
|
|
71
|
+
promiseMap.clear();
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
load,
|
|
76
|
+
loadReferencedUrlInfos,
|
|
77
|
+
getAllLoadDonePromise,
|
|
78
|
+
};
|
|
79
|
+
};
|