@nifrajs/cli 5.1.0 → 5.3.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 (230) hide show
  1. package/CHANGELOG.md +3313 -0
  2. package/README.md +3 -0
  3. package/dist/agent-files.d.ts +19 -11
  4. package/dist/agent-files.d.ts.map +1 -1
  5. package/dist/agent-files.js +26 -18
  6. package/dist/agent-files.js.map +1 -1
  7. package/dist/assure-hydration.d.ts.map +1 -1
  8. package/dist/assure-hydration.js +7 -2
  9. package/dist/assure-hydration.js.map +1 -1
  10. package/dist/assure.d.ts.map +1 -1
  11. package/dist/assure.js +14 -1
  12. package/dist/assure.js.map +1 -1
  13. package/dist/capabilities-tool.d.ts.map +1 -1
  14. package/dist/capabilities-tool.js +131 -45
  15. package/dist/capabilities-tool.js.map +1 -1
  16. package/dist/check-diagnostics.d.ts +5 -0
  17. package/dist/check-diagnostics.d.ts.map +1 -1
  18. package/dist/check-diagnostics.js +5 -0
  19. package/dist/check-diagnostics.js.map +1 -1
  20. package/dist/check-scan.d.ts +9 -3
  21. package/dist/check-scan.d.ts.map +1 -1
  22. package/dist/check-scan.js +61 -21
  23. package/dist/check-scan.js.map +1 -1
  24. package/dist/check.d.ts.map +1 -1
  25. package/dist/check.js +55 -15
  26. package/dist/check.js.map +1 -1
  27. package/dist/cli.d.ts.map +1 -1
  28. package/dist/cli.js +37 -18
  29. package/dist/cli.js.map +1 -1
  30. package/dist/command-catalog.d.ts.map +1 -1
  31. package/dist/command-catalog.js +9 -5
  32. package/dist/command-catalog.js.map +1 -1
  33. package/dist/db-tool.d.ts.map +1 -1
  34. package/dist/db-tool.js +2 -1
  35. package/dist/db-tool.js.map +1 -1
  36. package/dist/dev-bun-config.d.ts +6 -3
  37. package/dist/dev-bun-config.d.ts.map +1 -1
  38. package/dist/dev-bun-config.js +13 -10
  39. package/dist/dev-bun-config.js.map +1 -1
  40. package/dist/dev-feed-tool.d.ts +3 -2
  41. package/dist/dev-feed-tool.d.ts.map +1 -1
  42. package/dist/dev-feed-tool.js +26 -5
  43. package/dist/dev-feed-tool.js.map +1 -1
  44. package/dist/doctor.d.ts +15 -1
  45. package/dist/doctor.d.ts.map +1 -1
  46. package/dist/doctor.js +79 -61
  47. package/dist/doctor.js.map +1 -1
  48. package/dist/env-file.d.ts.map +1 -1
  49. package/dist/env-file.js +41 -8
  50. package/dist/env-file.js.map +1 -1
  51. package/dist/i18n-check.d.ts +11 -1
  52. package/dist/i18n-check.d.ts.map +1 -1
  53. package/dist/i18n-check.js +170 -17
  54. package/dist/i18n-check.js.map +1 -1
  55. package/dist/init-agents.d.ts +46 -6
  56. package/dist/init-agents.d.ts.map +1 -1
  57. package/dist/init-agents.js +193 -31
  58. package/dist/init-agents.js.map +1 -1
  59. package/dist/internal/project-specifiers.d.ts.map +1 -1
  60. package/dist/internal/project-specifiers.js +9 -1
  61. package/dist/internal/project-specifiers.js.map +1 -1
  62. package/dist/internal/source-facts.d.ts +22 -0
  63. package/dist/internal/source-facts.d.ts.map +1 -1
  64. package/dist/internal/source-facts.js +322 -0
  65. package/dist/internal/source-facts.js.map +1 -1
  66. package/dist/internal/workspace-packages.d.ts +22 -0
  67. package/dist/internal/workspace-packages.d.ts.map +1 -0
  68. package/dist/internal/workspace-packages.js +215 -0
  69. package/dist/internal/workspace-packages.js.map +1 -0
  70. package/dist/load.d.ts +7 -2
  71. package/dist/load.d.ts.map +1 -1
  72. package/dist/load.js +11 -2
  73. package/dist/load.js.map +1 -1
  74. package/dist/lock-links.d.ts +42 -0
  75. package/dist/lock-links.d.ts.map +1 -0
  76. package/dist/lock-links.js +144 -0
  77. package/dist/lock-links.js.map +1 -0
  78. package/dist/mcp-exec.d.ts +1 -0
  79. package/dist/mcp-exec.d.ts.map +1 -1
  80. package/dist/mcp-exec.js +16 -5
  81. package/dist/mcp-exec.js.map +1 -1
  82. package/dist/mcp-http.js +1 -1
  83. package/dist/mcp-io.d.ts +23 -3
  84. package/dist/mcp-io.d.ts.map +1 -1
  85. package/dist/mcp-io.js +59 -12
  86. package/dist/mcp-io.js.map +1 -1
  87. package/dist/mcp-isolate.d.ts.map +1 -1
  88. package/dist/mcp-isolate.js +2 -1
  89. package/dist/mcp-isolate.js.map +1 -1
  90. package/dist/mcp-root.d.ts +6 -4
  91. package/dist/mcp-root.d.ts.map +1 -1
  92. package/dist/mcp-root.js +12 -8
  93. package/dist/mcp-root.js.map +1 -1
  94. package/dist/migrate-layout.d.ts +2 -1
  95. package/dist/migrate-layout.d.ts.map +1 -1
  96. package/dist/migrate-layout.js +435 -29
  97. package/dist/migrate-layout.js.map +1 -1
  98. package/dist/project-site.d.ts +7 -0
  99. package/dist/project-site.d.ts.map +1 -0
  100. package/dist/project-site.js +19 -0
  101. package/dist/project-site.js.map +1 -0
  102. package/dist/recipes/4.0.0.d.ts.map +1 -1
  103. package/dist/recipes/4.0.0.js +2 -0
  104. package/dist/recipes/4.0.0.js.map +1 -1
  105. package/dist/recipes/5.1.0.d.ts +9 -0
  106. package/dist/recipes/5.1.0.d.ts.map +1 -0
  107. package/dist/recipes/5.1.0.js +22 -0
  108. package/dist/recipes/5.1.0.js.map +1 -0
  109. package/dist/recipes/5.2.0.d.ts +10 -0
  110. package/dist/recipes/5.2.0.d.ts.map +1 -0
  111. package/dist/recipes/5.2.0.js +32 -0
  112. package/dist/recipes/5.2.0.js.map +1 -0
  113. package/dist/recipes/5.3.0.d.ts +11 -0
  114. package/dist/recipes/5.3.0.d.ts.map +1 -0
  115. package/dist/recipes/5.3.0.js +35 -0
  116. package/dist/recipes/5.3.0.js.map +1 -0
  117. package/dist/recipes/index.d.ts +3 -0
  118. package/dist/recipes/index.d.ts.map +1 -1
  119. package/dist/recipes/index.js +9 -0
  120. package/dist/recipes/index.js.map +1 -1
  121. package/dist/review.d.ts.map +1 -1
  122. package/dist/review.js +4 -0
  123. package/dist/review.js.map +1 -1
  124. package/dist/rule-explain.d.ts +26 -0
  125. package/dist/rule-explain.d.ts.map +1 -0
  126. package/dist/rule-explain.js +49 -0
  127. package/dist/rule-explain.js.map +1 -0
  128. package/dist/rules/codes.d.ts +4 -0
  129. package/dist/rules/codes.d.ts.map +1 -1
  130. package/dist/rules/codes.js +4 -0
  131. package/dist/rules/codes.js.map +1 -1
  132. package/dist/rules/contract-visibility.d.ts.map +1 -1
  133. package/dist/rules/contract-visibility.js +93 -21
  134. package/dist/rules/contract-visibility.js.map +1 -1
  135. package/dist/rules/explanations.d.ts +14 -0
  136. package/dist/rules/explanations.d.ts.map +1 -0
  137. package/dist/rules/explanations.js +326 -0
  138. package/dist/rules/explanations.js.map +1 -0
  139. package/dist/rules/legacy.d.ts.map +1 -1
  140. package/dist/rules/legacy.js +24 -1
  141. package/dist/rules/legacy.js.map +1 -1
  142. package/dist/rules/merge-auth.d.ts +12 -0
  143. package/dist/rules/merge-auth.d.ts.map +1 -0
  144. package/dist/rules/merge-auth.js +52 -0
  145. package/dist/rules/merge-auth.js.map +1 -0
  146. package/dist/rules/pages.d.ts +51 -0
  147. package/dist/rules/pages.d.ts.map +1 -1
  148. package/dist/rules/pages.js +293 -2
  149. package/dist/rules/pages.js.map +1 -1
  150. package/dist/rules/route-statement.d.ts +10 -0
  151. package/dist/rules/route-statement.d.ts.map +1 -0
  152. package/dist/rules/route-statement.js +150 -0
  153. package/dist/rules/route-statement.js.map +1 -0
  154. package/dist/rules/routes.d.ts +3 -2
  155. package/dist/rules/routes.d.ts.map +1 -1
  156. package/dist/rules/routes.js +4 -3
  157. package/dist/rules/routes.js.map +1 -1
  158. package/dist/rules/zones.d.ts.map +1 -1
  159. package/dist/rules/zones.js +3 -2
  160. package/dist/rules/zones.js.map +1 -1
  161. package/dist/typecheck-coverage.d.ts +11 -0
  162. package/dist/typecheck-coverage.d.ts.map +1 -1
  163. package/dist/typecheck-coverage.js +50 -7
  164. package/dist/typecheck-coverage.js.map +1 -1
  165. package/dist/upgrade.d.ts +80 -11
  166. package/dist/upgrade.d.ts.map +1 -1
  167. package/dist/upgrade.js +332 -65
  168. package/dist/upgrade.js.map +1 -1
  169. package/dist/verification-plan.d.ts.map +1 -1
  170. package/dist/verification-plan.js +2 -0
  171. package/dist/verification-plan.js.map +1 -1
  172. package/dist/version-drift.d.ts.map +1 -1
  173. package/dist/version-drift.js +12 -1
  174. package/dist/version-drift.js.map +1 -1
  175. package/dist/web-app-options.d.ts +1 -1
  176. package/dist/web-app-options.d.ts.map +1 -1
  177. package/dist/web-app-options.js.map +1 -1
  178. package/docs/examples.json +19 -1
  179. package/docs/llms-full.txt +716 -138
  180. package/docs/types.json +516 -74
  181. package/package.json +13 -12
  182. package/src/agent-files.ts +27 -17
  183. package/src/assure-hydration.ts +8 -1
  184. package/src/assure.ts +11 -1
  185. package/src/capabilities-tool.ts +159 -50
  186. package/src/check-diagnostics.ts +10 -0
  187. package/src/check-scan.ts +64 -19
  188. package/src/check.ts +75 -15
  189. package/src/cli.ts +38 -17
  190. package/src/command-catalog.ts +16 -8
  191. package/src/db-tool.ts +2 -0
  192. package/src/dev-bun-config.ts +13 -9
  193. package/src/dev-feed-tool.ts +40 -6
  194. package/src/doctor.ts +102 -66
  195. package/src/env-file.ts +42 -7
  196. package/src/i18n-check.ts +254 -18
  197. package/src/init-agents.ts +221 -41
  198. package/src/internal/project-specifiers.ts +9 -1
  199. package/src/internal/source-facts.ts +397 -0
  200. package/src/internal/workspace-packages.ts +218 -0
  201. package/src/load.ts +19 -3
  202. package/src/lock-links.ts +173 -0
  203. package/src/mcp-exec.ts +18 -4
  204. package/src/mcp-http.ts +1 -1
  205. package/src/mcp-io.ts +72 -12
  206. package/src/mcp-isolate.ts +2 -0
  207. package/src/mcp-root.ts +14 -8
  208. package/src/migrate-layout.ts +496 -31
  209. package/src/project-site.ts +18 -0
  210. package/src/recipes/4.0.0.ts +2 -0
  211. package/src/recipes/5.1.0.ts +23 -0
  212. package/src/recipes/5.2.0.ts +33 -0
  213. package/src/recipes/5.3.0.ts +36 -0
  214. package/src/recipes/index.ts +9 -0
  215. package/src/review.ts +4 -0
  216. package/src/rule-explain.ts +75 -0
  217. package/src/rules/codes.ts +4 -0
  218. package/src/rules/contract-visibility.ts +118 -20
  219. package/src/rules/explanations.ts +339 -0
  220. package/src/rules/legacy.ts +24 -1
  221. package/src/rules/merge-auth.ts +55 -0
  222. package/src/rules/pages.ts +381 -2
  223. package/src/rules/route-statement.ts +170 -0
  224. package/src/rules/routes.ts +4 -3
  225. package/src/rules/zones.ts +3 -2
  226. package/src/typecheck-coverage.ts +51 -6
  227. package/src/upgrade.ts +430 -70
  228. package/src/verification-plan.ts +6 -0
  229. package/src/version-drift.ts +15 -0
  230. package/src/web-app-options.ts +9 -1
