Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Feb 25, 2025
1 parent 8432597 commit b48e367
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ packageExtensions:
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-compat.cjs
spec: "@yarnpkg/plugin-compat"
- path: incubator/yarn-plugin-align-deps/index.js
tsEnableAutoTypes: false
yarnPath: .yarn/releases/yarn-4.6.0.cjs
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,8 @@
}
}
},
"prettier": "./.github/prettierrc.json"
"prettier": "./.github/prettierrc.json",
"rnx-kit": {
"profiles": "./scripts/dependencies.config.js"
}
}
4 changes: 2 additions & 2 deletions packages/test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@
"jest": "^29.2.1",
"prettier": "^3.0.0",
"react-native-test-app": "^4.0.0",
"react-test-renderer": "18.3.1",
"typescript": "^5.0.0"
"react-test-renderer": "18.3.1"
},
"rnx-kit": {
"profile": "test",
"kitType": "app",
"build": {
"distribution": [
Expand Down
48 changes: 48 additions & 0 deletions scripts/dependencies.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as fs from "node:fs";
import * as path from "node:path";

function needsESLint(cwd) {
return fs.existsSync(path.join(cwd, "eslint.config.js"));
}

function needsJest(cwd, manifest) {
return "jest" in manifest || fs.existsSync(path.join(cwd, "jest.config.js"));
}

function needsTypeScript(cwd) {
return fs.existsSync(path.join(cwd, "tsconfig.json"));
}

const COMMON_DEPENDENCIES = [
["eslint", needsESLint],
["jest", needsJest],
["typescript", needsTypeScript],
];

const getDependencyVersion = (() => {
let deps;
return (name) => {
if (!deps) {
const url = new URL("package.json", import.meta.url);
const manifest = fs.readFileSync(url, { encoding: "utf-8" });
deps = JSON.parse(manifest)["dependencies"];
}

return deps[name];
};
})();

export default function (cwd, manifest) {
let extensions = undefined;

for (const [pkg, test] of COMMON_DEPENDENCIES) {
if (test(cwd, manifest)) {
extensions ||= { dependencies: {} };
extensions.dependencies[pkg] = getDependencyVersion(pkg);
}
}

console.log({ cwd, extensions });

return extensions;
}
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4592,7 +4592,6 @@ __metadata:
react-native-test-app: "npm:^4.0.0"
react-native-windows: "npm:^0.76.0"
react-test-renderer: "npm:18.3.1"
typescript: "npm:^5.0.0"
bin:
rnx: ../cli/bin/rnx-cli.cjs
rnx.reason: Workaround for Node not being able to find `rnx-cli` because of Yarn virtual packages
Expand Down

0 comments on commit b48e367

Please sign in to comment.