@homepages/concrete 1.0.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 (327) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +174 -0
  3. package/codemods/manifest.json +9 -0
  4. package/dist/artifact/playground/client/assets/index-BSA1yutg.css +1 -0
  5. package/dist/artifact/playground/client/assets/index-JloQyj8h.js +1101 -0
  6. package/dist/artifact/playground/client/index.html +13 -0
  7. package/dist/artifact/playground/client/island-canvas-host.mjs +1 -0
  8. package/dist/artifact/playground/host.mjs +127 -0
  9. package/dist/asset-modules.d.ts +99 -0
  10. package/dist/base.css +220 -0
  11. package/dist/browser/site-config.d.ts +18 -0
  12. package/dist/browser/site-config.js +56 -0
  13. package/dist/browser/submit-lead.d.ts +98 -0
  14. package/dist/browser/submit-lead.js +188 -0
  15. package/dist/browser.d.ts +3 -0
  16. package/dist/browser.js +4 -0
  17. package/dist/cli/build/artifact.js +225 -0
  18. package/dist/cli/build/captures.js +67 -0
  19. package/dist/cli/build/esbuild.js +127 -0
  20. package/dist/cli/build/fixtures.js +96 -0
  21. package/dist/cli/build/icons.js +76 -0
  22. package/dist/cli/build/index.js +38 -0
  23. package/dist/cli/build/playground.js +31 -0
  24. package/dist/cli/build/sections.js +236 -0
  25. package/dist/cli/build/source.js +62 -0
  26. package/dist/cli/build/static.js +156 -0
  27. package/dist/cli/capture/bundle.js +37 -0
  28. package/dist/cli/capture/capture-browser.js +51 -0
  29. package/dist/cli/capture/capture.js +121 -0
  30. package/dist/cli/check/analyze.js +95 -0
  31. package/dist/cli/check/index.js +19 -0
  32. package/dist/cli/check/load-workspace.js +119 -0
  33. package/dist/cli/check/messages.js +16 -0
  34. package/dist/cli/check/render/class-conflicts.js +39 -0
  35. package/dist/cli/check/render/html.js +86 -0
  36. package/dist/cli/check/render/inputs.js +53 -0
  37. package/dist/cli/check/render/invariants.js +58 -0
  38. package/dist/cli/check/render/island-frames.js +72 -0
  39. package/dist/cli/check/render/marker-coverage.js +102 -0
  40. package/dist/cli/check/render/nav.js +64 -0
  41. package/dist/cli/check/report.js +73 -0
  42. package/dist/cli/check/stages/bundles.js +129 -0
  43. package/dist/cli/check/stages/composition.js +67 -0
  44. package/dist/cli/check/stages/contracts.js +22 -0
  45. package/dist/cli/check/stages/dependencies.js +261 -0
  46. package/dist/cli/check/stages/fixtures.js +74 -0
  47. package/dist/cli/check/stages/lint.js +41 -0
  48. package/dist/cli/check/stages/logic.js +63 -0
  49. package/dist/cli/check/stages/render.js +144 -0
  50. package/dist/cli/check/stages/sections.js +83 -0
  51. package/dist/cli/check/stages/stylesheet.js +31 -0
  52. package/dist/cli/check/stages/typecheck.js +68 -0
  53. package/dist/cli/check/stages/workspace.js +26 -0
  54. package/dist/cli/commands.js +342 -0
  55. package/dist/cli/currency/cache.js +89 -0
  56. package/dist/cli/currency/decide.js +65 -0
  57. package/dist/cli/currency/opt-out.js +16 -0
  58. package/dist/cli/currency/preamble.js +183 -0
  59. package/dist/cli/currency/prompt.js +28 -0
  60. package/dist/cli/currency/refresh.js +44 -0
  61. package/dist/cli/currency/resolve-latest.js +185 -0
  62. package/dist/cli/currency/version-order.js +38 -0
  63. package/dist/cli/dev/crop.js +22 -0
  64. package/dist/cli/dev/hmr.js +26 -0
  65. package/dist/cli/dev/http.js +129 -0
  66. package/dist/cli/dev/index.js +70 -0
  67. package/dist/cli/dev/islands.js +390 -0
  68. package/dist/cli/dev/load-template.js +46 -0
  69. package/dist/cli/dev/request-error.js +22 -0
  70. package/dist/cli/dev/server.js +307 -0
  71. package/dist/cli/dev/tsconfig-paths.js +95 -0
  72. package/dist/cli/dev/vite.js +85 -0
  73. package/dist/cli/dev/workspace-reader.js +274 -0
  74. package/dist/cli/io.d.ts +14 -0
  75. package/dist/cli/media/cache.js +125 -0
  76. package/dist/cli/media/derive.js +252 -0
  77. package/dist/cli/media/deriver-plugin.js +71 -0
  78. package/dist/cli/property/index.js +180 -0
  79. package/dist/cli/property/library.js +137 -0
  80. package/dist/cli/publish/client.js +119 -0
  81. package/dist/cli/publish/freshness.js +66 -0
  82. package/dist/cli/publish/git.js +43 -0
  83. package/dist/cli/publish/index.js +207 -0
  84. package/dist/cli/publish/pack.js +78 -0
  85. package/dist/cli/publish/report.js +98 -0
  86. package/dist/cli/publish/target.js +87 -0
  87. package/dist/cli/publish/wire.js +29 -0
  88. package/dist/cli/tar.js +87 -0
  89. package/dist/cli/upgrade/codemod.js +56 -0
  90. package/dist/cli/upgrade/index.js +263 -0
  91. package/dist/cli/upgrade/manifest.js +72 -0
  92. package/dist/cli/upgrade/plan.js +68 -0
  93. package/dist/cli/upgrade/stage.js +71 -0
  94. package/dist/cli/version.d.ts +12 -0
  95. package/dist/cli/version.js +15 -0
  96. package/dist/cli/workspace.js +108 -0
  97. package/dist/cli.d.ts +6 -0
  98. package/dist/cli.js +94 -0
  99. package/dist/css/compile.js +77 -0
  100. package/dist/css/graph.js +109 -0
  101. package/dist/css/inline.js +132 -0
  102. package/dist/css/rules.js +65 -0
  103. package/dist/design-system/format-variants.js +127 -0
  104. package/dist/eslint/authoring.js +46 -0
  105. package/dist/eslint/correctness.js +42 -0
  106. package/dist/eslint/rules/editor-declaration.js +103 -0
  107. package/dist/eslint/rules/editor-reason.js +135 -0
  108. package/dist/eslint/rules/island-imports.js +20 -0
  109. package/dist/eslint/rules/jsx-visitor.js +20 -0
  110. package/dist/eslint/rules/no-client-runtime.js +88 -0
  111. package/dist/eslint/rules/no-editor-globals.js +60 -0
  112. package/dist/eslint/rules/no-hard-coded-color.js +183 -0
  113. package/dist/eslint/rules/no-inline-style.js +24 -0
  114. package/dist/eslint/rules/no-marker-literal.js +37 -0
  115. package/dist/eslint/rules/no-nondeterminism.js +44 -0
  116. package/dist/eslint/rules/no-px-breakpoint.js +44 -0
  117. package/dist/eslint/rules/no-raw-values.js +45 -0
  118. package/dist/eslint/rules/serializable-props.js +95 -0
  119. package/dist/eslint.d.ts +6 -0
  120. package/dist/eslint.js +26 -0
  121. package/dist/fixtures/brand.d.ts +4 -0
  122. package/dist/fixtures/brand.js +9 -0
  123. package/dist/fixtures/bundle-rule.js +67 -0
  124. package/dist/fixtures/canonical.d.ts +149 -0
  125. package/dist/fixtures/image-dimensions.js +59 -0
  126. package/dist/fixtures/load.js +154 -0
  127. package/dist/fixtures/media-plugin.js +141 -0
  128. package/dist/fixtures/media.js +165 -0
  129. package/dist/fixtures/property.js +210 -0
  130. package/dist/fixtures/resolve.js +202 -0
  131. package/dist/fixtures/rows.js +108 -0
  132. package/dist/fixtures/synthesize-empties.js +42 -0
  133. package/dist/fixtures.d.ts +213 -0
  134. package/dist/fixtures.js +37 -0
  135. package/dist/index.d.ts +53 -0
  136. package/dist/index.js +37 -0
  137. package/dist/islands/client-module.js +97 -0
  138. package/dist/islands/marker.d.ts +43 -0
  139. package/dist/islands/marker.js +44 -0
  140. package/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js +687 -0
  141. package/dist/packages/external/concrete/package.js +5 -0
  142. package/dist/packages/internal/fact-interpolation/dist/index.js +22 -0
  143. package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +111 -0
  144. package/dist/packages/internal/fill-bake/dist/display.js +9 -0
  145. package/dist/packages/internal/fill-bake/dist/index.js +6 -0
  146. package/dist/packages/internal/fill-bake/dist/reconcile-cross-section.js +170 -0
  147. package/dist/packages/internal/fill-vocabulary/dist/facts.d.ts +32 -0
  148. package/dist/packages/internal/fill-vocabulary/dist/facts.js +131 -0
  149. package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +73 -0
  150. package/dist/packages/internal/format-geometry/dist/capture.js +404 -0
  151. package/dist/packages/internal/format-geometry/dist/format.d.ts +41 -0
  152. package/dist/packages/internal/format-geometry/dist/geometry.js +58 -0
  153. package/dist/packages/internal/format-geometry/dist/index.js +4 -0
  154. package/dist/packages/internal/image-descriptor/dist/index.d.ts +35 -0
  155. package/dist/packages/internal/image-ladder/dist/crop.js +82 -0
  156. package/dist/packages/internal/image-ladder/dist/encode.js +23 -0
  157. package/dist/packages/internal/image-ladder/dist/index.js +4 -0
  158. package/dist/packages/internal/image-ladder/dist/policy.js +102 -0
  159. package/dist/packages/internal/island-runtime/dist/capture-holds.d.ts +13 -0
  160. package/dist/packages/internal/island-runtime/dist/capture-holds.js +45 -0
  161. package/dist/packages/internal/island-runtime/dist/contract.d.ts +176 -0
  162. package/dist/packages/internal/island-runtime/dist/contract.js +94 -0
  163. package/dist/packages/internal/island-runtime/dist/editor-instance-context.js +15 -0
  164. package/dist/packages/internal/island-runtime/dist/index.d.ts +103 -0
  165. package/dist/packages/internal/island-runtime/dist/index.js +163 -0
  166. package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +19 -0
  167. package/dist/packages/internal/island-runtime/dist/use-capture-ready.js +39 -0
  168. package/dist/packages/internal/island-runtime/dist/use-editor.d.ts +22 -0
  169. package/dist/packages/internal/island-runtime/dist/use-editor.js +54 -0
  170. package/dist/packages/internal/island-runtime/dist/viewport-schedule.js +105 -0
  171. package/dist/packages/internal/property-facts/dist/derive-facts-view.js +25 -0
  172. package/dist/packages/internal/property-facts/dist/index.js +3 -0
  173. package/dist/packages/internal/property-facts/dist/property-facts-CSdkSuD7.js +181 -0
  174. package/dist/packages/internal/section-contracts/dist/cap-contract.js +59 -0
  175. package/dist/packages/internal/section-contracts/dist/catalog.js +102 -0
  176. package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +24 -0
  177. package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +48 -0
  178. package/dist/packages/internal/section-contracts/dist/display-contract.js +30 -0
  179. package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +17 -0
  180. package/dist/packages/internal/section-contracts/dist/group-contract.js +21 -0
  181. package/dist/packages/internal/section-contracts/dist/index.js +26 -0
  182. package/dist/packages/internal/section-contracts/dist/interpolation-contract.js +48 -0
  183. package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +53 -0
  184. package/dist/packages/internal/section-contracts/dist/list-scalar-contract.js +70 -0
  185. package/dist/packages/internal/section-contracts/dist/name-title-contract.js +27 -0
  186. package/dist/packages/internal/section-contracts/dist/nested-slot-contract.js +12 -0
  187. package/dist/packages/internal/section-contracts/dist/option-source-contract.js +22 -0
  188. package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +18 -0
  189. package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +30 -0
  190. package/dist/packages/internal/section-contracts/dist/record-collection-contract.js +24 -0
  191. package/dist/packages/internal/section-contracts/dist/row-contract.js +37 -0
  192. package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +38 -0
  193. package/dist/packages/internal/section-contracts/dist/runners.js +181 -0
  194. package/dist/packages/internal/section-contracts/dist/select-contract.js +28 -0
  195. package/dist/packages/internal/section-contracts/dist/source-contract.js +48 -0
  196. package/dist/packages/internal/section-contracts/dist/source-filter-contract.js +15 -0
  197. package/dist/packages/internal/section-contracts/dist/sources-contract.js +28 -0
  198. package/dist/packages/internal/section-contracts/dist/url-contract.js +20 -0
  199. package/dist/packages/internal/source-resolution/dist/index.js +222 -0
  200. package/dist/packages/internal/template-artifact/dist/hash.js +50 -0
  201. package/dist/packages/internal/template-artifact/dist/index.js +7 -0
  202. package/dist/packages/internal/template-artifact/dist/layout.js +165 -0
  203. package/dist/packages/internal/template-artifact/dist/manifest.js +73 -0
  204. package/dist/packages/internal/template-artifact/dist/sha256.js +138 -0
  205. package/dist/packages/internal/template-artifact/dist/verify.js +275 -0
  206. package/dist/packages/internal/template-contracts/dist/collection-editing.js +38 -0
  207. package/dist/packages/internal/template-contracts/dist/content-categories.d.ts +10 -0
  208. package/dist/packages/internal/template-contracts/dist/content-categories.js +17 -0
  209. package/dist/packages/internal/template-contracts/dist/document-value.d.ts +33 -0
  210. package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +81 -0
  211. package/dist/packages/internal/template-contracts/dist/facts-view.js +136 -0
  212. package/dist/packages/internal/template-contracts/dist/layout.js +17 -0
  213. package/dist/packages/internal/template-contracts/dist/markers.d.ts +40 -0
  214. package/dist/packages/internal/template-contracts/dist/markers.js +41 -0
  215. package/dist/packages/internal/template-contracts/dist/poi-row.d.ts +63 -0
  216. package/dist/packages/internal/template-contracts/dist/select-key.js +13 -0
  217. package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +1112 -0
  218. package/dist/packages/internal/template-contracts/dist/slot-catalog.js +1109 -0
  219. package/dist/packages/internal/template-contracts/dist/slot-overrides.js +11 -0
  220. package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +45 -0
  221. package/dist/packages/internal/template-contracts/dist/video-value.d.ts +63 -0
  222. package/dist/playground/host/page-state.js +12 -0
  223. package/dist/playground/host/paths.js +9 -0
  224. package/dist/playground/layout.js +24 -0
  225. package/dist/playground/wire.js +36 -0
  226. package/dist/playground-island-runtime.d.ts +3 -0
  227. package/dist/playground-island-runtime.js +4 -0
  228. package/dist/primitives/FrameShell.d.ts +29 -0
  229. package/dist/primitives/FrameShell.js +34 -0
  230. package/dist/primitives/Image.d.ts +119 -0
  231. package/dist/primitives/Image.js +173 -0
  232. package/dist/primitives/Section.d.ts +22 -0
  233. package/dist/primitives/Section.js +26 -0
  234. package/dist/primitives/Tour.d.ts +43 -0
  235. package/dist/primitives/Tour.js +72 -0
  236. package/dist/primitives/Video.d.ts +57 -0
  237. package/dist/primitives/Video.js +116 -0
  238. package/dist/primitives/embed-playback.js +50 -0
  239. package/dist/primitives/index.d.ts +11 -0
  240. package/dist/primitives/marker-attrs.js +44 -0
  241. package/dist/primitives/object-fit.js +11 -0
  242. package/dist/primitives/picture-sources.d.ts +24 -0
  243. package/dist/primitives/picture-sources.js +52 -0
  244. package/dist/primitives/probe-context.js +24 -0
  245. package/dist/primitives/slot-bindings.d.ts +96 -0
  246. package/dist/primitives/slot-bindings.js +226 -0
  247. package/dist/primitives/slot-document.d.ts +35 -0
  248. package/dist/primitives/slot-document.js +37 -0
  249. package/dist/primitives/slot-group.d.ts +40 -0
  250. package/dist/primitives/slot-group.js +45 -0
  251. package/dist/primitives/slot-list.d.ts +21 -0
  252. package/dist/primitives/slot-list.js +23 -0
  253. package/dist/primitives/slot-media.d.ts +71 -0
  254. package/dist/primitives/slot-media.js +98 -0
  255. package/dist/primitives/slot-scalar.d.ts +53 -0
  256. package/dist/primitives/slot-scalar.js +98 -0
  257. package/dist/primitives/slot.d.ts +26 -0
  258. package/dist/primitives/slot.js +28 -0
  259. package/dist/rules/registry.js +479 -0
  260. package/dist/schema/compute.d.ts +22 -0
  261. package/dist/schema/compute.js +30 -0
  262. package/dist/schema/define-schema.d.ts +27 -0
  263. package/dist/schema/define-schema.js +73 -0
  264. package/dist/schema/extract-fill-spec.js +246 -0
  265. package/dist/schema/extract-used-facts.js +176 -0
  266. package/dist/schema/fact.d.ts +65 -0
  267. package/dist/schema/fact.js +33 -0
  268. package/dist/schema/fill-builders.d.ts +387 -0
  269. package/dist/schema/fill-builders.js +263 -0
  270. package/dist/schema/fill-declaration.d.ts +76 -0
  271. package/dist/schema/fill-declaration.js +43 -0
  272. package/dist/schema/fill-spec.d.ts +18 -0
  273. package/dist/schema/fill-spec.js +170 -0
  274. package/dist/schema/format-presets.d.ts +27 -0
  275. package/dist/schema/format-presets.js +76 -0
  276. package/dist/schema/format.d.ts +22 -0
  277. package/dist/schema/format.js +40 -0
  278. package/dist/schema/formats.d.ts +6 -0
  279. package/dist/schema/formats.js +7 -0
  280. package/dist/schema/layout.d.ts +32 -0
  281. package/dist/schema/layout.js +30 -0
  282. package/dist/schema/manifest.js +300 -0
  283. package/dist/schema/property-facts.d.ts +83 -0
  284. package/dist/schema/runtime-values.d.ts +88 -0
  285. package/dist/schema/section-nav.d.ts +38 -0
  286. package/dist/schema/section-nav.js +29 -0
  287. package/dist/schema/section-props.d.ts +98 -0
  288. package/dist/schema/section-schema.d.ts +53 -0
  289. package/dist/schema/section-schema.js +54 -0
  290. package/dist/schema/slot-builders.d.ts +497 -0
  291. package/dist/schema/slot-builders.js +331 -0
  292. package/dist/schema/slot-types.d.ts +110 -0
  293. package/dist/schema/slot-types.js +187 -0
  294. package/dist/section/declare.d.ts +44 -0
  295. package/dist/section/declare.js +27 -0
  296. package/dist/section/discovery.js +76 -0
  297. package/dist/section/groups.js +74 -0
  298. package/dist/section/materialize.js +28 -0
  299. package/dist/section/placements.js +28 -0
  300. package/dist/section/section.d.ts +69 -0
  301. package/dist/section/section.js +101 -0
  302. package/dist/site-analytics.d.ts +1 -0
  303. package/dist/site-analytics.js +15 -0
  304. package/dist/site-runtime/analytics.js +97 -0
  305. package/dist/site-runtime/site-integrations.js +97 -0
  306. package/dist/styles.css +60 -0
  307. package/dist/template/define-template.d.ts +139 -0
  308. package/dist/template/define-template.js +98 -0
  309. package/dist/template/logic-build.js +191 -0
  310. package/dist/template/logic-shim.d.ts +43 -0
  311. package/dist/template/logic-shim.js +52 -0
  312. package/dist/template/logic-transform.js +92 -0
  313. package/dist/template/materialize.js +107 -0
  314. package/dist/template/reconcile.d.ts +67 -0
  315. package/dist/template/reconcile.js +25 -0
  316. package/dist/template/running-copy.js +58 -0
  317. package/guide/reference/cli/INDEX.md +79 -0
  318. package/guide/reference/cli/build.md +48 -0
  319. package/guide/reference/cli/check.md +49 -0
  320. package/guide/reference/cli/dev.md +46 -0
  321. package/guide/reference/cli/property-add.md +53 -0
  322. package/guide/reference/cli/property-list.md +46 -0
  323. package/guide/reference/cli/publish.md +54 -0
  324. package/guide/reference/cli/upgrade.md +48 -0
  325. package/guide/reference/rules/INDEX.md +190 -0
  326. package/package.json +137 -0
  327. package/tsconfig.base.json +16 -0
