ionic-team / ionic-cli

The Ionic command-line interface
MIT License
2k stars 641 forks source link

Ionic CLI reformatting config.xml #2230

Closed jgw96 closed 6 years ago

jgw96 commented 7 years ago

From @arcreative on May 8, 2017 14:12

Ionic version: (check one with "x") [X] 1.x [ ] 2.x [ ] 3.x

Note: just the CLI, don't think the project version matters here

I'm submitting a ... (check one with "x") [X] bug report [ ] feature request [ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior: ionic build ios completely rewrites my config.xml and package.json files with trivial whitespace and other changes. There could be breaking changes, but it's very hard to tell because everything is completely rearranged.

Expected behavior: Leave my stuff alone!

Steps to reproduce: run ionic build ios

Copied from original issue: driftyco/ionic#11558

jgw96 commented 7 years ago

Hey! Thanks for opening an issue with us. What version of the cli are you running? (you can get this info from running ionic-info in your project directory)

jgw96 commented 7 years ago

From @arcreative on May 8, 2017 15:23

Oops, sorry! Looks like 2.2.3:

Your system information:

Cordova CLI: 7.0.0
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
ios-deploy version: 1.8.5
ios-sim version: 3.1.1
OS: macOS Sierra
Node Version: v6.10.3
Xcode version: Xcode 8.3.2 Build version 8E2002
jgw96 commented 7 years ago

All good, thanks for the info! Would you mind installing the latest beta version of the cli (instructions here) and seeing if you have the same issue? Also, just to confirm, you are using ionic 1 right?

jgw96 commented 7 years ago

From @mburger81 on May 8, 2017 19:4

I can confirm cli often rewrites config.xml and git has big diffs. I'm using cli 3 rc2

jgw96 commented 7 years ago

Hmm interesting. Going to go ahead and move this issue to the CLI repo then. Thanks for the info.

imhoffd commented 7 years ago

@arcreative @mburger81 This is a known issue that I'd like to look at in the future. Unfortunately, we need to modify the config.xml file for resource generation and livereloading. The xml libraries in node don't detect the indentation level, so we use the same indentation as Cordova: 4 spaces. The problem is, our starters had 2 spaces for a long time, so your app, as well as many others, likely have config.xml files that are indented with 2 spaces. This means upon the first 'cordova' command, your config.xml file is rewritten. But there shouldn't be any breaking changes, unless there's a bug in our xml library. Perhaps we can limit this by detecting whether or not we need to write the file, @jthoms1 ?

imhoffd commented 7 years ago

@mburger81 if you play around with it, it shouldn't do a subsequent massive diff after the first one

jthoms1 commented 7 years ago

@mburger81 With the new release of Ionic v3 we will no longer be modifying the package.json file. Also the config.xml rewrite will only occur only with 'ionic cordova run' or 'ionic cordova emulate'. That being said I second the comment by @dwieeb there isn't a good way to prevent the rewrite of config.xml.

mburger81 commented 7 years ago

Infact biggest change is after using cordova commands and package.json is not changed. For me is not a problem, I only confirmed the "issue" But by the way it is not very beautiful after run a command which does nothing change the entiere file results changed. After commiting this it remains the same for a while. Perhapse we install some new plugins or other before the issue comes ot again. But as I said, that's for sure not a problem!

Thx for your great work :)

mburger81 commented 7 years ago

@dwieeb @jthoms1 I installed latest cordova@7.0.0 with sudo npm -g install ionic@latest and remove android platform using cordova platforms remove android Then I simple run ionic cordova emulate android -lc which automatically adds the android paltform. But after doing this, I see some changes in my config.xml but the package.json changed a lot!

New in dependencies are:

"cordova-android": "^6.2.3",
"cordova-plugin-console": "1.0.5",
"cordova-plugin-crosswalk-webview": "~2.3.0",
"cordova-plugin-device": "1.1.4",
"cordova-plugin-network-information": "~1.3.3",
"cordova-plugin-splashscreen": "~4.0.1",
"cordova-plugin-statusbar": "2.2.1",
"cordova-plugin-whitelist": "1.3.1",
"ionic-plugin-keyboard": "~2.2.1"

