@astryxdesign/cli 0.7.5-canary.f2dafed → 0.7.5-canary.f57df18

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 (264) hide show
  1. package/README.md +19 -19
  2. package/api/component/_adapter.mjs +16 -1
  3. package/api/component/component.test.mjs +31 -0
  4. package/api/discover/_adapter.d.mts +1 -1
  5. package/api/docs/_adapter.d.mts +5 -2
  6. package/api/docs/_adapter.mjs +24 -16
  7. package/api/docs/docs.test.mjs +18 -0
  8. package/api/docs/integrationDocs.test.mjs +2 -2
  9. package/api/experimental.d.mts +5 -0
  10. package/api/experimental.mjs +15 -0
  11. package/api/hook/list/list.d.mts +1 -1
  12. package/api/icon/_adapter.d.mts +3 -2
  13. package/api/icon/_adapter.mjs +16 -3
  14. package/api/icon/_authoring.d.mts +5 -1
  15. package/api/icon/_authoring.mjs +478 -63
  16. package/api/icon/_options.d.mts +11 -0
  17. package/api/icon/_options.mjs +39 -4
  18. package/api/icon/_records.d.mts +19 -0
  19. package/api/icon/_records.mjs +25 -0
  20. package/api/icon/add/add.d.mts +3 -3
  21. package/api/icon/add/add.mjs +227 -14
  22. package/api/icon/all-or-nothing.test.mjs +283 -0
  23. package/api/icon/detail/detail.mjs +2 -13
  24. package/api/icon/error-codes.test.mjs +14 -7
  25. package/api/icon/icon.d.mts +2 -2
  26. package/api/icon/icon.doc.mjs +30 -2
  27. package/api/icon/icon.mjs +57 -8
  28. package/api/icon/icon.test.mjs +133 -1
  29. package/api/icon/icon.type.d.mts +126 -1
  30. package/api/icon/icon.type.mjs +67 -3
  31. package/api/icon/iconAdd.doc.mjs +22 -6
  32. package/api/icon/iconMap.doc.mjs +24 -8
  33. package/api/icon/iconNewDefinition.doc.mjs +2 -2
  34. package/api/icon/iconNewSet.doc.mjs +30 -2
  35. package/api/icon/iconUse.doc.mjs +4 -1
  36. package/api/icon/map/map.d.mts +4 -4
  37. package/api/icon/map/map.mjs +134 -9
  38. package/api/icon/new-definition/new-definition.mjs +6 -2
  39. package/api/icon/new-set/new-set.mjs +2 -2
  40. package/api/icon/new-set/new-set.test.mjs +60 -10
  41. package/api/icon/option-pairs.test.mjs +368 -0
  42. package/api/icon/search/search.d.mts +10 -0
  43. package/api/icon/search/search.mjs +55 -14
  44. package/api/icon/use/use.mjs +2 -13
  45. package/api/integration/add-helpers.d.mts +15 -1
  46. package/api/integration/add-helpers.mjs +1 -1
  47. package/api/integration/pack-check.lifecycle-output.test.mjs +24 -1
  48. package/api/integration/pack-check.mjs +10 -4
  49. package/api/integration/pack-check.test.mjs +5 -1
  50. package/api/integration/validate-integration.type.d.mts +3 -2
  51. package/api/integration/validate-integration.type.mjs +3 -2
  52. package/api/render/_adapter.d.mts +28 -0
  53. package/api/render/_adapter.mjs +540 -0
  54. package/api/render/render.d.mts +15 -0
  55. package/api/render/render.doc.d.mts +9 -0
  56. package/api/render/render.doc.mjs +112 -0
  57. package/api/render/render.mjs +113 -0
  58. package/api/render/render.test.mjs +1155 -0
  59. package/api/render/render.type.d.mts +74 -0
  60. package/api/render/render.type.mjs +64 -0
  61. package/api/search/_adapter.test.mjs +21 -2
  62. package/api/search/_result.d.mts +5 -5
  63. package/api/search/search.d.mts +1 -1
  64. package/api/template/template.mjs +3 -1
  65. package/api/template/template.type.d.mts +2 -1
  66. package/api/template/template.type.mjs +1 -1
  67. package/api/template/unknown-name.test.mjs +63 -0
  68. package/api/upgrade/_adapter.d.mts +2 -0
  69. package/api/upgrade/run/failure-receipt.test.mjs +212 -0
  70. package/api/upgrade/run/run.mjs +251 -10
  71. package/api/upgrade/upgrade.doc.mjs +4 -4
  72. package/api/upgrade/upgrade.mjs +19 -4
  73. package/api/upgrade/upgrade.type.d.mts +12 -1
  74. package/api/upgrade/upgrade.type.mjs +17 -4
  75. package/assets/codemods/__tests__/runner.symlinks.test.mjs +205 -0
  76. package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
  77. package/assets/codemods/integration-runner.mjs +8 -2
  78. package/assets/codemods/integration-runner.protection.test.mjs +53 -0
  79. package/assets/codemods/parse.mjs +94 -0
  80. package/assets/codemods/run-codemod.mjs +109 -5
  81. package/assets/codemods/runner.mjs +108 -10
  82. package/assets/codemods/transform-prop.mjs +99 -49
  83. package/assets/codemods/transform-prop.test.mjs +36 -1
  84. package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +216 -2
  85. package/assets/codemods/transforms/v0.1.3/migrate-layout-components-to-experimental.mjs +88 -6
  86. package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +4 -3
  87. package/assets/codemods/transforms/v0.7.0/__tests__/migrate-deprecated-theme-surface.test.mjs +207 -6
  88. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +123 -70
  89. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface-v0.6-data.mjs +6 -1
  90. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +244 -42
  91. package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +19 -77
  92. package/assets/docs/tree/icon-definitions.doc.mjs +2 -2
  93. package/assets/docs/tree/icon-set-files.doc.mjs +1 -1
  94. package/assets/docs/tree/icon-sets.doc.mjs +50 -20
  95. package/assets/docs/tree/render-pages.doc.mjs +94 -0
  96. package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
  97. package/assets/icons/definitions/activity.doc.mjs +1 -1
  98. package/assets/icons/definitions/alignCenter.doc.mjs +9 -0
  99. package/assets/icons/definitions/alignEnd.doc.mjs +10 -0
  100. package/assets/icons/definitions/alignStart.doc.mjs +10 -0
  101. package/assets/icons/definitions/archive.doc.mjs +1 -1
  102. package/assets/icons/definitions/arrowsUpDown.doc.mjs +1 -1
  103. package/assets/icons/definitions/attach.doc.mjs +1 -1
  104. package/assets/icons/definitions/audio.doc.mjs +1 -1
  105. package/assets/icons/definitions/cart.doc.mjs +1 -1
  106. package/assets/icons/definitions/checkDouble.doc.mjs +1 -1
  107. package/assets/icons/definitions/chevronsLeft.doc.mjs +1 -1
  108. package/assets/icons/definitions/chevronsRight.doc.mjs +1 -1
  109. package/assets/icons/definitions/close.doc.mjs +1 -1
  110. package/assets/icons/definitions/collapse.doc.mjs +1 -1
  111. package/assets/icons/definitions/compose.doc.mjs +1 -1
  112. package/assets/icons/definitions/conversation.doc.mjs +1 -1
  113. package/assets/icons/definitions/copy.doc.mjs +1 -1
  114. package/assets/icons/definitions/cpu.doc.mjs +9 -0
  115. package/assets/icons/definitions/database.doc.mjs +1 -1
  116. package/assets/icons/definitions/desktop.doc.mjs +1 -1
  117. package/assets/icons/definitions/discount.doc.mjs +1 -1
  118. package/assets/icons/definitions/download.doc.mjs +1 -1
  119. package/assets/icons/definitions/emoji.doc.mjs +1 -1
  120. package/assets/icons/definitions/error.doc.mjs +1 -1
  121. package/assets/icons/definitions/expand.doc.mjs +1 -1
  122. package/assets/icons/definitions/experiment.doc.mjs +1 -1
  123. package/assets/icons/definitions/externalLink.doc.mjs +7 -1
  124. package/assets/icons/definitions/eyeSlash.doc.mjs +1 -1
  125. package/assets/icons/definitions/flipHorizontal.doc.mjs +9 -0
  126. package/assets/icons/definitions/flipVertical.doc.mjs +9 -0
  127. package/assets/icons/definitions/folderAdd.doc.mjs +1 -1
  128. package/assets/icons/definitions/gitBranch.doc.mjs +9 -0
  129. package/assets/icons/definitions/gitFork.doc.mjs +9 -0
  130. package/assets/icons/definitions/info.doc.mjs +1 -1
  131. package/assets/icons/definitions/location.doc.mjs +1 -1
  132. package/assets/icons/definitions/mention.doc.mjs +1 -1
  133. package/assets/icons/definitions/menu.doc.mjs +1 -1
  134. package/assets/icons/definitions/microphone.doc.mjs +1 -1
  135. package/assets/icons/definitions/mobile.doc.mjs +1 -1
  136. package/assets/icons/definitions/money.doc.mjs +1 -1
  137. package/assets/icons/definitions/moreHorizontal.doc.mjs +1 -1
  138. package/assets/icons/definitions/notificationActive.doc.mjs +1 -1
  139. package/assets/icons/definitions/notificationOff.doc.mjs +1 -1
  140. package/assets/icons/definitions/panelLeft.doc.mjs +10 -0
  141. package/assets/icons/definitions/panelRight.doc.mjs +10 -0
  142. package/assets/icons/definitions/raiseHand.doc.mjs +1 -1
  143. package/assets/icons/definitions/redo.doc.mjs +1 -1
  144. package/assets/icons/definitions/refresh.doc.mjs +1 -1
  145. package/assets/icons/definitions/rotate.doc.mjs +9 -0
  146. package/assets/icons/definitions/scale.doc.mjs +10 -0
  147. package/assets/icons/definitions/search.doc.mjs +1 -1
  148. package/assets/icons/definitions/send.doc.mjs +1 -1
  149. package/assets/icons/definitions/settings.doc.mjs +1 -1
  150. package/assets/icons/definitions/star.doc.mjs +1 -1
  151. package/assets/icons/definitions/stop.doc.mjs +1 -1
  152. package/assets/icons/definitions/success.doc.mjs +1 -1
  153. package/assets/icons/definitions/textCase.doc.mjs +9 -0
  154. package/assets/icons/definitions/thumbsDown.doc.mjs +1 -1
  155. package/assets/icons/definitions/thumbsUp.doc.mjs +1 -1
  156. package/assets/icons/definitions/trendDown.doc.mjs +7 -1
  157. package/assets/icons/definitions/trendUp.doc.mjs +1 -1
  158. package/assets/icons/definitions/undo.doc.mjs +1 -1
  159. package/assets/icons/definitions/upload.doc.mjs +1 -1
  160. package/assets/icons/definitions/userAdd.doc.mjs +1 -1
  161. package/assets/icons/definitions/warning.doc.mjs +1 -1
  162. package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
  163. package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
  164. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +15 -14
  165. package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +30 -30
  166. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +15 -14
  167. package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +15 -14
  168. package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +17 -16
  169. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +29 -29
  170. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +9 -8
  171. package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +39 -41
  172. package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -0
  173. package/assets/templates/pages/form-wizard-inline/template.doc.mjs +6 -1
  174. package/assets/templates/pages/library/page.tsx +1 -2
  175. package/assets/templates/pages/table-comparison/template.doc.mjs +1 -0
  176. package/assets/templates/pages/table-tree/template.doc.mjs +3 -0
  177. package/authoring/codemod/type.ts +10 -0
  178. package/authoring/debug/parse.d.mts +2 -2
  179. package/authoring/doctypes/icon-definition/icon-definition.doc.mjs +4 -4
  180. package/authoring/doctypes/icon-set/icon-set-data.doc.mjs +6 -0
  181. package/authoring/doctypes/icon-set/parse.d.mts +1 -0
  182. package/authoring/doctypes/icon-set/parse.mjs +1 -0
  183. package/authoring/doctypes/icon-set/type.ts +5 -0
  184. package/authoring/doctypes/template/template.doc.mjs +1 -1
  185. package/authoring/doctypes/template/type.ts +2 -1
  186. package/clients/cli/commands/doctor.mjs +16 -17
  187. package/clients/cli/commands/experimental/icon.mjs +167 -35
  188. package/clients/cli/commands/experimental/index.mjs +2 -0
  189. package/clients/cli/commands/experimental/render.mjs +113 -0
  190. package/clients/cli/commands/experimental-icon-add.doc.mjs +14 -4
  191. package/clients/cli/commands/experimental-icon-map.doc.mjs +12 -2
  192. package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +1 -1
  193. package/clients/cli/commands/experimental-icon-new-set.doc.mjs +28 -1
  194. package/clients/cli/commands/experimental-icon.doc.mjs +18 -2
  195. package/clients/cli/commands/experimental-render.doc.mjs +60 -0
  196. package/clients/cli/commands/experimental.doc.mjs +4 -2
  197. package/clients/cli/commands/icon-authoring.test.mjs +1823 -13
  198. package/clients/cli/commands/icon-options-wiring.test.mjs +158 -0
  199. package/clients/cli/commands/icon.test.mjs +1 -1
  200. package/clients/cli/commands/template.mjs +4 -1
  201. package/clients/cli/commands/text-json-parity.test.mjs +46 -0
  202. package/clients/cli/commands/upgrade.doc.mjs +27 -0
  203. package/clients/cli/commands/upgrade.file-protection.test.mjs +175 -0
  204. package/clients/cli/commands/upgrade.flag-help.test.mjs +37 -0
  205. package/clients/cli/commands/upgrade.integration-policy.test.mjs +103 -0
  206. package/clients/cli/commands/upgrade.mjs +9 -2
  207. package/clients/cli/index.mjs +1 -0
  208. package/foundation/discovery/icon-set-checks.d.mts +43 -9
  209. package/foundation/discovery/icon-set-checks.mjs +296 -21
  210. package/foundation/discovery/icon-set-checks.test.mjs +125 -12
  211. package/foundation/discovery/icon-set-writer.d.mts +192 -3
  212. package/foundation/discovery/icon-set-writer.mjs +608 -34
  213. package/foundation/discovery/icon-set-writer.test.mjs +26 -0
  214. package/foundation/discovery/module-exports.mjs +82 -25
  215. package/foundation/discovery/module-exports.test.mjs +38 -1
  216. package/foundation/discovery/template-icons.d.mts +6 -0
  217. package/foundation/discovery/template-icons.mjs +98 -10
  218. package/foundation/discovery/template-icons.test.mjs +103 -0
  219. package/foundation/doc-compiler/doc-loads.test.mjs +20 -5
  220. package/foundation/doc-compiler/import.mjs +81 -8
  221. package/foundation/doc-compiler/read.d.mts +4 -3
  222. package/foundation/doc-compiler/read.mjs +15 -10
  223. package/foundation/doc-compiler/read.test.mjs +59 -1
  224. package/foundation/doc-compiler/tree.mjs +3 -1
  225. package/foundation/fs/module-loader.d.mts +3 -2
  226. package/foundation/fs/module-loader.mjs +3 -2
  227. package/foundation/fs/publish-file-eperm-mutation.test.mjs +2 -0
  228. package/foundation/fs/read-record.d.mts +27 -0
  229. package/foundation/fs/read-record.mjs +83 -15
  230. package/foundation/fs/read-record.test.mjs +88 -1
  231. package/foundation/render/assets.d.mts +31 -0
  232. package/foundation/render/assets.mjs +102 -0
  233. package/foundation/render/component-map.d.mts +52 -0
  234. package/foundation/render/component-map.mjs +141 -0
  235. package/foundation/render/css-cut.d.mts +29 -0
  236. package/foundation/render/css-cut.mjs +144 -0
  237. package/foundation/render/embedded-files.d.mts +28 -0
  238. package/foundation/render/embedded-files.mjs +108 -0
  239. package/foundation/render/embedded-imports.d.mts +61 -0
  240. package/foundation/render/embedded-imports.mjs +315 -0
  241. package/foundation/render/html-reader.d.mts +37 -0
  242. package/foundation/render/html-reader.mjs +121 -0
  243. package/foundation/render/page-worker.d.mts +7 -0
  244. package/foundation/render/page-worker.mjs +519 -0
  245. package/foundation/render/rebuild.d.mts +19 -0
  246. package/foundation/render/rebuild.mjs +269 -0
  247. package/foundation/render/render-page.d.mts +85 -0
  248. package/foundation/render/render-page.mjs +612 -0
  249. package/foundation/render/render.test.mjs +117 -0
  250. package/foundation/render/source-block.d.mts +52 -0
  251. package/foundation/render/source-block.mjs +106 -0
  252. package/foundation/response/base.d.ts +7 -0
  253. package/foundation/response/error-codes.d.mts +10 -1
  254. package/foundation/response/error-codes.doc.mjs +59 -2
  255. package/foundation/response/error-codes.mjs +62 -1
  256. package/foundation/response/json.d.mts +10 -3
  257. package/foundation/response/json.mjs +16 -4
  258. package/foundation/response/response-types.doc.mjs +38 -1
  259. package/foundation/text/string-utils.mjs +33 -0
  260. package/foundation/text/string-utils.test.mjs +17 -0
  261. package/foundation/text/suggest-order.d.mts +17 -3
  262. package/foundation/text/suggest-order.mjs +58 -13
  263. package/foundation/text/suggest-order.test.mjs +53 -0
  264. package/package.json +15 -9
