mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-01 11:18:24 +02:00
chore(v2): TypeScript, use isolatedModules (#4790)
* Use isolatedModules * better solution for useDocs? * fix blog-only mode * fix bad useDocs import
This commit is contained in:
parent
aaeda674b1
commit
01adf25b0f
5 changed files with 17 additions and 29 deletions
|
@ -30,3 +30,6 @@ packages:
|
||||||
# Log settings
|
# Log settings
|
||||||
logs:
|
logs:
|
||||||
- {type: stdout, format: pretty, level: http}
|
- {type: stdout, format: pretty, level: http}
|
||||||
|
|
||||||
|
# Fix 413 errors in e2e CI
|
||||||
|
max_body_size: 1000mb
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {useLocation} from '@docusaurus/router';
|
import {useLocation} from '@docusaurus/router';
|
||||||
import {
|
import useGlobalData, {
|
||||||
useAllPluginInstancesData,
|
// useAllPluginInstancesData,
|
||||||
usePluginData,
|
usePluginData,
|
||||||
} from '@docusaurus/useGlobalData';
|
} from '@docusaurus/useGlobalData';
|
||||||
|
|
||||||
|
@ -24,8 +24,11 @@ import {
|
||||||
GetActivePluginOptions,
|
GetActivePluginOptions,
|
||||||
} from '../../client/docsClientUtils';
|
} from '../../client/docsClientUtils';
|
||||||
|
|
||||||
|
// Not using useAllPluginInstancesData() because in blog-only mode, docs hooks are still used by the theme
|
||||||
|
// We need a fail-safe fallback when the docs plugin is not in use
|
||||||
export const useAllDocsData = (): Record<string, GlobalPluginData> =>
|
export const useAllDocsData = (): Record<string, GlobalPluginData> =>
|
||||||
useAllPluginInstancesData('docusaurus-plugin-content-docs');
|
// useAllPluginInstancesData('docusaurus-plugin-content-docs');
|
||||||
|
useGlobalData()['docusaurus-plugin-content-docs'] ?? {};
|
||||||
|
|
||||||
export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
|
export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
|
||||||
usePluginData('docusaurus-plugin-content-docs', pluginId) as GlobalPluginData;
|
usePluginData('docusaurus-plugin-content-docs', pluginId) as GlobalPluginData;
|
||||||
|
|
|
@ -5,27 +5,7 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// See https://github.com/facebook/docusaurus/issues/3360
|
// Re-expose useDocs
|
||||||
// TODO find a better solution, this shouldn't be needed
|
// Ensure it's always statically available even if user is not using the docs plugin
|
||||||
|
// Problem reported for the blog-only mode: https://github.com/facebook/docusaurus/issues/3360
|
||||||
// TODO this is not ideal and produce a warning!
|
export * from '@docusaurus/plugin-content-docs/lib/theme/hooks/useDocs';
|
||||||
// see https://github.com/webpack/webpack/issues/7713#issuecomment-467888437
|
|
||||||
// note: warning can be filtered: https://github.com/facebook/docusaurus/pull/3382#issuecomment-684966924
|
|
||||||
try {
|
|
||||||
// eslint-disable-next-line global-require
|
|
||||||
module.exports = require('@theme-init/hooks/useDocs');
|
|
||||||
} catch (e) {
|
|
||||||
// In case the docs plugin is not available, might be useful to stub some methods here
|
|
||||||
// https://github.com/facebook/docusaurus/issues/3947
|
|
||||||
const Empty = {};
|
|
||||||
module.exports = {
|
|
||||||
useAllDocsData: () => Empty,
|
|
||||||
useActivePluginAndVersion: () => undefined,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
throw new Error(
|
|
||||||
"The docs plugin is not used, so you can't require the useDocs hooks. ",
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
|
|
|
@ -5,8 +5,9 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export {
|
export {useThemeConfig} from './utils/useThemeConfig';
|
||||||
useThemeConfig,
|
|
||||||
|
export type {
|
||||||
ThemeConfig,
|
ThemeConfig,
|
||||||
Navbar,
|
Navbar,
|
||||||
NavbarItem,
|
NavbarItem,
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
|
||||||
/* Advanced Options */
|
/* Advanced Options */
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
|
|
Loading…
Add table
Reference in a new issue