Skip to content

Commit 1bdb0d3

Browse files
authored
fix: platform & plugin prerelease package support (#935)
1 parent 3381125 commit 1bdb0d3

File tree

3 files changed

+21
-33
lines changed

3 files changed

+21
-33
lines changed

spec/plugman/install.spec.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -160,59 +160,59 @@ describe('plugman/install', () => {
160160
execaSpy.and.returnValue(Promise.resolve({ stdout: '2.5.0' }));
161161
return install('android', project, pluginDir('com.cordova.engine'))
162162
.then(() => {
163-
expect(satisfies).toHaveBeenCalledWith('2.5.0', '>=1.0.0', true);
163+
expect(satisfies).toHaveBeenCalledWith('2.5.0', '>=1.0.0', { loose: true, includePrerelease: true });
164164
});
165165
}, TIMEOUT);
166166
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)', () => {
167167
execaSpy.and.returnValue(Promise.resolve({ stdout: '3.0.0rc1' }));
168168
return install('android', project, pluginDir('com.cordova.engine'))
169169
.then(() => {
170-
expect(satisfies).toHaveBeenCalledWith('3.0.0-rc1', '>=1.0.0', true);
170+
expect(satisfies).toHaveBeenCalledWith('3.0.0-rc1', '>=1.0.0', { loose: true, includePrerelease: true });
171171
});
172172
}, TIMEOUT);
173173
it('Test 009 : should check specific platform version over cordova version if specified', () => {
174174
execaSpy.and.returnValue(Promise.resolve({ stdout: '3.1.0' }));
175175
return install('android', project, pluginDir('com.cordova.engine-android'))
176176
.then(() => {
177-
expect(satisfies).toHaveBeenCalledWith('3.1.0', '>=3.1.0', true);
177+
expect(satisfies).toHaveBeenCalledWith('3.1.0', '>=3.1.0', { loose: true, includePrerelease: true });
178178
});
179179
}, TIMEOUT);
180180
it('Test 010 : should check platform sdk version if specified', () => {
181-
const cordovaVersion = require('../../package.json').version.replace(/-dev|-nightly.*$/, '');
181+
const cordovaVersion = require('../../package.json').version;
182182
execaSpy.and.returnValue(Promise.resolve({ stdout: '18' }));
183183
return install('android', project, pluginDir('com.cordova.engine-android'))
184184
.then(() => {
185185
expect(satisfies.calls.count()).toBe(3);
186186
// <engine name="cordova" VERSION=">=3.0.0"/>
187-
expect(satisfies.calls.argsFor(0)).toEqual([cordovaVersion, '>=3.0.0', true]);
187+
expect(satisfies.calls.argsFor(0)).toEqual([cordovaVersion, '>=3.0.0', { loose: true, includePrerelease: true }]);
188188
// <engine name="cordova-android" VERSION=">=3.1.0"/>
189-
expect(satisfies.calls.argsFor(1)).toEqual(['18.0.0', '>=3.1.0', true]);
189+
expect(satisfies.calls.argsFor(1)).toEqual(['18.0.0', '>=3.1.0', { loose: true, includePrerelease: true }]);
190190
// <engine name="android-sdk" VERSION=">=18"/>
191-
expect(satisfies.calls.argsFor(2)).toEqual(['18.0.0', '>=18', true]);
191+
expect(satisfies.calls.argsFor(2)).toEqual(['18.0.0', '>=18', { loose: true, includePrerelease: true }]);
192192
});
193193
}, TIMEOUT);
194194
it('Test 011 : should check engine versions', () => {
195195
return install('android', project, pluginDir('com.cordova.engine'))
196196
.then(() => {
197-
const plugmanVersion = require('../../package.json').version.replace(/-dev|-nightly.*$/, '');
198-
const cordovaVersion = require('../../package.json').version.replace(/-dev|-nightly.*$/, '');
197+
const plugmanVersion = require('../../package.json').version;
198+
const cordovaVersion = require('../../package.json').version;
199199
expect(satisfies.calls.count()).toBe(4);
200200
// <engine name="cordova" version=">=2.3.0"/>
201-
expect(satisfies.calls.argsFor(0)).toEqual([cordovaVersion, '>=2.3.0', true]);
201+
expect(satisfies.calls.argsFor(0)).toEqual([cordovaVersion, '>=2.3.0', { loose: true, includePrerelease: true }]);
202202
// <engine name="cordova-plugman" version=">=0.10.0" />
203-
expect(satisfies.calls.argsFor(1)).toEqual([plugmanVersion, '>=0.10.0', true]);
203+
expect(satisfies.calls.argsFor(1)).toEqual([plugmanVersion, '>=0.10.0', { loose: true, includePrerelease: true }]);
204204
// <engine name="mega-fun-plugin" version=">=1.0.0" scriptSrc="megaFunVersion" platform="*" />
205-
expect(satisfies.calls.argsFor(2)).toEqual([null, '>=1.0.0', true]);
205+
expect(satisfies.calls.argsFor(2)).toEqual([null, '>=1.0.0', { loose: true, includePrerelease: true }]);
206206
// <engine name="mega-boring-plugin" version=">=3.0.0" scriptSrc="megaBoringVersion" platform="ios|android" />
207-
expect(satisfies.calls.argsFor(3)).toEqual([null, '>=3.0.0', true]);
207+
expect(satisfies.calls.argsFor(3)).toEqual([null, '>=3.0.0', { loose: true, includePrerelease: true }]);
208208
});
209209
}, TIMEOUT);
210210
it('Test 012 : should not check custom engine version that is not supported for platform', () => {
211211
return install('blackberry10', project, pluginDir('com.cordova.engine'))
212212
.then(() => {
213213
// Version >=3.0.0 of `mega-boring-plugin` is specified with platform="ios|android"
214214
expect(satisfies.calls.count()).toBe(3);
215-
expect(satisfies).not.toHaveBeenCalledWith(jasmine.anything(), '>=3.0.0', true);
215+
expect(satisfies).not.toHaveBeenCalledWith(jasmine.anything(), '>=3.0.0', { loose: true, includePrerelease: true });
216216
});
217217
}, TIMEOUT);
218218
});

