Skip to content

Commit 1155072

Browse files
reggiCopilot
andcommitted
feat: publish --access=private alias for restricted
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 596706a commit 1155072

6 files changed

Lines changed: 73 additions & 6 deletions

File tree

tap-snapshots/test/lib/commands/publish.js.test.cjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,28 @@ exports[`test/lib/commands/publish.js TAP prioritize CLI flags over publishConfi
266266
+ @npmcli/test-package@1.0.0
267267
`
268268

269+
exports[`test/lib/commands/publish.js TAP private access > must match snapshot 1`] = `
270+
Array [
271+
"package: @npm/test-package@1.0.0",
272+
"Tarball Contents",
273+
"55B package.json",
274+
"Tarball Details",
275+
"name: @npm/test-package",
276+
"version: 1.0.0",
277+
"filename: npm-test-package-1.0.0.tgz",
278+
"package size: {size}",
279+
"unpacked size: 55 B",
280+
"shasum: {sha}",
281+
"integrity: {integrity}
282+
"total files: 1",
283+
"Publishing to https://registry.npmjs.org/ with tag latest and restricted access",
284+
]
285+
`
286+
287+
exports[`test/lib/commands/publish.js TAP private access > new package version 1`] = `
288+
+ @npm/test-package@1.0.0
289+
`
290+
269291
exports[`test/lib/commands/publish.js TAP public access > must match snapshot 1`] = `
270292
Array [
271293
"package: @npm/test-package@1.0.0",

tap-snapshots/test/lib/docs.js.test.cjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ safer to use a registry-provided authentication bearer token stored in the
191191
192192
* Default: 'public' for new packages, existing packages it will not change the
193193
current level
194-
* Type: null, "restricted", or "public"
194+
* Type: null, "restricted", "public", or "private"
195195
196196
If you do not want your scoped package to be publicly viewable (and
197197
installable) set \`--access=restricted\`.
@@ -203,6 +203,8 @@ packages. Specifying a value of \`restricted\` or \`public\` during publish will
203203
change the access for an existing package the same way that \`npm access set
204204
status\` would.
205205
206+
The value \`private\` is an alias for \`restricted\`.
207+
206208
207209
208210
#### \`all\`
@@ -5075,7 +5077,7 @@ Usage:
50755077
npm publish <package-spec>
50765078
50775079
Options:
5078-
[--tag <tag>] [--access <restricted|public>] [--dry-run] [--otp <otp>]
5080+
[--tag <tag>] [--access <restricted|public|private>] [--dry-run] [--otp <otp>]
50795081
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
50805082
[--workspaces] [--include-workspace-root] [--provenance|--provenance-file <file>]
50815083

test/lib/commands/publish.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,27 @@ t.test('restricted access', async t => {
742742
t.matchSnapshot(logs.notice)
743743
})
744744

745+
t.test('private access', async t => {
746+
const packageJson = {
747+
name: '@npm/test-package',
748+
version: '1.0.0',
749+
}
750+
const { npm, joinedOutput, logs, registry } = await loadNpmWithRegistry(t, {
751+
config: {
752+
...auth,
753+
access: 'private',
754+
},
755+
prefixDir: {
756+
'package.json': JSON.stringify(packageJson, null, 2),
757+
},
758+
authorization: token,
759+
})
760+
registry.publish('@npm/test-package', { packageJson, access: 'restricted' })
761+
await npm.exec('publish', [])
762+
t.matchSnapshot(joinedOutput(), 'new package version')
763+
t.matchSnapshot(logs.notice)
764+
})
765+
745766
t.test('public access', async t => {
746767
const { npm, joinedOutput, logs, registry } = await loadNpmWithRegistry(t, {
747768
config: {

workspaces/config/lib/definitions/definitions.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ const definitions = {
153153
defaultDescription: `
154154
'public' for new packages, existing packages it will not change the current level
155155
`,
156-
type: [null, 'restricted', 'public'],
156+
type: [null, 'restricted', 'public', 'private'],
157157
description: `
158158
If you do not want your scoped package to be publicly viewable (and
159159
installable) set \`--access=restricted\`.
@@ -164,8 +164,13 @@ const definitions = {
164164
packages. Specifying a value of \`restricted\` or \`public\` during
165165
publish will change the access for an existing package the same way that
166166
\`npm access set status\` would.
167+
168+
The value \`private\` is an alias for \`restricted\`.
167169
`,
168-
flatten,
170+
flatten (key, obj, flatOptions) {
171+
const value = obj[key]
172+
flatOptions.access = value === 'private' ? 'restricted' : value
173+
},
169174
}),
170175
all: new Definition('all', {
171176
default: false,

workspaces/config/test/definitions/definitions.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ t.test('basic flattening function camelCases from css-case', t => {
3333
t.end()
3434
})
3535

36+
t.test('access flattening maps private to restricted', t => {
37+
const definitions = mockDefs()
38+
const flatPrivate = {}
39+
definitions.access.flatten('access', { access: 'private' }, flatPrivate)
40+
t.equal(flatPrivate.access, 'restricted', 'private is mapped to restricted')
41+
const flatRestricted = {}
42+
definitions.access.flatten('access', { access: 'restricted' }, flatRestricted)
43+
t.equal(flatRestricted.access, 'restricted', 'restricted is passed through')
44+
const flatPublic = {}
45+
definitions.access.flatten('access', { access: 'public' }, flatPublic)
46+
t.equal(flatPublic.access, 'public', 'public is passed through')
47+
const flatNull = {}
48+
definitions.access.flatten('access', { access: null }, flatNull)
49+
t.equal(flatNull.access, null, 'null is passed through')
50+
t.end()
51+
})
52+
3653
t.test('editor', t => {
3754
t.test('has EDITOR and VISUAL, use EDITOR', t => {
3855
mockGlobals(t, { 'process.env': { EDITOR: 'vim', VISUAL: 'mate' } })

workspaces/config/test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ loglevel = yolo
390390
['warn', 'invalid config', 'omit="cucumber"', 'set in command line options'],
391391
['warn', 'invalid config', 'Must be one or more of:', 'dev, optional, peer'],
392392
['warn', 'invalid config', 'access="blueberry"', 'set in command line options'],
393-
['warn', 'invalid config', 'Must be one of:', 'null, restricted, public'],
393+
['warn', 'invalid config', 'Must be one of:', 'null, restricted, public, private'],
394394
['warn', 'invalid config', 'multiple-numbers="what kind of fruit is not a number"',
395395
'set in command line options'],
396396
['warn', 'invalid config', 'Must be one or more', 'numeric value'],
@@ -591,7 +591,7 @@ loglevel = yolo
591591
['warn', 'invalid config', 'omit="cucumber"', 'set in command line options'],
592592
['warn', 'invalid config', 'Must be one or more of:', 'dev, optional, peer'],
593593
['warn', 'invalid config', 'access="blueberry"', 'set in command line options'],
594-
['warn', 'invalid config', 'Must be one of:', 'null, restricted, public'],
594+
['warn', 'invalid config', 'Must be one of:', 'null, restricted, public, private'],
595595
['warn', 'invalid config', 'multiple-numbers="what kind of fruit is not a number"',
596596
'set in command line options'],
597597
['warn', 'invalid config', 'Must be one or more', 'numeric value'],

0 commit comments

Comments
 (0)