@jsenv/core 39.5.24 → 39.5.25

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.
@@ -3,7 +3,7 @@ import os, { networkInterfaces } from "node:os";
3
3
  import tty from "node:tty";
4
4
  import stringWidth from "string-width";
5
5
  import { pathToFileURL, fileURLToPath } from "node:url";
6
- import { readdir, chmod, stat, lstat, promises, readFileSync, writeFileSync as writeFileSync$1, mkdirSync, unlink, openSync, closeSync, rmdir, watch, readdirSync, statSync, createReadStream, lstatSync, readFile, existsSync, realpathSync } from "node:fs";
6
+ import { readdir, chmod, stat, lstat, chmodSync, statSync, lstatSync, promises, readFileSync, writeFileSync as writeFileSync$1, mkdirSync, unlink, openSync, closeSync, rmdir, watch, readdirSync, createReadStream, readFile, existsSync, realpathSync } from "node:fs";
7
7
  import { extname } from "node:path";
8
8
  import crypto, { createHash } from "node:crypto";
9
9
  import cluster from "node:cluster";
@@ -988,7 +988,7 @@ platform === 'Android'
988
988
  const ESC = '\u001B[';
989
989
 
990
990
  !isBrowser && process$1.env.TERM_PROGRAM === 'Apple_Terminal';
991
- const isWindows$3 = !isBrowser && process$1.platform === 'win32';
991
+ const isWindows$4 = !isBrowser && process$1.platform === 'win32';
992
992
 
