@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
@@ -74,7 +74,8 @@ const LEGACY_SERVER = /\.server(\.(?:[cm]?[jt]sx?|svelte|vue|mdx))$/
74
74
  const RETIRED_SPECIFIERS: Readonly<Record<string, string>> = {
75
75
  "@nifrajs/web/server-only": "@nifrajs/web/backend-only",
76
76
  }
77
- /** Scripts and config that name app files by path: scanned for paths that moved, never rewritten. */
77
+ /** Scripts and config that name app files by path: scanned for paths that moved. Only the app's own
78
+ * package.json is rewritten, in the fields `rewritePackagePaths` reads. */
78
79
  const TOOLING_FILE =
79
80
  /(?:\.(?:json|jsonc|ya?ml|toml|sh|bash|zsh|ps1)|(?:^|\/)(?:Dockerfile|Makefile|Procfile))$/
80
81
  const SELF_LOCATION = /\bimport\.meta\.(?:dirname|dir|filename|url)\b|\b__(?:dirname|filename)\b/
@@ -121,7 +122,8 @@ export interface LayoutMigrationIssue {
121
122
  export interface LayoutMigrationFollowUp {
122
123
  readonly file: string
123
124
  readonly reason: string
124
- readonly command: string
125
+ /** The command that settles it; absent when the step is an edit, such as a comment to update. */
126
+ readonly command?: string
125
127
  }
126
128
 
127
129
  export interface LayoutMigrationResult {
@@ -1134,6 +1136,130 @@ function importsOf(ts: typeof TS, file: string, text: string): ImportRef[] {
1134
1136
  return refs
1135
1137
  }
1136
1138
 
1139
+ /** One `import.meta.glob(...)` call and the spans of its pattern literals, quotes excluded. */
1140
+ interface GlobCall {
1141
+ readonly patterns: ReadonlyArray<{
1142
+ readonly text: string
1143
+ readonly start: number
1144
+ readonly end: number
1145
+ }>
1146
+ /** `false` when a pattern is computed, so what the call loads cannot be read. */
1147
+ readonly literal: boolean
1148
+ readonly line: number
1149
+ }
1150
+
1151
+ /** The `import.meta.glob` calls of a JS/TS module. */
1152
+ function globCalls(ts: typeof TS, file: string, text: string): GlobCall[] {
1153
+ if (!/\.[cm]?[jt]sx?$/.test(file) || !text.includes("import.meta.glob")) return []
1154
+ const sf = ts.createSourceFile(
1155
+ file,
1156
+ text,
1157
+ ts.ScriptTarget.Latest,
1158
+ true,
1159
+ file.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS,
1160
+ )
1161
+ const calls: GlobCall[] = []
1162
+ const visit = (node: TS.Node): void => {
1163
+ if (
1164
+ ts.isCallExpression(node) &&
1165
+ ts.isPropertyAccessExpression(node.expression) &&
1166
+ node.expression.name.text === "glob" &&
1167
+ ts.isMetaProperty(node.expression.expression) &&
1168
+ // nifra-expect NF-S002: keywordToken is a TypeScript SyntaxKind enum identifying import.meta, never a credential or request value.
1169
+ node.expression.expression.keywordToken === ts.SyntaxKind.ImportKeyword
1170
+ ) {
1171
+ const arg = node.arguments[0]
1172
+ const elements =
1173
+ arg === undefined ? [] : ts.isArrayLiteralExpression(arg) ? [...arg.elements] : [arg]
1174
+ const literals = elements.filter(ts.isStringLiteralLike)
1175
+ const literal = literals.length > 0 && literals.length === elements.length
1176
+ calls.push({
1177
+ patterns: literal
1178
+ ? literals.map((element) => ({
1179
+ text: element.text,
1180
+ start: element.getStart(sf) + 1,
1181
+ end: element.getEnd() - 1,
1182
+ }))
1183
+ : [],
1184
+ literal,
1185
+ line: sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1,
1186
+ })
1187
+ }
1188
+ ts.forEachChild(node, visit)
1189
+ }
1190
+ visit(sf)
1191
+ return calls
1192
+ }
1193
+
1194
+ /** A glob pattern written in `file` as an app-relative glob, by Vite's rules: `./` and `../` from the
1195
+ * file's folder, `/` from the app root. `undefined` for any other shape, such as an alias. */
1196
+ function appGlob(file: string, pattern: string): string | undefined {
1197
+ if (pattern.startsWith("/")) return pattern.slice(1)
1198
+ if (!pattern.startsWith("./") && !pattern.startsWith("../")) return undefined
1199
+ const at = posix.normalize(posix.join(posix.dirname(file), pattern))
1200
+ return at.startsWith("../") ? undefined : at
1201
+ }
1202
+
1203
+ /** The files among `files` a glob call in `file` loads, a `!` pattern excluding; `undefined` when a
1204
+ * pattern cannot be read from the app. */
1205
+ function globTargets(
1206
+ file: string,
1207
+ patterns: readonly string[],
1208
+ files: Iterable<string>,
1209
+ ): string[] | undefined {
1210
+ const include: Bun.Glob[] = []
1211
+ const exclude: Bun.Glob[] = []
1212
+ for (const raw of patterns) {
1213
+ const at = appGlob(file, raw.startsWith("!") ? raw.slice(1) : raw)
1214
+ if (at === undefined) return undefined
1215
+ ;(raw.startsWith("!") ? exclude : include).push(new Bun.Glob(at))
1216
+ }
1217
+ return [...files].filter(
1218
+ (candidate) =>
1219
+ candidate !== file &&
1220
+ include.some((glob) => glob.match(candidate)) &&
1221
+ !exclude.some((glob) => glob.match(candidate)),
1222
+ )
1223
+ }
1224
+
1225
+ /**
1226
+ * `pattern`, written in `from` (now `to`), re-pointed at the folder its matches `before` moved to: the
1227
+ * part before the first wildcard is the folder, and every match must keep its path below it.
1228
+ * `undefined` when the matches did not move as one folder.
1229
+ */
1230
+ function repointGlob(
1231
+ from: string,
1232
+ to: string,
1233
+ pattern: string,
1234
+ before: readonly string[],
1235
+ newPath: (file: string) => string,
1236
+ ): string | undefined {
1237
+ const negated = pattern.startsWith("!")
1238
+ const written = negated ? pattern.slice(1) : pattern
1239
+ const at = appGlob(from, written)
1240
+ if (at === undefined) return undefined
1241
+ const segments = at.split("/")
1242
+ const wild = segments.findIndex((segment) => /[*?[\]{}]/.test(segment))
1243
+ const base = (wild === -1 ? segments.slice(0, -1) : segments.slice(0, wild)).join("/")
1244
+ const rest = segments.slice(base === "" ? 0 : base.split("/").length).join("/")
1245
+ let moved: string | undefined
1246
+ for (const file of before) {
1247
+ if (base !== "" && !file.startsWith(`${base}/`)) continue
1248
+ const tail = base === "" ? file : file.slice(base.length + 1)
1249
+ const now = newPath(file)
1250
+ if (!now.endsWith(`/${tail}`) && now !== tail) return undefined
1251
+ const folder = now === tail ? "" : now.slice(0, now.length - tail.length - 1)
1252
+ if (moved !== undefined && folder !== moved) return undefined
1253
+ moved = folder
1254
+ }
1255
+ if (moved === undefined) return pattern
1256
+ const folder = posix.relative(posix.dirname(to), moved)
1257
+ const next = written.startsWith("/")
1258
+ ? `/${moved === "" ? "" : `${moved}/`}${rest}`
1259
+ : `${folder === "" ? "." : folder.startsWith("..") ? folder : `./${folder}`}/${rest}`
1260
+ return negated ? `!${next}` : next
1261
+ }
1262
+
1137
1263
  /** Resolve a relative specifier against the file map, the way a bundler would. */
1138
1264
  function resolveIn(
1139
1265
  files: ReadonlySet<string>,
@@ -1176,8 +1302,140 @@ function liveSpecifierSpans(
1176
1302
  return spans
1177
1303
  }
1178
1304
 
1305
+ /**
1306
+ * The comment spans of a JS/TS module: the leading and trailing trivia of each token. Empty when the
1307
+ * compiler cannot walk the tokens, so every mention in the file stays an issue.
1308
+ */
1309
+ function triviaCommentRanges(
1310
+ ts: typeof TS,
1311
+ file: string,
1312
+ text: string,
1313
+ ): Array<readonly [number, number]> {
1314
+ const spans = new Map<number, number>()
1315
+ const add = (ranges: readonly TS.CommentRange[] | undefined): void => {
1316
+ for (const range of ranges ?? []) spans.set(range.pos, range.end)
1317
+ }
1318
+ try {
1319
+ const kind = /x$/.test(file) ? ts.ScriptKind.TSX : ts.ScriptKind.TS
1320
+ const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, kind)
1321
+ const visit = (node: TS.Node): void => {
1322
+ // A JSDoc block is itself one of the comments its token's trivia holds; JSX text is not trivia.
1323
+ if (node.kind >= ts.SyntaxKind.FirstJSDocNode && node.kind <= ts.SyntaxKind.LastJSDocNode)
1324
+ return
1325
+ if (ts.isJsxText(node)) return
1326
+ const children = node.getChildren(source)
1327
+ if (children.length > 0) {
1328
+ for (const child of children) visit(child)
1329
+ return
1330
+ }
1331
+ add(ts.getLeadingCommentRanges(text, node.pos))
1332
+ add(ts.getTrailingCommentRanges(text, node.end))
1333
+ }
1334
+ visit(source)
1335
+ } catch {
1336
+ return []
1337
+ }
1338
+ return [...spans]
1339
+ }
1340
+
1179
1341
  const OWN_DIR = new Set(["import.meta.dir", "import.meta.dirname", "__dirname"])
1180
1342
 
1343
+ /**
1344
+ * The path `relative` names from the folder of `from`, named from the folder of `to`; `undefined` when
1345
+ * neither the file nor the target moved, so a file that stays keeps its spelling.
1346
+ */
1347
+ function rebaseRelative(
1348
+ from: string,
1349
+ to: string,
1350
+ relative: string,
1351
+ locate: (target: string) => string,
1352
+ ): string | undefined {
1353
+ const before = posix.normalize(posix.join(posix.dirname(from), relative))
1354
+ const target = locate(before)
1355
+ if (from === to && target === before) return undefined
1356
+ const next = posix.relative(posix.dirname(to), target) || "."
1357
+ return relative.endsWith("/") && next !== "." ? `${next}/` : next
1358
+ }
1359
+
1360
+ /** A shell script's own folder: `$(dirname "$0")`, `$(dirname "${BASH_SOURCE[0]}")`, `${0%/*}`. */
1361
+ const SHELL_OWN_DIR =
1362
+ /\$\(\s*dirname\s+("?)\$(?:0|\{BASH_SOURCE(?:\[0\])?\}|BASH_SOURCE)\1\s*\)|`dirname\s+("?)\$0\2`|\$\{(?:0|BASH_SOURCE(?:\[0\])?)%\/\*\}/g
1363
+ const SHELL_FILE = /\.(?:sh|bash|zsh)$/
1364
+
1365
+ /**
1366
+ * Re-point the paths a shell script moving from `from` to `to` builds from its own folder
1367
+ * (`cd "$(dirname "$0")/.."`), as `rebaseOwnPaths` does for a module. Returns the new text and the
1368
+ * first use of the script's folder with no literal path after it, which the migration cannot follow.
1369
+ */
1370
+ function rebaseShellPaths(
1371
+ from: string,
1372
+ to: string,
1373
+ text: string,
1374
+ locate: (target: string) => string,
1375
+ ): { readonly text: string; readonly unfollowed: string | undefined } {
1376
+ let unfollowed: string | undefined
1377
+ const edits: Array<{ start: number; end: number; text: string }> = []
1378
+ for (const match of text.matchAll(SHELL_OWN_DIR)) {
1379
+ const start = match.index + match[0].length
1380
+ const trailing = /^\/([\w.@-]+(?:\/[\w.@-]+)*\/?)/.exec(text.slice(start))?.[1]
1381
+ if (trailing === undefined) {
1382
+ unfollowed ??= match[0]
1383
+ continue
1384
+ }
1385
+ const rebased = rebaseRelative(from, to, trailing, locate)
1386
+ if (rebased !== undefined)
1387
+ edits.push({ start, end: start + 1 + trailing.length, text: `/${rebased}` })
1388
+ }
1389
+ let next = text
1390
+ for (const edit of edits.reverse())
1391
+ next = next.slice(0, edit.start) + edit.text + next.slice(edit.end)
1392
+ return { text: next, unfollowed }
1393
+ }
1394
+
1395
+ interface OwnDirAlias {
1396
+ readonly name: TS.Identifier
1397
+ readonly initializer: TS.Expression
1398
+ }
1399
+
1400
+ /**
1401
+ * Top-level `const dir = import.meta.dir` (or `.dirname`, `__dirname`) bindings, by name. A name the
1402
+ * file declares anywhere else (a parameter, an inner `let`) is left out: a use could be that binding.
1403
+ */
1404
+ function ownDirAliases(ts: typeof TS, sf: TS.SourceFile): Map<string, OwnDirAlias> {
1405
+ const aliases = new Map<string, OwnDirAlias>()
1406
+ for (const statement of sf.statements) {
1407
+ if (!ts.isVariableStatement(statement)) continue
1408
+ if ((statement.declarationList.flags & ts.NodeFlags.Const) === 0) continue
1409
+ for (const declaration of statement.declarationList.declarations) {
1410
+ const { name, initializer } = declaration
1411
+ if (
1412
+ ts.isIdentifier(name) &&
1413
+ initializer !== undefined &&
1414
+ OWN_DIR.has(initializer.getText(sf))
1415
+ )
1416
+ aliases.set(name.text, { name, initializer })
1417
+ }
1418
+ }
1419
+ if (aliases.size === 0) return aliases
1420
+ const declared = new Map<string, number>()
1421
+ const count = (node: TS.Node): void => {
1422
+ const name =
1423
+ ts.isVariableDeclaration(node) ||
1424
+ ts.isParameter(node) ||
1425
+ ts.isFunctionDeclaration(node) ||
1426
+ ts.isClassDeclaration(node) ||
1427
+ ts.isBindingElement(node)
1428
+ ? node.name
1429
+ : undefined
1430
+ if (name !== undefined && ts.isIdentifier(name))
1431
+ declared.set(name.text, (declared.get(name.text) ?? 0) + 1)
1432
+ ts.forEachChild(node, count)
1433
+ }
1434
+ count(sf)
1435
+ for (const name of [...aliases.keys()]) if (declared.get(name) !== 1) aliases.delete(name)
1436
+ return aliases
1437
+ }
1438
+
1181
1439
  /**
1182
1440
  * Re-point the paths a module moving from `from` to `to` builds from its own location, so each still
1183
1441
  * reaches what it did: `join(import.meta.dir, "..", "x")` (or `resolve`), `import.meta.dir + "/../x"`,
@@ -1201,8 +1459,10 @@ function rebaseOwnPaths(
1201
1459
  )
1202
1460
  const edits: Array<{ start: number; end: number; text: string }> = []
1203
1461
  const followed: Array<readonly [number, number]> = []
1462
+ const aliases = ownDirAliases(ts, sf)
1204
1463
  const isOwnDir = (node: TS.Node | undefined): node is TS.Expression =>
1205
- node !== undefined && OWN_DIR.has(node.getText(sf))
1464
+ node !== undefined &&
1465
+ (OWN_DIR.has(node.getText(sf)) || (ts.isIdentifier(node) && aliases.has(node.text)))
1206
1466
  const isLiteral = (
1207
1467
  node: TS.Node | undefined,
1208
1468
  ): node is TS.StringLiteral | TS.NoSubstitutionTemplateLiteral =>
@@ -1211,15 +1471,8 @@ function rebaseOwnPaths(
1211
1471
  const quote = node.getText(sf)[0] ?? '"'
1212
1472
  return `${quote}${value}${quote}`
1213
1473
  }
1214
- // The path `relative` names from the module's old folder, named from its new folder; `undefined`
1215
- // when neither moved, so a module that stays keeps its spelling.
1216
- const rebased = (relative: string): string | undefined => {
1217
- const before = posix.normalize(posix.join(posix.dirname(from), relative))
1218
- const target = locate(before)
1219
- if (from === to && target === before) return undefined
1220
- const next = posix.relative(posix.dirname(to), target) || "."
1221
- return relative.endsWith("/") && next !== "." ? `${next}/` : next
1222
- }
1474
+ const rebased = (relative: string): string | undefined =>
1475
+ rebaseRelative(from, to, relative, locate)
1223
1476
  const follow = (
1224
1477
  anchor: TS.Node,
1225
1478
  start: number,
@@ -1300,6 +1553,20 @@ function rebaseOwnPaths(
1300
1553
  ts.forEachChild(node, visit)
1301
1554
  }
1302
1555
  visit(sf)
1556
+ // An alias whose every use was re-pointed is followed too; one left in a call the migration cannot
1557
+ // read keeps its `import.meta.dir` unfollowed.
1558
+ for (const [name, declaration] of aliases) {
1559
+ const isFollowed = (node: TS.Node): boolean =>
1560
+ followed.some(([start, end]) => start <= node.getStart(sf) && node.getEnd() <= end)
1561
+ const uses: TS.Identifier[] = []
1562
+ const collect = (node: TS.Node): void => {
1563
+ if (ts.isIdentifier(node) && node.text === name && node !== declaration.name) uses.push(node)
1564
+ ts.forEachChild(node, collect)
1565
+ }
1566
+ collect(sf)
1567
+ if (uses.every(isFollowed))
1568
+ followed.push([declaration.initializer.getStart(sf), declaration.initializer.getEnd()])
1569
+ }
1303
1570
 
1304
1571
  const unfollowed = [...text.matchAll(new RegExp(SELF_LOCATION.source, "g"))].find(
1305
1572
  (match) => !followed.some(([start, end]) => start <= match.index && match.index < end),
@@ -1623,7 +1890,8 @@ function workspaceSiblings(root: string): readonly string[] | undefined {
1623
1890
  * Where code in a workspace sibling names an app file that moves: a relative import into the app, or
1624
1891
  * the file's path in a string or command (`bun -e 'import("./src/x.ts")'` with the app as its working
1625
1892
  * directory). Only files that mention the app's folder or package name are read further, and a path
1626
- * the sibling's own package holds is its own file. Report-only: the migration never edits a sibling.
1893
+ * the sibling's own package holds is its own file. Every line that names a path is listed, each marked
1894
+ * when it lies only in a comment. Report-only: the migration never edits a sibling.
1627
1895
  */
1628
1896
  function siblingReferences(
1629
1897
  ts: typeof TS,
@@ -1634,17 +1902,27 @@ function siblingReferences(
1634
1902
  moves: ReadonlyMap<string, string>,
1635
1903
  known: ReadonlySet<string>,
1636
1904
  ownName: string | undefined,
1637
- ): Array<{ readonly from: string; readonly to: string; readonly line: number }> {
1905
+ ): Array<{
1906
+ readonly from: string
1907
+ readonly to: string
1908
+ readonly lines: readonly number[]
1909
+ readonly commentLines: readonly number[]
1910
+ }> {
1638
1911
  const abs = join(pkg, file)
1639
1912
  // A process started in the app (`cwd: \`${repo}apps/web\``) reads its paths from the app root.
1640
1913
  const runsInApp = new RegExp(
1641
1914
  `\\bcwd\\s*:[^,\\n]*\\b${escapeRegExp(posix.basename(toPosix(root)))}\\b`,
1642
1915
  ).test(text)
1643
- const found = new Map<string, { from: string; to: string; line: number }>()
1644
- const report = (from: string, index: number): void => {
1916
+ const comments = /\.[cm]?[jt]sx?$/.test(file) ? triviaCommentRanges(ts, file, text) : []
1917
+ const found = new Map<string, { to: string; lines: Set<number>; commentLines: Set<number> }>()
1918
+ const report = (from: string, index: number, length: number): void => {
1645
1919
  const to = moves.get(from)
1646
- if (to === undefined || found.has(from)) return
1647
- found.set(from, { from, to, line: text.slice(0, index).split("\n").length })
1920
+ if (to === undefined) return
1921
+ const entry = found.get(from) ?? { to, lines: new Set(), commentLines: new Set() }
1922
+ found.set(from, entry)
1923
+ const line = text.slice(0, index).split("\n").length
1924
+ const inComment = comments.some(([start, end]) => start <= index && index + length <= end)
1925
+ ;(inComment ? entry.commentLines : entry.lines).add(line)
1648
1926
  }
1649
1927
  if (/\.(?:[cm]?[jt]sx?)$/.test(file)) {
1650
1928
  for (const { specifier } of importsOf(ts, file, text)) {
@@ -1656,7 +1934,7 @@ function siblingReferences(
1656
1934
  : undefined
1657
1935
  if (inApp === undefined || inApp.startsWith("../") || isAbsolute(inApp)) continue
1658
1936
  const target = resolveIn(known, "index.ts", `./${inApp}`)
1659
- if (target !== undefined) report(target, text.indexOf(specifier))
1937
+ if (target !== undefined) report(target, text.indexOf(specifier), specifier.length)
1660
1938
  }
1661
1939
  }
1662
1940
  for (const from of moves.keys()) {
@@ -1675,11 +1953,16 @@ function siblingReferences(
1675
1953
  if (prefix !== "" && !bases.some((base) => resolve(base, prefix) === root)) continue
1676
1954
  const own = existsSync(join(pkg, from)) || existsSync(join(dirname(abs), from))
1677
1955
  if (prefix === "" && own && !runsInApp) continue
1678
- report(from, match.index)
1679
- break
1956
+ report(from, match.index, match[0].length)
1680
1957
  }
1681
1958
  }
1682
- return [...found.values()]
1959
+ const byNumber = (a: number, b: number): number => a - b
1960
+ return [...found].map(([from, { to, lines, commentLines }]) => ({
1961
+ from,
1962
+ to,
1963
+ lines: [...lines].sort(byNumber),
1964
+ commentLines: [...commentLines].filter((line) => !lines.has(line)).sort(byNumber),
1965
+ }))
1683
1966
  }
1684
1967
 
1685
1968
  /** The package folder an app without its own package.json sits in (`--dir src`), at most two levels
@@ -2201,6 +2484,24 @@ export async function migrateLayout(
2201
2484
  })
2202
2485
  }
2203
2486
  }
2487
+ // What a glob loads is imported too: the files it matches go where the module that loads them goes.
2488
+ for (const call of globCalls(ts, file, text)) {
2489
+ const targets = call.literal
2490
+ ? globTargets(
2491
+ file,
2492
+ call.patterns.map((pattern) => pattern.text),
2493
+ known,
2494
+ )
2495
+ : undefined
2496
+ if (targets === undefined) {
2497
+ issues.push({
2498
+ file,
2499
+ 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`,
2500
+ })
2501
+ continue
2502
+ }
2503
+ for (const target of targets) refs.push({ target, typeOnly: false })
2504
+ }
2204
2505
  edges.set(file, refs)
2205
2506
  }
2206
2507
  // The config's module paths are entries too: the browser loads `clientModule`.
@@ -2513,6 +2814,47 @@ export async function migrateLayout(
2513
2814
  rewritten.push(file)
2514
2815
  }
2515
2816
 
2817
+ // A glob names its files by pattern, which no import rewrite reads: each one must still load, from
2818
+ // the module's new folder, the files it loaded before. A pattern whose matches moved together
2819
+ // into one folder is re-pointed at it; any other change is reported.
2820
+ for (const file of next.keys()) {
2821
+ const at = newPath(file)
2822
+ const text = final.get(at)
2823
+ if (text === undefined) continue
2824
+ const edits: Array<{ start: number; end: number; text: string }> = []
2825
+ for (const call of globCalls(ts, at, text)) {
2826
+ if (!call.literal) continue
2827
+ const written = call.patterns.map((pattern) => pattern.text)
2828
+ const before = globTargets(file, written, known)
2829
+ if (before === undefined || before.length === 0) continue
2830
+ const expected = before.map(newPath).sort(codeUnitOrder)
2831
+ const same = (patterns: readonly string[]): boolean => {
2832
+ const after = globTargets(at, patterns, planned)?.sort(codeUnitOrder)
2833
+ return after !== undefined && after.join("\n") === expected.join("\n")
2834
+ }
2835
+ if (same(written)) continue
2836
+ const repointed = written.map((pattern) => repointGlob(file, at, pattern, before, newPath))
2837
+ if (repointed.every((pattern) => pattern !== undefined) && same(repointed)) {
2838
+ call.patterns.forEach((pattern, index) => {
2839
+ const value = repointed[index]
2840
+ if (value !== undefined && value !== pattern.text)
2841
+ edits.push({ start: pattern.start, end: pattern.end, text: value })
2842
+ })
2843
+ continue
2844
+ }
2845
+ issues.push({
2846
+ file: at,
2847
+ 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`,
2848
+ })
2849
+ }
2850
+ if (edits.length === 0) continue
2851
+ let updated = text
2852
+ for (const edit of edits.sort((a, b) => b.start - a.start))
2853
+ updated = updated.slice(0, edit.start) + edit.text + updated.slice(edit.end)
2854
+ final.set(at, updated)
2855
+ if (!moveMap.has(file) && !rewritten.includes(file)) rewritten.push(file)
2856
+ }
2857
+
2516
2858
  // A config string names its module from the app root, so it follows the module, never the config
2517
2859
  // file; a path joined onto the config's folder is re-pointed with the module's own paths below.
2518
2860
  for (const configFile of CONFIG_FILES) {
@@ -2544,7 +2886,18 @@ export async function migrateLayout(
2544
2886
  // A moved module's paths from its own location now start from its new folder: re-point the ones it
2545
2887
  // spells out, and report the first one it cannot follow.
2546
2888
  const unfollowed = new Map<string, string>()
2889
+ /** Moved shell scripts whose own-folder paths were re-pointed: new path -> text. */
2890
+ const scriptWrites = new Map<string, string>()
2547
2891
  for (const { from, to } of moves) {
2892
+ if (SHELL_FILE.test(to) && !original.has(from)) {
2893
+ const script = readFileSync(join(root, from), "utf8")
2894
+ const result = rebaseShellPaths(from, to, script, (target) =>
2895
+ known.has(target) ? newPath(target) : target,
2896
+ )
2897
+ if (result.text !== script) scriptWrites.set(to, result.text)
2898
+ if (result.unfollowed !== undefined) unfollowed.set(to, result.unfollowed)
2899
+ continue
2900
+ }
2548
2901
  const text = final.get(to)
2549
2902
  if (text === undefined || !SELF_LOCATION.test(text)) continue
2550
2903
  if (!/\.[cm]?[jt]sx?$/.test(to)) {
@@ -2584,6 +2937,11 @@ export async function migrateLayout(
2584
2937
  .filter((file) => next.has(file) || !original.has(file))
2585
2938
  .map((file) => ({ from: splitFrom.get(file) ?? file, to: newPath(file) }))
2586
2939
  const tsconfigs = followTsconfigs(ts, root, moveMap, layout)
2940
+ // The app's own package.json names files from the app root: its scripts and entry fields follow.
2941
+ const manifestPath = join(root, "package.json")
2942
+ const manifest = existsSync(manifestPath)
2943
+ ? rewritePackagePaths(ts, readFileSync(manifestPath, "utf8"), moveMap)
2944
+ : undefined
2587
2945
  const scanned: Array<readonly [string, string]> = [...final]
2588
2946
  for (const file of everyFile) {
2589
2947
  if (
@@ -2593,17 +2951,22 @@ export async function migrateLayout(
2593
2951
  )
2594
2952
  scanned.push([
2595
2953
  newPath(file),
2596
- tsconfigs.files.get(file)?.text ?? readFileSync(join(root, file), "utf8"),
2954
+ (file === "package.json" ? manifest?.text : undefined) ??
2955
+ tsconfigs.files.get(file)?.text ??
2956
+ readFileSync(join(root, file), "utf8"),
2597
2957
  ])
2598
2958
  }
2959
+ // A mention only in comments is worth updating, not a decision: it never changes what runs.
2960
+ const commentFollowUps: LayoutMigrationFollowUp[] = []
2599
2961
  for (const [file, text] of scanned) {
2600
2962
  let live: ReadonlyArray<readonly [number, number]> | undefined
2963
+ let comments: ReadonlyArray<readonly [number, number]> | undefined
2601
2964
  for (const [from, to] of moveMap) {
2602
2965
  // `shared/lib/x.ts` contains `lib/x.ts`; that is the new path, not a stale one.
2603
2966
  const newPrefix = to.endsWith(from) ? to.slice(0, to.length - from.length) : undefined
2604
2967
  const stale = [
2605
2968
  ...text.matchAll(new RegExp(`(?<![\\w.-])${escapeRegExp(from)}(?![\\w])`, "g")),
2606
- ].some((match) => {
2969
+ ].filter((match) => {
2607
2970
  if (newPrefix !== undefined && text.slice(0, match.index).endsWith(newPrefix)) return false
2608
2971
  // An import that resolves after the moves is current, even when it still reads like the old
2609
2972
  // path: `./x.json` from a module that moved together with `x.json`.
@@ -2611,7 +2974,16 @@ export async function migrateLayout(
2611
2974
  const end = match.index + from.length
2612
2975
  return !live.some(([start, stop]) => start <= match.index && end <= stop)
2613
2976
  })
2614
- if (stale) issues.push({ file, reason: `mentions "${from}" by path; it moved to "${to}"` })
2977
+ if (stale.length === 0) continue
2978
+ comments ??= /\.[cm]?[jt]sx?$/.test(file) ? triviaCommentRanges(ts, file, text) : []
2979
+ const inComments = stale.every((match) =>
2980
+ comments?.some(
2981
+ ([start, stop]) => start <= match.index && match.index + from.length <= stop,
2982
+ ),
2983
+ )
2984
+ if (inComments)
2985
+ commentFollowUps.push({ file, reason: `a comment names "${from}", which moved to "${to}"` })
2986
+ else issues.push({ file, reason: `mentions "${from}" by path; it moved to "${to}"` })
2615
2987
  }
2616
2988
  }
2617
2989
 
@@ -2665,7 +3037,9 @@ export async function migrateLayout(
2665
3037
  if (!mentionsApp.test(text) && (ownName === undefined || !text.includes(`${ownName}/`)))
2666
3038
  continue
2667
3039
  const at = toPosix(relative(root, join(sibling, file)))
2668
- for (const { from, to, line } of siblingReferences(
3040
+ const onLines = (lines: readonly number[]): string =>
3041
+ `on line${lines.length === 1 ? "" : "s"} ${lines.join(", ")}`
3042
+ for (const { from, to, lines, commentLines } of siblingReferences(
2669
3043
  ts,
2670
3044
  root,
2671
3045
  sibling,
@@ -2675,10 +3049,18 @@ export async function migrateLayout(
2675
3049
  known,
2676
3050
  ownName,
2677
3051
  )) {
2678
- issues.push({
2679
- file: at,
2680
- reason: `names "${from}" on line ${line}, and it moves to "${to}" - it is outside the app, so the migration does not rewrite it`,
2681
- })
3052
+ const comments =
3053
+ commentLines.length === 0 ? "" : ` (and in a comment ${onLines(commentLines)})`
3054
+ if (lines.length > 0)
3055
+ issues.push({
3056
+ file: at,
3057
+ reason: `names "${from}" ${onLines(lines)}${comments}, and it moves to "${to}" - it is outside the app, so the migration does not rewrite it`,
3058
+ })
3059
+ else
3060
+ commentFollowUps.push({
3061
+ file: at,
3062
+ reason: `a comment ${onLines(commentLines)} names "${from}", which moved to "${to}"`,
3063
+ })
2682
3064
  }
2683
3065
  }
2684
3066
  }
@@ -2735,7 +3117,7 @@ export async function migrateLayout(
2735
3117
  })
2736
3118
  for (const [file, text] of schemaPlan?.edits ?? []) final.set(file, text)
2737
3119
  const schemas = (schemaPlan?.entries ?? []).filter((entry) => entry.status === "missing")
2738
- const followUps: LayoutMigrationFollowUp[] = []
3120
+ const followUps: LayoutMigrationFollowUp[] = [...commentFollowUps]
2739
3121
  for (const [file, text] of final) {
2740
3122
  if (!file.startsWith("routes/") || !/\.backend\.[cm]?[jt]s$/.test(file)) continue
2741
3123
  for (const { name, schema } of missingOutputSchemas(text)) {
@@ -2812,6 +3194,14 @@ export async function migrateLayout(
2812
3194
  toolingWrites.set("package.json", kind.text)
2813
3195
  tooling.push({ file: "package.json", change: '"nifra": { "kind": "api" }' })
2814
3196
  }
3197
+ if (manifest !== undefined && manifest.count > 0) {
3198
+ const current = toolingWrites.get("package.json") ?? readFileSync(manifestPath, "utf8")
3199
+ toolingWrites.set("package.json", rewritePackagePaths(ts, current, moveMap).text)
3200
+ tooling.push({
3201
+ file: "package.json",
3202
+ change: `${manifest.count} file path(s) in scripts and entry fields follow their moved files`,
3203
+ })
3204
+ }
2815
3205
 
2816
3206
  if (options.write === true) {
2817
3207
  for (const [file, text] of toolingWrites) writeFileSync(join(root, file), text)
@@ -2833,6 +3223,7 @@ export async function migrateLayout(
2833
3223
  renameSync(join(root, from), join(root, to))
2834
3224
  vacated.push(from)
2835
3225
  }
3226
+ for (const [file, text] of scriptWrites) writeFileSync(join(root, file), text)
2836
3227
  pruneVacatedDirs(root, vacated)
2837
3228
  }
2838
3229
  return {
@@ -3354,6 +3745,80 @@ function declareApiKind(ts: typeof TS, root: string): { text?: string; issue?: s
3354
3745
  return { text: insertProperty(source, text, nifra.initializer, '"kind": "api"') }
3355
3746
  }
3356
3747
 
3748
+ /** package.json fields whose string values name files from the package folder. */
3749
+ const PACKAGE_PATH_FIELDS = new Set([
3750
+ "main",
3751
+ "module",
3752
+ "types",
3753
+ "typings",
3754
+ "browser",
3755
+ "source",
3756
+ "bin",
3757
+ "exports",
3758
+ "imports",
3759
+ "files",
3760
+ "scripts",
3761
+ ])
3762
+
3763
+ /**
3764
+ * `text` (a package.json at the app root) with each moved file it names by its exact path, in the
3765
+ * fields above, named at its new path; `./` kept as written. A value with a `*` outside `scripts` is a
3766
+ * pattern over a folder, which no single move settles, so it stays and the path scan reports it.
3767
+ */
3768
+ function rewritePackagePaths(
3769
+ ts: typeof TS,
3770
+ text: string,
3771
+ moves: ReadonlyMap<string, string>,
3772
+ ): { readonly text: string; readonly count: number } {
3773
+ const source = ts.parseJsonText("package.json", text)
3774
+ const top = source.statements[0]?.expression
3775
+ if (top === undefined || !ts.isObjectLiteralExpression(top) || moves.size === 0)
3776
+ return { text, count: 0 }
3777
+ // Longest first, so `lib/a.test.ts` is not read as `lib/a.ts` with a tail.
3778
+ const ordered = [...moves].sort(([a], [b]) => b.length - a.length)
3779
+ const pattern = new RegExp(
3780
+ `(?<![\\w.@/-])(\\./)?(${ordered.map(([from]) => escapeRegExp(from)).join("|")})(?![\\w/-]|\\.\\w)`,
3781
+ "g",
3782
+ )
3783
+ const edits: Array<{ start: number; end: number; text: string }> = []
3784
+ let count = 0
3785
+ const visit = (node: TS.Node, field: string): void => {
3786
+ if (ts.isStringLiteral(node)) {
3787
+ if (field !== "scripts" && node.text.includes("*")) return
3788
+ const value = node.text.replace(pattern, (_match, dot: string | undefined, from: string) => {
3789
+ count += 1
3790
+ return `${dot ?? ""}${moves.get(from) ?? from}`
3791
+ })
3792
+ if (value !== node.text)
3793
+ edits.push({
3794
+ start: node.getStart(source),
3795
+ end: node.getEnd(),
3796
+ text: JSON.stringify(value),
3797
+ })
3798
+ return
3799
+ }
3800
+ if (ts.isArrayLiteralExpression(node)) {
3801
+ for (const element of node.elements) visit(element, field)
3802
+ return
3803
+ }
3804
+ if (!ts.isObjectLiteralExpression(node)) return
3805
+ for (const property of node.properties) {
3806
+ if (!ts.isPropertyAssignment(property)) continue
3807
+ // `"//x"` keys are comments by npm convention.
3808
+ if (ts.isStringLiteral(property.name) && property.name.text.startsWith("//")) continue
3809
+ visit(property.initializer, field)
3810
+ }
3811
+ }
3812
+ for (const property of top.properties) {
3813
+ if (!ts.isPropertyAssignment(property) || !ts.isStringLiteral(property.name)) continue
3814
+ if (PACKAGE_PATH_FIELDS.has(property.name.text)) visit(property.initializer, property.name.text)
3815
+ }
3816
+ let next = text
3817
+ for (const edit of edits.sort((a, b) => b.start - a.start))
3818
+ next = next.slice(0, edit.start) + edit.text + next.slice(edit.end)
3819
+ return { text: next, count }
3820
+ }
3821
+
3357
3822
  /** Tailwind `content` globs that matched a moved file at its old path and match nothing at its new one. */
3358
3823
  function staleContentGlobs(
3359
3824
  ts: typeof TS,