Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ionic CLI reformatting config.xml #2230

Closed
jgw96 opened this issue May 8, 2017 · 42 comments
Closed

Ionic CLI reformatting config.xml #2230

jgw96 opened this issue May 8, 2017 · 42 comments
Milestone

Comments

@jgw96
Copy link
Contributor

jgw96 commented May 8, 2017

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: ionic-team/ionic-framework#11558

@jgw96
Copy link
Contributor Author

jgw96 commented May 8, 2017

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
Copy link
Contributor Author

jgw96 commented May 8, 2017

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 jgw96 added v2 labels May 8, 2017
@jgw96
Copy link
Contributor Author

jgw96 commented May 8, 2017

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
Copy link
Contributor Author

jgw96 commented May 8, 2017

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
Copy link
Contributor Author

jgw96 commented May 8, 2017

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

@imhoffd
Copy link
Contributor

imhoffd commented May 8, 2017

@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 imhoffd changed the title Ionic CLI reformatting config.xml and package.json Ionic CLI reformatting config.xml May 8, 2017
@imhoffd imhoffd added v3 and removed needs info labels May 8, 2017
@imhoffd
Copy link
Contributor

imhoffd commented May 8, 2017

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

@jthoms1
Copy link
Contributor

jthoms1 commented May 8, 2017

@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
Copy link

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
Copy link

mburger81 commented May 9, 2017

@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
Copy link
Contributor

imhoffd commented May 9, 2017

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

@ghost
Copy link

ghost commented May 9, 2017

@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
Copy link
Contributor

imhoffd commented May 9, 2017

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

  • ionic state is being removed in CLI v3.
  • cordovaPlugins and cordovaPlatforms are created/modified by ionic state, not Cordova
  • Cordova uses the cordova node on your package.json

@Sh1d0w
Copy link

Sh1d0w commented May 10, 2017

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
Copy link

mburger81 commented May 10, 2017

@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
Copy link

acuntex commented Jun 20, 2017

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".

  • Random changes of indents (from 8 whitespaces to 4)
  • Changes of the node order (e.g. "cordova-android": "^6.2.3" gets moved up and down)
  • Changes of the attribute order (e.g. <icon src="resources/android/icon/drawable-xxxhdpi-icon.png" density="xxxhdpi"/> becomes <icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png"/>
  • <?xml version="1.0" encoding="UTF-8" standalone="yes"?> becomes <?xml version='1.0' encoding='utf-8'?>
  • Unasked version changes when adding platform (e.g. ionic platform add android changes "cordova.plugins.diagnostic": "3.6.4" to "cordova.plugins.diagnostic": "^3.6.4" thus breaking the build because it's downloading 3.6.5 and this would be "not an issue with with v3.6.5, but a knock-on effect of the alpha versions of Android Support Libraries permeating the Gradle versioning system" according to Problem with cordova build with cordova-diagnostic-plugin@3.6.5 dpa99c/cordova-diagnostic-plugin#216

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
Copy link

@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 �[2K�[G> cordova platform add android --save �[2K�[G⠙ Running command �[2K�[G⠹ Running command �[2K�[G⠸ Running command �[2K�[G⠼ Running command �[2K�[G⠴ Running command �[2K�[G⠦ Running command �[2K�[G⠧ Running command �[2K�[G⠇ Running command �[2K�[G⠏ Running command �[2K�[G⠋ Running command �[2K�[G⠙ Running command �[2K�[G⠹ Running command �[2K�[G⠸ Running command �[2K�[G⠼ Running command �[2K�[G⠴ Running command �[2K�[G⠦ Running command...

@arcreative
Copy link

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
Copy link

acuntex commented Jul 4, 2017

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
Copy link

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

@imhoffd imhoffd added this to the CLI Future milestone Jul 10, 2017
@uloco
Copy link

uloco commented Feb 5, 2018

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
Copy link
Contributor

imhoffd commented Feb 5, 2018

@uloco @peterpan666 ionic info ? No one has mentioned this since CLI 3.7.0 (August 2017) which includes this commit: 2b93ce2

@uloco
Copy link

uloco commented Feb 5, 2018

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
Copy link
Contributor

imhoffd commented Feb 5, 2018

@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
Copy link

uloco commented Feb 5, 2018

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
Copy link

uloco commented Feb 5, 2018

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
Copy link
Contributor

imhoffd commented Feb 5, 2018

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
Copy link

uloco commented Feb 6, 2018

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
Copy link
Contributor

imhoffd commented Feb 6, 2018

@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

  • Show the first few lines of config.xml, which is shown to have 2 space indentation.
  • Spin up chokidar to watch config.xml and print the head of the file whenever it changes, with a 1 second debounce.
$ 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

  • Invoke Cordova CLI w/o Ionic.
$ cordova run android

Terminal 1

  • Cordova CLI appears to trigger 3 change events. The events are debounced and the head of the file is printed, shown to have 4 space indentation.
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

  • Show the first few lines of config.xml, which is shown to have 2 space indentation.
  • Spin up chokidar to watch config.xml and print the head of the file whenever it changes, with a 1 second debounce.
$ 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

  • Invoke Ionic CLI with livereload. This command runs serve from @ionic/app-scripts and the Cordova CLI.
$ ionic cordova run android -l

Terminal 1

  • The Ionic CLI writes to config.xml one time before the Cordova CLI triggers its 3 file changes. The Ionic CLI writes 4 space indentation, and the Cordova CLI does as well.
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

  • CTRL-C to exit livereload process.
^C

Terminal 1

  • Observe additional write(s) as the Ionic CLI cleans up after itself (reset <content src=" ... "). The file is shown to have 4 space indentation.
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
Copy link

uloco commented Feb 7, 2018

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
Copy link

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

@kensodemann
Copy link
Member

@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
Copy link

TKlarissa commented Apr 20, 2018 via email

@kensodemann
Copy link
Member

kensodemann commented Apr 20, 2018

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

@TKlarissa
Copy link

TKlarissa commented Apr 20, 2018 via email

@kensodemann
Copy link
Member

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

@TKlarissa
Copy link

TKlarissa commented Apr 20, 2018 via email

@Sh1d0w
Copy link

Sh1d0w commented Apr 20, 2018

@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
Copy link

TKlarissa commented Apr 20, 2018 via email

@kensodemann
Copy link
Member

@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
Copy link

TKlarissa commented Apr 20, 2018 via email

@TKlarissa
Copy link

TKlarissa commented Apr 20, 2018 via email

@ionic-team ionic-team locked and limited conversation to collaborators Apr 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests