Skip to content

Commit

Permalink
feat(depsynky): allow ignoring dev dependencies (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
franklevasseur committed Apr 12, 2024
1 parent e980ce8 commit fb3a6fe
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
* @botpress/cloud-services

const @botpress/cloud-services

entities @franklevasseur
depsynky @franklevasseur
es-node @franklevasseur
expresso @franklevasseur
jex @franklevasseur
Expand Down
2 changes: 1 addition & 1 deletion depsynky/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bpinternal/depsynky",
"version": "0.0.1",
"version": "0.0.2",
"description": "CLI to synchronize dependencies accross a pnpm mono-repo",
"main": "dist/index.js",
"scripts": {
Expand Down
9 changes: 6 additions & 3 deletions depsynky/src/commands/check-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ export type CheckVersionsOpts = {
targetVersions: Record<string, string>
}

const LOCAL_VERSION = 'workspace:*'

const checker =
(pkg: utils.pkgjson.PackageJson) => (current: Record<string, string>, target: Record<string, string>) => {
for (const [name, version] of utils.objects.entries(target)) {
const currentVersion = current[name]
if (!currentVersion) {
continue
}
const isLocal = currentVersion === LOCAL_VERSION
const isLocal = utils.pnpm.isLocalVersion(currentVersion)
const isPublic = !pkg.private
if (isPublic && isLocal) {
throw new errors.DepSynkyError(
Expand All @@ -42,6 +40,11 @@ export const checkVersions = (argv: YargsConfig<typeof config.checkSchema>, opts

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

if (argv.ignoreDev) {
continue
}

devDependencies && check(devDependencies, targetVersions)
}

Expand Down
3 changes: 1 addition & 2 deletions depsynky/src/commands/sync-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ export type SyncVersionsOpts = {
targetVersions: Record<string, string>
}

const LOCAL_VERSION = 'workspace:*'
const updater =
(pkg: utils.pkgjson.PackageJson) => (current: Record<string, string>, target: Record<string, string>) => {
for (const [name, version] of utils.objects.entries(target)) {
const currentVersion = current[name]
if (!currentVersion) {
continue
}
const isLocal = currentVersion === LOCAL_VERSION
const isLocal = utils.pnpm.isLocalVersion(currentVersion)
const isPublic = !pkg.private
if (!isLocal) {
current[name] = version
Expand Down
17 changes: 12 additions & 5 deletions depsynky/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@ import { YargsSchema } from '@bpinternal/yargs-extra'
const defaultOptions = {
rootDir: {
type: 'string',
default: process.cwd(),
},
default: process.cwd()
}
} satisfies YargsSchema

export const bumpSchema = {
...defaultOptions,
sync: {
type: 'boolean',
default: true,
},
default: true
}
} satisfies YargsSchema

export const syncSchema = defaultOptions satisfies YargsSchema

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

export const listSchema = defaultOptions satisfies YargsSchema
1 change: 1 addition & 0 deletions depsynky/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ process.on('unhandledRejection', onError)
process.on('uncaughtException', onError)

void yargs
.scriptName('depsynky')
.command(
'bump [package]',
'Bump version of a package',
Expand Down
2 changes: 2 additions & 0 deletions depsynky/src/utils/pnpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ export const listPublicPackages = (rootDir: string): string[] => {
const workspaces = searchWorkspaces(rootDir)
return workspaces.filter((w) => !w.content.private).map((w) => w.content.name)
}

export const isLocalVersion = (version: string) => version.startsWith('workspace:')

0 comments on commit fb3a6fe

Please sign in to comment.