@jsenv/core 27.0.0-alpha.66 → 27.0.0-alpha.69

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.
Files changed (39) hide show
  1. package/dist/main.js +154 -85
  2. package/dist/s.js +626 -0
  3. package/dist/s.js.map +204 -0
  4. package/package.json +8 -7
  5. package/src/build/build.js +21 -11
  6. package/src/build/build_urls_generator.js +1 -1
  7. package/src/build/resync_ressource_hints.js +1 -1
  8. package/src/build/start_build_server.js +1 -1
  9. package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +5 -9
  10. package/src/dev/start_dev_server.js +1 -1
  11. package/src/execute/run.js +2 -1
  12. package/src/execute/runtimes/browsers/from_playwright.js +1 -1
  13. package/src/execute/runtimes/node/node_process.js +1 -1
  14. package/src/omega/errors.js +2 -2
  15. package/src/omega/file_url_converter.js +1 -1
  16. package/src/omega/kitchen.js +49 -7
  17. package/src/omega/server/file_service.js +2 -2
  18. package/src/omega/url_graph/url_info_transformations.js +12 -6
  19. package/src/omega/url_graph.js +3 -2
  20. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js +1 -1
  21. package/src/plugins/bundling/js_module/bundle_js_module.js +4 -13
  22. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +33 -26
  23. package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +1 -1
  24. package/src/plugins/importmap/jsenv_plugin_importmap.js +1 -1
  25. package/src/plugins/inline/jsenv_plugin_data_urls.js +1 -1
  26. package/src/plugins/inline/jsenv_plugin_html_inline_content.js +1 -1
  27. package/src/plugins/inline/jsenv_plugin_inline_query_param.js +1 -1
  28. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +3 -3
  29. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +12 -8
  30. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +4 -2
  31. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_workers.js +1 -1
  32. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +10 -6
  33. package/src/plugins/url_analysis/css/css_urls.js +1 -1
  34. package/src/plugins/url_analysis/html/html_urls.js +1 -1
  35. package/src/plugins/url_analysis/js/js_urls.js +1 -1
  36. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +5 -14
  37. package/src/test/execute_plan.js +11 -14
  38. package/src/test/execute_test_plan.js +10 -16
  39. package/src/test/execution_steps.js +1 -4
package/dist/main.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { parentPort } from "node:worker_threads";
2
- import { urlToRelativeUrl, normalizeStructuredMetaMap, urlToMeta, registerFileLifecycle, urlIsInsideOf, urlToFilename, urlToExtension, readFileSync as readFileSync$1, fileSystemPathToUrl, urlToFileSystemPath, isFileSystemPath, bufferToEtag, writeFileSync, ensureWindowsDriveLetter, moveUrl, collectFiles, assertAndNormalizeDirectoryUrl, registerDirectoryLifecycle, resolveUrl, writeFile, ensureEmptyDirectory, writeDirectory, resolveDirectoryUrl, urlToBasename } from "@jsenv/filesystem";
2
+ import { registerFileLifecycle, readFileSync as readFileSync$1, bufferToEtag, writeFileSync, ensureWindowsDriveLetter, collectFiles, assertAndNormalizeDirectoryUrl, registerDirectoryLifecycle, writeFile, ensureEmptyDirectory, writeDirectory } from "@jsenv/filesystem";
3
3
  import { createDetailedMessage, createLogger, loggerToLevels } from "@jsenv/logger";
4
4
  import { createTaskLog, ANSI, msAsDuration, msAsEllapsedTime, byteAsMemoryUsage, UNICODE, createLog, startSpinner, distributePercentages, byteAsFileSize } from "@jsenv/log";
5
- import { getCallerPosition } from "@jsenv/utils/src/caller_position.js";
5
+ import { urlToRelativeUrl, URL_META, generateInlineContentUrl, ensurePathnameTrailingSlash, urlIsInsideOf, urlToFilename, urlToExtension, DataUrl, injectQueryParams, injectQueryParamsIntoSpecifier, fileSystemPathToUrl, urlToFileSystemPath, isFileSystemPath, normalizeUrl, stringifyUrlSite, setUrlFilename, moveUrl, getCallerPosition, resolveUrl, resolveDirectoryUrl, asUrlWithoutSearch, asUrlUntilPathname, urlToBasename } from "@jsenv/urls";
6
6
  import { initReloadableProcess } from "@jsenv/utils/process_reload/process_reload.js";
7
7
  import { parseHtmlString, stringifyHtmlAst, visitHtmlAst, getHtmlNodeAttributeByName, htmlNodePosition, findNode, getHtmlNodeTextNode, removeHtmlNode, setHtmlNodeGeneratedText, removeHtmlNodeAttributeByName, parseScriptNode, injectScriptAsEarlyAsPossible, createHtmlNode, removeHtmlNodeText, assignHtmlNodeAttributes, parseLinkNode } from "@jsenv/utils/html_ast/html_ast.js";
8
8
  import { htmlAttributeSrcSet } from "@jsenv/utils/html_ast/html_attribute_src_set.js";
