diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts index 56422102c8..edad3bea4f 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts @@ -12,9 +12,8 @@ import { createSlugger, posixPath, DEFAULT_PLUGIN_ID, - LAST_UPDATE_FALLBACK, getLocaleConfig, -} from '@docusaurus/utils'; +VCS_HARDCODED_LAST_UPDATE_INFO} from '@docusaurus/utils'; import {getTagsFile} from '@docusaurus/utils-validation'; import {createSidebarsUtils} from '../sidebars/utils'; import { @@ -529,8 +528,8 @@ describe('simple site', () => { custom_edit_url: 'https://github.com/customUrl/docs/lorem.md', unrelated_front_matter: "won't be part of metadata", }, - lastUpdatedAt: LAST_UPDATE_FALLBACK.lastUpdatedAt, - lastUpdatedBy: LAST_UPDATE_FALLBACK.lastUpdatedBy, + lastUpdatedAt: VCS_HARDCODED_LAST_UPDATE_INFO.timestamp, + lastUpdatedBy: VCS_HARDCODED_LAST_UPDATE_INFO.author, tags: [], unlisted: false, }); @@ -664,7 +663,7 @@ describe('simple site', () => { }, title: 'Last Update Author Only', }, - lastUpdatedAt: LAST_UPDATE_FALLBACK.lastUpdatedAt, + lastUpdatedAt: VCS_HARDCODED_LAST_UPDATE_INFO.timestamp, lastUpdatedBy: 'Custom Author (processed by parseFrontMatter)', sidebarPosition: undefined, tags: [], diff --git a/packages/docusaurus-utils/src/__tests__/lastUpdateUtils.test.ts b/packages/docusaurus-utils/src/__tests__/lastUpdateUtils.test.ts index b913fb7335..8d61ef60cf 100644 --- a/packages/docusaurus-utils/src/__tests__/lastUpdateUtils.test.ts +++ b/packages/docusaurus-utils/src/__tests__/lastUpdateUtils.test.ts @@ -11,13 +11,13 @@ import path from 'path'; import {createTempRepo} from '@testing-utils/git'; import execa from 'execa'; +import {getGitLastUpdate, readLastUpdateData} from '../lastUpdateUtils'; import { - getGitLastUpdate, - LAST_UPDATE_FALLBACK, - LAST_UPDATE_UNTRACKED_GIT_FILEPATH, - readLastUpdateData, -} from '../lastUpdateUtils'; -import {DEFAULT_TEST_VCS_CONFIG} from '../vcs/vcs'; + VcsHardcoded, + VCS_HARDCODED_UNTRACKED_FILE_PATH, + VCS_HARDCODED_LAST_UPDATE_INFO, +} from '../vcs/vcsHardcoded'; + import type {FrontMatterLastUpdate} from '../lastUpdateUtils'; describe('getGitLastUpdate', () => { @@ -139,7 +139,7 @@ describe('readLastUpdateData', () => { filePath, options, lastUpdateFrontMatter, - DEFAULT_TEST_VCS_CONFIG, + VcsHardcoded, ); } @@ -148,7 +148,7 @@ describe('readLastUpdateData', () => { lastUpdateFrontMatter: FrontMatterLastUpdate | undefined, ) { return readData( - LAST_UPDATE_UNTRACKED_GIT_FILEPATH, + VCS_HARDCODED_UNTRACKED_FILE_PATH, {showLastUpdateAuthor: true, showLastUpdateTime: true}, lastUpdateFrontMatter, ); @@ -184,7 +184,7 @@ describe('readLastUpdateData', () => { {date: testDate}, ); expect(lastUpdatedAt).toEqual(testTimestamp); - expect(lastUpdatedBy).toBe(LAST_UPDATE_FALLBACK.lastUpdatedBy); + expect(lastUpdatedBy).toBe(VCS_HARDCODED_LAST_UPDATE_INFO.author); }); it('read last author show author time', async () => { @@ -194,7 +194,7 @@ describe('readLastUpdateData', () => { {author: testAuthor}, ); expect(lastUpdatedBy).toEqual(testAuthor); - expect(lastUpdatedAt).toBe(LAST_UPDATE_FALLBACK.lastUpdatedAt); + expect(lastUpdatedAt).toBe(VCS_HARDCODED_LAST_UPDATE_INFO.timestamp); }); it('read last all show author time', async () => { @@ -231,7 +231,7 @@ describe('readLastUpdateData', () => { {showLastUpdateAuthor: true, showLastUpdateTime: false}, {date: testDate}, ); - expect(lastUpdatedBy).toBe(LAST_UPDATE_FALLBACK.lastUpdatedBy); + expect(lastUpdatedBy).toBe(VCS_HARDCODED_LAST_UPDATE_INFO.author); expect(lastUpdatedAt).toBeUndefined(); }); @@ -251,7 +251,7 @@ describe('readLastUpdateData', () => { {showLastUpdateAuthor: true, showLastUpdateTime: false}, {}, ); - expect(lastUpdatedBy).toBe(LAST_UPDATE_FALLBACK.lastUpdatedBy); + expect(lastUpdatedBy).toBe(VCS_HARDCODED_LAST_UPDATE_INFO.author); expect(lastUpdatedAt).toBeUndefined(); }); @@ -272,7 +272,7 @@ describe('readLastUpdateData', () => { {author: testAuthor}, ); expect(lastUpdatedBy).toBeUndefined(); - expect(lastUpdatedAt).toEqual(LAST_UPDATE_FALLBACK.lastUpdatedAt); + expect(lastUpdatedAt).toEqual(VCS_HARDCODED_LAST_UPDATE_INFO.timestamp); }); it('read last author show time only - both front matter', async () => { diff --git a/packages/docusaurus-utils/src/index.ts b/packages/docusaurus-utils/src/index.ts index 493b6359b5..63da81e33c 100644 --- a/packages/docusaurus-utils/src/index.ts +++ b/packages/docusaurus-utils/src/index.ts @@ -126,7 +126,6 @@ export { getGitLastUpdate, getLastUpdate, readLastUpdateData, - LAST_UPDATE_FALLBACK, type LastUpdateData, type FrontMatterLastUpdate, } from './lastUpdateUtils'; @@ -138,4 +137,7 @@ export { DEFAULT_TEST_VCS_CONFIG, } from './vcs/vcs'; +// Annoying to have to expose that for tests :/ +export {VCS_HARDCODED_LAST_UPDATE_INFO} from './vcs/vcsHardcoded'; + export {normalizeTags, reportInlineTags} from './tags'; diff --git a/packages/docusaurus-utils/src/lastUpdateUtils.ts b/packages/docusaurus-utils/src/lastUpdateUtils.ts index 1409769bed..6d8b6d562e 100644 --- a/packages/docusaurus-utils/src/lastUpdateUtils.ts +++ b/packages/docusaurus-utils/src/lastUpdateUtils.ts @@ -12,8 +12,7 @@ import { GitNotFoundError, getFileCommitDate, } from './vcs/gitUtils'; -import {DEFAULT_VCS_CONFIG} from './vcs/vcs'; -import {VCS_HARDCODED_UNTRACKED_FILE_PATH} from './vcs/vcsHardcoded'; +import {getDefaultVcsConfig} from './vcs/vcs'; import type {PluginOptions, VcsConfig} from '@docusaurus/types'; export type LastUpdateData = { @@ -73,31 +72,9 @@ export async function getGitLastUpdate( } } -// TODO Docusaurus v4: remove this legacy fallback data -// we now have a Vcs API that does the same for dev/test envs -export const LAST_UPDATE_FALLBACK: LastUpdateData = { - lastUpdatedAt: 1539502055000, - lastUpdatedBy: 'Author', -}; - -// TODO Docusaurus v4 -// should be removed in favor of using the hardcoded VSC impl/constant directly -export const LAST_UPDATE_UNTRACKED_GIT_FILEPATH = - VCS_HARDCODED_UNTRACKED_FILE_PATH; - export async function getLastUpdate( filePath: string, ): Promise { - if (filePath === LAST_UPDATE_UNTRACKED_GIT_FILEPATH) { - return null; - } - if ( - process.env.NODE_ENV !== 'production' || - process.env.DOCUSAURUS_DISABLE_LAST_UPDATE === 'true' - ) { - // Use fake data in dev/test for faster development. - return LAST_UPDATE_FALLBACK; - } return getGitLastUpdate(filePath); } @@ -128,7 +105,7 @@ export async function readLastUpdateData( // This also ensures unit tests keep working without extra setup // We still want to ensure type safety by requiring the VCS param // TODO Docusaurus v4: refactor all these Git read APIs - const vcs = vcsParam ?? DEFAULT_VCS_CONFIG; + const vcs = vcsParam ?? getDefaultVcsConfig(); const {showLastUpdateAuthor, showLastUpdateTime} = options;