workspace-tools 0.38.5 → 0.40.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/lib/{workspaces/readPackageInfo.d.ts → getPackageInfo.d.ts} +3 -3
- package/lib/{workspaces/readPackageInfo.js → getPackageInfo.js} +8 -8
- package/lib/getPackageInfo.js.map +1 -0
- package/lib/getPackageInfos.js +3 -3
- package/lib/getPackageInfos.js.map +1 -1
- package/lib/git/config.d.ts +8 -0
- package/lib/git/config.js +17 -0
- package/lib/git/config.js.map +1 -0
- package/lib/git/getDefaultRemoteBranch.js +2 -1
- package/lib/git/getDefaultRemoteBranch.js.map +1 -1
- package/lib/git/git.d.ts +30 -10
- package/lib/git/git.js +47 -9
- package/lib/git/git.js.map +1 -1
- package/lib/git/gitUtilities.d.ts +88 -50
- package/lib/git/gitUtilities.js +187 -314
- package/lib/git/gitUtilities.js.map +1 -1
- package/lib/git/index.d.ts +2 -1
- package/lib/git/index.js +9 -1
- package/lib/git/index.js.map +1 -1
- package/lib/git/types.d.ts +60 -0
- package/lib/git/types.js +3 -0
- package/lib/git/types.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/workspaces/catalogs.d.ts +9 -4
- package/lib/workspaces/catalogs.js +21 -12
- package/lib/workspaces/catalogs.js.map +1 -1
- package/lib/workspaces/getChangedPackages.d.ts +49 -20
- package/lib/workspaces/getChangedPackages.js +39 -56
- package/lib/workspaces/getChangedPackages.js.map +1 -1
- package/lib/workspaces/getPackagesByFiles.d.ts +15 -6
- package/lib/workspaces/getPackagesByFiles.js +16 -17
- package/lib/workspaces/getPackagesByFiles.js.map +1 -1
- package/lib/workspaces/getWorkspacePackageInfo.js +3 -3
- package/lib/workspaces/getWorkspacePackageInfo.js.map +1 -1
- package/lib/workspaces/implementations/yarn.js +2 -2
- package/lib/workspaces/implementations/yarn.js.map +1 -1
- package/package.json +1 -1
- package/lib/workspaces/readPackageInfo.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { PackageInfo } from "
|
|
1
|
+
import type { PackageInfo } from "./types/PackageInfo";
|
|
2
2
|
/**
|
|
3
3
|
* Read package.json from the given path if it exists.
|
|
4
4
|
* Logs a warning if it doesn't exist, or there's an error reading or parsing it.
|
|
5
5
|
* @returns The package info, or undefined if it doesn't exist or can't be read
|
|
6
6
|
*/
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function getPackageInfo(cwd: string): PackageInfo | undefined;
|
|
8
8
|
/**
|
|
9
9
|
* Read package.json from the given path if it exists.
|
|
10
10
|
* Logs a warning if it doesn't exist, or there's an error reading or parsing it.
|
|
11
11
|
* @returns The package info, or undefined if it doesn't exist or can't be read
|
|
12
12
|
*/
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function getPackageInfoAsync(cwd: string): Promise<PackageInfo | undefined>;
|
|
@@ -3,18 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getPackageInfoAsync = exports.getPackageInfo = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const infoFromPackageJson_1 = require("
|
|
11
|
-
const logging_1 = require("
|
|
10
|
+
const infoFromPackageJson_1 = require("./infoFromPackageJson");
|
|
11
|
+
const logging_1 = require("./logging");
|
|
12
12
|
/**
|
|
13
13
|
* Read package.json from the given path if it exists.
|
|
14
14
|
* Logs a warning if it doesn't exist, or there's an error reading or parsing it.
|
|
15
15
|
* @returns The package info, or undefined if it doesn't exist or can't be read
|
|
16
16
|
*/
|
|
17
|
-
function
|
|
17
|
+
function getPackageInfo(cwd) {
|
|
18
18
|
const packageJsonPath = path_1.default.join(cwd, "package.json");
|
|
19
19
|
try {
|
|
20
20
|
if (!fs_1.default.existsSync(packageJsonPath)) {
|
|
@@ -28,13 +28,13 @@ function readPackageInfo(cwd) {
|
|
|
28
28
|
(0, logging_1.logVerboseWarning)(`Error reading or parsing ${packageJsonPath}: ${e?.message || e}`);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
exports.
|
|
31
|
+
exports.getPackageInfo = getPackageInfo;
|
|
32
32
|
/**
|
|
33
33
|
* Read package.json from the given path if it exists.
|
|
34
34
|
* Logs a warning if it doesn't exist, or there's an error reading or parsing it.
|
|
35
35
|
* @returns The package info, or undefined if it doesn't exist or can't be read
|
|
36
36
|
*/
|
|
37
|
-
async function
|
|
37
|
+
async function getPackageInfoAsync(cwd) {
|
|
38
38
|
const packageJsonPath = path_1.default.join(cwd, "package.json");
|
|
39
39
|
try {
|
|
40
40
|
if (!fs_1.default.existsSync(packageJsonPath)) {
|
|
@@ -48,5 +48,5 @@ async function readPackageInfoAsync(cwd) {
|
|
|
48
48
|
(0, logging_1.logVerboseWarning)(`Error reading or parsing ${packageJsonPath}: ${e?.message || e}`);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
exports.
|
|
52
|
-
//# sourceMappingURL=
|
|
51
|
+
exports.getPackageInfoAsync = getPackageInfoAsync;
|
|
52
|
+
//# sourceMappingURL=getPackageInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPackageInfo.js","sourceRoot":"","sources":["../src/getPackageInfo.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,2DAAqC;AACrC,gDAAwB;AAExB,+DAA4D;AAC5D,uCAA8C;AAE9C;;;;GAIG;AACH,SAAgB,cAAc,CAAC,GAAW;IACxC,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IACvD,IAAI;QACF,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE;YACnC,IAAA,2BAAiB,EAAC,wBAAwB,eAAe,EAAE,CAAC,CAAC;YAC7D,OAAO,SAAS,CAAC;SAClB;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;QAC1E,OAAO,IAAA,yCAAmB,EAAC,WAAW,EAAE,eAAe,CAAC,CAAC;KAC1D;IAAC,OAAO,CAAC,EAAE;QACV,IAAA,2BAAiB,EAAC,4BAA4B,eAAe,KAAM,CAAW,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC;KACjG;AACH,CAAC;AAbD,wCAaC;AAED;;;;GAIG;AACI,KAAK,UAAU,mBAAmB,CAAC,GAAW;IACnD,MAAM,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IACvD,IAAI;QACF,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE;YACnC,IAAA,2BAAiB,EAAC,wBAAwB,eAAe,EAAE,CAAC,CAAC;YAC7D,OAAO,SAAS,CAAC;SAClB;QAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,kBAAU,CAAC,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;QACpF,OAAO,IAAA,yCAAmB,EAAC,WAAW,EAAE,eAAe,CAAC,CAAC;KAC1D;IAAC,OAAO,CAAC,EAAE;QACV,IAAA,2BAAiB,EAAC,4BAA4B,eAAe,KAAM,CAAW,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC;KACjG;AACH,CAAC;AAbD,kDAaC"}
|
package/lib/getPackageInfos.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPackageInfosAsync = exports.getPackageInfos = void 0;
|
|
4
4
|
const getWorkspaces_1 = require("./workspaces/getWorkspaces");
|
|
5
|
-
const
|
|
5
|
+
const getPackageInfo_1 = require("./getPackageInfo");
|
|
6
6
|
/**
|
|
7
7
|
* Read all the package.json files in a monorepo. Only works for monorepos which
|
|
8
8
|
* use a supported workspace manager.
|
|
@@ -17,7 +17,7 @@ function getPackageInfos(cwd) {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
const rootInfo = (0,
|
|
20
|
+
const rootInfo = (0, getPackageInfo_1.getPackageInfo)(cwd);
|
|
21
21
|
if (rootInfo) {
|
|
22
22
|
packageInfos[rootInfo.name] = rootInfo;
|
|
23
23
|
}
|
|
@@ -43,7 +43,7 @@ async function getPackageInfosAsync(cwd) {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
|
-
const rootInfo = (0,
|
|
46
|
+
const rootInfo = (0, getPackageInfo_1.getPackageInfo)(cwd);
|
|
47
47
|
if (rootInfo) {
|
|
48
48
|
packageInfos[rootInfo.name] = rootInfo;
|
|
49
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPackageInfos.js","sourceRoot":"","sources":["../src/getPackageInfos.ts"],"names":[],"mappings":";;;AACA,8DAA+E;AAC/E,
|
|
1
|
+
{"version":3,"file":"getPackageInfos.js","sourceRoot":"","sources":["../src/getPackageInfos.ts"],"names":[],"mappings":";;;AACA,8DAA+E;AAC/E,qDAAkD;AAElD;;;;GAIG;AACH,SAAgB,eAAe,CAAC,GAAW;IACzC,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,MAAM,iBAAiB,GAAG,IAAA,6BAAa,EAAC,GAAG,CAAC,CAAC;IAE7C,IAAI,iBAAiB,CAAC,MAAM,EAAE;QAC5B,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE;YACnC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC;SAC1C;KACF;SAAM;QACL,MAAM,QAAQ,GAAG,IAAA,+BAAc,EAAC,GAAG,CAAC,CAAC;QACrC,IAAI,QAAQ,EAAE;YACZ,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC;SACxC;KACF;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAhBD,0CAgBC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,oBAAoB,CAAC,GAAW;IACpD,MAAM,YAAY,GAAiB,EAAE,CAAC;IACtC,MAAM,iBAAiB,GAAG,MAAM,IAAA,kCAAkB,EAAC,GAAG,CAAC,CAAC;IAExD,IAAI,iBAAiB,CAAC,MAAM,EAAE;QAC5B,KAAK,MAAM,GAAG,IAAI,iBAAiB,EAAE;YACnC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,WAAW,CAAC;SAC1C;KACF;SAAM;QACL,MAAM,QAAQ,GAAG,IAAA,+BAAc,EAAC,GAAG,CAAC,CAAC;QACrC,IAAI,QAAQ,EAAE;YACZ,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC;SACxC;KACF;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAhBD,oDAgBC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GitCommonOptions } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Get the value of a git config key. Returns null if it's not set.
|
|
4
|
+
* (Note: setting `throwOnError: true` will cause it to fail if the key is unset.)
|
|
5
|
+
*/
|
|
6
|
+
export declare function getConfigValue(options: {
|
|
7
|
+
key: string;
|
|
8
|
+
} & GitCommonOptions): string | null;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConfigValue = void 0;
|
|
4
|
+
const git_1 = require("./git");
|
|
5
|
+
/**
|
|
6
|
+
* Get the value of a git config key. Returns null if it's not set.
|
|
7
|
+
* (Note: setting `throwOnError: true` will cause it to fail if the key is unset.)
|
|
8
|
+
*/
|
|
9
|
+
function getConfigValue(options) {
|
|
10
|
+
const { key, ...gitOptions } = options;
|
|
11
|
+
const results = (0, git_1.git)(["config", key], gitOptions);
|
|
12
|
+
// command failure here just means it's not set
|
|
13
|
+
return results.success ? results.stdout.trim() : null;
|
|
14
|
+
}
|
|
15
|
+
exports.getConfigValue = getConfigValue;
|
|
16
|
+
// Other config helpers can move here in the future
|
|
17
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/git/config.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAG5B;;;GAGG;AACH,SAAgB,cAAc,CAAC,OAA2C;IACxE,MAAM,EAAE,GAAG,EAAE,GAAG,UAAU,EAAE,GAAG,OAAO,CAAC;IACvC,MAAM,OAAO,GAAG,IAAA,SAAG,EAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC;IACjD,+CAA+C;IAC/C,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACxD,CAAC;AALD,wCAKC;AAED,mDAAmD"}
|
|
@@ -30,7 +30,8 @@ function getDefaultRemoteBranch(...args) {
|
|
|
30
30
|
.find((line) => line.includes("HEAD branch"))
|
|
31
31
|
?.replace(/^\s*HEAD branch:\s+/, "");
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
remoteDefaultBranch || (remoteDefaultBranch = (0, gitUtilities_1.getDefaultBranch)({ cwd, throwOnError: options.strict }));
|
|
34
|
+
return `${defaultRemote}/${remoteDefaultBranch}`;
|
|
34
35
|
}
|
|
35
36
|
exports.getDefaultRemoteBranch = getDefaultRemoteBranch;
|
|
36
37
|
//# sourceMappingURL=getDefaultRemoteBranch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDefaultRemoteBranch.js","sourceRoot":"","sources":["../../src/git/getDefaultRemoteBranch.ts"],"names":[],"mappings":";;;AAAA,yDAA+E;AAC/E,+BAA4B;AAC5B,iDAAkD;AAoBlD,SAAgB,sBAAsB,CAAC,GAAG,IAAgD;IACxF,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACxC,MAAM,OAAO,GACX,OAAO,eAAe,KAAK,QAAQ;QACjC,CAAC,CAAE,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,EAAE,OAAO,EAAoC;QAC9E,CAAC,CAAC,eAAe,CAAC;IACtB,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAEhC,MAAM,aAAa,GAAG,IAAA,mCAAgB,EAAC,OAAO,CAAC,CAAC;IAEhD,IAAI,MAAM,EAAE;QACV,OAAO,GAAG,aAAa,IAAI,MAAM,EAAE,CAAC;KACrC;IAED,MAAM,UAAU,GAAG,IAAA,SAAG,EAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACnE,IAAI,mBAAuC,CAAC;IAE5C,IAAI,UAAU,CAAC,OAAO,EAAE;QACtB;;;;;;;WAOG;QACH,mBAAmB,GAAG,UAAU,CAAC,MAAM;aACpC,KAAK,CAAC,IAAI,CAAC;aACX,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;YAC7C,EAAE,OAAO,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;KACxC;IAED,
|
|
1
|
+
{"version":3,"file":"getDefaultRemoteBranch.js","sourceRoot":"","sources":["../../src/git/getDefaultRemoteBranch.ts"],"names":[],"mappings":";;;AAAA,yDAA+E;AAC/E,+BAA4B;AAC5B,iDAAkD;AAoBlD,SAAgB,sBAAsB,CAAC,GAAG,IAAgD;IACxF,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACxC,MAAM,OAAO,GACX,OAAO,eAAe,KAAK,QAAQ;QACjC,CAAC,CAAE,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,EAAE,OAAO,EAAoC;QAC9E,CAAC,CAAC,eAAe,CAAC;IACtB,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAEhC,MAAM,aAAa,GAAG,IAAA,mCAAgB,EAAC,OAAO,CAAC,CAAC;IAEhD,IAAI,MAAM,EAAE;QACV,OAAO,GAAG,aAAa,IAAI,MAAM,EAAE,CAAC;KACrC;IAED,MAAM,UAAU,GAAG,IAAA,SAAG,EAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACnE,IAAI,mBAAuC,CAAC;IAE5C,IAAI,UAAU,CAAC,OAAO,EAAE;QACtB;;;;;;;WAOG;QACH,mBAAmB,GAAG,UAAU,CAAC,MAAM;aACpC,KAAK,CAAC,IAAI,CAAC;aACX,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;YAC7C,EAAE,OAAO,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;KACxC;IAED,mBAAmB,KAAnB,mBAAmB,GAAK,IAAA,+BAAgB,EAAC,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,EAAC;IAEhF,OAAO,GAAG,aAAa,IAAI,mBAAmB,EAAE,CAAC;AACnD,CAAC;AAnCD,wDAmCC"}
|
package/lib/git/git.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
-
import { SpawnSyncReturns } from "child_process";
|
|
5
|
-
import {
|
|
4
|
+
import { SpawnSyncOptions, SpawnSyncReturns } from "child_process";
|
|
5
|
+
import { GitCommonOptions } from "./types";
|
|
6
|
+
export type GitOptions = Omit<SpawnSyncOptions, "cwd"> & GitCommonOptions & {
|
|
7
|
+
/** Operation description to be used in error message (formatted as start of sentence) */
|
|
8
|
+
description?: string;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
};
|
|
6
11
|
export declare class GitError extends Error {
|
|
7
|
-
originalError: unknown;
|
|
8
|
-
|
|
12
|
+
readonly originalError: unknown;
|
|
13
|
+
readonly gitOutput?: GitProcessOutput;
|
|
14
|
+
constructor(message: string, originalError?: unknown, gitOutput?: GitProcessOutput);
|
|
9
15
|
}
|
|
10
16
|
export type GitProcessOutput = {
|
|
11
17
|
stderr: string;
|
|
@@ -22,20 +28,34 @@ export declare function addGitObserver(observer: GitObserver): () => void;
|
|
|
22
28
|
/** Clear all git observers */
|
|
23
29
|
export declare function clearGitObservers(): void;
|
|
24
30
|
/**
|
|
25
|
-
* Runs git command - use this for read-only commands
|
|
26
|
-
*
|
|
31
|
+
* Runs git command - use this for read-only commands, or if you'd like to explicitly check the
|
|
32
|
+
* result and implement custom error handling.
|
|
27
33
|
*
|
|
28
34
|
* The caller is responsible for validating the input.
|
|
29
35
|
* `shell` will always be set to false.
|
|
30
36
|
*/
|
|
31
|
-
export declare function git(args: string[], options?:
|
|
37
|
+
export declare function git(args: string[], options?: GitOptions): GitProcessOutput;
|
|
32
38
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
39
|
+
* Run a git command. Use this for commands that make critical changes to the filesystem.
|
|
40
|
+
* If it fails, throw an error and set `process.exitCode = 1` (unless `options.noExitCode` is set).
|
|
35
41
|
*
|
|
36
42
|
* The caller is responsible for validating the input.
|
|
37
43
|
* `shell` will always be set to false.
|
|
38
44
|
*/
|
|
39
|
-
export declare function gitFailFast(args: string[], options?:
|
|
45
|
+
export declare function gitFailFast(args: string[], options?: GitCommonOptions & {
|
|
40
46
|
noExitCode?: boolean;
|
|
41
47
|
}): void;
|
|
48
|
+
/**
|
|
49
|
+
* Processes git command output by splitting it into lines and filtering out empty lines.
|
|
50
|
+
* Also filters out `node_modules` lines if specified in options.
|
|
51
|
+
*
|
|
52
|
+
* If the command failed with stderr output, an error is thrown.
|
|
53
|
+
*
|
|
54
|
+
* @param output - The git command output to process
|
|
55
|
+
* @returns An array of lines (presumably file paths), or an empty array if the command failed
|
|
56
|
+
* without stderr output.
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
59
|
+
export declare function processGitOutput(output: GitProcessOutput, options?: {
|
|
60
|
+
excludeNodeModules?: boolean;
|
|
61
|
+
}): string[];
|
package/lib/git/git.js
CHANGED
|
@@ -3,17 +3,21 @@
|
|
|
3
3
|
// Basic git wrappers
|
|
4
4
|
//
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.gitFailFast = exports.git = exports.clearGitObservers = exports.addGitObserver = exports.GitError = void 0;
|
|
6
|
+
exports.processGitOutput = exports.gitFailFast = exports.git = exports.clearGitObservers = exports.addGitObserver = exports.GitError = void 0;
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
8
|
class GitError extends Error {
|
|
9
|
-
constructor(message, originalError) {
|
|
9
|
+
constructor(message, originalError, gitOutput) {
|
|
10
10
|
if (originalError instanceof Error) {
|
|
11
11
|
super(`${message}: ${originalError.message}`);
|
|
12
12
|
}
|
|
13
|
+
else if (gitOutput?.stderr) {
|
|
14
|
+
super(`${message} -- stderr:\n${gitOutput.stderr}`);
|
|
15
|
+
}
|
|
13
16
|
else {
|
|
14
17
|
super(message);
|
|
15
18
|
}
|
|
16
19
|
this.originalError = originalError;
|
|
20
|
+
this.gitOutput = gitOutput;
|
|
17
21
|
}
|
|
18
22
|
}
|
|
19
23
|
exports.GitError = GitError;
|
|
@@ -48,19 +52,28 @@ function removeGitObserver(observer) {
|
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
/**
|
|
51
|
-
* Runs git command - use this for read-only commands
|
|
52
|
-
*
|
|
55
|
+
* Runs git command - use this for read-only commands, or if you'd like to explicitly check the
|
|
56
|
+
* result and implement custom error handling.
|
|
53
57
|
*
|
|
54
58
|
* The caller is responsible for validating the input.
|
|
55
59
|
* `shell` will always be set to false.
|
|
56
60
|
*/
|
|
57
61
|
function git(args, options) {
|
|
58
|
-
isDebug && console.log(`git ${args.join(" ")}`);
|
|
59
62
|
if (args.some((arg) => arg.startsWith("--upload-pack"))) {
|
|
60
63
|
// This is a security issue and not needed for any expected usage of this library.
|
|
61
64
|
throw new GitError("git command contains --upload-pack, which is not allowed: " + args.join(" "));
|
|
62
65
|
}
|
|
63
|
-
const
|
|
66
|
+
const gitDescription = `git ${args.join(" ")}`;
|
|
67
|
+
const { throwOnError, description = gitDescription, debug = isDebug, ...spawnOptions } = options || {};
|
|
68
|
+
debug && console.log(gitDescription);
|
|
69
|
+
let results;
|
|
70
|
+
try {
|
|
71
|
+
// this only throws if git isn't found or other rare cases
|
|
72
|
+
results = (0, child_process_1.spawnSync)("git", args, { maxBuffer: defaultMaxBuffer, ...spawnOptions });
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
throw new GitError(`${description} failed (while spawning process)`, e);
|
|
76
|
+
}
|
|
64
77
|
const output = {
|
|
65
78
|
...results,
|
|
66
79
|
// these may be undefined if stdio: inherit is set
|
|
@@ -68,7 +81,7 @@ function git(args, options) {
|
|
|
68
81
|
stdout: (results.stdout || "").toString().trimEnd(),
|
|
69
82
|
success: results.status === 0,
|
|
70
83
|
};
|
|
71
|
-
if (
|
|
84
|
+
if (debug) {
|
|
72
85
|
console.log("exited with code " + results.status);
|
|
73
86
|
output.stdout && console.log("git stdout:\n", output.stdout);
|
|
74
87
|
output.stderr && console.warn("git stderr:\n", output.stderr);
|
|
@@ -81,12 +94,15 @@ function git(args, options) {
|
|
|
81
94
|
}
|
|
82
95
|
observing = false;
|
|
83
96
|
}
|
|
97
|
+
if (!output.success && throwOnError) {
|
|
98
|
+
throw new GitError(`${description} failed${output.stderr ? `\n${output.stderr}` : ""}`, undefined, output);
|
|
99
|
+
}
|
|
84
100
|
return output;
|
|
85
101
|
}
|
|
86
102
|
exports.git = git;
|
|
87
103
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
104
|
+
* Run a git command. Use this for commands that make critical changes to the filesystem.
|
|
105
|
+
* If it fails, throw an error and set `process.exitCode = 1` (unless `options.noExitCode` is set).
|
|
90
106
|
*
|
|
91
107
|
* The caller is responsible for validating the input.
|
|
92
108
|
* `shell` will always be set to false.
|
|
@@ -103,4 +119,26 @@ function gitFailFast(args, options) {
|
|
|
103
119
|
}
|
|
104
120
|
}
|
|
105
121
|
exports.gitFailFast = gitFailFast;
|
|
122
|
+
/**
|
|
123
|
+
* Processes git command output by splitting it into lines and filtering out empty lines.
|
|
124
|
+
* Also filters out `node_modules` lines if specified in options.
|
|
125
|
+
*
|
|
126
|
+
* If the command failed with stderr output, an error is thrown.
|
|
127
|
+
*
|
|
128
|
+
* @param output - The git command output to process
|
|
129
|
+
* @returns An array of lines (presumably file paths), or an empty array if the command failed
|
|
130
|
+
* without stderr output.
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
function processGitOutput(output, options) {
|
|
134
|
+
if (!output.success) {
|
|
135
|
+
// If the intent was to throw on failure, `throwOnError` should have been set for the git command.
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
return output.stdout
|
|
139
|
+
.split(/\n/)
|
|
140
|
+
.map((line) => line.trim())
|
|
141
|
+
.filter((line) => !!line && (!options?.excludeNodeModules || !line.includes("node_modules")));
|
|
142
|
+
}
|
|
143
|
+
exports.processGitOutput = processGitOutput;
|
|
106
144
|
//# sourceMappingURL=git.js.map
|
package/lib/git/git.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/git/git.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,qBAAqB;AACrB,EAAE;;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ACtB;QAED,MAAM,IAAI,QAAQ,CAAC,4CAA4C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;MAC3E,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE;MACtC,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;KAC7C;AACH,CAAC;AAXD,kCAWC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,gBAAgB,CAAC,MAAwB,EAAE,OAA0C;IACnG,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;QACnB,kGAAkG;QAClG,OAAO,EAAE,CAAC;KACX;IAED,OAAO,MAAM,CAAC,MAAM;SACjB,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,EAAE,kBAAkB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;AAClG,CAAC;AAVD,4CAUC"}
|
|
@@ -1,142 +1,170 @@
|
|
|
1
|
+
import type { GetChangesBetweenRefsOptions, GitBranchOptions, GitCommitOptions, GitCommonOptions, GitFetchOptions, GitInitOptions, GitStageOptions, ParsedRemoteBranch, ParseRemoteBranchOptions } from "./types";
|
|
1
2
|
/**
|
|
2
3
|
* Get a list of files with untracked changes.
|
|
3
|
-
* Throws an error on failure.
|
|
4
|
+
* Throws an error on failure by default.
|
|
4
5
|
*
|
|
5
6
|
* @returns An array of file paths with untracked changes
|
|
6
7
|
*/
|
|
8
|
+
export declare function getUntrackedChanges(options: GitCommonOptions): string[];
|
|
9
|
+
/** @deprecated Use object params version */
|
|
7
10
|
export declare function getUntrackedChanges(cwd: string): string[];
|
|
8
11
|
/**
|
|
9
|
-
* Fetch from the given remote.
|
|
10
|
-
* Throws an error on failure.
|
|
12
|
+
* Fetch from the given remote (and optionally branch) or all remotes.
|
|
13
|
+
* Throws an error on failure by default.
|
|
11
14
|
*/
|
|
15
|
+
export declare function fetchRemote(options: GitFetchOptions): void;
|
|
16
|
+
/** @deprecated Use object params version */
|
|
12
17
|
export declare function fetchRemote(remote: string, cwd: string): void;
|
|
13
18
|
/**
|
|
14
|
-
* Fetch from the given remote and branch.
|
|
15
|
-
*
|
|
19
|
+
* Fetch from the given remote and branch. Throws an error on failure.
|
|
20
|
+
* @deprecated Use `fetchRemote({ remote, remoteBranch, cwd })`
|
|
16
21
|
*/
|
|
17
22
|
export declare function fetchRemoteBranch(remote: string, remoteBranch: string, cwd: string): void;
|
|
18
23
|
/**
|
|
19
24
|
* Gets file paths with changes that have not been staged yet.
|
|
20
|
-
* Throws an error on failure.
|
|
25
|
+
* Throws an error on failure by default.
|
|
21
26
|
*
|
|
22
27
|
* @returns An array of relative file paths with unstaged changes
|
|
23
28
|
*/
|
|
29
|
+
export declare function getUnstagedChanges(options: GitCommonOptions): string[];
|
|
30
|
+
/** @deprecated Use object params version */
|
|
24
31
|
export declare function getUnstagedChanges(cwd: string): string[];
|
|
25
32
|
/**
|
|
26
33
|
* Gets file paths with changes between the current branch and the given branch.
|
|
27
34
|
* Throws an error on failure.
|
|
28
35
|
*
|
|
29
36
|
* @returns An array of relative file paths that have changed
|
|
37
|
+
* @deprecated Use `getBranchChanges({ branch, cwd })`
|
|
30
38
|
*/
|
|
31
39
|
export declare function getChanges(branch: string, cwd: string): string[];
|
|
32
40
|
/**
|
|
33
41
|
* Gets file paths with changes between the branch and the merge-base.
|
|
42
|
+
* Throws an error on failure by default.
|
|
34
43
|
*
|
|
35
44
|
* @returns An array of relative file paths that have changed
|
|
36
45
|
*/
|
|
46
|
+
export declare function getBranchChanges(options: GitBranchOptions): string[];
|
|
47
|
+
/** @deprecated Use object params version */
|
|
37
48
|
export declare function getBranchChanges(branch: string, cwd: string): string[];
|
|
38
49
|
/**
|
|
39
50
|
* Gets file paths with changes between two git references (commits, branches, tags).
|
|
40
|
-
* Throws an error on failure.
|
|
51
|
+
* Throws an error on failure by default.
|
|
41
52
|
*
|
|
42
|
-
* @param fromRef - The starting reference
|
|
43
|
-
* @param toRef - The ending reference
|
|
44
|
-
* @param options - Additional git diff options
|
|
45
|
-
* @param pattern - Optional file pattern to filter results
|
|
46
|
-
* @param cwd - The working directory
|
|
47
53
|
* @returns An array of file paths that have changed
|
|
48
54
|
*/
|
|
55
|
+
export declare function getChangesBetweenRefs(options: GetChangesBetweenRefsOptions): string[];
|
|
56
|
+
/** @deprecated Use object param version */
|
|
49
57
|
export declare function getChangesBetweenRefs(fromRef: string, toRef: string, options: string[], pattern: string, cwd: string): string[];
|
|
50
58
|
/**
|
|
51
59
|
* Gets all files with staged changes (files added to the index).
|
|
52
|
-
* Throws an error on failure.
|
|
60
|
+
* Throws an error on failure by default.
|
|
53
61
|
*
|
|
54
62
|
* @returns An array of relative file paths that have been staged
|
|
55
63
|
*/
|
|
64
|
+
export declare function getStagedChanges(options: GitCommonOptions): string[];
|
|
65
|
+
/** @deprecated Use object params version */
|
|
56
66
|
export declare function getStagedChanges(cwd: string): string[];
|
|
57
67
|
/**
|
|
58
|
-
* Gets recent commit messages between the specified branch and HEAD.
|
|
59
|
-
*
|
|
68
|
+
* Gets recent commit messages between the specified parent branch and HEAD.
|
|
69
|
+
* By default, returns an empty array if the operation fails.
|
|
60
70
|
*
|
|
61
71
|
* @returns An array of commit message strings
|
|
62
72
|
*/
|
|
73
|
+
export declare function getRecentCommitMessages(options: GitBranchOptions): string[];
|
|
74
|
+
/** @deprecated Use object params version */
|
|
63
75
|
export declare function getRecentCommitMessages(branch: string, cwd: string): string[];
|
|
64
76
|
/**
|
|
65
77
|
* Gets the user email from the git config.
|
|
66
78
|
* @returns The email string if found, null otherwise
|
|
67
79
|
*/
|
|
80
|
+
export declare function getUserEmail(options: GitCommonOptions): string | null;
|
|
81
|
+
/** @deprecated Use object params version */
|
|
68
82
|
export declare function getUserEmail(cwd: string): string | null;
|
|
69
83
|
/**
|
|
70
84
|
* Gets the current branch name.
|
|
85
|
+
* In detached HEAD state, returns "HEAD".
|
|
86
|
+
*
|
|
71
87
|
* @returns The branch name if successful, null otherwise
|
|
72
88
|
*/
|
|
73
|
-
export declare function getBranchName(
|
|
89
|
+
export declare function getBranchName(options: GitCommonOptions): string;
|
|
90
|
+
/** @deprecated Use object params version */
|
|
91
|
+
export declare function getBranchName(cwd: string): string;
|
|
74
92
|
/**
|
|
75
93
|
* Gets the full reference path for a given branch.
|
|
76
|
-
*
|
|
94
|
+
* `branch` here is the short branch name, e.g. `branch-name`.
|
|
77
95
|
* @returns The full branch reference (e.g., `refs/heads/branch-name`) if found, null otherwise
|
|
78
96
|
*/
|
|
97
|
+
export declare function getFullBranchRef(options: GitBranchOptions): string | null;
|
|
98
|
+
/** @deprecated Use object params version */
|
|
79
99
|
export declare function getFullBranchRef(branch: string, cwd: string): string | null;
|
|
80
100
|
/**
|
|
81
101
|
* Gets the short branch name from a full branch reference.
|
|
82
|
-
* Note this may not work properly for the current branch.
|
|
83
|
-
* @param fullBranchRef - The full branch reference (e.g., `refs/heads/branch-name`)
|
|
84
102
|
* @returns The short branch name if successful, null otherwise
|
|
85
103
|
*/
|
|
104
|
+
export declare function getShortBranchName(options: {
|
|
105
|
+
/** The full branch reference (e.g., `refs/heads/branch-name`) */
|
|
106
|
+
fullBranchRef: string;
|
|
107
|
+
} & GitCommonOptions): string | null;
|
|
108
|
+
/** @deprecated Use object params version */
|
|
86
109
|
export declare function getShortBranchName(fullBranchRef: string, cwd: string): string | null;
|
|
87
110
|
/**
|
|
88
111
|
* Gets the current commit hash (SHA).
|
|
89
112
|
* @returns The hash if successful, null otherwise
|
|
90
113
|
*/
|
|
114
|
+
export declare function getCurrentHash(options: GitCommonOptions): string | null;
|
|
115
|
+
/** @deprecated Use object params version */
|
|
91
116
|
export declare function getCurrentHash(cwd: string): string | null;
|
|
92
117
|
/**
|
|
93
118
|
* Get the commit hash in which the file was first added.
|
|
94
119
|
* @returns The commit hash if found, undefined otherwise
|
|
95
120
|
*/
|
|
121
|
+
export declare function getFileAddedHash(options: {
|
|
122
|
+
filename: string;
|
|
123
|
+
} & GitCommonOptions): string | undefined;
|
|
124
|
+
/** @deprecated Use object params version */
|
|
96
125
|
export declare function getFileAddedHash(filename: string, cwd: string): string | undefined;
|
|
97
126
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* Throws an error if required email or username is not provided and not already configured.
|
|
127
|
+
* Run `git init` and verify that the `user.name` and `user.email` configs are set (at any level).
|
|
128
|
+
* Throws an error if `git init` fails.
|
|
101
129
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* @param username - Optional username to set in git config
|
|
130
|
+
* If `user.email` and `user.name` aren't already set globally, and the missing value is provided
|
|
131
|
+
* in params, set it at the repo level. Otherwise, throw an error.
|
|
105
132
|
*/
|
|
133
|
+
export declare function init(options: GitInitOptions): void;
|
|
134
|
+
/** @deprecated Use object params version */
|
|
106
135
|
export declare function init(cwd: string, email?: string, username?: string): void;
|
|
107
136
|
/**
|
|
108
137
|
* Stages files matching the given patterns.
|
|
109
138
|
*/
|
|
139
|
+
export declare function stage(options: GitStageOptions): void;
|
|
140
|
+
/** @deprecated Use object params version */
|
|
110
141
|
export declare function stage(patterns: string[], cwd: string): void;
|
|
111
142
|
/**
|
|
112
|
-
*
|
|
113
|
-
* Throws an error on failure.
|
|
114
|
-
*
|
|
115
|
-
* @param message - The commit message
|
|
116
|
-
* @param cwd - The working directory
|
|
117
|
-
* @param options - Additional git commit options
|
|
143
|
+
* Commit changes. Throws an error on failure by default.
|
|
118
144
|
*/
|
|
145
|
+
export declare function commit(options: GitCommitOptions): void;
|
|
146
|
+
/** @deprecated Use object params version */
|
|
119
147
|
export declare function commit(message: string, cwd: string, options?: string[]): void;
|
|
120
148
|
/**
|
|
121
149
|
* Stages files matching the given patterns and creates a commit with the specified message.
|
|
122
150
|
* Convenience function that combines `stage()` and `commit()`.
|
|
123
|
-
* Throws an error on commit failure.
|
|
124
|
-
*
|
|
125
|
-
* @param patterns - File patterns to stage
|
|
126
|
-
* @param message - The commit message
|
|
127
|
-
* @param cwd - The working directory
|
|
128
|
-
* @param commitOptions - Additional git commit options
|
|
151
|
+
* Throws an error on commit failure by default.
|
|
129
152
|
*/
|
|
153
|
+
export declare function stageAndCommit(options: GitStageOptions & GitCommitOptions): void;
|
|
154
|
+
/** @deprecated Use object params version */
|
|
130
155
|
export declare function stageAndCommit(patterns: string[], message: string, cwd: string, commitOptions?: string[]): void;
|
|
131
156
|
/**
|
|
132
157
|
* Reverts all local changes (both staged and unstaged) by stashing them and then dropping the stash.
|
|
133
|
-
* @returns True if the revert was successful, false otherwise
|
|
158
|
+
* @returns True if the revert was successful, false otherwise. It will also be false if there were
|
|
159
|
+
* no changes to revert. (To distinguish between this case and errors, use the `throwOnError` option.)
|
|
134
160
|
*/
|
|
161
|
+
export declare function revertLocalChanges(options: GitCommonOptions): boolean;
|
|
162
|
+
/** @deprecated Use object params version */
|
|
135
163
|
export declare function revertLocalChanges(cwd: string): boolean;
|
|
136
164
|
/**
|
|
137
165
|
* Attempts to determine the parent branch of the current branch using `git show-branch`.
|
|
138
|
-
*
|
|
139
166
|
* @returns The parent branch name if found, null otherwise
|
|
167
|
+
* @deprecated Does not appear to be used
|
|
140
168
|
*/
|
|
141
169
|
export declare function getParentBranch(cwd: string): string | null;
|
|
142
170
|
/**
|
|
@@ -144,27 +172,37 @@ export declare function getParentBranch(cwd: string): string | null;
|
|
|
144
172
|
*
|
|
145
173
|
* @returns The remote branch name (e.g., `origin/main`) if found, null otherwise
|
|
146
174
|
*/
|
|
175
|
+
export declare function getRemoteBranch(options: GitBranchOptions): string | null;
|
|
176
|
+
/** @deprecated Use object params version */
|
|
147
177
|
export declare function getRemoteBranch(branch: string, cwd: string): string | null;
|
|
148
178
|
/**
|
|
149
|
-
*
|
|
179
|
+
* Get the remote and branch name from a full branch name that may include a remote prefix.
|
|
180
|
+
* If the path doesn't start with one of `options.knownRemotes` (but has multiple segments),
|
|
181
|
+
* the actual list of remotes will be fetched to see if one of those matches.
|
|
150
182
|
*
|
|
151
|
-
*
|
|
183
|
+
* NOTE: The additional verification is new in the object params version; the original version
|
|
184
|
+
* incorrectly assumes the first segment before a slash is always a remote.
|
|
152
185
|
*/
|
|
153
|
-
export declare function parseRemoteBranch(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
186
|
+
export declare function parseRemoteBranch(options: ParseRemoteBranchOptions): ParsedRemoteBranch;
|
|
187
|
+
/**
|
|
188
|
+
* @deprecated Use object params version, which does more verification. This version inaccurately
|
|
189
|
+
* assumes the first segment before a slash is always a remote, which could lead to tricky bugs.
|
|
190
|
+
*/
|
|
191
|
+
export declare function parseRemoteBranch(branch: string): ParsedRemoteBranch;
|
|
159
192
|
/**
|
|
160
193
|
* Gets the default branch based on `git config init.defaultBranch`, falling back to `master`.
|
|
161
194
|
*/
|
|
195
|
+
export declare function getDefaultBranch(options: GitCommonOptions): string;
|
|
196
|
+
/** @deprecated Use object params version */
|
|
162
197
|
export declare function getDefaultBranch(cwd: string): string;
|
|
163
198
|
/**
|
|
164
199
|
* Lists all tracked files matching the given patterns.
|
|
165
|
-
*
|
|
166
|
-
* @param patterns - File patterns to match (passed to git ls-files)
|
|
167
|
-
* @param cwd - The working directory
|
|
200
|
+
* Throws on error by default.
|
|
168
201
|
* @returns An array of file paths, or an empty array if no files are found
|
|
169
202
|
*/
|
|
203
|
+
export declare function listAllTrackedFiles(options: {
|
|
204
|
+
/** File patterns to match (passed to git ls-files) */
|
|
205
|
+
patterns: string[];
|
|
206
|
+
} & GitCommonOptions): string[];
|
|
207
|
+
/** @deprecated Use object params version */
|
|
170
208
|
export declare function listAllTrackedFiles(patterns: string[], cwd: string): string[];
|