Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): Don't override registry with undefined by default #4643

Merged
merged 1 commit into from
Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions __tests__/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,25 @@ describe('--registry option', () => {
expect(stdoutOutput.toString()).toMatch(/getaddrinfo ENOTFOUND example-registry-doesnt-exist\.com/g);
}
});

test('registry option from yarnrc', async () => {
const cwd = await makeTemp();

const registry = 'https://registry.npmjs.org';
await fs.writeFile(`${cwd}/.yarnrc`, 'registry "' + registry + '"\n');

const packageJsonPath = path.join(cwd, 'package.json');
await fs.writeFile(packageJsonPath, JSON.stringify({}));

await runYarn(['add', 'left-pad'], {cwd});

const packageJson = JSON.parse(await fs.readFile(packageJsonPath));
const lockfile = explodeLockfile(await fs.readFile(path.join(cwd, 'yarn.lock')));

expect(packageJson.dependencies['left-pad']).toBeDefined();
expect(lockfile).toHaveLength(3);
expect(lockfile[2]).toContain(registry);
});
});

test('--cwd option', async () => {
Expand Down
9 changes: 8 additions & 1 deletion src/registries/base-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ export default class BaseRegistry {
async init(overrides: Object = {}): Promise<void> {
this.mergeEnv('yarn_');
await this.loadConfig();
Object.assign(this.config, overrides);

for (const override of Object.keys(overrides)) {
const val = overrides[override];

if (val !== undefined) {
this.config[override] = val;
}
}
this.loc = path.join(this.cwd, this.folder);
}

Expand Down