guyromb / cordova-open-native-settings

Plugin to open native screens of iOS/android settings (maintained, end-2020)
http://gsrweb.net
MIT License
113 stars 105 forks source link

Fix/plugin package id sync #10

Closed emcniece closed 7 years ago

emcniece commented 7 years ago

It turns out that while the publish to NPM solved our Ionic/Cordova resolution errors, Cordova has some behaviour where it updates package.json with each plugin as a Dependency, along with updating config.xml with the usual plugin details.

Because this repo is published at https://www.npmjs.com/package/cordova-open-native-settings, npm install cordova-open-native-settings causes this repo to be added to package.json as this:

"dependencies": {
...
  "cordova-open-native-settings": "~1.3.0",
...
}

However when Cordova reconciles the plugin repo on npmjs.com (cordova-open-native-settings) it adds the plugin ID to package.json instead of the NPM repo name, which creates this:

"dependencies": {
...
  "cordova-open-native-settings": "~1.3.0",
  "com.phonegap.plugins.nativesettingsopener": "^1.3.0",
...
}

This new package.json now fails to npm install because the plugin ID as a dependency isn't an actual NPM package.

I think the plugin needs to be published to NPM as its plugin ID, not as the package.json name. To confirm this behaviour, I published the plugin to a private registry:

plugin in private registry

After adjusting my project to pull from this private registry, the install process worked mostly as expected:

# ionic cordova plugin add com.phonegap.plugins.nativesettingsopener
✔ Creating ./www directory for you - done!
> cordova plugin add com.phonegap.plugins.nativesettingsopener --save
✔ Running command - done!
Adding net.gsrweb.cordova.plugins.cordovaopennativesettings to package.json
Saved plugin info for "net.gsrweb.cordova.plugins.cordovaopennativesettings" to config.xml

... but as you can see, Cordova parses the NPM repo and adds the plugin ID to package.json, and in this case net.gsrweb.cordova.plugins.cordovaopennativesettings is not a valid repository so if this change gets committed, any build after this point will result in a failure to obtain the plugin.

This PR is a 2-step fix for these problems. Contained here are some changes:

... and to make this fully functional, this plugin will need to be published to NPM as its plugin ID (net.gsrweb.cordova.plugins.cordovaopennativesettings). Now that the package.json name is the same as the plugin ID, the procedure is simply npm publish after merging this PR.

@guyromb as maintainer of this project, I think it makes sense for you to perform the merge and publish! Please let me know if it's a hassle and perhaps we can publish in a different way.

emcniece commented 7 years ago

@guyromb thanks for merging this! Sorry to bother you - final needed step is executing npm publish to ensure that this exists at https://www.npmjs.com/package/net.gsrweb.cordova.plugins.cordovaopennativesettings

This means that you could unpublish https://www.npmjs.com/package/cordova-open-native-settings as well.

guyromb commented 7 years ago

@emcniece I changed everything to cordova-open-native-settings, so it will be consistent. Can you confirm if you still have issues?

Thanks

emcniece commented 7 years ago

@guyromb Confirmed working!

✗ ionic cordova plugin add cordova-open-native-settings
> cordova plugin add cordova-open-native-settings --save
✔ Running command - done!
Installing "cordova-open-native-settings" for android
Installing "cordova-open-native-settings" for browser
Installing "cordova-open-native-settings" for ios
Adding cordova-open-native-settings to package.json
Saved plugin info for "cordova-open-native-settings" to config.xml

Thanks so much for your help.

guyromb commented 7 years ago

Thank you @emcniece