Skip to content

Commit df0f694

Browse files
committed
Migrate docs site to App Router on Next canary
1 parent 427f24d commit df0f694

File tree

86 files changed

+4345
-3428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+4345
-3428
lines changed

.eslintignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 37 deletions
This file was deleted.

eslint-local-rules/__tests__/lint-markdown-code-blocks.test.js

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,30 @@ const path = require('path');
1111
const {ESLint} = require('eslint');
1212
const plugin = require('..');
1313

14-
const FIXTURES_DIR = path.join(
15-
__dirname,
16-
'fixtures',
17-
'src',
18-
'content'
19-
);
14+
const FIXTURES_DIR = path.join(__dirname, 'fixtures', 'src', 'content');
2015
const PARSER_PATH = path.join(__dirname, '..', 'parser.js');
2116

2217
function createESLint({fix = false} = {}) {
2318
return new ESLint({
24-
useEslintrc: false,
19+
overrideConfigFile: true,
2520
fix,
26-
plugins: {
27-
'local-rules': plugin,
28-
},
29-
overrideConfig: {
30-
parser: PARSER_PATH,
31-
plugins: ['local-rules'],
32-
rules: {
33-
'local-rules/lint-markdown-code-blocks': 'error',
21+
overrideConfig: [
22+
{
23+
files: ['**/*.md'],
24+
languageOptions: {
25+
parser: require(PARSER_PATH),
26+
parserOptions: {
27+
sourceType: 'module',
28+
},
29+
},
30+
plugins: {
31+
'local-rules': plugin,
32+
},
33+
rules: {
34+
'local-rules/lint-markdown-code-blocks': 'error',
35+
},
3436
},
35-
parserOptions: {
36-
sourceType: 'module',
37-
},
38-
},
37+
],
3938
});
4039
}
4140

@@ -53,11 +52,7 @@ async function lintFixture(name, {fix = false} = {}) {
5352

5453
async function run() {
5554
const basicResult = await lintFixture('basic-error.md');
56-
assert.strictEqual(
57-
basicResult.messages.length,
58-
1,
59-
'expected one diagnostic'
60-
);
55+
assert.strictEqual(basicResult.messages.length, 1, 'expected one diagnostic');
6156
assert(
6257
basicResult.messages[0].message.includes('Calling setState during render'),
6358
'expected message to mention setState during render'
@@ -91,9 +86,7 @@ async function run() {
9186
fix: true,
9287
});
9388
assert(
94-
duplicateFixed.output.includes(
95-
"{expectedErrors: {'react-compiler': [4]}}"
96-
),
89+
duplicateFixed.output.includes("{expectedErrors: {'react-compiler': [4]}}"),
9790
'expected duplicates to be rewritten to a single canonical block'
9891
);
9992
assert(
@@ -118,14 +111,12 @@ async function run() {
118111
fix: true,
119112
});
120113
assert(
121-
malformedFixed.output.includes(
122-
"{expectedErrors: {'react-compiler': [4]}}"
123-
),
114+
malformedFixed.output.includes("{expectedErrors: {'react-compiler': [4]}}"),
124115
'expected malformed metadata to be replaced with canonical form'
125116
);
126117
}
127118

128-
run().catch(error => {
119+
run().catch((error) => {
129120
console.error(error);
130121
process.exitCode = 1;
131122
});

eslint-local-rules/rules/metadata.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,19 @@ function parseExpectedErrorsEntries(rawEntries) {
8484

8585
if (parsed && typeof parsed === 'object') {
8686
for (const [key, value] of Object.entries(parsed)) {
87-
entries[key] = normalizeEntryValues(Array.isArray(value) ? value.flat() : value);
87+
entries[key] = normalizeEntryValues(
88+
Array.isArray(value) ? value.flat() : value
89+
);
8890
}
8991
}
9092

9193
return entries;
9294
}
9395

9496
function parseExpectedErrorsToken(tokenText) {
95-
const match = tokenText.match(/^\{\s*expectedErrors\s*:\s*(\{[\s\S]*\})\s*\}$/);
97+
const match = tokenText.match(
98+
/^\{\s*expectedErrors\s*:\s*(\{[\s\S]*\})\s*\}$/
99+
);
96100
if (!match) {
97101
return null;
98102
}
@@ -103,7 +107,7 @@ function parseExpectedErrorsToken(tokenText) {
103107

104108
try {
105109
entries = parseExpectedErrorsEntries(entriesSource);
106-
} catch (error) {
110+
} catch {
107111
parseError = true;
108112
entries = {};
109113
}
@@ -203,7 +207,9 @@ function cloneMetadata(metadata) {
203207
}
204208

205209
function findExpectedErrorsToken(metadata) {
206-
return metadata.tokens.find((token) => token.type === 'expectedErrors') || null;
210+
return (
211+
metadata.tokens.find((token) => token.type === 'expectedErrors') || null
212+
);
207213
}
208214

209215
function getCompilerExpectedLines(metadata) {

eslint-local-rules/rules/react-compiler.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function runReactCompiler(code, filename) {
8282
configFile: false,
8383
babelrc: false,
8484
});
85-
} catch (error) {
85+
} catch {
8686
return {...result, diagnostics: []};
8787
}
8888

@@ -98,17 +98,19 @@ function runReactCompiler(code, filename) {
9898
continue;
9999
}
100100

101-
const loc = typeof detail.primaryLocation === 'function'
102-
? detail.primaryLocation()
103-
: null;
101+
const loc =
102+
typeof detail.primaryLocation === 'function'
103+
? detail.primaryLocation()
104+
: null;
104105

105106
if (loc == null || typeof loc === 'symbol') {
106107
continue;
107108
}
108109

109-
const message = typeof detail.printErrorMessage === 'function'
110-
? detail.printErrorMessage(result.sourceCode, {eslint: true})
111-
: detail.description || 'Unknown React Compiler error';
110+
const message =
111+
typeof detail.printErrorMessage === 'function'
112+
? detail.printErrorMessage(result.sourceCode, {eslint: true})
113+
: detail.description || 'Unknown React Compiler error';
112114

113115
diagnostics.push({detail, loc, message});
114116
}

eslint.config.mjs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import tseslint from 'typescript-eslint';
2+
import reactHooks from 'eslint-plugin-react-hooks';
3+
import nextCoreWebVitals from 'eslint-config-next/core-web-vitals';
4+
import localRules from './eslint-local-rules/index.js';
5+
import mdxParser from './eslint-local-rules/parser.js';
6+
7+
const config = [
8+
{
9+
ignores: [
10+
'.next/**',
11+
'node_modules/**',
12+
'coverage/**',
13+
'dist/**',
14+
'out/**',
15+
'scripts/**',
16+
'plugins/**',
17+
'.claude/**',
18+
'worker-bundle.dist.js',
19+
'src/components/MDX/Sandpack/sandpack-rsc/generatedSources.ts',
20+
'src/components/MDX/Sandpack/sandpack-rsc/sandbox-code/**',
21+
'next-env.d.ts',
22+
'next.config.js',
23+
],
24+
},
25+
...nextCoreWebVitals,
26+
{
27+
files: ['**/*.{js,jsx,ts,tsx}'],
28+
languageOptions: {
29+
parser: tseslint.parser,
30+
parserOptions: {
31+
ecmaVersion: 'latest',
32+
sourceType: 'module',
33+
ecmaFeatures: {
34+
jsx: true,
35+
},
36+
},
37+
},
38+
plugins: {
39+
'@typescript-eslint': tseslint.plugin,
40+
'react-hooks': reactHooks,
41+
'local-rules': localRules,
42+
},
43+
rules: {
44+
'no-unused-vars': 'off',
45+
'@typescript-eslint/no-unused-vars': ['error', {varsIgnorePattern: '^_'}],
46+
'react-hooks/exhaustive-deps': 'error',
47+
'react/no-unknown-property': ['error', {ignore: ['meta']}],
48+
'local-rules/lint-markdown-code-blocks': 'error',
49+
},
50+
},
51+
{
52+
files: ['src/content/**/*.md'],
53+
languageOptions: {
54+
parser: mdxParser,
55+
parserOptions: {
56+
sourceType: 'module',
57+
},
58+
},
59+
plugins: {
60+
'@typescript-eslint': tseslint.plugin,
61+
'react-hooks': reactHooks,
62+
'local-rules': localRules,
63+
},
64+
rules: {
65+
'no-unused-vars': 'off',
66+
'@typescript-eslint/no-unused-vars': 'off',
67+
'react-hooks/exhaustive-deps': 'off',
68+
'react/no-unknown-property': 'off',
69+
'local-rules/lint-markdown-code-blocks': 'error',
70+
},
71+
},
72+
];
73+
74+
export default config;

next-env.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference types="next/navigation-types/compat/navigation" />
4+
import './.next/dev/types/routes.d.ts';
35

46
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
7+
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

next.config.js

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
const nextConfig = {
1616
pageExtensions: ['jsx', 'js', 'ts', 'tsx', 'mdx', 'md'],
1717
reactStrictMode: true,
18+
reactCompiler: true,
19+
cacheComponents: true,
1820
experimental: {
1921
scrollRestoration: true,
20-
reactCompiler: true,
2122
},
2223
async rewrites() {
2324
return {
@@ -44,58 +45,23 @@ const nextConfig = {
4445
};
4546
},
4647
env: {},
47-
webpack: (config, {dev, isServer, ...options}) => {
48-
if (process.env.ANALYZE) {
49-
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
50-
config.plugins.push(
51-
new BundleAnalyzerPlugin({
52-
analyzerMode: 'static',
53-
reportFilename: options.isServer
54-
? '../analyze/server.html'
55-
: './analyze/client.html',
56-
})
57-
);
58-
}
48+
...(process.env.ANALYZE
49+
? {
50+
webpack: (config, {isServer}) => {
51+
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
52+
config.plugins.push(
53+
new BundleAnalyzerPlugin({
54+
analyzerMode: 'static',
55+
reportFilename: isServer
56+
? '../analyze/server.html'
57+
: './analyze/client.html',
58+
})
59+
);
5960

60-
// Don't bundle the shim unnecessarily.
61-
config.resolve.alias['use-sync-external-store/shim'] = 'react';
62-
63-
// ESLint depends on the CommonJS version of esquery,
64-
// but Webpack loads the ESM version by default. This
65-
// alias ensures the correct version is used.
66-
//
67-
// More info:
68-
// https://github.com/reactjs/react.dev/pull/8115
69-
config.resolve.alias['esquery'] = 'esquery/dist/esquery.min.js';
70-
71-
const {IgnorePlugin, NormalModuleReplacementPlugin} = require('webpack');
72-
config.plugins.push(
73-
new NormalModuleReplacementPlugin(
74-
/^raf$/,
75-
require.resolve('./src/utils/rafShim.js')
76-
),
77-
new NormalModuleReplacementPlugin(
78-
/^process$/,
79-
require.resolve('./src/utils/processShim.js')
80-
),
81-
new IgnorePlugin({
82-
checkResource(resource, context) {
83-
if (
84-
/\/eslint\/lib\/rules$/.test(context) &&
85-
/\.\/[\w-]+(\.js)?$/.test(resource)
86-
) {
87-
// Skips imports of built-in rules that ESLint
88-
// tries to carry into the bundle by default.
89-
// We only want the engine and the React rules.
90-
return true;
91-
}
92-
return false;
61+
return config;
9362
},
94-
})
95-
);
96-
97-
return config;
98-
},
63+
}
64+
: {}),
9965
};
10066

10167
module.exports = nextConfig;

0 commit comments

Comments
 (0)