dugite 1.110.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/README.md +18 -12
- package/build/lib/errors.js +2 -1
- package/build/lib/errors.js.map +1 -1
- package/build/lib/git-environment.js +2 -1
- package/build/lib/git-environment.js.map +1 -1
- package/build/lib/git-process.d.ts +3 -2
- package/build/lib/git-process.js +21 -14
- package/build/lib/git-process.js.map +1 -1
- package/build/lib/index.d.ts +2 -2
- package/build/lib/index.js +6 -5
- package/build/lib/index.js.map +1 -1
- package/package.json +14 -18
- package/script/download-git.js +49 -71
- package/script/utils.js +27 -0
package/README.md
CHANGED
@@ -12,6 +12,12 @@ Add it to your project:
|
|
12
12
|
> npm install dugite
|
13
13
|
```
|
14
14
|
|
15
|
+
or
|
16
|
+
|
17
|
+
```
|
18
|
+
> yarn add dugite
|
19
|
+
```
|
20
|
+
|
15
21
|
Then reference it in your application:
|
16
22
|
|
17
23
|
```js
|
@@ -19,7 +25,7 @@ import { GitProcess, GitError, IGitResult } from 'dugite'
|
|
19
25
|
|
20
26
|
const pathToRepository = 'C:/path/to/git/repository/'
|
21
27
|
|
22
|
-
const result = await GitProcess.exec([
|
28
|
+
const result = await GitProcess.exec(['status'], pathToRepository)
|
23
29
|
if (result.exitCode === 0) {
|
24
30
|
const output = result.stdout
|
25
31
|
// do some things with the output
|
@@ -31,16 +37,16 @@ if (result.exitCode === 0) {
|
|
31
37
|
|
32
38
|
### Features
|
33
39
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
- make it easy to work with Git repositories
|
41
|
+
- use the same commands as you would in a shell
|
42
|
+
- access to the full set of commands, options and formatting that Git core uses
|
43
|
+
- access to the latest features of Git
|
38
44
|
|
39
45
|
### Supported Platforms
|
40
46
|
|
41
|
-
|
42
|
-
|
43
|
-
|
47
|
+
- Windows 7 and later
|
48
|
+
- macOS 10.9 and up
|
49
|
+
- Linux (tested on Ubuntu Precise/Trusty and Fedora 24)
|
44
50
|
|
45
51
|
### Status
|
46
52
|
|
@@ -52,7 +58,7 @@ If you are interested in getting involved with this project, refer to the [CONTR
|
|
52
58
|
|
53
59
|
As this is under active development, the roadmap is also subject to change. Some ideas:
|
54
60
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
61
|
+
- authentication support in-the-box
|
62
|
+
- make environment setup easier to override
|
63
|
+
- API additions for common tasks such as parsing output
|
64
|
+
- error handling improvements
|
package/build/lib/errors.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.RepositoryDoesNotExistErrorCode = exports.GitNotFoundErrorCode = exports.GitErrorRegexes = exports.GitError = void 0;
|
3
4
|
/** The git errors which can be parsed from failed git commands. */
|
4
5
|
var GitError;
|
5
6
|
(function (GitError) {
|
@@ -126,7 +127,7 @@ exports.GitErrorRegexes = {
|
|
126
127
|
'error: cannot (pull with rebase|rebase): You have unstaged changes\\.\n\\s*error: [Pp]lease commit or stash them\\.': GitError.RebaseWithLocalChanges,
|
127
128
|
'error: commit (.+) is a merge but no -m option was given': GitError.MergeCommitNoMainlineOption,
|
128
129
|
'fatal: detected dubious ownership in repository at (.+)': GitError.UnsafeDirectory,
|
129
|
-
"fatal: path '(.+)' exists on disk, but not in '(.+)'": GitError.PathExistsButNotInRef
|
130
|
+
"fatal: path '(.+)' exists on disk, but not in '(.+)'": GitError.PathExistsButNotInRef,
|
130
131
|
};
|
131
132
|
/**
|
132
133
|
* The error code for when git cannot be found. This most likely indicates a
|
package/build/lib/errors.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../lib/errors.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../lib/errors.ts"],"names":[],"mappings":";;;AAAA,mEAAmE;AACnE,IAAY,QA6DX;AA7DD,WAAY,QAAQ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,CAAC,qBAAqB;IAChC,qHAAqH,EACnH,QAAQ,CAAC,sBAAsB;IACjC,0DAA0D,EACxD,QAAQ,CAAC,2BAA2B;IACtC,yDAAyD,EACvD,QAAQ,CAAC,eAAe;IAC1B,sDAAsD,EACpD,QAAQ,CAAC,qBAAqB;CACjC,CAAA;AAED;;;GAGG;AACU,QAAA,oBAAoB,GAAG,qBAAqB,CAAA;AAEzD,sEAAsE;AACzD,QAAA,+BAA+B,GAAG,iCAAiC,CAAA"}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.setupEnvironment = void 0;
|
3
4
|
const path = require("path");
|
4
5
|
function resolveEmbeddedGitDir() {
|
5
6
|
if (process.platform === 'darwin' ||
|
@@ -82,7 +83,7 @@ function setupEnvironment(environmentVariables) {
|
|
82
83
|
}
|
83
84
|
const env = Object.assign({}, process.env, {
|
84
85
|
GIT_EXEC_PATH: resolveGitExecPath(),
|
85
|
-
PATH: envPath
|
86
|
+
PATH: envPath,
|
86
87
|
}, environmentVariables);
|
87
88
|
if (process.platform === 'win32') {
|
88
89
|
// while reading the environment variable is case-insensitive
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"git-environment.js","sourceRoot":"","sources":["../../lib/git-environment.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"git-environment.js","sourceRoot":"","sources":["../../lib/git-environment.ts"],"names":[],"mappings":";;;AAAA,6BAA4B;AAE5B,SAAS,qBAAqB;IAC5B,IACE,OAAO,CAAC,QAAQ,KAAK,QAAQ;QAC7B,OAAO,CAAC,QAAQ,KAAK,OAAO;QAC5B,OAAO,CAAC,QAAQ,KAAK,SAAS;QAC9B,OAAO,CAAC,QAAQ,KAAK,OAAO,EAC5B;QACA,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAA;QAClB,OAAO,IAAI;aACR,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EA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AChC,uDAAuD;QACvD,uDAAuD;QACvD,wDAAwD;QACxD,GAAG,CAAC,MAAM,GAAG,MAAM,CAAA;QAEnB,IAAI,CAAC,GAAG,CAAC,cAAc,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE;YACnD,mEAAmE;YACnE,4DAA4D;YAC5D,MAAM,OAAO,GAAG,qBAAqB,EAAE,CAAA;YACvC,MAAM,WAAW,GAAG,GAAG,OAAO,iBAAiB,CAAA;YAC/C,GAAG,CAAC,cAAc,GAAG,WAAW,CAAA;SACjC;KACF;IAED,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,CAAA;AAC7B,CAAC;AA7DD,4CA6DC"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
/// <reference types="node" />
|
2
|
+
/// <reference types="node" />
|
2
3
|
import { GitError } from './errors';
|
3
4
|
import { ChildProcess } from 'child_process';
|
4
5
|
/** The result of shelling out to git. */
|
@@ -20,7 +21,7 @@ export interface IGitSpawnExecutionOptions {
|
|
20
21
|
* set as environment variables before executing the git
|
21
22
|
* process.
|
22
23
|
*/
|
23
|
-
readonly env?:
|
24
|
+
readonly env?: object;
|
24
25
|
}
|
25
26
|
/**
|
26
27
|
* A set of configuration options that can be passed when
|
@@ -32,7 +33,7 @@ export interface IGitExecutionOptions {
|
|
32
33
|
* set as environment variables before executing the git
|
33
34
|
* process.
|
34
35
|
*/
|
35
|
-
readonly env?:
|
36
|
+
readonly env?: object;
|
36
37
|
/**
|
37
38
|
* An optional string or buffer which will be written to
|
38
39
|
* the child process stdin stream immediately immediately
|
package/build/lib/git-process.js
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
4
5
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
6
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
-
function step(result) { result.done ? resolve(result.value) :
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
9
|
});
|
9
10
|
};
|
10
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.GitTaskCancelResult = exports.GitProcess = void 0;
|
11
13
|
const fs = require("fs");
|
12
14
|
const process_1 = require("process");
|
13
15
|
const child_process_1 = require("child_process");
|
@@ -35,12 +37,12 @@ class GitProcess {
|
|
35
37
|
if (options && options.env) {
|
36
38
|
customEnv = options.env;
|
37
39
|
}
|
38
|
-
const { env, gitLocation } = git_environment_1.setupEnvironment(customEnv);
|
40
|
+
const { env, gitLocation } = (0, git_environment_1.setupEnvironment)(customEnv);
|
39
41
|
const spawnArgs = {
|
40
42
|
env,
|
41
|
-
cwd: path
|
43
|
+
cwd: path,
|
42
44
|
};
|
43
|
-
const spawnedProcess = child_process_1.spawn(gitLocation, args, spawnArgs);
|
45
|
+
const spawnedProcess = (0, child_process_1.spawn)(gitLocation, args, spawnArgs);
|
44
46
|
ignoreClosedInputStream(spawnedProcess);
|
45
47
|
return spawnedProcess;
|
46
48
|
}
|
@@ -82,7 +84,7 @@ class GitProcess {
|
|
82
84
|
if (options && options.env) {
|
83
85
|
customEnv = options.env;
|
84
86
|
}
|
85
|
-
const { env, gitLocation } = git_environment_1.setupEnvironment(customEnv);
|
87
|
+
const { env, gitLocation } = (0, git_environment_1.setupEnvironment)(customEnv);
|
86
88
|
// Explicitly annotate opts since typescript is unable to infer the correct
|
87
89
|
// signature for execFile when options is passed as an opaque hash. The type
|
88
90
|
// definition for execFile currently infers based on the encoding parameter
|
@@ -92,9 +94,9 @@ class GitProcess {
|
|
92
94
|
cwd: path,
|
93
95
|
encoding: 'utf8',
|
94
96
|
maxBuffer: options ? options.maxBuffer : 10 * 1024 * 1024,
|
95
|
-
env
|
97
|
+
env,
|
96
98
|
};
|
97
|
-
const spawnedProcess = child_process_1.execFile(gitLocation, args, execOptions, function (err, stdout, stderr) {
|
99
|
+
const spawnedProcess = (0, child_process_1.execFile)(gitLocation, args, execOptions, function (err, stdout, stderr) {
|
98
100
|
result.updateProcessEnded();
|
99
101
|
if (!err) {
|
100
102
|
resolve({ stdout, stderr, exitCode: 0 });
|
@@ -142,9 +144,14 @@ class GitProcess {
|
|
142
144
|
});
|
143
145
|
pidResolve(spawnedProcess.pid);
|
144
146
|
ignoreClosedInputStream(spawnedProcess);
|
145
|
-
if (options && options.stdin !== undefined) {
|
147
|
+
if (options && options.stdin !== undefined && spawnedProcess.stdin) {
|
146
148
|
// See https://github.com/nodejs/node/blob/7b5ffa46fe4d2868c1662694da06eb55ec744bde/test/parallel/test-stdin-pipe-large.js
|
147
|
-
|
149
|
+
if (options.stdinEncoding) {
|
150
|
+
spawnedProcess.stdin.end(options.stdin, options.stdinEncoding);
|
151
|
+
}
|
152
|
+
else {
|
153
|
+
spawnedProcess.stdin.end(options.stdin);
|
154
|
+
}
|
148
155
|
}
|
149
156
|
if (options && options.processCallback) {
|
150
157
|
options.processCallback(spawnedProcess);
|
@@ -190,7 +197,7 @@ exports.GitProcess = GitProcess;
|
|
190
197
|
*
|
191
198
|
* See https://github.com/desktop/desktop/pull/4027#issuecomment-366213276
|
192
199
|
*/
|
193
|
-
function ignoreClosedInputStream(
|
200
|
+
function ignoreClosedInputStream({ stdin }) {
|
194
201
|
// If Node fails to spawn due to a runtime error (EACCESS, EAGAIN, etc)
|
195
202
|
// it will not setup the stdio streams, see
|
196
203
|
// https://github.com/nodejs/node/blob/v10.16.0/lib/internal/child_process.js#L342-L354
|
@@ -198,10 +205,10 @@ function ignoreClosedInputStream(process) {
|
|
198
205
|
// the synchronous path so if we attempts to call `.on` on `.stdin`
|
199
206
|
// (which is undefined) that error would be thrown before the underlying
|
200
207
|
// error.
|
201
|
-
if (!
|
208
|
+
if (!stdin) {
|
202
209
|
return;
|
203
210
|
}
|
204
|
-
|
211
|
+
stdin.on('error', err => {
|
205
212
|
const code = err.code;
|
206
213
|
// Is the error one that we'd expect from the input stream being
|
207
214
|
// closed, i.e. EPIPE on macOS and EOF on Windows. We've also
|
@@ -218,7 +225,7 @@ function ignoreClosedInputStream(process) {
|
|
218
225
|
//
|
219
226
|
// "For all EventEmitter objects, if an 'error' event handler is not
|
220
227
|
// provided, the error will be thrown"
|
221
|
-
if (
|
228
|
+
if (stdin.listeners('error').length <= 1) {
|
222
229
|
throw err;
|
223
230
|
}
|
224
231
|
});
|
@@ -249,7 +256,7 @@ class GitTask {
|
|
249
256
|
return GitTaskCancelResult.noProcessIdDefined;
|
250
257
|
}
|
251
258
|
try {
|
252
|
-
process_1.kill(pid);
|
259
|
+
(0, process_1.kill)(pid);
|
253
260
|
return GitTaskCancelResult.successfulCancel;
|
254
261
|
}
|
255
262
|
catch (e) { }
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"git-process.js","sourceRoot":"","sources":["../../lib/git-process.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"git-process.js","sourceRoot":"","sources":["../../lib/git-process.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yBAAwB;AACxB,qCAA8B;AAE9B,iDAA8E;AAC9E,qCAKiB;AAGjB,uDAAoD;AA+EpD,MAAa,UAAU;IACb,MAAM,CAAC,UAAU,CAAC,IAAY;QACpC,IAAI;YACF,EAAE,CAAC,UAAU,CAAC,IAAI,EAAG,EAAU,CAAC,IAAI,CAAC,CAAA;YACrC,OAAO,IAAI,CAAA;SACZ;QAAC,WAAM;YACN,OAAO,KAAK,CAAA;SACb;IACH,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CACjB,IAAc,EACd,IAAY,EACZ,OAAmC;QAEnC,IAAI,SAAS,GAAG,EAAE,CAAA;QAClB,IAAI,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE;YAC1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AEY,MAAM;;YACjB,IAAI,IAAI,CAAC,YAAY,EAAE;gBACrB,OAAO,mBAAmB,CAAC,mBAAmB,CAAA;aAC/C;YAED,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAA;YAE1B,IAAI,GAAG,KAAK,SAAS,EAAE;gBACrB,OAAO,mBAAmB,CAAC,kBAAkB,CAAA;aAC9C;YAED,IAAI;gBACF,IAAA,cAAI,EAAC,GAAG,CAAC,CAAA;gBACT,OAAO,mBAAmB,CAAC,gBAAgB,CAAA;aAC5C;YAAC,OAAO,CAAC,EAAE,GAAE;YAEd,OAAO,mBAAmB,CAAC,cAAc,CAAA;QAC3C,CAAC;KAAA;CACF"}
|
package/build/lib/index.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export { GitProcess, IGitResult, IGitExecutionOptions, IGitTask, GitTaskCancelResult } from './git-process';
|
2
|
-
export { GitError, RepositoryDoesNotExistErrorCode, GitNotFoundErrorCode } from './errors';
|
1
|
+
export { GitProcess, IGitResult, IGitExecutionOptions, IGitTask, GitTaskCancelResult, } from './git-process';
|
2
|
+
export { GitError, RepositoryDoesNotExistErrorCode, GitNotFoundErrorCode, } from './errors';
|
package/build/lib/index.js
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.GitNotFoundErrorCode = exports.RepositoryDoesNotExistErrorCode = exports.GitError = exports.GitTaskCancelResult = exports.GitProcess = void 0;
|
3
4
|
var git_process_1 = require("./git-process");
|
4
|
-
exports
|
5
|
-
exports
|
5
|
+
Object.defineProperty(exports, "GitProcess", { enumerable: true, get: function () { return git_process_1.GitProcess; } });
|
6
|
+
Object.defineProperty(exports, "GitTaskCancelResult", { enumerable: true, get: function () { return git_process_1.GitTaskCancelResult; } });
|
6
7
|
var errors_1 = require("./errors");
|
7
|
-
exports
|
8
|
-
exports
|
9
|
-
exports
|
8
|
+
Object.defineProperty(exports, "GitError", { enumerable: true, get: function () { return errors_1.GitError; } });
|
9
|
+
Object.defineProperty(exports, "RepositoryDoesNotExistErrorCode", { enumerable: true, get: function () { return errors_1.RepositoryDoesNotExistErrorCode; } });
|
10
|
+
Object.defineProperty(exports, "GitNotFoundErrorCode", { enumerable: true, get: function () { return errors_1.GitNotFoundErrorCode; } });
|
10
11
|
//# sourceMappingURL=index.js.map
|
package/build/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;;AAAA,6CAMsB;AALpB,yGAAA,UAAU,OAAA;AAIV,kHAAA,mBAAmB,OAAA;AAErB,mCAIiB;AAHf,kGAAA,QAAQ,OAAA;AACR,yHAAA,+BAA+B,OAAA;AAC/B,8GAAA,oBAAoB,OAAA"}
|
package/package.json
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
{
|
2
2
|
"name": "dugite",
|
3
|
-
"version": "
|
3
|
+
"version": "2.0.0",
|
4
4
|
"description": "Elegant bindings for Git",
|
5
5
|
"main": "./build/lib/index.js",
|
6
6
|
"typings": "./build/lib/index.d.ts",
|
7
7
|
"scripts": {
|
8
8
|
"clean": "rimraf build",
|
9
|
-
"build": "
|
10
|
-
"prepack": "
|
9
|
+
"build": "yarn clean && tsc -p ./tsconfig.json && tsc -p ./examples/tsconfig.json",
|
10
|
+
"prepack": "yarn build && yarn test",
|
11
11
|
"postpublish": "git push --follow-tags",
|
12
|
-
"test": "
|
12
|
+
"test": "yarn test:fast && yarn test:slow && yarn test:external",
|
13
13
|
"test:fast": "cross-env LOCAL_GIT_DIRECTORY=./git/ jest --runInBand --silent --config ./jest.fast.config.js",
|
14
14
|
"test:slow": "cross-env LOCAL_GIT_DIRECTORY=./git/ jest --runInBand --silent --config ./jest.slow.config.js",
|
15
15
|
"test:external": "jest --runInBand --silent --config ./jest.external.config.js",
|
16
|
+
"download-git": "node ./script/download-git.js",
|
16
17
|
"postinstall": "node ./script/download-git.js",
|
17
18
|
"prettify": "prettier \"{examples,lib,script,test}/**/*.ts\" --write",
|
18
19
|
"is-it-pretty": "prettier --check \"{examples,lib,script,test}/**/*.ts\"",
|
19
20
|
"update-embedded-git": "node ./script/update-embedded-git.js"
|
20
21
|
},
|
21
22
|
"engines": {
|
22
|
-
"node": ">=
|
23
|
-
"npm": ">= 3"
|
23
|
+
"node": ">= 14"
|
24
24
|
},
|
25
25
|
"repository": {
|
26
26
|
"type": "git",
|
@@ -33,28 +33,24 @@
|
|
33
33
|
},
|
34
34
|
"homepage": "https://github.com/desktop/dugite#readme",
|
35
35
|
"dependencies": {
|
36
|
-
"checksum": "^0.1.1",
|
37
|
-
"got": "^9.6.0",
|
38
|
-
"mkdirp": "^0.5.1",
|
39
36
|
"progress": "^2.0.3",
|
40
|
-
"
|
41
|
-
"tar": "^4.4.7"
|
37
|
+
"tar": "^6.1.11"
|
42
38
|
},
|
43
39
|
"devDependencies": {
|
44
|
-
"@types/
|
45
|
-
"@types/got": "^9.6.0",
|
46
|
-
"@types/jest": "^24.0.0",
|
40
|
+
"@types/jest": "^28.1.7",
|
47
41
|
"@types/mkdirp": "^0.5.2",
|
48
42
|
"@types/node": "^11.9.0",
|
49
43
|
"@types/progress": "^2.0.1",
|
50
44
|
"@types/rimraf": "2.0.2",
|
45
|
+
"@types/tar": "^6.1.2",
|
51
46
|
"byline": "^5.0.0",
|
52
47
|
"cross-env": "^5.2.0",
|
53
48
|
"find-git-exec": "0.0.1-alpha.2",
|
54
|
-
"jest": "^
|
55
|
-
"prettier": "^
|
49
|
+
"jest": "^28.1.3",
|
50
|
+
"prettier": "^2.7.1",
|
51
|
+
"rimraf": "^2.5.4",
|
56
52
|
"temp": "^0.9.0",
|
57
|
-
"ts-jest": "^
|
58
|
-
"typescript": "^
|
53
|
+
"ts-jest": "^28.0.8",
|
54
|
+
"typescript": "^4.7.4"
|
59
55
|
}
|
60
56
|
}
|
package/script/download-git.js
CHANGED
@@ -1,56 +1,37 @@
|
|
1
1
|
const fs = require('fs')
|
2
2
|
|
3
|
-
const got = require('got')
|
4
3
|
const ProgressBar = require('progress')
|
5
|
-
const mkdirp = require('mkdirp')
|
6
|
-
const checksum = require('checksum')
|
7
|
-
const rimraf = require('rimraf')
|
8
4
|
const tar = require('tar')
|
9
|
-
const
|
5
|
+
const https = require('https')
|
6
|
+
const { createHash } = require('crypto')
|
7
|
+
const { rm, mkdir, createReadStream, createWriteStream, existsSync } = require('fs')
|
10
8
|
|
11
9
|
const config = require('./config')()
|
12
10
|
|
13
|
-
function extract(source, callback) {
|
14
|
-
const extractor = tar
|
15
|
-
.extract({ cwd: config.outputPath })
|
16
|
-
.on('error', function(error) {
|
17
|
-
callback(error)
|
18
|
-
})
|
19
|
-
.on('end', function() {
|
20
|
-
callback()
|
21
|
-
})
|
22
|
-
|
23
|
-
fs.createReadStream(source)
|
24
|
-
.on('error', function(error) {
|
25
|
-
callback(error)
|
26
|
-
})
|
27
|
-
.pipe(zlib.Gunzip())
|
28
|
-
.pipe(extractor)
|
29
|
-
}
|
30
|
-
|
31
11
|
const verifyFile = function(file, callback) {
|
32
|
-
|
12
|
+
const h = createHash('sha256').on('finish', () => {
|
13
|
+
const hash = h.digest('hex')
|
33
14
|
const match = hash === config.checksum
|
34
|
-
|
35
15
|
if (!match) {
|
36
16
|
console.log(`Validation failed. Expected '${config.checksum}' but got '${hash}'`)
|
37
17
|
}
|
38
|
-
|
39
18
|
callback(match)
|
40
19
|
})
|
20
|
+
|
21
|
+
createReadStream(file).pipe(h)
|
41
22
|
}
|
42
23
|
|
43
24
|
const unpackFile = function(file) {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
process.exit(1)
|
48
|
-
}
|
25
|
+
tar.x({ cwd: config.outputPath, file }).catch(e => {
|
26
|
+
console.log('Unable to extract archive, aborting...', error)
|
27
|
+
process.exit(1)
|
49
28
|
})
|
50
29
|
}
|
51
30
|
|
52
|
-
const downloadAndUnpack = () => {
|
53
|
-
|
31
|
+
const downloadAndUnpack = (url, isFollowingRedirect) => {
|
32
|
+
if (!isFollowingRedirect) {
|
33
|
+
console.log(`Downloading Git from: ${url}`)
|
34
|
+
}
|
54
35
|
|
55
36
|
const options = {
|
56
37
|
headers: {
|
@@ -60,33 +41,35 @@ const downloadAndUnpack = () => {
|
|
60
41
|
secureProtocol: 'TLSv1_2_method'
|
61
42
|
}
|
62
43
|
|
63
|
-
const
|
64
|
-
|
65
|
-
client.pipe(fs.createWriteStream(config.tempFile))
|
44
|
+
const req = https.get(url, options)
|
66
45
|
|
67
|
-
|
46
|
+
req.on('error', function(error) {
|
68
47
|
if (error.code === 'ETIMEDOUT') {
|
69
48
|
console.log(
|
70
|
-
`A timeout has occurred while downloading '${
|
49
|
+
`A timeout has occurred while downloading '${url}' - check ` +
|
71
50
|
`your internet connection and try again. If you are using a proxy, ` +
|
72
51
|
`make sure that the HTTP_PROXY and HTTPS_PROXY environment variables are set.`,
|
73
52
|
error
|
74
53
|
)
|
75
54
|
} else {
|
76
|
-
console.log(`Error raised while downloading ${
|
55
|
+
console.log(`Error raised while downloading ${url}`, error)
|
77
56
|
}
|
78
57
|
process.exit(1)
|
79
58
|
})
|
80
59
|
|
81
|
-
|
60
|
+
req.on('response', function(res) {
|
61
|
+
if ([301, 302].includes(res.statusCode) && res.headers['location']) {
|
62
|
+
downloadAndUnpack(res.headers.location, true)
|
63
|
+
return
|
64
|
+
}
|
65
|
+
|
82
66
|
if (res.statusCode !== 200) {
|
83
|
-
console.log(`Non-200 response returned from ${
|
67
|
+
console.log(`Non-200 response returned from ${url} - (${res.statusCode})`)
|
84
68
|
process.exit(1)
|
85
69
|
}
|
86
70
|
|
87
71
|
const len = parseInt(res.headers['content-length'], 10)
|
88
72
|
|
89
|
-
console.log()
|
90
73
|
const bar = new ProgressBar('Downloading Git [:bar] :percent :etas', {
|
91
74
|
complete: '=',
|
92
75
|
incomplete: ' ',
|
@@ -94,13 +77,10 @@ const downloadAndUnpack = () => {
|
|
94
77
|
total: len
|
95
78
|
})
|
96
79
|
|
97
|
-
res.
|
98
|
-
bar.tick(chunk.length)
|
99
|
-
})
|
80
|
+
res.pipe(createWriteStream(config.tempFile))
|
100
81
|
|
82
|
+
res.on('data', c => bar.tick(c.length))
|
101
83
|
res.on('end', function() {
|
102
|
-
console.log('\n')
|
103
|
-
|
104
84
|
verifyFile(config.tempFile, valid => {
|
105
85
|
if (valid) {
|
106
86
|
unpackFile(config.tempFile)
|
@@ -121,34 +101,32 @@ if (config.source === '') {
|
|
121
101
|
process.exit(0)
|
122
102
|
}
|
123
103
|
|
124
|
-
|
125
|
-
try {
|
126
|
-
rimraf.sync(config.outputPath)
|
127
|
-
} catch (err) {
|
128
|
-
console.error(err)
|
129
|
-
return
|
130
|
-
}
|
131
|
-
}
|
132
|
-
|
133
|
-
mkdirp(config.outputPath, function(error) {
|
104
|
+
rm(config.outputPath, { recursive: true, force: true }, error => {
|
134
105
|
if (error) {
|
135
|
-
console.log(`Unable to
|
106
|
+
console.log(`Unable to clean directory at ${config.outputPath}`, error)
|
136
107
|
process.exit(1)
|
137
108
|
}
|
138
109
|
|
139
|
-
|
110
|
+
mkdir(config.outputPath, { recursive: true }, function(error) {
|
111
|
+
if (error) {
|
112
|
+
console.log(`Unable to create directory at ${config.outputPath}`, error)
|
113
|
+
process.exit(1)
|
114
|
+
}
|
140
115
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
116
|
+
const tempFile = config.tempFile
|
117
|
+
|
118
|
+
if (existsSync(tempFile)) {
|
119
|
+
verifyFile(tempFile, valid => {
|
120
|
+
if (valid) {
|
121
|
+
unpackFile(tempFile)
|
122
|
+
} else {
|
123
|
+
rmSync(tempFile)
|
124
|
+
downloadAndUnpack(config.source)
|
125
|
+
}
|
126
|
+
})
|
127
|
+
return
|
128
|
+
}
|
152
129
|
|
153
|
-
|
130
|
+
downloadAndUnpack(config.source)
|
131
|
+
})
|
154
132
|
})
|
package/script/utils.js
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
const https = require('https')
|
2
|
+
|
3
|
+
/** Quick-and-dirty async https (only) GET request */
|
4
|
+
const get = url => {
|
5
|
+
const options = {
|
6
|
+
headers: { 'User-Agent': 'dugite' },
|
7
|
+
secureProtocol: 'TLSv1_2_method'
|
8
|
+
}
|
9
|
+
|
10
|
+
return new Promise((resolve, reject) => {
|
11
|
+
https.get(url, options).on('response', res => {
|
12
|
+
if ([301, 302].includes(res.statusCode)) {
|
13
|
+
get(res.headers.location).then(resolve, reject)
|
14
|
+
} else if (res.statusCode !== 200) {
|
15
|
+
reject(new Error(`Got ${res.statusCode} from ${url}`))
|
16
|
+
} else {
|
17
|
+
const chunks = []
|
18
|
+
res.on('data', chunk => chunks.push(chunk))
|
19
|
+
res.on('end', () => {
|
20
|
+
resolve(Buffer.concat(chunks).toString('utf8'))
|
21
|
+
})
|
22
|
+
}
|
23
|
+
})
|
24
|
+
})
|
25
|
+
}
|
26
|
+
|
27
|
+
module.exports = { get }
|