From 532d3f503da77fcce6809faf4aa6d0941a869e6f Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Thu, 3 Feb 2022 01:43:54 -0300 Subject: [PATCH 1/5] feat: infer blog post date from git history --- .../package.json | 1 + .../src/__tests__/index.test.ts | 6 +-- .../src/blogUtils.ts | 50 ++++++++++++++++++- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/package.json b/packages/docusaurus-plugin-content-blog/package.json index b07685162b30..f41b400aafa7 100644 --- a/packages/docusaurus-plugin-content-blog/package.json +++ b/packages/docusaurus-plugin-content-blog/package.json @@ -30,6 +30,7 @@ "lodash": "^4.17.20", "reading-time": "^1.5.0", "remark-admonitions": "^1.2.1", + "shelljs": "^0.8.4", "tslib": "^2.3.1", "utility-types": "^3.10.0", "webpack": "^5.68.0" diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts index 5e5217a9a304..091f9d23a4bd 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts @@ -5,7 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -import fs from 'fs-extra'; import path from 'path'; import pluginContentBlog from '../index'; import type {DocusaurusConfig, LoadContext, I18n} from '@docusaurus/types'; @@ -425,9 +424,8 @@ describe('loadBlog', () => { ); const blogPosts = await getBlogPosts(siteDir); const noDateSource = path.posix.join('@site', PluginPath, 'no date.md'); - const noDateSourceBirthTime = ( - await fs.stat(noDateSource.replace('@site', siteDir)) - ).birthtime; + // the file creation date in git + const noDateSourceBirthTime = new Date('2019-07-27T11:03:14.000Z'); const formattedDate = Intl.DateTimeFormat('en', { day: 'numeric', month: 'long', diff --git a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index 254fb12cd943..b6bbb5b683ef 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -8,6 +8,7 @@ import fs from 'fs-extra'; import path from 'path'; import readingTime from 'reading-time'; +import shell from 'shelljs'; import {keyBy, mapValues} from 'lodash'; import type { BlogPost, @@ -38,6 +39,8 @@ import type { ReadingTimeFunction, } from '@docusaurus/plugin-content-blog'; +const GIT_COMMIT_TIMESTAMP_REGEX = /^(?\d+)$/; + export function truncate(fileString: string, truncateMarker: RegExp): string { return fileString.split(truncateMarker, 1).shift()!; } @@ -230,6 +233,14 @@ async function processBlogSourceFile( const parsedBlogFileName = parseBlogFileName(blogSourceRelative); + function getDateFromGitTimestamp(str: string): Date { + const timestamp = str.match(GIT_COMMIT_TIMESTAMP_REGEX)?.groups?.timestamp; + if (!timestamp) { + throw new Error(`Invalid timestamp from git log: ${str}`); + } + return new Date(Number(timestamp) * 1000); + } + async function getDate(): Promise { // Prefer user-defined date. if (frontMatter.date) { @@ -242,7 +253,44 @@ async function processBlogSourceFile( } else if (parsedBlogFileName.date) { return parsedBlogFileName.date; } - // Fallback to file create time + + if (!shell.test('-f', blogSourceAbsolute)) { + throw new Error( + `Retrieval of date failed at "${blogSourceAbsolute}" because the file does not exist.`, + ); + } + + // Fallback to the first commit date of the file + try { + if (!shell.which('git')) { + throw new Error( + 'Git is required for the blog plugin to better infer the original post date.', + ); + } + + const fileBasename = path.basename(blogSourceAbsolute); + const fileDirname = path.dirname(blogSourceAbsolute); + // --follow is necessary to follow file renames + // --diff-filter=A ensures we only get the commit which (A)dded the file + const result = shell.exec( + `git log --follow --max-count=1 --diff-filter=A --format=%ct -- "${fileBasename}"`, + { + cwd: fileDirname, // this is needed: https://github.com/facebook/docusaurus/pull/5048 + silent: true, + }, + ); + if (result.code !== 0) { + throw new Error( + `Retrieval of git history failed at "${blogSourceAbsolute}" with exit code ${result.code}: ${result.stderr}`, + ); + } + return getDateFromGitTimestamp(result.stdout.trim()); + } catch (e) { + logger.error(e); + logger.warn( + 'Unable to infer original post date from git. Falling back to file creation time.', + ); + } return (await fs.stat(blogSourceAbsolute)).birthtime; } From 6cbb002ad2f4137ec54573ab1702e85bc378b4d1 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Thu, 3 Feb 2022 02:24:25 -0300 Subject: [PATCH 2/5] test: fix no date test --- .../src/__tests__/index.test.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts index 091f9d23a4bd..30cbf79fc43f 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts @@ -6,6 +6,7 @@ */ import path from 'path'; +import shell from 'shelljs'; import pluginContentBlog from '../index'; import type {DocusaurusConfig, LoadContext, I18n} from '@docusaurus/types'; import {PluginOptionSchema} from '../pluginOptionSchema'; @@ -424,13 +425,17 @@ describe('loadBlog', () => { ); const blogPosts = await getBlogPosts(siteDir); const noDateSource = path.posix.join('@site', PluginPath, 'no date.md'); - // the file creation date in git - const noDateSourceBirthTime = new Date('2019-07-27T11:03:14.000Z'); + const noDateSourceFile = path.posix.join(siteDir, PluginPath, 'no date.md'); + // we know the file exist and we know we have git + const result = shell.exec( + `git log --follow --max-count=1 --diff-filter=A --format=%ct -- "${noDateSourceFile}"`, + ); + const noDateSourceTime = new Date(Number(result.stdout.trim()) * 1000); const formattedDate = Intl.DateTimeFormat('en', { day: 'numeric', month: 'long', year: 'numeric', - }).format(noDateSourceBirthTime); + }).format(noDateSourceTime); expect({ ...getByTitle(blogPosts, 'no date').metadata, @@ -443,7 +448,7 @@ describe('loadBlog', () => { title: 'no date', description: `no date`, authors: [], - date: noDateSourceBirthTime, + date: noDateSourceTime, formattedDate, frontMatter: {}, tags: [], From fa39f5dba507a609f2603747f61d8ab8c166f5c9 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Fri, 4 Feb 2022 00:30:09 -0300 Subject: [PATCH 3/5] refactor: move common logic to gitUtils --- .../package.json | 1 - .../src/blogUtils.ts | 54 ++---------- .../package.json | 1 - .../src/lastUpdate.ts | 56 ++----------- packages/docusaurus-utils/package.json | 1 + packages/docusaurus-utils/src/gitUtils.ts | 83 +++++++++++++++++++ packages/docusaurus-utils/src/index.ts | 1 + 7 files changed, 102 insertions(+), 95 deletions(-) create mode 100644 packages/docusaurus-utils/src/gitUtils.ts diff --git a/packages/docusaurus-plugin-content-blog/package.json b/packages/docusaurus-plugin-content-blog/package.json index f41b400aafa7..b07685162b30 100644 --- a/packages/docusaurus-plugin-content-blog/package.json +++ b/packages/docusaurus-plugin-content-blog/package.json @@ -30,7 +30,6 @@ "lodash": "^4.17.20", "reading-time": "^1.5.0", "remark-admonitions": "^1.2.1", - "shelljs": "^0.8.4", "tslib": "^2.3.1", "utility-types": "^3.10.0", "webpack": "^5.68.0" diff --git a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index b6bbb5b683ef..7738224e86b4 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -8,7 +8,6 @@ import fs from 'fs-extra'; import path from 'path'; import readingTime from 'reading-time'; -import shell from 'shelljs'; import {keyBy, mapValues} from 'lodash'; import type { BlogPost, @@ -28,6 +27,7 @@ import { Globby, normalizeFrontMatterTags, groupTaggedItems, + getCommitterDateForFile, getContentPathList, } from '@docusaurus/utils'; import type {LoadContext} from '@docusaurus/types'; @@ -39,8 +39,6 @@ import type { ReadingTimeFunction, } from '@docusaurus/plugin-content-blog'; -const GIT_COMMIT_TIMESTAMP_REGEX = /^(?\d+)$/; - export function truncate(fileString: string, truncateMarker: RegExp): string { return fileString.split(truncateMarker, 1).shift()!; } @@ -233,14 +231,6 @@ async function processBlogSourceFile( const parsedBlogFileName = parseBlogFileName(blogSourceRelative); - function getDateFromGitTimestamp(str: string): Date { - const timestamp = str.match(GIT_COMMIT_TIMESTAMP_REGEX)?.groups?.timestamp; - if (!timestamp) { - throw new Error(`Invalid timestamp from git log: ${str}`); - } - return new Date(Number(timestamp) * 1000); - } - async function getDate(): Promise { // Prefer user-defined date. if (frontMatter.date) { @@ -254,44 +244,18 @@ async function processBlogSourceFile( return parsedBlogFileName.date; } - if (!shell.test('-f', blogSourceAbsolute)) { - throw new Error( - `Retrieval of date failed at "${blogSourceAbsolute}" because the file does not exist.`, - ); - } - - // Fallback to the first commit date of the file + let result; try { - if (!shell.which('git')) { - throw new Error( - 'Git is required for the blog plugin to better infer the original post date.', - ); - } - - const fileBasename = path.basename(blogSourceAbsolute); - const fileDirname = path.dirname(blogSourceAbsolute); - // --follow is necessary to follow file renames - // --diff-filter=A ensures we only get the commit which (A)dded the file - const result = shell.exec( - `git log --follow --max-count=1 --diff-filter=A --format=%ct -- "${fileBasename}"`, - { - cwd: fileDirname, // this is needed: https://github.com/facebook/docusaurus/pull/5048 - silent: true, - }, - ); - if (result.code !== 0) { - throw new Error( - `Retrieval of git history failed at "${blogSourceAbsolute}" with exit code ${result.code}: ${result.stderr}`, - ); - } - return getDateFromGitTimestamp(result.stdout.trim()); + result = getCommitterDateForFile(blogSourceAbsolute, { + age: 'oldest', + includeAuthor: false, + }); } catch (e) { logger.error(e); - logger.warn( - 'Unable to infer original post date from git. Falling back to file creation time.', - ); + return (await fs.stat(blogSourceAbsolute)).birthtime; } - return (await fs.stat(blogSourceAbsolute)).birthtime; + + return result.date; } const date = await getDate(); diff --git a/packages/docusaurus-plugin-content-docs/package.json b/packages/docusaurus-plugin-content-docs/package.json index 54916f75b606..0e19912a12a2 100644 --- a/packages/docusaurus-plugin-content-docs/package.json +++ b/packages/docusaurus-plugin-content-docs/package.json @@ -34,7 +34,6 @@ "js-yaml": "^4.0.0", "lodash": "^4.17.20", "remark-admonitions": "^1.2.1", - "shelljs": "^0.8.4", "tslib": "^2.3.1", "utility-types": "^3.10.0", "webpack": "^5.68.0" diff --git a/packages/docusaurus-plugin-content-docs/src/lastUpdate.ts b/packages/docusaurus-plugin-content-docs/src/lastUpdate.ts index 9fdf2ecba7ed..e6ebf3c33412 100644 --- a/packages/docusaurus-plugin-content-docs/src/lastUpdate.ts +++ b/packages/docusaurus-plugin-content-docs/src/lastUpdate.ts @@ -5,69 +5,29 @@ * LICENSE file in the root directory of this source tree. */ -import shell from 'shelljs'; import logger from '@docusaurus/logger'; -import path from 'path'; +import {getCommitterDateForFile} from '@docusaurus/utils'; type FileLastUpdateData = {timestamp?: number; author?: string}; -const GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX = /^(?\d+),(?.+)$/; - -let showedGitRequirementError = false; - export async function getFileLastUpdate( filePath?: string, ): Promise { if (!filePath) { return null; } - function getTimestampAndAuthor(str: string): FileLastUpdateData | null { - if (!str) { - return null; - } - - const temp = str.match(GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX)?.groups; - return temp - ? {timestamp: Number(temp.timestamp), author: temp.author} - : null; - } // Wrap in try/catch in case the shell commands fail // (e.g. project doesn't use Git, etc). + let result; try { - if (!shell.which('git')) { - if (!showedGitRequirementError) { - showedGitRequirementError = true; - logger.warn('Sorry, the docs plugin last update options require Git.'); - } - - return null; - } - - if (!shell.test('-f', filePath)) { - throw new Error( - `Retrieval of git history failed at "${filePath}" because the file does not exist.`, - ); - } - - const fileBasename = path.basename(filePath); - const fileDirname = path.dirname(filePath); - const result = shell.exec( - `git log --max-count=1 --format=%ct,%an -- "${fileBasename}"`, - { - cwd: fileDirname, // this is needed: https://github.com/facebook/docusaurus/pull/5048 - silent: true, - }, - ); - if (result.code !== 0) { - throw new Error( - `Retrieval of git history failed at "${filePath}" with exit code ${result.code}: ${result.stderr}`, - ); - } - return getTimestampAndAuthor(result.stdout.trim()); + result = getCommitterDateForFile(filePath, { + age: 'newest', + includeAuthor: true, + }); } catch (e) { logger.error(e); + return null; } - - return null; + return {timestamp: result.timestamp, author: result.author}; } diff --git a/packages/docusaurus-utils/package.json b/packages/docusaurus-utils/package.json index 03cde25ee7dc..ee205b29c2c5 100644 --- a/packages/docusaurus-utils/package.json +++ b/packages/docusaurus-utils/package.json @@ -32,6 +32,7 @@ "remark-mdx-remove-exports": "^1.6.22", "remark-mdx-remove-imports": "^1.6.22", "resolve-pathname": "^3.0.0", + "shelljs": "^0.8.4", "tslib": "^2.3.1", "url-loader": "^4.1.1" }, diff --git a/packages/docusaurus-utils/src/gitUtils.ts b/packages/docusaurus-utils/src/gitUtils.ts new file mode 100644 index 000000000000..073ad29a1460 --- /dev/null +++ b/packages/docusaurus-utils/src/gitUtils.ts @@ -0,0 +1,83 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +import path from 'path'; +import shell from 'shelljs'; + +export const getCommitterDateForFile = ( + file: string, + options: { + age: 'oldest' | 'newest'; + includeAuthor: boolean; + } = {age: 'oldest', includeAuthor: false}, +): {date: Date; timestamp: number; author?: string} => { + if (!shell.which('git')) { + throw new Error( + `Failed to retrieve git history for "${file}" because git is not installed.`, + ); + } + + if (!shell.test('-f', file)) { + throw new Error( + `Failed to retrieve git history for "${file}" because the file does not exist.`, + ); + } + + const fileBasename = path.basename(file); + const fileDirname = path.dirname(file); + + let formatArg = '--format=%ct'; + if (options.includeAuthor) { + formatArg += ',%an'; + } + + let extraArgs = '--max-count=1'; + if (options.age === 'oldest') { + // --follow is necessary to follow file renames + // --diff-filter=A ensures we only get the commit which (A)dded the file + extraArgs += ' --follow --diff-filter=A'; + } + + const result = shell.exec( + `git log ${extraArgs} ${formatArg} -- "${fileBasename}"`, + { + // cwd is important, see: https://github.com/facebook/docusaurus/pull/5048 + cwd: fileDirname, + silent: true, + }, + ); + if (result.code !== 0) { + throw new Error( + `Failed to retrieve the git history for file "${file}" with exit code ${result.code}: ${result.stderr}`, + ); + } + let regex = /^(?\d+)$/; + if (options.includeAuthor) { + regex = /^(?\d+),(?.+)$/; + } + + const output = result.stdout.trim(); + const match = output.match(regex); + + if ( + !match || + !match.groups || + !match.groups.timestamp || + (options.includeAuthor && !match.groups.author) + ) { + throw new Error( + `Failed to retrieve the git history for file "${file}" with unexpected output: ${output}`, + ); + } + + const timestamp = Number(match.groups.timestamp); + const date = new Date(timestamp * 1000); + + if (options.includeAuthor) { + return {date, timestamp, author: match.groups.author}; + } + return {date, timestamp}; +}; diff --git a/packages/docusaurus-utils/src/index.ts b/packages/docusaurus-utils/src/index.ts index 4aed2648b250..52ebdafbac8d 100644 --- a/packages/docusaurus-utils/src/index.ts +++ b/packages/docusaurus-utils/src/index.ts @@ -30,6 +30,7 @@ export * from './markdownLinks'; export * from './slugger'; export * from './pathUtils'; export * from './hashUtils'; +export * from './gitUtils'; export * from './globUtils'; export * from './webpackUtils'; export * from './dataFileUtils'; From 65658257d14a06a70f0a348965165bd53eed0457 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Mon, 7 Feb 2022 00:08:31 -0300 Subject: [PATCH 4/5] Address comments and improve a few things --- .../src/__tests__/index.test.ts | 9 ++--- .../src/blogUtils.ts | 8 ++--- .../src/lastUpdate.ts | 16 ++++++--- packages/docusaurus-utils/src/gitUtils.ts | 33 ++++++++++++------- 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts index 30cbf79fc43f..200bb84432f8 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/index.test.ts @@ -6,13 +6,12 @@ */ import path from 'path'; -import shell from 'shelljs'; import pluginContentBlog from '../index'; import type {DocusaurusConfig, LoadContext, I18n} from '@docusaurus/types'; import {PluginOptionSchema} from '../pluginOptionSchema'; import type {BlogPost} from '../types'; import type {Joi} from '@docusaurus/utils-validation'; -import {posixPath} from '@docusaurus/utils'; +import {posixPath, getFileCommitDate} from '@docusaurus/utils'; import type { PluginOptions, EditUrlFunction, @@ -427,10 +426,8 @@ describe('loadBlog', () => { const noDateSource = path.posix.join('@site', PluginPath, 'no date.md'); const noDateSourceFile = path.posix.join(siteDir, PluginPath, 'no date.md'); // we know the file exist and we know we have git - const result = shell.exec( - `git log --follow --max-count=1 --diff-filter=A --format=%ct -- "${noDateSourceFile}"`, - ); - const noDateSourceTime = new Date(Number(result.stdout.trim()) * 1000); + const result = getFileCommitDate(noDateSourceFile, {age: 'oldest'}); + const noDateSourceTime = result.date; const formattedDate = Intl.DateTimeFormat('en', { day: 'numeric', month: 'long', diff --git a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts index 7738224e86b4..9c082b3e4443 100644 --- a/packages/docusaurus-plugin-content-blog/src/blogUtils.ts +++ b/packages/docusaurus-plugin-content-blog/src/blogUtils.ts @@ -27,7 +27,7 @@ import { Globby, normalizeFrontMatterTags, groupTaggedItems, - getCommitterDateForFile, + getFileCommitDate, getContentPathList, } from '@docusaurus/utils'; import type {LoadContext} from '@docusaurus/types'; @@ -244,18 +244,16 @@ async function processBlogSourceFile( return parsedBlogFileName.date; } - let result; try { - result = getCommitterDateForFile(blogSourceAbsolute, { + const result = getFileCommitDate(blogSourceAbsolute, { age: 'oldest', includeAuthor: false, }); + return result.date; } catch (e) { logger.error(e); return (await fs.stat(blogSourceAbsolute)).birthtime; } - - return result.date; } const date = await getDate(); diff --git a/packages/docusaurus-plugin-content-docs/src/lastUpdate.ts b/packages/docusaurus-plugin-content-docs/src/lastUpdate.ts index e6ebf3c33412..9114bb3d9ec7 100644 --- a/packages/docusaurus-plugin-content-docs/src/lastUpdate.ts +++ b/packages/docusaurus-plugin-content-docs/src/lastUpdate.ts @@ -6,10 +6,12 @@ */ import logger from '@docusaurus/logger'; -import {getCommitterDateForFile} from '@docusaurus/utils'; +import {getFileCommitDate, GitNotFoundError} from '@docusaurus/utils'; type FileLastUpdateData = {timestamp?: number; author?: string}; +let showedGitRequirementError = false; + export async function getFileLastUpdate( filePath?: string, ): Promise { @@ -19,15 +21,19 @@ export async function getFileLastUpdate( // Wrap in try/catch in case the shell commands fail // (e.g. project doesn't use Git, etc). - let result; try { - result = getCommitterDateForFile(filePath, { + const result = getFileCommitDate(filePath, { age: 'newest', includeAuthor: true, }); + return {timestamp: result.timestamp, author: result.author}; } catch (e) { - logger.error(e); + if (e instanceof GitNotFoundError && !showedGitRequirementError) { + logger.warn('Sorry, the docs plugin last update options require Git.'); + showedGitRequirementError = true; + } else { + logger.error(e); + } return null; } - return {timestamp: result.timestamp, author: result.author}; } diff --git a/packages/docusaurus-utils/src/gitUtils.ts b/packages/docusaurus-utils/src/gitUtils.ts index 073ad29a1460..0d368972fc56 100644 --- a/packages/docusaurus-utils/src/gitUtils.ts +++ b/packages/docusaurus-utils/src/gitUtils.ts @@ -7,15 +7,24 @@ import path from 'path'; import shell from 'shelljs'; -export const getCommitterDateForFile = ( +export class GitNotFoundError extends Error {} + +export const getFileCommitDate = ( file: string, - options: { - age: 'oldest' | 'newest'; - includeAuthor: boolean; - } = {age: 'oldest', includeAuthor: false}, -): {date: Date; timestamp: number; author?: string} => { + { + age = 'oldest', + includeAuthor = false, + }: { + age?: 'oldest' | 'newest'; + includeAuthor?: boolean; + }, +): { + date: Date; + timestamp: number; + author?: string; +} => { if (!shell.which('git')) { - throw new Error( + throw new GitNotFoundError( `Failed to retrieve git history for "${file}" because git is not installed.`, ); } @@ -30,12 +39,12 @@ export const getCommitterDateForFile = ( const fileDirname = path.dirname(file); let formatArg = '--format=%ct'; - if (options.includeAuthor) { + if (includeAuthor) { formatArg += ',%an'; } let extraArgs = '--max-count=1'; - if (options.age === 'oldest') { + if (age === 'oldest') { // --follow is necessary to follow file renames // --diff-filter=A ensures we only get the commit which (A)dded the file extraArgs += ' --follow --diff-filter=A'; @@ -55,7 +64,7 @@ export const getCommitterDateForFile = ( ); } let regex = /^(?\d+)$/; - if (options.includeAuthor) { + if (includeAuthor) { regex = /^(?\d+),(?.+)$/; } @@ -66,7 +75,7 @@ export const getCommitterDateForFile = ( !match || !match.groups || !match.groups.timestamp || - (options.includeAuthor && !match.groups.author) + (includeAuthor && !match.groups.author) ) { throw new Error( `Failed to retrieve the git history for file "${file}" with unexpected output: ${output}`, @@ -76,7 +85,7 @@ export const getCommitterDateForFile = ( const timestamp = Number(match.groups.timestamp); const date = new Date(timestamp * 1000); - if (options.includeAuthor) { + if (includeAuthor) { return {date, timestamp, author: match.groups.author}; } return {date, timestamp}; From eff155af7a14f11dc4b6db8cfd65fc59b58d84f8 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Mon, 7 Feb 2022 00:20:27 -0300 Subject: [PATCH 5/5] Add shelljs to dev-deps of docs Because it's only used in tests. --- packages/docusaurus-plugin-content-docs/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/docusaurus-plugin-content-docs/package.json b/packages/docusaurus-plugin-content-docs/package.json index f52b63f79ae8..305ae16ff5f5 100644 --- a/packages/docusaurus-plugin-content-docs/package.json +++ b/packages/docusaurus-plugin-content-docs/package.json @@ -46,6 +46,7 @@ "commander": "^5.1.0", "escape-string-regexp": "^4.0.0", "picomatch": "^2.1.1", + "shelljs": "^0.8.4", "utility-types": "^3.10.0" }, "peerDependencies": {