mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-29 04:21:39 -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
231 lines
6.1 KiB
TypeScript
231 lines
6.1 KiB
TypeScript
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
import { STORE_VERSION } from '@pnpm/constants'
|
|
import { fetch, install } from '@pnpm/installing.commands'
|
|
import { prepare } from '@pnpm/prepare'
|
|
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
|
|
import { closeAllStoreIndexes } from '@pnpm/store.index'
|
|
import { finishWorkers } from '@pnpm/worker'
|
|
import { rimrafSync } from '@zkochan/rimraf'
|
|
|
|
const REGISTRY_URL = `http://localhost:${REGISTRY_MOCK_PORT}`
|
|
|
|
const DEFAULT_OPTIONS = {
|
|
argv: {
|
|
original: [],
|
|
},
|
|
bail: false,
|
|
bin: 'node_modules/.bin',
|
|
cliOptions: {},
|
|
deployAllFiles: false,
|
|
excludeLinksFromLockfile: false,
|
|
extraEnv: {},
|
|
include: {
|
|
dependencies: true,
|
|
devDependencies: true,
|
|
optionalDependencies: true,
|
|
},
|
|
lock: true,
|
|
preferWorkspacePackages: true,
|
|
pnpmfile: ['.pnpmfile.cjs'],
|
|
pnpmHomeDir: '',
|
|
rawConfig: { registry: REGISTRY_URL },
|
|
rawLocalConfig: { registry: REGISTRY_URL },
|
|
registries: {
|
|
default: REGISTRY_URL,
|
|
},
|
|
rootProjectManifestDir: '',
|
|
sort: true,
|
|
userConfig: {},
|
|
workspaceConcurrency: 1,
|
|
virtualStoreDirMaxLength: process.platform === 'win32' ? 60 : 120,
|
|
}
|
|
|
|
test('fetch dependencies', async () => {
|
|
const project = prepare({
|
|
dependencies: { 'is-positive': '1.0.0' },
|
|
devDependencies: { 'is-negative': '1.0.0' },
|
|
})
|
|
const storeDir = path.resolve('store')
|
|
|
|
await install.handler({
|
|
...DEFAULT_OPTIONS,
|
|
cacheDir: path.resolve('cache'),
|
|
dir: process.cwd(),
|
|
linkWorkspacePackages: true,
|
|
storeDir,
|
|
})
|
|
|
|
rimrafSync(path.resolve(project.dir(), 'node_modules'))
|
|
rimrafSync(path.resolve(project.dir(), './package.json'))
|
|
|
|
project.storeHasNot('is-negative')
|
|
project.storeHasNot('is-positive')
|
|
|
|
await fetch.handler({
|
|
...DEFAULT_OPTIONS,
|
|
cacheDir: path.resolve('cache'),
|
|
dir: process.cwd(),
|
|
storeDir,
|
|
})
|
|
|
|
project.storeHas('is-positive')
|
|
project.storeHas('is-negative')
|
|
})
|
|
|
|
test('fetch production dependencies', async () => {
|
|
const project = prepare({
|
|
dependencies: { 'is-positive': '1.0.0' },
|
|
devDependencies: { 'is-negative': '1.0.0' },
|
|
})
|
|
const storeDir = path.resolve('store')
|
|
await install.handler({
|
|
...DEFAULT_OPTIONS,
|
|
cacheDir: path.resolve('cache'),
|
|
dir: process.cwd(),
|
|
linkWorkspacePackages: true,
|
|
storeDir,
|
|
})
|
|
|
|
rimrafSync(path.resolve(project.dir(), 'node_modules'))
|
|
rimrafSync(path.resolve(project.dir(), './package.json'))
|
|
|
|
project.storeHasNot('is-negative')
|
|
project.storeHasNot('is-positive')
|
|
|
|
await fetch.handler({
|
|
...DEFAULT_OPTIONS,
|
|
cacheDir: path.resolve('cache'),
|
|
dev: true,
|
|
dir: process.cwd(),
|
|
storeDir,
|
|
})
|
|
|
|
project.storeHasNot('is-negative')
|
|
project.storeHas('is-positive')
|
|
})
|
|
|
|
test('fetch only dev dependencies', async () => {
|
|
const project = prepare({
|
|
dependencies: { 'is-positive': '1.0.0' },
|
|
devDependencies: { 'is-negative': '1.0.0' },
|
|
})
|
|
const storeDir = path.resolve('store')
|
|
await install.handler({
|
|
...DEFAULT_OPTIONS,
|
|
cacheDir: path.resolve('cache'),
|
|
dir: process.cwd(),
|
|
linkWorkspacePackages: true,
|
|
storeDir,
|
|
})
|
|
|
|
rimrafSync(path.resolve(project.dir(), 'node_modules'))
|
|
rimrafSync(path.resolve(project.dir(), './package.json'))
|
|
|
|
project.storeHasNot('is-negative')
|
|
project.storeHasNot('is-positive')
|
|
|
|
await fetch.handler({
|
|
...DEFAULT_OPTIONS,
|
|
cacheDir: path.resolve('cache'),
|
|
dev: true,
|
|
dir: process.cwd(),
|
|
storeDir,
|
|
})
|
|
|
|
project.storeHas('is-negative')
|
|
project.storeHasNot('is-positive')
|
|
})
|
|
|
|
// Regression test for https://github.com/pnpm/pnpm/issues/10460
|
|
// pnpm fetch should skip local file: protocol dependencies
|
|
// because they won't be available in Docker builds
|
|
test('fetch skips file: protocol dependencies that do not exist', async () => {
|
|
const project = prepare({
|
|
dependencies: {
|
|
'is-positive': '1.0.0',
|
|
'@local/pkg': 'file:./local-pkg',
|
|
},
|
|
})
|
|
const storeDir = path.resolve('store')
|
|
const localPkgDir = path.resolve(project.dir(), 'local-pkg')
|
|
|
|
// Create the local package for initial install to generate lockfile
|
|
fs.mkdirSync(localPkgDir, { recursive: true })
|
|
fs.writeFileSync(
|
|
path.join(localPkgDir, 'package.json'),
|
|
JSON.stringify({ name: '@local/pkg', version: '1.0.0' })
|
|
)
|
|
|
|
// Create a lockfile with the file: dependency
|
|
await install.handler({
|
|
...DEFAULT_OPTIONS,
|
|
cacheDir: path.resolve('cache'),
|
|
dir: process.cwd(),
|
|
linkWorkspacePackages: true,
|
|
storeDir,
|
|
})
|
|
|
|
rimrafSync(path.resolve(project.dir(), 'node_modules'))
|
|
rimrafSync(path.resolve(project.dir(), './package.json'))
|
|
// Remove the local package directory to simulate Docker build scenario
|
|
rimrafSync(localPkgDir)
|
|
|
|
project.storeHasNot('is-positive')
|
|
|
|
// This should not throw an error even though the file: dependency doesn't exist
|
|
await fetch.handler({
|
|
...DEFAULT_OPTIONS,
|
|
cacheDir: path.resolve('cache'),
|
|
dir: process.cwd(),
|
|
storeDir,
|
|
})
|
|
|
|
project.storeHas('is-positive')
|
|
})
|
|
|
|
test('fetch populates global virtual store links/', async () => {
|
|
prepare({
|
|
dependencies: {
|
|
'is-positive': '1.0.0',
|
|
},
|
|
devDependencies: {
|
|
'is-negative': '1.0.0',
|
|
},
|
|
})
|
|
const storeDir = path.resolve('store')
|
|
const globalVirtualStoreDir = path.join(storeDir, STORE_VERSION, 'links')
|
|
|
|
// Generate the lockfile only — no need for a full install
|
|
await install.handler({
|
|
...DEFAULT_OPTIONS,
|
|
cacheDir: path.resolve('cache'),
|
|
dir: process.cwd(),
|
|
linkWorkspacePackages: true,
|
|
lockfileOnly: true,
|
|
storeDir,
|
|
})
|
|
|
|
// Drain workers and close SQLite connections before removing the store (required on Windows)
|
|
await finishWorkers()
|
|
closeAllStoreIndexes()
|
|
|
|
// Remove the store — simulate a cold start with only the lockfile
|
|
rimrafSync(storeDir)
|
|
|
|
// Fetch with enableGlobalVirtualStore — should populate links/
|
|
await fetch.handler({
|
|
...DEFAULT_OPTIONS,
|
|
cacheDir: path.resolve('cache'),
|
|
dir: process.cwd(),
|
|
storeDir,
|
|
enableGlobalVirtualStore: true,
|
|
})
|
|
|
|
// The global virtual store links/ directory should exist and contain packages
|
|
expect(fs.existsSync(globalVirtualStoreDir)).toBeTruthy()
|
|
const entries = fs.readdirSync(globalVirtualStoreDir)
|
|
expect(entries.length).toBeGreaterThan(0)
|
|
})
|