@jsenv/js-module-fallback 1.0.1 → 1.0.4
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/js-module-fallback",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"/src/"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@babel/parser": "7.
|
|
28
|
+
"@babel/parser": "7.22.4",
|
|
29
29
|
"@babel/plugin-proposal-dynamic-import": "7.18.6",
|
|
30
30
|
"@babel/plugin-transform-modules-umd": "7.18.6",
|
|
31
|
-
"@babel/plugin-transform-modules-systemjs": "7.
|
|
32
|
-
"
|
|
33
|
-
"@jsenv/
|
|
31
|
+
"@babel/plugin-transform-modules-systemjs": "7.22.3",
|
|
32
|
+
"babel-plugin-transform-async-to-promises": "0.8.18",
|
|
33
|
+
"@jsenv/ast": "4.0.3",
|
|
34
34
|
"@jsenv/sourcemap": "1.0.10",
|
|
35
35
|
"@jsenv/urls": "2.0.0"
|
|
36
36
|
},
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
} from "@jsenv/sourcemap";
|
|
9
9
|
import { applyBabelPlugins } from "@jsenv/ast";
|
|
10
10
|
|
|
11
|
-
import { requireBabelPlugin } from "./internal/require_babel_plugin.js";
|
|
12
11
|
import { babelPluginTransformImportMetaUrl } from "./internal/babel_plugin_transform_import_meta_url.js";
|
|
13
12
|
import { babelPluginTransformImportMetaResolve } from "./internal/babel_plugin_transform_import_meta_resolve.js";
|
|
14
13
|
// because of https://github.com/rpetrich/babel-plugin-transform-async-to-promises/issues/84
|
|
@@ -24,31 +23,23 @@ export const systemJsClientFileUrlDefault = new URL(
|
|
|
24
23
|
export const convertJsModuleToJsClassic = async ({
|
|
25
24
|
systemJsInjection,
|
|
26
25
|
systemJsClientFileUrl = systemJsClientFileUrlDefault,
|
|
27
|
-
urlInfo,
|
|
28
|
-
jsModuleUrlInfo,
|
|
29
|
-
}) => {
|
|
30
|
-
let jsClassicFormat;
|
|
31
|
-
if (urlInfo.isEntryPoint && !jsModuleUrlInfo.data.usesImport) {
|
|
32
|
-
// if it's an entry point without dependency (it does not use import)
|
|
33
|
-
// then we can use UMD
|
|
34
|
-
jsClassicFormat = "umd";
|
|
35
|
-
} else {
|
|
36
|
-
// otherwise we have to use system in case it's imported
|
|
37
|
-
// by an other file (for entry points)
|
|
38
|
-
// or to be able to import when it uses import
|
|
39
|
-
jsClassicFormat = "system";
|
|
40
|
-
}
|
|
41
26
|
|
|
42
|
-
|
|
27
|
+
input,
|
|
28
|
+
inputIsEntryPoint,
|
|
29
|
+
inputSourcemap,
|
|
30
|
+
inputUrl,
|
|
31
|
+
outputUrl,
|
|
32
|
+
outputFormat = "system", // "systemjs" or "umd"
|
|
33
|
+
}) => {
|
|
43
34
|
const { code, map } = await applyBabelPlugins({
|
|
44
35
|
babelPlugins: [
|
|
45
|
-
...(
|
|
36
|
+
...(outputFormat === "system"
|
|
46
37
|
? [
|
|
47
38
|
// proposal-dynamic-import required with systemjs for babel8:
|
|
48
39
|
// https://github.com/babel/babel/issues/10746
|
|
49
40
|
require("@babel/plugin-proposal-dynamic-import"),
|
|
50
41
|
require("@babel/plugin-transform-modules-systemjs"),
|
|
51
|
-
[babelPluginRelativeImports, { rootUrl:
|
|
42
|
+
[babelPluginRelativeImports, { rootUrl: inputUrl }],
|
|
52
43
|
[
|
|
53
44
|
customAsyncToPromises,
|
|
54
45
|
{
|
|
@@ -59,7 +50,7 @@ export const convertJsModuleToJsClassic = async ({
|
|
|
59
50
|
]
|
|
60
51
|
: [
|
|
61
52
|
[
|
|
62
|
-
|
|
53
|
+
require("babel-plugin-transform-async-to-promises"),
|
|
63
54
|
{
|
|
64
55
|
asyncAwait: false, // already handled + we might not needs it at all
|
|
65
56
|
topLevelAwait: "simple",
|
|
@@ -68,18 +59,17 @@ export const convertJsModuleToJsClassic = async ({
|
|
|
68
59
|
babelPluginTransformImportMetaUrl,
|
|
69
60
|
babelPluginTransformImportMetaResolve,
|
|
70
61
|
require("@babel/plugin-transform-modules-umd"),
|
|
71
|
-
[babelPluginRelativeImports, { rootUrl:
|
|
62
|
+
[babelPluginRelativeImports, { rootUrl: inputUrl }],
|
|
72
63
|
]),
|
|
73
64
|
],
|
|
74
|
-
|
|
65
|
+
input,
|
|
66
|
+
inputIsJsModule: true,
|
|
67
|
+
inputUrl,
|
|
68
|
+
outputUrl,
|
|
75
69
|
});
|
|
76
|
-
let sourcemap =
|
|
70
|
+
let sourcemap = inputSourcemap;
|
|
77
71
|
sourcemap = await composeTwoSourcemaps(sourcemap, map);
|
|
78
|
-
if (
|
|
79
|
-
systemJsInjection &&
|
|
80
|
-
jsClassicFormat === "system" &&
|
|
81
|
-
urlInfo.isEntryPoint
|
|
82
|
-
) {
|
|
72
|
+
if (systemJsInjection && outputFormat === "system" && inputIsEntryPoint) {
|
|
83
73
|
const magicSource = createMagicSource(code);
|
|
84
74
|
let systemJsFileContent = readFileSync(
|
|
85
75
|
new URL(systemJsClientFileUrl),
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import { pathToFileURL } from "node:url";
|
|
3
|
-
|
|
4
|
-
const require = createRequire(import.meta.url);
|
|
5
|
-
const babelPluginPackagePath = require.resolve("@jsenv/babel-plugins");
|
|
6
|
-
const babelPluginPackageUrl = pathToFileURL(babelPluginPackagePath);
|
|
7
|
-
|
|
8
|
-
export const requireBabelPlugin = createRequire(babelPluginPackageUrl);
|