mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-28 09:47:48 +02:00
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
/**
|
|
* 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 fs from 'fs-extra';
|
|
import {Globby} from '@docusaurus/utils';
|
|
import {Joi} from '@docusaurus/utils-validation';
|
|
|
|
type TsconfigFile = {
|
|
file: string;
|
|
content: {
|
|
extends?: string;
|
|
compilerOptions: {
|
|
[key: string]: unknown;
|
|
};
|
|
};
|
|
};
|
|
|
|
async function getTsconfigFiles(): Promise<TsconfigFile[]> {
|
|
const files = await Globby('packages/*/tsconfig.*');
|
|
return Promise.all(
|
|
files.map((file) =>
|
|
fs
|
|
.readJSON(file)
|
|
.then((content: TsconfigFile['content']) => ({file, content})),
|
|
),
|
|
);
|
|
}
|
|
|
|
const tsconfigSchema = Joi.object({
|
|
extends: Joi.valid(
|
|
'../../tsconfig.base.json',
|
|
'../../tsconfig.base.client.json',
|
|
),
|
|
}).unknown();
|
|
|
|
describe('tsconfig files', () => {
|
|
it('contain all required fields', async () => {
|
|
const tsconfigFiles = await getTsconfigFiles();
|
|
|
|
tsconfigFiles
|
|
// Ignore noEmit configs
|
|
.forEach((file) => {
|
|
try {
|
|
Joi.attempt(file.content, tsconfigSchema);
|
|
} catch (e) {
|
|
(
|
|
e as Error
|
|
).message += `\n${file.file} does not match the required schema.`;
|
|
throw e;
|
|
}
|
|
});
|
|
});
|
|
});
|