Files
pnpm/exec/lifecycle/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

157 lines
5.0 KiB
TypeScript

/// <reference path="../../../__typings__/index.d.ts"/>
import fs from 'node:fs'
import path from 'node:path'
import { PnpmError } from '@pnpm/error'
import { runLifecycleHook, runLifecycleHooksConcurrently, runPostinstallHooks } from '@pnpm/exec.lifecycle'
import { tempDir } from '@pnpm/prepare'
import type { StoreController } from '@pnpm/store.controller-types'
import { fixtures } from '@pnpm/test-fixtures'
import { createTestIpcServer } from '@pnpm/test-ipc-server'
import type { ProjectRootDir } from '@pnpm/types'
import isWindows from 'is-windows'
const skipOnWindows = isWindows() ? test.skip : test
const f = fixtures(path.join(import.meta.dirname, 'fixtures'))
const rootModulesDir = path.join(import.meta.dirname, '..', 'node_modules')
test('runLifecycleHook()', async () => {
const pkgRoot = f.find('simple')
await using server = await createTestIpcServer(path.join(pkgRoot, 'test.sock'))
const { default: pkg } = await import(path.join(pkgRoot, 'package.json'))
await runLifecycleHook('postinstall', pkg, {
depPath: '/simple/1.0.0',
optional: false,
pkgRoot,
rawConfig: {},
rootModulesDir,
unsafePerm: true,
})
expect(server.getLines()).toStrictEqual(['install'])
})
test('runLifecycleHook() escapes the args passed to the script', async () => {
const pkgRoot = f.find('escape-args')
const { default: pkg } = await import(path.join(pkgRoot, 'package.json'))
await runLifecycleHook('echo', pkg, {
depPath: '/escape-args/1.0.0',
pkgRoot,
rawConfig: {},
rootModulesDir,
unsafePerm: true,
args: ['Revert "feature (#1)"'],
})
expect((await import(path.join(pkgRoot, 'output.json'))).default).toStrictEqual(['Revert "feature (#1)"'])
})
test('runLifecycleHook() passes newline correctly', async () => {
const pkgRoot = f.find('escape-newline')
const { default: pkg } = await import(path.join(pkgRoot, 'package.json'))
await runLifecycleHook('echo', pkg, {
depPath: 'escape-newline@1.0.0',
pkgRoot,
rawConfig: {},
rootModulesDir,
unsafePerm: true,
args: ['a\nb != \'A\\nB\''],
})
expect((await import(path.join(pkgRoot, 'output.json'))).default).toStrictEqual([
process.platform === 'win32' ? 'a\\nb != \'A\\\\nB\'' : 'a\nb != \'A\\nB\'',
])
})
test('runLifecycleHook() sets frozen-lockfile to false', async () => {
const pkgRoot = f.find('inspect-frozen-lockfile')
await using server = await createTestIpcServer(path.join(pkgRoot, 'test.sock'))
const { default: pkg } = await import(path.join(pkgRoot, 'package.json'))
await runLifecycleHook('postinstall', pkg, {
depPath: '/inspect-frozen-lockfile/1.0.0',
pkgRoot,
rawConfig: {
'frozen-lockfile': true,
},
rootModulesDir,
unsafePerm: true,
})
expect(server.getLines()).toStrictEqual(['empty string'])
})
test('runPostinstallHooks()', async () => {
const pkgRoot = f.find('with-many-scripts')
await using server = await createTestIpcServer(path.join(pkgRoot, 'test.sock'))
await runPostinstallHooks({
depPath: '/with-many-scripts/1.0.0',
optional: false,
pkgRoot,
rawConfig: {},
rootModulesDir,
unsafePerm: true,
})
expect(server.getLines()).toStrictEqual(['preinstall', 'install', 'postinstall'])
})
test('runLifecycleHook() should throw an error while missing script start or file server.js', async () => {
const pkgRoot = f.find('without-script-start-serverjs')
const { default: pkg } = await import(path.join(pkgRoot, 'package.json'))
await expect(
runLifecycleHook('start', pkg, {
depPath: '/without-script-start-serverjs/1.0.0',
optional: false,
pkgRoot,
rawConfig: {},
rootModulesDir,
unsafePerm: true,
})
).rejects.toThrow(new PnpmError('NO_SCRIPT_OR_SERVER', 'Missing script start or file server.js'))
})
test('preinstall script does not trigger node-gyp rebuild', async () => {
const pkgRoot = f.find('gyp-with-preinstall')
await using server = await createTestIpcServer(path.join(pkgRoot, 'test.sock'))
await runPostinstallHooks({
depPath: '/gyp-with-preinstall/1.0.0',
optional: false,
pkgRoot,
rawConfig: {},
rootModulesDir,
unsafePerm: true,
})
expect(server.getLines()).toStrictEqual(['preinstall'])
})
skipOnWindows('runLifecycleHooksConcurrently() should check binding.gyp', async () => {
const projectDir = tempDir(false)
fs.writeFileSync(path.join(projectDir, 'binding.gyp'), JSON.stringify({
targets: [
{
target_name: 'run_js_script',
actions: [
{
action_name: 'execute_postinstall',
inputs: [],
outputs: ['foo'],
action: ['node', '-e', 'require(\'fs\').writeFileSync(\'foo\', \'\', \'utf8\')'],
},
],
},
],
}), 'utf8')
await runLifecycleHooksConcurrently(['install'], [{ buildIndex: 0, rootDir: projectDir as ProjectRootDir, modulesDir: '', manifest: {} }], 5, {
storeController: {} as StoreController,
optional: false,
rawConfig: {},
unsafePerm: true,
})
expect(fs.existsSync(path.join(projectDir, 'foo'))).toBeTruthy()
})