and there is a new node

    "cordova": {
        "plugins": {
            "cordova-plugin-console": {},
            "cordova-plugin-crosswalk-webview": {},
            "cordova-plugin-device": {},
            "cordova-plugin-network-information": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-statusbar": {},
            "cordova-plugin-whitelist": {},
            "ionic-plugin-keyboard": {}
        },
        "platforms": [
            "android"
        ]
    }

Do you think this is okay? It is a lot of changes and not the default I saw before using ionic.

Why I'm trying to use cordova 7 instead of 6.5.0?.

Upgrading sdk tools to 26.0.x I'm running in the famous bug: Could not find an installed version of Gradle This should be resolved on cordova's android@6.2.3, but I still have the problem!

Edit: Now on sdk tools to 26.0.3 you have to install grade manually sudo apt-get install gradle

But remains the question about this many installed plugins and new nodes! for example ionic cordova plugin add cordova-plugin-network-information--save

adds this node to package.json

"cordova": {
        "plugins": {
            "cordova-plugin-network-information": {}
        }
}

Is this okay?

imhoffd commented 7 years ago

@mburger81 Yes, this is all expected behavior. See https://cordova.apache.org/news/2017/05/04/cordova-7.html

ghost commented 7 years ago

@dwieeb Thanks for the information. Does it make sense to keep the cordova plugins, listed as ionic-native npm dependencies now? Would that cause any sort of duplication? What about the cordovaPlugins and cordovaPlatforms nodes in package.json? Those information should be available to cli (for ionic state functionalities) from the recently added cordova node. Right?

imhoffd commented 7 years ago

@Maziar-Fotouhi I updated CHANGELOG.md to hopefully clear some things up.

Sh1d0w commented 7 years ago

There is an amazing library that detects the indentation for JSON files. The algorithm is very simple, probably can be used as well for xml files?

https://github.com/sindresorhus/detect-indent#algorithm

mburger81 commented 7 years ago

@dwieeb Okay, but honestly I didn't figured out in your link something about cordova-plugin-console and other dependencies added to package.json

And in my opinion there is a other thing I really don't understand and I'm really not sure. ionic cordova emulate android adds this new dependencies in package.json

"cordova-android": "6.2.3",
"cordova-plugin-console": "1.0.5",
"cordova-plugin-crosswalk-webview": "~2.3.0",
"cordova-plugin-device": "1.1.4",
"cordova-plugin-splashscreen": "~4.0.1",
"cordova-plugin-statusbar": "2.2.1",
"cordova-plugin-whitelist": "1.3.1",
"ionic-plugin-keyboard": "~2.2.1"

But in the node_modules folder there is only cordova-android installed, so no other plugins. But Splashscreen, webview, statusbar and other are working without any issues.

Only after run again npm install, there are installed the new cordova plugins in node_mdoules folder. I'm not sure about the ionic-plugin-keyboard if it was there beforee, I didn't look for it. sorry.

Do you think this behavior is right?

Edit: Also @Maziar-Fotouhi wrote about the npm dependencies, but in your response you wrote cordova is using cordova node, but now there are many cordvoa DEPENDENCIES which in my opinion doesn't make sense, because if they are not installed it does work just the same.

acuntex commented 6 years ago

We are also having a lot of problems with this permanent automatic config.xml- and package.json-changes since the ionic-cli has been "renewed".

And the biggest problem is that all changes seem to be vice-versa, so it's a continuous backward and forward.

Most of the problems are just formatting problems. But if you have a bigger team and there are concurrent edits, there are always merge problems because almost every line has been changed which costs a lot of time and money.

The version problem is a big deal because this is really breaking the builds.

