@docusaurus/plugin-content-docs 0.0.0-4540 → 0.0.0-4542

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/lastUpdate.js CHANGED
@@ -10,6 +10,7 @@ exports.getFileLastUpdate = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const shelljs_1 = (0, tslib_1.__importDefault)(require("shelljs"));
12
12
  const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
13
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
13
14
  const GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX = /^(?<timestamp>\d+),(?<author>.+)$/;
14
15
  let showedGitRequirementError = false;
15
16
  async function getFileLastUpdate(filePath) {
@@ -36,7 +37,13 @@ async function getFileLastUpdate(filePath) {
36
37
  }
37
38
  return null;
38
39
  }
39
- const result = shelljs_1.default.exec(`git log -1 --format=%ct,%an "${filePath}"`, {
40
+ if (!shelljs_1.default.test('-f', filePath)) {
41
+ throw new Error(`Retrieval of git history failed at "${filePath}" because the file does not exist.`);
42
+ }
43
+ const fileBasename = path_1.default.basename(filePath);
44
+ const fileDirname = path_1.default.dirname(filePath);
45
+ const result = shelljs_1.default.exec(`git log --max-count=1 --format=%ct,%an -- "${fileBasename}"`, {
46
+ cwd: fileDirname,
40
47
  silent: true,
41
48
  });
42
49
  if (result.code !== 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-4540",
3
+ "version": "0.0.0-4542",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -23,11 +23,11 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
- "@docusaurus/core": "0.0.0-4540",
27
- "@docusaurus/logger": "0.0.0-4540",
28
- "@docusaurus/mdx-loader": "0.0.0-4540",
29
- "@docusaurus/utils": "0.0.0-4540",
30
- "@docusaurus/utils-validation": "0.0.0-4540",
26
+ "@docusaurus/core": "0.0.0-4542",
27
+ "@docusaurus/logger": "0.0.0-4542",
28
+ "@docusaurus/mdx-loader": "0.0.0-4542",
29
+ "@docusaurus/utils": "0.0.0-4542",
30
+ "@docusaurus/utils-validation": "0.0.0-4542",
31
31
  "combine-promises": "^1.1.0",
32
32
  "fs-extra": "^10.0.0",
33
33
  "import-fresh": "^3.2.2",
@@ -40,8 +40,8 @@
40
40
  "webpack": "^5.68.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@docusaurus/module-type-aliases": "0.0.0-4540",
44
- "@docusaurus/types": "0.0.0-4540",
43
+ "@docusaurus/module-type-aliases": "0.0.0-4542",
44
+ "@docusaurus/types": "0.0.0-4542",
45
45
  "@types/js-yaml": "^4.0.0",
46
46
  "@types/picomatch": "^2.2.1",
47
47
  "commander": "^5.1.0",
@@ -57,5 +57,5 @@
57
57
  "engines": {
58
58
  "node": ">=14"
59
59
  },
60
- "gitHead": "3bb46cc9766cd9a6e87fee3407d038b45eeee93a"
60
+ "gitHead": "681dde74d0f947b69f54858c12e7e8199b856714"
61
61
  }
package/src/lastUpdate.ts CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  import shell from 'shelljs';
9
9
  import logger from '@docusaurus/logger';
10
+ import path from 'path';
10
11
 
11
12
  type FileLastUpdateData = {timestamp?: number; author?: string};
12
13
 
@@ -43,9 +44,21 @@ export async function getFileLastUpdate(
43
44
  return null;
44
45
  }
45
46
 
46
- const result = shell.exec(`git log -1 --format=%ct,%an "${filePath}"`, {
47
- silent: true,
48
- });
47
+ if (!shell.test('-f', filePath)) {
48
+ throw new Error(
49
+ `Retrieval of git history failed at "${filePath}" because the file does not exist.`,
50
+ );
51
+ }
52
+
53
+ const fileBasename = path.basename(filePath);
54
+ const fileDirname = path.dirname(filePath);
55
+ const result = shell.exec(
56
+ `git log --max-count=1 --format=%ct,%an -- "${fileBasename}"`,
57
+ {
58
+ cwd: fileDirname, // this is needed: https://github.com/facebook/docusaurus/pull/5048
59
+ silent: true,
60
+ },
61
+ );
49
62
  if (result.code !== 0) {
50
63
  throw new Error(
51
64
  `Retrieval of git history failed at "${filePath}" with exit code ${result.code}: ${result.stderr}`,