@nestledjs/upgrades 0.3.0 → 0.3.2

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,119 @@
1
+ /**
2
+ * Every path with uncommitted changes at this moment — staged, unstaged, or untracked (each file of an
3
+ * untracked directory individually) — excluding our own `.nestled/` bookkeeping, the same exclusion
4
+ * `hasUncommittedChanges` makes. Both sides of a staged rename are included.
5
+ */
6
+ export declare function dirtyPaths(cwd: string): Set<string>;
7
+ /**
8
+ * Ignored paths that exist right now, as `git status --ignored` reports them, as a test of whether a
9
+ * path existed (as an ignored file) at this moment. Git collapses an ignored directory to one entry,
10
+ * so its files are listed here directly, up to a limit; inside a directory too large to list (a
11
+ * `node_modules`), every path counts as pre-existing, which can only ever leave a file behind.
12
+ */
13
+ export declare function ignoredPaths(cwd: string): (path: string) => boolean;
14
+ /**
15
+ * Every path a unified diff would create, modify, delete or rename (both sides), relative to the
16
+ * directory `git apply` runs in, minus paths matching `excludes` (the `--exclude` globs passed to
17
+ * `git apply`). Hunk bodies are skipped by their line counts, so a removed line that happens to read
18
+ * `-- a/x` is never mistaken for a header.
19
+ */
20
+ export declare function patchPaths(diffText: string, excludes?: string[]): string[];
21
+ /** What is at a path on disk, captured so it can be put back exactly. */
22
+ type FileState = {
23
+ kind: 'absent';
24
+ } | {
25
+ kind: 'file';
26
+ contents: Buffer;
27
+ mode: number;
28
+ } | {
29
+ kind: 'link';
30
+ target: string;
31
+ }
32
+ /** A directory or special file: never captured, never overwritten. A directory above a path keeps its mode. */
33
+ | {
34
+ kind: 'other';
35
+ mode?: number;
36
+ };
37
+ /** A path's state together with the state of each directory above it (a real directory, or a link). */
38
+ interface Captured {
39
+ state: FileState;
40
+ ancestors: {
41
+ absolute: string;
42
+ state: FileState;
43
+ }[];
44
+ }
45
+ /**
46
+ * The paths one apply run changes, each with how it looked before the run first touched it, so a
47
+ * rollback can put back exactly those paths and leave every other file alone.
48
+ *
49
+ * Call `willTouch` before writing a path. Its state at that moment is the pre-run state, because
50
+ * the run never writes a path it has not declared, and a path the user had uncommitted is refused
51
+ * before it gets here.
52
+ */
53
+ export declare class RunChanges {
54
+ private readonly root;
55
+ private readonly startCommit;
56
+ private readonly prior;
57
+ /** Pre-existing ignored files a step surfaced: restored on rollback, never committed as the run's. */
58
+ private readonly preserved;
59
+ /** A pre-existing ignored file a step surfaced: the user's, so no later note may write it. */
60
+ isPreserved(path: string): boolean;
61
+ /** `root` is the repository root; `startCommit` is HEAD before the run ('' on an unborn branch). */
62
+ constructor(root: string, startCommit: string);
63
+ get paths(): string[];
64
+ has(path: string): boolean;
65
+ willTouch(paths: Iterable<string>): void;
66
+ /**
67
+ * Record paths something the run did has already changed (an install's or a hook's side effects).
68
+ * Only paths that were clean before that step may be passed. Each was tracked at the start commit,
69
+ * did not exist, or existed but was ignored (`existedIgnored`): a step that changes an ignore rule,
70
+ * or force-adds and commits, can surface a file it never wrote. That last kind is the user's: it is
71
+ * kept as it is now and, after a rollback, put back the same way, unstaged. Returns the paths among
72
+ * `paths` that the run now owns, which never include the user's.
73
+ */
74
+ didChange(paths: Iterable<string>, existedIgnored?: (path: string) => boolean): string[];
75
+ /**
76
+ * Put `paths` (default: every path this run touched) back to their pre-run state, in both the
77
+ * index and the working tree. Nothing outside them is read or written.
78
+ */
79
+ restore(paths?: Iterable<string>): void;
80
+ /** Paths of `paths` present in the start commit's tree. */
81
+ private trackedAtStart;
82
+ /** Remove directories a created file left empty, up to (never including) the repository root. */
83
+ private pruneEmptyParents;
84
+ }
85
+ /**
86
+ * Every file and link under `dir` (repository-root-relative, ending in `/`), as root-relative paths,
87
+ * without following directory links. With `limit`, null once more than that many are found.
88
+ */
89
+ export declare function listFiles(root: string, dir: string, limit?: number): string[] | null;
90
+ /** The user's uncommitted work at a set of paths: what is on disk, and what is staged. */
91
+ export interface UserState {
92
+ files: Map<string, Captured>;
93
+ index: Map<string, string[]>;
94
+ }
95
+ /** Capture `paths` as they are now, on disk and in the index. */
96
+ export declare function snapshotFiles(root: string, paths: Iterable<string>): UserState;
97
+ /**
98
+ * Put back every snapshotted path whose file (contents, mode, symlink target, or presence) or index
99
+ * entry no longer matches, and return those paths. Used around steps that run third-party code (a
100
+ * package install, verification commands) on a dirty tree, so a script that rewrites, replaces or
101
+ * re-stages a file the user has uncommitted work in cannot cost them that work.
102
+ */
103
+ export interface RestoreResult {
104
+ /** Paths found changed and put back (or attempted): the caller blocks on any. */
105
+ restored: string[];
106
+ /** Paths that could not be put back, with where their saved state was written instead. */
107
+ unrecovered: {
108
+ path: string;
109
+ savedTo: string;
110
+ }[];
111
+ }
112
+ export declare function restoreChangedFiles(root: string, snapshot: UserState): RestoreResult;
113
+ /**
114
+ * Commit only `paths`, leaving anything else the user has staged or modified out of the commit and
115
+ * exactly as it was. Returns the new HEAD (short), the unchanged HEAD when none of `paths` changed,
116
+ * or '' when staging or committing failed (a commit hook rejecting it, say), like `commitAll`.
117
+ */
118
+ export declare function commitPaths(root: string, message: string, paths: string[]): string;
119
+ export {};