Skip to content

Commit dd62db1

Browse files
committed
docs: update docs/logging for new --access default
1 parent f7b6314 commit dd62db1

File tree

8 files changed

+217
-60
lines changed

8 files changed

+217
-60
lines changed

docs/content/commands/npm-publish.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,19 @@ tarball that will be compared with the local files by default.
118118

119119
#### `access`
120120

121-
* Default: 'restricted' for scoped packages, 'public' for unscoped packages
121+
* Default: 'public' for new packages, existing packages it will not change the
122+
current level
122123
* Type: null, "restricted", or "public"
123124

124-
When publishing scoped packages, the access level defaults to `restricted`.
125-
If you want your scoped package to be publicly viewable (and installable)
126-
set `--access=public`. The only valid values for `access` are `public` and
127-
`restricted`. Unscoped packages _always_ have an access level of `public`.
125+
If do not want your scoped package to be publicly viewable (and installable)
126+
set `--access=restricted`.
128127

129-
Note: Using the `--access` flag on the `npm publish` command will only set
130-
the package access level on the initial publish of the package. Any
131-
subsequent `npm publish` commands using the `--access` flag will not have an
132-
effect to the access level. To make changes to the access level after the
133-
initial publish use `npm access`.
128+
Unscoped packages can not be set to `restricted`.
129+
130+
Note: This defaults to not changing the current access level for existing
131+
packages. Specifying a value of `restricted` or `public` during publish will
132+
change the access for an existing package the same way that `npm access set
133+
status` would.
134134

135135
<!-- automatically generated, do not edit manually -->
136136
<!-- see lib/utils/config/definitions.js -->

docs/content/using-npm/config.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,19 @@ safer to use a registry-provided authentication bearer token stored in the
151151

152152
#### `access`
153153

154-
* Default: 'restricted' for scoped packages, 'public' for unscoped packages
154+
* Default: 'public' for new packages, existing packages it will not change the
155+
current level
155156
* Type: null, "restricted", or "public"
156157

157-
When publishing scoped packages, the access level defaults to `restricted`.
158-
If you want your scoped package to be publicly viewable (and installable)
159-
set `--access=public`. The only valid values for `access` are `public` and
160-
`restricted`. Unscoped packages _always_ have an access level of `public`.
158+
If do not want your scoped package to be publicly viewable (and installable)
159+
set `--access=restricted`.
161160

162-
Note: Using the `--access` flag on the `npm publish` command will only set
163-
the package access level on the initial publish of the package. Any
164-
subsequent `npm publish` commands using the `--access` flag will not have an
165-
effect to the access level. To make changes to the access level after the
166-
initial publish use `npm access`.
161+
Unscoped packages can not be set to `restricted`.
162+
163+
Note: This defaults to not changing the current access level for existing
164+
packages. Specifying a value of `restricted` or `public` during publish will
165+
change the access for an existing package the same way that `npm access set
166+
status` would.
167167

168168
<!-- automatically generated, do not edit manually -->
169169
<!-- see lib/utils/config/definitions.js -->

lib/commands/publish.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,13 @@ class Publish extends BaseCommand {
114114
}
115115
}
116116

117-
log.notice(
118-
'',
119-
`Publishing to ${outputRegistry} with tag ${defaultTag}${dryRun ? ' (dry-run)' : ''}`
120-
)
117+
const access = opts.access === null ? 'default' : opts.access
118+
let msg = `Publishing to ${outputRegistry} with tag ${defaultTag} and ${access} access`
119+
if (dryRun) {
120+
msg = `${msg} (dry-run)`
121+
}
122+
123+
log.notice('', msg)
121124

