Files
pnpm/deps/path/test/index.ts
Zoltan Kochan 4a36b9a110 refactor: rename internal packages to @pnpm/<domain>.<leaf> convention (#10997)
## 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
2026-03-17 21:50:40 +01:00

153 lines
6.8 KiB
TypeScript

/// <reference path="../../../__typings__/index.d.ts"/>
import {
depPathToFilename,
getPkgIdWithPatchHash,
isAbsolute,
isRuntimeDepPath,
parse,
refToRelative,
removeSuffix,
tryGetPackageId,
} from '@pnpm/deps.path'
import type { DepPath } from '@pnpm/types'
test('isAbsolute()', () => {
expect(isAbsolute('/foo/1.0.0')).toBeFalsy()
expect(isAbsolute('registry.npmjs.org/foo/1.0.0')).toBeTruthy()
})
test('parse()', () => {
/* eslint-disable @typescript-eslint/no-explicit-any */
expect(() => parse(undefined as any)).toThrow(/got `undefined`/)
expect(() => parse({} as any)).toThrow(/got `object`/)
expect(() => parse(1 as any)).toThrow(/got `number`/)
/* eslint-enable @typescript-eslint/no-explicit-any */
expect(parse('foo@1.0.0')).toStrictEqual({
name: 'foo',
peerDepGraphHash: undefined,
version: '1.0.0',
patchHash: undefined,
})
expect(parse('@foo/bar@1.0.0')).toStrictEqual({
name: '@foo/bar',
peerDepGraphHash: undefined,
version: '1.0.0',
patchHash: undefined,
})
expect(parse('foo@1.0.0(@types/babel__core@7.1.14)')).toStrictEqual({
name: 'foo',
peerDepGraphHash: '(@types/babel__core@7.1.14)',
version: '1.0.0',
patchHash: undefined,
})
expect(parse('foo@1.0.0(@types/babel__core@7.1.14)(foo@1.0.0)')).toStrictEqual({
name: 'foo',
peerDepGraphHash: '(@types/babel__core@7.1.14)(foo@1.0.0)',
version: '1.0.0',
patchHash: undefined,
})
expect(parse('@(-.-)/foo@1.0.0(@types/babel__core@7.1.14)(foo@1.0.0)')).toStrictEqual({
name: '@(-.-)/foo',
peerDepGraphHash: '(@types/babel__core@7.1.14)(foo@1.0.0)',
version: '1.0.0',
patchHash: undefined,
})
expect(parse('tar-pkg@file:../tar-pkg-1.0.0.tgz')).toStrictEqual({
name: 'tar-pkg',
nonSemverVersion: 'file:../tar-pkg-1.0.0.tgz',
peerDepGraphHash: undefined,
patchHash: undefined,
})
expect(parse('foo@1.0.0(patch_hash=0000)(@types/babel__core@7.1.14)')).toStrictEqual({
name: 'foo',
peerDepGraphHash: '(@types/babel__core@7.1.14)',
version: '1.0.0',
patchHash: '(patch_hash=0000)',
})
})
test('refToRelative()', () => {
expect(refToRelative('1.3.0', '@most/multicast')).toBe('@most/multicast@1.3.0')
expect(refToRelative('1.3.0', 'most')).toBe('most@1.3.0')
expect(refToRelative('m@1.3.0', 'most')).toBe('m@1.3.0')
expect(refToRelative('@most/multicast@1.3.0', 'most')).toBe('@most/multicast@1.3.0')
expect(refToRelative('@most/multicast@1.3.0', '@most/multicast')).toBe('@most/multicast@1.3.0')
expect(refToRelative('@most/multicast@1.3.0(@foo/bar@1.0.0)', '@most/multicast')).toBe('@most/multicast@1.3.0(@foo/bar@1.0.0)')
expect(refToRelative('@most/multicast@1.3.0(@foo/bar@1.0.0)(@foo/qar@1.0.0)', '@most/multicast')).toBe('@most/multicast@1.3.0(@foo/bar@1.0.0)(@foo/qar@1.0.0)')
// linked dependencies don't have a relative path
expect(refToRelative('link:../foo', 'foo')).toBeNull()
expect(refToRelative('file:../tarball.tgz', 'foo')).toBe('foo@file:../tarball.tgz')
expect(refToRelative('1.3.0(@foo/bar@1.0.0)', '@qar/bar')).toBe('@qar/bar@1.3.0(@foo/bar@1.0.0)')
expect(refToRelative('1.3.0(@foo/bar@1.0.0)(@foo/qar@1.0.0)', '@qar/bar')).toBe('@qar/bar@1.3.0(@foo/bar@1.0.0)(@foo/qar@1.0.0)')
})
test('depPathToFilename()', () => {
expect(depPathToFilename('/foo@1.0.0', 120)).toBe('foo@1.0.0')
expect(depPathToFilename('/@foo/bar@1.0.0', 120)).toBe('@foo+bar@1.0.0')
expect(depPathToFilename('github.com/something/foo/0000?v=1', 120)).toBe('github.com+something+foo+0000+v=1')
expect(depPathToFilename('\\//:*?"<>|', 120)).toBe('++++++++++')
expect(depPathToFilename('/foo@1.0.0(react@16.0.0)(react-dom@16.0.0)', 120)).toBe('foo@1.0.0_react@16.0.0_react-dom@16.0.0')
expect(depPathToFilename('/foo@1.0.0(react@16.0.0(react-dom@1.0.0))(react-dom@16.0.0)', 120)).toBe('foo@1.0.0_react@16.0.0_react-dom@1.0.0__react-dom@16.0.0')
const filename = depPathToFilename('file:test/foo-1.0.0.tgz_foo@2.0.0', 120)
expect(filename).toBe('file+test+foo-1.0.0.tgz_foo@2.0.0')
expect(filename).not.toContain(':')
expect(depPathToFilename('abcd/'.repeat(200), 120)).toBe('abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+abcd+ab_e7c10c3598ebbc0ca640b6524c68e602') // cspell:disable-line
expect(depPathToFilename('/JSONSteam@1.0.0', 120)).toBe('JSONSteam@1.0.0_533d3b11e9111b7a24f914844c021ddf') // cspell:disable-line
expect(depPathToFilename('foo@git+https://github.com/something/foo#1234', 120)).toBe('foo@git+https+++github.com+something+foo+1234')
expect(depPathToFilename('foo@https://codeload.github.com/something/foo/tar.gz/1234#path:packages/foo', 120)).toBe('foo@https+++codeload.github.com+something+foo+tar.gz+1234+path+packages+foo')
})
test('tryGetPackageId', () => {
expect(tryGetPackageId('/foo@1.0.0(@types/babel__core@7.1.14)' as DepPath)).toBe('/foo@1.0.0')
expect(tryGetPackageId('/foo@1.0.0(@types/babel__core@7.1.14(is-odd@1.0.0))' as DepPath)).toBe('/foo@1.0.0')
expect(tryGetPackageId('/@(-.-)/foo@1.0.0(@types/babel__core@7.1.14)' as DepPath)).toBe('/@(-.-)/foo@1.0.0')
expect(tryGetPackageId('foo@1.0.0(patch_hash=xxxx)(@types/babel__core@7.1.14)' as DepPath)).toBe('foo@1.0.0')
})
test('getPkgIdWithPatchHash', () => {
// Runtime dependency
expect(getPkgIdWithPatchHash('node@runtime:24.11.1' as DepPath)).toBe('node@runtime:24.11.1')
// Regular packages
expect(getPkgIdWithPatchHash('foo@1.0.0' as DepPath)).toBe('foo@1.0.0')
// Packages with patch hash
expect(getPkgIdWithPatchHash('foo@1.0.0(patch_hash=xxxx)' as DepPath)).toBe('foo@1.0.0(patch_hash=xxxx)')
// Packages with peer dependencies (should remove peer dependencies)
expect(getPkgIdWithPatchHash('foo@1.0.0(@types/babel__core@7.1.14)' as DepPath)).toBe('foo@1.0.0')
// Packages with both patch hash and peer dependencies (should keep patch hash, remove peer dependencies)
expect(getPkgIdWithPatchHash('foo@1.0.0(patch_hash=xxxx)(@types/babel__core@7.1.14)' as DepPath)).toBe('foo@1.0.0(patch_hash=xxxx)')
// Scoped packages
expect(getPkgIdWithPatchHash('@foo/bar@1.0.0' as DepPath)).toBe('@foo/bar@1.0.0')
// Scoped packages with patch hash
expect(getPkgIdWithPatchHash('@foo/bar@1.0.0(patch_hash=yyyy)' as DepPath)).toBe('@foo/bar@1.0.0(patch_hash=yyyy)')
// Scoped packages with peer dependencies
expect(getPkgIdWithPatchHash('@foo/bar@1.0.0(@types/node@18.0.0)' as DepPath)).toBe('@foo/bar@1.0.0')
// Scoped packages with both patch hash and peer dependencies
expect(getPkgIdWithPatchHash('@foo/bar@1.0.0(patch_hash=zzzz)(@types/node@18.0.0)' as DepPath)).toBe('@foo/bar@1.0.0(patch_hash=zzzz)')
})
test('isRuntimeDepPath', () => {
expect(isRuntimeDepPath('node@runtime:20.1.0' as DepPath)).toBeTruthy()
expect(isRuntimeDepPath('node@20.1.0' as DepPath)).toBeFalsy()
})
test('removeSuffix', () => {
expect(removeSuffix('foo@1.0.0(patch_hash=0000)(@types/babel__core@7.1.14)')).toBe('foo@1.0.0')
})