@savvy-web/silk 2.0.0 → 2.1.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 (155) hide show
  1. package/README.md +7 -5
  2. package/changesets-changelog.cjs +10 -4
  3. package/changesets-changelog.js +54057 -1
  4. package/changesets-markdownlint.cjs +10 -4
  5. package/changesets-markdownlint.js +54057 -1
  6. package/package.json +5 -4
  7. package/tsconfig/node/dist/tsconfig.tsbuildinfo +1 -1
  8. package/_virtual/_rolldown/runtime.cjs +0 -45
  9. package/_virtual/_rolldown/runtime.js +0 -45
  10. package/packages/silk-effects/dist/dev/pkg/_virtual/_rolldown/runtime.cjs +0 -15
  11. package/packages/silk-effects/dist/dev/pkg/_virtual/_rolldown/runtime.js +0 -14
  12. package/packages/silk-effects/dist/dev/pkg/changesets/api/categories.cjs +0 -247
  13. package/packages/silk-effects/dist/dev/pkg/changesets/api/categories.js +0 -247
  14. package/packages/silk-effects/dist/dev/pkg/changesets/api/changelog.cjs +0 -134
  15. package/packages/silk-effects/dist/dev/pkg/changesets/api/changelog.js +0 -134
  16. package/packages/silk-effects/dist/dev/pkg/changesets/api/dependency-table.cjs +0 -163
  17. package/packages/silk-effects/dist/dev/pkg/changesets/api/dependency-table.js +0 -163
  18. package/packages/silk-effects/dist/dev/pkg/changesets/api/linter.cjs +0 -170
  19. package/packages/silk-effects/dist/dev/pkg/changesets/api/linter.js +0 -170
  20. package/packages/silk-effects/dist/dev/pkg/changesets/api/transformer.cjs +0 -134
  21. package/packages/silk-effects/dist/dev/pkg/changesets/api/transformer.js +0 -134
  22. package/packages/silk-effects/dist/dev/pkg/changesets/categories/index.cjs +0 -317
  23. package/packages/silk-effects/dist/dev/pkg/changesets/categories/index.js +0 -299
  24. package/packages/silk-effects/dist/dev/pkg/changesets/categories/types.cjs +0 -65
  25. package/packages/silk-effects/dist/dev/pkg/changesets/categories/types.js +0 -65
  26. package/packages/silk-effects/dist/dev/pkg/changesets/changelog/formatting.cjs +0 -114
  27. package/packages/silk-effects/dist/dev/pkg/changesets/changelog/formatting.js +0 -113
  28. package/packages/silk-effects/dist/dev/pkg/changesets/changelog/getDependencyReleaseLine.cjs +0 -118
  29. package/packages/silk-effects/dist/dev/pkg/changesets/changelog/getDependencyReleaseLine.js +0 -118
  30. package/packages/silk-effects/dist/dev/pkg/changesets/changelog/getReleaseLine.cjs +0 -122
  31. package/packages/silk-effects/dist/dev/pkg/changesets/changelog/getReleaseLine.js +0 -122
  32. package/packages/silk-effects/dist/dev/pkg/changesets/changelog/index.cjs +0 -97
  33. package/packages/silk-effects/dist/dev/pkg/changesets/changelog/index.js +0 -97
  34. package/packages/silk-effects/dist/dev/pkg/changesets/constants.cjs +0 -43
  35. package/packages/silk-effects/dist/dev/pkg/changesets/constants.js +0 -42
  36. package/packages/silk-effects/dist/dev/pkg/changesets/errors.cjs +0 -386
  37. package/packages/silk-effects/dist/dev/pkg/changesets/errors.js +0 -371
  38. package/packages/silk-effects/dist/dev/pkg/changesets/index.cjs +0 -300
  39. package/packages/silk-effects/dist/dev/pkg/changesets/index.js +0 -179
  40. package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/index.cjs +0 -34
  41. package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/index.js +0 -29
  42. package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/content-structure.cjs +0 -98
  43. package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/content-structure.js +0 -98
  44. package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/dependency-table-format.cjs +0 -170
  45. package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/dependency-table-format.js +0 -170
  46. package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/heading-hierarchy.cjs +0 -61
  47. package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/heading-hierarchy.js +0 -61
  48. package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/required-sections.cjs +0 -54
  49. package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/required-sections.js +0 -54
  50. package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/uncategorized-content.cjs +0 -54
  51. package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/uncategorized-content.js +0 -54
  52. package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/utils.cjs +0 -31
  53. package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/utils.js +0 -30
  54. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/aggregate-dependency-tables.cjs +0 -47
  55. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/aggregate-dependency-tables.js +0 -47
  56. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/contributor-footnotes.cjs +0 -123
  57. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/contributor-footnotes.js +0 -123
  58. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/deduplicate-items.cjs +0 -32
  59. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/deduplicate-items.js +0 -32
  60. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/issue-link-refs.cjs +0 -59
  61. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/issue-link-refs.js +0 -59
  62. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/maintenance-note.cjs +0 -61
  63. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/maintenance-note.js +0 -61
  64. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/merge-sections.cjs +0 -43
  65. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/merge-sections.js +0 -43
  66. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/normalize-format.cjs +0 -47
  67. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/normalize-format.js +0 -47
  68. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/reorder-sections.cjs +0 -34
  69. package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/reorder-sections.js +0 -34
  70. package/packages/silk-effects/dist/dev/pkg/changesets/remark/presets.cjs +0 -120
  71. package/packages/silk-effects/dist/dev/pkg/changesets/remark/presets.js +0 -119
  72. package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/content-structure.cjs +0 -22
  73. package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/content-structure.js +0 -22
  74. package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/dependency-table-format.cjs +0 -40
  75. package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/dependency-table-format.js +0 -40
  76. package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/heading-hierarchy.cjs +0 -19
  77. package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/heading-hierarchy.js +0 -19
  78. package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/required-sections.cjs +0 -17
  79. package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/required-sections.js +0 -17
  80. package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/uncategorized-content.cjs +0 -31
  81. package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/uncategorized-content.js +0 -31
  82. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/changeset.cjs +0 -148
  83. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/changeset.js +0 -145
  84. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/dependency-table.cjs +0 -203
  85. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/dependency-table.js +0 -198
  86. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/git.cjs +0 -69
  87. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/git.js +0 -68
  88. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/github.cjs +0 -177
  89. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/github.js +0 -174
  90. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/options.cjs +0 -183
  91. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/options.js +0 -181
  92. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/package-scope.cjs +0 -129
  93. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/package-scope.js +0 -127
  94. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/primitives.cjs +0 -72
  95. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/primitives.js +0 -71
  96. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/release-plan.cjs +0 -62
  97. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/release-plan.js +0 -56
  98. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/version-files.cjs +0 -154
  99. package/packages/silk-effects/dist/dev/pkg/changesets/schemas/version-files.js +0 -150
  100. package/packages/silk-effects/dist/dev/pkg/changesets/services/branch-analyzer.cjs +0 -300
  101. package/packages/silk-effects/dist/dev/pkg/changesets/services/branch-analyzer.js +0 -294
  102. package/packages/silk-effects/dist/dev/pkg/changesets/services/changelog.cjs +0 -50
  103. package/packages/silk-effects/dist/dev/pkg/changesets/services/changelog.js +0 -49
  104. package/packages/silk-effects/dist/dev/pkg/changesets/services/config-inspector.cjs +0 -489
  105. package/packages/silk-effects/dist/dev/pkg/changesets/services/config-inspector.js +0 -481
  106. package/packages/silk-effects/dist/dev/pkg/changesets/services/deps-regen.cjs +0 -375
  107. package/packages/silk-effects/dist/dev/pkg/changesets/services/deps-regen.js +0 -371
  108. package/packages/silk-effects/dist/dev/pkg/changesets/services/github.cjs +0 -160
  109. package/packages/silk-effects/dist/dev/pkg/changesets/services/github.js +0 -157
  110. package/packages/silk-effects/dist/dev/pkg/changesets/services/maintenance-reason.cjs +0 -68
  111. package/packages/silk-effects/dist/dev/pkg/changesets/services/maintenance-reason.js +0 -66
  112. package/packages/silk-effects/dist/dev/pkg/changesets/services/markdown.cjs +0 -87
  113. package/packages/silk-effects/dist/dev/pkg/changesets/services/markdown.js +0 -85
  114. package/packages/silk-effects/dist/dev/pkg/changesets/services/release-planner.cjs +0 -352
  115. package/packages/silk-effects/dist/dev/pkg/changesets/services/release-planner.js +0 -348
  116. package/packages/silk-effects/dist/dev/pkg/changesets/utils/commit-parser.cjs +0 -81
  117. package/packages/silk-effects/dist/dev/pkg/changesets/utils/commit-parser.js +0 -80
  118. package/packages/silk-effects/dist/dev/pkg/changesets/utils/dep-diff.cjs +0 -111
  119. package/packages/silk-effects/dist/dev/pkg/changesets/utils/dep-diff.js +0 -111
  120. package/packages/silk-effects/dist/dev/pkg/changesets/utils/dependency-table.cjs +0 -351
  121. package/packages/silk-effects/dist/dev/pkg/changesets/utils/dependency-table.js +0 -347
  122. package/packages/silk-effects/dist/dev/pkg/changesets/utils/git.cjs +0 -51
  123. package/packages/silk-effects/dist/dev/pkg/changesets/utils/git.js +0 -51
  124. package/packages/silk-effects/dist/dev/pkg/changesets/utils/issue-refs.cjs +0 -102
  125. package/packages/silk-effects/dist/dev/pkg/changesets/utils/issue-refs.js +0 -101
  126. package/packages/silk-effects/dist/dev/pkg/changesets/utils/jsonpath.cjs +0 -178
  127. package/packages/silk-effects/dist/dev/pkg/changesets/utils/jsonpath.js +0 -175
  128. package/packages/silk-effects/dist/dev/pkg/changesets/utils/logger.cjs +0 -51
  129. package/packages/silk-effects/dist/dev/pkg/changesets/utils/logger.js +0 -50
  130. package/packages/silk-effects/dist/dev/pkg/changesets/utils/markdown-link.cjs +0 -59
  131. package/packages/silk-effects/dist/dev/pkg/changesets/utils/markdown-link.js +0 -57
  132. package/packages/silk-effects/dist/dev/pkg/changesets/utils/publishability.cjs +0 -50
  133. package/packages/silk-effects/dist/dev/pkg/changesets/utils/publishability.js +0 -50
  134. package/packages/silk-effects/dist/dev/pkg/changesets/utils/remark-pipeline.cjs +0 -81
  135. package/packages/silk-effects/dist/dev/pkg/changesets/utils/remark-pipeline.js +0 -79
  136. package/packages/silk-effects/dist/dev/pkg/changesets/utils/section-parser.cjs +0 -94
  137. package/packages/silk-effects/dist/dev/pkg/changesets/utils/section-parser.js +0 -94
  138. package/packages/silk-effects/dist/dev/pkg/changesets/utils/strip-frontmatter.cjs +0 -47
  139. package/packages/silk-effects/dist/dev/pkg/changesets/utils/strip-frontmatter.js +0 -46
  140. package/packages/silk-effects/dist/dev/pkg/changesets/utils/version-blocks.cjs +0 -110
  141. package/packages/silk-effects/dist/dev/pkg/changesets/utils/version-blocks.js +0 -108
  142. package/packages/silk-effects/dist/dev/pkg/changesets/utils/version-files.cjs +0 -336
  143. package/packages/silk-effects/dist/dev/pkg/changesets/utils/version-files.js +0 -336
  144. package/packages/silk-effects/dist/dev/pkg/changesets/vendor/github-info.cjs +0 -77
  145. package/packages/silk-effects/dist/dev/pkg/changesets/vendor/github-info.js +0 -77
  146. package/packages/silk-effects/dist/dev/pkg/errors/ChangesetConfigError.cjs +0 -21
  147. package/packages/silk-effects/dist/dev/pkg/errors/ChangesetConfigError.js +0 -21
  148. package/packages/silk-effects/dist/dev/pkg/schemas/VersioningSchemas.cjs +0 -101
  149. package/packages/silk-effects/dist/dev/pkg/schemas/VersioningSchemas.js +0 -99
  150. package/packages/silk-effects/dist/dev/pkg/services/ChangesetConfig.cjs +0 -81
  151. package/packages/silk-effects/dist/dev/pkg/services/ChangesetConfig.js +0 -80
  152. package/packages/silk-effects/dist/dev/pkg/services/ChangesetConfigReader.cjs +0 -109
  153. package/packages/silk-effects/dist/dev/pkg/services/ChangesetConfigReader.js +0 -108
  154. package/packages/silk-effects/dist/dev/pkg/services/SilkPublishability.cjs +0 -238
  155. package/packages/silk-effects/dist/dev/pkg/services/SilkPublishability.js +0 -236