@@ -0,0 +1,263 @@
1
+ import { booleanFlag, findCommand, flagName, parseSpec, stringFlag } from "../commands.js";
2
+ import { CONCRETE_PACKAGE, findWorkspaceRoot, isRegistryRange, readDeclaredRange, resolveInstalledPackageDir, resolveInstalledVersion } from "../workspace.js";
3
+ import { compareVersions, parseVersion } from "../currency/version-order.js";
4
+ import { NO_AUTO_UPDATE_ENV, optedOut } from "../currency/opt-out.js";
5
+ import { runNpm } from "../currency/refresh.js";
6
+ import { resolveLatest, versionExists } from "../currency/resolve-latest.js";
7
+ import { CODEMODS_DIR, MANIFEST_FILE, parseCodemodManifest, stepsBetween } from "./manifest.js";
8
+ import { runCodemod } from "./codemod.js";
9
+ import { planRewrite } from "./plan.js";
10
+ import { stageWithNpmPack } from "./stage.js";
11
+ import { join } from "node:path";
12
+ import { readFile, stat, writeFile } from "node:fs/promises";
13
+ import { parseArgs } from "node:util";
14
+
15
+ //#region src/cli/upgrade/index.ts
16
+ /** Every line this command prints names itself — its output interleaves with npm's. */
17
+ const PREFIX = "concrete upgrade";
18
+ /**
19
+ * How long reading npm's config may take before the registry answer is unknown. Its own
20
+ * deadline, apart from the request's: this is a command the author asked for, not a read
21
+ * in front of every command, and on a loaded box spawning npm alone can outlast the whole
22
+ * two-second budget — which would turn a plain "not published" into a real install that
23
+ * fails in npm's words instead. The request itself still gives up at the usual budget.
24
+ */
25
+ const CONFIG_READ_TIMEOUT_MS = 15e3;
26
+ const defaultUpgradeEnvironment = {
27
+ latest: ({ root, env }) => resolveLatest({
28
+ cwd: root,
29
+ env,
30
+ configTimeoutMs: CONFIG_READ_TIMEOUT_MS
31
+ }),
32
+ exists: (version, { root, env }) => versionExists(version, {
33
+ cwd: root,
34
+ env,
35
+ configTimeoutMs: CONFIG_READ_TIMEOUT_MS
36
+ }),
37
+ install: (request) => runNpm(["install"], request),
38
+ stageTarget: stageWithNpmPack
39
+ };
40
+ function say(stream, text) {
41
+ stream.write(text.endsWith("\n") ? text : `${text}\n`);
42
+ }
43
+ function messageOf(cause) {
44
+ return cause instanceof Error ? cause.message : String(cause);
45
+ }
46
+ async function isFile(path) {
47
+ try {
48
+ return (await stat(path)).isFile();
49
+ } catch {
50
+ return false;
51
+ }
52
+ }
53
+ /**
54
+ * The version to move to, or the exit code when there is none to act on.
55
+ *
56
+ * A `--to` the registry does not carry is a refusal BEFORE anything is written. A registry
57
+ * that cannot be read at all is not: an author offline for the afternoon has nothing to
58
+ * act on, and failing them would only teach them to reach for the kill switch.
59
+ */
60
+ async function resolveTarget(requested, request, environment, io) {
61
+ if (requested === null) {
62
+ const latest = await environment.latest(request);
63
+ if (latest === null || parseVersion(latest) === null) {
64
+ say(io.stderr, `${PREFIX}: could not reach the registry, so there is nothing to compare against. Nothing was changed.`);
65
+ return { code: 0 };
66
+ }
67
+ return { version: latest };
68
+ }
69
+ if (parseVersion(requested) === null) {
70
+ say(io.stderr, `${PREFIX}: --to takes one exact version, e.g. --to 2.0.0. Got: ${requested}`);
71
+ return { code: 1 };
72
+ }
73
+ if (await environment.exists(requested, request) === "absent") {
74
+ say(io.stderr, `${PREFIX}: ${CONCRETE_PACKAGE}@${requested} is not published. Nothing was changed.`);
75
+ return { code: 1 };
76
+ }
77
+ return { version: requested };
78
+ }
79
+ /** The codemod manifest a package directory carries, or throws naming what is wrong. */
80
+ async function readManifestIn(packageDir) {
81
+ let text;
82
+ try {
83
+ text = await readFile(join(packageDir, CODEMODS_DIR, MANIFEST_FILE), "utf8");
84
+ } catch {
85
+ throw new Error(`the package carries no ${CODEMODS_DIR}/${MANIFEST_FILE}, so which codemods to run is unknown`);
86
+ }
87
+ return parseCodemodManifest(text);
88
+ }
89
+ function renderRewrite(rewrite) {
90
+ return ` ${CONCRETE_PACKAGE} ${rewrite.from} -> ${rewrite.to}\n`;
91
+ }
92
+ /** The plan, one release at a time: its codemods in order, then what it leaves to the author. */
93
+ function renderPlan(steps) {
94
+ const lines = [];
95
+ for (const step of steps) {
96
+ if (step.codemods.length === 0 && step.manual.length === 0) continue;
97
+ lines.push(` ${step.version}`, ...step.codemods.map((slug) => ` ${slug}`), ...step.manual.map((m) => ` by hand: ${m}`));
98
+ }
99
+ return lines.length === 0 ? `${PREFIX}: no codemod lies between these versions.\n` : `${PREFIX}: codemods, in the order they run:\n${lines.join("\n")}\n`;
100
+ }
101
+ function renderManual(steps) {
102
+ const manual = steps.flatMap((step) => step.manual.map((m) => ` ${step.version}: ${m}`));
103
+ return manual.length === 0 ? "" : `\n${PREFIX}: still to do by hand — no codemod could make these changes:\n${manual.join("\n")}\n`;
104
+ }
105
+ /**
106
+ * Runs every codemod of every step, in order, reporting each file on stdout. Returns
107
+ * `true` when all ran. A throw stops the chain — every later codemod was written against
108
+ * the tree this one was meant to leave — and is reported on stderr with what never ran.
109
+ */
110
+ async function runSteps(steps, packageDir, root, io) {
111
+ const queue = steps.flatMap((step) => step.codemods.map((slug) => ({
112
+ version: step.version,
113
+ slug
114
+ })));
115
+ for (const [index, { version, slug }] of queue.entries()) {
116
+ say(io.stdout, ` ${version} ${slug}`);
117
+ try {
118
+ const report = await runCodemod(packageDir, slug, root);
119
+ for (const file of report.rewritten) say(io.stdout, ` rewrote ${file}`);
120
+ for (const { file, reason } of report.notRewritten) say(io.stdout, ` could not rewrite ${file}: ${reason}`);
121
+ if (report.rewritten.length === 0 && report.notRewritten.length === 0) say(io.stdout, " nothing to rewrite");
122
+ } catch (cause) {
123
+ const remaining = queue.slice(index + 1).map((entry) => entry.slug);
124
+ say(io.stderr, `${PREFIX}: codemod ${messageOf(cause)}`);
125
+ say(io.stderr, `${PREFIX}: stopped. The package is installed, and the files listed above were already rewritten` + (remaining.length === 0 ? "." : `; these did not run: ${remaining.join(", ")}.`) + ` Restore from version control, or finish the port by hand.`);
126
+ return false;
127
+ }
128
+ }
129
+ return true;
130
+ }
131
+ /** Orders two versions both already known to parse. */
132
+ function isAfter(a, b) {
133
+ const left = parseVersion(a);
134
+ const right = parseVersion(b);
135
+ return left !== null && right !== null && compareVersions(left, right) > 0;
136
+ }
137
+ /** The command, over an injected outside world. `runUpgrade` is it over the real one. */
138
+ function upgradeWith(environment) {
139
+ return async (argv, io) => {
140
+ const command = findCommand("upgrade");
141
+ let values;
142
+ try {
143
+ ({values} = parseArgs({
144
+ args: [...argv],
145
+ ...parseSpec("upgrade")
146
+ }));
147
+ } catch (cause) {
148
+ say(io.stderr, `${PREFIX}: ${messageOf(cause)}\n${PREFIX}: to move to one specific version, pass ${flagName(command, "to")} <version>.`);
149
+ return 1;
150
+ }
151
+ const dryRun = booleanFlag(values, "dry-run");
152
+ if (optedOut(io.env)) {
153
+ say(io.stderr, `${PREFIX}: ${NO_AUTO_UPDATE_ENV} is set, so nothing was changed. Unset it to upgrade.`);
154
+ return 0;
155
+ }
156
+ let root;
157
+ try {
158
+ root = await findWorkspaceRoot(io.cwd);
159
+ } catch (cause) {
160
+ say(io.stderr, `${PREFIX}: ${messageOf(cause)}`);
161
+ return 1;
162
+ }
163
+ const declared = await readDeclaredRange(root);
164
+ if (declared !== null && !isRegistryRange(declared)) {
165
+ say(io.stderr, `${PREFIX}: this workspace installs ${CONCRETE_PACKAGE} from ${declared}, not from the registry. Nothing was changed.`);
166
+ return 0;
167
+ }
168
+ if (!await isFile(join(root, "package-lock.json"))) {
169
+ say(io.stderr, `${PREFIX}: no package-lock.json at the workspace root, so nothing was changed. Run \`npm install\` to create one, then upgrade.`);
170
+ return 0;
171
+ }
172
+ const installed = await resolveInstalledVersion(root);
173
+ if (installed === null || parseVersion(installed) === null) {
174
+ say(io.stderr, `${PREFIX}: ${CONCRETE_PACKAGE} is not installed at the workspace root, so nothing was changed. Run \`npm install\` first.`);
175
+ return 0;
176
+ }
177
+ const request = {
178
+ root,
179
+ env: io.env
180
+ };
181
+ const target = await resolveTarget(stringFlag(values, "to"), request, environment, io);
182
+ if (!("version" in target)) return target.code;
183
+ const manifestPath = join(root, "package.json");
184
+ const before = await readFile(manifestPath, "utf8");
185
+ let plan;
186
+ try {
187
+ plan = planRewrite(before, target.version);
188
+ } catch (cause) {
189
+ say(io.stderr, `${PREFIX}: ${messageOf(cause)}`);
190
+ return 1;
191
+ }
192
+ if (plan.rewrite === null && installed === target.version) {
193
+ say(io.stdout, `${PREFIX}: already on ${target.version}.`);
194
+ return 0;
195
+ }
196
+ const forward = isAfter(target.version, installed);
197
+ say(io.stdout, `${PREFIX}: moving this workspace from ${installed} to ${target.version}\n`);
198
+ if (plan.rewrite !== null) say(io.stdout, renderRewrite(plan.rewrite));
199
+ if (!forward) say(io.stdout, `${PREFIX}: that is not forward, and no codemod runs backward — only the package moves.`);
200
+ if (dryRun) {
201
+ if (forward) {
202
+ let staged;
203
+ try {
204
+ staged = await environment.stageTarget(target.version, {
205
+ ...request,
206
+ sink: io.stderr
207
+ });
208
+ const steps = stepsBetween(await readManifestIn(staged.dir), installed, target.version);
209
+ say(io.stdout, renderPlan(steps));
210
+ } catch (cause) {
211
+ say(io.stderr, `${PREFIX}: could not read ${target.version}'s codemods (${messageOf(cause)}), so the plan is incomplete.`);
212
+ return 1;
213
+ } finally {
214
+ await staged?.dispose();
215
+ }
216
+ }
217
+ say(io.stdout, `${PREFIX}: --dry-run, so nothing was written or installed. Re-run without it to apply.`);
218
+ return 0;
219
+ }
220
+ if (plan.rewrite !== null) await writeFile(manifestPath, plan.manifest, "utf8");
221
+ const failure = await environment.install({
222
+ ...request,
223
+ sink: io.stderr
224
+ });
225
+ if (failure !== null) {
226
+ let restored = true;
227
+ try {
228
+ await writeFile(manifestPath, before, "utf8");
229
+ } catch {
230
+ restored = false;
231
+ }
232
+ say(io.stderr, `${PREFIX}: ${failure}\n` + (restored ? `${PREFIX}: package.json has been put back the way it was, and no codemod ran.` : `${PREFIX}: package.json could NOT be put back — its range now names ${target.version}. No codemod ran.`));
233
+ return 1;
234
+ }
235
+ const landed = await resolveInstalledVersion(root);
236
+ const packageDir = resolveInstalledPackageDir(root);
237
+ if (landed === null || packageDir === null || parseVersion(landed) === null) {
238
+ say(io.stderr, `${PREFIX}: the install finished but ${CONCRETE_PACKAGE} does not resolve from the workspace root, so no codemod ran.`);
239
+ return 1;
240
+ }
241
+ const done = `${PREFIX}: done — this workspace is on ${landed}. Commit package.json, package-lock.json and every rewritten file together.`;
242
+ if (!isAfter(landed, installed)) {
243
+ say(io.stdout, done);
244
+ return 0;
245
+ }
246
+ let steps;
247
+ try {
248
+ steps = stepsBetween(await readManifestIn(packageDir), installed, landed);
249
+ } catch (cause) {
250
+ say(io.stderr, `${PREFIX}: ${landed} is installed, but ${messageOf(cause)}. No codemod ran.`);
251
+ return 1;
252
+ }
253
+ if (steps.some((step) => step.codemods.length > 0)) say(io.stdout, `${PREFIX}: running codemods, in order:`);
254
+ if (!await runSteps(steps, packageDir, root, io)) return 1;
255
+ const manual = renderManual(steps);
256
+ say(io.stdout, manual === "" ? done : `${manual}\n${done}`);
257
+ return 0;
258
+ };
259
+ }
260
+ const runUpgrade = upgradeWith(defaultUpgradeEnvironment);
261
+
262
+ //#endregion
263
+ export { defaultUpgradeEnvironment, runUpgrade, upgradeWith };
@@ -0,0 +1,72 @@
1
+ import { compareVersions, parseVersion } from "../currency/version-order.js";
2
+ import { z } from "zod";
3
+
4
+ //#region src/cli/upgrade/manifest.ts
5
+ /** The manifest format this reader understands. A file naming another number is refused. */
6
+ const MANIFEST_SCHEMA = 1;
7
+ /** Where the manifest and the codemods live, relative to the package root. Shipped. */
8
+ const CODEMODS_DIR = "codemods";
9
+ const MANIFEST_FILE = "manifest.json";
10
+ const ENTRY_SCHEMA = z.object({
11
+ codemods: z.array(z.string().regex(/^[a-z0-9][a-z0-9-]*$/, "a codemod slug is a file name: lowercase letters, digits and dashes")),
12
+ manual: z.array(z.string()).default([])
13
+ });
14
+ const MANIFEST_ZOD = z.object({
15
+ schema: z.literal(1),
16
+ versions: z.record(z.string().refine((v) => parseVersion(v) !== null, { message: "a version key must be an exact semver version" }), ENTRY_SCHEMA)
17
+ });
18
+ function valueAt(root, path) {
19
+ let at = root;
20
+ for (const key of path) {
21
+ if (typeof at !== "object" || at === null) return void 0;
22
+ at = at[key];
23
+ }
24
+ return at;
25
+ }
26
+ /**
27
+ * Parses the manifest text, refusing with a sentence that names what is wrong. A
28
+ * manifest this reader cannot trust is not a manifest with no codemods — acting on
29
+ * either as though it were the other would silently skip a migration.
30
+ */
31
+ function parseCodemodManifest(text) {
32
+ let raw;
33
+ try {
34
+ raw = JSON.parse(text);
35
+ } catch (cause) {
36
+ throw new Error(`the codemod manifest is not valid JSON: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
37
+ }
38
+ const parsed = MANIFEST_ZOD.safeParse(raw);
39
+ if (!parsed.success) {
40
+ const issue = parsed.error.issues[0];
41
+ const path = issue?.path ?? [];
42
+ const where = path.length > 0 ? ` at ${path.map(String).join(".")}` : "";
43
+ const offending = valueAt(raw, path);
44
+ const got = typeof offending === "string" ? ` (got "${offending}")` : "";
45
+ const detail = issue?.message ?? "not the shape of a manifest";
46
+ throw new Error(`the codemod manifest is not readable${where}: ${detail}${got}. This reader understands schema ${String(1)}.`);
47
+ }
48
+ return parsed.data;
49
+ }
50
+ /**
51
+ * Every release strictly above `installed` and up to and including `target`, in
52
+ * ascending version order. Empty when the move is backward or nowhere: a codemod ports
53
+ * a workspace forward across the break it shipped with and has no inverse.
54
+ */
55
+ function stepsBetween(manifest, installed, target) {
56
+ const low = parseVersion(installed);
57
+ const high = parseVersion(target);
58
+ if (low === null || high === null) return [];
59
+ const inRange = (v) => compareVersions(v, low) > 0 && compareVersions(v, high) <= 0;
60
+ return Object.entries(manifest.versions).map(([version, entry]) => ({
61
+ version,
62
+ parsed: parseVersion(version),
63
+ entry
64
+ })).filter((row) => row.parsed !== null && inRange(row.parsed)).sort((a, b) => compareVersions(a.parsed, b.parsed)).map(({ version, entry }) => ({
65
+ version,
66
+ codemods: entry.codemods,
67
+ manual: entry.manual
68
+ }));
69
+ }
70
+
71
+ //#endregion
72
+ export { CODEMODS_DIR, MANIFEST_FILE, parseCodemodManifest, stepsBetween };
@@ -0,0 +1,68 @@
1
+ import { CONCRETE_PACKAGE, DEPENDENCY_SECTIONS, isRegistryRange } from "../workspace.js";
2
+
3
+ //#region src/cli/upgrade/plan.ts
4
+ /**
5
+ * The dependency RANGE to stamp for the package at `version`.
6
+ *
7
+ * A release gets a caret so a later patch is picked up by the preamble's refresh
8
+ * without another upgrade. A prerelease is pinned EXACTLY: a caret over one would let
9
+ * npm resolve onto a later prerelease than the one the author asked for. The scaffolder
10
+ * stamps a fresh workspace by this same rule, so an upgraded workspace and a newly
11
+ * created one on the same version carry the same manifest.
12
+ */
13
+ function rangeFor(version) {
14
+ return version.includes("-") ? version : `^${version}`;
15
+ }
16
+ /** The indentation the file already uses, so the rewrite is a diff of the range only. */
17
+ function detectIndent(text) {
18
+ return /\n([ \t]+)"/.exec(text)?.[1] ?? 2;
19
+ }
20
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
21
+ /**
22
+ * What moving this workspace to `targetVersion` would rewrite.
23
+ *
24
+ * Throws when the text is not a JSON object or declares the package in no dependency
25
+ * block — the caller found the workspace root BY that declaration, so either is a
26
+ * manifest that changed under it, and rewriting half of it would be worse than stopping.
27
+ */
28
+ function planRewrite(manifestText, targetVersion) {
29
+ let parsed;
30
+ try {
31
+ parsed = JSON.parse(manifestText);
32
+ } catch (cause) {
33
+ throw new Error(`package.json is not valid JSON: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
34
+ }
35
+ if (!isRecord(parsed)) throw new Error("package.json does not hold a JSON object.");
36
+ const target = rangeFor(targetVersion);
37
+ for (const section of DEPENDENCY_SECTIONS) {
38
+ const block = parsed[section];
39
+ if (!isRecord(block)) continue;
40
+ const spec = block[CONCRETE_PACKAGE];
41
+ if (typeof spec !== "string") continue;
42
+ if (!isRegistryRange(spec)) return {
43
+ rewrite: null,
44
+ skipped: spec,
45
+ manifest: manifestText
46
+ };
47
+ if (spec === target) return {
48
+ rewrite: null,
49
+ skipped: null,
50
+ manifest: manifestText
51
+ };
52
+ block[CONCRETE_PACKAGE] = target;
53
+ const serialized = JSON.stringify(parsed, null, detectIndent(manifestText));
54
+ return {
55
+ rewrite: {
56
+ section,
57
+ from: spec,
58
+ to: target
59
+ },
60
+ skipped: null,
61
+ manifest: manifestText.endsWith("\n") ? `${serialized}\n` : serialized
62
+ };
63
+ }
64
+ throw new Error(`package.json does not depend on ${CONCRETE_PACKAGE}, so there is no range to move.`);
65
+ }
66
+
67
+ //#endregion
68
+ export { planRewrite, rangeFor };
@@ -0,0 +1,71 @@
1
+ import { CONCRETE_PACKAGE } from "../workspace.js";
2
+ import { readTarball } from "../tar.js";
3
+ import { CODEMODS_DIR } from "./manifest.js";
4
+ import { dirname, join } from "node:path";
5
+ import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
6
+ import { spawn } from "node:child_process";
7
+ import { tmpdir } from "node:os";
8
+
9
+ //#region src/cli/upgrade/stage.ts
10
+ function npmPack(version, destination, request) {
11
+ return new Promise((resolve) => {
12
+ let child;
13
+ try {
14
+ child = spawn("npm", [
15
+ "pack",
16
+ `${CONCRETE_PACKAGE}@${version}`,
17
+ "--pack-destination",
18
+ destination,
19
+ "--ignore-scripts"
20
+ ], {
21
+ cwd: request.root,
22
+ env: { ...request.env },
23
+ stdio: [
24
+ "ignore",
25
+ "pipe",
26
+ "pipe"
27
+ ],
28
+ shell: process.platform === "win32"
29
+ });
30
+ } catch (cause) {
31
+ resolve(cause instanceof Error ? cause.message : String(cause));
32
+ return;
33
+ }
34
+ child.stdout.pipe(request.sink, { end: false });
35
+ child.stderr.pipe(request.sink, { end: false });
36
+ child.once("error", (cause) => resolve(cause.message));
37
+ child.once("close", (code) => resolve(code === 0 ? null : `npm pack exited ${String(code)}`));
38
+ });
39
+ }
40
+ /** Fetches `@homepages/concrete@<version>` and lays out its manifest and codemods. */
41
+ async function stageWithNpmPack(version, request) {
42
+ const scratch = await mkdtemp(join(tmpdir(), "concrete-upgrade-target-"));
43
+ const dispose = () => rm(scratch, {
44
+ recursive: true,
45
+ force: true
46
+ });
47
+ try {
48
+ const failure = await npmPack(version, scratch, request);
49
+ if (failure !== null) throw new Error(failure);
50
+ const tarball = (await readdir(scratch)).find((file) => file.endsWith(".tgz"));
51
+ if (tarball === void 0) throw new Error("npm pack wrote no tarball");
52
+ const keep = (path) => path === "package.json" || path.startsWith(`${"codemods"}/`);
53
+ const files = readTarball(await readFile(join(scratch, tarball))).filter((file) => keep(file.path));
54
+ const dir = join(scratch, "package");
55
+ for (const file of files) {
56
+ const target = join(dir, ...file.path.split("/"));
57
+ await mkdir(dirname(target), { recursive: true });
58
+ await writeFile(target, file.body);
59
+ }
60
+ return {
61
+ dir,
62
+ dispose
63
+ };
64
+ } catch (cause) {
65
+ await dispose();
66
+ throw cause;
67
+ }
68
+ }
69
+
70
+ //#endregion
71
+ export { stageWithNpmPack };
@@ -0,0 +1,12 @@
1
+ //#region src/cli/version.d.ts
2
+ /**
3
+ * The published version of this package, as the `concrete` command reports it.
4
+ *
5
+ * Read from package.json and inlined at build time, so it cannot drift: changesets
6
+ * owns package.json's version, and a hardcoded constant here would have to be
7
+ * hand-edited on every release. `dist/cli.js --version` is asserted against
8
+ * package.json to prove the inlining actually happened.
9
+ */
10
+ declare const CONCRETE_CLI_VERSION: string;
11
+ //#endregion
12
+ export { CONCRETE_CLI_VERSION };
@@ -0,0 +1,15 @@
1
+ import { version } from "../packages/external/concrete/package.js";
2
+
3
+ //#region src/cli/version.ts
4
+ /**
5
+ * The published version of this package, as the `concrete` command reports it.
6
+ *
7
+ * Read from package.json and inlined at build time, so it cannot drift: changesets
8
+ * owns package.json's version, and a hardcoded constant here would have to be
9
+ * hand-edited on every release. `dist/cli.js --version` is asserted against
10
+ * package.json to prove the inlining actually happened.
11
+ */
12
+ const CONCRETE_CLI_VERSION = version;
13
+
14
+ //#endregion
15
+ export { CONCRETE_CLI_VERSION };
@@ -0,0 +1,108 @@
1
+ import { dirname, join, resolve } from "node:path";
2
+ import { pathToFileURL } from "node:url";
3
+ import { readFile, stat } from "node:fs/promises";
4
+ import { createRequire } from "node:module";
5
+
6
+ //#region src/cli/workspace.ts
7
+ /** The package a workspace depends on — the one thing that makes it a workspace. */
8
+ const CONCRETE_PACKAGE = "@homepages/concrete";
9
+ /**
10
+ * The blocks npm resolves a version range from. `peerDependencies` is not one of them
11
+ * in a template workspace — nothing there declares a peer.
12
+ */
13
+ const DEPENDENCY_SECTIONS = [
14
+ "dependencies",
15
+ "devDependencies",
16
+ "optionalDependencies"
17
+ ];
18
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
19
+ /** The range a manifest declares for the package, or `null` when it declares none. */
20
+ function declaredRange(manifest) {
21
+ if (!isRecord(manifest)) return null;
22
+ for (const section of DEPENDENCY_SECTIONS) {
23
+ const block = manifest[section];
24
+ if (!isRecord(block)) continue;
25
+ const range = block[CONCRETE_PACKAGE];
26
+ if (typeof range === "string") return range;
27
+ }
28
+ return null;
29
+ }
30
+ /**
31
+ * Whether a declared range resolves from the registry at all.
32
+ *
33
+ * `workspace:*`, `file:`, `link:`, a git or tarball URL — every one of these names an
34
+ * install the registry knows nothing about, so no published version can be "ahead" of
35
+ * it. The internal templates in the framework's own repository ride `workspace:*`,
36
+ * and this is what keeps the currency preamble inert for them.
37
+ */
38
+ function isRegistryRange(range) {
39
+ return !/^[a-z][a-z0-9+.-]*:/i.test(range.trim());
40
+ }
41
+ async function isFile(path) {
42
+ try {
43
+ return (await stat(path)).isFile();
44
+ } catch {
45
+ return false;
46
+ }
47
+ }
48
+ async function readManifest(dir) {
49
+ const path = join(dir, "package.json");
50
+ if (!await isFile(path)) return void 0;
51
+ try {
52
+ return JSON.parse(await readFile(path, "utf8"));
53
+ } catch {
54
+ return;
55
+ }
56
+ }
57
+ /**
58
+ * The nearest ancestor of `from` (inclusive) whose package.json depends on the
59
+ * package. Throws, with the fix, when there is none.
60
+ */
61
+ async function findWorkspaceRoot(from) {
62
+ let dir = resolve(from);
63
+ for (;;) {
64
+ if (declaredRange(await readManifest(dir)) !== null) return dir;
65
+ const parent = dirname(dir);
66
+ if (parent === dir) throw new Error(`not inside a workspace — no parent directory has a package.json that depends on ${CONCRETE_PACKAGE}.\nRun this from your workspace root, or create one with \`npm create @homepages/concrete\`.`);
67
+ dir = parent;
68
+ }
69
+ }
70
+ /** The range `<root>/package.json` declares for the package, or `null`. Never throws. */
71
+ async function readDeclaredRange(root) {
72
+ return declaredRange(await readManifest(root));
73
+ }
74
+ /**
75
+ * The directory of the package this workspace's own `node_modules` resolves — resolved
76
+ * from `root` rather than from whatever copy the running process's own module graph
77
+ * happens to be. Run through `npx` or a global install, that can be a different install
78
+ * entirely: the command's own copy, not this workspace's.
79
+ *
80
+ * `null` when nothing is installed there — the command that needs it owes the author
81
+ * that error in its own words.
82
+ */
83
+ function resolveInstalledPackageDir(root) {
84
+ const require = createRequire(pathToFileURL(join(root, "package.json")));
85
+ try {
86
+ return dirname(require.resolve(`${CONCRETE_PACKAGE}/package.json`));
87
+ } catch {
88
+ return null;
89
+ }
90
+ }
91
+ /**
92
+ * The version of the package this workspace's own `node_modules` actually resolves,
93
+ * read straight off the installed package's manifest (`resolveInstalledPackageDir`).
94
+ * `null` when nothing is installed there, or its manifest names no version.
95
+ */
96
+ async function resolveInstalledVersion(root) {
97
+ const dir = resolveInstalledPackageDir(root);
98
+ if (dir === null) return null;
99
+ try {
100
+ const parsed = JSON.parse(await readFile(join(dir, "package.json"), "utf8"));
101
+ return isRecord(parsed) && typeof parsed.version === "string" ? parsed.version : null;
102
+ } catch {
103
+ return null;
104
+ }
105
+ }
106
+
107
+ //#endregion
108
+ export { CONCRETE_PACKAGE, DEPENDENCY_SECTIONS, declaredRange, findWorkspaceRoot, isRegistryRange, readDeclaredRange, resolveInstalledPackageDir, resolveInstalledVersion };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { CliIo } from "./cli/io.js";
2
+ import { CONCRETE_CLI_VERSION } from "./cli/version.js";
3
+ //#region src/cli/index.d.ts
4
+ declare function main(argv: readonly string[], io: CliIo): Promise<number>;
5
+ //#endregion
6
+ export { CONCRETE_CLI_VERSION, main };