From 02422a6e31ab705d21fa14c22dab0cd53033defe Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Wed, 5 Apr 2023 22:27:26 +0200 Subject: [PATCH] Chore: Access utils lib with relative path --- packages/app-cli/package.json | 2 +- packages/app-mobile/ios/Podfile.lock | 4 +-- packages/lib/package.json | 2 +- packages/plugin-repo-cli/package.json | 2 +- packages/tools/package.json | 2 +- packages/tools/utils/loadSponsors.ts | 5 ++- packages/utils/index.ts | 19 ++++++++-- yarn.lock | 50 ++++++++++++++++++++++++--- 8 files changed, 70 insertions(+), 16 deletions(-) diff --git a/packages/app-cli/package.json b/packages/app-cli/package.json index 6b8fc1f86..f2f755c83 100644 --- a/packages/app-cli/package.json +++ b/packages/app-cli/package.json @@ -43,7 +43,7 @@ "dependencies": { "@joplin/lib": "~2.11", "@joplin/renderer": "~2.11", - "@joplin/utils": "~2.11", + "@joplin/utils": "../utils", "aws-sdk": "2.1290.0", "chalk": "4.1.2", "compare-version": "0.1.2", diff --git a/packages/app-mobile/ios/Podfile.lock b/packages/app-mobile/ios/Podfile.lock index 6866f329f..d382d5c77 100644 --- a/packages/app-mobile/ios/Podfile.lock +++ b/packages/app-mobile/ios/Podfile.lock @@ -680,7 +680,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: boost: a7c83b31436843459a1961bfd74b96033dc77234 CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99 - DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54 + DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662 FBLazyVector: 48289402952f4f7a4e235de70a9a590aa0b79ef4 FBReactNativeSpec: dd1186fd05255e3457baa2f4ca65e94c2cd1e3ac Flipper: 26fc4b7382499f1281eb8cb921e5c3ad6de91fe0 @@ -693,7 +693,7 @@ SPEC CHECKSUMS: Flipper-RSocket: d9d9ade67cbecf6ac10730304bf5607266dd2541 FlipperKit: cbdee19bdd4e7f05472a66ce290f1b729ba3cb86 fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9 - glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b + glog: 5337263514dd6f09803962437687240c5dc39aa4 hermes-engine: 2af7b7a59128f250adfd86f15aa1d5a2ecd39995 JoplinCommonShareExtension: a8b60b02704d85a7305627912c0240e94af78db7 JoplinRNShareExtension: 485f3e6dad83b7b77f1572eabc249f869ee55c02 diff --git a/packages/lib/package.json b/packages/lib/package.json index 43b22d2d4..7f5b4ef9a 100644 --- a/packages/lib/package.json +++ b/packages/lib/package.json @@ -38,7 +38,7 @@ "@joplin/renderer": "~2.11", "@joplin/turndown": "^4.0.65", "@joplin/turndown-plugin-gfm": "^1.0.47", - "@joplin/utils": "~2.11", + "@joplin/utils": "../utils", "@types/nanoid": "3.0.0", "async-mutex": "0.4.0", "base-64": "1.0.0", diff --git a/packages/plugin-repo-cli/package.json b/packages/plugin-repo-cli/package.json index 1ad814909..9a39dc8db 100644 --- a/packages/plugin-repo-cli/package.json +++ b/packages/plugin-repo-cli/package.json @@ -20,7 +20,7 @@ "dependencies": { "@joplin/lib": "~2.11", "@joplin/tools": "~2.11", - "@joplin/utils": "~2.11", + "@joplin/utils": "../utils", "fs-extra": "11.1.1", "gh-release-assets": "2.0.1", "node-fetch": "2.6.7", diff --git a/packages/tools/package.json b/packages/tools/package.json index f8a3ac61f..336e1de40 100644 --- a/packages/tools/package.json +++ b/packages/tools/package.json @@ -22,7 +22,7 @@ "dependencies": { "@joplin/lib": "~2.11", "@joplin/renderer": "~2.11", - "@joplin/utils": "~2.11", + "@joplin/utils": "../utils", "dayjs": "1.11.7", "execa": "4.1.0", "fs-extra": "11.1.1", diff --git a/packages/tools/utils/loadSponsors.ts b/packages/tools/utils/loadSponsors.ts index 9f92037e4..1aa6e5f1b 100644 --- a/packages/tools/utils/loadSponsors.ts +++ b/packages/tools/utils/loadSponsors.ts @@ -1,10 +1,8 @@ import { readFile } from 'fs-extra'; -import { rootDir } from '@joplin/utils'; +import { getRootDir } from '@joplin/utils'; import { fetchWithRetry } from '@joplin/utils/net'; import { githubOauthToken } from '../tool-utils'; -const sponsorsPath = `${rootDir}/packages/tools/sponsors.json`; - export interface GithubSponsor { name: string; id: string; @@ -23,6 +21,7 @@ export interface OrgSponsor { } export const loadSponsors = async (): Promise => { + const sponsorsPath = `${await getRootDir()}/packages/tools/sponsors.json`; const output: Sponsors = JSON.parse(await readFile(sponsorsPath, 'utf8')); output.orgs = output.orgs.map(o => { diff --git a/packages/utils/index.ts b/packages/utils/index.ts index e35088eac..3f33cc819 100644 --- a/packages/utils/index.ts +++ b/packages/utils/index.ts @@ -2,12 +2,27 @@ import execCommand from './execCommand'; import commandToString from './commandToString'; import splitCommandString from './splitCommandString'; import { dirname } from 'path'; +import { pathExists } from 'fs-extra'; -const rootDir = dirname(dirname(dirname(__dirname))); +let rootDir_ = ''; + +const getRootDir = async () => { + if (rootDir_) return rootDir_; + + let p = dirname(dirname(dirname(__dirname))); + for (let i = 0; i < 9999; i++) { + if (await pathExists(`${p}/.eslintrc.js`)) { + rootDir_ = p; + return rootDir_; + } + p = dirname(p); + } + throw new Error('Could not find root dir'); +}; export { execCommand, commandToString, splitCommandString, - rootDir, + getRootDir, }; diff --git a/yarn.lock b/yarn.lock index e3fe9842a..bb0a61e62 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5090,7 +5090,7 @@ __metadata: "@joplin/renderer": ~2.11 "@joplin/turndown": ^4.0.65 "@joplin/turndown-plugin-gfm": ^1.0.47 - "@joplin/utils": ~2.11 + "@joplin/utils": ../utils "@types/fs-extra": 9.0.13 "@types/jest": 29.2.6 "@types/js-yaml": 4.0.5 @@ -5196,7 +5196,7 @@ __metadata: dependencies: "@joplin/lib": ~2.11 "@joplin/tools": ~2.11 - "@joplin/utils": ~2.11 + "@joplin/utils": ../utils "@types/fs-extra": 9.0.13 "@types/jest": 29.2.6 "@types/node": 18.11.18 @@ -5350,7 +5350,7 @@ __metadata: "@joplin/fork-htmlparser2": ^4.1.43 "@joplin/lib": ~2.11 "@joplin/renderer": ~2.11 - "@joplin/utils": ~2.11 + "@joplin/utils": ../utils "@rmp135/sql-ts": 1.16.0 "@types/fs-extra": 9.0.13 "@types/jest": 29.2.6 @@ -5414,7 +5414,47 @@ __metadata: languageName: unknown linkType: soft -"@joplin/utils@workspace:packages/utils, @joplin/utils@~2.11": +"@joplin/utils@file:../utils::locator=%40joplin%2Flib%40workspace%3Apackages%2Flib": + version: 2.11.0 + resolution: "@joplin/utils@file:../utils#../utils::hash=19ab4d&locator=%40joplin%2Flib%40workspace%3Apackages%2Flib" + dependencies: + execa: 5.1.1 + node-fetch: 2.6.7 + checksum: cd6b4304347a57ec1065a1e64441c749911c714cc8df924683979321b1df4b18064e7ef8a255f19e92387f57861e6af0edda26f1196997745d977b54acf461a6 + languageName: node + linkType: hard + +"@joplin/utils@file:../utils::locator=%40joplin%2Fplugin-repo-cli%40workspace%3Apackages%2Fplugin-repo-cli": + version: 2.11.0 + resolution: "@joplin/utils@file:../utils#../utils::hash=19ab4d&locator=%40joplin%2Fplugin-repo-cli%40workspace%3Apackages%2Fplugin-repo-cli" + dependencies: + execa: 5.1.1 + node-fetch: 2.6.7 + checksum: cd6b4304347a57ec1065a1e64441c749911c714cc8df924683979321b1df4b18064e7ef8a255f19e92387f57861e6af0edda26f1196997745d977b54acf461a6 + languageName: node + linkType: hard + +"@joplin/utils@file:../utils::locator=%40joplin%2Ftools%40workspace%3Apackages%2Ftools": + version: 2.11.0 + resolution: "@joplin/utils@file:../utils#../utils::hash=19ab4d&locator=%40joplin%2Ftools%40workspace%3Apackages%2Ftools" + dependencies: + execa: 5.1.1 + node-fetch: 2.6.7 + checksum: cd6b4304347a57ec1065a1e64441c749911c714cc8df924683979321b1df4b18064e7ef8a255f19e92387f57861e6af0edda26f1196997745d977b54acf461a6 + languageName: node + linkType: hard + +"@joplin/utils@file:../utils::locator=joplin%40workspace%3Apackages%2Fapp-cli": + version: 2.11.0 + resolution: "@joplin/utils@file:../utils#../utils::hash=19ab4d&locator=joplin%40workspace%3Apackages%2Fapp-cli" + dependencies: + execa: 5.1.1 + node-fetch: 2.6.7 + checksum: cd6b4304347a57ec1065a1e64441c749911c714cc8df924683979321b1df4b18064e7ef8a255f19e92387f57861e6af0edda26f1196997745d977b54acf461a6 + languageName: node + linkType: hard + +"@joplin/utils@workspace:packages/utils": version: 0.0.0-use.local resolution: "@joplin/utils@workspace:packages/utils" dependencies: @@ -21170,7 +21210,7 @@ __metadata: "@joplin/lib": ~2.11 "@joplin/renderer": ~2.11 "@joplin/tools": ~2.11 - "@joplin/utils": ~2.11 + "@joplin/utils": ../utils "@types/fs-extra": 9.0.13 "@types/jest": 29.2.6 "@types/node": 18.11.18