Files
react-native/packages/eslint-plugin-codegen/package.json
T
Ramanpreet Nara 758b63313c Use custom require hook to strip Flow types from NativeModule spec parser
Summary:
## Context
We currently run ESLint using `flow-node`. This is a very recent change that was introduced in these two diffs:
- Switch VSCode ESLint plugin using flow-node: D24454702.
- Switch all ESLint scripts to use flow-node: D24379783 (https://github.com/facebook/react-native/commit/ad5802cf916c1cbe3e142385a29810a0d7205c6c).

## Problem
Because `react-native/eslint-plugin-codegen` (written in vanilla JavaScript) requires two files from `react-native-codegen` (written with Flow typings), we force all requires executed while initializing ESLint to compile out Flow types. Issues:
- In the grand scheme of things, this is such a tiny and isolated problem. It shouldn't be the reason why we switch over to using flow node. That's a larger decision that should be discussed outside of this diff.
- On VSCode cold start, in D24454702, I measured that using flow-node adds approximately 320ms to JavaScript file lint time. So, this is just slow.

## Solution
- Switch ESLint back to using regular node:
   - Revert the changes to VSCode's ESLint plugin: D24454702
   - Revert the changes to the internal ESLint scripts: D24379783 (https://github.com/facebook/react-native/commit/ad5802cf916c1cbe3e142385a29810a0d7205c6c).
- Inside the ESLint plugin, register a temporary require hook to remove Flow types from the NativeModule spec parser, before we require it. We de-register this hook after the requires finish.

## Implementation Notes:
- The `with-babel-register/` is a fork of `babel/register`, except I simplified the implementation based on the assumption that we're using it literally to only compile `react-native-codegen`.
- `with-babel-register/` uses a disk cache, so we only call transformSync when a the input file (1) hasn't been transformed before, or (2) the cache entry was created before the file was last modified.
- I ported over the source-map logic, so that when the NativeModule spec parser throws non-parsing errors, we get the correct stack trace. **Note:** I'm not sure if the source maps will work if there's a babel/register earlier during initialization. However, I don't think this will pose an actual problem, since we don't use a babel/register hook earlier. So, I think we should punt on this investigation.

## Alternative: Why aren't we using babel/register?
Every time you call babel/register, it replaces the last registered hook. We don't want the ESLint plugin to be changing any existing require hooks that people have set up. Abandoned diff with babel/register: D24519349.

Changelog: [Internal]

Reviewed By: cpojer

Differential Revision: D24551549

fbshipit-source-id: bbd7c5be44f74c0e9adbb20fe86e09802410b123
2020-10-27 00:41:47 -07:00

22 lines
601 B
JSON

{
"name": "@react-native/eslint-plugin-codegen",
"version": "0.0.1",
"description": "ESLint rules to validate NativeModule and Component Specs",
"main": "index.js",
"repository": {
"type": "git",
"url": "git@github.com:facebook/react-native.git",
"directory": "packages/eslint-plugin-codegen"
},
"dependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-transform-flow-strip-types": "^7.0.0",
"flow-parser": "^0.121.0",
"make-dir": "^2.1.0",
"pirates":"^4.0.1",
"react-native-codegen": "*",
"source-map-support": "0.5.0"
},
"license": "MIT"
}