mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-01 10:22:30 +02:00
chore: prevent importing theme components with relative paths (#7674)
This commit is contained in:
parent
2c7012f706
commit
90a8ca387e
4 changed files with 53 additions and 31 deletions
49
.eslintrc.js
vendored
49
.eslintrc.js
vendored
|
@ -9,6 +9,18 @@ const OFF = 0;
|
||||||
const WARNING = 1;
|
const WARNING = 1;
|
||||||
const ERROR = 2;
|
const ERROR = 2;
|
||||||
|
|
||||||
|
const ClientRestrictedImportPatterns = [
|
||||||
|
// Prevent importing lodash in client bundle for bundle size
|
||||||
|
'lodash',
|
||||||
|
'lodash.**',
|
||||||
|
'lodash/**',
|
||||||
|
// Prevent importing server code in client bundle
|
||||||
|
'**/../babel/**',
|
||||||
|
'**/../server/**',
|
||||||
|
'**/../commands/**',
|
||||||
|
'**/../webpack/**',
|
||||||
|
];
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
root: true,
|
root: true,
|
||||||
env: {
|
env: {
|
||||||
|
@ -371,25 +383,32 @@ module.exports = {
|
||||||
},
|
},
|
||||||
overrides: [
|
overrides: [
|
||||||
{
|
{
|
||||||
files: [
|
files: ['packages/docusaurus/src/client/**/*.{js,ts,tsx}'],
|
||||||
'packages/docusaurus-*/src/theme/**/*.{js,ts,tsx}',
|
|
||||||
'packages/docusaurus/src/client/**/*.{js,ts,tsx}',
|
|
||||||
],
|
|
||||||
rules: {
|
rules: {
|
||||||
'no-restricted-imports': [
|
'no-restricted-imports': [
|
||||||
'error',
|
'error',
|
||||||
{
|
{
|
||||||
patterns: [
|
patterns: ClientRestrictedImportPatterns,
|
||||||
// Prevent importing lodash in client bundle for bundle size
|
},
|
||||||
'lodash',
|
],
|
||||||
'lodash.**',
|
},
|
||||||
'lodash/**',
|
},
|
||||||
// Prevent importing server code in client bundle
|
{
|
||||||
'**/../babel/**',
|
files: ['packages/docusaurus-*/src/theme/**/*.{js,ts,tsx}'],
|
||||||
'**/../server/**',
|
excludedFiles: '*.test.{js,ts,tsx}',
|
||||||
'**/../commands/**',
|
rules: {
|
||||||
'**/../webpack/**',
|
'no-restricted-imports': [
|
||||||
],
|
'error',
|
||||||
|
{
|
||||||
|
patterns: ClientRestrictedImportPatterns.concat(
|
||||||
|
// Prevents relative imports between React theme components
|
||||||
|
[
|
||||||
|
'../**',
|
||||||
|
'./**',
|
||||||
|
// Allows relative styles module import with consistent filename
|
||||||
|
'!./styles.module.css',
|
||||||
|
],
|
||||||
|
),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {
|
||||||
import BlogLayout from '@theme/BlogLayout';
|
import BlogLayout from '@theme/BlogLayout';
|
||||||
import TagsListByLetter from '@theme/TagsListByLetter';
|
import TagsListByLetter from '@theme/TagsListByLetter';
|
||||||
import type {Props} from '@theme/BlogTagsListPage';
|
import type {Props} from '@theme/BlogTagsListPage';
|
||||||
import SearchMetadata from '../SearchMetadata';
|
import SearchMetadata from '@theme/SearchMetadata';
|
||||||
|
|
||||||
export default function BlogTagsListPage({tags, sidebar}: Props): JSX.Element {
|
export default function BlogTagsListPage({tags, sidebar}: Props): JSX.Element {
|
||||||
const title = translateTagsPageTitle();
|
const title = translateTagsPageTitle();
|
||||||
|
|
|
@ -16,8 +16,8 @@ import Navbar from '@theme/Navbar';
|
||||||
import Footer from '@theme/Footer';
|
import Footer from '@theme/Footer';
|
||||||
import LayoutProviders from '@theme/LayoutProviders';
|
import LayoutProviders from '@theme/LayoutProviders';
|
||||||
import ErrorPageContent from '@theme/ErrorPageContent';
|
import ErrorPageContent from '@theme/ErrorPageContent';
|
||||||
import './styles.css';
|
|
||||||
import type {Props} from '@theme/Layout';
|
import type {Props} from '@theme/Layout';
|
||||||
|
import styles from './styles.module.css';
|
||||||
|
|
||||||
export default function Layout(props: Props): JSX.Element {
|
export default function Layout(props: Props): JSX.Element {
|
||||||
const {
|
const {
|
||||||
|
@ -41,7 +41,12 @@ export default function Layout(props: Props): JSX.Element {
|
||||||
|
|
||||||
<Navbar />
|
<Navbar />
|
||||||
|
|
||||||
<div className={clsx(ThemeClassNames.wrapper.main, wrapperClassName)}>
|
<div
|
||||||
|
className={clsx(
|
||||||
|
ThemeClassNames.wrapper.main,
|
||||||
|
styles.mainWrapper,
|
||||||
|
wrapperClassName,
|
||||||
|
)}>
|
||||||
<ErrorBoundary fallback={(params) => <ErrorPageContent {...params} />}>
|
<ErrorBoundary fallback={(params) => <ErrorPageContent {...params} />}>
|
||||||
{children}
|
{children}
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
|
|
|
@ -5,23 +5,21 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
html,
|
:global(html, body) {
|
||||||
body {
|
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#__docusaurus {
|
.mainWrapper {
|
||||||
|
flex: 1 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Docusaurus-specific utility class */
|
||||||
|
:global(.docusaurus-mt-lg) {
|
||||||
|
margin-top: 3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(#__docusaurus) {
|
||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.main-wrapper {
|
|
||||||
flex: 1 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Docusaurus-specific utility classes */
|
|
||||||
|
|
||||||
.docusaurus-mt-lg {
|
|
||||||
margin-top: 3rem;
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue