[
https://issues.apache.org/jira/browse/CB-8754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14383991#comment-14383991
]
ASF subversion and git services commented on CB-8754:
-----------------------------------------------------
Commit 4ad1b3d8226df68db8ee26451554996b77399314 in cordova-lib's branch
refs/heads/master from [~TimBarham]
[ https://git-wip-us.apache.org/repos/asf?p=cordova-lib.git;h=4ad1b3d ]
CB-8754 Auto-restoring a plugin fails when adding a platform.
Start with a blank Cordova app, then enter the following:
cordova plugin add org.apache.cordova.camera --save
cordova plugin remove org.apache.cordova.camera
cordova platform add browser
The final step should restore the camera plugin, but it fails with the
following exception:
TypeError: Cannot read property 'latest' of undefined
at next
(D:\GIT\Cordova\cordova-lib\cordova-lib\node_modules\npm\lib\cache.js:694:35)
at
D:\GIT\Cordova\cordova-lib\cordova-lib\node_modules\npm\lib\cache.js:682:5
at RegClient.get_
(D:\GIT\Cordova\cordova-lib\cordova-lib\node_modules\npm\node_modules\npm-registry-client\lib\get.js:105:14)
at RegClient.<anonymous>
(D:\GIT\Cordova\cordova-lib\cordova-lib\node_modules\npm\node_modules\npm-registry-client\lib\get.js:41:12)
at fs.js:336:14
at
D:\GIT\Cordova\cordova-lib\cordova-lib\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:103:5
at FSReqWrap.oncomplete (fs.js:99:15)
The core problem here is an issue with how we work with npm. Every time we are
going to use npm (when dealing with plugins), we call npm.load() passing it our
settings. But npm.load() can only be called once per session - subsequent calls
are ignored. The correct approach is to call npm.load() without any settings
(to make sure npm is loaded), then call npm.config.set() for each setting.
This change had been made for platforms, but not plugins. I also wanted to make
sure each time we worked with npm we had a clean config (for example, if we get
an npm package from the Cordova plugin respository, then later from the npm
repository, it would try to get the second package from the CPR because that
setting would still be around and not get overridden). So now any code that
wants to load and init npm I pass through a central "load and restore" method.
You pass this method your npm settings and the chain of promises you want to
execute with those settings applied. It loads and initializes npm, executes the
promises, then restores npm's configuration to what it was before we started.
Finally, once that problem was fixed there was an additional problem - we were
adding plugins too early and the platform wasn't fully initialized, so we'd get
an error about not being able to find the platform's config.xml file.
> Auto-restoring a plugin fails when adding a platform
> ----------------------------------------------------
>
> Key: CB-8754
> URL: https://issues.apache.org/jira/browse/CB-8754
> Project: Apache Cordova
> Issue Type: Bug
> Components: CordovaLib
> Affects Versions: Master
> Reporter: Tim Barham
> Assignee: Tim Barham
> Original Estimate: 5h
> Remaining Estimate: 5h
>
> Start with a blank Cordova app, then enter the following:
> {noformat}
> cordova plugin add org.apache.cordova.camera --save
> cordova plugin remove org.apache.cordova.camera
> cordova platform add browser
> {noformat}
>
> The final step should restore the camera plugin, but it fails with the
> following exception:
> {noformat}
> TypeError: Cannot read property 'latest' of undefined
> at next
> (D:\GIT\Cordova\cordova-lib\cordova-lib\node_modules\npm\lib\cache.js:694:35)
> at
> D:\GIT\Cordova\cordova-lib\cordova-lib\node_modules\npm\lib\cache.js:682:5
> at RegClient.get_
> (D:\GIT\Cordova\cordova-lib\cordova-lib\node_modules\npm\node_modules\npm-registry-client\lib\get.js:105:14)
> at RegClient.<anonymous>
> (D:\GIT\Cordova\cordova-lib\cordova-lib\node_modules\npm\node_modules\npm-registry-client\lib\get.js:41:12)
> at fs.js:336:14
> at
> D:\GIT\Cordova\cordova-lib\cordova-lib\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:103:5
> at FSReqWrap.oncomplete (fs.js:99:15)
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]