mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 16:47:26 +02:00
fix(content-docs): warn when files are not tracked (#6937)
* fix(docs): warn when files are not tracked * chore(devcontainer): use non-root user * test: fix jest in vscode * test(docs): improve existing test * chore(devcontainer): fix jest error on startup * chore: fix comments * chore: remove "probably" from error message
This commit is contained in:
parent
e8a2f66a0f
commit
e19a4e23e7
10 changed files with 77 additions and 13 deletions
|
@ -1,10 +1,33 @@
|
||||||
{
|
{
|
||||||
"name": "Docusaurus Dev Container",
|
"image": "mcr.microsoft.com/vscode/devcontainers/base:ubuntu-20.04",
|
||||||
"image": "mcr.microsoft.com/vscode/devcontainers/typescript-node:14-buster",
|
|
||||||
"settings": {
|
"settings": {
|
||||||
"terminal.integrated.shell.linux": "/bin/bash"
|
"[typescript]": {
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
"editor.formatOnSave": true
|
||||||
},
|
},
|
||||||
"extensions": ["dbaeumer.vscode-eslint", "orta.vscode-jest"],
|
"[json]": {
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
},
|
||||||
|
"[jsonc]": {
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extensions": [
|
||||||
|
"dbaeumer.vscode-eslint",
|
||||||
|
"orta.vscode-jest",
|
||||||
|
"esbenp.prettier-vscode",
|
||||||
|
"streetsidesoftware.code-spell-checker"
|
||||||
|
],
|
||||||
"forwardPorts": [3000],
|
"forwardPorts": [3000],
|
||||||
"postCreateCommand": "yarn install"
|
"containerUser": "vscode",
|
||||||
|
"postCreateCommand": "yarn install",
|
||||||
|
"waitFor": "postCreateCommand", // otherwise automated jest tests fail
|
||||||
|
"features": {
|
||||||
|
"node": {
|
||||||
|
"version": "14"
|
||||||
|
},
|
||||||
|
"github-cli": "latest"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ module.exports = {
|
||||||
curly: [WARNING, 'all'],
|
curly: [WARNING, 'all'],
|
||||||
'global-require': WARNING,
|
'global-require': WARNING,
|
||||||
'lines-between-class-members': OFF,
|
'lines-between-class-members': OFF,
|
||||||
|
'max-classes-per-file': OFF,
|
||||||
'max-len': [
|
'max-len': [
|
||||||
WARNING,
|
WARNING,
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
import {fileURLToPath} from 'url';
|
import {fileURLToPath} from 'url';
|
||||||
|
|
||||||
|
process.env.TZ = 'UTC';
|
||||||
|
|
||||||
const ignorePatterns = [
|
const ignorePatterns = [
|
||||||
'/node_modules/',
|
'/node_modules/',
|
||||||
'__fixtures__',
|
'__fixtures__',
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
"lint:spelling": "cspell \"**\" --no-progress",
|
"lint:spelling": "cspell \"**\" --no-progress",
|
||||||
"lint:style": "stylelint \"**/*.css\"",
|
"lint:style": "stylelint \"**/*.css\"",
|
||||||
"lerna": "lerna",
|
"lerna": "lerna",
|
||||||
"test": "cross-env TZ=UTC jest",
|
"test": "jest",
|
||||||
"test:build:website": "./admin/scripts/test-release.sh",
|
"test:build:website": "./admin/scripts/test-release.sh",
|
||||||
"watch": "yarn lerna run --parallel watch",
|
"watch": "yarn lerna run --parallel watch",
|
||||||
"clear": "(yarn workspace website clear || echo 'Failure while running docusaurus clear') && yarn lerna exec --ignore docusaurus yarn rimraf lib lib-next",
|
"clear": "(yarn workspace website clear || echo 'Failure while running docusaurus clear') && yarn lerna exec --ignore docusaurus yarn rimraf lib lib-next",
|
||||||
|
|
|
@ -247,7 +247,7 @@ async function processBlogSourceFile(
|
||||||
});
|
});
|
||||||
return result.date;
|
return result.date;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err);
|
logger.warn(err);
|
||||||
return (await fs.stat(blogSourceAbsolute)).birthtime;
|
return (await fs.stat(blogSourceAbsolute)).birthtime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ describe('getFileLastUpdate', () => {
|
||||||
|
|
||||||
it('non-existing file', async () => {
|
it('non-existing file', async () => {
|
||||||
const consoleMock = jest
|
const consoleMock = jest
|
||||||
.spyOn(console, 'error')
|
.spyOn(console, 'warn')
|
||||||
.mockImplementation(() => {});
|
.mockImplementation(() => {});
|
||||||
const nonExistingFileName = '.nonExisting';
|
const nonExistingFileName = '.nonExisting';
|
||||||
const nonExistingFilePath = path.join(
|
const nonExistingFilePath = path.join(
|
||||||
|
@ -65,10 +65,17 @@ describe('getFileLastUpdate', () => {
|
||||||
consoleMock.mockRestore();
|
consoleMock.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('temporary created file that has no git timestamp', async () => {
|
it('temporary created file that is not tracked by git', async () => {
|
||||||
|
const consoleMock = jest
|
||||||
|
.spyOn(console, 'warn')
|
||||||
|
.mockImplementation(() => {});
|
||||||
const tempFilePath = path.join(__dirname, '__fixtures__', '.temp');
|
const tempFilePath = path.join(__dirname, '__fixtures__', '.temp');
|
||||||
await fs.writeFile(tempFilePath, 'Lorem ipsum :)');
|
await fs.writeFile(tempFilePath, 'Lorem ipsum :)');
|
||||||
await expect(getFileLastUpdate(tempFilePath)).resolves.toBeNull();
|
await expect(getFileLastUpdate(tempFilePath)).resolves.toBeNull();
|
||||||
|
expect(consoleMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(consoleMock).toHaveBeenLastCalledWith(
|
||||||
|
expect.stringMatching(/not tracked by git./),
|
||||||
|
);
|
||||||
await fs.unlink(tempFilePath);
|
await fs.unlink(tempFilePath);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,16 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import logger from '@docusaurus/logger';
|
import logger from '@docusaurus/logger';
|
||||||
import {getFileCommitDate, GitNotFoundError} from '@docusaurus/utils';
|
import {
|
||||||
|
getFileCommitDate,
|
||||||
|
FileNotTrackedError,
|
||||||
|
GitNotFoundError,
|
||||||
|
} from '@docusaurus/utils';
|
||||||
|
|
||||||
type FileLastUpdateData = {timestamp?: number; author?: string};
|
type FileLastUpdateData = {timestamp?: number; author?: string};
|
||||||
|
|
||||||
let showedGitRequirementError = false;
|
let showedGitRequirementError = false;
|
||||||
|
let showedFileNotTrackedError = false;
|
||||||
|
|
||||||
export async function getFileLastUpdate(
|
export async function getFileLastUpdate(
|
||||||
filePath?: string,
|
filePath?: string,
|
||||||
|
@ -31,8 +36,16 @@ export async function getFileLastUpdate(
|
||||||
if (err instanceof GitNotFoundError && !showedGitRequirementError) {
|
if (err instanceof GitNotFoundError && !showedGitRequirementError) {
|
||||||
logger.warn('Sorry, the docs plugin last update options require Git.');
|
logger.warn('Sorry, the docs plugin last update options require Git.');
|
||||||
showedGitRequirementError = true;
|
showedGitRequirementError = true;
|
||||||
|
} else if (
|
||||||
|
err instanceof FileNotTrackedError &&
|
||||||
|
!showedFileNotTrackedError
|
||||||
|
) {
|
||||||
|
logger.warn(
|
||||||
|
'Cannot infer the update date for some files, as they are not tracked by git.',
|
||||||
|
);
|
||||||
|
showedFileNotTrackedError = true;
|
||||||
} else {
|
} else {
|
||||||
logger.error(err);
|
logger.warn(err);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ import shell from 'shelljs';
|
||||||
|
|
||||||
export class GitNotFoundError extends Error {}
|
export class GitNotFoundError extends Error {}
|
||||||
|
|
||||||
|
export class FileNotTrackedError extends Error {}
|
||||||
|
|
||||||
export const getFileCommitDate = (
|
export const getFileCommitDate = (
|
||||||
file: string,
|
file: string,
|
||||||
{
|
{
|
||||||
|
@ -70,6 +72,13 @@ export const getFileCommitDate = (
|
||||||
}
|
}
|
||||||
|
|
||||||
const output = result.stdout.trim();
|
const output = result.stdout.trim();
|
||||||
|
|
||||||
|
if (!output) {
|
||||||
|
throw new FileNotTrackedError(
|
||||||
|
`Failed to retrieve the git history for file "${file}" because the file is not tracked by git.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const match = output.match(regex);
|
const match = output.match(regex);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -21,7 +21,11 @@ export {
|
||||||
WEBPACK_URL_LOADER_LIMIT,
|
WEBPACK_URL_LOADER_LIMIT,
|
||||||
} from './constants';
|
} from './constants';
|
||||||
export {generate, genChunkName, readOutputHTMLFile} from './emitUtils';
|
export {generate, genChunkName, readOutputHTMLFile} from './emitUtils';
|
||||||
export {getFileCommitDate, GitNotFoundError} from './gitUtils';
|
export {
|
||||||
|
getFileCommitDate,
|
||||||
|
FileNotTrackedError,
|
||||||
|
GitNotFoundError,
|
||||||
|
} from './gitUtils';
|
||||||
export {
|
export {
|
||||||
mergeTranslations,
|
mergeTranslations,
|
||||||
updateTranslationFileMessages,
|
updateTranslationFileMessages,
|
||||||
|
|
|
@ -53,11 +53,13 @@ customizability
|
||||||
daishi
|
daishi
|
||||||
datagit
|
datagit
|
||||||
datas
|
datas
|
||||||
|
dbaeumer
|
||||||
décembre
|
décembre
|
||||||
dedup
|
dedup
|
||||||
deduplicated
|
deduplicated
|
||||||
déja
|
déja
|
||||||
deps
|
deps
|
||||||
|
devcontainers
|
||||||
devspace
|
devspace
|
||||||
devto
|
devto
|
||||||
dmitry
|
dmitry
|
||||||
|
@ -78,6 +80,7 @@ endilie
|
||||||
endiliey
|
endiliey
|
||||||
entrypoints
|
entrypoints
|
||||||
errnametoolong
|
errnametoolong
|
||||||
|
esbenp
|
||||||
esbuild
|
esbuild
|
||||||
eslintcache
|
eslintcache
|
||||||
evaluable
|
evaluable
|
||||||
|
@ -98,8 +101,8 @@ globby
|
||||||
goss
|
goss
|
||||||
goyal
|
goyal
|
||||||
gtag
|
gtag
|
||||||
hardcoding
|
|
||||||
hahaha
|
hahaha
|
||||||
|
hardcoding
|
||||||
héctor
|
héctor
|
||||||
héllô
|
héllô
|
||||||
heuristical
|
heuristical
|
||||||
|
@ -184,6 +187,7 @@ opensearch
|
||||||
opensearchdescription
|
opensearchdescription
|
||||||
optimizt
|
optimizt
|
||||||
optind
|
optind
|
||||||
|
orta
|
||||||
overrideable
|
overrideable
|
||||||
pageview
|
pageview
|
||||||
palenight
|
palenight
|
||||||
|
@ -296,6 +300,7 @@ typesense
|
||||||
unflat
|
unflat
|
||||||
unist
|
unist
|
||||||
unlocalized
|
unlocalized
|
||||||
|
unmatch
|
||||||
unnormalized
|
unnormalized
|
||||||
unoptimized
|
unoptimized
|
||||||
unprefixed
|
unprefixed
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue