@savvy-web/silk-effects 1.6.0 → 2.0.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.
- package/changesets/errors.js +44 -1
- package/changesets/index.js +8 -11
- package/changesets/services/deps-regen.js +152 -113
- package/changesets/services/release-planner.js +105 -81
- package/changesets/utils/dep-diff.js +81 -47
- package/changesets/utils/git.js +51 -0
- package/changesets/utils/publishability.js +14 -2
- package/index.d.ts +157 -141
- package/package.json +2 -2
- package/changesets/services/workspace-snapshot.js +0 -181
- package/changesets/utils/worktree-snapshot.js +0 -142
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { GitError } from "../errors.js";
|
|
2
|
-
import { Effect } from "effect";
|
|
3
|
-
import { readFileSync, readdirSync } from "node:fs";
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { execFileSync } from "node:child_process";
|
|
6
|
-
|
|
7
|
-
//#region src/changesets/utils/worktree-snapshot.ts
|
|
8
|
-
/**
|
|
9
|
-
* Shared helpers for `deps detect` and `deps regen` — both need to read
|
|
10
|
-
* workspace package snapshots from the live working tree (the "after"
|
|
11
|
-
* side of a dep diff that isn't pinned to a git ref) and to resolve the
|
|
12
|
-
* merge-base for the default `--from` ref.
|
|
13
|
-
*
|
|
14
|
-
* @remarks
|
|
15
|
-
* `WorkspaceSnapshotReader` covers the git-ref side via `git show`. This
|
|
16
|
-
* module is the working-tree counterpart — staged and unstaged
|
|
17
|
-
* `package.json` edits show up here, matching `analyze-branch`'s
|
|
18
|
-
* coverage of the working tree.
|
|
19
|
-
*
|
|
20
|
-
* @internal
|
|
21
|
-
*/
|
|
22
|
-
/**
|
|
23
|
-
* Run `git merge-base <base> HEAD`, returning the SHA. Errors propagate
|
|
24
|
-
* as {@link GitError}.
|
|
25
|
-
*
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
function gitMergeBase(cwd, base) {
|
|
29
|
-
return Effect.try({
|
|
30
|
-
try: () => execFileSync("git", [
|
|
31
|
-
"merge-base",
|
|
32
|
-
base,
|
|
33
|
-
"HEAD"
|
|
34
|
-
], {
|
|
35
|
-
cwd,
|
|
36
|
-
encoding: "utf8",
|
|
37
|
-
stdio: [
|
|
38
|
-
"ignore",
|
|
39
|
-
"pipe",
|
|
40
|
-
"pipe"
|
|
41
|
-
]
|
|
42
|
-
}).trim(),
|
|
43
|
-
catch: (error) => {
|
|
44
|
-
const stderr = error.stderr;
|
|
45
|
-
const text = typeof stderr === "string" ? stderr : stderr?.toString() ?? "";
|
|
46
|
-
return new GitError({
|
|
47
|
-
command: `git merge-base ${base} HEAD`,
|
|
48
|
-
cwd,
|
|
49
|
-
reason: text.trim() || (error.message ?? String(error))
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Normalize a pnpm-workspace.yaml glob entry for filesystem expansion.
|
|
56
|
-
*
|
|
57
|
-
* `packages/**` collapses to `packages/*` (retains the wildcard so the
|
|
58
|
-
* caller hits the directory-listing path); `packages/*` and a literal
|
|
59
|
-
* `packages/foo` are passed through unchanged.
|
|
60
|
-
*
|
|
61
|
-
* Returning the literal-path form for `packages/**` (i.e., `"packages"`)
|
|
62
|
-
* would route the caller through the "no wildcards" branch and silently
|
|
63
|
-
* skip every child workspace.
|
|
64
|
-
*
|
|
65
|
-
* @internal
|
|
66
|
-
*/
|
|
67
|
-
function normalizeWorkspaceGlob(glob) {
|
|
68
|
-
return glob.replace(/\/\*\*$/, "/*");
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Read every workspace package's `package.json` from the live working
|
|
72
|
-
* tree, returning {@link WorkspaceSnapshot} entries matching the shape
|
|
73
|
-
* `WorkspaceSnapshotReader.snapshotAt` produces for git refs.
|
|
74
|
-
*
|
|
75
|
-
* @remarks
|
|
76
|
-
* Falls back to root-only when `pnpm-workspace.yaml` is missing or
|
|
77
|
-
* unparseable. Uses `node:fs.readdirSync` for directory expansion
|
|
78
|
-
* (portable across platforms — `execFileSync("ls")` is not).
|
|
79
|
-
*
|
|
80
|
-
* @internal
|
|
81
|
-
*/
|
|
82
|
-
function snapshotFromWorktree(cwd) {
|
|
83
|
-
const snapshots = [];
|
|
84
|
-
const dirs = /* @__PURE__ */ new Set([cwd]);
|
|
85
|
-
for (const dir of expandWorkspaceDirs(cwd)) dirs.add(dir);
|
|
86
|
-
for (const dir of dirs) try {
|
|
87
|
-
const pkgJson = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
|
|
88
|
-
if (!pkgJson.name) continue;
|
|
89
|
-
const rel = dir === cwd ? "." : dir.slice(cwd.length + 1);
|
|
90
|
-
snapshots.push({
|
|
91
|
-
name: pkgJson.name,
|
|
92
|
-
relativePath: rel,
|
|
93
|
-
version: pkgJson.version ?? "0.0.0",
|
|
94
|
-
dependencies: pkgJson.dependencies ?? {},
|
|
95
|
-
devDependencies: pkgJson.devDependencies ?? {},
|
|
96
|
-
peerDependencies: pkgJson.peerDependencies ?? {},
|
|
97
|
-
optionalDependencies: pkgJson.optionalDependencies ?? {}
|
|
98
|
-
});
|
|
99
|
-
} catch {}
|
|
100
|
-
return snapshots;
|
|
101
|
-
}
|
|
102
|
-
function expandWorkspaceDirs(cwd) {
|
|
103
|
-
let yaml;
|
|
104
|
-
try {
|
|
105
|
-
yaml = readFileSync(join(cwd, "pnpm-workspace.yaml"), "utf8");
|
|
106
|
-
} catch {
|
|
107
|
-
return [];
|
|
108
|
-
}
|
|
109
|
-
const dirs = [];
|
|
110
|
-
const lines = yaml.split(/\r?\n/);
|
|
111
|
-
let inPackagesBlock = false;
|
|
112
|
-
for (const line of lines) {
|
|
113
|
-
if (/^\s*#/.test(line)) continue;
|
|
114
|
-
if (/^\s*packages\s*:\s*$/.test(line)) {
|
|
115
|
-
inPackagesBlock = true;
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (!inPackagesBlock) continue;
|
|
119
|
-
const m = line.match(/^\s+-\s+["']?(.+?)["']?\s*$/);
|
|
120
|
-
if (m) {
|
|
121
|
-
const glob = normalizeWorkspaceGlob(m[1]);
|
|
122
|
-
if (glob.includes("*") || glob.includes("?")) {
|
|
123
|
-
const prefix = glob.includes("/") ? glob.slice(0, glob.lastIndexOf("/") + 1) : "";
|
|
124
|
-
let entries = [];
|
|
125
|
-
try {
|
|
126
|
-
entries = readdirSync(join(cwd, prefix || "."));
|
|
127
|
-
} catch {
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
const regex = new RegExp(`^${glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]")}$`);
|
|
131
|
-
for (const entry of entries) {
|
|
132
|
-
const candidate = prefix ? `${prefix}${entry}` : entry;
|
|
133
|
-
if (regex.test(candidate)) dirs.push(join(cwd, candidate));
|
|
134
|
-
}
|
|
135
|
-
} else dirs.push(join(cwd, glob));
|
|
136
|
-
} else if (line.length > 0 && !line.startsWith(" ") && !line.startsWith(" ")) inPackagesBlock = false;
|
|
137
|
-
}
|
|
138
|
-
return dirs;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
//#endregion
|
|
142
|
-
export { gitMergeBase, normalizeWorkspaceGlob, snapshotFromWorktree };
|