@b64hub/sfpm-cli 0.3.0 → 0.5.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,142 @@
1
+ import path from 'node:path';
2
+ /**
3
+ * Determine the package selection mode from supplied flags.
4
+ *
5
+ * Ensures exactly one selection strategy is active; throws if multiple are specified.
6
+ *
7
+ * @param names - Explicitly named packages from argv
8
+ * @param tags - Package tags specified via --tag (matched against package.json keywords)
9
+ * @param dir - Directory path specified via --path
10
+ * @returns SelectionMode configured for the active strategy
11
+ * @throws Error if more than one selection mode is active
12
+ */
13
+ export function resolveSelectionMode(names, tags, dir) {
14
+ // Identify which modes are active
15
+ const active = [];
16
+ if (names.length > 0)
17
+ active.push('packages');
18
+ if (tags?.length)
19
+ active.push('--tag');
20
+ if (dir)
21
+ active.push('--path');
22
+ if (active.length > 1) {
23
+ throw new Error(`Select packages by exactly one of: package names, --tag, or --path (got ${active.join(', ')}).`);
24
+ }
25
+ if (names.length > 0)
26
+ return { kind: 'explicit', names };
27
+ if (tags?.length)
28
+ return { kind: 'tag', tags };
29
+ if (dir)
30
+ return { dir, kind: 'path' };
31
+ return { kind: 'all' };
32
+ }
33
+ /**
34
+ * Check if a child directory is within a parent directory.
35
+ *
36
+ * Both paths are resolved to absolute form.
37
+ * Returns true if child is exactly parent or a descendant of parent (not a sibling).
38
+ *
39
+ * @param parent - Parent directory path
40
+ * @param child - Child directory path
41
+ * @returns true if child is parent or within parent
42
+ */
43
+ function isWithin(parent, child) {
44
+ const absParent = path.resolve(parent);
45
+ const absChild = path.resolve(child);
46
+ // Exact match
47
+ if (absParent === absChild)
48
+ return true;
49
+ const rel = path.relative(absParent, absChild);
50
+ // rel starts with '..' => child is outside parent
51
+ // isAbsolute(rel) => child is on a different drive (windows)
52
+ // otherwise, rel is a relative path from parent to child
53
+ return !rel.startsWith('..') && !path.isAbsolute(rel);
54
+ }
55
+ /**
56
+ * Decide whether `release create` was invoked with no selection or naming
57
+ * signal at all — i.e. bare `sfpm release create`, which should launch the
58
+ * interactive guided walkthrough instead of failing on a missing --name.
59
+ *
60
+ * @param argv - Positional package name arguments
61
+ * @param flags - The subset of flags that count as a selection/naming signal
62
+ * @param flags.name - The --name flag value, if supplied
63
+ * @param flags.path - The --path flag value, if supplied
64
+ * @param flags.tag - The --tag flag value(s), if supplied
65
+ * @returns true when nothing was supplied and the wizard should run
66
+ */
67
+ export function isBareInvocation(argv, flags) {
68
+ return argv.length === 0 && !flags.tag?.length && !flags.path && !flags.name;
69
+ }
70
+ /**
71
+ * Collect the distinct package tags (package.json keywords) present across
72
+ * a set of workspace candidates, sorted for stable prompt/display order.
73
+ *
74
+ * @param candidates - Available workspace packages with metadata
75
+ * @returns Sorted array of distinct tag values
76
+ */
77
+ export function getDistinctTags(candidates) {
78
+ const tags = new Set();
79
+ for (const candidate of candidates) {
80
+ for (const keyword of candidate.keywords) {
81
+ tags.add(keyword);
82
+ }
83
+ }
84
+ return [...tags].sort();
85
+ }
86
+ /**
87
+ * Select package names from candidates using the specified selection mode.
88
+ *
89
+ * @param candidates - Available workspace packages with metadata
90
+ * @param mode - The selection strategy to apply
91
+ * @returns Array of selected package names
92
+ */
93
+ export function selectPackageNames(candidates, mode) {
94
+ switch (mode.kind) {
95
+ case 'all': {
96
+ return candidates.map(c => c.name);
97
+ }
98
+ case 'explicit': {
99
+ return mode.names;
100
+ }
101
+ case 'path': {
102
+ return candidates.filter(c => isWithin(mode.dir, c.dir)).map(c => c.name);
103
+ }
104
+ case 'tag': {
105
+ return candidates
106
+ .filter(c => mode.tags.some(t => c.keywords.includes(t)))
107
+ .map(c => c.name);
108
+ }
109
+ }
110
+ }
111
+ /**
112
+ * Reconcile a release manifest against what's currently in node_modules.
113
+ *
114
+ * Checks for:
115
+ * - Missing packages (declared but not installed)
116
+ * - Version mismatches (unless --skip-version-check is set)
117
+ *
118
+ * Uses exact string comparison, not semver.eq — a release pins an exact artifact.
119
+ *
120
+ * @param declared - Packages and versions from the release manifest
121
+ * @param resolved - Packages and versions currently in node_modules (from ArtifactProvider)
122
+ * @param options - Control behavior
123
+ * @param options.skipVersionCheck - Skip version mismatch checks (still validates packages are present)
124
+ * @returns Reconciliation result with missing and mismatched arrays
125
+ */
126
+ export function reconcileManifest(declared, resolved, options) {
127
+ const mismatched = [];
128
+ const missing = [];
129
+ for (const { name, version } of declared) {
130
+ const actual = resolved.get(name);
131
+ if (actual === undefined) {
132
+ missing.push(name);
133
+ continue;
134
+ }
135
+ // Only check version mismatch if not explicitly skipped
136
+ if (!options?.skipVersionCheck && actual !== version) {
137
+ mismatched.push({ actual, expected: version, name });
138
+ }
139
+ }
140
+ return { mismatched, missing };
141
+ }
142
+ //# sourceMappingURL=release.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release.js","sourceRoot":"","sources":["../../src/types/release.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAsB5B;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAe,EAAE,IAAe,EAAE,GAAY;IACjF,kCAAkC;IAClC,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IAC7C,IAAI,IAAI,EAAE,MAAM;QAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACtC,IAAI,GAAG;QAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAE9B,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,2EAA2E,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACnH,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAC,CAAA;IACtD,IAAI,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