@ankhorage/devtools 2.3.14 → 2.3.15
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 +1 -1
- package/dist/tools/package/index.js +2 -1
- package/dist/tools/package/isCompatibleDevtoolsRange.d.ts +2 -0
- package/dist/tools/package/isCompatibleDevtoolsRange.js +39 -0
- package/dist/tools/workflows/files/ci.yml +20 -0
- package/dist/tools/workflows/files/release.yml +68 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
# @ankhorage/devtools
|
|
5
5
|
|
|
6
|
-
         
|
|
7
7
|
|
|
8
8
|
Shared tooling, repository automation, and agent standards for Ankhorage TypeScript projects
|
|
9
9
|
|
|
@@ -22,6 +22,7 @@ import { readFile, writeFile } from 'node:fs/promises';
|
|
|
22
22
|
import { resolve } from 'node:path';
|
|
23
23
|
import { REPOSITORY_RULE_METADATA } from '@ankhorage/rules-repository';
|
|
24
24
|
import { applyBunRuntimePolicy } from '../../policy/applyBunRuntimePolicy.js';
|
|
25
|
+
import { isCompatibleDevtoolsRange } from './isCompatibleDevtoolsRange.js';
|
|
25
26
|
import { resolvePackageCapabilitiesAsync } from './resolvePackageCapabilitiesAsync.js';
|
|
26
27
|
const PACKAGE_PATH = 'package.json';
|
|
27
28
|
const DEVTOOLS_PACKAGE_NAME = '@ankhorage/devtools';
|
|
@@ -183,7 +184,7 @@ function applyDevtoolsDependencyPlacement(dependencies, devDependencies, devtool
|
|
|
183
184
|
}
|
|
184
185
|
/*** Check that Devtools is development-only at the current synchronized version. */
|
|
185
186
|
function hasCurrentDevtoolsDependencyPlacement(dependencies, devDependencies, devtoolsVersion) {
|
|
186
|
-
return (devDependencies[DEVTOOLS_PACKAGE_NAME]
|
|
187
|
+
return (isCompatibleDevtoolsRange(devDependencies[DEVTOOLS_PACKAGE_NAME], devtoolsVersion) &&
|
|
187
188
|
dependencies[DEVTOOLS_PACKAGE_NAME] === undefined);
|
|
188
189
|
}
|
|
189
190
|
/*** Remove direct development dependencies owned by the Devtools package. */
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*** Check whether the declared Devtools caret range includes the executing Devtools release. */
|
|
2
|
+
export function isCompatibleDevtoolsRange(range, version) {
|
|
3
|
+
const rangeParts = parseStableVersion(typeof range === 'string' ? range.slice(1) : '');
|
|
4
|
+
const versionParts = parseStableVersion(version);
|
|
5
|
+
if (typeof range !== 'string' ||
|
|
6
|
+
!range.startsWith('^') ||
|
|
7
|
+
rangeParts === undefined ||
|
|
8
|
+
versionParts === undefined) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (rangeParts.major !== versionParts.major)
|
|
12
|
+
return false;
|
|
13
|
+
if (rangeParts.major > 0)
|
|
14
|
+
return compareStableVersions(versionParts, rangeParts) >= 0;
|
|
15
|
+
if (rangeParts.minor !== versionParts.minor)
|
|
16
|
+
return false;
|
|
17
|
+
if (rangeParts.minor > 0)
|
|
18
|
+
return versionParts.patch >= rangeParts.patch;
|
|
19
|
+
return versionParts.patch === rangeParts.patch;
|
|
20
|
+
}
|
|
21
|
+
/*** Parse one stable semantic version used by the managed Devtools range contract. */
|
|
22
|
+
function parseStableVersion(value) {
|
|
23
|
+
const match = /^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)$/u.exec(value);
|
|
24
|
+
if (match?.groups === undefined)
|
|
25
|
+
return undefined;
|
|
26
|
+
return {
|
|
27
|
+
major: Number(match.groups.major),
|
|
28
|
+
minor: Number(match.groups.minor),
|
|
29
|
+
patch: Number(match.groups.patch),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/*** Compare stable semantic-version tuples. */
|
|
33
|
+
function compareStableVersions(left, right) {
|
|
34
|
+
if (left.major !== right.major)
|
|
35
|
+
return left.major - right.major;
|
|
36
|
+
if (left.minor !== right.minor)
|
|
37
|
+
return left.minor - right.minor;
|
|
38
|
+
return left.patch - right.patch;
|
|
39
|
+
}
|
|
@@ -33,6 +33,26 @@ jobs:
|
|
|
33
33
|
- name: Install dependencies
|
|
34
34
|
run: bun install
|
|
35
35
|
|
|
36
|
+
- name: Reject package version rollback
|
|
37
|
+
if: github.event_name == 'pull_request'
|
|
38
|
+
run: |
|
|
39
|
+
base_sha='${{ github.event.pull_request.base.sha }}'
|
|
40
|
+
base_version="$(git show "${base_sha}:package.json" | node -e "let source=''; process.stdin.on('data',(chunk)=>source+=chunk); process.stdin.on('end',()=>process.stdout.write(JSON.parse(source).version ?? ''))")"
|
|
41
|
+
candidate_version="$(node -p "require('./package.json').version")"
|
|
42
|
+
BASE_VERSION="$base_version" CANDIDATE_VERSION="$candidate_version" node -e '
|
|
43
|
+
const parse = (value) => {
|
|
44
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/u.exec(value);
|
|
45
|
+
if (!match) throw new Error(`Expected a stable semantic version, received ${value}.`);
|
|
46
|
+
return match.slice(1).map(Number);
|
|
47
|
+
};
|
|
48
|
+
const base = parse(process.env.BASE_VERSION);
|
|
49
|
+
const candidate = parse(process.env.CANDIDATE_VERSION);
|
|
50
|
+
const index = candidate.findIndex((part, candidateIndex) => part !== base[candidateIndex]);
|
|
51
|
+
if (index !== -1 && candidate[index] < base[index]) {
|
|
52
|
+
throw new Error(`Package version rollback: ${process.env.CANDIDATE_VERSION} is lower than base ${process.env.BASE_VERSION}. Rebase and retain at least the base version before merging.`);
|
|
53
|
+
}
|
|
54
|
+
'
|
|
55
|
+
|
|
36
56
|
- name: Run build
|
|
37
57
|
run: |
|
|
38
58
|
if node -e "const p=require('./package.json'); process.exit(p.scripts?.build ? 0 : 1)"; then
|
|
@@ -91,6 +91,60 @@ jobs:
|
|
|
91
91
|
echo "No Ankh package metadata found; skipping capability materialization."
|
|
92
92
|
fi
|
|
93
93
|
|
|
94
|
+
- name: Verify npm release baseline
|
|
95
|
+
id: release-baseline
|
|
96
|
+
if: hashFiles('.changeset/config.json') != ''
|
|
97
|
+
run: |
|
|
98
|
+
package_name="$(node -p "require('./package.json').name")"
|
|
99
|
+
current_version="$(node -p "require('./package.json').version")"
|
|
100
|
+
registry_evidence="${RUNNER_TEMP}/npm-release-versions.json"
|
|
101
|
+
registry_error="${RUNNER_TEMP}/npm-release-versions.error"
|
|
102
|
+
|
|
103
|
+
if npm view "$package_name" versions --json > "$registry_evidence" 2> "$registry_error"; then
|
|
104
|
+
highest_published_version="$(node -e '
|
|
105
|
+
const raw = JSON.parse(require("node:fs").readFileSync(process.argv[1], "utf8"));
|
|
106
|
+
const parse = (value) => /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/u.exec(value)?.slice(1).map(Number);
|
|
107
|
+
const compare = (left, right) => {
|
|
108
|
+
const index = left.findIndex((part, candidate) => part !== right[candidate]);
|
|
109
|
+
return index === -1 ? 0 : left[index] - right[index];
|
|
110
|
+
};
|
|
111
|
+
const versions = Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : undefined;
|
|
112
|
+
if (versions === undefined || versions.length === 0 || versions.some((value) => typeof value !== "string")) {
|
|
113
|
+
throw new Error("npm registry returned an invalid version list.");
|
|
114
|
+
}
|
|
115
|
+
const stable = versions.filter((value) => parse(value));
|
|
116
|
+
if (stable.length === 0) throw new Error("npm registry returned no stable published version.");
|
|
117
|
+
stable.sort((left, right) => compare(parse(left), parse(right)));
|
|
118
|
+
process.stdout.write(stable.at(-1) ?? "");
|
|
119
|
+
' "$registry_evidence")"
|
|
120
|
+
elif node -e '
|
|
121
|
+
const { readFileSync } = require("node:fs");
|
|
122
|
+
const error = readFileSync(process.argv[1], "utf8");
|
|
123
|
+
const packageNotFound =
|
|
124
|
+
/^npm error code E404$/mu.test(error) &&
|
|
125
|
+
/^npm error 404 Not Found - GET https:\/\/registry\.npmjs\.org\/.+ - Not found$/mu.test(error) &&
|
|
126
|
+
/^npm error 404 .+ is not in this registry\.$/mu.test(error);
|
|
127
|
+
process.exit(packageNotFound ? 0 : 1);
|
|
128
|
+
' "$registry_error"; then
|
|
129
|
+
highest_published_version=""
|
|
130
|
+
else
|
|
131
|
+
echo "::error title=npm release baseline unavailable::Could not determine the highest published version for $package_name. Refusing to version or publish without registry evidence."
|
|
132
|
+
exit 1
|
|
133
|
+
fi
|
|
134
|
+
|
|
135
|
+
if [ -n "$highest_published_version" ]; then
|
|
136
|
+
CURRENT_VERSION="$current_version" HIGHEST_PUBLISHED_VERSION="$highest_published_version" node -e '
|
|
137
|
+
const parse = (value) => value.split(".").map(Number);
|
|
138
|
+
const current = parse(process.env.CURRENT_VERSION);
|
|
139
|
+
const highest = parse(process.env.HIGHEST_PUBLISHED_VERSION);
|
|
140
|
+
const index = current.findIndex((part, candidate) => part !== highest[candidate]);
|
|
141
|
+
if (index !== -1 && current[index] < highest[index]) {
|
|
142
|
+
throw new Error(`Package version rollback: ${process.env.CURRENT_VERSION} is lower than published npm version ${process.env.HIGHEST_PUBLISHED_VERSION}. Restore main to the published baseline before applying pending Changesets.`);
|
|
143
|
+
}
|
|
144
|
+
'
|
|
145
|
+
fi
|
|
146
|
+
echo "highest_published_version=$highest_published_version" >> "$GITHUB_OUTPUT"
|
|
147
|
+
|
|
94
148
|
- name: Validate release contract
|
|
95
149
|
run: |
|
|
96
150
|
if node -e "const p=require('./package.json'); process.exit(p.name === '@ankhorage/doctor' ? 0 : 1)"; then
|
|
@@ -102,6 +156,8 @@ jobs:
|
|
|
102
156
|
- name: Version packages directly on main
|
|
103
157
|
id: release
|
|
104
158
|
if: hashFiles('.changeset/config.json') != ''
|
|
159
|
+
env:
|
|
160
|
+
HIGHEST_PUBLISHED_VERSION: ${{ steps.release-baseline.outputs.highest_published_version }}
|
|
105
161
|
run: |
|
|
106
162
|
if [ -z "$(find .changeset -maxdepth 1 -type f -name '*.md' ! -name README.md -print -quit)" ]; then
|
|
107
163
|
current_version="$(node -p "require('./package.json').version")"
|
|
@@ -148,6 +204,18 @@ jobs:
|
|
|
148
204
|
fi
|
|
149
205
|
after_version="$(node -p "require('./package.json').version")"
|
|
150
206
|
|
|
207
|
+
if [ -n "$HIGHEST_PUBLISHED_VERSION" ]; then
|
|
208
|
+
CANDIDATE_VERSION="$after_version" HIGHEST_PUBLISHED_VERSION="$HIGHEST_PUBLISHED_VERSION" node -e '
|
|
209
|
+
const parse = (value) => value.split(".").map(Number);
|
|
210
|
+
const candidate = parse(process.env.CANDIDATE_VERSION);
|
|
211
|
+
const highest = parse(process.env.HIGHEST_PUBLISHED_VERSION);
|
|
212
|
+
const index = candidate.findIndex((part, candidateIndex) => part !== highest[candidateIndex]);
|
|
213
|
+
if (index === -1 || candidate[index] < highest[index]) {
|
|
214
|
+
throw new Error(`Release version ${process.env.CANDIDATE_VERSION} must be strictly greater than published npm version ${process.env.HIGHEST_PUBLISHED_VERSION}. Refusing to create a duplicate or rollback release.`);
|
|
215
|
+
}
|
|
216
|
+
'
|
|
217
|
+
fi
|
|
218
|
+
|
|
151
219
|
if [ "$before_version" != "$after_version" ]; then
|
|
152
220
|
if node -e "const p=require('./package.json'); process.exit(p.ankh?.structure === undefined ? 1 : 0)"; then
|
|
153
221
|
__ANKH_STRUCTURE_RELEASE_COMMAND__ build .
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/devtools",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.15",
|
|
4
4
|
"description": "Shared tooling, repository automation, and agent standards for Ankhorage TypeScript projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/ankhorage/devtools#readme",
|