From 9e26e62e21e319b7a79eae97dcd098707626448d Mon Sep 17 00:00:00 2001 From: Erisu Date: Sun, 27 Oct 2024 14:55:46 +0900 Subject: [PATCH] fix: platform & plugin prelease package support --- spec/plugman/install.spec.js | 28 ++++++++++++++-------------- src/cordova/platform/addHelper.js | 8 +++----- src/plugman/install.js | 18 ++++-------------- 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/spec/plugman/install.spec.js b/spec/plugman/install.spec.js index a2c128473..c630d408e 100644 --- a/spec/plugman/install.spec.js +++ b/spec/plugman/install.spec.js @@ -160,51 +160,51 @@ 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); // - 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 }]); // - 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 }]); // - 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); // - 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 }]); // - 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 }]); // - 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 }]); // - 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', () => { @@ -212,7 +212,7 @@ describe('plugman/install', () => { .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); }); diff --git a/src/cordova/platform/addHelper.js b/src/cordova/platform/addHelper.js index d72f283b7..98793a700 100644 --- a/src/cordova/platform/addHelper.js +++ b/src/cordova/platform/addHelper.js @@ -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); } diff --git a/src/plugman/install.js b/src/plugman/install.js index 857a624a1..34e2a0d50 100644 --- a/src/plugman/install.js +++ b/src/plugman/install.js @@ -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 tag to be installed with - // engine with '-dev' or '-nightly' suffixes. It is required due to new semver range logic, - // introduced in semver@3.x. 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 })); }