src/cordova/platform/addHelper.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,9 @@ function addHelper (cmd, hooksRunner, projectRoot, targets, opts) {
132132
}
133133
}
134134

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

src/plugman/install.js

+4-14
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,12 @@ function possiblyFetch (id, plugins_dir, options) {
9999

100100
function checkEngines (engines) {
101101
for (let i = 0; i < engines.length; i++) {
102-
const engine = engines[i];
103-
104-
// This is a hack to allow plugins with <engine> tag to be installed with
105-
// engine with '-dev' or '-nightly' suffixes. It is required due to new semver range logic,
106-
// introduced in [email protected]. For more details see https://github.com/npm/node-semver#prerelease-tags.
107-
//
108-
// This may lead to false-positive checks, when engine version with dropped
109-
// suffix is equal to one of range bounds, for example: 5.1.0-dev >= 5.1.0.
110-
// However this shouldn't be a problem, because this only should happen in dev workflow.
111-
engine.currentVersion = engine.currentVersion && engine.currentVersion.replace(/-dev|-nightly.*$/, '');
112-
if (semver.satisfies(engine.currentVersion, engine.minVersion, /* loose= */true) || engine.currentVersion === null) {
102+
const { currentVersion, minVersion, name } = engines[i];
103+
104+
if (semver.satisfies(currentVersion, minVersion, { loose: true, includePrerelease: true }) || currentVersion === null) {
113105
continue; // engine ok!
114106
} else {
115-
const msg = 'Plugin doesn\'t support this project\'s ' + engine.name + ' version. ' +
116-
engine.name + ': ' + engine.currentVersion +
117-
', failed version requirement: ' + engine.minVersion;
107+
const msg = `Plugin doesn't support this project's ${name} version. ${name}: ${currentVersion}, failed version requirement: ${minVersion}`;
118108
events.emit('warn', msg);
119109
return Promise.reject(Object.assign(new Error(), { skip: true }));
120110
}

0 commit comments

Comments
 (0)