From b48e367005d4dc47efe2a28d39311d2c8f473ff0 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Mon, 3 Jun 2024 16:32:27 +0200 Subject: [PATCH] add example --- .yarnrc.yml | 1 + package.json | 5 +++- packages/test-app/package.json | 4 +-- scripts/dependencies.config.js | 48 ++++++++++++++++++++++++++++++++++ yarn.lock | 1 - 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 scripts/dependencies.config.js diff --git a/.yarnrc.yml b/.yarnrc.yml index a041b8bca..0a5894d92 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -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 diff --git a/package.json b/package.json index 078da8caf..aac5116b2 100644 --- a/package.json +++ b/package.json @@ -228,5 +228,8 @@ } } }, - "prettier": "./.github/prettierrc.json" + "prettier": "./.github/prettierrc.json", + "rnx-kit": { + "profiles": "./scripts/dependencies.config.js" + } } diff --git a/packages/test-app/package.json b/packages/test-app/package.json index d0f63237f..4d40c745a 100644 --- a/packages/test-app/package.json +++ b/packages/test-app/package.json @@ -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": [ diff --git a/scripts/dependencies.config.js b/scripts/dependencies.config.js new file mode 100644 index 000000000..e45b8b46d --- /dev/null +++ b/scripts/dependencies.config.js @@ -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; +} diff --git a/yarn.lock b/yarn.lock index f06da3ea5..84fc384bd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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