Skip to content

Commit

Permalink
refactor(content-docs): use shelljs instead of execa
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Nov 8, 2021
1 parent 13d07ef commit f2455ff
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
1 change: 0 additions & 1 deletion packages/docusaurus-plugin-content-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"chalk": "^4.1.2",
"combine-promises": "^1.1.0",
"escape-string-regexp": "^4.0.0",
"execa": "^5.0.0",
"fs-extra": "^10.0.0",
"globby": "^11.0.2",
"import-fresh": "^3.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('lastUpdate', () => {
expect(await getFileLastUpdate(nonExistingFilePath)).toBeNull();
expect(consoleMock).toHaveBeenCalledTimes(1);
expect(consoleMock.mock.calls[0][0].message).toContain(
`Command failed with exit code 128: git log -1 --format=%ct, %an ${nonExistingFileName}`,
`fatal: ambiguous argument '${nonExistingFilePath}': unknown revision or path not in the working tree.`,
);
expect(await getFileLastUpdate(null)).toBeNull();
expect(await getFileLastUpdate(undefined)).toBeNull();
Expand Down
19 changes: 6 additions & 13 deletions packages/docusaurus-plugin-content-docs/src/lastUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
*/

import shell from 'shelljs';
import execa from 'execa';
import path from 'path';

type FileLastUpdateData = {timestamp?: number; author?: string};

const GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX = /^(\d+), (.+)$/;
const GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX = /^(\d+),(.+)$/;

let showedGitRequirementError = false;

Expand Down Expand Up @@ -44,16 +42,11 @@ export async function getFileLastUpdate(
return null;
}

const fileBasename = path.basename(filePath);
const fileDirname = path.dirname(filePath);
const {stdout} = await execa(
'git',
['log', '-1', '--format=%ct, %an', fileBasename],
{
cwd: fileDirname,
},
);
return getTimestampAndAuthor(stdout);
const result = shell.exec(`git log -1 --format=%ct,%an ${filePath}`);
if (result.stderr) {
throw new Error(result.stderr);
}
return getTimestampAndAuthor(result.stdout.trim());
} catch (error) {
console.error(error);
}
Expand Down

0 comments on commit f2455ff

Please sign in to comment.