@jsenv/core 39.3.12 → 39.4.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.
@@ -14,7 +14,7 @@ import { Http2ServerResponse } from "node:http2";
14
14
  import { performance as performance$1 } from "node:perf_hooks";
15
15
  import { lookup } from "node:dns";
16
16
  import { parseJsUrls, parseHtml, visitHtmlNodes, getHtmlNodeAttribute, analyzeScriptNode, getHtmlNodeText, stringifyHtmlAst, setHtmlNodeAttributes, applyBabelPlugins, injectJsImport, visitJsAstUntil, injectHtmlNodeAsEarlyAsPossible, createHtmlNode, generateUrlForInlineContent, parseJsWithAcorn, getHtmlNodePosition, getUrlForContentInsideHtml, setHtmlNodeText, parseCssUrls, getHtmlNodeAttributePosition, parseSrcSet, removeHtmlNodeText, removeHtmlNode, getUrlForContentInsideJs, analyzeLinkNode, injectJsenvScript, findHtmlNode, insertHtmlNodeAfter } from "@jsenv/ast";
17
- import { sourcemapConverter, createMagicSource, composeTwoSourcemaps, SOURCEMAP, generateSourcemapFileUrl, generateSourcemapDataUrl } from "@jsenv/sourcemap";
17
+ import { sourcemapConverter, createMagicSource, composeTwoSourcemaps, generateSourcemapFileUrl, SOURCEMAP, generateSourcemapDataUrl } from "@jsenv/sourcemap";
18
18
  import { createRequire } from "node:module";
19
19
  import { systemJsClientFileUrlDefault, convertJsModuleToJsClassic } from "@jsenv/js-module-fallback";
20
20
  import { RUNTIME_COMPAT } from "@jsenv/runtime-compat";
