Skip to content

Commit 4b67f6e

Browse files
github-actions[bot]reggiCopilot
authored
feat: publish --access=private alias for restricted (#9416)
Backport of #9153 to `release/v11`. Co-authored-by: Tea Reggi <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent a10c7ca commit 4b67f6e

7 files changed

Lines changed: 74 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
@@ -271,6 +271,28 @@ exports[`test/lib/commands/publish.js TAP prioritize CLI flags over publishConfi
271271
272272
`
273273

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

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ safer to use a registry-provided authentication bearer token stored in the
195195
196196
* Default: 'public' for new packages, existing packages it will not change the
197197
current level
198-
* Type: null, "restricted", or "public"
198+
* Type: null, "restricted", "public", or "private"
199199
200200
If you do not want your scoped package to be publicly viewable (and
201201
installable) set \`--access=restricted\`.
@@ -207,6 +207,8 @@ packages. Specifying a value of \`restricted\` or \`public\` during publish will
207207
change the access for an existing package the same way that \`npm access set
208208
status\` would.
209209
210+
The value \`private\` is an alias for \`restricted\`.
211+
210212
211213
212214
#### \`all\`
@@ -5472,7 +5474,7 @@ Usage:
54725474
npm publish <package-spec>
54735475
54745476
Options:
5475-
[--tag <tag>] [--access <restricted|public>] [--dry-run] [--otp <otp>]
5477+
[--tag <tag>] [--access <restricted|public|private>] [--dry-run] [--otp <otp>]
54765478
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
54775479
[--workspaces] [--include-workspace-root] [--provenance|--provenance-file <file>]
54785480

‎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
@@ -154,7 +154,7 @@ const definitions = {
154154
defaultDescription: `
155155
'public' for new packages, existing packages it will not change the current level
156156
`,
157-
type: [null, 'restricted', 'public'],
157+
type: [null, 'restricted', 'public', 'private'],
158158
description: `
159159
If you do not want your scoped package to be publicly viewable (and
160160
installable) set \`--access=restricted\`.
@@ -165,8 +165,13 @@ const definitions = {
165165
packages. Specifying a value of \`restricted\` or \`public\` during
166166
publish will change the access for an existing package the same way that
167167
\`npm access set status\` would.
168+
169+
The value \`private\` is an alias for \`restricted\`.
168170
`,
169-
flatten,
171+
flatten (key, obj, flatOptions) {
172+
const value = obj[key]
173+
flatOptions.access = value === 'private' ? 'restricted' : value
174+
},
170175
}),
171176
all: new Definition('all', {
172177
default: false,

‎workspaces/config/tap-snapshots/test/type-description.js.test.cjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Object {
1515
null,
1616
"restricted",
1717
"public",
18+
"private",
1819
],
1920
"all": Array [
2021
"boolean value (true or 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)