@@ -61,6 +61,7 @@ import {
61
61
  PathSafetyError,
62
62
  } from '../../../foundation/fs/path-safety.mjs';
63
63
  import {createFileProtectionResolver} from '../../../foundation/fs/file-protection.mjs';
64
+ import {withoutProtected} from '../../../assets/codemods/runner.mjs';
64
65
 
65
66
  /**
66
67
  * Collapse per-codemod protection hits into one stable row per file.
@@ -93,6 +94,55 @@ function summarizeProtectedFiles(rows) {
93
94
  .sort((a, b) => a.file.localeCompare(b.file));
94
95
  }
95
96
 
97
+ /**
98
+ * Collapse per-codemod declined candidates into one row per file, in the
99
+ * receipt's `{file, location?, reason}` shape. A file the receipt lists under
100
+ * `protectedFiles` is left out: a codemod still requires a change to it, and
101
+ * that already makes the run incomplete.
102
+ * @param {Array<{file: string, codemod: string, location?: string, reason: string}>} rows
103
+ * @param {Array<{file: string}>} [protectedRows]
104
+ * @returns {Array<{file: string, location?: string, reason: string}>}
105
+ */
106
+ function summarizeDeclinedCandidates(rows, protectedRows = []) {
107
+ /** @type {Map<string, {file: string, location?: string, reason: string}>} */
108
+ const byFile = new Map();
109
+ for (const {file, location, reason} of withoutProtected(
110
+ rows,
111
+ protectedRows,
112
+ )) {
113
+ if (byFile.has(file)) continue;
114
+ byFile.set(file, {file, ...(location ? {location} : {}), reason});
115
+ }
116
+ return [...byFile.values()].sort((a, b) => a.file.localeCompare(b.file));
117
+ }
118
+
119
+ /**
120
+ * Print the protected files the run skipped because a codemod could not parse
121
+ * them, from the final declined list (files it reports as protected are
122
+ * already left out), so the text output carries what the receipt lists.
123
+ * @param {Array<{file: string, location?: string, reason: string}>} declined
124
+ */
125
+ function logDeclined(declined) {
126
+ if (declined.length === 0) return;
127
+ const n = declined.length;
128
+ logger.warn(
129
+ `${n} protected file${n === 1 ? ' was' : 's were'} skipped because ${n === 1 ? 'it does' : 'they do'} not parse; review manually:`,
130
+ );
131
+ for (const {file, location, reason} of declined) {
132
+ logger.warn(` ${file}${location ? `:${location}` : ''} - ${reason}`);
133
+ }
134
+ }
135
+
136
+ /**
137
+ * @template {Array<{file: string, location?: string, reason: string}>} T
138
+ * @param {T} declined
139
+ * @returns {T}
140
+ */
141
+ function logged(declined) {
142
+ logDeclined(declined);
143
+ return declined;
144
+ }
145
+
96
146
  /** @param {string} cwd */
