Skip to content

Commit

Permalink
refactor: use Object.fromEntries instead of Ramda.fromPairs
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed Dec 21, 2022
1 parent c9d3970 commit 7030cc2
Show file tree
Hide file tree
Showing 21 changed files with 24 additions and 51 deletions.
3 changes: 1 addition & 2 deletions config/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { createMatcher } from '@pnpm/matcher'
import camelcase from 'camelcase'
import isWindows from 'is-windows'
import normalizeRegistryUrl from 'normalize-registry-url'
import fromPairs from 'ramda/src/fromPairs'
import realpathMissing from 'realpath-missing'
import pathAbsolute from 'path-absolute'
import which from 'which'
Expand Down Expand Up @@ -244,7 +243,7 @@ export async function getConfig (

const rcOptions = Object.keys(rcOptionsTypes)

const pnpmConfig: ConfigWithDeprecatedSettings = fromPairs([
const pnpmConfig: ConfigWithDeprecatedSettings = Object.fromEntries([
...rcOptions.map((configKey) => [camelcase(configKey), npmConfig.get(configKey)]) as any, // eslint-disable-line
...Object.entries(cliOptions).filter(([name, value]) => typeof value !== 'undefined').map(([name, value]) => [camelcase(name), value]),
]) as unknown as ConfigWithDeprecatedSettings
Expand Down
4 changes: 1 addition & 3 deletions fetching/directory-fetcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@
"@pnpm/fetcher-base": "workspace:*",
"@pnpm/read-project-manifest": "workspace:*",
"@pnpm/resolver-base": "workspace:*",
"npm-packlist": "^5.1.3",
"ramda": "npm:@pnpm/ramda@0.28.1"
"npm-packlist": "^5.1.3"
},
"devDependencies": {
"@pnpm/directory-fetcher": "workspace:*",
"@pnpm/test-fixtures": "workspace:*",
"@types/npm-packlist": "^3.0.0",
"@types/ramda": "0.28.20",
"@zkochan/rimraf": "^2.1.2"
},
"exports": {
Expand Down
3 changes: 1 addition & 2 deletions fetching/directory-fetcher/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from 'path'
import type { DirectoryFetcher, DirectoryFetcherOptions } from '@pnpm/fetcher-base'
import { logger } from '@pnpm/logger'
import { safeReadProjectManifestOnly } from '@pnpm/read-project-manifest'
import fromPairs from 'ramda/src/fromPairs'
import packlist from 'npm-packlist'

const directoryFetcherLogger = logger('directory-fetcher')
Expand Down Expand Up @@ -128,7 +127,7 @@ async function fetchPackageFilesFromDir (
opts: FetchFromDirOpts
) {
const files = await packlist({ path: dir })
const filesIndex: Record<string, string> = fromPairs(files.map((file) => [file, path.join(dir, file)]))
const filesIndex: Record<string, string> = Object.fromEntries(files.map((file) => [file, path.join(dir, file)]))
if (opts.manifest) {
// In a regular pnpm workspace it will probably never happen that a dependency has no package.json file.
// Safe read was added to support the Bit workspace in which the components have no package.json files.
Expand Down
3 changes: 1 addition & 2 deletions hooks/read-package-hook/src/createReadPackageHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
ProjectManifest,
ReadPackageHook,
} from '@pnpm/types'
import fromPairs from 'ramda/src/fromPairs'
import isEmpty from 'ramda/src/isEmpty'
import pipeWith from 'ramda/src/pipeWith'
import { createPackageExtender } from './createPackageExtender'
Expand All @@ -32,7 +31,7 @@ export function createReadPackageHook (
): ReadPackageHook | undefined {
const hooks: ReadPackageHook[] = []
if (!ignoreCompatibilityDb) {
hooks.push(createPackageExtender(fromPairs(compatPackageExtensions)))
hooks.push(createPackageExtender(Object.fromEntries(compatPackageExtensions)))
}
if (!isEmpty(packageExtensions ?? {})) {
hooks.push(createPackageExtender(packageExtensions!))
Expand Down
3 changes: 1 addition & 2 deletions lockfile/filter-lockfile/src/filterLockfile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Lockfile } from '@pnpm/lockfile-types'
import { DependenciesField } from '@pnpm/types'
import fromPairs from 'ramda/src/fromPairs'
import mapValues from 'ramda/src/map'
import { filterImporter } from './filterImporter'

Expand All @@ -25,6 +24,6 @@ export function filterLockfile (
return {
...lockfile,
importers: mapValues((importer) => filterImporter(importer, opts.include), lockfile.importers),
packages: fromPairs(pairs),
packages: Object.fromEntries(pairs),
}
}
3 changes: 1 addition & 2 deletions lockfile/lockfile-utils/src/extendProjectsWithTargetDirs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from 'path'
import { Lockfile } from '@pnpm/lockfile-types'
import { depPathToFilename } from '@pnpm/dependency-path'
import fromPairs from 'ramda/src/fromPairs'

type GetLocalLocations = (depPath: string, pkgName: string) => string[]

Expand All @@ -17,7 +16,7 @@ export function extendProjectsWithTargetDirs<T> (
? (depPath: string) => ctx.pkgLocationsByDepPath![depPath]
: (depPath: string, pkgName: string) => [path.join(ctx.virtualStoreDir, depPathToFilename(depPath), 'node_modules', pkgName)]
const projectsById: Record<string, T & { id: string, targetDirs: string[], stages?: string[] }> =
fromPairs(projects.map((project) => [project.id, { ...project, targetDirs: [] as string[] }]))
Object.fromEntries(projects.map((project) => [project.id, { ...project, targetDirs: [] as string[] }]))
Object.entries(lockfile.packages ?? {})
.forEach(([depPath, pkg]) => {
if (pkg.resolution?.['type'] !== 'directory') return
Expand Down
5 changes: 2 additions & 3 deletions lockfile/plugin-commands-audit/src/fix.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AuditReport, AuditAdvisory } from '@pnpm/audit'
import { readProjectManifest } from '@pnpm/read-project-manifest'
import { difference } from 'ramda'
import fromPairs from 'ramda/src/fromPairs'
import difference from 'ramda/src/difference'

export async function fix (dir: string, auditReport: AuditReport) {
const { manifest, writeProjectManifest } = await readProjectManifest(dir)
Expand All @@ -24,7 +23,7 @@ function createOverrides (advisories: AuditAdvisory[], ignoreCves?: string[]) {
if (ignoreCves) {
advisories = advisories.filter(({ cves }) => difference(cves, ignoreCves).length > 0)
}
return fromPairs(
return Object.fromEntries(
advisories
.filter(({ vulnerable_versions, patched_versions }) => vulnerable_versions !== '>=0.0.0' && patched_versions !== '<0.0.0') // eslint-disable-line
.map((advisory) => [
Expand Down
3 changes: 1 addition & 2 deletions pkg-manager/core/src/install/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import pFilter from 'p-filter'
import pLimit from 'p-limit'
import pMapValues from 'p-map-values'
import flatten from 'ramda/src/flatten'
import fromPairs from 'ramda/src/fromPairs'
import mapValues from 'ramda/src/map'
import equals from 'ramda/src/equals'
import isEmpty from 'ramda/src/isEmpty'
Expand Down Expand Up @@ -918,7 +917,7 @@ const _installInContext: InstallFunction = async (projects, ctx, opts) => {
)
await finishLockfileUpdates()
if (opts.enablePnp) {
const importerNames = fromPairs(
const importerNames = Object.fromEntries(
projects.map(({ manifest, id }) => [id, manifest.name ?? id])
)
await writePnpFile(result.currentLockfile, {
Expand Down
5 changes: 2 additions & 3 deletions pkg-manager/core/src/install/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
} from '@pnpm/types'
import pLimit from 'p-limit'
import pathExists from 'path-exists'
import fromPairs from 'ramda/src/fromPairs'
import equals from 'ramda/src/equals'
import isEmpty from 'ramda/src/isEmpty'
import difference from 'ramda/src/difference'
Expand Down Expand Up @@ -99,7 +98,7 @@ export async function linkPackages (
if (!opts.include.optionalDependencies) {
depNodes = depNodes.filter(({ optional }) => !optional)
}
depGraph = fromPairs(depNodes.map((depNode) => [depNode.depPath, depNode]))
depGraph = Object.fromEntries(depNodes.map((depNode) => [depNode.depPath, depNode]))
const removedDepPaths = await prune(projects, {
currentLockfile: opts.currentLockfile,
hoistedDependencies: opts.hoistedDependencies,
Expand Down Expand Up @@ -159,7 +158,7 @@ export async function linkPackages (
})

if (opts.symlink) {
const projectsToLink = fromPairs(await Promise.all(
const projectsToLink = Object.fromEntries(await Promise.all(
projects.map(async ({ id, manifest, modulesDir, rootDir }) => {
const deps = opts.dependenciesByProjectId[id]
const importerFromLockfile = newCurrentLockfile.importers[id]
Expand Down
3 changes: 1 addition & 2 deletions pkg-manager/get-context/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import rimraf from '@zkochan/rimraf'
import pathAbsolute from 'path-absolute'
import clone from 'ramda/src/clone'
import equals from 'ramda/src/equals'
import fromPairs from 'ramda/src/fromPairs'
import { checkCompatibility } from './checkCompatibility'
import { UnexpectedStoreError } from './checkCompatibility/UnexpectedStoreError'
import { UnexpectedVirtualStoreDirError } from './checkCompatibility/UnexpectedVirtualStoreDirError'
Expand Down Expand Up @@ -160,7 +159,7 @@ export async function getContext (
lockfileDir: opts.lockfileDir,
modulesFile: importersContext.modules,
pendingBuilds: importersContext.pendingBuilds,
projects: fromPairs(importersContext.projects.map((project) => [project.rootDir, project])),
projects: Object.fromEntries(importersContext.projects.map((project) => [project.rootDir, project])),
publicHoistPattern: importersContext.currentPublicHoistPattern ?? opts.publicHoistPattern,
registries: {
...opts.registries,
Expand Down
5 changes: 2 additions & 3 deletions pkg-manager/headless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import * as dp from '@pnpm/dependency-path'
import pLimit from 'p-limit'
import pathAbsolute from 'path-absolute'
import equals from 'ramda/src/equals'
import fromPairs from 'ramda/src/fromPairs'
import isEmpty from 'ramda/src/isEmpty'
import omit from 'ramda/src/omit'
import pick from 'ramda/src/pick'
Expand Down Expand Up @@ -302,7 +301,7 @@ export async function headlessInstall (opts: HeadlessOptions) {
)
)
if (opts.enablePnp) {
const importerNames = fromPairs(
const importerNames = Object.fromEntries(
selectedProjects.map(({ manifest, id }) => [id, manifest.name ?? id])
)
await writePnpFile(filteredLockfile, {
Expand Down Expand Up @@ -594,7 +593,7 @@ async function symlinkDirectDependencies (
})
})
if (symlink !== false) {
const projectsToLink = fromPairs(await Promise.all(
const projectsToLink = Object.fromEntries(await Promise.all(
projects.map(async ({ rootDir, id, modulesDir }) => ([id, {
dir: rootDir,
modulesDir,
Expand Down
3 changes: 1 addition & 2 deletions pkg-manager/headless/test/utils/testDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { safeReadPackageJsonFromDir } from '@pnpm/read-package-json'
import { readProjectsContext } from '@pnpm/read-projects-context'
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
import { getStorePath } from '@pnpm/store-path'
import fromPairs from 'ramda/src/fromPairs'
import tempy from 'tempy'

const registry = `http://localhost:${REGISTRY_MOCK_PORT}/`
Expand Down Expand Up @@ -76,7 +75,7 @@ export async function testDefaults (
},
pendingBuilds,
selectedProjectDirs: opts.selectedProjectDirs ?? projects.map((project) => project.rootDir),
allProjects: fromPairs(
allProjects: Object.fromEntries(
await Promise.all(projects.map(async (project) => [project.rootDir, { ...project, manifest: await safeReadPackageJsonFromDir(project.rootDir) }]))
),
rawConfig: {},
Expand Down
3 changes: 1 addition & 2 deletions pkg-manager/link-bins/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import isWindows from 'is-windows'
import normalizePath from 'normalize-path'
import pSettle from 'p-settle'
import { KeyValuePair } from 'ramda'
import fromPairs from 'ramda/src/fromPairs'
import isEmpty from 'ramda/src/isEmpty'
import unnest from 'ramda/src/unnest'
import partition from 'ramda/src/partition'
Expand Down Expand Up @@ -124,7 +123,7 @@ async function _linkBins (

const results1 = await pSettle(cmdsWithOwnName.map(async (cmd) => linkBin(cmd, binsDir, opts)))

const usedNames = fromPairs(cmdsWithOwnName.map((cmd) => [cmd.name, cmd.name] as KeyValuePair<string, string>))
const usedNames = Object.fromEntries(cmdsWithOwnName.map((cmd) => [cmd.name, cmd.name] as KeyValuePair<string, string>))
const results2 = await pSettle(cmdsWithOtherNames.map(async (cmd) => {
if (usedNames[cmd.name]) {
binsConflictLogger.debug({
Expand Down
3 changes: 1 addition & 2 deletions pkg-manager/modules-yaml/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from 'path'
import { DependenciesField, HoistedDependencies, Registries } from '@pnpm/types'
import readYamlFile from 'read-yaml-file'
import fromPairs from 'ramda/src/fromPairs'
import mapValues from 'ramda/src/map'
import isWindows from 'is-windows'
import writeYamlFile from 'write-yaml-file'
Expand Down Expand Up @@ -57,7 +56,7 @@ export async function readModulesManifest (modulesDir: string): Promise<Modules
}
if ((modules.hoistedAliases != null) && !modules.hoistedDependencies) {
modules.hoistedDependencies = mapValues(
(aliases) => fromPairs(aliases.map((alias) => [alias, 'public'])),
(aliases) => Object.fromEntries(aliases.map((alias) => [alias, 'public'])),
modules.hoistedAliases
)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg-manager/plugin-commands-installation/src/import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { logger } from '@pnpm/logger'
import { sequenceGraph } from '@pnpm/sort-packages'
import rimraf from '@zkochan/rimraf'
import loadJsonFile from 'load-json-file'
import fromPairs from 'ramda/src/fromPairs'
import mapValues from 'ramda/src/map'
import renderHelp from 'render-help'
import { parse as parseYarnLock } from '@yarnpkg/lockfile'
Expand Down Expand Up @@ -227,7 +226,7 @@ async function readNpmLockfile (dir: string) {

function getPreferredVersions (versionsByPackageNames: Record<string, Set<string>>) {
const preferredVersions = mapValues(
(versions) => fromPairs(Array.from(versions).map((version) => [version, 'version'])),
(versions) => Object.fromEntries(Array.from(versions).map((version) => [version, 'version'])),
versionsByPackageNames
)
return preferredVersions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ReadPackageHook,
Registries,
} from '@pnpm/types'
import fromPairs from 'ramda/src/fromPairs'
import partition from 'ramda/src/partition'
import zipObj from 'ramda/src/zipObj'
import { WantedDependency } from './getNonDevWantedDependencies'
Expand Down Expand Up @@ -154,7 +153,7 @@ export async function resolveDependencyTree<T> (
}
return {
updatePackageManifest: importer.updatePackageManifest,
parentPkgAliases: fromPairs(
parentPkgAliases: Object.fromEntries(
importer.wantedDependencies.filter(({ alias }) => alias).map(({ alias }) => [alias, true])
) as ParentPkgAliases,
preferredVersions: importer.preferredVersions ?? {},
Expand Down
5 changes: 2 additions & 3 deletions pkg-manager/resolve-dependencies/src/resolvePeers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '@pnpm/types'
import { depPathToFilename, createPeersFolderSuffix } from '@pnpm/dependency-path'
import { KeyValuePair } from 'ramda'
import fromPairs from 'ramda/src/fromPairs'
import isEmpty from 'ramda/src/isEmpty'
import mapValues from 'ramda/src/map'
import pick from 'ramda/src/pick'
Expand Down Expand Up @@ -117,7 +116,7 @@ function createPkgsByName<T extends PartialResolvedPackage> (
}
) {
return Object.assign(
fromPairs(
Object.fromEntries(
topParents.map(({ name, version, linkedDir }): KeyValuePair<string, ParentRef> => [
name,
{
Expand Down Expand Up @@ -215,7 +214,7 @@ function resolvePeersOfNode<T extends PartialResolvedPackage> (
ctx.depGraph[hit.depPath].depth = Math.min(ctx.depGraph[hit.depPath].depth, node.depth)
return {
missingPeers: hit.missingPeers,
resolvedPeers: fromPairs(hit.resolvedPeers),
resolvedPeers: Object.fromEntries(hit.resolvedPeers),
}
}

Expand Down
3 changes: 1 addition & 2 deletions pkg-manager/resolve-dependencies/src/updateLockfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import * as dp from '@pnpm/dependency-path'
import getNpmTarballUrl from 'get-npm-tarball-url'
import { KeyValuePair } from 'ramda'
import isEmpty from 'ramda/src/isEmpty'
import fromPairs from 'ramda/src/fromPairs'
import mergeRight from 'ramda/src/mergeRight'
import partition from 'ramda/src/partition'
import { depPathToRef } from './depPathToRef'
Expand Down Expand Up @@ -199,7 +198,7 @@ function updateResolvedDeps (
registries: Registries,
depGraph: DependenciesGraph
) {
const newResolvedDeps = fromPairs<string>(
const newResolvedDeps = Object.fromEntries(
updatedDeps
.map(({ alias, depPath }): KeyValuePair<string, string> => {
if (depPath.startsWith('link:')) {
Expand Down
6 changes: 0 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pnpm/src/getOptionType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import nopt from '@pnpm/nopt'
import fromPairs from 'ramda/src/fromPairs'
import omit from 'ramda/src/omit'

export interface CompletionCtx {
Expand Down Expand Up @@ -42,7 +41,7 @@ function getOptionType (
shorthands: Record<string, string | string[]>,
option: string
) {
const allBools = fromPairs(Object.keys(optionTypes).map((optionName) => [optionName, Boolean]))
const allBools = Object.fromEntries(Object.keys(optionTypes).map((optionName) => [optionName, Boolean]))
const result = omit(['argv'], nopt(allBools, shorthands, [option], 0))
return optionTypes[Object.entries(result)[0]?.[0]]
}
Expand Down
3 changes: 1 addition & 2 deletions releasing/plugin-commands-publishing/src/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import realpathMissing from 'realpath-missing'
import renderHelp from 'render-help'
import tar from 'tar-stream'
import packlist from 'npm-packlist'
import fromPairs from 'ramda/src/fromPairs'
import { runScriptsIfPresent } from './publish'

const LICENSE_GLOB = 'LICEN{S,C}E{,.*}'
Expand Down Expand Up @@ -95,7 +94,7 @@ export async function handler (
}
const tarballName = `${manifest.name.replace('@', '').replace('/', '-')}-${manifest.version}.tgz`
const files = await packlist({ path: dir })
const filesMap: Record<string, string> = fromPairs(files.map((file) => [`package/${file}`, path.join(dir, file)]))
const filesMap: Record<string, string> = Object.fromEntries(files.map((file) => [`package/${file}`, path.join(dir, file)]))
if (opts.workspaceDir != null && dir !== opts.workspaceDir && !files.some((file) => /LICEN[CS]E(\..+)?/i.test(file))) {
const licenses = await findLicenses({ cwd: opts.workspaceDir })
for (const license of licenses) {
Expand Down

0 comments on commit 7030cc2

Please sign in to comment.