As side note: I cannot even blame my developers for negligence because they blame the tools and the acceptance of ionic/cordova is constantly dropping mostly among native developers. :(

Without any reproaches, but in all my frustration I'm asking myself why there were that many changes in the xml- and json-serialization in the ionic-cli version with the fancy "⠧ Running command-Screen" that were really necessary? It worked perfectly before :(

Edit: And while writing this, there is suddenly something new: It's now adding "es6-promise-plugin" without even asking or telling me why the heck he is adding further code to my project which is not really trustworthy.

corran2go commented 6 years ago

@acuntex perfectly described all the major pain points I'm also experiencing.

This leads to further errors as one tends to revert the changes in config.xml and package.json because they change constantly from one formating to the other.

Also the fancy "⠧ Running command-Screen" leads to tons of logs on our build servers: + ionic cordova platform add android > cordova platform add android --save ⠙ Running command ⠹ Running command ⠸ Running command ⠼ Running command ⠴ Running command ⠦ Running command ⠧ Running command ⠇ Running command ⠏ Running command ⠋ Running command ⠙ Running command ⠹ Running command ⠸ Running command ⠼ Running command ⠴ Running command ⠦ Running command...

arcreative commented 6 years ago

Agreed with @acuntex and @corran2go. I'm getting really really close to abandoning the CLI entirely (aside from ionic start ...) as its lack of support for a true build process has led me to use gulp directly. There's very little left that Ionic CLI does that doesn't frustrate me. Fixing these issues would alleviate that somewhat.

acuntex commented 6 years ago

The bug is open for 2 month now, I don't think there is going to happen anything soon. Since the ionic team has gone commercial (ionic.io paid services) this seems to be the top priority. Unless they realize that disregarding the community will lead to less users and therefore less profit there won't be any change.

@arcreative Any chance you could inspire us so we can get rid of ionic-cli? :)

arcreative commented 6 years ago

@acuntex I have a pretty sweet gulpfile that just needs a bit more tweaking, will see if I can share it shortly.

uloco commented 6 years ago

Running ionic cordova commands still rewrites package.json (new line at the end of file gets removed everytime) and config.xml (formatting to 4 spaces, single quotes and new line at the end of file gets added). Working with npm also rewrites package.json and changes some stuff (adding a newline at eof). How can one not get crazy about this guys. Tell me where to fix this, and I will do my very best to accomplish. This bug is now present for months but nobody cares. I cannot stand this anymore.

imhoffd commented 6 years ago

@uloco @peterpan666 ionic info ? No one has mentioned this since CLI 3.7.0 (August 2017) which includes this commit: https://github.com/ionic-team/ionic-cli/commit/2b93ce279387122ab69bdb93f82c09422809b646

uloco commented 6 years ago

cli packages:

@ionic/cli-plugin-proxy : 1.5.6
@ionic/cli-utils        : 1.19.0
ionic (Ionic CLI)       : 3.19.0

global packages:

cordova (Cordova CLI) : 7.1.0

local packages:

@ionic/app-scripts : 3.1.4
Cordova Platforms  : android 6.4.0 ios 4.5.4
Ionic Framework    : ionic-angular 3.9.2

System:

Android SDK Tools : 26.1.1
ios-deploy        : 1.9.2
Node              : v9.4.0
npm               : 5.6.0
OS                : macOS High Sierra
Xcode             : Xcode 9.2 Build version 9C40b
imhoffd commented 6 years ago

@uloco Does it happen with every command invocation, or just when it downloads platforms/plugins? Can you verify whether it's ionic or cordova by running just the cordova CLI directly and observing file changes? Both CLIs read and write to these files.

uloco commented 6 years ago

It should be noted, that my config.xml file should have 2 space indentation, because I am using this everywhere. I don't want to use different style for different file types. Everytime I run ionic cordova xyz it rewrites my stuff. Each time I start the emulator or run it on a device, no matter what, it rewrites both files package.json and config.xml. It does not matter if all dependencies are already installed. Running cordova only yields the same problem.

uloco commented 6 years ago

I think this is a cordova issue. But the problem is still present since months and your commit did not change anything regarding this problem for me. I thought you were addressing this issue in your commit. If this wasn't your intention, than I think this could be the wrong place for this...

imhoffd commented 6 years ago

My commit is reconciling package.json and config.xml modifications between ionic and cordova. Previously, because they were using different libraries, they would overwrite each other's changes with different styles nearly every time either command was run, which was really annoying.

Unfortunately Cordova doesn't offer indentation detection or configuration for config.xml, so the best we can do is follow along until this is a feature (but I doubt it will be).

If this is a huge annoyance, I recommend using a precommit git hook that runs an xml formatter.

uloco commented 6 years ago

