@jsenv/core 40.2.1 → 40.3.2

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.
@@ -1,7 +1,7 @@
1
1
  import stripAnsi from "strip-ansi";
2
2
  import { createSupportsColor, isUnicodeSupported, emojiRegex, eastAsianWidth, clearTerminal, eraseLines, createSupportsColor$1, isUnicodeSupported$1, emojiRegex$1, eastAsianWidth$1, clearTerminal$1, eraseLines$1, createSupportsColor$2, isUnicodeSupported$2, emojiRegex$2, eastAsianWidth$2, clearTerminal$2, eraseLines$2 } from "./jsenv_core_node_modules.js";
3
3
  import { stripVTControlCharacters } from "node:util";
4
- import { existsSync, chmodSync, statSync, lstatSync, readdirSync, openSync, closeSync, unlinkSync, rmdirSync, mkdirSync, readFileSync, writeFileSync as writeFileSync$2, watch, realpathSync, readdir, chmod, stat, lstat, promises, unlink, rmdir } from "node:fs";
4
+ import { existsSync, readFileSync as readFileSync$2, chmodSync, statSync, lstatSync, readdirSync, openSync, closeSync, unlinkSync, rmdirSync, mkdirSync, writeFileSync as writeFileSync$2, watch, realpathSync, readdir, chmod, stat, lstat, promises, unlink, rmdir } from "node:fs";
5
5
  import { extname } from "node:path";
6
6
  import crypto, { createHash } from "node:crypto";
7
7
  import { pathToFileURL, fileURLToPath } from "node:url";
@@ -621,6 +621,29 @@ const fillLeft$1 = (value, biggestValue, char = " ") => {
621
621
  return padded;
622
622
  };
623
623
 
