@jsenv/js-module-fallback 1.0.3 → 1.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/js-module-fallback",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,15 +22,16 @@
22
22
  },
23
23
  "main": "./src/main.js",
24
24
  "files": [
25
- "/src/"
25
+ "/src/",
26
+ "/dist/"
26
27
  ],
27
28
  "dependencies": {
28
- "@babel/parser": "7.22.4",
29
+ "@babel/parser": "7.22.5",
29
30
  "@babel/plugin-proposal-dynamic-import": "7.18.6",
30
- "@babel/plugin-transform-modules-umd": "7.18.6",
31
- "@babel/plugin-transform-modules-systemjs": "7.22.3",
31
+ "@babel/plugin-transform-modules-umd": "7.22.5",
32
+ "@babel/plugin-transform-modules-systemjs": "7.22.5",
32
33
  "babel-plugin-transform-async-to-promises": "0.8.18",
33
- "@jsenv/ast": "4.0.3",
34
+ "@jsenv/ast": "4.1.0",
34
35
  "@jsenv/sourcemap": "1.0.10",
35
36
  "@jsenv/urls": "2.0.0"
36
37
  },
@@ -1,11 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
- import { readFileSync } from "node:fs";
3
2
  import { urlToRelativeUrl } from "@jsenv/urls";
4
- import {
5
- createMagicSource,
6
- composeTwoSourcemaps,
7
- SOURCEMAP,
8
- } from "@jsenv/sourcemap";
3
+ import { composeTwoSourcemaps } from "@jsenv/sourcemap";
9
4
  import { applyBabelPlugins } from "@jsenv/ast";
10
5
 
11
6
  import { babelPluginTransformImportMetaUrl } from "./internal/babel_plugin_transform_import_meta_url.js";
@@ -13,19 +8,15 @@ import { babelPluginTransformImportMetaResolve } from "./internal/babel_plugin_t
13
8
  // because of https://github.com/rpetrich/babel-plugin-transform-async-to-promises/issues/84
14
9
  import customAsyncToPromises from "./internal/async-to-promises.js";
15
10
 
16
- const require = createRequire(import.meta.url);
17
-
18
11
  export const systemJsClientFileUrlDefault = new URL(
19
12
  "./client/s.js",
20
13
  import.meta.url,
21
14
  ).href;
22
15
 
23
- export const convertJsModuleToJsClassic = async ({
24
- systemJsInjection,
25
- systemJsClientFileUrl = systemJsClientFileUrlDefault,
16
+ const require = createRequire(import.meta.url);
26
17
 
18
+ export const convertJsModuleToJsClassic = async ({
27
19
  input,
28
- inputIsEntryPoint,
29
20
  inputSourcemap,
30
21
  inputUrl,
31
22
  outputUrl,
@@ -38,8 +29,8 @@ export const convertJsModuleToJsClassic = async ({
38
29
  // proposal-dynamic-import required with systemjs for babel8:
39
30
  // https://github.com/babel/babel/issues/10746
40
31
  require("@babel/plugin-proposal-dynamic-import"),
41
- require("@babel/plugin-transform-modules-systemjs"),
42
32
  [babelPluginRelativeImports, { rootUrl: inputUrl }],
33
+ require("@babel/plugin-transform-modules-systemjs"),
43
34
  [
44
35
  customAsyncToPromises,
45
36
  {
@@ -58,8 +49,8 @@ export const convertJsModuleToJsClassic = async ({
58
49
  ],
59
50
  babelPluginTransformImportMetaUrl,
60
51
  babelPluginTransformImportMetaResolve,
61
- require("@babel/plugin-transform-modules-umd"),
62
52
  [babelPluginRelativeImports, { rootUrl: inputUrl }],
53
+ require("@babel/plugin-transform-modules-umd"),
63
54
  ]),
64
55
  ],
65
56
  input,
@@ -67,35 +58,7 @@ export const convertJsModuleToJsClassic = async ({
67
58
  inputUrl,
68
59
  outputUrl,
69
60
  });
70
- let sourcemap = inputSourcemap;
71
- sourcemap = await composeTwoSourcemaps(sourcemap, map);
72
- if (systemJsInjection && outputFormat === "system" && inputIsEntryPoint) {
73
- const magicSource = createMagicSource(code);
74
- let systemJsFileContent = readFileSync(
75
- new URL(systemJsClientFileUrl),
76
- "utf8",
77
- );
78
- const sourcemapFound = SOURCEMAP.readComment({
79
- contentType: "text/javascript",
80
- content: systemJsFileContent,
81
- });
82
- if (sourcemapFound) {
83
- // for now let's remove s.js sourcemap
84
- // because it would likely mess the sourcemap of the entry point itself
85
- systemJsFileContent = SOURCEMAP.writeComment({
86
- contentType: "text/javascript",
87
- content: systemJsFileContent,
88
- specifier: "",
89
- });
90
- }
91
- magicSource.prepend(`${systemJsFileContent}\n\n`);
92
- const magicResult = magicSource.toContentAndSourcemap();
93
- sourcemap = await composeTwoSourcemaps(sourcemap, magicResult.sourcemap);
94
- return {
95
- content: magicResult.content,
96
- sourcemap,
97
- };
98
- }
61
+ const sourcemap = await composeTwoSourcemaps(inputSourcemap, map);
99
62
  return {
100
63
  content: code,
101
64
  sourcemap,
@@ -114,8 +77,12 @@ const babelPluginRelativeImports = (babel) => {
114
77
  const t = babel.types;
115
78
 
116
79
  const replaceSpecifierAtPath = (path, state) => {
117
- const specifier = path.node.value;
80
+ let specifier = path.node.value;
118
81
  if (specifier.startsWith("file://")) {
82
+ const specifierUrlObject = new URL(specifier);
83
+ const { searchParams } = specifierUrlObject;
84
+ searchParams.delete("dynamic_import");
85
+ specifier = specifierUrlObject.href;
119
86
  const specifierRelative = urlToRelativeUrl(specifier, state.opts.rootUrl);
120
87
  path.replaceWith(t.stringLiteral(specifierRelative));
121
88
  }