From ebcc3ff56f09e90e750407ea4393bafb9443bdb3 Mon Sep 17 00:00:00 2001 From: Audrey So Date: Wed, 2 Aug 2017 10:21:06 -0700 Subject: [PATCH 1/5] CB-13055 : updated integration tests, removed lazy_load.js, removed gitclone and nofetch, and npm dependency --- integration-tests/HooksRunner.spec.js | 125 ++++---- integration-tests/fetch.spec.js | 2 +- integration-tests/pkgJson-restore.spec.js | 44 ++- integration-tests/pkgJson.spec.js | 12 +- integration-tests/platform.spec.js | 24 +- integration-tests/plugin.spec.js | 16 +- integration-tests/plugman_fetch.spec.js | 194 +----------- package.json | 1 - .../plugins/com.plugin.withhooks/package.json | 11 + .../fixtures/plugins/fake1/package.json | 28 ++ .../org.test.defaultvariables/package.json | 28 ++ .../fixtures/plugins/test/package.json | 11 + spec/cordova/lazy_load.spec.js | 277 ----------------- spec/cordova/platform/addHelper.spec.js | 74 ----- spec/cordova/plugin/add.spec.js | 2 +- spec/plugman/config.spec.js | 30 -- spec/plugman/install.spec.js | 14 - spec/plugman/owner.spec.js | 30 -- .../package.json | 28 ++ .../plugins/recursivePlug/package.json | 28 ++ spec/plugman/registry/registry.spec.js | 19 +- spec/plugman/search.spec.js | 29 -- src/cordova/lazy_load.js | 289 ------------------ src/cordova/platform/addHelper.js | 17 -- src/cordova/plugin/add.js | 2 +- src/cordova/remote_load.js | 78 ----- src/gitclone.js | 68 ----- src/plugman/fetch.js | 41 --- src/plugman/init-defaults.js | 16 +- src/plugman/registry/registry.js | 111 ++----- src/plugman/util/plugins.js | 71 ----- 31 files changed, 281 insertions(+), 1439 deletions(-) create mode 100644 spec/cordova/fixtures/plugins/com.plugin.withhooks/package.json create mode 100644 spec/cordova/fixtures/plugins/fake1/package.json create mode 100644 spec/cordova/fixtures/plugins/org.test.defaultvariables/package.json create mode 100644 spec/cordova/fixtures/plugins/test/package.json delete mode 100644 spec/cordova/lazy_load.spec.js delete mode 100644 spec/plugman/config.spec.js delete mode 100644 spec/plugman/owner.spec.js create mode 100644 spec/plugman/plugins/org.test.plugins.childbrowser/package.json create mode 100644 spec/plugman/plugins/recursivePlug/package.json delete mode 100644 spec/plugman/search.spec.js delete mode 100644 src/cordova/lazy_load.js delete mode 100644 src/cordova/remote_load.js delete mode 100644 src/gitclone.js delete mode 100644 src/plugman/util/plugins.js diff --git a/integration-tests/HooksRunner.spec.js b/integration-tests/HooksRunner.spec.js index 45e383cb4..34d3e1bd8 100644 --- a/integration-tests/HooksRunner.spec.js +++ b/integration-tests/HooksRunner.spec.js @@ -17,6 +17,9 @@ under the License. **/ +/* eslint no-mixed-spaces-and-tabs : 0 */ +/* eslint no-tabs : 0 */ + var cordova = require('../src/cordova/cordova'); var HooksRunner = require('../src/hooks/HooksRunner'); var shell = require('shelljs'); @@ -28,7 +31,6 @@ var child_process = require('child_process'); var helpers = require('../spec/helpers'); var PluginInfo = require('cordova-common').PluginInfo; var superspawn = require('cordova-common').superspawn; -var config = require('../src/cordova/config'); var platform = os.platform(); var tmpDir = helpers.tmpDir('hooks_test'); @@ -101,28 +103,8 @@ describe('HooksRunner', function () { it('Test 003 : should init test fixtures', function (done) { hooksRunner = new HooksRunner(project); - // Now we load the config.json in the newly created project and edit the target platform's lib entry - // to point at the fixture version. This is necessary so that cordova.prepare can find cordova.js there. - var c = config.read(project); - c.lib[helpers.testPlatform].url = path.join(fixtures, 'platforms', helpers.testPlatform + '-lib'); - config.write(project, c); - - // The config.json in the fixture project points at fake "local" paths. - // Since it's not a URL, the lazy-loader will just return the junk path. - spyOn(superspawn, 'spawn').and.callFake(function (cmd, args) { - if (cmd.match(/create\b/)) { - // This is a call to the bin/create script, so do the copy ourselves. - shell.cp('-R', path.join(fixtures, 'platforms', 'android'), path.join(project, 'platforms')); - } else if (cmd.match(/update\b/)) { - fs.writeFileSync(path.join(project, 'platforms', helpers.testPlatform, 'updated'), 'I was updated!', 'utf-8'); - } else if (cmd.match(/version/)) { - return '3.6.0'; - } - return Q(); - }); - // Add the testing platform. - cordova.platform('add', [helpers.testPlatform]).fail(function (err) { + cordova.platform('add', [helpers.testPlatform], {'fetch': true}).fail(function (err) { expect(err).toBeUndefined(); console.error(err); done(); @@ -137,15 +119,13 @@ describe('HooksRunner', function () { }; options = cordovaUtil.preProcessOptions(options); - hookOptions = { projectRoot: project, cordova: options }; - cordova.plugin('add', testPluginFixturePath).fail(function (err) { + cordova.plugin('add', testPluginFixturePath, {'fetch': true}).fail(function (err) { expect(err && err.stack).toBeUndefined(); done(); }).then(function () { testPluginInstalledPath = path.join(projectRoot, 'plugins', 'com.plugin.withhooks'); - shell.chmod('-R', 'ug+x', path.join(testPluginInstalledPath, 'scripts')); done(); }); }); @@ -354,45 +334,8 @@ describe('HooksRunner', function () { }); describe('plugin hooks', function () { - it('Test 009 : should execute hook scripts serially from plugin.xml', function (done) { - var test_event = 'before_build'; - var projectRoot = cordovaUtil.isCordova(); - var hooksOrderFile = path.join(projectRoot, 'hooks_order.txt'); - - switchToOnlyNonPlatformScriptsPluginConfig(); - - return hooksRunner.fire(test_event, hookOptions).then(function () { - expect(hooksOrderFile).toExist(); - - expect(hooksOrderFileIsOrdered(hooksOrderFile)).toBe(true); - }).fail(function (err) { - expect(err).toBeUndefined(); - }).then(function () { - restorePluginConfig(projectRoot); - done(); - }); - }); - - it('Test 010 : should execute hook scripts serially from plugin.xml including platform scripts', function (done) { - var test_event = 'before_build'; - var projectRoot = cordovaUtil.isCordova(); - var hooksOrderFile = path.join(projectRoot, 'hooks_order.txt'); - - switchToOnePlatformScriptsPluginConfig(); - - return hooksRunner.fire(test_event, hookOptions).then(function () { - expect(hooksOrderFile).toExist(); - - expect(hooksOrderFileIsOrdered(hooksOrderFile)).toBe(true); - }).fail(function (err) { - expect(err).toBeUndefined(); - }).then(function () { - restorePluginConfig(projectRoot); - done(); - }); - }); - it('Test 011 : should filter hook scripts from plugin.xml by platform', function (done) { + shell.chmod('-R', 'ug+x', path.join(testPluginInstalledPath, 'scripts')); var test_event = 'before_build'; var projectRoot = cordovaUtil.isCordova(); var hooksOrderFile = path.join(projectRoot, 'hooks_order.txt'); @@ -426,7 +369,7 @@ describe('HooksRunner', function () { cordova.plugin('rm', 'com.plugin.withhooks').fail(function (err) { expect(err.stack).toBeUndefined(); }).then(function () { - cordova.plugin('add', testPluginFixturePath).fail(function (err) { + cordova.plugin('add', testPluginFixturePath, {'fetch': true}).fail(function (err) { expect(err).toBeUndefined(); }).then(function () { testPluginInstalledPath = path.join(projectRoot, 'plugins', 'com.plugin.withhooks'); @@ -476,6 +419,60 @@ describe('HooksRunner', function () { }).fin(done); }); }); + }); + + describe('plugin hooks', function () { + beforeEach(function () { + spyOn(superspawn, 'spawn').and.callFake(function (cmd, args) { + if (cmd.match(/create\b/)) { + // This is a call to the bin/create script, so do the copy ourselves. + shell.cp('-R', path.join(fixtures, 'platforms', 'android'), path.join(project, 'platforms')); + } else if (cmd.match(/update\b/)) { + fs.writeFileSync(path.join(project, 'platforms', helpers.testPlatform, 'updated'), 'I was updated!', 'utf-8'); + } else if (cmd.match(/version/)) { + return '3.6.0'; + } + return Q(); + }); + }); + + it('Test 009 : should execute hook scripts serially from plugin.xml', function (done) { + var test_event = 'before_build'; + var projectRoot = cordovaUtil.isCordova(); + var hooksOrderFile = path.join(projectRoot, 'hooks_order.txt'); + + switchToOnlyNonPlatformScriptsPluginConfig(); + + return hooksRunner.fire(test_event, hookOptions).then(function () { + expect(hooksOrderFile).toExist(); + + expect(hooksOrderFileIsOrdered(hooksOrderFile)).toBe(true); + }).fail(function (err) { + expect(err).toBeUndefined(); + }).then(function () { + restorePluginConfig(projectRoot); + done(); + }); + }); + + it('Test 010 : should execute hook scripts serially from plugin.xml including platform scripts', function (done) { + var test_event = 'before_build'; + var projectRoot = cordovaUtil.isCordova(); + var hooksOrderFile = path.join(projectRoot, 'hooks_order.txt'); + + switchToOnePlatformScriptsPluginConfig(); + + return hooksRunner.fire(test_event, hookOptions).then(function () { + expect(hooksOrderFile).toExist(); + + expect(hooksOrderFileIsOrdered(hooksOrderFile)).toBe(true); + }).fail(function (err) { + expect(err).toBeUndefined(); + }).then(function () { + restorePluginConfig(projectRoot); + done(); + }); + }); it('Test 013 : should not execute the designated hook when --nohooks option specifies the exact hook name', function (done) { var test_event = 'before_build'; diff --git a/integration-tests/fetch.spec.js b/integration-tests/fetch.spec.js index d3de92143..4d9225970 100644 --- a/integration-tests/fetch.spec.js +++ b/integration-tests/fetch.spec.js @@ -145,7 +145,7 @@ describe('end-to-end plugin dependency tests', function () { return cordova.platform('add', 'android', {'fetch': true}); }) .then(function () { - return cordova.plugin('add', 'https://github.com/apache/cordova-plugin-file'); + return cordova.plugin('add', 'https://github.com/apache/cordova-plugin-file', {'fetch': true}); }) .then(function () { return cordova.plugin('add', plugins['Test4'], {'fetch': true}); diff --git a/integration-tests/pkgJson-restore.spec.js b/integration-tests/pkgJson-restore.spec.js index bcae5de9b..d2dff15da 100644 --- a/integration-tests/pkgJson-restore.spec.js +++ b/integration-tests/pkgJson-restore.spec.js @@ -6,9 +6,7 @@ to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -259,7 +257,7 @@ describe('tests platform/spec restore with --save', function () { expect(path.join(pluginsFolderPath, 'cordova-plugin-splashscreen')).not.toExist(); }).then(function () { // Add platform (so that prepare can run). - return cordovaPlatform('add', 'browser', {'save': true, 'fetch': true}); + return cordovaPlatform('add', 'https://github.com/apache/cordova-browser.git', {'save': true, 'fetch': true}); }).then(function () { // Run cordova prepare with fetch. return prepare({'save': true, 'fetch': true}); @@ -339,7 +337,7 @@ describe('tests platform/spec restore with --save', function () { return cordovaPlatform('add', secondPlatformAdded, {'fetch': true}); }).then(function () { // Add helpers.testPlatform to project with --save - return cordovaPlatform('add', [helpers.testPlatform], {'save': true}); + return cordovaPlatform('add', [helpers.testPlatform], {'save': true, 'fetch': true}); }).then(function () { // Delete any previous caches of require(package.json) and (platformsJson) pkgJson = cordova_util.requireNoCache(pkgJsonPath); @@ -369,7 +367,7 @@ describe('tests platform/spec restore with --save', function () { expect(platformsJson[helpers.testPlatform]).toBeUndefined(); }).then(function () { // Run cordova prepare - return prepare(); + return prepare({'fetch': true}); }).then(function () { // Delete any previous caches of platformsJson platformsJson = cordova_util.requireNoCache(platformsFolderPath); @@ -433,7 +431,7 @@ describe('files should not be modified if their platforms are identical', functi // Pkg.json and config.xml contain only android at this point (basePkgJson6). emptyPlatformList().then(function () { // Run cordova prepare. - return prepare(); + return prepare({'fetch': true}); }).then(function () { var cfg2 = new ConfigParser(configXmlPath); engines = cfg2.getEngines(); @@ -516,7 +514,7 @@ describe('update pkg.json to include platforms in config.xml', function () { expect(pkgJson.dependencies[browserPlatform]).toBeUndefined(); expect(pkgJson.dependencies[androidPlatform]).toBeUndefined(); emptyPlatformList().then(function () { - return prepare(); + return prepare({'fetch': true}); }).then(function () { pkgJson = cordova_util.requireNoCache(pkgJsonPath); // Expect 'browser' to be added to pkg.json. @@ -673,7 +671,7 @@ describe('update config.xml to include platforms in pkg.json', function () { expect(pkgJson.dependencies).toEqual({ 'cordova-android': '^5.0.0', 'cordova-browser': '^4.1.0' }); emptyPlatformList().then(function () { // Run cordova prepare. - return prepare(); + return prepare({ 'fetch': true }); }).then(function () { // Delete any previous caches of require(package.json). pkgJson = cordova_util.requireNoCache(pkgJsonPath); @@ -1079,7 +1077,7 @@ describe('update pkg.json AND config.xml to include all plugins/merge variables emptyPlatformList().then(function () { // Run cordova prepare - return prepare({'save': true}); + return prepare({'save': true, 'fetch': true}); }).then(function () { // Delete any previous caches of require(package.json) pkgJson = cordova_util.requireNoCache(pkgJsonPath); @@ -1096,13 +1094,13 @@ describe('update pkg.json AND config.xml to include all plugins/merge variables variable_3: 'value_3', variable_2: 'value_2' }); // Config.xml plugin spec should be updated to ^2.3.0 - expect(configPlugin.spec).toEqual('^2.3.0'); + expect(configPlugin.spec).toEqual('^2.4.1'); } // Expect that splashscreen and device have 0 variables if (configPlugin.name === 'cordova-plugin-device') { expect(configPluginVariables).toEqual({}); // Config.xml device plugin still has the spec ~1.0.0 - expect(configPlugin.spec).toEqual('~1.0.0'); + expect(configPlugin.spec).toEqual('^1.0.1'); } if (configPlugin.name === 'cordova-plugin-splashscreen') { expect(configPluginVariables).toEqual({}); @@ -1116,10 +1114,10 @@ describe('update pkg.json AND config.xml to include all plugins/merge variables // Pkg.json has all 3 plugins with the correct specs expect(Object.keys(pkgJson.cordova.plugins).length === 3); expect(pkgJson.cordova.plugins['cordova-plugin-camera']).toBeDefined(); - expect(pkgJson.dependencies['cordova-plugin-camera']).toEqual('^2.3.0'); + expect(pkgJson.dependencies['cordova-plugin-camera']).toEqual('^2.4.1'); expect(pkgJson.cordova.plugins['cordova-plugin-splashscreen']).toBeDefined(); expect(pkgJson.cordova.plugins['cordova-plugin-device']).toBeDefined(); - expect(pkgJson.dependencies['cordova-plugin-device']).toEqual('~1.0.0'); + expect(pkgJson.dependencies['cordova-plugin-device']).toEqual('^1.0.1'); // Expect that splashscreen and device have 0 variables expect(pkgJson.cordova.plugins['cordova-plugin-splashscreen']).toEqual({}); expect(pkgJson.cordova.plugins['cordova-plugin-device']).toEqual({}); @@ -1199,7 +1197,7 @@ describe('update config.xml to include the plugin that is in pkg.json', function emptyPlatformList().then(function () { // Run cordova prepare. - return prepare({'fetch': false, 'save': true}); + return prepare({'fetch': true, 'save': true}); }).then(function () { // Delete any previous caches of require(package.json). pkgJson = cordova_util.requireNoCache(pkgJsonPath); @@ -1212,16 +1210,16 @@ describe('update config.xml to include the plugin that is in pkg.json', function configPlugin = cfg2.getPlugin(configPlugins[i]); configPluginVariables = configPlugin.variables; // Pkg.json dependencies should be the same. - expect(pkgJson.dependencies).toEqual({ 'cordova-plugin-camera': '^2.3.0' }); + expect(pkgJson.dependencies['cordova-plugin-camera']).toEqual(('^2.4.1')); // Config.xml camera variables have been added. if (configPlugin.name === 'cordova-plugin-camera') { expect(configPluginVariables).toEqual({ variable_1: 'value_1' }); // Check that the camera plugin has the correct spec and has been updated in config.xml - expect(configPlugin.spec).toEqual('^2.3.0'); + expect(configPlugin.spec).toEqual('^2.4.1'); } } // Check to make sure that the config.xml spec was overwritten by the pkg.json one. - expect(configPluginSpecs).toEqual({ name: 'cordova-plugin-camera', spec: '^2.3.0', variables: { variable_1: 'value_1' } }); + expect(configPluginSpecs).toEqual({ name: 'cordova-plugin-camera', spec: '^2.4.1', variables: { variable_1: 'value_1' } }); // Camera plugin gets added to config.xml. expect(Object.keys(configPlugins).length === 1); expect(configPlugins.indexOf('cordova-plugin-camera')).toEqual(0); @@ -1296,7 +1294,7 @@ describe('platforms and plugins should be restored with config.xml even without emptyPlatformList().then(function () { // Run platform add. - return cordovaPlatform('add', browserPlatform, {'save': true}); + return cordovaPlatform('add', browserPlatform, {'save': true, 'fetch': true}); }).then(function () { // Android and browser are in config.xml. var cfg3 = new ConfigParser(configXmlPath); @@ -1443,7 +1441,7 @@ describe('tests platform/spec restore with --save', function () { emptyPlatformList().then(function () { // Add the testing platform with --save. - return cordovaPlatform('add', 'android', {'save': true}); + return cordovaPlatform('add', 'android', {'save': true, 'fetch': true}); }).then(function () { pkgJson = cordova_util.requireNoCache(pkgJsonPath); // Require platformsFolderPath @@ -1468,7 +1466,7 @@ describe('tests platform/spec restore with --save', function () { expect(platformsJson[helpers.testPlatform]).toBeUndefined(); }).then(function () { // Run cordova prepare. - return prepare(); + return prepare({'fetch': true}); }).then(function () { // Delete any previous caches of platforms.json. platformsJson = cordova_util.requireNoCache(platformsFolderPath); @@ -1495,10 +1493,10 @@ describe('tests platform/spec restore with --save', function () { emptyPlatformList().then(function () { // Add the testing platform with --save. - return cordovaPlatform('add', [helpers.testPlatform], {'save': true}); + return cordovaPlatform('add', [helpers.testPlatform], {'save': true, 'fetch': true}); }).then(function () { // Add the 'browser' platform with --save - return cordovaPlatform('add', secondPlatformAdded, {'save': true}); + return cordovaPlatform('add', secondPlatformAdded, {'save': true, 'fetch': true}); }).then(function () { // Delete any previous caches of require(package.json) and (platforms.json). pkgJson = cordova_util.requireNoCache(pkgJsonPath); @@ -1530,7 +1528,7 @@ describe('tests platform/spec restore with --save', function () { expect(platformsJson[secondPlatformAdded]).toBeUndefined(); }).then(function () { // Run cordova prepare. - return prepare(); + return prepare({'fetch': true}); }).then(function () { // Delete any previous caches of platformsJson. platformsJson = cordova_util.requireNoCache(platformsFolderPath); diff --git a/integration-tests/pkgJson.spec.js b/integration-tests/pkgJson.spec.js index ce3716a1f..8cdd7ead2 100644 --- a/integration-tests/pkgJson.spec.js +++ b/integration-tests/pkgJson.spec.js @@ -116,7 +116,7 @@ describe('plugin end-to-end', function () { return cordova.plugin('add', 'cordova-plugin-geolocation', {'save': true, 'fetch': true}) .then(function () { // Add a second plugin without save. - return cordova.plugin('add', pluginId); + return cordova.plugin('add', pluginId, {'fetch': true}); }).then(function () { // Delete any previous caches of require(package.json). pkgJson = cordova_util.requireNoCache(pkgJsonPath); @@ -137,7 +137,7 @@ describe('plugin end-to-end', function () { expect(pkgJsonPath).toExist(); // Add the plugin with --save. - return cordova.plugin('add', pluginId, {'save': true}) + return cordova.plugin('add', pluginId, {'save': true, 'fetch': true}) .then(function () { // Delete any previous caches of require(package.json). pkgJson = cordova_util.requireNoCache(pkgJsonPath); @@ -166,7 +166,7 @@ describe('plugin end-to-end', function () { expect(pkgJsonPath).toExist(); // Add the plugin with --save. - return cordova.plugin('add', pluginId, {'save': true, 'cli_variables': {'someKey': 'someValue'}}) + return cordova.plugin('add', pluginId, {'fetch': true, 'save': true, 'cli_variables': {'someKey': 'someValue'}}) .then(function () { // Delete any previous caches of require(package.json). pkgJson = cordova_util.requireNoCache(pkgJsonPath); @@ -411,7 +411,7 @@ describe('platform end-to-end with --save', function () { // Check there are no platforms yet. emptyPlatformList().then(function () { // Add the testing platform with --save. - return cordova.platform('add', [helpers.testPlatform], {'save': true}); + return cordova.platform('add', [helpers.testPlatform], {'save': true, 'fetch': true}); }).then(function () { // Check the platform add was successful. pkgJson = require(pkgJsonPath); @@ -438,7 +438,7 @@ describe('platform end-to-end with --save', function () { emptyPlatformList().then(function () { // Add the testing platform with --save. - return cordova.platform('add', [helpers.testPlatform], {'save': true}); + return cordova.platform('add', [helpers.testPlatform], {'save': true, 'fetch': true}); }).then(function () { // Check the platform add was successful. pkgJson = cordova_util.requireNoCache(pkgJsonPath); @@ -467,7 +467,7 @@ describe('platform end-to-end with --save', function () { // Pkg.json "platforms" should be empty and helpers.testPlatform should not exist in pkg.json. expect(pkgJson.cordova).toBeUndefined(); // Add platform without --save. - cordova.platform('add', [helpers.testPlatform]) + cordova.platform('add', [helpers.testPlatform], {'fetch': true}) .then(function () { // Check the platform add was successful, reload, skipping cache. pkgJson = cordova_util.requireNoCache(pkgJsonPath); diff --git a/integration-tests/platform.spec.js b/integration-tests/platform.spec.js index a5d2a9391..3ffa63487 100644 --- a/integration-tests/platform.spec.js +++ b/integration-tests/platform.spec.js @@ -128,12 +128,11 @@ describe('platform end-to-end', function () { expect(err).toBeUndefined(); }).fin(done); }); - - it('Test 002 : should install plugins correctly while adding platform', function (done) { - - cordova.plugin('add', path.join(pluginsDir, 'test')) + // was using old fetch code/gitclone... test might not be valid anymore. + xit('Test 002 : should install plugins correctly while adding platform', function (done) { + cordova.plugin('add', path.join(pluginsDir, 'test'), {'fetch': true}) .then(function () { - return cordova.platform('add', [helpers.testPlatform]); + return cordova.platform('add', [helpers.testPlatform], {'fetch': true}); }) .then(function () { // Check the platform add was successful. @@ -190,17 +189,17 @@ describe('platform add plugin rm end-to-end', function () { return cordova.platform('add', 'browser@latest', {'fetch': true}); }) .then(function () { - return cordova.plugin('add', 'cordova-plugin-media'); + return cordova.plugin('add', 'cordova-plugin-media', {'fetch': true}); }) .then(function () { expect(path.join(pluginsDir, 'cordova-plugin-media')).toExist(); expect(path.join(pluginsDir, 'cordova-plugin-file')).toExist(); - return cordova.platform('add', 'android'); + return cordova.platform('add', 'android', {'fetch': true}); }) .then(function () { expect(path.join(pluginsDir, 'cordova-plugin-media')).toExist(); expect(path.join(pluginsDir, 'cordova-plugin-file')).toExist(); - return cordova.plugin('rm', 'cordova-plugin-media'); + return cordova.plugin('rm', 'cordova-plugin-media', {'fetch': true}); }) .then(function () { expect(path.join(pluginsDir, 'cordova-plugin-media')).not.toExist(); @@ -235,7 +234,7 @@ describe('platform add and remove --fetch', function () { cordova.create('helloFetch') .then(function () { process.chdir(project); - return cordova.platform('add', 'browser', {'fetch': true}); + return cordova.platform('add', 'browser', {'fetch': true, 'save': true}); }) .then(function () { expect(path.join(nodeModulesDir, 'cordova-browser')).toExist(); @@ -289,26 +288,23 @@ describe('plugin add and rm end-to-end --fetch', function () { return cordova.platform('add', 'browser', {'fetch': true}); }) .then(function () { - return cordova.plugin('add', 'cordova-plugin-media', {'fetch': true}); + return cordova.plugin('add', 'cordova-plugin-media', {'fetch': true, 'save': true}); }) .then(function () { expect(path.join(pluginsDir, 'cordova-plugin-media')).toExist(); expect(path.join(pluginsDir, 'cordova-plugin-file')).toExist(); - expect(path.join(pluginsDir, 'cordova-plugin-compat')).toExist(); expect(path.join(project, 'node_modules', 'cordova-plugin-media')).toExist(); expect(path.join(project, 'node_modules', 'cordova-plugin-file')).toExist(); - expect(path.join(project, 'node_modules', 'cordova-plugin-compat')).toExist(); return cordova.platform('add', 'android', {'fetch': true}); }) .then(function () { expect(path.join(pluginsDir, 'cordova-plugin-media')).toExist(); expect(path.join(pluginsDir, 'cordova-plugin-file')).toExist(); - return cordova.plugin('rm', 'cordova-plugin-media', {'fetch': true}); + return cordova.plugin('rm', 'cordova-plugin-media'); }) .then(function () { expect(path.join(pluginsDir, 'cordova-plugin-media')).not.toExist(); expect(path.join(pluginsDir, 'cordova-plugin-file')).not.toExist(); - expect(path.join(pluginsDir, 'cordova-plugin-compat')).not.toExist(); // These don't work yet due to the tests finishing before the promise resolves. // expect(path.join(project, 'node_modules', 'cordova-plugin-media')).not.toExist(); // expect(path.join(project, 'node_modules', 'cordova-plugin-file')).not.toExist(); diff --git a/integration-tests/plugin.spec.js b/integration-tests/plugin.spec.js index 815d4182b..d70e64d06 100644 --- a/integration-tests/plugin.spec.js +++ b/integration-tests/plugin.spec.js @@ -132,7 +132,7 @@ describe('plugin end-to-end', function () { }); it('Test 001 : should successfully add and remove a plugin with no options', function (done) { - addPlugin(path.join(pluginsDir, 'fake1'), pluginId, {}, done) + addPlugin(path.join(pluginsDir, 'fake1'), pluginId, {'fetch': true}, done) .then(function () { expect(install.runInstall).toHaveBeenCalled(); expect(platforms.getPlatformApi.calls.count()).toEqual(1); @@ -158,7 +158,7 @@ describe('plugin end-to-end', function () { shell.cd(subdir); // Add plugin using relative path - addPlugin(path.relative(subdir, plugindir), pluginId, {}, done) + addPlugin(path.relative(subdir, plugindir), pluginId, {'fetch': true}, done) .then(function () { return removePlugin(pluginId); }) @@ -171,7 +171,7 @@ describe('plugin end-to-end', function () { it('Test 005 : should respect preference default values', function (done) { var plugin_util = require('../src/cordova/plugin/util'); spyOn(plugin_util, 'mergeVariables').and.returnValue({ REQUIRED: 'NO', REQUIRED_ANDROID: 'NO' }); - addPlugin(path.join(pluginsDir, org_test_defaultvariables), org_test_defaultvariables, {cli_variables: { REQUIRED: 'NO', REQUIRED_ANDROID: 'NO' }}, done) + addPlugin(path.join(pluginsDir, org_test_defaultvariables), org_test_defaultvariables, { cli_variables: { REQUIRED: 'NO', REQUIRED_ANDROID: 'NO' }, 'fetch': true }, done) .then(function () { var platformJsonPath = path.join(project, 'plugins', helpers.testPlatform + '.json'); var installed_plugins = require(platformJsonPath).installed_plugins; @@ -190,7 +190,7 @@ describe('plugin end-to-end', function () { }, 30000); it('Test 006 : should successfully add a plugin when specifying CLI variables', function (done) { - addPlugin(path.join(pluginsDir, org_test_defaultvariables), org_test_defaultvariables, {cli_variables: { REQUIRED: 'yes', REQUIRED_ANDROID: 'yes' }}, done) + addPlugin(path.join(pluginsDir, org_test_defaultvariables), org_test_defaultvariables, {cli_variables: { REQUIRED: 'yes', REQUIRED_ANDROID: 'yes' }, 'fetch': true}, done) .fail(function (err) { expect(err).toBeUndefined(); }) @@ -231,7 +231,7 @@ describe('plugin end-to-end', function () { it('Test 009 : should not check npm info when fetching from a Git repository', function (done) { spyOn(registry, 'info'); - addPlugin(testGitPluginRepository, testGitPluginId, {}, done) + addPlugin(testGitPluginRepository, testGitPluginId, {'fetch': true}, done) .then(function () { expect(registry.info).not.toHaveBeenCalled(); }) @@ -241,7 +241,7 @@ describe('plugin end-to-end', function () { .fin(done); }, 30000); - it('Test 010 : should select the plugin version based on npm info when fetching from npm', function (done) { + it('Test 010 : should use registry.info to get plugin & version', function (done) { mockPluginFetch(npmInfoTestPlugin, path.join(pluginsDir, npmInfoTestPlugin)); spyOn(registry, 'info').and.callThrough(); @@ -250,7 +250,7 @@ describe('plugin end-to-end', function () { expect(registry.info).toHaveBeenCalled(); var fetchTarget = plugman.fetch.calls.mostRecent().args[0]; - expect(fetchTarget).toEqual(npmInfoTestPlugin + '@' + npmInfoTestPluginVersion); + expect(fetchTarget).toEqual(npmInfoTestPlugin); }) .fail(function (err) { expect(err).toBeUndefined(); @@ -268,7 +268,7 @@ describe('plugin end-to-end', function () { // Check to make sure that we are at least trying to get the correct package. // This package is not published to npm, so we can't truly do end-to-end tests - expect(registry.info).toHaveBeenCalledWith([scopedPackage]); + expect(registry.info).toHaveBeenCalledWith([scopedPackage], jasmine.any(String), jasmine.any(Object)); var fetchTarget = plugman.fetch.calls.mostRecent().args[0]; expect(fetchTarget).toEqual(scopedPackage); diff --git a/integration-tests/plugman_fetch.spec.js b/integration-tests/plugman_fetch.spec.js index 69b46cd1a..9c2faf7b2 100644 --- a/integration-tests/plugman_fetch.spec.js +++ b/integration-tests/plugman_fetch.spec.js @@ -23,7 +23,6 @@ var os = require('os'); var path = require('path'); var shell = require('shelljs'); var realrm = shell.rm; -var TIMEOUT = 60 * 1000; // xml_helpers = require('../src/util/xml-helpers'), var metadata = require('../src/plugman/util/metadata'); var temp = path.join(os.tmpdir(), 'plugman', 'fetch'); @@ -35,9 +34,7 @@ var test_plugin_searchpath = path.join(test_plugin, '..'); // test_plugin_xml = xml_helpers.parseElementtreeSync(path.join(test_plugin, 'plugin.xml')), var test_plugin_id = 'org.test.plugins.childbrowser'; var test_plugin_version = '0.6.0'; -var plugins = require('../src/plugman/util/plugins'); var Q = require('q'); -var registry = require('../src/plugman/registry/registry'); describe('fetch', function () { @@ -92,7 +89,7 @@ describe('fetch', function () { }); it('Test 001 : should copy locally-available plugin to plugins directory', function (done) { - wrapper(fetch(test_plugin, temp), done, function () { + wrapper(fetch(test_plugin, temp, { fetch: true }), done, function () { expect(cp).toHaveBeenCalledWith('-R', path.join(test_plugin, '*'), path.join(temp, test_plugin_id)); }); }); @@ -102,13 +99,13 @@ describe('fetch', function () { }); }); it('Test 003 : should create a symlink if used with `link` param', function (done) { - wrapper(fetch(test_plugin, temp, { link: true }), done, function () { + wrapper(fetch(test_plugin, temp, { fetch: true, link: true }), done, function () { expect(sym).toHaveBeenCalledWith(test_plugin, path.join(temp, test_plugin_id), 'dir'); }); }); it('Test 004 : should fail when the expected ID doesn\'t match', function (done) { - fetch(test_plugin, temp, { expected_id: 'wrongID' }) + fetch(test_plugin, temp, { expected_id: 'wrongID', fetch: true }) .then(function () { expect('this call').toBe('fail'); }, function (err) { @@ -117,12 +114,12 @@ describe('fetch', function () { }); it('Test 005 : should succeed when the expected ID is correct', function (done) { - wrapper(fetch(test_plugin, temp, { expected_id: test_plugin_id }), done, function () { + wrapper(fetch(test_plugin, temp, { expected_id: test_plugin_id, fetch: true }), done, function () { expect(1).toBe(1); }); }); it('Test 006 : should fail when the expected ID with version specified doesn\'t match', function (done) { - fetch(test_plugin, temp, { expected_id: test_plugin_id + '@wrongVersion' }) + fetch(test_plugin, temp, { expected_id: test_plugin_id + '@wrongVersion', fetch: true }) .then(function () { expect('this call').toBe('fail'); }, function (err) { @@ -131,7 +128,7 @@ describe('fetch', function () { }); it('Test 007 : should succeed when the plugin version specified is correct', function (done) { var exp_id = test_plugin_id + '@' + test_plugin_version; - wrapper(fetch(test_plugin, temp, { expected_id: exp_id }), done, function () { + wrapper(fetch(test_plugin, temp, { expected_id: exp_id, fetch: true }), done, function () { expect(1).toBe(1); }); }); @@ -142,6 +139,7 @@ describe('fetch', function () { }); }); it('Test 028 : should fail when locally-available plugin is missing pacakge.json', function (done) { + test_plugin = path.join(plugins_dir, 'org.test.androidonly'); fetch(test_plugin, temp, {fetch: true}) .then(function () { expect(false).toBe(true); @@ -152,129 +150,6 @@ describe('fetch', function () { }); }); }); - describe('git plugins', function () { - var clone; - var save_metadata; - var done; // eslint-disable-line no-unused-vars - - beforeEach(function () { - clone = spyOn(plugins, 'clonePluginGitRepo').and.returnValue(Q(test_plugin)); - save_metadata = spyOn(metadata, 'save_fetch_metadata'); - done = false; - }); - it('Test 008 : should call clonePluginGitRepo for https:// and git:// based urls', function (done) { - var url = 'https://github.com/bobeast/GAPlugin.git'; - fetch(url, temp).then(function () { - expect(save_metadata).toHaveBeenCalled(); - expect(clone).toHaveBeenCalledWith(url, temp, '.', undefined, undefined); - done(); - }); - }, 6000); - - it('Test 009 : should call clonePluginGitRepo with subdir if applicable', function (done) { - var url = 'https://github.com/bobeast/GAPlugin.git'; - var dir = 'fakeSubDir'; - fetch(url, temp, { subdir: dir }).then(function () { - expect(clone).toHaveBeenCalledWith(url, temp, dir, undefined, undefined); - expect(save_metadata).toHaveBeenCalled(); - done(); - }); - }, 6000); - - it('Test 010 : should call clonePluginGitRepo with subdir and git ref if applicable', function (done) { - var url = 'https://github.com/bobeast/GAPlugin.git'; - var dir = 'fakeSubDir'; - var ref = 'fakeGitRef'; - fetch(url, temp, { subdir: dir, git_ref: ref }).then(function () { - expect(clone).toHaveBeenCalledWith(url, temp, dir, ref, undefined); - expect(save_metadata).toHaveBeenCalled(); - done(); - }); - }, 6000); - - it('Test 011 : should extract the git ref from the URL hash, if provided', function (done) { - var url = 'https://github.com/bobeast/GAPlugin.git#fakeGitRef'; - var baseURL = 'https://github.com/bobeast/GAPlugin.git'; - fetch(url, temp, {}).then(function () { - expect(clone).toHaveBeenCalledWith(baseURL, temp, '.', 'fakeGitRef', undefined); - expect(save_metadata).toHaveBeenCalled(); - done(); - }); - }, 6000); - - it('Test 012 : should extract the subdir from the URL hash, if provided', function (done) { - var url = 'https://github.com/bobeast/GAPlugin.git#:fakeSubDir'; - var baseURL = 'https://github.com/bobeast/GAPlugin.git'; - fetch(url, temp, {}).then(function (result) { - expect(clone).toHaveBeenCalledWith(baseURL, temp, 'fakeSubDir', undefined, undefined); - expect(save_metadata).toHaveBeenCalled(); - done(); - }); - }, 6000); - - it('Test 013 : should extract the git ref and subdir from the URL hash, if provided', function (done) { - var url = 'https://github.com/bobeast/GAPlugin.git#fakeGitRef:/fake/Sub/Dir/'; - var baseURL = 'https://github.com/bobeast/GAPlugin.git'; - fetch(url, temp, {}).then(function (result) { - expect(clone).toHaveBeenCalledWith(baseURL, temp, 'fake/Sub/Dir', 'fakeGitRef', undefined); - expect(save_metadata).toHaveBeenCalled(); - done(); - }); - }, 6000); - - it('Test 014 : should fail when the expected ID doesn\'t match', function (done) { - fetch('https://github.com/bobeast/GAPlugin.git', temp, { expected_id: 'wrongID' }) - .then(function () { - expect('this call').toBe('fail'); - }, function (err) { - expect('' + err).toContain('Expected plugin to have ID "wrongID" but got'); - }).fin(done); - }); - - it('Test 015 : should fail when the expected ID with version specified doesn\'t match', function (done) { - fetch('https://github.com/bobeast/GAPlugin.git', temp, { expected_id: 'id@wrongVersion' }) - .then(function () { - expect('this call').toBe('fail'); - }, function (err) { - expect('' + err).toContain('Expected plugin to have ID "id" but got'); - }).fin(done); - }); - - it('Test 016 : should succeed when the expected ID is correct', function (done) { - wrapper(fetch('https://github.com/bobeast/GAPlugin.git', temp, { expected_id: test_plugin_id }), done, function () { - expect(1).toBe(1); - }); - }); - }); - - describe('github plugins', function () { - // these tests actually pull a plugin from github - beforeEach(function () { - realrm('-rf', temp); - }); - - // this commit uses the new id - it('Test 017 : should fetch from a commit-sha', function (done) { - wrapper(fetch('http://github.com/apache/cordova-plugin-device.git#ad5f1e7bfd05ef98c01df549a0fa98036a5625db', temp, { expected_id: 'cordova-plugin-device' }), done, function () { - expect(1).toBe(1); - done(); - }); - }, TIMEOUT); - // this branch uses the old id - it('Test 018 : should fetch from a branch', function (done) { - wrapper(fetch('http://github.com/apache/cordova-plugin-device.git#cdvtest', temp, { expected_id: 'org.apache.cordova.device' }), done, function () { - expect(1).toBe(1); - done(); - }); - }, TIMEOUT); - // this tag uses the new id - it('Test 019 : should fetch from a tag', function (done) { - wrapper(fetch('http://github.com/apache/cordova-plugin-device.git#r1.0.0', temp, { expected_id: 'cordova-plugin-device' }), done, function () { - expect(1).toBe(1); - done(); - }); - }, TIMEOUT); - }); describe('fetch recursive error CB-8809', function () { @@ -284,7 +159,7 @@ describe('fetch', function () { if (/^win/.test(process.platform)) { it('Test 020 : should copy all but the /demo/ folder', function (done) { var cp = spyOn(shell, 'cp'); - wrapper(fetch(srcDir, appDir), done, function () { + wrapper(fetch(srcDir, appDir, {fetch: true}), done, function () { expect(cp).toHaveBeenCalledWith('-R', path.join(srcDir, 'asset.txt'), path.join(appDir, 'test-recursive')); expect(cp).not.toHaveBeenCalledWith('-R', srcDir, path.join(appDir, 'test-recursive')); }); @@ -294,61 +169,10 @@ describe('fetch', function () { var cp = spyOn(shell, 'cp').and.callFake(function () {}); - wrapper(fetch(srcDir, appDir), done, function () { + wrapper(fetch(srcDir, appDir, {fetch: true}), done, function () { expect(cp).not.toHaveBeenCalled(); }); }); } - - }); - - describe('registry plugins', function () { - /* eslint-disable no-unused-vars */ - var pluginId = 'dummyplugin'; - var sFetch; - var rm; - var sym; - var save_metadata; - /* eslint-enable no-unused-vars */ - beforeEach(function () { - rm = spyOn(shell, 'rm'); - sym = spyOn(fs, 'symlinkSync'); - save_metadata = spyOn(metadata, 'save_fetch_metadata'); - sFetch = spyOn(registry, 'fetch').and.returnValue(Q(test_plugin)); - realrm('-rf', temp); - }); - - it('Test 022 : should fail when the expected ID with version specified doesn\'t match', function (done) { - // fetch(pluginId, temp, { expected_id: test_plugin_id + '@wrongVersion' }) - fetch(pluginId, temp, { expected_id: 'wrongID' }) - .then(function () { - expect('this call').toBe('fail'); - }, function (err) { - expect('' + err).toContain('Expected plugin to have ID "wrongID" but got'); - }).fin(done); - }); - - it('Test 023 : should succeed when the expected ID is correct', function (done) { - wrapper(fetch(pluginId, temp, { expected_id: test_plugin_id }), done, function () { - expect(1).toBe(1); - }); - }); - it('Test 024 : should succeed when the plugin version specified is correct', function (done) { - wrapper(fetch(pluginId, temp, { expected_id: test_plugin_id + '@' + test_plugin_version }), done, function () { - expect(1).toBe(1); - }); - }); - it('Test 025 : should fetch plugins that are scoped packages', function (done) { - var scopedPackage = '@testcope/dummy-plugin'; - wrapper(fetch(scopedPackage, temp, { expected_id: test_plugin_id }), done, function () { - expect(sFetch).toHaveBeenCalledWith([scopedPackage]); - }); - }); - it('Test 026 : should fetch plugins that are scoped packages and have versions specified', function (done) { - var scopedPackage = '@testcope/dummy-plugin@latest'; - wrapper(fetch(scopedPackage, temp, { expected_id: test_plugin_id }), done, function () { - expect(sFetch).toHaveBeenCalledWith([scopedPackage]); - }); - }); }); }); diff --git a/package.json b/package.json index 71a732dc6..0cc02f47b 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "glob": "7.1.1", "init-package-json": "^1.2.0", "nopt": "4.0.1", - "npm": "^2.10.x", "opener": "1.4.2", "plist": "2.0.1", "properties-parser": "0.3.1", diff --git a/spec/cordova/fixtures/plugins/com.plugin.withhooks/package.json b/spec/cordova/fixtures/plugins/com.plugin.withhooks/package.json new file mode 100644 index 000000000..6df177b32 --- /dev/null +++ b/spec/cordova/fixtures/plugins/com.plugin.withhooks/package.json @@ -0,0 +1,11 @@ +{ + "name": "withhooks", + "version": "3.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/spec/cordova/fixtures/plugins/fake1/package.json b/spec/cordova/fixtures/plugins/fake1/package.json new file mode 100644 index 000000000..4ad87cdeb --- /dev/null +++ b/spec/cordova/fixtures/plugins/fake1/package.json @@ -0,0 +1,28 @@ +{ + "name": "fake1", + "version": "1.3.1", + "description": "Empty plugin used as part of the tests in cordova-lib", + "cordova": { + "id": "fake1", + "platforms": [] + }, + "repository": { + "type": "git", + "url": "git://git-wip-us.apache.org/repos/asf/cordova-lib.git" + }, + "author": "Apache Software Foundation", + "license": "Apache-2.0", + "engines": { + "cordovaDependencies": { + "0.0.0": { + "cordova-android": "<2.1.0" + }, + "1.1.2": { + "cordova-android": ">=2.1.0 <7.0.0" + }, + "1.3.0": { + "cordova-android": "7.0.0" + } + } + } +} diff --git a/spec/cordova/fixtures/plugins/org.test.defaultvariables/package.json b/spec/cordova/fixtures/plugins/org.test.defaultvariables/package.json new file mode 100644 index 000000000..b7f919bd4 --- /dev/null +++ b/spec/cordova/fixtures/plugins/org.test.defaultvariables/package.json @@ -0,0 +1,28 @@ +{ + "name": "org.test.defaultvariables", + "version": "1.3.1", + "description": "Empty plugin used as part of the tests in cordova-lib", + "cordova": { + "id": "cordova-lib-test-plugin", + "platforms": [] + }, + "repository": { + "type": "git", + "url": "git://git-wip-us.apache.org/repos/asf/cordova-lib.git" + }, + "author": "Apache Software Foundation", + "license": "Apache-2.0", + "engines": { + "cordovaDependencies": { + "0.0.0": { + "cordova-android": "<2.1.0" + }, + "1.1.2": { + "cordova-android": ">=2.1.0 <7.0.0" + }, + "1.3.0": { + "cordova-android": "7.0.0" + } + } + } +} diff --git a/spec/cordova/fixtures/plugins/test/package.json b/spec/cordova/fixtures/plugins/test/package.json new file mode 100644 index 000000000..86dc97e44 --- /dev/null +++ b/spec/cordova/fixtures/plugins/test/package.json @@ -0,0 +1,11 @@ +{ + "name": "0", + "version": "3.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} diff --git a/spec/cordova/lazy_load.spec.js b/spec/cordova/lazy_load.spec.js deleted file mode 100644 index a4ede0dcf..000000000 --- a/spec/cordova/lazy_load.spec.js +++ /dev/null @@ -1,277 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ - -var lazy_load = require('../../src/cordova/lazy_load'); -var npmHelper = require('../../src/util/npm-helper'); -var config = require('../../src/cordova/config'); -var shell = require('shelljs'); -var npm = require('npm'); -var path = require('path'); -var HooksRunner = require('../../src/hooks/HooksRunner'); -var request = require('request'); -var fs = require('fs'); -var Q = require('q'); -var platforms = require('../../src/platforms/platforms'); - -describe('lazy_load module', function () { - var custom_path, cachePackage, fakeLazyLoad; - beforeEach(function () { - custom_path = spyOn(config, 'has_custom_path').and.returnValue(false); - cachePackage = spyOn(npmHelper, 'cachePackage').and.returnValue(Q(path.join('lib', 'dir'))); - fakeLazyLoad = function (id, platform, version) { - if (platform === 'wp7' || platform === 'wp8') { - return Q(path.join('lib', 'wp', id, version, platform)); - } else { - return Q(path.join('lib', platform, id, version, platforms[platform] && platforms[platform].subdirectory ? platforms[platform].subdirectory : '')); - } - }; - }); - describe('cordova method (loads stock cordova libs)', function () { - var custom; // eslint-disable-line no-unused-vars - var version; - beforeEach(function () { - custom = spyOn(lazy_load, 'custom').and.returnValue(Q(path.join('lib', 'dir'))); - version = platforms.android.version; - platforms.android.version = '3.14.15.9265'; - }); - afterEach(function () { - platforms.android.version = version; - }); - it('Test 001: should throw if platform is not a stock cordova platform', function (done) { - lazy_load.cordova('atari').then(function () { - expect('this call').toEqual('to fail'); - }, function (err) { - expect('' + err).toContain('Cordova library "atari" not recognized.'); - }).fin(done); - }); - it('Test 002 : should invoke lazy_load.custom with appropriate url, platform, and version as specified in platforms manifest', function (done) { - lazy_load.cordova('android').then(function (dir) { - expect(cachePackage).toHaveBeenCalled(); - expect(dir).toBeDefined(); - done(); - }); - }); - }); - - describe('custom method (loads custom cordova libs)', function () { - /* eslint-disable no-unused-vars */ - var exists; - var fire; - var rm; - var mv; - var readdir; - /* eslint-enable no-unused-vars */ - beforeEach(function () { - spyOn(shell, 'mkdir'); - rm = spyOn(shell, 'rm'); - mv = spyOn(shell, 'mv'); - exists = spyOn(fs, 'existsSync').and.returnValue(false); - readdir = spyOn(fs, 'readdirSync').and.returnValue(['somefile.txt']); - fire = spyOn(HooksRunner, 'fire').and.returnValue(Q()); - }); - - it('Test 003 : should callback with no errors and not fire event hooks if library already exists', function (done) { - exists.and.returnValue(true); - var mock_platforms = { - 'platform X': { - id: 'some id', - url: 'http://some remote url', - version: 'three point five' - } - }; - lazy_load.custom(mock_platforms, 'platform X').then(function () { - expect(fire).not.toHaveBeenCalled(); - }, function (err) { - expect(err).not.toBeDefined(); - }).fin(done); - }); - it('Test 004 : should callback with no errors and fire event hooks even if library already exists if the lib url is a local dir', function (done) { - exists.and.returnValue(true); - var mock_platforms = { - 'platform X': { - id: 'some id', - url: 'some local dir', - version: 'three point six' - } - }; - lazy_load.custom(mock_platforms, 'platform X').then(function () { - expect(fire).not.toHaveBeenCalled(); - }, function (err) { - expect(err).not.toBeDefined(); - }).fin(done); - }); - - describe('remote URLs for libraries', function () { - var req; - var events = {}; - var fakeRequest = { - on: jasmine.createSpy().and.callFake(function (event, cb) { - events[event] = cb; - return fakeRequest; - }), - pipe: jasmine.createSpy().and.callFake(function () { return fakeRequest; }) - }; - beforeEach(function () { - events = {}; - fakeRequest.on.calls.reset(); - fakeRequest.pipe.calls.reset(); - req = spyOn(request, 'get').and.callFake(function () { - // Fire the 'end' event shortly. - setTimeout(function () { - events['end'](); - }, 10); - return fakeRequest; - }); - spyOn(npm, 'load').and.callFake(function (cb) { cb(); }); - spyOn(npm.config, 'get').and.returnValue(null); - }); - - it('Test 005 : should call request with appropriate url params', function (done) { - var url = 'https://github.com/apache/someplugin'; - var with_android_platform = { - 'android': { - id: 'random', - url: url, - version: '1.0' - } - }; - lazy_load.custom(with_android_platform, 'android').then(function () { - expect(req).toHaveBeenCalledWith({ - url: url - }, jasmine.any(Function)); - }, function (err) { - expect(err).not.toBeDefined(); - }).fin(done); - }); - it('Test 006 : should take into account https-proxy npm configuration var if exists for https:// calls', function (done) { - var proxy = 'https://somelocalproxy.com'; - npm.config.get.and.returnValue(proxy); - var url = 'https://github.com/apache/someplugin'; - var with_android_platform = { - 'android': { - id: 'random', - url: url, - version: '1.0' - } - }; - lazy_load.custom(with_android_platform, 'android').then(function () { - expect(req).toHaveBeenCalledWith({ - url: url, - proxy: proxy - }, jasmine.any(Function)); - }, function (err) { - expect(err).not.toBeDefined(); - }).fin(done); - }); - it('Test 007 : should take into account proxy npm config var if exists for http:// calls', function (done) { - var proxy = 'http://somelocalproxy.com'; - npm.config.get.and.returnValue(proxy); - var url = 'http://github.com/apache/someplugin'; - var with_android_platform = { - 'android': { - id: 'random', - url: url, - version: '1.0' - } - }; - lazy_load.custom(with_android_platform, 'android').then(function () { - expect(req).toHaveBeenCalledWith({ - url: url, - proxy: proxy - }, jasmine.any(Function)); - }, function (err) { - expect(err).not.toBeDefined(); - }).fin(done); - }); - }); - - describe('local paths for libraries', function () { - it('Test 009 : should return the local path, no symlink', function (done) { - var mock_platforms = { - 'X': { - id: 'id', - url: '/some/random/lib', - version: 'three point eight' - } - }; - lazy_load.custom(mock_platforms, 'X').then(function (dir) { - expect(path.normpath(dir)).toEqual('/some/random/lib'); - }, function (err) { - expect(err).toBeUndefined(); - }).fin(done); - }); - it('Test 010 : should not file download hook', function (done) { - var mock_platforms = { - 'X': { - id: 'id', - url: '/some/random/lib', - version: 'three point nine' - } - }; - lazy_load.custom(mock_platforms, 'X').then(function () { - expect(fire).not.toHaveBeenCalledWith('after_library_download', {platform: 'X', url: '/some/random/lib', id: 'id', version: 'three point nine', path: '/some/random/lib', symlink: false}); - }, function (err) { - expect(err).toBeUndefined(); - }).fin(done); - }); - }); - }); - - describe('based_on_config method', function () { - var cordova; - var custom; - var read; // eslint-disable-line no-unused-vars - beforeEach(function () { - cordova = spyOn(lazy_load, 'cordova').and.returnValue(Q()); - custom = spyOn(lazy_load, 'custom').and.returnValue(Q()); - }); - it('Test 011 : should invoke custom if a custom lib is specified', function (done) { - read = spyOn(config, 'read').and.returnValue({ - lib: { - maybe: { - url: 'you or eye?', - id: 'eye dee', - version: 'four point twenty' - } - } - }); - var p = '/some/random/custom/path'; - custom_path.and.returnValue(p); - custom.and.callFake(function (platforms, platform) { - expect(platform).toEqual('maybe'); - expect(platforms[platform].url).toEqual('you or eye?'); - expect(platforms[platform].id).toEqual('eye dee'); - expect(platforms[platform].version).toEqual('four point twenty'); - return fakeLazyLoad(platforms[platform].id, platform, platforms[platform].version); - }); - lazy_load.based_on_config('yup', 'maybe').then(function () { - expect(custom).toHaveBeenCalled(); - }, function (err) { - expect(err).toBeUndefined(); - }).fin(done); - }); - it('Test 012 : should invoke cordova if no custom lib is specified', function (done) { - lazy_load.based_on_config('yup', 'ios').then(function () { - expect(cordova).toHaveBeenCalled(); - }, function (err) { - expect(err).toBeUndefined(); - }).fin(done); - }); - }); -}); diff --git a/spec/cordova/platform/addHelper.spec.js b/spec/cordova/platform/addHelper.spec.js index 4b84d4021..7a48c9532 100644 --- a/spec/cordova/platform/addHelper.spec.js +++ b/spec/cordova/platform/addHelper.spec.js @@ -29,9 +29,7 @@ var cordova_util = require('../../../src/cordova/util'); var cordova_config = require('../../../src/cordova/config'); var plugman = require('../../../src/plugman/plugman'); var fetch_metadata = require('../../../src/plugman/util/metadata'); -var lazy_load = require('../../../src/cordova/lazy_load'); var prepare = require('../../../src/cordova/prepare'); -var gitclone = require('../../../src/gitclone'); var fail; describe('cordova/platform/addHelper', function () { @@ -346,8 +344,6 @@ describe('cordova/platform/addHelper', function () { describe('downloadPlatform', function () { beforeEach(function () { spyOn(Q, 'reject').and.callThrough(); - spyOn(lazy_load, 'based_on_config'); - spyOn(lazy_load, 'git_clone').and.callThrough(); platform_addHelper.downloadPlatform.and.callThrough(); }); describe('errors', function () { @@ -359,42 +355,6 @@ describe('cordova/platform/addHelper', function () { expect(e.message).toContain('fetch has failed, rejecting promise'); }).done(done); }); - - it('should reject the promise should lazy_load.git_clone fail', function (done) { - lazy_load.based_on_config.and.returnValue(false); - cordova_util.isUrl.and.returnValue(true); - platform_addHelper.downloadPlatform(projectRoot, 'android', 'https://github.com/apache/cordova-android', {save: true}).then(function () { - fail('success handler unexpectedly invoked'); - }).fail(function (e) { - expect(Q.reject).toHaveBeenCalled(); - expect(events.emit).toHaveBeenCalledWith('verbose', 'Cloning failed. Let\'s try handling it as a tarball'); - }).done(done); - }, 60000); - - it('should reject the promise should lazy_load.based_on_config fail', function (done) { - spyOn(gitclone, 'clone').and.callThrough(); - lazy_load.git_clone.and.returnValue(true); - lazy_load.based_on_config.and.returnValue(false); - cordova_util.isUrl.and.returnValue(true); - platform_addHelper.downloadPlatform(projectRoot, 'android', 'https://github.com/apache/cordova-android', {save: true}).then(function () { - fail('success handler unexpectedly invoked'); - }).fail(function (e) { - expect(Q.reject).toHaveBeenCalled(); - expect(lazy_load.based_on_config).not.toHaveBeenCalled(); - }).done(done); - }, 60000); - - it('should reject the promise should both git_clone and based_on_config fail after the latter was fallen back on', function (done) { - lazy_load.git_clone.and.returnValue(Q.reject('git_clone failed')); - lazy_load.based_on_config.and.returnValue(Q.reject('based_on_config failed')); - cordova_util.isUrl.and.returnValue(true); - fetch_mock.and.returnValue(true); - platform_addHelper.downloadPlatform(projectRoot, 'android', 'https://github.com/apache/cordova-android', {save: true}).then(function () { - fail('success handler unexpectedly invoked'); - }).fail(function (e) { - expect(Q.reject).toHaveBeenCalled(); - }).done(done); - }, 60000); }); describe('happy path', function () { it('should invoke cordova-fetch if fetch was provided as an option', function (done) { @@ -405,40 +365,6 @@ describe('cordova/platform/addHelper', function () { fail('fail handler unexpectedly invoked'); }).done(done); }); - - it('should invoke lazy_load.git_clone if the version to download is a URL', function (done) { - lazy_load.git_clone.and.callThrough(); - spyOn(gitclone, 'clone').and.returnValue(true); - fetch_mock.and.returnValue(true); - cordova_util.isUrl.and.returnValue(true); - platform_addHelper.downloadPlatform(projectRoot, 'android', 'https://github.com/apache/cordova-android', {save: true}).then(function () { - expect(events.emit).toHaveBeenCalledWith('log', 'git cloning: https://github.com/apache/cordova-android'); - expect(cordova_util.isUrl).toHaveBeenCalledWith('https://github.com/apache/cordova-android'); - expect(lazy_load.git_clone).toHaveBeenCalled(); - }).fail(function (e) { - fail('fail handler unexpectedly invoked'); - }).done(done); - }, 60000); - - it('should attempt to lazy_load.based_on_config if lazy_load.git_clone fails', function (done) { - cordova_util.isUrl.and.returnValue(true); - platform_addHelper.downloadPlatform(projectRoot, 'android', 'https://github.com/apache/cordova-android', {save: true}).then(function () { - expect(events.emit).toHaveBeenCalledWith('verbose', '"git" command line tool is not installed: make sure it is accessible on your PATH.'); - expect(events.emit).toHaveBeenCalledWith('verbose', 'Cloning failed. Let\'s try handling it as a tarball'); - expect(lazy_load.based_on_config).toHaveBeenCalled(); - }).fail(function (e) { - fail('fail handler unexpectedly invoked'); - }).done(done); - }, 60000); - - it('should by default attempt to lazy_load.based_on_config', function (done) { - platform_addHelper.downloadPlatform(projectRoot, 'android', '6.0.0', {save: true}).then(function () { - expect(lazy_load.based_on_config).toHaveBeenCalledWith('/some/path', 'android@6.0.0', Object({ save: true })); - }).fail(function (e) { - fail('fail handler unexpectedly invoked'); - }).done(done); - }, 60000); - it('should pass along a libDir argument to getPlatformDetailsFromDir on a successful platform download', function (done) { cordova_util.isUrl.and.returnValue(true); platform_addHelper.downloadPlatform(projectRoot, 'android', 'https://github.com/apache/cordova-android', {save: true}).then(function () { diff --git a/spec/cordova/plugin/add.spec.js b/spec/cordova/plugin/add.spec.js index e60fdd41b..5cfd237ec 100644 --- a/spec/cordova/plugin/add.spec.js +++ b/spec/cordova/plugin/add.spec.js @@ -356,7 +356,7 @@ describe('cordova/plugin/add', function () { it('should retrieve plugin info via registry.info', function (done) { add.determinePluginTarget(projectRoot, Cfg_parser_mock, 'cordova-plugin-device', {}) .then(function (target) { - expect(registry.info).toHaveBeenCalledWith(['cordova-plugin-device']); + expect(registry.info).toHaveBeenCalledWith(['cordova-plugin-device'], '/some/path', jasmine.any(Object)); expect(events.emit).toHaveBeenCalledWith('verbose', 'Attempting to use npm info for cordova-plugin-device to choose a compatible release'); expect(target).toEqual('cordova-plugin-device'); }).fail(function (e) { diff --git a/spec/plugman/config.spec.js b/spec/plugman/config.spec.js deleted file mode 100644 index 46c4a03c0..000000000 --- a/spec/plugman/config.spec.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ -var config = require('../../src/plugman/config'); -var Q = require('q'); -var registry = require('../../src/plugman/registry/registry'); - -describe('config', function () { - it('Test 001 : should run config', function () { - var sConfig = spyOn(registry, 'config').and.returnValue(Q()); - var params = ['set', 'registry', 'http://registry.cordova.io']; - config(params); - expect(sConfig).toHaveBeenCalledWith(params); - }); -}); diff --git a/spec/plugman/install.spec.js b/spec/plugman/install.spec.js index 7d9ca8880..3341ea395 100644 --- a/spec/plugman/install.spec.js +++ b/spec/plugman/install.spec.js @@ -461,20 +461,6 @@ describe('install', function () { }); }, TIMEOUT); - it('Test 024 : should throw if git is not found on the path and a remote url is requested', function (done) { - spyOn(fs, 'existsSync').and.callFake(fake['existsSync']['noPlugins']); - fetchSpy.and.callThrough(); - spyOn(shell, 'which').and.returnValue(null); - install('android', project, 'https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git') - .then(function (result) { - expect(false).toBe(true); - done(); - }).fail(function err (errMsg) { - expect(errMsg.toString()).toContain('"git" command line tool is not installed: make sure it is accessible on your PATH.'); - done(); - }); - }, TIMEOUT); - it('Test 025 :should not fail when trying to install plugin less than minimum version. Skip instead ', function (done) { spyOn(semver, 'satisfies').and.returnValue(false); exec.and.callFake(function (cmd, cb) { diff --git a/spec/plugman/owner.spec.js b/spec/plugman/owner.spec.js deleted file mode 100644 index 0b85fc842..000000000 --- a/spec/plugman/owner.spec.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ -var owner = require('../../src/plugman/owner'); -var Q = require('q'); -var registry = require('../../src/plugman/registry/registry'); - -describe('owner', function () { - it('Test 001 : should run owner', function () { - var sOwner = spyOn(registry, 'owner').and.returnValue(Q()); - var params = ['add', 'anis', 'org.test.plugins.dummyplugin']; - owner(params); - expect(sOwner).toHaveBeenCalledWith(params); - }); -}); diff --git a/spec/plugman/plugins/org.test.plugins.childbrowser/package.json b/spec/plugman/plugins/org.test.plugins.childbrowser/package.json new file mode 100644 index 000000000..607d86fdc --- /dev/null +++ b/spec/plugman/plugins/org.test.plugins.childbrowser/package.json @@ -0,0 +1,28 @@ +{ + "name": "childbrowser", + "version": "1.3.1", + "description": "Empty plugin used as part of the tests in cordova-lib", + "cordova": { + "id": "childbrowser", + "platforms": [] + }, + "repository": { + "type": "git", + "url": "git://git-wip-us.apache.org/repos/asf/cordova-lib.git" + }, + "author": "Apache Software Foundation", + "license": "Apache-2.0", + "engines": { + "cordovaDependencies": { + "0.0.0": { + "cordova-android": "<2.1.0" + }, + "1.1.2": { + "cordova-android": ">=2.1.0 <7.0.0" + }, + "1.3.0": { + "cordova-android": "7.0.0" + } + } + } +} diff --git a/spec/plugman/plugins/recursivePlug/package.json b/spec/plugman/plugins/recursivePlug/package.json new file mode 100644 index 000000000..34f2122b1 --- /dev/null +++ b/spec/plugman/plugins/recursivePlug/package.json @@ -0,0 +1,28 @@ +{ + "name": "recursive", + "version": "1.3.1", + "description": "Empty plugin used as part of the tests in cordova-lib", + "cordova": { + "id": "recursive", + "platforms": [] + }, + "repository": { + "type": "git", + "url": "git://git-wip-us.apache.org/repos/asf/cordova-lib.git" + }, + "author": "Apache Software Foundation", + "license": "Apache-2.0", + "engines": { + "cordovaDependencies": { + "0.0.0": { + "cordova-android": "<2.1.0" + }, + "1.1.2": { + "cordova-android": ">=2.1.0 <7.0.0" + }, + "1.3.0": { + "cordova-android": "7.0.0" + } + } + } +} diff --git a/spec/plugman/registry/registry.spec.js b/spec/plugman/registry/registry.spec.js index d02a19d0c..127c997ab 100644 --- a/spec/plugman/registry/registry.spec.js +++ b/spec/plugman/registry/registry.spec.js @@ -93,7 +93,8 @@ describe('registry', function () { }, 6000); }); describe('actions', function () { - var fakeLoad, fakeNPMCommands; + var fakeLoad; // eslint-disable-line no-unused-vars + var fakeNPMCommands; beforeEach(function () { done = false; @@ -123,21 +124,5 @@ describe('registry', function () { npm.config.get = function () {}; npm.config.del = function () {}; }); - it('Test 005 : should run config', function (done) { - var params = ['set', 'registry', 'http://registry.cordova.io']; - return registryPromise(true, registry.config(params).then(function () { - expect(fakeLoad).toHaveBeenCalledWith(jasmine.any(Object), jasmine.any(Function)); - expect(fakeNPMCommands.config).toHaveBeenCalledWith(params, jasmine.any(Function)); - done(); - })); - }, 6000); - it('Test 006 : should run search', function (done) { - var params = ['dummyplugin', 'plugin']; - return registryPromise(true, registry.search(params).then(function () { - expect(fakeLoad).toHaveBeenCalledWith(jasmine.any(Object), jasmine.any(Function)); - expect(fakeNPMCommands.search).toHaveBeenCalledWith(params, true, jasmine.any(Function)); - done(); - })); - }, 6000); }); }); diff --git a/spec/plugman/search.spec.js b/spec/plugman/search.spec.js deleted file mode 100644 index 2ce243174..000000000 --- a/spec/plugman/search.spec.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ -var search = require('../../src/plugman/search'); -var Q = require('q'); -var registry = require('../../src/plugman/registry/registry'); - -describe('search', function () { - it('Test 001 : should search a plugin', function () { - var sSearch = spyOn(registry, 'search').and.returnValue(Q()); - search(new Array('myplugin', 'keyword')); // eslint-disable-line no-array-constructor - expect(sSearch).toHaveBeenCalledWith(['myplugin', 'keyword']); - }); -}); diff --git a/src/cordova/lazy_load.js b/src/cordova/lazy_load.js deleted file mode 100644 index 0bc184075..000000000 --- a/src/cordova/lazy_load.js +++ /dev/null @@ -1,289 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ - -var path = require('path'); -var _ = require('underscore'); -var fs = require('fs'); -var shell = require('shelljs'); -var platforms = require('../platforms/platforms'); -var events = require('cordova-common').events; -var request = require('request'); -var config = require('./config'); -var HooksRunner = require('../hooks/HooksRunner'); -var zlib = require('zlib'); -var tar = require('tar'); -var URL = require('url'); -var Q = require('q'); -var npm = require('npm'); -var npmhelper = require('../util/npm-helper'); -var util = require('./util'); -var gitclone = require('../gitclone'); -var stubplatform = { - url: undefined, - version: undefined, - altplatform: undefined, - subdirectory: '' -}; - -exports.cordova = cordova; -exports.cordova_git = cordova_git; -exports.git_clone = git_clone_platform; -exports.cordova_npm = cordova_npm; -exports.custom = custom; -exports.based_on_config = based_on_config; - -function Platform (platformString) { - var name, - platform, - parts, - version; - if (platformString.indexOf('@') !== -1) { - parts = platformString.split('@'); - name = parts[0]; - version = parts[1]; - } else { - name = platformString; - } - platform = _.extend({}, platforms[name]); - this.name = name; - this.version = version || platform.version; - this.packageName = 'cordova-' + name; - this.source = 'source' in platform ? platform.source : 'npm'; -} - -// Returns a promise for the path to the lazy-loaded directory. -function based_on_config (project_root, platform, opts) { - var custom_path = config.has_custom_path(project_root, platform); - if (custom_path) { - var dot_file = config.read(project_root); - var mixed_platforms = _.extend({}, platforms); - mixed_platforms[platform] = _.extend(({}, mixed_platforms[platform], dot_file.lib && dot_file.lib[platform])) || ({}); - return module.exports.custom(mixed_platforms, platform); - } else { - return module.exports.cordova(platform, opts); - } -} - -// Returns a promise for the path to the lazy-loaded directory. -function cordova (platform, opts) { - platform = new Platform(platform); - var use_git = platform.source === 'git'; - if (use_git) { - return module.exports.cordova_git(platform); - } else { - return module.exports.cordova_npm(platform); - } -} - -function cordova_git (platform) { - var mixed_platforms = _.extend({}, platforms); - var plat; - if (!(platform.name in platforms)) { - return Q.reject(new Error('Cordova library "' + platform.name + '" not recognized.')); - } - plat = mixed_platforms[platform.name]; - plat.id = 'cordova'; - - // We can't use a version range when getting from git, so if we have a range, find the latest release on npm that matches. - return util.getLatestMatchingNpmVersion(platform.packageName, platform.version).then(function (version) { - plat.version = version; - if (/^...*:/.test(plat.url)) { - plat.url = plat.url + ';a=snapshot;h=' + version + ';sf=tgz'; - } - return module.exports.custom(mixed_platforms, platform.name); - }); -} - -function cordova_npm (platform) { - if (!(platform.name in platforms)) { - return Q.reject(new Error('Cordova library "' + platform.name + '" not recognized.')); - } - // Check if this version was already downloaded from git, if yes, use that copy. - // TODO: remove this once we fully switch to npm workflow. - var platdir = platforms[platform.name].altplatform || platform.name; - // If platform.version specifies a *range*, we need to determine what version we'll actually get from npm (the - // latest version that matches the range) to know what local directory to look for. - return util.getLatestMatchingNpmVersion(platform.packageName, platform.version).then(function (version) { - var git_dload_dir = path.join(util.libDirectory, platdir, 'cordova', version); - if (fs.existsSync(git_dload_dir)) { - var subdir = platforms[platform.name].subdirectory; - if (subdir) { - git_dload_dir = path.join(git_dload_dir, subdir); - } - events.emit('verbose', 'Platform files for "' + platform.name + '" previously downloaded not from npm. Using that copy.'); - return Q(git_dload_dir); - } - - // Note that because the version of npm we use internally doesn't support caret versions, in order to allow them - // from the command line and in config.xml, we use the actual version returned by getLatestMatchingNpmVersion(). - return npmhelper.cachePackage(platform.packageName, version); - }); -} - -// Returns a promise for the path to the lazy-loaded directory. -function custom (platforms, platform) { - var plat; - var id; - var uri; - var url; - var version; - var subdir; - var platdir; - var download_dir; - var tmp_dir; - var lib_dir; - var isUri; - if (!(platform in platforms)) { - return Q.reject(new Error('Cordova library "' + platform + '" not recognized.')); - } - - plat = _.extend({}, stubplatform, platforms[platform]); - version = plat.version; - // Older tools can still provide uri (as opposed to url) as part of extra - // config to create, it should override the default url provided in - // platfroms.js - url = plat.uri || plat.url; - id = plat.id; - subdir = plat.subdirectory; - platdir = plat.altplatform || platform; - // Return early for already-cached remote URL, or for local URLs. - uri = URL.parse(url); - isUri = uri.protocol && uri.protocol[1] !== ':'; // second part of conditional is for awesome windows support. fuuu windows - if (isUri) { - download_dir = path.join(util.libDirectory, platdir, id, version); - lib_dir = path.join(download_dir, subdir); - if (fs.existsSync(download_dir)) { - events.emit('verbose', id + ' library for "' + platform + '" already exists. No need to download. Continuing.'); - return Q(lib_dir); - } - } else { - // Local path. - lib_dir = path.join(url, subdir); - return Q(lib_dir); - } - - return HooksRunner.fire('before_library_download', { - platform: platform, - url: url, - id: id, - version: version - }).then(function () { - var uri = URL.parse(url); - var d = Q.defer(); - npm.load(function (err) { // eslint-disable-line handle-callback-err - // Check if NPM proxy settings are set. If so, include them in the request() call. - var proxy; - if (uri.protocol === 'https:') { - proxy = npm.config.get('https-proxy'); - } else if (uri.protocol === 'http:') { - proxy = npm.config.get('proxy'); - } - var strictSSL = npm.config.get('strict-ssl'); - - // Create a tmp dir. Using /tmp is a problem because it's often on a different partition and sehll.mv() - // fails in this case with "EXDEV, cross-device link not permitted". - var tmp_subidr = 'tmp_' + id + '_' + process.pid + '_' + (new Date()).valueOf(); - tmp_dir = path.join(util.libDirectory, 'tmp', tmp_subidr); - shell.rm('-rf', tmp_dir); - shell.mkdir('-p', tmp_dir); - - var size = 0; - var request_options = {url: url}; - if (proxy) { - request_options.proxy = proxy; - } - if (typeof strictSSL === 'boolean') { - request_options.strictSSL = strictSSL; - } - events.emit('verbose', 'Requesting ' + JSON.stringify(request_options) + '...'); - events.emit('log', 'Downloading ' + id + ' library for ' + platform + '...'); - var req = request.get(request_options, function (err, res, body) { - if (err) { - shell.rm('-rf', tmp_dir); - d.reject(err); - } else if (res.statusCode !== 200) { - shell.rm('-rf', tmp_dir); - d.reject(new Error('HTTP error ' + res.statusCode + ' retrieving version ' + version + ' of ' + id + ' for ' + platform)); - } else { - size = body.length; - } - }); - req.pipe(zlib.createUnzip()) - .on('error', function (err) { // eslint-disable-line handle-callback-err - // Sometimes if the URL is bad (most likely unavailable version), and git-wip-us.apache.org is - // particularly slow at responding, we hit an error because of bad data piped to zlib.createUnzip() - // before we hit the request.get() callback above (with a 404 error). Handle that gracefully. It is - // likely that we will end up calling d.reject() for an HTTP error in the request() callback above, but - // in case not, reject with a useful error here. - d.reject(new Error('Unable to fetch platform ' + platform + '@' + version + ': Error: version not found.')); - }) - .pipe(tar.Extract({path: tmp_dir})) - .on('error', function (err) { - shell.rm('-rf', tmp_dir); - d.reject(err); - }) - .on('end', function () { - events.emit('verbose', 'Downloaded, unzipped and extracted ' + size + ' byte response.'); - events.emit('log', 'Download complete'); - var entries = fs.readdirSync(tmp_dir); - var entry = path.join(tmp_dir, entries[0]); - shell.mkdir('-p', download_dir); - shell.mv('-f', path.join(entry, '*'), download_dir); - shell.rm('-rf', tmp_dir); - d.resolve(HooksRunner.fire('after_library_download', { - platform: platform, - url: url, - id: id, - version: version, - path: lib_dir, - size: size, - symlink: false - })); - }); - }); - return d.promise.then(function () { return lib_dir; }); - }); -} - -// Returns a promise -function git_clone_platform (git_url, branch) { - // Create a tmp dir. Using /tmp is a problem because it's often on a different partition and sehll.mv() - // fails in this case with "EXDEV, cross-device link not permitted". - var tmp_subidr = 'tmp_cordova_git_' + process.pid + '_' + (new Date()).valueOf(); - var tmp_dir = path.join(util.libDirectory, 'tmp', tmp_subidr); - shell.rm('-rf', tmp_dir); - shell.mkdir('-p', tmp_dir); - - return HooksRunner.fire('before_platform_clone', { - repository: git_url, - location: tmp_dir - }).then(function () { - var branchToCheckout = branch || 'master'; - return gitclone.clone(git_url, branchToCheckout, tmp_dir); - }).then(function () { - HooksRunner.fire('after_platform_clone', { - repository: git_url, - location: tmp_dir - }); - return tmp_dir; - }).fail(function (err) { - shell.rm('-rf', tmp_dir); - return Q.reject(err); - }); -} diff --git a/src/cordova/platform/addHelper.js b/src/cordova/platform/addHelper.js index b6a9e0272..2b3ce97bc 100644 --- a/src/cordova/platform/addHelper.js +++ b/src/cordova/platform/addHelper.js @@ -31,7 +31,6 @@ var cordova_util = require('../util'); // var prepare = require('../prepare'); var promiseutil = require('../../util/promise-util'); var config = require('../config'); -var lazy_load = require('../lazy_load'); var platformMetadata = require('../platform_metadata'); var platforms = require('../../platforms/platforms'); var detectIndent = require('detect-indent'); @@ -313,22 +312,6 @@ function downloadPlatform (projectRoot, platform, version, opts) { events.emit('log', 'Using cordova-fetch for ' + target); return fetch(target, projectRoot, opts); } - - if (cordova_util.isUrl(version)) { - events.emit('log', 'git cloning: ' + version); - var parts = version.split('#'); - var git_url = parts[0]; - var branchToCheckout = parts[1]; - return lazy_load.git_clone(git_url, branchToCheckout).fail(function (err) { - // If it looks like a url, but cannot be cloned, try handling it differently. - // it's because it's a tarball of the form: - // - https://api.github.com/repos/msopenTech/cordova-browser/tarball/my-branch - events.emit('verbose', err.message); - events.emit('verbose', 'Cloning failed. Let\'s try handling it as a tarball'); - return lazy_load.based_on_config(projectRoot, target, opts); - }); - } - return lazy_load.based_on_config(projectRoot, target, opts); }).fail(function (error) { var message = 'Failed to fetch platform ' + target + '\nProbably this is either a connection problem, or platform spec is incorrect.' + diff --git a/src/cordova/plugin/add.js b/src/cordova/plugin/add.js index dd6058b76..bf86d1fce 100644 --- a/src/cordova/plugin/add.js +++ b/src/cordova/plugin/add.js @@ -287,7 +287,7 @@ function determinePluginTarget (projectRoot, cfg, target, fetchOptions) { } // if noregistry or searchpath are true, then shouldUseNpmInfo is false. Just return target // else run `npm info` on the target via registry.info so we could get engines elemenent in package.json. Pass that info to getFetchVersion which determines the correct plugin to fetch based on engines element. - return (shouldUseNpmInfo ? registry.info([id]) + return (shouldUseNpmInfo ? registry.info([id], projectRoot, fetchOptions) .then(function (pluginInfo) { return module.exports.getFetchVersion(projectRoot, pluginInfo, cordovaVersion); }) : Q(null)) diff --git a/src/cordova/remote_load.js b/src/cordova/remote_load.js deleted file mode 100644 index c6b72d6c3..000000000 --- a/src/cordova/remote_load.js +++ /dev/null @@ -1,78 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ - -var path = require('path'); -var shell = require('shelljs'); -var Q = require('q'); -var npmHelper = require('../util/npm-helper'); -var util = require('./util'); -var git = require('../gitclone'); - -/* -Fetches the latests version of a package from NPM. A promise is returned that -resolves to the directory the NPM package is located in. Package options must be -passed containing a packageName, name, and version. - -options - Package options - */ -function npmFetch (packageName, packageVersion) { - return npmHelper.fetchPackage(packageName, packageVersion); -} - -/* -Performs a Git clone an a Git URL, and branch. If the clone was successful, -the path to the cloned directory will be returned. Otherwise, a error is -returned. A gitURL, must be passed, and a branch to checkout at is optionally -passed. - -gitURL - URL to Git repository -branch - Branch to checkout at - */ -function gitClone (gitURL, branch) { - var cloneCallback; // Resultant callback - var tmpSubDir; // Temporary sub-directory - var tmpDir; // Temporary directory - var checkoutBranch; // Branch to checkout - - checkoutBranch = branch || 'master'; - tmpSubDir = 'tmp_cordova_git_' + process.pid + '_' + (new Date()).valueOf(); - tmpDir = path.join(util.libDirectory, 'tmp', tmpSubDir); - - shell.rm('-rf', tmpDir); - shell.mkdir('-p', tmpDir); - - cloneCallback = git.clone(gitURL, checkoutBranch, tmpDir); - - // Callback for Git clone - cloneCallback.then( - function () { - return tmpDir; - }, - function (err) { - shell.rm('-rf', tmpDir); - - return Q.reject(err); - } - ); - - return cloneCallback; -} - -exports.gitClone = gitClone; -exports.npmFetch = npmFetch; diff --git a/src/gitclone.js b/src/gitclone.js deleted file mode 100644 index 9aa2fc4b3..000000000 --- a/src/gitclone.js +++ /dev/null @@ -1,68 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ - -var Q = require('q'); -var shell = require('shelljs'); -var events = require('cordova-common').events; -var path = require('path'); -var superspawn = require('cordova-common').superspawn; -var os = require('os'); - -exports.clone = clone; - -// clone_dir, if provided is the directory that git will clone into. -// if no clone_dir is supplied, a temp directory will be created and used by git. -function clone (git_url, git_ref, clone_dir) { - - var needsGitCheckout = !!git_ref; - if (!shell.which('git')) { - return Q.reject(new Error('"git" command line tool is not installed: make sure it is accessible on your PATH.')); - } - - // If no clone_dir is specified, create a tmp dir which git will clone into. - var tmp_dir = clone_dir; - if (!tmp_dir) { - tmp_dir = path.join(os.tmpdir(), 'git', String((new Date()).valueOf())); - } - shell.rm('-rf', tmp_dir); - shell.mkdir('-p', tmp_dir); - - var cloneArgs = ['clone']; - if (!needsGitCheckout) { - // only get depth of 1 if there is no branch/commit specified - cloneArgs.push('--depth=1'); - } - cloneArgs.push(git_url, tmp_dir); - return superspawn.spawn('git', cloneArgs) - .then(function () { - if (needsGitCheckout) { - return superspawn.spawn('git', ['checkout', git_ref], { - cwd: tmp_dir - }); - } - }) - .then(function () { - events.emit('log', 'Repository "' + git_url + '" checked out to git ref "' + (git_ref || 'master') + '".'); - return tmp_dir; - }) - .fail(function (err) { - shell.rm('-rf', tmp_dir); - return Q.reject(err); - }); -} diff --git a/src/plugman/fetch.js b/src/plugman/fetch.js index 731509fba..fa10e413f 100644 --- a/src/plugman/fetch.js +++ b/src/plugman/fetch.js @@ -23,13 +23,11 @@ var url = require('url'); var underscore = require('underscore'); var semver = require('semver'); var PluginInfoProvider = require('cordova-common').PluginInfoProvider; -var plugins = require('./util/plugins'); var CordovaError = require('cordova-common').CordovaError; var events = require('cordova-common').events; var metadata = require('./util/metadata'); var path = require('path'); var Q = require('q'); -var registry = require('./registry/registry'); var pluginSpec = require('../cordova/plugin/plugin_spec_parser'); var fetch = require('cordova-fetch'); var cordovaUtil = require('../cordova/util'); @@ -85,33 +83,6 @@ function fetchPlugin (plugin_src, plugins_dir, options) { } } return Q.when().then(function () { - // If it looks like a network URL, git clone it - // skip git cloning if user passed in --fetch flag - if (uri.protocol && uri.protocol !== 'file:' && uri.protocol[1] !== ':' && !plugin_src.match(/^\w+:\\/) && !options.fetch) { - events.emit('log', 'Fetching plugin "' + plugin_src + '" via git clone'); - if (options.link) { - events.emit('log', '--link is not supported for git URLs and will be ignored'); - } - - return plugins.clonePluginGit(plugin_src, plugins_dir, options) - .fail(function (error) { - var message = 'Failed to fetch plugin ' + plugin_src + ' via git.' + - '\nEither there is a connection problems, or plugin spec is incorrect:\n\t' + error; - return Q.reject(new CordovaError(message)); - }) - .then(function (dir) { - return { - pinfo: pluginInfoProvider.get(dir), - dest: dir, - fetchJsonSource: { - type: 'git', - url: plugin_src, - subdir: options.subdir, - ref: options.git_ref - } - }; - }); - } // If it's not a network URL, it's either a local path or a plugin ID. var plugin_dir = cordovaUtil.fixRelativePath(path.join(plugin_src, options.subdir)); return Q.when().then(function () { @@ -141,18 +112,8 @@ function fetchPlugin (plugin_src, plugins_dir, options) { // something went wrong with cordova-fetch return Q.reject(new CordovaError(error.message)); }); - } else { - // nofetch - return { - pinfo: pluginInfoProvider.get(plugin_dir), - fetchJsonSource: { - type: 'local', - path: plugin_dir - } - }; } } - // If there is no such local path, it's a plugin id or id@versionspec. // First look for it in the local search path (if provided). var pinfo = findLocalPlugin(plugin_src, options.searchpath, pluginInfoProvider); @@ -201,8 +162,6 @@ function fetchPlugin (plugin_src, plugins_dir, options) { var fetchPluginSrc = specContainsSpecialCharacters ? parsedSpec.package + '@"' + parsedSpec.version + '"' : plugin_src; P = fetch(fetchPluginSrc, projectRoot, options); - } else { - P = registry.fetch([plugin_src]); } skipCopyingPlugin = false; } diff --git a/src/plugman/init-defaults.js b/src/plugman/init-defaults.js index 9c80f40b6..fbe4e9233 100644 --- a/src/plugman/init-defaults.js +++ b/src/plugman/init-defaults.js @@ -138,14 +138,14 @@ if (!package.engines) { if (!package.author) { exports.author = (config.get('init.author.name') || config.get('init-author-name')) ? - { - 'name': config.get('init.author.name') || - config.get('init-author-name'), - 'email': config.get('init.author.email') || - config.get('init-author-email'), - 'url': config.get('init.author.url') || - config.get('init-author-url') - } + { + 'name': config.get('init.author.name') || + config.get('init-author-name'), + 'email': config.get('init.author.email') || + config.get('init-author-email'), + 'url': config.get('init.author.url') || + config.get('init-author-url') + } : prompt('author'); } var license = package.license || diff --git a/src/plugman/registry/registry.js b/src/plugman/registry/registry.js index 723c0546d..1c86b2f61 100644 --- a/src/plugman/registry/registry.js +++ b/src/plugman/registry/registry.js @@ -17,107 +17,34 @@ under the License. */ -var npm = require('npm'); -var Q = require('q'); -var npmhelper = require('../../util/npm-helper'); -var events = require('cordova-common').events; -var pluginSpec = require('../../cordova/plugin/plugin_spec_parser'); +var fetch = require('cordova-fetch'); +var superspawn = require('cordova-common').superspawn; module.exports = { settings: null, - /** - * @method config - * @param {Array} args Command argument - * @return {Promise.} Promised configuration object. - */ - config: function (args) { - return initThenLoadSettingsWithRestore(function () { - return Q.ninvoke(npm.commands, 'config', args); - }); - }, - - /** - * @method owner - * @param {Array} args Command argument - * @return {Promise.} Promise for completion. - */ - owner: function (args) { - var command = args && args[0]; - if (command && (command === 'add' || command === 'rm')) { - return Q.reject('Support for \'owner add/rm\' commands has been removed ' + - 'due to transition of Cordova plugins registry to read-only state'); - } - - return initThenLoadSettingsWithRestore(function () { - return Q.ninvoke(npm.commands, 'owner', args); - }); - }, - - /** - * @method search - * @param {Array} args Array of keywords - * @return {Promise.} Promised search results. - */ - search: function (args) { - return initThenLoadSettingsWithRestore(function () { - return Q.ninvoke(npm.commands, 'search', args, true); - }); - }, - - /** - * @method fetch - * @param {Array} with one element - the plugin id or "id@version" - * @return {Promise.} Promised path to fetched package. - */ - fetch: function (plugin) { - plugin = plugin.shift(); - return Q.fcall(function () { - // fetch from npm - return fetchPlugin(plugin); - }).fail(function (error) { - return Q.reject(error); - }); - }, /** * @method info * @param {String} name Plugin name * @return {Promise.} Promised package info. */ - info: function (plugin) { + info: function (plugin, dest, opts) { + opts = opts || {}; + var fetchArgs = opts.link ? ['link'] : ['install']; plugin = plugin.shift(); - return npmhelper.loadWithSettingsThenRestore({ - 'cache-min': 0, - 'cache-max': 0 - }, function () { - return Q.ninvoke(npm.commands, 'view', [plugin], /* silent = */ true) - .then(function (info) { - // Plugin info should be accessed as info[version]. If a version - // specifier like >=x.y.z was used when calling npm view, info - // can contain several versions, but we take the first one here. - var version = Object.keys(info)[0]; - return info[version]; - }); - }); + // set the directory where npm install will be run + opts.cwd = dest; + // check if npm is installed + return fetch.isNpmInstalled() + .then(function () { + return superspawn.spawn('npm', fetchArgs, opts) + .then(function (info) { + // Plugin info should be accessed as info[version]. If a version + // specifier like >=x.y.z was used when calling npm view, info + // can contain several versions, but we take the first one here. + var version = Object.keys(info)[0]; + return info[version]; + }); + }); } }; - -/** - * @description Calls npmhelper.loadWithSettingsThenRestore, which initializes npm.config with - * settings, executes the promises, then restores npm.config. Use this rather than passing settings to npm.load, since - * that only works the first time you try to load npm. - */ -function initThenLoadSettingsWithRestore (promises) { - return npmhelper.loadWithSettingsThenRestore({}, promises); -} - -/** -* @param {string} plugin - the plugin id or "id@version" -* @return {Promise.} Promised path to fetched package. -*/ -function fetchPlugin (plugin) { - events.emit('log', 'Fetching plugin "' + plugin + '" via npm'); - var parsedSpec = pluginSpec.parse(plugin); - var scope = parsedSpec.scope || ''; - return npmhelper.fetchPackage(scope + parsedSpec.id, parsedSpec.version); -} diff --git a/src/plugman/util/plugins.js b/src/plugman/util/plugins.js deleted file mode 100644 index 72409ee72..000000000 --- a/src/plugman/util/plugins.js +++ /dev/null @@ -1,71 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ - -var path = require('path'); -var shell = require('shelljs'); -var events = require('cordova-common').events; -var gitclone = require('../../gitclone'); -var tmp_dir; - -var PluginInfo = require('cordova-common').PluginInfo; - -module.exports = { - searchAndReplace: require('./search-and-replace'), - - clonePluginGit: function (plugin_git_url, plugins_dir, options) { - return module.exports.clonePluginGitRepo(plugin_git_url, plugins_dir, options.subdir, options.git_ref, options.pluginInfoProvider).then( - function (dst) { - // Keep location where we checked out git repo - options.plugin_src_dir = tmp_dir; - return dst; - } - ); - }, - - clonePluginGitRepo: function (plugin_git_url, plugins_dir, subdir, git_ref, pluginInfoProvider) { - return gitclone.clone(plugin_git_url, git_ref).then(function (tmp_dir) { - // Read the plugin.xml file and extract the plugin's ID. - tmp_dir = path.join(tmp_dir, subdir); - var pluginInfo = new PluginInfo(tmp_dir); - var plugin_id = pluginInfo.id; - - // TODO: what if a plugin depended on different subdirectories of the same plugin? this would fail. - // should probably copy over entire plugin git repo contents into plugins_dir and handle subdir separately during install. - var plugin_dir = path.join(plugins_dir, plugin_id); - events.emit('verbose', 'Copying fetched plugin over "' + plugin_dir + '"...'); - shell.mkdir('-p', plugin_dir); - - // use cp instead of mv, as it would fail if tmp_dir is mounted - // on a different device from the plugin_dir - shell.cp('-R', path.join(tmp_dir, '*'), plugin_dir); - - // the tmp_dir is cleaned after copy - shell.rm('-Rf', tmp_dir); - - pluginInfo.dir = plugin_dir; - if (pluginInfoProvider) { - pluginInfoProvider.put(pluginInfo); - } - - events.emit('verbose', 'Plugin "' + plugin_id + '" fetched.'); - process.env.CORDOVA_PLUGIN_ID = plugin_id; - return plugin_dir; - }); - } -}; From 62f7c6405415ad78f292b82c4052042b7681bbda Mon Sep 17 00:00:00 2001 From: Audrey So Date: Tue, 28 Nov 2017 11:10:38 -0800 Subject: [PATCH 2/5] CB-13055 : added info to plugin util file and rm registry and updated tests --- integration-tests/pkgJson-restore.spec.js | 50 ++-- integration-tests/plugin.spec.js | 28 +-- integration-tests/plugman_fetch.spec.js | 2 +- package.json | 1 + spec/cordova/fixtures/basePkgJson4/config.xml | 2 +- .../fixtures/basePkgJson4/package.json | 4 +- spec/cordova/plugin/add.spec.js | 11 +- spec/plugman/info.spec.js | 33 --- spec/plugman/registry/registry.spec.js | 128 ---------- src/cordova/plugin/add.js | 3 +- src/cordova/plugin/util.js | 19 ++ src/plugman/config.js | 24 -- src/plugman/info.js | 25 -- src/plugman/owner.js | 25 -- src/plugman/plugman.js | 4 - src/plugman/registry/registry.js | 50 ---- src/plugman/search.js | 24 -- src/util/npm-helper.js | 230 +++++++++--------- 18 files changed, 184 insertions(+), 479 deletions(-) delete mode 100644 spec/plugman/info.spec.js delete mode 100644 spec/plugman/registry/registry.spec.js delete mode 100644 src/plugman/config.js delete mode 100644 src/plugman/info.js delete mode 100644 src/plugman/owner.js delete mode 100644 src/plugman/registry/registry.js delete mode 100644 src/plugman/search.js diff --git a/integration-tests/pkgJson-restore.spec.js b/integration-tests/pkgJson-restore.spec.js index d2dff15da..1122028b5 100644 --- a/integration-tests/pkgJson-restore.spec.js +++ b/integration-tests/pkgJson-restore.spec.js @@ -316,7 +316,7 @@ describe('tests platform/spec restore with --save', function () { return cordovaPlatform('list').then(function () { var installed = results.match(/Installed platforms:\n {2}(.*)/); expect(installed).toBeDefined(); - expect(installed[1].indexOf(helpers.testPlatform)).toBeGreaterThan(-1); + expect(installed[1].indexOf(helpers.testPlatform)).toBe(-1); }); } /** Test#003 will add two platforms to package.json - one with the 'save' flag and one @@ -329,7 +329,7 @@ describe('tests platform/spec restore with --save', function () { var pkgJsonPath = path.join(cwd, 'package.json'); var pkgJson; var platformsFolderPath = path.join(cwd, 'platforms/platforms.json'); - var secondPlatformAdded = 'browser'; + var secondPlatformAdded = 'ios'; var platformsJson; emptyPlatformList().then(function () { @@ -337,22 +337,22 @@ describe('tests platform/spec restore with --save', function () { return cordovaPlatform('add', secondPlatformAdded, {'fetch': true}); }).then(function () { // Add helpers.testPlatform to project with --save - return cordovaPlatform('add', [helpers.testPlatform], {'save': true, 'fetch': true}); + return cordovaPlatform('add', ['browser'], {'save': true, 'fetch': true}); }).then(function () { // Delete any previous caches of require(package.json) and (platformsJson) pkgJson = cordova_util.requireNoCache(pkgJsonPath); platformsJson = cordova_util.requireNoCache(platformsFolderPath); // Check the platform add of only helpers.testPlatform was successful in package.json. expect(pkgJson.cordova.platforms).toBeDefined(); - expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1); + expect(pkgJson.cordova.platforms.indexOf('browser')).toBeGreaterThan(-1); expect(pkgJson.cordova.platforms.indexOf(secondPlatformAdded)).toEqual(-1); // Expect both platforms to be installed platform list in platforms.json - expect(platformsJson[helpers.testPlatform]).toBeDefined(); + expect(platformsJson['browser']).toBeDefined(); expect(platformsJson[secondPlatformAdded]).toBeDefined(); }).then(fullPlatformList) // Platforms should still be in platform ls. .then(function () { // Remove helpers.testPlatform without --save. - return cordovaPlatform('rm', [helpers.testPlatform]); + return cordovaPlatform('rm', ['browser']); }).then(function () { // Remove secondPlatformAdded without --save. return cordovaPlatform('rm', secondPlatformAdded); @@ -361,10 +361,10 @@ describe('tests platform/spec restore with --save', function () { platformsJson = cordova_util.requireNoCache(platformsFolderPath); pkgJson = cordova_util.requireNoCache(pkgJsonPath); // Check that the platform that was added with --save is still in package.json. - expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1); + expect(pkgJson.cordova.platforms.indexOf('browser')).toBeGreaterThan(-1); // Check that both platforms were removed from the platforms.json. expect(platformsJson[secondPlatformAdded]).toBeUndefined(); - expect(platformsJson[helpers.testPlatform]).toBeUndefined(); + expect(platformsJson['browser']).toBeUndefined(); }).then(function () { // Run cordova prepare return prepare({'fetch': true}); @@ -372,7 +372,7 @@ describe('tests platform/spec restore with --save', function () { // Delete any previous caches of platformsJson platformsJson = cordova_util.requireNoCache(platformsFolderPath); // Expect "helpers.testPlatform" to be in the installed platforms list. - expect(platformsJson[helpers.testPlatform]).toBeDefined(); + expect(platformsJson['browser']).toBeDefined(); // Expect that 'browser' will not be in platforms.json and has not been restored. expect(platformsJson[secondPlatformAdded]).toBeUndefined(); }).fail(function (err) { @@ -489,7 +489,7 @@ describe('update pkg.json to include platforms in config.xml', function () { * is updated with the correct spec/dependencies when restored. Checks that specs are * added properly, too. */ - it('Test#005 : if config.xml has android & browser platforms and pkg.json has android, update pkg.json to also include browser with spec', function (done) { + xit('Test#005 : if config.xml has android & browser platforms and pkg.json has android, update pkg.json to also include browser with spec', function (done) { var cwd = process.cwd(); var configXmlPath = path.join(cwd, 'config.xml'); var cfg = new ConfigParser(configXmlPath); @@ -650,7 +650,7 @@ describe('update config.xml to include platforms in pkg.json', function () { * and config.xml is updated to include 'browser'. Also, if there is a specified spec in pkg.json, * it should be added to config.xml during restore. */ - it('Test#007 : if pkgJson has android & browser platforms and config.xml has android, update config to also include browser and spec', function (done) { + xit('Test#007 : if pkgJson has android & browser platforms and config.xml has android, update config to also include browser and spec', function (done) { var cwd = process.cwd(); var configXmlPath = path.join(cwd, 'config.xml'); var cfg1 = new ConfigParser(configXmlPath); @@ -664,11 +664,11 @@ describe('update config.xml to include platforms in pkg.json', function () { var configEngArray = engNames.slice(); // Expect that config.xml contains only android at this point (basePjgJson4) - expect(configEngArray.indexOf('android')).toBeGreaterThan(-1); + expect(configEngArray.indexOf('ios')).toBeGreaterThan(-1); expect(configEngArray.indexOf('browser')).toEqual(-1); expect(configEngArray.length === 1); // Pkg.json has cordova-browser in its dependencies. - expect(pkgJson.dependencies).toEqual({ 'cordova-android': '^5.0.0', 'cordova-browser': '^4.1.0' }); + expect(pkgJson.dependencies).toEqual({ 'cordova-ios': '^4.5.4', 'cordova-browser': '^4.1.0' }); emptyPlatformList().then(function () { // Run cordova prepare. return prepare({ 'fetch': true }); @@ -684,14 +684,14 @@ describe('update config.xml to include platforms in pkg.json', function () { // Expect 'browser' to be added to config.xml. expect(configEngArray.indexOf('browser')).toBeGreaterThan(-1); // Expect 'android' to still be in config.xml. - expect(configEngArray.indexOf('android')).toBeGreaterThan(-1); + expect(configEngArray.indexOf('ios')).toBeGreaterThan(-1); // Expect config.xml array to have 2 elements (platforms). expect(configEngArray.length === 2); // Check to make sure that 'browser' spec was added properly. - expect(engines).toEqual([ { name: 'android', spec: '^5.0.0' }, { name: 'browser', spec: '^4.1.0' } ]); + expect(engines).toEqual([ { name: 'ios', spec: '^4.5.4' }, { name: 'browser', spec: '^4.1.0' } ]); // No change to pkg.json dependencies. - expect(pkgJson.dependencies).toEqual({ 'cordova-android': '^5.0.0', 'cordova-browser': '^4.1.0' }); - expect(pkgJson.dependencies['cordova-android']).toEqual('^5.0.0'); + expect(pkgJson.dependencies).toEqual({ 'cordova-ios': '^4.5.4', 'cordova-browser': '^4.1.0' }); + expect(pkgJson.dependencies['cordova-ios']).toEqual('^4.5.4'); expect(pkgJson.dependencies['cordova-browser']).toEqual('^4.1.0'); }).fail(function (err) { expect(err).toBeUndefined(); @@ -1441,29 +1441,29 @@ describe('tests platform/spec restore with --save', function () { emptyPlatformList().then(function () { // Add the testing platform with --save. - return cordovaPlatform('add', 'android', {'save': true, 'fetch': true}); + return cordovaPlatform('add', 'browser', {'save': true, 'fetch': true}); }).then(function () { pkgJson = cordova_util.requireNoCache(pkgJsonPath); // Require platformsFolderPath platformsJson = cordova_util.requireNoCache(platformsFolderPath); // Check the platform add was successful in package.json. expect(pkgJson.cordova.platforms).toBeDefined(); - expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1); + expect(pkgJson.cordova.platforms.indexOf('browser')).toBeGreaterThan(-1); // Expect that "helpers.testPlatform" in the installed platform list in platforms.json expect(platformsJson).toBeDefined(); - expect(platformsJson[helpers.testPlatform]).toBeDefined(); - }).then(fullPlatformList) // Platform should still be in platform ls. + expect(platformsJson['browser']).toBeDefined(); + }).then() // Platform should still be in platform ls. .then(function () { // And now remove helpers.testPlatform without --save. - return cordovaPlatform('rm', [helpers.testPlatform]); + return cordovaPlatform('rm', ['browser']); }).then(function () { // Delete any previous caches of require(package.json) and (platforms.json) platformsJson = cordova_util.requireNoCache(platformsFolderPath); pkgJson = cordova_util.requireNoCache(pkgJsonPath); // Check that the platform removed without --save is still in platforms key. - expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1); + expect(pkgJson.cordova.platforms.indexOf('browser')).toBeGreaterThan(-1); // Check that the platform was removed from the platforms.json - expect(platformsJson[helpers.testPlatform]).toBeUndefined(); + expect(platformsJson['browser']).toBeUndefined(); }).then(function () { // Run cordova prepare. return prepare({'fetch': true}); @@ -1471,7 +1471,7 @@ describe('tests platform/spec restore with --save', function () { // Delete any previous caches of platforms.json. platformsJson = cordova_util.requireNoCache(platformsFolderPath); // Expect "helpers.testPlatform" to be in the installed platforms list in platforms.json. - expect(platformsJson[helpers.testPlatform]).toBeDefined(); + expect(platformsJson['browser']).toBeDefined(); }).fail(function (err) { expect(err).toBeUndefined(); }).fin(done); diff --git a/integration-tests/plugin.spec.js b/integration-tests/plugin.spec.js index d70e64d06..380c22b55 100644 --- a/integration-tests/plugin.spec.js +++ b/integration-tests/plugin.spec.js @@ -26,7 +26,7 @@ var cordova = require('../src/cordova/cordova'); var platforms = require('../src/platforms/platforms'); var plugman = require('../src/plugman/plugman'); var install = require('../src/plugman/install'); -var registry = require('../src/plugman/registry/registry'); +var plugin_util = require('../src/cordova/plugin/util'); var util = require('../src/cordova/util'); @@ -199,10 +199,10 @@ describe('plugin end-to-end', function () { it('Test 007 : should not check npm info when using the searchpath flag', function (done) { mockPluginFetch(npmInfoTestPlugin, path.join(pluginsDir, npmInfoTestPlugin)); - spyOn(registry, 'info'); + spyOn(plugin_util, 'info'); return addPlugin(npmInfoTestPlugin, npmInfoTestPlugin, {searchpath: pluginsDir}, done) .then(function () { - expect(registry.info).not.toHaveBeenCalled(); + expect(plugin_util.info).not.toHaveBeenCalled(); var fetchOptions = plugman.fetch.calls.mostRecent().args[2]; expect(fetchOptions.searchpath[0]).toExist(); }) @@ -215,10 +215,10 @@ describe('plugin end-to-end', function () { it('Test 008 : should not check npm info when using the noregistry flag', function (done) { mockPluginFetch(npmInfoTestPlugin, path.join(pluginsDir, npmInfoTestPlugin)); - spyOn(registry, 'info'); + spyOn(plugin_util, 'info'); addPlugin(npmInfoTestPlugin, npmInfoTestPlugin, {noregistry: true}, done) .then(function () { - expect(registry.info).not.toHaveBeenCalled(); + expect(plugin_util.info).not.toHaveBeenCalled(); var fetchOptions = plugman.fetch.calls.mostRecent().args[2]; expect(fetchOptions.noregistry).toBeTruthy(); @@ -230,10 +230,10 @@ describe('plugin end-to-end', function () { }, 30000); it('Test 009 : should not check npm info when fetching from a Git repository', function (done) { - spyOn(registry, 'info'); + spyOn(plugin_util, 'info'); addPlugin(testGitPluginRepository, testGitPluginId, {'fetch': true}, done) .then(function () { - expect(registry.info).not.toHaveBeenCalled(); + expect(plugin_util.info).not.toHaveBeenCalled(); }) .fail(function (err) { expect(err).toBeUndefined(); @@ -244,13 +244,13 @@ describe('plugin end-to-end', function () { it('Test 010 : should use registry.info to get plugin & version', function (done) { mockPluginFetch(npmInfoTestPlugin, path.join(pluginsDir, npmInfoTestPlugin)); - spyOn(registry, 'info').and.callThrough(); + spyOn(plugin_util, 'info').and.callThrough(); addPlugin(npmInfoTestPlugin, npmInfoTestPlugin, {'fetch': true}, done) .then(function () { - expect(registry.info).toHaveBeenCalled(); + expect(plugin_util.info).toHaveBeenCalled(); var fetchTarget = plugman.fetch.calls.mostRecent().args[0]; - expect(fetchTarget).toEqual(npmInfoTestPlugin); + expect(fetchTarget).toEqual(npmInfoTestPlugin + '@' + npmInfoTestPluginVersion); }) .fail(function (err) { expect(err).toBeUndefined(); @@ -262,13 +262,13 @@ describe('plugin end-to-end', function () { var scopedPackage = '@testscope/' + npmInfoTestPlugin; mockPluginFetch(npmInfoTestPlugin, path.join(pluginsDir, npmInfoTestPlugin)); - spyOn(registry, 'info').and.returnValue(Q({})); + spyOn(plugin_util, 'info').and.returnValue(Q({})); addPlugin(scopedPackage, npmInfoTestPlugin, {}, done) .then(function () { // Check to make sure that we are at least trying to get the correct package. // This package is not published to npm, so we can't truly do end-to-end tests - expect(registry.info).toHaveBeenCalledWith([scopedPackage], jasmine.any(String), jasmine.any(Object)); + expect(plugin_util.info).toHaveBeenCalledWith([scopedPackage]); var fetchTarget = plugman.fetch.calls.mostRecent().args[0]; expect(fetchTarget).toEqual(scopedPackage); @@ -283,10 +283,10 @@ describe('plugin end-to-end', function () { var scopedPackage = '@testscope/' + npmInfoTestPlugin + '@latest'; mockPluginFetch(npmInfoTestPlugin, path.join(pluginsDir, npmInfoTestPlugin)); - spyOn(registry, 'info'); + spyOn(plugin_util, 'info'); addPlugin(scopedPackage, npmInfoTestPlugin, {}, done) .then(function () { - expect(registry.info).not.toHaveBeenCalled(); + expect(plugin_util.info).not.toHaveBeenCalled(); var fetchTarget = plugman.fetch.calls.mostRecent().args[0]; expect(fetchTarget).toEqual(scopedPackage); diff --git a/integration-tests/plugman_fetch.spec.js b/integration-tests/plugman_fetch.spec.js index 9c2faf7b2..982c3a650 100644 --- a/integration-tests/plugman_fetch.spec.js +++ b/integration-tests/plugman_fetch.spec.js @@ -151,7 +151,7 @@ describe('fetch', function () { }); }); - describe('fetch recursive error CB-8809', function () { + xdescribe('fetch recursive error CB-8809', function () { var srcDir = path.join(plugins_dir, 'recursivePlug'); var appDir = path.join(plugins_dir, 'recursivePlug', 'demo'); diff --git a/package.json b/package.json index 0cc02f47b..16e6af499 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "cordova-serve": "^2.0.0", "dep-graph": "1.1.0", "detect-indent": "^5.0.0", + "dependency-ls": "^1.1.1", "elementtree": "0.1.6", "glob": "7.1.1", "init-package-json": "^1.2.0", diff --git a/spec/cordova/fixtures/basePkgJson4/config.xml b/spec/cordova/fixtures/basePkgJson4/config.xml index d1141a146..e0d85b5d7 100644 --- a/spec/cordova/fixtures/basePkgJson4/config.xml +++ b/spec/cordova/fixtures/basePkgJson4/config.xml @@ -11,5 +11,5 @@ - + diff --git a/spec/cordova/fixtures/basePkgJson4/package.json b/spec/cordova/fixtures/basePkgJson4/package.json index 5079224ee..34e1155db 100644 --- a/spec/cordova/fixtures/basePkgJson4/package.json +++ b/spec/cordova/fixtures/basePkgJson4/package.json @@ -4,7 +4,7 @@ "description": "", "main": "index.js", "dependencies": { - "cordova-android": "^5.0.0", + "cordova-ios": "^4.5.4", "cordova-browser": "^4.1.0" }, "devDependencies": {}, @@ -15,7 +15,7 @@ "license": "ISC", "cordova": { "platforms": [ - "android", + "ios", "browser" ] } diff --git a/spec/cordova/plugin/add.spec.js b/spec/cordova/plugin/add.spec.js index 5cfd237ec..4164f9c5b 100644 --- a/spec/cordova/plugin/add.spec.js +++ b/spec/cordova/plugin/add.spec.js @@ -29,7 +29,6 @@ var path = require('path'); var fs = require('fs'); var config = require('../../../src/cordova/config'); var events = require('cordova-common').events; -var registry = require('../../../src/plugman/registry/registry'); var plugin_util = require('../../../src/cordova/plugin/util'); describe('cordova/plugin/add', function () { @@ -72,7 +71,7 @@ describe('cordova/plugin/add', function () { // requireNoCache is used to require package.json spyOn(cordova_util, 'requireNoCache').and.returnValue(package_json_mock); spyOn(events, 'emit'); - spyOn(registry, 'info').and.returnValue(Q()); + spyOn(plugin_util, 'info').and.returnValue(Q()); spyOn(add, 'getFetchVersion').and.returnValue(Q()); spyOn(plugin_util, 'saveToConfigXmlOn').and.returnValue(true); }); @@ -356,7 +355,7 @@ describe('cordova/plugin/add', function () { it('should retrieve plugin info via registry.info', function (done) { add.determinePluginTarget(projectRoot, Cfg_parser_mock, 'cordova-plugin-device', {}) .then(function (target) { - expect(registry.info).toHaveBeenCalledWith(['cordova-plugin-device'], '/some/path', jasmine.any(Object)); + expect(plugin_util.info).toHaveBeenCalledWith(['cordova-plugin-device']); expect(events.emit).toHaveBeenCalledWith('verbose', 'Attempting to use npm info for cordova-plugin-device to choose a compatible release'); expect(target).toEqual('cordova-plugin-device'); }).fail(function (e) { @@ -365,10 +364,10 @@ describe('cordova/plugin/add', function () { }).done(done); }); it('should feed registry.info plugin information into getFetchVersion', function (done) { - registry.info.and.returnValue(Q({'plugin': 'info'})); + plugin_util.info.and.returnValue(Q({'plugin': 'info'})); add.determinePluginTarget(projectRoot, Cfg_parser_mock, 'cordova-plugin-device', {}) .then(function (target) { - expect(registry.info).toHaveBeenCalled(); + expect(plugin_util.info).toHaveBeenCalled(); expect(add.getFetchVersion).toHaveBeenCalledWith(jasmine.anything(), {'plugin': 'info'}, jasmine.anything()); expect(target).toEqual('cordova-plugin-device'); expect(events.emit).toHaveBeenCalledWith('verbose', 'Attempting to use npm info for cordova-plugin-device to choose a compatible release'); @@ -381,7 +380,7 @@ describe('cordova/plugin/add', function () { add.getFetchVersion.and.returnValue(Q('1.0.0')); add.determinePluginTarget(projectRoot, Cfg_parser_mock, 'cordova-plugin-device', {}) .then(function (target) { - expect(registry.info).toHaveBeenCalled(); + expect(plugin_util.info).toHaveBeenCalled(); expect(add.getFetchVersion).toHaveBeenCalled(); expect(target).toEqual('cordova-plugin-device@1.0.0'); expect(events.emit).toHaveBeenCalledWith('verbose', 'Attempting to use npm info for cordova-plugin-device to choose a compatible release'); diff --git a/spec/plugman/info.spec.js b/spec/plugman/info.spec.js deleted file mode 100644 index 8f45b2874..000000000 --- a/spec/plugman/info.spec.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ -var search = require('../../src/plugman/info'); -var Q = require('q'); -var registry = require('../../src/plugman/registry/registry'); - -describe('info', function () { - it('Test 001 : should show plugin info', function () { - var sSearch = spyOn(registry, 'info').and.returnValue(Q({ - name: 'fakePlugin', - version: '1.0.0', - engines: [{ name: 'plugman', version: '>=0.11' }] - })); - search(new Array('myplugin')); - expect(sSearch).toHaveBeenCalledWith(['myplugin']); - }); -}); diff --git a/spec/plugman/registry/registry.spec.js b/spec/plugman/registry/registry.spec.js deleted file mode 100644 index 127c997ab..000000000 --- a/spec/plugman/registry/registry.spec.js +++ /dev/null @@ -1,128 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ -var registry = require('../../../src/plugman/registry/registry'); -var manifest = require('../../../src/plugman/registry/manifest'); -var fs = require('fs'); -var path = require('path'); -var shell = require('shelljs'); -var os = require('os'); -var npm = require('npm'); - -describe('registry', function () { - var done; // eslint-disable-line no-unused-vars - beforeEach(function () { - done = false; - }); - - function registryPromise (shouldSucceed, f) { - return f - .then(function () { - done = true; - expect(shouldSucceed).toBe(true); - }).fail(function (err) { - done = err; - expect(shouldSucceed).toBe(false); - }); - } - - describe('manifest', function () { - var pluginDir, tmp_plugin, tmp_plugin_xml, tmp_package_json; - beforeEach(function () { - pluginDir = path.join(__dirname, '/../plugins/com.cordova.engine'); - tmp_plugin = path.join(os.tmpdir(), 'plugin'); - tmp_plugin_xml = path.join(tmp_plugin, 'plugin.xml'); - tmp_package_json = path.join(tmp_plugin, 'package.json'); - shell.cp('-R', pluginDir + '/*', tmp_plugin); - }); - afterEach(function () { - shell.rm('-rf', tmp_plugin); - }); - it('Test 001 : should generate a package.json from a plugin.xml', function (done) { - return registryPromise(true, manifest.generatePackageJsonFromPluginXml(tmp_plugin)) - .then(function () { - expect(fs.existsSync(tmp_package_json)); - var packageJson = JSON.parse(fs.readFileSync(tmp_package_json)); - expect(packageJson.name).toEqual('com.cordova.engine'); - expect(packageJson.version).toEqual('1.0.0'); - expect(packageJson.engines).toEqual( - [ { name: 'cordova', version: '>=2.3.0' }, { name: 'cordova-plugman', version: '>=0.10.0' }, { name: 'mega-fun-plugin', version: '>=1.0.0' }, { name: 'mega-boring-plugin', version: '>=3.0.0' } ]); - done(); - }); - }, 6000); - it('Test 002 : should raise an error if name does not follow com.domain.* format', function (done) { - var xmlData = fs.readFileSync(tmp_plugin_xml).toString().replace('id="com.cordova.engine"', 'id="engine"'); - fs.writeFileSync(tmp_plugin_xml, xmlData); - return registryPromise(false, manifest.generatePackageJsonFromPluginXml(tmp_plugin)) - .then(function () { - done(); - }); - }); - // Expect the package.json to NOT exist - it('Test 003 : should generate a package.json if name uses org.apache.cordova.* for a whitelisted plugin', function (done) { - var xmlData = fs.readFileSync(tmp_plugin_xml).toString().replace('id="com.cordova.engine"', 'id="org.apache.cordova.camera"'); - fs.writeFileSync(tmp_plugin_xml, xmlData); - return registryPromise(true, manifest.generatePackageJsonFromPluginXml(tmp_plugin)) - .then(function (result) { - expect(fs.existsSync(tmp_package_json)).toBe(true); - done(); - }); - }, 6000); - it('Test 004 : should raise an error if name uses org.apache.cordova.* for a non-whitelisted plugin', function (done) { - var xmlData = fs.readFileSync(tmp_plugin_xml).toString().replace('id="com.cordova.engine"', 'id="org.apache.cordova.myinvalidplugin"'); - fs.writeFileSync(tmp_plugin_xml, xmlData); - return registryPromise(false, manifest.generatePackageJsonFromPluginXml(tmp_plugin)) - .then(function () { - done(); - }); - }, 6000); - }); - describe('actions', function () { - var fakeLoad; // eslint-disable-line no-unused-vars - var fakeNPMCommands; - - beforeEach(function () { - done = false; - var fakeSettings = { - cache: '/some/cache/dir', - logstream: 'somelogstream@2313213', - userconfig: '/some/config/dir' - }; - - var fakeNPM = function () { - if (arguments.length > 0) { - var cb = arguments[arguments.length - 1]; - if (cb && typeof cb === 'function') cb(null, true); - } - }; - - registry.settings = fakeSettings; - fakeLoad = spyOn(npm, 'load').and.callFake(function () { arguments[arguments.length - 1](null, true); }); - - fakeNPMCommands = {}; - ['config', 'adduser', 'cache', 'publish', 'unpublish', 'search'].forEach(function (cmd) { - fakeNPMCommands[cmd] = jasmine.createSpy(cmd).and.callFake(fakeNPM); - }); - - npm.commands = fakeNPMCommands; - npm.config.set = function () {}; - npm.config.get = function () {}; - npm.config.del = function () {}; - }); - }); -}); diff --git a/src/cordova/plugin/add.js b/src/cordova/plugin/add.js index bf86d1fce..65a75812c 100644 --- a/src/cordova/plugin/add.js +++ b/src/cordova/plugin/add.js @@ -23,7 +23,6 @@ var config = require('../config'); var cordova_pkgJson = require('../../../package.json'); var pluginSpec = require('./plugin_spec_parser'); var plugman = require('../../plugman/plugman'); -var registry = require('../../plugman/registry/registry'); var chainMap = require('../../util/promise-util').Q_chainmap; var ConfigParser = require('cordova-common').ConfigParser; var CordovaError = require('cordova-common').CordovaError; @@ -287,7 +286,7 @@ function determinePluginTarget (projectRoot, cfg, target, fetchOptions) { } // if noregistry or searchpath are true, then shouldUseNpmInfo is false. Just return target // else run `npm info` on the target via registry.info so we could get engines elemenent in package.json. Pass that info to getFetchVersion which determines the correct plugin to fetch based on engines element. - return (shouldUseNpmInfo ? registry.info([id], projectRoot, fetchOptions) + return (shouldUseNpmInfo ? plugin_util.info([id]) .then(function (pluginInfo) { return module.exports.getFetchVersion(projectRoot, pluginInfo, cordovaVersion); }) : Q(null)) diff --git a/src/cordova/plugin/util.js b/src/cordova/plugin/util.js index 6dfced9da..ef1f41554 100644 --- a/src/cordova/plugin/util.js +++ b/src/cordova/plugin/util.js @@ -22,10 +22,13 @@ var PluginInfoProvider = require('cordova-common').PluginInfoProvider; var shell = require('shelljs'); var events = require('cordova-common').events; var CordovaError = require('cordova-common').CordovaError; +var fetch = require('cordova-fetch'); +var superspawn = require('cordova-common').superspawn; module.exports.saveToConfigXmlOn = saveToConfigXmlOn; module.exports.getInstalledPlugins = getInstalledPlugins; module.exports.mergeVariables = mergeVariables; +module.exports.info = info; function getInstalledPlugins (projectRoot) { var pluginsDir = path.join(projectRoot, 'plugins'); @@ -75,3 +78,19 @@ function mergeVariables (pluginInfo, cfg, opts) { } return opts.cli_variables; } + +function info (plugin) { + var viewArgs = ['view']; + plugin = plugin.shift(); + viewArgs.push(plugin); + viewArgs.push('--json'); + // check if npm is installed + return fetch.isNpmInstalled() + .then(function () { + return superspawn.spawn('npm', viewArgs) + .then(function (info) { + var pluginInfo = JSON.parse(info); + return pluginInfo; + }); + }); +} diff --git a/src/plugman/config.js b/src/plugman/config.js deleted file mode 100644 index cbc71a881..000000000 --- a/src/plugman/config.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ - -var registry = require('./registry/registry'); - -module.exports = function (params) { - return registry.config(params); -}; diff --git a/src/plugman/info.js b/src/plugman/info.js deleted file mode 100644 index 7f87244ff..000000000 --- a/src/plugman/info.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ - -var registry = require('./registry/registry'); - -// Returns a promise. -module.exports = function (plugin) { - return registry.info(plugin); -}; diff --git a/src/plugman/owner.js b/src/plugman/owner.js deleted file mode 100644 index 17faf9dcd..000000000 --- a/src/plugman/owner.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ - -var registry = require('./registry/registry'); - -// Returns a promise. -module.exports = function (args) { - return registry.owner(args); -}; diff --git a/src/plugman/plugman.js b/src/plugman/plugman.js index 9a1281fc1..9b249bfd8 100644 --- a/src/plugman/plugman.js +++ b/src/plugman/plugman.js @@ -33,10 +33,6 @@ var plugman = { fetch: require('./fetch'), browserify: require('./browserify'), help: require('./help'), - config: require('./config'), - owner: require('./owner'), - search: require('./search'), - info: require('./info'), create: require('./create'), platform: require('./platform_operation'), createpackagejson: require('./createpackagejson'), diff --git a/src/plugman/registry/registry.js b/src/plugman/registry/registry.js deleted file mode 100644 index 1c86b2f61..000000000 --- a/src/plugman/registry/registry.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ - -var fetch = require('cordova-fetch'); -var superspawn = require('cordova-common').superspawn; - -module.exports = { - settings: null, - - /** - * @method info - * @param {String} name Plugin name - * @return {Promise.} Promised package info. - */ - info: function (plugin, dest, opts) { - opts = opts || {}; - var fetchArgs = opts.link ? ['link'] : ['install']; - plugin = plugin.shift(); - // set the directory where npm install will be run - opts.cwd = dest; - // check if npm is installed - return fetch.isNpmInstalled() - .then(function () { - return superspawn.spawn('npm', fetchArgs, opts) - .then(function (info) { - // Plugin info should be accessed as info[version]. If a version - // specifier like >=x.y.z was used when calling npm view, info - // can contain several versions, but we take the first one here. - var version = Object.keys(info)[0]; - return info[version]; - }); - }); - } -}; diff --git a/src/plugman/search.js b/src/plugman/search.js deleted file mode 100644 index 474edc9a0..000000000 --- a/src/plugman/search.js +++ /dev/null @@ -1,24 +0,0 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ - -var registry = require('./registry/registry'); - -module.exports = function (search_opts) { - return registry.search(search_opts); -}; diff --git a/src/util/npm-helper.js b/src/util/npm-helper.js index f8003c101..9cd16a7e3 100644 --- a/src/util/npm-helper.js +++ b/src/util/npm-helper.js @@ -1,130 +1,130 @@ -/** - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at +// /** +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// */ -// Helper methods to help keep npm operations separated. +// // Helper methods to help keep npm operations separated. -var npm = require('npm'); -var path = require('path'); -var fs = require('fs'); -var Q = require('q'); -var unpack = require('./unpack'); -var util = require('../cordova/util'); -var cachedSettings = null; -var cachedSettingsValues = null; +// var npm = require('npm'); +// var path = require('path'); +// var fs = require('fs'); +// var Q = require('q'); +// var unpack = require('./unpack'); +// var util = require('../cordova/util'); +// var cachedSettings = null; +// var cachedSettingsValues = null; -/** - * @description Calls npm.load, then initializes npm.config with the specified settings. Then executes a chain of - * promises that rely on those npm settings, then restores npm settings back to their previous value. Use this rather - * than passing settings to npm.load, since that only works the first time you try to load npm. - * @param {Object} settings - * @param {Function} promiseChain - */ -function loadWithSettingsThenRestore (settings, promiseChain) { - return loadWithSettings(settings).then(promiseChain).finally(restoreSettings); -} +// /** +// * @description Calls npm.load, then initializes npm.config with the specified settings. Then executes a chain of +// * promises that rely on those npm settings, then restores npm settings back to their previous value. Use this rather +// * than passing settings to npm.load, since that only works the first time you try to load npm. +// * @param {Object} settings +// * @param {Function} promiseChain +// */ +// function loadWithSettingsThenRestore (settings, promiseChain) { +// return loadWithSettings(settings).then(promiseChain).finally(restoreSettings); +// } -function loadWithSettings (settings) { - if (cachedSettings) { - throw new Error('Trying to initialize npm when settings have not been restored from a previous initialization.'); - } +// function loadWithSettings (settings) { +// if (cachedSettings) { +// throw new Error('Trying to initialize npm when settings have not been restored from a previous initialization.'); +// } - return Q.nfcall(npm.load, settings).then(function () { - for (var prop in settings) { - var currentValue = npm.config.get(prop); - var newValue = settings[prop]; +// return Q.nfcall(npm.load, settings).then(function () { +// for (var prop in settings) { +// var currentValue = npm.config.get(prop); +// var newValue = settings[prop]; - if (currentValue !== newValue) { - cachedSettingsValues = cachedSettingsValues || {}; - cachedSettings = cachedSettings || []; - cachedSettings.push(prop); - if (typeof currentValue !== 'undefined') { - cachedSettingsValues[prop] = currentValue; - } - npm.config.set(prop, newValue); - } - } - }); -} +// if (currentValue !== newValue) { +// cachedSettingsValues = cachedSettingsValues || {}; +// cachedSettings = cachedSettings || []; +// cachedSettings.push(prop); +// if (typeof currentValue !== 'undefined') { +// cachedSettingsValues[prop] = currentValue; +// } +// npm.config.set(prop, newValue); +// } +// } +// }); +// } -function restoreSettings () { - if (cachedSettings) { - cachedSettings.forEach(function (prop) { - if (prop in cachedSettingsValues) { - npm.config.set(prop, cachedSettingsValues[prop]); - } else { - npm.config.del(prop); - } - }); - cachedSettings = null; - cachedSettingsValues = null; - } -} +// function restoreSettings () { +// if (cachedSettings) { +// cachedSettings.forEach(function (prop) { +// if (prop in cachedSettingsValues) { +// npm.config.set(prop, cachedSettingsValues[prop]); +// } else { +// npm.config.del(prop); +// } +// }); +// cachedSettings = null; +// cachedSettingsValues = null; +// } +// } -/** - * Fetches the latest version of a package from NPM that matches the specified version. Returns a promise that - * resolves to the directory the NPM package is located in. - * @param packageName - name of an npm package - * @param packageVersion - requested version or version range - */ -function fetchPackage (packageName, packageVersion) { - // Get the latest matching version from NPM if a version range is specified - return util.getLatestMatchingNpmVersion(packageName, packageVersion).then( - function (latestVersion) { - return cachePackage(packageName, latestVersion); - } - ); -} +// /** +// * Fetches the latest version of a package from NPM that matches the specified version. Returns a promise that +// * resolves to the directory the NPM package is located in. +// * @param packageName - name of an npm package +// * @param packageVersion - requested version or version range +// */ +// function fetchPackage (packageName, packageVersion) { +// // Get the latest matching version from NPM if a version range is specified +// return util.getLatestMatchingNpmVersion(packageName, packageVersion).then( +// function (latestVersion) { +// return cachePackage(packageName, latestVersion); +// } +// ); +// } -/** - * Invokes "npm cache add," and then returns a promise that resolves to a directory containing the downloaded, - * or cached package. - * @param packageName - name of an npm package - * @param packageVersion - requested version (not a version range) - */ -function cachePackage (packageName, packageVersion) { - return Q().then(function () { - var cacheDir = path.join(util.libDirectory, 'npm_cache'); +// /** +// * Invokes "npm cache add," and then returns a promise that resolves to a directory containing the downloaded, +// * or cached package. +// * @param packageName - name of an npm package +// * @param packageVersion - requested version (not a version range) +// */ +// function cachePackage (packageName, packageVersion) { +// return Q().then(function () { +// var cacheDir = path.join(util.libDirectory, 'npm_cache'); - // If already cached, use that rather than calling 'npm cache add' again. - var packageCacheDir = path.resolve(cacheDir, packageName, packageVersion); - var packageTGZ = path.resolve(packageCacheDir, 'package.tgz'); - if (fs.existsSync(packageTGZ)) { - return unpack.unpackTgz(packageTGZ, path.resolve(packageCacheDir, 'package')); - } +// // If already cached, use that rather than calling 'npm cache add' again. +// var packageCacheDir = path.resolve(cacheDir, packageName, packageVersion); +// var packageTGZ = path.resolve(packageCacheDir, 'package.tgz'); +// if (fs.existsSync(packageTGZ)) { +// return unpack.unpackTgz(packageTGZ, path.resolve(packageCacheDir, 'package')); +// } - // Load with NPM configuration - return loadWithSettingsThenRestore({'cache': cacheDir}, - function () { - // Invoke NPM Cache Add - return Q.ninvoke(npm.commands, 'cache', ['add', (packageName + '@' + packageVersion)]).then( - function (info) { - var packageDir = path.resolve(npm.cache, info.name, info.version, 'package'); - var packageTGZ = path.resolve(npm.cache, info.name, info.version, 'package.tgz'); +// // Load with NPM configuration +// return loadWithSettingsThenRestore({'cache': cacheDir}, +// function () { +// // Invoke NPM Cache Add +// return Q.ninvoke(npm.commands, 'cache', ['add', (packageName + '@' + packageVersion)]).then( +// function (info) { +// var packageDir = path.resolve(npm.cache, info.name, info.version, 'package'); +// var packageTGZ = path.resolve(npm.cache, info.name, info.version, 'package.tgz'); - return unpack.unpackTgz(packageTGZ, packageDir); - } - ); - } - ); - }); -} +// return unpack.unpackTgz(packageTGZ, packageDir); +// } +// ); +// } +// ); +// }); +// } -module.exports.loadWithSettingsThenRestore = loadWithSettingsThenRestore; -module.exports.fetchPackage = fetchPackage; -module.exports.cachePackage = cachePackage; +// module.exports.loadWithSettingsThenRestore = loadWithSettingsThenRestore; +// module.exports.fetchPackage = fetchPackage; +// module.exports.cachePackage = cachePackage; From 6e22fb4c217d77d28b58ebe580fa4f998ee6d5e6 Mon Sep 17 00:00:00 2001 From: Audrey So Date: Tue, 12 Dec 2017 14:04:04 -0800 Subject: [PATCH 3/5] CB-13055 : updated after PR feedback This closes #608 --- integration-tests/platform.spec.js | 4 +- integration-tests/plugin.spec.js | 2 +- integration-tests/plugman_fetch.spec.js | 2 +- src/plugman/fetch.js | 3 +- src/util/npm-helper.js | 130 ------------------------ 5 files changed, 5 insertions(+), 136 deletions(-) delete mode 100644 src/util/npm-helper.js diff --git a/integration-tests/platform.spec.js b/integration-tests/platform.spec.js index 3ffa63487..aa30e044b 100644 --- a/integration-tests/platform.spec.js +++ b/integration-tests/platform.spec.js @@ -128,8 +128,8 @@ describe('platform end-to-end', function () { expect(err).toBeUndefined(); }).fin(done); }); - // was using old fetch code/gitclone... test might not be valid anymore. - xit('Test 002 : should install plugins correctly while adding platform', function (done) { + + it('Test 002 : should install plugins correctly while adding platform', function (done) { cordova.plugin('add', path.join(pluginsDir, 'test'), {'fetch': true}) .then(function () { return cordova.platform('add', [helpers.testPlatform], {'fetch': true}); diff --git a/integration-tests/plugin.spec.js b/integration-tests/plugin.spec.js index 380c22b55..0bf602d56 100644 --- a/integration-tests/plugin.spec.js +++ b/integration-tests/plugin.spec.js @@ -241,7 +241,7 @@ describe('plugin end-to-end', function () { .fin(done); }, 30000); - it('Test 010 : should use registry.info to get plugin & version', function (done) { + it('Test 010 : should select the plugin version based on npm info when fetching from npm', function (done) { mockPluginFetch(npmInfoTestPlugin, path.join(pluginsDir, npmInfoTestPlugin)); spyOn(plugin_util, 'info').and.callThrough(); diff --git a/integration-tests/plugman_fetch.spec.js b/integration-tests/plugman_fetch.spec.js index 982c3a650..9c2faf7b2 100644 --- a/integration-tests/plugman_fetch.spec.js +++ b/integration-tests/plugman_fetch.spec.js @@ -151,7 +151,7 @@ describe('fetch', function () { }); }); - xdescribe('fetch recursive error CB-8809', function () { + describe('fetch recursive error CB-8809', function () { var srcDir = path.join(plugins_dir, 'recursivePlug'); var appDir = path.join(plugins_dir, 'recursivePlug', 'demo'); diff --git a/src/plugman/fetch.js b/src/plugman/fetch.js index fa10e413f..4d83f69c1 100644 --- a/src/plugman/fetch.js +++ b/src/plugman/fetch.js @@ -83,7 +83,6 @@ function fetchPlugin (plugin_src, plugins_dir, options) { } } return Q.when().then(function () { - // If it's not a network URL, it's either a local path or a plugin ID. var plugin_dir = cordovaUtil.fixRelativePath(path.join(plugin_src, options.subdir)); return Q.when().then(function () { // check if it is a local path @@ -114,7 +113,7 @@ function fetchPlugin (plugin_src, plugins_dir, options) { }); } } - // If there is no such local path, it's a plugin id or id@versionspec. + // If there is no such local path or it's a git URL, it's a plugin id or id@versionspec. // First look for it in the local search path (if provided). var pinfo = findLocalPlugin(plugin_src, options.searchpath, pluginInfoProvider); if (pinfo) { diff --git a/src/util/npm-helper.js b/src/util/npm-helper.js deleted file mode 100644 index 9cd16a7e3..000000000 --- a/src/util/npm-helper.js +++ /dev/null @@ -1,130 +0,0 @@ -// /** -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 - -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// */ - -// // Helper methods to help keep npm operations separated. - -// var npm = require('npm'); -// var path = require('path'); -// var fs = require('fs'); -// var Q = require('q'); -// var unpack = require('./unpack'); -// var util = require('../cordova/util'); -// var cachedSettings = null; -// var cachedSettingsValues = null; - -// /** -// * @description Calls npm.load, then initializes npm.config with the specified settings. Then executes a chain of -// * promises that rely on those npm settings, then restores npm settings back to their previous value. Use this rather -// * than passing settings to npm.load, since that only works the first time you try to load npm. -// * @param {Object} settings -// * @param {Function} promiseChain -// */ -// function loadWithSettingsThenRestore (settings, promiseChain) { -// return loadWithSettings(settings).then(promiseChain).finally(restoreSettings); -// } - -// function loadWithSettings (settings) { -// if (cachedSettings) { -// throw new Error('Trying to initialize npm when settings have not been restored from a previous initialization.'); -// } - -// return Q.nfcall(npm.load, settings).then(function () { -// for (var prop in settings) { -// var currentValue = npm.config.get(prop); -// var newValue = settings[prop]; - -// if (currentValue !== newValue) { -// cachedSettingsValues = cachedSettingsValues || {}; -// cachedSettings = cachedSettings || []; -// cachedSettings.push(prop); -// if (typeof currentValue !== 'undefined') { -// cachedSettingsValues[prop] = currentValue; -// } -// npm.config.set(prop, newValue); -// } -// } -// }); -// } - -// function restoreSettings () { -// if (cachedSettings) { -// cachedSettings.forEach(function (prop) { -// if (prop in cachedSettingsValues) { -// npm.config.set(prop, cachedSettingsValues[prop]); -// } else { -// npm.config.del(prop); -// } -// }); -// cachedSettings = null; -// cachedSettingsValues = null; -// } -// } - -// /** -// * Fetches the latest version of a package from NPM that matches the specified version. Returns a promise that -// * resolves to the directory the NPM package is located in. -// * @param packageName - name of an npm package -// * @param packageVersion - requested version or version range -// */ -// function fetchPackage (packageName, packageVersion) { -// // Get the latest matching version from NPM if a version range is specified -// return util.getLatestMatchingNpmVersion(packageName, packageVersion).then( -// function (latestVersion) { -// return cachePackage(packageName, latestVersion); -// } -// ); -// } - -// /** -// * Invokes "npm cache add," and then returns a promise that resolves to a directory containing the downloaded, -// * or cached package. -// * @param packageName - name of an npm package -// * @param packageVersion - requested version (not a version range) -// */ -// function cachePackage (packageName, packageVersion) { -// return Q().then(function () { -// var cacheDir = path.join(util.libDirectory, 'npm_cache'); - -// // If already cached, use that rather than calling 'npm cache add' again. -// var packageCacheDir = path.resolve(cacheDir, packageName, packageVersion); -// var packageTGZ = path.resolve(packageCacheDir, 'package.tgz'); -// if (fs.existsSync(packageTGZ)) { -// return unpack.unpackTgz(packageTGZ, path.resolve(packageCacheDir, 'package')); -// } - -// // Load with NPM configuration -// return loadWithSettingsThenRestore({'cache': cacheDir}, -// function () { -// // Invoke NPM Cache Add -// return Q.ninvoke(npm.commands, 'cache', ['add', (packageName + '@' + packageVersion)]).then( -// function (info) { -// var packageDir = path.resolve(npm.cache, info.name, info.version, 'package'); -// var packageTGZ = path.resolve(npm.cache, info.name, info.version, 'package.tgz'); - -// return unpack.unpackTgz(packageTGZ, packageDir); -// } -// ); -// } -// ); -// }); -// } - -// module.exports.loadWithSettingsThenRestore = loadWithSettingsThenRestore; -// module.exports.fetchPackage = fetchPackage; -// module.exports.cachePackage = cachePackage; From 8f823f7e9136395403dd350d973f82814b4ebb1f Mon Sep 17 00:00:00 2001 From: Steve Gill Date: Tue, 12 Dec 2017 21:14:42 -0800 Subject: [PATCH 4/5] CB-13055: fixed failing tests --- integration-tests/pkgJson-restore.spec.js | 3 +-- integration-tests/plugman_fetch.spec.js | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/integration-tests/pkgJson-restore.spec.js b/integration-tests/pkgJson-restore.spec.js index 1122028b5..04253e035 100644 --- a/integration-tests/pkgJson-restore.spec.js +++ b/integration-tests/pkgJson-restore.spec.js @@ -222,7 +222,6 @@ describe('tests platform/spec restore with --save', function () { var configXmlPath = path.join(cwd, 'config.xml'); var configPlugins; var configPlugin; - emptyPlatformList().then(function () { // Add plugin with save and fetch. return cordovaPlugin('add', ['https://github.com/apache/cordova-plugin-splashscreen'], {'save': true, 'fetch': true}); @@ -257,7 +256,7 @@ describe('tests platform/spec restore with --save', function () { expect(path.join(pluginsFolderPath, 'cordova-plugin-splashscreen')).not.toExist(); }).then(function () { // Add platform (so that prepare can run). - return cordovaPlatform('add', 'https://github.com/apache/cordova-browser.git', {'save': true, 'fetch': true}); + return cordovaPlatform('add', 'browser', {'save': true, 'fetch': true}); }).then(function () { // Run cordova prepare with fetch. return prepare({'save': true, 'fetch': true}); diff --git a/integration-tests/plugman_fetch.spec.js b/integration-tests/plugman_fetch.spec.js index 9c2faf7b2..985b9a412 100644 --- a/integration-tests/plugman_fetch.spec.js +++ b/integration-tests/plugman_fetch.spec.js @@ -155,6 +155,9 @@ describe('fetch', function () { var srcDir = path.join(plugins_dir, 'recursivePlug'); var appDir = path.join(plugins_dir, 'recursivePlug', 'demo'); + fetch.__set__('fetch', function (pluginDir) { + return Q(pluginDir); + }); if (/^win/.test(process.platform)) { it('Test 020 : should copy all but the /demo/ folder', function (done) { From c374b7e4795da5df2277c51292c7616e67fd25e4 Mon Sep 17 00:00:00 2001 From: Steve Gill Date: Tue, 12 Dec 2017 22:54:51 -0800 Subject: [PATCH 5/5] CB-13674: updated cordova dependencies --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 16e6af499..0856fbf48 100644 --- a/package.json +++ b/package.json @@ -18,10 +18,10 @@ }, "dependencies": { "aliasify": "^2.1.0", - "cordova-common": "2.1.1", - "cordova-create": "~1.1.0", - "cordova-fetch": "1.2.1", - "cordova-js": "4.2.2", + "cordova-common": "^2.2.0", + "cordova-create": "^1.1.0", + "cordova-fetch": "^1.2.1", + "cordova-js": "^4.2.2", "cordova-serve": "^2.0.0", "dep-graph": "1.1.0", "detect-indent": "^5.0.0",