-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathverify-auth.js
33 lines (30 loc) · 1022 Bytes
/
verify-auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { execa } from "execa";
import normalizeUrl from "normalize-url";
import AggregateError from "aggregate-error";
import getError from "./get-error.js";
import getRegistry from "./get-registry.js";
import setNpmrcAuth from "./set-npmrc-auth.js";
export default async function (npmrc, pkg, context) {
const {
cwd,
env: { DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org/", ...env },
stdout,
stderr,
} = context;
const registry = getRegistry(pkg, context);
await setNpmrcAuth(npmrc, registry, context);
if (normalizeUrl(registry) === normalizeUrl(DEFAULT_NPM_REGISTRY)) {
try {
const whoamiResult = execa("npm", ["whoami", "--userconfig", npmrc, "--registry", registry], {
cwd,
env,
preferLocal: true,
});
whoamiResult.stdout.pipe(stdout, { end: false });
whoamiResult.stderr.pipe(stderr, { end: false });
await whoamiResult;
} catch {
throw new AggregateError([getError("EINVALIDNPMTOKEN", { registry })]);
}
}
}