mirror of
https://github.com/pnpm/pnpm.git
synced 2026-02-02 03:02:49 -05:00
refactor!: read-modules-yaml
This commit is contained in:
5
.changeset/fluffy-paws-repair.md
Normal file
5
.changeset/fluffy-paws-repair.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/modules-yaml": major
|
||||
---
|
||||
|
||||
Export readModulesManifest and writeModulesManifest instead of read and write.
|
||||
@@ -34,7 +34,7 @@ import { writePnpFile } from '@pnpm/lockfile-to-pnp'
|
||||
import { extendProjectsWithTargetDirs } from '@pnpm/lockfile-utils'
|
||||
import { logger, globalInfo, streamParser } from '@pnpm/logger'
|
||||
import { getAllDependenciesFromManifest } from '@pnpm/manifest-utils'
|
||||
import { write as writeModulesYaml } from '@pnpm/modules-yaml'
|
||||
import { writeModulesManifest } from '@pnpm/modules-yaml'
|
||||
import { readModulesDir } from '@pnpm/read-modules-dir'
|
||||
import { safeReadProjectManifestOnly } from '@pnpm/read-project-manifest'
|
||||
import { removeBin } from '@pnpm/remove-bins'
|
||||
@@ -1081,7 +1081,7 @@ const _installInContext: InstallFunction = async (projects, ctx, opts) => {
|
||||
injectedDeps[project.id] = project.targetDirs.map((targetDir) => path.relative(opts.lockfileDir, targetDir))
|
||||
}
|
||||
}
|
||||
return writeModulesYaml(ctx.rootModulesDir, {
|
||||
return writeModulesManifest(ctx.rootModulesDir, {
|
||||
...ctx.modulesFile,
|
||||
hoistedDependencies: result.newHoistedDependencies,
|
||||
hoistPattern: ctx.hoistPattern,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import path from 'path'
|
||||
import { write as writeModulesYaml } from '@pnpm/modules-yaml'
|
||||
import { writeModulesManifest } from '@pnpm/modules-yaml'
|
||||
import { prepareEmpty } from '@pnpm/prepare'
|
||||
import {
|
||||
addDependenciesToPackage,
|
||||
@@ -34,7 +34,7 @@ test('the modules cache is pruned when it expires', async () => {
|
||||
const prunedAt = new Date()
|
||||
prunedAt.setMinutes(prunedAt.getMinutes() - 3)
|
||||
modulesFile!.prunedAt = prunedAt.toString()
|
||||
await writeModulesYaml(path.resolve('node_modules'), modulesFile as any) // eslint-disable-line
|
||||
await writeModulesManifest(path.resolve('node_modules'), modulesFile as any) // eslint-disable-line
|
||||
|
||||
await addDependenciesToPackage(manifest,
|
||||
['is-negative@2.0.0'],
|
||||
@@ -72,7 +72,7 @@ test('the modules cache is pruned when it expires and headless install is used',
|
||||
const prunedAt = new Date()
|
||||
prunedAt.setMinutes(prunedAt.getMinutes() - 3)
|
||||
modulesFile!.prunedAt = prunedAt.toString()
|
||||
await writeModulesYaml(path.resolve('node_modules'), modulesFile as any) // eslint-disable-line
|
||||
await writeModulesManifest(path.resolve('node_modules'), modulesFile as any) // eslint-disable-line
|
||||
|
||||
await install(manifest, await testDefaults({ frozenLockfile: true, modulesCacheMaxAge: 2 }))
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
nameVerFromPkgSnapshot,
|
||||
pkgSnapshotToResolution,
|
||||
} from '@pnpm/lockfile-utils'
|
||||
import { read as readModulesYaml } from '@pnpm/modules-yaml'
|
||||
import { readModulesManifest } from '@pnpm/modules-yaml'
|
||||
import { normalizeRegistries } from '@pnpm/normalize-registries'
|
||||
import { readModulesDir } from '@pnpm/read-modules-dir'
|
||||
import { safeReadPackageJsonFromDir } from '@pnpm/read-package-json'
|
||||
@@ -61,7 +61,7 @@ export async function buildDependenciesHierarchy (
|
||||
throw new TypeError('opts.lockfileDir is required')
|
||||
}
|
||||
const modulesDir = await realpathMissing(path.join(maybeOpts.lockfileDir, 'node_modules'))
|
||||
const modules = await readModulesYaml(modulesDir)
|
||||
const modules = await readModulesManifest(modulesDir)
|
||||
const registries = normalizeRegistries({
|
||||
...maybeOpts?.registries,
|
||||
...modules?.registries,
|
||||
|
||||
@@ -46,7 +46,7 @@ import {
|
||||
import { prune } from '@pnpm/modules-cleaner'
|
||||
import {
|
||||
IncludedDependencies,
|
||||
write as writeModulesYaml,
|
||||
writeModulesManifest,
|
||||
} from '@pnpm/modules-yaml'
|
||||
import { HoistingLimits } from '@pnpm/real-hoist'
|
||||
import { readPackageJsonFromDir } from '@pnpm/read-package-json'
|
||||
@@ -515,7 +515,7 @@ export async function headlessInstall (opts: HeadlessOptions) {
|
||||
injectedDeps[project.id] = project.targetDirs.map((targetDir) => path.relative(opts.lockfileDir, targetDir))
|
||||
}
|
||||
}
|
||||
await writeModulesYaml(rootModulesDir, {
|
||||
await writeModulesManifest(rootModulesDir, {
|
||||
hoistedDependencies: newHoistedDependencies,
|
||||
hoistPattern: opts.hoistPattern,
|
||||
included: opts.include,
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
} from '@pnpm/core-loggers'
|
||||
import { headlessInstall } from '@pnpm/headless'
|
||||
import { readWantedLockfile } from '@pnpm/lockfile-file'
|
||||
import { read as readModulesYaml } from '@pnpm/modules-yaml'
|
||||
import { readModulesManifest } from '@pnpm/modules-yaml'
|
||||
import { tempDir } from '@pnpm/prepare'
|
||||
import { getIntegrity, REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
|
||||
import { fixtures } from '@pnpm/test-fixtures'
|
||||
@@ -341,7 +341,7 @@ test('run pre/postinstall scripts', async () => {
|
||||
expect(await exists(path.join(prefix, 'output.json'))).toBeFalsy()
|
||||
|
||||
const nmPath = path.join(prefix, 'node_modules')
|
||||
const modulesYaml = await readModulesYaml(nmPath)
|
||||
const modulesYaml = await readModulesManifest(nmPath)
|
||||
expect(modulesYaml).toBeTruthy()
|
||||
expect(modulesYaml!.pendingBuilds).toStrictEqual(['.', '/@pnpm.e2e/pre-and-postinstall-scripts-example/1.0.0'])
|
||||
})
|
||||
|
||||
@@ -31,7 +31,7 @@ export interface Modules {
|
||||
injectedDeps?: Record<string, string[]>
|
||||
}
|
||||
|
||||
export async function read (modulesDir: string): Promise<Modules | null> {
|
||||
export async function readModulesManifest (modulesDir: string): Promise<Modules | null> {
|
||||
const modulesYamlPath = path.join(modulesDir, MODULES_FILENAME)
|
||||
let modules!: Modules
|
||||
try {
|
||||
@@ -90,7 +90,7 @@ const YAML_OPTS = {
|
||||
sortKeys: true,
|
||||
}
|
||||
|
||||
export async function write (
|
||||
export async function writeModulesManifest (
|
||||
modulesDir: string,
|
||||
modules: Modules & { registries: Registries }
|
||||
) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/// <reference path="../../../typings/index.d.ts"/>
|
||||
import path from 'path'
|
||||
import { read, write } from '@pnpm/modules-yaml'
|
||||
import { readModulesManifest, writeModulesManifest } from '@pnpm/modules-yaml'
|
||||
import readYamlFile from 'read-yaml-file'
|
||||
import isWindows from 'is-windows'
|
||||
import tempy from 'tempy'
|
||||
|
||||
test('write() and read()', async () => {
|
||||
test('writeModulesManifest() and readModulesManifest()', async () => {
|
||||
const modulesDir = tempy.directory()
|
||||
const modulesYaml = {
|
||||
hoistedDependencies: {},
|
||||
@@ -27,8 +27,8 @@ test('write() and read()', async () => {
|
||||
storeDir: '/.pnpm-store',
|
||||
virtualStoreDir: path.join(modulesDir, '.pnpm'),
|
||||
}
|
||||
await write(modulesDir, modulesYaml)
|
||||
expect(await read(modulesDir)).toEqual(modulesYaml)
|
||||
await writeModulesManifest(modulesDir, modulesYaml)
|
||||
expect(await readModulesManifest(modulesDir)).toEqual(modulesYaml)
|
||||
|
||||
const raw = await readYamlFile<object>(path.join(modulesDir, '.modules.yaml'))
|
||||
expect(raw['virtualStoreDir']).toBeDefined()
|
||||
@@ -36,7 +36,7 @@ test('write() and read()', async () => {
|
||||
})
|
||||
|
||||
test('backward compatible read of .modules.yaml created with shamefully-hoist=true', async () => {
|
||||
const modulesYaml = await read(path.join(__dirname, 'fixtures/old-shamefully-hoist'))
|
||||
const modulesYaml = await readModulesManifest(path.join(__dirname, 'fixtures/old-shamefully-hoist'))
|
||||
if (modulesYaml == null) {
|
||||
fail('modulesYaml was nullish')
|
||||
}
|
||||
@@ -49,7 +49,7 @@ test('backward compatible read of .modules.yaml created with shamefully-hoist=tr
|
||||
})
|
||||
|
||||
test('backward compatible read of .modules.yaml created with shamefully-hoist=false', async () => {
|
||||
const modulesYaml = await read(path.join(__dirname, 'fixtures/old-no-shamefully-hoist'))
|
||||
const modulesYaml = await readModulesManifest(path.join(__dirname, 'fixtures/old-no-shamefully-hoist'))
|
||||
if (modulesYaml == null) {
|
||||
fail('modulesYaml was nullish')
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
readWantedLockfile,
|
||||
} from '@pnpm/lockfile-file'
|
||||
import { createMatcher } from '@pnpm/matcher'
|
||||
import { read as readModulesManifest } from '@pnpm/modules-yaml'
|
||||
import { readModulesManifest } from '@pnpm/modules-yaml'
|
||||
import {
|
||||
IncludedDependencies,
|
||||
ProjectManifest,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { PnpmError } from '@pnpm/error'
|
||||
import { readProjects } from '@pnpm/filter-workspace-packages'
|
||||
import { Lockfile } from '@pnpm/lockfile-types'
|
||||
import * as modulesYaml from '@pnpm/modules-yaml'
|
||||
import { readModulesManifest } from '@pnpm/modules-yaml'
|
||||
import { install, update } from '@pnpm/plugin-commands-installation'
|
||||
import { preparePackages } from '@pnpm/prepare'
|
||||
import { addDistTag } from '@pnpm/registry-mock'
|
||||
@@ -114,7 +114,7 @@ test('recursive update prod dependencies only', async () => {
|
||||
).toStrictEqual(
|
||||
['/@pnpm.e2e/bar/100.0.0', '/@pnpm.e2e/foo/100.1.0']
|
||||
)
|
||||
const modules = await modulesYaml.read('./node_modules')
|
||||
const modules = await readModulesManifest('./node_modules')
|
||||
expect(modules?.included).toStrictEqual({
|
||||
dependencies: true,
|
||||
devDependencies: true,
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
} from '@pnpm/lockfile-utils'
|
||||
import { lockfileWalker, LockfileWalkerStep } from '@pnpm/lockfile-walker'
|
||||
import { logger, streamParser } from '@pnpm/logger'
|
||||
import { write as writeModulesYaml } from '@pnpm/modules-yaml'
|
||||
import { writeModulesManifest } from '@pnpm/modules-yaml'
|
||||
import { createOrConnectStoreController } from '@pnpm/store-connection-manager'
|
||||
import { ProjectManifest } from '@pnpm/types'
|
||||
import * as dp from 'dependency-path'
|
||||
@@ -175,7 +175,7 @@ export async function rebuildProjects (
|
||||
}
|
||||
}
|
||||
|
||||
await writeModulesYaml(ctx.rootModulesDir, {
|
||||
await writeModulesManifest(ctx.rootModulesDir, {
|
||||
prunedAt: new Date().toUTCString(),
|
||||
...ctx.modulesFile,
|
||||
hoistedDependencies: ctx.hoistedDependencies,
|
||||
|
||||
@@ -3,7 +3,7 @@ import path from 'path'
|
||||
import { LOCKFILE_VERSION, WANTED_LOCKFILE } from '@pnpm/constants'
|
||||
import { findWorkspacePackages } from '@pnpm/find-workspace-packages'
|
||||
import { Lockfile } from '@pnpm/lockfile-types'
|
||||
import { read as readModulesManifest } from '@pnpm/modules-yaml'
|
||||
import { readModulesManifest } from '@pnpm/modules-yaml'
|
||||
import {
|
||||
prepare,
|
||||
prepareEmpty,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import path from 'path'
|
||||
import { getLockfileImporterId } from '@pnpm/lockfile-file'
|
||||
import { Modules, read as readModulesYaml } from '@pnpm/modules-yaml'
|
||||
import { Modules, readModulesManifest } from '@pnpm/modules-yaml'
|
||||
import { normalizeRegistries } from '@pnpm/normalize-registries'
|
||||
import { DependenciesField, HoistedDependencies, Registries } from '@pnpm/types'
|
||||
import realpathMissing from 'realpath-missing'
|
||||
@@ -34,7 +34,7 @@ export async function readProjectsContext<T> (
|
||||
}> {
|
||||
const relativeModulesDir = opts.modulesDir ?? 'node_modules'
|
||||
const rootModulesDir = await realpathMissing(path.join(opts.lockfileDir, relativeModulesDir))
|
||||
const modules = await readModulesYaml(rootModulesDir)
|
||||
const modules = await readModulesManifest(rootModulesDir)
|
||||
return {
|
||||
currentHoistPattern: modules?.hoistPattern,
|
||||
currentPublicHoistPattern: modules?.publicHoistPattern,
|
||||
|
||||
@@ -2,7 +2,7 @@ import path from 'path'
|
||||
import { assertStore } from '@pnpm/assert-store'
|
||||
import { WANTED_LOCKFILE } from '@pnpm/constants'
|
||||
import { Lockfile, ProjectSnapshot } from '@pnpm/lockfile-types'
|
||||
import { Modules, read as readModules } from '@pnpm/modules-yaml'
|
||||
import { Modules, readModulesManifest } from '@pnpm/modules-yaml'
|
||||
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
|
||||
import readYamlFile from 'read-yaml-file'
|
||||
import exists from 'path-exists'
|
||||
@@ -58,7 +58,7 @@ export function assertProject (projectPath: string, encodedRegistryName?: string
|
||||
}
|
||||
async function getStoreInstance () {
|
||||
if (!cachedStore) {
|
||||
const modulesYaml = await readModules(modules)
|
||||
const modulesYaml = await readModulesManifest(modules)
|
||||
if (modulesYaml == null) {
|
||||
throw new Error(`Cannot find module store. No .modules.yaml found at "${modules}"`)
|
||||
}
|
||||
@@ -71,7 +71,7 @@ export function assertProject (projectPath: string, encodedRegistryName?: string
|
||||
return cachedStore
|
||||
}
|
||||
async function getVirtualStoreDir () {
|
||||
const modulesYaml = await readModules(modules)
|
||||
const modulesYaml = await readModulesManifest(modules)
|
||||
if (modulesYaml == null) {
|
||||
return path.join(modules, '.pnpm')
|
||||
}
|
||||
@@ -142,7 +142,7 @@ export function assertProject (projectPath: string, encodedRegistryName?: string
|
||||
throw err
|
||||
}
|
||||
},
|
||||
readModulesManifest: async () => readModules(modules),
|
||||
readModulesManifest: async () => readModulesManifest(modules),
|
||||
async readLockfile (lockfileName: string = WANTED_LOCKFILE) {
|
||||
try {
|
||||
return await readYamlFile(path.join(projectPath, lockfileName))
|
||||
|
||||
Reference in New Issue
Block a user