stovmascript / react-native-version

:1234: Version your React Native or Expo app in a `npm version` fashion.
MIT License
576 stars 75 forks source link

Crashing on Windows 10 for iOS #38

Closed VinceBT closed 6 years ago

VinceBT commented 6 years ago

image

And Git tells that not a single modification has been done

cvvspb commented 6 years ago

image

Same

stovmascript commented 6 years ago

How are you building iOS apps on Windows? It's not supported by React Native.

VinceBT commented 6 years ago

So you are meaning that I need to have a Mac in order to update a string indicating a version number in some file ;) ?

At least give a meaningful error message.

stovmascript commented 6 years ago

No, but in case you haven't noticed, this package is prefixed with react-native-, so one would assume it would follow the platform support of the react-native package. If you want to "update a string in some file", you can write your own script ;)

I would like to look into this, but before I start spending my free time doing it, it would be nice to have some more info, like the question I asked.

VinceBT commented 6 years ago

In case you haven't noticed, I'm not the only one that wants to increase their app version for Android AND iOS at the same time when coding in Windows before using a Mac and building it instantly after pulling the code.

Coding in Windows, building Android on Windows and building iOS on a rented Mac.

stovmascript commented 6 years ago

I noticed and that's why I asked the question.

Anyway, thanks for providing some info about your setup. Now I can see how you're using the tool and how Windows users might be using RN with two machines. It makes sense to support Windows right away and I'll look into it.

VinceBT commented 6 years ago

Thanks for your attention to this issue. I'm seeing no reason why this may fail on Windows, maybe the pbxproj parser ?

stovmascript commented 6 years ago

The pbxproj parser should be pretty cross platform. Actually added it to start supporting Linux and move away from Apple's agvtool. But there are some shell commands executed with node that might be causing the issue. There's actually a open PR #44 to deal with Git tag updating not working on Windows. There might be more commands causing the issue.

cvvspb commented 6 years ago

Hi there! As @VinceBT has already mentioned, it is pretty common for a react-native app developer to have two build machines. Personally, I use Windows 10 notebook to build Android app version and Macbook to build for iOS. I would use the same version number for both platforms and I would like to have an opportunity to bump version on any of the notebooks.

What is interesting: I have 2 react-native apps in a single repository, each of them targeting 2 versions: iOS and Android. For one of the apps, react-native-version fails with the undefined error message mentioned above. For the other one, it updates both android build.gradle and iOS Info.plist/pbxproj just fine.

I'm willing to contribute, so I'm going to have a closer look at this issue today.

cvvspb commented 6 years ago

Looks like it's a pbxproj-dom issue in my case. Exception is thrown here: const xcode = Xcode.open(path.join(projectFolder, "project.pbxproj"));

Xcode.js:

Xcode.open = function (path) { var xcode = new Xcode(); xcode.document = pbx.parse(parser.parse(fs.readFileSync(path).toString())); xcode.path = path; return xcode; };

parser.parse throws this: SyntaxError: Expected "\"", "\'", "\\"", "\n", or [^\"] but "\" found. at peg$buildStructuredError (C:\Users\cvv\Projects\react-native-version\node_modules\pbxproj-dom\parser.js:318:12) at Object.peg$parse [as parse] (C:\Users\cvv\Projects\react-native-version\node_modules\pbxproj-dom\parser.js:921:11) at Function.Xcode.open (C:\Users\cvv\Projects\react-native-version\node_modules\pbxproj-dom\xcode.js:16:43) at C:\Users\cvv\Projects\react-native-version\index.js:241:25 at new Promise () at Object.version (C:\Users\cvv\Projects\react-native-version\index.js:170:9) at Object. (C:\Users\cvv\Projects\react-native-version\cli.js:50:5) at Module._compile (module.js:632:14) at Object.Module._extensions..js (module.js:646:10) at Module.load (module.js:554:32)

I'm going to double-check pbxproj structure.

It would be great if react-native-version could just pass the error to the console instead of vague "[RNV] undefined" message

stovmascript commented 6 years ago

@cvvspb Thanks for looking into it.

For the case of 2 RN projects in one repo. Could you provide a sample tree view to see how the repo is structured and also the method how you execute RNV?

cvvspb commented 6 years ago

@stovmascript, the repo structure is very simple: /RootFolder/ /RootFolder/Project1 (react-native app 1) /RootFolder/Project1/js/.... /RootFolder/Project1/android/.... /RootFolder/Project1/ios/.... /RootFolder/Project1/package.json .... /RootFolder/Project2 (react-native app 2) /RootFolder/Project2/js/.... /RootFolder/Project2/android/.... /RootFolder/Project2/ios/.... /RootFolder/Project2/package.json ... /RootFolder/Backend (Project3 - node.js app) ...

I executed RNV in each of the projects separately. As I've mentioned earlier, the problem was in project.pbxproj file - it got corrupted after some "react-native link" commands. XCode didn't notice invalid entries but pbxproj-dom did throw an exception while parsing.

I've fixed project.pbxproj file and now it works OK!

stovmascript commented 6 years ago