I have written a cordova hook for reformatting config.xml in the after_prepare step. (I dont want to make my git repo dirty, if there are no changes I bother, so git hooks are no option for me.) The funny thing about this is the following: During ionic cordova run the file gets the expected indentation, and after the cli is done building, config.xml gets the 4 space indentation again. This only happens in combination with ionic. Running cordova alone yields the expected effect. Perhaps your commit is messing things up then... Do you have an idea how to overcome this behaviour? Perhaps another hook type?

imhoffd commented 6 years ago

@uloco The Ionic CLI rewrites config.xml to have 4 spaces because that's exactly what the Cordova CLI does as well. If you have a hook in after_prepare, it will run after the Cordova prepare step, which happens in the middle of ionic cordova run. You're invoking a formatter in the middle of an operation that rewrites config.xml multiple times.

Unfortunately, the CLI hooks available today aren't sufficient for your use case. They're only useful for running stuff before/after the build/serve process. For CLI v4, I am building a hook system which may evolve into supporting your use case, but I haven't heard much demand for this. It seems the vast majority of people are okay with 4 spaces in an xml file, but I can see why it's annoying.

For the time being, the best thing I can think of is running ionic cordova run ... ; ./scripts/my-formatter so that it always runs after the Ionic CLI (use a semicolon to separate the commands, not &&). You can then add this to an npm script to shorten it for your daily development.

The following is expected behavior today. You can see why formatting the file during after_prepare may not work:

Cordova

Terminal 1

$ head config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.ionic.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>cdvapp</name>
  <description>An awesome Ionic/Cordova app.</description>
  <author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
  <content src="index.html" />
  <access origin="*" />
  <allow-intent href="http://*/*" />
  <allow-intent href="https://*/*" />
  <allow-intent href="tel:*" />
$ chokidar -d 1000 -c 'head config.xml' config.xml
Watching "config.xml" ..

Terminal 2

$ cordova run android

Terminal 1

change:config.xml
change:config.xml
change:config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.ionic.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>cdvapp</name>
    <description>An awesome Ionic/Cordova app.</description>
    <author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />

Ionic

Terminal 1

$ head config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.ionic.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>cdvapp</name>
  <description>An awesome Ionic/Cordova app.</description>
  <author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
  <content src="index.html" />
  <access origin="*" />
  <allow-intent href="http://*/*" />
  <allow-intent href="https://*/*" />
  <allow-intent href="tel:*" />
$ chokidar -d 1000 -c 'head config.xml' config.xml
Watching "config.xml" ..

Terminal 2

$ ionic cordova run android -l

Terminal 1

change:config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.ionic.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>cdvapp</name>
    <description>An awesome Ionic/Cordova app.</description>
    <author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
change:config.xml
change:config.xml
change:config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.ionic.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>cdvapp</name>
    <description>An awesome Ionic/Cordova app.</description>
    <author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
    <content original-src="index.html" src="http://10.0.128.17:8100" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />

Terminal 2

^C

Terminal 1

change:config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.ionic.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>cdvapp</name>
    <description>An awesome Ionic/Cordova app.</description>
    <author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
change:config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.ionic.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>cdvapp</name>
    <description>An awesome Ionic/Cordova app.</description>
    <author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
uloco commented 6 years ago

Thank you very much for your in depth explanation. This is another reason to keep on sticking to the ionic-team. You do your job quite well :)

TKlarissa commented 6 years ago

Hi here please i need urgent help ...my ionic project do not have the config.xml file ....how can i add one thanks

kensodemann commented 6 years ago

@TKlarissa - if you answered "No" to the "Cordova" question when doing ionic start to create your app, you will not have a config.xml file. It will be generated, though, if you later add Cordova integration via ionic cordova platform add ios or ionic cordova platform add android

TKlarissa commented 6 years ago

i just tried ionic cordova platform add android and i had the error "Error: ENOENT: no such file or directory, open '/home/larissa/maibeta/myapplication/config.xml' "

On 20 April 2018 at 13:54, Ken Sodemann notifications@github.com wrote:

@TKlarissa https://github.com/TKlarissa - if you answered "No" to the "Cordova" question when doing ionic start to create your app, you will not have a config.xml file. It will be generated, though, if you later add Cordova integration via ionic cordova platform add ios or ionic cordova platform add android

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ionic-team/ionic-cli/issues/2230#issuecomment-383086642, or mute the thread https://github.com/notifications/unsubscribe-auth/AkTlbI1bdyLgOe-N-MI56cpLh1dbJ6aWks5tqdqfgaJpZM4NUYem .