@@ -1,336 +0,0 @@
1
- const require_version_files = require('../schemas/version-files.cjs');
2
- const require_index = require('../../../../../../../node_modules/.pnpm/tinyglobby@0.2.17/node_modules/tinyglobby/dist/index.cjs');
3
- const require_jsonpath = require('./jsonpath.cjs');
4
- let effect = require("effect");
5
- let node_path = require("node:path");
6
- let node_fs = require("node:fs");
7
-
8
- //#region ../silk-effects/dist/dev/pkg/changesets/utils/version-files.js
9
- /**
10
- * Utilities for updating version fields in additional JSON files.
11
- *
12
- * @remarks
13
- * Implements the `versionFiles` feature of `\@savvy-web/changesets`, which
14
- * allows version numbers to be synchronized across arbitrary JSON files
15
- * (e.g., `tauri.conf.json`, `manifest.json`) during the changeset version
16
- * step.
17
- *
18
- * The flow is:
19
- * 1. Extract and validate `versionFiles` from a pre-parsed config
20
- * 2. Resolve glob patterns to absolute file paths
21
- * 3. Discover workspace packages to determine the correct version per file
22
- * (using longest-prefix matching)
23
- * 4. Update JSONPath-specified fields in each matched file
24
- *
25
- * @see {@link jsonPathGet} and {@link jsonPathSet} for the JSONPath implementation
26
- *
27
- * @internal
28
- */
29
- /**
30
- * Static utility class for version file operations.
31
- *
32
- * @remarks
33
- * Orchestrates the full version file update workflow: reading config,
34
- * discovering workspace versions, resolving globs, and updating JSON
35
- * files at specified JSONPath locations. Designed to be called from
36
- * the CLI `version` command.
37
- *
38
- * Version resolution uses longest-prefix matching: for a file at
39
- * `/repo/packages/ui/tauri.conf.json`, if workspace `packages/ui`
40
- * has version `2.0.0`, that version is used rather than the root version.
41
- *
42
- * @example
43
- * ```typescript
44
- * import { VersionFiles } from "../utils/version-files.js";
45
- *
46
- * const configs = VersionFiles.extractVersionFiles(parsedConfig);
47
- * if (configs) {
48
- * const updates = VersionFiles.processVersionFiles("/path/to/project", configs);
49
- * for (const update of updates) {
50
- * console.log(`Updated ${update.filePath} to ${update.version}`);
51
- * }
52
- * }
53
- * ```
54
- *
55
- * @internal
56
- */
57
- var VersionFiles = class VersionFiles {
58
- /**
59
- * Extract and validate `versionFiles` from a pre-parsed changeset config object.
60
- *
61
- * @remarks
62
- * Accepts a config object (already parsed from `.changeset/config.json`),
63
- * extracts the `changelog` tuple's second element (options object), and
64
- * validates the `versionFiles` key against `LegacyVersionFilesSchema`. Returns
65
- * `undefined` if `changelog` is not a tuple, the `versionFiles` key is
66
- * absent, or the array is empty. Schema validation errors are logged as
67
- * warnings but do not throw.
68
- *
69
- * File reading and JSONC parsing are delegated to the caller
70
- * (e.g., `ChangesetConfigReader` from `\@savvy-web/silk-effects`).
71
- *
72
- * @param config - Pre-parsed changeset config object
73
- * @returns Parsed config array, or `undefined` if not configured
74
- */
75
- static extractVersionFiles(config) {
76
- const { changelog } = config;
77
- if (!Array.isArray(changelog) || changelog.length < 2) return;
78
- const options = changelog[1];
79
- if (!options || typeof options !== "object" || !("versionFiles" in options)) return;
80
- try {
81
- const decoded = effect.Schema.decodeUnknownSync(require_version_files.LegacyVersionFilesSchema)(options.versionFiles);
82
- return decoded.length > 0 ? decoded : void 0;
83
- } catch (error) {
84
- console.warn(`[changesets] Invalid versionFiles configuration: ${error instanceof Error ? error.message : String(error)}`);
85
- return;
86
- }
87
- }
88
- /**
89
- * Discover all workspace packages and their current versions.
90
- *
91
- * @remarks
92
- * Accepts a pre-resolved list of workspace packages (e.g., from
93
- * `WorkspaceDiscovery.listPackages()`). The root package is always
94
- * included if not already present in the packages list.
95
- * Deduplicates by absolute path and skips entries without a version.
96
- *
97
- * @param cwd - Project root directory
98
- * @param packages - Pre-resolved workspace packages
99
- * @returns Array of workspace packages with versions
100
- */
101
- static discoverVersions(cwd, packages) {
102
- const resolvedCwd = (0, node_path.resolve)(cwd);
103
- const results = [];
104
- const seen = /* @__PURE__ */ new Set();
105
- for (const pkg of packages) {
106
- if (seen.has(pkg.path) || !pkg.version) continue;
107
- seen.add(pkg.path);
108
- results.push({
109
- name: pkg.name,
110
- path: pkg.path,
111
- version: pkg.version
112
- });
113
- }
114
- if (!seen.has(resolvedCwd)) {
115
- const version = readPackageVersion(resolvedCwd);
116
- if (version) {
117
- let rootName = "root";
118
- try {
119
- const pkg = JSON.parse((0, node_fs.readFileSync)((0, node_path.join)(resolvedCwd, "package.json"), "utf-8"));
120
- if (pkg.name) rootName = pkg.name;
121
- } catch {}
122
- results.push({
123
- name: rootName,
124
- path: resolvedCwd,
125
- version
126
- });
127
- }
128
- }
129
- return results;
130
- }
131
- /**
132
- * Determine which workspace version applies to a given file path
133
- * using longest-prefix matching.
134
- *
135
- * @remarks
136
- * For each workspace, checks whether the file is contained within
137
- * it (i.e., the relative path does not start with `..`). Among all
138
- * matching workspaces, the one with the longest absolute path wins
139
- * (most specific match). Falls back to `rootVersion` if no workspace
140
- * contains the file.
141
- *
142
- * @param filePath - Absolute path to the file
143
- * @param workspaces - Discovered workspace versions
144
- * @param rootVersion - Fallback version from project root
145
- * @returns The version string to use
146
- */
147
- static resolveVersion(filePath, workspaces, rootVersion) {
148
- const resolved = (0, node_path.resolve)(filePath);
149
- let bestMatch;
150
- let bestLength = 0;
151
- for (const ws of workspaces) if (!(0, node_path.relative)(ws.path, resolved).startsWith("..") && ws.path.length > bestLength) {
152
- bestMatch = ws;
153
- bestLength = ws.path.length;
154
- }
155
- return bestMatch?.version ?? rootVersion;
156
- }
157
- /**
158
- * Resolve glob patterns to absolute file paths.
159
- *
160
- * @remarks
161
- * Uses `tinyglobby` to expand each config's glob pattern relative to
162
- * `cwd`. The `node_modules` directory is always ignored. Returns
163
- * tuples pairing each resolved absolute path with its originating config.
164
- *
165
- * @param configs - Version file configurations
166
- * @param cwd - Project root directory
167
- * @returns Array of `[filePath, config]` tuples
168
- */
169
- static resolveGlobs(configs, cwd) {
170
- const results = [];
171
- const resolvedCwd = (0, node_path.resolve)(cwd);
172
- for (const config of configs) {
173
- const matches = require_index.globSync(config.glob, {
174
- cwd: resolvedCwd,
175
- ignore: ["**/node_modules/**"]
176
- });
177
- for (const match of matches) results.push([(0, node_path.join)(resolvedCwd, match), config]);
178
- }
179
- return results;
180
- }
181
- /**
182
- * Detect indentation from file content.
183
- *
184
- * @remarks
185
- * Looks for the first line starting with whitespace followed by a
186
- * double-quote (typical JSON property). Defaults to 2 spaces if
187
- * no indentation pattern is found.
188
- *
189
- * @param content - Raw file content
190
- * @returns Detected indent string (defaults to 2 spaces)
191
- */
192
- static detectIndent(content) {
193
- return content.match(/^(\s+)"/m)?.[1] ?? " ";
194
- }
195
- /**
196
- * Update JSON file at specified JSONPath locations.
197
- *
198
- * @remarks
199
- * Reads the file, detects its indentation style and trailing newline
200
- * preference, applies all JSONPath updates via {@link jsonPathSet},
201
- * and writes the result back preserving the original formatting.
202
- * Returns `undefined` if no JSONPath locations matched (no write occurs).
203
- *
204
- * @param filePath - Absolute path to the JSON file
205
- * @param jsonPaths - JSONPath expressions to update
206
- * @param version - New version string
207
- * @returns Update result, or `undefined` if no changes were made
208
- */
209
- static updateFile(filePath, jsonPaths, version) {
210
- const content = (0, node_fs.readFileSync)(filePath, "utf-8");
211
- const indent = VersionFiles.detectIndent(content);
212
- const trailingNewline = content.endsWith("\n");
213
- const obj = JSON.parse(content);
214
- const previousValues = jsonPaths.flatMap((jp) => require_jsonpath.jsonPathGet(obj, jp));
215
- let totalUpdated = 0;
216
- for (const jp of jsonPaths) totalUpdated += require_jsonpath.jsonPathSet(obj, jp, version);
217
- if (totalUpdated === 0) return;
218
- let output = JSON.stringify(obj, null, indent);
219
- if (trailingNewline) output += "\n";
220
- (0, node_fs.writeFileSync)(filePath, output, "utf-8");
221
- return {
222
- filePath,
223
- jsonPaths,
224
- version,
225
- previousValues
226
- };
227
- }
228
- /**
229
- * Orchestrate the full version file update flow.
230
- *
231
- * @remarks
232
- * Combines {@link VersionFiles.discoverVersions},
233
- * {@link VersionFiles.resolveGlobs}, {@link VersionFiles.resolveVersion},
234
- * and {@link VersionFiles.updateFile} into a single operation. In dry-run
235
- * mode, files are read and JSONPaths are resolved but no writes occur.
236
- *
237
- * @param cwd - Project root directory
238
- * @param configs - Validated version file configurations
239
- * @param dryRun - If true, do not write files (default: `false`)
240
- * @returns Array of update results
241
- * @throws If any file cannot be read or parsed
242
- */
243
- static processVersionFiles(cwd, configs, dryRun = false, packages = []) {
244
- const workspaces = VersionFiles.discoverVersions(cwd, packages);
245
- const rootVersion = workspaces.find((ws) => ws.path === (0, node_path.resolve)(cwd))?.version ?? "0.0.0";
246
- const resolved = VersionFiles.resolveGlobs(configs, cwd);
247
- const updates = [];
248
- for (const [filePath, config] of resolved) {
249
- const jsonPaths = config.paths ?? ["$.version"];
250
- const version = config.package ? workspaces.find((ws) => ws.name === config.package)?.version ?? rootVersion : VersionFiles.resolveVersion(filePath, workspaces, rootVersion);
251
- try {
252
- if (dryRun) {
253
- const content = (0, node_fs.readFileSync)(filePath, "utf-8");
254
- const obj = JSON.parse(content);
255
- const previousValues = jsonPaths.flatMap((jp) => require_jsonpath.jsonPathGet(obj, jp));
256
- if (previousValues.length > 0) updates.push({
257
- filePath,
258
- jsonPaths,
259
- version,
260
- previousValues
261
- });
262
- } else {
263
- const result = VersionFiles.updateFile(filePath, jsonPaths, version);
264
- if (result) updates.push(result);
265
- }
266
- } catch (error) {
267
- throw new Error(`Failed to update ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
268
- }
269
- }
270
- return updates;
271
- }
272
- /**
273
- * Apply version-file updates from the resolved (post-`ConfigInspector`)
274
- * representation. Each {@link ResolvedPackageScope} already names the
275
- * owning package and carries its current version plus the materialized
276
- * file paths, so no glob expansion or path-prefix workspace resolution
277
- * is needed here — the inspector has done that work.
278
- *
279
- * @remarks
280
- * This is the 0.9.0 successor to {@link VersionFiles.processVersionFiles}.
281
- * The old method stays in place to handle the deprecated top-level
282
- * `versionFiles[]` shape (read by `cli/commands/init.ts` for its
283
- * validation pass), and is removed alongside the legacy schema in
284
- * 1.0.0.
285
- *
286
- * @param scopes - Per-package resolved scopes from {@link ConfigInspector.inspect}
287
- * @param dryRun - When `true`, do not write files
288
- * @returns Array of update results, one per file that actually had a
289
- * matching JSONPath
290
- *
291
- * @internal
292
- */
293
- static processResolvedVersionFiles(scopes, dryRun = false) {
294
- const updates = [];
295
- for (const scope of scopes) for (const vf of scope.versionFiles) {
296
- const jsonPaths = vf.paths.length > 0 ? vf.paths : ["$.version"];
297
- for (const filePath of vf.matchedFiles) try {
298
- if (dryRun) {
299
- const content = (0, node_fs.readFileSync)(filePath, "utf-8");
300
- const obj = JSON.parse(content);
301
- const previousValues = jsonPaths.flatMap((jp) => require_jsonpath.jsonPathGet(obj, jp));
302
- if (previousValues.length > 0) updates.push({
303
- filePath,
304
- jsonPaths,
305
- version: scope.version,
306
- previousValues
307
- });
308
- } else {
309
- const result = VersionFiles.updateFile(filePath, jsonPaths, scope.version);
310
- if (result) updates.push(result);
311
- }
312
- } catch (error) {
313
- throw new Error(`Failed to update ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
314
- }
315
- }
316
- return updates;
317
- }
318
- };
319
- /**
320
- * Read the `version` field from a `package.json` in the given directory.
321
- *
322
- * @param dir - Absolute path to the directory containing `package.json`
323
- * @returns The version string, or `undefined` if the file is missing or has no `version` field
324
- *
325
- * @internal
326
- */
327
- function readPackageVersion(dir) {
328
- try {
329
- return JSON.parse((0, node_fs.readFileSync)((0, node_path.join)(dir, "package.json"), "utf-8")).version;
330
- } catch {
331
- return;
332
- }
333
- }
334
-
335
- //#endregion
336
- exports.VersionFiles = VersionFiles;
@@ -1,336 +0,0 @@
1
- import { LegacyVersionFilesSchema } from "../schemas/version-files.js";
2
- import { globSync } from "../../../../../../../node_modules/.pnpm/tinyglobby@0.2.17/node_modules/tinyglobby/dist/index.js";
3
- import { jsonPathGet, jsonPathSet } from "./jsonpath.js";
4
- import { Schema } from "effect";
5
- import { join, relative, resolve } from "node:path";
6
- import { readFileSync, writeFileSync } from "node:fs";
7
-
8
- //#region ../silk-effects/dist/dev/pkg/changesets/utils/version-files.js
9
- /**
10
- * Utilities for updating version fields in additional JSON files.
11
- *
12
- * @remarks
13
- * Implements the `versionFiles` feature of `\@savvy-web/changesets`, which
14
- * allows version numbers to be synchronized across arbitrary JSON files
15
- * (e.g., `tauri.conf.json`, `manifest.json`) during the changeset version
16
- * step.
17
- *
18
- * The flow is:
19
- * 1. Extract and validate `versionFiles` from a pre-parsed config
20
- * 2. Resolve glob patterns to absolute file paths
21
- * 3. Discover workspace packages to determine the correct version per file
22
- * (using longest-prefix matching)
23
- * 4. Update JSONPath-specified fields in each matched file
24
- *
25
- * @see {@link jsonPathGet} and {@link jsonPathSet} for the JSONPath implementation
26
- *
27
- * @internal
28
- */
29
- /**
30
- * Static utility class for version file operations.
31
- *
32
- * @remarks
33
- * Orchestrates the full version file update workflow: reading config,
34
- * discovering workspace versions, resolving globs, and updating JSON
35
- * files at specified JSONPath locations. Designed to be called from
36
- * the CLI `version` command.
37
- *
38
- * Version resolution uses longest-prefix matching: for a file at
39
- * `/repo/packages/ui/tauri.conf.json`, if workspace `packages/ui`
40
- * has version `2.0.0`, that version is used rather than the root version.
41
- *
42
- * @example
43
- * ```typescript
44
- * import { VersionFiles } from "../utils/version-files.js";
45
- *
46
- * const configs = VersionFiles.extractVersionFiles(parsedConfig);
47
- * if (configs) {
48
- * const updates = VersionFiles.processVersionFiles("/path/to/project", configs);
49
- * for (const update of updates) {
50
- * console.log(`Updated ${update.filePath} to ${update.version}`);
51
- * }
52
- * }
53
- * ```
54
- *
55
- * @internal
56
- */
57
- var VersionFiles = class VersionFiles {
58
- /**
59
- * Extract and validate `versionFiles` from a pre-parsed changeset config object.
60
- *
61
- * @remarks
62
- * Accepts a config object (already parsed from `.changeset/config.json`),
63
- * extracts the `changelog` tuple's second element (options object), and
64
- * validates the `versionFiles` key against `LegacyVersionFilesSchema`. Returns
65
- * `undefined` if `changelog` is not a tuple, the `versionFiles` key is
66
- * absent, or the array is empty. Schema validation errors are logged as
67
- * warnings but do not throw.
68
- *
69
- * File reading and JSONC parsing are delegated to the caller
70
- * (e.g., `ChangesetConfigReader` from `\@savvy-web/silk-effects`).
71
- *
72
- * @param config - Pre-parsed changeset config object
73
- * @returns Parsed config array, or `undefined` if not configured
74
- */
75
- static extractVersionFiles(config) {
76
- const { changelog } = config;
77
- if (!Array.isArray(changelog) || changelog.length < 2) return;
78
- const options = changelog[1];
79
- if (!options || typeof options !== "object" || !("versionFiles" in options)) return;
80
- try {
81
- const decoded = Schema.decodeUnknownSync(LegacyVersionFilesSchema)(options.versionFiles);
82
- return decoded.length > 0 ? decoded : void 0;
83
- } catch (error) {
84
- console.warn(`[changesets] Invalid versionFiles configuration: ${error instanceof Error ? error.message : String(error)}`);
85
- return;
86
- }
87
- }
88
- /**
89
- * Discover all workspace packages and their current versions.
90
- *
91
- * @remarks
92
- * Accepts a pre-resolved list of workspace packages (e.g., from
93
- * `WorkspaceDiscovery.listPackages()`). The root package is always
94
- * included if not already present in the packages list.
95
- * Deduplicates by absolute path and skips entries without a version.
96
- *
97
- * @param cwd - Project root directory
98
- * @param packages - Pre-resolved workspace packages
99
- * @returns Array of workspace packages with versions
100
- */
101
- static discoverVersions(cwd, packages) {
102
- const resolvedCwd = resolve(cwd);
103
- const results = [];
104
- const seen = /* @__PURE__ */ new Set();
105
- for (const pkg of packages) {
106
- if (seen.has(pkg.path) || !pkg.version) continue;
107
- seen.add(pkg.path);
108
- results.push({
109
- name: pkg.name,
110
- path: pkg.path,
111
- version: pkg.version
112
- });
113
- }
114
- if (!seen.has(resolvedCwd)) {
115
- const version = readPackageVersion(resolvedCwd);
116
- if (version) {
117
- let rootName = "root";
118
- try {
119
- const pkg = JSON.parse(readFileSync(join(resolvedCwd, "package.json"), "utf-8"));
120
- if (pkg.name) rootName = pkg.name;
121
- } catch {}
122
- results.push({
123
- name: rootName,
124
- path: resolvedCwd,
125
- version
126
- });
127
- }
128
- }
129
- return results;
130
- }
131
- /**
132
- * Determine which workspace version applies to a given file path
133
- * using longest-prefix matching.
134
- *
135
- * @remarks
136
- * For each workspace, checks whether the file is contained within
137
- * it (i.e., the relative path does not start with `..`). Among all
138
- * matching workspaces, the one with the longest absolute path wins
139
- * (most specific match). Falls back to `rootVersion` if no workspace
140
- * contains the file.
141
- *
142
- * @param filePath - Absolute path to the file
143
- * @param workspaces - Discovered workspace versions
144
- * @param rootVersion - Fallback version from project root
145
- * @returns The version string to use
146
- */
147
- static resolveVersion(filePath, workspaces, rootVersion) {
148
- const resolved = resolve(filePath);
149
- let bestMatch;
150
- let bestLength = 0;
151
- for (const ws of workspaces) if (!relative(ws.path, resolved).startsWith("..") && ws.path.length > bestLength) {
152
- bestMatch = ws;
153
- bestLength = ws.path.length;
154
- }
155
- return bestMatch?.version ?? rootVersion;
156
- }
157
- /**
158
- * Resolve glob patterns to absolute file paths.
159
- *
160
- * @remarks
161
- * Uses `tinyglobby` to expand each config's glob pattern relative to
162
- * `cwd`. The `node_modules` directory is always ignored. Returns
163
- * tuples pairing each resolved absolute path with its originating config.
164
- *
165
- * @param configs - Version file configurations
166
- * @param cwd - Project root directory
167
- * @returns Array of `[filePath, config]` tuples
168
- */
169
- static resolveGlobs(configs, cwd) {
170
- const results = [];
171
- const resolvedCwd = resolve(cwd);
172
- for (const config of configs) {
173
- const matches = globSync(config.glob, {
174
- cwd: resolvedCwd,
175
- ignore: ["**/node_modules/**"]
176
- });
177
- for (const match of matches) results.push([join(resolvedCwd, match), config]);
178
- }
179
- return results;
180
- }
181
- /**
182
- * Detect indentation from file content.
183
- *
184
- * @remarks
185
- * Looks for the first line starting with whitespace followed by a
186
- * double-quote (typical JSON property). Defaults to 2 spaces if
187
- * no indentation pattern is found.
188
- *
189
- * @param content - Raw file content
190
- * @returns Detected indent string (defaults to 2 spaces)
191
- */
192
- static detectIndent(content) {
193
- return content.match(/^(\s+)"/m)?.[1] ?? " ";
194
- }
195
- /**
196
- * Update JSON file at specified JSONPath locations.
197
- *
198
- * @remarks
199
- * Reads the file, detects its indentation style and trailing newline
200
- * preference, applies all JSONPath updates via {@link jsonPathSet},
201
- * and writes the result back preserving the original formatting.
202
- * Returns `undefined` if no JSONPath locations matched (no write occurs).
203
- *
204
- * @param filePath - Absolute path to the JSON file
205
- * @param jsonPaths - JSONPath expressions to update
206
- * @param version - New version string
207
- * @returns Update result, or `undefined` if no changes were made
208
- */
209
- static updateFile(filePath, jsonPaths, version) {
210
- const content = readFileSync(filePath, "utf-8");
211
- const indent = VersionFiles.detectIndent(content);
212
- const trailingNewline = content.endsWith("\n");
213
- const obj = JSON.parse(content);
214
- const previousValues = jsonPaths.flatMap((jp) => jsonPathGet(obj, jp));
215
- let totalUpdated = 0;
216
- for (const jp of jsonPaths) totalUpdated += jsonPathSet(obj, jp, version);
217
- if (totalUpdated === 0) return;
218
- let output = JSON.stringify(obj, null, indent);
219
- if (trailingNewline) output += "\n";
220
- writeFileSync(filePath, output, "utf-8");
221
- return {
222
- filePath,
223
- jsonPaths,
224
- version,
225
- previousValues
226
- };
227
- }
228
- /**
229
- * Orchestrate the full version file update flow.
230
- *
231
- * @remarks
232
- * Combines {@link VersionFiles.discoverVersions},
233
- * {@link VersionFiles.resolveGlobs}, {@link VersionFiles.resolveVersion},
234
- * and {@link VersionFiles.updateFile} into a single operation. In dry-run
235
- * mode, files are read and JSONPaths are resolved but no writes occur.
236
- *
237
- * @param cwd - Project root directory
238
- * @param configs - Validated version file configurations
239
- * @param dryRun - If true, do not write files (default: `false`)
240
- * @returns Array of update results
241
- * @throws If any file cannot be read or parsed
242
- */
243
- static processVersionFiles(cwd, configs, dryRun = false, packages = []) {
244
- const workspaces = VersionFiles.discoverVersions(cwd, packages);
245
- const rootVersion = workspaces.find((ws) => ws.path === resolve(cwd))?.version ?? "0.0.0";
246
- const resolved = VersionFiles.resolveGlobs(configs, cwd);
247
- const updates = [];
248
- for (const [filePath, config] of resolved) {
249
- const jsonPaths = config.paths ?? ["$.version"];
250
- const version = config.package ? workspaces.find((ws) => ws.name === config.package)?.version ?? rootVersion : VersionFiles.resolveVersion(filePath, workspaces, rootVersion);
251
- try {
252
- if (dryRun) {
253
- const content = readFileSync(filePath, "utf-8");
254
- const obj = JSON.parse(content);
255
- const previousValues = jsonPaths.flatMap((jp) => jsonPathGet(obj, jp));
256
- if (previousValues.length > 0) updates.push({
257
- filePath,
258
- jsonPaths,
259
- version,
260
- previousValues
261
- });
262
- } else {
263
- const result = VersionFiles.updateFile(filePath, jsonPaths, version);
264
- if (result) updates.push(result);
265
- }
266
- } catch (error) {
267
- throw new Error(`Failed to update ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
268
- }
269
- }
270
- return updates;
271
- }
272
- /**
273
- * Apply version-file updates from the resolved (post-`ConfigInspector`)
274
- * representation. Each {@link ResolvedPackageScope} already names the
275
- * owning package and carries its current version plus the materialized
276
- * file paths, so no glob expansion or path-prefix workspace resolution
277
- * is needed here — the inspector has done that work.
278
- *
279
- * @remarks
280
- * This is the 0.9.0 successor to {@link VersionFiles.processVersionFiles}.
281
- * The old method stays in place to handle the deprecated top-level
282
- * `versionFiles[]` shape (read by `cli/commands/init.ts` for its
283
- * validation pass), and is removed alongside the legacy schema in
284
- * 1.0.0.
285
- *
286
- * @param scopes - Per-package resolved scopes from {@link ConfigInspector.inspect}
287
- * @param dryRun - When `true`, do not write files
288
- * @returns Array of update results, one per file that actually had a
289
- * matching JSONPath
290
- *
291
- * @internal
292
- */
293
- static processResolvedVersionFiles(scopes, dryRun = false) {
294
- const updates = [];
295
- for (const scope of scopes) for (const vf of scope.versionFiles) {
296
- const jsonPaths = vf.paths.length > 0 ? vf.paths : ["$.version"];
297
- for (const filePath of vf.matchedFiles) try {
298
- if (dryRun) {
299
- const content = readFileSync(filePath, "utf-8");
300
- const obj = JSON.parse(content);
301
- const previousValues = jsonPaths.flatMap((jp) => jsonPathGet(obj, jp));
302
- if (previousValues.length > 0) updates.push({
303
- filePath,
304
- jsonPaths,
305
- version: scope.version,
306
- previousValues
307
- });
308
- } else {
309
- const result = VersionFiles.updateFile(filePath, jsonPaths, scope.version);
310
- if (result) updates.push(result);
311
- }
312
- } catch (error) {
313
- throw new Error(`Failed to update ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
314
- }
315
- }
316
- return updates;
317
- }
318
- };
319
- /**
320
- * Read the `version` field from a `package.json` in the given directory.
321
- *
322
- * @param dir - Absolute path to the directory containing `package.json`
323
- * @returns The version string, or `undefined` if the file is missing or has no `version` field
324
- *
325
- * @internal
326
- */
327
- function readPackageVersion(dir) {
328
- try {
329
- return JSON.parse(readFileSync(join(dir, "package.json"), "utf-8")).version;
330
- } catch {
331
- return;
332
- }
333
- }
334
-
335
- //#endregion
336
- export { VersionFiles };