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

Ability to opt-out of offline mirror #3009

Merged
merged 1 commit into from
Apr 7, 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
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['[email protected]'].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['[email protected]'].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['[email protected]'].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