@nifrajs/cli 5.8.0 → 5.9.0

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 (248) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/dist/agent-files.d.ts +0 -22
  3. package/dist/agent-files.d.ts.map +1 -1
  4. package/dist/agent-files.js +3 -1
  5. package/dist/agent-files.js.map +1 -1
  6. package/dist/assure-hydration.d.ts.map +1 -1
  7. package/dist/assure-hydration.js +2 -10
  8. package/dist/assure-hydration.js.map +1 -1
  9. package/dist/assure.d.ts.map +1 -1
  10. package/dist/assure.js +3 -3
  11. package/dist/assure.js.map +1 -1
  12. package/dist/check-scan.d.ts +2 -0
  13. package/dist/check-scan.d.ts.map +1 -1
  14. package/dist/check-scan.js +54 -86
  15. package/dist/check-scan.js.map +1 -1
  16. package/dist/check.d.ts +3 -0
  17. package/dist/check.d.ts.map +1 -1
  18. package/dist/check.js +20 -23
  19. package/dist/check.js.map +1 -1
  20. package/dist/cli.d.ts +8 -0
  21. package/dist/cli.d.ts.map +1 -1
  22. package/dist/cli.js +42 -13
  23. package/dist/cli.js.map +1 -1
  24. package/dist/command-catalog.d.ts.map +1 -1
  25. package/dist/command-catalog.js +20 -30
  26. package/dist/command-catalog.js.map +1 -1
  27. package/dist/config-target.js +1 -1
  28. package/dist/config-target.js.map +1 -1
  29. package/dist/db-child.js +3 -10
  30. package/dist/db-child.js.map +1 -1
  31. package/dist/db-config.d.ts +2 -0
  32. package/dist/db-config.d.ts.map +1 -1
  33. package/dist/db-config.js +2 -0
  34. package/dist/db-config.js.map +1 -1
  35. package/dist/doctor.d.ts +14 -3
  36. package/dist/doctor.d.ts.map +1 -1
  37. package/dist/doctor.js +91 -6
  38. package/dist/doctor.js.map +1 -1
  39. package/dist/frontend-guidance.d.ts +19 -0
  40. package/dist/frontend-guidance.d.ts.map +1 -1
  41. package/dist/frontend-guidance.js +267 -23
  42. package/dist/frontend-guidance.js.map +1 -1
  43. package/dist/hand-built-manifest.d.ts.map +1 -1
  44. package/dist/hand-built-manifest.js +1 -1
  45. package/dist/hand-built-manifest.js.map +1 -1
  46. package/dist/internal/control-character.d.ts +3 -0
  47. package/dist/internal/control-character.d.ts.map +1 -0
  48. package/dist/internal/control-character.js +10 -0
  49. package/dist/internal/control-character.js.map +1 -0
  50. package/dist/internal/escape-regexp.d.ts +3 -0
  51. package/dist/internal/escape-regexp.d.ts.map +1 -0
  52. package/dist/internal/escape-regexp.js +5 -0
  53. package/dist/internal/escape-regexp.js.map +1 -0
  54. package/dist/internal/line-at.d.ts +3 -0
  55. package/dist/internal/line-at.d.ts.map +1 -0
  56. package/dist/internal/line-at.js +5 -0
  57. package/dist/internal/line-at.js.map +1 -0
  58. package/dist/internal/nifra-project.d.ts.map +1 -1
  59. package/dist/internal/nifra-project.js +35 -41
  60. package/dist/internal/nifra-project.js.map +1 -1
  61. package/dist/internal/posix-path.d.ts +3 -0
  62. package/dist/internal/posix-path.d.ts.map +1 -0
  63. package/dist/internal/posix-path.js +5 -0
  64. package/dist/internal/posix-path.js.map +1 -0
  65. package/dist/internal/project-specifiers.d.ts.map +1 -1
  66. package/dist/internal/project-specifiers.js +3 -10
  67. package/dist/internal/project-specifiers.js.map +1 -1
  68. package/dist/internal/realpath-or-self.d.ts +3 -0
  69. package/dist/internal/realpath-or-self.d.ts.map +1 -0
  70. package/dist/internal/realpath-or-self.js +11 -0
  71. package/dist/internal/realpath-or-self.js.map +1 -0
  72. package/dist/internal/record.d.ts +3 -0
  73. package/dist/internal/record.d.ts.map +1 -0
  74. package/dist/internal/record.js +5 -0
  75. package/dist/internal/record.js.map +1 -0
  76. package/dist/internal/source-facts.d.ts.map +1 -1
  77. package/dist/internal/source-facts.js +28 -25
  78. package/dist/internal/source-facts.js.map +1 -1
  79. package/dist/introspect.d.ts +0 -22
  80. package/dist/introspect.d.ts.map +1 -1
  81. package/dist/introspect.js +11 -151
  82. package/dist/introspect.js.map +1 -1
  83. package/dist/levels-tool.d.ts +2 -0
  84. package/dist/levels-tool.d.ts.map +1 -1
  85. package/dist/levels-tool.js +54 -64
  86. package/dist/levels-tool.js.map +1 -1
  87. package/dist/load.d.ts +6 -1
  88. package/dist/load.d.ts.map +1 -1
  89. package/dist/load.js.map +1 -1
  90. package/dist/local-cli.d.ts +7 -0
  91. package/dist/local-cli.d.ts.map +1 -1
  92. package/dist/local-cli.js +13 -0
  93. package/dist/local-cli.js.map +1 -1
  94. package/dist/mcp-docs-tools.d.ts +1 -1
  95. package/dist/mcp-docs-tools.d.ts.map +1 -1
  96. package/dist/mcp-docs-tools.js +46 -3
  97. package/dist/mcp-docs-tools.js.map +1 -1
  98. package/dist/mcp-http.d.ts +1 -1
  99. package/dist/mcp-http.js +2 -2
  100. package/dist/mcp-io.d.ts +16 -0
  101. package/dist/mcp-io.d.ts.map +1 -1
  102. package/dist/mcp-io.js +63 -0
  103. package/dist/mcp-io.js.map +1 -1
  104. package/dist/mcp-isolate.d.ts.map +1 -1
  105. package/dist/mcp-isolate.js +2 -1
  106. package/dist/mcp-isolate.js.map +1 -1
  107. package/dist/mcp-project-child.d.ts.map +1 -1
  108. package/dist/mcp-project-child.js +5 -12
  109. package/dist/mcp-project-child.js.map +1 -1
  110. package/dist/mcp-render.d.ts.map +1 -1
  111. package/dist/mcp-render.js +9 -51
  112. package/dist/mcp-render.js.map +1 -1
  113. package/dist/mcp-root.js +1 -1
  114. package/dist/mcp-root.js.map +1 -1
  115. package/dist/mcp-run.d.ts.map +1 -1
  116. package/dist/mcp-run.js +3 -46
  117. package/dist/mcp-run.js.map +1 -1
  118. package/dist/mcp-ws.d.ts.map +1 -1
  119. package/dist/mcp-ws.js +2 -18
  120. package/dist/mcp-ws.js.map +1 -1
  121. package/dist/migrate-layout.d.ts.map +1 -1
  122. package/dist/migrate-layout.js +36 -57
  123. package/dist/migrate-layout.js.map +1 -1
  124. package/dist/output-schemas.d.ts.map +1 -1
  125. package/dist/output-schemas.js +7 -7
  126. package/dist/output-schemas.js.map +1 -1
  127. package/dist/port.d.ts.map +1 -1
  128. package/dist/port.js +1 -2
  129. package/dist/port.js.map +1 -1
  130. package/dist/ppr-read-fix.js +2 -2
  131. package/dist/ppr-read-fix.js.map +1 -1
  132. package/dist/recipes/5.9.0.d.ts +10 -0
  133. package/dist/recipes/5.9.0.d.ts.map +1 -0
  134. package/dist/recipes/5.9.0.js +41 -0
  135. package/dist/recipes/5.9.0.js.map +1 -0
  136. package/dist/recipes/index.d.ts +5 -0
  137. package/dist/recipes/index.d.ts.map +1 -1
  138. package/dist/recipes/index.js +2 -0
  139. package/dist/recipes/index.js.map +1 -1
  140. package/dist/review.d.ts.map +1 -1
  141. package/dist/review.js +9 -13
  142. package/dist/review.js.map +1 -1
  143. package/dist/rules/contract-visibility.d.ts.map +1 -1
  144. package/dist/rules/contract-visibility.js +3 -9
  145. package/dist/rules/contract-visibility.js.map +1 -1
  146. package/dist/rules/data-guard.d.ts.map +1 -1
  147. package/dist/rules/data-guard.js +3 -10
  148. package/dist/rules/data-guard.js.map +1 -1
  149. package/dist/rules/pages.d.ts.map +1 -1
  150. package/dist/rules/pages.js +41 -58
  151. package/dist/rules/pages.js.map +1 -1
  152. package/dist/rules/routes.d.ts.map +1 -1
  153. package/dist/rules/routes.js +20 -27
  154. package/dist/rules/routes.js.map +1 -1
  155. package/dist/rules/security.d.ts.map +1 -1
  156. package/dist/rules/security.js +206 -313
  157. package/dist/rules/security.js.map +1 -1
  158. package/dist/rules/zones.d.ts.map +1 -1
  159. package/dist/rules/zones.js +3 -10
  160. package/dist/rules/zones.js.map +1 -1
  161. package/dist/runtime-differences.d.ts +62 -0
  162. package/dist/runtime-differences.d.ts.map +1 -0
  163. package/dist/runtime-differences.js +222 -0
  164. package/dist/runtime-differences.js.map +1 -0
  165. package/dist/sdk.d.ts.map +1 -1
  166. package/dist/sdk.js +43 -43
  167. package/dist/sdk.js.map +1 -1
  168. package/dist/smoke.d.ts.map +1 -1
  169. package/dist/smoke.js +4 -12
  170. package/dist/smoke.js.map +1 -1
  171. package/dist/source-rewrites.d.ts +27 -0
  172. package/dist/source-rewrites.d.ts.map +1 -0
  173. package/dist/source-rewrites.js +402 -0
  174. package/dist/source-rewrites.js.map +1 -0
  175. package/dist/stylex-migrate.d.ts.map +1 -1
  176. package/dist/stylex-migrate.js +1 -1
  177. package/dist/stylex-migrate.js.map +1 -1
  178. package/dist/symptom-search.d.ts +5 -0
  179. package/dist/symptom-search.d.ts.map +1 -0
  180. package/dist/symptom-search.js +21 -0
  181. package/dist/symptom-search.js.map +1 -0
  182. package/dist/upgrade.d.ts +28 -3
  183. package/dist/upgrade.d.ts.map +1 -1
  184. package/dist/upgrade.js +153 -64
  185. package/dist/upgrade.js.map +1 -1
  186. package/dist/verification-plan.d.ts.map +1 -1
  187. package/dist/verification-plan.js +5 -3
  188. package/dist/verification-plan.js.map +1 -1
  189. package/docs/examples.json +32 -2
  190. package/docs/llms-full.txt +749 -95
  191. package/docs/types.json +300 -61
  192. package/package.json +11 -11
  193. package/src/agent-files.ts +4 -1
  194. package/src/assure-hydration.ts +2 -9
  195. package/src/assure.ts +3 -4
  196. package/src/check-scan.ts +65 -82
  197. package/src/check.ts +25 -23
  198. package/src/cli.ts +61 -13
  199. package/src/command-catalog.ts +22 -32
  200. package/src/config-target.ts +1 -1
  201. package/src/db-child.ts +3 -10
  202. package/src/db-config.ts +4 -0
  203. package/src/doctor.ts +128 -12
  204. package/src/frontend-guidance.ts +344 -25
  205. package/src/hand-built-manifest.ts +1 -2
  206. package/src/internal/control-character.ts +8 -0
  207. package/src/internal/escape-regexp.ts +4 -0
  208. package/src/internal/line-at.ts +4 -0
  209. package/src/internal/nifra-project.ts +39 -35
  210. package/src/internal/posix-path.ts +4 -0
  211. package/src/internal/project-specifiers.ts +3 -10
  212. package/src/internal/realpath-or-self.ts +10 -0
  213. package/src/internal/record.ts +4 -0
  214. package/src/internal/source-facts.ts +39 -29
  215. package/src/introspect.ts +16 -156
  216. package/src/levels-tool.ts +71 -78
  217. package/src/load.ts +6 -1
  218. package/src/local-cli.ts +12 -0
  219. package/src/mcp-docs-tools.ts +51 -3
  220. package/src/mcp-http.ts +2 -2
  221. package/src/mcp-io.ts +77 -0
  222. package/src/mcp-isolate.ts +2 -3
  223. package/src/mcp-project-child.ts +5 -14
  224. package/src/mcp-render.ts +11 -59
  225. package/src/mcp-root.ts +1 -1
  226. package/src/mcp-run.ts +5 -54
  227. package/src/mcp-ws.ts +2 -19
  228. package/src/migrate-layout.ts +52 -72
  229. package/src/output-schemas.ts +7 -8
  230. package/src/port.ts +1 -4
  231. package/src/ppr-read-fix.ts +2 -2
  232. package/src/recipes/5.9.0.ts +42 -0
  233. package/src/recipes/index.ts +7 -0
  234. package/src/review.ts +12 -15
  235. package/src/rules/contract-visibility.ts +3 -8
  236. package/src/rules/data-guard.ts +3 -10
  237. package/src/rules/pages.ts +47 -58
  238. package/src/rules/routes.ts +21 -27
  239. package/src/rules/security.ts +224 -255
  240. package/src/rules/zones.ts +3 -10
  241. package/src/runtime-differences.ts +302 -0
  242. package/src/sdk.ts +55 -58
  243. package/src/smoke.ts +4 -13
  244. package/src/source-rewrites.ts +463 -0
  245. package/src/stylex-migrate.ts +1 -3
  246. package/src/symptom-search.ts +27 -0
  247. package/src/upgrade.ts +194 -74
  248. package/src/verification-plan.ts +10 -4
