diff --git a/.changeset/flat-seahorses-count.md b/.changeset/flat-seahorses-count.md new file mode 100644 index 0000000000..04b7035749 --- /dev/null +++ b/.changeset/flat-seahorses-count.md @@ -0,0 +1,5 @@ +--- +"@pnpm/list": minor +--- + +pnpm list to show information whether the package is private or not diff --git a/fixtures/workspace-with-private-pkgs/package.json b/fixtures/workspace-with-private-pkgs/package.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/fixtures/workspace-with-private-pkgs/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/fixtures/workspace-with-private-pkgs/packages/private/package.json b/fixtures/workspace-with-private-pkgs/packages/private/package.json new file mode 100644 index 0000000000..84de736e2b --- /dev/null +++ b/fixtures/workspace-with-private-pkgs/packages/private/package.json @@ -0,0 +1,8 @@ +{ + "name": "private", + "version": "1.0.0", + "private": true, + "dependencies": { + "is-positive": "1.0.0" + } +} diff --git a/fixtures/workspace-with-private-pkgs/packages/public/package.json b/fixtures/workspace-with-private-pkgs/packages/public/package.json new file mode 100644 index 0000000000..1ef8a940b5 --- /dev/null +++ b/fixtures/workspace-with-private-pkgs/packages/public/package.json @@ -0,0 +1,8 @@ +{ + "name": "public", + "version": "1.0.0", + "dependencies": { + "is-positive": "1.0.0" + } +} + diff --git a/fixtures/workspace-with-private-pkgs/pnpm-lock.yaml b/fixtures/workspace-with-private-pkgs/pnpm-lock.yaml new file mode 100644 index 0000000000..7d56e232cf --- /dev/null +++ b/fixtures/workspace-with-private-pkgs/pnpm-lock.yaml @@ -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 diff --git a/fixtures/workspace-with-private-pkgs/pnpm-workspace.yaml b/fixtures/workspace-with-private-pkgs/pnpm-workspace.yaml new file mode 100644 index 0000000000..eccc335f93 --- /dev/null +++ b/fixtures/workspace-with-private-pkgs/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - 'packages/**' \ No newline at end of file diff --git a/packages/list/src/index.ts b/packages/list/src/index.ts index b92ee12b99..0b40640fb4 100644 --- a/packages/list/src/index.ts +++ b/packages/list/src/index.ts @@ -97,6 +97,7 @@ export default async function ( return { name: entryPkg.name, version: entryPkg.version, + private: entryPkg.private, path: projectPath, ...dependenciesHierarchy, diff --git a/packages/list/src/renderJson.ts b/packages/list/src/renderJson.ts index e0bbacd5fb..dbd3af3dbc 100644 --- a/packages/list/src/renderJson.ts +++ b/packages/list/src/renderJson.ts @@ -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) { diff --git a/packages/list/src/renderParseable.ts b/packages/list/src/renderParseable.ts index 9c69004c34..5918f4ef4e 100644 --- a/packages/list/src/renderParseable.ts +++ b/packages/list/src/renderParseable.ts @@ -44,6 +44,9 @@ function renderParseableForPackage ( if (pkg.version) { firstLine += `@${pkg.version}` } + if (pkg.private) { + firstLine += ':PRIVATE' + } } return [ firstLine, diff --git a/packages/list/src/renderTree.ts b/packages/list/src/renderTree.ts index c3f190e37d..2cb4e6ecd5 100644 --- a/packages/list/src/renderTree.ts +++ b/packages/list/src/renderTree.ts @@ -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[] = [ diff --git a/packages/list/src/types.ts b/packages/list/src/types.ts index 17852ffad4..85b3c67ecc 100644 --- a/packages/list/src/types.ts +++ b/packages/list/src/types.ts @@ -4,4 +4,5 @@ export type PackageDependencyHierarchy = DependenciesHierarchy & { name?: string version?: string path: string + private?: boolean } diff --git a/packages/list/test/index.ts b/packages/list/test/index.ts index 276e654d1f..4c87ccd6b9 100644 --- a/packages/list/test/index.ts +++ b/packages/list/test/index.ts @@ -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',