From a8b2a238aeeaecf051046765dc1b3aa5c90225b1 Mon Sep 17 00:00:00 2001 From: Seth Silesky <5115498+silesky@users.noreply.github.com> Date: Mon, 11 Dec 2023 17:37:31 -0600 Subject: [PATCH] Fix create-release script to work with any CWD (#1013) --- scripts/create-release-from-tags/index.ts | 17 +++++++++++++---- scripts/package.json | 1 + yarn.lock | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/scripts/create-release-from-tags/index.ts b/scripts/create-release-from-tags/index.ts index 906a939ce..094edeef5 100755 --- a/scripts/create-release-from-tags/index.ts +++ b/scripts/create-release-from-tags/index.ts @@ -3,6 +3,7 @@ import getPackages from 'get-monorepo-packages' import path from 'path' import fs from 'fs' import { exists } from '../utils/exists' +import { yarnWorkspaceRootSync } from '@node-kit/yarn-workspace-root' export type Config = { isDryRun: boolean @@ -47,10 +48,18 @@ export const getConfig = async (): Promise => { } } -const getChangelogPath = (packageName: string): string | undefined => { - const result = getPackages('.').find((p) => - p.package.name.includes(packageName) - ) +const getRelativeWorkspaceRoot = (): string => { + const root = yarnWorkspaceRootSync() + if (!root) { + throw new Error('cannot get workspace root.') + } + return path.relative(process.cwd(), root) +} + +const packages = getPackages(getRelativeWorkspaceRoot()) + +export const getChangelogPath = (packageName: string): string | undefined => { + const result = packages.find((p) => p.package.name.includes(packageName)) if (!result) throw new Error(`could not find package with name: ${packageName}.`) diff --git a/scripts/package.json b/scripts/package.json index 0407b9133..9cf25a45d 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -14,6 +14,7 @@ }, "packageManager": "yarn@3.4.1", "devDependencies": { + "@node-kit/yarn-workspace-root": "^3.2.0", "@types/node": "^16", "ts-node": "^10.8.0" } diff --git a/yarn.lock b/yarn.lock index bb535f418..40008725c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2850,6 +2850,7 @@ __metadata: version: 0.0.0-use.local resolution: "@internal/scripts@workspace:scripts" dependencies: + "@node-kit/yarn-workspace-root": ^3.2.0 "@types/node": ^16 ts-node: ^10.8.0 languageName: unknown @@ -3607,6 +3608,24 @@ __metadata: languageName: node linkType: hard +"@node-kit/extra.fs@npm:3.2.0": + version: 3.2.0 + resolution: "@node-kit/extra.fs@npm:3.2.0" + checksum: 48781d37ddd45f544774c17fccf31e1bfe648a16354cf8b20b28f0315798d977336a50c2a4cbb421fd9016792a0860cb2254e7450885324e7ace08903176b58b + languageName: node + linkType: hard + +"@node-kit/yarn-workspace-root@npm:^3.2.0": + version: 3.2.0 + resolution: "@node-kit/yarn-workspace-root@npm:3.2.0" + dependencies: + "@node-kit/extra.fs": 3.2.0 + find-up: ^5.0.0 + micromatch: ^4.0.5 + checksum: 18eca9649017f1b419a230909c319d57fe26400d3074685bb89946be30b3eb6670594dc7bb20d1a4d83cb4b991acf9818026b214fb879717f5ca0290ed934c3e + languageName: node + linkType: hard + "@nodelib/fs.scandir@npm:2.1.5": version: 2.1.5 resolution: "@nodelib/fs.scandir@npm:2.1.5"