Skip to content

Commit 194a4b6

Browse files
committed
fix: support private registry
1 parent 09ed04f commit 194a4b6

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

src/npm.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,22 @@ const _getNpmRegistry = async (pm: PackageManager, pkg?: PackageInfo) => {
5858
try {
5959
const pkgName = pkg?.name;
6060
let registry = pkg?.packageJson.publishConfig?.registry;
61-
if (!registry) {
62-
const cmd = pm.id === 'berry' ? getBerryRegistryCmd(pkgName) : getNpmRegistryCmd(pm, pkgName);
61+
if (registry) {
62+
return removeTrailingSlashes(registry);
63+
}
6364

64-
registry = await run(cmd, {
65-
trim: true,
66-
cwd: ['npm', 'yarn'].includes(pm.id) ? undefined : pkg?.dir,
67-
});
65+
const cmd = pm.id === 'berry' ? getBerryRegistryCmd(pkgName) : getNpmRegistryCmd(pm, pkgName);
6866

69-
registry = registry === 'undefined' ? '' : registry;
70-
}
67+
registry = await run(cmd, {
68+
trim: true,
69+
cwd: ['npm', 'yarn'].includes(pm.id) ? undefined : pkg?.dir,
70+
});
71+
72+
registry = registry === 'undefined' ? '' : registry;
73+
74+
return removeTrailingSlashes(registry) || NPM_REGISTRY;
7175
} catch {}
76+
7277
return NPM_REGISTRY;
7378
};
7479

src/publish.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ async function bumpVersionAndTag(opts: ReleaseOptions) {
5050
}
5151

5252
async function runPublishPackages(opts: ReleaseOptions) {
53-
const { pkgs, dryRun } = opts;
53+
const { pkgs, dryRun, packageManager: pm } = opts;
5454
const twoFactorState = getTwoFactorState(opts);
5555

5656
if (opts.publish) {
5757
for (const pkg of pkgs) {
5858
if (!dryRun && opts.build && pkg.packageJson?.scripts?.build) {
59-
await run('npm run build', { cwd: pkg.dir });
59+
await run(`${pm.cli} run build`, { cwd: pkg.dir });
6060
}
6161
await publishOnePackage(pkg, opts, twoFactorState);
6262
const tag = `${pkg.name}@${pkg.newVersion}`;
@@ -66,10 +66,8 @@ async function runPublishPackages(opts: ReleaseOptions) {
6666

6767
const gitUrl = await getRepositoryUrl();
6868
if (gitUrl) {
69-
try {
70-
await run(`git push --follow-tags`, { dryRun });
71-
} catch {
72-
await run(`git push`, { dryRun });
69+
await run(`git push`, { dryRun });
70+
if (!opts.releaseDraft) {
7371
await run(`git push --tags`, { dryRun });
7472
}
7573
}

src/utils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ export async function run(cmd: string | string[], options?: RunExecaOptions): Pr
123123

124124
try {
125125
const { stdout } = await $(execOpts)`${cmd}`;
126-
126+
const std = Array.isArray(stdout) ? stdout.join('\n') : (stdout as string) || '';
127127
spin && spin.stop();
128128

129-
log(stdout);
129+
log(std);
130130

131131
if (trim) {
132-
return stdout.trim().replace(/\n|\r/g, '');
132+
return std.trim().replace(/\n|\r/g, '');
133133
}
134-
return stdout.trim();
134+
return std.trim();
135135
} catch (e: any) {
136136
spin && spin.stop();
137137

0 commit comments

Comments
 (0)