Skip to content

Commit

Permalink
Merge branch 'main' into jh/invisible-docs
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts
  • Loading branch information
slorber committed Apr 13, 2022
2 parents a4fc23d + ee4c984 commit 3b4d27e
Show file tree
Hide file tree
Showing 82 changed files with 1,724 additions and 1,536 deletions.
2 changes: 1 addition & 1 deletion admin/new.docusaurus.io/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"@netlify/functions": "^1.0.0"
},
"devDependencies": {
"netlify-cli": "^9.13.6"
"netlify-cli": "^9.16.4"
}
}
2 changes: 1 addition & 1 deletion admin/scripts/image-resize.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ await Promise.all(
new URL(`../../website/src/data/showcase/${img}`, import.meta.url),
);
const {width, height} = imageSize(imgPath);
if (width === 640 && height === 320) {
if (width === 640 && height === 320 && imgPath.endsWith('.png')) {
// Do not emit if not resized. Important because we can't guarantee
// idempotency during resize -> optimization
return;
Expand Down
25 changes: 11 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,31 @@
"lock:update": "npx yarn-deduplicate"
},
"devDependencies": {
"@babel/cli": "^7.17.6",
"@babel/core": "^7.17.8",
"@babel/preset-typescript": "^7.16.7",
"@crowdin/cli": "^3.7.8",
"@swc/core": "^1.2.162",
"@swc/core": "^1.2.164",
"@swc/jest": "^0.2.20",
"@testing-library/react-hooks": "^7.0.2",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.181",
"@types/node": "^17.0.23",
"@types/prompts": "^2.0.14",
"@types/react": "^17.0.43",
"@types/react": "^18.0.0",
"@types/react-dev-utils": "^9.0.10",
"@types/react-test-renderer": "^17.0.1",
"@types/semver": "^7.3.9",
"@types/shelljs": "^0.8.11",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"concurrently": "^7.0.0",
"@typescript-eslint/eslint-plugin": "^5.18.0",
"@typescript-eslint/parser": "^5.18.0",
"concurrently": "^7.1.0",
"cross-env": "^7.0.3",
"cspell": "^5.19.5",
"eslint": "^8.12.0",
"cspell": "^5.19.6",
"eslint": "^8.13.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^26.1.3",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.1.4",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.4.0",
Expand All @@ -99,9 +96,9 @@
"lerna": "^4.0.0",
"lerna-changelog": "^2.2.0",
"lint-staged": "^12.3.7",
"netlify-cli": "^9.13.6",
"netlify-cli": "^9.16.4",
"nodemon": "^2.0.15",
"prettier": "^2.6.1",
"prettier": "^2.6.2",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-test-renderer": "^17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"fs-extra": "^10.0.1",
"lodash": "^4.17.21",
"prompts": "^2.4.2",
"semver": "^7.3.5",
"semver": "^7.3.6",
"shelljs": "^0.8.5",
"supports-color": "^9.2.2",
"tslib": "^2.3.1"
Expand Down
6 changes: 3 additions & 3 deletions packages/create-docusaurus/templates/facebook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
},
"devDependencies": {
"@babel/eslint-parser": "^7.17.0",
"eslint": "^8.12.0",
"eslint": "^8.13.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.4.0",
"prettier": "^2.6.1",
"prettier": "^2.6.2",
"stylelint": "^14.6.1"
},
"browserslist": {
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus-mdx-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
},
"license": "MIT",
"dependencies": {
"@babel/parser": "^7.17.8",
"@babel/traverse": "^7.17.3",
"@babel/parser": "^7.17.9",
"@babel/traverse": "^7.17.9",
"@docusaurus/logger": "2.0.0-beta.18",
"@docusaurus/utils": "2.0.0-beta.18",
"@mdx-js/mdx": "^1.6.22",
Expand All @@ -33,7 +33,7 @@
"tslib": "^2.3.1",
"unist-util-visit": "^2.0.3",
"url-loader": "^4.1.1",
"webpack": "^5.70.1"
"webpack": "^5.72.0"
},
"devDependencies": {
"@docusaurus/types": "2.0.0-beta.18",
Expand Down
19 changes: 19 additions & 0 deletions packages/docusaurus-mdx-loader/src/mdx-loader.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import type {Plugin} from 'unified';
import type {TOCItem} from '@docusaurus/types';

export type MDXPlugin =
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -16,3 +17,21 @@ export type MDXOptions = {
beforeDefaultRemarkPlugins: MDXPlugin[];
beforeDefaultRehypePlugins: MDXPlugin[];
};

export type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
/** As verbatim declared in the MDX document. */
readonly frontMatter: FrontMatter;
/** As provided by the content plugin. */
readonly metadata: Metadata;
/** A list of TOC items (headings). */
readonly toc: readonly TOCItem[];
/** First h1 title before any content. */
readonly contentTitle: string | undefined;
/**
* Usually image assets that may be collocated like `./img/thumbnail.png`.
* The loader would also bundle these assets and the client should use these
* in priority.
*/
readonly assets: Assets;
(): JSX.Element;
};
6 changes: 3 additions & 3 deletions packages/docusaurus-migrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
"@docusaurus/logger": "2.0.0-beta.18",
"@docusaurus/utils": "2.0.0-beta.18",
"@mapbox/hast-util-to-jsx": "^2.0.0",
"color": "^4.2.1",
"color": "^4.2.3",
"commander": "^5.1.0",
"fs-extra": "^10.0.1",
"hast-util-to-string": "^1.0.4",
"html-tags": "^3.1.0",
"html-tags": "^3.2.0",
"import-fresh": "^3.3.0",
"jscodeshift": "^0.13.1",
"rehype-parse": "^7.0.1",
"remark-parse": "^8.0.2",
"remark-stringify": "^8.1.0",
"semver": "^7.3.5",
"semver": "^7.3.6",
"tslib": "^2.3.1",
"unified": "^9.2.2",
"unist-util-visit": "^2.0.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-content-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"remark-admonitions": "^1.2.1",
"tslib": "^2.3.1",
"utility-types": "^3.10.0",
"webpack": "^5.70.1"
"webpack": "^5.72.0"
},
"devDependencies": {
"@docusaurus/types": "2.0.0-beta.18",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ declare module '@docusaurus/plugin-content-blog' {
}

declare module '@theme/BlogPostPage' {
import type {TOCItem} from '@docusaurus/types';
import type {LoadedMDXContent} from '@docusaurus/mdx-loader';
import type {
BlogPostFrontMatter,
BlogPostMetadata,
Expand All @@ -433,22 +433,7 @@ declare module '@theme/BlogPostPage' {
}
>;

export type Content = {
/** Same as `metadata.frontMatter` */
readonly frontMatter: FrontMatter;
/**
* Usually image assets that may be collocated like `./img/thumbnail.png`.
* The loader would also bundle these assets and the client should use these
* in priority.
*/
readonly assets: Assets;
/** Metadata of the post. */
readonly metadata: Metadata;
/** A list of TOC items (headings). */
readonly toc: readonly TOCItem[];
/** Renders the actual MDX content. */
(): JSX.Element;
};
export type Content = LoadedMDXContent<FrontMatter, Metadata, Assets>;

export interface Props {
/** Blog sidebar. */
Expand Down
3 changes: 2 additions & 1 deletion packages/docusaurus-plugin-content-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "2.0.0-beta.18",
"description": "Docs plugin for Docusaurus.",
"main": "lib/index.js",
"sideEffects": false,
"exports": {
"./client": "./lib/client/index.js",
"./server": "./lib/server-export.js",
Expand Down Expand Up @@ -36,7 +37,7 @@
"remark-admonitions": "^1.2.1",
"tslib": "^2.3.1",
"utility-types": "^3.10.0",
"webpack": "^5.70.1"
"webpack": "^5.72.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "2.0.0-beta.18",
Expand Down
Binary file modified packages/docusaurus-plugin-content-docs/src/__tests__/cli.test.ts
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import type {Optional} from 'utility-types';
import {createSlugger, posixPath, DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
import {createSidebarsUtils} from '../sidebars/utils';

jest.setTimeout(15000);

const fixtureDir = path.join(__dirname, '__fixtures__');

const createFakeDocFile = ({
Expand Down
63 changes: 15 additions & 48 deletions packages/docusaurus-plugin-content-docs/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

import {
getVersionsFilePath,
getVersionedDocsDirPath,
getVersionedSidebarsDirPath,
getVersionDocsDirPath,
getVersionSidebarsPath,
getDocsDirPathLocalized,
} from './versions';
} from './versions/files';
import {validateVersionName} from './versions/validation';
import fs from 'fs-extra';
import path from 'path';
import type {PluginOptions} from '@docusaurus/plugin-content-docs';
import {loadSidebarsFileUnsafe, resolveSidebarPathOption} from './sidebars';
import {loadSidebarsFileUnsafe} from './sidebars';
import {CURRENT_VERSION_NAME} from './constants';
import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
import logger from '@docusaurus/logger';
Expand Down Expand Up @@ -42,13 +43,8 @@ async function createVersionedSidebarFile({
const shouldCreateVersionedSidebarFile = Object.keys(sidebars).length > 0;

if (shouldCreateVersionedSidebarFile) {
const versionedSidebarsDir = getVersionedSidebarsDirPath(siteDir, pluginId);
const newSidebarFile = path.join(
versionedSidebarsDir,
`version-${version}-sidebars.json`,
);
await fs.outputFile(
newSidebarFile,
getVersionSidebarsPath(siteDir, pluginId, version),
`${JSON.stringify(sidebars, null, 2)}\n`,
'utf8',
);
Expand All @@ -57,7 +53,7 @@ async function createVersionedSidebarFile({

// Tests depend on non-default export for mocking.
export async function cliDocsVersionCommand(
version: string | null | undefined,
version: string,
{id: pluginId, path: docsPath, sidebarPath}: PluginOptions,
{siteDir, i18n}: LoadContext,
): Promise<void> {
Expand All @@ -66,44 +62,18 @@ export async function cliDocsVersionCommand(
const pluginIdLogPrefix =
pluginId === DEFAULT_PLUGIN_ID ? '[docs]' : `[${pluginId}]`;

if (!version) {
throw new Error(
`${pluginIdLogPrefix}: no version tag specified! Pass the version you wish to create as an argument, for example: 1.0.0.`,
);
}

if (version.includes('/') || version.includes('\\')) {
throw new Error(
`${pluginIdLogPrefix}: invalid version tag specified! Do not include slash (/) or backslash (\\). Try something like: 1.0.0.`,
);
}

if (version.length > 32) {
throw new Error(
`${pluginIdLogPrefix}: invalid version tag specified! Length cannot exceed 32 characters. Try something like: 1.0.0.`,
);
}

// Since we are going to create `version-${version}` folder, we need to make
// sure it's a valid pathname.
// eslint-disable-next-line no-control-regex
if (/[<>:"|?*\x00-\x1F]/.test(version)) {
throw new Error(
`${pluginIdLogPrefix}: invalid version tag specified! Please ensure its a valid pathname too. Try something like: 1.0.0.`,
);
}

if (/^\.\.?$/.test(version)) {
throw new Error(
`${pluginIdLogPrefix}: invalid version tag specified! Do not name your version "." or "..". Try something like: 1.0.0.`,
);
try {
validateVersionName(version);
} catch (e) {
logger.info`${pluginIdLogPrefix}: Invalid version name provided. Try something like: 1.0.0`;
throw e;
}

// Load existing versions.
let versions = [];
const versionsJSONFile = getVersionsFilePath(siteDir, pluginId);
if (await fs.pathExists(versionsJSONFile)) {
versions = JSON.parse(await fs.readFile(versionsJSONFile, 'utf8'));
versions = await fs.readJSON(versionsJSONFile);
}

// Check if version already exists.
Expand Down Expand Up @@ -146,10 +116,7 @@ export async function cliDocsVersionCommand(

const newVersionDir =
locale === i18n.defaultLocale
? path.join(
getVersionedDocsDirPath(siteDir, pluginId),
`version-${version}`,
)
? getVersionDocsDirPath(siteDir, pluginId, version)
: getDocsDirPathLocalized({
siteDir,
locale,
Expand All @@ -164,7 +131,7 @@ export async function cliDocsVersionCommand(
siteDir,
pluginId,
version,
sidebarPath: resolveSidebarPathOption(siteDir, sidebarPath),
sidebarPath,
});

// Update versions.json file.
Expand Down
Loading

0 comments on commit 3b4d27e

Please sign in to comment.