@docusaurus/utils 3.9.2 → 3.10.1-canary-6591
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/index.d.ts +5 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +13 -11
- package/lib/index.js.map +1 -1
- package/lib/lastUpdateUtils.d.ts +2 -6
- package/lib/lastUpdateUtils.d.ts.map +1 -1
- package/lib/lastUpdateUtils.js +13 -60
- package/lib/lastUpdateUtils.js.map +1 -1
- package/lib/markdownHeadingIdUtils.d.ts +49 -0
- package/lib/markdownHeadingIdUtils.d.ts.map +1 -0
- package/lib/markdownHeadingIdUtils.js +148 -0
- package/lib/markdownHeadingIdUtils.js.map +1 -0
- package/lib/markdownUtils.d.ts +0 -31
- package/lib/markdownUtils.d.ts.map +1 -1
- package/lib/markdownUtils.js +0 -89
- package/lib/markdownUtils.js.map +1 -1
- package/lib/moduleUtils.d.ts.map +1 -1
- package/lib/moduleUtils.js +4 -4
- package/lib/moduleUtils.js.map +1 -1
- package/lib/{gitUtils.d.ts → vcs/gitUtils.d.ts} +18 -0
- package/lib/vcs/gitUtils.d.ts.map +1 -0
- package/lib/vcs/gitUtils.js +343 -0
- package/lib/vcs/gitUtils.js.map +1 -0
- package/lib/vcs/vcs.d.ts +19 -0
- package/lib/vcs/vcs.d.ts.map +1 -0
- package/lib/vcs/vcs.js +46 -0
- package/lib/vcs/vcs.js.map +1 -0
- package/lib/vcs/vcsDefaultV1.d.ts +13 -0
- package/lib/vcs/vcsDefaultV1.d.ts.map +1 -0
- package/lib/vcs/vcsDefaultV1.js +33 -0
- package/lib/vcs/vcsDefaultV1.js.map +1 -0
- package/lib/vcs/vcsDefaultV2.d.ts +13 -0
- package/lib/vcs/vcsDefaultV2.d.ts.map +1 -0
- package/lib/vcs/vcsDefaultV2.js +33 -0
- package/lib/vcs/vcsDefaultV2.js.map +1 -0
- package/lib/vcs/vcsDisabled.d.ts +12 -0
- package/lib/vcs/vcsDisabled.d.ts.map +1 -0
- package/lib/vcs/vcsDisabled.js +24 -0
- package/lib/vcs/vcsDisabled.js.map +1 -0
- package/lib/vcs/vcsGitAdHoc.d.ts +16 -0
- package/lib/vcs/vcsGitAdHoc.d.ts.map +1 -0
- package/lib/vcs/vcsGitAdHoc.js +29 -0
- package/lib/vcs/vcsGitAdHoc.js.map +1 -0
- package/lib/vcs/vcsGitEager.d.ts +10 -0
- package/lib/vcs/vcsGitEager.d.ts.map +1 -0
- package/lib/vcs/vcsGitEager.js +89 -0
- package/lib/vcs/vcsGitEager.js.map +1 -0
- package/lib/vcs/vcsHardcoded.d.ts +17 -0
- package/lib/vcs/vcsHardcoded.d.ts.map +1 -0
- package/lib/vcs/vcsHardcoded.js +41 -0
- package/lib/vcs/vcsHardcoded.js.map +1 -0
- package/package.json +11 -11
- package/src/index.ts +11 -8
- package/src/lastUpdateUtils.ts +18 -76
- package/src/markdownHeadingIdUtils.ts +209 -0
- package/src/markdownUtils.ts +0 -119
- package/src/moduleUtils.ts +6 -8
- package/src/vcs/gitUtils.ts +541 -0
- package/src/vcs/vcs.ts +54 -0
- package/src/vcs/vcsDefaultV1.ts +33 -0
- package/src/vcs/vcsDefaultV2.ts +33 -0
- package/src/vcs/vcsDisabled.ts +25 -0
- package/src/vcs/vcsGitAdHoc.ts +30 -0
- package/src/vcs/vcsGitEager.ts +135 -0
- package/src/vcs/vcsHardcoded.ts +45 -0
- package/lib/cliUtils.d.ts +0 -14
- package/lib/cliUtils.d.ts.map +0 -1
- package/lib/cliUtils.js +0 -49
- package/lib/cliUtils.js.map +0 -1
- package/lib/gitUtils.d.ts.map +0 -1
- package/lib/gitUtils.js +0 -103
- package/lib/gitUtils.js.map +0 -1
- package/src/cliUtils.ts +0 -65
- package/src/gitUtils.ts +0 -200
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { VcsConfig } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* This VCS implements the historical Git automatic strategy.
|
|
10
|
+
* It is only enabled in production mode, using ad-hoc git log commands.
|
|
11
|
+
*/
|
|
12
|
+
export declare const VcsDefaultV1: VcsConfig;
|
|
13
|
+
//# sourceMappingURL=vcsDefaultV1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcsDefaultV1.d.ts","sourceRoot":"","sources":["../../src/vcs/vcsDefaultV1.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AASjD;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,SAU1B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.VcsDefaultV1 = void 0;
|
|
10
|
+
const vcsHardcoded_1 = require("./vcsHardcoded");
|
|
11
|
+
const vcsGitAdHoc_1 = require("./vcsGitAdHoc");
|
|
12
|
+
function getDynamicStrategy() {
|
|
13
|
+
return process.env.NODE_ENV === 'development' ||
|
|
14
|
+
process.env.NODE_ENV === 'test'
|
|
15
|
+
? vcsHardcoded_1.VcsHardcoded
|
|
16
|
+
: vcsGitAdHoc_1.VcsGitAdHoc;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* This VCS implements the historical Git automatic strategy.
|
|
20
|
+
* It is only enabled in production mode, using ad-hoc git log commands.
|
|
21
|
+
*/
|
|
22
|
+
exports.VcsDefaultV1 = {
|
|
23
|
+
initialize: (...params) => {
|
|
24
|
+
return getDynamicStrategy().initialize(...params);
|
|
25
|
+
},
|
|
26
|
+
getFileCreationInfo: (...params) => {
|
|
27
|
+
return getDynamicStrategy().getFileCreationInfo(...params);
|
|
28
|
+
},
|
|
29
|
+
getFileLastUpdateInfo: (...params) => {
|
|
30
|
+
return getDynamicStrategy().getFileLastUpdateInfo(...params);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=vcsDefaultV1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcsDefaultV1.js","sourceRoot":"","sources":["../../src/vcs/vcsDefaultV1.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,iDAA4C;AAC5C,+CAA0C;AAG1C,SAAS,kBAAkB;IACzB,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC3C,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM;QAC/B,CAAC,CAAC,2BAAY;QACd,CAAC,CAAC,yBAAW,CAAC;AAClB,CAAC;AAED;;;GAGG;AACU,QAAA,YAAY,GAAc;IACrC,UAAU,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE;QACxB,OAAO,kBAAkB,EAAE,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC;IACpD,CAAC;IACD,mBAAmB,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE;QACjC,OAAO,kBAAkB,EAAE,CAAC,mBAAmB,CAAC,GAAG,MAAM,CAAC,CAAC;IAC7D,CAAC;IACD,qBAAqB,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE;QACnC,OAAO,kBAAkB,EAAE,CAAC,qBAAqB,CAAC,GAAG,MAAM,CAAC,CAAC;IAC/D,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { VcsConfig } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* This VCS implements the new eager Git automatic strategy.
|
|
10
|
+
* It is only enabled in production mode, reading the git repository eagerly.
|
|
11
|
+
*/
|
|
12
|
+
export declare const VcsDefaultV2: VcsConfig;
|
|
13
|
+
//# sourceMappingURL=vcsDefaultV2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcsDefaultV2.d.ts","sourceRoot":"","sources":["../../src/vcs/vcsDefaultV2.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AASjD;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,SAU1B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.VcsDefaultV2 = void 0;
|
|
10
|
+
const vcsHardcoded_1 = require("./vcsHardcoded");
|
|
11
|
+
const vcsGitEager_1 = require("./vcsGitEager");
|
|
12
|
+
function getStrategy() {
|
|
13
|
+
return process.env.NODE_ENV === 'development' ||
|
|
14
|
+
process.env.NODE_ENV === 'test'
|
|
15
|
+
? vcsHardcoded_1.VcsHardcoded
|
|
16
|
+
: vcsGitEager_1.VscGitEager;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* This VCS implements the new eager Git automatic strategy.
|
|
20
|
+
* It is only enabled in production mode, reading the git repository eagerly.
|
|
21
|
+
*/
|
|
22
|
+
exports.VcsDefaultV2 = {
|
|
23
|
+
initialize: (...params) => {
|
|
24
|
+
return getStrategy().initialize(...params);
|
|
25
|
+
},
|
|
26
|
+
getFileCreationInfo: (...params) => {
|
|
27
|
+
return getStrategy().getFileCreationInfo(...params);
|
|
28
|
+
},
|
|
29
|
+
getFileLastUpdateInfo: (...params) => {
|
|
30
|
+
return getStrategy().getFileLastUpdateInfo(...params);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=vcsDefaultV2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcsDefaultV2.js","sourceRoot":"","sources":["../../src/vcs/vcsDefaultV2.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,iDAA4C;AAC5C,+CAA0C;AAG1C,SAAS,WAAW;IAClB,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa;QAC3C,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM;QAC/B,CAAC,CAAC,2BAAY;QACd,CAAC,CAAC,yBAAW,CAAC;AAClB,CAAC;AAED;;;GAGG;AACU,QAAA,YAAY,GAAc;IACrC,UAAU,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE;QACxB,OAAO,WAAW,EAAE,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC,CAAC;IAC7C,CAAC;IACD,mBAAmB,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE;QACjC,OAAO,WAAW,EAAE,CAAC,mBAAmB,CAAC,GAAG,MAAM,CAAC,CAAC;IACtD,CAAC;IACD,qBAAqB,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE;QACnC,OAAO,WAAW,EAAE,CAAC,qBAAqB,CAAC,GAAG,MAAM,CAAC,CAAC;IACxD,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { VcsConfig } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* This VCS implementation always returns null values
|
|
10
|
+
*/
|
|
11
|
+
export declare const VcsDisabled: VcsConfig;
|
|
12
|
+
//# sourceMappingURL=vcsDisabled.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcsDisabled.d.ts","sourceRoot":"","sources":["../../src/vcs/vcsDisabled.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,SAYzB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.VcsDisabled = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* This VCS implementation always returns null values
|
|
12
|
+
*/
|
|
13
|
+
exports.VcsDisabled = {
|
|
14
|
+
initialize: () => {
|
|
15
|
+
// Noop
|
|
16
|
+
},
|
|
17
|
+
getFileCreationInfo: async (_filePath) => {
|
|
18
|
+
return null;
|
|
19
|
+
},
|
|
20
|
+
getFileLastUpdateInfo: async (_ilePath) => {
|
|
21
|
+
return null;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=vcsDisabled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcsDisabled.js","sourceRoot":"","sources":["../../src/vcs/vcsDisabled.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAIH;;GAEG;AACU,QAAA,WAAW,GAAc;IACpC,UAAU,EAAE,GAAG,EAAE;QACf,OAAO;IACT,CAAC;IAED,mBAAmB,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,qBAAqB,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { VcsConfig } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* A VCS strategy to query Git information in an ad-hoc way.
|
|
10
|
+
* This is the default/historical Docusaurus Git VCS implementation.
|
|
11
|
+
* Unfortunately, it is a major bottleneck for large sites/repositories.
|
|
12
|
+
*
|
|
13
|
+
* See also https://github.com/facebook/docusaurus/issues/11208
|
|
14
|
+
*/
|
|
15
|
+
export declare const VcsGitAdHoc: VcsConfig;
|
|
16
|
+
//# sourceMappingURL=vcsGitAdHoc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcsGitAdHoc.d.ts","sourceRoot":"","sources":["../../src/vcs/vcsGitAdHoc.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAEjD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,EAAE,SAYzB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.VcsGitAdHoc = void 0;
|
|
10
|
+
const gitUtils_1 = require("./gitUtils");
|
|
11
|
+
/**
|
|
12
|
+
* A VCS strategy to query Git information in an ad-hoc way.
|
|
13
|
+
* This is the default/historical Docusaurus Git VCS implementation.
|
|
14
|
+
* Unfortunately, it is a major bottleneck for large sites/repositories.
|
|
15
|
+
*
|
|
16
|
+
* See also https://github.com/facebook/docusaurus/issues/11208
|
|
17
|
+
*/
|
|
18
|
+
exports.VcsGitAdHoc = {
|
|
19
|
+
initialize: () => {
|
|
20
|
+
// Nothing to do here for the default/historical Git implementation
|
|
21
|
+
},
|
|
22
|
+
getFileCreationInfo: async (filePath) => {
|
|
23
|
+
return (0, gitUtils_1.getGitCreation)(filePath);
|
|
24
|
+
},
|
|
25
|
+
getFileLastUpdateInfo: async (filePath) => {
|
|
26
|
+
return (0, gitUtils_1.getGitLastUpdate)(filePath);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=vcsGitAdHoc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcsGitAdHoc.js","sourceRoot":"","sources":["../../src/vcs/vcsGitAdHoc.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,yCAA4D;AAG5D;;;;;;GAMG;AACU,QAAA,WAAW,GAAc;IACpC,UAAU,EAAE,GAAG,EAAE;QACf,mEAAmE;IACrE,CAAC;IAED,mBAAmB,EAAE,KAAK,EAAE,QAAgB,EAAE,EAAE;QAC9C,OAAO,IAAA,yBAAc,EAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED,qBAAqB,EAAE,KAAK,EAAE,QAAgB,EAAE,EAAE;QAChD,OAAO,IAAA,2BAAgB,EAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { VcsConfig } from '@docusaurus/types';
|
|
8
|
+
export declare function createVcsGitEagerConfig(): VcsConfig;
|
|
9
|
+
export declare const VscGitEager: VcsConfig;
|
|
10
|
+
//# sourceMappingURL=vcsGitEager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcsGitEager.d.ts","sourceRoot":"","sources":["../../src/vcs/vcsGitEager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAmEjD,wBAAgB,uBAAuB,IAAI,SAAS,CAiDnD;AAGD,eAAO,MAAM,WAAW,EAAE,SAAqC,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.VscGitEager = void 0;
|
|
10
|
+
exports.createVcsGitEagerConfig = createVcsGitEagerConfig;
|
|
11
|
+
const tslib_1 = require("tslib");
|
|
12
|
+
const node_path_1 = require("node:path");
|
|
13
|
+
const logger_1 = tslib_1.__importStar(require("@docusaurus/logger"));
|
|
14
|
+
const gitUtils_1 = require("./gitUtils");
|
|
15
|
+
// The Map keys should be absolute file paths, not relative Git paths
|
|
16
|
+
function resolveFileInfoMapPaths(repoRoot, filesInfo) {
|
|
17
|
+
function transformMapEntry(entry) {
|
|
18
|
+
// We just resolve the Git paths that are relative to the repo root
|
|
19
|
+
return [(0, node_path_1.resolve)(repoRoot, entry[0]), entry[1]];
|
|
20
|
+
}
|
|
21
|
+
return new Map(Array.from(filesInfo.entries()).map(transformMapEntry));
|
|
22
|
+
}
|
|
23
|
+
function mergeFileMaps(fileMaps) {
|
|
24
|
+
return new Map(fileMaps.flatMap((m) => [...m]));
|
|
25
|
+
}
|
|
26
|
+
async function loadAllGitFilesInfoMap(cwd) {
|
|
27
|
+
const roots = await logger_1.PerfLogger.async('Reading Git root dirs', () => (0, gitUtils_1.getGitAllRepoRoots)(cwd));
|
|
28
|
+
const allMaps = await Promise.all(roots.map(async (root) => {
|
|
29
|
+
const map = await logger_1.PerfLogger.async(`Reading Git history for repo ${logger_1.default.path((0, node_path_1.basename)(root))}`, () => (0, gitUtils_1.getGitRepositoryFilesInfo)(root));
|
|
30
|
+
return resolveFileInfoMapPaths(root, map);
|
|
31
|
+
}));
|
|
32
|
+
return mergeFileMaps(allMaps);
|
|
33
|
+
}
|
|
34
|
+
async function initialize({ siteDir, }) {
|
|
35
|
+
try {
|
|
36
|
+
const isInWorktree = await (0, gitUtils_1.isGitInsideWorktree)(siteDir);
|
|
37
|
+
if (!isInWorktree) {
|
|
38
|
+
return { type: 'error', reason: 'not-in-worktree' };
|
|
39
|
+
}
|
|
40
|
+
const filesMap = await loadAllGitFilesInfoMap(siteDir);
|
|
41
|
+
return { type: 'success', filesMap };
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return { type: 'error', reason: 'unknown', cause: error };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function createVcsGitEagerConfig() {
|
|
48
|
+
let initPromise = null;
|
|
49
|
+
async function getGitFileInfo(filePath) {
|
|
50
|
+
const init = (await initPromise);
|
|
51
|
+
if (init.type === 'success') {
|
|
52
|
+
return init.filesMap.get(filePath) ?? null;
|
|
53
|
+
}
|
|
54
|
+
else if (init.reason === 'not-in-worktree') {
|
|
55
|
+
throw new Error(`This Docusaurus site is outside any Git worktree.
|
|
56
|
+
Unable to read Git info for file ${logger_1.default.path(filePath)} `);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
throw init.cause;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
initialize: ({ siteDir }) => {
|
|
64
|
+
if (initPromise) {
|
|
65
|
+
// We only initialize this VCS once!
|
|
66
|
+
// For i18n sites, this permits reading ahead of time for all locales
|
|
67
|
+
// so that it only slows down the first locale
|
|
68
|
+
// I assume this logic is fine, but we'll see if it causes trouble
|
|
69
|
+
// Note: we could also only call "initialize()" once from the outside,
|
|
70
|
+
// But maybe it could be useful for custom VCS implementations to be
|
|
71
|
+
// able to initialize once per locale?
|
|
72
|
+
logger_1.PerfLogger.log('Git Eager VCS strategy already initialized, skipping re-initialization');
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
initPromise = logger_1.PerfLogger.async('Git Eager VCS init', () => initialize({ siteDir }));
|
|
76
|
+
},
|
|
77
|
+
getFileCreationInfo: async (filePath) => {
|
|
78
|
+
const fileInfo = await getGitFileInfo(filePath);
|
|
79
|
+
return fileInfo?.creation ?? null;
|
|
80
|
+
},
|
|
81
|
+
getFileLastUpdateInfo: async (filePath) => {
|
|
82
|
+
const fileInfo = await getGitFileInfo(filePath);
|
|
83
|
+
return fileInfo?.lastUpdate ?? null;
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
// TODO it probably shouldn't be a singleton, but good enough for now
|
|
88
|
+
exports.VscGitEager = createVcsGitEagerConfig();
|
|
89
|
+
//# sourceMappingURL=vcsGitEager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcsGitEager.js","sourceRoot":"","sources":["../../src/vcs/vcsGitEager.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { VcsConfig, VcsChangeInfo } from '@docusaurus/types';
|
|
8
|
+
export declare const VCS_HARDCODED_CREATION_INFO: VcsChangeInfo;
|
|
9
|
+
export declare const VCS_HARDCODED_LAST_UPDATE_INFO: VcsChangeInfo;
|
|
10
|
+
export declare const VCS_HARDCODED_UNTRACKED_FILE_PATH: string;
|
|
11
|
+
/**
|
|
12
|
+
* This VCS implementation always returns hardcoded values for testing purposes.
|
|
13
|
+
* It is also useful in dev environments where VCS info is not important.
|
|
14
|
+
* Reading information from the VCS can be slow and is not always necessary.
|
|
15
|
+
*/
|
|
16
|
+
export declare const VcsHardcoded: VcsConfig;
|
|
17
|
+
//# sourceMappingURL=vcsHardcoded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcsHardcoded.d.ts","sourceRoot":"","sources":["../../src/vcs/vcsHardcoded.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAE,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAEhE,eAAO,MAAM,2BAA2B,EAAE,aAGzC,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,aAG5C,CAAC;AAEF,eAAO,MAAM,iCAAiC,QAAmC,CAAC;AAElF;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,SAkB1B,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.VcsHardcoded = exports.VCS_HARDCODED_UNTRACKED_FILE_PATH = exports.VCS_HARDCODED_LAST_UPDATE_INFO = exports.VCS_HARDCODED_CREATION_INFO = void 0;
|
|
10
|
+
exports.VCS_HARDCODED_CREATION_INFO = {
|
|
11
|
+
timestamp: 1490997600000, // 1st Apr 2017
|
|
12
|
+
author: 'Creator',
|
|
13
|
+
};
|
|
14
|
+
exports.VCS_HARDCODED_LAST_UPDATE_INFO = {
|
|
15
|
+
timestamp: 1539502055000, // 14th Oct 2018
|
|
16
|
+
author: 'Author',
|
|
17
|
+
};
|
|
18
|
+
exports.VCS_HARDCODED_UNTRACKED_FILE_PATH = `file/path/${Math.random()}.mdx`;
|
|
19
|
+
/**
|
|
20
|
+
* This VCS implementation always returns hardcoded values for testing purposes.
|
|
21
|
+
* It is also useful in dev environments where VCS info is not important.
|
|
22
|
+
* Reading information from the VCS can be slow and is not always necessary.
|
|
23
|
+
*/
|
|
24
|
+
exports.VcsHardcoded = {
|
|
25
|
+
initialize: () => {
|
|
26
|
+
// Noop
|
|
27
|
+
},
|
|
28
|
+
getFileCreationInfo: async (filePath) => {
|
|
29
|
+
if (filePath === exports.VCS_HARDCODED_UNTRACKED_FILE_PATH) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return exports.VCS_HARDCODED_CREATION_INFO;
|
|
33
|
+
},
|
|
34
|
+
getFileLastUpdateInfo: async (filePath) => {
|
|
35
|
+
if (filePath === exports.VCS_HARDCODED_UNTRACKED_FILE_PATH) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return exports.VCS_HARDCODED_LAST_UPDATE_INFO;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=vcsHardcoded.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcsHardcoded.js","sourceRoot":"","sources":["../../src/vcs/vcsHardcoded.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAIU,QAAA,2BAA2B,GAAkB;IACxD,SAAS,EAAE,aAAa,EAAE,eAAe;IACzC,MAAM,EAAE,SAAS;CAClB,CAAC;AAEW,QAAA,8BAA8B,GAAkB;IAC3D,SAAS,EAAE,aAAa,EAAE,gBAAgB;IAC1C,MAAM,EAAE,QAAQ;CACjB,CAAC;AAEW,QAAA,iCAAiC,GAAG,aAAa,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;AAElF;;;;GAIG;AACU,QAAA,YAAY,GAAc;IACrC,UAAU,EAAE,GAAG,EAAE;QACf,OAAO;IACT,CAAC;IAED,mBAAmB,EAAE,KAAK,EAAE,QAAgB,EAAE,EAAE;QAC9C,IAAI,QAAQ,KAAK,yCAAiC,EAAE,CAAC;YACnD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,mCAA2B,CAAC;IACrC,CAAC;IAED,qBAAqB,EAAE,KAAK,EAAE,QAAgB,EAAE,EAAE;QAChD,IAAI,QAAQ,KAAK,yCAAiC,EAAE,CAAC;YACnD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,sCAA8B,CAAC;IACxC,CAAC;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.1-canary-6591",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "3.
|
|
22
|
-
"@docusaurus/types": "3.
|
|
23
|
-
"@docusaurus/utils-common": "3.
|
|
21
|
+
"@docusaurus/logger": "3.10.1-canary-6591",
|
|
22
|
+
"@docusaurus/types": "3.10.1-canary-6591",
|
|
23
|
+
"@docusaurus/utils-common": "3.10.1-canary-6591",
|
|
24
24
|
"escape-string-regexp": "^4.0.0",
|
|
25
|
-
"execa": "5.1.1",
|
|
25
|
+
"execa": "^5.1.1",
|
|
26
26
|
"file-loader": "^6.2.0",
|
|
27
|
-
"fs-extra": "^11.
|
|
27
|
+
"fs-extra": "^11.2.0",
|
|
28
28
|
"github-slugger": "^1.5.0",
|
|
29
29
|
"globby": "^11.1.0",
|
|
30
30
|
"gray-matter": "^4.0.3",
|
|
@@ -38,18 +38,18 @@
|
|
|
38
38
|
"tslib": "^2.6.0",
|
|
39
39
|
"url-loader": "^4.1.1",
|
|
40
40
|
"utility-types": "^3.10.0",
|
|
41
|
-
"webpack": "^5.
|
|
41
|
+
"webpack": "^5.106.2"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
|
-
"node": ">=
|
|
44
|
+
"node": ">=24.14"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/dedent": "^0.7.0",
|
|
48
48
|
"@types/github-slugger": "^1.3.0",
|
|
49
|
-
"@types/micromatch": "^4.0.
|
|
50
|
-
"@types/react-dom": "^
|
|
49
|
+
"@types/micromatch": "^4.0.10",
|
|
50
|
+
"@types/react-dom": "^19.2.3",
|
|
51
51
|
"dedent": "^0.7.0",
|
|
52
52
|
"tmp-promise": "^3.0.3"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "0a37b4e95aa595949734a1cb72d13305bbacb822"
|
|
55
55
|
}
|
package/src/index.ts
CHANGED
|
@@ -25,10 +25,12 @@ export {
|
|
|
25
25
|
} from './constants';
|
|
26
26
|
export {generate, readOutputHTMLFile} from './emitUtils';
|
|
27
27
|
export {
|
|
28
|
+
// TODO Docusaurus v4: remove these legacy exports,
|
|
29
|
+
// they are only kept for retro-compatibility
|
|
28
30
|
getFileCommitDate,
|
|
29
31
|
FileNotTrackedError,
|
|
30
32
|
GitNotFoundError,
|
|
31
|
-
} from './gitUtils';
|
|
33
|
+
} from './vcs/gitUtils';
|
|
32
34
|
export {
|
|
33
35
|
mergeTranslations,
|
|
34
36
|
updateTranslationFileMessages,
|
|
@@ -66,17 +68,20 @@ export {
|
|
|
66
68
|
getTagVisibility,
|
|
67
69
|
} from './tags';
|
|
68
70
|
export {
|
|
69
|
-
parseMarkdownHeadingId,
|
|
70
|
-
escapeMarkdownHeadingIds,
|
|
71
71
|
unwrapMdxCodeBlocks,
|
|
72
72
|
admonitionTitleToDirectiveLabel,
|
|
73
73
|
createExcerpt,
|
|
74
74
|
DEFAULT_PARSE_FRONT_MATTER,
|
|
75
75
|
parseMarkdownContentTitle,
|
|
76
76
|
parseMarkdownFile,
|
|
77
|
+
} from './markdownUtils';
|
|
78
|
+
export {
|
|
79
|
+
parseMarkdownHeadingId,
|
|
80
|
+
escapeMarkdownHeadingIds,
|
|
77
81
|
writeMarkdownHeadingId,
|
|
82
|
+
type HeadingIdSyntax,
|
|
78
83
|
type WriteHeadingIDOptions,
|
|
79
|
-
} from './
|
|
84
|
+
} from './markdownHeadingIdUtils';
|
|
80
85
|
export {
|
|
81
86
|
type ContentPaths,
|
|
82
87
|
type SourceToPermalink,
|
|
@@ -117,16 +122,14 @@ export {
|
|
|
117
122
|
} from './dataFileUtils';
|
|
118
123
|
export {isDraft, isUnlisted} from './contentVisibilityUtils';
|
|
119
124
|
export {escapeRegexp} from './regExpUtils';
|
|
120
|
-
export {askPreferredLanguage} from './cliUtils';
|
|
121
125
|
export {flattenRoutes} from './routeUtils';
|
|
122
126
|
|
|
123
127
|
export {
|
|
124
|
-
getGitLastUpdate,
|
|
125
|
-
getLastUpdate,
|
|
126
128
|
readLastUpdateData,
|
|
127
|
-
LAST_UPDATE_FALLBACK,
|
|
128
129
|
type LastUpdateData,
|
|
129
130
|
type FrontMatterLastUpdate,
|
|
130
131
|
} from './lastUpdateUtils';
|
|
131
132
|
|
|
133
|
+
export {VcsPresetNames, getVcsPreset, TEST_VCS} from './vcs/vcs';
|
|
134
|
+
|
|
132
135
|
export {normalizeTags, reportInlineTags} from './tags';
|
package/src/lastUpdateUtils.ts
CHANGED
|
@@ -6,13 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import _ from 'lodash';
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
GitNotFoundError,
|
|
13
|
-
getFileCommitDate,
|
|
14
|
-
} from './gitUtils';
|
|
15
|
-
import type {PluginOptions} from '@docusaurus/types';
|
|
9
|
+
import {getVcsPreset} from './vcs/vcs';
|
|
10
|
+
|
|
11
|
+
import type {PluginOptions, VcsConfig} from '@docusaurus/types';
|
|
16
12
|
|
|
17
13
|
export type LastUpdateData = {
|
|
18
14
|
/**
|
|
@@ -29,72 +25,6 @@ export type LastUpdateData = {
|
|
|
29
25
|
lastUpdatedBy: string | undefined | null;
|
|
30
26
|
};
|
|
31
27
|
|
|
32
|
-
let showedGitRequirementError = false;
|
|
33
|
-
let showedFileNotTrackedError = false;
|
|
34
|
-
|
|
35
|
-
export async function getGitLastUpdate(
|
|
36
|
-
filePath: string,
|
|
37
|
-
): Promise<LastUpdateData | null> {
|
|
38
|
-
if (!filePath) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Wrap in try/catch in case the shell commands fail
|
|
43
|
-
// (e.g. project doesn't use Git, etc).
|
|
44
|
-
try {
|
|
45
|
-
const result = await getFileCommitDate(filePath, {
|
|
46
|
-
age: 'newest',
|
|
47
|
-
includeAuthor: true,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
return {lastUpdatedAt: result.timestamp, lastUpdatedBy: result.author};
|
|
51
|
-
} catch (err) {
|
|
52
|
-
if (err instanceof GitNotFoundError) {
|
|
53
|
-
if (!showedGitRequirementError) {
|
|
54
|
-
logger.warn('Sorry, the last update options require Git.');
|
|
55
|
-
showedGitRequirementError = true;
|
|
56
|
-
}
|
|
57
|
-
} else if (err instanceof FileNotTrackedError) {
|
|
58
|
-
if (!showedFileNotTrackedError) {
|
|
59
|
-
logger.warn(
|
|
60
|
-
'Cannot infer the update date for some files, as they are not tracked by git.',
|
|
61
|
-
);
|
|
62
|
-
showedFileNotTrackedError = true;
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
throw new Error(
|
|
66
|
-
`An error occurred when trying to get the last update date`,
|
|
67
|
-
{cause: err},
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export const LAST_UPDATE_FALLBACK: LastUpdateData = {
|
|
75
|
-
lastUpdatedAt: 1539502055000,
|
|
76
|
-
lastUpdatedBy: 'Author',
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// Not proud of this, but convenient for tests :/
|
|
80
|
-
export const LAST_UPDATE_UNTRACKED_GIT_FILEPATH = `file/path/${Math.random()}.mdx`;
|
|
81
|
-
|
|
82
|
-
export async function getLastUpdate(
|
|
83
|
-
filePath: string,
|
|
84
|
-
): Promise<LastUpdateData | null> {
|
|
85
|
-
if (filePath === LAST_UPDATE_UNTRACKED_GIT_FILEPATH) {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
if (
|
|
89
|
-
process.env.NODE_ENV !== 'production' ||
|
|
90
|
-
process.env.DOCUSAURUS_DISABLE_LAST_UPDATE === 'true'
|
|
91
|
-
) {
|
|
92
|
-
// Use fake data in dev/test for faster development.
|
|
93
|
-
return LAST_UPDATE_FALLBACK;
|
|
94
|
-
}
|
|
95
|
-
return getGitLastUpdate(filePath);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
28
|
type LastUpdateOptions = Pick<
|
|
99
29
|
PluginOptions,
|
|
100
30
|
'showLastUpdateAuthor' | 'showLastUpdateTime'
|
|
@@ -109,11 +39,21 @@ export type FrontMatterLastUpdate = {
|
|
|
109
39
|
date?: Date | string;
|
|
110
40
|
};
|
|
111
41
|
|
|
42
|
+
// TODO Docusaurus v4: refactor/rename, make it clear this fn is only
|
|
43
|
+
// for Markdown files with front matter shared by content plugin
|
|
112
44
|
export async function readLastUpdateData(
|
|
113
45
|
filePath: string,
|
|
114
46
|
options: LastUpdateOptions,
|
|
115
47
|
lastUpdateFrontMatter: FrontMatterLastUpdate | undefined,
|
|
48
|
+
vcsParam: Pick<VcsConfig, 'getFileLastUpdateInfo'>,
|
|
116
49
|
): Promise<LastUpdateData> {
|
|
50
|
+
// We fallback to the default VSC config at runtime on purpose
|
|
51
|
+
// It preserves retro-compatibility if a third-party plugin imports it
|
|
52
|
+
// This also ensures unit tests keep working without extra setup
|
|
53
|
+
// We still want to ensure type safety by requiring the VCS param
|
|
54
|
+
// TODO Docusaurus v4: refactor all these Git read APIs
|
|
55
|
+
const vcs = vcsParam ?? getVcsPreset('default-v1');
|
|
56
|
+
|
|
117
57
|
const {showLastUpdateAuthor, showLastUpdateTime} = options;
|
|
118
58
|
|
|
119
59
|
if (!showLastUpdateAuthor && !showLastUpdateTime) {
|
|
@@ -128,14 +68,16 @@ export async function readLastUpdateData(
|
|
|
128
68
|
// We try to minimize git last update calls
|
|
129
69
|
// We call it at most once
|
|
130
70
|
// If all the data is provided as front matter, we do not call it
|
|
131
|
-
const getLastUpdateMemoized = _.memoize(() =>
|
|
71
|
+
const getLastUpdateMemoized = _.memoize(() =>
|
|
72
|
+
vcs.getFileLastUpdateInfo(filePath),
|
|
73
|
+
);
|
|
132
74
|
const getLastUpdateBy = () =>
|
|
133
75
|
getLastUpdateMemoized().then((update) => {
|
|
134
76
|
// Important, see https://github.com/facebook/docusaurus/pull/11211
|
|
135
77
|
if (update === null) {
|
|
136
78
|
return null;
|
|
137
79
|
}
|
|
138
|
-
return update?.
|
|
80
|
+
return update?.author;
|
|
139
81
|
});
|
|
140
82
|
const getLastUpdateAt = () =>
|
|
141
83
|
getLastUpdateMemoized().then((update) => {
|
|
@@ -143,7 +85,7 @@ export async function readLastUpdateData(
|
|
|
143
85
|
if (update === null) {
|
|
144
86
|
return null;
|
|
145
87
|
}
|
|
146
|
-
return update?.
|
|
88
|
+
return update?.timestamp;
|
|
147
89
|
});
|
|
148
90
|
|
|
149
91
|
const lastUpdatedBy = showLastUpdateAuthor
|