1
1
import type { CommonOptions , PackageMeta } from '../types'
2
2
import { existsSync , promises as fs } from 'node:fs'
3
- import path from 'node:path '
3
+ import process from 'node:process '
4
4
import detectIndent from 'detect-indent'
5
5
import fg from 'fast-glob'
6
+ import { findUp } from 'find-up-simple'
7
+ import { dirname , join , resolve } from 'pathe'
6
8
import { DEFAULT_IGNORE_PATHS } from '../constants'
7
9
import { createDependenciesFilter } from '../utils/dependenciesFilter'
8
10
import { loadPackageJSON , writePackageJSON } from './packageJson'
@@ -46,6 +48,7 @@ export async function loadPackage(
46
48
export async function loadPackages ( options : CommonOptions ) : Promise < PackageMeta [ ] > {
47
49
let packagesNames : string [ ] = [ ]
48
50
51
+ const cwd = resolve ( options . cwd || process . cwd ( ) )
49
52
const filter = createDependenciesFilter ( options . include , options . exclude )
50
53
51
54
if ( options . recursive ) {
@@ -61,7 +64,25 @@ export async function loadPackages(options: CommonOptions): Promise<PackageMeta[
61
64
packagesNames = [ 'package.json' ]
62
65
}
63
66
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' ) ) ) {
65
86
packagesNames . unshift ( 'pnpm-workspace.yaml' )
66
87
}
67
88
0 commit comments