97
147
  function loadFileProtection(cwd) {
98
148
  try {
@@ -109,6 +159,83 @@ function loadFileProtection(cwd) {
109
159
  }
110
160
  }
111
161
 
162
+ /**
163
+ * The receipt of a run that stopped after codemods ran. Whatever the codemods
164
+ * already wrote stays on disk, so the error the run throws carries this
165
+ * receipt (`failWithReceipt`): a caller that reads only the error would
166
+ * report nothing changed while the files it lists remain modified
167
+ * (spec:AST-040 FR7).
168
+ *
169
+ * @param {{from: string, to: string, codemods: number, integrations: string[], sourcePathFound: boolean, cwd: string, changedFiles: string[], transformsApplied: number, protectedRows: Array<{file: string, codemod: string, reason: string, declaration: string, generated: boolean, command?: string}>, errors: Array<{file: string, codemod: string, error: string}>, declinedRows?: Array<{file: string, codemod: string, location?: string, reason: string}>, errorCode: string, cliBehindCore?: import('../upgrade.type.mjs').CliBehindCore | null, registryCompositions?: import('../upgrade.type.mjs').RegistryCompositionSummary}} facts
170
+ * @returns {import('../upgrade.type.mjs').UpgradeRunResponse['data']}
171
+ */
172
+ function stoppedReceipt({
173
+ from,
174
+ to,
175
+ codemods,
176
+ integrations,
177
+ sourcePathFound,
178
+ cwd,
179
+ changedFiles,
180
+ transformsApplied,
181
+ protectedRows,
182
+ errors,
183
+ declinedRows = [],
184
+ errorCode,
185
+ cliBehindCore,
186
+ registryCompositions,
187
+ }) {
188
+ const modifiedFiles = uniqueFiles(changedFiles).map(file =>
189
+ path.relative(cwd, file).split(path.sep).join('/'),
190
+ );
191
+ return /** @type {import('../upgrade.type.mjs').UpgradeRunResponse['data']} */ ({
192
+ from,
193
+ to,
194
+ codemods,
195
+ integrations,
196
+ agentDocsRefreshed: false,
197
+ agentDocs: {
198
+ status: 'current',
199
+ installedVersion: to,
200
+ fromVersions: [],
201
+ files: [],
202
+ refreshed: false,
203
+ action: 'none',
204
+ },
205
+ sourcePathFound,
206
+ filesChanged: modifiedFiles.length,
207
+ transformsApplied,
208
+ modifiedFiles,
209
+ protectedFiles: summarizeProtectedFiles(protectedRows),
210
+ declinedCandidates: logged(
211
+ summarizeDeclinedCandidates(declinedRows, protectedRows),
212
+ ),
213
+ complete: false,
214
+ errorCode,
215
+ errors,
216
+ ...(registryCompositions ? {registryCompositions} : {}),
217
+ ...(cliBehindCore ? {cliBehindCore} : {}),
218
+ });
219
+ }
220
+
221
+ /**
222
+ * The error a run throws once codemods have run: the same message and stable
223
+ * code as always, plus the run's receipt on `receipt`, so the JSON error
224
+ * envelope and a programmatic caller can still see what was written.
225
+ * @param {string} message
226
+ * @param {string} code
227
+ * @param {import('../upgrade.type.mjs').UpgradeRunResponse['data']} receipt
228
+ * @returns {AstryxError & {receipt: import('../upgrade.type.mjs').UpgradeRunResponse['data']}}
229
+ */
230
+ function failWithReceipt(message, code, receipt) {
231
+ const err =
232
+ /** @type {AstryxError & {receipt: import('../upgrade.type.mjs').UpgradeRunResponse['data']}} */ (
233
+ new AstryxError(message, undefined, code)
234
+ );
235
+ err.receipt = receipt;
236
+ return err;
237
+ }
238
+
112
239
  /**
113
240
  * Run the upgrade pipeline for a validated, non-list invocation. Returns the
114
241
  * terminal run receipt, or one of the status short-circuits; throws AstryxError
@@ -331,7 +458,12 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
331
458
  path.relative(cwd, file).split(path.sep).join('/'),
332
459
  ),
333
460
  protectedFiles,
334
- declinedCandidates: [],
461
+ declinedCandidates: logged(
462
+ summarizeDeclinedCandidates(
463
+ coreResult?.declinedCandidates ?? [],
464
+ allProtected,
465
+ ),
466
+ ),
335
467
  complete: false,
336
468
  errorCode: 'ERR_CODEMOD_PROTECTED',
337
469
  errors: coreResult?.errors ?? [],
@@ -368,6 +500,33 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
368
500
  // Genuine config error: abort.
369
501
  logger.error(configErr.message);
370
502
  logger.log('Aborted\n');
503
+ if ((coreResult?.writtenFiles.length ?? 0) > 0) {
504
+ // Core codemods already wrote: the error carries what they changed.
505
+ if (cliBehindCore) logCliBehindCore(cliBehindCore, targetVersion);
506
+ const stopped = stoppedReceipt({
507
+ from: currentVersion,
508
+ to: targetVersion,
509
+ codemods: totalTransforms,
510
+ integrations: [],
511
+ sourcePathFound,
512
+ cwd,
513
+ changedFiles: coreResult?.changedFiles ?? [],
514
+ transformsApplied: coreResult?.totalTransformsApplied ?? 0,
515
+ protectedRows: [],
516
+ errors: [
517
+ ...(coreResult?.errors ?? []),
518
+ {file: '.', codemod: 'config', error: configErr.message},
519
+ ],
520
+ declinedRows: coreResult?.declinedCandidates ?? [],
521
+ errorCode: ERROR_CODES.ERR_INVALID_ARGUMENT,
522
+ cliBehindCore,
523
+ });
524
+ throw failWithReceipt(
525
+ configErr.message,
526
+ ERROR_CODES.ERR_INVALID_ARGUMENT,
527
+ stopped,
528
+ );
529
+ }
371
530
  throw new AstryxError(
372
531
  configErr.message,
373
532
  undefined,
@@ -561,7 +720,34 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
561
720
  logger.error(msg);
562
721
  if (initialProtected.length === 0) {
563
722
  logger.log('Upgrade failed\n');
564
- throw new AstryxError(msg, undefined, ERROR_CODES.ERR_CODEMOD_FAILED);
723
+ throw failWithReceipt(
724
+ msg,
725
+ ERROR_CODES.ERR_CODEMOD_FAILED,
726
+ stoppedReceipt({
727
+ from: currentVersion,
728
+ to: targetVersion,
729
+ codemods: totalTransforms,
730
+ integrations: receipt.integrations,
731
+ sourcePathFound,
732
+ cwd,
733
+ changedFiles: mergedChangedFiles,
734
+ transformsApplied: mergedTransformsApplied,
735
+ protectedRows: [],
736
+ errors: [
737
+ ...mergedErrors,
738
+ {file: '.', codemod: 'post-codemod-hook', error: msg},
739
+ ],
740
+ declinedRows: [
741
+ ...(coreResult?.declinedCandidates ?? []),
742
+ ...(integrationResult?.declinedCandidates ?? []),
743
+ ],
744
+ errorCode: ERROR_CODES.ERR_CODEMOD_FAILED,
745
+ cliBehindCore,
746
+ ...(registryResult
747
+ ? {registryCompositions: registryResult.summary}
748
+ : {}),
749
+ }),
750
+ );
565
751
  }
566
752
  hookFailure = msg;
567
753
  finalErrors = [
@@ -586,8 +772,44 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
586
772
  // selected codemods in preview mode against fresh bytes and fresh declarations
587
773
  // to distinguish resolved outputs from changes that remain blocked.
588
774
  let remainingProtected = initialProtected;
775
+ let remainingDeclined = [
776
+ ...(coreResult?.declinedCandidates ?? []),
777
+ ...(integrationResult?.declinedCandidates ?? []),
778
+ ];
589
779
  if (apply && shouldRunHooks && !hookFailure) {
590
- const refreshedProtection = loadFileProtection(cwd);
780
+ let refreshedProtection;
781
+ try {
782
+ refreshedProtection = loadFileProtection(cwd);
783
+ } catch (err) {
784
+ if (!(err instanceof AstryxError)) throw err;
785
+ // The hooks ran after the codemods wrote; the error carries their receipt.
786
+ if (cliBehindCore) logCliBehindCore(cliBehindCore, targetVersion);
787
+ const stopped = stoppedReceipt({
788
+ from: currentVersion,
789
+ to: targetVersion,
790
+ codemods: totalTransforms,
791
+ integrations: receipt.integrations,
792
+ sourcePathFound,
793
+ cwd,
794
+ changedFiles: [...mergedChangedFiles, ...hookModifiedFiles],
795
+ transformsApplied: mergedTransformsApplied,
796
+ protectedRows: initialProtected,
797
+ errors: [
798
+ ...mergedErrors,
799
+ {file: '.', codemod: 'file-protection', error: err.message},
800
+ ],
801
+ declinedRows: [
802
+ ...(coreResult?.declinedCandidates ?? []),
803
+ ...(integrationResult?.declinedCandidates ?? []),
804
+ ],
805
+ errorCode: err.code,
806
+ cliBehindCore,
807
+ ...(registryResult
808
+ ? {registryCompositions: registryResult.summary}
809
+ : {}),
810
+ });
811
+ throw failWithReceipt(err.message, err.code, stopped);
812
+ }
591
813
  const coreCheck = await runCoreCodemods(versionManifests, {
592
814
  apply: false,
593
815
  path: path_,
@@ -638,6 +860,12 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
638
860
  recheckedProtected.push(...(initialByFile.get(file) ?? []));
639
861
  }
640
862
  remainingProtected = recheckedProtected;
863
+ // Regenerated bytes decide what a codemod could not parse, as they decide
864
+ // what is still protected.
865
+ remainingDeclined = [
866
+ ...(checkedCore?.declinedCandidates ?? []),
867
+ ...(integrationCheck?.declinedCandidates ?? []),
868
+ ];
641
869
  finalErrors = [
642
870
  ...mergedErrors,
643
871
  ...(checkedCore?.errors ?? []),
@@ -653,10 +881,15 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
653
881
  ...hookModifiedFiles,
654
882
  ]).map(file => path.relative(cwd, file).split(path.sep).join('/'));
655
883
  receipt.protectedFiles = protectedFiles;
656
- receipt.declinedCandidates = [];
657
- receipt.complete = protectedFiles.length === 0;
658
- if (!receipt.complete) {
884
+ receipt.declinedCandidates = logged(
885
+ summarizeDeclinedCandidates(remainingDeclined, remainingProtected),
886
+ );
887
+ receipt.complete = protectedFiles.length === 0 && finalErrors.length === 0;
888
+ if (protectedFiles.length > 0) {
659
889
  receipt.errorCode = 'ERR_CODEMOD_PROTECTED';
890
+ } else if (finalErrors.length > 0) {
891
+ // Only on the receipt the thrown error carries (below).
892
+ receipt.errorCode = 'ERR_CODEMOD_FAILED';
660
893
  }
661
894
  receipt.errors = finalErrors;
662
895
  if (registryResult) receipt.registryCompositions = registryResult.summary;
@@ -674,14 +907,22 @@ export async function run(options = {}, {cwd = process.cwd(), origin} = {}) {
674
907
  }
675
908
  }
676
909
 
677
- if (receipt.errors?.length > 0 && protectedFiles.length === 0) {
678
- const msg = `Upgrade completed with ${receipt.errors.length} codemod error${receipt.errors.length === 1 ? '' : 's'}.`;
910
+ if (finalErrors.length > 0 && protectedFiles.length === 0) {
911
+ const msg = `Upgrade completed with ${finalErrors.length} codemod error${finalErrors.length === 1 ? '' : 's'}.`;
679
912
  logger.log('Upgrade failed\n');
680
- throw new AstryxError(msg, undefined, ERROR_CODES.ERR_CODEMOD_FAILED);
913
+ // The error carries the receipt: every file the codemods wrote before the
914
+ // failure stays changed, and the caller keeps or reverts them knowingly.
915
+ throw failWithReceipt(
916
+ msg,
917
+ ERROR_CODES.ERR_CODEMOD_FAILED,
918
+ /** @type {import('../upgrade.type.mjs').UpgradeRunResponse['data']} */ (
919
+ /** @type {unknown} */ (receipt)
920
+ ),
921
+ );
681
922
  }