@@ -11,17 +11,13 @@ import { applyPostCss } from "@jsenv/utils/css_ast/apply_post_css.js";
11
11
  import { postCssPluginUrlVisitor } from "@jsenv/utils/css_ast/postcss_plugin_url_visitor.js";
12
12
  import { parseJsUrls } from "@jsenv/utils/js_ast/parse_js_urls.js";
13
13
  import { resolveImport, normalizeImportMap, composeTwoImportMaps } from "@jsenv/importmap";
14
- import { generateInlineContentUrl } from "@jsenv/utils/urls/inline_content_url_generator.js";
15
14
  import { applyNodeEsmResolution, defaultLookupPackageScope, defaultReadPackageJson, readCustomConditionsFromProcessArgs, applyFileSystemMagicResolution } from "@jsenv/node-esm-resolution";
16
- import { statSync, readdirSync, readFileSync, realpathSync, existsSync } from "node:fs";
15
+ import { statSync, realpathSync, readdirSync, readFileSync, existsSync } from "node:fs";
17
16
  import { pathToFileURL } from "node:url";
18
- import { ensurePathnameTrailingSlash, injectQueryParams, injectQueryParamsIntoSpecifier, normalizeUrl, setUrlFilename, asUrlWithoutSearch, asUrlUntilPathname } from "@jsenv/utils/urls/url_utils.js";
19
17
  import { CONTENT_TYPE } from "@jsenv/utils/content_type/content_type.js";
20
18
  import { JS_QUOTES } from "@jsenv/utils/string/js_quotes.js";
21
19
  import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js";
22
- import { DataUrl } from "@jsenv/utils/urls/data_url.js";
23
20
  import { transpileWithParcel, minifyWithParcel } from "@jsenv/utils/css_ast/parcel_css.js";
24
- import { fetchOriginalUrlInfo } from "@jsenv/utils/graph/fetch_original_url_info.js";
25
21
  import { createRequire } from "node:module";
26
22
  import { composeTwoSourcemaps } from "@jsenv/utils/sourcemap/sourcemap_composition_v3.js";
27
23
  import babelParser from "@babel/parser";
@@ -32,7 +28,6 @@ import { applyRollupPlugins } from "@jsenv/utils/js_ast/apply_rollup_plugins.js"
32
28
  import { sourcemapConverter } from "@jsenv/utils/sourcemap/sourcemap_converter.js";
33
29
  import { createCallbackList, createCallbackListNotifiedOnce, Abort, raceCallbacks, raceProcessTeardownEvents } from "@jsenv/abort";
34
30
  import { createSSEService } from "@jsenv/utils/event_source/sse_service.js";
35
- import { stringifyUrlSite } from "@jsenv/utils/urls/url_trace.js";
36
31
  import { timeStart, fetchFileSystem, composeTwoResponses, serveDirectory, startServer, pluginCORS, jsenvAccessControlAllowedHeaders, pluginServerTiming, pluginRequestWaitingCheck, composeServices, findFreePort } from "@jsenv/server";
37
32
  import { SOURCEMAP, generateSourcemapUrl, sourcemapToBase64Url } from "@jsenv/utils/sourcemap/sourcemap_utils.js";
38
33
  import { validateResponseIntegrity } from "@jsenv/integrity";
@@ -58,7 +53,7 @@ import { uneval } from "@jsenv/uneval";
58
53
  import { createVersionGenerator } from "@jsenv/utils/versioning/version_generator.js";
59
54
 
60
55
  const parseAndTransformHtmlUrls = async (urlInfo, context) => {
61
- const url = urlInfo.data.rawUrl || urlInfo.url;
56
+ const url = urlInfo.originalUrl;
62
57
  const content = urlInfo.content;
63
58
  const {
64
59
  scenario,
@@ -368,7 +363,7 @@ const parseAndTransformCssUrls = async (urlInfo, context) => {
368
363
  });
369
364
  }
370
365
  })],
371
- url: urlInfo.data.rawUrl || urlInfo.url,
366
+ url: urlInfo.originalUrl,
372
367
  content: urlInfo.content
373
368
  });
374
369
  await Promise.all(actions.map(action => action()));