@@ -1178,15 +1178,13 @@ const createDynamicLog = ({
1178
1178
  // is that node.js will later throw error if stream gets closed
1179
1179
  // while something listening data on it
1180
1180
  const spyStreamOutput = (stream, callback) => {
1181
- const originalWrite = stream.write;
1182
-
1183
1181
  let output = "";
1184
1182
  let installed = true;
1185
-
1183
+ const originalWrite = stream.write;
1186
1184
  stream.write = function (...args /* chunk, encoding, callback */) {
1187
1185
  output += args;
1188
1186
  callback(output);
1189
- return originalWrite.call(stream, ...args);
1187
+ return originalWrite.call(this, ...args);
1190
1188
  };
1191
1189
 
1192
1190
  const uninstall = () => {
@@ -12015,6 +12013,48 @@ const assertFetchedContentCompliance = ({ urlInfo, content }) => {
12015
12013
  }
12016
12014
  };
12017
12015
 
12016
+ const determineFileUrlForOutDirectory = (urlInfo) => {
12017
+ let { url, filenameHint } = urlInfo;
12018
+ const { rootDirectoryUrl, outDirectoryUrl } = urlInfo.context;
12019
+ if (!outDirectoryUrl) {
12020
+ return url;
12021
+ }
12022
+ if (!url.startsWith("file:")) {
12023
+ return url;
12024
+ }
12025
+ if (!urlIsInsideOf(url, rootDirectoryUrl)) {
12026
+ const fsRootUrl = ensureWindowsDriveLetter("file:///", url);
12027
+ url = `${rootDirectoryUrl}@fs/${url.slice(fsRootUrl.length)}`;
12028
+ }
12029
+ if (filenameHint) {
12030
+ url = setUrlFilename(url, filenameHint);
12031
+ }
12032
+ return moveUrl({
12033
+ url,
12034
+ from: rootDirectoryUrl,
12035
+ to: outDirectoryUrl,
12036
+ });
12037
+ };
12038
+
12039
+ const determineSourcemapFileUrl = (urlInfo) => {
12040
+ // sourcemap is a special kind of reference:
12041
+ // It's a reference to a content generated dynamically the content itself.
12042
+ // when jsenv is done cooking the file
12043
+ // during build it's urlInfo.url to be inside the build
12044
+ // but otherwise it's generatedUrl to be inside .jsenv/ directory
12045
+ const generatedUrlObject = new URL(urlInfo.generatedUrl);
12046
+ generatedUrlObject.searchParams.delete("js_module_fallback");
12047
+ generatedUrlObject.searchParams.delete("as_js_module");
12048
+ generatedUrlObject.searchParams.delete("as_js_classic");
12049
+ generatedUrlObject.searchParams.delete("as_css_module");
12050
+ generatedUrlObject.searchParams.delete("as_json_module");
12051
+ generatedUrlObject.searchParams.delete("as_text_module");
12052
+ generatedUrlObject.searchParams.delete("dynamic_import");
12053
+ generatedUrlObject.searchParams.delete("cjs_as_js_module");
12054
+ const urlForSourcemap = generatedUrlObject.href;
12055
+ return generateSourcemapFileUrl(urlForSourcemap);
12056
+ };
12057
+
12018
12058
  const createEventEmitter = () => {
12019
12059
  const callbackSet = new Set();
12020
12060
  const on = (callback) => {
@@ -12485,7 +12525,9 @@ const createReference = ({
12485
12525
  if (specifier instanceof URL) {
12486
12526
  specifier = specifier.href;
12487
12527
  } else {
12488
- throw new TypeError(`"specifier" must be a string, got ${specifier}`);
12528
+ throw new TypeError(
12529
+ `"specifier" must be a string, got ${specifier} in ${ownerUrlInfo.url}`,
12530
+ );
12489
12531
  }
12490
12532
  }
12491
12533
  const reference = {
@@ -12890,7 +12932,7 @@ const applyReferenceEffectsOnUrlInfo = (reference) => {
12890
12932
  }
12891
12933
  referencedUrlInfo.firstReference = reference;
12892
12934
  referencedUrlInfo.originalUrl =
12893
- referencedUrlInfo.originalUrl || reference.url;
12935
+ referencedUrlInfo.originalUrl || (reference.original || reference).url;
12894
12936
 
12895
12937
  if (reference.isEntryPoint || isWebWorkerEntryPointReference(reference)) {
12896
12938
  referencedUrlInfo.isEntryPoint = true;
@@ -13791,22 +13833,6 @@ const createUrlInfoTransformer = ({
13791
13833
  if (!may || !shouldHandle) {
13792
13834
  return;
13793
13835
  }
13794
- // sourcemap is a special kind of reference:
13795
- // It's a reference to a content generated dynamically the content itself.
13796
- // when jsenv is done cooking the file
13797
- // during build it's urlInfo.url to be inside the build
13798
- // but otherwise it's generatedUrl to be inside .jsenv/ directory
13799
- const generatedUrlObject = new URL(urlInfo.generatedUrl);
13800
- generatedUrlObject.searchParams.delete("js_module_fallback");
13801
- generatedUrlObject.searchParams.delete("as_js_module");
13802
- generatedUrlObject.searchParams.delete("as_js_classic");
13803
- generatedUrlObject.searchParams.delete("as_css_module");
13804
- generatedUrlObject.searchParams.delete("as_json_module");
13805
- generatedUrlObject.searchParams.delete("as_text_module");
13806
- generatedUrlObject.searchParams.delete("dynamic_import");
13807
- generatedUrlObject.searchParams.delete("cjs_as_js_module");
13808
- const urlForSourcemap = generatedUrlObject.href;
13809
- urlInfo.sourcemapGeneratedUrl = generateSourcemapFileUrl(urlForSourcemap);
13810
13836
 
13811
13837
  // case #1: already loaded during "load" hook
13812
13838
  // - happens during build
@@ -14228,7 +14254,11 @@ const createKitchen = ({
14228
14254
  reference.type !== "js_import"
14229
14255
  ) {
14230
14256
  referenceUrl = `ignore:${referenceUrl}`;
14231
- } else if (isIgnored(referenceUrl)) {
14257
+ } else if (
14258
+ reference.url && reference.original
14259
+ ? isIgnored(reference.original.url)
14260
+ : isIgnored(referenceUrl)
14261
+ ) {
14232
14262
  referenceUrl = `ignore:${referenceUrl}`;
14233
14263
  }
14234
14264
 
@@ -14320,13 +14350,16 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
14320
14350
  kitchenContext.resolveReference = resolveReference;
14321
14351
 
14322
14352
  const finalizeReference = (reference) => {
14353
+ const urlInfo = reference.urlInfo;
14354
+ urlInfo.generatedUrl = determineFileUrlForOutDirectory(urlInfo);
14355
+ urlInfo.sourcemapGeneratedUrl = determineSourcemapFileUrl(urlInfo);
14356
+
14323
14357
  if (reference.isImplicit && reference.isWeak) {
14324
14358
  // not needed for implicit references that are not rendered anywhere
14325
14359
  // this condition excludes:
14326
14360
  // - side_effect_file references injected in entry points or at the top of files
14327
14361
  return;
14328
14362
  }
14329
-
14330
14363
  {
14331
14364
  // This hook must touch reference.generatedUrl, NOT reference.url
14332
14365
  // And this is because this hook inject query params used to:
@@ -14433,7 +14466,9 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
14433
14466
  urlInfo.subtypeHint ||
14434
14467
  "";
14435
14468
  // during build urls info are reused and load returns originalUrl/originalContent
14436
- urlInfo.originalUrl = originalUrl || urlInfo.originalUrl;
14469
+ urlInfo.originalUrl = originalUrl
14470
+ ? String(originalUrl)
14471
+ : urlInfo.originalUrl;
14437
14472
  if (data) {
14438
14473
  Object.assign(urlInfo.data, data);
14439
14474
  }
@@ -14444,7 +14479,6 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
14444
14479
  urlInfo,
14445
14480
  content,
14446
14481
  });
14447
- urlInfo.generatedUrl = determineFileUrlForOutDirectory(urlInfo);
14448
14482
 
14449
14483
  // we wait here to read .contentAst and .originalContentAst
14450
14484
  // so that we don't trigger lazy getters
@@ -14781,30 +14815,6 @@ const inferUrlInfoType = (urlInfo) => {
14781
14815
  return "other";
14782
14816
  };
14783
14817
 
14784
- const determineFileUrlForOutDirectory = (urlInfo) => {
14785
- if (!urlInfo.context.outDirectoryUrl) {
14786
- return urlInfo.url;
14787
- }
14788
- if (!urlInfo.url.startsWith("file:")) {
14789
- return urlInfo.url;
14790
- }
14791
- let url = urlInfo.url;
14792
- if (!urlIsInsideOf(urlInfo.url, urlInfo.context.rootDirectoryUrl)) {
14793
- const fsRootUrl = ensureWindowsDriveLetter("file:///", urlInfo.url);
14794
- url = `${urlInfo.context.rootDirectoryUrl}@fs/${url.slice(
14795
- fsRootUrl.length,
14796
- )}`;
14797
- }
14798
- if (urlInfo.filenameHint) {
14799
- url = setUrlFilename(url, urlInfo.filenameHint);
14800
- }
14801
- return moveUrl({
14802
- url,
14803
- from: urlInfo.context.rootDirectoryUrl,
14804
- to: urlInfo.context.outDirectoryUrl,
14805
- });
14806
- };
14807
-
14808
14818
  const createUrlGraphSummary = (
14809
14819
  urlGraph,
14810
14820
  { title = "graph summary" } = {},
@@ -18305,17 +18315,27 @@ const createNodeEsmResolver = ({
18305
18315
  const { ownerUrlInfo } = reference;
18306
18316
  if (reference.specifier === "/") {
18307
18317
  const { mainFilePath, rootDirectoryUrl } = ownerUrlInfo.context;
18308
- return String(new URL(mainFilePath, rootDirectoryUrl));
18318
+ const url = new URL(mainFilePath, rootDirectoryUrl);
18319
+ return url;
18309
18320
  }
18310
18321
  if (reference.specifier[0] === "/") {
18311
- return new URL(
18322
+ const url = new URL(
18312
18323
  reference.specifier.slice(1),
18313
18324
  ownerUrlInfo.context.rootDirectoryUrl,
18314
- ).href;
18325
+ );
18326
+ return url;
18327
+ }
18328
+ let parentUrl;
18329
+ if (reference.baseUrl) {
18330
+ parentUrl = reference.baseUrl;
18331
+ } else if (ownerUrlInfo.originalUrl?.startsWith("http")) {
18332
+ parentUrl = ownerUrlInfo.originalUrl;
18333
+ } else {
18334
+ parentUrl = ownerUrlInfo.url;
18315
18335
  }
18316
- const parentUrl = reference.baseUrl || ownerUrlInfo.url;
18317
18336
  if (!parentUrl.startsWith("file:")) {
18318
- return new URL(reference.specifier, parentUrl).href;
18337
+ const url = new URL(reference.specifier, parentUrl);
18338
+ return url;
18319
18339
  }
18320
18340
  const { url, type, packageDirectoryUrl } = applyNodeEsmResolution({
18321
18341
  conditions: packageConditions,
@@ -18502,20 +18522,22 @@ const jsenvPluginWebResolution = () => {
18502
18522
  const { ownerUrlInfo } = reference;
18503
18523
  if (reference.specifier === "/") {
18504
18524
  const { mainFilePath, rootDirectoryUrl } = ownerUrlInfo.context;
18505
- return String(new URL(mainFilePath, rootDirectoryUrl));
18525
+ const url = new URL(mainFilePath, rootDirectoryUrl);
18526
+ return url;
18506
18527
  }
18507
18528
  if (reference.specifier[0] === "/") {
18508
- return new URL(
18529
+ const url = new URL(
18509
18530
  reference.specifier.slice(1),
18510
18531
  ownerUrlInfo.context.rootDirectoryUrl,
18511
- ).href;
18532
+ );
18533
+ return url;
18512
18534
  }
18513
- return new URL(
18514
- reference.specifier,
18515
- // baseUrl happens second argument to new URL() is different from
18516
- // import.meta.url or document.currentScript.src
18517
- reference.baseUrl || ownerUrlInfo.url,
18518
- ).href;
18535
+ // baseUrl happens second argument to new URL() is different from
18536
+ // import.meta.url or document.currentScript.src
18537
+ const parentUrl =
18538
+ reference.baseUrl || ownerUrlInfo.originalUrl || ownerUrlInfo.url;
18539
+ const url = new URL(reference.specifier, parentUrl);
18540
+ return url;
18519
18541
  },
18520
18542
  };
18521
18543
  };
@@ -18623,10 +18645,18 @@ const jsenvPluginFsRedirection = ({
18623
18645
  if (!stat) {
18624
18646
  return null;
18625
18647
  }
18626
- const urlRaw = preserveSymlinks
18627
- ? urlObject.href
18628
- : resolveSymlink(urlObject.href);
18629
- const resolvedUrl = `${urlRaw}${search}${hash}`;
18648
+ const urlBeforeSymlinkResolution = urlObject.href;
18649
+ if (preserveSymlinks) {
18650
+ return `${urlBeforeSymlinkResolution}${search}${hash}`;
18651
+ }
18652
+ const urlAfterSymlinkResolution = resolveSymlink(
18653
+ urlBeforeSymlinkResolution,
18654
+ );
18655
+ if (urlAfterSymlinkResolution !== urlBeforeSymlinkResolution) {
18656
+ reference.leadsToASymlink = true;
18657
+ // reference.baseUrl = urlBeforeSymlinkResolution;
18658
+ }
18659
+ const resolvedUrl = `${urlAfterSymlinkResolution}${search}${hash}`;
18630
18660
  return resolvedUrl;
18631
18661
  },
18632
18662
  };
@@ -18704,17 +18734,17 @@ const jsenvPluginProtocolFile = ({
18704
18734
  return null;
18705
18735
  },
18706
18736
  formatReference: (reference) => {
18707
- if (!reference.generatedUrl.startsWith("file:")) {
18737
+ const { generatedUrl } = reference;
18738
+ if (!generatedUrl.startsWith("file:")) {
18708
18739
  return null;
18709
18740
  }
18710
18741
  const { rootDirectoryUrl } = reference.ownerUrlInfo.context;
18711
- if (urlIsInsideOf(reference.generatedUrl, rootDirectoryUrl)) {
18712
- return `/${urlToRelativeUrl(
18713
- reference.generatedUrl,
18714
- rootDirectoryUrl,
18715
- )}`;
18742
+ if (urlIsInsideOf(generatedUrl, rootDirectoryUrl)) {
18743
+ const result = `/${urlToRelativeUrl(generatedUrl, rootDirectoryUrl)}`;
18744
+ return result;
18716
18745
  }
18717
- return `/@fs/${reference.generatedUrl.slice("file:///".length)}`;
18746
+ const result = `/@fs/${generatedUrl.slice("file:///".length)}`;
18747
+ return result;
18718
18748
  },
18719
18749
  },
18720
18750
  {
@@ -18945,24 +18975,96 @@ const replacePlaceholders$1 = (html, replacers) => {
18945
18975
  });
18946
18976
  };
18947
18977
 
18948
- const jsenvPluginProtocolHttp = () => {
18978
+ const jsenvPluginProtocolHttp = ({ include }) => {
18979
+ if (include === false) {
18980
+ return {
18981
+ name: "jsenv:protocol_http",
18982
+ appliesDuring: "*",
18983
+ redirectReference: (reference) => {
18984
+ if (!reference.url.startsWith("http")) {
18985
+ return null;
18986
+ }
18987
+ return `ignore:${reference.url}`;
18988
+ },
18989
+ };
18990
+ }
18991
+ const shouldInclude =
18992
+ include === true
18993
+ ? () => true
18994
+ : URL_META.createFilter(include, "http://jsenv.com");
18995
+
18949
18996
  return {
18950
18997
  name: "jsenv:protocol_http",
18951
- appliesDuring: "*",
18998
+ appliesDuring: "build",
18999
+ // resolveReference: (reference) => {
19000
+ // if (reference.original && reference.original.url.startsWith("http")) {
19001
+ // return new URL(reference.specifier, reference.original.url);
19002
+ // }
19003
+ // return null;
19004
+ // },
18952
19005
  redirectReference: (reference) => {
18953
- // TODO: according to some pattern matching jsenv could be allowed
18954
- // to fetch and transform http urls
18955
- if (
18956
- reference.url.startsWith("http:") ||
18957
- reference.url.startsWith("https:")
18958
- ) {
19006
+ if (!reference.url.startsWith("http")) {
19007
+ return null;
19008
+ }
19009
+ if (!shouldInclude(reference.url)) {
18959
19010
  return `ignore:${reference.url}`;
18960
19011
  }
18961
- return null;
19012
+ const outDirectoryUrl = reference.ownerUrlInfo.context.outDirectoryUrl;
19013
+ const urlObject = new URL(reference.url);
19014
+ const { host, pathname, search } = urlObject;
19015
+ let fileUrl = String(outDirectoryUrl);
19016
+ if (reference.url.startsWith("http:")) {
19017
+ fileUrl += "@http/";
19018
+ } else {
19019
+ fileUrl += "@https/";
19020
+ }
19021
+ fileUrl += asValidFilename(host);
19022
+ if (pathname) {
19023
+ fileUrl += "/";
19024
+ fileUrl += asValidFilename(pathname);
19025
+ }
19026
+ if (search) {
19027
+ fileUrl += search;
19028
+ }
19029
+ return fileUrl;
19030
+ },
19031
+ fetchUrlContent: async (urlInfo) => {
19032
+ if (!urlInfo.originalUrl.startsWith("http")) {
19033
+ return null;
19034
+ }
19035
+ const response = await fetch(urlInfo.originalUrl);
19036
+ const responseStatus = response.status;
19037
+ if (responseStatus < 200 || responseStatus > 299) {
19038
+ throw new Error(`unexpected response status ${responseStatus}`);
19039
+ }
19040
+ const responseHeaders = response.headers;
19041
+ const responseContentType = responseHeaders.get("content-type");
19042
+ const contentType = responseContentType || "application/octet-stream";
19043
+ const isTextual = CONTENT_TYPE.isTextual(contentType);
19044
+ let content;
19045
+ if (isTextual) {
19046
+ content = await response.text();
19047
+ } else {
19048
+ content = await response.buffer;
19049
+ }
19050
+ return {
19051
+ content,
19052
+ contentType,
19053
+ contentLength: responseHeaders.get("content-length") || undefined,
19054
+ };
18962
19055
  },
18963
19056
  };
18964
19057
  };
18965
19058
 
19059
+ // see https://github.com/parshap/node-sanitize-filename/blob/master/index.js
19060
+ const asValidFilename = (string) => {
19061
+ string = string.trim().toLowerCase();
19062
+ if (string === ".") return "_";
19063
+ if (string === "..") return "__";
19064
+ string = string.replace(/[ ,]/g, "_").replace(/["/?<>\\:*|]/g, "");
19065
+ return string;
19066
+ };
19067
+
18966
19068
  const jsenvPluginInjections = (rawAssociations) => {
18967
19069
  let resolvedAssociations;
18968
19070
 
@@ -20348,6 +20450,7 @@ const getCorePlugins = ({
20348
20450
  injections,
20349
20451
  transpilation = true,
20350
20452
  inlining = true,
20453
+ http = false,
20351
20454
 
20352
20455
  clientAutoreload,
20353
20456
  cacheControl,
@@ -20363,6 +20466,12 @@ const getCorePlugins = ({
20363
20466
  if (ribbon === true) {
20364
20467
  ribbon = {};
20365
20468
  }
20469
+ if (http === true) {
20470
+ http = { include: true };
20471
+ }
20472
+ if (http === false) {
20473
+ http = { include: false };
20474
+ }
20366
20475
 
20367
20476
  return [
20368
20477
  jsenvPluginReferenceAnalysis(referenceAnalysis),
@@ -20377,11 +20486,12 @@ const getCorePlugins = ({
20377
20486
  - reference inside a js module -> resolved by node esm
20378
20487
  - All the rest uses web standard url resolution
20379
20488
  */
20489
+ jsenvPluginProtocolHttp(http),
20380
20490
  jsenvPluginProtocolFile({
20381
20491
  magicExtensions,
20382
20492
  magicDirectoryIndex,
20383
20493
  }),
20384
- jsenvPluginProtocolHttp(),
20494
+
20385
20495
  ...(nodeEsmResolution
20386
20496
  ? [jsenvPluginNodeEsmResolution(nodeEsmResolution)]
20387
20497
  : []),
@@ -20844,6 +20954,42 @@ const createBuildSpecifierManager = ({
20844
20954
  const url = new URL(reference.specifier, parentUrl).href;
20845
20955
  return url;
20846
20956
  },
20957
+ redirectReference: (reference) => {
20958
+ let referenceBeforeInlining = reference;
20959
+ if (
20960
+ referenceBeforeInlining.isInline &&
20961
+ referenceBeforeInlining.prev &&
20962
+ !referenceBeforeInlining.prev.isInline
20963
+ ) {
20964
+ referenceBeforeInlining = referenceBeforeInlining.prev;
20965
+ }
20966
+ const rawUrl = referenceBeforeInlining.url;
20967
+ const rawUrlInfo = rawKitchen.graph.getUrlInfo(rawUrl);
20968
+ if (rawUrlInfo) {
20969
+ reference.filenameHint = rawUrlInfo.filenameHint;
20970
+ return null;
20971
+ }
20972
+ if (referenceBeforeInlining.injected) {
20973
+ return null;
20974
+ }
20975
+ if (
20976
+ referenceBeforeInlining.isInline &&
20977
+ referenceBeforeInlining.ownerUrlInfo.url ===
20978
+ referenceBeforeInlining.ownerUrlInfo.originalUrl
20979
+ ) {
20980
+ const rawUrlInfo = findRawUrlInfoWhenInline(
20981
+ referenceBeforeInlining,
20982
+ rawKitchen,
20983
+ );
20984
+ if (rawUrlInfo) {
20985
+ reference.rawUrl = rawUrlInfo.url;
20986
+ reference.filenameHint = rawUrlInfo.filenameHint;
20987
+ return null;
20988
+ }
20989
+ }
20990
+ reference.filenameHint = referenceBeforeInlining.filenameHint;
20991
+ return null;
20992
+ },
20847
20993
  transformReferenceSearchParams: () => {
20848
20994
  // those search params are reflected into the build file name
20849
20995
  // moreover it create cleaner output
@@ -20888,13 +21034,10 @@ const createBuildSpecifierManager = ({
20888
21034
  ) {
20889
21035
  firstReference = firstReference.prev;
20890
21036
  }
20891
- const rawUrl = firstReference.url;
21037
+ const rawUrl = firstReference.rawUrl || firstReference.url;
20892
21038
  const rawUrlInfo = rawKitchen.graph.getUrlInfo(rawUrl);
20893
21039
  const bundleInfo = bundleInfoMap.get(rawUrl);
20894
21040
  if (bundleInfo) {
20895
- if (rawUrlInfo && !finalUrlInfo.filenameHint) {
20896
- finalUrlInfo.filenameHint = rawUrlInfo.filenameHint;
20897
- }
20898
21041
  finalUrlInfo.remapReference = bundleInfo.remapReference;
20899
21042
  return {
20900
21043
  // url: bundleInfo.url,
@@ -20907,9 +21050,6 @@ const createBuildSpecifierManager = ({
20907
21050
  };
20908
21051
  }
20909
21052
  if (rawUrlInfo) {
20910
- if (rawUrlInfo && !finalUrlInfo.filenameHint) {
20911
- finalUrlInfo.filenameHint = rawUrlInfo.filenameHint;
20912
- }
20913
21053
  return rawUrlInfo;
20914
21054
  }
20915
21055
  // reference injected during "shape":
@@ -20931,9 +21071,6 @@ const createBuildSpecifierManager = ({
20931
21071
  content: reference.content,
20932
21072
  contentType: reference.contentType,
20933
21073
  });
20934
- if (!finalUrlInfo.filenameHint) {
20935
- finalUrlInfo.filenameHint = reference.filenameHint;
20936
- }
20937
21074
  const rawUrlInfo = rawReference.urlInfo;
20938
21075
  await rawUrlInfo.cook();
20939
21076
  return {
@@ -20950,48 +21087,17 @@ const createBuildSpecifierManager = ({
20950
21087
  firstReference.ownerUrlInfo.url ===
20951
21088
  firstReference.ownerUrlInfo.originalUrl
20952
21089
  ) {
20953
- const rawUrlInfo = GRAPH_VISITOR.find(
20954
- rawKitchen.graph,
20955
- (rawUrlInfoCandidate) => {
20956
- const { inlineUrlSite } = rawUrlInfoCandidate;
20957
- if (!inlineUrlSite) {
20958
- return false;
20959
- }
20960
- if (
20961
- inlineUrlSite.url === firstReference.ownerUrlInfo.url &&
20962
- inlineUrlSite.line === firstReference.specifierLine &&
20963
- inlineUrlSite.column === firstReference.specifierColumn
20964
- ) {
20965
- return true;
20966
- }
20967
- if (rawUrlInfoCandidate.content === firstReference.content) {
20968
- return true;
20969
- }
20970
- if (
20971
- rawUrlInfoCandidate.originalContent === firstReference.content
20972
- ) {
20973
- return true;
20974
- }
20975
- return false;
20976
- },
20977
- );
20978
21090
  if (rawUrlInfo) {
20979
- if (!finalUrlInfo.filenameHint) {
20980
- finalUrlInfo.filenameHint = rawUrlInfo.filenameHint;
20981
- }
20982
21091
  return rawUrlInfo;
20983
21092
  }
20984
21093
  }
20985
- if (!finalUrlInfo.filenameHint) {
20986
- finalUrlInfo.filenameHint = firstReference.filenameHint;
20987
- }
20988
21094
  return {
20989
21095
  originalContent: finalUrlInfo.originalContent,
20990
21096
  content: firstReference.content,
20991
21097
  contentType: firstReference.contentType,
20992
21098
  };
20993
21099
  }
20994
- throw new Error(createDetailedMessage$1(`Cannot fetch ${rawUrl}`));
21100
+ throw new Error(createDetailedMessage$1(`${rawUrl} not found in graph`));
20995
21101
  },
20996
21102
  };
20997
21103
 
@@ -21421,10 +21527,15 @@ const createBuildSpecifierManager = ({
21421
21527
  if (urlInfo.isEntryPoint) {
21422
21528
  generateReplacement(urlInfo.firstReference);
21423
21529
  }
21424
- if (urlInfo.isInline) {
21425
- generateReplacement(urlInfo.firstReference);
21426
- }
21427
21530
  if (urlInfo.type === "sourcemap") {
21531
+ const { referenceFromOthersSet } = urlInfo;
21532
+ let lastRef;
21533
+ for (const ref of referenceFromOthersSet) {
21534
+ lastRef = ref;
21535
+ }
21536
+ generateReplacement(lastRef);
21537
+ }
21538
+ if (urlInfo.isInline) {
21428
21539
  generateReplacement(urlInfo.firstReference);
21429
21540
  }
21430
21541
  if (urlInfo.firstReference.type === "side_effect_file") {
@@ -21661,10 +21772,10 @@ const createBuildSpecifierManager = ({
21661
21772
  GRAPH_VISITOR.forEachUrlInfoStronglyReferenced(
21662
21773
  finalKitchen.graph.rootUrlInfo,
21663
21774
  (urlInfo) => {
21664
- if (!urlInfo.url.startsWith("file:")) {
21775
+ const buildUrl = urlInfoToBuildUrlMap.get(urlInfo);
21776
+ if (!buildUrl) {
21665
21777
  return;
21666
21778
  }
21667
- const buildUrl = urlInfoToBuildUrlMap.get(urlInfo);
21668
21779
  const buildSpecifier = buildUrlToBuildSpecifierMap.get(buildUrl);
21669
21780
  const buildSpecifierVersioned = versioning
21670
21781
  ? buildSpecifierToBuildSpecifierVersionedMap.get(buildSpecifier)
@@ -21716,6 +21827,33 @@ const createBuildSpecifierManager = ({
21716
21827
  };
21717
21828
  };
21718
21829
 
21830
+ const findRawUrlInfoWhenInline = (reference, rawKitchen) => {
21831
+ const rawUrlInfo = GRAPH_VISITOR.find(
21832
+ rawKitchen.graph,
21833
+ (rawUrlInfoCandidate) => {
21834
+ const { inlineUrlSite } = rawUrlInfoCandidate;
21835
+ if (!inlineUrlSite) {
21836
+ return false;
21837
+ }
21838
+ if (
21839
+ inlineUrlSite.url === reference.ownerUrlInfo.url &&
21840
+ inlineUrlSite.line === reference.specifierLine &&
21841
+ inlineUrlSite.column === reference.specifierColumn
21842
+ ) {
21843
+ return true;
21844
+ }
21845
+ if (rawUrlInfoCandidate.content === reference.content) {
21846
+ return true;
21847
+ }
21848
+ if (rawUrlInfoCandidate.originalContent === reference.content) {
21849
+ return true;
21850
+ }
21851
+ return false;
21852
+ },
21853
+ );
21854
+ return rawUrlInfo;
21855
+ };
21856
+
21719
21857
  // see https://github.com/rollup/rollup/blob/ce453507ab8457dd1ea3909d8dd7b117b2d14fab/src/utils/hashPlaceholders.ts#L1
21720
21858
  // see also "New hashing algorithm that "fixes (nearly) everything"
21721
21859
  // at https://github.com/rollup/rollup/pull/4543
@@ -22017,6 +22155,10 @@ const build = async ({
22017
22155
  signal = new AbortController().signal,
22018
22156
  handleSIGINT = true,
22019
22157
  logLevel = "info",
22158
+ logs = {
22159
+ disabled: false,
22160
+ animation: true,
22161
+ },
22020
22162
  sourceDirectoryUrl,
22021
22163
  buildDirectoryUrl,
22022
22164
  entryPoints = {},
@@ -22045,6 +22187,7 @@ const build = async ({
22045
22187
  sourceFilesConfig = {},
22046
22188
  cooldownBetweenFileEvents,
22047
22189
  watch = false,
22190
+ http = false,
22048
22191
 
22049
22192
  directoryToClean,
22050
22193
  sourcemaps = "none",
@@ -22155,8 +22298,9 @@ const build = async ({
22155
22298
  const logger = createLogger({ logLevel });
22156
22299
  const createBuildTask = (label) => {
22157
22300
  return createTaskLog(label, {
22158
- disabled: !logger.levels.debug && !logger.levels.info,
22159
- animated: !logger.levels.debug,
22301
+ disabled:
22302
+ logs.disabled || (!logger.levels.debug && !logger.levels.info),
22303
+ animated: logs.animation && !logger.levels.debug,
22160
22304
  });
22161
22305
  };
22162
22306
 
@@ -22231,6 +22375,7 @@ build ${entryPointKeys.length} entry points`);
22231
22375
  jsModuleFallback: false,
22232
22376
  },
22233
22377
  inlining: false,
22378
+ http,
22234
22379
  scenarioPlaceholders,
22235
22380
  }),
22236
22381
  ],