@docusaurus/utils 0.0.0-4744 → 0.0.0-4750
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/gitUtils.d.ts +12 -5
- package/lib/gitUtils.d.ts.map +1 -1
- package/lib/gitUtils.js +7 -10
- package/lib/gitUtils.js.map +1 -1
- package/package.json +4 -4
- package/src/gitUtils.ts +25 -16
package/lib/gitUtils.d.ts
CHANGED
|
@@ -8,12 +8,19 @@ export declare class GitNotFoundError extends Error {
|
|
|
8
8
|
}
|
|
9
9
|
export declare class FileNotTrackedError extends Error {
|
|
10
10
|
}
|
|
11
|
-
export declare
|
|
12
|
-
age?:
|
|
13
|
-
includeAuthor?:
|
|
14
|
-
})
|
|
11
|
+
export declare function getFileCommitDate(file: string, args: {
|
|
12
|
+
age?: 'oldest' | 'newest';
|
|
13
|
+
includeAuthor?: false;
|
|
14
|
+
}): {
|
|
15
15
|
date: Date;
|
|
16
16
|
timestamp: number;
|
|
17
|
-
|
|
17
|
+
};
|
|
18
|
+
export declare function getFileCommitDate(file: string, args: {
|
|
19
|
+
age?: 'oldest' | 'newest';
|
|
20
|
+
includeAuthor: true;
|
|
21
|
+
}): {
|
|
22
|
+
date: Date;
|
|
23
|
+
timestamp: number;
|
|
24
|
+
author: string;
|
|
18
25
|
};
|
|
19
26
|
//# sourceMappingURL=gitUtils.d.ts.map
|
package/lib/gitUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitUtils.d.ts","sourceRoot":"","sources":["../src/gitUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAE9C,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AAEjD,
|
|
1
|
+
{"version":3,"file":"gitUtils.d.ts","sourceRoot":"","sources":["../src/gitUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAE9C,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AAEjD,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IAAC,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAAC,aAAa,CAAC,EAAE,KAAK,CAAA;CAAC,GACvD;IACD,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AACF,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IAAC,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAAC,aAAa,EAAE,IAAI,CAAA;CAAC,GACrD;IACD,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
package/lib/gitUtils.js
CHANGED
|
@@ -16,15 +16,15 @@ exports.GitNotFoundError = GitNotFoundError;
|
|
|
16
16
|
class FileNotTrackedError extends Error {
|
|
17
17
|
}
|
|
18
18
|
exports.FileNotTrackedError = FileNotTrackedError;
|
|
19
|
-
|
|
19
|
+
function getFileCommitDate(file, { age = 'oldest', includeAuthor = false, }) {
|
|
20
20
|
if (!shelljs_1.default.which('git')) {
|
|
21
21
|
throw new GitNotFoundError(`Failed to retrieve git history for "${file}" because git is not installed.`);
|
|
22
22
|
}
|
|
23
23
|
if (!shelljs_1.default.test('-f', file)) {
|
|
24
24
|
throw new Error(`Failed to retrieve git history for "${file}" because the file does not exist.`);
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
// Commit time and author name; not using author time so that amended commits
|
|
27
|
+
// can have their dates updated
|
|
28
28
|
let formatArg = '--format=%ct';
|
|
29
29
|
if (includeAuthor) {
|
|
30
30
|
formatArg += ',%an';
|
|
@@ -35,9 +35,9 @@ const getFileCommitDate = (file, { age = 'oldest', includeAuthor = false, }) =>
|
|
|
35
35
|
// --diff-filter=A ensures we only get the commit which (A)dded the file
|
|
36
36
|
extraArgs += ' --follow --diff-filter=A';
|
|
37
37
|
}
|
|
38
|
-
const result = shelljs_1.default.exec(`git log ${extraArgs} ${formatArg} -- "${
|
|
38
|
+
const result = shelljs_1.default.exec(`git log ${extraArgs} ${formatArg} -- "${path_1.default.basename(file)}"`, {
|
|
39
39
|
// cwd is important, see: https://github.com/facebook/docusaurus/pull/5048
|
|
40
|
-
cwd:
|
|
40
|
+
cwd: path_1.default.dirname(file),
|
|
41
41
|
silent: true,
|
|
42
42
|
});
|
|
43
43
|
if (result.code !== 0) {
|
|
@@ -52,10 +52,7 @@ const getFileCommitDate = (file, { age = 'oldest', includeAuthor = false, }) =>
|
|
|
52
52
|
throw new FileNotTrackedError(`Failed to retrieve the git history for file "${file}" because the file is not tracked by git.`);
|
|
53
53
|
}
|
|
54
54
|
const match = output.match(regex);
|
|
55
|
-
if (!match
|
|
56
|
-
!match.groups ||
|
|
57
|
-
!match.groups.timestamp ||
|
|
58
|
-
(includeAuthor && !match.groups.author)) {
|
|
55
|
+
if (!match) {
|
|
59
56
|
throw new Error(`Failed to retrieve the git history for file "${file}" with unexpected output: ${output}`);
|
|
60
57
|
}
|
|
61
58
|
const timestamp = Number(match.groups.timestamp);
|
|
@@ -64,6 +61,6 @@ const getFileCommitDate = (file, { age = 'oldest', includeAuthor = false, }) =>
|
|
|
64
61
|
return { date, timestamp, author: match.groups.author };
|
|
65
62
|
}
|
|
66
63
|
return { date, timestamp };
|
|
67
|
-
}
|
|
64
|
+
}
|
|
68
65
|
exports.getFileCommitDate = getFileCommitDate;
|
|
69
66
|
//# sourceMappingURL=gitUtils.js.map
|
package/lib/gitUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitUtils.js","sourceRoot":"","sources":["../src/gitUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AACxB,8DAA4B;AAE5B,MAAa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I,MAAM,CAAC,IAAI,KAAK,CAAC,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,gDAAgD,IAAI,oBAAoB,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,MAAM,EAAE,CACxG,CAAC;KACH;IACD,IAAI,KAAK,GAAG,qBAAqB,CAAC;IAClC,IAAI,aAAa,EAAE;QACjB,KAAK,GAAG,mCAAmC,CAAC;KAC7C;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAEpC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,mBAAmB,CAC3B,gDAAgD,IAAI,2CAA2C,CAChG,CAAC;KACH;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAElC,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CACb,gDAAgD,IAAI,6BAA6B,MAAM,EAAE,CAC1F,CAAC;KACH;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,MAAO,CAAC,SAAS,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IAExC,IAAI,aAAa,EAAE;QACjB,OAAO,EAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,MAAO,CAAC,MAAO,EAAC,CAAC;KACzD;IACD,OAAO,EAAC,IAAI,EAAE,SAAS,EAAC,CAAC;AAC3B,CAAC;AAjFD,8CAiFC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4750",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "0.0.0-
|
|
21
|
+
"@docusaurus/logger": "0.0.0-4750",
|
|
22
22
|
"@svgr/webpack": "^6.2.1",
|
|
23
23
|
"file-loader": "^6.2.0",
|
|
24
24
|
"fs-extra": "^10.0.1",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"node": ">=14"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@docusaurus/types": "0.0.0-
|
|
41
|
+
"@docusaurus/types": "0.0.0-4750",
|
|
42
42
|
"@types/dedent": "^0.7.0",
|
|
43
43
|
"@types/github-slugger": "^1.3.0",
|
|
44
44
|
"@types/micromatch": "^4.0.2",
|
|
45
45
|
"@types/react-dom": "^17.0.14",
|
|
46
46
|
"dedent": "^0.7.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "6d0cf0bf7ead33dbb6553e16ce44da6a9999a8ed"
|
|
49
49
|
}
|
package/src/gitUtils.ts
CHANGED
|
@@ -12,7 +12,22 @@ export class GitNotFoundError extends Error {}
|
|
|
12
12
|
|
|
13
13
|
export class FileNotTrackedError extends Error {}
|
|
14
14
|
|
|
15
|
-
export
|
|
15
|
+
export function getFileCommitDate(
|
|
16
|
+
file: string,
|
|
17
|
+
args: {age?: 'oldest' | 'newest'; includeAuthor?: false},
|
|
18
|
+
): {
|
|
19
|
+
date: Date;
|
|
20
|
+
timestamp: number;
|
|
21
|
+
};
|
|
22
|
+
export function getFileCommitDate(
|
|
23
|
+
file: string,
|
|
24
|
+
args: {age?: 'oldest' | 'newest'; includeAuthor: true},
|
|
25
|
+
): {
|
|
26
|
+
date: Date;
|
|
27
|
+
timestamp: number;
|
|
28
|
+
author: string;
|
|
29
|
+
};
|
|
30
|
+
export function getFileCommitDate(
|
|
16
31
|
file: string,
|
|
17
32
|
{
|
|
18
33
|
age = 'oldest',
|
|
@@ -25,7 +40,7 @@ export const getFileCommitDate = (
|
|
|
25
40
|
date: Date;
|
|
26
41
|
timestamp: number;
|
|
27
42
|
author?: string;
|
|
28
|
-
}
|
|
43
|
+
} {
|
|
29
44
|
if (!shell.which('git')) {
|
|
30
45
|
throw new GitNotFoundError(
|
|
31
46
|
`Failed to retrieve git history for "${file}" because git is not installed.`,
|
|
@@ -38,9 +53,8 @@ export const getFileCommitDate = (
|
|
|
38
53
|
);
|
|
39
54
|
}
|
|
40
55
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
56
|
+
// Commit time and author name; not using author time so that amended commits
|
|
57
|
+
// can have their dates updated
|
|
44
58
|
let formatArg = '--format=%ct';
|
|
45
59
|
if (includeAuthor) {
|
|
46
60
|
formatArg += ',%an';
|
|
@@ -54,10 +68,10 @@ export const getFileCommitDate = (
|
|
|
54
68
|
}
|
|
55
69
|
|
|
56
70
|
const result = shell.exec(
|
|
57
|
-
`git log ${extraArgs} ${formatArg} -- "${
|
|
71
|
+
`git log ${extraArgs} ${formatArg} -- "${path.basename(file)}"`,
|
|
58
72
|
{
|
|
59
73
|
// cwd is important, see: https://github.com/facebook/docusaurus/pull/5048
|
|
60
|
-
cwd:
|
|
74
|
+
cwd: path.dirname(file),
|
|
61
75
|
silent: true,
|
|
62
76
|
},
|
|
63
77
|
);
|
|
@@ -81,22 +95,17 @@ export const getFileCommitDate = (
|
|
|
81
95
|
|
|
82
96
|
const match = output.match(regex);
|
|
83
97
|
|
|
84
|
-
if (
|
|
85
|
-
!match ||
|
|
86
|
-
!match.groups ||
|
|
87
|
-
!match.groups.timestamp ||
|
|
88
|
-
(includeAuthor && !match.groups.author)
|
|
89
|
-
) {
|
|
98
|
+
if (!match) {
|
|
90
99
|
throw new Error(
|
|
91
100
|
`Failed to retrieve the git history for file "${file}" with unexpected output: ${output}`,
|
|
92
101
|
);
|
|
93
102
|
}
|
|
94
103
|
|
|
95
|
-
const timestamp = Number(match.groups
|
|
104
|
+
const timestamp = Number(match.groups!.timestamp);
|
|
96
105
|
const date = new Date(timestamp * 1000);
|
|
97
106
|
|
|
98
107
|
if (includeAuthor) {
|
|
99
|
-
return {date, timestamp, author: match.groups
|
|
108
|
+
return {date, timestamp, author: match.groups!.author!};
|
|
100
109
|
}
|
|
101
110
|
return {date, timestamp};
|
|
102
|
-
}
|
|
111
|
+
}
|