mirror of
https://github.com/pnpm/pnpm.git
synced 2026-07-26 07:27:20 -04:00
feat: pnpm list to show information whether the package is private or not (#4256)
close #4246
This commit is contained in:
5
.changeset/flat-seahorses-count.md
Normal file
5
.changeset/flat-seahorses-count.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/list": minor
|
||||
---
|
||||
|
||||
pnpm list to show information whether the package is private or not
|
||||
1
fixtures/workspace-with-private-pkgs/package.json
Normal file
1
fixtures/workspace-with-private-pkgs/package.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "private",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"is-positive": "1.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "public",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"is-positive": "1.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
25
fixtures/workspace-with-private-pkgs/pnpm-lock.yaml
generated
Normal file
25
fixtures/workspace-with-private-pkgs/pnpm-lock.yaml
generated
Normal file
@@ -0,0 +1,25 @@
|
||||
lockfileVersion: 5.3
|
||||
|
||||
importers:
|
||||
|
||||
.:
|
||||
specifiers: {}
|
||||
|
||||
packages/private:
|
||||
specifiers:
|
||||
is-positive: 1.0.0
|
||||
dependencies:
|
||||
is-positive: 1.0.0
|
||||
|
||||
packages/public:
|
||||
specifiers:
|
||||
is-positive: 1.0.0
|
||||
dependencies:
|
||||
is-positive: 1.0.0
|
||||
|
||||
packages:
|
||||
|
||||
/is-positive/1.0.0:
|
||||
resolution: {integrity: sha1-iACYVrZKLx632LsBeUGEJK4EUss=}
|
||||
engines: {node: '>=0.10.0'}
|
||||
dev: false
|
||||
2
fixtures/workspace-with-private-pkgs/pnpm-workspace.yaml
Normal file
2
fixtures/workspace-with-private-pkgs/pnpm-workspace.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
packages:
|
||||
- 'packages/**'
|
||||
@@ -97,6 +97,7 @@ export default async function (
|
||||
return {
|
||||
name: entryPkg.name,
|
||||
version: entryPkg.version,
|
||||
private: entryPkg.private,
|
||||
|
||||
path: projectPath,
|
||||
...dependenciesHierarchy,
|
||||
|
||||
@@ -21,6 +21,7 @@ export default async function (
|
||||
name: pkg.name,
|
||||
version: pkg.version,
|
||||
path: pkg.path,
|
||||
private: !!pkg.private,
|
||||
}
|
||||
for (const dependenciesField of [...DEPENDENCIES_FIELDS.sort(), 'unsavedDependencies']) {
|
||||
if (pkg[dependenciesField]?.length) {
|
||||
|
||||
@@ -44,6 +44,9 @@ function renderParseableForPackage (
|
||||
if (pkg.version) {
|
||||
firstLine += `@${pkg.version}`
|
||||
}
|
||||
if (pkg.private) {
|
||||
firstLine += ':PRIVATE'
|
||||
}
|
||||
}
|
||||
return [
|
||||
firstLine,
|
||||
|
||||
@@ -60,6 +60,10 @@ async function renderTreeForPackage (
|
||||
label += ' '
|
||||
}
|
||||
label += pkg.path
|
||||
|
||||
if (pkg.private) {
|
||||
label += ' (PRIVATE)'
|
||||
}
|
||||
let output = `${chalk.bold.underline(label)}\n`
|
||||
const useColumns = opts.depth === 0 && !opts.long && !opts.search
|
||||
const dependenciesFields: string[] = [
|
||||
|
||||
@@ -4,4 +4,5 @@ export type PackageDependencyHierarchy = DependenciesHierarchy & {
|
||||
name?: string
|
||||
version?: string
|
||||
path: string
|
||||
private?: boolean
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ const fixtureWithNoPkgVersion = path.join(fixtures, 'fixture-with-no-pkg-version
|
||||
const fixtureWithExternalLockfile = path.join(fixtures, 'fixture-with-external-shrinkwrap', 'pkg')
|
||||
const workspaceWith2Pkgs = path.join(fixtures, 'workspace-with-2-pkgs')
|
||||
const workspaceWithDifferentDeps = path.join(fixtures, 'workspace-with-different-deps')
|
||||
const workspaceWithPrivatePkgs = path.join(fixtures, 'workspace-with-private-pkgs')
|
||||
const emptyFixture = path.join(fixtures, 'empty')
|
||||
const fixtureWithAliasedDep = path.join(fixtures, 'with-aliased-dep')
|
||||
|
||||
@@ -60,6 +61,25 @@ ${DEPENDENCIES}
|
||||
is-positive ${VERSION_CLR('1.0.0')}`)
|
||||
})
|
||||
|
||||
test('list in workspace with private package', async () => {
|
||||
expect(await list([
|
||||
path.join(workspaceWithPrivatePkgs, 'packages/private'),
|
||||
path.join(workspaceWithPrivatePkgs, 'packages/public'),
|
||||
], {
|
||||
lockfileDir: workspaceWithPrivatePkgs,
|
||||
})).toBe(`${LEGEND}
|
||||
|
||||
${boldHighlighted(`private@1.0.0 ${path.join(workspaceWithPrivatePkgs, 'packages/private')} (PRIVATE)`)}
|
||||
|
||||
${DEPENDENCIES}
|
||||
is-positive ${VERSION_CLR('1.0.0')}
|
||||
|
||||
${boldHighlighted(`public@1.0.0 ${path.join(workspaceWithPrivatePkgs, 'packages/public')}`)}
|
||||
|
||||
${DEPENDENCIES}
|
||||
is-positive ${VERSION_CLR('1.0.0')}`)
|
||||
})
|
||||
|
||||
test('list with default parameters', async () => {
|
||||
expect(await list([fixture], { lockfileDir: fixture })).toBe(`${LEGEND}
|
||||
|
||||
@@ -228,6 +248,72 @@ ${OPTIONAL_DEP_CLR('is-negative')} ${VERSION_CLR('2.1.0')}
|
||||
https://github.com/kevva/is-negative#readme`)
|
||||
})
|
||||
|
||||
test('parseable list in workspace with private package', async () => {
|
||||
expect(await list([
|
||||
path.join(workspaceWithPrivatePkgs, 'packages/private'),
|
||||
path.join(workspaceWithPrivatePkgs, 'packages/public'),
|
||||
], {
|
||||
reportAs: 'parseable',
|
||||
lockfileDir: workspaceWithPrivatePkgs,
|
||||
})).toBe(`${path.join(workspaceWithPrivatePkgs, 'packages/private')}
|
||||
${path.join(workspaceWithPrivatePkgs, 'packages/private/node_modules/.pnpm/is-positive@1.0.0')}
|
||||
${path.join(workspaceWithPrivatePkgs, 'packages/public')}
|
||||
${path.join(workspaceWithPrivatePkgs, 'packages/public/node_modules/.pnpm/is-positive@1.0.0')}`)
|
||||
})
|
||||
|
||||
test('long parseable list in workspace with private package', async () => {
|
||||
expect(await list([
|
||||
path.join(workspaceWithPrivatePkgs, 'packages/private'),
|
||||
path.join(workspaceWithPrivatePkgs, 'packages/public'),
|
||||
], {
|
||||
reportAs: 'parseable',
|
||||
long: true,
|
||||
lockfileDir: workspaceWithPrivatePkgs,
|
||||
})).toBe(`${path.join(workspaceWithPrivatePkgs, 'packages/private')}:private@1.0.0:PRIVATE
|
||||
${path.join(workspaceWithPrivatePkgs, 'packages/private/node_modules/.pnpm/is-positive@1.0.0')}:is-positive@1.0.0
|
||||
${path.join(workspaceWithPrivatePkgs, 'packages/public')}:public@1.0.0
|
||||
${path.join(workspaceWithPrivatePkgs, 'packages/public/node_modules/.pnpm/is-positive@1.0.0')}:is-positive@1.0.0`)
|
||||
})
|
||||
|
||||
test('JSON list in workspace with private package', async () => {
|
||||
expect(await list([
|
||||
path.join(workspaceWithPrivatePkgs, 'packages/private'),
|
||||
path.join(workspaceWithPrivatePkgs, 'packages/public'),
|
||||
], {
|
||||
reportAs: 'json',
|
||||
lockfileDir: workspaceWithPrivatePkgs,
|
||||
})).toBe(
|
||||
JSON.stringify([
|
||||
{
|
||||
name: 'private',
|
||||
version: '1.0.0',
|
||||
path: path.join(workspaceWithPrivatePkgs, 'packages/private'),
|
||||
private: true,
|
||||
dependencies: {
|
||||
'is-positive': {
|
||||
from: 'is-positive',
|
||||
version: '1.0.0',
|
||||
resolved: 'https://registry.npmjs.org/is-positive/-/is-positive-1.0.0.tgz',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'public',
|
||||
version: '1.0.0',
|
||||
path: path.join(workspaceWithPrivatePkgs, 'packages/public'),
|
||||
private: false,
|
||||
dependencies: {
|
||||
'is-positive': {
|
||||
from: 'is-positive',
|
||||
version: '1.0.0',
|
||||
resolved: 'https://registry.npmjs.org/is-positive/-/is-positive-1.0.0.tgz',
|
||||
},
|
||||
},
|
||||
},
|
||||
], null, 2)
|
||||
)
|
||||
})
|
||||
|
||||
test('parseable list with depth 1', async () => {
|
||||
expect(await list([fixture], { reportAs: 'parseable', depth: 1, lockfileDir: fixture })).toBe(`${fixture}
|
||||
${path.join(fixture, 'node_modules/.pnpm/detect-indent@5.0.0')}
|
||||
@@ -246,6 +332,7 @@ test('JSON list with depth 1', async () => {
|
||||
name: 'fixture',
|
||||
version: '1.0.0',
|
||||
path: fixture,
|
||||
private: false,
|
||||
dependencies: {
|
||||
'write-json-file': {
|
||||
from: 'write-json-file',
|
||||
@@ -321,6 +408,7 @@ test('JSON list with aliased dep', async () => {
|
||||
name: 'with-aliased-dep',
|
||||
version: '1.0.0',
|
||||
path: fixtureWithAliasedDep,
|
||||
private: false,
|
||||
dependencies: {
|
||||
positive: {
|
||||
from: 'is-positive',
|
||||
@@ -338,6 +426,7 @@ test('JSON list with aliased dep', async () => {
|
||||
name: 'with-aliased-dep',
|
||||
version: '1.0.0',
|
||||
path: fixtureWithAliasedDep,
|
||||
private: false,
|
||||
dependencies: {
|
||||
positive: {
|
||||
from: 'is-positive',
|
||||
|
||||
Reference in New Issue
Block a user