Skip to content

Commit

Permalink
[code-infra] Remove rsc-builder (#45079)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Jan 21, 2025
1 parent a56abff commit 180cf80
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 255 deletions.
6 changes: 0 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,6 @@ jobs:
- run:
name: '`pnpm proptypes` changes committed?'
command: git add -A && git diff --exit-code --staged
- run:
name: 'Write "use client" directive'
command: pnpm rsc:build
- run:
name: '`pnpm rsc:build` changes committed?'
command: git add -A && git diff --exit-code --staged
- run:
name: Generate the documentation
command: pnpm docs:api
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"docs:mdicons:synonyms": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js,.mjs\" ./docs/scripts/updateIconSynonyms && pnpm prettier",
"docs:zipRules": "cd docs && rm mui-vale.zip && zip -r mui-vale.zip mui-vale && cd ../ && vale sync",
"extract-error-codes": "cross-env MUI_EXTRACT_ERROR_CODES=true lerna run --concurrency 1 build:modern",
"rsc:build": "tsx ./packages/rsc-builder/buildRsc.ts",
"template:screenshot": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js\" ./docs/scripts/generateTemplateScreenshots",
"install:codesandbox": "pnpm install --no-frozen-lockfile",
"jsonlint": "node ./scripts/jsonlint.mjs",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,56 @@
module.exports = {
/// @ts-check

const REACT_CLIENT_APIS = new Set([
'useState',
'useEffect',
'useLayoutEffect',
'useReducer',
'useTransition',
'createContext',
]);

/**
* @param {import('eslint').AST.Program} ast
* @param {string} directive
* @returns
*/
function hasDirective(ast, directive) {
return ast.body.some(
(statement) =>
statement.type === 'ExpressionStatement' &&
statement.expression.type === 'Literal' &&
statement.expression.value === directive,
);
}

module.exports = /** @type {import('eslint').Rule.RuleModule} */ ({
create(context) {
let hasUseClientDirective = false;
const apis = new Set([
'useState',
'useEffect',
'useLayoutEffect',
'useReducer',
'useTransition',
'createContext',
]);
let hasUseServerDirective = false;
return {
/** @param {import('eslint').AST.Program} node */
Program(node) {
hasUseClientDirective = node.body.some(
(statement) =>
statement.type === 'ExpressionStatement' &&
statement.expression.type === 'Literal' &&
statement.expression.value === 'use client',
);
hasUseServerDirective = hasDirective(node, 'use server');
hasUseClientDirective = hasDirective(node, 'use client');
},
CallExpression(node) {
if (
!hasUseClientDirective &&
node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'Identifier' &&
node.callee.object.name === 'React' &&
apis.has(node.callee.property.name)
node.callee.property.type === 'Identifier' &&
REACT_CLIENT_APIS.has(node.callee.property.name)
) {
context.report({
node,
message: `Using 'React.${node.callee.property.name}' is forbidden if the file doesn't have a 'use client' directive.`,
fix(fixer) {
const sourceCode = context.getSourceCode();
if (
sourceCode.text.includes('"use server"') ||
sourceCode.text.includes("'use server'")
) {
if (hasUseServerDirective) {
return null;
}

const firstToken = sourceCode.ast.body[0];
const firstToken = context.sourceCode.ast.body[0];
return fixer.insertTextBefore(firstToken, "'use client';\n");
},
});
Expand All @@ -48,4 +61,4 @@ module.exports = {
meta: {
fixable: 'code',
},
};
});
176 changes: 0 additions & 176 deletions packages/rsc-builder/buildRsc.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/rsc-builder/package.json

This file was deleted.

19 changes: 0 additions & 19 deletions packages/rsc-builder/tsconfig.json

This file was deleted.

16 changes: 0 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 180cf80

Please sign in to comment.