@jsenv/core 37.0.5 → 37.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "37.0.5",
3
+ "version": "37.1.1",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -69,7 +69,7 @@
69
69
  "@jsenv/node-esm-resolution": "1.0.1",
70
70
  "@jsenv/js-module-fallback": "1.2.0",
71
71
  "@jsenv/runtime-compat": "1.1.0",
72
- "@jsenv/server": "15.0.4",
72
+ "@jsenv/server": "15.1.0",
73
73
  "@jsenv/sourcemap": "1.1.0",
74
74
  "@jsenv/plugin-transpilation": "1.2.1",
75
75
  "@jsenv/plugin-supervisor": "1.2.0",
@@ -347,7 +347,7 @@ build ${entryPointKeys.length} entry points`);
347
347
  sourcemaps,
348
348
  sourcemapsSourcesContent,
349
349
  outDirectoryUrl: outDirectoryUrl
350
- ? new URL("build/", outDirectoryUrl)
350
+ ? new URL("prebuild/", outDirectoryUrl)
351
351
  : undefined,
352
352
  });
353
353
 
@@ -602,13 +602,6 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
602
602
  rawUrlInfo.url,
603
603
  "raw file",
604
604
  );
605
- if (buildUrl.includes("?")) {
606
- associateBuildUrlAndRawUrl(
607
- asUrlWithoutSearch(buildUrl),
608
- rawUrlInfo.url,
609
- "raw file",
610
- );
611
- }
612
605
  return buildUrl;
613
606
  }
614
607
  if (reference.type === "sourcemap_comment") {
@@ -822,84 +815,86 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
822
815
  bundler.urlInfoMap.set(rawUrlInfo.url, rawUrlInfo);
823
816
  }
824
817
  };
825
- GRAPH_VISITOR.forEach(rawKitchen.graph, (rawUrlInfo) => {
826
- // ignore unused urls (avoid bundling things that are not actually used)
827
- // happens for:
828
- // - js import assertions
829
- // - conversion to js classic using ?as_js_classic or ?js_module_fallback
830
- if (!rawUrlInfo.isUsed()) {
831
- return;
832
- }
833
- if (rawUrlInfo.isEntryPoint) {
834
- addToBundlerIfAny(rawUrlInfo);
835
- }
836
- if (rawUrlInfo.type === "html") {
837
- rawUrlInfo.referenceToOthersSet.forEach((referenceToOther) => {
838
- if (referenceToOther.isWeak) {
839
- return;
840
- }
841
- const referencedUrlInfo = referenceToOther.urlInfo;
842
- if (referencedUrlInfo.isInline) {
843
- if (referencedUrlInfo.type === "js_module") {
844
- // bundle inline script type module deps
845
- referencedUrlInfo.referenceToOthersSet.forEach(
846
- (jsModuleReferenceToOther) => {
847
- if (jsModuleReferenceToOther.type === "js_import") {
848
- const inlineUrlInfo = jsModuleReferenceToOther.urlInfo;
849
- addToBundlerIfAny(inlineUrlInfo);
850
- }
851
- },
852
- );
818
+ // ignore unused urls thanks to "forEachUrlInfoStronglyReferenced"
819
+ // it avoid bundling things that are not actually used
820
+ // happens for:
821
+ // - js import assertions
822
+ // - conversion to js classic using ?as_js_classic or ?js_module_fallback
823
+ GRAPH_VISITOR.forEachUrlInfoStronglyReferenced(
824
+ rawKitchen.graph.rootUrlInfo,
825
+ (rawUrlInfo) => {
826
+ if (rawUrlInfo.isEntryPoint) {
827
+ addToBundlerIfAny(rawUrlInfo);
828
+ }
829
+ if (rawUrlInfo.type === "html") {
830
+ rawUrlInfo.referenceToOthersSet.forEach((referenceToOther) => {
831
+ if (referenceToOther.isWeak) {
832
+ return;
853
833
  }
854
- // inline content cannot be bundled
855
- return;
856
- }
857
- addToBundlerIfAny(referencedUrlInfo);
858
- });
859
- rawUrlInfo.referenceToOthersSet.forEach((referenceToOther) => {
860
- if (
861
- referenceToOther.isResourceHint &&
862
- referenceToOther.expectedType === "js_module"
863
- ) {
864
834
  const referencedUrlInfo = referenceToOther.urlInfo;
835
+ if (referencedUrlInfo.isInline) {
836
+ if (referencedUrlInfo.type === "js_module") {
837
+ // bundle inline script type module deps
838
+ referencedUrlInfo.referenceToOthersSet.forEach(
839
+ (jsModuleReferenceToOther) => {
840
+ if (jsModuleReferenceToOther.type === "js_import") {
841
+ const inlineUrlInfo =
842
+ jsModuleReferenceToOther.urlInfo;
843
+ addToBundlerIfAny(inlineUrlInfo);
844
+ }
845
+ },
846
+ );
847
+ }
848
+ // inline content cannot be bundled
849
+ return;
850
+ }
851
+ addToBundlerIfAny(referencedUrlInfo);
852
+ });
853
+ rawUrlInfo.referenceToOthersSet.forEach((referenceToOther) => {
865
854
  if (
866
- referencedUrlInfo &&
867
- // something else than the resource hint is using this url
868
- referencedUrlInfo.referenceFromOthersSet.size > 0
855
+ referenceToOther.isResourceHint &&
856
+ referenceToOther.expectedType === "js_module"
869
857
  ) {
870
- addToBundlerIfAny(referencedUrlInfo);
858
+ const referencedUrlInfo = referenceToOther.urlInfo;
859
+ if (
860
+ referencedUrlInfo &&
861
+ // something else than the resource hint is using this url
862
+ referencedUrlInfo.referenceFromOthersSet.size > 0
863
+ ) {
864
+ addToBundlerIfAny(referencedUrlInfo);
865
+ }
871
866
  }
872
- }
873
- });
874
- return;
875
- }
876
- // File referenced with new URL('./file.js', import.meta.url)
877
- // are entry points that should be bundled
878
- // For instance we will bundle service worker/workers detected like this
879
- if (rawUrlInfo.type === "js_module") {
880
- rawUrlInfo.referenceToOthersSet.forEach((referenceToOther) => {
881
- if (referenceToOther.type === "js_url") {
882
- const referencedUrlInfo = referenceToOther.urlInfo;
883
- for (const referenceFromOther of referencedUrlInfo.referenceFromOthersSet) {
884
- if (referenceFromOther.url === referencedUrlInfo.url) {
885
- if (
886
- referenceFromOther.subtype === "import_dynamic" ||
887
- referenceFromOther.type === "script"
888
- ) {
889
- // will already be bundled
890
- return;
867
+ });
868
+ return;
869
+ }
870
+ // File referenced with new URL('./file.js', import.meta.url)
871
+ // are entry points that should be bundled
872
+ // For instance we will bundle service worker/workers detected like this
873
+ if (rawUrlInfo.type === "js_module") {
874
+ rawUrlInfo.referenceToOthersSet.forEach((referenceToOther) => {
875
+ if (referenceToOther.type === "js_url") {
876
+ const referencedUrlInfo = referenceToOther.urlInfo;
877
+ for (const referenceFromOther of referencedUrlInfo.referenceFromOthersSet) {
878
+ if (referenceFromOther.url === referencedUrlInfo.url) {
879
+ if (
880
+ referenceFromOther.subtype === "import_dynamic" ||
881
+ referenceFromOther.type === "script"
882
+ ) {
883
+ // will already be bundled
884
+ return;
885
+ }
891
886
  }
892
887
  }
888
+ addToBundlerIfAny(referencedUrlInfo);
889
+ return;
893
890
  }
894
- addToBundlerIfAny(referencedUrlInfo);
895
- return;
896
- }
897
- if (referenceToOther.type === "js_inline_content") {
898
- // we should bundle it too right?
899
- }
900
- });
901
- }
902
- });
891
+ if (referenceToOther.type === "js_inline_content") {
892
+ // we should bundle it too right?
893
+ }
894
+ });
895
+ }
896
+ },
897
+ );
903
898
  await Object.keys(bundlers).reduce(async (previous, type) => {
904
899
  await previous;
905
900
  const bundler = bundlers[type];
@@ -1209,24 +1204,14 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
1209
1204
  resyncTask.done();
1210
1205
  }
1211
1206
  }
1212
- delete_unused_urls: {
1213
- const actions = [];
1214
- GRAPH_VISITOR.forEach(finalKitchen.graph, (urlInfo) => {
1215
- if (!urlInfo.isUsed()) {
1216
- actions.push(() => {
1217
- urlInfo.deleteFromGraph();
1218
- });
1219
- }
1220
- });
1221
- actions.forEach((action) => action());
1222
- }
1223
1207
  inject_urls_in_service_workers: {
1224
1208
  const serviceWorkerEntryUrlInfos = GRAPH_VISITOR.filter(
1225
1209
  finalKitchen.graph,
1226
1210
  (finalUrlInfo) => {
1227
1211
  return (
1228
1212
  finalUrlInfo.subtype === "service_worker" &&
1229
- finalUrlInfo.isEntryPoint
1213
+ finalUrlInfo.isEntryPoint &&
1214
+ finalUrlInfo.isUsed()
1230
1215
  );
1231
1216
  },
1232
1217
  );
@@ -1235,34 +1220,34 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
1235
1220
  "inject urls in service worker",
1236
1221
  );
1237
1222
  const serviceWorkerResources = {};
1238
- GRAPH_VISITOR.forEach(finalKitchen.graph, (urlInfo) => {
1239
- if (urlInfo.isRoot) {
1240
- return;
1241
- }
1242
- if (!urlInfo.url.startsWith("file:")) {
1243
- return;
1244
- }
1245
- if (urlInfo.isInline) {
1246
- return;
1247
- }
1248
- if (!canUseVersionedUrl(urlInfo)) {
1249
- // when url is not versioned we compute a "version" for that url anyway
1250
- // so that service worker source still changes and navigator
1251
- // detect there is a change
1223
+ GRAPH_VISITOR.forEachUrlInfoStronglyReferenced(
1224
+ finalKitchen.graph.rootUrlInfo,
1225
+ (urlInfo) => {
1226
+ if (!urlInfo.url.startsWith("file:")) {
1227
+ return;
1228
+ }
1229
+ if (urlInfo.isInline) {
1230
+ return;
1231
+ }
1232
+ if (!canUseVersionedUrl(urlInfo)) {
1233
+ // when url is not versioned we compute a "version" for that url anyway
1234
+ // so that service worker source still changes and navigator
1235
+ // detect there is a change
1236
+ const buildSpecifier = findKey(buildSpecifierMap, urlInfo.url);
1237
+ serviceWorkerResources[buildSpecifier] = {
1238
+ version: buildVersionsManager.getVersion(urlInfo),
1239
+ };
1240
+ return;
1241
+ }
1252
1242
  const buildSpecifier = findKey(buildSpecifierMap, urlInfo.url);
1243
+ const buildSpecifierVersioned =
1244
+ buildVersionsManager.getBuildSpecifierVersioned(buildSpecifier);
1253
1245
  serviceWorkerResources[buildSpecifier] = {
1254
1246
  version: buildVersionsManager.getVersion(urlInfo),
1247
+ versionedUrl: buildSpecifierVersioned,
1255
1248
  };
1256
- return;
1257
- }
1258
- const buildSpecifier = findKey(buildSpecifierMap, urlInfo.url);
1259
- const buildSpecifierVersioned =
1260
- buildVersionsManager.getBuildSpecifierVersioned(buildSpecifier);
1261
- serviceWorkerResources[buildSpecifier] = {
1262
- version: buildVersionsManager.getVersion(urlInfo),
1263
- versionedUrl: buildSpecifierVersioned,
1264
- };
1265
- });
1249
+ },
1250
+ );
1266
1251
  for (const serviceWorkerEntryUrlInfo of serviceWorkerEntryUrlInfos) {
1267
1252
  const serviceWorkerResourcesWithoutSwScriptItSelf = {
1268
1253
  ...serviceWorkerResources,
@@ -1302,48 +1287,48 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
1302
1287
  const buildRelativeUrl = urlToRelativeUrl(url, buildDirectoryUrl);
1303
1288
  return buildRelativeUrl;
1304
1289
  };
1305
- GRAPH_VISITOR.forEach(finalKitchen.graph, (urlInfo) => {
1306
- if (urlInfo.isRoot) {
1307
- return;
1308
- }
1309
- if (!urlInfo.url.startsWith("file:")) {
1310
- return;
1311
- }
1312
- if (urlInfo.type === "directory") {
1313
- return;
1314
- }
1315
- if (urlInfo.isInline) {
1316
- const buildRelativeUrl = getBuildRelativeUrl(urlInfo.url);
1317
- buildContents[buildRelativeUrl] = urlInfo.content;
1318
- buildInlineRelativeUrls.push(buildRelativeUrl);
1319
- } else {
1320
- const buildRelativeUrl = getBuildRelativeUrl(urlInfo.url);
1321
- if (
1322
- buildVersionsManager.getVersion(urlInfo) &&
1323
- canUseVersionedUrl(urlInfo)
1324
- ) {
1325
- const buildSpecifier = findKey(buildSpecifierMap, urlInfo.url);
1326
- const buildSpecifierVersioned =
1327
- buildVersionsManager.getBuildSpecifierVersioned(buildSpecifier);
1328
- const buildUrlVersioned = asBuildUrlVersioned({
1329
- buildSpecifierVersioned,
1330
- buildDirectoryUrl,
1331
- });
1332
- const buildRelativeUrlVersioned = urlToRelativeUrl(
1333
- buildUrlVersioned,
1334
- buildDirectoryUrl,
1335
- );
1336
- if (versioningMethod === "search_param") {
1337
- buildContents[buildRelativeUrl] = urlInfo.content;
1290
+ GRAPH_VISITOR.forEachUrlInfoStronglyReferenced(
1291
+ finalKitchen.graph.rootUrlInfo,
1292
+ (urlInfo) => {
1293
+ if (!urlInfo.url.startsWith("file:")) {
1294
+ return;
1295
+ }
1296
+ if (urlInfo.type === "directory") {
1297
+ return;
1298
+ }
1299
+ if (urlInfo.isInline) {
1300
+ const buildRelativeUrl = getBuildRelativeUrl(urlInfo.url);
1301
+ buildContents[buildRelativeUrl] = urlInfo.content;
1302
+ buildInlineRelativeUrls.push(buildRelativeUrl);
1303
+ } else {
1304
+ const buildRelativeUrl = getBuildRelativeUrl(urlInfo.url);
1305
+ if (
1306
+ buildVersionsManager.getVersion(urlInfo) &&
1307
+ canUseVersionedUrl(urlInfo)
1308
+ ) {
1309
+ const buildSpecifier = findKey(buildSpecifierMap, urlInfo.url);
1310
+ const buildSpecifierVersioned =
1311
+ buildVersionsManager.getBuildSpecifierVersioned(buildSpecifier);
1312
+ const buildUrlVersioned = asBuildUrlVersioned({
1313
+ buildSpecifierVersioned,
1314
+ buildDirectoryUrl,
1315
+ });
1316
+ const buildRelativeUrlVersioned = urlToRelativeUrl(
1317
+ buildUrlVersioned,
1318
+ buildDirectoryUrl,
1319
+ );
1320
+ if (versioningMethod === "search_param") {
1321
+ buildContents[buildRelativeUrl] = urlInfo.content;
1322
+ } else {
1323
+ buildContents[buildRelativeUrlVersioned] = urlInfo.content;
1324
+ }
1325
+ buildManifest[buildRelativeUrl] = buildRelativeUrlVersioned;
1338
1326
  } else {
1339
- buildContents[buildRelativeUrlVersioned] = urlInfo.content;
1327
+ buildContents[buildRelativeUrl] = urlInfo.content;
1340
1328
  }
1341
- buildManifest[buildRelativeUrl] = buildRelativeUrlVersioned;
1342
- } else {
1343
- buildContents[buildRelativeUrl] = urlInfo.content;
1344
1329
  }
1345
- }
1346
- });
1330
+ },
1331
+ );
1347
1332
  const buildFileContents = {};
1348
1333
  const buildInlineContents = {};
1349
1334
  Object.keys(buildContents)
@@ -1378,7 +1363,9 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
1378
1363
  writingFiles.done();
1379
1364
  }
1380
1365
  logger.info(
1381
- createUrlGraphSummary(finalKitchen.graph, { title: "build files" }),
1366
+ createUrlGraphSummary(finalKitchen.graph, {
1367
+ title: "build files",
1368
+ }),
1382
1369
  );
1383
1370
  return {
1384
1371
  buildFileContents,
@@ -213,63 +213,60 @@ export const createBuildVersionsManager = ({
213
213
 
214
214
  const contentOnlyVersionMap = new Map();
215
215
  generate_content_only_versions: {
216
- GRAPH_VISITOR.forEach(finalKitchen.graph, (urlInfo) => {
217
- // ignore:
218
- // - inline files and data files:
219
- // they are already taken into account in the file where they appear
220
- // - ignored files:
221
- // we don't know their content
222
- // - unused files without reference
223
- // File updated such as style.css -> style.css.js or file.js->file.nomodule.js
224
- // Are used at some point just to be discarded later because they need to be converted
225
- // There is no need to version them and we could not because the file have been ignored
226
- // so their content is unknown
227
- if (urlInfo.isRoot) {
228
- return;
229
- }
230
- if (urlInfo.type === "sourcemap") {
231
- return;
232
- }
233
- if (urlInfo.isInline) {
234
- return;
235
- }
236
- if (urlInfo.url.startsWith("data:")) {
237
- // urlInfo became inline and is not referenced by something else
238
- return;
239
- }
240
- if (urlInfo.url.startsWith("ignore:")) {
241
- return;
242
- }
243
- if (!urlInfo.isUsed()) {
244
- return;
245
- }
246
- let content = urlInfo.content;
247
- if (urlInfo.type === "html") {
248
- content = stringifyHtmlAst(
249
- parseHtmlString(urlInfo.content, {
250
- storeOriginalPositions: false,
251
- }),
252
- {
253
- cleanupJsenvAttributes: true,
254
- cleanupPositionAttributes: true,
255
- },
256
- );
257
- }
258
- if (
259
- CONTENT_TYPE.isTextual(urlInfo.contentType) &&
260
- urlInfo.referenceToOthersSet.size > 0
261
- ) {
262
- const containedPlaceholders = new Set();
263
- const contentWithPredictibleVersionPlaceholders =
264
- replaceWithDefaultAndPopulateContainedPlaceholders(
265
- content,
266
- containedPlaceholders,
216
+ GRAPH_VISITOR.forEachUrlInfoStronglyReferenced(
217
+ finalKitchen.graph.rootUrlInfo,
218
+ (urlInfo) => {
219
+ // ignore:
220
+ // - inline files and data files:
221
+ // they are already taken into account in the file where they appear
222
+ // - ignored files:
223
+ // we don't know their content
224
+ // - unused files without reference
225
+ // File updated such as style.css -> style.css.js or file.js->file.nomodule.js
226
+ // Are used at some point just to be discarded later because they need to be converted
227
+ // There is no need to version them and we could not because the file have been ignored
228
+ // so their content is unknown
229
+ if (urlInfo.type === "sourcemap") {
230
+ return;
231
+ }
232
+ if (urlInfo.isInline) {
233
+ return;
234
+ }
235
+ if (urlInfo.url.startsWith("data:")) {
236
+ // urlInfo became inline and is not referenced by something else
237
+ return;
238
+ }
239
+ if (urlInfo.url.startsWith("ignore:")) {
240
+ return;
241
+ }
242
+ let content = urlInfo.content;
243
+ if (urlInfo.type === "html") {
244
+ content = stringifyHtmlAst(
245
+ parseHtmlString(urlInfo.content, {
246
+ storeOriginalPositions: false,
247
+ }),
248
+ {
249
+ cleanupJsenvAttributes: true,
250
+ cleanupPositionAttributes: true,
251
+ },
267
252
  );
268
- content = contentWithPredictibleVersionPlaceholders;
269
- }
270
- const contentVersion = generateVersion([content], versionLength);
271
- contentOnlyVersionMap.set(urlInfo, contentVersion);
272
- });
253
+ }
254
+ if (
255
+ CONTENT_TYPE.isTextual(urlInfo.contentType) &&
256
+ urlInfo.referenceToOthersSet.size > 0
257
+ ) {
258
+ const containedPlaceholders = new Set();
259
+ const contentWithPredictibleVersionPlaceholders =
260
+ replaceWithDefaultAndPopulateContainedPlaceholders(
261
+ content,
262
+ containedPlaceholders,
263
+ );
264
+ content = contentWithPredictibleVersionPlaceholders;
265
+ }
266
+ const contentVersion = generateVersion([content], versionLength);
267
+ contentOnlyVersionMap.set(urlInfo, contentVersion);
268
+ },
269
+ );
273
270
  }
274
271
 
275
272
  generate_versions: {