mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-06 00:06:06 -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
118 lines
4.4 KiB
TypeScript
118 lines
4.4 KiB
TypeScript
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
import { linkBins } from '@pnpm/bins.linker'
|
|
import { fetchFromDir } from '@pnpm/fetching.directory-fetcher'
|
|
import { logger } from '@pnpm/logger'
|
|
import type { FilesMap } from '@pnpm/store.cafs-types'
|
|
import type { StoreController } from '@pnpm/store.controller-types'
|
|
import type { ProjectManifest, ProjectRootDir } from '@pnpm/types'
|
|
import { runGroups } from 'run-groups'
|
|
|
|
import { runLifecycleHook, type RunLifecycleHookOptions } from './runLifecycleHook.js'
|
|
|
|
export type RunLifecycleHooksConcurrentlyOptions = Omit<RunLifecycleHookOptions,
|
|
| 'depPath'
|
|
| 'pkgRoot'
|
|
| 'rootModulesDir'
|
|
> & {
|
|
resolveSymlinksInInjectedDirs?: boolean
|
|
storeController: StoreController
|
|
extraNodePaths?: string[]
|
|
preferSymlinkedExecutables?: boolean
|
|
}
|
|
|
|
export interface Importer {
|
|
buildIndex: number
|
|
manifest: ProjectManifest
|
|
rootDir: ProjectRootDir
|
|
modulesDir: string
|
|
stages?: string[]
|
|
targetDirs?: string[]
|
|
}
|
|
|
|
export async function runLifecycleHooksConcurrently (
|
|
stages: string[],
|
|
importers: Importer[],
|
|
childConcurrency: number,
|
|
opts: RunLifecycleHooksConcurrentlyOptions
|
|
): Promise<void> {
|
|
const importersByBuildIndex = new Map<number, Importer[]>()
|
|
for (const importer of importers) {
|
|
if (!importersByBuildIndex.has(importer.buildIndex)) {
|
|
importersByBuildIndex.set(importer.buildIndex, [importer])
|
|
} else {
|
|
importersByBuildIndex.get(importer.buildIndex)!.push(importer)
|
|
}
|
|
}
|
|
const sortedBuildIndexes = Array.from(importersByBuildIndex.keys()).sort((a, b) => a - b)
|
|
const groups = sortedBuildIndexes.map((buildIndex) => {
|
|
const importers = importersByBuildIndex.get(buildIndex)!
|
|
return importers.map(({ manifest, modulesDir, rootDir, stages: importerStages, targetDirs }) =>
|
|
async () => {
|
|
// We are linking the bin files, in case they were created by lifecycle scripts of other workspace packages.
|
|
await linkBins(modulesDir, path.join(modulesDir, '.bin'), {
|
|
extraNodePaths: opts.extraNodePaths,
|
|
allowExoticManifests: true,
|
|
preferSymlinkedExecutables: opts.preferSymlinkedExecutables,
|
|
projectManifest: manifest,
|
|
warn: (message: string) => {
|
|
logger.warn({ message, prefix: rootDir })
|
|
},
|
|
})
|
|
const runLifecycleHookOpts: RunLifecycleHookOptions = {
|
|
...opts,
|
|
depPath: rootDir,
|
|
pkgRoot: rootDir,
|
|
rootModulesDir: modulesDir,
|
|
}
|
|
let isBuilt = false
|
|
for (const stage of (importerStages ?? stages)) {
|
|
if (await runLifecycleHook(stage, manifest, runLifecycleHookOpts)) { // eslint-disable-line no-await-in-loop
|
|
isBuilt = true
|
|
}
|
|
}
|
|
if (targetDirs == null || targetDirs.length === 0 || !isBuilt) return
|
|
const filesResponse = await fetchFromDir(rootDir, { resolveSymlinks: opts.resolveSymlinksInInjectedDirs })
|
|
await Promise.all(
|
|
targetDirs.map(async (targetDir) => {
|
|
const targetModulesDir = path.join(targetDir, 'node_modules')
|
|
const newFilesMap: FilesMap = new Map(filesResponse.filesMap)
|
|
if (fs.existsSync(targetModulesDir)) {
|
|
// If the target directory contains a node_modules directory
|
|
// (it may happen when the hoisted node linker is used)
|
|
// then we need to preserve this node_modules.
|
|
// So we scan this node_modules directory and pass it as part of the new package.
|
|
await scanDir('node_modules', targetModulesDir, targetModulesDir, newFilesMap)
|
|
}
|
|
return opts.storeController.importPackage(targetDir, {
|
|
filesResponse: {
|
|
resolvedFrom: 'local-dir',
|
|
...filesResponse,
|
|
filesMap: newFilesMap,
|
|
},
|
|
force: false,
|
|
})
|
|
})
|
|
)
|
|
}
|
|
)
|
|
})
|
|
await runGroups(childConcurrency, groups)
|
|
}
|
|
|
|
async function scanDir (prefix: string, rootDir: string, currentDir: string, index: FilesMap): Promise<void> {
|
|
const files = await fs.promises.readdir(currentDir)
|
|
await Promise.all(files.map(async (file) => {
|
|
const fullPath = path.join(currentDir, file)
|
|
const stat = await fs.promises.stat(fullPath)
|
|
if (stat.isDirectory()) {
|
|
return scanDir(prefix, rootDir, fullPath, index)
|
|
}
|
|
if (stat.isFile()) {
|
|
const relativePath = path.relative(rootDir, fullPath)
|
|
index.set(path.join(prefix, relativePath), fullPath)
|
|
}
|
|
}))
|
|
}
|