Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[forgive] Scaffold workspaces #31917

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
"react-is": "0.0.0-experimental-4beb1fd8-20241118"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-commonjs": "^28.0.2",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-node-resolve": "^16.0.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@rollup/plugin-typescript": "^12.1.2",
"@tsconfig/strictest": "^2.0.5",
"concurrently": "^7.4.0",
"folder-hash": "^4.0.4",
Expand Down
1 change: 1 addition & 0 deletions compiler/packages/babel-plugin-react-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"babel-jest": "^29.0.3",
"babel-plugin-fbt": "^1.0.0",
"babel-plugin-fbt-runtime": "^1.0.0",
"cosmiconfig": "^9.0.0",
"eslint": "^8.57.1",
"invariant": "^2.2.4",
"jest": "^29.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const DEV_ROLLUP_CONFIG = {
format: 'cjs',
sourcemap: false,
exports: 'named',
inlineDynamicImports: true,
},
plugins: [
typescript({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
*/

import type * as BabelCore from '@babel/core';
import {compileProgram, parsePluginOptions} from '../Entrypoint';
import {
compileProgram,
findReactConfig,
parsePluginOptions,
type PluginOptions,
} from '../Entrypoint';
import {
injectReanimatedFlag,
pipelineUsesReanimatedPlugin,
Expand All @@ -29,7 +34,18 @@ export default function BabelPluginReactCompiler(
* want Forget to run true to source as possible.
*/
Program(prog, pass): void {
let opts = parsePluginOptions(pass.opts);
const reactConfig = findReactConfig();
let opts: PluginOptions | null = null;
if (reactConfig != null) {
opts = parsePluginOptions(reactConfig.config);
if (pass.opts != null) {
console.warn(
`Duplicate React Compiler config found, defaulting to reactrc found in: ${reactConfig.filepath}`,
);
}
} else {
opts = parsePluginOptions(pass.opts);
}
const isDev =
(typeof __DEV__ !== 'undefined' && __DEV__ === true) ||
process.env['NODE_ENV'] === 'development';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import {hasOwnProperty} from '../Utils/utils';
import {fromZodError} from 'zod-validation-error';
import {CompilerPipelineValue} from './Pipeline';
import {type CosmiconfigResult, cosmiconfigSync} from 'cosmiconfig';

const PanicThresholdOptionsSchema = z.enum([
/*
Expand Down Expand Up @@ -286,3 +287,11 @@ export function parseTargetConfig(value: unknown): CompilerReactTarget {
function isCompilerFlag(s: string): s is keyof PluginOptions {
return hasOwnProperty(defaultOptions, s);
}

export function findReactConfig(): CosmiconfigResult {
const explorerSync = cosmiconfigSync('react', {
searchStrategy: 'project',
cache: true,
});
return explorerSync.search();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const DEV_ROLLUP_CONFIG = {
file: 'dist/index.js',
format: 'cjs',
sourcemap: false,
inlineDynamicImports: true,
},
treeshake: {
moduleSideEffects: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const DEV_ROLLUP_CONFIG = {
format: 'cjs',
sourcemap: false,
exports: 'named',
inlineDynamicImports: true,
},
plugins: [
typescript({
Expand Down
1 change: 1 addition & 0 deletions compiler/packages/react-compiler-runtime/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const PROD_ROLLUP_CONFIG = {
file: 'dist/index.js',
format: 'cjs',
sourcemap: true,
inlineDynamicImports: true,
},
plugins: [
typescript({
Expand Down
22 changes: 22 additions & 0 deletions compiler/packages/react-forgive/client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"private": "true",
"name": "react-forgive-client",
"version": "0.0.0",
"description": "Experimental LSP client",
"license": "MIT",
"scripts": {
"build": "echo 'no build'",
"test": "echo 'no tests'"
},
"repository": {
"type": "git",
"url": "git+https://github.com/facebook/react.git",
"directory": "compiler/packages/react-forgive-client"
},
"dependencies": {
"vscode-languageclient": "^9.0.1"
},
"devDependencies": {
"@types/vscode": "^1.95.0"
}
}
59 changes: 59 additions & 0 deletions compiler/packages/react-forgive/client/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@types/vscode@^1.95.0":
version "1.96.0"
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.96.0.tgz#3181004bf25d71677ae4aacdd7605a3fd7edf08e"
integrity sha512-qvZbSZo+K4ZYmmDuaodMbAa67Pl6VDQzLKFka6rq+3WUTY4Kro7Bwoi0CuZLO/wema0ygcmpwow7zZfPJTs5jg==

balanced-match@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==

brace-expansion@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae"
integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==
dependencies:
balanced-match "^1.0.0"

minimatch@^5.1.0:
version "5.1.6"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.6.tgz#1cfcb8cf5522ea69952cd2af95ae09477f122a96"
integrity sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==
dependencies:
brace-expansion "^2.0.1"

semver@^7.3.7:
version "7.6.3"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143"
integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==

vscode-jsonrpc@8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-8.2.0.tgz#f43dfa35fb51e763d17cd94dcca0c9458f35abf9"
integrity sha512-C+r0eKJUIfiDIfwJhria30+TYWPtuHJXHtI7J0YlOmKAo7ogxP20T0zxB7HZQIFhIyvoBPwWskjxrvAtfjyZfA==

vscode-languageclient@^9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-9.0.1.tgz#cdfe20267726c8d4db839dc1e9d1816e1296e854"
integrity sha512-JZiimVdvimEuHh5olxhxkht09m3JzUGwggb5eRUkzzJhZ2KjCN0nh55VfiED9oez9DyF8/fz1g1iBV3h+0Z2EA==
dependencies:
minimatch "^5.1.0"
semver "^7.3.7"
vscode-languageserver-protocol "3.17.5"

vscode-languageserver-protocol@3.17.5:
version "3.17.5"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.5.tgz#864a8b8f390835572f4e13bd9f8313d0e3ac4bea"
integrity sha512-mb1bvRJN8SVznADSGWM9u/b07H7Ecg0I3OgXDuLdn307rl/J3A9YD6/eYOssqhecL27hK1IPZAsaqh00i/Jljg==
dependencies:
vscode-jsonrpc "8.2.0"
vscode-languageserver-types "3.17.5"

vscode-languageserver-types@3.17.5:
version "3.17.5"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.17.5.tgz#3273676f0cf2eab40b3f44d085acbb7f08a39d8a"
integrity sha512-Ld1VelNuX9pdF39h2Hgaeb5hEZM2Z3jUrrMgWQAu82jMtZp7p3vJT3BzToKtZI7NgQssZje5o0zryOrhQvzQAg==
59 changes: 59 additions & 0 deletions compiler/packages/react-forgive/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "react-forgive",
"displayName": "React Analyzer",
"description": "React LSP",
"license": "MIT",
"version": "0.0.0",
"repository": {
"type": "git",
"url": "git+https://github.com/facebook/react.git",
"directory": "compiler/packages/react-forgive"
},
"categories": [
"Programming Languages"
],
"keywords": [
"react",
"react analyzer",
"react compiler"
],
"publisher": "Meta",
"engines": {
"vscode": "^1.75.0"
},
"activationEvents": [
"onLanguage:javascriptreact",
"onLanguage:typescriptreact"
],
"main": "./dist/extension.js",
"contributes": {
"commands": [
{
"command": "react-forgive.toggleAll",
"title": "React Analyzer: Toggle on/off"
}
]
},
"scripts": {
"compile": "yarn run esbuild-base -- --sourcemap",
"dev": "yarn run package && yarn run install-ext",
"esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node",
"install-ext": "code --install-extension vscode-react-compiler-0.0.1.vsix",
"lint": "eslint src --ext ts",
"package": "vsce package",
"postinstall": "cd client && yarn install && cd ../server && yarn install && cd ..",
"pretest": "yarn run compile && yarn run lint",
"test": "vscode-test",
"test-compile": "tsc -p ./",
"vscode:prepublish": "yarn run esbuild-base -- --minify",
"watch": "yarn run esbuild-base -- --sourcemap --watch"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@types/node": "^20",
"esbuild": "^0.24.0",
"eslint": "^9.13.0",
"typescript": "^5.7.2",
"typescript-eslint": "^8.16.0"
}
}
20 changes: 20 additions & 0 deletions compiler/packages/react-forgive/server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"private": "true",
"name": "react-forgive-server",
"version": "0.0.0",
"description": "Experimental LSP server",
"license": "MIT",
"scripts": {
"build": "echo 'no build'",
"test": "echo 'no tests'"
},
"repository": {
"type": "git",
"url": "git+https://github.com/facebook/react.git",
"directory": "compiler/packages/react-forgive-server"
},
"dependencies": {
"vscode-languageserver": "^9.0.1",
"vscode-languageserver-textdocument": "^1.0.12"
}
}
6 changes: 6 additions & 0 deletions compiler/packages/react-forgive/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
13 changes: 13 additions & 0 deletions compiler/packages/react-forgive/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "@tsconfig/strictest/tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "node",
"outDir": "dist",
"jsx": "react-jsxdev",
"lib": ["ES2020"],
"target": "ES2020",
},
"exclude": ["node_modules", ".vscode-test"],
"include": ["src/**/*.ts"],
}
33 changes: 33 additions & 0 deletions compiler/packages/react-forgive/server/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


vscode-jsonrpc@8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-8.2.0.tgz#f43dfa35fb51e763d17cd94dcca0c9458f35abf9"
integrity sha512-C+r0eKJUIfiDIfwJhria30+TYWPtuHJXHtI7J0YlOmKAo7ogxP20T0zxB7HZQIFhIyvoBPwWskjxrvAtfjyZfA==

vscode-languageserver-protocol@3.17.5:
version "3.17.5"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.17.5.tgz#864a8b8f390835572f4e13bd9f8313d0e3ac4bea"
integrity sha512-mb1bvRJN8SVznADSGWM9u/b07H7Ecg0I3OgXDuLdn307rl/J3A9YD6/eYOssqhecL27hK1IPZAsaqh00i/Jljg==
dependencies:
vscode-jsonrpc "8.2.0"
vscode-languageserver-types "3.17.5"

vscode-languageserver-textdocument@^1.0.12:
version "1.0.12"
resolved "https://registry.yarnpkg.com/vscode-languageserver-textdocument/-/vscode-languageserver-textdocument-1.0.12.tgz#457ee04271ab38998a093c68c2342f53f6e4a631"
integrity sha512-cxWNPesCnQCcMPeenjKKsOCKQZ/L6Tv19DTRIGuLWe32lyzWhihGVJ/rcckZXJxfdKCFvRLS3fpBIsV/ZGX4zA==

vscode-languageserver-types@3.17.5:
version "3.17.5"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.17.5.tgz#3273676f0cf2eab40b3f44d085acbb7f08a39d8a"
integrity sha512-Ld1VelNuX9pdF39h2Hgaeb5hEZM2Z3jUrrMgWQAu82jMtZp7p3vJT3BzToKtZI7NgQssZje5o0zryOrhQvzQAg==

vscode-languageserver@^9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-9.0.1.tgz#500aef82097eb94df90d008678b0b6b5f474015b"
integrity sha512-woByF3PDpkHFUreUa7Hos7+pUWdeWMXRd26+ZX2A8cFx6v/JPTtd4/uN0/jB6XQHYaOlHbio03NTHCqrgG5n7g==
dependencies:
vscode-languageserver-protocol "3.17.5"
Loading
Loading