From 93fa0f7c2857b5e9301d554b2b4c362d20988324 Mon Sep 17 00:00:00 2001 From: Konstantin Raev Date: Fri, 20 Jan 2017 23:48:50 +0000 Subject: [PATCH] fix: check for cpu and os constraints if the arrays are not empty (#2490) * fix: check for cpu and os constraints if the arrays are not empty * added tests fixture --- __tests__/commands/install/integration.js | 22 +++++++++++++------ .../fixtures/install/empty-os/package.json | 5 +++++ __tests__/fixtures/install/empty-os/yarn.lock | 13 +++++++++++ src/package-compatibility.js | 20 ++++++++++------- 4 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 __tests__/fixtures/install/empty-os/package.json create mode 100644 __tests__/fixtures/install/empty-os/yarn.lock diff --git a/__tests__/commands/install/integration.js b/__tests__/commands/install/integration.js index 08981b627d..dc49cf0b8e 100644 --- a/__tests__/commands/install/integration.js +++ b/__tests__/commands/install/integration.js @@ -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 => { - // 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 => { + // 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 => { + return runInstall({}, 'empty-os', async (config) => { + assert(await fs.exists(path.join(config.cwd, 'node_modules', 'feed'))); + }); }); -}); diff --git a/__tests__/fixtures/install/empty-os/package.json b/__tests__/fixtures/install/empty-os/package.json new file mode 100644 index 0000000000..eea039fddf --- /dev/null +++ b/__tests__/fixtures/install/empty-os/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "feed": "0.3.0" + } +} diff --git a/__tests__/fixtures/install/empty-os/yarn.lock b/__tests__/fixtures/install/empty-os/yarn.lock new file mode 100644 index 0000000000..4ab6c0f534 --- /dev/null +++ b/__tests__/fixtures/install/empty-os/yarn.lock @@ -0,0 +1,13 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +feed@0.3.0: + 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" diff --git a/src/package-compatibility.js b/src/package-compatibility.js index 64b1f82f5f..fd6ab8d6b9 100644 --- a/src/package-compatibility.js +++ b/src/package-compatibility.js @@ -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') {