Skip to content

Commit

Permalink
Upgrade Docusaurus - enable Docusaurus Faster (#385)
Browse files Browse the repository at this point in the history
- Upgrade website to Docusaurus v3.6
- Make this plugin compatible with Docusaurus Faster
- Keep retro-compatibility with lower versions

---------

Co-authored-by: Rohit Gohri <[email protected]>
  • Loading branch information
slorber and rohit-gohri authored Nov 8, 2024
1 parent ec090ef commit a986be6
Show file tree
Hide file tree
Showing 19 changed files with 2,373 additions and 437 deletions.
6 changes: 6 additions & 0 deletions .changeset/small-ligers-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"docusaurus-theme-redoc": minor
"redocusaurus": patch
---

Upgrade Docusaurus - add support for Docusaurus Faster (RsPack)
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,5 @@ static/openapi
.pnp.*

website/version.json

.idea
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-redoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"redoc": "2.1.5"
},
"devDependencies": {
"@docusaurus/types": "^3.4.0",
"@docusaurus/utils": "^3.4.0",
"@docusaurus/types": "^3.6.0",
"@docusaurus/utils": "^3.6.0",
"core-js": "^3.36.0",
"mobx": "^6.12.4",
"react": "^18.3.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/docusaurus-theme-redoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
"styled-components": "^6.1.11"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "^3.4.0",
"@docusaurus/theme-classic": "^3.4.0",
"@docusaurus/theme-common": "^3.4.0",
"@docusaurus/types": "^3.4.0",
"@docusaurus/module-type-aliases": "^3.6.0",
"@docusaurus/theme-classic": "^3.6.0",
"@docusaurus/theme-common": "^3.6.0",
"@docusaurus/types": "^3.6.0",
"@types/lodash": "^4.14.200",
"@types/postcss-prefix-selector": "^1",
"@types/react": "^18.3.3",
Expand Down
12 changes: 6 additions & 6 deletions packages/docusaurus-theme-redoc/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import path from 'path';
import type { LoadContext, Plugin } from '@docusaurus/types';
import { ThemeOptions, GlobalData } from './types/options';
import type { ThemeOptions, GlobalData } from './types/options';
import { getGlobalData } from './redocData';

// eslint-disable-next-line import/no-extraneous-dependencies, import/order
import webpack from 'webpack';

export type { ThemeOptions, GlobalData };

Expand All @@ -14,14 +13,15 @@ export default function redocTheme(
): Plugin<null> {
return {
name: 'docusaurus-theme-redoc',
configureWebpack(_config, isServer) {
configureWebpack(_config, isServer,{currentBundler}) {
const bundler = currentBundler.instance ?? require("webpack")
return {
plugins: [
new webpack.NormalModuleReplacementPlugin(
new bundler.NormalModuleReplacementPlugin(
/^tty$/,
require.resolve('./tty'),
),
new webpack.DefinePlugin({
new bundler.DefinePlugin({
'process.versions.node': JSON.stringify(
process.versions.node || '0.0.0',
),
Expand All @@ -33,7 +33,7 @@ export default function redocTheme(
}),
...(isServer
? [
new webpack.NormalModuleReplacementPlugin(
new bundler.NormalModuleReplacementPlugin(
/theme\/Redoc\/Styles/,
path.join(__dirname, 'theme', 'Redoc', 'ServerStyles.js'),
),
Expand Down
6 changes: 5 additions & 1 deletion packages/docusaurus-theme-redoc/src/redocData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { RedocRawOptions } from 'redoc';
import merge from 'lodash/merge';
import { Config, loadConfig } from '@redocly/openapi-core';
import { GlobalData, RedocThemeOverrides, ThemeOptions } from './types/options';
import type {
GlobalData,
RedocThemeOverrides,
ThemeOptions,
} from './types/options';

const defaultOptions: Partial<RedocRawOptions> = {
scrollYOffset: 'nav.navbar',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import Layout from '@theme/Layout';
import Redoc from '@theme/Redoc';
import { ApiDocProps as Props } from '../../types/common';
import type { ApiDocProps as Props } from '../../types/common';

function ApiDoc({ layoutProps, specProps }: Props): JSX.Element {
const defaultTitle = specProps.spec?.info?.title || 'API Docs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useMemo } from 'react';
import Redoc from '@theme/Redoc';
import useSpecData from '@theme/useSpecData';
import { MdxProps as Props } from '../../types/common';
import type { MdxProps as Props } from '../../types/common';
import '../ApiSchema/styles.css';

const ApiDocMdx: React.FC<Props> = ({ id }: Props): JSX.Element => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import '../../global';
import { SchemaDefinition } from 'redoc';
import { useSpec } from '../../utils/useSpec';
import { useSpecData } from '../useSpecData';
import { ApiSchemaProps as Props } from '../../types/common';
import type { ApiSchemaProps as Props } from '../../types/common';
import '../Redoc/styles.css';
import './styles.css';

Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-theme-redoc/src/theme/Redoc/Redoc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import clsx from 'clsx';
import '../../global';
import { RedocStandalone, RedocRawOptions } from 'redoc';
import { SpecProps } from '../../types/common';
import type { SpecProps } from '../../types/common';
import { useSpecOptions } from '../../utils/useSpecOptions';
import './styles.css';
import ServerRedoc from './ServerRedoc';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import clsx from 'clsx';
import '../../global';
import { Redoc as RedocComponent, RedocRawOptions } from 'redoc';
import { SpecProps } from '../../types/common';
import type { SpecProps } from '../../types/common';
import { useSpec } from '../../utils/useSpec';
import { ServerStyles } from './Styles';
import './styles.css';
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-theme-redoc/src/theme/useSpecData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useAllPluginInstancesData } from '@docusaurus/useGlobalData';
import { SpecProps } from '../types/common';
import type { SpecProps } from '../types/common';

/**
*
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-theme-redoc/src/utils/useSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import useIsBrowser from '@docusaurus/useIsBrowser';
import { useColorMode } from '@docusaurus/theme-common';
import '../global';
import { AppStore, RedocRawOptions } from 'redoc';
import { SpecProps } from '../types/common';
import type { SpecProps } from '../types/common';
import { useSpecOptions } from './useSpecOptions';

// the current store singleton in the app's instance
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-theme-redoc/src/utils/useSpecOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
import { useColorMode } from '@docusaurus/theme-common';
import merge from 'lodash/merge';
import '../global';
import { RedocRawOptions } from 'redoc';
import { SpecProps } from '../types/common';
import type { RedocRawOptions } from 'redoc';
import type { SpecProps } from '../types/common';
import { GlobalData } from '../types/options';

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/redocusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"node": ">=14"
},
"devDependencies": {
"@docusaurus/theme-common": "^3.4.0",
"@docusaurus/utils": "^3.4.0",
"@docusaurus/theme-common": "^3.6.0",
"@docusaurus/utils": "^3.6.0",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"react": "^18.3.1",
Expand Down
3 changes: 0 additions & 3 deletions website/babel.config.js

This file was deleted.

4 changes: 4 additions & 0 deletions website/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ if (process.env.VERCEL_URL) {
}

const config: Config = {
future: {
// See https://docusaurus.io/blog/releases/3.6
experimental_faster: true,
},
title: 'Redocusaurus',
tagline: 'OpenAPI solution for Docusaurus docs with Redoc',
customFields: {
Expand Down
9 changes: 5 additions & 4 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
"test": "percy snapshot snapshots.js"
},
"dependencies": {
"@docusaurus/core": "^3.4.0",
"@docusaurus/preset-classic": "^3.4.0",
"@docusaurus/theme-common": "^3.4.0",
"@docusaurus/utils": "^3.4.0",
"@docusaurus/core": "^3.6.0",
"@docusaurus/faster": "^3.6.0",
"@docusaurus/preset-classic": "^3.6.0",
"@docusaurus/theme-common": "^3.6.0",
"@docusaurus/utils": "^3.6.0",
"clsx": "^1.2.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
Loading

0 comments on commit a986be6

Please sign in to comment.