Skip to content

Commit

Permalink
fixes and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi committed Dec 5, 2023
1 parent 145cdda commit 0f9184e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion source/cli-implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ try {

const branch = flags.branch ?? await git.defaultBranch();

const isYarnBerry = flags.yarn && await checkIfYarnBerry(pkg);
const isYarnBerry = flags.yarn && checkIfYarnBerry(pkg);

const options = await ui({
...flags,
Expand Down
3 changes: 2 additions & 1 deletion source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const np = async (input = 'patch', options, {pkg, rootDir, isYarnBerry}) => {

// Yarn berry doesn't support git commiting/tagging, so use npm
const shouldUseYarnForVersioning = options.yarn === true && !isYarnBerry;
const shouldUseNpmForVersioning = options.yarn === false || isYarnBerry;

// To prevent the process from hanging due to watch mode (e.g. when running `vitest`)
const ciEnvOptions = {env: {CI: 'true'}};
Expand Down Expand Up @@ -197,7 +198,7 @@ const np = async (input = 'patch', options, {pkg, rootDir, isYarnBerry}) => {
},
{
title: 'Bumping version using npm',
enabled: () => !shouldUseYarnForVersioning,
enabled: () => shouldUseNpmForVersioning,
skip() {
if (options.preview) {
let previewText = `[Preview] Command not executed: npm version ${input}`;
Expand Down
2 changes: 1 addition & 1 deletion source/npm/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const getFilesToBePacked = async rootDir => {

export const getRegistryUrl = async (pkgManager, pkg) => {
if (pkgManager === 'yarn-berry') {
const {stdout} = await execa('yarn', 'config', 'get', 'npmRegistryServer');
const {stdout} = await execa('yarn', ['config', 'get', 'npmRegistryServer']);
return stdout;
}

Expand Down
2 changes: 1 addition & 1 deletion source/yarn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import semver from 'semver';

export async function checkIfYarnBerry(pkg) {
export function checkIfYarnBerry(pkg) {
if (typeof pkg.packageManager !== 'string') {
return false;
}
Expand Down
10 changes: 10 additions & 0 deletions test/npm/util/get-registry-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ test('yarn', createFixture, [{
);
});

test('yarn-berry', createFixture, [{
command: 'yarn config get npmRegistryServer',
stdout: 'https://registry.yarnpkg.com',
}], async ({t, testedModule: npm}) => {
t.is(
await npm.getRegistryUrl('yarn-berry', {}),
'https://registry.yarnpkg.com',
);
});

test('external', createFixture, [{
command: 'npm config get registry --registry http://my-internal-registry.local',
stdout: 'http://my-internal-registry.local',
Expand Down
15 changes: 15 additions & 0 deletions test/util/yarn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import test from 'ava';
import {checkIfYarnBerry} from '../../source/yarn.js';

test('checkIfYarnBerry', t => {
t.is(checkIfYarnBerry({}), false);
t.is(checkIfYarnBerry({
packageManager: 'npm',
}), false);
t.is(checkIfYarnBerry({
packageManager: '[email protected]',
}), false);
t.is(checkIfYarnBerry({
packageManager: '[email protected]',
}), true);
});

0 comments on commit 0f9184e

Please sign in to comment.