workspace-tools 0.40.4 → 0.41.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/README.md +39 -1
- package/lib/dependencies/index.d.ts +2 -2
- package/lib/dependencies/index.js +31 -12
- package/lib/dependencies/index.js.map +1 -1
- package/lib/dependencies/transitiveDeps.d.ts +1 -1
- package/lib/dependencies/transitiveDeps.js +59 -38
- package/lib/dependencies/transitiveDeps.js.map +1 -1
- package/lib/getPackageInfo.d.ts +7 -5
- package/lib/getPackageInfo.js +46 -39
- package/lib/getPackageInfo.js.map +1 -1
- package/lib/getPackageInfos.d.ts +31 -8
- package/lib/getPackageInfos.js +41 -41
- package/lib/getPackageInfos.js.map +1 -1
- package/lib/git/config.d.ts +1 -1
- package/lib/git/config.js +15 -12
- package/lib/git/config.js.map +1 -1
- package/lib/git/getDefaultRemote.js +45 -30
- package/lib/git/getDefaultRemote.js.map +1 -1
- package/lib/git/getDefaultRemoteBranch.d.ts +1 -1
- package/lib/git/getDefaultRemoteBranch.js +35 -24
- package/lib/git/getDefaultRemoteBranch.js.map +1 -1
- package/lib/git/getRepositoryName.d.ts +1 -1
- package/lib/git/getRepositoryName.js +17 -19
- package/lib/git/getRepositoryName.js.map +1 -1
- package/lib/git/git.d.ts +2 -5
- package/lib/git/git.js +62 -64
- package/lib/git/git.js.map +1 -1
- package/lib/git/gitUtilities.d.ts +3 -3
- package/lib/git/gitUtilities.js +377 -147
- package/lib/git/gitUtilities.js.map +1 -1
- package/lib/git/index.d.ts +5 -5
- package/lib/git/index.js +50 -28
- package/lib/git/index.js.map +1 -1
- package/lib/git/types.js +4 -3
- package/lib/git/types.js.map +1 -1
- package/lib/graph/createDependencyMap.d.ts +12 -2
- package/lib/graph/createDependencyMap.js +18 -10
- package/lib/graph/createDependencyMap.js.map +1 -1
- package/lib/graph/createPackageGraph.d.ts +10 -6
- package/lib/graph/createPackageGraph.js +58 -42
- package/lib/graph/createPackageGraph.js.map +1 -1
- package/lib/graph/getPackageDependencies.d.ts +2 -2
- package/lib/graph/getPackageDependencies.js +24 -53
- package/lib/graph/getPackageDependencies.js.map +1 -1
- package/lib/graph/index.d.ts +4 -4
- package/lib/graph/index.js +25 -27
- package/lib/graph/index.js.map +1 -1
- package/lib/index.d.ts +29 -27
- package/lib/index.js +154 -75
- package/lib/index.js.map +1 -1
- package/lib/isCachingEnabled.js +17 -6
- package/lib/isCachingEnabled.js.map +1 -1
- package/lib/lockfile/nameAtVersion.js +9 -4
- package/lib/lockfile/nameAtVersion.js.map +1 -1
- package/lib/lockfile/parseBerryLock.d.ts +1 -1
- package/lib/lockfile/parseBerryLock.js +13 -11
- package/lib/lockfile/parseBerryLock.js.map +1 -1
- package/lib/lockfile/parseLockFile.d.ts +2 -0
- package/lib/lockfile/parseLockFile.js +87 -0
- package/lib/lockfile/parseLockFile.js.map +1 -0
- package/lib/lockfile/parseNpmLock.d.ts +1 -1
- package/lib/lockfile/parseNpmLock.js +15 -7
- package/lib/lockfile/parseNpmLock.js.map +1 -1
- package/lib/lockfile/parsePnpmLock.d.ts +1 -1
- package/lib/lockfile/parsePnpmLock.js +14 -9
- package/lib/lockfile/parsePnpmLock.js.map +1 -1
- package/lib/lockfile/queryLockFile.d.ts +1 -1
- package/lib/lockfile/queryLockFile.js +11 -6
- package/lib/lockfile/queryLockFile.js.map +1 -1
- package/lib/lockfile/readYaml.js +17 -9
- package/lib/lockfile/readYaml.js.map +1 -1
- package/lib/lockfile/types.js +3 -2
- package/lib/lockfile/types.js.map +1 -1
- package/lib/logging.js +10 -6
- package/lib/logging.js.map +1 -1
- package/lib/paths.d.ts +4 -1
- package/lib/paths.js +60 -58
- package/lib/paths.js.map +1 -1
- package/lib/scope.js +30 -21
- package/lib/scope.js.map +1 -1
- package/lib/types/Catalogs.js +8 -3
- package/lib/types/Catalogs.js.map +1 -1
- package/lib/types/PackageGraph.d.ts +5 -1
- package/lib/types/PackageGraph.js +4 -3
- package/lib/types/PackageGraph.js.map +1 -1
- package/lib/types/PackageInfo.d.ts +1 -1
- package/lib/types/PackageInfo.js +3 -2
- package/lib/types/PackageInfo.js.map +1 -1
- package/lib/types/WorkspaceInfo.d.ts +3 -5
- package/lib/types/WorkspaceInfo.js +3 -2
- package/lib/types/WorkspaceInfo.js.map +1 -1
- package/lib/types/WorkspaceManager.js +4 -0
- package/lib/types/WorkspaceManager.js.map +1 -0
- package/lib/workspaces/catalogsToYaml.d.ts +1 -1
- package/lib/workspaces/catalogsToYaml.js +12 -10
- package/lib/workspaces/catalogsToYaml.js.map +1 -1
- package/lib/workspaces/findWorkspacePath.d.ts +2 -1
- package/lib/workspaces/findWorkspacePath.js +10 -12
- package/lib/workspaces/findWorkspacePath.js.map +1 -1
- package/lib/workspaces/getAllPackageJsonFiles.d.ts +10 -4
- package/lib/workspaces/getAllPackageJsonFiles.js +32 -22
- package/lib/workspaces/getAllPackageJsonFiles.js.map +1 -1
- package/lib/workspaces/getCatalogVersion.d.ts +1 -1
- package/lib/workspaces/getCatalogVersion.js +19 -32
- package/lib/workspaces/getCatalogVersion.js.map +1 -1
- package/lib/workspaces/getCatalogs.d.ts +8 -2
- package/lib/workspaces/getCatalogs.js +23 -15
- package/lib/workspaces/getCatalogs.js.map +1 -1
- package/lib/workspaces/getChangedPackages.d.ts +1 -1
- package/lib/workspaces/getChangedPackages.js +47 -30
- package/lib/workspaces/getChangedPackages.js.map +1 -1
- package/lib/workspaces/getPackagesByFiles.js +29 -24
- package/lib/workspaces/getPackagesByFiles.js.map +1 -1
- package/lib/workspaces/getWorkspaceInfos.d.ts +36 -0
- package/lib/workspaces/getWorkspaceInfos.js +60 -0
- package/lib/workspaces/getWorkspaceInfos.js.map +1 -0
- package/lib/workspaces/getWorkspaceManagerRoot.d.ts +16 -0
- package/lib/workspaces/getWorkspaceManagerRoot.js +32 -0
- package/lib/workspaces/getWorkspaceManagerRoot.js.map +1 -0
- package/lib/workspaces/getWorkspacePackagePaths.d.ts +17 -2
- package/lib/workspaces/getWorkspacePackagePaths.js +138 -24
- package/lib/workspaces/getWorkspacePackagePaths.js.map +1 -1
- package/lib/workspaces/getWorkspacePatterns.d.ts +11 -0
- package/lib/workspaces/getWorkspacePatterns.js +25 -0
- package/lib/workspaces/getWorkspacePatterns.js.map +1 -0
- package/lib/workspaces/implementations/WorkspaceUtilities.d.ts +27 -0
- package/lib/workspaces/implementations/WorkspaceUtilities.js +4 -0
- package/lib/workspaces/implementations/WorkspaceUtilities.js.map +1 -0
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.d.ts +9 -0
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js +38 -0
- package/lib/workspaces/implementations/getPackageJsonWorkspacePatterns.js.map +1 -0
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.d.ts +19 -5
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js +38 -40
- package/lib/workspaces/implementations/getWorkspaceManagerAndRoot.js.map +1 -1
- package/lib/workspaces/implementations/getWorkspaceUtilities.d.ts +4 -36
- package/lib/workspaces/implementations/getWorkspaceUtilities.js +35 -20
- package/lib/workspaces/implementations/getWorkspaceUtilities.js.map +1 -1
- package/lib/workspaces/implementations/index.d.ts +2 -2
- package/lib/workspaces/implementations/index.js +19 -7
- package/lib/workspaces/implementations/index.js.map +1 -1
- package/lib/workspaces/implementations/lerna.d.ts +2 -20
- package/lib/workspaces/implementations/lerna.js +77 -62
- package/lib/workspaces/implementations/lerna.js.map +1 -1
- package/lib/workspaces/implementations/npm.d.ts +3 -17
- package/lib/workspaces/implementations/npm.js +12 -43
- package/lib/workspaces/implementations/npm.js.map +1 -1
- package/lib/workspaces/implementations/pnpm.d.ts +2 -30
- package/lib/workspaces/implementations/pnpm.js +32 -89
- package/lib/workspaces/implementations/pnpm.js.map +1 -1
- package/lib/workspaces/implementations/rush.d.ts +2 -22
- package/lib/workspaces/implementations/rush.js +26 -69
- package/lib/workspaces/implementations/rush.js.map +1 -1
- package/lib/workspaces/implementations/yarn.d.ts +2 -35
- package/lib/workspaces/implementations/yarn.js +33 -85
- package/lib/workspaces/implementations/yarn.js.map +1 -1
- package/lib/workspaces/wrapWorkspaceUtility.d.ts +31 -0
- package/lib/workspaces/wrapWorkspaceUtility.js +47 -0
- package/lib/workspaces/wrapWorkspaceUtility.js.map +1 -0
- package/package.json +21 -12
- package/lib/getPackagePaths.d.ts +0 -10
- package/lib/getPackagePaths.js +0 -49
- package/lib/getPackagePaths.js.map +0 -1
- package/lib/infoFromPackageJson.d.ts +0 -17
- package/lib/infoFromPackageJson.js +0 -11
- package/lib/infoFromPackageJson.js.map +0 -1
- package/lib/lockfile/index.d.ts +0 -6
- package/lib/lockfile/index.js +0 -105
- package/lib/lockfile/index.js.map +0 -1
- package/lib/workspaces/WorkspaceManager.js +0 -3
- package/lib/workspaces/WorkspaceManager.js.map +0 -1
- package/lib/workspaces/getWorkspacePackageInfo.d.ts +0 -26
- package/lib/workspaces/getWorkspacePackageInfo.js +0 -76
- package/lib/workspaces/getWorkspacePackageInfo.js.map +0 -1
- package/lib/workspaces/getWorkspaceRoot.d.ts +0 -25
- package/lib/workspaces/getWorkspaceRoot.js +0 -35
- package/lib/workspaces/getWorkspaceRoot.js.map +0 -1
- package/lib/workspaces/getWorkspaces.d.ts +0 -20
- package/lib/workspaces/getWorkspaces.js +0 -39
- package/lib/workspaces/getWorkspaces.js.map +0 -1
- package/lib/workspaces/implementations/packageJsonWorkspaces.d.ts +0 -31
- package/lib/workspaces/implementations/packageJsonWorkspaces.js +0 -104
- package/lib/workspaces/implementations/packageJsonWorkspaces.js.map +0 -1
- package/lib/workspaces/listOfWorkspacePackageNames.d.ts +0 -5
- package/lib/workspaces/listOfWorkspacePackageNames.js +0 -11
- package/lib/workspaces/listOfWorkspacePackageNames.js.map +0 -1
- /package/lib/{workspaces → types}/WorkspaceManager.d.ts +0 -0
package/lib/git/config.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getConfigValue", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getConfigValue;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _git = require("./git.js");
|
|
9
12
|
function getConfigValue(options) {
|
|
10
13
|
const { key, ...gitOptions } = options;
|
|
11
|
-
const results = (0,
|
|
14
|
+
const results = (0, _git.git)([
|
|
15
|
+
"config",
|
|
16
|
+
key
|
|
17
|
+
], gitOptions);
|
|
12
18
|
// command failure here just means it's not set
|
|
13
19
|
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
|
|
20
|
+
} // Other config helpers can move here in the future
|
package/lib/git/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/git/config.ts"],"sourcesContent":["import { git } from \"./git.js\";\nimport { type GitCommonOptions } from \"./types.js\";\n\n/**\n * Get the value of a git config key. Returns null if it's not set.\n * (Note: setting `throwOnError: true` will cause it to fail if the key is unset.)\n */\nexport function getConfigValue(options: { key: string } & GitCommonOptions): string | null {\n const { key, ...gitOptions } = options;\n const results = git([\"config\", key], gitOptions);\n // command failure here just means it's not set\n return results.success ? results.stdout.trim() : null;\n}\n\n// Other config helpers can move here in the future\n"],"names":["getConfigValue","options","key","gitOptions","results","git","success","stdout","trim"],"mappings":";;;;+BAOgBA;;;eAAAA;;;qBAPI;AAOb,SAASA,eAAeC,OAA2C;IACxE,MAAM,EAAEC,GAAG,EAAE,GAAGC,YAAY,GAAGF;IAC/B,MAAMG,UAAUC,IAAAA,QAAG,EAAC;QAAC;QAAUH;KAAI,EAAEC;IACrC,+CAA+C;IAC/C,OAAOC,QAAQE,OAAO,GAAGF,QAAQG,MAAM,CAACC,IAAI,KAAK;AACnD,EAEA,mDAAmD"}
|
|
@@ -1,50 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getDefaultRemote", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getDefaultRemote;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
+
const _paths = require("../paths.js");
|
|
14
|
+
const _getRepositoryName = require("./getRepositoryName.js");
|
|
15
|
+
const _git = require("./git.js");
|
|
16
|
+
function _interop_require_default(obj) {
|
|
17
|
+
return obj && obj.__esModule ? obj : {
|
|
18
|
+
default: obj
|
|
19
|
+
};
|
|
20
|
+
}
|
|
12
21
|
function getDefaultRemote(cwdOrOptions) {
|
|
13
|
-
const options = typeof cwdOrOptions === "string" ? {
|
|
22
|
+
const options = typeof cwdOrOptions === "string" ? {
|
|
23
|
+
cwd: cwdOrOptions
|
|
24
|
+
} : cwdOrOptions;
|
|
14
25
|
const { cwd, strict, verbose } = options;
|
|
15
|
-
const log = (message)
|
|
16
|
-
const logOrThrow = (message)
|
|
26
|
+
const log = (message)=>verbose && console.log(message);
|
|
27
|
+
const logOrThrow = (message)=>{
|
|
17
28
|
if (strict) {
|
|
18
29
|
throw new Error(message);
|
|
19
30
|
}
|
|
20
31
|
log(message);
|
|
21
32
|
};
|
|
22
|
-
const gitRoot = (0,
|
|
33
|
+
const gitRoot = (0, _paths.findGitRoot)(cwd);
|
|
23
34
|
let packageJson = {};
|
|
24
|
-
const packageJsonPath =
|
|
35
|
+
const packageJsonPath = _path.default.join(gitRoot, "package.json");
|
|
25
36
|
try {
|
|
26
|
-
packageJson = JSON.parse(
|
|
27
|
-
}
|
|
28
|
-
catch (e) {
|
|
37
|
+
packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, "utf8").trim());
|
|
38
|
+
} catch (e) {
|
|
29
39
|
logOrThrow(`Could not read "${packageJsonPath}"`);
|
|
30
40
|
}
|
|
31
41
|
const { repository } = packageJson;
|
|
32
|
-
const repositoryUrl = typeof repository === "string" ? repository :
|
|
42
|
+
const repositoryUrl = typeof repository === "string" ? repository : repository && repository.url || "";
|
|
33
43
|
if (!repositoryUrl) {
|
|
34
44
|
// This is always logged because it's strongly recommended to fix
|
|
35
45
|
console.log(`Valid "repository" key not found in "${packageJsonPath}". Consider adding this info for more accurate git remote detection.`);
|
|
36
46
|
}
|
|
37
|
-
/** Repository full name (owner and repo name) specified in package.json */
|
|
38
|
-
const
|
|
39
|
-
|
|
47
|
+
/** Repository full name (owner and repo name) specified in package.json */ const repositoryName = (0, _getRepositoryName.getRepositoryName)(repositoryUrl);
|
|
48
|
+
const remotesResult = (0, _git.git)([
|
|
49
|
+
"remote",
|
|
50
|
+
"-v"
|
|
51
|
+
], {
|
|
52
|
+
cwd
|
|
53
|
+
});
|
|
40
54
|
if (!remotesResult.success) {
|
|
41
55
|
logOrThrow(`Could not determine available git remotes under "${cwd}"`);
|
|
42
56
|
}
|
|
43
|
-
/** Mapping from remote URL to full name (owner and repo name) */
|
|
44
|
-
|
|
45
|
-
remotesResult.stdout.split("\n").forEach((line) => {
|
|
57
|
+
/** Mapping from remote URL to full name (owner and repo name) */ const remotes = {};
|
|
58
|
+
remotesResult.stdout.split("\n").forEach((line)=>{
|
|
46
59
|
const [remoteName, remoteUrl] = line.split(/\s+/);
|
|
47
|
-
const remoteRepoName = (0,
|
|
60
|
+
const remoteRepoName = (0, _getRepositoryName.getRepositoryName)(remoteUrl);
|
|
48
61
|
if (remoteRepoName) {
|
|
49
62
|
remotes[remoteRepoName] = remoteName;
|
|
50
63
|
}
|
|
@@ -59,8 +72,12 @@ function getDefaultRemote(cwdOrOptions) {
|
|
|
59
72
|
}
|
|
60
73
|
// Default to upstream or origin if available, or the first remote otherwise
|
|
61
74
|
const allRemoteNames = Object.values(remotes);
|
|
62
|
-
const fallbacks = [
|
|
63
|
-
|
|
75
|
+
const fallbacks = [
|
|
76
|
+
"upstream",
|
|
77
|
+
"origin",
|
|
78
|
+
...allRemoteNames
|
|
79
|
+
];
|
|
80
|
+
for (const fallback of fallbacks){
|
|
64
81
|
if (allRemoteNames.includes(fallback)) {
|
|
65
82
|
log(`Default to remote "${fallback}"`);
|
|
66
83
|
return fallback;
|
|
@@ -73,5 +90,3 @@ function getDefaultRemote(cwdOrOptions) {
|
|
|
73
90
|
log(`Assuming default remote "origin".`);
|
|
74
91
|
return "origin";
|
|
75
92
|
}
|
|
76
|
-
exports.getDefaultRemote = getDefaultRemote;
|
|
77
|
-
//# sourceMappingURL=getDefaultRemote.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/git/getDefaultRemote.ts"],"sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport { findGitRoot } from \"../paths.js\";\nimport { type PackageInfo } from \"../types/PackageInfo.js\";\nimport { getRepositoryName } from \"./getRepositoryName.js\";\nimport { git } from \"./git.js\";\n\nexport type GetDefaultRemoteOptions = {\n /** Get repository info relative to this directory. */\n cwd: string;\n /**\n * If true, throw an error if remote info can't be found, or if a `repository` is not specified\n * in package.json and no matching remote is found.\n */\n strict?: boolean;\n /** If true, log debug messages about how the remote was chosen */\n verbose?: boolean;\n};\n\n/**\n * Get the name of the default remote: the one matching the `repository` field in package.json.\n * Throws if `options.cwd` is not in a git repo or there's no package.json at the repo root.\n *\n * The order of preference for returned remotes is:\n * 1. If `repository` is defined in package.json, the remote with a matching URL (if `options.strict`\n * is true, throws an error if no matching remote exists)\n * 2. `upstream` if defined\n * 3. `origin` if defined\n * 4. The first defined remote\n * 5. If there are no defined remotes: throws an error if `options.strict` is true; otherwise returns `origin`\n *\n * @returns The name of the inferred default remote.\n */\nexport function getDefaultRemote(options: GetDefaultRemoteOptions): string;\n/** @deprecated Use the object param version */\nexport function getDefaultRemote(cwd: string): string;\nexport function getDefaultRemote(cwdOrOptions: string | GetDefaultRemoteOptions): string {\n const options = typeof cwdOrOptions === \"string\" ? { cwd: cwdOrOptions } : cwdOrOptions;\n const { cwd, strict, verbose } = options;\n\n const log = (message: string) => verbose && console.log(message);\n const logOrThrow = (message: string) => {\n if (strict) {\n throw new Error(message);\n }\n log(message);\n };\n\n const gitRoot = findGitRoot(cwd);\n\n let packageJson: Partial<PackageInfo> = {};\n const packageJsonPath = path.join(gitRoot, \"package.json\");\n try {\n packageJson = JSON.parse(fs.readFileSync(packageJsonPath, \"utf8\").trim());\n } catch (e) {\n logOrThrow(`Could not read \"${packageJsonPath}\"`);\n }\n\n const { repository } = packageJson;\n const repositoryUrl = typeof repository === \"string\" ? repository : (repository && repository.url) || \"\";\n if (!repositoryUrl) {\n // This is always logged because it's strongly recommended to fix\n console.log(\n `Valid \"repository\" key not found in \"${packageJsonPath}\". Consider adding this info for more accurate git remote detection.`\n );\n }\n /** Repository full name (owner and repo name) specified in package.json */\n const repositoryName = getRepositoryName(repositoryUrl);\n\n const remotesResult = git([\"remote\", \"-v\"], { cwd });\n if (!remotesResult.success) {\n logOrThrow(`Could not determine available git remotes under \"${cwd}\"`);\n }\n\n /** Mapping from remote URL to full name (owner and repo name) */\n const remotes: { [remoteRepoUrl: string]: string } = {};\n remotesResult.stdout.split(\"\\n\").forEach((line) => {\n const [remoteName, remoteUrl] = line.split(/\\s+/);\n const remoteRepoName = getRepositoryName(remoteUrl);\n if (remoteRepoName) {\n remotes[remoteRepoName] = remoteName;\n }\n });\n\n if (repositoryName) {\n // If the repository name was found in package.json, check for a matching remote\n if (remotes[repositoryName]) {\n return remotes[repositoryName];\n }\n\n // If `strict` is true, and repositoryName is found, there MUST be a matching remote\n logOrThrow(`Could not find remote pointing to repository \"${repositoryName}\".`);\n }\n\n // Default to upstream or origin if available, or the first remote otherwise\n const allRemoteNames = Object.values(remotes);\n const fallbacks = [\"upstream\", \"origin\", ...allRemoteNames];\n for (const fallback of fallbacks) {\n if (allRemoteNames.includes(fallback)) {\n log(`Default to remote \"${fallback}\"`);\n return fallback;\n }\n }\n\n // If we get here, no git remotes were found. This should probably always be an error (since\n // subsequent operations which require a remote likely won't work), but to match old behavior,\n // still default to \"origin\" unless `strict` is true.\n logOrThrow(`Could not find any remotes in git repo at \"${gitRoot}\".`);\n log(`Assuming default remote \"origin\".`);\n return \"origin\";\n}\n"],"names":["getDefaultRemote","cwdOrOptions","options","cwd","strict","verbose","log","message","console","logOrThrow","Error","gitRoot","findGitRoot","packageJson","packageJsonPath","path","join","JSON","parse","fs","readFileSync","trim","e","repository","repositoryUrl","url","repositoryName","getRepositoryName","remotesResult","git","success","remotes","stdout","split","forEach","line","remoteName","remoteUrl","remoteRepoName","allRemoteNames","Object","values","fallbacks","fallback","includes"],"mappings":";;;;+BAoCgBA;;;eAAAA;;;2DApCD;6DACE;uBACW;mCAEM;qBACd;;;;;;AA+Bb,SAASA,iBAAiBC,YAA8C;IAC7E,MAAMC,UAAU,OAAOD,iBAAiB,WAAW;QAAEE,KAAKF;IAAa,IAAIA;IAC3E,MAAM,EAAEE,GAAG,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGH;IAEjC,MAAMI,MAAM,CAACC,UAAoBF,WAAWG,QAAQF,GAAG,CAACC;IACxD,MAAME,aAAa,CAACF;QAClB,IAAIH,QAAQ;YACV,MAAM,IAAIM,MAAMH;QAClB;QACAD,IAAIC;IACN;IAEA,MAAMI,UAAUC,IAAAA,kBAAW,EAACT;IAE5B,IAAIU,cAAoC,CAAC;IACzC,MAAMC,kBAAkBC,aAAI,CAACC,IAAI,CAACL,SAAS;IAC3C,IAAI;QACFE,cAAcI,KAAKC,KAAK,CAACC,WAAE,CAACC,YAAY,CAACN,iBAAiB,QAAQO,IAAI;IACxE,EAAE,OAAOC,GAAG;QACVb,WAAW,CAAC,gBAAgB,EAAEK,gBAAgB,CAAC,CAAC;IAClD;IAEA,MAAM,EAAES,UAAU,EAAE,GAAGV;IACvB,MAAMW,gBAAgB,OAAOD,eAAe,WAAWA,aAAa,AAACA,cAAcA,WAAWE,GAAG,IAAK;IACtG,IAAI,CAACD,eAAe;QAClB,iEAAiE;QACjEhB,QAAQF,GAAG,CACT,CAAC,qCAAqC,EAAEQ,gBAAgB,oEAAoE,CAAC;IAEjI;IACA,yEAAyE,GACzE,MAAMY,iBAAiBC,IAAAA,oCAAiB,EAACH;IAEzC,MAAMI,gBAAgBC,IAAAA,QAAG,EAAC;QAAC;QAAU;KAAK,EAAE;QAAE1B;IAAI;IAClD,IAAI,CAACyB,cAAcE,OAAO,EAAE;QAC1BrB,WAAW,CAAC,iDAAiD,EAAEN,IAAI,CAAC,CAAC;IACvE;IAEA,+DAA+D,GAC/D,MAAM4B,UAA+C,CAAC;IACtDH,cAAcI,MAAM,CAACC,KAAK,CAAC,MAAMC,OAAO,CAAC,CAACC;QACxC,MAAM,CAACC,YAAYC,UAAU,GAAGF,KAAKF,KAAK,CAAC;QAC3C,MAAMK,iBAAiBX,IAAAA,oCAAiB,EAACU;QACzC,IAAIC,gBAAgB;YAClBP,OAAO,CAACO,eAAe,GAAGF;QAC5B;IACF;IAEA,IAAIV,gBAAgB;QAClB,gFAAgF;QAChF,IAAIK,OAAO,CAACL,eAAe,EAAE;YAC3B,OAAOK,OAAO,CAACL,eAAe;QAChC;QAEA,oFAAoF;QACpFjB,WAAW,CAAC,8CAA8C,EAAEiB,eAAe,EAAE,CAAC;IAChF;IAEA,4EAA4E;IAC5E,MAAMa,iBAAiBC,OAAOC,MAAM,CAACV;IACrC,MAAMW,YAAY;QAAC;QAAY;WAAaH;KAAe;IAC3D,KAAK,MAAMI,YAAYD,UAAW;QAChC,IAAIH,eAAeK,QAAQ,CAACD,WAAW;YACrCrC,IAAI,CAAC,mBAAmB,EAAEqC,SAAS,CAAC,CAAC;YACrC,OAAOA;QACT;IACF;IAEA,4FAA4F;IAC5F,8FAA8F;IAC9F,qDAAqD;IACrDlC,WAAW,CAAC,2CAA2C,EAAEE,QAAQ,EAAE,CAAC;IACpEL,IAAI,CAAC,iCAAiC,CAAC;IACvC,OAAO;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GetDefaultRemoteOptions } from "./getDefaultRemote";
|
|
1
|
+
import { type GetDefaultRemoteOptions } from "./getDefaultRemote.js";
|
|
2
2
|
export type GetDefaultRemoteBranchOptions = GetDefaultRemoteOptions & {
|
|
3
3
|
/** Name of branch to use. If undefined, uses the default branch name (falling back to `master`). */
|
|
4
4
|
branch?: string;
|
|
@@ -1,37 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getDefaultRemoteBranch", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getDefaultRemoteBranch;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _getDefaultRemote = require("./getDefaultRemote.js");
|
|
12
|
+
const _git = require("./git.js");
|
|
13
|
+
const _gitUtilities = require("./gitUtilities.js");
|
|
7
14
|
function getDefaultRemoteBranch(...args) {
|
|
8
15
|
const [branchOrOptions, argsCwd] = args;
|
|
9
|
-
const options = typeof branchOrOptions === "string"
|
|
10
|
-
|
|
11
|
-
:
|
|
16
|
+
const options = typeof branchOrOptions === "string" ? {
|
|
17
|
+
branch: branchOrOptions,
|
|
18
|
+
cwd: argsCwd
|
|
19
|
+
} : branchOrOptions;
|
|
12
20
|
const { cwd, branch } = options;
|
|
13
|
-
const defaultRemote = (0,
|
|
21
|
+
const defaultRemote = (0, _getDefaultRemote.getDefaultRemote)(options);
|
|
14
22
|
if (branch) {
|
|
15
23
|
return `${defaultRemote}/${branch}`;
|
|
16
24
|
}
|
|
17
|
-
const showRemote = (0,
|
|
25
|
+
const showRemote = (0, _git.git)([
|
|
26
|
+
"remote",
|
|
27
|
+
"show",
|
|
28
|
+
defaultRemote
|
|
29
|
+
], {
|
|
30
|
+
cwd
|
|
31
|
+
});
|
|
18
32
|
let remoteDefaultBranch;
|
|
19
33
|
if (showRemote.success) {
|
|
20
34
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
remoteDefaultBranch = showRemote.stdout
|
|
29
|
-
.split(/\n/)
|
|
30
|
-
.find((line) => line.includes("HEAD branch"))
|
|
31
|
-
?.replace(/^\s*HEAD branch:\s+/, "");
|
|
35
|
+
* `showRemote.stdout` is something like this:
|
|
36
|
+
*
|
|
37
|
+
* * remote origin
|
|
38
|
+
* Fetch URL: .../monorepo-upstream
|
|
39
|
+
* Push URL: .../monorepo-upstream
|
|
40
|
+
* HEAD branch: main
|
|
41
|
+
*/ remoteDefaultBranch = showRemote.stdout.split(/\n/).find((line)=>line.includes("HEAD branch"))?.replace(/^\s*HEAD branch:\s+/, "");
|
|
32
42
|
}
|
|
33
|
-
remoteDefaultBranch || (remoteDefaultBranch = (0,
|
|
43
|
+
remoteDefaultBranch || (remoteDefaultBranch = (0, _gitUtilities.getDefaultBranch)({
|
|
44
|
+
cwd,
|
|
45
|
+
throwOnError: options.strict
|
|
46
|
+
}));
|
|
34
47
|
return `${defaultRemote}/${remoteDefaultBranch}`;
|
|
35
48
|
}
|
|
36
|
-
exports.getDefaultRemoteBranch = getDefaultRemoteBranch;
|
|
37
|
-
//# sourceMappingURL=getDefaultRemoteBranch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/git/getDefaultRemoteBranch.ts"],"sourcesContent":["import { getDefaultRemote, type GetDefaultRemoteOptions } from \"./getDefaultRemote.js\";\nimport { git } from \"./git.js\";\nimport { getDefaultBranch } from \"./gitUtilities.js\";\n\nexport type GetDefaultRemoteBranchOptions = GetDefaultRemoteOptions & {\n /** Name of branch to use. If undefined, uses the default branch name (falling back to `master`). */\n branch?: string;\n};\n\n/**\n * Gets a reference to `options.branch` or the default branch relative to the default remote.\n * (See {@link getDefaultRemote} for how the default remote is determined.)\n * Throws if `options.cwd` is not in a git repo or there's no package.json at the repo root.\n * @returns A branch reference like `upstream/master` or `origin/master`.\n */\nexport function getDefaultRemoteBranch(options: GetDefaultRemoteBranchOptions): string;\n/**\n * First param: `branch`. Second param: `cwd`. See {@link GetDefaultRemoteBranchOptions} for more info.\n * (This had to be changed to `...args` to avoid a conflict with the object param version.)\n * @deprecated Use the object param version\n */\nexport function getDefaultRemoteBranch(...args: string[]): string;\nexport function getDefaultRemoteBranch(...args: (string | GetDefaultRemoteBranchOptions)[]): string {\n const [branchOrOptions, argsCwd] = args;\n const options =\n typeof branchOrOptions === \"string\"\n ? ({ branch: branchOrOptions, cwd: argsCwd } as GetDefaultRemoteBranchOptions)\n : branchOrOptions;\n const { cwd, branch } = options;\n\n const defaultRemote = getDefaultRemote(options);\n\n if (branch) {\n return `${defaultRemote}/${branch}`;\n }\n\n const showRemote = git([\"remote\", \"show\", defaultRemote], { cwd });\n let remoteDefaultBranch: string | undefined;\n\n if (showRemote.success) {\n /**\n * `showRemote.stdout` is something like this:\n *\n * * remote origin\n * Fetch URL: .../monorepo-upstream\n * Push URL: .../monorepo-upstream\n * HEAD branch: main\n */\n remoteDefaultBranch = showRemote.stdout\n .split(/\\n/)\n .find((line) => line.includes(\"HEAD branch\"))\n ?.replace(/^\\s*HEAD branch:\\s+/, \"\");\n }\n\n remoteDefaultBranch ||= getDefaultBranch({ cwd, throwOnError: options.strict });\n\n return `${defaultRemote}/${remoteDefaultBranch}`;\n}\n"],"names":["getDefaultRemoteBranch","args","branchOrOptions","argsCwd","options","branch","cwd","defaultRemote","getDefaultRemote","showRemote","git","remoteDefaultBranch","success","stdout","split","find","line","includes","replace","getDefaultBranch","throwOnError","strict"],"mappings":";;;;+BAsBgBA;;;eAAAA;;;kCAtB+C;qBAC3C;8BACa;AAoB1B,SAASA,uBAAuB,GAAGC,IAAgD;IACxF,MAAM,CAACC,iBAAiBC,QAAQ,GAAGF;IACnC,MAAMG,UACJ,OAAOF,oBAAoB,WACtB;QAAEG,QAAQH;QAAiBI,KAAKH;IAAQ,IACzCD;IACN,MAAM,EAAEI,GAAG,EAAED,MAAM,EAAE,GAAGD;IAExB,MAAMG,gBAAgBC,IAAAA,kCAAgB,EAACJ;IAEvC,IAAIC,QAAQ;QACV,OAAO,GAAGE,cAAc,CAAC,EAAEF,QAAQ;IACrC;IAEA,MAAMI,aAAaC,IAAAA,QAAG,EAAC;QAAC;QAAU;QAAQH;KAAc,EAAE;QAAED;IAAI;IAChE,IAAIK;IAEJ,IAAIF,WAAWG,OAAO,EAAE;QACtB;;;;;;;KAOC,GACDD,sBAAsBF,WAAWI,MAAM,CACpCC,KAAK,CAAC,MACNC,IAAI,CAAC,CAACC,OAASA,KAAKC,QAAQ,CAAC,iBAC5BC,QAAQ,uBAAuB;IACrC;IAEAP,wBAAAA,sBAAwBQ,IAAAA,8BAAgB,EAAC;QAAEb;QAAKc,cAAchB,QAAQiB,MAAM;IAAC;IAE7E,OAAO,GAAGd,cAAc,CAAC,EAAEI,qBAAqB;AAClD"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* including special handling for the many ADO/VSO URL formats.
|
|
4
4
|
*
|
|
5
5
|
* Examples:
|
|
6
|
-
* - returns `microsoft/
|
|
6
|
+
* - returns `microsoft/lage` for `https://github.com/microsoft/lage.git`
|
|
7
7
|
* - returns `foo/bar/some-repo` for `https://dev.azure.com/foo/bar/_git/some-repo`
|
|
8
8
|
*/
|
|
9
9
|
export declare function getRepositoryName(url: string): string;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getRepositoryName", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getRepositoryName;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _giturlparse = /*#__PURE__*/ _interop_require_default(require("git-url-parse"));
|
|
12
|
+
function _interop_require_default(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
16
17
|
function getRepositoryName(url) {
|
|
17
18
|
try {
|
|
18
19
|
// Mostly use this standard library, but fix some VSO/ADO-specific quirks to account for the
|
|
@@ -26,7 +27,7 @@ function getRepositoryName(url) {
|
|
|
26
27
|
// https://dev.azure.com/foo/bar/_git/_optimized/some-repo
|
|
27
28
|
// https://user@dev.azure.com/foo/bar/_git/some-repo
|
|
28
29
|
// git@ssh.dev.azure.com:v3/foo/bar/some-repo
|
|
29
|
-
const parsedUrl = (0,
|
|
30
|
+
const parsedUrl = (0, _giturlparse.default)(url.replace("/_optimized/", "/").replace("/DefaultCollection/", "/"));
|
|
30
31
|
// `host` is set in `parse-url` but not documented... https://github.com/IonicaBizau/parse-url/blob/c830d48647f33c054745a916cf7c4c58722f4b25/src/index.js#L28
|
|
31
32
|
const host = parsedUrl.host || "";
|
|
32
33
|
const isVSO = host.endsWith(".visualstudio.com");
|
|
@@ -46,10 +47,7 @@ function getRepositoryName(url) {
|
|
|
46
47
|
organization = host.match(/([^.@]+)\.visualstudio\.com$/)?.[1];
|
|
47
48
|
}
|
|
48
49
|
return `${organization}/${parsedUrl.owner}/${parsedUrl.name}`;
|
|
49
|
-
}
|
|
50
|
-
catch (err) {
|
|
50
|
+
} catch (err) {
|
|
51
51
|
return "";
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
exports.getRepositoryName = getRepositoryName;
|
|
55
|
-
//# sourceMappingURL=getRepositoryName.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/git/getRepositoryName.ts"],"sourcesContent":["import gitUrlParse from \"git-url-parse\";\n\n/**\n * Get a repository full name (owner and repo, plus organization for ADO/VSO) from a repository URL,\n * including special handling for the many ADO/VSO URL formats.\n *\n * Examples:\n * - returns `microsoft/lage` for `https://github.com/microsoft/lage.git`\n * - returns `foo/bar/some-repo` for `https://dev.azure.com/foo/bar/_git/some-repo`\n */\nexport function getRepositoryName(url: string): string {\n try {\n // Mostly use this standard library, but fix some VSO/ADO-specific quirks to account for the\n // fact that all of the following URLs should be considered to point to the same repo:\n // https://foo.visualstudio.com/bar/_git/some-repo\n // https://foo.visualstudio.com/DefaultCollection/bar/_git/some-repo\n // https://user:token@foo.visualstudio.com/DefaultCollection/bar/_git/some-repo\n // https://foo.visualstudio.com/DefaultCollection/bar/_git/_optimized/some-repo\n // foo@vs-ssh.visualstudio.com:v3/foo/bar/some-repo\n // https://dev.azure.com/foo/bar/_git/some-repo\n // https://dev.azure.com/foo/bar/_git/_optimized/some-repo\n // https://user@dev.azure.com/foo/bar/_git/some-repo\n // git@ssh.dev.azure.com:v3/foo/bar/some-repo\n const parsedUrl = gitUrlParse(url.replace(\"/_optimized/\", \"/\").replace(\"/DefaultCollection/\", \"/\"));\n\n // `host` is set in `parse-url` but not documented... https://github.com/IonicaBizau/parse-url/blob/c830d48647f33c054745a916cf7c4c58722f4b25/src/index.js#L28\n const host: string = (parsedUrl as any).host || \"\";\n const isVSO = host.endsWith(\".visualstudio.com\");\n if (!isVSO && host !== \"dev.azure.com\" && host !== \"ssh.dev.azure.com\") {\n return parsedUrl.full_name;\n }\n\n // As of writing, ADO and VSO SSH URLs are parsed completely wrong\n const sshMatch = parsedUrl.full_name.match(\n /(vs-ssh\\.visualstudio\\.com|ssh\\.dev\\.azure\\.com):v\\d+\\/([^/]+)\\/([^/]+)/\n );\n if (sshMatch) {\n return `${sshMatch[2]}/${sshMatch[3]}/${parsedUrl.name}`;\n }\n\n // As of writing, full_name is wrong for enough variants of ADO and VSO URLs that it\n // makes more sense to just build it manually.\n let organization: string | undefined = parsedUrl.organization;\n if (!organization && isVSO) {\n // organization is missing or wrong for VSO\n organization = host.match(/([^.@]+)\\.visualstudio\\.com$/)?.[1];\n }\n return `${organization}/${parsedUrl.owner}/${parsedUrl.name}`;\n } catch (err) {\n return \"\";\n }\n}\n"],"names":["getRepositoryName","url","parsedUrl","gitUrlParse","replace","host","isVSO","endsWith","full_name","sshMatch","match","name","organization","owner","err"],"mappings":";;;;+BAUgBA;;;eAAAA;;;oEAVQ;;;;;;AAUjB,SAASA,kBAAkBC,GAAW;IAC3C,IAAI;QACF,4FAA4F;QAC5F,sFAAsF;QACtF,kDAAkD;QAClD,oEAAoE;QACpE,+EAA+E;QAC/E,+EAA+E;QAC/E,mDAAmD;QACnD,+CAA+C;QAC/C,0DAA0D;QAC1D,oDAAoD;QACpD,6CAA6C;QAC7C,MAAMC,YAAYC,IAAAA,oBAAW,EAACF,IAAIG,OAAO,CAAC,gBAAgB,KAAKA,OAAO,CAAC,uBAAuB;QAE9F,6JAA6J;QAC7J,MAAMC,OAAe,AAACH,UAAkBG,IAAI,IAAI;QAChD,MAAMC,QAAQD,KAAKE,QAAQ,CAAC;QAC5B,IAAI,CAACD,SAASD,SAAS,mBAAmBA,SAAS,qBAAqB;YACtE,OAAOH,UAAUM,SAAS;QAC5B;QAEA,kEAAkE;QAClE,MAAMC,WAAWP,UAAUM,SAAS,CAACE,KAAK,CACxC;QAEF,IAAID,UAAU;YACZ,OAAO,GAAGA,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAEA,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAEP,UAAUS,IAAI,EAAE;QAC1D;QAEA,oFAAoF;QACpF,8CAA8C;QAC9C,IAAIC,eAAmCV,UAAUU,YAAY;QAC7D,IAAI,CAACA,gBAAgBN,OAAO;YAC1B,2CAA2C;YAC3CM,eAAeP,KAAKK,KAAK,CAAC,iCAAiC,CAAC,EAAE;QAChE;QACA,OAAO,GAAGE,aAAa,CAAC,EAAEV,UAAUW,KAAK,CAAC,CAAC,EAAEX,UAAUS,IAAI,EAAE;IAC/D,EAAE,OAAOG,KAAK;QACZ,OAAO;IACT;AACF"}
|
package/lib/git/git.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/// <reference types="node" />
|
|
4
|
-
import { SpawnSyncOptions, SpawnSyncReturns } from "child_process";
|
|
5
|
-
import { GitCommonOptions } from "./types";
|
|
1
|
+
import { type SpawnSyncOptions, type SpawnSyncReturns } from "child_process";
|
|
2
|
+
import { type GitCommonOptions } from "./types.js";
|
|
6
3
|
export type GitOptions = Omit<SpawnSyncOptions, "cwd"> & GitCommonOptions & {
|
|
7
4
|
/** Operation description to be used in error message (formatted as start of sentence) */
|
|
8
5
|
description?: string;
|
package/lib/git/git.js
CHANGED
|
@@ -1,65 +1,86 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
//
|
|
3
2
|
// Basic git wrappers
|
|
4
3
|
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
"use strict";
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
function _export(target, all) {
|
|
9
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
_export(exports, {
|
|
15
|
+
get GitError () {
|
|
16
|
+
return GitError;
|
|
17
|
+
},
|
|
18
|
+
get addGitObserver () {
|
|
19
|
+
return addGitObserver;
|
|
20
|
+
},
|
|
21
|
+
get clearGitObservers () {
|
|
22
|
+
return clearGitObservers;
|
|
23
|
+
},
|
|
24
|
+
get git () {
|
|
25
|
+
return git;
|
|
26
|
+
},
|
|
27
|
+
get gitFailFast () {
|
|
28
|
+
return gitFailFast;
|
|
29
|
+
},
|
|
30
|
+
get processGitOutput () {
|
|
31
|
+
return processGitOutput;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const _child_process = require("child_process");
|
|
35
|
+
function _define_property(obj, key, value) {
|
|
36
|
+
if (key in obj) {
|
|
37
|
+
Object.defineProperty(obj, key, {
|
|
38
|
+
value: value,
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
writable: true
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
obj[key] = value;
|
|
45
|
+
}
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
8
48
|
class GitError extends Error {
|
|
9
|
-
constructor(message, originalError, gitOutput)
|
|
49
|
+
constructor(message, originalError, gitOutput){
|
|
10
50
|
if (originalError instanceof Error) {
|
|
11
|
-
super(`${message}: ${originalError.message}`);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
else {
|
|
17
|
-
super(message);
|
|
51
|
+
super(`${message}: ${originalError.message}`), _define_property(this, "originalError", void 0), _define_property(this, "gitOutput", void 0);
|
|
52
|
+
} else if (gitOutput?.stderr) {
|
|
53
|
+
super(`${message} -- stderr:\n${gitOutput.stderr}`), _define_property(this, "originalError", void 0), _define_property(this, "gitOutput", void 0);
|
|
54
|
+
} else {
|
|
55
|
+
super(message), _define_property(this, "originalError", void 0), _define_property(this, "gitOutput", void 0);
|
|
18
56
|
}
|
|
19
57
|
this.originalError = originalError;
|
|
20
58
|
this.gitOutput = gitOutput;
|
|
21
59
|
}
|
|
22
60
|
}
|
|
23
|
-
exports.GitError = GitError;
|
|
24
61
|
/**
|
|
25
62
|
* A global maxBuffer override for all git operations.
|
|
26
63
|
* Bumps up the default to 500MB instead of 1MB.
|
|
27
64
|
* Override this value with the `GIT_MAX_BUFFER` environment variable.
|
|
28
|
-
*/
|
|
29
|
-
const defaultMaxBuffer = process.env.GIT_MAX_BUFFER ? parseInt(process.env.GIT_MAX_BUFFER) : 500 * 1024 * 1024;
|
|
65
|
+
*/ const defaultMaxBuffer = process.env.GIT_MAX_BUFFER ? parseInt(process.env.GIT_MAX_BUFFER) : 500 * 1024 * 1024;
|
|
30
66
|
const isDebug = !!process.env.GIT_DEBUG;
|
|
31
67
|
const observers = [];
|
|
32
68
|
let observing;
|
|
33
|
-
/**
|
|
34
|
-
* Adds an observer for the git operations, e.g. for testing
|
|
35
|
-
* @returns a function to remove the observer
|
|
36
|
-
*/
|
|
37
69
|
function addGitObserver(observer) {
|
|
38
70
|
observers.push(observer);
|
|
39
|
-
return ()
|
|
71
|
+
return ()=>removeGitObserver(observer);
|
|
40
72
|
}
|
|
41
|
-
exports.addGitObserver = addGitObserver;
|
|
42
|
-
/** Clear all git observers */
|
|
43
73
|
function clearGitObservers() {
|
|
44
74
|
observers.splice(0, observers.length);
|
|
45
75
|
}
|
|
46
|
-
|
|
47
|
-
/** Remove a git observer */
|
|
48
|
-
function removeGitObserver(observer) {
|
|
76
|
+
/** Remove a git observer */ function removeGitObserver(observer) {
|
|
49
77
|
const index = observers.indexOf(observer);
|
|
50
78
|
if (index > -1) {
|
|
51
79
|
observers.splice(index, 1);
|
|
52
80
|
}
|
|
53
81
|
}
|
|
54
|
-
/**
|
|
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.
|
|
57
|
-
*
|
|
58
|
-
* The caller is responsible for validating the input.
|
|
59
|
-
* `shell` will always be set to false.
|
|
60
|
-
*/
|
|
61
82
|
function git(args, options) {
|
|
62
|
-
if (args.some((arg)
|
|
83
|
+
if (args.some((arg)=>arg.startsWith("--upload-pack"))) {
|
|
63
84
|
// This is a security issue and not needed for any expected usage of this library.
|
|
64
85
|
throw new GitError("git command contains --upload-pack, which is not allowed: " + args.join(" "));
|
|
65
86
|
}
|
|
@@ -69,9 +90,11 @@ function git(args, options) {
|
|
|
69
90
|
let results;
|
|
70
91
|
try {
|
|
71
92
|
// this only throws if git isn't found or other rare cases
|
|
72
|
-
results = (0,
|
|
73
|
-
|
|
74
|
-
|
|
93
|
+
results = (0, _child_process.spawnSync)("git", args, {
|
|
94
|
+
maxBuffer: defaultMaxBuffer,
|
|
95
|
+
...spawnOptions
|
|
96
|
+
});
|
|
97
|
+
} catch (e) {
|
|
75
98
|
throw new GitError(`${description} failed (while spawning process)`, e);
|
|
76
99
|
}
|
|
77
100
|
const output = {
|
|
@@ -79,7 +102,7 @@ function git(args, options) {
|
|
|
79
102
|
// these may be undefined if stdio: inherit is set
|
|
80
103
|
stderr: (results.stderr || "").toString().trimEnd(),
|
|
81
104
|
stdout: (results.stdout || "").toString().trimEnd(),
|
|
82
|
-
success: results.status === 0
|
|
105
|
+
success: results.status === 0
|
|
83
106
|
};
|
|
84
107
|
if (debug) {
|
|
85
108
|
console.log("exited with code " + results.status);
|
|
@@ -89,7 +112,7 @@ function git(args, options) {
|
|
|
89
112
|
// notify observers, flipping the observing bit to prevent infinite loops
|
|
90
113
|
if (!observing) {
|
|
91
114
|
observing = true;
|
|
92
|
-
for (const observer of observers)
|
|
115
|
+
for (const observer of observers){
|
|
93
116
|
observer(args, output);
|
|
94
117
|
}
|
|
95
118
|
observing = false;
|
|
@@ -99,14 +122,6 @@ function git(args, options) {
|
|
|
99
122
|
}
|
|
100
123
|
return output;
|
|
101
124
|
}
|
|
102
|
-
exports.git = git;
|
|
103
|
-
/**
|
|
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).
|
|
106
|
-
*
|
|
107
|
-
* The caller is responsible for validating the input.
|
|
108
|
-
* `shell` will always be set to false.
|
|
109
|
-
*/
|
|
110
125
|
function gitFailFast(args, options) {
|
|
111
126
|
const gitResult = git(args, options);
|
|
112
127
|
if (!gitResult.success) {
|
|
@@ -118,27 +133,10 @@ function gitFailFast(args, options) {
|
|
|
118
133
|
${gitResult.stderr?.toString().trimEnd()}`);
|
|
119
134
|
}
|
|
120
135
|
}
|
|
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
136
|
function processGitOutput(output, options) {
|
|
134
137
|
if (!output.success) {
|
|
135
138
|
// If the intent was to throw on failure, `throwOnError` should have been set for the git command.
|
|
136
139
|
return [];
|
|
137
140
|
}
|
|
138
|
-
return output.stdout
|
|
139
|
-
.split(/\n/)
|
|
140
|
-
.map((line) => line.trim())
|
|
141
|
-
.filter((line) => !!line && (!options?.excludeNodeModules || !line.includes("node_modules")));
|
|
141
|
+
return output.stdout.split(/\n/).map((line)=>line.trim()).filter((line)=>!!line && (!options?.excludeNodeModules || !line.includes("node_modules")));
|
|
142
142
|
}
|
|
143
|
-
exports.processGitOutput = processGitOutput;
|
|
144
|
-
//# sourceMappingURL=git.js.map
|