@docusaurus/utils 4.0.0-canary-6946 → 4.0.0-canary-6948
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/vcs/gitUtils.d.ts +10 -13
- package/lib/vcs/gitUtils.d.ts.map +1 -1
- package/lib/vcs/gitUtils.js +22 -40
- package/lib/vcs/gitUtils.js.map +1 -1
- package/package.json +4 -4
- package/src/vcs/gitUtils.ts +40 -55
package/lib/vcs/gitUtils.d.ts
CHANGED
|
@@ -4,18 +4,15 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
/** Custom error thrown when the current file is not tracked by git. */
|
|
8
|
-
export declare class FileNotTrackedError extends Error {
|
|
9
|
-
}
|
|
10
7
|
/**
|
|
11
8
|
* Fetches the git history of a file and returns a relevant commit date.
|
|
12
9
|
* It gets the commit date instead of author date so that amended commits
|
|
13
10
|
* can have their dates updated.
|
|
14
11
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* @throws
|
|
18
|
-
* unexpected text.
|
|
12
|
+
* Returns `null` if the file is not tracked by git.
|
|
13
|
+
*
|
|
14
|
+
* @throws If git is not found in `PATH`, if the file does not exist, if
|
|
15
|
+
* `git log` exited with non-zero, or if it outputs unexpected text.
|
|
19
16
|
*/
|
|
20
17
|
export declare function getFileCommitDate(
|
|
21
18
|
/** Absolute path to the file. */
|
|
@@ -32,16 +29,16 @@ file: string, args: {
|
|
|
32
29
|
date: Date;
|
|
33
30
|
/** Timestamp returned from git, converted to **milliseconds**. */
|
|
34
31
|
timestamp: number;
|
|
35
|
-
}>;
|
|
32
|
+
} | null>;
|
|
36
33
|
/**
|
|
37
34
|
* Fetches the git history of a file and returns a relevant commit date.
|
|
38
35
|
* It gets the commit date instead of author date so that amended commits
|
|
39
36
|
* can have their dates updated.
|
|
40
37
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* @throws
|
|
44
|
-
* unexpected text.
|
|
38
|
+
* Returns `null` if the file is not tracked by git.
|
|
39
|
+
*
|
|
40
|
+
* @throws If git is not found in `PATH`, if the file does not exist, if
|
|
41
|
+
* `git log` exited with non-zero, or if it outputs unexpected text.
|
|
45
42
|
*/
|
|
46
43
|
export declare function getFileCommitDate(
|
|
47
44
|
/** Absolute path to the file. */
|
|
@@ -59,7 +56,7 @@ file: string, args: {
|
|
|
59
56
|
timestamp: number;
|
|
60
57
|
/** The author's name, as returned from git. */
|
|
61
58
|
author: string;
|
|
62
|
-
}>;
|
|
59
|
+
} | null>;
|
|
63
60
|
type GitCommitInfo = {
|
|
64
61
|
timestamp: number;
|
|
65
62
|
author: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitUtils.d.ts","sourceRoot":"","sources":["../../src/vcs/gitUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"gitUtils.d.ts","sourceRoot":"","sources":["../../src/vcs/gitUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA0CH;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB;AACrC,iCAAiC;AACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IACJ;;;OAGG;IACH,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,uEAAuE;IACvE,aAAa,CAAC,EAAE,KAAK,CAAC;CACvB,GACA,OAAO,CAAC;IACT,4BAA4B;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,IAAI,CAAC,CAAC;AACV;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB;AACrC,iCAAiC;AACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IACJ;;;OAGG;IACH,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,aAAa,EAAE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@ -6,7 +6,6 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.FileNotTrackedError = void 0;
|
|
10
9
|
exports.getFileCommitDate = getFileCommitDate;
|
|
11
10
|
exports.getGitLastUpdate = getGitLastUpdate;
|
|
12
11
|
exports.getGitCreation = getGitCreation;
|
|
@@ -49,20 +48,9 @@ const realHasGitFn = () => {
|
|
|
49
48
|
// The hasGit call is synchronous IO so we memoize it
|
|
50
49
|
// The user won't install Git in the middle of a build anyway...
|
|
51
50
|
const hasGit = process.env.NODE_ENV === 'test' ? realHasGitFn : lodash_1.default.memoize(realHasGitFn);
|
|
52
|
-
// TODO Docusaurus v4: remove this
|
|
53
|
-
// Exceptions are not made for control flow logic
|
|
54
|
-
/** Custom error thrown when git is not found in `PATH`. */
|
|
55
|
-
class GitNotFoundError extends Error {
|
|
56
|
-
}
|
|
57
|
-
// TODO Docusaurus v4: remove this, only kept for retro-compatibility
|
|
58
|
-
// Exceptions are not made for control flow logic
|
|
59
|
-
/** Custom error thrown when the current file is not tracked by git. */
|
|
60
|
-
class FileNotTrackedError extends Error {
|
|
61
|
-
}
|
|
62
|
-
exports.FileNotTrackedError = FileNotTrackedError;
|
|
63
51
|
async function getFileCommitDate(file, { age = 'oldest', includeAuthor = false, }) {
|
|
64
52
|
if (!hasGit()) {
|
|
65
|
-
throw new
|
|
53
|
+
throw new Error(`Failed to retrieve git history for "${file}" because git is not installed.`);
|
|
66
54
|
}
|
|
67
55
|
if (!(await (0, fs_1.pathExists)(file))) {
|
|
68
56
|
throw new Error(`Failed to retrieve git history for "${file}" because the file does not exist.`);
|
|
@@ -92,8 +80,9 @@ async function getFileCommitDate(file, { age = 'oldest', includeAuthor = false,
|
|
|
92
80
|
? /(?:^|\n)RESULT:(?<timestamp>\d+),(?<author>.+)(?:$|\n)/
|
|
93
81
|
: /(?:^|\n)RESULT:(?<timestamp>\d+)(?:$|\n)/;
|
|
94
82
|
const output = result.stdout.trim();
|
|
83
|
+
// No output: the file is not tracked by git
|
|
95
84
|
if (!output) {
|
|
96
|
-
|
|
85
|
+
return null;
|
|
97
86
|
}
|
|
98
87
|
const match = output.match(regex);
|
|
99
88
|
if (!match) {
|
|
@@ -107,40 +96,33 @@ async function getFileCommitDate(file, { age = 'oldest', includeAuthor = false,
|
|
|
107
96
|
}
|
|
108
97
|
return { date, timestamp };
|
|
109
98
|
}
|
|
110
|
-
let
|
|
111
|
-
let
|
|
99
|
+
let showedGitRequirementWarning = false;
|
|
100
|
+
let showedFileNotTrackedWarning = false;
|
|
112
101
|
async function getGitCommitInfo(filePath, age) {
|
|
113
102
|
if (!filePath) {
|
|
114
103
|
return null;
|
|
115
104
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
age,
|
|
121
|
-
includeAuthor: true,
|
|
122
|
-
});
|
|
123
|
-
return { timestamp: result.timestamp, author: result.author };
|
|
124
|
-
}
|
|
125
|
-
catch (err) {
|
|
126
|
-
// TODO legacy perf issue: do not use exceptions for control flow!
|
|
127
|
-
if (err instanceof GitNotFoundError) {
|
|
128
|
-
if (!showedGitRequirementError) {
|
|
129
|
-
logger_1.default.warn('Sorry, the last update options require Git.');
|
|
130
|
-
showedGitRequirementError = true;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
else if (err instanceof FileNotTrackedError) {
|
|
134
|
-
if (!showedFileNotTrackedError) {
|
|
135
|
-
logger_1.default.warn('Cannot infer the update date for some files, as they are not tracked by git.');
|
|
136
|
-
showedFileNotTrackedError = true;
|
|
137
|
-
}
|
|
105
|
+
if (!hasGit()) {
|
|
106
|
+
if (!showedGitRequirementWarning) {
|
|
107
|
+
logger_1.default.warn('Sorry, the last update options require Git.');
|
|
108
|
+
showedGitRequirementWarning = true;
|
|
138
109
|
}
|
|
139
|
-
|
|
140
|
-
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const result = await getFileCommitDate(filePath, {
|
|
113
|
+
age,
|
|
114
|
+
includeAuthor: true,
|
|
115
|
+
}).catch((err) => {
|
|
116
|
+
throw new Error(`An error occurred when trying to get the file ${age === 'oldest' ? 'creation' : 'last update'} date from Git`, { cause: err });
|
|
117
|
+
});
|
|
118
|
+
if (!result) {
|
|
119
|
+
if (!showedFileNotTrackedWarning) {
|
|
120
|
+
logger_1.default.warn('Cannot infer the update date for some files, as they are not tracked by git.');
|
|
121
|
+
showedFileNotTrackedWarning = true;
|
|
141
122
|
}
|
|
142
123
|
return null;
|
|
143
124
|
}
|
|
125
|
+
return { timestamp: result.timestamp, author: result.author };
|
|
144
126
|
}
|
|
145
127
|
async function getGitLastUpdate(filePath) {
|
|
146
128
|
return getGitCommitInfo(filePath, 'newest');
|
package/lib/vcs/gitUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitUtils.js","sourceRoot":"","sources":["../../src/vcs/gitUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"gitUtils.js","sourceRoot":"","sources":["../../src/vcs/gitUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;AAEH,kEAA6B;AAC7B,8DAAyB;AACzB,4DAAuB;AACvB,iCAAuC;AACvC,8DAA6B;AAC7B,wEAAwC;AACxC,uCAA8C;AAE9C,2EAA2E;AAC3E,wDAAwD;AACxD,MAAM,4BAA4B,GAAG,iBAAE,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC;AAEnE,MAAM,wBAAwB,GAAG,OAAO,CAAC,GAAG,CAAC,kCAAkC;IAC7E,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kCAAkC,EAAE,EAAE,CAAC;IAC9D,CAAC,CAAC,SAAS,CAAC;AAEd,MAAM,qBAAqB,GACzB,wBAAwB,IAAI,wBAAwB,GAAG,CAAC;IACtD,CAAC,CAAC,wBA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e,GAAG,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE,WAAW,CAAC,CAAC;QACnE,MAAM,WAAW,GACf,CAAC,eAAe,IAAI,eAAe,KAAK,mBAAmB;YACzD,CAAC,CAAC,EAAC,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,aAAa,EAAC;YACrD,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC;QAE/B,MAAM,qBAAqB,GAAG,eAAe,EAAE,UAAU,CAAC,SAAS,IAAI,CAAC,CAAC;QACzE,MAAM,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC;QACvE,MAAM,aAAa,GACjB,CAAC,eAAe,IAAI,iBAAiB,KAAK,qBAAqB;YAC7D,CAAC,CAAC,EAAC,SAAS,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa,EAAC;YACvD,CAAC,CAAC,eAAe,CAAC,UAAU,CAAC;QAEjC,UAAU,CAAC,GAAG,CAAC,YAAY,EAAE;YAC3B,QAAQ,EAAE,WAAW;YACrB,UAAU,EAAE,aAAa;SAC1B,CAAC,CAAC;IACL,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils",
|
|
3
|
-
"version": "4.0.0-canary-
|
|
3
|
+
"version": "4.0.0-canary-6948",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@11ty/gray-matter": "^3.0.0",
|
|
18
|
-
"@docusaurus/fs": "4.0.0-canary-
|
|
19
|
-
"@docusaurus/logger": "4.0.0-canary-
|
|
20
|
-
"@docusaurus/types": "4.0.0-canary-
|
|
18
|
+
"@docusaurus/fs": "4.0.0-canary-6948",
|
|
19
|
+
"@docusaurus/logger": "4.0.0-canary-6948",
|
|
20
|
+
"@docusaurus/types": "4.0.0-canary-6948",
|
|
21
21
|
"execa": "^10.0.1",
|
|
22
22
|
"github-slugger": "^2.0.0",
|
|
23
23
|
"jiti": "^2.7.0",
|
package/src/vcs/gitUtils.ts
CHANGED
|
@@ -45,25 +45,15 @@ const realHasGitFn = () => {
|
|
|
45
45
|
const hasGit =
|
|
46
46
|
process.env.NODE_ENV === 'test' ? realHasGitFn : _.memoize(realHasGitFn);
|
|
47
47
|
|
|
48
|
-
// TODO Docusaurus v4: remove this
|
|
49
|
-
// Exceptions are not made for control flow logic
|
|
50
|
-
/** Custom error thrown when git is not found in `PATH`. */
|
|
51
|
-
class GitNotFoundError extends Error {}
|
|
52
|
-
|
|
53
|
-
// TODO Docusaurus v4: remove this, only kept for retro-compatibility
|
|
54
|
-
// Exceptions are not made for control flow logic
|
|
55
|
-
/** Custom error thrown when the current file is not tracked by git. */
|
|
56
|
-
export class FileNotTrackedError extends Error {}
|
|
57
|
-
|
|
58
48
|
/**
|
|
59
49
|
* Fetches the git history of a file and returns a relevant commit date.
|
|
60
50
|
* It gets the commit date instead of author date so that amended commits
|
|
61
51
|
* can have their dates updated.
|
|
62
52
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @throws
|
|
66
|
-
* unexpected text.
|
|
53
|
+
* Returns `null` if the file is not tracked by git.
|
|
54
|
+
*
|
|
55
|
+
* @throws If git is not found in `PATH`, if the file does not exist, if
|
|
56
|
+
* `git log` exited with non-zero, or if it outputs unexpected text.
|
|
67
57
|
*/
|
|
68
58
|
export async function getFileCommitDate(
|
|
69
59
|
/** Absolute path to the file. */
|
|
@@ -82,16 +72,16 @@ export async function getFileCommitDate(
|
|
|
82
72
|
date: Date; // TODO duplicate data, not really useful?
|
|
83
73
|
/** Timestamp returned from git, converted to **milliseconds**. */
|
|
84
74
|
timestamp: number;
|
|
85
|
-
}>;
|
|
75
|
+
} | null>;
|
|
86
76
|
/**
|
|
87
77
|
* Fetches the git history of a file and returns a relevant commit date.
|
|
88
78
|
* It gets the commit date instead of author date so that amended commits
|
|
89
79
|
* can have their dates updated.
|
|
90
80
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* @throws
|
|
94
|
-
* unexpected text.
|
|
81
|
+
* Returns `null` if the file is not tracked by git.
|
|
82
|
+
*
|
|
83
|
+
* @throws If git is not found in `PATH`, if the file does not exist, if
|
|
84
|
+
* `git log` exited with non-zero, or if it outputs unexpected text.
|
|
95
85
|
*/
|
|
96
86
|
export async function getFileCommitDate(
|
|
97
87
|
/** Absolute path to the file. */
|
|
@@ -111,7 +101,7 @@ export async function getFileCommitDate(
|
|
|
111
101
|
timestamp: number;
|
|
112
102
|
/** The author's name, as returned from git. */
|
|
113
103
|
author: string;
|
|
114
|
-
}>;
|
|
104
|
+
} | null>;
|
|
115
105
|
|
|
116
106
|
export async function getFileCommitDate(
|
|
117
107
|
file: string,
|
|
@@ -126,9 +116,9 @@ export async function getFileCommitDate(
|
|
|
126
116
|
date: Date;
|
|
127
117
|
timestamp: number;
|
|
128
118
|
author?: string;
|
|
129
|
-
}> {
|
|
119
|
+
} | null> {
|
|
130
120
|
if (!hasGit()) {
|
|
131
|
-
throw new
|
|
121
|
+
throw new Error(
|
|
132
122
|
`Failed to retrieve git history for "${file}" because git is not installed.`,
|
|
133
123
|
);
|
|
134
124
|
}
|
|
@@ -172,10 +162,9 @@ export async function getFileCommitDate(
|
|
|
172
162
|
|
|
173
163
|
const output = result.stdout.trim();
|
|
174
164
|
|
|
165
|
+
// No output: the file is not tracked by git
|
|
175
166
|
if (!output) {
|
|
176
|
-
|
|
177
|
-
`Failed to retrieve the git history for file "${file}" because the file is not tracked by git.`,
|
|
178
|
-
);
|
|
167
|
+
return null;
|
|
179
168
|
}
|
|
180
169
|
|
|
181
170
|
const match = output.match(regex);
|
|
@@ -196,8 +185,8 @@ export async function getFileCommitDate(
|
|
|
196
185
|
return {date, timestamp};
|
|
197
186
|
}
|
|
198
187
|
|
|
199
|
-
let
|
|
200
|
-
let
|
|
188
|
+
let showedGitRequirementWarning = false;
|
|
189
|
+
let showedFileNotTrackedWarning = false;
|
|
201
190
|
|
|
202
191
|
type GitCommitInfo = {timestamp: number; author: string};
|
|
203
192
|
|
|
@@ -208,38 +197,34 @@ async function getGitCommitInfo(
|
|
|
208
197
|
if (!filePath) {
|
|
209
198
|
return null;
|
|
210
199
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
} else {
|
|
234
|
-
throw new Error(
|
|
235
|
-
`An error occurred when trying to get the file ${
|
|
236
|
-
age === 'oldest' ? 'creation' : 'last update'
|
|
237
|
-
} date from Git`,
|
|
238
|
-
{cause: err},
|
|
200
|
+
if (!hasGit()) {
|
|
201
|
+
if (!showedGitRequirementWarning) {
|
|
202
|
+
logger.warn('Sorry, the last update options require Git.');
|
|
203
|
+
showedGitRequirementWarning = true;
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
const result = await getFileCommitDate(filePath, {
|
|
208
|
+
age,
|
|
209
|
+
includeAuthor: true,
|
|
210
|
+
}).catch((err) => {
|
|
211
|
+
throw new Error(
|
|
212
|
+
`An error occurred when trying to get the file ${
|
|
213
|
+
age === 'oldest' ? 'creation' : 'last update'
|
|
214
|
+
} date from Git`,
|
|
215
|
+
{cause: err},
|
|
216
|
+
);
|
|
217
|
+
});
|
|
218
|
+
if (!result) {
|
|
219
|
+
if (!showedFileNotTrackedWarning) {
|
|
220
|
+
logger.warn(
|
|
221
|
+
'Cannot infer the update date for some files, as they are not tracked by git.',
|
|
239
222
|
);
|
|
223
|
+
showedFileNotTrackedWarning = true;
|
|
240
224
|
}
|
|
241
225
|
return null;
|
|
242
226
|
}
|
|
227
|
+
return {timestamp: result.timestamp, author: result.author};
|
|
243
228
|
}
|
|
244
229
|
|
|
245
230
|
export async function getGitLastUpdate(
|