From b72d90971f0283b0c51d04cf8e540513cd02802e Mon Sep 17 00:00:00 2001 From: Justin Hernandez Date: Thu, 4 Sep 2025 17:16:28 -0700 Subject: [PATCH] chore: address yarn lock issues (#1004) * address yarn lock issues * fix postinstall --- package.json | 3 +- scripts/run-patch-package.cjs | 55 +++++++++++++++++++++++++++++++++++ yarn.lock | 8 ----- 3 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 scripts/run-patch-package.cjs diff --git a/package.json b/package.json index ac4e3af10..7a756f1eb 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "format:github": "prettier --parser yaml --write .github/**/*.yml --single-quote false", "format:root": "prettier --parser markdown --write *.md scripts/**/*.md && prettier --parser yaml --write .*.{yml,yaml} --single-quote false && prettier --write scripts/**/*.{js,mjs,ts} && prettier --parser json --write scripts/**/*.json", "gitleaks": "gitleaks protect --staged --redact --config=.gitleaks.toml", - "postinstall": "patch-package", + "postinstall": "node scripts/run-patch-package.cjs", "lint": "yarn lint:headers && yarn workspaces foreach --parallel -i --all --exclude self-workspace-root run lint", "lint:headers": "node scripts/check-duplicate-headers.cjs app && node scripts/check-license-headers.mjs app --check && node scripts/check-duplicate-headers.cjs packages/mobile-sdk-alpha && node scripts/check-license-headers.mjs packages/mobile-sdk-alpha --check", "lint:headers:fix": "node scripts/check-duplicate-headers.cjs app && node scripts/check-license-headers.mjs app --fix && node scripts/check-duplicate-headers.cjs packages/mobile-sdk-alpha && node scripts/check-license-headers.mjs packages/mobile-sdk-alpha --fix", @@ -46,7 +46,6 @@ "husky": "9.1.7", "knip": "^5.62.0", "patch-package": "^8.0.0", - "postinstall-postinstall": "^2.1.0", "typescript": "^5.9.2" }, "packageManager": "yarn@4.6.0", diff --git a/scripts/run-patch-package.cjs b/scripts/run-patch-package.cjs new file mode 100644 index 000000000..d377224bf --- /dev/null +++ b/scripts/run-patch-package.cjs @@ -0,0 +1,55 @@ +#!/usr/bin/env node + +const fs = require('fs'); +const path = require('path'); +const { spawnSync } = require('child_process'); + +const repositoryRootPath = path.resolve(__dirname, '..'); +const patchesDirectoryPath = path.join(repositoryRootPath, 'patches'); + +function directoryContainsPatchFiles(directoryPath) { + try { + if (!fs.existsSync(directoryPath)) return false; + const entries = fs.readdirSync(directoryPath); + for (const entryName of entries) { + const absoluteEntryPath = path.join(directoryPath, entryName); + const entryStats = fs.statSync(absoluteEntryPath); + if (entryStats.isDirectory()) { + if (directoryContainsPatchFiles(absoluteEntryPath)) return true; + } else if (entryName.endsWith('.patch')) { + return true; + } + } + return false; + } catch { + return false; + } +} + +function isExecutableAvailableOnPath(executableName) { + const whichCommand = process.platform === 'win32' ? 'where' : 'command -v'; + const whichResult = spawnSync(whichCommand, [executableName], { shell: true, stdio: 'ignore' }); + return whichResult.status === 0; +} + +if (!fs.existsSync(patchesDirectoryPath)) { + console.log('patch-package: patches directory not found, skipping'); + process.exit(0); +} + +if (!directoryContainsPatchFiles(patchesDirectoryPath)) { + console.log('patch-package: no patches found, skipping'); + process.exit(0); +} + +if (!isExecutableAvailableOnPath('patch-package')) { + console.log('patch-package not installed, skipping'); + process.exit(0); +} + +const patchRun = spawnSync('patch-package', { shell: true, stdio: 'inherit' }); +if (patchRun.status !== 0) { + process.exit(patchRun.status || 1); +} + +process.exit(0); diff --git a/yarn.lock b/yarn.lock index ff907185b..d0ee11390 100644 --- a/yarn.lock +++ b/yarn.lock @@ -21655,13 +21655,6 @@ __metadata: languageName: node linkType: hard -"postinstall-postinstall@npm:^2.1.0": - version: 2.1.0 - resolution: "postinstall-postinstall@npm:2.1.0" - checksum: 10c0/70488447292c712afa7806126824d6fe93362392cbe261ae60166d9119a350713e0dbf4deb2ca91637c1037bc030ed1de78d61d9041bf2504513070f1caacdfd - languageName: node - linkType: hard - "prelude-ls@npm:^1.2.1": version: 1.2.1 resolution: "prelude-ls@npm:1.2.1" @@ -23484,7 +23477,6 @@ __metadata: husky: "npm:9.1.7" knip: "npm:^5.62.0" patch-package: "npm:^8.0.0" - postinstall-postinstall: "npm:^2.1.0" react: "npm:^18.3.1" react-native: "npm:0.76.9" typescript: "npm:^5.9.2"