[英]cordova platform add: adding second platform removes node modules for existing plugins and platforms
I am basically doing the following:我基本上在做以下事情:
cordova plugin add pluginA
cordova plugin add pluginC
cordova plugin add pluginX
cordova platform add android
This installs the plugins and cordova-android@8.1.0 which is there in node modules along with pluginA, pluginB and pluginC once the add completes.这会在添加完成后安装插件和 cordova-android@8.1.0,它们与 pluginA、pluginB 和 pluginC 一起存在于节点模块中。 I then do:-然后我做: -
cordova platform add ios@5
Installs cordova-ios, but removes cordova-android module and all the plugin modules from node_modules.安装 cordova-ios,但从 node_modules 中删除 cordova-android 模块和所有插件模块。 Doesn't remove the platform, just the node modules.不删除平台,只删除节点模块。
With npm timing turned on, I can see it running the following npm command, and that npm command removes cordova-android and the plugins打开 npm 计时,我可以看到它运行以下 npm 命令,并且 npm 命令删除了 cordova-android 和插件
1 verbose cli [
1 verbose cli '/usr/local/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'install',
1 verbose cli 'cordova-ios@5',
1 verbose cli '--production',
1 verbose cli '--save-exact'
1 verbose cli ]
I have managed to reproduce the issue with a basic project setup, based on my real project cut to the bone:根据我切入骨干的真实项目,我已经设法通过基本项目设置重现了该问题:
mkdir issue && cd issue && {
mkdir www
echo '{}' > build.json
cat >config.xml <<-EOF
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.mobile.test" version="0.0.1" android-versionCode="1"
xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<name>Test Client</name>
<description>Test Client</description>
<author email="user@email.com" href="http://www.yourcompany.com">Your Company</author>
<content src="index.html" />
<engine name="ios" spec="5" />
</widget>
EOF
cordova --verbose platform add --save android
cordova --verbose platform add --save ios@5
test ! -d node_modules/cordova-android \
&& echo "cordova-android has been removed"
}
From ~/.npm/_logs
I can see the following npm commands are executed:从~/.npm/_logs
我可以看到执行了以下 npm 命令:
/usr/local/bin/node /usr/local/bin/npm view cordova-custom-config --json
/usr/local/bin/node /usr/local/bin/npm install cordova-custom-config --production --save
/usr/local/bin/node /usr/local/bin/npm install cordova-android@^8.0.0 --production --save-exact
/usr/local/bin/node /usr/local/bin/npm install cordova-ios@5 --production --save-exact
And from the npm log for the install cordova-ios@5 can see that npm decided to uninstall cordova-android而从安装cordova-ios@5的npm日志可以看出npm决定卸载cordova-android
97 silly diffTrees remove cordova-android@8.1.0
98 silly diffTrees remove cordova-custom-config@5.1.0
NPM Version Information: NPM 版本信息:
2 info using npm@6.14.8
3 info using node@v14.15.1
Also, for reference, using these commands to enable npm logging:此外,作为参考,使用这些命令启用 npm 日志记录:
npm config set timing true
npm config set logs-max 10000
The behaviour is triggered by having a single <engine/>
node in config.xml
.该行为由config.xml
中的单个<engine/>
节点触发。 Specifying both engines, or no engines at all, the modules are not removed when adding a second platform.指定两个引擎,或根本不指定引擎,添加第二个平台时不会删除模块。
<engine name="ios" spec="5" />
<engine name="android" spec="8" />
The following config.xml
works.以下config.xml
有效。
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.mobile.test" version="0.0.1" android-versionCode="1"
xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<name>Test Client</name>
<description>Test Client</description>
<author email="user@email.com" href="http://www.yourcompany.com">Your Company</author>
<content src="index.html" />
</widget>
Quite why the <engine/>
node is influencing npm
to remove those modules I have no idea.不知道为什么<engine/>
节点会影响npm
删除那些模块。
The following script works, leaving both the plugins and cordova platforms intact.以下脚本有效,使插件和 cordova 平台保持不变。
mkdir issue && cd issue && {
mkdir www
echo "{}" >build.json
cat >config.xml <<-EOF
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.mobile.test" version="0.0.1" android-versionCode="1"
xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<name>Test Client</name>
<description>Test Client</description>
<author email="user@email.com" href="http://www.yourcompany.com">Your Company</author>
<content src="index.html" />
</widget>
EOF
cordova plugin add cordova-custom-config
cordova platform add --save android
cordova platform add --save ios@5
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.