mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-15 12:38:45 -04:00
## Summary Rename all internal packages so their npm names follow the `@pnpm/<domain>.<leaf>` convention, matching their directory structure. Also rename directories to remove redundancy and improve clarity. ### Bulk rename (94 packages) All `@pnpm/` packages now derive their name from their directory path using dot-separated segments. Exceptions: `packages/`, `__utils__/`, and `pnpm/artifacts/` keep leaf names only. ### Directory renames (removing redundant prefixes) - `cli/cli-meta` → `cli/meta`, `cli/cli-utils` → `cli/utils` - `config/config` → `config/reader`, `config/config-writer` → `config/writer` - `fetching/fetching-types` → `fetching/types` - `lockfile/lockfile-to-pnp` → `lockfile/to-pnp` - `store/store-connection-manager` → `store/connection-manager` - `store/store-controller-types` → `store/controller-types` - `store/store-path` → `store/path` ### Targeted renames (clarity improvements) - `deps/dependency-path` → `deps/path` (`@pnpm/deps.path`) - `deps/calc-dep-state` → `deps/graph-hasher` (`@pnpm/deps.graph-hasher`) - `deps/inspection/dependencies-hierarchy` → `deps/inspection/tree-builder` (`@pnpm/deps.inspection.tree-builder`) - `bins/link-bins` → `bins/linker`, `bins/remove-bins` → `bins/remover`, `bins/package-bins` → `bins/resolver` - `installing/get-context` → `installing/context` - `store/package-store` → `store/controller` - `pkg-manifest/manifest-utils` → `pkg-manifest/utils` ### Manifest reader/writer renames - `workspace/read-project-manifest` → `workspace/project-manifest-reader` (`@pnpm/workspace.project-manifest-reader`) - `workspace/write-project-manifest` → `workspace/project-manifest-writer` (`@pnpm/workspace.project-manifest-writer`) - `workspace/read-manifest` → `workspace/workspace-manifest-reader` (`@pnpm/workspace.workspace-manifest-reader`) - `workspace/manifest-writer` → `workspace/workspace-manifest-writer` (`@pnpm/workspace.workspace-manifest-writer`) ### Workspace package renames - `workspace/find-packages` → `workspace/projects-reader` - `workspace/find-workspace-dir` → `workspace/root-finder` - `workspace/resolve-workspace-range` → `workspace/range-resolver` - `workspace/filter-packages-from-dir` merged into `workspace/filter-workspace-packages` → `workspace/projects-filter` ### Domain moves - `pkg-manifest/read-project-manifest` → `workspace/project-manifest-reader` - `pkg-manifest/write-project-manifest` → `workspace/project-manifest-writer` - `pkg-manifest/exportable-manifest` → `releasing/exportable-manifest` ### Scope - 1206 files changed - Updated: package.json names/deps, TypeScript imports, tsconfig references, changeset files, renovate.json, test fixtures, import ordering
251 lines
6.7 KiB
TypeScript
251 lines
6.7 KiB
TypeScript
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
import { jest } from '@jest/globals'
|
|
import { LOCKFILE_VERSION, WANTED_LOCKFILE } from '@pnpm/constants'
|
|
import { prepareEmpty, preparePackages } from '@pnpm/prepare'
|
|
import type { ProjectManifest, ProjectRootDir } from '@pnpm/types'
|
|
import { writeYamlFileSync } from 'write-yaml-file'
|
|
|
|
import { testDefaults } from '../utils/index.js'
|
|
|
|
jest.unstable_mockModule('@pnpm/network.git-utils', () => ({ getCurrentBranch: jest.fn() }))
|
|
|
|
const { getCurrentBranch } = await import('@pnpm/network.git-utils')
|
|
const { install, mutateModules } = await import('@pnpm/installing.deps-installer')
|
|
|
|
test('install with git-branch-lockfile = true', async () => {
|
|
prepareEmpty()
|
|
|
|
const branchName: string = 'main-branch'
|
|
jest.mocked(getCurrentBranch).mockReturnValue(Promise.resolve(branchName))
|
|
|
|
const opts = testDefaults({
|
|
useGitBranchLockfile: true,
|
|
})
|
|
|
|
await install({
|
|
dependencies: {
|
|
'is-positive': '^3.0.0',
|
|
},
|
|
}, opts)
|
|
|
|
expect(fs.existsSync(`pnpm-lock.${branchName}.yaml`)).toBe(true)
|
|
expect(fs.existsSync(WANTED_LOCKFILE)).toBe(false)
|
|
})
|
|
|
|
test('install with git-branch-lockfile = true and no lockfile changes', async () => {
|
|
prepareEmpty()
|
|
|
|
const branchName: string = 'main-branch'
|
|
jest.mocked(getCurrentBranch).mockReturnValue(Promise.resolve(branchName))
|
|
|
|
const manifest: ProjectManifest = {
|
|
dependencies: {
|
|
'is-positive': '^3.0.0',
|
|
},
|
|
}
|
|
|
|
const opts1 = testDefaults({
|
|
useGitBranchLockfile: false,
|
|
})
|
|
await install(manifest, opts1)
|
|
|
|
expect(fs.existsSync(WANTED_LOCKFILE)).toBe(true)
|
|
|
|
const opts2 = testDefaults({
|
|
useGitBranchLockfile: true,
|
|
})
|
|
await install(manifest, opts2)
|
|
expect(fs.existsSync(WANTED_LOCKFILE)).toBe(true)
|
|
// Git branch lockfile is created only if there are changes in the lockfile
|
|
expect(fs.existsSync(`pnpm-lock.${branchName}.yaml`)).toBe(false)
|
|
})
|
|
|
|
test('install a workspace with git-branch-lockfile = true', async () => {
|
|
const rootManifest: ProjectManifest = {
|
|
name: 'root',
|
|
}
|
|
const project1Manifest: ProjectManifest = {
|
|
name: 'project-1',
|
|
dependencies: { 'is-positive': '1.0.0' },
|
|
}
|
|
const project2Manifest: ProjectManifest = {
|
|
name: 'project-2',
|
|
dependencies: { 'is-positive': '1.0.0' },
|
|
}
|
|
preparePackages([
|
|
{
|
|
location: '.',
|
|
package: rootManifest,
|
|
},
|
|
{
|
|
location: 'project-1',
|
|
package: project1Manifest,
|
|
},
|
|
{
|
|
location: 'project-2',
|
|
package: project2Manifest,
|
|
},
|
|
])
|
|
|
|
const branchName: string = 'main-branch'
|
|
jest.mocked(getCurrentBranch).mockReturnValue(Promise.resolve(branchName))
|
|
|
|
const opts = testDefaults({
|
|
useGitBranchLockfile: true,
|
|
allProjects: [
|
|
{
|
|
buildIndex: 0,
|
|
manifest: rootManifest,
|
|
rootDir: process.cwd() as ProjectRootDir,
|
|
},
|
|
{
|
|
buildIndex: 0,
|
|
manifest: project1Manifest,
|
|
rootDir: path.resolve('project-1') as ProjectRootDir,
|
|
},
|
|
{
|
|
buildIndex: 0,
|
|
manifest: project2Manifest,
|
|
rootDir: path.resolve('project-2') as ProjectRootDir,
|
|
},
|
|
],
|
|
})
|
|
|
|
await mutateModules([
|
|
{
|
|
mutation: 'install',
|
|
rootDir: process.cwd() as ProjectRootDir,
|
|
},
|
|
{
|
|
mutation: 'install',
|
|
rootDir: path.resolve('project-1') as ProjectRootDir,
|
|
},
|
|
{
|
|
mutation: 'install',
|
|
rootDir: path.resolve('project-2') as ProjectRootDir,
|
|
},
|
|
], opts)
|
|
|
|
expect(fs.existsSync(`pnpm-lock.${branchName}.yaml`)).toBe(true)
|
|
expect(fs.existsSync(WANTED_LOCKFILE)).toBe(false)
|
|
})
|
|
|
|
test('install with --merge-git-branch-lockfiles', async () => {
|
|
prepareEmpty()
|
|
|
|
const branchName: string = 'main-branch'
|
|
jest.mocked(getCurrentBranch).mockReturnValue(Promise.resolve(branchName))
|
|
|
|
const otherLockfilePath: string = path.resolve('pnpm-lock.other.yaml')
|
|
writeYamlFileSync(otherLockfilePath, {
|
|
whatever: 'whatever',
|
|
})
|
|
|
|
expect(fs.existsSync(otherLockfilePath)).toBe(true)
|
|
expect(fs.existsSync(WANTED_LOCKFILE)).toBe(false)
|
|
|
|
const opts = testDefaults({
|
|
useGitBranchLockfile: true,
|
|
mergeGitBranchLockfiles: true,
|
|
})
|
|
await install({
|
|
dependencies: {
|
|
'is-positive': '^3.0.0',
|
|
},
|
|
}, opts)
|
|
|
|
expect(fs.existsSync(otherLockfilePath)).toBe(false)
|
|
expect(fs.existsSync(WANTED_LOCKFILE)).toBe(true)
|
|
})
|
|
|
|
test('install with --merge-git-branch-lockfiles when merged lockfile is up to date', async () => {
|
|
const project = prepareEmpty()
|
|
|
|
// @types/semver installed in the main branch
|
|
writeYamlFileSync(WANTED_LOCKFILE, {
|
|
importers: {
|
|
'.': {
|
|
dependencies: {
|
|
'@types/semver': {
|
|
specifier: '5.3.31',
|
|
version: '5.3.31',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
lockfileVersion: LOCKFILE_VERSION,
|
|
packages: {
|
|
'@types/semver@5.3.31': {
|
|
resolution: {
|
|
integrity: 'sha512-WBv5F9HrWTyG800cB9M3veCVkFahqXN7KA7c3VUCYZm/xhNzzIFiXiq+rZmj75j7GvWelN3YNrLX7FjtqBvhMw==',
|
|
},
|
|
},
|
|
},
|
|
snapshots: {
|
|
'@types/semver@5.3.31': {},
|
|
},
|
|
}, { lineWidth: 1000 })
|
|
|
|
const branchName: string = 'main-branch'
|
|
jest.mocked(getCurrentBranch).mockReturnValue(Promise.resolve(branchName))
|
|
|
|
// is-positive installed in the other branch
|
|
const otherLockfilePath: string = path.resolve('pnpm-lock.other.yaml')
|
|
const otherLockfileContent = {
|
|
importers: {
|
|
'.': {
|
|
dependencies: {
|
|
'@types/semver': {
|
|
specifier: '5.3.31',
|
|
version: '5.3.31',
|
|
},
|
|
'is-positive': {
|
|
specifier: '^3.1.0',
|
|
version: '3.1.0',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
lockfileVersion: LOCKFILE_VERSION,
|
|
packages: {
|
|
'@types/semver@5.3.31': {
|
|
resolution: {
|
|
integrity: 'sha512-WBv5F9HrWTyG800cB9M3veCVkFahqXN7KA7c3VUCYZm/xhNzzIFiXiq+rZmj75j7GvWelN3YNrLX7FjtqBvhMw==',
|
|
},
|
|
},
|
|
'is-positive@3.1.0': {
|
|
resolution: {
|
|
integrity: 'sha512-8ND1j3y9/HP94TOvGzr69/FgbkX2ruOldhLEsTWwcJVfo4oRjwemJmJxt7RJkKYH8tz7vYBP9JcKQY8CLuJ90Q==',
|
|
},
|
|
},
|
|
},
|
|
snapshots: {
|
|
'@types/semver@5.3.31': {},
|
|
'is-positive@3.1.0': {},
|
|
},
|
|
}
|
|
writeYamlFileSync(otherLockfilePath, otherLockfileContent, { lineWidth: 1000 })
|
|
|
|
// the other branch merged to the main branch
|
|
const projectManifest: ProjectManifest = {
|
|
dependencies: {
|
|
'@types/semver': '5.3.31',
|
|
'is-positive': '^3.1.0',
|
|
},
|
|
}
|
|
const opts = testDefaults({
|
|
useGitBranchLockfile: true,
|
|
mergeGitBranchLockfiles: true,
|
|
frozenLockfile: true,
|
|
})
|
|
await install(projectManifest, opts)
|
|
|
|
expect(fs.existsSync(otherLockfilePath)).toBe(false)
|
|
expect(fs.existsSync(WANTED_LOCKFILE)).toBe(true)
|
|
|
|
const wantedLockfileAfterMergeOther = project.readLockfile()
|
|
expect(wantedLockfileAfterMergeOther).toEqual(otherLockfileContent)
|
|
})
|