@cvvspb Ok. Yeah, I admit error forwarding needs some work (#15).

cvvspb commented 6 years ago

There is one more thing: there is an issue with git tags if someone uses the same approach as I do (two or more separate apps in a single repo with different versions). Basic setup doesn't allow this, 'cause if the version of, say, app 1 is 0.5.0 and version of app 2 is 0.4.5 and you want to bump app 2 to 0.5.0 git wouldn't allow to have 2 tags like "v0.5.0" I had to prefix tags with project name to solve the issue, like: "Project1-v0.5.0", "Project2-v0.5.0" I could write a little how-to if required.

stovmascript commented 6 years ago

@VinceBT @cvvspb Hey guys, can you update and test the new version of RNV (2.5.0)? It contains the aforementioned PR #44, which fixes the Git tag issue on Windows. I just started looking into this issue and testing on Windows and everything seems to be working:

clipboard01

Tested on the same fixture I run tests on.

Edit: Updated link to test fixture.

VinceBT commented 6 years ago

Having almost the same error than before.

Its is not saying [RNV] undefined anymore now.

$ npm version major
v2.0.0

> RandomProject@1.0.0 postversion C:\Users\AdminUser\RandomProject
> react-native-version --never-amend

[RNV] Versioning Android...
[RNV] Android updated
[RNV] Versioning iOS...

  Usage: cli [options] [projectPath]

  Version your React Native app in a `npm version` fashion.

  Options:

    -V, --version                output the version number
    -a, --amend                  Amend the previous commit. Also updates the latest Git tag to point to the amended commit. This is done automatically when react-native-version is run from the "version" or "postversion" npm script. Use "--never-amend" if you never want to amend.
    --skip-tag                   For use with "--amend", if you don't want to update Git tags. Use this option if you have git-tag-version set to false in your npm config or you use "--no-git-tag-version" during npm-version.
    -A, --never-amend            Never amend the previous commit.
    -b, --increment-build        Only increment build number.
    -B, --never-increment-build  Never increment build number.
    -d, --android [path]         Path to your "android/app/build.gradle" file. (default: android/app/build.gradle)
    -i, --ios [path]             Path to your "ios/" folder. (default: ios)
    -L, --legacy                 Version iOS using agvtool (macOS only). Requires Xcode Command Line Tools.
    -q, --quiet                  Be quiet, only report errors.
    -r, --reset-build            Reset build number back to "1" (iOS only). Unlike Android's "versionCode", iOS doesn't require you to bump the "CFBundleVersion", as long as "CFBundleShortVersionString" changes. To make it consistent across platforms, react-native-version bumps both by default. You can use this option if you prefer to keep the build number value at "1" after every version change. If you then need to push another build under the same version, you can use "-bt ios" to increment.
    -s, --set-build <number>     Set a build number. WARNING: Watch out when setting high values. This option follows Android's app versioning specifics - the value has to be an integer and cannot be greater than 2100000000. You cannot decrement this value after publishing to Google Play! More info at: https://developer.android.com/studio/publish/versioning.html#appversioning
    -t, --target <platforms>     Only version specified platforms, eg. "--target android,ios".
    -h, --help                   output usage information
[RNV] Done, with errors.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! RandomProject@1.0.0 postversion: `react-native-version --never-amend`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the RandomProject@1.0.0 postversion script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\AdminUser\AppData\Roaming\npm-cache\_logs\2018-04-23T15_03_26_167Z-debug.log
stovmascript commented 6 years ago

@VinceBT I tried to set up my project like yours, but I'm still not able to reproduce the problem.

clipboard02

Could you provide a sample project?

stovmascript commented 6 years ago

I just tried again on a brand new RN project and again, no problems. There must be something specific that's throwing off the pbxproj parser...

suside commented 6 years ago

In my case I was removing tvos/watch builds from my project and it turned out I somehow still have:

INFOPLIST_FILE = "MyApp-tvOS/Info.plist";

in ios/MyApp.xcodeproj/project.pbxproj while MyApp-tvOS/Info.plist file was already deleted.

I figured that little fix here index.js#L399

log({ ...{ style: 'red', text: String(err) }, ...err });

should print all unexpected errors.

stovmascript commented 6 years ago

@suside That would make sense becase the project.pbxproj is used to build a list of Info.plist files which are then read, but there's no error handling in case the file doesn't exist.

Edit: Well now there will be, with your contribution.

stovmascript commented 6 years ago

@VinceBT @cvvspb Hey guys, check out the new version (2.5.2) that's out now on npm. It should now print a meaningful error message in the console.

Feel free to reopen, if a Windows related issue still persists.

VinceBT commented 6 years ago

After your commit, I finally get the error but I guess it would make more sense to print the full stacktrace. I replaced err.toString() by err.stack in https://github.com/stovmascript/react-native-version/blob/d6729d6efe621f7ebb144197ea8582fc9d166e97/index.js#L400 Here is what I've got

[RNV] Versioning iOS...
[RNV] SyntaxError: Expected "\"", "\\'", "\\\"", "\\n", or [^\\"] but "\\" found.
    at peg$buildStructuredError (C:\Users\AdminUser\RandomProject\node_modules\pbxproj-dom\parser.js:318:12)
    at Object.peg$parse [as parse] (C:\Users\AdminUser\RandomProject\node_modules\pbxproj-dom\parser.js:921:11)
    at Function.Xcode.open (C:\Users\AdminUser\RandomProject\node_modules\pbxproj-dom\xcode.js:16:43)
    at C:\Users\AdminUser\RandomProject\node_modules\react-native-version\index.js:266:25
    at new Promise (<anonymous>)
    at Object.version (C:\Users\AdminUser\RandomProject\node_modules\react-native-version\index.js:175:9)
    at Object.<anonymous> (C:\Users\AdminUser\RandomProject\node_modules\react-native-version\cli.js:56:5)
    at Module._compile (module.js:662:30)
    at Object.Module._extensions..js (module.js:673:10)
    at Module.load (module.js:575:32)
stovmascript commented 6 years ago

@VinceBT Will look into better error handling in general. Did you find out what that specific error was about?

VinceBT commented 6 years ago

Since the parser doesn't give the line he thinks there is a problem on, I cannot give a look but I've used kin to verify if my pbxproj was correct and it said it was.

VinceBT commented 6 years ago

Found fix in https://github.com/stovmascript/react-native-version/issues/52#issuecomment-393343784