@jsenv/core 28.2.0 → 28.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/dist/main.js CHANGED
@@ -3741,6 +3741,9 @@ const createUrlGraph = () => {
3741
3741
 
3742
3742
  if (urlInfo) {
3743
3743
  urlInfoMap.delete(url);
3744
+ urlInfo.dependencies.forEach(dependencyUrl => {
3745
+ getUrlInfo(dependencyUrl).dependents.delete(url);
3746
+ });
3744
3747
 
3745
3748
  if (urlInfo.sourcemapReference) {
3746
3749
  deleteUrlInfo(urlInfo.sourcemapReference.url);
@@ -10034,7 +10037,10 @@ const convertJsModuleToJsClassic = async ({
10034
10037
  };
10035
10038
  };
10036
10039
 
10037
- // propagate ?as_js_classic to referenced urls
10040
+ /*
10041
+ * - propagate ?as_js_classic to urls
10042
+ * - perform conversion from js module to js classic when url uses ?as_js_classic
10043
+ */
10038
10044
  const jsenvPluginAsJsClassicConversion = ({
10039
10045
  systemJsInjection,
10040
10046
  systemJsClientFileUrl,
@@ -11008,6 +11014,14 @@ const jsenvPluginAsJsClassicLibrary = ({
11008
11014
  isImplicit: true
11009
11015
  });
11010
11016
  });
11017
+ } else if (context.scenarios.build) {
11018
+ jsModuleBundledUrlInfo.sourceUrls.forEach(sourceUrl => {
11019
+ const sourceUrlInfo = context.urlGraph.getUrlInfo(sourceUrl);
11020
+
11021
+ if (sourceUrlInfo.dependents.size === 0) {
11022
+ context.urlGraph.deleteUrlInfo(sourceUrl);
11023
+ }
11024
+ });
11011
11025
  }
11012
11026
 
11013
11027
  const {
@@ -11023,7 +11037,7 @@ const jsenvPluginAsJsClassicLibrary = ({
11023
11037
  content,
11024
11038
  contentType: "text/javascript",
11025
11039
  type: "js_classic",
11026
- originalUrl: jsModuleUrlInfo.originalUrl,
11040
+ originalUrl: urlInfo.originalUrl,
11027
11041
  originalContent: jsModuleUrlInfo.originalContent,
11028
11042
  sourcemap
11029
11043
  };
@@ -18865,7 +18879,8 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
18865
18879
  specifier: context.reference.specifier.replace(`?${searchParam}`, "").replace(`&${searchParam}`, ""),
18866
18880
  url: urlObject.href,
18867
18881
  generatedSpecifier: null,
18868
- generatedUrl: null
18882
+ generatedUrl: null,
18883
+ filename: null
18869
18884
  };
18870
18885
  const urlInfoWithoutSearchParam = context.urlGraph.reuseOrCreateUrlInfo(referenceWithoutSearchParam.url);
18871
18886
 
@@ -18971,7 +18986,7 @@ const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
18971
18986
  urlInfo.injected = true;
18972
18987
  }
18973
18988
 
18974
- if (reference.filename) {
18989
+ if (reference.filename && !urlInfo.filename) {
18975
18990
  urlInfo.filename = reference.filename;
18976
18991
  }
18977
18992
 
@@ -19916,7 +19931,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
19916
19931
  });
19917
19932
  const finalGraphKitchen = createKitchen({
19918
19933
  logLevel,
19919
- rootDirectoryUrl,
19934
+ rootDirectoryUrl: buildDirectoryUrl,
19920
19935
  urlGraph: finalGraph,
19921
19936
  scenarios: {
19922
19937
  build: true
@@ -20297,6 +20312,15 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
20297
20312
  };
20298
20313
 
20299
20314
  GRAPH.forEach(rawGraph, rawUrlInfo => {
20315
+ // cleanup unused urls (avoid bundling things that are not actually used)
20316
+ // happens for:
20317
+ // - js import assertions
20318
+ // - as_js_classic_library
20319
+ if (!isUsed(rawUrlInfo)) {
20320
+ rawGraph.deleteUrlInfo(rawUrlInfo.url);
20321
+ return;
20322
+ }
20323
+
20300
20324
  if (rawUrlInfo.isEntryPoint) {
20301
20325
  addToBundlerIfAny(rawUrlInfo);
20302
20326
 
@@ -20845,11 +20869,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
20845
20869
  {
20846
20870
  const actions = [];
20847
20871
  GRAPH.forEach(finalGraph, urlInfo => {
20848
- // nothing uses this url anymore
20849
- // - versioning update inline content
20850
- // - file converted for import assertion or js_classic conversion
20851
- if (!urlInfo.isEntryPoint && urlInfo.type !== "sourcemap" && urlInfo.dependents.size === 0 && !urlInfo.injected // injected during postbuild
20852
- ) {
20872
+ if (!isUsed(urlInfo)) {
20853
20873
  actions.push(() => {
20854
20874
  finalGraph.deleteUrlInfo(urlInfo.url);
20855
20875
  });
@@ -21146,6 +21166,29 @@ const assertEntryPoints = ({
21146
21166
  });
21147
21167
  };
21148
21168
 
21169
+ const isUsed = urlInfo => {
21170
+ // nothing uses this url anymore
21171
+ // - versioning update inline content
21172
+ // - file converted for import assertion or js_classic conversion
21173
+ if (urlInfo.isEntryPoint) {
21174
+ return true;
21175
+ }
21176
+
21177
+ if (urlInfo.type === "sourcemap") {
21178
+ return true;
21179
+ }
21180
+
21181
+ if (urlInfo.injected) {
21182
+ return true;
21183
+ }
21184
+
21185
+ if (urlInfo.dependents.size > 0) {
21186
+ return true;
21187
+ }
21188
+
21189
+ return false;
21190
+ };
21191
+
21149
21192
  const canUseVersionedUrl = urlInfo => {
21150
21193
  if (urlInfo.isEntryPoint) {
21151
21194
  return false;
@@ -25778,7 +25821,9 @@ const startDevServer = async ({
25778
25821
  sourcemaps = "inline",
25779
25822
  sourcemapsSourcesProtocol,
25780
25823
  sourcemapsSourcesContent,
25781
- writeGeneratedFiles = true
25824
+ // no real need to write files during github workflow
25825
+ // and mitigates https://github.com/actions/runner-images/issues/3885
25826
+ writeGeneratedFiles = !process.env.CI
25782
25827
  }) => {
25783
25828
  const logger = createLogger({
25784
25829
  logLevel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "28.2.0",
3
+ "version": "28.2.1",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -103,7 +103,7 @@
103
103
  "@jsenv/eslint-config": "16.2.1",
104
104
  "@jsenv/file-size-impact": "13.0.1",
105
105
  "@jsenv/https-local": "3.0.1",
106
- "@jsenv/package-workspace": "0.4.1",
106
+ "@jsenv/package-workspace": "0.5.0",
107
107
  "@jsenv/performance-impact": "3.0.1",
108
108
  "eslint": "8.21.0",
109
109
  "eslint-plugin-html": "7.1.0",
@@ -264,7 +264,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
264
264
  })
265
265
  const finalGraphKitchen = createKitchen({
266
266
  logLevel,
267
- rootDirectoryUrl,
267
+ rootDirectoryUrl: buildDirectoryUrl,
268
268
  urlGraph: finalGraph,
269
269
  scenarios: { build: true },
270
270
  runtimeCompat,
@@ -643,6 +643,14 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
643
643
  }
644
644
  }
645
645
  GRAPH.forEach(rawGraph, (rawUrlInfo) => {
646
+ // cleanup unused urls (avoid bundling things that are not actually used)
647
+ // happens for:
648
+ // - js import assertions
649
+ // - as_js_classic_library
650
+ if (!isUsed(rawUrlInfo)) {
651
+ rawGraph.deleteUrlInfo(rawUrlInfo.url)
652
+ return
653
+ }
646
654
  if (rawUrlInfo.isEntryPoint) {
647
655
  addToBundlerIfAny(rawUrlInfo)
648
656
  if (rawUrlInfo.type === "html") {
@@ -1216,15 +1224,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
1216
1224
  delete_unused_urls: {
1217
1225
  const actions = []
1218
1226
  GRAPH.forEach(finalGraph, (urlInfo) => {
1219
- // nothing uses this url anymore
1220
- // - versioning update inline content
1221
- // - file converted for import assertion or js_classic conversion
1222
- if (
1223
- !urlInfo.isEntryPoint &&
1224
- urlInfo.type !== "sourcemap" &&
1225
- urlInfo.dependents.size === 0 &&
1226
- !urlInfo.injected // injected during postbuild
1227
- ) {
1227
+ if (!isUsed(urlInfo)) {
1228
1228
  actions.push(() => {
1229
1229
  finalGraph.deleteUrlInfo(urlInfo.url)
1230
1230
  })
@@ -1501,6 +1501,25 @@ const assertEntryPoints = ({ entryPoints }) => {
1501
1501
  })
1502
1502
  }
1503
1503
 
1504
+ const isUsed = (urlInfo) => {
1505
+ // nothing uses this url anymore
1506
+ // - versioning update inline content
1507
+ // - file converted for import assertion or js_classic conversion
1508
+ if (urlInfo.isEntryPoint) {
1509
+ return true
1510
+ }
1511
+ if (urlInfo.type === "sourcemap") {
1512
+ return true
1513
+ }
1514
+ if (urlInfo.injected) {
1515
+ return true
1516
+ }
1517
+ if (urlInfo.dependents.size > 0) {
1518
+ return true
1519
+ }
1520
+ return false
1521
+ }
1522
+
1504
1523
  const canUseVersionedUrl = (urlInfo) => {
1505
1524
  if (urlInfo.isEntryPoint) {
1506
1525
  return false
@@ -68,7 +68,9 @@ export const startDevServer = async ({
68
68
  sourcemaps = "inline",
69
69
  sourcemapsSourcesProtocol,
70
70
  sourcemapsSourcesContent,
71
- writeGeneratedFiles = true,
71
+ // no real need to write files during github workflow
72
+ // and mitigates https://github.com/actions/runner-images/issues/3885
73
+ writeGeneratedFiles = !process.env.CI,
72
74
  }) => {
73
75
  const logger = createLogger({ logLevel })
74
76
  rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
@@ -714,6 +714,7 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
714
714
  url: urlObject.href,
715
715
  generatedSpecifier: null,
716
716
  generatedUrl: null,
717
+ filename: null,
717
718
  }
718
719
  const urlInfoWithoutSearchParam = context.urlGraph.reuseOrCreateUrlInfo(
719
720
  referenceWithoutSearchParam.url,
@@ -813,7 +814,7 @@ const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
813
814
  if (reference.injected) {
814
815
  urlInfo.injected = true
815
816
  }
816
- if (reference.filename) {
817
+ if (reference.filename && !urlInfo.filename) {
817
818
  urlInfo.filename = reference.filename
818
819
  }
819
820
  if (reference.isInline) {
@@ -12,6 +12,9 @@ export const createUrlGraph = () => {
12
12
  const urlInfo = urlInfoMap.get(url)
13
13
  if (urlInfo) {
14
14
  urlInfoMap.delete(url)
15
+ urlInfo.dependencies.forEach((dependencyUrl) => {
16
+ getUrlInfo(dependencyUrl).dependents.delete(url)
17
+ })
15
18
  if (urlInfo.sourcemapReference) {
16
19
  deleteUrlInfo(urlInfo.sourcemapReference.url)
17
20
  }
@@ -1,5 +1,7 @@
1
- // propagate ?as_js_classic to referenced urls
2
- // and perform the conversion during fetchUrlContent
1
+ /*
2
+ * - propagate ?as_js_classic to urls
3
+ * - perform conversion from js module to js classic when url uses ?as_js_classic
4
+ */
3
5
 
4
6
  import { injectQueryParams } from "@jsenv/urls"
5
7
  import { convertJsModuleToJsClassic } from "./convert_js_module_to_js_classic.js"
@@ -64,6 +64,13 @@ export const jsenvPluginAsJsClassicLibrary = ({
64
64
  isImplicit: true,
65
65
  })
66
66
  })
67
+ } else if (context.scenarios.build) {
68
+ jsModuleBundledUrlInfo.sourceUrls.forEach((sourceUrl) => {
69
+ const sourceUrlInfo = context.urlGraph.getUrlInfo(sourceUrl)
70
+ if (sourceUrlInfo.dependents.size === 0) {
71
+ context.urlGraph.deleteUrlInfo(sourceUrl)
72
+ }
73
+ })
67
74
  }
68
75
  const { content, sourcemap } = await convertJsModuleToJsClassic({
69
76
  systemJsInjection,
@@ -75,7 +82,7 @@ export const jsenvPluginAsJsClassicLibrary = ({
75
82
  content,
76
83
  contentType: "text/javascript",
77
84
  type: "js_classic",
78
- originalUrl: jsModuleUrlInfo.originalUrl,
85
+ originalUrl: urlInfo.originalUrl,
79
86
  originalContent: jsModuleUrlInfo.originalContent,
80
87
  sourcemap,
81
88
  }