dsh-trajectory-traceview-plus 0.10.0 → 0.11.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.
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Fail when the released version, its Git tag, and the changelog disagree.
4
+ *
5
+ * `README.md` §14 used to admit this was unchecked ("版本号与 tag 不一致 → 暂无自动
6
+ * 检查,人工确认"). A human reminder is exactly the kind of rule that rots: the
7
+ * dangerous case is silent, because `npm publish` succeeds whether or not the tag
8
+ * exists, and a tag can point at a commit whose `package.json` still says the old
9
+ * version — so the tarball a user installs is not the tree the tag claims.
10
+ *
11
+ * Three hard failures, one notice:
12
+ *
13
+ * F1 tag `v<version>` exists but that commit's package.json says another version
14
+ * F2 `CHANGELOG.md` has no heading for `<version>`
15
+ * F3 `<version>` is not greater than the highest other tag (version went backwards)
16
+ * note no tag yet — a development state, not an error
17
+ *
18
+ * Deliberately does NOT require a tag: work-in-progress commits bump the version
19
+ * before the tag is cut, and failing there would train people to skip the check.
20
+ *
21
+ * node scripts/version-check.mjs
22
+ */
23
+ import { execFileSync } from 'node:child_process';
24
+ import { readFileSync } from 'node:fs';
25
+ import { dirname, join } from 'node:path';
26
+ import { fileURLToPath } from 'node:url';
27
+
28
+ const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
29
+ const git = (...args) => execFileSync('git', args, { cwd: ROOT, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 }).trim();
30
+
31
+ const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
32
+ const version = String(pkg.version);
33
+
34
+ /** Numeric triple from `1.2.3` / `v1.2.3`; anything else (pre-release) keeps its text. */
35
+ function parse(v) {
36
+ const m = /^v?(\d+)\.(\d+)\.(\d+)(.*)$/.exec(v);
37
+ return m === null ? null : { nums: [Number(m[1]), Number(m[2]), Number(m[3])], rest: m[4] };
38
+ }
39
+ function compare(a, b) {
40
+ for (let i = 0; i < 3; i += 1) if (a.nums[i] !== b.nums[i]) return a.nums[i] - b.nums[i];
41
+ // A pre-release sorts BEFORE its release (1.0.0-rc < 1.0.0).
42
+ if (a.rest === b.rest) return 0;
43
+ if (a.rest === '') return 1;
44
+ if (b.rest === '') return -1;
45
+ return a.rest < b.rest ? -1 : 1;
46
+ }
47
+
48
+ const self = parse(version);
49
+ if (self === null) {
50
+ console.error('version-check: package.json version is not semver: ' + JSON.stringify(version));
51
+ process.exit(1);
52
+ }
53
+
54
+ const failures = [];
55
+ const notices = [];
56
+
57
+ // ── F3: the version must move forward relative to every other tag ──────────────
58
+ const tags = git('tag', '--list', 'v*').split('\n').filter(Boolean);
59
+ const others = tags.filter((t) => t !== 'v' + version).map((t) => ({ tag: t, v: parse(t) })).filter((x) => x.v !== null);
60
+ if (others.length > 0) {
61
+ const highest = others.reduce((best, x) => (compare(x.v, best.v) > 0 ? x : best));
62
+ if (compare(self, highest.v) <= 0) {
63
+ failures.push('F3 package.json is ' + version + ' but tag ' + highest.tag + ' is already that high or higher — the version went backwards');
64
+ }
65
+ }
66
+
67
+ // ── F1: an existing tag must describe the same version it is named after ───────
68
+ const tagName = 'v' + version;
69
+ if (tags.includes(tagName)) {
70
+ let taggedVersion = null;
71
+ try {
72
+ taggedVersion = JSON.parse(git('show', tagName + ':package.json')).version;
73
+ } catch {
74
+ failures.push('F1 tag ' + tagName + ' exists but its package.json could not be read');
75
+ }
76
+ if (taggedVersion !== null && String(taggedVersion) !== version) {
77
+ failures.push('F1 tag ' + tagName + ' points at a commit whose package.json says ' + taggedVersion + ' — the tag and the published tree disagree');
78
+ }
79
+ // A tag that is not reachable from HEAD cannot describe what is being shipped.
80
+ try {
81
+ git('merge-base', '--is-ancestor', tagName, 'HEAD');
82
+ } catch {
83
+ notices.push('tag ' + tagName + ' is not an ancestor of HEAD — this checkout is not the tagged tree');
84
+ }
85
+ } else {
86
+ notices.push('no tag ' + tagName + ' yet (development state; tag before publishing)');
87
+ }
88
+
89
+ // ── F2: the changelog must mention the version being released ─────────────────
90
+ let changelog = '';
91
+ try {
92
+ changelog = readFileSync(join(ROOT, 'CHANGELOG.md'), 'utf8');
93
+ } catch {
94
+ failures.push('F2 CHANGELOG.md is missing');
95
+ }
96
+ if (changelog !== '' && changelog.indexOf('## ' + version) < 0) {
97
+ failures.push('F2 CHANGELOG.md has no "## ' + version + '" heading — a release without an entry is a release nobody can read about');
98
+ }
99
+
100
+ for (const n of notices) console.log('version-check: note: ' + n);
101
+ if (failures.length > 0) {
102
+ for (const f of failures) console.error('version-check: FAIL ' + f);
103
+ process.exit(1);
104
+ }
105
+ console.log('VERSION OK (' + version + ', ' + tags.length + ' tag(s) seen)');
File without changes