@@ -1 +1 @@
1
- {"version":3,"file":"migrate-layout.d.ts","sourceRoot":"","sources":["../src/migrate-layout.ts"],"names":[],"mappings":"AA2CA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAA;AAOrC,OAAO,EAAE,KAAK,iBAAiB,EAAqB,MAAM,qBAAqB,CAAA;AAgE/E,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED,0GAA0G;AAC1G,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,qBAAqB;IACpC,wDAAwD;IACxD,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;IACvB,wGAAwG;IACxG,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,KAAK,CAAA;IAC5B,oEAAoE;IACpE,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;QAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;QACrB,QAAQ,CAAC,OAAO,EA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ACY_SERVER = /\.server(\.(?:[cm]?[jt]sx?|svelte|vue|mdx))$/;
60
60
  const RETIRED_SPECIFIERS = {
61
61
  "@nifrajs/web/server-only": "@nifrajs/web/backend-only",
62
62
  };
63
- /** Scripts and config that name app files by path: scanned for paths that moved, never rewritten. */
63
+ /** Scripts and config that name app files by path: scanned for paths that moved. Only the app's own
64
+ * package.json is rewritten, in the fields `rewritePackagePaths` reads. */
64
65
  const TOOLING_FILE = /(?:\.(?:json|jsonc|ya?ml|toml|sh|bash|zsh|ps1)|(?:^|\/)(?:Dockerfile|Makefile|Procfile))$/;
65
66
  const SELF_LOCATION = /\bimport\.meta\.(?:dirname|dir|filename|url)\b|\b__(?:dirname|filename)\b/;
66
67
  const SKIP_DIRS = new Set(["node_modules", "dist", "build", "coverage", ".git", ".vite", "public"]);
@@ -919,6 +920,101 @@ function importsOf(ts, file, text) {
919
920
  visit(sf);
920
921
  return refs;
921
922
  }
923
+ /** The `import.meta.glob` calls of a JS/TS module. */
924
+ function globCalls(ts, file, text) {
925
+ if (!/\.[cm]?[jt]sx?$/.test(file) || !text.includes("import.meta.glob"))
926
+ return [];
927
+ const sf = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, file.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
928
+ const calls = [];
929
+ const visit = (node) => {
930
+ if (ts.isCallExpression(node) &&
931
+ ts.isPropertyAccessExpression(node.expression) &&
932
+ node.expression.name.text === "glob" &&
933
+ ts.isMetaProperty(node.expression.expression) &&
934
+ // nifra-expect NF-S002: keywordToken is a TypeScript SyntaxKind enum identifying import.meta, never a credential or request value.
935
+ node.expression.expression.keywordToken === ts.SyntaxKind.ImportKeyword) {
936
+ const arg = node.arguments[0];
937
+ const elements = arg === undefined ? [] : ts.isArrayLiteralExpression(arg) ? [...arg.elements] : [arg];
938
+ const literals = elements.filter(ts.isStringLiteralLike);
939
+ const literal = literals.length > 0 && literals.length === elements.length;
940
+ calls.push({
941
+ patterns: literal
942
+ ? literals.map((element) => ({
943
+ text: element.text,
944
+ start: element.getStart(sf) + 1,
945
+ end: element.getEnd() - 1,
946
+ }))
947
+ : [],
948
+ literal,
949
+ line: sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1,
950
+ });
951
+ }
952
+ ts.forEachChild(node, visit);
953
+ };
954
+ visit(sf);
955
+ return calls;
956
+ }
957
+ /** A glob pattern written in `file` as an app-relative glob, by Vite's rules: `./` and `../` from the
958
+ * file's folder, `/` from the app root. `undefined` for any other shape, such as an alias. */
959
+ function appGlob(file, pattern) {
960
+ if (pattern.startsWith("/"))
961
+ return pattern.slice(1);
962
+ if (!pattern.startsWith("./") && !pattern.startsWith("../"))
963
+ return undefined;
964
+ const at = posix.normalize(posix.join(posix.dirname(file), pattern));
965
+ return at.startsWith("../") ? undefined : at;
966
+ }
967
+ /** The files among `files` a glob call in `file` loads, a `!` pattern excluding; `undefined` when a
968
+ * pattern cannot be read from the app. */
969
+ function globTargets(file, patterns, files) {
970
+ const include = [];
971
+ const exclude = [];
972
+ for (const raw of patterns) {
973
+ const at = appGlob(file, raw.startsWith("!") ? raw.slice(1) : raw);
974
+ if (at === undefined)
975
+ return undefined;
976
+ (raw.startsWith("!") ? exclude : include).push(new Bun.Glob(at));
977
+ }
978
+ return [...files].filter((candidate) => candidate !== file &&
979
+ include.some((glob) => glob.match(candidate)) &&
980
+ !exclude.some((glob) => glob.match(candidate)));
981
+ }
982
+ /**
983
+ * `pattern`, written in `from` (now `to`), re-pointed at the folder its matches `before` moved to: the
984
+ * part before the first wildcard is the folder, and every match must keep its path below it.
985
+ * `undefined` when the matches did not move as one folder.
986
+ */
987
+ function repointGlob(from, to, pattern, before, newPath) {
988
+ const negated = pattern.startsWith("!");
989
+ const written = negated ? pattern.slice(1) : pattern;
990
+ const at = appGlob(from, written);
991
+ if (at === undefined)
992
+ return undefined;
993
+ const segments = at.split("/");
994
+ const wild = segments.findIndex((segment) => /[*?[\]{}]/.test(segment));
995
+ const base = (wild === -1 ? segments.slice(0, -1) : segments.slice(0, wild)).join("/");
996
+ const rest = segments.slice(base === "" ? 0 : base.split("/").length).join("/");
997
+ let moved;
998
+ for (const file of before) {
999
+ if (base !== "" && !file.startsWith(`${base}/`))
1000
+ continue;
1001
+ const tail = base === "" ? file : file.slice(base.length + 1);
1002
+ const now = newPath(file);
1003
+ if (!now.endsWith(`/${tail}`) && now !== tail)
1004
+ return undefined;
1005
+ const folder = now === tail ? "" : now.slice(0, now.length - tail.length - 1);
1006
+ if (moved !== undefined && folder !== moved)
1007
+ return undefined;
1008
+ moved = folder;
1009
+ }
1010
+ if (moved === undefined)
1011
+ return pattern;
1012
+ const folder = posix.relative(posix.dirname(to), moved);
1013
+ const next = written.startsWith("/")
1014
+ ? `/${moved === "" ? "" : `${moved}/`}${rest}`
1015
+ : `${folder === "" ? "." : folder.startsWith("..") ? folder : `./${folder}`}/${rest}`;
1016
+ return negated ? `!${next}` : next;
1017
+ }
922
1018
  /** Resolve a relative specifier against the file map, the way a bundler would. */
923
1019
  function resolveIn(files, from, specifier) {
924
1020
  if (!specifier.startsWith("."))
@@ -952,7 +1048,121 @@ function liveSpecifierSpans(ts, file, text, files) {
952
1048
  }
953
1049
  return spans;
954
1050
  }
1051
+ /**
1052
+ * The comment spans of a JS/TS module: the leading and trailing trivia of each token. Empty when the
1053
+ * compiler cannot walk the tokens, so every mention in the file stays an issue.
1054
+ */
1055
+ function triviaCommentRanges(ts, file, text) {
1056
+ const spans = new Map();
1057
+ const add = (ranges) => {
1058
+ for (const range of ranges ?? [])
1059
+ spans.set(range.pos, range.end);
1060
+ };
1061
+ try {
1062
+ const kind = /x$/.test(file) ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
1063
+ const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, kind);
1064
+ const visit = (node) => {
1065
+ // A JSDoc block is itself one of the comments its token's trivia holds; JSX text is not trivia.
1066
+ if (node.kind >= ts.SyntaxKind.FirstJSDocNode && node.kind <= ts.SyntaxKind.LastJSDocNode)
1067
+ return;
1068
+ if (ts.isJsxText(node))
1069
+ return;
1070
+ const children = node.getChildren(source);
1071
+ if (children.length > 0) {
1072
+ for (const child of children)
1073
+ visit(child);
1074
+ return;
1075
+ }
1076
+ add(ts.getLeadingCommentRanges(text, node.pos));
1077
+ add(ts.getTrailingCommentRanges(text, node.end));
1078
+ };
1079
+ visit(source);
1080
+ }
1081
+ catch {
1082
+ return [];
1083
+ }
1084
+ return [...spans];
1085
+ }
955
1086
  const OWN_DIR = new Set(["import.meta.dir", "import.meta.dirname", "__dirname"]);
