@jsenv/plugin-as-js-classic 1.2.0 → 1.2.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-as-js-classic",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,6 +26,6 @@
26
26
  "dependencies": {
27
27
  "@jsenv/urls": "2.0.0",
28
28
  "@jsenv/js-module-fallback": "1.1.0",
29
- "@jsenv/plugin-bundling": "2.2.0"
29
+ "@jsenv/plugin-bundling": "2.2.1"
30
30
  }
31
31
  }
@@ -60,6 +60,29 @@ export const jsenvPluginAsJsClassic = () => {
60
60
  },
61
61
  });
62
62
  const jsModuleBundledUrlInfo = bundleUrlInfos[jsModuleUrlInfo.url];
63
+
64
+ let outputFormat;
65
+ // if imported by js, we have to use systemjs
66
+ // or if import things
67
+ if (
68
+ jsModuleBundledUrlInfo.data.usesImport ||
69
+ isImportedByJs(urlInfo, context.urlGraph)
70
+ ) {
71
+ // we have to use system when it uses import
72
+ outputFormat = "system";
73
+ urlInfo.type = "js_classic";
74
+ context.referenceUtils.foundSideEffectFile({
75
+ sideEffectFileUrl: systemJsClientFileUrlDefault,
76
+ expectedType: "js_classic",
77
+ line: 0,
78
+ column: 0,
79
+ });
80
+ } else {
81
+ // if there is no dependency (it does not use import)
82
+ // then we can use UMD
83
+ outputFormat = "umd";
84
+ }
85
+
63
86
  if (context.dev) {
64
87
  jsModuleBundledUrlInfo.sourceUrls.forEach((sourceUrl) => {
65
88
  context.referenceUtils.inject({
@@ -77,24 +100,6 @@ export const jsenvPluginAsJsClassic = () => {
77
100
  });
78
101
  }
79
102
 
80
- let outputFormat;
81
- if (urlInfo.isEntryPoint && !jsModuleBundledUrlInfo.data.usesImport) {
82
- // if it's an entry point without dependency (it does not use import)
83
- // then we can use UMD
84
- outputFormat = "umd";
85
- } else {
86
- // otherwise we have to use system in case it's imported
87
- // by an other file (for entry points)
88
- // or to be able to import when it uses import
89
- outputFormat = "system";
90
- urlInfo.type = "js_classic";
91
- context.referenceUtils.foundSideEffectFile({
92
- sideEffectFileUrl: systemJsClientFileUrlDefault,
93
- expectedType: "js_classic",
94
- line: 0,
95
- column: 0,
96
- });
97
- }
98
103
  const { content, sourcemap } = await convertJsModuleToJsClassic({
99
104
  rootDirectoryUrl: context.rootDirectoryUrl,
100
105
  input: jsModuleBundledUrlInfo.content,
@@ -116,6 +121,19 @@ export const jsenvPluginAsJsClassic = () => {
116
121
  };
117
122
  };
118
123
 
124
+ const isImportedByJs = (jsModuleUrlInfo, urlGraph) => {
125
+ for (const dependentUrl of jsModuleUrlInfo.dependents) {
126
+ const dependentUrlInfo = urlGraph.getUrlInfo(dependentUrl);
127
+ if (
128
+ dependentUrlInfo.type === "js_module" ||
129
+ dependentUrlInfo.type === "js_classic"
130
+ ) {
131
+ return true;
132
+ }
133
+ }
134
+ return false;
135
+ };
136
+
119
137
  const generateJsClassicFilename = (url) => {
120
138
  const filename = urlToFilename(url);
121
139
  let [basename, extension] = splitFileExtension(filename);