dsh-remote 0.8.94 → 1.1.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.
Files changed (196) hide show
  1. package/LICENSE +21 -21
  2. package/README.en.md +128 -370
  3. package/README.md +129 -355
  4. package/cordis.patch.yml +9 -9
  5. package/lib/audit.js +45 -45
  6. package/lib/auto-update.js +70 -0
  7. package/lib/binding.js +174 -172
  8. package/lib/boot.js +42 -42
  9. package/lib/client.js +6381 -4662
  10. package/lib/credential.js +277 -270
  11. package/lib/errors.js +141 -141
  12. package/lib/exec-job.js +245 -242
  13. package/lib/file-changes.js +57 -0
  14. package/lib/file-reference.js +457 -457
  15. package/lib/forwards.js +258 -258
  16. package/lib/host-api.js +822 -822
  17. package/lib/hostkey.js +108 -108
  18. package/lib/http-transport.js +201 -201
  19. package/lib/ignore.js +202 -202
  20. package/lib/index.js +4555 -4488
  21. package/lib/instructions-dynamic.js +415 -415
  22. package/lib/instructions.js +288 -288
  23. package/lib/open-folder.js +56 -56
  24. package/lib/openssh.js +950 -940
  25. package/lib/paths.js +292 -292
  26. package/lib/pool.js +1029 -1029
  27. package/lib/posix-shell.cjs +34 -34
  28. package/lib/registry.js +296 -296
  29. package/lib/remote-fs.js +179 -173
  30. package/lib/remote-git.js +127 -0
  31. package/lib/remote-sandbox.js +183 -183
  32. package/lib/remote-shell-child.cjs +460 -397
  33. package/lib/remote-shell.js +697 -697
  34. package/lib/remote-skills.js +312 -312
  35. package/lib/remote-write.js +51 -0
  36. package/lib/routes-audit.js +58 -58
  37. package/lib/routes-forwards.js +72 -72
  38. package/lib/routes-fs.js +299 -251
  39. package/lib/routes-machines.js +217 -186
  40. package/lib/routes-misc.js +187 -187
  41. package/lib/routes-term.js +169 -169
  42. package/lib/routes-update.js +147 -143
  43. package/lib/routes-web-attach.js +121 -112
  44. package/lib/routes-workspace.js +325 -312
  45. package/lib/search.js +235 -235
  46. package/lib/self-heal.js +130 -130
  47. package/lib/sftp-surface.js +119 -119
  48. package/lib/sshconfig.js +779 -779
  49. package/lib/sync-status.js +31 -0
  50. package/lib/sync.js +350 -350
  51. package/lib/tasks.js +95 -95
  52. package/lib/telemetry.js +247 -247
  53. package/lib/terminal.js +205 -205
  54. package/lib/tui/flow.js +130 -130
  55. package/lib/tui/format.js +380 -380
  56. package/lib/tui/i18n.js +350 -350
  57. package/lib/tui/index.js +531 -531
  58. package/lib/tui/provider.js +344 -344
  59. package/lib/tui/scene.js +986 -986
  60. package/lib/update.js +497 -490
  61. package/lib/vendor/jsdiff/LICENSE +29 -0
  62. package/lib/vendor/jsdiff/SOURCE.md +4 -0
  63. package/lib/vendor/jsdiff/diff/base.js +254 -0
  64. package/lib/vendor/jsdiff/diff/line.js +66 -0
  65. package/lib/vendor/jsdiff/patch/create.js +229 -0
  66. package/lib/vendor/jsdiff/util/params.js +15 -0
  67. package/lib/web-attach.js +1081 -860
  68. package/lib/workspace-cleanup.js +337 -337
  69. package/lib/workspace-search.js +219 -0
  70. package/node_modules/buildcheck/.eslintrc.js +5 -0
  71. package/node_modules/buildcheck/.github/workflows/ci.yml +88 -0
  72. package/node_modules/buildcheck/.github/workflows/lint.yml +27 -0
  73. package/node_modules/buildcheck/.npmignore +3 -0
  74. package/node_modules/buildcheck/LICENSE +19 -0
  75. package/node_modules/buildcheck/README.md +106 -0
  76. package/node_modules/buildcheck/deps/Find-VisualStudio.cs +250 -0
  77. package/node_modules/buildcheck/lib/findvs.js +361 -0
  78. package/node_modules/buildcheck/lib/index.js +738 -0
  79. package/node_modules/buildcheck/package.json +36 -0
  80. package/node_modules/buildcheck/test/test.js +8 -0
  81. package/node_modules/cpu-features/.eslintrc.js +5 -0
  82. package/node_modules/cpu-features/.github/workflows/ci.yml +74 -0
  83. package/node_modules/cpu-features/.github/workflows/lint.yml +27 -0
  84. package/node_modules/cpu-features/LICENSE +19 -0
  85. package/node_modules/cpu-features/README.md +59 -0
  86. package/node_modules/cpu-features/binding.gyp +16 -0
  87. package/node_modules/cpu-features/buildcheck.js +32 -0
  88. package/node_modules/cpu-features/deps/cpu_features/.clang-format +4 -0
  89. package/node_modules/cpu-features/deps/cpu_features/.dockerignore +31 -0
  90. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/Dockerfile +5 -0
  91. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/aarch64_linux_cmake.yml +30 -0
  92. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_freebsd_cmake.yml +22 -0
  93. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_linux_bazel.yml +26 -0
  94. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_linux_cmake.yml +31 -0
  95. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_macos_cmake.yml +43 -0
  96. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/amd64_windows_cmake.yml +25 -0
  97. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/arm_linux_cmake.yml +31 -0
  98. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/clang_format.yml +24 -0
  99. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/mips_linux_cmake.yml +30 -0
  100. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/power_linux_cmake.yml +29 -0
  101. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/riscv_linux_cmake.yml +28 -0
  102. package/node_modules/cpu-features/deps/cpu_features/.github/workflows/s390x_linux_cmake.yml +27 -0
  103. package/node_modules/cpu-features/deps/cpu_features/.grenrc.yml +21 -0
  104. package/node_modules/cpu-features/deps/cpu_features/BUILD.bazel +329 -0
  105. package/node_modules/cpu-features/deps/cpu_features/CMakeLists.txt +261 -0
  106. package/node_modules/cpu-features/deps/cpu_features/CONTRIBUTING.md +23 -0
  107. package/node_modules/cpu-features/deps/cpu_features/LICENSE +230 -0
  108. package/node_modules/cpu-features/deps/cpu_features/README.md +272 -0
  109. package/node_modules/cpu-features/deps/cpu_features/WORKSPACE +19 -0
  110. package/node_modules/cpu-features/deps/cpu_features/bazel/ci/README.md +5 -0
  111. package/node_modules/cpu-features/deps/cpu_features/bazel/platforms.bzl +11 -0
  112. package/node_modules/cpu-features/deps/cpu_features/cmake/CpuFeaturesConfig.cmake.in +3 -0
  113. package/node_modules/cpu-features/deps/cpu_features/cmake/CpuFeaturesNdkCompatConfig.cmake.in +3 -0
  114. package/node_modules/cpu-features/deps/cpu_features/cmake/README.md +30 -0
  115. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/Makefile +252 -0
  116. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/README.md +40 -0
  117. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/docker.dot +64 -0
  118. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/docker.svg +312 -0
  119. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/doc/generate_image.sh +7 -0
  120. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/docker/amd64/Dockerfile +48 -0
  121. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/docker/toolchain/Dockerfile +34 -0
  122. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/sample/CMakeLists.txt +22 -0
  123. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/sample/main.cpp +11 -0
  124. package/node_modules/cpu-features/deps/cpu_features/cmake/ci/vagrant/freebsd/Vagrantfile +107 -0
  125. package/node_modules/cpu-features/deps/cpu_features/cmake/googletest.CMakeLists.txt.in +15 -0
  126. package/node_modules/cpu-features/deps/cpu_features/cpu_features.gyp +105 -0
  127. package/node_modules/cpu-features/deps/cpu_features/include/cpu_features_cache_info.h +54 -0
  128. package/node_modules/cpu-features/deps/cpu_features/include/cpu_features_macros.h +384 -0
  129. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_aarch64.h +259 -0
  130. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_arm.h +121 -0
  131. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_mips.h +74 -0
  132. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_ppc.h +149 -0
  133. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_riscv.h +72 -0
  134. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_s390x.h +108 -0
  135. package/node_modules/cpu-features/deps/cpu_features/include/cpuinfo_x86.h +288 -0
  136. package/node_modules/cpu-features/deps/cpu_features/include/internal/bit_utils.h +40 -0
  137. package/node_modules/cpu-features/deps/cpu_features/include/internal/cpuid_x86.h +37 -0
  138. package/node_modules/cpu-features/deps/cpu_features/include/internal/filesystem.h +39 -0
  139. package/node_modules/cpu-features/deps/cpu_features/include/internal/hwcaps.h +240 -0
  140. package/node_modules/cpu-features/deps/cpu_features/include/internal/stack_line_reader.h +49 -0
  141. package/node_modules/cpu-features/deps/cpu_features/include/internal/string_view.h +110 -0
  142. package/node_modules/cpu-features/deps/cpu_features/include/internal/windows_utils.h +70 -0
  143. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/CMakeLists.txt +60 -0
  144. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/README.md +4 -0
  145. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/cpu-features.c +205 -0
  146. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/cpu-features.h +320 -0
  147. package/node_modules/cpu-features/deps/cpu_features/ndk_compat/ndk-compat-test.c +12 -0
  148. package/node_modules/cpu-features/deps/cpu_features/patches/0001-Add-Apple-Silicon-Support.patch +456 -0
  149. package/node_modules/cpu-features/deps/cpu_features/scripts/generate_badges.d +165 -0
  150. package/node_modules/cpu-features/deps/cpu_features/scripts/make_release.sh +75 -0
  151. package/node_modules/cpu-features/deps/cpu_features/scripts/run_integration.sh +490 -0
  152. package/node_modules/cpu-features/deps/cpu_features/scripts/test_integration.sh +79 -0
  153. package/node_modules/cpu-features/deps/cpu_features/src/copy.inl +19 -0
  154. package/node_modules/cpu-features/deps/cpu_features/src/define_introspection.inl +86 -0
  155. package/node_modules/cpu-features/deps/cpu_features/src/define_introspection_and_hwcaps.inl +26 -0
  156. package/node_modules/cpu-features/deps/cpu_features/src/equals.inl +22 -0
  157. package/node_modules/cpu-features/deps/cpu_features/src/filesystem.c +62 -0
  158. package/node_modules/cpu-features/deps/cpu_features/src/hwcaps.c +169 -0
  159. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64__base_implementation.inl +88 -0
  160. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_linux_or_android.c +79 -0
  161. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_macos_or_iphone.c +82 -0
  162. package/node_modules/cpu-features/deps/cpu_features/src/impl_aarch64_windows.c +138 -0
  163. package/node_modules/cpu-features/deps/cpu_features/src/impl_arm_linux_or_android.c +212 -0
  164. package/node_modules/cpu-features/deps/cpu_features/src/impl_mips_linux_or_android.c +93 -0
  165. package/node_modules/cpu-features/deps/cpu_features/src/impl_ppc_linux.c +163 -0
  166. package/node_modules/cpu-features/deps/cpu_features/src/impl_riscv_linux.c +111 -0
  167. package/node_modules/cpu-features/deps/cpu_features/src/impl_s390x_linux.c +120 -0
  168. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86__base_implementation.inl +2055 -0
  169. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_freebsd.c +68 -0
  170. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_linux_or_android.c +58 -0
  171. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_macos.c +57 -0
  172. package/node_modules/cpu-features/deps/cpu_features/src/impl_x86_windows.c +58 -0
  173. package/node_modules/cpu-features/deps/cpu_features/src/stack_line_reader.c +132 -0
  174. package/node_modules/cpu-features/deps/cpu_features/src/string_view.c +192 -0
  175. package/node_modules/cpu-features/deps/cpu_features/src/utils/list_cpu_features.c +461 -0
  176. package/node_modules/cpu-features/deps/cpu_features/test/CMakeLists.txt +114 -0
  177. package/node_modules/cpu-features/deps/cpu_features/test/bit_utils_test.cc +53 -0
  178. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_aarch64_test.cc +396 -0
  179. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_arm_test.cc +384 -0
  180. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_mips_test.cc +176 -0
  181. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_ppc_test.cc +131 -0
  182. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_riscv_test.cc +180 -0
  183. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_s390x_test.cc +82 -0
  184. package/node_modules/cpu-features/deps/cpu_features/test/cpuinfo_x86_test.cc +1729 -0
  185. package/node_modules/cpu-features/deps/cpu_features/test/filesystem_for_testing.cc +103 -0
  186. package/node_modules/cpu-features/deps/cpu_features/test/filesystem_for_testing.h +61 -0
  187. package/node_modules/cpu-features/deps/cpu_features/test/hwcaps_for_testing.cc +52 -0
  188. package/node_modules/cpu-features/deps/cpu_features/test/hwcaps_for_testing.h +31 -0
  189. package/node_modules/cpu-features/deps/cpu_features/test/stack_line_reader_test.cc +132 -0
  190. package/node_modules/cpu-features/deps/cpu_features/test/string_view_test.cc +202 -0
  191. package/node_modules/cpu-features/lib/index.js +5 -0
  192. package/node_modules/cpu-features/package.json +40 -0
  193. package/node_modules/cpu-features/src/binding.cc +151 -0
  194. package/node_modules/cpu-features/test/test.js +12 -0
  195. package/node_modules/nan/tools/1to2.js +0 -0
  196. package/package.json +107 -103
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2009-2015, Kevin Decker <kpdecker@gmail.com>
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,4 @@
1
+ Source: https://www.npmjs.com/package/diff/v/8.0.4
2
+ License: BSD-3-Clause
3
+ Only the ESM structuredPatch dependency closure is included.
4
+ Rebuild: npm ci --legacy-peer-deps && node scripts/vendor-diff.mjs
@@ -0,0 +1,254 @@
1
+ // Vendored unchanged from jsdiff 8.0.4; BSD-3-Clause. See lib/vendor/jsdiff/LICENSE.
2
+ export default class Diff {
3
+ diff(oldStr, newStr,
4
+ // Type below is not accurate/complete - see above for full possibilities - but it compiles
5
+ options = {}) {
6
+ let callback;
7
+ if (typeof options === 'function') {
8
+ callback = options;
9
+ options = {};
10
+ }
11
+ else if ('callback' in options) {
12
+ callback = options.callback;
13
+ }
14
+ // Allow subclasses to massage the input prior to running
15
+ const oldString = this.castInput(oldStr, options);
16
+ const newString = this.castInput(newStr, options);
17
+ const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
18
+ const newTokens = this.removeEmpty(this.tokenize(newString, options));
19
+ return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
20
+ }
21
+ diffWithOptionsObj(oldTokens, newTokens, options, callback) {
22
+ var _a;
23
+ const done = (value) => {
24
+ value = this.postProcess(value, options);
25
+ if (callback) {
26
+ setTimeout(function () { callback(value); }, 0);
27
+ return undefined;
28
+ }
29
+ else {
30
+ return value;
31
+ }
32
+ };
33
+ const newLen = newTokens.length, oldLen = oldTokens.length;
34
+ let editLength = 1;
35
+ let maxEditLength = newLen + oldLen;
36
+ if (options.maxEditLength != null) {
37
+ maxEditLength = Math.min(maxEditLength, options.maxEditLength);
38
+ }
39
+ const maxExecutionTime = (_a = options.timeout) !== null && _a !== void 0 ? _a : Infinity;
40
+ const abortAfterTimestamp = Date.now() + maxExecutionTime;
41
+ const bestPath = [{ oldPos: -1, lastComponent: undefined }];
42
+ // Seed editLength = 0, i.e. the content starts with the same values
43
+ let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
44
+ if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
45
+ // Identity per the equality and tokenizer
46
+ return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
47
+ }
48
+ // Once we hit the right edge of the edit graph on some diagonal k, we can
49
+ // definitely reach the end of the edit graph in no more than k edits, so
50
+ // there's no point in considering any moves to diagonal k+1 any more (from
51
+ // which we're guaranteed to need at least k+1 more edits).
52
+ // Similarly, once we've reached the bottom of the edit graph, there's no
53
+ // point considering moves to lower diagonals.
54
+ // We record this fact by setting minDiagonalToConsider and
55
+ // maxDiagonalToConsider to some finite value once we've hit the edge of
56
+ // the edit graph.
57
+ // This optimization is not faithful to the original algorithm presented in
58
+ // Myers's paper, which instead pointlessly extends D-paths off the end of
59
+ // the edit graph - see page 7 of Myers's paper which notes this point
60
+ // explicitly and illustrates it with a diagram. This has major performance
61
+ // implications for some common scenarios. For instance, to compute a diff
62
+ // where the new text simply appends d characters on the end of the
63
+ // original text of length n, the true Myers algorithm will take O(n+d^2)
64
+ // time while this optimization needs only O(n+d) time.
65
+ let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
66
+ // Main worker method. checks all permutations of a given edit length for acceptance.
67
+ const execEditLength = () => {
68
+ for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
69
+ let basePath;
70
+ const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
71
+ if (removePath) {
72
+ // No one else is going to attempt to use this value, clear it
73
+ // @ts-expect-error - perf optimisation. This type-violating value will never be read.
74
+ bestPath[diagonalPath - 1] = undefined;
75
+ }
76
+ let canAdd = false;
77
+ if (addPath) {
78
+ // what newPos will be after we do an insertion:
79
+ const addPathNewPos = addPath.oldPos - diagonalPath;
80
+ canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
81
+ }
82
+ const canRemove = removePath && removePath.oldPos + 1 < oldLen;
83
+ if (!canAdd && !canRemove) {
84
+ // If this path is a terminal then prune
85
+ // @ts-expect-error - perf optimisation. This type-violating value will never be read.
86
+ bestPath[diagonalPath] = undefined;
87
+ continue;
88
+ }
89
+ // Select the diagonal that we want to branch from. We select the prior
90
+ // path whose position in the old string is the farthest from the origin
91
+ // and does not pass the bounds of the diff graph
92
+ if (!canRemove || (canAdd && removePath.oldPos < addPath.oldPos)) {
93
+ basePath = this.addToPath(addPath, true, false, 0, options);
94
+ }
95
+ else {
96
+ basePath = this.addToPath(removePath, false, true, 1, options);
97
+ }
98
+ newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
99
+ if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
100
+ // If we have hit the end of both strings, then we are done
101
+ return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
102
+ }
103
+ else {
104
+ bestPath[diagonalPath] = basePath;
105
+ if (basePath.oldPos + 1 >= oldLen) {
106
+ maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
107
+ }
108
+ if (newPos + 1 >= newLen) {
109
+ minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
110
+ }
111
+ }
112
+ }
113
+ editLength++;
114
+ };
115
+ // Performs the length of edit iteration. Is a bit fugly as this has to support the
116
+ // sync and async mode which is never fun. Loops over execEditLength until a value
117
+ // is produced, or until the edit length exceeds options.maxEditLength (if given),
118
+ // in which case it will return undefined.
119
+ if (callback) {
120
+ (function exec() {
121
+ setTimeout(function () {
122
+ if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
123
+ return callback(undefined);
124
+ }
125
+ if (!execEditLength()) {
126
+ exec();
127
+ }
128
+ }, 0);
129
+ }());
130
+ }
131
+ else {
132
+ while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
133
+ const ret = execEditLength();
134
+ if (ret) {
135
+ return ret;
136
+ }
137
+ }
138
+ }
139
+ }
140
+ addToPath(path, added, removed, oldPosInc, options) {
141
+ const last = path.lastComponent;
142
+ if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
143
+ return {
144
+ oldPos: path.oldPos + oldPosInc,
145
+ lastComponent: { count: last.count + 1, added: added, removed: removed, previousComponent: last.previousComponent }
146
+ };
147
+ }
148
+ else {
149
+ return {
150
+ oldPos: path.oldPos + oldPosInc,
151
+ lastComponent: { count: 1, added: added, removed: removed, previousComponent: last }
152
+ };
153
+ }
154
+ }
155
+ extractCommon(basePath, newTokens, oldTokens, diagonalPath, options) {
156
+ const newLen = newTokens.length, oldLen = oldTokens.length;
157
+ let oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
158
+ while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
159
+ newPos++;
160
+ oldPos++;
161
+ commonCount++;
162
+ if (options.oneChangePerToken) {
163
+ basePath.lastComponent = { count: 1, previousComponent: basePath.lastComponent, added: false, removed: false };
164
+ }
165
+ }
166
+ if (commonCount && !options.oneChangePerToken) {
167
+ basePath.lastComponent = { count: commonCount, previousComponent: basePath.lastComponent, added: false, removed: false };
168
+ }
169
+ basePath.oldPos = oldPos;
170
+ return newPos;
171
+ }
172
+ equals(left, right, options) {
173
+ if (options.comparator) {
174
+ return options.comparator(left, right);
175
+ }
176
+ else {
177
+ return left === right
178
+ || (!!options.ignoreCase && left.toLowerCase() === right.toLowerCase());
179
+ }
180
+ }
181
+ removeEmpty(array) {
182
+ const ret = [];
183
+ for (let i = 0; i < array.length; i++) {
184
+ if (array[i]) {
185
+ ret.push(array[i]);
186
+ }
187
+ }
188
+ return ret;
189
+ }
190
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
191
+ castInput(value, options) {
192
+ return value;
193
+ }
194
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
195
+ tokenize(value, options) {
196
+ return Array.from(value);
197
+ }
198
+ join(chars) {
199
+ // Assumes ValueT is string, which is the case for most subclasses.
200
+ // When it's false, e.g. in diffArrays, this method needs to be overridden (e.g. with a no-op)
201
+ // Yes, the casts are verbose and ugly, because this pattern - of having the base class SORT OF
202
+ // assume tokens and values are strings, but not completely - is weird and janky.
203
+ return chars.join('');
204
+ }
205
+ postProcess(changeObjects,
206
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
207
+ options) {
208
+ return changeObjects;
209
+ }
210
+ get useLongestToken() {
211
+ return false;
212
+ }
213
+ buildValues(lastComponent, newTokens, oldTokens) {
214
+ // First we convert our linked list of components in reverse order to an
215
+ // array in the right order:
216
+ const components = [];
217
+ let nextComponent;
218
+ while (lastComponent) {
219
+ components.push(lastComponent);
220
+ nextComponent = lastComponent.previousComponent;
221
+ delete lastComponent.previousComponent;
222
+ lastComponent = nextComponent;
223
+ }
224
+ components.reverse();
225
+ const componentLen = components.length;
226
+ let componentPos = 0, newPos = 0, oldPos = 0;
227
+ for (; componentPos < componentLen; componentPos++) {
228
+ const component = components[componentPos];
229
+ if (!component.removed) {
230
+ if (!component.added && this.useLongestToken) {
231
+ let value = newTokens.slice(newPos, newPos + component.count);
232
+ value = value.map(function (value, i) {
233
+ const oldValue = oldTokens[oldPos + i];
234
+ return oldValue.length > value.length ? oldValue : value;
235
+ });
236
+ component.value = this.join(value);
237
+ }
238
+ else {
239
+ component.value = this.join(newTokens.slice(newPos, newPos + component.count));
240
+ }
241
+ newPos += component.count;
242
+ // Common case
243
+ if (!component.added) {
244
+ oldPos += component.count;
245
+ }
246
+ }
247
+ else {
248
+ component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
249
+ oldPos += component.count;
250
+ }
251
+ }
252
+ return components;
253
+ }
254
+ }
@@ -0,0 +1,66 @@
1
+ // Vendored unchanged from jsdiff 8.0.4; BSD-3-Clause. See lib/vendor/jsdiff/LICENSE.
2
+ import Diff from './base.js';
3
+ import { generateOptions } from '../util/params.js';
4
+ class LineDiff extends Diff {
5
+ constructor() {
6
+ super(...arguments);
7
+ this.tokenize = tokenize;
8
+ }
9
+ equals(left, right, options) {
10
+ // If we're ignoring whitespace, we need to normalise lines by stripping
11
+ // whitespace before checking equality. (This has an annoying interaction
12
+ // with newlineIsToken that requires special handling: if newlines get their
13
+ // own token, then we DON'T want to trim the *newline* tokens down to empty
14
+ // strings, since this would cause us to treat whitespace-only line content
15
+ // as equal to a separator between lines, which would be weird and
16
+ // inconsistent with the documented behavior of the options.)
17
+ if (options.ignoreWhitespace) {
18
+ if (!options.newlineIsToken || !left.includes('\n')) {
19
+ left = left.trim();
20
+ }
21
+ if (!options.newlineIsToken || !right.includes('\n')) {
22
+ right = right.trim();
23
+ }
24
+ }
25
+ else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
26
+ if (left.endsWith('\n')) {
27
+ left = left.slice(0, -1);
28
+ }
29
+ if (right.endsWith('\n')) {
30
+ right = right.slice(0, -1);
31
+ }
32
+ }
33
+ return super.equals(left, right, options);
34
+ }
35
+ }
36
+ export const lineDiff = new LineDiff();
37
+ export function diffLines(oldStr, newStr, options) {
38
+ return lineDiff.diff(oldStr, newStr, options);
39
+ }
40
+ export function diffTrimmedLines(oldStr, newStr, options) {
41
+ options = generateOptions(options, { ignoreWhitespace: true });
42
+ return lineDiff.diff(oldStr, newStr, options);
43
+ }
44
+ // Exported standalone so it can be used from jsonDiff too.
45
+ export function tokenize(value, options) {
46
+ if (options.stripTrailingCr) {
47
+ // remove one \r before \n to match GNU diff's --strip-trailing-cr behavior
48
+ value = value.replace(/\r\n/g, '\n');
49
+ }
50
+ const retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
51
+ // Ignore the final empty token that occurs if the string ends with a new line
52
+ if (!linesAndNewlines[linesAndNewlines.length - 1]) {
53
+ linesAndNewlines.pop();
54
+ }
55
+ // Merge the content and line separators into single tokens
56
+ for (let i = 0; i < linesAndNewlines.length; i++) {
57
+ const line = linesAndNewlines[i];
58
+ if (i % 2 && !options.newlineIsToken) {
59
+ retLines[retLines.length - 1] += line;
60
+ }
61
+ else {
62
+ retLines.push(line);
63
+ }
64
+ }
65
+ return retLines;
66
+ }
@@ -0,0 +1,229 @@
1
+ // Vendored unchanged from jsdiff 8.0.4; BSD-3-Clause. See lib/vendor/jsdiff/LICENSE.
2
+ import { diffLines } from '../diff/line.js';
3
+ export const INCLUDE_HEADERS = {
4
+ includeIndex: true,
5
+ includeUnderline: true,
6
+ includeFileHeaders: true
7
+ };
8
+ export const FILE_HEADERS_ONLY = {
9
+ includeIndex: false,
10
+ includeUnderline: false,
11
+ includeFileHeaders: true
12
+ };
13
+ export const OMIT_HEADERS = {
14
+ includeIndex: false,
15
+ includeUnderline: false,
16
+ includeFileHeaders: false
17
+ };
18
+ export function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
19
+ let optionsObj;
20
+ if (!options) {
21
+ optionsObj = {};
22
+ }
23
+ else if (typeof options === 'function') {
24
+ optionsObj = { callback: options };
25
+ }
26
+ else {
27
+ optionsObj = options;
28
+ }
29
+ if (typeof optionsObj.context === 'undefined') {
30
+ optionsObj.context = 4;
31
+ }
32
+ // We copy this into its own variable to placate TypeScript, which thinks
33
+ // optionsObj.context might be undefined in the callbacks below.
34
+ const context = optionsObj.context;
35
+ // @ts-expect-error (runtime check for something that is correctly a static type error)
36
+ if (optionsObj.newlineIsToken) {
37
+ throw new Error('newlineIsToken may not be used with patch-generation functions, only with diffing functions');
38
+ }
39
+ if (!optionsObj.callback) {
40
+ return diffLinesResultToPatch(diffLines(oldStr, newStr, optionsObj));
41
+ }
42
+ else {
43
+ const { callback } = optionsObj;
44
+ diffLines(oldStr, newStr, Object.assign(Object.assign({}, optionsObj), { callback: (diff) => {
45
+ const patch = diffLinesResultToPatch(diff);
46
+ // TypeScript is unhappy without the cast because it does not understand that `patch` may
47
+ // be undefined here only if `callback` is StructuredPatchCallbackAbortable:
48
+ callback(patch);
49
+ } }));
50
+ }
51
+ function diffLinesResultToPatch(diff) {
52
+ // STEP 1: Build up the patch with no "" lines and with the arrays
53
+ // of lines containing trailing newline characters. We'll tidy up later...
54
+ if (!diff) {
55
+ return;
56
+ }
57
+ diff.push({ value: '', lines: [] }); // Append an empty value to make cleanup easier
58
+ function contextLines(lines) {
59
+ return lines.map(function (entry) { return ' ' + entry; });
60
+ }
61
+ const hunks = [];
62
+ let oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1;
63
+ for (let i = 0; i < diff.length; i++) {
64
+ const current = diff[i], lines = current.lines || splitLines(current.value);
65
+ current.lines = lines;
66
+ if (current.added || current.removed) {
67
+ // If we have previous context, start with that
68
+ if (!oldRangeStart) {
69
+ const prev = diff[i - 1];
70
+ oldRangeStart = oldLine;
71
+ newRangeStart = newLine;
72
+ if (prev) {
73
+ curRange = context > 0 ? contextLines(prev.lines.slice(-context)) : [];
74
+ oldRangeStart -= curRange.length;
75
+ newRangeStart -= curRange.length;
76
+ }
77
+ }
78
+ // Output our changes
79
+ for (const line of lines) {
80
+ curRange.push((current.added ? '+' : '-') + line);
81
+ }
82
+ // Track the updated file position
83
+ if (current.added) {
84
+ newLine += lines.length;
85
+ }
86
+ else {
87
+ oldLine += lines.length;
88
+ }
89
+ }
90
+ else {
91
+ // Identical context lines. Track line changes
92
+ if (oldRangeStart) {
93
+ // Close out any changes that have been output (or join overlapping)
94
+ if (lines.length <= context * 2 && i < diff.length - 2) {
95
+ // Overlapping
96
+ for (const line of contextLines(lines)) {
97
+ curRange.push(line);
98
+ }
99
+ }
100
+ else {
101
+ // end the range and output
102
+ const contextSize = Math.min(lines.length, context);
103
+ for (const line of contextLines(lines.slice(0, contextSize))) {
104
+ curRange.push(line);
105
+ }
106
+ const hunk = {
107
+ oldStart: oldRangeStart,
108
+ oldLines: (oldLine - oldRangeStart + contextSize),
109
+ newStart: newRangeStart,
110
+ newLines: (newLine - newRangeStart + contextSize),
111
+ lines: curRange
112
+ };
113
+ hunks.push(hunk);
114
+ oldRangeStart = 0;
115
+ newRangeStart = 0;
116
+ curRange = [];
117
+ }
118
+ }
119
+ oldLine += lines.length;
120
+ newLine += lines.length;
121
+ }
122
+ }
123
+ // Step 2: eliminate the trailing `\n` from each line of each hunk, and, where needed, add
124
+ // "".
125
+ for (const hunk of hunks) {
126
+ for (let i = 0; i < hunk.lines.length; i++) {
127
+ if (hunk.lines[i].endsWith('\n')) {
128
+ hunk.lines[i] = hunk.lines[i].slice(0, -1);
129
+ }
130
+ else {
131
+ hunk.lines.splice(i + 1, 0, '\');
132
+ i++; // Skip the line we just added, then continue iterating
133
+ }
134
+ }
135
+ }
136
+ return {
137
+ oldFileName: oldFileName, newFileName: newFileName,
138
+ oldHeader: oldHeader, newHeader: newHeader,
139
+ hunks: hunks
140
+ };
141
+ }
142
+ }
143
+ /**
144
+ * creates a unified diff patch.
145
+ * @param patch either a single structured patch object (as returned by `structuredPatch`) or an array of them (as returned by `parsePatch`)
146
+ */
147
+ export function formatPatch(patch, headerOptions) {
148
+ if (!headerOptions) {
149
+ headerOptions = INCLUDE_HEADERS;
150
+ }
151
+ if (Array.isArray(patch)) {
152
+ if (patch.length > 1 && !headerOptions.includeFileHeaders) {
153
+ throw new Error('Cannot omit file headers on a multi-file patch. '
154
+ + '(The result would be unparseable; how would a tool trying to apply '
155
+ + 'the patch know which changes are to which file?)');
156
+ }
157
+ return patch.map(p => formatPatch(p, headerOptions)).join('\n');
158
+ }
159
+ const ret = [];
160
+ if (headerOptions.includeIndex && patch.oldFileName == patch.newFileName) {
161
+ ret.push('Index: ' + patch.oldFileName);
162
+ }
163
+ if (headerOptions.includeUnderline) {
164
+ ret.push('===================================================================');
165
+ }
166
+ if (headerOptions.includeFileHeaders) {
167
+ ret.push('--- ' + patch.oldFileName + (typeof patch.oldHeader === 'undefined' ? '' : '\t' + patch.oldHeader));
168
+ ret.push('+++ ' + patch.newFileName + (typeof patch.newHeader === 'undefined' ? '' : '\t' + patch.newHeader));
169
+ }
170
+ for (let i = 0; i < patch.hunks.length; i++) {
171
+ const hunk = patch.hunks[i];
172
+ // Unified Diff Format quirk: If the chunk size is 0,
173
+ // the first number is one lower than one would expect.
174
+ // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
175
+ if (hunk.oldLines === 0) {
176
+ hunk.oldStart -= 1;
177
+ }
178
+ if (hunk.newLines === 0) {
179
+ hunk.newStart -= 1;
180
+ }
181
+ ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines
182
+ + ' +' + hunk.newStart + ',' + hunk.newLines
183
+ + ' @@');
184
+ for (const line of hunk.lines) {
185
+ ret.push(line);
186
+ }
187
+ }
188
+ return ret.join('\n') + '\n';
189
+ }
190
+ export function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
191
+ if (typeof options === 'function') {
192
+ options = { callback: options };
193
+ }
194
+ if (!(options === null || options === void 0 ? void 0 : options.callback)) {
195
+ const patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
196
+ if (!patchObj) {
197
+ return;
198
+ }
199
+ return formatPatch(patchObj, options === null || options === void 0 ? void 0 : options.headerOptions);
200
+ }
201
+ else {
202
+ const { callback } = options;
203
+ structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, Object.assign(Object.assign({}, options), { callback: patchObj => {
204
+ if (!patchObj) {
205
+ callback(undefined);
206
+ }
207
+ else {
208
+ callback(formatPatch(patchObj, options.headerOptions));
209
+ }
210
+ } }));
211
+ }
212
+ }
213
+ export function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
214
+ return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
215
+ }
216
+ /**
217
+ * Split `text` into an array of lines, including the trailing newline character (where present)
218
+ */
219
+ function splitLines(text) {
220
+ const hasTrailingNl = text.endsWith('\n');
221
+ const result = text.split('\n').map(line => line + '\n');
222
+ if (hasTrailingNl) {
223
+ result.pop();
224
+ }
225
+ else {
226
+ result.push(result.pop().slice(0, -1));
227
+ }
228
+ return result;
229
+ }
@@ -0,0 +1,15 @@
1
+ // Vendored unchanged from jsdiff 8.0.4; BSD-3-Clause. See lib/vendor/jsdiff/LICENSE.
2
+ export function generateOptions(options, defaults) {
3
+ if (typeof options === 'function') {
4
+ defaults.callback = options;
5
+ }
6
+ else if (options) {
7
+ for (const name in options) {
8
+ /* istanbul ignore else */
9
+ if (Object.prototype.hasOwnProperty.call(options, name)) {
10
+ defaults[name] = options[name];
11
+ }
12
+ }
13
+ }
14
+ return defaults;
15
+ }