0
# Registry Operations
1
2
Commands for interacting with npm registries, managing authentication, and publishing packages.
3
4
## Capabilities
5
6
### Authentication
7
8
Manage authentication credentials for package registries.
9
10
```bash { .api }
11
yarn login # Login to registry (interactive)
12
yarn logout # Logout from current registry
13
```
14
15
**Usage Examples:**
16
17
```bash
18
# Login to default registry (npmjs.org)
19
yarn login
20
21
# Login to scoped registry
22
npm login --registry=https://npm.company.com --scope=@company
23
24
# Logout from current registry
25
yarn logout
26
```
27
28
**Login Process:**
29
1. Prompts for username
30
2. Prompts for password
31
3. Prompts for email
32
4. Optionally prompts for 2FA token
33
5. Stores authentication token in `.yarnrc` or global config
34
35
### Package Publishing
36
37
Publish packages to the registry.
38
39
```bash { .api }
40
yarn publish [tarball] [options]
41
42
# Options:
43
--tag <tag> # Publish with specific tag (default: "latest")
44
--access <public|restricted> # Set package access level
45
--registry <url> # Publish to specific registry
46
--new-version <version> # Set version before publishing
47
--major # Increment major version before publishing
48
--minor # Increment minor version before publishing
49
--patch # Increment patch version before publishing
50
--no-git-tag-version # Don't create git tag for version
51
--no-commit-hooks # Don't run git commit hooks
52
```
53
54
**Usage Examples:**
55
56
```bash
57
# Basic publish (uses version from package.json)
58
yarn publish
59
60
# Publish with tag
61
yarn publish --tag beta
62
yarn publish --tag next
63
64
# Publish as public package (for scoped packages)
65
yarn publish --access public
66
67
# Publish to specific registry
68
yarn publish --registry https://npm.company.com
69
70
# Increment version and publish
71
yarn publish --patch # 1.0.0 -> 1.0.1
72
yarn publish --minor # 1.0.0 -> 1.1.0
73
yarn publish --major # 1.0.0 -> 2.0.0
74
75
# Publish specific version
76
yarn publish --new-version 1.2.3
77
78
# Publish tarball
79
yarn pack
80
yarn publish package.tgz
81
```
82
83
**Publishing Process:**
84
1. Runs `prepublishOnly` script
85
2. Creates package tarball
86
3. Uploads to registry
87
4. Runs `postpublish` script
88
5. Optionally creates git tag
89
90
### Package Access Management
91
92
Manage who can access and modify packages.
93
94
```bash { .api }
95
yarn access public <package> # Make package public
96
yarn access restricted <package> # Make package restricted (private)
97
yarn access grant <permissions> <scope:team> <package> # Grant access
98
yarn access revoke <permissions> <scope:team> <package> # Revoke access
99
yarn access list packages [scope] # List packages user can access
100
yarn access list collaborators <package> # List package collaborators
101
yarn access edit <package> # Edit package access (opens editor)
102
103
# Permissions:
104
# read-only - Can download and install
105
# read-write - Can download, install, and publish
106
```
107
108
**Usage Examples:**
109
110
```bash
111
# Make scoped package public
112
yarn access public @mycompany/my-package
113
114
# Make package private
115
yarn access restricted my-package
116
117
# Grant read-only access to team
118
yarn access grant read-only @mycompany:developers @mycompany/my-package
119
120
# Grant read-write access to team
121
yarn access grant read-write @mycompany:maintainers @mycompany/my-package
122
123
# Revoke access from team
124
yarn access revoke read-write @mycompany:developers @mycompany/my-package
125
126
# List packages I can access
127
yarn access list packages
128
129
# List packages for specific scope
130
yarn access list packages @mycompany
131
132
# List who has access to package
133
yarn access list collaborators @mycompany/my-package
134
```
135
136
### Package Ownership
137
138
Manage package ownership and maintainers.
139
140
```bash { .api }
141
yarn owner add <user> <package> # Add user as owner
142
yarn owner remove <user> <package> # Remove user as owner
143
yarn owner list <package> # List package owners
144
```
145
146
**Usage Examples:**
147
148
```bash
149
# Add owner to package
150
yarn owner add john-doe my-package
151
yarn owner add jane-smith @mycompany/my-package
152
153
# Remove owner from package
154
yarn owner remove former-employee my-package
155
156
# List current owners
157
yarn owner list my-package
158
yarn owner list @mycompany/my-package
159
```
160
161
**Owner Permissions:**
162
- Publish new versions
163
- Add/remove other owners
164
- Manage package access
165
- Deprecate package versions
166
- Transfer package ownership
167
168
### Package Tags
169
170
Manage package version tags for different release channels.
171
172
```bash { .api }
173
yarn tag add <package>@<version> <tag> # Add tag to version
174
yarn tag remove <package> <tag> # Remove tag
175
yarn tag list <package> # List all tags for package
176
```
177
178
**Usage Examples:**
179
180
```bash
181
# Add tag to specific version
182
yarn tag add my-package@1.2.0 beta
183
yarn tag add my-package@2.0.0-rc.1 next
184
185
# Remove tag
186
yarn tag remove my-package beta
187
yarn tag remove my-package next
188
189
# List all tags
190
yarn tag list my-package
191
192
# Common tag patterns
193
yarn tag add my-package@1.0.1 latest # Stable release
194
yarn tag add my-package@1.1.0-beta.1 beta # Beta release
195
yarn tag add my-package@2.0.0-alpha.1 alpha # Alpha release
196
yarn tag add my-package@1.0.2 lts # Long-term support
197
```
198
199
**Installing Tagged Versions:**
200
```bash
201
# Install specific tag
202
yarn add my-package@beta
203
yarn add my-package@next
204
yarn add my-package@lts
205
206
# Default tag is "latest"
207
yarn add my-package # Same as my-package@latest
208
```
209
210
### Team Management
211
212
Manage organization teams and permissions (npm Organizations feature).
213
214
```bash { .api }
215
yarn team create <scope:team> # Create team
216
yarn team destroy <scope:team> # Delete team
217
yarn team add <scope:team> <user> # Add user to team
218
yarn team remove <scope:team> <user> # Remove user from team
219
yarn team list <scope> # List teams in scope
220
yarn team list <scope:team> # List users in team
221
```
222
223
**Usage Examples:**
224
225
```bash
226
# Create team
227
yarn team create @mycompany:developers
228
yarn team create @mycompany:admins
229
230
# Add users to team
231
yarn team add @mycompany:developers john-doe
232
yarn team add @mycompany:developers jane-smith
233
234
# Remove user from team
235
yarn team remove @mycompany:developers former-employee
236
237
# List all teams in organization
238
yarn team list @mycompany
239
240
# List users in specific team
241
yarn team list @mycompany:developers
242
243
# Delete team
244
yarn team destroy @mycompany:old-team
245
```
246
247
**Team Integration with Access Control:**
248
```bash
249
# Grant access to team
250
yarn access grant read-only @mycompany:developers @mycompany/my-package
251
yarn access grant read-write @mycompany:maintainers @mycompany/my-package
252
253
# Revoke access from team
254
yarn access revoke read-write @mycompany:developers @mycompany/my-package
255
```
256
257
## Registry Configuration
258
259
### Default Registry
260
261
```bash
262
# Set default registry
263
yarn config set registry https://registry.npmjs.org
264
265
# Use company registry
266
yarn config set registry https://npm.company.com
267
268
# Check current registry
269
yarn config get registry
270
```
271
272
### Scoped Registries
273
274
```bash
275
# Set registry for specific scope
276
yarn config set @mycompany:registry https://npm.company.com
277
278
# Set authentication for scoped registry
279
yarn config set //npm.company.com/:_authToken ${NPM_TOKEN}
280
281
# Install from scoped registry
282
yarn add @mycompany/internal-package
283
```
284
285
### Authentication Tokens
286
287
```bash
288
# Set authentication token
289
yarn config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
290
291
# Set token for specific registry
292
yarn config set //npm.company.com/:_authToken ${COMPANY_NPM_TOKEN}
293
294
# Use .npmrc file for project-specific config
295
echo "//npm.company.com/:_authToken=${NPM_TOKEN}" >> .npmrc
296
```
297
298
## Publishing Workflows
299
300
### Pre-publish Preparation
301
302
```json
303
{
304
"scripts": {
305
"prepublishOnly": "yarn test && yarn build",
306
"postpublish": "echo 'Published successfully!'"
307
},
308
"files": [
309
"dist/",
310
"lib/",
311
"README.md",
312
"package.json"
313
]
314
}
315
```
316
317
### Version Management
318
319
```bash
320
# Semantic versioning workflow
321
yarn version --patch # Bug fixes: 1.0.0 -> 1.0.1
322
yarn version --minor # New features: 1.0.0 -> 1.1.0
323
yarn version --major # Breaking changes: 1.0.0 -> 2.0.0
324
325
# Pre-release versions
326
yarn version --prerelease # 1.0.0 -> 1.0.1-0
327
yarn version --prerelease --preid=alpha # 1.0.0 -> 1.0.1-alpha.0
328
yarn version --prerelease --preid=beta # 1.0.0 -> 1.0.1-beta.0
329
yarn version --prerelease --preid=rc # 1.0.0 -> 1.0.1-rc.0
330
331
# Specific version
332
yarn version --new-version 2.1.0
333
```
334
335
### CI/CD Publishing
336
337
```bash
338
# Automated publishing in CI
339
if [ "$BRANCH" = "main" ]; then
340
yarn publish --tag latest
341
elif [ "$BRANCH" = "develop" ]; then
342
yarn publish --tag beta
343
fi
344
345
# Publishing with 2FA in CI (using npm)
346
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
347
npm publish --tag latest
348
349
# Security: Clean up token after publishing
350
rm .npmrc
351
```
352
353
### Monorepo Publishing
354
355
```bash
356
# Publish all workspace packages
357
yarn workspaces foreach --no-private publish
358
359
# Publish specific workspace
360
yarn workspace @company/package-a publish --tag latest
361
362
# Version and publish all packages
363
yarn workspaces foreach version patch
364
yarn workspaces foreach --no-private publish
365
```