/** * @license * Copyright 2026 Qwen Team * SPDX-License-Identifier: Apache-2.0 */ import { globSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; function toGlobPath(filePath) { return filePath.replaceAll('\\', '/'); } export function getWorkspacePackageJsonPaths(root, workspaces) { const packageJsonPaths = new Set(); for (const workspace of workspaces) { const isExcluded = workspace.startsWith('!'); const pattern = toGlobPath(isExcluded ? workspace.slice(1) : workspace); const matches = globSync(`${pattern}/package.json`, { cwd: root }); for (const match of matches) { const packageJsonPath = toGlobPath(match); if (isExcluded) { packageJsonPaths.delete(packageJsonPath); } else { packageJsonPaths.add(packageJsonPath); } } } return [...packageJsonPaths].sort(); } export function getTestCiWorkspacePackageJsonPaths(root) { const { workspaces } = JSON.parse( readFileSync(join(root, 'package.json'), 'utf8'), ); return getWorkspacePackageJsonPaths(root, workspaces).filter( (packageJsonPath) => { const { scripts } = JSON.parse( readFileSync(join(root, packageJsonPath), 'utf8'), ); return Boolean(scripts?.['test:ci']); }, ); }