1087
+ /**
1088
+ * The path `relative` names from the folder of `from`, named from the folder of `to`; `undefined` when
1089
+ * neither the file nor the target moved, so a file that stays keeps its spelling.
1090
+ */
1091
+ function rebaseRelative(from, to, relative, locate) {
1092
+ const before = posix.normalize(posix.join(posix.dirname(from), relative));
1093
+ const target = locate(before);
1094
+ if (from === to && target === before)
1095
+ return undefined;
1096
+ const next = posix.relative(posix.dirname(to), target) || ".";
1097
+ return relative.endsWith("/") && next !== "." ? `${next}/` : next;
1098
+ }
1099
+ /** A shell script's own folder: `$(dirname "$0")`, `$(dirname "${BASH_SOURCE[0]}")`, `${0%/*}`. */
1100
+ const SHELL_OWN_DIR = /\$\(\s*dirname\s+("?)\$(?:0|\{BASH_SOURCE(?:\[0\])?\}|BASH_SOURCE)\1\s*\)|`dirname\s+("?)\$0\2`|\$\{(?:0|BASH_SOURCE(?:\[0\])?)%\/\*\}/g;
1101
+ const SHELL_FILE = /\.(?:sh|bash|zsh)$/;
1102
+ /**
1103
+ * Re-point the paths a shell script moving from `from` to `to` builds from its own folder
1104
+ * (`cd "$(dirname "$0")/.."`), as `rebaseOwnPaths` does for a module. Returns the new text and the
1105
+ * first use of the script's folder with no literal path after it, which the migration cannot follow.
1106
+ */
1107
+ function rebaseShellPaths(from, to, text, locate) {
1108
+ let unfollowed;
1109
+ const edits = [];
1110
+ for (const match of text.matchAll(SHELL_OWN_DIR)) {
1111
+ const start = match.index + match[0].length;
1112
+ const trailing = /^\/([\w.@-]+(?:\/[\w.@-]+)*\/?)/.exec(text.slice(start))?.[1];
1113
+ if (trailing === undefined) {
1114
+ unfollowed ??= match[0];
1115
+ continue;
1116
+ }
1117
+ const rebased = rebaseRelative(from, to, trailing, locate);
1118
+ if (rebased !== undefined)
1119
+ edits.push({ start, end: start + 1 + trailing.length, text: `/${rebased}` });
1120
+ }
1121
+ let next = text;
1122
+ for (const edit of edits.reverse())
1123
+ next = next.slice(0, edit.start) + edit.text + next.slice(edit.end);
1124
+ return { text: next, unfollowed };
1125
+ }
1126
+ /**
1127
+ * Top-level `const dir = import.meta.dir` (or `.dirname`, `__dirname`) bindings, by name. A name the
1128
+ * file declares anywhere else (a parameter, an inner `let`) is left out: a use could be that binding.
1129
+ */
1130
+ function ownDirAliases(ts, sf) {
1131
+ const aliases = new Map();
1132
+ for (const statement of sf.statements) {
1133
+ if (!ts.isVariableStatement(statement))
1134
+ continue;
1135
+ if ((statement.declarationList.flags & ts.NodeFlags.Const) === 0)
1136
+ continue;
1137
+ for (const declaration of statement.declarationList.declarations) {
1138
+ const { name, initializer } = declaration;
1139
+ if (ts.isIdentifier(name) &&
1140
+ initializer !== undefined &&
1141
+ OWN_DIR.has(initializer.getText(sf)))
1142
+ aliases.set(name.text, { name, initializer });
1143
+ }
1144
+ }
1145
+ if (aliases.size === 0)
1146
+ return aliases;
1147
+ const declared = new Map();
1148
+ const count = (node) => {
1149
+ const name = ts.isVariableDeclaration(node) ||
1150
+ ts.isParameter(node) ||
1151
+ ts.isFunctionDeclaration(node) ||
1152
+ ts.isClassDeclaration(node) ||
1153
+ ts.isBindingElement(node)
1154
+ ? node.name
1155
+ : undefined;
1156
+ if (name !== undefined && ts.isIdentifier(name))
1157
+ declared.set(name.text, (declared.get(name.text) ?? 0) + 1);
1158
+ ts.forEachChild(node, count);
1159
+ };
1160
+ count(sf);
1161
+ for (const name of [...aliases.keys()])
1162
+ if (declared.get(name) !== 1)
1163
+ aliases.delete(name);
1164
+ return aliases;
1165
+ }
956
1166
  /**
957
1167
  * Re-point the paths a module moving from `from` to `to` builds from its own location, so each still
958
1168
  * reaches what it did: `join(import.meta.dir, "..", "x")` (or `resolve`), `import.meta.dir + "/../x"`,
@@ -964,22 +1174,15 @@ function rebaseOwnPaths(ts, from, to, text, locate) {
964
1174
  const sf = ts.createSourceFile(to, text, ts.ScriptTarget.Latest, true, to.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
965
1175
  const edits = [];
966
1176
  const followed = [];
967
- const isOwnDir = (node) => node !== undefined && OWN_DIR.has(node.getText(sf));
1177
+ const aliases = ownDirAliases(ts, sf);
1178
+ const isOwnDir = (node) => node !== undefined &&
1179
+ (OWN_DIR.has(node.getText(sf)) || (ts.isIdentifier(node) && aliases.has(node.text)));
968
1180
  const isLiteral = (node) => node !== undefined && (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node));
969
1181
  const quoted = (node, value) => {
970
1182
  const quote = node.getText(sf)[0] ?? '"';
971
1183
  return `${quote}${value}${quote}`;
972
1184
  };
973
- // The path `relative` names from the module's old folder, named from its new folder; `undefined`
974
- // when neither moved, so a module that stays keeps its spelling.
975
- const rebased = (relative) => {
976
- const before = posix.normalize(posix.join(posix.dirname(from), relative));
977
- const target = locate(before);
978
- if (from === to && target === before)
979
- return undefined;
980
- const next = posix.relative(posix.dirname(to), target) || ".";
981
- return relative.endsWith("/") && next !== "." ? `${next}/` : next;
982
- };
1185
+ const rebased = (relative) => rebaseRelative(from, to, relative, locate);
983
1186
  const follow = (anchor, start, end, replacement) => {
984
1187
  followed.push([anchor.getStart(sf), anchor.getEnd()]);
985
1188
  if (replacement !== undefined && text.slice(start, end) !== replacement)
@@ -1040,6 +1243,20 @@ function rebaseOwnPaths(ts, from, to, text, locate) {
1040
1243
  ts.forEachChild(node, visit);
1041
1244
  };
1042
1245
  visit(sf);
1246
+ // An alias whose every use was re-pointed is followed too; one left in a call the migration cannot
1247
+ // read keeps its `import.meta.dir` unfollowed.
1248
+ for (const [name, declaration] of aliases) {
1249
+ const isFollowed = (node) => followed.some(([start, end]) => start <= node.getStart(sf) && node.getEnd() <= end);
1250
+ const uses = [];
1251
+ const collect = (node) => {
1252
+ if (ts.isIdentifier(node) && node.text === name && node !== declaration.name)
1253
+ uses.push(node);
1254
+ ts.forEachChild(node, collect);
1255
+ };
1256
+ collect(sf);
1257
+ if (uses.every(isFollowed))
1258
+ followed.push([declaration.initializer.getStart(sf), declaration.initializer.getEnd()]);
1259
+ }
1043
1260
  const unfollowed = [...text.matchAll(new RegExp(SELF_LOCATION.source, "g"))].find((match) => !followed.some(([start, end]) => start <= match.index && match.index < end))?.[0];
1044
1261
  let next = text;
1045
1262
  for (const edit of edits.sort((a, b) => b.start - a.start))
@@ -1308,18 +1525,24 @@ function workspaceSiblings(root) {
1308
1525
  * Where code in a workspace sibling names an app file that moves: a relative import into the app, or
1309
1526
  * the file's path in a string or command (`bun -e 'import("./src/x.ts")'` with the app as its working
1310
1527
  * directory). Only files that mention the app's folder or package name are read further, and a path
1311
- * the sibling's own package holds is its own file. Report-only: the migration never edits a sibling.
1528
+ * the sibling's own package holds is its own file. Every line that names a path is listed, each marked
1529
+ * when it lies only in a comment. Report-only: the migration never edits a sibling.
1312
1530
  */
1313
1531
  function siblingReferences(ts, root, pkg, file, text, moves, known, ownName) {
1314
1532
  const abs = join(pkg, file);
1315
1533
  // A process started in the app (`cwd: \`${repo}apps/web\``) reads its paths from the app root.
