Skip to content

Commit

Permalink
Fix create-release script to work with any CWD (#1013)
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky authored Dec 11, 2023
1 parent 55018cb commit a8b2a23
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
17 changes: 13 additions & 4 deletions scripts/create-release-from-tags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,10 +48,18 @@ export const getConfig = async (): Promise<Config> => {
}
}

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}.`)

Expand Down
1 change: 1 addition & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit a8b2a23

Please sign in to comment.