Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dedupe/check/src/dedupeDiffCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ function diffSnapshots<TSnapshot> (
continue
}

const updates = fields.reduce((acc: ResolutionChangesByAlias, dependencyField) => ({
...acc,
...getResolutionUpdates(prevSnapshot[dependencyField] ?? {}, nextSnapshot[dependencyField] ?? {}),
}), {})
const updates: ResolutionChangesByAlias = {}
for (const dependencyField of fields) {
Object.assign(updates, getResolutionUpdates(prevSnapshot[dependencyField] ?? {}, nextSnapshot[dependencyField] ?? {}))
}

if (Object.keys(updates).length > 0) {
updated[id] = updates
Expand Down
8 changes: 5 additions & 3 deletions env/plugin-commands-env/src/envList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ async function listLocalVersions (opts: NvmNodeCommandOptions): Promise<LocalVer
}
const { nodeLink } = await getNodeExecPathAndTargetDir(opts.pnpmHomeDir)
const nodeVersionDirs = await fs.readdir(nodeBaseDir)
return nodeVersionDirs.reduce(({ currentVersion, versions }, nodeVersion) => {
let currentVersion: string | undefined
const versions: string[] = []
for (const nodeVersion of nodeVersionDirs) {
const nodeVersionDir = path.join(nodeBaseDir, nodeVersion)
const nodeExec = getNodeExecPathInNodeDir(nodeVersionDir)
if (nodeLink?.startsWith(nodeVersionDir)) {
Expand All @@ -42,8 +44,8 @@ async function listLocalVersions (opts: NvmNodeCommandOptions): Promise<LocalVer
if (semver.valid(nodeVersion) && existsSync(nodeExec)) {
versions.push(nodeVersion)
}
return { currentVersion, versions }
}, { currentVersion: undefined, versions: [] } as LocalVersions)
}
return { currentVersion, versions }
}

