@savvy-web/silk 2.0.0 → 2.1.1
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.
- package/README.md +7 -5
- package/changesets-changelog.cjs +109 -61
- package/changesets-changelog.d.cts +1 -1
- package/changesets-changelog.d.ts +1 -1
- package/changesets-changelog.js +54099 -1
- package/changesets-markdownlint.cjs +109 -61
- package/changesets-markdownlint.d.cts +1 -1
- package/changesets-markdownlint.d.ts +1 -1
- package/changesets-markdownlint.js +54099 -1
- package/package.json +5 -4
- package/tsconfig/node/dist/tsconfig.tsbuildinfo +1 -1
- package/_virtual/_rolldown/runtime.cjs +0 -45
- package/_virtual/_rolldown/runtime.js +0 -45
- package/packages/silk-effects/dist/dev/pkg/_virtual/_rolldown/runtime.cjs +0 -15
- package/packages/silk-effects/dist/dev/pkg/_virtual/_rolldown/runtime.js +0 -14
- package/packages/silk-effects/dist/dev/pkg/changesets/api/categories.cjs +0 -247
- package/packages/silk-effects/dist/dev/pkg/changesets/api/categories.js +0 -247
- package/packages/silk-effects/dist/dev/pkg/changesets/api/changelog.cjs +0 -134
- package/packages/silk-effects/dist/dev/pkg/changesets/api/changelog.js +0 -134
- package/packages/silk-effects/dist/dev/pkg/changesets/api/dependency-table.cjs +0 -163
- package/packages/silk-effects/dist/dev/pkg/changesets/api/dependency-table.js +0 -163
- package/packages/silk-effects/dist/dev/pkg/changesets/api/linter.cjs +0 -170
- package/packages/silk-effects/dist/dev/pkg/changesets/api/linter.js +0 -170
- package/packages/silk-effects/dist/dev/pkg/changesets/api/transformer.cjs +0 -134
- package/packages/silk-effects/dist/dev/pkg/changesets/api/transformer.js +0 -134
- package/packages/silk-effects/dist/dev/pkg/changesets/categories/index.cjs +0 -317
- package/packages/silk-effects/dist/dev/pkg/changesets/categories/index.js +0 -299
- package/packages/silk-effects/dist/dev/pkg/changesets/categories/types.cjs +0 -65
- package/packages/silk-effects/dist/dev/pkg/changesets/categories/types.js +0 -65
- package/packages/silk-effects/dist/dev/pkg/changesets/changelog/formatting.cjs +0 -114
- package/packages/silk-effects/dist/dev/pkg/changesets/changelog/formatting.js +0 -113
- package/packages/silk-effects/dist/dev/pkg/changesets/changelog/getDependencyReleaseLine.cjs +0 -118
- package/packages/silk-effects/dist/dev/pkg/changesets/changelog/getDependencyReleaseLine.js +0 -118
- package/packages/silk-effects/dist/dev/pkg/changesets/changelog/getReleaseLine.cjs +0 -122
- package/packages/silk-effects/dist/dev/pkg/changesets/changelog/getReleaseLine.js +0 -122
- package/packages/silk-effects/dist/dev/pkg/changesets/changelog/index.cjs +0 -97
- package/packages/silk-effects/dist/dev/pkg/changesets/changelog/index.js +0 -97
- package/packages/silk-effects/dist/dev/pkg/changesets/constants.cjs +0 -43
- package/packages/silk-effects/dist/dev/pkg/changesets/constants.js +0 -42
- package/packages/silk-effects/dist/dev/pkg/changesets/errors.cjs +0 -386
- package/packages/silk-effects/dist/dev/pkg/changesets/errors.js +0 -371
- package/packages/silk-effects/dist/dev/pkg/changesets/index.cjs +0 -300
- package/packages/silk-effects/dist/dev/pkg/changesets/index.js +0 -179
- package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/index.cjs +0 -34
- package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/index.js +0 -29
- package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/content-structure.cjs +0 -98
- package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/content-structure.js +0 -98
- package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/dependency-table-format.cjs +0 -170
- package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/dependency-table-format.js +0 -170
- package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/heading-hierarchy.cjs +0 -61
- package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/heading-hierarchy.js +0 -61
- package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/required-sections.cjs +0 -54
- package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/required-sections.js +0 -54
- package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/uncategorized-content.cjs +0 -54
- package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/uncategorized-content.js +0 -54
- package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/utils.cjs +0 -31
- package/packages/silk-effects/dist/dev/pkg/changesets/markdownlint/rules/utils.js +0 -30
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/aggregate-dependency-tables.cjs +0 -47
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/aggregate-dependency-tables.js +0 -47
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/contributor-footnotes.cjs +0 -123
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/contributor-footnotes.js +0 -123
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/deduplicate-items.cjs +0 -32
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/deduplicate-items.js +0 -32
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/issue-link-refs.cjs +0 -59
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/issue-link-refs.js +0 -59
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/maintenance-note.cjs +0 -61
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/maintenance-note.js +0 -61
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/merge-sections.cjs +0 -43
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/merge-sections.js +0 -43
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/normalize-format.cjs +0 -47
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/normalize-format.js +0 -47
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/reorder-sections.cjs +0 -34
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/plugins/reorder-sections.js +0 -34
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/presets.cjs +0 -120
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/presets.js +0 -119
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/content-structure.cjs +0 -22
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/content-structure.js +0 -22
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/dependency-table-format.cjs +0 -40
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/dependency-table-format.js +0 -40
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/heading-hierarchy.cjs +0 -19
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/heading-hierarchy.js +0 -19
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/required-sections.cjs +0 -17
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/required-sections.js +0 -17
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/uncategorized-content.cjs +0 -31
- package/packages/silk-effects/dist/dev/pkg/changesets/remark/rules/uncategorized-content.js +0 -31
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/changeset.cjs +0 -148
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/changeset.js +0 -145
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/dependency-table.cjs +0 -203
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/dependency-table.js +0 -198
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/git.cjs +0 -69
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/git.js +0 -68
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/github.cjs +0 -177
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/github.js +0 -174
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/options.cjs +0 -183
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/options.js +0 -181
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/package-scope.cjs +0 -129
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/package-scope.js +0 -127
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/primitives.cjs +0 -72
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/primitives.js +0 -71
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/release-plan.cjs +0 -62
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/release-plan.js +0 -56
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/version-files.cjs +0 -154
- package/packages/silk-effects/dist/dev/pkg/changesets/schemas/version-files.js +0 -150
- package/packages/silk-effects/dist/dev/pkg/changesets/services/branch-analyzer.cjs +0 -300
- package/packages/silk-effects/dist/dev/pkg/changesets/services/branch-analyzer.js +0 -294
- package/packages/silk-effects/dist/dev/pkg/changesets/services/changelog.cjs +0 -50
- package/packages/silk-effects/dist/dev/pkg/changesets/services/changelog.js +0 -49
- package/packages/silk-effects/dist/dev/pkg/changesets/services/config-inspector.cjs +0 -489
- package/packages/silk-effects/dist/dev/pkg/changesets/services/config-inspector.js +0 -481
- package/packages/silk-effects/dist/dev/pkg/changesets/services/deps-regen.cjs +0 -375
- package/packages/silk-effects/dist/dev/pkg/changesets/services/deps-regen.js +0 -371
- package/packages/silk-effects/dist/dev/pkg/changesets/services/github.cjs +0 -160
- package/packages/silk-effects/dist/dev/pkg/changesets/services/github.js +0 -157
- package/packages/silk-effects/dist/dev/pkg/changesets/services/maintenance-reason.cjs +0 -68
- package/packages/silk-effects/dist/dev/pkg/changesets/services/maintenance-reason.js +0 -66
- package/packages/silk-effects/dist/dev/pkg/changesets/services/markdown.cjs +0 -87
- package/packages/silk-effects/dist/dev/pkg/changesets/services/markdown.js +0 -85
- package/packages/silk-effects/dist/dev/pkg/changesets/services/release-planner.cjs +0 -352
- package/packages/silk-effects/dist/dev/pkg/changesets/services/release-planner.js +0 -348
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/commit-parser.cjs +0 -81
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/commit-parser.js +0 -80
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/dep-diff.cjs +0 -111
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/dep-diff.js +0 -111
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/dependency-table.cjs +0 -351
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/dependency-table.js +0 -347
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/git.cjs +0 -51
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/git.js +0 -51
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/issue-refs.cjs +0 -102
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/issue-refs.js +0 -101
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/jsonpath.cjs +0 -178
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/jsonpath.js +0 -175
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/logger.cjs +0 -51
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/logger.js +0 -50
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/markdown-link.cjs +0 -59
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/markdown-link.js +0 -57
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/publishability.cjs +0 -50
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/publishability.js +0 -50
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/remark-pipeline.cjs +0 -81
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/remark-pipeline.js +0 -79
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/section-parser.cjs +0 -94
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/section-parser.js +0 -94
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/strip-frontmatter.cjs +0 -47
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/strip-frontmatter.js +0 -46
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/version-blocks.cjs +0 -110
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/version-blocks.js +0 -108
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/version-files.cjs +0 -336
- package/packages/silk-effects/dist/dev/pkg/changesets/utils/version-files.js +0 -336
- package/packages/silk-effects/dist/dev/pkg/changesets/vendor/github-info.cjs +0 -77
- package/packages/silk-effects/dist/dev/pkg/changesets/vendor/github-info.js +0 -77
- package/packages/silk-effects/dist/dev/pkg/errors/ChangesetConfigError.cjs +0 -21
- package/packages/silk-effects/dist/dev/pkg/errors/ChangesetConfigError.js +0 -21
- package/packages/silk-effects/dist/dev/pkg/schemas/VersioningSchemas.cjs +0 -101
- package/packages/silk-effects/dist/dev/pkg/schemas/VersioningSchemas.js +0 -99
- package/packages/silk-effects/dist/dev/pkg/services/ChangesetConfig.cjs +0 -81
- package/packages/silk-effects/dist/dev/pkg/services/ChangesetConfig.js +0 -80
- package/packages/silk-effects/dist/dev/pkg/services/ChangesetConfigReader.cjs +0 -109
- package/packages/silk-effects/dist/dev/pkg/services/ChangesetConfigReader.js +0 -108
- package/packages/silk-effects/dist/dev/pkg/services/SilkPublishability.cjs +0 -238
- 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 };
|