Skip to content

Commit

Permalink
fix: platform & plugin prelease package support
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu committed Oct 27, 2024
1 parent 3381125 commit 9e26e62
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
28 changes: 14 additions & 14 deletions spec/plugman/install.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,59 +160,59 @@ describe('plugman/install', () => {
execaSpy.and.returnValue(Promise.resolve({ stdout: '2.5.0' }));
return install('android', project, pluginDir('com.cordova.engine'))
.then(() => {
expect(satisfies).toHaveBeenCalledWith('2.5.0', '>=1.0.0', true);
expect(satisfies).toHaveBeenCalledWith('2.5.0', '>=1.0.0', { loose: true, includePrerelease: true });
});
}, TIMEOUT);
it('Test 008 : should check version and munge it a little if it has "rc" in it so it plays nice with semver (introduce a dash in it)', () => {
execaSpy.and.returnValue(Promise.resolve({ stdout: '3.0.0rc1' }));
return install('android', project, pluginDir('com.cordova.engine'))
.then(() => {
expect(satisfies).toHaveBeenCalledWith('3.0.0-rc1', '>=1.0.0', true);
expect(satisfies).toHaveBeenCalledWith('3.0.0-rc1', '>=1.0.0', { loose: true, includePrerelease: true });
});
}, TIMEOUT);
it('Test 009 : should check specific platform version over cordova version if specified', () => {
execaSpy.and.returnValue(Promise.resolve({ stdout: '3.1.0' }));
return install('android', project, pluginDir('com.cordova.engine-android'))
.then(() => {
expect(satisfies).toHaveBeenCalledWith('3.1.0', '>=3.1.0', true);
expect(satisfies).toHaveBeenCalledWith('3.1.0', '>=3.1.0', { loose: true, includePrerelease: true });
});
}, TIMEOUT);
it('Test 010 : should check platform sdk version if specified', () => {
const cordovaVersion = require('../../package.json').version.replace(/-dev|-nightly.*$/, '');
const cordovaVersion = require('../../package.json').version;
execaSpy.and.returnValue(Promise.resolve({ stdout: '18' }));
return install('android', project, pluginDir('com.cordova.engine-android'))
.then(() => {
expect(satisfies.calls.count()).toBe(3);
// <engine name="cordova" VERSION=">=3.0.0"/>
expect(satisfies.calls.argsFor(0)).toEqual([cordovaVersion, '>=3.0.0', true]);
expect(satisfies.calls.argsFor(0)).toEqual([cordovaVersion, '>=3.0.0', { loose: true, includePrerelease: true }]);
// <engine name="cordova-android" VERSION=">=3.1.0"/>
expect(satisfies.calls.argsFor(1)).toEqual(['18.0.0', '>=3.1.0', true]);
expect(satisfies.calls.argsFor(1)).toEqual(['18.0.0', '>=3.1.0', { loose: true, includePrerelease: true }]);
// <engine name="android-sdk" VERSION=">=18"/>
expect(satisfies.calls.argsFor(2)).toEqual(['18.0.0', '>=18', true]);
expect(satisfies.calls.argsFor(2)).toEqual(['18.0.0', '>=18', { loose: true, includePrerelease: true }]);
});
}, TIMEOUT);
it('Test 011 : should check engine versions', () => {
return install('android', project, pluginDir('com.cordova.engine'))
.then(() => {
const plugmanVersion = require('../../package.json').version.replace(/-dev|-nightly.*$/, '');
const cordovaVersion = require('../../package.json').version.replace(/-dev|-nightly.*$/, '');
const plugmanVersion = require('../../package.json').version;
const cordovaVersion = require('../../package.json').version;
expect(satisfies.calls.count()).toBe(4);
// <engine name="cordova" version=">=2.3.0"/>
expect(satisfies.calls.argsFor(0)).toEqual([cordovaVersion, '>=2.3.0', true]);
expect(satisfies.calls.argsFor(0)).toEqual([cordovaVersion, '>=2.3.0', { loose: true, includePrerelease: true }]);
// <engine name="cordova-plugman" version=">=0.10.0" />
expect(satisfies.calls.argsFor(1)).toEqual([plugmanVersion, '>=0.10.0', true]);
expect(satisfies.calls.argsFor(1)).toEqual([plugmanVersion, '>=0.10.0', { loose: true, includePrerelease: true }]);
// <engine name="mega-fun-plugin" version=">=1.0.0" scriptSrc="megaFunVersion" platform="*" />
expect(satisfies.calls.argsFor(2)).toEqual([null, '>=1.0.0', true]);
expect(satisfies.calls.argsFor(2)).toEqual([null, '>=1.0.0', { loose: true, includePrerelease: true }]);
// <engine name="mega-boring-plugin" version=">=3.0.0" scriptSrc="megaBoringVersion" platform="ios|android" />
expect(satisfies.calls.argsFor(3)).toEqual([null, '>=3.0.0', true]);
expect(satisfies.calls.argsFor(3)).toEqual([null, '>=3.0.0', { loose: true, includePrerelease: true }]);
});
}, TIMEOUT);
it('Test 012 : should not check custom engine version that is not supported for platform', () => {
return install('blackberry10', project, pluginDir('com.cordova.engine'))
.then(() => {
// Version >=3.0.0 of `mega-boring-plugin` is specified with platform="ios|android"
expect(satisfies.calls.count()).toBe(3);
expect(satisfies).not.toHaveBeenCalledWith(jasmine.anything(), '>=3.0.0', true);
expect(satisfies).not.toHaveBeenCalledWith(jasmine.anything(), '>=3.0.0', { loose: true, includePrerelease: true });
});
}, TIMEOUT);
});
Expand Down
8 changes: 3 additions & 5 deletions src/cordova/platform/addHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,9 @@ function addHelper (cmd, hooksRunner, projectRoot, targets, opts) {
}
}

