apache / cordova-lib

Apache Cordova Tooling Library
https://cordova.apache.org/
Apache License 2.0
221 stars 243 forks source link

Failure to install plugin with url#git_ref:subdir spec #861

Closed Chuckytuh closed 3 years ago

Chuckytuh commented 3 years ago

Bug Report

There's a behavioural mismatch between documentation (cordova-cli doc, Website) and what really happens when cordova plugin add is used when attempting to install a plugin from a git repo by specifying git_ref and subdir.

Problem

What is expected to happen?

According to the documentation, one could do:

cordova plugin add https://github.com/Chuckytuh/cordova-swift-plugins-test\#0.0.1:cordova-outsystems-swiftplugin42

In order to install a plugin that is located in the provided github repo under the specified subdir.

What does actually happen?

Not what is documented. See:

23:36:55 ❯ cordova plugin add https://github.com/Chuckytuh/cordova-swift-plugins-test\#0.0.1:cordova-outsystems-swiftplugin42 --verbose
No scripts found for hook "before_plugin_add".
Calling plugman.fetch on plugin "https://github.com/Chuckytuh/cordova-swift-plugins-test#0.0.1:cordova-outsystems-swiftplugin42"
fetch: Installing https://github.com/Chuckytuh/cordova-swift-plugins-test#0.0.1:cordova-outsystems-swiftplugin42 to /Users/calcifer/Development/OutSystems/outsystems-mobile-rd/tmp/test-plugin-swift/myapp
Running command: npm install https://github.com/Chuckytuh/cordova-swift-plugins-test#0.0.1:cordova-outsystems-swiftplugin42 --save-dev
Command finished with error code 1: npm install,https://github.com/Chuckytuh/cordova-swift-plugins-test#0.0.1:cordova-outsystems-swiftplugin42,--save-dev
Failed to fetch plugin https://github.com/Chuckytuh/cordova-swift-plugins-test#0.0.1:cordova-outsystems-swiftplugin42 via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
CordovaError: Error: npm: Command failed with exit code 1 Error output:
npm ERR! code 128
npm ERR! Command failed: git checkout 0.0.1:cordova-outsystems-swiftplugin42
npm ERR! fatal: Cannot switch branch to a non-commit '0.0.1:cordova-outsystems-swiftplugin42'
npm ERR!

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/calcifer/.npm/_logs/2020-11-24T00_57_08_549Z-debug.log
CordovaError: Failed to fetch plugin https://github.com/Chuckytuh/cordova-swift-plugins-test#0.0.1:cordova-outsystems-swiftplugin42 via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
CordovaError: Error: npm: Command failed with exit code 1 Error output:
npm ERR! code 128
npm ERR! Command failed: git checkout 0.0.1:cordova-outsystems-swiftplugin42
npm ERR! fatal: Cannot switch branch to a non-commit '0.0.1:cordova-outsystems-swiftplugin42'
npm ERR!

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/calcifer/.npm/_logs/2020-11-24T00_57_08_549Z-debug.log
    at /Users/calcifer/.nodenv/versions/12.19.0/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/fetch.js:140:43
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Information

After debugging the install process, it is clear that cordova-lib is capable of parsing the required information from the URL (url, git_ref and subdir), sadly, when the times comes to fetch the plugin, cordova-fetch is executed which delegates to npm install, ending up failling because npm parses everything from # onwards as being the git_ref.

Command or Code

$ cordova create testapp
$ cd testapp
$ cordova platform add ios
$ cordova plugin add https://github.com/Chuckytuh/cordova-swift-plugins-test\#0.0.1:cordova-outsystems-swiftplugin42

Environment, Platform, Device

Both Android and iOS

Version information

Checklist

dpogue commented 3 years ago

The :subdir syntax is no longer supported since we rely on npm for managing the dependencies