Skip to content

Commit

Permalink
Ability to opt-out of offline mirror (#3009)
Browse files Browse the repository at this point in the history
Configs are merged with configs in parent directories, so currently if a .yarnrc in a parent directory enables the offline mirror, all projects in child directories would also use the offline mirror.

This commit allows a child directory to opt-out of the offline mirror in their own .yarnrc with `yarn-offline-mirror false`.

Previously if you specified `false` you'd get an exception as false is parsed as boolean but it expects a string.

Also included tests verifying the existing .yarnrc merging behaviour (previously wasn't covered).

t14078443
  • Loading branch information
danharper authored and bestander committed Apr 7, 2017
1 parent 188d377 commit bdec717
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 2 deletions.
9 changes: 7 additions & 2 deletions __tests__/commands/_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function run<T, R>(
) => Promise<T> | T,
args: Array<string>,
flags: Object,
name: string,
name: string | { source: string, cwd: string },
checkInstalled: ?(config: Config, reporter: R, install: T) => ?Promise<void>,
beforeInstall: ?(cwd: string) => ?Promise<void>,
): Promise<void> {
Expand All @@ -81,9 +81,14 @@ export async function run<T, R>(

let cwd;
if (fixturesLoc) {
const dir = path.join(fixturesLoc, name);
const source = typeof name === 'string' ? name : name.source;

const dir = path.join(fixturesLoc, source);
cwd = await fs.makeTempDir(path.basename(dir));
await fs.copy(dir, cwd, reporter);
if (typeof name !== 'string') {
cwd = path.join(cwd, name.cwd);
}
} else {
// if fixture loc is not set then CWD is some empty temp dir
cwd = await fs.makeTempDir();
Expand Down
37 changes: 37 additions & 0 deletions __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {run as cache} from '../../../src/cli/commands/cache.js';
import {run as check} from '../../../src/cli/commands/check.js';
import * as constants from '../../../src/constants.js';
import * as reporters from '../../../src/reporters/index.js';
import {parse} from '../../../src/lockfile/wrapper.js';
import {Install} from '../../../src/cli/commands/install.js';
import Lockfile from '../../../src/lockfile/wrapper.js';
import * as fs from '../../../src/util/fs.js';
Expand Down Expand Up @@ -580,6 +581,42 @@ if (process.platform !== 'win32') {
});
}

test.concurrent('offline mirror can be enabled from parent dir', (): Promise<void> => {
const fixture = {source: 'offline-mirror-configuration', cwd: 'enabled-from-parent'};
return runInstall({}, fixture, async (config, reporter) => {
const rawLockfile = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockfile = parse(rawLockfile);
expect(lockfile['mime-types@2.1.14'].resolved).toEqual(
'https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.14.tgz#f7ef7d97583fcaf3b7d282b6f8b5679dab1e94ee',
);
expect(await fs.exists(path.join(config.cwd, '../offline-mirror/mime-types-2.1.14.tgz'))).toBe(true);
});
});

test.concurrent('offline mirror can be enabled from parent dir, with merging of own .yarnrc', (): Promise<void> => {
const fixture = {source: 'offline-mirror-configuration', cwd: 'enabled-from-parent-merge'};
return runInstall({}, fixture, async (config, reporter) => {
const rawLockfile = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockfile = parse(rawLockfile);
expect(lockfile['mime-types@2.1.14'].resolved).toEqual(
'https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.14.tgz#f7ef7d97583fcaf3b7d282b6f8b5679dab1e94ee',
);
expect(await fs.exists(path.join(config.cwd, '../offline-mirror/mime-types-2.1.14.tgz'))).toBe(true);
});
});

test.concurrent('offline mirror can be disabled locally', (): Promise<void> => {
const fixture = {source: 'offline-mirror-configuration', cwd: 'disabled-locally'};
return runInstall({}, fixture, async (config, reporter) => {
const rawLockfile = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockfile = parse(rawLockfile);
expect(lockfile['mime-types@2.1.14'].resolved).toEqual(
'https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.14.tgz#f7ef7d97583fcaf3b7d282b6f8b5679dab1e94ee',
);
expect(await fs.exists(path.join(config.cwd, '../offline-mirror/mime-types-2.1.14.tgz'))).toBe(false);
});
});

// sync test because we need to get all the requests to confirm their validity
test('install a scoped module from authed private registry', (): Promise<void> => {
return runInstall({noLockfile: true}, 'install-from-authed-private-registry', async (config) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn-offline-mirror "./offline-mirror"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn-offline-mirror false
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"mime-types": "2.1.14"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
something else
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"mime-types": "2.1.14"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"mime-types": "2.1.14"
}
}
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ export default class Config {
const registryMirrorPath = registry.config['yarn-offline-mirror'];
if (registryMirrorPath === false) {
return null;
}
if (registryMirrorPath == null) {
continue;
}
Expand Down

0 comments on commit bdec717

Please sign in to comment.