Skip to content

Commit

Permalink
fix: check for cpu and os constraints if the arrays are not empty (#2490
Browse files Browse the repository at this point in the history
)

* fix: check for cpu and os constraints if the arrays are not empty

* added tests fixture
  • Loading branch information
bestander authored Jan 20, 2017
1 parent 49c02b3 commit 93fa0f7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
22 changes: 15 additions & 7 deletions __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,19 @@ test.concurrent('a subdependency of an optional dependency that fails should be
});

// disabled while fix is not merged
test.skip('should not loose dependencies when installing with --production',
(): Promise<void> => {
// revealed https://github.com/yarnpkg/yarn/issues/2263
return runInstall({production: true}, 'prod-should-keep-subdeps', async (config) => {
// would be hoisted from gulp/vinyl-fs/glob-stream/minimatch/brace-expansion/balanced-match
assert.equal(await getPackageVersion(config, 'balanced-match'), '0.4.2');
test.skip('should not loose dependencies when installing with --production',
(): Promise<void> => {
// revealed https://github.com/yarnpkg/yarn/issues/2263
return runInstall({production: true}, 'prod-should-keep-subdeps', async (config) => {
// would be hoisted from gulp/vinyl-fs/glob-stream/minimatch/brace-expansion/balanced-match
assert.equal(await getPackageVersion(config, 'balanced-match'), '0.4.2');
});
});

// https://github.com/yarnpkg/yarn/issues/2470
test.concurrent('a allows dependency with [] in os cpu requirements',
(): Promise<void> => {
return runInstall({}, 'empty-os', async (config) => {
assert(await fs.exists(path.join(config.cwd, 'node_modules', 'feed')));
});
});
});
5 changes: 5 additions & 0 deletions __tests__/fixtures/install/empty-os/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"feed": "0.3.0"
}
}
13 changes: 13 additions & 0 deletions __tests__/fixtures/install/empty-os/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


[email protected]:
version "0.3.0"
resolved "https://registry.yarnpkg.com/feed/-/feed-0.3.0.tgz#65bcc4c9c57fde8e277faf4afff80c2d1d90e82d"
dependencies:
xml ">= 0.0.5"

"xml@>= 0.0.5":
version "1.0.1"
resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5"
20 changes: 12 additions & 8 deletions src/package-compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,20 @@ export default class PackageCompatibility {
}
};

if (!this.config.ignorePlatform && Array.isArray(info.os)) {
if (!PackageCompatibility.isValidPlatform(info.os)) {
pushError(this.reporter.lang('incompatibleOS', process.platform));
}
const invalidPlatform = !this.config.ignorePlatform &&
Array.isArray(info.os) &&
info.os.length > 0 &&
!PackageCompatibility.isValidPlatform(info.os);
if (invalidPlatform) {
pushError(this.reporter.lang('incompatibleOS', process.platform));
}

if (!this.config.ignorePlatform && Array.isArray(info.cpu)) {
if (!PackageCompatibility.isValidArch(info.cpu)) {
pushError(this.reporter.lang('incompatibleCPU', process.arch));
}
const invalidCpu = !this.config.ignorePlatform &&
Array.isArray(info.cpu) &&
info.cpu.length > 0 &&
!PackageCompatibility.isValidArch(info.cpu);
if (invalidCpu) {
pushError(this.reporter.lang('incompatibleCPU', process.arch));
}

if (!this.ignoreEngines && typeof info.engines === 'object') {
Expand Down

0 comments on commit 93fa0f7

Please sign in to comment.