Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(content-docs): use shelljs instead of execa #5904

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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