Skip to content

Commit

Permalink
Explicitly require mdx loader as an optional peer dependency.
Browse files Browse the repository at this point in the history
Added rimraf as a dev dependency to enable cross platform removal of the tsconfig.lib.tsbuildinfo file, and thus cross platform builds.

Fix configuration to satisfy the mdx loader's options (specifically, the static folders and site dir).

Adjusted the whitelisting to only include files that are enabled, rather than include both if either changelogs or readmes are enabled.

Removed an unnecessary await in extractSidebar call.
  • Loading branch information
boenrobot committed Feb 8, 2024
1 parent b7612a4 commit fad9565
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"clean": "packemon clean --cwd packages/plugin",
"docs": "yarn run build && cd website && yarn run start",
"build": "packemon build --addEngines --cwd packages/plugin",
"pack": "rm -f packages/plugin/tsconfig.lib.tsbuildinfo && packemon pack --addEngines --declaration --cwd packages/plugin",
"pack": "rimraf packages/plugin/tsconfig.lib.tsbuildinfo && packemon pack --addEngines --declaration --cwd packages/plugin",
"format": "prettier --write .",
"lint": "eslint --cache --color --fix --ext .ts,.tsx ./packages/*/{src,tests} ./website/src",
"type": "tsc --build",
Expand All @@ -23,6 +23,7 @@
"prettier": "^3.2.4",
"prettier-config-moon": "^1.1.2",
"react": "^18.2.0",
"rimraf": "^5.0.5",
"tsconfig-moon": "^1.3.0",
"typescript": "^5.3.3"
},
Expand Down
1 change: 1 addition & 0 deletions packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"peerDependencies": {
"@docusaurus/core": "^3.0.0",
"@docusaurus/mdx-loader": "^3.0.0",
"react": ">=18.0.0",
"typescript": "^5.0.0"
},
Expand Down
24 changes: 16 additions & 8 deletions packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fs from 'fs';
import path from 'path';
import type { Options as MDXLoaderOptions } from '@docusaurus/mdx-loader';
import type { PropVersionDocs, PropVersionMetadata } from '@docusaurus/plugin-content-docs';
import { CURRENT_VERSION_NAME } from '@docusaurus/plugin-content-docs/server';
import type { LoadContext, Plugin, RouteConfig } from '@docusaurus/types';
Expand Down Expand Up @@ -216,7 +217,7 @@ export default function typedocApiPlugin(
packages.sort((a, d) => options.sortPackages(a, d));

// Generate sidebars (this runs before the main sidebar is loaded)
const sidebars = await extractSidebar(
const sidebars = extractSidebar(
packages,
removeScopes,
changelogs,
Expand Down Expand Up @@ -418,10 +419,16 @@ export default function typedocApiPlugin(
// Whitelist the folders that this webpack rule applies to, otherwise we collide with the native
// docs/blog plugins. We need to include the specific files only, as in polyrepo mode, the `cfg.packagePath`
// can be project root (where the regular docs are too).
const include = packageConfigs.flatMap((cfg) => [
path.join(options.projectRoot, cfg.packagePath, options.readmeName),
path.join(options.projectRoot, cfg.packagePath, options.changelogName),
]);
const include = packageConfigs.flatMap((cfg) => {
const list: string[] = [];
if (readmes) {
list.push(path.join(options.projectRoot, cfg.packagePath, options.readmeName));
}
if (changelogs) {
list.push(path.join(options.projectRoot, cfg.packagePath, options.changelogName));
}
return list;
});

return {
module: {
Expand All @@ -437,12 +444,13 @@ export default function typedocApiPlugin(
admonitions: true,
remarkPlugins: options.remarkPlugins,
rehypePlugins: options.rehypePlugins,
staticDir: path.join(context.siteDir, 'static'),
// Since this isnt a doc/blog page, we can get
siteDir: context.siteDir,
staticDirs: [...context.siteConfig.staticDirectories, path.join(context.siteDir, 'static')],
// Since this isn't a doc/blog page, we can get
// away with it being a partial!
isMDXPartial: () => true,
markdownConfig: context.siteConfig.markdown,
},
} satisfies MDXLoaderOptions,
},
{
loader: path.resolve(__dirname, './markdownLoader.js'),
Expand Down
28 changes: 28 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7353,6 +7353,7 @@ __metadata:
prettier: "npm:^3.2.4"
prettier-config-moon: "npm:^1.1.2"
react: "npm:^18.2.0"
rimraf: "npm:^5.0.5"
tsconfig-moon: "npm:^1.3.0"
typescript: "npm:^5.3.3"
languageName: unknown
Expand All @@ -7376,6 +7377,7 @@ __metadata:
typescript: "npm:^5.3.3"
peerDependencies:
"@docusaurus/core": ^3.0.0
"@docusaurus/mdx-loader": ^3.0.0
react: ">=18.0.0"
typescript: ^5.0.0
languageName: unknown
Expand Down Expand Up @@ -9191,6 +9193,21 @@ __metadata:
languageName: node
linkType: hard

"glob@npm:^10.3.7":
version: 10.3.10
resolution: "glob@npm:10.3.10"
dependencies:
foreground-child: "npm:^3.1.0"
jackspeak: "npm:^2.3.5"
minimatch: "npm:^9.0.1"
minipass: "npm:^5.0.0 || ^6.0.2 || ^7.0.0"
path-scurry: "npm:^1.10.1"
bin:
glob: dist/esm/bin.mjs
checksum: 38bdb2c9ce75eb5ed168f309d4ed05b0798f640b637034800a6bf306f39d35409bf278b0eaaffaec07591085d3acb7184a201eae791468f0f617771c2486a6a8
languageName: node
linkType: hard

"glob@npm:^7.0.0, glob@npm:^7.1.3, glob@npm:^7.1.4, glob@npm:^7.1.6":
version: 7.2.3
resolution: "glob@npm:7.2.3"
Expand Down Expand Up @@ -15823,6 +15840,17 @@ __metadata:
languageName: node
linkType: hard

"rimraf@npm:^5.0.5":
version: 5.0.5
resolution: "rimraf@npm:5.0.5"
dependencies:
glob: "npm:^10.3.7"
bin:
rimraf: dist/esm/bin.mjs
checksum: a612c7184f96258b7d1328c486b12ca7b60aa30e04229a08bbfa7e964486deb1e9a1b52d917809311bdc39a808a4055c0f950c0280fba194ba0a09e6f0d404f6
languageName: node
linkType: hard

"rollup-plugin-node-externals@npm:^5.1.3":
version: 5.1.3
resolution: "rollup-plugin-node-externals@npm:5.1.3"
Expand Down

0 comments on commit fad9565

Please sign in to comment.