kensodemann commented 6 years ago

@TKlarissa - what version of the CLI are you using? Please provide the output of ionic info

TKlarissa commented 6 years ago

please give me a solution to this please it is quit urgent

On 20 April 2018 at 14:03, Ines Larissa Koyoue koyouelarissa95@gmail.com wrote:

i just tried ionic cordova platform add android and i had the error "Error: ENOENT: no such file or directory, open '/home/larissa/maibeta/ myapplication/config.xml' "

On 20 April 2018 at 13:54, Ken Sodemann notifications@github.com wrote:

@TKlarissa https://github.com/TKlarissa - if you answered "No" to the "Cordova" question when doing ionic start to create your app, you will not have a config.xml file. It will be generated, though, if you later add Cordova integration via ionic cordova platform add ios or ionic cordova platform add android

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ionic-team/ionic-cli/issues/2230#issuecomment-383086642, or mute the thread https://github.com/notifications/unsubscribe-auth/AkTlbI1bdyLgOe-N-MI56cpLh1dbJ6aWks5tqdqfgaJpZM4NUYem .

kensodemann commented 6 years ago

I am trying to, but I need the information I asked for in my prior msg (output of ionic info)

TKlarissa commented 6 years ago
@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

On 20 April 2018 at 14:11, Ken Sodemann notifications@github.com wrote:

I am trying to, but I need the information I asked for in my prior msg (output of ionic info)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ionic-team/ionic-cli/issues/2230#issuecomment-383090971, or mute the thread https://github.com/notifications/unsubscribe-auth/AkTlbNUHgIZemfAXlrnig_rL6s-WiurTks5tqd5sgaJpZM4NUYem .

Sh1d0w commented 6 years ago

@TKlarissa This is not a chat or support forum. Please stop spamming all of us with your posts, use Ionic forums instead if you need help.

TKlarissa commented 6 years ago

cordova (Cordova CLI) : 8.0.0

On 20 April 2018 at 14:14, Ines Larissa Koyoue koyouelarissa95@gmail.com wrote:

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

On 20 April 2018 at 14:11, Ken Sodemann notifications@github.com wrote:

I am trying to, but I need the information I asked for in my prior msg (output of ionic info)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ionic-team/ionic-cli/issues/2230#issuecomment-383090971, or mute the thread https://github.com/notifications/unsubscribe-auth/AkTlbNUHgIZemfAXlrnig_rL6s-WiurTks5tqd5sgaJpZM4NUYem .

kensodemann commented 6 years ago

@TKlarissa - OK, so you are up to date. Why not just generate a new project using ionic start, be sure to answer "Yes" to the Cordova question, copy the config.xml from there, and then copy it over and change as appropriate.

If at that point you are still having issues, please go to the support forum and post something there (https://forum.ionicframework.com)

TKlarissa commented 6 years ago

Can I have the link to the forum ?

On Fri, Apr 20, 2018, 14:15 Radoslav Vitanov notifications@github.com wrote:

@TKlarissa https://github.com/TKlarissa This is not a chat or support forum. Please stop spamming all of us with your posts, use Ionic forums instead if you need help.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ionic-team/ionic-cli/issues/2230#issuecomment-383092238, or mute the thread https://github.com/notifications/unsubscribe-auth/AkTlbDqxrOWU04C7Jg6vF2NQqlTdXOLzks5tqd9_gaJpZM4NUYem .

TKlarissa commented 6 years ago

Ok thanks for your help let me try it

On Fri, Apr 20, 2018, 14:21 Ines Larissa Koyoue koyouelarissa95@gmail.com wrote:

Can I have the link to the forum ?

On Fri, Apr 20, 2018, 14:15 Radoslav Vitanov notifications@github.com wrote:

@TKlarissa https://github.com/TKlarissa This is not a chat or support forum. Please stop spamming all of us with your posts, use Ionic forums instead if you need help.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ionic-team/ionic-cli/issues/2230#issuecomment-383092238, or mute the thread https://github.com/notifications/unsubscribe-auth/AkTlbDqxrOWU04C7Jg6vF2NQqlTdXOLzks5tqd9_gaJpZM4NUYem .