Files
pnpm/installing/commands/test/import.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

157 lines
4.8 KiB
TypeScript

/// <reference path="../../../__typings__/index.d.ts" />
import path from 'node:path'
import { assertProject } from '@pnpm/assert-project'
import { PnpmError } from '@pnpm/error'
import { importCommand } from '@pnpm/installing.commands'
import { prepare } from '@pnpm/prepare'
import { addDistTag, REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
import { fixtures } from '@pnpm/test-fixtures'
import { temporaryDirectory } from 'tempy'
const f = fixtures(import.meta.dirname)
const REGISTRY = `http://localhost:${REGISTRY_MOCK_PORT}`
const TMP = temporaryDirectory()
const DEFAULT_OPTS = {
ca: undefined,
cacheDir: path.join(TMP, 'cache'),
cert: undefined,
fetchRetries: 2,
fetchRetryFactor: 90,
fetchRetryMaxtimeout: 90,
fetchRetryMintimeout: 10,
httpsProxy: undefined,
key: undefined,
localAddress: undefined,
lock: false,
lockStaleDuration: 90,
networkConcurrency: 16,
offline: false,
preferWorkspacePackages: true,
proxy: undefined,
pnpmHomeDir: '',
rawConfig: { registry: REGISTRY },
registries: { default: REGISTRY },
registry: REGISTRY,
rootProjectManifestDir: '',
storeDir: path.join(TMP, 'store'),
strictSsl: false,
userAgent: 'pnpm',
userConfig: {},
useRunningStoreServer: false,
useStoreServer: false,
virtualStoreDirMaxLength: process.platform === 'win32' ? 60 : 120,
}
test('import from package-lock.json', async () => {
await addDistTag({ package: '@pnpm.e2e/dep-of-pkg-with-1-dep', version: '100.1.0', distTag: 'latest' })
f.prepare('has-package-lock-json')
await importCommand.handler({
...DEFAULT_OPTS,
dir: process.cwd(),
}, [])
const project = assertProject(process.cwd())
const lockfile = project.readLockfile()
expect(lockfile.packages).toHaveProperty(['@pnpm.e2e/dep-of-pkg-with-1-dep@100.0.0'])
expect(lockfile.packages).not.toHaveProperty(['@pnpm.e2e/dep-of-pkg-with-1-dep@100.1.0'])
// node_modules is not created
project.hasNot('@pnpm.e2e/dep-of-pkg-with-1-dep')
project.hasNot('@pnpm.e2e/pkg-with-1-dep')
})
test('import from yarn.lock', async () => {
await addDistTag({ package: '@pnpm.e2e/dep-of-pkg-with-1-dep', version: '100.1.0', distTag: 'latest' })
f.prepare('has-yarn-lock')
await importCommand.handler({
...DEFAULT_OPTS,
dir: process.cwd(),
}, [])
const project = assertProject(process.cwd())
const lockfile = project.readLockfile()
expect(lockfile.packages).toHaveProperty(['@pnpm.e2e/dep-of-pkg-with-1-dep@100.0.0'])
expect(lockfile.packages).not.toHaveProperty(['@pnpm.e2e/dep-of-pkg-with-1-dep@100.1.0'])
// node_modules is not created
project.hasNot('@pnpm.e2e/dep-of-pkg-with-1-dep')
project.hasNot('@pnpm.e2e/pkg-with-1-dep')
})
test('import from yarn2 lock file', async () => {
f.prepare('has-yarn2-lock')
await importCommand.handler({
...DEFAULT_OPTS,
dir: process.cwd(),
}, [])
const project = assertProject(process.cwd())
const lockfile = project.readLockfile()
expect(lockfile.packages).toHaveProperty(['is-positive@1.0.0'])
expect(lockfile.packages).toHaveProperty(['is-negative@1.0.0'])
// node_modules is not created
project.hasNot('balanced-match')
project.hasNot('brace-expansion')
})
test('import from npm-shrinkwrap.json', async () => {
await addDistTag({ package: '@pnpm.e2e/dep-of-pkg-with-1-dep', version: '100.1.0', distTag: 'latest' })
f.prepare('has-npm-shrinkwrap-json')
await importCommand.handler({
...DEFAULT_OPTS,
dir: process.cwd(),
}, [])
const project = assertProject(process.cwd())
const lockfile = project.readLockfile()
expect(lockfile.packages).toHaveProperty(['@pnpm.e2e/dep-of-pkg-with-1-dep@100.0.0'])
expect(lockfile.packages).not.toHaveProperty(['@pnpm.e2e/dep-of-pkg-with-1-dep@100.1.0'])
// node_modules is not created
project.hasNot('@pnpm.e2e/dep-of-pkg-with-1-dep')
project.hasNot('@pnpm.e2e/pkg-with-1-dep')
})
test('import fails when no lockfiles are found', async () => {
prepare(undefined)
await expect(
importCommand.handler({
...DEFAULT_OPTS,
dir: process.cwd(),
}, [])
).rejects.toThrow(
new PnpmError('LOCKFILE_NOT_FOUND', 'No lockfile found')
)
})
test('import from package-lock.json v3', async () => {
await addDistTag({ package: '@pnpm.e2e/dep-of-pkg-with-1-dep', version: '100.1.0', distTag: 'latest' })
f.prepare('has-package-lock-v3-json')
await importCommand.handler({
...DEFAULT_OPTS,
dir: process.cwd(),
}, [])
const project = assertProject(process.cwd())
const lockfile = project.readLockfile()
expect(lockfile.packages).toHaveProperty(['@pnpm.e2e/dep-of-pkg-with-1-dep@100.0.0'])
expect(lockfile.packages).not.toHaveProperty(['@pnpm.e2e/dep-of-pkg-with-1-dep@100.1.0'])
// node_modules is not created
project.hasNot('@pnpm.e2e/dep-of-pkg-with-1-dep')
project.hasNot('@pnpm.e2e/pkg-with-1-dep')
})