-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat(Worklets): JS code duplication #6921
Open
tjzel
wants to merge
36
commits into
main
Choose a base branch
from
@tjzel/worklets/duplicate-javascript
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
2f8b9c4
feat: stub of node module react-native-worklets
tjzel fcfda4f
feat: preliminary use of react-native-worklets in reanimated
tjzel a9b6af2
chore: fix CMakeLists
tjzel 96b76d7
Merge branch 'main' into @tjzel/worklets/node-module-with-rea-support
tjzel 3ee4d4f
chore: add explanatory comments
tjzel 1f40ace
feat: add linting to react-native-worklets
tjzel 7fccc99
chore: add missing dependency
tjzel 661706a
chore: add external-worklets-example
tjzel b127bea
chore: fix FabricExample occurences
tjzel a507fdc
chore: update github actions
tjzel afd030d
chore: fix CI
tjzel 2634199
chore: remove excessive changes
tjzel 64aea46
chore: remove external worklets
tjzel 3701183
chore: cleanup
tjzel ceee2f7
chore: draft duplication
tjzel 62c9488
chore: cleanup
tjzel 50d3f00
chore: improve react-native-worklets detection script
tjzel 7e75fb3
refactor: move ReanimatedVersion to Reanimated
tjzel f1aa4be
refactor: duplicatable code
tjzel 972d143
chore: fix filename in script
tjzel 88e38c0
Merge branch 'main' into @tjzel/worklets/restructure-worklets-source-…
tjzel 08ad6ab
chore: cleanup
tjzel 6a35149
chore: cleanup
tjzel 45a4c27
Merge branch 'main' into @tjzel/worklets/restructure-worklets-source-…
tjzel 1bcb1a9
Merge remote-tracking branch 'origin/@tjzel/worklets/restructure-work…
tjzel 077304b
chore: fix CI issues
tjzel e492782
Merge branch '@tjzel/worklets/duplicate-reanimated-code' into @tjzel/…
tjzel f70c622
chore: cleanup
tjzel 4cb0b45
chore: fix ts error
tjzel 6ee2b7b
chore: aggregate commit
tjzel 6fd9490
Merge branch 'main' into @tjzel/worklets/duplicate-javascript
tjzel 201d42c
chore: cleanup
tjzel e9ad506
chore: try adjust gitattributes
tjzel 383beed
chore: fix ci
tjzel 428d6ed
chore: remove debugging code
tjzel 93e8dfb
chore: fix importing react-native-worklets
tjzel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/.yarn/** linguist-vendored | ||
/.yarn/releases/* binary | ||
/.yarn/plugins/**/* binary | ||
/.yarn/** linguist-vendored=true | ||
/.yarn/releases/* binary=true | ||
/.yarn/plugins/**/* binary=true | ||
/packages/eslint-plugin-reanimated/index.js linguist-generated=true | ||
/packages/eslint-plugin-reanimated/types linguist-generated=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,34 @@ | ||
import App from '@/App'; | ||
/* eslint-disable no-var */ | ||
/* eslint-disable no-inner-declarations */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable no-underscore-dangle */ | ||
|
||
// This detection mechanism is necessary for the time being for dynamic | ||
// resolution of worklets. `react-native-worklets` is present in monorepo's | ||
// node_modules therefore allowed to be imported though it's not a dependency. | ||
let hasExternalWorklets = false; | ||
try { | ||
const packageJson = require('./package.json') as Record< | ||
string, | ||
Record<string, unknown> | ||
>; | ||
hasExternalWorklets = | ||
packageJson?.dependencies?.['react-native-worklets'] !== undefined || | ||
packageJson?.devDependencies?.['react-native-worklets'] !== undefined; | ||
} catch (_e) { | ||
// Do nothing. | ||
} | ||
|
||
declare global { | ||
var __DISALLOW_WORKLETS_IMPORT: boolean | undefined; | ||
} | ||
|
||
globalThis.__DISALLOW_WORKLETS_IMPORT = !hasExternalWorklets; | ||
|
||
// Has to be imported dynamically to inject __DISALLOW_WORKLETS_IMPORT before | ||
// any other code is executed. | ||
const App = require('@/App').default; | ||
|
||
export default App; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
import noAnimatedStyleToNonAnimatedComponent from './noAnimatedStyleToNonAnimatedComponent'; | ||
import useReanimatedError from './useReanimatedError'; | ||
import useWorkletsResolver from './useWorkletsResolver'; | ||
|
||
export const rules = { | ||
'animated-style-non-animated-component': | ||
noAnimatedStyleToNonAnimatedComponent, | ||
'use-reanimated-error': useReanimatedError, | ||
'use-worklets-resolver': useWorkletsResolver, | ||
} satisfies Record<string, TSESLint.RuleModule<string, Array<unknown>>>; |
41 changes: 41 additions & 0 deletions
41
packages/eslint-plugin-reanimated/src/useWorkletsResolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; | ||
|
||
const rule: TSESLint.RuleModule<'useWorkletsResolver', []> = { | ||
create: function (context) { | ||
return { | ||
ImportDeclaration(node: TSESTree.ImportDeclaration) { | ||
const workletsRegex = /\/worklets[/.*]?/; | ||
if (node.source.value.match(workletsRegex)) { | ||
const replacement = node.source.value.replace( | ||
workletsRegex, | ||
'/WorkletsResolver' | ||
); | ||
|
||
context.report({ | ||
node, | ||
messageId: 'useWorkletsResolver', | ||
fix: function (fixer) { | ||
return fixer.replaceText(node.source, `'${replacement}'`); | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
meta: { | ||
docs: { | ||
recommended: 'recommended', | ||
description: | ||
"Warns when `react-native-reanimated` doesn't use `WorkletsResolver` to import worklets' files`.", | ||
}, | ||
messages: { | ||
useWorkletsResolver: "Import worklets' files via WorkletsResolver.", | ||
}, | ||
type: 'suggestion', | ||
schema: [], | ||
fixable: 'code', | ||
}, | ||
defaultOptions: [], | ||
}; | ||
|
||
export default rule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/eslint-plugin-reanimated/types/useWorkletsResolver.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
declare const rule: TSESLint.RuleModule<'useWorkletsResolver', []>; | ||
export default rule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,4 @@ apple/worklets | |
Common/cpp/worklets | ||
android/src/worklets | ||
android/src/main/cpp/worklets | ||
src/worklets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 20 additions & 16 deletions
36
packages/react-native-reanimated/src/ReanimatedModule/NativeReanimated.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
packages/react-native-reanimated/src/ReanimatedModule/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
'use strict'; | ||
|
||
export { ReanimatedModule } from './reanimatedModuleInstance'; | ||
export type { ReanimatedModuleProxy } from './reanimatedModuleProxy'; | ||
export type { | ||
IReanimatedModule, | ||
ReanimatedModuleProxy, | ||
} from './reanimatedModuleProxy'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 17 additions & 15 deletions
32
packages/react-native-reanimated/src/ReanimatedModule/js-reanimated/JSReanimated.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't understand how things keep duplicating when I rebase 😭