if (/-nightly|-dev$/.exec(platDetails.version)) {
msg = 'Warning: using prerelease platform ' + platform +
'@' + platDetails.version +
'.\nUse \'cordova platform add ' +
platform + '@latest\' to add the latest published version instead.';
if (semver.prerelease(platDetails.version)) {
msg = `Warning: using prerelease platform ${platform}@${platDetails.version}.`;
msg += `\nUse 'cordova platform add ${platform}@latest to add the latest published version instead.`;
events.emit('warn', msg);
}

Expand Down
18 changes: 4 additions & 14 deletions src/plugman/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,12 @@ function possiblyFetch (id, plugins_dir, options) {

function checkEngines (engines) {
for (let i = 0; i < engines.length; i++) {
const engine = engines[i];

// This is a hack to allow plugins with <engine> tag to be installed with
// engine with '-dev' or '-nightly' suffixes. It is required due to new semver range logic,
// introduced in [email protected]. For more details see https://github.com/npm/node-semver#prerelease-tags.
//
// This may lead to false-positive checks, when engine version with dropped
// suffix is equal to one of range bounds, for example: 5.1.0-dev >= 5.1.0.
// However this shouldn't be a problem, because this only should happen in dev workflow.
engine.currentVersion = engine.currentVersion && engine.currentVersion.replace(/-dev|-nightly.*$/, '');
if (semver.satisfies(engine.currentVersion, engine.minVersion, /* loose= */true) || engine.currentVersion === null) {
const { currentVersion, minVersion, name } = engines[i];

if (semver.satisfies(currentVersion, minVersion, { loose: true, includePrerelease: true }) || currentVersion === null) {
continue; // engine ok!
} else {
const msg = 'Plugin doesn\'t support this project\'s ' + engine.name + ' version. ' +
engine.name + ': ' + engine.currentVersion +
', failed version requirement: ' + engine.minVersion;
const msg = `Plugin doesn't support this project's ${name} version. ${name}: ${currentVersion}, failed version requirement: ${minVersion}`;
events.emit('warn', msg);
return Promise.reject(Object.assign(new Error(), { skip: true }));
}
Expand Down

0 comments on commit 9e26e62

Please sign in to comment.