1316
1534
  const runsInApp = new RegExp(`\\bcwd\\s*:[^,\\n]*\\b${escapeRegExp(posix.basename(toPosix(root)))}\\b`).test(text);
1535
+ const comments = /\.[cm]?[jt]sx?$/.test(file) ? triviaCommentRanges(ts, file, text) : [];
1317
1536
  const found = new Map();
1318
- const report = (from, index) => {
1537
+ const report = (from, index, length) => {
1319
1538
  const to = moves.get(from);
1320
- if (to === undefined || found.has(from))
1539
+ if (to === undefined)
1321
1540
  return;
1322
- found.set(from, { from, to, line: text.slice(0, index).split("\n").length });
1541
+ const entry = found.get(from) ?? { to, lines: new Set(), commentLines: new Set() };
1542
+ found.set(from, entry);
1543
+ const line = text.slice(0, index).split("\n").length;
1544
+ const inComment = comments.some(([start, end]) => start <= index && index + length <= end);
1545
+ (inComment ? entry.commentLines : entry.lines).add(line);
1323
1546
  };
1324
1547
  if (/\.(?:[cm]?[jt]sx?)$/.test(file)) {
1325
1548
  for (const { specifier } of importsOf(ts, file, text)) {
@@ -1333,7 +1556,7 @@ function siblingReferences(ts, root, pkg, file, text, moves, known, ownName) {
1333
1556
  continue;
1334
1557
  const target = resolveIn(known, "index.ts", `./${inApp}`);
1335
1558
  if (target !== undefined)
1336
- report(target, text.indexOf(specifier));
1559
+ report(target, text.indexOf(specifier), specifier.length);
1337
1560
  }
1338
1561
  }
1339
1562
  for (const from of moves.keys()) {
@@ -1351,11 +1574,16 @@ function siblingReferences(ts, root, pkg, file, text, moves, known, ownName) {
1351
1574
  const own = existsSync(join(pkg, from)) || existsSync(join(dirname(abs), from));
1352
1575
  if (prefix === "" && own && !runsInApp)
1353
1576
  continue;
1354
- report(from, match.index);
1355
- break;
1577
+ report(from, match.index, match[0].length);
1356
1578
  }
1357
1579
  }
1358
- return [...found.values()];
1580
+ const byNumber = (a, b) => a - b;
1581
+ return [...found].map(([from, { to, lines, commentLines }]) => ({
1582
+ from,
1583
+ to,
1584
+ lines: [...lines].sort(byNumber),
1585
+ commentLines: [...commentLines].filter((line) => !lines.has(line)).sort(byNumber),
1586
+ }));
1359
1587
  }
1360
1588
  /** The package folder an app without its own package.json sits in (`--dir src`), at most two levels
1361
1589
  * up and never a workspace root, so the scan beside it stays inside one package. */
@@ -1830,6 +2058,21 @@ export async function migrateLayout(appRoot, options = {}) {
1830
2058
  });
