@rulecad/versions 0.1.0 → 0.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/package.json +8 -3
- package/versions.d.mts +32 -0
- package/versions.mjs +9 -0
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/versions",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Semver for physical parts: a change to what other parts fit against is major, so you know when an old print stops fitting.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"exports":
|
|
6
|
+
"exports": {
|
|
7
|
+
"types": "./versions.d.mts",
|
|
8
|
+
"default": "./versions.mjs"
|
|
9
|
+
},
|
|
7
10
|
"files": [
|
|
8
11
|
"versions.mjs",
|
|
12
|
+
"versions.d.mts",
|
|
9
13
|
"README.md",
|
|
10
14
|
"LICENSE"
|
|
11
15
|
],
|
|
@@ -32,5 +36,6 @@
|
|
|
32
36
|
"dependencies": {
|
|
33
37
|
"@rulecad/variables": "^0.1.0",
|
|
34
38
|
"@rulecad/keyboard-layout": "^0.1.0"
|
|
35
|
-
}
|
|
39
|
+
},
|
|
40
|
+
"types": "./versions.d.mts"
|
|
36
41
|
}
|
package/versions.d.mts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** The next version. @param {string} v '1.2.3' @param {'major' | 'minor' | 'patch'} kind @returns {string} */
|
|
2
|
+
export function bump(v: string, kind: "major" | "minor" | "patch"): string;
|
|
3
|
+
/** Whether a version is in a range (^1.2.0, ~1.2.0 or 1.2.0); ^0.2.0 takes 0.3.0. @param {string} version @param {string} range @returns {boolean} */
|
|
4
|
+
export function satisfies(version: string, range: string): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* What changed between two snapshots of a design, and the bump that needs.
|
|
7
|
+
* @param {Snapshot} before @param {Snapshot} after
|
|
8
|
+
* @returns {{ kind: 'major' | 'minor' | 'patch' | null, reasons: { kind: 'major' | 'minor' | 'patch', text: string }[] }}
|
|
9
|
+
*/
|
|
10
|
+
export function compare(before: Snapshot, after: Snapshot): {
|
|
11
|
+
kind: "major" | "minor" | "patch" | null;
|
|
12
|
+
reasons: {
|
|
13
|
+
kind: "major" | "minor" | "patch";
|
|
14
|
+
text: string;
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
export function parse(v: any): number[];
|
|
18
|
+
export function newer(x: any, y: any): boolean;
|
|
19
|
+
export function bigger(k1: any, k2: any): any;
|
|
20
|
+
/**
|
|
21
|
+
* a design: its .json, resolve()'s entries and its code
|
|
22
|
+
*/
|
|
23
|
+
export type Snapshot = {
|
|
24
|
+
object: object;
|
|
25
|
+
entries: {
|
|
26
|
+
name: string;
|
|
27
|
+
value: any;
|
|
28
|
+
}[];
|
|
29
|
+
js: string;
|
|
30
|
+
layouts?: Record<string, object>;
|
|
31
|
+
engine?: string;
|
|
32
|
+
};
|
package/versions.mjs
CHANGED
|
@@ -9,8 +9,11 @@ import { fmt } from '@rulecad/variables';
|
|
|
9
9
|
import { project } from '@rulecad/keyboard-layout';
|
|
10
10
|
|
|
11
11
|
// ---------- semver ----------
|
|
12
|
+
/** @typedef {{ object: object, entries: { name: string, value: any }[], js: string, layouts?: Record<string, object>, engine?: string }} Snapshot a design: its .json, resolve()'s entries and its code */
|
|
13
|
+
|
|
12
14
|
const KINDS = ['patch', 'minor', 'major'];
|
|
13
15
|
export const parse = (v) => { const m = String(v).match(/^(\d+)\.(\d+)\.(\d+)$/); if (!m) throw new Error(`"${v}" isn't a version like 1.2.0`); return m.slice(1).map(Number); };
|
|
16
|
+
/** The next version. @param {string} v '1.2.3' @param {'major' | 'minor' | 'patch'} kind @returns {string} */
|
|
14
17
|
export function bump(v, kind) {
|
|
15
18
|
const [a, b, c] = parse(v);
|
|
16
19
|
return kind === 'major' ? `${a + 1}.0.0` : kind === 'minor' ? `${a}.${b + 1}.0` : `${a}.${b}.${c + 1}`;
|
|
@@ -20,6 +23,7 @@ export const bigger = (k1, k2) => (KINDS.indexOf(k1) >= KINDS.indexOf(k2) ? k1 :
|
|
|
20
23
|
|
|
21
24
|
|
|
22
25
|
// satisfies('0.2.1', '^0.2.0') -> true
|
|
26
|
+
/** Whether a version is in a range (^1.2.0, ~1.2.0 or 1.2.0); ^0.2.0 takes 0.3.0. @param {string} version @param {string} range @returns {boolean} */
|
|
23
27
|
export function satisfies(version, range) {
|
|
24
28
|
const m = String(range).match(/^([~^]?)(\d+\.\d+\.\d+)$/);
|
|
25
29
|
if (!m) throw new Error(`"${range}" isn't a version range like ^1.2.0, ~1.2.0 or 1.2.0`);
|
|
@@ -32,6 +36,11 @@ export function satisfies(version, range) {
|
|
|
32
36
|
// ---------- what changed ----------
|
|
33
37
|
// compare(before, after) -> { kind: 'major'|'minor'|'patch'|null, reasons }
|
|
34
38
|
// before/after: { object, entries, js } (entries from resolve(), js the design's source).
|
|
39
|
+
/**
|
|
40
|
+
* What changed between two snapshots of a design, and the bump that needs.
|
|
41
|
+
* @param {Snapshot} before @param {Snapshot} after
|
|
42
|
+
* @returns {{ kind: 'major' | 'minor' | 'patch' | null, reasons: { kind: 'major' | 'minor' | 'patch', text: string }[] }}
|
|
43
|
+
*/
|
|
35
44
|
export function compare(before, after) {
|
|
36
45
|
const reasons = [], add = (kind, text) => reasons.push({ kind, text });
|
|
37
46
|
const val = (r, name) => r.entries.find((e) => e.name === name);
|