MCPcopy
hub / github.com/antfu-collective/taze / loadPackages

Function loadPackages

src/io/packages.ts:92–180  ·  view source on GitHub ↗
(options: CommonOptions)

Source from the content-addressed store, hash-verified

90}
91
92export async function loadPackages(options: CommonOptions): Promise<PackageMeta[]> {
93 let packagesNames: string[] = []
94
95 const cwd = resolve(options.cwd || process.cwd())
96 const filter = createDependenciesFilter(options.include, options.exclude)
97
98 if (options.recursive) {
99 // Look for both package.yaml and package.json files
100 const yamlPackages = await glob('**/package.yaml', {
101 ignore: DEFAULT_IGNORE_PATHS.concat(options.ignorePaths || []),
102 cwd: options.cwd,
103 onlyFiles: true,
104 dot: false,
105 expandDirectories: false,
106 })
107
108 const jsonPackages = await glob('**/package.json', {
109 ignore: DEFAULT_IGNORE_PATHS.concat(options.ignorePaths || []),
110 cwd: options.cwd,
111 onlyFiles: true,
112 dot: false,
113 expandDirectories: false,
114 })
115
116 // Prioritize package.yaml over package.json in the same directory
117 const packageDirs = new Set<string>()
118
119 // Add all package.yaml files first (higher priority)
120 for (const yamlPkg of yamlPackages) {
121 packagesNames.push(yamlPkg)
122 const dir = dirname(yamlPkg)
123 packageDirs.add(dir)
124 }
125
126 // Add package.json files only if no package.yaml exists in the same directory
127 for (const jsonPkg of jsonPackages) {
128 const dir = dirname(jsonPkg)
129 if (!packageDirs.has(dir)) {
130 packagesNames.push(jsonPkg)
131 }
132 }
133 }
134 else {
135 packagesNames = await glob('package.{yaml,json}', { cwd })
136 }
137
138 packagesNames = packagesNames.sort((a, b) => a.localeCompare(b))
139
140 if (options.ignoreOtherWorkspaces) {
141 packagesNames = (await Promise.all(
142 packagesNames.map(async (packagePath) => {
143 if (!packagePath.includes('/'))
144 return [packagePath]
145
146 const absolute = join(cwd, packagePath)
147 const gitDir = findUp('.git', { cwd: absolute, last: cwd })
148 if (gitDir && dirname(gitDir) !== cwd)
149 return []

Callers 1

CheckPackagesFunction · 0.90

Calls 2

createDependenciesFilterFunction · 0.90
loadPackageFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…