1831
2059
  }
1832
2060
  }
2061
+ // What a glob loads is imported too: the files it matches go where the module that loads them goes.
2062
+ for (const call of globCalls(ts, file, text)) {
2063
+ const targets = call.literal
2064
+ ? globTargets(file, call.patterns.map((pattern) => pattern.text), known)
2065
+ : undefined;
2066
+ if (targets === undefined) {
2067
+ issues.push({
2068
+ file,
2069
+ reason: `the import.meta.glob on line ${call.line} takes a pattern the migration cannot read (computed, or not starting with ./, ../ or /), so the files it loads stay where they are; check it by hand`,
2070
+ });
2071
+ continue;
2072
+ }
2073
+ for (const target of targets)
2074
+ refs.push({ target, typeOnly: false });
2075
+ }
1833
2076
  edges.set(file, refs);
1834
2077
  }
1835
2078
  // The config's module paths are entries too: the browser loads `clientModule`.
@@ -2123,6 +2366,52 @@ export async function migrateLayout(appRoot, options = {}) {
2123
2366
  (redirectedFiles.has(file) || (updated !== text && original.get(file) === text)))
2124
2367
  rewritten.push(file);
2125
2368
  }
2369
+ // A glob names its files by pattern, which no import rewrite reads: each one must still load, from
2370
+ // the module's new folder, the files it loaded before. A pattern whose matches moved together
2371
+ // into one folder is re-pointed at it; any other change is reported.
2372
+ for (const file of next.keys()) {
2373
+ const at = newPath(file);
2374
+ const text = final.get(at);
2375
+ if (text === undefined)
2376
+ continue;
2377
+ const edits = [];
2378
+ for (const call of globCalls(ts, at, text)) {
2379
+ if (!call.literal)
2380
+ continue;
2381
+ const written = call.patterns.map((pattern) => pattern.text);
2382
+ const before = globTargets(file, written, known);
2383
+ if (before === undefined || before.length === 0)
2384
+ continue;
2385
+ const expected = before.map(newPath).sort(codeUnitOrder);
2386
+ const same = (patterns) => {
2387
+ const after = globTargets(at, patterns, planned)?.sort(codeUnitOrder);
2388
+ return after !== undefined && after.join("\n") === expected.join("\n");
2389
+ };
2390
+ if (same(written))
2391
+ continue;
2392
+ const repointed = written.map((pattern) => repointGlob(file, at, pattern, before, newPath));
2393
+ if (repointed.every((pattern) => pattern !== undefined) && same(repointed)) {
2394
+ call.patterns.forEach((pattern, index) => {
2395
+ const value = repointed[index];
2396
+ if (value !== undefined && value !== pattern.text)
2397
+ edits.push({ start: pattern.start, end: pattern.end, text: value });
2398
+ });
2399
+ continue;
2400
+ }
2401
+ issues.push({
2402
+ file: at,
2403
+ reason: `the import.meta.glob on line ${call.line} loaded ${before.length} file(s) such as "${before[0]}", which do not stay together under one folder after the moves, so its pattern cannot follow them; move them together or point the pattern at them by hand`,
2404
+ });
2405
+ }
2406
+ if (edits.length === 0)
2407
+ 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);
2412
+ if (!moveMap.has(file) && !rewritten.includes(file))
2413
+ rewritten.push(file);
2414
+ }
2126
2415
  // A config string names its module from the app root, so it follows the module, never the config
