Skip to content

Commit cc4df77

Browse files
committedFeb 18, 2025
feat: introduce ignoreOtherWorkspaces and enable by default
1 parent c305650 commit cc4df77

13 files changed

+71
-27
lines changed
 

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ export default defineConfig({
9797
'**/node_modules/**',
9898
'**/test/**',
9999
],
100+
// ignore package.json that in other workspaces (with their own .git,pnpm-workspace.yaml,etc.)
101+
ignoreOtherWorkspaces: true,
100102
// override with different bumping mode for each package
101103
packageMode: {
102104
'typescript': 'major',

‎package.json

+2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
},
3636
"dependencies": {
3737
"@antfu/ni": "^23.3.1",
38+
"find-up-simple": "^1.0.0",
3839
"ofetch": "^1.4.1",
3940
"package-manager-detector": "^0.2.9",
41+
"pathe": "^2.0.3",
4042
"tinyexec": "^0.3.2",
4143
"unconfig": "^7.0.0",
4244
"yaml": "^2.7.0",

‎pnpm-lock.yaml

+25-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/cli.ts

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ function commonOptions(args: Argv<object>): Argv<CommonOptions> {
4848
type: 'string',
4949
describe: 'ignore paths for search package.json',
5050
})
51+
.option('ignore-other-workspaces', {
52+
type: 'boolean',
53+
default: true,
54+
describe: 'ignore package.json that in other workspaces (with their own .git,pnpm-workspace.yaml,etc.)',
55+
})
5156
.option('include', {
5257
alias: 'n',
5358
type: 'string',

‎src/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const DEFAULT_COMMON_OPTIONS: CommonOptions = {
2020
recursive: false,
2121
force: false,
2222
ignorePaths: '',
23+
ignoreOtherWorkspaces: true,
2324
include: '',
2425
exclude: '',
2526
depFields: {},

‎src/io/packageJson.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CommonOptions, PackageMeta, RawDep } from '../types'
2-
import path from 'node:path'
2+
import { resolve } from 'pathe'
33
import { builtinAddons } from '../addons'
44
import { dumpDependencies, getByPath, parseDependencies, parseDependency, setByPath } from './dependencies'
55
import { readJSON, writeJSON } from './packages'
@@ -19,7 +19,7 @@ export async function loadPackageJSON(
1919
options: CommonOptions,
2020
shouldUpdate: (name: string) => boolean,
2121
): Promise<PackageMeta[]> {
22-
const filepath = path.resolve(options.cwd ?? '', relative)
22+
const filepath = resolve(options.cwd ?? '', relative)
2323
const raw = await readJSON(filepath)
2424
const deps: RawDep[] = []
2525

‎src/io/packages.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type { CommonOptions, PackageMeta } from '../types'
22
import { existsSync, promises as fs } from 'node:fs'
3-
import path from 'node:path'
3+
import process from 'node:process'
44
import detectIndent from 'detect-indent'
55
import fg from 'fast-glob'
6+
import { findUp } from 'find-up-simple'
7+
import { dirname, join, resolve } from 'pathe'
68
import { DEFAULT_IGNORE_PATHS } from '../constants'
79
import { createDependenciesFilter } from '../utils/dependenciesFilter'
810
import { loadPackageJSON, writePackageJSON } from './packageJson'
@@ -46,6 +48,7 @@ export async function loadPackage(
4648
export async function loadPackages(options: CommonOptions): Promise<PackageMeta[]> {
4749
let packagesNames: string[] = []
4850

51+
const cwd = resolve(options.cwd || process.cwd())
4952
const filter = createDependenciesFilter(options.include, options.exclude)
5053

5154
if (options.recursive) {
@@ -61,7 +64,25 @@ export async function loadPackages(options: CommonOptions): Promise<PackageMeta[
6164
packagesNames = ['package.json']
6265
}
6366

64-
if (existsSync(path.join(options.cwd || '', 'pnpm-workspace.yaml'))) {
67+
if (options.ignoreOtherWorkspaces) {
68+
packagesNames = (await Promise.all(
69+
packagesNames.map(async (packagePath) => {
70+
if (!packagePath.includes('/'))
71+
return [packagePath]
72+
73+
const absolute = join(cwd, packagePath)
74+
const gitDir = await findUp('.git', { cwd: absolute, stopAt: cwd })
75+
if (gitDir && dirname(gitDir) !== cwd)
76+
return []
77+
const pnpmWorkspace = await findUp('pnpm-workspace.yaml', { cwd: absolute, stopAt: cwd })
78+
if (pnpmWorkspace && dirname(pnpmWorkspace) !== cwd)
79+
return []
80+
return [packagePath]
81+
}),
82+
)).flat()
83+
}
84+
85+
if (existsSync(join(cwd, 'pnpm-workspace.yaml'))) {
6586
packagesNames.unshift('pnpm-workspace.yaml')
6687
}
6788

‎src/io/pnpmWorkspaces.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { Scalar } from 'yaml'
22
import type { CommonOptions, PnpmWorkspaceMeta, RawDep } from '../types'
33
import fs from 'node:fs/promises'
4-
import path from 'node:path'
54
import _debug from 'debug'
5+
import { resolve } from 'pathe'
66
import { isAlias, parse, parseDocument, YAMLMap } from 'yaml'
77
import { findAnchor, writeYaml } from '../utils/yaml'
88
import { dumpDependencies, parseDependency } from './dependencies'
@@ -14,7 +14,7 @@ export async function loadPnpmWorkspace(
1414
options: CommonOptions,
1515
shouldUpdate: (name: string) => boolean,
1616
): Promise<PnpmWorkspaceMeta[]> {
17-
const filepath = path.resolve(options.cwd ?? '', relative)
17+
const filepath = resolve(options.cwd ?? '', relative)
1818
const rawText = await fs.readFile(filepath, 'utf-8')
1919
const raw = parse(rawText)
2020
const document = parseDocument(rawText)

‎src/io/resolves.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { CheckOptions, DependencyFilter, DependencyResolvedCallback, DiffType, PackageData, PackageMeta, RangeMode, RawDep, ResolvedDepChange } from '../types'
22
import { existsSync, promises as fs, lstatSync } from 'node:fs'
33
import os from 'node:os'
4-
import { resolve } from 'node:path'
54
import _debug from 'debug'
65
import pLimit from 'p-limit'
6+
import { resolve } from 'pathe'
77
import semver from 'semver'
88
import { diffSorter } from '../filters/diff-sorter'
99
import { getPackageMode } from '../utils/config'

‎src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export interface CommonOptions {
6363
cwd?: string
6464
recursive?: boolean
6565
ignorePaths?: string | string[]
66+
ignoreOtherWorkspaces?: boolean
6667
include?: string | string[]
6768
exclude?: string | string[]
6869
loglevel?: LogLevel

‎src/utils/npm.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// ported from: https://github.com/raineorshine/npm-check-updates/blob/master/lib/package-managers/npm.js
22

33
import type { Recordable } from '@npmcli/config'
4-
import path from 'node:path'
54
import process from 'node:process'
5+
import { dirname, join } from 'pathe'
66

77
async function _getNpmConfig() {
88
const { default: NpmCliConfig } = await import('@npmcli/config')
99
const npmcliConfig = new NpmCliConfig({
1010
definitions: {},
11-
npmPath: path.dirname(process.cwd()),
11+
npmPath: dirname(process.cwd()),
1212
flatten: (current, total) => {
1313
Object.assign(total, current)
1414
},
@@ -24,8 +24,8 @@ async function _getNpmConfig() {
2424
if (cli)
2525
cli.data[key] = value
2626
}
27-
setCliOption('userconfig', path.join(npmcliConfig.home, '.npmrc'))
28-
setCliOption('globalconfig', path.join(npmcliConfig.globalPrefix, 'etc', 'npmrc'))
27+
setCliOption('userconfig', join(npmcliConfig.home, '.npmrc'))
28+
setCliOption('globalconfig', join(npmcliConfig.globalPrefix, 'etc', 'npmrc'))
2929
}
3030

3131
// npmcliConfig.load() would set unnecessary environment variables

‎test/cli.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import path from 'node:path'
1+
import { resolve } from 'pathe'
22
import { exec } from 'tinyexec'
33
import { expect, it } from 'vitest'
44

55
it('taze cli should just works', async () => {
6-
const binPath = path.resolve(__dirname, '../bin/taze.mjs')
6+
const binPath = resolve(__dirname, '../bin/taze.mjs')
77

88
const proc = await exec(process.execPath, [binPath], { throwOnError: true })
99

‎test/packageConfig.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CheckOptions, CommonOptions, ResolvedDepChange } from '../src'
2-
import { join } from 'node:path'
32
import process from 'node:process'
3+
import { join } from 'pathe'
44
import { describe, expect, it } from 'vitest'
55
import { CheckPackages } from '../src'
66
import { resolveConfig } from '../src/config'

0 commit comments

Comments
 (0)
Please sign in to comment.