This is an automated email from the ASF dual-hosted git repository.

erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-lib.git


The following commit(s) were added to refs/heads/master by this push:
     new 1bdb0d3c fix: platform & plugin prerelease package support (#935)
1bdb0d3c is described below

commit 1bdb0d3ccfa46b0f0512518de5af5ed8865eb312
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Mon Oct 28 10:52:20 2024 +0900

    fix: platform & plugin prerelease package support (#935)
---
 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 a2c12847..c630d408 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);
                         // <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', () => {
@@ -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 d72f283b..98793a70 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 857a624a..34e2a0d5 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 <engine> 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 }));
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to