Skip to content

Commit b699ad2

Browse files
smnbbrvhansl
authored andcommitted
fix(@schematics/update): process always-auth and _auth correctly, better support for private repositories
1 parent 8c4ddff commit b699ad2

File tree

1 file changed

+26
-3
lines changed
  • packages/schematics/update/update

1 file changed

+26
-3
lines changed

packages/schematics/update/update/npm.ts

+26-3
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ export function getNpmPackageJson(
198198
getNpmConfigOption('_authToken', registryKey),
199199
getNpmConfigOption('username', registryKey, true),
200200
getNpmConfigOption('password', registryKey, true),
201-
getNpmConfigOption('alwaysAuth', registryKey, true),
201+
getNpmConfigOption('email', registryKey, true),
202+
getNpmConfigOption('always-auth', registryKey, true),
202203
).pipe(
203204
toArray(),
204205
concatMap(options => {
@@ -211,6 +212,7 @@ export function getNpmPackageJson(
211212
authToken,
212213
username,
213214
password,
215+
email,
214216
alwaysAuth,
215217
] = options;
216218

@@ -222,17 +224,38 @@ export function getNpmPackageJson(
222224
token?: string,
223225
alwaysAuth?: boolean;
224226
username?: string;
225-
password?: string
227+
password?: string;
228+
email?: string;
226229
} = {};
227230

228231
if (alwaysAuth !== undefined) {
229232
auth.alwaysAuth = alwaysAuth === 'false' ? false : !!alwaysAuth;
230233
}
231234

235+
if (email) {
236+
auth.email = email;
237+
}
238+
232239
if (authToken) {
233240
auth.token = authToken;
234241
} else if (token) {
235-
auth.token = token;
242+
try {
243+
// attempt to parse "username:password" from base64 token
244+
// to enable Artifactory / Nexus-like repositories support
245+
const delimiter = ':';
246+
const parsedToken = Buffer.from(token, 'base64').toString('ascii');
247+
const [extractedUsername, ...passwordArr] = parsedToken.split(delimiter);
248+
const extractedPassword = passwordArr.join(delimiter);
249+
250+
if (extractedUsername && extractedPassword) {
251+
auth.username = extractedUsername;
252+
auth.password = extractedPassword;
253+
} else {
254+
throw new Error('Unable to extract username and password from _auth token');
255+
}
256+
} catch (ex) {
257+
auth.token = token;
258+
}
236259
} else if (username) {
237260
auth.username = username;
238261
auth.password = password;

0 commit comments

Comments
 (0)