682
923
 
683
924
  // Only refresh managed docs after all required codemod changes are complete.
684
- if (protectedFiles.length === 0) {
925
+ if (receipt.complete) {
685
926
  const agentDocsPlan = await prepareAgentDocsRefresh({
686
927
  cwd,
687
928
  origin,
@@ -128,13 +128,13 @@ export const doc = {
128
128
  {
129
129
  type: 'upgrade.run',
130
130
  description:
131
- 'The terminal run receipt: from, to, codemods (count), integrations, agentDocs, agentDocsRefreshed, registryCompositions (when receipts are found), sourcePathFound (false when the resolved `path` does not exist, so nothing was scanned), filesChanged, transformsApplied, modifiedFiles, protectedFiles, declinedCandidates, errors, and complete. When a protected file still requires a change, complete is false and errorCode is ERR_CODEMOD_PROTECTED; the CLI exits nonzero while preserving the structured receipt. When the installed Core is newer than the CLI, it also carries cliBehindCore ({cliVersion, command}): codemods for the releases after cliVersion did not run, and command runs the same upgrade with the matching CLI.',
131
+ 'The terminal run receipt: from, to, codemods (count), integrations, agentDocs, agentDocsRefreshed, registryCompositions (when receipts are found), sourcePathFound (false when the resolved `path` does not exist, so nothing was scanned), filesChanged, transformsApplied, modifiedFiles, protectedFiles, declinedCandidates, errors, and complete. When a protected file still requires a change, complete is false and errorCode is ERR_CODEMOD_PROTECTED; the CLI exits nonzero while preserving the structured receipt. A run that fails after its codemods ran throws instead (see throws), and the thrown AstryxError carries the same receipt on `receipt`, with complete false and errorCode set to its code. When the installed Core is newer than the CLI, it also carries cliBehindCore ({cliVersion, command}): codemods for the releases after cliVersion did not run, and command runs the same upgrade with the matching CLI.',
132
132
  },
133
133
  ],
134
134
  throws: [
135
135
  {
136
136
  code: 'ERR_INVALID_ARGUMENT',
137
- when: '`from` is missing (and neither `list` nor `registry` is set); `list` and `registry` are both set; `list` is combined with `from`, `force`, `apply`, `path` (non-default), `codemod`, `skipCodemod`, `integration` or `installDeps`; `registry` is combined with `from`, `force`, `codemod`, `skipCodemod`, `integration` or `installDeps`; an `integration` specifier is invalid or not installed; or astryx.config fails to load or validate and no pending config codemod repairs it',
137
+ when: '`from` is missing (and neither `list` nor `registry` is set); `list` and `registry` are both set; `list` is combined with `from`, `force`, `apply`, `path` (non-default), `codemod`, `skipCodemod`, `integration` or `installDeps`; `registry` is combined with `from`, `force`, `codemod`, `skipCodemod`, `integration` or `installDeps`; an `integration` specifier is invalid or not installed; or astryx.config fails to load or validate and no pending config codemod repairs it (when core codemods already wrote files, the error carries their receipt on `receipt`)',
138
138
  },
139
139
  {code: 'ERR_INVALID_VERSION', when: '`from` is not a valid semver string'},
140
140
  {
@@ -155,11 +155,11 @@ export const doc = {
155
155
  },
156
156
  {
157
157
  code: 'ERR_CODEMOD_FAILED',
158
- when: 'one or more codemods failed, or a post-codemod hook failed, and no protected file still needs a change (otherwise an upgrade.run receipt with complete: false is returned)',
158
+ when: "one or more codemods failed, or a post-codemod hook failed, and no protected file still needs a change (otherwise an upgrade.run receipt with complete: false is returned). The error carries the run's receipt on `receipt`: the files already changed, each failure in errors, complete: false",
159
159
  },
160
160
  {
161
161
  code: 'ERR_CODEMOD_PROTECTION_SOURCE',
162
- when: 'a working-tree protection declaration cannot be read or parsed before writes begin',
162
+ when: 'a working-tree protection declaration cannot be read or parsed before writes begin, or after post-codemod hooks rewrite it (the error then carries the receipt on `receipt`)',
163
163
  },
164
164
  ],
165
165
  examples: [
@@ -120,8 +120,23 @@ export async function upgrade(options = {}, {cwd = process.cwd()} = {}) {
120
120
  // A run from a subfolder upgrades the project the folder belongs to, and
121
121
  // names files relative to the folder it ran in.
122
122
  const scoped = scopeToProject(options, cwd);
123
- return relativeToOrigin(
124
- await run(scoped.options, {cwd: scoped.cwd, origin: scoped.origin}),
125
- scoped,
126
- );
123
+ let result;
124
+ try {
125
+ result = await run(scoped.options, {
126
+ cwd: scoped.cwd,
127
+ origin: scoped.origin,
128
+ });
129
+ } catch (err) {
130
+ // A failure after codemods wrote carries their receipt; name its files
131
+ // from the folder the command ran in, as a returned receipt does.
132
+ const receipt = /** @type {any} */ (err)?.receipt;
133
+ if (err instanceof AstryxError && receipt) {
134
+ /** @type {any} */ (err).receipt = relativeToOrigin(
135
+ {type: 'upgrade.run', data: receipt},
136
+ scoped,
137
+ ).data;
138
+ }
139
+ throw err;
140
+ }
141
+ return relativeToOrigin(result, scoped);
127
142
  }
@@ -193,7 +193,7 @@ export type UpgradeRunResponse = {
193
193
  sourcePathFound: boolean;
194
194
  registryCompositions?: RegistryCompositionSummary | undefined;
195
195
  complete?: boolean | undefined;
196
- errorCode?: "ERR_CODEMOD_PROTECTED" | undefined;
196
+ errorCode?: string | undefined;
197
197
  filesChanged?: number | undefined;
198
198
  modifiedFiles?: string[] | undefined;
199
199
  protectedFiles?: ProtectedCodemodFile[] | undefined;
@@ -211,6 +211,17 @@ export type UpgradeRunResponse = {
211
211
  cliBehindCore?: CliBehindCore | undefined;
212
212
  };
213
213
  };
214
+ /**
215
+ * What a failed upgrade had already done. When a run fails after its codemods
216
+ * ran (a codemod or post-codemod hook failed, or an error stopped it after
217
+ * codemods wrote files), the failure keeps its usual shape: the --json error
218
+ * envelope `{apiVersion, error, code}` and a rejected `upgrade()` with that
219
+ * `code`. The envelope adds `receipt`, and the thrown AstryxError a `receipt`
220
+ * property: the same `upgrade.run` data a completed run returns, with
221
+ * `complete: false` and `errorCode` equal to the error's `code`. Files in
222
+ * `modifiedFiles` stay changed.
223
+ */
224
+ export type UpgradeFailureReceipt = UpgradeRunResponse["data"];
214
225
  /**
215
226
  * astryx --json upgrade — short-circuit status results.
216
227
  *
@@ -131,17 +131,30 @@
131
131
  * @property {AgentDocsSummary} data.agentDocs
132
132
  * @property {boolean} data.sourcePathFound Whether the resolved source directory (`path`, default `./src`) exists. False means no source file was read, so a zero `filesChanged` says nothing about the project being migrated.
133
133
  * @property {RegistryCompositionSummary} [data.registryCompositions]
134
- * @property {boolean} [data.complete] False when protected required changes remain.
135
- * @property {'ERR_CODEMOD_PROTECTED'} [data.errorCode] Stable incomplete-result code when complete is false.
134
+ * @property {boolean} [data.complete] False when protected required changes remain. Also false on the receipt a failed run's error carries (`UpgradeFailureReceipt`).
135
+ * @property {string} [data.errorCode] Stable incomplete-result code when complete is false: `ERR_CODEMOD_PROTECTED` on a returned receipt; on the receipt a failed run's error carries, the error's own code.
136
136
  * @property {number} [data.filesChanged] Distinct files changed across core + integration codemods (apply mode). One file that four codemods each changed counts once.
137
137
  * @property {string[]} [data.modifiedFiles] Files changed or previewed, relative to the folder the command ran in.
138
138
  * @property {ProtectedCodemodFile[]} [data.protectedFiles] Protected files that still require a codemod change after regeneration.
139
- * @property {Array<{file: string, location?: string, reason: string}>} [data.declinedCandidates] Candidates left unchanged because proof was insufficient. Each `file` is relative to the folder the command ran in.
139
+ * @property {Array<{file: string, location?: string, reason: string}>} [data.declinedCandidates] Candidates left unchanged because proof was insufficient, one row per file, for manual review. A protected file whose own source does not parse is listed here, with the parse error's `line:column` as `location` and a `reason` that starts with `unparseable protected file`, instead of failing the run. Declined candidates do not make the run incomplete. Each `file` is relative to the folder the command ran in.
140
140
  * @property {number} [data.transformsApplied] Total codemod changes. A code or config codemod counts once for each file it changed, so one file changed by four of them counts four times; a project codemod counts once, however many files it writes.
141
- * @property {Array<{file: string, codemod: string, error: string}>} [data.errors] Per-codemod errors, when any codemod failed. Each `file` is relative to the folder the command ran in.
141
+ * @property {Array<{file: string, codemod: string, error: string}>} [data.errors] Per-codemod errors, when any codemod failed. On the receipt a failed run's error carries, also a post-codemod hook failure (`codemod: 'post-codemod-hook'`) or the error that stopped the run after codemods wrote files. Each `file` is relative to the folder the command ran in.
142
142
  * @property {CliBehindCore} [data.cliBehindCore] Present only when the installed Core is newer than this CLI: codemods for the releases after `cliBehindCore.cliVersion` did not run.
143
143
  */
144
144
 
145
+ /**
146
+ * What a failed upgrade had already done. When a run fails after its codemods
147
+ * ran (a codemod or post-codemod hook failed, or an error stopped it after
148
+ * codemods wrote files), the failure keeps its usual shape: the --json error
149
+ * envelope `{apiVersion, error, code}` and a rejected `upgrade()` with that
150
+ * `code`. The envelope adds `receipt`, and the thrown AstryxError a `receipt`
151
+ * property: the same `upgrade.run` data a completed run returns, with
152
+ * `complete: false` and `errorCode` equal to the error's `code`. Files in
153
+ * `modifiedFiles` stay changed.
154
+ *
155
+ * @typedef {UpgradeRunResponse['data']} UpgradeFailureReceipt
156
+ */
157
+
145
158
  /**
146
159
  * astryx --json upgrade — short-circuit status results.
147
160
  *
@@ -0,0 +1,205 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The codemod walkers never follow a symbolic link into installed
5
+ * dependencies, a package store or version-control metadata; other linked
6
+ * folders are still scanned, read-only.
7
+ */
8
+
9
+ import {afterEach, beforeEach, describe, expect, it} from 'vitest';
10
+ import * as fs from 'node:fs';
11
+ import * as path from 'node:path';
12
+ import {runCodemods} from '../runner.mjs';
13
+ import {findSourceFiles as findIntegrationSourceFiles} from '../run-codemod.mjs';
14
+
15
+ let tmpDir;
16
+ let originalCwd;
17
+
18
+ beforeEach(() => {
19
+ originalCwd = process.cwd();
20
+ tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-runner-test-'));
21
+ process.chdir(tmpDir);
22
+ });
23
+
24
+ afterEach(() => {
25
+ process.chdir(originalCwd);
26
+ fs.rmSync(tmpDir, {recursive: true, force: true});
27
+ });
28
+
29
+ describe('findSourceFiles — symbolic links into dependency trees', () => {
30
+ const manifests = [
31
+ {
32
+ version: '0.1.3',
33
+ transforms: [
34
+ {
35
+ name: 'p',
36
+ meta: {title: 'p'},
37
+ transform: f => f.source.replace(/foo/g, 'bar'),
38
+ },
39
+ ],
40
+ },
41
+ ];
42
+
43
+ // A tree a symlinked dependency folder points at: a package store outside
44
+ // the project, holding a file the transform would change.
45
+ function seedStore() {
46
+ const store = path.join(tmpDir, 'store', 'node_modules', 'pkg');
47
+ fs.mkdirSync(store, {recursive: true});
48
+ fs.writeFileSync(path.join(store, 'index.ts'), 'const foo = 1;\n');
49
+ fs.mkdirSync(path.join(tmpDir, 'src'), {recursive: true});
50
+ fs.writeFileSync(path.join(tmpDir, 'src', 'real.ts'), 'const foo = 2;\n');
51
+ return store;
52
+ }
53
+
54
+ it('does not descend a symlinked node_modules', async () => {
55
+ const store = seedStore();
56
+ fs.symlinkSync(
57
+ path.dirname(store),
58
+ path.join(tmpDir, 'src', 'node_modules'),
59
+ );
60
+
61
+ const r = await runCodemods(manifests, {
62
+ apply: true,
63
+ path: './src',
64
+ root: tmpDir,
65
+ silent: true,
66
+ });
67
+
68
+ expect(r.writtenFiles.map(f => path.basename(f))).toEqual(['real.ts']);
69
+ expect(r.protectedFiles).toEqual([]);
70
+ expect(
71
+ findIntegrationSourceFiles(path.join(tmpDir, 'src')).map(f =>
72
+ path.relative(tmpDir, f),
73
+ ),
74
+ ).toEqual([path.join('src', 'real.ts')]);
75
+ });
76
+
77
+ it('does not descend a link whose target is inside a dependency tree', async () => {
78
+ const store = seedStore();
79
+ fs.symlinkSync(store, path.join(tmpDir, 'src', 'pkg'));
80
+
81
+ const r = await runCodemods(manifests, {
82
+ apply: true,
83
+ path: './src',
84
+ root: tmpDir,
85
+ silent: true,
86
+ });
87
+
88
+ expect(r.writtenFiles.map(f => path.basename(f))).toEqual(['real.ts']);
89
+ expect(r.protectedFiles).toEqual([]);
90
+ expect(
91
+ findIntegrationSourceFiles(path.join(tmpDir, 'src')).map(f =>
92
+ path.relative(tmpDir, f),
93
+ ),
94
+ ).toEqual([path.join('src', 'real.ts')]);
95
+ });
96
+
97
+ it('does not descend a link into a Yarn cache folder', async () => {
98
+ const cached = path.join(tmpDir, '.yarn', 'cache', 'pkg');
99
+ fs.mkdirSync(cached, {recursive: true});
100
+ fs.writeFileSync(path.join(cached, 'index.ts'), 'const foo = 1;\n');
101
+ fs.mkdirSync(path.join(tmpDir, 'src'), {recursive: true});
102
+ fs.writeFileSync(path.join(tmpDir, 'src', 'real.ts'), 'const foo = 2;\n');
103
+ fs.symlinkSync(cached, path.join(tmpDir, 'src', 'pkg'));
104
+
105
+ const r = await runCodemods(manifests, {
106
+ apply: true,
107
+ path: '.',
108
+ root: tmpDir,
109
+ silent: true,
110
+ });
111
+
112
+ expect(r.writtenFiles.map(f => path.basename(f))).toEqual(['real.ts']);
113
+ expect(r.protectedFiles).toEqual([]);
114
+ expect(
115
+ findIntegrationSourceFiles(tmpDir).map(f => path.relative(tmpDir, f)),
116
+ ).toEqual([path.join('src', 'real.ts')]);
117
+ });
118
+
119
+ it('still descends ordinary symlinked directories in a project below a node_modules folder', async () => {
120
+ const project = path.join(tmpDir, 'node_modules', 'consumer');
121
+ const shared = path.join(project, 'shared');
122
+ fs.mkdirSync(path.join(project, 'src'), {recursive: true});
123
+ fs.mkdirSync(shared, {recursive: true});
124
+ fs.writeFileSync(path.join(shared, 'nested.ts'), 'const foo = 1;\n');
125
+ fs.symlinkSync(shared, path.join(project, 'src', 'linked'));
126
+
127
+ const r = await runCodemods(manifests, {
128
+ apply: true,
129
+ path: path.join(project, 'src'),
130
+ root: project,
131
+ silent: true,
132
+ });
133
+
134
+ expect(r.protectedFiles).toEqual([
135
+ expect.objectContaining({
136
+ file: 'src/linked/nested.ts',
137
+ reason: 'symlink',
138
+ }),
139
+ ]);
140
+ expect(
141
+ findIntegrationSourceFiles(path.join(project, 'src'), project).map(f =>
142
+ path.relative(project, f),
143
+ ),
144
+ ).toEqual([path.join('src', 'linked', 'nested.ts')]);
145
+ });
146
+
147
+ it('does not descend a link into a Yarn cache outside the project', async () => {
148
+ const project = path.join(tmpDir, 'project');
149
+ const cached = path.join(tmpDir, 'other-project', '.yarn', 'cache', 'pkg');
150
+ fs.mkdirSync(cached, {recursive: true});
151
+ fs.writeFileSync(path.join(cached, 'index.ts'), 'const foo = 1;\n');
152
+ fs.mkdirSync(path.join(project, 'src'), {recursive: true});
153
+ fs.writeFileSync(path.join(project, 'src', 'real.ts'), 'const foo = 2;\n');
154
+ fs.symlinkSync(
155
+ path.join('..', '..', 'other-project', '.yarn', 'cache', 'pkg'),
156
+ path.join(project, 'src', 'pkg'),
157
+ );
158
+
159
+ const r = await runCodemods(manifests, {
160
+ apply: true,
161
+ path: path.join(project, 'src'),
162
+ root: project,
163
+ silent: true,
164
+ });
165
+
166
+ expect(r.writtenFiles.map(f => path.basename(f))).toEqual(['real.ts']);
167
+ expect(r.protectedFiles).toEqual([]);
168
+ expect(
169
+ findIntegrationSourceFiles(path.join(project, 'src')).map(f =>
170
+ path.relative(project, f),
171
+ ),
172
+ ).toEqual([path.join('src', 'real.ts')]);
173
+ expect(fs.readFileSync(path.join(cached, 'index.ts'), 'utf-8')).toBe(
174
+ 'const foo = 1;\n',
175
+ );
176
+ });
177
+
178
+ it('does not descend a link from a project below node_modules to a sibling dependency', async () => {
179
+ const project = path.join(tmpDir, 'node_modules', 'consumer');
180
+ const sibling = path.join(tmpDir, 'node_modules', 'dep');
181
+ fs.mkdirSync(path.join(project, 'src'), {recursive: true});
182
+ fs.mkdirSync(sibling, {recursive: true});
183
+ fs.writeFileSync(path.join(sibling, 'index.ts'), 'const foo = 1;\n');
184
+ fs.writeFileSync(path.join(project, 'src', 'real.ts'), 'const foo = 2;\n');
185
+ fs.symlinkSync(sibling, path.join(project, 'src', 'dep'));
186
+
187
+ const r = await runCodemods(manifests, {
188
+ apply: true,
189
+ path: path.join(project, 'src'),
190
+ root: project,
191
+ silent: true,
192
+ });
193
+
194
+ expect(r.writtenFiles.map(f => path.basename(f))).toEqual(['real.ts']);
195
+ expect(r.protectedFiles).toEqual([]);
196
+ expect(
197
+ findIntegrationSourceFiles(path.join(project, 'src'), project).map(f =>
198
+ path.relative(project, f),
199
+ ),
200
+ ).toEqual([path.join('src', 'real.ts')]);
201
+ expect(fs.readFileSync(path.join(sibling, 'index.ts'), 'utf-8')).toBe(
202
+ 'const foo = 1;\n',
203
+ );
204
+ });
205
+ });