2127
2416
  // file; a path joined onto the config's folder is re-pointed with the module's own paths below.
2128
2417
  for (const configFile of CONFIG_FILES) {
@@ -2158,7 +2447,18 @@ export async function migrateLayout(appRoot, options = {}) {
2158
2447
  // A moved module's paths from its own location now start from its new folder: re-point the ones it
2159
2448
  // spells out, and report the first one it cannot follow.
2160
2449
  const unfollowed = new Map();
2450
+ /** Moved shell scripts whose own-folder paths were re-pointed: new path -> text. */
2451
+ const scriptWrites = new Map();
2161
2452
  for (const { from, to } of moves) {
2453
+ if (SHELL_FILE.test(to) && !original.has(from)) {
2454
+ const script = readFileSync(join(root, from), "utf8");
2455
+ const result = rebaseShellPaths(from, to, script, (target) => known.has(target) ? newPath(target) : target);
2456
+ if (result.text !== script)
2457
+ scriptWrites.set(to, result.text);
2458
+ if (result.unfollowed !== undefined)
2459
+ unfollowed.set(to, result.unfollowed);
2460
+ continue;
2461
+ }
2162
2462
  const text = final.get(to);
2163
2463
  if (text === undefined || !SELF_LOCATION.test(text))
2164
2464
  continue;
@@ -2196,6 +2496,11 @@ export async function migrateLayout(appRoot, options = {}) {
2196
2496
  .filter((file) => next.has(file) || !original.has(file))
2197
2497
  .map((file) => ({ from: splitFrom.get(file) ?? file, to: newPath(file) }));
2198
2498
  const tsconfigs = followTsconfigs(ts, root, moveMap, layout);
2499
+ // The app's own package.json names files from the app root: its scripts and entry fields follow.
2500
+ const manifestPath = join(root, "package.json");
2501
+ const manifest = existsSync(manifestPath)
2502
+ ? rewritePackagePaths(ts, readFileSync(manifestPath, "utf8"), moveMap)
2503
+ : undefined;
2199
2504
  const scanned = [...final];
2200
2505
  for (const file of everyFile) {
2201
2506
  if (!original.has(file) &&
@@ -2203,17 +2508,22 @@ export async function migrateLayout(appRoot, options = {}) {
2203
2508
  statSync(join(root, file)).size <= 256_000)
2204
2509
  scanned.push([
2205
2510
  newPath(file),
2206
- tsconfigs.files.get(file)?.text ?? readFileSync(join(root, file), "utf8"),
2511
+ (file === "package.json" ? manifest?.text : undefined) ??
2512
+ tsconfigs.files.get(file)?.text ??
2513
+ readFileSync(join(root, file), "utf8"),
2207
2514
  ]);
2208
2515
  }
2516
+ // A mention only in comments is worth updating, not a decision: it never changes what runs.
2517
+ const commentFollowUps = [];
2209
2518
  for (const [file, text] of scanned) {
2210
2519
  let live;
2520
+ let comments;
2211
2521
  for (const [from, to] of moveMap) {
2212
2522
  // `shared/lib/x.ts` contains `lib/x.ts`; that is the new path, not a stale one.
2213
2523
  const newPrefix = to.endsWith(from) ? to.slice(0, to.length - from.length) : undefined;
2214
2524
  const stale = [
2215
2525
  ...text.matchAll(new RegExp(`(?<![\\w.-])${escapeRegExp(from)}(?![\\w])`, "g")),
2216
- ].some((match) => {
2526
+ ].filter((match) => {
2217
2527
  if (newPrefix !== undefined && text.slice(0, match.index).endsWith(newPrefix))
2218
2528
  return false;
2219
2529
  // An import that resolves after the moves is current, even when it still reads like the old
@@ -2222,7 +2532,13 @@ export async function migrateLayout(appRoot, options = {}) {
2222
2532
  const end = match.index + from.length;
2223
2533
  return !live.some(([start, stop]) => start <= match.index && end <= stop);
2224
2534
  });
2225
- if (stale)
2535
+ if (stale.length === 0)
2536
+ continue;
2537
+ comments ??= /\.[cm]?[jt]sx?$/.test(file) ? triviaCommentRanges(ts, file, text) : [];
2538
+ const inComments = stale.every((match) => comments?.some(([start, stop]) => start <= match.index && match.index + from.length <= stop));
2539
+ if (inComments)
2540
+ commentFollowUps.push({ file, reason: `a comment names "${from}", which moved to "${to}"` });
2541
+ else
2226
2542
  issues.push({ file, reason: `mentions "${from}" by path; it moved to "${to}"` });
2227
2543
  }
2228
2544
  }
@@ -2273,11 +2589,19 @@ export async function migrateLayout(appRoot, options = {}) {
2273
2589
  if (!mentionsApp.test(text) && (ownName === undefined || !text.includes(`${ownName}/`)))
2274
2590
  continue;
2275
2591
  const at = toPosix(relative(root, join(sibling, file)));
2276
- for (const { from, to, line } of siblingReferences(ts, root, sibling, file, text, moveMap, known, ownName)) {
2277
- issues.push({
2278
- file: at,
2279
- reason: `names "${from}" on line ${line}, and it moves to "${to}" - it is outside the app, so the migration does not rewrite it`,
2280
- });
2592
+ const onLines = (lines) => `on line${lines.length === 1 ? "" : "s"} ${lines.join(", ")}`;
2593
+ for (const { from, to, lines, commentLines } of siblingReferences(ts, root, sibling, file, text, moveMap, known, ownName)) {
2594
+ const comments = commentLines.length === 0 ? "" : ` (and in a comment ${onLines(commentLines)})`;
2595
+ if (lines.length > 0)
2596
+ issues.push({
2597
+ file: at,
2598
+ reason: `names "${from}" ${onLines(lines)}${comments}, and it moves to "${to}" - it is outside the app, so the migration does not rewrite it`,
2599
+ });
2600
+ else
2601
+ commentFollowUps.push({
2602
+ file: at,
2603
+ reason: `a comment ${onLines(commentLines)} names "${from}", which moved to "${to}"`,
2604
+ });
2281
2605
  }
2282
2606
  }
2283
2607
  }
@@ -2329,7 +2653,7 @@ export async function migrateLayout(appRoot, options = {}) {
2329
2653
  for (const [file, text] of schemaPlan?.edits ?? [])
2330
2654
  final.set(file, text);
2331
2655
  const schemas = (schemaPlan?.entries ?? []).filter((entry) => entry.status === "missing");
2332
- const followUps = [];
2656
+ const followUps = [...commentFollowUps];
2333
2657
  for (const [file, text] of final) {
2334
2658
  if (!file.startsWith("routes/") || !/\.backend\.[cm]?[jt]s$/.test(file))
2335
2659
  continue;
@@ -2410,6 +2734,14 @@ export async function migrateLayout(appRoot, options = {}) {
2410
2734
  toolingWrites.set("package.json", kind.text);
2411
2735
  tooling.push({ file: "package.json", change: '"nifra": { "kind": "api" }' });
2412
2736
  }
2737
+ if (manifest !== undefined && manifest.count > 0) {
2738
+ const current = toolingWrites.get("package.json") ?? readFileSync(manifestPath, "utf8");
2739
+ toolingWrites.set("package.json", rewritePackagePaths(ts, current, moveMap).text);
2740
+ tooling.push({
2741
+ file: "package.json",
2742
+ change: `${manifest.count} file path(s) in scripts and entry fields follow their moved files`,
2743
+ });
2744
+ }
2413
2745
  if (options.write === true) {
2414
2746
  for (const [file, text] of toolingWrites)
2415
2747
  writeFileSync(join(root, file), text);
@@ -2434,6 +2766,8 @@ export async function migrateLayout(appRoot, options = {}) {
2434
2766
  renameSync(join(root, from), join(root, to));
2435
2767
  vacated.push(from);
2436
2768
  }
2769
+ for (const [file, text] of scriptWrites)
2770
+ writeFileSync(join(root, file), text);
2437
2771
  pruneVacatedDirs(root, vacated);
2438
2772
  }
2439
2773
  return {
@@ -2894,6 +3228,78 @@ function declareApiKind(ts, root) {
2894
3228
  return { issue: '"nifra" is not an object; add "kind": "api" to it by hand' };
2895
3229
  return { text: insertProperty(source, text, nifra.initializer, '"kind": "api"') };
2896
3230
  }
3231
+ /** package.json fields whose string values name files from the package folder. */
3232
+ const PACKAGE_PATH_FIELDS = new Set([
3233
+ "main",
3234
+ "module",
3235
+ "types",
3236
+ "typings",
3237
+ "browser",
3238
+ "source",
3239
+ "bin",
3240
+ "exports",
3241
+ "imports",
3242
+ "files",
3243
+ "scripts",
3244
+ ]);
3245
+ /**
3246
+ * `text` (a package.json at the app root) with each moved file it names by its exact path, in the
3247
+ * fields above, named at its new path; `./` kept as written. A value with a `*` outside `scripts` is a
3248
+ * pattern over a folder, which no single move settles, so it stays and the path scan reports it.
3249
+ */
3250
+ function rewritePackagePaths(ts, text, moves) {
3251
+ const source = ts.parseJsonText("package.json", text);
3252
+ const top = source.statements[0]?.expression;
3253
+ if (top === undefined || !ts.isObjectLiteralExpression(top) || moves.size === 0)
3254
+ return { text, count: 0 };
3255
+ // Longest first, so `lib/a.test.ts` is not read as `lib/a.ts` with a tail.
3256
+ const ordered = [...moves].sort(([a], [b]) => b.length - a.length);
3257
+ const pattern = new RegExp(`(?<![\\w.@/-])(\\./)?(${ordered.map(([from]) => escapeRegExp(from)).join("|")})(?![\\w/-]|\\.\\w)`, "g");
3258
+ const edits = [];
3259
+ let count = 0;
3260
+ const visit = (node, field) => {
3261
+ if (ts.isStringLiteral(node)) {
3262
+ if (field !== "scripts" && node.text.includes("*"))
3263
+ return;
3264
+ const value = node.text.replace(pattern, (_match, dot, from) => {
3265
+ count += 1;
3266
+ return `${dot ?? ""}${moves.get(from) ?? from}`;
3267
+ });
3268
+ if (value !== node.text)
3269
+ edits.push({
3270
+ start: node.getStart(source),
3271
+ end: node.getEnd(),
3272
+ text: JSON.stringify(value),
3273
+ });
3274
+ return;
3275
+ }
3276
+ if (ts.isArrayLiteralExpression(node)) {
3277
+ for (const element of node.elements)
3278
+ visit(element, field);
3279
+ return;
3280
+ }
3281
+ if (!ts.isObjectLiteralExpression(node))
3282
+ return;
3283
+ for (const property of node.properties) {
3284
+ if (!ts.isPropertyAssignment(property))
3285
+ continue;
3286
+ // `"//x"` keys are comments by npm convention.
3287
+ if (ts.isStringLiteral(property.name) && property.name.text.startsWith("//"))
3288
+ continue;
3289
+ visit(property.initializer, field);
3290
+ }
3291
+ };
3292
+ for (const property of top.properties) {
3293
+ if (!ts.isPropertyAssignment(property) || !ts.isStringLiteral(property.name))
3294
+ continue;
3295
+ if (PACKAGE_PATH_FIELDS.has(property.name.text))
3296
+ visit(property.initializer, property.name.text);
3297
+ }
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 };
3302
+ }
2897
3303
  /** Tailwind `content` globs that matched a moved file at its old path and match nothing at its new one. */
2898
3304
  function staleContentGlobs(ts, text, moves) {
2899
3305
  const globs = [];