'use strict'; var glob = require('@techor/glob'); var extend = require('@techor/extend'); var fs = require('@techor/fs'); var path = require('path'); var fs$1 = require('fs'); var yaml = require('js-yaml'); var log = require('@techor/log'); function readWorkspaces(options) { const pkg = fs.readJSONFileSync(path.resolve(options?.cwd || '', './package.json')); return pkg ? pkg?.workspaces || [] : undefined // package.json does not exist ; } function queryWorkspaces(patterns, options) { options = extend({ ignore: [ '**/node_modules/**' ] }, options); patterns = patterns?.length ? patterns : readWorkspaces(options); return patterns?.length ? glob.explorePathsSync(patterns.map((eachWorkspace)=>eachWorkspace + '/package.json'), options).map((eachWorkspace)=>eachWorkspace.replace('/package.json', '')) : []; } function readPNPMWorkspaces(options) { const pnpmWorkspaceContent = fs$1.readFileSync(path.resolve(options?.cwd || '', './pnpm-workspace.yaml')); if (pnpmWorkspaceContent) { const pnpmWorkspaceJSON = yaml.load(pnpmWorkspaceContent); return pnpmWorkspaceJSON.packages || []; } else { return undefined // pnpm-workspace.yaml does not exist ; } } function readWorkspacePackages(patterns = [], options) { const workspaces = queryWorkspaces(patterns, options); return workspaces.length ? workspaces.map((eachWorkspace)=>fs.readJSONFileSync(path.join(options?.cwd || '', eachWorkspace, 'package.json'))) : []; } function explorePackageManager(options) { if (fs$1.existsSync(path.resolve(options?.cwd || '', './pnpm-workspace.yaml'))) { log.info`pnpm-workspace.yaml is detected`; return 'pnpm'; } else if (fs$1.existsSync(path.resolve(options?.cwd || '', './package.json'))) { log.info`package.json is detected`; return 'npm'; } } exports.explorePackageManager = explorePackageManager; exports.queryWorkspaces = queryWorkspaces; exports.readPNPMWorkspaces = readPNPMWorkspaces; exports.readWorkspacePackages = readWorkspacePackages; exports.readWorkspaces = readWorkspaces;