isomorphic-git 1.44.15 → 1.44.17

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.
@@ -712,57 +712,75 @@ function dirname(path) {
712
712
  }
713
713
 
714
714
  /*!
715
- * This code for `path.join` is directly copied from @zenfs/core/path for bundle size improvements.
716
- * SPDX-License-Identifier: LGPL-3.0-or-later
717
- * Copyright (c) James Prevett and other ZenFS contributors.
715
+ * The POSIX core below - `assertPath`, `normalizeStringPosix` and the body of
716
+ * `normalize` - comes from path-browserify, which extracted it from Node.js.
717
+ * Reformatted to this project's style (`const`/`let`, no semicolons); the
718
+ * algorithm is unchanged.
718
719
  *
719
- * Windows support added:
720
+ * SPDX-License-Identifier: MIT
721
+ * Copyright (c) 2013 James Halliday
722
+ * Copyright Joyent, Inc. and other Node contributors.
723
+ *
724
+ * @see https://github.com/browserify/path-browserify
725
+ *
726
+ * The Windows handling is this project's own, added in #2302. path-browserify
727
+ * is the POSIX part of `path` only, so `normalize` and `join` are wrapped with:
720
728
  * - Backslashes are normalised to forward slashes before processing.
721
729
  * - Drive-letter prefixes (e.g. "C:") are detected and preserved through
722
730
  * normalisation, so absolute Windows paths are handled correctly.
723
- * - An absolute argument passed to join() resets the accumulated path,
731
+ * - A drive-letter argument passed to join() resets the accumulated path,
724
732
  * matching Node behaviour and handling worktree gitdir paths properly.
725
733
  *
726
734
  * Limitation: UNC paths (e.g. \\server\share) are not supported. The leading
727
735
  * backslashes are normalised to forward slashes and then collapsed by
728
- * normalizeString, losing the UNC root. Git on Windows works with
736
+ * normalizeStringPosix, losing the UNC root. Git on Windows works with
729
737
  * drive-letter paths, so this is not expected to be a practical issue.
730
738
  */
731
739
 
