Skip to content

Commit

Permalink
fix: fix trying to read from a directory, instead of the yarnrc file
Browse files Browse the repository at this point in the history
  • Loading branch information
dmeents committed Mar 7, 2023
1 parent d0c96fa commit 7900ded
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ export async function getYarnRc(cwd: string) {
let yarnRc: Record<string, string>;

try {
yarnRc = (await yaml.load(fs.readFileSync(cwd, 'utf8'))) as Record<
string,
string
>;
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_PACKAGE);
Expand Down
17 changes: 16 additions & 1 deletion src/utils/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tempy from 'tempy';
import * as fs from 'fs';
import { getPackage } from './index';
import { getPackage, getYarnRc } from './index';

describe('utils', () => {
describe('getPackage', () => {
Expand Down Expand Up @@ -31,4 +31,19 @@ describe('utils', () => {
await expect(getPackage(cwd)).rejects.toThrow();
});
});

describe('getYarnRc', () => {
it('should return the .yarnrc.yml if it exists', async () => {
const cwd = tempy.directory();

const mockYarnRc = {
npmPublishRegistry: 'https://registry.npmjs.org',
};

fs.writeFileSync(`${cwd}/.yarnrc.yml`, JSON.stringify(mockYarnRc));
const result = await getYarnRc(cwd);

expect(result.npmPublishRegistry).toEqual(mockYarnRc.npmPublishRegistry);
});
});
});

0 comments on commit 7900ded

Please sign in to comment.