122125
if (!dryRun) {
123126
await otplease(this.npm, opts, opts => libpub(manifest, tarballData, opts))

lib/utils/config/definitions.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,19 @@ define('_auth', {
160160
define('access', {
161161
default: null,
162162
defaultDescription: `
163-
'restricted' for scoped packages, 'public' for unscoped packages
163+
'public' for new packages, existing packages it will not change the current level
164164
`,
165165
type: [null, 'restricted', 'public'],
166166
description: `
167-
When publishing scoped packages, the access level defaults to
168-
\`restricted\`. If you want your scoped package to be publicly viewable
169-
(and installable) set \`--access=public\`. The only valid values for
170-
\`access\` are \`public\` and \`restricted\`. Unscoped packages _always_
171-
have an access level of \`public\`.
172-
173-
Note: Using the \`--access\` flag on the \`npm publish\` command will only
174-
set the package access level on the initial publish of the package. Any
175-
subsequent \`npm publish\` commands using the \`--access\` flag will not
176-
have an effect to the access level. To make changes to the access level
177-
after the initial publish use \`npm access\`.
167+
If do not want your scoped package to be publicly viewable (and
168+
installable) set \`--access=restricted\`.
169+
170+
Unscoped packages can not be set to \`restricted\`.
171+
172+
Note: This defaults to not changing the current access level for existing
173+
packages. Specifying a value of \`restricted\` or \`public\` during
174+
publish will change the access for an existing package the same way that
175+
\`npm access set status\` would.
178176
`,
179177
flatten,
180178
})

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

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Array [
5151
],
5252
Array [
5353
"",
54-
"Publishing to https://registry.npmjs.org/ with tag latest (dry-run)",
54+
"Publishing to https://registry.npmjs.org/ with tag latest and default access (dry-run)",
5555
],
5656
]
5757
`
@@ -72,7 +72,7 @@ exports[`test/lib/commands/publish.js TAP json > must match snapshot 1`] = `
7272
Array [
7373
Array [
7474
"",
75-
"Publishing to https://registry.npmjs.org/ with tag latest",
75+
"Publishing to https://registry.npmjs.org/ with tag latest and default access",
7676
],
7777
]
7878
`
@@ -112,6 +112,53 @@ Array [
112112
]
113113
`
114114

115+
exports[`test/lib/commands/publish.js TAP public access > must match snapshot 1`] = `
116+
Array [
117+
Array [
118+
"",
119+
],
120+
Array [
121+
"",
122+
"package: @npm/[email protected]",
123+
],
124+
Array [
125+
"=== Tarball Contents ===",
126+
],
127+
Array [
128+
"",
129+
"55B package.json",
130+
],
131+
Array [
132+
"=== Tarball Details ===",
133+
],
134+
Array [
135+
"",
136+
String(
137+
name: @npm/test-package
138+
version: 1.0.0
139+
filename: @npm/test-package-1.0.0.tgz
140+
package size: 147 B
141+
unpacked size: 55 B
142+
shasum:{sha}
143+
integrity:{sha}
144+
total files: 1
145+
),
146+
],
147+
Array [
148+
"",
149+
"",
150+
],
151+
Array [
152+
"",
153+
"Publishing to https://registry.npmjs.org/ with tag latest and public access",
154+
],
155+
]
156+
`
157+
158+
exports[`test/lib/commands/publish.js TAP public access > new package version 1`] = `
159+
160+
`
161+
115162
exports[`test/lib/commands/publish.js TAP re-loads publishConfig.registry if added during script process > new package version 1`] = `
116163
117164
`
@@ -120,6 +167,53 @@ exports[`test/lib/commands/publish.js TAP respects publishConfig.registry, runs
120167
121168
`
122169

170+
exports[`test/lib/commands/publish.js TAP restricted access > must match snapshot 1`] = `
171+
Array [
172+
Array [
173+
"",
174+
],
175+
Array [
176+
"",
177+
"package: @npm/[email protected]",
178+
],
179+
Array [
180+
"=== Tarball Contents ===",
181+
],
182+
Array [
183+
"",
184+
"55B package.json",
185+
],
186+
Array [
187+
"=== Tarball Details ===",
188+
],
189+
Array [
190+
"",
191+
String(
192+
name: @npm/test-package
193+
version: 1.0.0
194+
filename: @npm/test-package-1.0.0.tgz
195+
package size: 147 B
196+
unpacked size: 55 B
197+
shasum:{sha}
198+
integrity:{sha}
199+
total files: 1
200+
),
201+
],
202+
Array [
203+
"",
204+
"",
205+
],
206+
Array [
207+
"",
208+
"Publishing to https://registry.npmjs.org/ with tag latest and restricted access",
209+
],
210+
]
211+
`
212+
213+
exports[`test/lib/commands/publish.js TAP restricted access > new package version 1`] = `
214+
215+
`
216+
123217
exports[`test/lib/commands/publish.js TAP scoped _auth config scoped registry > new package version 1`] = `
124218
125219
`
@@ -165,7 +259,7 @@ Array [
165259
],
166260
Array [
167261
"",
168-
"Publishing to https://registry.npmjs.org/ with tag latest",
262+
"Publishing to https://registry.npmjs.org/ with tag latest and default access",
169263
],
170264
]
171265
`

tap-snapshots/test/lib/utils/config/definitions.js.test.cjs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,19 @@ safer to use a registry-provided authentication bearer token stored in the
180180
exports[`test/lib/utils/config/definitions.js TAP > config description for access 1`] = `
181181
#### \`access\`
182182
183-
* Default: 'restricted' for scoped packages, 'public' for unscoped packages
183+
* Default: 'public' for new packages, existing packages it will not change the
184+
current level
184185
* Type: null, "restricted", or "public"
185186
186-
When publishing scoped packages, the access level defaults to \`restricted\`.
187-
If you want your scoped package to be publicly viewable (and installable)
188-
set \`--access=public\`. The only valid values for \`access\` are \`public\` and
189-
\`restricted\`. Unscoped packages _always_ have an access level of \`public\`.
187+
If do not want your scoped package to be publicly viewable (and installable)
188+
set \`--access=restricted\`.
190189
191-
Note: Using the \`--access\` flag on the \`npm publish\` command will only set
192-
the package access level on the initial publish of the package. Any
193-
subsequent \`npm publish\` commands using the \`--access\` flag will not have an
194-
effect to the access level. To make changes to the access level after the
195-
initial publish use \`npm access\`.
190+
Unscoped packages can not be set to \`restricted\`.
191+
192+
Note: This defaults to not changing the current access level for existing
193+
packages. Specifying a value of \`restricted\` or \`public\` during publish will
194+
change the access for an existing package the same way that \`npm access set
195+
status\` would.
196196
`
197197

198198
exports[`test/lib/utils/config/definitions.js TAP > config description for all 1`] = `

tap-snapshots/test/lib/utils/config/describe-all.js.test.cjs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ safer to use a registry-provided authentication bearer token stored in the
2424
2525
#### \`access\`
2626
27-
* Default: 'restricted' for scoped packages, 'public' for unscoped packages
27+
* Default: 'public' for new packages, existing packages it will not change the
28+
current level
2829
* Type: null, "restricted", or "public"
2930
30-
When publishing scoped packages, the access level defaults to \`restricted\`.
31-
If you want your scoped package to be publicly viewable (and installable)
32-
set \`--access=public\`. The only valid values for \`access\` are \`public\` and
33-
\`restricted\`. Unscoped packages _always_ have an access level of \`public\`.
31+
If do not want your scoped package to be publicly viewable (and installable)
32+
set \`--access=restricted\`.
3433
35-
Note: Using the \`--access\` flag on the \`npm publish\` command will only set
36-
the package access level on the initial publish of the package. Any
37-
subsequent \`npm publish\` commands using the \`--access\` flag will not have an
38-
effect to the access level. To make changes to the access level after the
39-
initial publish use \`npm access\`.
34+
Unscoped packages can not be set to \`restricted\`.
35+
36+
Note: This defaults to not changing the current access level for existing
37+
packages. Specifying a value of \`restricted\` or \`public\` during publish will
38+
change the access for an existing package the same way that \`npm access set
39+
status\` would.
4040
4141
<!-- automatically generated, do not edit manually -->
4242
<!-- see lib/utils/config/definitions.js -->

test/lib/commands/publish.js

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ t.cleanSnapshot = data => {
2828
t.test('respects publishConfig.registry, runs appropriate scripts', async t => {
2929
const { npm, joinedOutput, prefix } = await loadMockNpm(t, {
3030
config: {
31-
loglevel: 'silent', // prevent scripts from leaking to stdout during the test
31+
loglevel: 'silent',
3232
[`${alternateRegistry.slice(6)}/:_authToken`]: 'test-other-token',
3333
},
3434
prefixDir: {
@@ -730,3 +730,65 @@ t.test('scoped _auth config scoped registry', async t => {
730730
await npm.exec('publish', [])
731731
t.matchSnapshot(joinedOutput(), 'new package version')
732732
})
733+
734+
t.test('restricted access', async t => {
735+
const spec = npa('@npm/test-package')
736+
const { npm, joinedOutput, logs } = await loadMockNpm(t, {
737+
config: {
738+
...auth,
739+
access: 'restricted',
740+
},
741+
prefixDir: {
742+
'package.json': JSON.stringify({
743+
name: '@npm/test-package',
744+
version: '1.0.0',
745+
}, null, 2),
746+
},
747+
globals: ({ prefix }) => ({
748+
'process.cwd': () => prefix,
749+
}),
750+
})
751+
const registry = new MockRegistry({
752+
tap: t,
753+
registry: npm.config.get('registry'),
754+
authorization: token,
755+
})
756+
registry.nock.put(`/${spec.escapedName}`, body => {
757+
t.equal(body.access, 'restricted', 'access is explicitly set to restricted')
758+
return true
759+
}).reply(200, {})
760+
await npm.exec('publish', [])
761+
t.matchSnapshot(joinedOutput(), 'new package version')
762+
t.matchSnapshot(logs.notice)
763+
})
764+
765+
t.test('public access', async t => {
766+
const spec = npa('@npm/test-package')
767+
const { npm, joinedOutput, logs } = await loadMockNpm(t, {
768+
config: {
769+
...auth,
770+
access: 'public',
771+
},
772+
prefixDir: {
773+
'package.json': JSON.stringify({
774+
name: '@npm/test-package',
775+
version: '1.0.0',
776+
}, null, 2),
777+
},
778+
globals: ({ prefix }) => ({
779+
'process.cwd': () => prefix,
780+
}),
781+
})
782+
const registry = new MockRegistry({
783+
tap: t,
784+
registry: npm.config.get('registry'),
785+
authorization: token,
786+
})
787+
registry.nock.put(`/${spec.escapedName}`, body => {
788+
t.equal(body.access, 'public', 'access is explicitly set to public')
789+
return true
790+
}).reply(200, {})
791+
await npm.exec('publish', [])
792+
t.matchSnapshot(joinedOutput(), 'new package version')
793+
t.matchSnapshot(logs.notice)
794+
})

0 commit comments

Comments
 (0)