Skip to content

Commit 40b5fb8

Browse files
authored
Minor tweaks to website (#6264)
## What's the problem this PR addresses? Some minor/nitpick-level problems with the website Note: This PR has *some* overlap with #6218. I'll rebase one when the other is merged ## How did you fix it? - Removed remnants of TypeScript misconfiguration created when first adding the docusaurus workspace via `create-docusaurus` - Reorganized the directory structure of the docusaurus workspace. In particular, moved stuff that is run in build-time (except the `docusaurus.config.ts` itself) to a `config` directory. May not seem like much but as more stuff gets added this can keep thing clean and manageable. - Used admonitions instead of plain text where appropriate - Made the remark plugins apply to the CHANGELOG (they weren't before) - Cleaned up and reorganized the dependencies. Of course there are different schools of philosophy regarding what should count as a dependency vs devDependency in a frontend app. Ultimately I decided for Docusaurus, it makes more sense to say everything needed to run `yarn build` successfully is a dep and devDeps are those that are purely for DX (e.g. types) - Removed babel and browserslist config as we are not using them at all ## Checklist <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed.
1 parent f1edfae commit 40b5fb8

27 files changed

+164
-208
lines changed

.pnp.cjs

Lines changed: 12 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

env.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/docusaurus/babel.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import type {Options as MDXLoaderOptions, MDXOptions} from '@docusaurus/mdx-loader';
2+
import type {LoadContext, Plugin} from '@docusaurus/types';
3+
import {createRequire} from 'node:module';
4+
import path from 'node:path';
5+
6+
const webpack = createRequire(require.resolve(`@docusaurus/core/package.json`))(`webpack`);
7+
8+
export type Options = {
9+
changelog: Partial<MDXOptions>;
10+
};
11+
12+
const plugin = async function(context: LoadContext, options: Options): Promise<Plugin> {
13+
return {
14+
name: `docusaurus-plugin-yarn-webpack-config`,
15+
configureWebpack(config, isServer, utils) {
16+
return {
17+
module: {
18+
rules: [
19+
{
20+
test: /\.term\.dat$/,
21+
use: [require.resolve(`../../webpack/ansi-loader.js`)],
22+
},
23+
{
24+
test: /\.mdx?$/,
25+
include: require.resolve(`@yarnpkg/monorepo/CHANGELOG.md`),
26+
use: [
27+
utils.getJSLoader({isServer}),
28+
{
29+
loader: require.resolve(`@docusaurus/mdx-loader`),
30+
options: {
31+
admonitions: true,
32+
siteDir: context.siteDir,
33+
staticDirs: context.siteConfig.staticDirectories.map(dir => path.resolve(context.siteDir, dir)),
34+
isMDXPartial: () => true,
35+
isMDXPartialFrontMatterWarningDisabled: true,
36+
markdownConfig: context.siteConfig.markdown,
37+
...options.changelog,
38+
} satisfies MDXLoaderOptions,
39+
},
40+
],
41+
},
42+
],
43+
},
44+
resolve: {
45+
fallback: {
46+
fs: false,
47+
module: false,
48+
buffer: false,
49+
os: require.resolve(`os-browserify`),
50+
path: require.resolve(`path-browserify`),
51+
},
52+
alias: {
53+
'@mdx-js/react': require.resolve(`@mdx-js/react`),
54+
react: path.resolve(require.resolve(`react/package.json`), `..`),
55+
},
56+
},
57+
plugins: [
58+
new webpack.DefinePlugin({
59+
[`process.env`]: JSON.stringify({
60+
NODE_ENV: `development`,
61+
}),
62+
[`process.platform`]: JSON.stringify(`browser`),
63+
[`process.versions`]: JSON.stringify({
64+
node: `18.0.0`,
65+
}),
66+
}),
67+
],
68+
};
69+
},
70+
};
71+
};
72+
73+
// eslint-disable-next-line arca/no-default-export
74+
export default plugin;

packages/docusaurus/src/remark/autoLink.ts renamed to packages/docusaurus/config/remark/autoLink.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {MdxJsxFlowElement} from 'mdast-util-mdx-jsx';
33
import type {Parent, Root} from 'mdast';
44
import type {Transformer} from 'unified';
55
import {visitParents as visit} from 'unist-util-visit-parents';
6-
import {pathToFileURL} from 'url';
76

87
export type AutoLinkSpec = {
98
sourceType: `json-schema`;
@@ -95,8 +94,7 @@ export const plugin = (userSpecs: Array<AutoLinkSpec>) => () => {
9594
});
9695

9796
if (hasAutoLinks) {
98-
const url = pathToFileURL(require.resolve(`../components/AutoLink.tsx`));
99-
const code = `import {AutoLink} from ${JSON.stringify(url)};\n`;
97+
const code = `import {AutoLink} from "@site/src/components/AutoLink.tsx";\n`;
10098
ast.children.unshift({
10199
type: `mdxjsEsm`,
102100
value: code,

packages/docusaurus/src/remark/commandLineHighlight.ts renamed to packages/docusaurus/config/remark/commandLineHighlight.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import {YarnCli, getCli} from '@yarnpkg/cli';
22
import {parseShell} from '@yarnpkg/parsers';
3-
import {Definition, Token} from 'clipanion';
3+
import type {Definition, Token} from 'clipanion';
44
import {fromJs} from 'esast-util-from-js';
55
import {capitalize} from 'lodash';
66
import type {MdxJsxFlowElement} from 'mdast-util-mdx-jsx';
77
import type {Parent, Root} from 'mdast';
88
import type {Transformer} from 'unified';
99
import {visitParents as visit} from 'unist-util-visit-parents';
10-
import {pathToFileURL} from 'url';
1110

1211
export type ScriptLine =
1312
| RawLine
@@ -198,8 +197,7 @@ export const plugin = () => () => {
198197
});
199198

200199
if (highlightNodes.length > 0) {
201-
const url = pathToFileURL(require.resolve(`../components/CommandLineHighlight.tsx`));
202-
const code = `import {CommandLineHighlight} from ${JSON.stringify(url)};\n`;
200+
const code = `import {CommandLineHighlight} from "@site/src/components/CommandLineHighlight.tsx";\n`;
203201
ast.children.unshift({
204202
type: `mdxjsEsm`,
205203
value: code,

packages/docusaurus/docs/advanced/03-pnp/pnp-api.mdx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ export const VERSIONS: {std: number, [key: string]: number};
120120

121121
The `VERSIONS` object contains a set of numbers that detail which version of the API is currently exposed. The only version that is guaranteed to be there is `std`, which will refer to the version of this document. Other keys are meant to be used to describe extensions provided by third-party implementors. Versions will only be bumped when the signatures of the public API change.
122122

123-
**Note:** The current version is 3. We bump it responsibly and strive to make each version backward-compatible with the previous ones, but as you can probably guess some features are only available with the latest versions.
123+
:::note
124+
The current version is 3. We bump it responsibly and strive to make each version backward-compatible with the previous ones, but as you can probably guess some features are only available with the latest versions.
125+
:::
124126

125127
### `topLevel`
126128

@@ -132,7 +134,9 @@ The `topLevel` object is a simple package locator pointing to the top-level pack
132134

133135
This object is provided for convenience and doesn't necessarily needs to be used; you may create your own top-level locator by using your own locator literal with both fields set to `null`.
134136

135-
**Note:** These special top-level locators are merely aliases to physical locators, which can be accessed by calling `findPackageLocator`.
137+
:::note
138+
These special top-level locators are merely aliases to physical locators, which can be accessed by calling `findPackageLocator`.
139+
:::
136140

137141
### `getLocator(...)`
138142

@@ -152,15 +156,19 @@ export function getDependencyTreeRoots(): PackageLocator[];
152156

153157
The `getDependencyTreeRoots` function will return the set of locators that constitute the roots of individual dependency trees. In Yarn, there is exactly one such locator for each workspace in the project.
154158

155-
**Note:** This function will always return the physical locators, so it'll never return the special top-level locator described in the `topLevel` section.
159+
:::note
160+
This function will always return the physical locators, so it'll never return the special top-level locator described in the `topLevel` section.
161+
:::
156162

157163
### `getAllLocators(...)`
158164

159165
```ts
160166
export function getAllLocators(): PackageLocator[];
161167
```
162168

163-
**Important:** This function is not part of the Plug'n'Play specification and only available as a Yarn extension. In order to use it, you first must check that the [`VERSIONS`](/advanced/pnpapi#versions) dictionary contains a valid `getAllLocators` property.
169+
:::warning important
170+
This function is not part of the Plug'n'Play specification and only available as a Yarn extension. In order to use it, you first must check that the [`VERSIONS`](/advanced/pnpapi#versions) dictionary contains a valid `getAllLocators` property.
171+
:::
164172

165173
The `getAllLocators` function will return all locators from the dependency tree, in no particular order (although it'll always be a consistent order between calls for the same API). It can be used when you wish to know more about the packages themselves, but not about the exact tree layout.
166174

@@ -180,7 +188,9 @@ export function findPackageLocator(location: string): PackageLocator | null;
180188

181189
Given a location on the disk, the `findPackageLocator` function will return the package locator for the package that "owns" the path. For example, running this function on something conceptually similar to `/path/to/node_modules/foo/index.js` would return a package locator pointing to the `foo` package (and its exact version).
182190

183-
**Note:** This function will always return the physical locators, so it'll never return the special top-level locator described in the `topLevel` section. You can leverage this property to extract the physical locator for the top-level package:
191+
:::note
192+
This function will always return the physical locators, so it'll never return the special top-level locator described in the `topLevel` section. You can leverage this property to extract the physical locator for the top-level package:
193+
:::
184194

185195
```ts
186196
const virtualLocator = pnpApi.topLevel;
@@ -265,7 +275,9 @@ This function will return `null` if the request is a builtin module, unless `con
265275
export function resolveVirtual(path: string): string | null;
266276
```
267277

268-
**Important:** This function is not part of the Plug'n'Play specification and only available as a Yarn extension. In order to use it, you first must check that the [`VERSIONS`](/advanced/pnpapi#versions) dictionary contains a valid `resolveVirtual` property.
278+
:::warning important
279+
This function is not part of the Plug'n'Play specification and only available as a Yarn extension. In order to use it, you first must check that the [`VERSIONS`](/advanced/pnpapi#versions) dictionary contains a valid `resolveVirtual` property.
280+
:::
269281

270282
The `resolveVirtual` function will accept any path as parameter and return the same path minus any [virtual component](/advanced/lexicon#virtual-package). This makes it easier to store the location to the files in a portable way as long as you don't care about losing the dependency tree information in the process (requiring files through those paths will prevent them from accessing their peer dependencies).
271283

@@ -302,7 +314,9 @@ console.log(crossFs.readFileSync(`C:\\path\\to\\archive.zip\\package.json`));
302314

303315
The following function implements a tree traversal in order to print the list of locators from the tree.
304316

305-
**Important note:** This implementation iterates over **all** the nodes in the tree, even if they are found multiple times (which is very often the case). As a result the execution time is way higher than it could be. Optimize as needed 🙂
317+
:::warning important
318+
This implementation iterates over **all** the nodes in the tree, even if they are found multiple times (which is very often the case). As a result the execution time is way higher than it could be. Optimize as needed 🙂
319+
:::
306320

307321
```ts
308322
const pnp = require(`pnpapi`);

packages/docusaurus/docs/advanced/03-pnp/pnp-spec.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ GET_PACKAGE(manifest, locator)
235235
FIND_LOCATOR(manifest, moduleUrl)
236236
```
237237

238-
Note: The algorithm described here is quite inefficient. You should make sure to prepare data structure more suited for this task when you read the manifest.
238+
:::note
239+
The algorithm described here is quite inefficient. You should make sure to prepare data structure more suited for this task when you read the manifest.
240+
:::
239241

240242
1. Let `bestLength` be **0**
241243

packages/docusaurus/docs/advanced/04-technical/contributing.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ yarn version check --interactive
116116

117117
If it fails and you have no idea why, feel free to ping a maintainer and we'll do our best to help you.
118118

119-
**Note:** If you modify one of the [default plugins](https://github.com/yarnpkg/berry#default-plugins), you will also need to bump `@yarnpkg/cli`.
119+
:::note
120+
If you modify one of the [default plugins](https://github.com/yarnpkg/berry#default-plugins), you will also need to bump `@yarnpkg/cli`.
121+
:::
120122

121123
## Reviewing other PRs
122124

@@ -125,7 +127,7 @@ It's generally seen as [bad form](https://twitter.com/brian_d_vaughn/status/1224
125127

126128
## Writing documentation
127129

128-
We use [Docusaurus](https://docusaurus.io/docs) to generate HTML pages from [mdx](https://mdxjs.com/docs/) sources files.
130+
We use [Docusaurus](https://docusaurus.io/docs) to generate HTML pages from [mdx](https://mdxjs.com/docs/) sources files.
129131

130132
Our website is stored within the [`packages/docusaurus`](https://github.com/yarnpkg/berry/tree/master/packages/docusaurus) directory. You can change a page by modifying the corresponding `.mdx` file in the `docs` folder. For example, you'd edit this very page [here](https://github.com/yarnpkg/berry/blob/master/packages/docusaurus/docs/advanced/04-technical/contributing.md).
131133

packages/docusaurus/docs/features/constraints.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const {defineConfig} = require(`@yarnpkg/types`);
136136
/**
137137
* This rule will enforce that a workspace MUST depend on the same version of
138138
* a dependency as the one used by the other workspaces.
139-
*
139+
*
140140
* @param {Context} context
141141
*/
142142
function enforceConsistentDependenciesAcrossTheProject({Yarn}) {

packages/docusaurus/docs/getting-started/basics/install.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ sidebar_position: 2
77
---
88

99
:::tip
10-
1110
The preferred way to manage Yarn is by-project and through [Corepack](/corepack), a tool shipped by default with Node.js. Modern releases of Yarn aren't meant to be installed globally, or from npm.
12-
1311
:::
1412

1513
1. Start by enabling [Corepack](/corepack), if it isn't already; this will add the `yarn` binary to your PATH:

packages/docusaurus/docs/getting-started/extra/questions-and-answers.mdx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@ If you're interested to know more about each of these files:
9191

9292
- `.yarnrc.yml` (and its older counterpart, `.yarnrc`) are configuration files. They should always be stored in your project.
9393

94-
> **Tip:** You can also add a `.gitattributes` file to identify the release and plugin bundles as binary content. This way Git won't bother showing massive diffs when each time you subsequently add or update them:
95-
>
96-
> ```gitattributes
97-
> /.yarn/releases/** binary
98-
> /.yarn/plugins/** binary
99-
> ```
94+
:::tip
95+
You can also add a `.gitattributes` file to identify the release and plugin bundles as binary content. This way Git won't bother showing massive diffs when each time you subsequently add or update them:
96+
97+
```gitattributes
98+
/.yarn/releases/** binary
99+
/.yarn/plugins/** binary
100+
```
101+
:::
100102

101103
## Does Yarn support ESM?
102104

packages/docusaurus/docs/getting-started/migrating/pnp.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ yarn jest
116116

117117
We now need to inject some variables into the environment for Node to be able to locate your dependencies. In order to make this possible, we ask you to use `yarn node` which transparently does the heavy lifting.
118118

119-
**Note:** this section only applies to the _shell CLI_. The commands defined in your `scripts` are unaffected, as we make sure that `node` always points to the right location, with the right variables already set.
119+
:::note
120+
this section only applies to the _shell CLI_. The commands defined in your `scripts` are unaffected, as we make sure that `node` always points to the right location, with the right variables already set.
121+
:::
120122

121123
### Setup your IDE for PnP support
122124

packages/docusaurus/docusaurus.config.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import * as path from 'node:p
99
import {themes} from 'prism-react-renderer';
1010
import {satisfies} from 'semver';
1111

12-
import * as autoLink from './src/remark/autoLink';
13-
import * as commandLineHighlight from './src/remark/commandLineHighlight';
12+
import * as autoLink from './config/remark/autoLink';
13+
import * as commandLineHighlight from './config/remark/commandLineHighlight';
1414

1515
const remarkPlugins = [
1616
commandLineHighlight.plugin(),
@@ -89,7 +89,7 @@ async function typedocPluginConfig(): Promise<Partial<DocusaurusPluginTypeDocApi
8989
readmes: true,
9090
gitRefName: process.env.COMMIT_REF ?? `master`,
9191
typedocOptions: {
92-
plugin: [`./src/typedoc/plugin.ts`],
92+
plugin: [`./config/typedoc/plugin.ts`],
9393
},
9494
remarkPlugins,
9595
};
@@ -141,7 +141,14 @@ export default async function (): Promise<Config> {
141141
},
142142

143143
plugins: [
144-
require.resolve(`./plugin`),
144+
[
145+
`./config/docusaurus/plugins/webpack-config.ts`,
146+
{
147+
changelog: {
148+
remarkPlugins,
149+
},
150+
},
151+
],
145152
[
146153
`docusaurus-plugin-typedoc-api`,
147154
await typedocPluginConfig(),
@@ -154,7 +161,7 @@ export default async function (): Promise<Config> {
154161
options: {
155162
loader: `tsx`,
156163
format: isServer ? `cjs` : undefined,
157-
target: isServer ? `node12` : `es2017`,
164+
target: isServer ? `node18` : `es2017`,
158165
},
159166
}),
160167
},
@@ -174,12 +181,12 @@ export default async function (): Promise<Config> {
174181
label: `master (${YarnVersion})`,
175182
},
176183
},
177-
sidebarPath: require.resolve(`./sidebars.ts`),
184+
sidebarPath: `./config/docusaurus/sidebars.ts`,
178185
editUrl: `https://github.com/yarnpkg/berry/edit/master/packages/docusaurus/`,
179186
remarkPlugins,
180187
},
181188
theme: {
182-
customCss: require.resolve(`./src/css/custom.css`),
189+
customCss: `./src/css/custom.css`,
183190
},
184191
} satisfies Options,
185192
],

0 commit comments

Comments
 (0)