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

feat(babel): Extension resolver plugin #28

Merged
merged 1 commit into from
Jul 1, 2024
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"dependencies": {
"@babel/core": "^7.24.7",
"@babel/register": "^7.24.6",
"babel-plugin-module-resolver": "^5.0.2",
"babel-plugin-extension-resolver": "^1.0.12",
"dot-prop-immutable": "^2.1.1",
"pino": "^9.2.0",
"pino-pretty": "^11.2.1",
Expand Down
24 changes: 7 additions & 17 deletions src/lib/babelRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,13 @@ register({
cache: true,
only: [/node_modules[/\\](react-native|@react-native)[/\\]/],
plugins: [
["module-resolver", {
resolvePath(sourcePath: string) {
if (sourcePath.startsWith(".")) {
const hastePaths = [
"/Image",
"/Platform",
"/PlatformColorValueTypes",
"/BaseViewConfig",
];

return hastePaths.some(path => sourcePath.endsWith(path))
? `${sourcePath}.ios`
: undefined;
}

return undefined;
},
["extension-resolver", {
extensions: [
".ios.js",
".ios.jsx",
".js",
".jsx",
],
}],
],
presets: ["module:@react-native/babel-preset"],
Expand Down
94 changes: 27 additions & 67 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3838,16 +3838,12 @@ __metadata:
languageName: node
linkType: hard

"babel-plugin-module-resolver@npm:^5.0.2":
version: 5.0.2
resolution: "babel-plugin-module-resolver@npm:5.0.2"
"babel-plugin-extension-resolver@npm:^1.0.12":
version: 1.0.12
resolution: "babel-plugin-extension-resolver@npm:1.0.12"
dependencies:
find-babel-config: "npm:^2.1.1"
glob: "npm:^9.3.3"
pkg-up: "npm:^3.1.0"
reselect: "npm:^4.1.7"
resolve: "npm:^1.22.8"
checksum: 10/8084fa8a4cd96aaa861e5fe765a6cd03accef64d21d4108e314029bcd5f3a7fd96faf0c877c575a6a24d4fe0d87458d49748ca56faa4c77b2b812e4ed6023768
resolve: "npm:1.17.0"
checksum: 10/08c84f43b01dcedddf08d556aa69b6a6641cde41fbb21e711cfe080d066bc7ed506a463c1f4bd65f35284571dba55c398e846a299fd164f234d447661a4e7a6b
languageName: node
linkType: hard

Expand Down Expand Up @@ -5999,16 +5995,6 @@ __metadata:
languageName: node
linkType: hard

"find-babel-config@npm:^2.1.1":
version: 2.1.1
resolution: "find-babel-config@npm:2.1.1"
dependencies:
json5: "npm:^2.2.3"
path-exists: "npm:^4.0.0"
checksum: 10/a3e632a93ba2286b01f1273b90a1ef36e8d53351489817cbec500aa43169cc795122e788f4059c9876e5111dc587be65e46f3a2c9fed9161f21e754821b222d3
languageName: node
linkType: hard

"find-cache-dir@npm:^2.0.0":
version: 2.1.0
resolution: "find-cache-dir@npm:2.1.0"
Expand Down Expand Up @@ -6399,18 +6385,6 @@ __metadata:
languageName: node
linkType: hard

"glob@npm:^9.3.3":
version: 9.3.5
resolution: "glob@npm:9.3.5"
dependencies:
fs.realpath: "npm:^1.0.0"
minimatch: "npm:^8.0.2"
minipass: "npm:^4.2.4"
path-scurry: "npm:^1.6.1"
checksum: 10/e5fa8a58adf53525bca42d82a1fad9e6800032b7e4d372209b80cfdca524dd9a7dbe7d01a92d7ed20d89c572457f12c250092bc8817cb4f1c63efefdf9b658c0
languageName: node
linkType: hard

"globals@npm:^11.1.0":
version: 11.12.0
resolution: "globals@npm:11.12.0"
Expand Down Expand Up @@ -8586,15 +8560,6 @@ __metadata:
languageName: node
linkType: hard

"minimatch@npm:^8.0.2":
version: 8.0.4
resolution: "minimatch@npm:8.0.4"
dependencies:
brace-expansion: "npm:^2.0.1"
checksum: 10/aef05598ee565e1013bc8a10f53410ac681561f901c1a084b8ecfd016c9ed919f58f4bbd5b63e05643189dfb26e8106a84f0e1ff12e4a263aa37e1cae7ce9828
languageName: node
linkType: hard

"minimatch@npm:^9.0.0, minimatch@npm:^9.0.3, minimatch@npm:^9.0.4":
version: 9.0.5
resolution: "minimatch@npm:9.0.5"
Expand Down Expand Up @@ -8680,13 +8645,6 @@ __metadata:
languageName: node
linkType: hard

"minipass@npm:^4.2.4":
version: 4.2.8
resolution: "minipass@npm:4.2.8"
checksum: 10/e148eb6dcb85c980234cad889139ef8ddf9d5bdac534f4f0268446c8792dd4c74f4502479be48de3c1cce2f6450f6da4d0d4a86405a8a12be04c1c36b339569a
languageName: node
linkType: hard

"minipass@npm:^5.0.0":
version: 5.0.0
resolution: "minipass@npm:5.0.0"
Expand Down Expand Up @@ -9716,7 +9674,7 @@ __metadata:
languageName: node
linkType: hard

"path-scurry@npm:^1.11.1, path-scurry@npm:^1.6.1":
"path-scurry@npm:^1.11.1":
version: 1.11.1
resolution: "path-scurry@npm:1.11.1"
dependencies:
Expand Down Expand Up @@ -9895,15 +9853,6 @@ __metadata:
languageName: node
linkType: hard

"pkg-up@npm:^3.1.0":
version: 3.1.0
resolution: "pkg-up@npm:3.1.0"
dependencies:
find-up: "npm:^3.0.0"
checksum: 10/5bac346b7c7c903613c057ae3ab722f320716199d753f4a7d053d38f2b5955460f3e6ab73b4762c62fd3e947f58e04f1343e92089e7bb6091c90877406fcd8c8
languageName: node
linkType: hard

"possible-typed-array-names@npm:^1.0.0":
version: 1.0.0
resolution: "possible-typed-array-names@npm:1.0.0"
Expand Down Expand Up @@ -10239,7 +10188,7 @@ __metadata:
"@types/react": "npm:^18.3.3"
"@types/react-test-renderer": "npm:^18.3.0"
"@types/sinon": "npm:^17.0.3"
babel-plugin-module-resolver: "npm:^5.0.2"
babel-plugin-extension-resolver: "npm:^1.0.12"
dot-prop-immutable: "npm:^2.1.1"
eslint: "npm:^9.6.0"
eslint-import-resolver-typescript: "npm:^3.6.1"
Expand Down Expand Up @@ -10624,13 +10573,6 @@ __metadata:
languageName: node
linkType: hard

"reselect@npm:^4.1.7":
version: 4.1.8
resolution: "reselect@npm:4.1.8"
checksum: 10/199984d9872f71cd207f4aa6e6fd2bd48d95154f7aa9b3aee3398335f39f5491059e732f28c12e9031d5d434adab2c458dc8af5afb6564d0ad37e1644445e09c
languageName: node
linkType: hard

"resolve-from@npm:^3.0.0":
version: 3.0.0
resolution: "resolve-from@npm:3.0.0"
Expand Down Expand Up @@ -10659,7 +10601,16 @@ __metadata:
languageName: node
linkType: hard

"resolve@npm:^1.14.2, resolve@npm:^1.22.4, resolve@npm:^1.22.8, resolve@npm:~1.22.1":
"resolve@npm:1.17.0":
version: 1.17.0
resolution: "resolve@npm:1.17.0"
dependencies:
path-parse: "npm:^1.0.6"
checksum: 10/74141da8c56192fd46f6aa887864f8fd74c1755425174526610cb775177278bb414c6f6feb3051ccd73d774d2ae124c6c97e463e30d7ffd9a87f7da202b851dd
languageName: node
linkType: hard

"resolve@npm:^1.14.2, resolve@npm:^1.22.4, resolve@npm:~1.22.1":
version: 1.22.8
resolution: "resolve@npm:1.22.8"
dependencies:
Expand Down Expand Up @@ -10695,7 +10646,16 @@ __metadata:
languageName: node
linkType: hard

"resolve@patch:resolve@npm%3A^1.14.2#optional!builtin<compat/resolve>, resolve@patch:resolve@npm%3A^1.22.4#optional!builtin<compat/resolve>, resolve@patch:resolve@npm%3A^1.22.8#optional!builtin<compat/resolve>, resolve@patch:resolve@npm%3A~1.22.1#optional!builtin<compat/resolve>":
"resolve@patch:resolve@npm%3A1.17.0#optional!builtin<compat/resolve>":
version: 1.17.0
resolution: "resolve@patch:resolve@npm%3A1.17.0#optional!builtin<compat/resolve>::version=1.17.0&hash=c3c19d"
dependencies:
path-parse: "npm:^1.0.6"
checksum: 10/02e87fe9233d169fdc5220572c7b8933c9e23323aaecfd5b8d0b106a7f09dc676dd4d380e66c72b1369489292bcb337b13aad28b480a1bde5a5c040ff16758ea
languageName: node
linkType: hard

"resolve@patch:resolve@npm%3A^1.14.2#optional!builtin<compat/resolve>, resolve@patch:resolve@npm%3A^1.22.4#optional!builtin<compat/resolve>, resolve@patch:resolve@npm%3A~1.22.1#optional!builtin<compat/resolve>":
version: 1.22.8
resolution: "resolve@patch:resolve@npm%3A1.22.8#optional!builtin<compat/resolve>::version=1.22.8&hash=c3c19d"
dependencies:
Expand Down
Loading