Skip to content

Commit

Permalink
fix: not finding yarnrc no longer throws
Browse files Browse the repository at this point in the history
  • Loading branch information
dmeents committed Mar 31, 2023
1 parent 5c2f7c4 commit ff2ab83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
11 changes: 5 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import {
} from './utils';
import { Context, PrepareContext } from './types';
import { Yarn } from './utils/yarn';
import readPkg from 'read-pkg';

let verified = false;
let prepared = false;
let packageJson: readPkg.NormalizedPackageJson;
let yarnrc: Record<string, string> = {};
const yarn = new Yarn();

export async function verifyConditions(
Expand All @@ -21,15 +24,14 @@ export async function verifyConditions(
config = PluginConfig.normalize(config);

ctx.logger.log(`read ${ctx.cwd}/package.json`);
const packageJson = await getPackage(ctx.cwd);
packageJson = await getPackage(ctx.cwd);

if (config.npmPublish === false) {
if (!config.npmPublish) {
ctx.logger.log('skipping registry configuration since npmPublish is false');
return;
}

const registryFromPackage = packageJson?.publishConfig?.registry as string;
let yarnrc: Record<string, string> = {};
let registryFromYarnrc = '';

if (!registryFromPackage) {
Expand Down Expand Up @@ -85,7 +87,6 @@ export async function verifyConditions(
}

export async function prepare(config: PluginConfig, ctx: PrepareContext) {
ctx.logger.log(`read ${ctx.cwd}/package.json`);
config = PluginConfig.normalize(config);

if (config.changeVersion) {
Expand Down Expand Up @@ -123,8 +124,6 @@ export async function publish(config: PluginConfig, ctx: PrepareContext) {
return;
}

ctx.logger.log(`read ${ctx.cwd}/package.json`);
const packageJson = await getPackage(ctx.cwd);
const { version } = ctx.nextRelease;

ctx.logger.log(`get channel to publish to`);
Expand Down
6 changes: 2 additions & 4 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ export async function getPackage(cwd: string) {
}

export async function getYarnRc(cwd: string) {
let yarnRc: Record<string, string>;
let yarnRc: Record<string, string> = {};

try {
yarnRc = (await yaml.load(
fs.readFileSync(`${cwd}/.yarnrc.yml`, 'utf8'),
)) as Record<string, string>;
} catch (err) {
const { code } = err as { code?: string };
if (code === 'ENOENT') throw error(ErrorTypes.MISSING_YARNRC);
throw new AggregateError([err]);
/* empty */
}

return yarnRc;
Expand Down

0 comments on commit ff2ab83

Please sign in to comment.