@bratel/dgit 0.0.14 → 0.0.16

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/cmd/action.js CHANGED
@@ -10,7 +10,8 @@ const MAX_TEXT_ELLIPSIS = 30;
10
10
  function DownloadAction(githubLink, cmd) {
11
11
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
12
  let { ref = '', dest = '', owner = '', repoName = '', relativePath = '', password, } = cmd;
13
- const { exclude = '', include = '', log = false, logPrefix = '[dgit-logger]', } = cmd;
13
+ const { exclude = '', include = '', log = false, logPrefix = '[dgit-logger]', exactMatch = false, // 是否精确匹配
14
+ } = cmd;
14
15
  const { parallelLimit = '', username, token, } = cmd;
15
16
  const { proxy = '', } = cmd;
16
17
  if (githubLink && (0, utils_1.isHttpsLink)(githubLink)) {
@@ -56,6 +57,7 @@ function DownloadAction(githubLink, cmd) {
56
57
  parallelLimit: Number(parallelLimit.trim()),
57
58
  exclude: excludeList,
58
59
  include: includeList,
60
+ exactMatch,
59
61
  }, {
60
62
  beforeLoadTree() {
61
63
  spinner.start();
package/lib/cmd/main.js CHANGED
@@ -29,6 +29,7 @@ program
29
29
  .option('-t --token, <token>', 'specified git account personal access token.')
30
30
  .option('-e --exclude, <relativePath,...,relativePath>', 'indicates which file paths need to be excluded in the current directory.')
31
31
  .option('-i --include, <relativePath,...,relativePath>', 'indicates which files need to be included in the exclusion file list.')
32
+ .option('--exact-match', 'enable exact path matching instead of prefix matching.')
32
33
  .option('--log', 'output dgit internal log details.')
33
34
  .option('--log-prefix, <log>', 'dgit internal log prefix.')
34
35
  .option('--proxy, <proxyHttp>', 'dgit proxy download url.')
package/lib/cmd/type.d.ts CHANGED
@@ -17,6 +17,7 @@ export interface CommandInfo {
17
17
  log?: boolean;
18
18
  logPrefix?: string;
19
19
  proxy?: string;
20
+ exactMatch?: boolean;
20
21
  }
21
22
  export interface DownloadPromptInfo {
22
23
  dest: string;
package/lib/dgit.js CHANGED
@@ -13,6 +13,7 @@ const UserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
13
13
  const DEFAULT_PARALLEL_LIMIT = 10;
14
14
  const MAX_PARALLEL_LIMIT = 100;
15
15
  const JSON_STRINGIFY_PADDING = 2;
16
+ // https://deepwiki.com/search/python-node-treepythonjula-pyt_e06e7d62-6a9a-4d4b-9e74-0a1cf32f4946?mode=fast
16
17
  function dgit(repoOption, dPath, dgitOptions, hooks) {
17
18
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
18
19
  const { username, password, token, githubLink, proxy = '', } = repoOption;
@@ -28,7 +29,7 @@ function dgit(repoOption, dPath, dgitOptions, hooks) {
28
29
  throw new Error('invalid repo option.');
29
30
  }
30
31
  const logger = (0, log_1.createLogger)(dgitOptions);
31
- const { exclude = [], include = [] } = dgitOptions || {};
32
+ const { exclude = [], include = [], exactMatch = false } = dgitOptions || {};
32
33
  let { parallelLimit = DEFAULT_PARALLEL_LIMIT } = dgitOptions || {};
33
34
  if (!parallelLimit || parallelLimit <= 0) {
34
35
  logger('parallelLimit value is invalid.');
@@ -44,29 +45,26 @@ function dgit(repoOption, dPath, dgitOptions, hooks) {
44
45
  });
45
46
  const { getRepoTreeUrl, getDownloadUrl } = (0, repo_1.default)(owner, repoName, ref, proxy);
46
47
  const url = getRepoTreeUrl();
47
- const headers = {
48
- 'User-Agent': UserAgent,
49
- 'Authorization': token ? `token ${token}` : undefined,
50
- };
51
- const auth = username && password
52
- ? {
53
- user: username,
54
- pass: password,
55
- sendImmediately: true,
56
- }
57
- : undefined;
58
- const options = {
48
+ const config = {
59
49
  url,
60
- headers,
61
- auth,
50
+ headers: {
51
+ 'User-Agent': UserAgent,
52
+ 'Authorization': token ? `token ${token}` : undefined,
53
+ },
54
+ auth: username && password
55
+ ? {
56
+ username,
57
+ password,
58
+ }
59
+ : undefined,
62
60
  };
63
61
  const destPath = node_path_1.default.isAbsolute(dPath) ? dPath : node_path_1.default.resolve(node_process_1.default.cwd(), dPath);
64
62
  logger(' request repo tree options.');
65
- logger(JSON.stringify(options, null, JSON_STRINGIFY_PADDING));
63
+ logger(JSON.stringify(config, null, JSON_STRINGIFY_PADDING));
66
64
  try {
67
65
  logger(' loading remote repo tree...');
68
66
  beforeLoadTree && beforeLoadTree();
69
- const body = yield (0, request_1.requestGetPromise)(options, dgitOptions || {}, {
67
+ const body = yield (0, request_1.requestGetPromise)(config, dgitOptions || {}, {
70
68
  onRetry() {
71
69
  logger(` request ${url} failed. Retrying...`);
72
70
  onRetry && onRetry();
@@ -74,7 +72,7 @@ function dgit(repoOption, dPath, dgitOptions, hooks) {
74
72
  });
75
73
  logger(' loading remote repo tree succeed.');
76
74
  afterLoadTree && afterLoadTree();
77
- const result = JSON.parse(body);
75
+ const result = body;
78
76
  if (!result.tree || result.tree.length <= 0) {
79
77
  throw new Error('404 repo not found!');
80
78
  }
@@ -82,7 +80,15 @@ function dgit(repoOption, dPath, dgitOptions, hooks) {
82
80
  const includeTreeNodeList = treeNodeList.filter((node) => {
83
81
  const nPath = node_path_1.default.resolve(__dirname, node.path);
84
82
  const rPath = node_path_1.default.resolve(__dirname, relativePath);
85
- if (!nPath.startsWith(rPath) || node.type !== 'blob') {
83
+ let pathMatch;
84
+ if (exactMatch) {
85
+ // 精确匹配:路径完全相等或者路径后跟分隔符
86
+ pathMatch = nPath === rPath || nPath.startsWith(rPath + node_path_1.default.sep) || nPath.startsWith(`${rPath}/`);
87
+ }
88
+ else {
89
+ pathMatch = nPath.startsWith(rPath);
90
+ }
91
+ if (!pathMatch || node.type !== 'blob') {
86
92
  return false;
87
93
  }
88
94
  if (exclude.some(v => nPath.startsWith(node_path_1.default.resolve(rPath, v)))
package/lib/repo.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- declare function repoUtils(owner: string, repoName: string, ref: string, proxy: string): {
1
+ declare function repoUtils(owner: string, repoName: string, ref: string, proxy: string | null): {
2
2
  getRepoTreeUrl: () => string;
3
3
  getDownloadUrl: (path: string) => string;
4
4
  };
package/lib/request.d.ts CHANGED
@@ -1,7 +1,5 @@
1
+ import type { AxiosRequestConfig } from 'axios';
1
2
  import type fs from 'node:fs';
2
- import type { CoreOptions, UrlOptions } from 'request';
3
3
  import type { DgitGlobalOption, DgitLifeCycle } from './type';
4
- type RequestOption = UrlOptions & CoreOptions;
5
- export declare function requestGetPromise(options: RequestOption, dgitOptions: DgitGlobalOption, hooks?: DgitLifeCycle): Promise<any>;
4
+ export declare function requestGetPromise(config: AxiosRequestConfig, dgitOptions: DgitGlobalOption, hooks?: DgitLifeCycle): Promise<any>;
6
5
  export declare function requestOnStream(url: string, ws: fs.WriteStream, dgitOptions: DgitGlobalOption, hooks?: DgitLifeCycle): void;
7
- export {};
package/lib/request.js CHANGED
@@ -3,15 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requestGetPromise = requestGetPromise;
4
4
  exports.requestOnStream = requestOnStream;
5
5
  const tslib_1 = require("tslib");
6
- const request_1 = tslib_1.__importDefault(require("request"));
6
+ const axios_1 = tslib_1.__importDefault(require("axios"));
7
7
  const utils_1 = require("./cmd/utils");
8
8
  const log_1 = require("./log");
9
9
  const REQUEST_RETRY_DELAY = 1500;
10
10
  const DEFAULT_MAX_RETRY_COUNT = 5;
11
- function requestGet(options, maxRetryCount, hooks) {
12
- const { onSuccess, onError, onFinish, onRetry, } = hooks || {};
13
- request_1.default.get(options, (err, _, body) => {
14
- if (err) {
11
+ function requestGet(config, maxRetryCount, hooks) {
12
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
+ const { onSuccess, onError, onFinish, onRetry, } = hooks || {};
14
+ try {
15
+ const response = yield (0, axios_1.default)(config);
16
+ onSuccess && onSuccess(response.data);
17
+ onFinish && onFinish();
18
+ }
19
+ catch (err) {
15
20
  if (maxRetryCount < 1) {
16
21
  onError && onError(err);
17
22
  onFinish && onFinish();
@@ -19,15 +24,12 @@ function requestGet(options, maxRetryCount, hooks) {
19
24
  }
20
25
  setTimeout(() => {
21
26
  onRetry && onRetry();
22
- requestGet(options, maxRetryCount - 1, hooks);
27
+ requestGet(config, maxRetryCount - 1, hooks);
23
28
  }, REQUEST_RETRY_DELAY);
24
- return;
25
29
  }
26
- onSuccess && onSuccess(body);
27
- onFinish && onFinish();
28
30
  });
29
31
  }
30
- function requestGetPromise(options, dgitOptions, hooks) {
32
+ function requestGetPromise(config, dgitOptions, hooks) {
31
33
  return new Promise((resolve, reject) => {
32
34
  const { maxRetryCount = DEFAULT_MAX_RETRY_COUNT } = dgitOptions;
33
35
  const { onSuccess, onError, onFinish, onRetry, } = hooks || {};
@@ -43,18 +45,25 @@ function requestGetPromise(options, dgitOptions, hooks) {
43
45
  onFinish,
44
46
  onRetry,
45
47
  };
46
- requestGet(options, maxRetryCount, newHooks);
48
+ requestGet(config, maxRetryCount, newHooks);
47
49
  });
48
50
  }
49
51
  function requestOnStream(url, ws, dgitOptions, hooks) {
50
52
  const { maxRetryCount = DEFAULT_MAX_RETRY_COUNT } = dgitOptions;
51
53
  const logger = (0, log_1.createLogger)(dgitOptions);
52
54
  const { onSuccess, onError, onFinish, onRetry, } = hooks || {};
53
- const fn = (retryCount) => {
55
+ const fn = (retryCount) => tslib_1.__awaiter(this, void 0, void 0, function* () {
54
56
  const downloadUrl = (0, utils_1.AddExtraRandomQs)(url);
55
57
  logger(` dowloading from ${downloadUrl}...`);
56
- (0, request_1.default)(encodeURI(downloadUrl))
57
- .on('error', (err) => {
58
+ try {
59
+ const response = yield (0, axios_1.default)({
60
+ method: 'GET',
61
+ url: encodeURI(downloadUrl),
62
+ responseType: 'stream',
63
+ });
64
+ response.data.pipe(ws);
65
+ }
66
+ catch (err) {
58
67
  if (retryCount <= 0) {
59
68
  onError && onError(err);
60
69
  onFinish && onFinish();
@@ -64,9 +73,8 @@ function requestOnStream(url, ws, dgitOptions, hooks) {
64
73
  onRetry && onRetry();
65
74
  fn(retryCount - 1);
66
75
  }, REQUEST_RETRY_DELAY);
67
- })
68
- .pipe(ws);
69
- };
76
+ }
77
+ });
70
78
  ws.on('finish', () => {
71
79
  onSuccess && onSuccess();
72
80
  onFinish && onFinish();
package/lib/type.d.ts CHANGED
@@ -6,6 +6,7 @@ export interface DgitGlobalOption {
6
6
  logPrefix?: string;
7
7
  exclude?: GithubRelativePath[];
8
8
  include?: GithubRelativePath[];
9
+ exactMatch?: boolean;
9
10
  }
10
11
  export interface PrivateOption {
11
12
  username?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bratel/dgit",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "@dking/hasaki-cli init application",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -24,7 +24,7 @@
24
24
  "build:ts": "tsc --build",
25
25
  "lint": "eslint",
26
26
  "lint:fix": "eslint src --ext .jsx --ext .js --ext .tsx --ext .ts --cache --fix",
27
- "test:mocha": "nyc --reporter=text mocha --require ts-node/register test/**/*.{ts,tsx} -t 60000",
27
+ "test:mocha": "npm run build:ts && nyc --reporter=text mocha --require ts-node/register test/**/*.{ts,tsx} -t 60000",
28
28
  "test:mocha:reporter": "nyc --reporter=lcov --reporter=text mocha --require ts-node/register test/**/*.{ts,tsx} -t 60000 --reporter=mochawesome",
29
29
  "watch:ts": "tsc --watch",
30
30
  "prepublishOnly": "npm run test:mocha && npm run lint && npm run build:ts"
@@ -35,14 +35,13 @@
35
35
  "@types/inquirer": "^9.0.9",
36
36
  "@types/ora": "^3.2.0",
37
37
  "@types/progress": "^2.0.7",
38
- "@types/request": "^2.48.13",
39
38
  "async": "^3.2.6",
39
+ "axios": "^1.13.2",
40
40
  "chalk": "^5.6.2",
41
41
  "commander": "^14.0.2",
42
42
  "inquirer": "^13.1.0",
43
43
  "ora": "^9.0.0",
44
- "progress": "^2.0.3",
45
- "request": "^2.88.2"
44
+ "progress": "^2.0.3"
46
45
  },
47
46
  "devDependencies": {
48
47
  "@antfu/eslint-config": "^6.7.3",
@@ -59,6 +58,16 @@
59
58
  "ts-node": "^10.9.2",
60
59
  "typescript": "^5.9.3"
61
60
  },
61
+ "overrides": {
62
+ "request": {
63
+ "form-data": "^4.0.4",
64
+ "tough-cookie": "^4.1.3"
65
+ }
66
+ },
67
+ "resolutions": {
68
+ "form-data": "^4.0.4",
69
+ "tough-cookie": "^4.1.3"
70
+ },
62
71
  "husky": {
63
72
  "hooks": {
64
73
  "pre-commit": "lint-staged"
package/src/cmd/action.ts CHANGED
@@ -29,6 +29,7 @@ async function DownloadAction(githubLink: string | undefined, cmd: Command & Com
29
29
  include = '',
30
30
  log = false,
31
31
  logPrefix = '[dgit-logger]',
32
+ exactMatch = false, // 是否精确匹配
32
33
  } = cmd;
33
34
 
34
35
  const {
@@ -92,6 +93,7 @@ async function DownloadAction(githubLink: string | undefined, cmd: Command & Com
92
93
  parallelLimit: Number(parallelLimit.trim()),
93
94
  exclude: excludeList,
94
95
  include: includeList,
96
+ exactMatch,
95
97
  },
96
98
  {
97
99
  beforeLoadTree() {
package/src/cmd/main.ts CHANGED
@@ -49,6 +49,7 @@ program
49
49
  '-i --include, <relativePath,...,relativePath>',
50
50
  'indicates which files need to be included in the exclusion file list.',
51
51
  )
52
+ .option('--exact-match', 'enable exact path matching instead of prefix matching.')
52
53
  .option('--log', 'output dgit internal log details.')
53
54
  .option('--log-prefix, <log>', 'dgit internal log prefix.')
54
55
  .option('--proxy, <proxyHttp>', 'dgit proxy download url.')
package/src/cmd/type.ts CHANGED
@@ -18,6 +18,7 @@ export interface CommandInfo {
18
18
  log?: boolean;
19
19
  logPrefix?: string;
20
20
  proxy?: string;
21
+ exactMatch?: boolean;
21
22
  }
22
23
 
23
24
  export interface DownloadPromptInfo {
package/src/dgit.ts CHANGED
@@ -23,6 +23,7 @@ const DEFAULT_PARALLEL_LIMIT = 10;
23
23
  const MAX_PARALLEL_LIMIT = 100;
24
24
  const JSON_STRINGIFY_PADDING = 2;
25
25
 
26
+ // https://deepwiki.com/search/python-node-treepythonjula-pyt_e06e7d62-6a9a-4d4b-9e74-0a1cf32f4946?mode=fast
26
27
  async function dgit(repoOption: RepoOptionType, dPath: string, dgitOptions?: DgitGlobalOption, hooks?: DgitLifeCycle & DgitLoadGitTree): Promise<void> {
27
28
  const {
28
29
  username,
@@ -53,7 +54,7 @@ async function dgit(repoOption: RepoOptionType, dPath: string, dgitOptions?: Dgi
53
54
 
54
55
  const logger = createLogger(dgitOptions);
55
56
 
56
- const { exclude = [], include = [] } = dgitOptions || {};
57
+ const { exclude = [], include = [], exactMatch = false } = dgitOptions || {};
57
58
 
58
59
  let { parallelLimit = DEFAULT_PARALLEL_LIMIT } = dgitOptions || {};
59
60
  if (!parallelLimit || parallelLimit <= 0) {
@@ -85,34 +86,29 @@ async function dgit(repoOption: RepoOptionType, dPath: string, dgitOptions?: Dgi
85
86
  const { getRepoTreeUrl, getDownloadUrl } = repo(owner, repoName, ref, proxy);
86
87
  const url = getRepoTreeUrl();
87
88
 
88
- const headers = {
89
- 'User-Agent': UserAgent,
90
- 'Authorization': token ? `token ${token}` : undefined,
91
- };
92
-
93
- const auth = username && password
94
- ? {
95
- user: username,
96
- pass: password,
97
- sendImmediately: true,
98
- }
99
- : undefined;
100
-
101
- const options = {
89
+ const config = {
102
90
  url,
103
- headers,
104
- auth,
91
+ headers: {
92
+ 'User-Agent': UserAgent,
93
+ 'Authorization': token ? `token ${token}` : undefined,
94
+ },
95
+ auth: username && password
96
+ ? {
97
+ username,
98
+ password,
99
+ }
100
+ : undefined,
105
101
  };
106
102
 
107
103
  const destPath = path.isAbsolute(dPath) ? dPath : path.resolve(process.cwd(), dPath);
108
104
 
109
105
  logger(' request repo tree options.');
110
- logger(JSON.stringify(options, null, JSON_STRINGIFY_PADDING));
106
+ logger(JSON.stringify(config, null, JSON_STRINGIFY_PADDING));
111
107
 
112
108
  try {
113
109
  logger(' loading remote repo tree...');
114
110
  beforeLoadTree && beforeLoadTree();
115
- const body = await requestGetPromise(options, dgitOptions || {}, {
111
+ const body = await requestGetPromise(config, dgitOptions || {}, {
116
112
  onRetry() {
117
113
  logger(` request ${url} failed. Retrying...`);
118
114
  onRetry && onRetry();
@@ -121,7 +117,7 @@ async function dgit(repoOption: RepoOptionType, dPath: string, dgitOptions?: Dgi
121
117
 
122
118
  logger(' loading remote repo tree succeed.');
123
119
  afterLoadTree && afterLoadTree();
124
- const result = JSON.parse(body);
120
+ const result = body;
125
121
 
126
122
  if (!result.tree || result.tree.length <= 0) {
127
123
  throw new Error('404 repo not found!');
@@ -131,7 +127,15 @@ async function dgit(repoOption: RepoOptionType, dPath: string, dgitOptions?: Dgi
131
127
  const includeTreeNodeList = treeNodeList.filter((node) => {
132
128
  const nPath = path.resolve(__dirname, node.path);
133
129
  const rPath = path.resolve(__dirname, relativePath);
134
- if (!nPath.startsWith(rPath) || node.type !== 'blob') {
130
+ let pathMatch: boolean;
131
+ if (exactMatch) {
132
+ // 精确匹配:路径完全相等或者路径后跟分隔符
133
+ pathMatch = nPath === rPath || nPath.startsWith(rPath + path.sep) || nPath.startsWith(`${rPath}/`);
134
+ }
135
+ else {
136
+ pathMatch = nPath.startsWith(rPath);
137
+ }
138
+ if (!pathMatch || node.type !== 'blob') {
135
139
  return false;
136
140
  }
137
141
  if (
package/src/repo.ts CHANGED
@@ -1,4 +1,4 @@
1
- function repoUtils(owner: string, repoName: string, ref: string, proxy: string) {
1
+ function repoUtils(owner: string, repoName: string, ref: string, proxy: string | null) {
2
2
  return {
3
3
  getRepoTreeUrl: () => `https://api.github.com/repos/${owner}/${repoName}/git/trees/${ref}?recursive=1`,
4
4
  getDownloadUrl: (path: string) => `${proxy ? `${proxy}/` : ''}https://raw.githubusercontent.com/${owner}/${repoName}/${ref}/${path}`,
package/src/request.ts CHANGED
@@ -1,16 +1,14 @@
1
+ import type { AxiosRequestConfig } from 'axios';
1
2
  import type fs from 'node:fs';
2
- import type { CoreOptions, UrlOptions } from 'request';
3
3
  import type { DgitGlobalOption, DgitLifeCycle } from './type';
4
- import request from 'request';
4
+ import axios from 'axios';
5
5
  import { AddExtraRandomQs } from './cmd/utils';
6
6
  import { createLogger } from './log';
7
7
 
8
- type RequestOption = UrlOptions & CoreOptions;
9
-
10
8
  const REQUEST_RETRY_DELAY = 1500;
11
9
  const DEFAULT_MAX_RETRY_COUNT = 5;
12
10
 
13
- function requestGet(options: RequestOption, maxRetryCount: number, hooks?: DgitLifeCycle): void {
11
+ async function requestGet(config: AxiosRequestConfig, maxRetryCount: number, hooks?: DgitLifeCycle): Promise<void> {
14
12
  const {
15
13
  onSuccess,
16
14
  onError,
@@ -18,26 +16,25 @@ function requestGet(options: RequestOption, maxRetryCount: number, hooks?: DgitL
18
16
  onRetry,
19
17
  } = hooks || {};
20
18
 
21
- request.get(options, (err, _, body) => {
22
- if (err) {
23
- if (maxRetryCount < 1) {
24
- onError && onError(err);
25
- onFinish && onFinish();
26
- return;
27
- }
28
- setTimeout(() => {
29
- onRetry && onRetry();
30
- requestGet(options, maxRetryCount - 1, hooks);
31
- }, REQUEST_RETRY_DELAY);
19
+ try {
20
+ const response = await axios(config);
21
+ onSuccess && onSuccess(response.data);
22
+ onFinish && onFinish();
23
+ }
24
+ catch (err: any) {
25
+ if (maxRetryCount < 1) {
26
+ onError && onError(err);
27
+ onFinish && onFinish();
32
28
  return;
33
29
  }
34
-
35
- onSuccess && onSuccess(body);
36
- onFinish && onFinish();
37
- });
30
+ setTimeout(() => {
31
+ onRetry && onRetry();
32
+ requestGet(config, maxRetryCount - 1, hooks);
33
+ }, REQUEST_RETRY_DELAY);
34
+ }
38
35
  }
39
36
 
40
- export function requestGetPromise(options: RequestOption, dgitOptions: DgitGlobalOption, hooks?: DgitLifeCycle): Promise<any> {
37
+ export function requestGetPromise(config: AxiosRequestConfig, dgitOptions: DgitGlobalOption, hooks?: DgitLifeCycle): Promise<any> {
41
38
  return new Promise((resolve, reject) => {
42
39
  const { maxRetryCount = DEFAULT_MAX_RETRY_COUNT } = dgitOptions;
43
40
 
@@ -61,7 +58,7 @@ export function requestGetPromise(options: RequestOption, dgitOptions: DgitGloba
61
58
  onRetry,
62
59
  };
63
60
 
64
- requestGet(options, maxRetryCount, newHooks);
61
+ requestGet(config, maxRetryCount, newHooks);
65
62
  });
66
63
  }
67
64
 
@@ -77,23 +74,32 @@ export function requestOnStream(url: string, ws: fs.WriteStream, dgitOptions: Dg
77
74
  onRetry,
78
75
  } = hooks || {};
79
76
 
80
- const fn = (retryCount: number): void => {
77
+ const fn = async (retryCount: number): Promise<void> => {
81
78
  const downloadUrl = AddExtraRandomQs(url);
82
79
  logger(` dowloading from ${downloadUrl}...`);
83
80
 
84
- request(encodeURI(downloadUrl))
85
- .on('error', (err) => {
86
- if (retryCount <= 0) {
87
- onError && onError(err);
88
- onFinish && onFinish();
89
- return;
90
- }
91
- setTimeout(() => {
92
- onRetry && onRetry();
93
- fn(retryCount - 1);
94
- }, REQUEST_RETRY_DELAY);
95
- })
96
- .pipe(ws);
81
+ try {
82
+ const response = await axios(
83
+ {
84
+ method: 'GET',
85
+ url: encodeURI(downloadUrl),
86
+ responseType: 'stream',
87
+ },
88
+ );
89
+ response.data.pipe(ws);
90
+ }
91
+ catch (err: any) {
92
+ if (retryCount <= 0) {
93
+ onError && onError(err);
94
+ onFinish && onFinish();
95
+ return;
96
+ }
97
+
98
+ setTimeout(() => {
99
+ onRetry && onRetry();
100
+ fn(retryCount - 1);
101
+ }, REQUEST_RETRY_DELAY);
102
+ }
97
103
  };
98
104
 
99
105
  ws.on('finish', () => {
package/src/type.ts CHANGED
@@ -7,6 +7,7 @@ export interface DgitGlobalOption {
7
7
  logPrefix?: string;
8
8
  exclude?: GithubRelativePath[];
9
9
  include?: GithubRelativePath[];
10
+ exactMatch?: boolean; // 精确匹配,比如只匹配mingw-w64-python,不去匹配mingw-w64-python-*
10
11
  }
11
12
 
12
13
  export interface PrivateOption {
package/tsconfig.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "compilerOptions": {
3
3
  /* Basic Options */
4
4
  // "incremental": true, /* Enable incremental compilation */
5
- "target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
5
+ "target": "ES2016", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
6
6
 
7
7
  "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
8
8
  // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
@@ -65,6 +65,9 @@
65
65
  "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
66
66
  "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
67
67
  },
68
+ "ts-node": {
69
+ "files": true
70
+ },
68
71
  "include": [
69
72
  "src/**/*"
70
73
  ],