@@ -409,7 +404,7 @@ const isWebWorkerUrlInfo = urlInfo => {
409
404
  const parseAndTransformJsUrls = async (urlInfo, context) => {
410
405
  const jsMentions = await parseJsUrls({
411
406
  js: urlInfo.content,
412
- url: urlInfo.data && urlInfo.data.rawUrl || urlInfo.url,
407
+ url: urlInfo.originalUrl,
413
408
  isJsModule: urlInfo.type === "js_module",
414
409
  isWebWorker: isWebWorkerUrlInfo(urlInfo)
415
410
  });
@@ -513,16 +508,18 @@ const jsenvPluginUrlAnalysis = ({
513
508
  let getIncludeInfo = () => undefined;
514
509
 
515
510
  if (include) {
516
- const includeMetaMap = normalizeStructuredMetaMap({
511
+ const associations = URL_META.resolveAssociations({
517
512
  include
518
513
  }, rootDirectoryUrl);
519
514
 
520
515
  getIncludeInfo = url => {
521
- const meta = urlToMeta({
516
+ const {
517
+ include
518
+ } = URL_META.applyAssociations({
522
519
  url,
523
- structuredMetaMap: includeMetaMap
520
+ associations
524
521
  });
525
- return meta.include;
522
+ return include;
526
523
  };
527
524
  }
528
525
 
@@ -1110,36 +1107,33 @@ const jsenvPluginFileUrls = ({
1110
1107
  search,
1111
1108
  hash
1112
1109
  } = urlObject;
1113
-
1114
- const resolveSymlink = fileUrl => {
1115
- const realPath = realpathSync(new URL(fileUrl));
1116
- const realFileUrl = `${pathToFileURL(realPath)}${search}${hash}`;
1117
- return realFileUrl;
1118
- };
1119
-
1120
1110
  let {
1121
1111
  pathname
1122
1112
  } = urlObject;
1123
1113
  const pathnameUsesTrailingSlash = pathname.endsWith("/");
1124
1114
  urlObject.search = "";
1125
- urlObject.hash = ""; // force trailing slash on directories and remove eventual trailing slash on files
1115
+ urlObject.hash = "";
1116
+ const foundADirectory = stat && stat.isDirectory();
1117
+ const foundSomething = stat && !foundADirectory; // force trailing slash on directories
1126
1118
 
1127
- if (stat && stat.isDirectory()) {
1128
- reference.expectedType = "directory";
1119
+ if (foundADirectory && !pathnameUsesTrailingSlash) {
1120
+ urlObject.pathname = `${pathname}/`;
1121
+ } // otherwise remove trailing slash if any
1129
1122
 
1130
- if (!pathnameUsesTrailingSlash) {
1131
- urlObject.pathname = `${pathname}/`;
1132
- }
1133
-
1134
- if (directoryReferenceAllowed) {
1135
- return preservesSymlink ? urlObject.href : resolveSymlink(urlObject.href);
1136
- } // give a chane to magic resolution if enabled
1137
1123
 
1138
- } else if (pathnameUsesTrailingSlash) {
1139
- // a warning would be great because it's strange to reference a file with a trailing slash
1124
+ if (foundSomething && pathnameUsesTrailingSlash) {
1125
+ // a warning here? (because it's strange to reference a file with a trailing slash)
1140
1126
  urlObject.pathname = pathname.slice(0, -1);
1141
1127
  }
1142
1128
 
1129
+ if (foundADirectory && directoryReferenceAllowed) {
1130
+ reference.data.foundADirectory = true;
1131
+ const directoryFacadeUrl = urlObject.href;
1132
+ const directoryUrlRaw = preservesSymlink ? directoryFacadeUrl : resolveSymlink(directoryFacadeUrl);
1133
+ const directoryUrl = `${directoryUrlRaw}${search}${hash}`;
1134
+ return directoryUrl;
1135
+ }
1136
+
1143
1137
  const url = urlObject.href;
1144
1138
  const filesystemResolution = applyFileSystemMagicResolution(url, {
1145
1139
  fileStat: stat,
@@ -1148,12 +1142,15 @@ const jsenvPluginFileUrls = ({
1148
1142
  });
1149
1143
 
1150
1144
  if (!filesystemResolution.found) {
1145
+ reference.data.foundADirectory = foundADirectory;
1151
1146
  return null;
1152
1147
  }
1153
1148
 
1154
- const fileUrlRaw = filesystemResolution.url;
1149
+ reference.data.foundADirectory = filesystemResolution.isDirectory;
1150
+ const fileFacadeUrl = filesystemResolution.url;
1151
+ const fileUrlRaw = preservesSymlink ? fileFacadeUrl : resolveSymlink(fileFacadeUrl);
1155
1152
  const fileUrl = `${fileUrlRaw}${search}${hash}`;
1156
- return preservesSymlink ? fileUrl : resolveSymlink(fileUrl);
1153
+ return fileUrl;
1157
1154
  }
1158
1155
  }, {
1159
1156
  name: "jsenv:filesystem_resolution",
@@ -1207,7 +1204,7 @@ const jsenvPluginFileUrls = ({
1207
1204
 
1208
1205
  const urlObject = new URL(urlInfo.url);
1209
1206
 
1210
- if (context.reference.expectedType === "directory") {
1207
+ if (context.reference.data.foundADirectory) {
1211
1208
  if (directoryReferenceAllowed) {
1212
1209
  const directoryEntries = readdirSync(urlObject);
1213
1210
  let filename;
@@ -1228,7 +1225,7 @@ const jsenvPluginFileUrls = ({
1228
1225
  }
1229
1226
 
1230
1227
  const error = new Error("found a directory on filesystem");
1231
- error.code = "EISDIR";
1228
+ error.code = "DIRECTORY_REFERENCE_NOT_ALLOWED";
1232
1229
  throw error;
1233
1230
  }
1234
1231
 
@@ -1250,6 +1247,10 @@ const jsenvPluginFileUrls = ({
1250
1247
  }];
1251
1248
  };
1252
1249
 
1250
+ const resolveSymlink = fileUrl => {
1251
+ return pathToFileURL(realpathSync(new URL(fileUrl))).href;
1252
+ };
1253
+
1253
1254
  const jsenvPluginHttpUrls = () => {
1254
1255
  return {
1255
1256
  name: "jsenv:http_urls",
@@ -1435,7 +1436,7 @@ const jsenvPluginJsInlineContent = ({
1435
1436
  const parseAndTransformInlineContentCalls = async (urlInfo, context) => {
1436
1437
  const inlineContentInfos = await parseJsInlineContentInfos({
1437
1438
  js: urlInfo.content,
1438
- url: urlInfo.data && urlInfo.data.rawUrl || urlInfo.url,
1439
+ url: urlInfo.originalUrl,
1439
1440
  isJsModule: urlInfo.type === "js_module"
1440
1441
  });
1441
1442
 
@@ -1521,7 +1522,7 @@ const parseJsInlineContentInfos = async ({
1521
1522
  } = await applyBabelPlugins({
1522
1523
  babelPlugins: [babelPluginMetadataInlineContents],
1523
1524
  urlInfo: {
1524
- url,
1525
+ originalUrl: url,
1525
1526
  type: isJsModule ? "js_module" : "js_classic",
1526
1527
  content: js
1527
1528
  }
@@ -2628,7 +2629,7 @@ const jsenvPluginAsModules = () => {
2628
2629
  name: `jsenv:as_json_module`,
2629
2630
  appliesDuring: "*",
2630
2631
  fetchUrlContent: async (urlInfo, context) => {
2631
- const originalUrlInfo = await fetchOriginalUrlInfo({
2632
+ const originalUrlInfo = await context.fetchOriginalUrlInfo({
2632
2633
  urlInfo,
2633
2634
  context,
2634
2635
  searchParam: "as_json_module",
@@ -2641,6 +2642,8 @@ const jsenvPluginAsModules = () => {
2641
2642
 
2642
2643
  const jsonText = JSON.stringify(originalUrlInfo.content.trim());
2643
2644
  return {
2645
+ originalUrl: originalUrlInfo.originalUrl,
2646
+ originalContent: originalUrlInfo.originalContent,
2644
2647
  type: "js_module",
2645
2648
  contentType: "text/javascript",
2646
2649
  // here we could `export default ${jsonText}`:
@@ -2654,7 +2657,7 @@ const jsenvPluginAsModules = () => {
2654
2657
  name: `jsenv:as_css_module`,
2655
2658
  appliesDuring: "*",
2656
2659
  fetchUrlContent: async (urlInfo, context) => {
2657
- const originalUrlInfo = await fetchOriginalUrlInfo({
2660
+ const originalUrlInfo = await context.fetchOriginalUrlInfo({
2658
2661
  urlInfo,
2659
2662
  context,
2660
2663
  searchParam: "as_css_module",
@@ -2672,6 +2675,8 @@ const jsenvPluginAsModules = () => {
2672
2675
  canUseTemplateString: true
2673
2676
  });
2674
2677
  return {
2678
+ originalUrl: originalUrlInfo.originalUrl,
2679
+ originalContent: originalUrlInfo.originalContent,
2675
2680
  type: "js_module",
2676
2681
  contentType: "text/javascript",
2677
2682
  content: `import { InlineContent } from ${JSON.stringify(inlineContentClientFileUrl)}
@@ -2687,7 +2692,7 @@ const jsenvPluginAsModules = () => {
2687
2692
  name: `jsenv:as_text_module`,
2688
2693
  appliesDuring: "*",
2689
2694
  fetchUrlContent: async (urlInfo, context) => {
2690
- const originalUrlInfo = await fetchOriginalUrlInfo({
2695
+ const originalUrlInfo = await context.fetchOriginalUrlInfo({
2691
2696
  urlInfo,
2692
2697
  context,
2693
2698
  searchParam: "as_text_module",
@@ -2705,6 +2710,8 @@ const jsenvPluginAsModules = () => {
2705
2710
  canUseTemplateString: true
2706
2711
  });
2707
2712
  return {
2713
+ originalUrl: originalUrlInfo.originalUrl,
2714
+ originalContent: originalUrlInfo.originalContent,
2708
2715
  type: "js_module",
2709
2716
  contentType: "text/javascript",
2710
2717
  content: `import { InlineContent } from ${JSON.stringify(inlineContentClientFileUrl)}
@@ -3180,7 +3187,7 @@ const jsenvPluginAsJsClassicConversion = ({
3180
3187
  }
3181
3188
  },
3182
3189
  fetchUrlContent: async (urlInfo, context) => {
3183
- const originalUrlInfo = await fetchOriginalUrlInfo({
3190
+ const originalUrlInfo = await context.fetchOriginalUrlInfo({
3184
3191
  urlInfo,
3185
3192
  context,
3186
3193
  searchParam: "as_js_classic",
@@ -3216,6 +3223,8 @@ const jsenvPluginAsJsClassicConversion = ({
3216
3223
  });
3217
3224
  urlInfo.data.jsClassicFormat = jsClassicFormat;
3218
3225
  return {
3226
+ originalUrl: originalUrlInfo.originalUrl,
3227
+ originalContent: originalUrlInfo.originalContent,
3219
3228
  type: "js_classic",
3220
3229
  contentType: "text/javascript",
3221
3230
  content,
@@ -3269,6 +3278,8 @@ const convertJsModuleToJsClassic = async ({
3269
3278
  }], babelPluginTransformImportMetaUrl, require$3("@babel/plugin-transform-modules-umd")])],
3270
3279
  urlInfo
3271
3280
  });
3281
+ let sourcemap = urlInfo.sourcemap;
3282
+ sourcemap = await composeTwoSourcemaps(sourcemap, map);
3272
3283
 
3273
3284
  if (systemJsInjection && jsClassicFormat === "system" && isJsEntryPoint) {
3274
3285
  const magicSource = createMagicSource(code);
@@ -3276,19 +3287,17 @@ const convertJsModuleToJsClassic = async ({
3276
3287
  as: "string"
3277
3288
  });
3278
3289
  magicSource.prepend(`${systemjsCode}\n\n`);
3279
- const {
3280
- content,
3281
- sourcemap
3282
- } = magicSource.toContentAndSourcemap();
3290
+ const magicResult = magicSource.toContentAndSourcemap();
3291
+ sourcemap = await composeTwoSourcemaps(sourcemap, magicResult.sourcemap);
3283
3292
  return {
3284
- content,
3285
- sourcemap: await composeTwoSourcemaps(map, sourcemap)
3293
+ content: magicResult.content,
3294
+ sourcemap
3286
3295
  };
3287
3296
  }
3288
3297
 
3289
3298
  return {
3290
3299
  content: code,
3291
- sourcemap: map
3300
+ sourcemap
3292
3301
  };
3293
3302
  };
3294
3303
 
@@ -4847,14 +4856,14 @@ const rollupPluginJsenv = ({
4847
4856
  let importCanBeBundled = () => true;
4848
4857
 
4849
4858
  if (include) {
4850
- const bundleIncludeConfig = normalizeStructuredMetaMap({
4859
+ const associations = URL_META.resolveAssociations({
4851
4860
  bundle: include
4852
4861
  }, rootDirectoryUrl);
4853
4862
 
4854
4863
  importCanBeBundled = url => {
4855
- return urlToMeta({
4864
+ return URL_META.applyAssociations({
4856
4865
  url,
4857
- structuredMetaMap: bundleIncludeConfig
4866
+ associations
4858
4867
  }).bundle;
4859
4868
  };
4860
4869
  }
@@ -6353,8 +6362,9 @@ const createUrlInfo = url => {
6353
6362
  contentType: "",
6354
6363
  // "text/html", "text/css", "text/javascript", "application/json", ...
6355
6364
  url,
6356
- filename: "",
6365
+ originalUrl: undefined,
6357
6366
  generatedUrl: null,
6367
+ filename: "",
6358
6368
  isInline: false,
6359
6369
  inlineUrlSite: null,
6360
6370
  shouldHandle: undefined,
@@ -6698,7 +6708,7 @@ const createUrlInfoTransformer = ({
6698
6708
  sourcemapsSourcesContent || urlInfo.isInline || sourcemap.sources && sourcemap.sources.some(source => !source || !source.startsWith("file:"));
6699
6709
 
6700
6710
  if (sourcemap.sources && sourcemap.sources.length > 1) {
6701
- sourcemap.sources = sourcemap.sources.map(source => new URL(source, urlInfo.data.rawUrl || urlInfo.url).href);
6711
+ sourcemap.sources = sourcemap.sources.map(source => new URL(source, urlInfo.originalUrl).href);
6702
6712
 
6703
6713
  if (!wantSourcesContent) {
6704
6714
  sourcemap.sourcesContent = undefined;
@@ -6707,7 +6717,7 @@ const createUrlInfoTransformer = ({
6707
6717
  return sourcemap;
6708
6718
  }
6709
6719
 
6710
- sourcemap.sources = [urlInfo.data.rawUrl || urlInfo.url];
6720
+ sourcemap.sources = [urlInfo.originalUrl];
6711
6721
  sourcemap.sourcesContent = [urlInfo.originalContent];
6712
6722
 
6713
6723
  if (!wantSourcesContent) {
@@ -6743,6 +6753,7 @@ const createUrlInfoTransformer = ({
6743
6753
  sourcemapUrlInfo.isInline = sourcemaps === "inline"; // already loaded during "load" hook (happens during build)
6744
6754
 
6745
6755
  if (urlInfo.sourcemap) {
6756
+ urlInfo.sourcemap = normalizeSourcemap(urlInfo, urlInfo.sourcemap);
6746
6757
  return;
6747
6758
  } // check for existing sourcemap for this content
6748
6759
 
@@ -6771,8 +6782,9 @@ const createUrlInfoTransformer = ({
6771
6782
  await context.cook(sourcemapUrlInfo, {
6772
6783
  reference: sourcemapReference
6773
6784
  });
6774
- const sourcemap = JSON.parse(sourcemapUrlInfo.content);
6775
- urlInfo.sourcemap = normalizeSourcemap(urlInfo, sourcemap);
6785
+ const sourcemapRaw = JSON.parse(sourcemapUrlInfo.content);
6786
+ const sourcemap = normalizeSourcemap(urlInfo, sourcemapRaw);
6787
+ urlInfo.sourcemap = sourcemap;
6776
6788
  } catch (e) {
6777
6789
  logger.error(`Error while handling existing sourcemap: ${e.message}`);
6778
6790
  return;
@@ -6831,7 +6843,7 @@ const createUrlInfoTransformer = ({
6831
6843
  if (sourcemapsRelativeSources) {
6832
6844
  sourcemap.sources = sourcemap.sources.map(source => {
6833
6845
  const sourceRelative = urlToRelativeUrl(source, urlInfo.url);
6834
- return sourceRelative;
6846
+ return sourceRelative || ".";
6835
6847
  });
6836
6848
  }
6837
6849
 
@@ -6848,6 +6860,9 @@ const createUrlInfoTransformer = ({
6848
6860
  specifier: sourcemaps === "file" && sourcemapsRelativeSources ? urlToRelativeUrl(sourcemapReference.url, urlInfo.url) : sourcemapReference.generatedSpecifier
6849
6861
  });
6850
6862
  }
6863
+ } else if (urlInfo.sourcemapReference) {
6864
+ // in the end we don't use the sourcemap placeholder
6865
+ urlGraph.deleteUrlInfo(urlInfo.sourcemapReference.url);
6851
6866
  }
6852
6867
 
6853
6868
  urlInfo.contentEtag = bufferToEtag(Buffer.from(urlInfo.content));
@@ -6925,9 +6940,9 @@ const createFetchUrlContentError = ({
6925
6940
  });
6926
6941
  }
6927
6942
 
6928
- if (error.code === "EISDIR") {
6943
+ if (error.code === "DIRECTORY_REFERENCE_NOT_ALLOWED") {
6929
6944
  return createFailedToFetchUrlContentError({
6930
- code: "EISDIR",
6945
+ code: "DIRECTORY_REFERENCE_NOT_ALLOWED",
6931
6946
  reason: `found a directory on filesystem`
6932
6947
  });
6933
6948
  }
@@ -7293,6 +7308,7 @@ const createKitchen = ({
7293
7308
  type,
7294
7309
  subtype,
7295
7310
  contentType = "application/octet-stream",
7311
+ originalUrl,
7296
7312
  originalContent,
7297
7313
  content,
7298
7314
  sourcemap,
@@ -7307,8 +7323,9 @@ const createKitchen = ({
7307
7323
  type: urlInfo.type,
7308
7324
  subtype: urlInfo.subtype
7309
7325
  });
7310
- urlInfo.contentType = contentType; // during build urls info are reused and load returns originalContent
7326
+ urlInfo.contentType = contentType; // during build urls info are reused and load returns originalUrl/originalContent
7311
7327
 
7328
+ urlInfo.originalUrl = originalUrl || urlInfo.originalUrl;
7312
7329
  urlInfo.originalContent = originalContent === undefined ? content : originalContent;
7313
7330
  urlInfo.content = content;
7314
7331
  urlInfo.sourcemap = sourcemap;
@@ -7631,6 +7648,45 @@ const createKitchen = ({
7631
7648
  return [ref, urlInfo];
7632
7649
  };
7633
7650
 
7651
+ const fetchOriginalUrlInfo = async ({
7652
+ urlInfo,
7653
+ context,
7654
+ searchParam,
7655
+ expectedType
7656
+ }) => {
7657
+ const urlObject = new URL(urlInfo.url);
7658
+ const {
7659
+ searchParams
7660
+ } = urlObject;
7661
+
7662
+ if (!searchParams.has(searchParam)) {
7663
+ return null;
7664
+ }
7665
+
7666
+ searchParams.delete(searchParam);
7667
+ const originalUrl = urlObject.href;
7668
+ const originalReference = { ...(context.reference.original || context.reference),
7669
+ expectedType
7670
+ };
7671
+ originalReference.url = originalUrl;
7672
+ const originalUrlInfo = context.urlGraph.reuseOrCreateUrlInfo(originalReference.url);
7673
+
7674
+ if (originalUrlInfo.originalUrl === undefined) {
7675
+ applyReferenceEffectsOnUrlInfo(originalReference, originalUrlInfo, context);
7676
+ }
7677
+
7678
+ await context.fetchUrlContent(originalUrlInfo, {
7679
+ reference: originalReference
7680
+ });
7681
+
7682
+ if (originalUrlInfo.dependents.size === 0) {
7683
+ context.urlGraph.deleteUrlInfo(originalUrlInfo.url);
7684
+ }
7685
+
7686
+ return originalUrlInfo;
7687
+ };
7688
+
7689
+ kitchenContext.fetchOriginalUrlInfo = fetchOriginalUrlInfo;
7634
7690
  return {
7635
7691
  pluginController,
7636
7692
  urlInfoTransformer,
@@ -7686,6 +7742,7 @@ const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
7686
7742
  urlInfo.shouldHandle = true;
7687
7743
  }
7688
7744
 
7745
+ urlInfo.originalUrl = urlInfo.originalUrl || reference.url;
7689
7746
  Object.assign(urlInfo.data, reference.data);
7690
7747
  Object.assign(urlInfo.timing, reference.timing);
7691
7748
 
@@ -8074,7 +8131,7 @@ const createFileService = ({
8074
8131
  };
8075
8132
  }
8076
8133
 
8077
- if (code === "EISDIR") {
8134
+ if (code === "DIRECTORY_REFERENCE_NOT_ALLOWED") {
8078
8135
  return serveDirectory(reference.url, {
8079
8136
  headers: {
8080
8137
  accept: "text/html"
@@ -8277,19 +8334,18 @@ const jsenvPluginExplorer = ({
8277
8334
  return null;
8278
8335
  }
8279
8336
 
8280
- const structuredMetaMapRelativeForExplorable = {};
8337
+ const associationsForExplorable = {};
8281
8338
  Object.keys(groups).forEach(groupName => {
8282
8339
  const groupConfig = groups[groupName];
8283
- structuredMetaMapRelativeForExplorable[groupName] = {
8340
+ associationsForExplorable[groupName] = {
8284
8341
  "**/.jsenv/": false,
8285
8342
  // avoid visting .jsenv directory in jsenv itself
8286
8343
  ...groupConfig
8287
8344
  };
8288
8345
  });
8289
- const structuredMetaMapForExplorable = normalizeStructuredMetaMap(structuredMetaMapRelativeForExplorable, rootDirectoryUrl);
8290
8346
  const matchingFileResultArray = await collectFiles({
8291
8347
  directoryUrl: rootDirectoryUrl,
8292
- structuredMetaMap: structuredMetaMapForExplorable,
8348
+ associations: associationsForExplorable,
8293
8349
  predicate: meta => Object.keys(meta).some(group => Boolean(meta[group]))
8294
8350
  });
8295
8351
  const files = matchingFileResultArray.map(({
@@ -8766,13 +8822,12 @@ const generateExecutionSteps = async (plan, {
8766
8822
  signal,
8767
8823
  rootDirectoryUrl
8768
8824
  }) => {
8769
- const structuredMetaMap = {
8770
- filePlan: plan
8771
- };
8772
8825
  const fileResultArray = await collectFiles({
8773
8826
  signal,
8774
8827
  directoryUrl: rootDirectoryUrl,
8775
- structuredMetaMap,
8828
+ associations: {
8829
+ filePlan: plan
8830
+ },
8776
8831
  predicate: ({
8777
8832
  filePlan
8778
8833
  }) => filePlan
@@ -9233,7 +9288,7 @@ const executePlan = async (plan, {
9233
9288
  const executionSpinner = !debugLogsEnabled && executionLogsEnabled && process.stdout.isTTY && // if there is an error during execution npm will mess up the output
9234
9289
  // (happens when npm runs several command in a workspace)
9235
9290
  // so we enable spinner only when !process.exitCode (no error so far)
9236
- !process.exitCode;
9291
+ process.exitCode !== 1;
9237
9292
  const startMs = Date.now();
9238
9293
  const report = {};
9239
9294
  let rawOutput = "";
@@ -9247,15 +9302,18 @@ const executePlan = async (plan, {
9247
9302
  const coverageTempDirectoryUrl = new URL(coverageTempDirectoryRelativeUrl, rootDirectoryUrl).href;
9248
9303
 
9249
9304
  if (coverage) {
9250
- const structuredMetaMapForCover = normalizeStructuredMetaMap({
9305
+ const associations = URL_META.resolveAssociations({
9251
9306
  cover: coverageConfig
9252
9307
  }, rootDirectoryUrl);
9253
9308
 
9254
9309
  const urlShouldBeCovered = url => {
9255
- return urlToMeta({
9310
+ const {
9311
+ cover
9312
+ } = URL_META.applyAssociations({
9256
9313
  url: new URL(url, rootDirectoryUrl).href,
9257
- structuredMetaMap: structuredMetaMapForCover
9258
- }).cover;
9314
+ associations
9315
+ });
9316
+ return cover;
9259
9317
  };
9260
9318
 
9261
9319
  runtimeParams.urlShouldBeCovered = urlShouldBeCovered; // in case runned multiple times, we don't want to keep writing lot of files in this directory
@@ -9718,17 +9776,20 @@ const executeTestPlan = async ({
9718
9776
  }
9719
9777
 
9720
9778
  if (!coverageAndExecutionAllowed) {
9721
- const structuredMetaMapForExecute = normalizeStructuredMetaMap({
9779
+ const associationsForExecute = URL_META.resolveAssociations({
9722
9780
  execute: testPlan
9723
9781
  }, "file:///");
9724
- const structuredMetaMapForCover = normalizeStructuredMetaMap({
9782
+ const associationsForCover = URL_META.resolveAssociations({
9725
9783
  cover: coverageConfig
9726
9784
  }, "file:///");
9727
- const patternsMatchingCoverAndExecute = Object.keys(structuredMetaMapForExecute.execute).filter(testPlanPattern => {
9728
- return urlToMeta({
9785
+ const patternsMatchingCoverAndExecute = Object.keys(associationsForExecute.execute).filter(testPlanPattern => {
9786
+ const {
9787
+ cover
9788
+ } = URL_META.applyAssociations({
9729
9789
  url: testPlanPattern,
9730
- structuredMetaMap: structuredMetaMapForCover
9731
- }).cover;
9790
+ associations: associationsForCover
9791
+ });
9792
+ return cover;
9732
9793
  });
9733
9794
 
9734
9795
  if (patternsMatchingCoverAndExecute.length) {
@@ -11750,7 +11811,7 @@ const resyncRessourceHints = async ({
11750
11811
  }
11751
11812
 
11752
11813
  if (urlInfo.dependents.size === 0) {
11753
- logger.warn(`remove ressource hint because "${href}" not used anymore`);
11814
+ logger.info(`remove ressource hint because "${href}" not used anymore`);
11754
11815
  actions.push(() => {
11755
11816
  removeHtmlNode(linkNode);
11756
11817
  });
@@ -11846,6 +11907,7 @@ const build = async ({
11846
11907
  },
11847
11908
  plugins = [],
11848
11909
  sourcemaps = false,
11910
+ sourcemapsSourcesContent,
11849
11911
  urlAnalysis = {},
11850
11912
  nodeEsmResolution,
11851
11913
  fileSystemMagicResolution,
@@ -11928,6 +11990,7 @@ build ${entryPointKeys.length} entry points`);
11928
11990
  urlGraph: rawGraph,
11929
11991
  scenario: "build",
11930
11992
  sourcemaps,
11993
+ sourcemapsSourcesContent,
11931
11994
  runtimeCompat,
11932
11995
  writeGeneratedFiles,
11933
11996
  plugins: [...plugins, {
@@ -12128,6 +12191,8 @@ build ${entryPointKeys.length} entry points`);
12128
12191
  type,
12129
12192
  subtype: rawUrlInfo ? rawUrlInfo.subtype : undefined,
12130
12193
  filename: rawUrlInfo ? rawUrlInfo.filename : undefined,
12194
+ originalUrl: rawUrlInfo ? rawUrlInfo.originalUrl : undefined,
12195
+ originalContent: rawUrlInfo ? rawUrlInfo.originalContent : undefined,
12131
12196
  ...bundlerGeneratedUrlInfo,
12132
12197
  data: { ...(rawUrlInfo ? rawUrlInfo.data : {}),
12133
12198
  ...bundlerGeneratedUrlInfo.data,
@@ -12173,6 +12238,7 @@ build ${entryPointKeys.length} entry points`);
12173
12238
  urlGraph: finalGraph,
12174
12239
  scenario: "build",
12175
12240
  sourcemaps,
12241
+ sourcemapsSourcesContent,
12176
12242
  sourcemapsRelativeSources: !versioning,
12177
12243
  runtimeCompat,
12178
12244
  writeGeneratedFiles,
@@ -12328,12 +12394,12 @@ build ${entryPointKeys.length} entry points`);
12328
12394
  urlInfo: rawUrlInfo,
12329
12395
  parentUrlInfo
12330
12396
  });
12397
+ rawUrls[buildUrl] = rawUrlInfo.url;
12331
12398
 
12332
12399
  if (buildUrl.includes("?")) {
12333
12400
  rawUrls[asUrlWithoutSearch(buildUrl)] = rawUrlInfo.url;
12334
12401
  }
12335
12402
 
12336
- rawUrls[buildUrl] = rawUrlInfo.url;
12337
12403
  return buildUrl;
12338
12404
  }
12339
12405
 
@@ -12504,6 +12570,7 @@ ${Object.keys(finalGraph.urlInfos).join("\n")}`);
12504
12570
  baseUrl,
12505
12571
  postBuildEntryUrls,
12506
12572
  sourcemaps,
12573
+ sourcemapsSourcesContent,
12507
12574
  runtimeCompat,
12508
12575
  writeGeneratedFiles,
12509
12576
  rawGraph,
@@ -12731,6 +12798,7 @@ const applyUrlVersioning = async ({
12731
12798
  baseUrl,
12732
12799
  postBuildEntryUrls,
12733
12800
  sourcemaps,
12801
+ sourcemapsSourcesContent,
12734
12802
  runtimeCompat,
12735
12803
  writeGeneratedFiles,
12736
12804
  rawGraph,
@@ -12833,6 +12901,7 @@ const applyUrlVersioning = async ({
12833
12901
  urlGraph: finalGraph,
12834
12902
  scenario: "build",
12835
12903
  sourcemaps,
12904
+ sourcemapsSourcesContent,
12836
12905
  sourcemapsRelativeSources: true,
12837
12906
  runtimeCompat,
12838
12907
  writeGeneratedFiles,