993
993
  isBrowser ? () => {
994
994
  throw new Error('`process.cwd()` only works in Node.js, not the browser.');
@@ -1014,7 +1014,7 @@ const eraseLines = count => {
1014
1014
  const eraseLine = ESC + '2K';
1015
1015
  const eraseScreen = ESC + '2J';
1016
1016
 
1017
- const clearTerminal = isWindows$3
1017
+ const clearTerminal = isWindows$4
1018
1018
  ? `${eraseScreen}${ESC}0f`
1019
1019
  // 1. Erases the screen (Only done in case `2` is not supported)
1020
1020
  // 2. Erases the whole screen including scrollback buffer
@@ -1808,13 +1808,21 @@ const urlIsInsideOf = (url, otherUrl) => {
1808
1808
  };
1809
1809
 
1810
1810
  const urlToFileSystemPath = (url) => {
1811
- let urlString = String(url);
1812
- if (urlString[urlString.length - 1] === "/") {
1811
+ const urlObject = new URL(url);
1812
+ let urlString;
1813
+ if (urlObject.hash) {
1814
+ const origin =
1815
+ urlObject.protocol === "file:" ? "file://" : urlObject.origin;
1816
+ urlString = `${origin}${urlObject.pathname}${urlObject.search}%23${urlObject.hash.slice(1)}`;
1817
+ } else {
1818
+ urlString = urlObject.href;
1819
+ }
1820
+ const fileSystemPath = fileURLToPath(urlString);
1821
+ if (fileSystemPath[fileSystemPath.length - 1] === "/") {
1813
1822
  // remove trailing / so that nodejs path becomes predictable otherwise it logs
1814
1823
  // the trailing slash on linux but does not on windows
1815
- urlString = urlString.slice(0, -1);
1824
+ return fileSystemPath.slice(0, -1);
1816
1825
  }
1817
- const fileSystemPath = fileURLToPath(urlString);
1818
1826
  return fileSystemPath;
1819
1827
  };
1820
1828
 
@@ -1977,7 +1985,7 @@ const comparePathnames = (leftPathame, rightPathname) => {
1977
1985
  return 0;
1978
1986
  };
1979
1987
 
1980
- const isWindows$2 = process.platform === "win32";
1988
+ const isWindows$3 = process.platform === "win32";
1981
1989
  const baseUrlFallback = fileSystemPathToUrl$1(process.cwd());
1982
1990
 
1983
1991
  /**
@@ -2000,7 +2008,7 @@ const ensureWindowsDriveLetter = (url, baseUrl) => {
2000
2008
  throw new Error(`absolute url expect but got ${url}`);
2001
2009
  }
2002
2010
 
2003
- if (!isWindows$2) {
2011
+ if (!isWindows$3) {
2004
2012
  return url;
2005
2013
  }
2006
2014
 
@@ -3165,7 +3173,7 @@ const writeEntryPermissions = async (source, permissions) => {
3165
3173
  */
3166
3174
 
3167
3175
 
3168
- const isWindows$1 = process.platform === "win32";
3176
+ const isWindows$2 = process.platform === "win32";
3169
3177
 
3170
3178
  const readEntryStat = async (
3171
3179
  source,
@@ -3185,7 +3193,7 @@ const readEntryStat = async (
3185
3193
  return readStat(sourcePath, {
3186
3194
  followLink,
3187
3195
  ...handleNotFoundOption,
3188
- ...(isWindows$1
3196
+ ...(isWindows$2
3189
3197
  ? {
3190
3198
  // Windows can EPERM on stat
3191
3199
  handlePermissionDeniedError: async (error) => {
@@ -3250,13 +3258,104 @@ const readStat = (
3250
3258
  });
3251
3259
  };
3252
3260
 
3261
+ const writeEntryPermissionsSync = (source, permissions) => {
3262
+ const sourceUrl = assertAndNormalizeFileUrl(source);
3263
+
3264
+ let binaryFlags;
3265
+ {
3266
+ binaryFlags = permissions;
3267
+ }
3268
+
3269
+ chmodSync(new URL(sourceUrl), binaryFlags);
3270
+ };
3271
+
3253
3272
  /*
3254
3273
  * - stats object documentation on Node.js
3255
3274
  * https://nodejs.org/docs/latest-v13.x/api/fs.html#fs_class_fs_stats
3256
3275
  */
3257
3276
 
3258
3277
 
3259
- process.platform === "win32";
3278
+ const isWindows$1 = process.platform === "win32";
3279
+
3280
+ const readEntryStatSync = (
3281
+ source,
3282
+ { nullIfNotFound = false, followLink = true } = {},
3283
+ ) => {
3284
+ let sourceUrl = assertAndNormalizeFileUrl(source);
3285
+ if (sourceUrl.endsWith("/")) sourceUrl = sourceUrl.slice(0, -1);
3286
+
3287
+ const sourcePath = urlToFileSystemPath(sourceUrl);
3288
+
3289
+ const handleNotFoundOption = nullIfNotFound
3290
+ ? {
3291
+ handleNotFoundError: () => null,
3292
+ }
3293
+ : {};
3294
+
3295
+ return statSyncNaive(sourcePath, {
3296
+ followLink,
3297
+ ...handleNotFoundOption,
3298
+ ...(isWindows$1
3299
+ ? {
3300
+ // Windows can EPERM on stat
3301
+ handlePermissionDeniedError: (error) => {
3302
+ console.error(
3303
+ `trying to fix windows EPERM after stats on ${sourcePath}`,
3304
+ );
3305
+
3306
+ try {
3307
+ // unfortunately it means we mutate the permissions
3308
+ // without being able to restore them to the previous value
3309
+ // (because reading current permission would also throw)
3310
+ writeEntryPermissionsSync(sourceUrl, 0o666);
3311
+ const stats = statSyncNaive(sourcePath, {
3312
+ followLink,
3313
+ ...handleNotFoundOption,
3314
+ // could not fix the permission error, give up and throw original error
3315
+ handlePermissionDeniedError: () => {
3316
+ console.error(`still got EPERM after stats on ${sourcePath}`);
3317
+ throw error;
3318
+ },
3319
+ });
3320
+ return stats;
3321
+ } catch (e) {
3322
+ console.error(
3323
+ `error while trying to fix windows EPERM after stats on ${sourcePath}: ${e.stack}`,
3324
+ );
3325
+ throw error;
3326
+ }
3327
+ },
3328
+ }
3329
+ : {}),
3330
+ });
3331
+ };
3332
+
3333
+ const statSyncNaive = (
3334
+ sourcePath,
3335
+ {
3336
+ followLink,
3337
+ handleNotFoundError = null,
3338
+ handlePermissionDeniedError = null,
3339
+ } = {},
3340
+ ) => {
3341
+ const nodeMethod = followLink ? statSync : lstatSync;
3342
+
3343
+ try {
3344
+ const stats = nodeMethod(sourcePath);
3345
+ return stats;
3346
+ } catch (error) {
3347
+ if (handleNotFoundError && error.code === "ENOENT") {
3348
+ return handleNotFoundError(error);
3349
+ }
3350
+ if (
3351
+ handlePermissionDeniedError &&
3352
+ (error.code === "EPERM" || error.code === "EACCES")
3353
+ ) {
3354
+ return handlePermissionDeniedError(error);
3355
+ }
3356
+ throw error;
3357
+ }
3358
+ };
3260
3359
 
3261
3360
  const statsToType = (stats) => {
3262
3361
  if (stats.isFile()) return "file";
@@ -3958,7 +4057,7 @@ const registerDirectoryLifecycle = (
3958
4057
  try {
3959
4058
  const relativeUrl = urlToRelativeUrl(url, source);
3960
4059
  const previousInfo = infoMap.get(relativeUrl);
3961
- const stat = statSync(new URL(url));
4060
+ const stat = readEntryStatSync(new URL(url));
3962
4061
  const type = statsToType(stat);
3963
4062
  const patternValue = previousInfo
3964
4063
  ? previousInfo.patternValue
@@ -4035,7 +4134,7 @@ const registerDirectoryLifecycle = (
4035
4134
  const removedEntryRelativeUrl = relativeUrlCandidateArray.find(
4036
4135
  (relativeUrlCandidate) => {
4037
4136
  try {
4038
- statSync(new URL(relativeUrlCandidate, sourceUrl));
4137
+ readEntryStatSync(new URL(relativeUrlCandidate, sourceUrl));
4039
4138
  return false;
4040
4139
  } catch (e) {
4041
4140
  if (e.code === "ENOENT") {
@@ -4186,8 +4285,8 @@ const registerDirectoryLifecycle = (
4186
4285
  }
4187
4286
  };
4188
4287
  const handleEntryUpdated = (entryInfo) => {
4189
- infoMap.set(entryInfo.relativeUrl, entryInfo);
4190
4288
  if (updated && entryInfo.patternValue && shouldCallUpdated(entryInfo)) {
4289
+ infoMap.set(entryInfo.relativeUrl, entryInfo);
4191
4290
  updated({
4192
4291
  relativeUrl: entryInfo.relativeUrl,
4193
4292
  type: entryInfo.type,
@@ -8686,7 +8785,7 @@ const bundleCss = async (cssUrlInfos) => {
8686
8785
  },
8687
8786
  resolve(specifier, from) {
8688
8787
  const fileUrlObject = new URL(specifier, pathToFileURL(from));
8689
- const filePath = fileURLToPath(fileUrlObject);
8788
+ const filePath = urlToFileSystemPath(fileUrlObject);
8690
8789
  return filePath;
8691
8790
  },
8692
8791
  },
@@ -8755,7 +8854,7 @@ const minifyCss = async (cssUrlInfo) => {
8755
8854
 
8756
8855
  const targets = runtimeCompatToTargets$1(cssUrlInfo.context.runtimeCompat);
8757
8856
  const { code, map } = transform({
8758
- filename: fileURLToPath(cssUrlInfo.originalUrl),
8857
+ filename: urlToFileSystemPath(cssUrlInfo.originalUrl),
8759
8858
  code: Buffer.from(cssUrlInfo.content),
8760
8859
  targets,
8761
8860
  minify: true,
@@ -10601,7 +10700,7 @@ const applyCssTranspilation = async ({
10601
10700
  const { transform } = await import("lightningcss");
10602
10701
  const targets = runtimeCompatToTargets(runtimeCompat);
10603
10702
  const { code, map } = transform({
10604
- filename: fileURLToPath(inputUrl),
10703
+ filename: urlToFileSystemPath(inputUrl),
10605
10704
  code: Buffer.from(input),
10606
10705
  targets,
10607
10706
  minify: false,
@@ -18276,7 +18375,7 @@ const applyFileSystemMagicResolution = (
18276
18375
 
18277
18376
  if (fileStat === undefined) {
18278
18377
  try {
18279
- fileStat = statSync(new URL(fileUrl));
18378
+ fileStat = readEntryStatSync(new URL(fileUrl));
18280
18379
  } catch (e) {
18281
18380
  if (e.code === "ENOENT") {
18282
18381
  result.lastENOENTError = e;
@@ -18318,7 +18417,7 @@ const applyFileSystemMagicResolution = (
18318
18417
  const urlCandidate = `${parentUrl}${urlFilename}${extensionToTry}`;
18319
18418
  let stat;
18320
18419
  try {
18321
- stat = statSync(new URL(urlCandidate));
18420
+ stat = readEntryStatSync(new URL(urlCandidate));
18322
18421
  } catch (e) {
18323
18422
  if (e.code === "ENOENT") {
18324
18423
  stat = null;
@@ -18679,7 +18778,7 @@ const jsenvPluginFsRedirection = ({
18679
18778
  const urlObject = new URL(reference.url);
18680
18779
  let stat;
18681
18780
  try {
18682
- stat = statSync(urlObject);
18781
+ stat = readEntryStatSync(urlObject);
18683
18782
  } catch (e) {
18684
18783
  if (e.code === "ENOENT") {
18685
18784
  stat = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "39.5.24",
3
+ "version": "39.5.25",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -69,22 +69,22 @@
69
69
  "dependencies": {
70
70
  "@financial-times/polyfill-useragent-normaliser": "1.10.2",
71
71
  "@jsenv/abort": "4.3.0",
72
- "@jsenv/ast": "6.3.5",
73
- "@jsenv/filesystem": "4.10.11",
72
+ "@jsenv/ast": "6.3.6",
73
+ "@jsenv/filesystem": "4.10.12",
74
74
  "@jsenv/humanize": "1.2.8",
75
75
  "@jsenv/importmap": "1.2.1",
76
76
  "@jsenv/integrity": "0.0.2",
77
- "@jsenv/js-module-fallback": "1.3.49",
77
+ "@jsenv/js-module-fallback": "1.3.50",
78
78
  "@jsenv/node-esm-resolution": "1.0.6",
79
- "@jsenv/plugin-bundling": "2.7.16",
79
+ "@jsenv/plugin-bundling": "2.7.17",
80
80
  "@jsenv/plugin-minification": "1.5.10",
81
- "@jsenv/plugin-supervisor": "1.5.28",
82
- "@jsenv/plugin-transpilation": "1.4.84",
81
+ "@jsenv/plugin-supervisor": "1.5.29",
82
+ "@jsenv/plugin-transpilation": "1.4.85",
83
83
  "@jsenv/runtime-compat": "1.3.1",
84
84
  "@jsenv/server": "15.3.3",
85
- "@jsenv/sourcemap": "1.2.25",
85
+ "@jsenv/sourcemap": "1.2.26",
86
86
  "@jsenv/url-meta": "8.5.2",
87
- "@jsenv/urls": "2.5.2",
87
+ "@jsenv/urls": "2.5.3",
88
88
  "@jsenv/utils": "2.1.2",
89
89
  "string-width": "7.2.0"
90
90
  },
@@ -1,8 +1,9 @@
1
+ import { readEntryStatSync } from "@jsenv/filesystem";
1
2
  import {
2
3
  applyFileSystemMagicResolution,
3
4
  getExtensionsToTry,
4
5
  } from "@jsenv/node-esm-resolution";
5
- import { realpathSync, statSync } from "node:fs";
6
+ import { realpathSync } from "node:fs";
6
7
  import { pathToFileURL } from "node:url";
7
8
 
8
9
  export const jsenvPluginFsRedirection = ({
@@ -39,7 +40,7 @@ export const jsenvPluginFsRedirection = ({
39
40
  const urlObject = new URL(reference.url);
40
41
  let stat;
41
42
  try {
42
- stat = statSync(urlObject);
43
+ stat = readEntryStatSync(urlObject);
43
44
  } catch (e) {
44
45
  if (e.code === "ENOENT") {
45
46
  stat = null;