feat(core): support TypeScript + ESM configuration (#9317)

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
Chongyi Zheng 2023-10-13 20:46:03 -04:00 committed by GitHub
parent 336a44f3ea
commit 45f1a669b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
126 changed files with 2054 additions and 914 deletions

View file

@ -9,10 +9,9 @@ import fs from 'fs-extra';
import path from 'path';
import _ from 'lodash';
import logger from '@docusaurus/logger';
import {Globby} from '@docusaurus/utils';
import {loadFreshModule, Globby} from '@docusaurus/utils';
import Yaml from 'js-yaml';
import combinePromises from 'combine-promises';
import importFresh from 'import-fresh';
import {validateSidebars, validateCategoryMetadataFile} from './validation';
import {normalizeSidebars} from './normalization';
import {processSidebars} from './processor';
@ -68,7 +67,7 @@ async function readCategoriesMetadata(contentPath: string) {
);
}
export async function loadSidebarsFileUnsafe(
async function loadSidebarsFileUnsafe(
sidebarFilePath: string | false | undefined,
): Promise<SidebarsConfig> {
// false => no sidebars
@ -89,7 +88,19 @@ export async function loadSidebarsFileUnsafe(
}
// We don't want sidebars to be cached because of hot reloading.
return importFresh(sidebarFilePath);
const module = await loadFreshModule(sidebarFilePath);
// TODO unsafe, need to refactor and improve validation
return module as SidebarsConfig;
}
export async function loadSidebarsFile(
sidebarFilePath: string | false | undefined,
): Promise<SidebarsConfig> {
const sidebars = await loadSidebarsFileUnsafe(sidebarFilePath);
// TODO unsafe, need to refactor and improve validation
return sidebars as SidebarsConfig;
}
export async function loadSidebars(