-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Separate Package for @react-native/event-emitter
#34401
Conversation
LogError: Error: Failed to load parser '@typescript-eslint/parser' declared in '../.eslintrc.js » @react-native-community/eslint-config#overrides[1]': Cannot find module 'typescript'
Require stack:
- /home/runner/work/react-native/react-native/node_modules/@typescript-eslint/typescript-estree/dist/parser.js
- /home/runner/work/react-native/react-native/node_modules/@typescript-eslint/typescript-estree/dist/index.js
- /home/runner/work/react-native/react-native/node_modules/@typescript-eslint/parser/dist/parser.js
- /home/runner/work/react-native/react-native/node_modules/@typescript-eslint/parser/dist/index.js
- /home/runner/work/react-native/react-native/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function._module2.default._load (/home/runner/work/react-native/react-native/bots/node_modules/override-require/dist/overrideRequire.js:43:25)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/home/runner/work/react-native/react-native/node_modules/@typescript-eslint/typescript-estree/dist/parser.js:35:25)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.customModuleHandler (/home/runner/work/react-native/react-native/bots/node_modules/danger/distribution/runner/runners/inline.js:129:28)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/runner/work/react-native/react-native/node_modules/@typescript-eslint/typescript-estree/dist/parser.js',
'/home/runner/work/react-native/react-native/node_modules/@typescript-eslint/typescript-estree/dist/index.js',
'/home/runner/work/react-native/react-native/node_modules/@typescript-eslint/parser/dist/parser.js',
'/home/runner/work/react-native/react-native/node_modules/@typescript-eslint/parser/dist/index.js',
'/home/runner/work/react-native/react-native/node_modules/@eslint/eslintrc/dist/eslintrc.cjs'
]
}
danger-results://tmp/danger-results.json |
6741133
to
e62c227
Compare
Base commit: be8fe7a |
Base commit: 4eec473 |
I suppose this is something worth discussing in react-native-community/discussions-and-proposals#480, but the expectations for a package inside
Apologies for the stream of consciousness. 😅 And also… I have no idea what is going on with Danger and the ESLint dependency error:
|
I investigated the Danger error a bit. It appears that this PR uncovered a dormant problem with our ESLint setup (wherein the dependencies of I suspect that this problem has been dormant because most of the React Native repository has not used TypeScript, so all of the optional TypeScript dependencies were blissfully absent. Since this PR introduces TypeScript definition files to be linted, those code paths are now being exercised and the TypeScript dependencies cannot resolve, therefore causing errors in the ESLint pipeline. #34423 reworks how we extend |
…#34423) Summary: Changes the React Native base ESLint configuration to consume `react-native-community/eslint-config` as a [yarn workspace](https://classic.yarnpkg.com/lang/en/docs/workspaces/), so that any dependencies of `react-native-community/eslint-config` can also be resolved from the root directory of `react-native`. Previously, `~/.eslintrc.js` extended `react-native-community/eslint-config` using a relative file path. This is problematic because if any dependencies (notably, optional peer dependencies such as some of the TypeScript dependencies) are not already installed at the root directory of `react-native`, running ESLint could fail to resolve any required dependencies. In other words, there was an implicit dependency that `react-native/yarn.lock` would also contain any dependencies required by `react-native/packages/eslint-config-react-native-community/yarn.lock`. With this change, running `yarn` from the root directory of `react-native` will also install any dependencies of `react-native-community/eslint-config`, and it will also symlink `react-native/node_modules/react-native-community/eslint-config` to `../../packages/eslint-config-react-native-community` (meaning any local changes to the config will still be reflected during active development). ## Changelog [Internal] Pull Request resolved: #34423 Test Plan: Successfully install dependencies and run ESLint. ``` $ cd react-native $ yarn $ yarn lint ``` Successfully run Danger on #34401 (which would previously fail because `typescript-eslint/eslint-plugin` could not be resolved from the root directory of `react-native`): ``` $ cd react-native/bots $ yarn $ node ./node_modules/.bin/danger pr #34401 ``` Reviewed By: NickGerleman Differential Revision: D38710285 Pulled By: yungsters fbshipit-source-id: a06ceea0884a90be60f6f5db9a5d42be52a951d5
e0efcc5
to
cfbf7e7
Compare
babel "$ROOT_DIR/src/EventEmitter.js" --out-dir "$ROOT_DIR/lib" | ||
prettier "$ROOT_DIR/lib/EventEmitter.js" --write | ||
|
||
cp "$ROOT_DIR/src/EventEmitter.js" "$ROOT_DIR/lib/EventEmitter.js.flow" | ||
cp "$ROOT_DIR/src/EventEmitter.d.ts" "$ROOT_DIR/lib/EventEmitter.d.ts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A potentially interesting choice that I've made here is checking in the build artifacts at packages/event-emitter/lib
.
The reason I am doing this is because in order for @react-native/event-emitter
to be resolvable locally using Yarn Workspaces without requiring that developers independently run cd packages/event-emitter; yarn
(which is cumbersome), we can instead check these built artifacts in so that rebasing onto the main branch simply gets you the newly built files. That is, the onus of updating these files is on whoever changes (and presumably tests) the source files.
As a consequence, one strange thing I'm doing here is running prettier
on the Babel output file. This is so that yarn run format-check
does not fail on that build artifact in CI. 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A potentially interesting choice that I've made here is checking in the build artifacts at packages/event-emitter/lib.
FYI That's consistent with what we do for react-native-codegen
Hmm… I'm not sure why Danger is still failing. Here are logs for the failing run: https://github.com/facebook/react-native/runs/7849986801?check_suite_focus=true
But here is me testing Danger locally (and seeing it succeed):
Any ideas? 🫠 |
Let me try moving the Edit: Hmm… nope. 😭 |
2e2cf13
to
a9bf973
Compare
hey @yungsters I tried taking a quick look; there are a couple things that I think might be worth looking closer into (in no particular order):
Aside from those more technical things, I also wanted to call out that it'd be best to also find a way to automate the release process for this package - since, aside core |
That's essentially covered by the point 2. in this RFC comment: react-native-community/discussions-and-proposals#480 (comment) |
oh yeah I know we are talking about it in the RFC; I just think it's likely that this PR will land before all that work is done 🤣 |
Totally. It's not worth to block this. |
…facebook#34423) Summary: Changes the React Native base ESLint configuration to consume `react-native-community/eslint-config` as a [yarn workspace](https://classic.yarnpkg.com/lang/en/docs/workspaces/), so that any dependencies of `react-native-community/eslint-config` can also be resolved from the root directory of `react-native`. Previously, `~/.eslintrc.js` extended `react-native-community/eslint-config` using a relative file path. This is problematic because if any dependencies (notably, optional peer dependencies such as some of the TypeScript dependencies) are not already installed at the root directory of `react-native`, running ESLint could fail to resolve any required dependencies. In other words, there was an implicit dependency that `react-native/yarn.lock` would also contain any dependencies required by `react-native/packages/eslint-config-react-native-community/yarn.lock`. With this change, running `yarn` from the root directory of `react-native` will also install any dependencies of `react-native-community/eslint-config`, and it will also symlink `react-native/node_modules/react-native-community/eslint-config` to `../../packages/eslint-config-react-native-community` (meaning any local changes to the config will still be reflected during active development). ## Changelog [Internal] Pull Request resolved: facebook#34423 Test Plan: Successfully install dependencies and run ESLint. ``` $ cd react-native $ yarn $ yarn lint ``` Successfully run Danger on facebook#34401 (which would previously fail because `typescript-eslint/eslint-plugin` could not be resolved from the root directory of `react-native`): ``` $ cd react-native/bots $ yarn $ node ./node_modules/.bin/danger pr facebook#34401 ``` Reviewed By: NickGerleman Differential Revision: D38710285 Pulled By: yungsters fbshipit-source-id: a06ceea0884a90be60f6f5db9a5d42be52a951d5
…facebook#34423) Summary: Changes the React Native base ESLint configuration to consume `react-native-community/eslint-config` as a [yarn workspace](https://classic.yarnpkg.com/lang/en/docs/workspaces/), so that any dependencies of `react-native-community/eslint-config` can also be resolved from the root directory of `react-native`. Previously, `~/.eslintrc.js` extended `react-native-community/eslint-config` using a relative file path. This is problematic because if any dependencies (notably, optional peer dependencies such as some of the TypeScript dependencies) are not already installed at the root directory of `react-native`, running ESLint could fail to resolve any required dependencies. In other words, there was an implicit dependency that `react-native/yarn.lock` would also contain any dependencies required by `react-native/packages/eslint-config-react-native-community/yarn.lock`. With this change, running `yarn` from the root directory of `react-native` will also install any dependencies of `react-native-community/eslint-config`, and it will also symlink `react-native/node_modules/react-native-community/eslint-config` to `../../packages/eslint-config-react-native-community` (meaning any local changes to the config will still be reflected during active development). ## Changelog [Internal] Pull Request resolved: facebook#34423 Test Plan: Successfully install dependencies and run ESLint. ``` $ cd react-native $ yarn $ yarn lint ``` Successfully run Danger on facebook#34401 (which would previously fail because `typescript-eslint/eslint-plugin` could not be resolved from the root directory of `react-native`): ``` $ cd react-native/bots $ yarn $ node ./node_modules/.bin/danger pr facebook#34401 ``` Reviewed By: NickGerleman Differential Revision: D38710285 Pulled By: yungsters fbshipit-source-id: a06ceea0884a90be60f6f5db9a5d42be52a951d5
a9bf973
to
2037697
Compare
Summary: currently, using TS, this is a valid import: `import { EventEmitter } from 'react-native';` However, looking at the [index file](https://github.com/facebook/react-native/blob/main/index.js) we can see that there is no such export. I first thought I'd add the EventEmitter export in order to get the `index.js` in line with the types, but it appears that the Event Emitter will become a separate package at some point #34401 so removing it from the types seems to be better for future. ## Changelog fix: remove unavailable EventEmitter TS export Pick one each for the category and type tags: [INTERNAL] [CHANGED] - remove unavailable EventEmitter TS export For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests Pull Request resolved: #36109 Test Plan: tested locally: using `import { EventEmitter } from 'react-native';` correctly gives `TS2305: Module '"react-native"' has no exported member 'EventEmitter'.` Reviewed By: javache, cortinico Differential Revision: D43155568 Pulled By: NickGerleman fbshipit-source-id: b9e8c3f4be9812637c8588d14a9ce4edf188ed36
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This PR was closed because it has been stalled for 7 days with no activity. |
Any update on this? |
This is still something I plan to do, but I haven't had time to revisit it. I'll try to do this soon. |
Summary: currently, using TS, this is a valid import: `import { EventEmitter } from 'react-native';` However, looking at the [index file](https://github.com/facebook/react-native/blob/main/index.js) we can see that there is no such export. I first thought I'd add the EventEmitter export in order to get the `index.js` in line with the types, but it appears that the Event Emitter will become a separate package at some point facebook#34401 so removing it from the types seems to be better for future. ## Changelog fix: remove unavailable EventEmitter TS export Pick one each for the category and type tags: [INTERNAL] [CHANGED] - remove unavailable EventEmitter TS export For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests Pull Request resolved: facebook#36109 Test Plan: tested locally: using `import { EventEmitter } from 'react-native';` correctly gives `TS2305: Module '"react-native"' has no exported member 'EventEmitter'.` Reviewed By: javache, cortinico Differential Revision: D43155568 Pulled By: NickGerleman fbshipit-source-id: b9e8c3f4be9812637c8588d14a9ce4edf188ed36
Summary
Moves
EventEmitter.js
(and support files) intopackages/event-emitter
and prepares it to be published as an independent package named@react-native/event-emitter
.Changelog
[General][Changed] - Hoisted
EventEmitter
into a separate package,@react-native/event-emitter
.Test Plan