mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-27 19:41:44 -04:00
- Rename `installing/core` → `installing/deps-installer` and `installing/headless` → `installing/deps-restorer` for clearer naming
- Rename all `plugin-commands-*` directories to use `-commands` suffix convention
- Merge multiple command packages per domain into a single `commands/` directory (one commands package per domain rule):
- `building/{build-commands,policy-commands}` → `building/commands`
- `deps/compliance/{audit-commands,licenses-commands,sbom-commands}` → `deps/compliance/commands`
- `deps/inspection/{listing-commands,outdated-commands}` → `deps/inspection/commands`
- `store/{store-commands,inspecting-commands}` → `store/commands`
- `releasing/{publish-commands,deploy-commands}` → `releasing/commands`
- `cli/{completion-commands,doctor-commands}` → `cli/commands`
- `engine/pm/{self-updater-commands,setup-commands}` → `engine/pm/commands`
- `engine/runtime/{runtime-commands,env-commands}` → `engine/runtime/commands`
- `cache/cache-commands` → `cache/commands`
- Fix relative paths in merged test files (pnpmBin, __typings__ references)
- Update jest config to ignore `utils/` dirs at any nesting depth under `test/`
- Fix stale package names in changeset files
162 lines
3.9 KiB
TypeScript
162 lines
3.9 KiB
TypeScript
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
import { jest } from '@jest/globals'
|
|
import { preparePackages } from '@pnpm/prepare'
|
|
import { writeYamlFile } from 'write-yaml-file'
|
|
|
|
import { DEFAULT_OPTS } from './utils/index.js'
|
|
|
|
const debug = jest.fn()
|
|
jest.unstable_mockModule('@pnpm/logger', () => {
|
|
return {
|
|
logger: () => ({ debug }),
|
|
globalInfo: jest.fn(),
|
|
globalWarn: jest.fn(),
|
|
streamParser: jest.fn(),
|
|
}
|
|
})
|
|
|
|
const { filterPackagesFromDir } = await import('@pnpm/workspace.filter-packages-from-dir')
|
|
const { exec } = await import('@pnpm/plugin-commands-script-runners')
|
|
|
|
afterEach(() => {
|
|
jest.mocked(debug).mockClear()
|
|
})
|
|
|
|
test('pnpm exec --recursive --no-reporter-hide-prefix prints prefixes', async () => {
|
|
preparePackages([
|
|
{
|
|
location: 'packages/foo',
|
|
package: { name: 'foo' },
|
|
},
|
|
{
|
|
location: 'packages/bar',
|
|
package: { name: 'bar' },
|
|
},
|
|
])
|
|
|
|
await writeYamlFile('pnpm-workspace.yaml', {
|
|
packages: ['packages/*'],
|
|
})
|
|
|
|
const { selectedProjectsGraph } = await filterPackagesFromDir(process.cwd(), [])
|
|
|
|
const scriptFile = path.resolve('script.js')
|
|
fs.writeFileSync(scriptFile, `
|
|
console.log('hello from stdout')
|
|
console.error('hello from stderr')
|
|
console.log('name is ' + require(require('path').resolve('package.json')).name)
|
|
`)
|
|
|
|
await exec.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
recursive: true,
|
|
bail: true,
|
|
reporterHidePrefix: false,
|
|
selectedProjectsGraph,
|
|
}, [process.execPath, scriptFile])
|
|
|
|
for (const name of ['foo', 'bar']) {
|
|
const loggerOpts = {
|
|
wd: path.resolve('packages', name),
|
|
depPath: name,
|
|
stage: '(exec)',
|
|
}
|
|
expect(debug).toHaveBeenCalledWith({
|
|
...loggerOpts,
|
|
line: 'hello from stdout',
|
|
stdio: 'stdout',
|
|
})
|
|
expect(debug).toHaveBeenCalledWith({
|
|
...loggerOpts,
|
|
line: 'hello from stderr',
|
|
stdio: 'stderr',
|
|
})
|
|
expect(debug).toHaveBeenCalledWith({
|
|
...loggerOpts,
|
|
line: `name is ${name}`,
|
|
stdio: 'stdout',
|
|
})
|
|
expect(debug).toHaveBeenCalledWith({
|
|
...loggerOpts,
|
|
optional: false,
|
|
exitCode: 0,
|
|
})
|
|
}
|
|
})
|
|
|
|
test('pnpm exec --recursive --reporter-hide-prefix does not print prefixes', async () => {
|
|
preparePackages([
|
|
{
|
|
location: 'packages/foo',
|
|
package: { name: 'foo' },
|
|
},
|
|
{
|
|
location: 'packages/bar',
|
|
package: { name: 'bar' },
|
|
},
|
|
])
|
|
|
|
await writeYamlFile('pnpm-workspace.yaml', {
|
|
packages: ['packages/*'],
|
|
})
|
|
|
|
const { selectedProjectsGraph } = await filterPackagesFromDir(process.cwd(), [])
|
|
|
|
const scriptFile = path.resolve('script.js')
|
|
fs.writeFileSync(scriptFile, `
|
|
console.log('hello from stdout')
|
|
console.error('hello from stderr')
|
|
console.log('name is ' + require(require('path').resolve('package.json')).name)
|
|
`)
|
|
|
|
await exec.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
recursive: true,
|
|
bail: true,
|
|
reporterHidePrefix: true,
|
|
selectedProjectsGraph,
|
|
}, [process.execPath, scriptFile])
|
|
|
|
expect(debug).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('pnpm exec --recursive does not print prefixes by default', async () => {
|
|
preparePackages([
|
|
{
|
|
location: 'packages/foo',
|
|
package: { name: 'foo' },
|
|
},
|
|
{
|
|
location: 'packages/bar',
|
|
package: { name: 'bar' },
|
|
},
|
|
])
|
|
|
|
await writeYamlFile('pnpm-workspace.yaml', {
|
|
packages: ['packages/*'],
|
|
})
|
|
|
|
const { selectedProjectsGraph } = await filterPackagesFromDir(process.cwd(), [])
|
|
|
|
const scriptFile = path.resolve('script.js')
|
|
fs.writeFileSync(scriptFile, `
|
|
console.log('hello from stdout')
|
|
console.error('hello from stderr')
|
|
console.log('name is ' + require(require('path').resolve('package.json')).name)
|
|
`)
|
|
|
|
await exec.handler({
|
|
...DEFAULT_OPTS,
|
|
dir: process.cwd(),
|
|
recursive: true,
|
|
bail: true,
|
|
selectedProjectsGraph,
|
|
}, [process.execPath, scriptFile])
|
|
|
|
expect(debug).not.toHaveBeenCalled()
|
|
})
|