Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(depsynky): handle peerDependencies + uniform ignore dev accross all commands #533

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified depsynky/bin.js
100644 → 100755
Empty file.
3 changes: 1 addition & 2 deletions depsynky/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bpinternal/depsynky",
"version": "0.0.10",
"version": "0.1.0",
"description": "CLI to synchronize dependencies accross a pnpm mono-repo",
"main": "dist/index.js",
"scripts": {
Expand All @@ -12,7 +12,6 @@
"bin": {
"depsynky": "./bin.js"
},

"author": "Botpress, Inc.",
"license": "MIT",
"dependencies": {
Expand Down
20 changes: 10 additions & 10 deletions depsynky/src/commands/check-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export type CheckVersionsOpts = {
}

const checker =
(pkg: utils.pkgjson.PackageJson) => (current: Record<string, string>, target: Record<string, string>) => {
(pkg: utils.pkgjson.PackageJson) => (current: Record<string, string> | undefined, target: Record<string, string>) => {
if (!current) {
return
}

for (const [name, version] of utils.objects.entries(target)) {
const currentVersion = current[name]
if (!currentVersion) {
Expand All @@ -35,17 +39,13 @@ export const checkVersions = (argv: YargsConfig<typeof config.checkSchema>, opts
const allPackages = utils.pnpm.searchWorkspaces(argv.rootDir)
const targetVersions = opts.targetVersions ?? utils.pnpm.versions(allPackages)

for (const { path: pkgPath, content } of allPackages) {
const { dependencies, devDependencies } = utils.pkgjson.read(pkgPath)
for (const { content } of allPackages) {
const { dependencies, devDependencies, peerDependencies } = content

const check = checker(content)
dependencies && check(dependencies, targetVersions)

if (argv.ignoreDev) {
continue
}

devDependencies && check(devDependencies, targetVersions)
check(dependencies, targetVersions)
check(peerDependencies, targetVersions)
!argv.ignoreDev && check(devDependencies, targetVersions)
}

logger.info('All versions are in sync')
Expand Down
20 changes: 15 additions & 5 deletions depsynky/src/commands/sync-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export type SyncVersionsOpts = {
}

const updater =
(pkg: utils.pkgjson.PackageJson) => (current: Record<string, string>, target: Record<string, string>) => {
(pkg: utils.pkgjson.PackageJson) => (current: Record<string, string> | undefined, target: Record<string, string>) => {
if (!current) {
return current
}

for (const [name, version] of utils.objects.entries(target)) {
const currentVersion = current[name]
if (!currentVersion) {
Expand Down Expand Up @@ -36,12 +40,18 @@ export const syncVersions = (argv: YargsConfig<typeof config.syncSchema>, opts:
const targetVersions = opts.targetVersions ?? utils.pnpm.versions(allPackages)

for (const { path: pkgPath, content } of allPackages) {
const { dependencies, devDependencies } = utils.pkgjson.read(pkgPath)
const { dependencies, devDependencies, peerDependencies } = content

const update = updater(content)
const updatedDeps = dependencies && update(dependencies, targetVersions)
const updatedDevDeps = devDependencies && update(devDependencies, targetVersions)

utils.pkgjson.update(pkgPath, { dependencies: updatedDeps, devDependencies: updatedDevDeps })
const updatedDeps = update(dependencies, targetVersions)
const updatedPeerDeps = update(peerDependencies, targetVersions)
const updatedDevDeps = argv.ignoreDev ? devDependencies : update(devDependencies, targetVersions)

utils.pkgjson.update(pkgPath, {
dependencies: updatedDeps,
devDependencies: updatedDevDeps,
peerDependencies: updatedPeerDeps
})
}
}
16 changes: 9 additions & 7 deletions depsynky/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ const defaultOptions = {
rootDir: {
type: 'string',
default: process.cwd()
},
ignoreDev: {
type: 'boolean',
description: 'Ignore dev dependencies',
default: false
}
} satisfies YargsSchema

Expand All @@ -15,15 +20,12 @@ export const bumpSchema = {
}
} satisfies YargsSchema

export const syncSchema = defaultOptions satisfies YargsSchema
export const syncSchema = {
...defaultOptions
} satisfies YargsSchema

export const checkSchema = {
...defaultOptions,
ignoreDev: {
type: 'boolean',
description: 'Ignore dev dependencies',
default: false
}
...defaultOptions
} satisfies YargsSchema

export const listSchema = defaultOptions satisfies YargsSchema
1 change: 1 addition & 0 deletions depsynky/src/utils/pkgjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type PackageJson = {
private?: boolean
dependencies?: Record<string, string>
devDependencies?: Record<string, string>
peerDependencies?: Record<string, string>
}

export const read = (filePath: string): PackageJson => {
Expand Down
Loading