Skip to content

Commit

Permalink
Ability to opt-out of offline mirror
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 committed Mar 28, 2017
1 parent fb1d128 commit ced6d04
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 1 deletion.
14 changes: 13 additions & 1 deletion __tests__/commands/_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,21 @@ export async function run<T, R>(

let cwd;
if (fixturesLoc) {
const dir = path.join(fixturesLoc, name);
let parentDir = name;
let childDir = '';

// if the name is a path, copy the parent dir, then use the child dir as the cwd
// there's some existing tests which reference fixtures in a parent dir (../), so excluding those
const nameSepIndex = name.indexOf('/');
if (nameSepIndex !== -1 && name.indexOf('../') === -1) {
parentDir = name.slice(0, nameSepIndex);
childDir = name.slice(nameSepIndex);
}

const dir = path.join(fixturesLoc, parentDir);
cwd = await fs.makeTempDir(path.basename(dir));
await fs.copy(dir, cwd, reporter);
cwd += childDir;
} else {
// if fixture loc is not set then CWD is some empty temp dir
cwd = await fs.makeTempDir();
Expand Down
26 changes: 26 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 @@ -809,6 +810,31 @@ test.concurrent('lockfile should be created when missing even if integrity match
});
});

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

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

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

test.concurrent('install infers line endings from existing win32 lockfile', async (): Promise<void> => {
await runInstall({}, 'install-infers-line-endings-from-existing-lockfile',
async (config): Promise<void> => {
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 @@ -368,6 +368,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 ced6d04

Please sign in to comment.