Skip to content

Commit bd7acfb

Browse files
committed
feat(verify-auth): configure npmrc details again
1 parent f5c8d85 commit bd7acfb

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

lib/verify-auth.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,47 @@ function registryIsDefault(registry, DEFAULT_NPM_REGISTRY) {
99
return normalizeUrl(registry) === normalizeUrl(DEFAULT_NPM_REGISTRY);
1010
}
1111

12+
function targetingDefaultRegistryButNoTokenProvided(registry, DEFAULT_NPM_REGISTRY, errors) {
13+
return registryIsDefault(registry, DEFAULT_NPM_REGISTRY) && errors.length === 1 && errors[0].code === "ENONPMTOKEN";
14+
}
15+
1216
export default async function (npmrc, pkg, context) {
1317
const {
1418
cwd,
1519
env: { DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org/", ...env },
1620
stdout,
1721
stderr,
22+
logger,
1823
} = context;
1924
const registry = getRegistry(pkg, context);
2025

21-
// await setNpmrcAuth(npmrc, registry, context);
26+
try {
27+
logger.log("setting npmrc auth for registry", registry);
28+
await setNpmrcAuth(npmrc, registry, context);
29+
} catch (aggregateError) {
30+
const { errors } = aggregateError;
31+
32+
if (targetingDefaultRegistryButNoTokenProvided(registry, DEFAULT_NPM_REGISTRY, errors)) {
33+
logger.log("NPM_TOKEN was not provided for the default npm registry.");
34+
} else {
35+
throw aggregateError;
36+
}
37+
}
2238

2339
if (registryIsDefault(registry, DEFAULT_NPM_REGISTRY)) {
24-
// try {
25-
const publishDryRunResult = execa("npm", ["publish", "--dry-run", "--tag=semantic-release-auth-check"], {cwd, env, preferLocal: true, lines: true});
26-
// const whoamiResult = execa("npm", ["whoami", "--userconfig", npmrc, "--registry", registry], {
27-
// cwd,
28-
// env,
29-
// preferLocal: true,
30-
// });
31-
// whoamiResult.stdout.pipe(stdout, { end: false });
32-
// whoamiResult.stderr.pipe(stderr, { end: false });
33-
// await whoamiResult;
40+
const publishDryRunResult = execa(
41+
"npm",
42+
["publish", "--dry-run", "--tag=semantic-release-auth-check", "--userconfig", npmrc, "--registry", registry],
43+
{ cwd, env, preferLocal: true, lines: true }
44+
);
45+
3446
publishDryRunResult.stdout.pipe(stdout, { end: false });
3547
publishDryRunResult.stderr.pipe(stderr, { end: false });
3648

3749
(await publishDryRunResult).stderr.forEach((line) => {
3850
if (line.includes("This command requires you to be logged in to ")) {
39-
throw new AggregateError([getError("EINVALIDNPMAUTH" )]);
51+
throw new AggregateError([getError("EINVALIDNPMAUTH")]);
4052
}
41-
})
42-
// } catch {
43-
// throw new AggregateError([getError("EINVALIDNPMAUTH", { registry })]);
44-
// }
53+
});
4554
}
4655
}

0 commit comments

Comments
 (0)