Skip to content
Permalink
Browse files
fix: Platforms restored from both dev and normal dependencies. (#874)
* fix: Check for platform version in both normal and dev dependencies within package.json file.

* fix: added unit test for package.json devDependencies (#866)

Co-authored-by: Aidanas Tamasauskas <aidana.tamasauskas@nutshellapps.co.uk>
Co-authored-by: Richard Li <li.richard.2013@gmail.com>
  • Loading branch information
3 people committed Sep 26, 2021
1 parent 0b9fa57 commit 33ce4fe787f4ea1508f83787b2d50083c2ea0154
Showing 2 changed files with 18 additions and 1 deletion.
@@ -247,6 +247,21 @@ describe('cordova/platform/addHelper', function () {
});
});

it('should use pkgJson version devDependencies, if dependencies are nonempty but do not include the platform', function () {
package_json_mock.dependencies.lorem = {}; // Add some item to dependencies so it's defined but nonempty
package_json_mock.cordova = { platforms: ['ios'] };
package_json_mock.devDependencies.ios = {};
cordova_util.requireNoCache.and.returnValue(package_json_mock);
fs.existsSync.and.callFake(function (filePath) {
return path.basename(filePath) === 'package.json';
});
fs.readFileSync.and.returnValue('{}');
return platform_addHelper('add', hooks_mock, projectRoot, ['ios'], { save: true, restoring: true }).then(function () {
expect(platform_addHelper.getVersionFromConfigFile).not.toHaveBeenCalled();
expect(fs.writeFileSync).toHaveBeenCalled();
});
});

it('should only write the package.json file if it was modified', function () {
package_json_mock.cordova = { platforms: ['ios'] };
cordova_util.requireNoCache.and.returnValue(package_json_mock);
@@ -99,7 +99,9 @@ function addHelper (cmd, hooksRunner, projectRoot, targets, opts) {
} else if (pkgJson.dependencies[platform]) {
spec = pkgJson.dependencies[platform];
}
} else if (spec === undefined && pkgJson && pkgJson.devDependencies && cmd === 'add') {
}

if (spec === undefined && pkgJson && pkgJson.devDependencies && cmd === 'add') {
if (pkgJson.devDependencies['cordova-' + platform]) {
spec = pkgJson.devDependencies['cordova-' + platform];
} else if (pkgJson.devDependencies[platform]) {

0 comments on commit 33ce4fe

Please sign in to comment.