Skip to content

Commit b48e367

Browse files
committed
add example
1 parent 8432597 commit b48e367

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ packageExtensions:
4141
plugins:
4242
- path: .yarn/plugins/@yarnpkg/plugin-compat.cjs
4343
spec: "@yarnpkg/plugin-compat"
44+
- path: incubator/yarn-plugin-align-deps/index.js
4445
tsEnableAutoTypes: false
4546
yarnPath: .yarn/releases/yarn-4.6.0.cjs

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,5 +228,8 @@
228228
}
229229
}
230230
},
231-
"prettier": "./.github/prettierrc.json"
231+
"prettier": "./.github/prettierrc.json",
232+
"rnx-kit": {
233+
"profiles": "./scripts/dependencies.config.js"
234+
}
232235
}

packages/test-app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@
6969
"jest": "^29.2.1",
7070
"prettier": "^3.0.0",
7171
"react-native-test-app": "^4.0.0",
72-
"react-test-renderer": "18.3.1",
73-
"typescript": "^5.0.0"
72+
"react-test-renderer": "18.3.1"
7473
},
7574
"rnx-kit": {
75+
"profile": "test",
7676
"kitType": "app",
7777
"build": {
7878
"distribution": [

scripts/dependencies.config.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as fs from "node:fs";
2+
import * as path from "node:path";
3+
4+
function needsESLint(cwd) {
5+
return fs.existsSync(path.join(cwd, "eslint.config.js"));
6+
}
7+
8+
function needsJest(cwd, manifest) {
9+
return "jest" in manifest || fs.existsSync(path.join(cwd, "jest.config.js"));
10+
}
11+
12+
function needsTypeScript(cwd) {
13+
return fs.existsSync(path.join(cwd, "tsconfig.json"));
14+
}
15+
16+
const COMMON_DEPENDENCIES = [
17+
["eslint", needsESLint],
18+
["jest", needsJest],
19+
["typescript", needsTypeScript],
20+
];
21+
22+
const getDependencyVersion = (() => {
23+
let deps;
24+
return (name) => {
25+
if (!deps) {
26+
const url = new URL("package.json", import.meta.url);
27+
const manifest = fs.readFileSync(url, { encoding: "utf-8" });
28+
deps = JSON.parse(manifest)["dependencies"];
29+
}
30+
31+
return deps[name];
32+
};
33+
})();
34+
35+
export default function (cwd, manifest) {
36+
let extensions = undefined;
37+
38+
for (const [pkg, test] of COMMON_DEPENDENCIES) {
39+
if (test(cwd, manifest)) {
40+
extensions ||= { dependencies: {} };
41+
extensions.dependencies[pkg] = getDependencyVersion(pkg);
42+
}
43+
}
44+
45+
console.log({ cwd, extensions });
46+
47+
return extensions;
48+
}

yarn.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4592,7 +4592,6 @@ __metadata:
45924592
react-native-test-app: "npm:^4.0.0"
45934593
react-native-windows: "npm:^0.76.0"
45944594
react-test-renderer: "npm:18.3.1"
4595-
typescript: "npm:^5.0.0"
45964595
bin:
45974596
rnx: ../cli/bin/rnx-cli.cjs
45984597
rnx.reason: Workaround for Node not being able to find `rnx-cli` because of Yarn virtual packages

0 commit comments

Comments
 (0)