Skip to content

Commit

Permalink
Merge branch 'master' into npm4-prepublish
Browse files Browse the repository at this point in the history
* master: (66 commits)
  Add --no-bin-links flag - fixes yarnpkg#929 (yarnpkg#1651)
  Add option to change the prefix of the global bin folder - fixes yarnpkg#630 (yarnpkg#1654)
  patterns -> filteredPatterns
  Add helpful nudge to yarnpkg/rfcs on issue template (yarnpkg#1650)
  Change reporter.log to console.log in generate-lock-entry command - fixes yarnpkg#644 (yarnpkg#1652)
  Fixed add command flag (yarnpkg#1653)
  Nested executables fix (yarnpkg#1210)
  Added short-flags for yarn add (yarnpkg#1618)
  Add name lookups to ls command - fixes yarnpkg#1599 (yarnpkg#1643)
  Disable flaky secureUrl test (yarnpkg#1644)
  Add unit tests for `yarn why`. (yarnpkg#1544)
  Refine flow type for config.generateHardModulePath (yarnpkg#1642)
  Use ~/Library/Caches as default cache location on OSX - fixes yarnpkg#1637 (yarnpkg#1638)
  Update aliases.js (yarnpkg#1635)
  Update aliases.js (yarnpkg#1634)
  Add webhook to archive AppVeyor build artifacts (yarnpkg#1631)
  Attempt to fix failing Circle CI builds (yarnpkg#1629)
  Adding 'yarn global upgrade'(Issue yarnpkg#776) (yarnpkg#1616)
  Show error message in stdout. (yarnpkg#1502)
  Nicer permission errors when trying to write global binaries - fixes yarnpkg#1578 (yarnpkg#1592)
  ...
  • Loading branch information
Diogo Franco (Kovensky) committed Nov 4, 2016
2 parents 5a4a818 + 96fbeea commit fda0ecf
Show file tree
Hide file tree
Showing 146 changed files with 3,319 additions and 366 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!-- *Before creating an issue please make sure you are using the latest version of yarn.* -->

**Do you want to request a *feature* or report a *bug*?**
<!-- Is the feature a substantial feature request? Please use https://github.com/yarnpkg/rfcs -->

**What is the current behavior?**

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ test/fixtures/**/.fbkpm

# IDE
.idea/
/__tests__/fixtures/request-cache/
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

**Fast:** Yarn caches every package it downloads so it never needs to download the same package again. It also parallelizes operations to maximize resource utilization so install times are faster than ever.

**Reliable:** Using a a detailed, concise lockfile format, and a deterministic algorithm for installs, Yarn is able to guarantee that an install that worked on one system will work exactly the same way on any other system.
**Reliable:** Using a detailed, concise lockfile format and a deterministic algorithm for installs, Yarn is able to guarantee that an install that worked on one system will work exactly the same way on any other system.

**Secure:** Yarn uses checksums to verify the integrity of every installed package before its code is executed.

Expand All @@ -38,8 +38,7 @@ Read the [Installation Guide](https://yarnpkg.com/en/docs/install) on our websit

## Contributing to Yarn

Contributions are always welcome, no matter how large or small. Before contributing,
please read the [code of conduct](CODE_OF_CONDUCT.md).
Contributions are always welcome, no matter how large or small. Before contributing, please read the [code of conduct](CODE_OF_CONDUCT.md).

See [Contributing](CONTRIBUTING.md).

Expand Down
2 changes: 1 addition & 1 deletion __tests__/__snapshots__/fetchers.js.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
exports[`test TarballFetcher.fetch throws on invalid hash 1`] = `"https://github.com/sindresorhus/beeper/archive/master.tar.gz: Bad hash. Expected foo but got a32262ca1e22a3746b970936d3944b4bfd6cb9e9 "`;
exports[`test TarballFetcher.fetch throws on invalid hash 1`] = `"https://github.com/sindresorhus/beeper/archive/master.tar.gz: Bad hash. Expected \"foo\" but got \"a32262ca1e22a3746b970936d3944b4bfd6cb9e9\" "`;
2 changes: 1 addition & 1 deletion __tests__/cli/aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('shorthands and affordances', () => {
expect(aliases['tst']).toBe('test');
expect(aliases['un']).toBe('remove');
expect(aliases['up']).toBe('update');
expect(aliases['v']).toBe('info');
expect(aliases['v']).toBe('version');
expect(aliases['add-user']).toBe('login');
expect(aliases['dist-tag']).toBe('tag');
expect(aliases['dist-tags']).toBe('tag');
Expand Down
111 changes: 12 additions & 99 deletions __tests__/commands/install.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* @flow */

import {run as uninstall} from '../../src/cli/commands/remove.js';
import {run as check} from '../../src/cli/commands/check.js';
import * as reporters from '../../src/reporters/index.js';
import {Install} from '../../src/cli/commands/install.js';
Expand Down Expand Up @@ -114,6 +113,10 @@ test.concurrent('install from offline mirror', (): Promise<void> => {
assert(allFiles.findIndex((file): boolean => {
return file.relative === path.join('node_modules', 'fake-dependency', 'package.json');
}) !== -1);

assert(allFiles.findIndex((file): boolean => {
return file.relative === path.join('node_modules', '@fakescope', 'fake-dependency', 'package.json');
}) !== -1);
});
});

Expand Down Expand Up @@ -385,104 +388,6 @@ test.concurrent(
},
);

test.concurrent(
'uninstall should remove dependency from package.json, yarn.lock and node_modules',
(): Promise<void> => {
const mirrorPath = 'mirror-for-offline';

return runInstall({}, 'uninstall-should-clean', async (config, reporter) => {
assert.equal(
await getPackageVersion(config, 'dep-a'),
'1.0.0',
);

await fs.copy(path.join(config.cwd, 'yarn.lock'), path.join(config.cwd, 'yarn.lock.orig'));
await fs.copy(path.join(config.cwd, 'package.json'), path.join(config.cwd, 'package.json.orig'));

try {
await uninstall(config, reporter, {}, ['dep-a']);

assert(!await fs.exists(path.join(config.cwd, 'node_modules/dep-a')));
assert(await fs.exists(path.join(config.cwd, `${mirrorPath}/dep-a-1.0.0.tgz`)));

assert.deepEqual(
JSON.parse(await fs.readFile(path.join(config.cwd, 'package.json'))).dependencies,
{},
);

const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockFileLines = explodeLockfile(lockFileContent);
assert.equal(lockFileLines.length, 0);
} finally {
await fs.unlink(path.join(config.cwd, 'yarn.lock'));
await fs.unlink(path.join(config.cwd, 'package.json'));
await fs.copy(path.join(config.cwd, 'yarn.lock.orig'), path.join(config.cwd, 'yarn.lock'));
await fs.copy(path.join(config.cwd, 'package.json.orig'), path.join(config.cwd, 'package.json'));
await fs.unlink(path.join(config.cwd, 'yarn.lock.orig'));
await fs.unlink(path.join(config.cwd, 'package.json.orig'));
}
});
},
);

test.concurrent('uninstall should remove subdependencies', (): Promise<void> => {
// A@1 -> B@1
// C@1

// remove A

// C@1

const mirrorPath = 'mirror-for-offline';

return runInstall({}, 'uninstall-should-remove-subdependencies', async (config, reporter) => {
try {
assert.equal(
await getPackageVersion(config, 'dep-a'),
'1.0.0',
);
assert.equal(
await getPackageVersion(config, 'dep-b'),
'1.0.0',
);
assert.equal(
await getPackageVersion(config, 'dep-c'),
'1.0.0',
);

await fs.copy(path.join(config.cwd, 'yarn.lock'), path.join(config.cwd, 'yarn.lock.orig'));
await fs.copy(path.join(config.cwd, 'package.json'), path.join(config.cwd, 'package.json.orig'));

await uninstall(config, reporter, {}, ['dep-a']);

assert(!await fs.exists(path.join(config.cwd, 'node_modules/dep-a')));
assert(!await fs.exists(path.join(config.cwd, 'node_modules/dep-b')));
assert(await fs.exists(path.join(config.cwd, 'node_modules/dep-c')));

assert(await fs.exists(path.join(config.cwd, `${mirrorPath}/dep-a-1.0.0.tgz`)));
assert(await fs.exists(path.join(config.cwd, `${mirrorPath}/dep-b-1.0.0.tgz`)));
assert(await fs.exists(path.join(config.cwd, `${mirrorPath}/dep-c-1.0.0.tgz`)));

assert.deepEqual(
JSON.parse(await fs.readFile(path.join(config.cwd, 'package.json'))).dependencies,
{'dep-c': '^1.0.0'},
);

const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockFileLines = explodeLockfile(lockFileContent);
assert.equal(lockFileLines.length, 3);
assert.equal(lockFileLines[0], 'dep-c@^1.0.0:');
} finally {
await fs.unlink(path.join(config.cwd, 'yarn.lock'));
await fs.unlink(path.join(config.cwd, 'package.json'));
await fs.copy(path.join(config.cwd, 'yarn.lock.orig'), path.join(config.cwd, 'yarn.lock'));
await fs.copy(path.join(config.cwd, 'package.json.orig'), path.join(config.cwd, 'package.json'));
await fs.unlink(path.join(config.cwd, 'yarn.lock.orig'));
await fs.unlink(path.join(config.cwd, 'package.json.orig'));
}
});
});

test.concurrent('check should verify that top level dependencies are installed correctly', (): Promise<void> => {
return runInstall({}, 'check-top-correct', async (config, reporter) => {

Expand Down Expand Up @@ -614,6 +519,14 @@ test.concurrent(
},
);

test.concurrent('install should hoist nested bin scripts', (): Promise<void> => {
return runInstall({}, 'install-nested-bin', async (config) => {
const binScripts = await fs.walk(path.join(config.cwd, 'node_modules', '.bin'));
assert.equal(binScripts.length, 10);
assert(binScripts.findIndex((f) => f.basename === 'eslint') > -1);
});
});


xit('install should update a dependency to yarn and mirror (PR import scenario 2)', (): Promise<void> => {
// mime-types@2.0.0 is saved in local mirror and gets updated to mime-types@2.1.11 via
Expand Down
133 changes: 133 additions & 0 deletions __tests__/commands/outdated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* @flow */

import {Reporter} from '../../src/reporters/index.js';
import {run as outdated} from '../../src/cli/commands/outdated.js';
import * as fs from '../../src/util/fs.js';
import * as reporters from '../../src/reporters/index.js';
import Config from '../../src/config.js';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000;

const stream = require('stream');
const path = require('path');
const os = require('os');

const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'outdated');

async function runOutdated(
flags: Object,
args: Array<string>,
name: string,
checkOutdated?: ?(config: Config, reporter: Reporter, out: string) => ?Promise<void>,
): Promise<void> {
const dir = path.join(fixturesLoc, name);
const cwd = path.join(
os.tmpdir(),
`yarn-${path.basename(dir)}-${Math.random()}`,
);
await fs.unlink(cwd);
await fs.copy(dir, cwd);

for (const {basename, absolute} of await fs.walk(cwd)) {
if (basename.toLowerCase() === '.ds_store') {
await fs.unlink(absolute);
}
}

let out = '';
const stdout = new stream.Writable({
decodeStrings: false,
write(data, encoding, cb) {
out += data;
cb();
},
});

const reporter = new reporters.JSONReporter({stdout});

// create directories
await fs.mkdirp(path.join(cwd, '.yarn'));
await fs.mkdirp(path.join(cwd, 'node_modules'));

try {
const config = new Config(reporter);
await config.init({
cwd,
globalFolder: path.join(cwd, '.yarn/.global'),
cacheFolder: path.join(cwd, '.yarn'),
linkFolder: path.join(cwd, '.yarn/.link'),
});

await outdated(config, reporter, flags, args);

if (checkOutdated) {
await checkOutdated(config, reporter, out);
}

} catch (err) {
throw new Error(`${err && err.stack} \nConsole output:\n ${out}`);
}
}

test.concurrent('throws if lockfile is out of date', (): Promise<void> => {
const reporter = new reporters.ConsoleReporter({});

return new Promise(async (resolve) => {
try {
await runOutdated({}, [], 'lockfile-outdated');
} catch (err) {
expect(err.message).toContain(reporter.lang('lockfileOutdated'));
} finally {
resolve();
}
});
});

test.concurrent('no output when current matches latest', (): Promise<void> => {
return runOutdated({}, [], 'current-is-latest', (config, reporter, out): ?Promise<void> => {
expect(out).toBe('');
});
});

test.concurrent('works with no arguments', (): Promise<void> => {
return runOutdated({}, [], 'no-args', (config, reporter, out): ?Promise<void> => {
const json: Object = JSON.parse(out);

expect(json.data.body.length).toBe(1);
});
});

test.concurrent('works with single argument', (): Promise<void> => {
return runOutdated({}, ['max-safe-integer'], 'single-package', (config, reporter, out): ?Promise<void> => {
const json: Object = JSON.parse(out);

expect(json.data.body.length).toBe(1);
expect(json.data.body[0][0]).toBe('max-safe-integer');
});
});

test.concurrent('works with multiple arguments', (): Promise<void> => {
return runOutdated({}, ['left-pad', 'max-safe-integer'], 'multiple-packages',
(config, reporter, out): ?Promise<void> => {
const json: Object = JSON.parse(out);

expect(json.data.body.length).toBe(2);
expect(json.data.body[0][0]).toBe('left-pad');
expect(json.data.body[1][0]).toBe('max-safe-integer');
},
);
});

test.concurrent('works with exotic resolvers', (): Promise<void> => {
return runOutdated({}, [], 'exotic-resolvers',
(config, reporter, out): ?Promise<void> => {
const json: Object = JSON.parse(out);
const first = ['max-safe-integer', '1.0.1', 'exotic', 'exotic', null];
const second = ['yarn', '0.16.2', 'exotic', 'exotic', null];

expect(json.data.body.length).toBe(2);
expect(json.data.body[0]).toEqual(first);
expect(json.data.body[1]).toEqual(second);
},
);
});
Loading

0 comments on commit fda0ecf

Please sign in to comment.