@@ -25,7 +25,7 @@
25
25
  * a moved name at runtime, a helper both halves need, a loader with no output schema, an import no
26
26
  * specifier reaches after the moves, a specifier that names nothing) instead of guessing.
27
27
  */
28
- import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, writeFileSync, } from "node:fs";
28
+ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmdirSync, rmSync, statSync, writeFileSync, } from "node:fs";
29
29
  import { builtinModules } from "node:module";
30
30
  import { dirname, extname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
31
31
  import { BACKEND_ROUTE_EXPORTS } from "@nifrajs/web/route-manifest";
@@ -33,8 +33,11 @@ import { parseZoneConfig } from "@nifrajs/web/zones";
33
33
  import { BACKEND_APP_FILE, CONFIG_FILE, FRAMEWORK_FILE, retiredRootFiles } from "./app-files.js";
34
34
  import { codeUnitOrder } from "./internal/code-unit-order.js";
35
35
  import { configPathReader } from "./internal/config-paths.js";
36
+ import { escapeRegExp } from "./internal/escape-regexp.js";
36
37
  import { createKindProbe, hasWebConfig } from "./internal/nifra-project.js";
38
+ import { toPosix } from "./internal/posix-path.js";
37
39
  import { createSpecifierResolver, isFile } from "./internal/project-specifiers.js";
40
+ import { realpathOrSelf } from "./internal/realpath-or-self.js";
38
41
  import { importTypeScript } from "./internal/typescript-import.js";
39
42
  import { planOutputSchemas } from "./output-schemas.js";
40
43
  import { missingOutputSchemas } from "./rules/data-guard.js";
@@ -96,7 +99,6 @@ const SUBJECT_EXTENSIONS = [
96
99
  ".svelte",
97
100
  ".vue",
98
101
  ];
99
- const toPosix = (path) => path.replaceAll("\\", "/");
100
102
  /** A specifier without its `?query` or `#hash`; a leading `#` names a package.json import. Cut by
101
103
  * index, since `/[?#].*$/` retries from every `#` and is quadratic on a long run of them. */
102
104
  const withoutQuery = (specifier) => {
@@ -325,7 +327,6 @@ function filterExportList(ts, sf, node, keep) {
325
327
  const leading = node.getFullText(sf).slice(0, node.getStart(sf) - node.getFullStart());
326
328
  return `${leading}export ${node.isTypeOnly ? "type " : ""}{ ${kept.join(", ")} }${from}${terminatorOf(sf, node)}`;
327
329
  }
328
- const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
329
330
  const joinStatements = (texts) => {
330
331
  const body = texts.join("").replace(/^\s*\n/, "");
331
332
  return body.endsWith("\n") ? body : `${body}\n`;
@@ -845,6 +846,13 @@ function scriptBlocks(source) {
845
846
  }
846
847
  return blocks;
847
848
  }
849
+ /** `text` with every edit made, last offset first so the ones before it still point where they did. */
850
+ function applyEdits(text, edits) {
851
+ let out = text;
852
+ for (const edit of edits.sort((a, b) => b.start - a.start))
853
+ out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
854
+ return out;
855
+ }
848
856
  /** The path argument of `mock.module("./x", ...)` or a vitest/jest twin, when it is a literal. */
849
857
  function mockedSpecifier(ts, node) {
850
858
  const callee = node.expression;
@@ -1258,10 +1266,7 @@ function rebaseOwnPaths(ts, from, to, text, locate) {
1258
1266
  followed.push([declaration.initializer.getStart(sf), declaration.initializer.getEnd()]);
1259
1267
  }
1260
1268
  const unfollowed = [...text.matchAll(new RegExp(SELF_LOCATION.source, "g"))].find((match) => !followed.some(([start, end]) => start <= match.index && match.index < end))?.[0];
1261
- let next = text;
1262
- for (const edit of edits.sort((a, b) => b.start - a.start))
1263
- next = next.slice(0, edit.start) + edit.text + next.slice(edit.end);
1264
- return { text: next, unfollowed };
1269
+ return { text: applyEdits(text, edits), unfollowed };
1265
1270
  }
1266
1271
  /** Rewrite one relative specifier from `from`'s new location to `target`'s new location, keeping the
1267
1272
  * author's style: extension kept when written, dropped when not, `/index` collapsed when it was. */
@@ -1397,10 +1402,7 @@ function redirectMovedImports(ts, file, text, splitOf) {
1397
1402
  ts.forEachChild(node, visit);
1398
1403
  };
1399
1404
  visit(sf);
1400
- let out = text;
1401
- for (const edit of edits.sort((a, b) => b.start - a.start))
1402
- out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
1403
- return { text: out, issues, redirects };
1405
+ return { text: applyEdits(text, edits), issues, redirects };
1404
1406
  }
1405
1407
  /**
1406
1408
  * The exports code reads from what `import()` loads: off the awaited module (`(await import(x)).a`),
@@ -1456,7 +1458,7 @@ function dynamicReads(ts, sf, call) {
1456
1458
  function workspacePattern(glob) {
1457
1459
  const source = glob
1458
1460
  .replace(/^\.\//, "")
1459
- .replace(/\/+$/, "")
1461
+ .replace(/(?<!\/)\/+$/, "")
1460
1462
  .split("/")
1461
1463
  .map((segment) => segment === "**"
1462
1464
  ? "(?:[^/]+/)*?[^/]*"
@@ -1642,35 +1644,30 @@ function rewriteImports(ts, file, text, rewrite) {
1642
1644
  visit(sf);
1643
1645
  };
1644
1646
  const edits = [];
1645
- if (/\.(?:svelte|vue)$/.test(file)) {
1646
- for (const block of scriptBlocks(text))
1647
- replace(text.slice(block.start, block.end), block.start, edits, ts.ScriptKind.TS);
1648
- }
1649
- else if (file.endsWith(".css")) {
1650
- for (const match of text.matchAll(/(@import\s+(?:url\()?["'])([^"']+)["']/g)) {
1647
+ // A match's group 2 is the specifier; group 1 is everything before it.
1648
+ const rewriteMatches = (pattern) => {
1649
+ for (const match of text.matchAll(pattern)) {
1651
1650
  const next = rewrite(match[2] ?? "");
1652
1651
  if (next !== undefined) {
1653
1652
  const start = (match.index ?? 0) + (match[1] ?? "").length;
1654
1653
  edits.push({ start, end: start + (match[2] ?? "").length, text: next });
1655
1654
  }
1656
1655
  }
1656
+ };
1657
+ if (/\.(?:svelte|vue)$/.test(file)) {
1658
+ for (const block of scriptBlocks(text))
1659
+ replace(text.slice(block.start, block.end), block.start, edits, ts.ScriptKind.TS);
1660
+ }
1661
+ else if (file.endsWith(".css")) {
1662
+ rewriteMatches(/(@import\s+(?:url\()?["'])([^"']+)["']/g);
1657
1663
  }
1658
1664
  else if (file.endsWith(".mdx")) {
1659
- for (const match of text.matchAll(/^((?:import|export)\s[^\n]*?from\s+["'])([^"']+)["']/gm)) {
1660
- const next = rewrite(match[2] ?? "");
1661
- if (next !== undefined) {
1662
- const start = (match.index ?? 0) + (match[1] ?? "").length;
1663
- edits.push({ start, end: start + (match[2] ?? "").length, text: next });
1664
- }
1665
- }
1665
+ rewriteMatches(/^((?:import|export)\s[^\n]*?from\s+["'])([^"']+)["']/gm);
1666
1666
  }
1667
1667
  else if (/\.[cm]?[jt]sx?$/.test(file)) {
1668
1668
  replace(text, 0, edits, file.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
1669
1669
  }
1670
- let out = text;
1671
- for (const edit of edits.sort((a, b) => b.start - a.start))
1672
- out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
1673
- return out;
1670
+ return applyEdits(text, edits);
1674
1671
  }
1675
1672
  /** `ServerOnly` imported from `@nifrajs/web` becomes `BackendOnly`, along with every use of it. */
1676
1673
  function renameRetiredTypes(ts, file, text) {
@@ -1718,10 +1715,7 @@ function renameRetiredTypes(ts, file, text) {
1718
1715
  else if (/\.[cm]?[jt]sx?$/.test(file)) {
1719
1716
  scan(text, 0, file.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
1720
1717
  }
1721
- let out = text;
1722
- for (const edit of edits.sort((a, b) => b.start - a.start))
1723
- out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
1724
- return out;
1718
+ return applyEdits(text, edits);
1725
1719
  }
1726
1720
  // ---------------------------------------------------------------------------------------------------
1727
1721
  // The migration
@@ -1937,14 +1931,7 @@ export async function migrateLayout(appRoot, options = {}) {
1937
1931
  const resolver = createSpecifierResolver({
1938
1932
  moduleExists: (path) => knownPaths.has(path) || isFile(path),
1939
1933
  });
1940
- const realRoot = (() => {
1941
- try {
1942
- return realpathSync(root);
1943
- }
1944
- catch {
1945
- return root;
1946
- }
1947
- })();
1934
+ const realRoot = realpathOrSelf(root);
1948
1935
  /** An app file as the migration names it, from a path the resolver found (real, or as planned). */
1949
1936
  const appFile = (path) => {
1950
1937
  if (path === undefined)
@@ -2405,10 +2392,7 @@ export async function migrateLayout(appRoot, options = {}) {
2405
2392
  }
2406
2393
  if (edits.length === 0)
2407
2394
  continue;
2408
- let updated = text;
2409
- for (const edit of edits.sort((a, b) => b.start - a.start))
2410
- updated = updated.slice(0, edit.start) + edit.text + updated.slice(edit.end);
2411
- final.set(at, updated);
2395
+ final.set(at, applyEdits(text, edits));
2412
2396
  if (!moveMap.has(file) && !rewritten.includes(file))
2413
2397
  rewritten.push(file);
2414
2398
  }
@@ -2434,10 +2418,7 @@ export async function migrateLayout(appRoot, options = {}) {
2434
2418
  }
2435
2419
  if (edits.length === 0)
2436
2420
  continue;
2437
- let updated = text;
2438
- for (const edit of edits.sort((a, b) => b.start - a.start))
2439
- updated = updated.slice(0, edit.start) + edit.text + updated.slice(edit.end);
2440
- final.set(at, updated);
2421
+ final.set(at, applyEdits(text, edits));
2441
2422
  if (!moveMap.has(configFile) && !rewritten.includes(configFile))
2442
2423
  rewritten.push(configFile);
2443
2424
  }
@@ -2835,7 +2816,10 @@ const matchers = new Map();
2835
2816
  function matches(pattern, file) {
2836
2817
  let match = matchers.get(pattern);
2837
2818
  if (match === undefined) {
2838
- let spec = pattern.replaceAll("\\", "/").replace(/^\.\//, "").replace(/\/+$/, "");
2819
+ let spec = pattern
2820
+ .replaceAll("\\", "/")
2821
+ .replace(/^\.\//, "")
2822
+ .replace(/(?<!\/)\/+$/, "");
2839
2823
  if (spec === "" || spec === ".")
2840
2824
  match = () => true;
2841
2825
  else if (!/[*?]/.test(spec)) {
@@ -2948,9 +2932,7 @@ function followTsconfigs(ts, root, moves, layout) {
2948
2932
  }
2949
2933
  own.set(key, lists);
2950
2934
  }
2951
- let updated = text;
2952
- for (const edit of edits.sort((a, b) => b.start - a.start))
2953
- updated = updated.slice(0, edit.start) + edit.text + updated.slice(edit.end);
2935
+ let updated = applyEdits(text, edits);
2954
2936
  const changes = [];
2955
2937
  if (edits.length > 0)
2956
2938
  changes.push(`${edits.length} file path(s) follow their moved files`);
@@ -3295,10 +3277,7 @@ function rewritePackagePaths(ts, text, moves) {
3295
3277
  if (PACKAGE_PATH_FIELDS.has(property.name.text))
3296
3278
  visit(property.initializer, property.name.text);
3297
3279
  }
3298
- let next = text;
3299
- for (const edit of edits.sort((a, b) => b.start - a.start))
3300
- next = next.slice(0, edit.start) + edit.text + next.slice(edit.end);
3301
- return { text: next, count };
3280
+ return { text: applyEdits(text, edits), count };
3302
3281
  }
3303
3282
  /** Tailwind `content` globs that matched a moved file at its old path and match nothing at its new one. */
3304
3283
  function staleContentGlobs(ts, text, moves) {