async function listRemoteVersions (opts: NvmNodeCommandOptions, versionSpec?: string): Promise<string[]> {
Expand Down
7 changes: 4 additions & 3 deletions exec/plugin-commands-script-runners/src/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ export async function writeRecursiveSummary (opts: { dir: string, summary: Recur
}

export function createEmptyRecursiveSummary (chunks: string[][]): RecursiveSummary {
return chunks.flat().reduce<RecursiveSummary>((acc, prefix) => {
const acc: RecursiveSummary = {}
for (const prefix of chunks.flat()) {
acc[prefix] = { status: 'queued' }
return acc
}, {})
}
return acc
}

export function getExecutionDuration (start: [number, number]): number {
Expand Down
8 changes: 4 additions & 4 deletions lockfile/filtering/src/filterLockfileByImporters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ export function filterLockfileByImporters (
)
}

const importers = importerIds.reduce((acc, importerId) => {
acc[importerId] = filterImporter(lockfile.importers[importerId], opts.include)
return acc
}, { ...lockfile.importers })
const importers = { ...lockfile.importers }
for (const importerId of importerIds) {
importers[importerId] = filterImporter(lockfile.importers[importerId], opts.include)
}

return {
...lockfile,
Expand Down
29 changes: 16 additions & 13 deletions lockfile/filtering/src/filterLockfileByImportersAndEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,21 @@ interface ParsedDepRefs {
}

function parseDepRefs (refsByPkgNames: Array<[string, string]>, lockfile: Lockfile): ParsedDepRefs {
return refsByPkgNames
.reduce((acc, [pkgName, ref]) => {
if (ref.startsWith('link:')) {
const importerId = ref.substring(5) as ProjectId
if (lockfile.importers[importerId]) {
acc.importerIds.push(importerId)
}
return acc
const acc: ParsedDepRefs = {
depPaths: [],
importerIds: [],
}
for (const [pkgName, ref] of refsByPkgNames) {
if (ref.startsWith('link:')) {
const importerId = ref.substring(5) as ProjectId
if (lockfile.importers[importerId]) {
acc.importerIds.push(importerId)
}
const depPath = dp.refToRelative(ref, pkgName)
if (depPath == null) return acc
acc.depPaths.push(depPath)
return acc
}, { depPaths: [], importerIds: [] } as ParsedDepRefs)
continue
}
const depPath = dp.refToRelative(ref, pkgName)
if (depPath == null) continue
acc.depPaths.push(depPath)
}
return acc
}
8 changes: 4 additions & 4 deletions lockfile/fs/src/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ export function createLockfileObject (
peersSuffixMaxLength: number
}
): Lockfile {
const importers = importerIds.reduce((acc, importerId) => {
acc[importerId] = {
const importers: Lockfile['importers'] = {}
for (const importerId of importerIds) {
importers[importerId] = {
dependencies: {},
specifiers: {},
}
return acc
}, {} as Lockfile['importers'])
}
return {
importers,
lockfileVersion: opts.lockfileVersion || LOCKFILE_VERSION,
Expand Down
15 changes: 7 additions & 8 deletions packages/render-peer-issues/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ export function renderPeerIssues (
if (allowedVersionsMatchAll[peerName]?.some((range) => semver.satisfies(issue.foundVersion, range))) continue
const currentParentPkg = issue.parents.at(-1)
if (currentParentPkg && allowedVersionsByParentPkgName[peerName]?.[currentParentPkg.name]) {
const allowedVersionsByParent = allowedVersionsByParentPkgName[peerName][currentParentPkg.name]
.reduce((acc, { targetPkg, parentPkg, ranges }) => {
if (!parentPkg.pref || currentParentPkg.version &&
(isSubRange(parentPkg.pref, currentParentPkg.version) || semver.satisfies(currentParentPkg.version, parentPkg.pref))) {
acc[targetPkg.name] = ranges
}
return acc
}, {} as Record<string, string[]>)
const allowedVersionsByParent: Record<string, string[]> = {}
for (const { targetPkg, parentPkg, ranges } of allowedVersionsByParentPkgName[peerName][currentParentPkg.name]) {
if (!parentPkg.pref || currentParentPkg.version &&
(isSubRange(parentPkg.pref, currentParentPkg.version) || semver.satisfies(currentParentPkg.version, parentPkg.pref))) {
allowedVersionsByParent[targetPkg.name] = ranges
}
}
if (allowedVersionsByParent[peerName]?.some((range) => semver.satisfies(issue.foundVersion, range))) continue
}
createTree(projects[projectId], issue.parents, formatUnmetPeerMessage({
Expand Down
14 changes: 7 additions & 7 deletions pkg-manager/core/src/install/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1279,13 +1279,13 @@ const _installInContext: InstallFunction = async (projects, ctx, opts) => {
await Promise.all(projects.map(async (project, index) => {
let linkedPackages!: string[]
if (ctx.publicHoistPattern?.length && path.relative(project.rootDir, opts.lockfileDir) === '') {
const nodeExecPathByAlias = Object.entries(project.manifest.dependenciesMeta ?? {})
.reduce((prev, [alias, { node }]) => {
if (node) {
prev[alias] = node
}
return prev
}, {} as Record<string, string>)
const nodeExecPathByAlias: Record<string, string> = {}
for (const alias in project.manifest.dependenciesMeta) {
const { node } = project.manifest.dependenciesMeta[alias]
if (node) {
nodeExecPathByAlias[alias] = node
}
}
linkedPackages = await linkBins(project.modulesDir, project.binsDir, {
allowExoticManifests: true,
preferSymlinkedExecutables: opts.preferSymlinkedExecutables,
Expand Down
22 changes: 12 additions & 10 deletions pkg-manager/headless/src/lockfileToHoistedDepGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ async function _lockfileToHoistedDepGraph (
}

function directDepsMap (directDepDirs: string[], graph: DependenciesGraph): Record<string, string> {
return directDepDirs.reduce((acc, dir) => {
const acc: Record<string, string> = {}
for (const dir of directDepDirs) {
acc[graph[dir].alias!] = dir
return acc
}, {} as Record<string, string>)
}
return acc
}

function pickLinkedDirectDeps (
Expand All @@ -142,13 +143,14 @@ function pickLinkedDirectDeps (
...(include.dependencies ? importer.dependencies : {}),
...(include.optionalDependencies ? importer.optionalDependencies : {}),
}
return Object.entries(rootDeps)
.reduce((directDeps, [alias, ref]) => {
if (ref.startsWith('link:')) {
directDeps[alias] = path.resolve(importerDir, ref.slice(5))
}
return directDeps
}, {} as Record<string, string>)
const directDeps: Record<string, string> = {}
for (const alias in rootDeps) {
const ref = rootDeps[alias]
if (ref.startsWith('link:')) {
directDeps[alias] = path.resolve(importerDir, ref.slice(5))
}
}
return directDeps
}

async function fetchDeps (
Expand Down
7 changes: 4 additions & 3 deletions pkg-manager/modules-cleaner/src/prune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,12 @@ function getPkgsDepPaths (
packages: PackageSnapshots,
skipped: Set<string>
): Record<DepPath, string> {
return Object.entries(packages).reduce((acc, [depPath, pkg]) => {
const acc: Record<DepPath, string> = {}
for (const [depPath, pkg] of Object.entries(packages)) {
if (skipped.has(depPath)) return acc
acc[depPath as DepPath] = packageIdFromSnapshot(depPath as DepPath, pkg)
return acc
}, {} as Record<DepPath, string>)
}
return acc
}

function getPkgsDepPathsOwnedOnlyByImporters (
Expand Down
7 changes: 4 additions & 3 deletions pkg-manager/plugin-commands-installation/src/recursive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,11 @@ function getAllProjects (manifestsByPath: ManifestsByPath, allProjectsGraph: Pro
interface ManifestsByPath { [dir: string]: Omit<Project, 'rootDir' | 'rootDirRealPath'> }

function getManifestsByPath (projects: Project[]): Record<ProjectRootDir, Omit<Project, 'rootDir' | 'rootDirRealPath'>> {
return projects.reduce((manifestsByPath, { rootDir, manifest, writeProjectManifest }) => {
const manifestsByPath: Record<string, Omit<Project, 'rootDir' | 'rootDirRealPath'>> = {}
for (const { rootDir, manifest, writeProjectManifest } of projects) {
manifestsByPath[rootDir] = { manifest, writeProjectManifest }
return manifestsByPath
}, {} as Record<string, Omit<Project, 'rootDir' | 'rootDirRealPath'>>)
}
return manifestsByPath
}

function getImporters (opts: Pick<RecursiveOptions, 'selectedProjectsGraph' | 'ignoredPackages'>): Array<{ rootDir: ProjectRootDir, rootDirRealPath: ProjectRootDirRealPath }> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ export function getUpdateChoices (outdatedPkgsOfProjects: OutdatedPackage[], wor
// returns only the keys that are true
const header: string[] = Object.keys(pickBy(and, headerRow))

return Object.entries(groupPkgsByType).reduce((finalChoices: ChoiceGroup, [depGroup, choiceRows]) => {
if (choiceRows.length === 0) {
return finalChoices
}
const finalChoices: ChoiceGroup = []
for (const [depGroup, choiceRows] of Object.entries(groupPkgsByType)) {
if (choiceRows.length === 0) continue

const rawChoices = choiceRows.map(choice => buildPkgChoice(choice, workspacesEnabled))
// add in a header row for each group
Expand Down Expand Up @@ -79,9 +78,8 @@ export function getUpdateChoices (outdatedPkgsOfProjects: OutdatedPackage[], wor
// we rename it here to "[dependencies]" or "[devDependencies]",
// which will be filtered out in the format function of the prompt.
finalChoices.push({ name: `[${depGroup}]`, choices, message: depGroup })

return finalChoices
}, [])
}
return finalChoices
}

function buildPkgChoice (outdatedPkg: OutdatedPackage, workspacesEnabled: boolean): { raw: string[], name: string, disabled?: boolean } {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ export function updateToWorkspacePackagesFromManifest (
...(include.dependencies ? manifest.dependencies : {}),
...(include.optionalDependencies ? manifest.optionalDependencies : {}),
} as Record<string, string>
const updateSpecs = Object.keys(allDeps).reduce((acc: string[], depName) => {
if (workspacePackages.has(depName)) {
acc.push(`${depName}@workspace:*`)
}
return acc
}, [])
return updateSpecs
return Object.keys(allDeps)
.filter(depName => workspacePackages.has(depName))
.map(depName => `${depName}@workspace:*`)
}

export function createWorkspaceSpecs (specs: string[], workspacePackages: WorkspacePackages): string[] {
Expand Down
8 changes: 4 additions & 4 deletions pkg-manager/resolve-dependencies/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,10 @@ function addDirectDependenciesToLockfile (
newProjectSnapshot.specifiers[linkedPkg.alias] = getSpecFromPackageManifest(newManifest, linkedPkg.alias)
})

const directDependenciesByAlias = directDependencies.reduce((acc, directDependency) => {
acc[directDependency.alias] = directDependency
return acc
}, {} as Record<string, ResolvedDirectDependency>)
const directDependenciesByAlias: Record<string, ResolvedDirectDependency> = {}
for (const directDependency of directDependencies) {
directDependenciesByAlias[directDependency.alias] = directDependency
}

const allDeps = Array.from(new Set(Object.keys(getAllDependenciesFromManifest(newManifest))))

Expand Down
41 changes: 21 additions & 20 deletions pkg-manager/resolve-dependencies/src/toResolveImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,26 @@ function getPreferredVersionsFromPackage (
type VersionSpecsByRealNames = Record<string, Record<string, 'version' | 'range' | 'tag'>>

function getVersionSpecsByRealNames (deps: Dependencies): VersionSpecsByRealNames {
return Object.entries(deps)
.reduce((acc, [depName, currentPref]) => {
if (currentPref.startsWith('npm:')) {
const pref = currentPref.slice(4)
const index = pref.lastIndexOf('@')
const spec = pref.slice(index + 1)
const selector = getVerSelType(spec)
if (selector != null) {
const pkgName = pref.substring(0, index)
acc[pkgName] = acc[pkgName] || {}
acc[pkgName][selector.normalized] = selector.type
}
} else if (!currentPref.includes(':')) { // we really care only about semver specs
const selector = getVerSelType(currentPref)
if (selector != null) {
acc[depName] = acc[depName] || {}
acc[depName][selector.normalized] = selector.type
}
const acc: VersionSpecsByRealNames = {}
for (const depName in deps) {
const currentPref = deps[depName]
if (currentPref.startsWith('npm:')) {
const pref = currentPref.slice(4)
const index = pref.lastIndexOf('@')
const spec = pref.slice(index + 1)
const selector = getVerSelType(spec)
if (selector != null) {
const pkgName = pref.substring(0, index)
acc[pkgName] = acc[pkgName] || {}
acc[pkgName][selector.normalized] = selector.type
}
return acc
}, {} as VersionSpecsByRealNames)
} else if (!currentPref.includes(':')) { // we really care only about semver specs
const selector = getVerSelType(currentPref)
if (selector != null) {
acc[depName] = acc[depName] || {}
acc[depName][selector.normalized] = selector.type
}
}
}
return acc
}
8 changes: 4 additions & 4 deletions resolving/git-resolver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ async function getRepoRefs (repo: string, ref: string | null): Promise<Record<st
}
// graceful-git by default retries 10 times, reduce to single retry
const result = await git(['ls-remote', ...gitArgs], { retries: 1 })
const refs: Record<string, string> = result.stdout.split('\n').reduce((obj: Record<string, string>, line: string) => {
const refs: Record<string, string> = {}
for (const line of result.stdout.split('\n')) {
const [commit, refName] = line.split('\t')
obj[refName] = commit
return obj
}, {})
refs[refName] = commit
}
return refs
}

Expand Down
10 changes: 3 additions & 7 deletions reviewing/license-scanner/src/getPkgInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,9 @@ function coerceToString (field: unknown): string | null {
function parseLicenseManifestField (field: unknown): string {
if (Array.isArray(field)) {
const licenses = field
const licenseTypes = licenses.reduce((listOfLicenseTypes, license) => {
const type = coerceToString(license.type) ?? coerceToString(license.name)
if (type) {
listOfLicenseTypes.push(type)
}
return listOfLicenseTypes
}, [])
const licenseTypes = licenses
.map(license => coerceToString(license.type) ?? coerceToString(license.name))
.filter((licenseType): licenseType is string => !!licenseType)

if (licenseTypes.length > 1) {
const combinedLicenseTypes = licenseTypes.join(' OR ') as string
Expand Down
8 changes: 5 additions & 3 deletions store/plugin-commands-store-inspecting/src/findHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export async function handler (opts: FindHashCommandOptions, params: string[]):
)
}

return result.reduce((acc, { name, version, filesIndexFile }) => {
acc += `${PACKAGE_INFO_CLR(name)}@${PACKAGE_INFO_CLR(version)} ${INDEX_PATH_CLR(filesIndexFile)}\n`; return acc
}, '')
let acc = ''
for (const { name, version, filesIndexFile } of result) {
acc += `${PACKAGE_INFO_CLR(name)}@${PACKAGE_INFO_CLR(version)} ${INDEX_PATH_CLR(filesIndexFile)}\n`
}
return acc
}