732
- function normalizeString(path, aar) {
740
+ function assertPath(path) {
741
+ if (typeof path !== 'string') {
742
+ throw new TypeError(
743
+ 'Path must be a string. Received ' + JSON.stringify(path)
744
+ )
745
+ }
746
+ }
747
+
748
+ // Resolves . and .. elements in a path with directory names
749
+ function normalizeStringPosix(path, allowAboveRoot) {
733
750
  let res = '';
734
751
  let lastSegmentLength = 0;
735
752
  let lastSlash = -1;
736
753
  let dots = 0;
737
- let char = '\x00';
754
+ let code;
738
755
  for (let i = 0; i <= path.length; ++i) {
739
- if (i < path.length) char = path[i];
740
- else if (char === '/') break
741
- else char = '/';
742
-
743
- if (char === '/') {
756
+ if (i < path.length) code = path.charCodeAt(i);
757
+ else if (code === 47 /* / */) break
758
+ else code = 47; /* / */
759
+ if (code === 47 /* / */) {
744
760
  if (lastSlash === i - 1 || dots === 1) {
745
761
  // NOOP
746
- } else if (dots === 2) {
762
+ } else if (lastSlash !== i - 1 && dots === 2) {
747
763
  if (
748
764
  res.length < 2 ||
749
765
  lastSegmentLength !== 2 ||
750
- res.at(-1) !== '.' ||
751
- res.at(-2) !== '.'
766
+ res.charCodeAt(res.length - 1) !== 46 /* . */ ||
767
+ res.charCodeAt(res.length - 2) !== 46 /* . */
752
768
  ) {
753
769
  if (res.length > 2) {
754
770
  const lastSlashIndex = res.lastIndexOf('/');
755
- if (lastSlashIndex === -1) {
756
- res = '';
757
- lastSegmentLength = 0;
758
- } else {
759
- res = res.slice(0, lastSlashIndex);
760
- lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
771
+ if (lastSlashIndex !== res.length - 1) {
772
+ if (lastSlashIndex === -1) {
773
+ res = '';
774
+ lastSegmentLength = 0;
775
+ } else {
776
+ res = res.slice(0, lastSlashIndex);
777
+ lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
778
+ }
779
+ lastSlash = i;
780
+ dots = 0;
781
+ continue
761
782
  }
762
- lastSlash = i;
763
- dots = 0;
764
- continue
765
- } else if (res.length !== 0) {
783
+ } else if (res.length === 2 || res.length === 1) {
766
784
  res = '';
767
785
  lastSegmentLength = 0;
768
786
  lastSlash = i;
@@ -770,8 +788,9 @@ function normalizeString(path, aar) {
770
788
  continue
771
789
  }
772
790
  }
773
- if (aar) {
774
- res += res.length > 0 ? '/..' : '..';
791
+ if (allowAboveRoot) {
792
+ if (res.length > 0) res += '/..';
793
+ else res = '..';
775
794
  lastSegmentLength = 2;
776
795
  }
777
796
  } else {
@@ -781,7 +800,7 @@ function normalizeString(path, aar) {
781
800
  }
782
801
  lastSlash = i;
783
802
  dots = 0;
784
- } else if (char === '.' && dots !== -1) {
803
+ } else if (code === 46 /* . */ && dots !== -1) {
785
804
  ++dots;
786
805
  } else {
787
806
  dots = -1;
@@ -799,7 +818,9 @@ function getWindowsDrivePrefix(path) {
799
818
  }
800
819
 
801
820
  function normalize(path) {
802
- if (!path.length) return '.'
821
+ assertPath(path);
822
+
823
+ if (path.length === 0) return '.'
803
824
 
804
825
  // Normalise backslashes to forward slashes before any other processing.
805
826
  path = path.replace(/\\/g, '/');
@@ -807,26 +828,19 @@ function normalize(path) {
807
828
  const drivePrefix = getWindowsDrivePrefix(path);
808
829
  // isAbsolute: Unix root ('/foo') OR Windows drive+slash ('C:/foo').
809
830
  const isAbsolute =
810
- path[0] === '/' || (drivePrefix !== null && path[2] === '/');
811
- const trailingSeparator = path.at(-1) === '/';
812
-
813
- // Strip the drive prefix before feeding into normalizeString so that the
814
- // core algorithm only ever sees a plain POSIX-style string.
815
- const pathBody = drivePrefix ? path.slice(2) : path;
816
-
817
- let normalized = normalizeString(pathBody, !isAbsolute);
831
+ path.charCodeAt(0) === 47 /* / */ ||
832
+ (drivePrefix !== null && path.charCodeAt(2) === 47); /* / */
833
+ const trailingSeparator = path.charCodeAt(path.length - 1) === 47; /* / */
834
+
835
+ // Strip the drive prefix before normalizing so that the core algorithm only
836
+ // ever sees a plain POSIX-style string.
837
+ let normalized = normalizeStringPosix(
838
+ drivePrefix ? path.slice(2) : path,
839
+ !isAbsolute
840
+ );
818
841
 
819
- if (!normalized.length) {
820
- const root = drivePrefix
821
- ? isAbsolute
822
- ? drivePrefix + '/'
823
- : drivePrefix
824
- : isAbsolute
825
- ? '/'
826
- : '.';
827
- return trailingSeparator && !isAbsolute ? root + '/' : root
828
- }
829
- if (trailingSeparator) normalized += '/';
842
+ if (normalized.length === 0 && !isAbsolute) normalized = '.';
843
+ if (normalized.length > 0 && trailingSeparator) normalized += '/';
830
844
 
831
845
  if (drivePrefix) {
832
846
  return isAbsolute
@@ -840,19 +854,21 @@ function join(...args) {
840
854
  if (args.length === 0) return '.'
841
855
  let joined;
842
856
  for (let i = 0; i < args.length; ++i) {
857
+ assertPath(args[i]);
843
858
  // Normalise separators before processing.
844
859
  const arg = args[i].replace(/\\/g, '/');
845
860
  if (arg.length === 0) continue
846
861
 
847
862
  // A Windows drive-letter path (e.g. "C:/worktrees/foo") cannot be
848
863
  // meaningfully appended to any base, so it resets the accumulator.
849
- // Unix absolute paths (leading '/') are NOT reset here — that would be
864
+ // Unix absolute paths (leading '/') are NOT reset here - that would be
850
865
  // path.resolve() semantics; path.join('foo', '/bar') must yield 'foo/bar'.
851
866
  if (/^[a-zA-Z]:\//.test(arg)) {
852
867
  joined = arg;
868
+ } else if (joined === undefined) {
869
+ joined = arg;
853
870
  } else {
854
- if (joined === undefined) joined = arg;
855
- else joined += '/' + arg;
871
+ joined += '/' + arg;
856
872
  }
857
873
  }
858
874
  if (joined === undefined) return '.'
package/managers/index.js CHANGED
@@ -706,57 +706,75 @@ function dirname(path) {
706
706
  }
707
707
 
708
708
  /*!
709
- * This code for `path.join` is directly copied from @zenfs/core/path for bundle size improvements.
710
- * SPDX-License-Identifier: LGPL-3.0-or-later
711
- * Copyright (c) James Prevett and other ZenFS contributors.
709
+ * The POSIX core below - `assertPath`, `normalizeStringPosix` and the body of
710
+ * `normalize` - comes from path-browserify, which extracted it from Node.js.
711
+ * Reformatted to this project's style (`const`/`let`, no semicolons); the
712
+ * algorithm is unchanged.
712
713
  *
713
- * Windows support added:
714
+ * SPDX-License-Identifier: MIT
715
+ * Copyright (c) 2013 James Halliday
716
+ * Copyright Joyent, Inc. and other Node contributors.
717
+ *
718
+ * @see https://github.com/browserify/path-browserify
719
+ *
720
+ * The Windows handling is this project's own, added in #2302. path-browserify
721
+ * is the POSIX part of `path` only, so `normalize` and `join` are wrapped with:
714
722
  * - Backslashes are normalised to forward slashes before processing.
715
723
  * - Drive-letter prefixes (e.g. "C:") are detected and preserved through
716
724
  * normalisation, so absolute Windows paths are handled correctly.
717
- * - An absolute argument passed to join() resets the accumulated path,
725
+ * - A drive-letter argument passed to join() resets the accumulated path,
718
726
  * matching Node behaviour and handling worktree gitdir paths properly.
719
727
  *
720
728
  * Limitation: UNC paths (e.g. \\server\share) are not supported. The leading
721
729
  * backslashes are normalised to forward slashes and then collapsed by
722
- * normalizeString, losing the UNC root. Git on Windows works with
730
+ * normalizeStringPosix, losing the UNC root. Git on Windows works with
723
731
  * drive-letter paths, so this is not expected to be a practical issue.
724
732
  */
725
733
 
726
- function normalizeString(path, aar) {
734
+ function assertPath(path) {
735
+ if (typeof path !== 'string') {
736
+ throw new TypeError(
737
+ 'Path must be a string. Received ' + JSON.stringify(path)
738
+ )
739
+ }
740
+ }
741
+
742
+ // Resolves . and .. elements in a path with directory names
743
+ function normalizeStringPosix(path, allowAboveRoot) {
727
744
  let res = '';
728
745
  let lastSegmentLength = 0;
729
746
  let lastSlash = -1;
730
747
  let dots = 0;
731
- let char = '\x00';
748
+ let code;
732
749
  for (let i = 0; i <= path.length; ++i) {
733
- if (i < path.length) char = path[i];
734
- else if (char === '/') break
735
- else char = '/';
736
-
737
- if (char === '/') {
750
+ if (i < path.length) code = path.charCodeAt(i);
751
+ else if (code === 47 /* / */) break
752
+ else code = 47; /* / */
753
+ if (code === 47 /* / */) {
738
754
  if (lastSlash === i - 1 || dots === 1) {
739
755
  // NOOP
740
- } else if (dots === 2) {
756
+ } else if (lastSlash !== i - 1 && dots === 2) {
741
757
  if (
742
758
  res.length < 2 ||
743
759
  lastSegmentLength !== 2 ||
744
- res.at(-1) !== '.' ||
745
- res.at(-2) !== '.'
760
+ res.charCodeAt(res.length - 1) !== 46 /* . */ ||
761
+ res.charCodeAt(res.length - 2) !== 46 /* . */
746
762
  ) {
747
763
  if (res.length > 2) {
748
764
  const lastSlashIndex = res.lastIndexOf('/');
749
- if (lastSlashIndex === -1) {
750
- res = '';
751
- lastSegmentLength = 0;
752
- } else {
753
- res = res.slice(0, lastSlashIndex);
754
- lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
765
+ if (lastSlashIndex !== res.length - 1) {
766
+ if (lastSlashIndex === -1) {
767
+ res = '';
768
+ lastSegmentLength = 0;
769
+ } else {
770
+ res = res.slice(0, lastSlashIndex);
771
+ lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
772
+ }
773
+ lastSlash = i;
774
+ dots = 0;
775
+ continue
755
776
  }
756
- lastSlash = i;
757
- dots = 0;
758
- continue
759
- } else if (res.length !== 0) {
777
+ } else if (res.length === 2 || res.length === 1) {
760
778
  res = '';
761
779
  lastSegmentLength = 0;
762
780
  lastSlash = i;
@@ -764,8 +782,9 @@ function normalizeString(path, aar) {
764
782
  continue
765
783
  }
766
784
  }
767
- if (aar) {
768
- res += res.length > 0 ? '/..' : '..';
785
+ if (allowAboveRoot) {
786
+ if (res.length > 0) res += '/..';
787
+ else res = '..';
769
788
  lastSegmentLength = 2;
770
789
  }
771
790
  } else {
@@ -775,7 +794,7 @@ function normalizeString(path, aar) {
775
794
  }
776
795
  lastSlash = i;
777
796
  dots = 0;
778
- } else if (char === '.' && dots !== -1) {
797
+ } else if (code === 46 /* . */ && dots !== -1) {
779
798
  ++dots;
780
799
  } else {
781
800
  dots = -1;
@@ -793,7 +812,9 @@ function getWindowsDrivePrefix(path) {
793
812
  }
794
813
 
795
814
  function normalize(path) {
796
- if (!path.length) return '.'
815
+ assertPath(path);
816
+
817
+ if (path.length === 0) return '.'
797
818
 
798
819
  // Normalise backslashes to forward slashes before any other processing.
799
820
  path = path.replace(/\\/g, '/');
@@ -801,26 +822,19 @@ function normalize(path) {
801
822
  const drivePrefix = getWindowsDrivePrefix(path);
802
823
  // isAbsolute: Unix root ('/foo') OR Windows drive+slash ('C:/foo').
803
824
  const isAbsolute =
804
- path[0] === '/' || (drivePrefix !== null && path[2] === '/');
805
- const trailingSeparator = path.at(-1) === '/';
806
-
807
- // Strip the drive prefix before feeding into normalizeString so that the
808
- // core algorithm only ever sees a plain POSIX-style string.
809
- const pathBody = drivePrefix ? path.slice(2) : path;
810
-
811
- let normalized = normalizeString(pathBody, !isAbsolute);
825
+ path.charCodeAt(0) === 47 /* / */ ||
826
+ (drivePrefix !== null && path.charCodeAt(2) === 47); /* / */
827
+ const trailingSeparator = path.charCodeAt(path.length - 1) === 47; /* / */
828
+
829
+ // Strip the drive prefix before normalizing so that the core algorithm only
830
+ // ever sees a plain POSIX-style string.
831
+ let normalized = normalizeStringPosix(
832
+ drivePrefix ? path.slice(2) : path,
833
+ !isAbsolute
834
+ );
812
835
 
813
- if (!normalized.length) {
814
- const root = drivePrefix
815
- ? isAbsolute
816
- ? drivePrefix + '/'
817
- : drivePrefix
818
- : isAbsolute
819
- ? '/'
820
- : '.';
821
- return trailingSeparator && !isAbsolute ? root + '/' : root
822
- }
823
- if (trailingSeparator) normalized += '/';
836
+ if (normalized.length === 0 && !isAbsolute) normalized = '.';
837
+ if (normalized.length > 0 && trailingSeparator) normalized += '/';
824
838
 
825
839
  if (drivePrefix) {
826
840
  return isAbsolute
@@ -834,19 +848,21 @@ function join(...args) {
834
848
  if (args.length === 0) return '.'
835
849
  let joined;
836
850
  for (let i = 0; i < args.length; ++i) {
851
+ assertPath(args[i]);
837
852
  // Normalise separators before processing.
838
853
  const arg = args[i].replace(/\\/g, '/');
839
854
  if (arg.length === 0) continue
840
855
 
841
856
  // A Windows drive-letter path (e.g. "C:/worktrees/foo") cannot be
842
857
  // meaningfully appended to any base, so it resets the accumulator.
843
- // Unix absolute paths (leading '/') are NOT reset here — that would be
858
+ // Unix absolute paths (leading '/') are NOT reset here - that would be
844
859
  // path.resolve() semantics; path.join('foo', '/bar') must yield 'foo/bar'.
845
860
  if (/^[a-zA-Z]:\//.test(arg)) {
846
861
  joined = arg;
862
+ } else if (joined === undefined) {
863
+ joined = arg;
847
864
  } else {
848
- if (joined === undefined) joined = arg;
849
- else joined += '/' + arg;
865
+ joined += '/' + arg;
850
866
  }
851
867
  }
852
868
  if (joined === undefined) return '.'