feat: pnpm list to show information whether the package is private or not (#4256)

close #4246
This commit is contained in:
Kenrick
2022-01-19 17:27:51 +08:00
committed by GitHub
parent b39cabde82
commit 57af1b1b5e
12 changed files with 148 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/list": minor
---
pnpm list to show information whether the package is private or not

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1,8 @@
{
"name": "private",
"version": "1.0.0",
"private": true,
"dependencies": {
"is-positive": "1.0.0"
}
}

View File

@@ -0,0 +1,8 @@
{
"name": "public",
"version": "1.0.0",
"dependencies": {
"is-positive": "1.0.0"
}
}

View 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

View File

@@ -0,0 +1,2 @@
packages:
- 'packages/**'

View File

@@ -97,6 +97,7 @@ export default async function (
return {
name: entryPkg.name,
version: entryPkg.version,
private: entryPkg.private,
path: projectPath,
...dependenciesHierarchy,

View File

@@ -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) {

View File

@@ -44,6 +44,9 @@ function renderParseableForPackage (
if (pkg.version) {
firstLine += `@${pkg.version}`
}
if (pkg.private) {
firstLine += ':PRIVATE'
}
}
return [
firstLine,

View File

@@ -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[] = [

View File

@@ -4,4 +4,5 @@ export type PackageDependencyHierarchy = DependenciesHierarchy & {
name?: string
version?: string
path: string
private?: boolean
}

View File

@@ -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',