624
+ const errorToHTML$1 = (error) => {
625
+ const errorIsAPrimitive =
626
+ error === null ||
627
+ (typeof error !== "object" && typeof error !== "function");
628
+
629
+ if (errorIsAPrimitive) {
630
+ if (typeof error === "string") {
631
+ return `<pre>${escapeHtml$1(error)}</pre>`;
632
+ }
633
+ return `<pre>${JSON.stringify(error, null, " ")}</pre>`;
634
+ }
635
+ return `<pre>${escapeHtml$1(error.stack)}</pre>`;
636
+ };
637
+
638
+ const escapeHtml$1 = (string) => {
639
+ return string
640
+ .replace(/&/g, "&amp;")
641
+ .replace(/</g, "&lt;")
642
+ .replace(/>/g, "&gt;")
643
+ .replace(/"/g, "&quot;")
644
+ .replace(/'/g, "&#039;");
645
+ };
646
+
624
647
  const LOG_LEVEL_OFF$2 = "off";
625
648
 
626
649
  const LOG_LEVEL_DEBUG$2 = "debug";
@@ -1867,8 +1890,11 @@ const getParentDirectoryUrl$1 = (url) => {
1867
1890
  return new URL(url.endsWith("/") ? "../" : "./", url).href;
1868
1891
  };
1869
1892
 
1870
- const findAncestorDirectoryUrl$1 = (url, callback) => {
1893
+ const findSelfOrAncestorDirectoryUrl$1 = (url, callback) => {
1871
1894
  url = String(url);
1895
+ if (!url.endsWith("/")) {
1896
+ url = new URL("./", url).href;
1897
+ }
1872
1898
  while (url !== "file:///") {
1873
1899
  if (callback(url)) {
1874
1900
  return url;
@@ -1879,12 +1905,25 @@ const findAncestorDirectoryUrl$1 = (url, callback) => {
1879
1905
  };
1880
1906
 
1881
1907
  const lookupPackageDirectory$1 = (currentUrl) => {
1882
- return findAncestorDirectoryUrl$1(currentUrl, (ancestorDirectoryUrl) => {
1908
+ return findSelfOrAncestorDirectoryUrl$1(currentUrl, (ancestorDirectoryUrl) => {
1883
1909
  const potentialPackageJsonFileUrl = `${ancestorDirectoryUrl}package.json`;
1884
1910
  return existsSync(new URL(potentialPackageJsonFileUrl));
1885
1911
  });
1886
1912
  };
1887
1913
 
1914
+ const readPackageAtOrNull$1 = (packageDirectoryUrl) => {
1915
+ try {
1916
+ const packageFileContent = readFileSync$2(
1917
+ new URL("./package.json", packageDirectoryUrl),
1918
+ "utf8",
1919
+ );
1920
+ const packageJSON = JSON.parse(packageFileContent);
1921
+ return packageJSON;
1922
+ } catch {
1923
+ return null;
1924
+ }
1925
+ };
1926
+
1888
1927
  /*
1889
1928
  * Link to things doing pattern matching:
1890
1929
  * https://git-scm.com/docs/gitignore
@@ -2839,6 +2878,33 @@ const normalizeMediaType$1 = (value) => {
2839
2878
  return value;
2840
2879
  };
2841
2880
 
2881
+ const readFileSync$1 = (value, { as } = {}) => {
2882
+ const fileUrl = assertAndNormalizeFileUrl$1(value);
2883
+ if (as === undefined) {
2884
+ const contentType = CONTENT_TYPE$1.fromUrlExtension(fileUrl);
2885
+ if (CONTENT_TYPE$1.isJson(contentType)) {
2886
+ as = "json";
2887
+ } else if (CONTENT_TYPE$1.isTextual(contentType)) {
2888
+ as = "string";
2889
+ } else {
2890
+ as = "buffer";
2891
+ }
2892
+ }
2893
+ const buffer = readFileSync$2(new URL(fileUrl));
2894
+ if (as === "buffer") {
2895
+ return buffer;
2896
+ }
2897
+ if (as === "string") {
2898
+ return buffer.toString();
2899
+ }
2900
+ if (as === "json") {
2901
+ return JSON.parse(buffer.toString());
2902
+ }
2903
+ throw new Error(
2904
+ `"as" must be one of "buffer","string","json" received "${as}"`,
2905
+ );
2906
+ };
2907
+
2842
2908
  const removeEntrySync$1 = (
2843
2909
  source,
2844
2910
  {
@@ -3064,7 +3130,7 @@ const writeDirectorySync$1 = (
3064
3130
  if (e.code === "ENOTDIR") {
3065
3131
  let previousNonDirUrl = destinationUrl;
3066
3132
  // we must try all parent directories as long as it fails with ENOTDIR
3067
- findAncestorDirectoryUrl$1(destinationUrl, (ancestorUrl) => {
3133
+ findSelfOrAncestorDirectoryUrl$1(destinationUrl, (ancestorUrl) => {
3068
3134
  try {
3069
3135
  statSync(new URL(ancestorUrl));
3070
3136
  return true;
@@ -3128,7 +3194,7 @@ const writeFileSync$1 = (destination, content = "", { force } = {}) => {
3128
3194
  const destinationUrl = assertAndNormalizeFileUrl$1(destination);
3129
3195
  const destinationUrlObject = new URL(destinationUrl);
3130
3196
  if (content && content instanceof URL) {
3131
- content = readFileSync(content);
3197
+ content = readFileSync$2(content);
3132
3198
  }
3133
3199
  try {
3134
3200
  writeFileSync$2(destinationUrlObject, content);
@@ -3154,6 +3220,31 @@ const writeFileSync$1 = (destination, content = "", { force } = {}) => {
3154
3220
  }
3155
3221
  };
3156
3222
 
3223
+ const updateJsonFileSync$1 = (fileUrl, values = {}) => {
3224
+ try {
3225
+ const jsonString = readFileSync$1(fileUrl, { as: "string" });
3226
+ const json = JSON.parse(jsonString);
3227
+ const newContent = { ...json };
3228
+ for (const key of Object.keys(values)) {
3229
+ const value = values[key];
3230
+ newContent[key] = value;
3231
+ }
3232
+ let jsonFormatted;
3233
+ if (jsonString.startsWith("{\n")) {
3234
+ jsonFormatted = JSON.stringify(newContent, null, " ");
3235
+ } else {
3236
+ jsonFormatted = JSON.stringify(newContent);
3237
+ }
3238
+ writeFileSync$1(fileUrl, jsonFormatted);
3239
+ } catch (e) {
3240
+ if (e.code === "ENOENT") {
3241
+ writeFileSync$1(fileUrl, JSON.stringify(values));
3242
+ return;
3243
+ }
3244
+ throw e;
3245
+ }
3246
+ };
3247
+
3157
3248
  const callOnceIdlePerFile$1 = (callback, idleMs) => {
3158
3249
  const timeoutIdMap = new Map();
3159
3250
  return (fileEvent) => {
@@ -3791,7 +3882,7 @@ const defaultLookupPackageScope$1 = (url) => {
3791
3882
 
3792
3883
  const defaultReadPackageJson$1 = (packageUrl) => {
3793
3884
  const packageJsonUrl = new URL("package.json", packageUrl);
3794
- const buffer = readFileSync(packageJsonUrl);
3885
+ const buffer = readFileSync$2(packageJsonUrl);
3795
3886
  const string = String(buffer);
3796
3887
  try {
3797
3888
  return JSON.parse(string);
@@ -4647,7 +4738,7 @@ const mainLegacyResolvers$1 = {
4647
4738
  };
4648
4739
  }
4649
4740
  const browserMainUrlObject = new URL(browserMain, packageDirectoryUrl);
4650
- const content = readFileSync(browserMainUrlObject, "utf-8");
4741
+ const content = readFileSync$2(browserMainUrlObject, "utf-8");
4651
4742
  if (
4652
4743
  (/typeof exports\s*==/.test(content) &&
4653
4744
  /typeof module\s*==/.test(content)) ||
@@ -6676,7 +6767,7 @@ const injectSideEffectFileIntoBabelAst$1 = ({
6676
6767
  });
6677
6768
  return;
6678
6769
  }
6679
- const sidEffectFileContent = readFileSync(new URL(sideEffectFileUrl), "utf8");
6770
+ const sidEffectFileContent = readFileSync$2(new URL(sideEffectFileUrl), "utf8");
6680
6771
  const sideEffectFileContentAst = babel.parse(sidEffectFileContent);
6681
6772
  if (isJsModule) {
6682
6773
  injectAstAfterImport$1(programPath, sideEffectFileContentAst);
@@ -9439,6 +9530,29 @@ const fillLeft = (value, biggestValue, char = " ") => {
9439
9530
  return padded;
9440
9531
  };
9441
9532
 
9533
+ const errorToHTML = (error) => {
9534
+ const errorIsAPrimitive =
9535
+ error === null ||
9536
+ (typeof error !== "object" && typeof error !== "function");
9537
+
9538
+ if (errorIsAPrimitive) {
9539
+ if (typeof error === "string") {
9540
+ return `<pre>${escapeHtml(error)}</pre>`;
9541
+ }
9542
+ return `<pre>${JSON.stringify(error, null, " ")}</pre>`;
9543
+ }
9544
+ return `<pre>${escapeHtml(error.stack)}</pre>`;
9545
+ };
9546
+
9547
+ const escapeHtml = (string) => {
9548
+ return string
9549
+ .replace(/&/g, "&amp;")
9550
+ .replace(/</g, "&lt;")
9551
+ .replace(/>/g, "&gt;")
9552
+ .replace(/"/g, "&quot;")
9553
+ .replace(/'/g, "&#039;");
9554
+ };
9555
+
9442
9556
  const renderBigSection = (params) => {
9443
9557
  return renderSection({
9444
9558
  width: 45,
@@ -10820,8 +10934,11 @@ const getParentDirectoryUrl = (url) => {
10820
10934
  return new URL(url.endsWith("/") ? "../" : "./", url).href;
10821
10935
  };
10822
10936
 
10823
- const findAncestorDirectoryUrl = (url, callback) => {
10937
+ const findSelfOrAncestorDirectoryUrl = (url, callback) => {
10824
10938
  url = String(url);
10939
+ if (!url.endsWith("/")) {
10940
+ url = new URL("./", url).href;
10941
+ }
10825
10942
  while (url !== "file:///") {
10826
10943
  if (callback(url)) {
10827
10944
  return url;
@@ -10832,15 +10949,54 @@ const findAncestorDirectoryUrl = (url, callback) => {
10832
10949
  };
10833
10950
 
10834
10951
  const lookupPackageDirectory = (currentUrl) => {
10835
- return findAncestorDirectoryUrl(currentUrl, (ancestorDirectoryUrl) => {
10952
+ return findSelfOrAncestorDirectoryUrl(currentUrl, (ancestorDirectoryUrl) => {
10836
10953
  const potentialPackageJsonFileUrl = `${ancestorDirectoryUrl}package.json`;
10837
10954
  return existsSync(new URL(potentialPackageJsonFileUrl));
10838
10955
  });
10839
10956
  };
10840
10957
 
10958
+ const createLookupPackageDirectory = () => {
10959
+ const cache = new Map();
10960
+ const lookupPackageDirectoryWithCache = (currentUrl) => {
10961
+ const directoryUrls = [];
10962
+ currentUrl = String(currentUrl);
10963
+ if (currentUrl.endsWith("/")) {
10964
+ directoryUrls.push(currentUrl);
10965
+ } else {
10966
+ const directoryUrl = new URL("./", currentUrl).href;
10967
+ directoryUrls.push(directoryUrl);
10968
+ currentUrl = directoryUrl;
10969
+ }
10970
+ while (currentUrl !== "file:///") {
10971
+ const fromCache = cache.get(currentUrl);
10972
+ if (fromCache !== undefined) {
10973
+ return fromCache;
10974
+ }
10975
+ const packageJsonUrlCandidate = `${currentUrl}package.json`;
10976
+ if (existsSync(new URL(packageJsonUrlCandidate))) {
10977
+ for (const directoryUrl of directoryUrls) {
10978
+ cache.set(directoryUrl, currentUrl);
10979
+ }
10980
+ return currentUrl;
10981
+ }
10982
+ const directoryUrl = getParentDirectoryUrl(currentUrl);
10983
+ directoryUrls.push(directoryUrl);
10984
+ currentUrl = directoryUrl;
10985
+ }
10986
+ for (const directoryUrl of directoryUrls) {
10987
+ cache.set(directoryUrl, null);
10988
+ }
10989
+ return null;
10990
+ };
10991
+ lookupPackageDirectoryWithCache.clearCache = () => {
10992
+ cache.clear();
10993
+ };
10994
+ return lookupPackageDirectoryWithCache;
10995
+ };
10996
+
10841
10997
  const readPackageAtOrNull = (packageDirectoryUrl) => {
10842
10998
  try {
10843
- const packageFileContent = readFileSync(
10999
+ const packageFileContent = readFileSync$2(
10844
11000
  new URL("./package.json", packageDirectoryUrl),
10845
11001
  "utf8",
10846
11002
  );
@@ -11994,6 +12150,33 @@ const normalizeMediaType = (value) => {
11994
12150
  return value;
11995
12151
  };
11996
12152
 
12153
+ const readFileSync = (value, { as } = {}) => {
12154
+ const fileUrl = assertAndNormalizeFileUrl(value);
12155
+ if (as === undefined) {
12156
+ const contentType = CONTENT_TYPE.fromUrlExtension(fileUrl);
12157
+ if (CONTENT_TYPE.isJson(contentType)) {
12158
+ as = "json";
12159
+ } else if (CONTENT_TYPE.isTextual(contentType)) {
12160
+ as = "string";
12161
+ } else {
12162
+ as = "buffer";
12163
+ }
12164
+ }
12165
+ const buffer = readFileSync$2(new URL(fileUrl));
12166
+ if (as === "buffer") {
12167
+ return buffer;
12168
+ }
12169
+ if (as === "string") {
12170
+ return buffer.toString();
12171
+ }
12172
+ if (as === "json") {
12173
+ return JSON.parse(buffer.toString());
12174
+ }
12175
+ throw new Error(
12176
+ `"as" must be one of "buffer","string","json" received "${as}"`,
12177
+ );
12178
+ };
12179
+
11997
12180
  const removeEntrySync = (
11998
12181
  source,
11999
12182
  {
@@ -12219,7 +12402,7 @@ const writeDirectorySync = (
12219
12402
  if (e.code === "ENOTDIR") {
12220
12403
  let previousNonDirUrl = destinationUrl;
12221
12404
  // we must try all parent directories as long as it fails with ENOTDIR
12222
- findAncestorDirectoryUrl(destinationUrl, (ancestorUrl) => {
12405
+ findSelfOrAncestorDirectoryUrl(destinationUrl, (ancestorUrl) => {
12223
12406
  try {
12224
12407
  statSync(new URL(ancestorUrl));
12225
12408
  return true;
@@ -12283,7 +12466,7 @@ const writeFileSync = (destination, content = "", { force } = {}) => {
12283
12466
  const destinationUrl = assertAndNormalizeFileUrl(destination);
12284
12467
  const destinationUrlObject = new URL(destinationUrl);
12285
12468
  if (content && content instanceof URL) {
12286
- content = readFileSync(content);
12469
+ content = readFileSync$2(content);
12287
12470
  }
12288
12471
  try {
12289
12472
  writeFileSync$2(destinationUrlObject, content);
@@ -12556,6 +12739,31 @@ const removeDirectoryNaive = (
12556
12739
  });
12557
12740
  };
12558
12741
 
12742
+ const updateJsonFileSync = (fileUrl, values = {}) => {
12743
+ try {
12744
+ const jsonString = readFileSync(fileUrl, { as: "string" });
12745
+ const json = JSON.parse(jsonString);
12746
+ const newContent = { ...json };
12747
+ for (const key of Object.keys(values)) {
12748
+ const value = values[key];
12749
+ newContent[key] = value;
12750
+ }
12751
+ let jsonFormatted;
12752
+ if (jsonString.startsWith("{\n")) {
12753
+ jsonFormatted = JSON.stringify(newContent, null, " ");
12754
+ } else {
12755
+ jsonFormatted = JSON.stringify(newContent);
12756
+ }
12757
+ writeFileSync(fileUrl, jsonFormatted);
12758
+ } catch (e) {
12759
+ if (e.code === "ENOENT") {
12760
+ writeFileSync(fileUrl, JSON.stringify(values));
12761
+ return;
12762
+ }
12763
+ throw e;
12764
+ }
12765
+ };
12766
+
12559
12767
  const ensureEmptyDirectory = async (source) => {
12560
12768
  const stats = await readEntryStat(source, {
12561
12769
  nullIfNotFound: true,
@@ -13337,7 +13545,7 @@ const defaultLookupPackageScope = (url) => {
13337
13545
 
13338
13546
  const defaultReadPackageJson = (packageUrl) => {
13339
13547
  const packageJsonUrl = new URL("package.json", packageUrl);
13340
- const buffer = readFileSync(packageJsonUrl);
13548
+ const buffer = readFileSync$2(packageJsonUrl);
13341
13549
  const string = String(buffer);
13342
13550
  try {
13343
13551
  return JSON.parse(string);
@@ -14193,7 +14401,7 @@ const mainLegacyResolvers = {
14193
14401
  };
14194
14402
  }
14195
14403
  const browserMainUrlObject = new URL(browserMain, packageDirectoryUrl);
14196
- const content = readFileSync(browserMainUrlObject, "utf-8");
14404
+ const content = readFileSync$2(browserMainUrlObject, "utf-8");
14197
14405
  if (
14198
14406
  (/typeof exports\s*==/.test(content) &&
14199
14407
  /typeof module\s*==/.test(content)) ||
@@ -14644,6 +14852,7 @@ const bundleJsModules = async (
14644
14852
  signal,
14645
14853
  logger,
14646
14854
  rootDirectoryUrl,
14855
+ packageDirectory,
14647
14856
  runtimeCompat,
14648
14857
  sourcemaps,
14649
14858
  isSupportedOnCurrentClients,
@@ -14685,9 +14894,8 @@ const bundleJsModules = async (
14685
14894
  if (chunks) {
14686
14895
  let workspaces;
14687
14896
  let packageName;
14688
- const packageDirectoryUrl = lookupPackageDirectory(rootDirectoryUrl);
14689
- if (packageDirectoryUrl) {
14690
- const packageJSON = readPackageAtOrNull(packageDirectoryUrl);
14897
+ if (packageDirectory.url) {
14898
+ const packageJSON = packageDirectory.read(packageDirectory.url);
14691
14899
  if (packageJSON) {
14692
14900
  packageName = packageJSON.name;
14693
14901
  workspaces = packageJSON.workspaces;
@@ -14718,7 +14926,7 @@ const bundleJsModules = async (
14718
14926
  for (const workspace of workspaces) {
14719
14927
  const workspacePattern = new URL(
14720
14928
  workspace.endsWith("/*") ? workspace.slice(0, -1) : workspace,
14721
- packageDirectoryUrl,
14929
+ packageDirectory.url,
14722
14930
  ).href;
14723
14931
  workspacePatterns[workspacePattern] = true;
14724
14932
  }
@@ -14919,96 +15127,29 @@ const rollupPluginJsenv = ({
14919
15127
  return new URL(rollupFileInfo.fileName, buildDirectoryUrl).href;
14920
15128
  };
14921
15129
 
14922
- const packageSideEffectsCacheMap = new Map();
14923
- const readClosestPackageJsonSideEffects = (url) => {
14924
- const packageDirectoryUrl = lookupPackageDirectory(url);
14925
- if (!packageDirectoryUrl) {
14926
- return undefined;
14927
- }
14928
- const fromCache = packageSideEffectsCacheMap.get(packageDirectoryUrl);
14929
- if (fromCache) {
14930
- return fromCache.value;
14931
- }
14932
- try {
14933
- const packageFileContent = readFileSync(
14934
- new URL("./package.json", packageDirectoryUrl),
14935
- "utf8",
14936
- );
14937
- const packageJSON = JSON.parse(packageFileContent);
14938
- return storePackageSideEffect(packageDirectoryUrl, packageJSON);
14939
- } catch {
14940
- return storePackageSideEffect(packageDirectoryUrl, null);
14941
- }
14942
- };
14943
- const storePackageSideEffect = (packageDirectoryUrl, packageJson) => {
14944
- if (!packageJson) {
14945
- packageSideEffectsCacheMap.set(packageDirectoryUrl, { value: undefined });
14946
- return undefined;
14947
- }
14948
- const value = packageJson.sideEffects;
14949
- if (Array.isArray(value)) {
14950
- const sideEffectPatterns = {};
14951
- for (const v of value) {
14952
- sideEffectPatterns[v] = true;
14953
- }
14954
- const associations = URL_META.resolveAssociations(
14955
- { sideEffects: sideEffectPatterns },
14956
- packageDirectoryUrl,
14957
- );
14958
- const isMatching = (url) => {
14959
- const meta = URL_META.applyAssociations({ url, associations });
14960
- return meta.sideEffects || false;
14961
- };
14962
- packageSideEffectsCacheMap.set(packageDirectoryUrl, {
14963
- value: isMatching,
14964
- });
14965
- return isMatching;
14966
- }
14967
- packageSideEffectsCacheMap.set(packageDirectoryUrl, { value });
14968
- return value;
14969
- };
14970
-
14971
- const inferSideEffectsFromResolvedUrl = (url) => {
15130
+ const getModuleSideEffects = (url) => {
14972
15131
  if (url.startsWith("ignore:")) {
14973
- // console.log(`may have side effect: ${url}`);
14974
- // double ignore we must keep the import
14975
- return null;
15132
+ url = url.slice("ignore:".length);
14976
15133
  }
14977
15134
  if (isSpecifierForNodeBuiltin(url)) {
14978
15135
  return false;
14979
15136
  }
14980
- const closestPackageJsonSideEffects =
14981
- readClosestPackageJsonSideEffects(url);
14982
- if (closestPackageJsonSideEffects === undefined) {
14983
- // console.log(`may have side effect: ${url}`);
14984
- return null;
15137
+ if (urlToExtension$2(url) === ".css") {
15138
+ return true;
14985
15139
  }
14986
- if (typeof closestPackageJsonSideEffects === "function") {
14987
- const haveSideEffect = closestPackageJsonSideEffects(url);
14988
- // if (haveSideEffect) {
14989
- // console.log(`have side effect: ${url}`);
14990
- // }
14991
- return haveSideEffect;
15140
+ const urlInfo = graph.getUrlInfo(url);
15141
+ if (!urlInfo) {
15142
+ return null; // we don't know
14992
15143
  }
14993
- return closestPackageJsonSideEffects;
14994
- };
14995
- const getModuleSideEffects = (url, importer) => {
14996
- if (!url.startsWith("ignore:")) {
14997
- return inferSideEffectsFromResolvedUrl(url);
15144
+ if (urlInfo.contentSideEffects.length === 0) {
15145
+ return null; // we don't know
14998
15146
  }
14999
- url = url.slice("ignore:".length);
15000
- if (url.startsWith("file:")) {
15001
- return inferSideEffectsFromResolvedUrl(url);
15002
- }
15003
- try {
15004
- const result = kitchen.resolve(url, importer);
15005
- if (result.packageDirectoryUrl) {
15006
- storePackageSideEffect(result.packageDirectoryUrl, result.packageJson);
15147
+ for (const contentSideEffect of urlInfo.contentSideEffects) {
15148
+ if (contentSideEffect.has) {
15149
+ return true;
15007
15150
  }
15008
- return inferSideEffectsFromResolvedUrl(url);
15009
- } catch {
15010
- return null;
15011
15151
  }
15152
+ return false;
15012
15153
  };
15013
15154
 
15014
15155
  const resolveImport = (specifier, importer) => {
@@ -15020,9 +15161,7 @@ const rollupPluginJsenv = ({
15020
15161
 
15021
15162
  const dynamicImportIdSet = new Set();
15022
15163
  const assignDynamicImportId = (urlImportedDynamically) => {
15023
- const urlInfo = jsModuleUrlInfos[0].context.kitchen.graph.getUrlInfo(
15024
- urlImportedDynamically,
15025
- );
15164
+ const urlInfo = kitchen.graph.getUrlInfo(urlImportedDynamically);
15026
15165
  let dynamicImportIdBase =
15027
15166
  urlInfo && urlInfo.filenameHint
15028
15167
  ? filenameWithoutExtension(urlInfo.filenameHint)
@@ -15266,10 +15405,7 @@ const rollupPluginJsenv = ({
15266
15405
  }
15267
15406
  if (chunkInfo.isDynamicEntry) {
15268
15407
  const originalFileUrl = getOriginalUrl(chunkInfo, true);
15269
- const urlInfo =
15270
- jsModuleUrlInfos[0].context.kitchen.graph.getUrlInfo(
15271
- originalFileUrl,
15272
- );
15408
+ const urlInfo = kitchen.graph.getUrlInfo(originalFileUrl);
15273
15409
  if (urlInfo && urlInfo.filenameHint) {
15274
15410
  return urlInfo.filenameHint;
15275
15411
  }
@@ -15288,33 +15424,50 @@ const rollupPluginJsenv = ({
15288
15424
  if (isFileSystemPath$1(importer)) {
15289
15425
  importer = PATH_AND_URL_CONVERTER.asFileUrl(importer);
15290
15426
  }
15291
- const urlObject = resolveImport(specifier, importer);
15292
- if (!urlObject.href.startsWith("file:")) {
15293
- return { id: specifier, external: true };
15427
+ const resolvedUrlObject = resolveImport(specifier, importer);
15428
+ const resolvedUrl = resolvedUrlObject.href;
15429
+ if (!resolvedUrl.startsWith("file:")) {
15430
+ return {
15431
+ id: specifier,
15432
+ external: true,
15433
+ moduleSideEffects: getModuleSideEffects(resolvedUrl),
15434
+ };
15294
15435
  }
15295
15436
  const searchParamsToAdd =
15296
- augmentDynamicImportUrlSearchParams(urlObject);
15437
+ augmentDynamicImportUrlSearchParams(resolvedUrlObject);
15297
15438
  if (searchParamsToAdd) {
15298
- injectQueryParams(urlObject, searchParamsToAdd);
15439
+ injectQueryParams(resolvedUrlObject, searchParamsToAdd);
15299
15440
  }
15300
- const id = urlObject.href;
15301
- return { id, external: true };
15441
+ const id = resolvedUrlObject.href;
15442
+ return {
15443
+ id,
15444
+ external: true,
15445
+ moduleSideEffects: getModuleSideEffects(id),
15446
+ };
15302
15447
  }
15303
15448
  if (isolateDynamicImports) {
15304
15449
  if (isFileSystemPath$1(importer)) {
15305
15450
  importer = PATH_AND_URL_CONVERTER.asFileUrl(importer);
15306
15451
  }
15307
- const urlObject = resolveImport(specifier, importer);
15308
- if (!urlObject.href.startsWith("file:")) {
15309
- return { id: specifier, external: true };
15452
+ const resolvedUrlObject = resolveImport(specifier, importer);
15453
+ const resolvedUrl = resolvedUrlObject.href;
15454
+ if (!resolvedUrl.startsWith("file:")) {
15455
+ return {
15456
+ id: specifier,
15457
+ external: true,
15458
+ moduleSideEffects: getModuleSideEffects(resolvedUrl),
15459
+ };
15310
15460
  }
15311
- const importId = assignDynamicImportId(urlObject.href);
15312
- injectQueryParams(urlObject, {
15461
+ const importId = assignDynamicImportId(resolvedUrlObject.href);
15462
+ injectQueryParams(resolvedUrlObject, {
15313
15463
  dynamic_import_id: importId,
15314
15464
  });
15315
- const url = urlObject.href;
15465
+ const url = resolvedUrlObject.href;
15316
15466
  const filePath = PATH_AND_URL_CONVERTER.asFilePath(url);
15317
- return { id: filePath };
15467
+ return {
15468
+ id: filePath,
15469
+ moduleSideEffects: getModuleSideEffects(url),
15470
+ };
15318
15471
  }
15319
15472
  return null;
15320
15473
  },
@@ -15328,21 +15481,21 @@ const rollupPluginJsenv = ({
15328
15481
  return {
15329
15482
  id: resolvedUrl,
15330
15483
  external: true,
15331
- moduleSideEffects: getModuleSideEffects(resolvedUrl, importer),
15484
+ moduleSideEffects: getModuleSideEffects(resolvedUrl),
15332
15485
  };
15333
15486
  }
15334
15487
  if (!importCanBeBundled(resolvedUrl)) {
15335
15488
  return {
15336
15489
  id: resolvedUrl,
15337
15490
  external: true,
15338
- moduleSideEffects: getModuleSideEffects(resolvedUrl, importer),
15491
+ moduleSideEffects: getModuleSideEffects(resolvedUrl),
15339
15492
  };
15340
15493
  }
15341
15494
  if (resolvedUrl.startsWith("ignore:")) {
15342
15495
  return {
15343
15496
  id: resolvedUrl,
15344
15497
  external: true,
15345
- moduleSideEffects: getModuleSideEffects(resolvedUrl, importer),
15498
+ moduleSideEffects: getModuleSideEffects(resolvedUrl),
15346
15499
  };
15347
15500
  }
15348
15501
  if (importer.includes("dynamic_import_id")) {
@@ -15357,7 +15510,7 @@ const rollupPluginJsenv = ({
15357
15510
  return {
15358
15511
  id: PATH_AND_URL_CONVERTER.asFilePath(isolatedResolvedUrl),
15359
15512
  external: false,
15360
- moduleSideEffects: getModuleSideEffects(resolvedUrl, importer),
15513
+ moduleSideEffects: getModuleSideEffects(resolvedUrl),
15361
15514
  };
15362
15515
  }
15363
15516
  }
@@ -15366,13 +15519,13 @@ const rollupPluginJsenv = ({
15366
15519
  return {
15367
15520
  id: resolvedUrl,
15368
15521
  external: true,
15369
- moduleSideEffects: getModuleSideEffects(resolvedUrl, importer),
15522
+ moduleSideEffects: getModuleSideEffects(resolvedUrl),
15370
15523
  };
15371
15524
  }
15372
15525
  return {
15373
15526
  id: PATH_AND_URL_CONVERTER.asFilePath(resolvedUrl),
15374
15527
  external: false,
15375
- moduleSideEffects: getModuleSideEffects(resolvedUrl, importer),
15528
+ moduleSideEffects: getModuleSideEffects(resolvedUrl),
15376
15529
  };
15377
15530
  },
15378
15531
  async load(rollupId) {
@@ -15645,7 +15798,7 @@ const jsenvPluginMinification = ({
15645
15798
  willMinifyJsModule: Boolean(js_module),
15646
15799
  willMinifyJson: Boolean(json),
15647
15800
  },
15648
- optimizeUrlContent: {
15801
+ optimizeBuildUrlContent: {
15649
15802
  html: htmlMinifier,
15650
15803
  svg: svgMinifier,
15651
15804
  css: cssMinifier,
@@ -17042,7 +17195,7 @@ const injectSideEffectFileIntoBabelAst = ({
17042
17195
  });
17043
17196
  return;
17044
17197
  }
17045
- const sidEffectFileContent = readFileSync(new URL(sideEffectFileUrl), "utf8");
17198
+ const sidEffectFileContent = readFileSync$2(new URL(sideEffectFileUrl), "utf8");
17046
17199
  const sideEffectFileContentAst = babel.parse(sidEffectFileContent);
17047
17200
  if (isJsModule) {
17048
17201
  injectAstAfterImport(programPath, sideEffectFileContentAst);
@@ -23677,4 +23830,4 @@ const assertAndNormalizeDirectoryUrl = (
23677
23830
  return value;
23678
23831
  };
23679
23832
 
23680
- export { ANSI$2 as ANSI, ANSI$1, Abort$1 as Abort, Abort as Abort$1, CONTENT_TYPE$1 as CONTENT_TYPE, CONTENT_TYPE as CONTENT_TYPE$1, DATA_URL$1 as DATA_URL, DATA_URL as DATA_URL$1, JS_QUOTES$1 as JS_QUOTES, JS_QUOTES as JS_QUOTES$1, RUNTIME_COMPAT$1 as RUNTIME_COMPAT, RUNTIME_COMPAT as RUNTIME_COMPAT$1, UNICODE$1 as UNICODE, URL_META$1 as URL_META, URL_META as URL_META$1, applyFileSystemMagicResolution$1 as applyFileSystemMagicResolution, applyFileSystemMagicResolution as applyFileSystemMagicResolution$1, applyNodeEsmResolution$1 as applyNodeEsmResolution, applyNodeEsmResolution as applyNodeEsmResolution$1, asSpecifierWithoutSearch$1 as asSpecifierWithoutSearch, asSpecifierWithoutSearch as asSpecifierWithoutSearch$1, asUrlWithoutSearch$1 as asUrlWithoutSearch, asUrlWithoutSearch as asUrlWithoutSearch$1, assertAndNormalizeDirectoryUrl$2 as assertAndNormalizeDirectoryUrl, assertAndNormalizeDirectoryUrl$1, assertAndNormalizeDirectoryUrl as assertAndNormalizeDirectoryUrl$2, browserDefaultRuntimeCompat, bufferToEtag$1 as bufferToEtag, bufferToEtag as bufferToEtag$1, clearDirectorySync, compareFileUrls$1 as compareFileUrls, compareFileUrls as compareFileUrls$1, comparePathnames, composeTwoImportMaps$1 as composeTwoImportMaps, composeTwoImportMaps as composeTwoImportMaps$1, createDetailedMessage$3 as createDetailedMessage, createDetailedMessage$1, createDynamicLog$1 as createDynamicLog, createLogger$2 as createLogger, createLogger$1, createLogger as createLogger$2, createTaskLog$2 as createTaskLog, createTaskLog$1, createTaskLog as createTaskLog$2, defaultLookupPackageScope$1 as defaultLookupPackageScope, defaultLookupPackageScope as defaultLookupPackageScope$1, defaultReadPackageJson$1 as defaultReadPackageJson, defaultReadPackageJson as defaultReadPackageJson$1, distributePercentages, ensureEmptyDirectory, ensurePathnameTrailingSlash$2 as ensurePathnameTrailingSlash, ensurePathnameTrailingSlash$1, ensureWindowsDriveLetter$1 as ensureWindowsDriveLetter, ensureWindowsDriveLetter as ensureWindowsDriveLetter$1, escapeRegexpSpecialChars, generateContentFrame$1 as generateContentFrame, generateContentFrame as generateContentFrame$1, getCallerPosition$1 as getCallerPosition, getCallerPosition as getCallerPosition$1, getExtensionsToTry$1 as getExtensionsToTry, getExtensionsToTry as getExtensionsToTry$1, humanizeDuration$1 as humanizeDuration, humanizeFileSize, humanizeMemory, inferRuntimeCompatFromClosestPackage, injectQueryParamIntoSpecifierWithoutEncoding, injectQueryParamsIntoSpecifier$1 as injectQueryParamsIntoSpecifier, injectQueryParamsIntoSpecifier as injectQueryParamsIntoSpecifier$1, isFileSystemPath$2 as isFileSystemPath, isFileSystemPath$1, jsenvPluginBundling, jsenvPluginJsModuleFallback, jsenvPluginMinification, jsenvPluginTranspilation$1 as jsenvPluginTranspilation, jsenvPluginTranspilation as jsenvPluginTranspilation$1, lookupPackageDirectory$1 as lookupPackageDirectory, lookupPackageDirectory as lookupPackageDirectory$1, memoizeByFirstArgument, moveUrl$1 as moveUrl, moveUrl as moveUrl$1, nodeDefaultRuntimeCompat, normalizeImportMap$1 as normalizeImportMap, normalizeImportMap as normalizeImportMap$1, normalizeUrl$1 as normalizeUrl, normalizeUrl as normalizeUrl$1, raceProcessTeardownEvents$1 as raceProcessTeardownEvents, raceProcessTeardownEvents as raceProcessTeardownEvents$1, readCustomConditionsFromProcessArgs$1 as readCustomConditionsFromProcessArgs, readCustomConditionsFromProcessArgs as readCustomConditionsFromProcessArgs$1, readEntryStatSync$1 as readEntryStatSync, readEntryStatSync as readEntryStatSync$1, readPackageAtOrNull, registerDirectoryLifecycle$1 as registerDirectoryLifecycle, registerDirectoryLifecycle as registerDirectoryLifecycle$1, renderBigSection, renderDetails, renderTable, renderUrlOrRelativeUrlFilename, resolveImport$1 as resolveImport, resolveImport as resolveImport$1, setUrlBasename$1 as setUrlBasename, setUrlBasename as setUrlBasename$1, setUrlExtension$1 as setUrlExtension, setUrlExtension as setUrlExtension$1, setUrlFilename$1 as setUrlFilename, setUrlFilename as setUrlFilename$1, startMonitoringCpuUsage, startMonitoringMemoryUsage, stringifyUrlSite$1 as stringifyUrlSite, stringifyUrlSite as stringifyUrlSite$1, urlIsInsideOf$1 as urlIsInsideOf, urlIsInsideOf as urlIsInsideOf$1, urlToBasename$1 as urlToBasename, urlToBasename as urlToBasename$1, urlToExtension$4 as urlToExtension, urlToExtension$2 as urlToExtension$1, urlToExtension as urlToExtension$2, urlToFileSystemPath$1 as urlToFileSystemPath, urlToFileSystemPath as urlToFileSystemPath$1, urlToFilename$3 as urlToFilename, urlToFilename$1, urlToPathname$4 as urlToPathname, urlToPathname$2 as urlToPathname$1, urlToPathname as urlToPathname$2, urlToRelativeUrl$1 as urlToRelativeUrl, urlToRelativeUrl as urlToRelativeUrl$1, validateResponseIntegrity$1 as validateResponseIntegrity, validateResponseIntegrity as validateResponseIntegrity$1, writeFileSync$1 as writeFileSync, writeFileSync as writeFileSync$1 };
23833
+ export { ANSI$2 as ANSI, ANSI$1, Abort$1 as Abort, Abort as Abort$1, CONTENT_TYPE$1 as CONTENT_TYPE, CONTENT_TYPE as CONTENT_TYPE$1, DATA_URL$1 as DATA_URL, DATA_URL as DATA_URL$1, JS_QUOTES$1 as JS_QUOTES, JS_QUOTES as JS_QUOTES$1, RUNTIME_COMPAT$1 as RUNTIME_COMPAT, RUNTIME_COMPAT as RUNTIME_COMPAT$1, UNICODE$1 as UNICODE, URL_META$1 as URL_META, URL_META as URL_META$1, applyFileSystemMagicResolution$1 as applyFileSystemMagicResolution, applyFileSystemMagicResolution as applyFileSystemMagicResolution$1, applyNodeEsmResolution$1 as applyNodeEsmResolution, applyNodeEsmResolution as applyNodeEsmResolution$1, asSpecifierWithoutSearch$1 as asSpecifierWithoutSearch, asSpecifierWithoutSearch as asSpecifierWithoutSearch$1, asUrlWithoutSearch$1 as asUrlWithoutSearch, asUrlWithoutSearch as asUrlWithoutSearch$1, assertAndNormalizeDirectoryUrl$2 as assertAndNormalizeDirectoryUrl, assertAndNormalizeDirectoryUrl$1, assertAndNormalizeDirectoryUrl as assertAndNormalizeDirectoryUrl$2, browserDefaultRuntimeCompat, bufferToEtag$1 as bufferToEtag, bufferToEtag as bufferToEtag$1, clearDirectorySync, compareFileUrls$1 as compareFileUrls, compareFileUrls as compareFileUrls$1, comparePathnames, composeTwoImportMaps$1 as composeTwoImportMaps, composeTwoImportMaps as composeTwoImportMaps$1, createDetailedMessage$3 as createDetailedMessage, createDetailedMessage$1, createDynamicLog$1 as createDynamicLog, createLogger$2 as createLogger, createLogger$1, createLogger as createLogger$2, createLookupPackageDirectory, createTaskLog$2 as createTaskLog, createTaskLog$1, createTaskLog as createTaskLog$2, defaultLookupPackageScope$1 as defaultLookupPackageScope, defaultLookupPackageScope as defaultLookupPackageScope$1, defaultReadPackageJson$1 as defaultReadPackageJson, defaultReadPackageJson as defaultReadPackageJson$1, distributePercentages, ensureEmptyDirectory, ensurePathnameTrailingSlash$2 as ensurePathnameTrailingSlash, ensurePathnameTrailingSlash$1, ensureWindowsDriveLetter$1 as ensureWindowsDriveLetter, ensureWindowsDriveLetter as ensureWindowsDriveLetter$1, errorToHTML$1 as errorToHTML, errorToHTML as errorToHTML$1, escapeRegexpSpecialChars, generateContentFrame$1 as generateContentFrame, generateContentFrame as generateContentFrame$1, getCallerPosition$1 as getCallerPosition, getCallerPosition as getCallerPosition$1, getExtensionsToTry$1 as getExtensionsToTry, getExtensionsToTry as getExtensionsToTry$1, humanizeDuration$1 as humanizeDuration, humanizeFileSize, humanizeMemory, inferRuntimeCompatFromClosestPackage, injectQueryParamIntoSpecifierWithoutEncoding, injectQueryParamsIntoSpecifier$1 as injectQueryParamsIntoSpecifier, injectQueryParamsIntoSpecifier as injectQueryParamsIntoSpecifier$1, isFileSystemPath$2 as isFileSystemPath, isFileSystemPath$1, isSpecifierForNodeBuiltin$1 as isSpecifierForNodeBuiltin, isSpecifierForNodeBuiltin as isSpecifierForNodeBuiltin$1, jsenvPluginBundling, jsenvPluginJsModuleFallback, jsenvPluginMinification, jsenvPluginTranspilation$1 as jsenvPluginTranspilation, jsenvPluginTranspilation as jsenvPluginTranspilation$1, lookupPackageDirectory$1 as lookupPackageDirectory, lookupPackageDirectory as lookupPackageDirectory$1, memoizeByFirstArgument, moveUrl$1 as moveUrl, moveUrl as moveUrl$1, nodeDefaultRuntimeCompat, normalizeImportMap$1 as normalizeImportMap, normalizeImportMap as normalizeImportMap$1, normalizeUrl$1 as normalizeUrl, normalizeUrl as normalizeUrl$1, raceProcessTeardownEvents$1 as raceProcessTeardownEvents, raceProcessTeardownEvents as raceProcessTeardownEvents$1, readCustomConditionsFromProcessArgs$1 as readCustomConditionsFromProcessArgs, readCustomConditionsFromProcessArgs as readCustomConditionsFromProcessArgs$1, readEntryStatSync$1 as readEntryStatSync, readEntryStatSync as readEntryStatSync$1, readPackageAtOrNull$1 as readPackageAtOrNull, readPackageAtOrNull as readPackageAtOrNull$1, registerDirectoryLifecycle$1 as registerDirectoryLifecycle, registerDirectoryLifecycle as registerDirectoryLifecycle$1, renderBigSection, renderDetails, renderTable, renderUrlOrRelativeUrlFilename, resolveImport$1 as resolveImport, resolveImport as resolveImport$1, setUrlBasename$1 as setUrlBasename, setUrlBasename as setUrlBasename$1, setUrlExtension$1 as setUrlExtension, setUrlExtension as setUrlExtension$1, setUrlFilename$1 as setUrlFilename, setUrlFilename as setUrlFilename$1, startMonitoringCpuUsage, startMonitoringMemoryUsage, stringifyUrlSite$1 as stringifyUrlSite, stringifyUrlSite as stringifyUrlSite$1, updateJsonFileSync$1 as updateJsonFileSync, updateJsonFileSync as updateJsonFileSync$1, urlIsInsideOf$1 as urlIsInsideOf, urlIsInsideOf as urlIsInsideOf$1, urlToBasename$1 as urlToBasename, urlToBasename as urlToBasename$1, urlToExtension$4 as urlToExtension, urlToExtension$2 as urlToExtension$1, urlToExtension as urlToExtension$2, urlToFileSystemPath$1 as urlToFileSystemPath, urlToFileSystemPath as urlToFileSystemPath$1, urlToFilename$3 as urlToFilename, urlToFilename$1, urlToPathname$4 as urlToPathname, urlToPathname$2 as urlToPathname$1, urlToPathname as urlToPathname$2, urlToRelativeUrl$1 as urlToRelativeUrl, urlToRelativeUrl as urlToRelativeUrl$1, validateResponseIntegrity$1 as validateResponseIntegrity, validateResponseIntegrity as validateResponseIntegrity$1, writeFileSync$1 as writeFileSync, writeFileSync as writeFileSync$1 };