-
Notifications
You must be signed in to change notification settings - Fork 100
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
[office-addin-debugging] On Mac, .bin contains CRLF instead of LF #168
Comments
We don't create the .bin folder. It is created by "npm install" based on the "bin" in package.json. Please let us know what versions of Node and NPM you are using: Also, on my Mac, I have installed Node via homebrew. It would help to know how you've installed Node and whether you are also using something like NVM to be able to switch NPM versions. |
Node: |
Please see if you have different results when using Node 10. |
I ran into this problem too. Fixed it by changing the line endings of |
node 8 and 10 both work correctly. |
@jpshankle Thanks for the info. I think this is a bug with Node 12, although I couldn't find any issues related to it when searching the repository. Do you want to open an issue there? https://github.com/nodejs/node/issues Also, do all of the node_modules/.bin files have the issue or is it specific to a particular package? |
I have only run into it in the |
I'm seeing the same issue with Node 10. Changing the line ending fixed it. |
@akrantz the npm/npm#12371 seems to relate, but I don't think it was ever definitively resolved (despite being marked as such). I'm not sure it can be resolved to everyone's satisfaction, because NPM shouldn't really be assuming anything about people's uploaded code. By adding the shebang It is never going to be a node issue, because node doesn't come into the picture until the shell successfully parses the shebang, so node version is not relevant. It could be that previous versions of npm worked round this mistake, or it could even be that previous versions of bash on macOS could deal with CRLF, which might be why it seems to work for some. |
OK, perhaps this is just a git issue in that the line endings are not converted to LF only on check-in, and it may be due to this one particular package which is why we don't see it consistently across packages. |
@TCourtneyOwen I wonder if this is really a git issue or rather from the fact that we usually build and publish from Windows machines. |
Also, this mentions that .bin is symlinked to |
@akrantz Are you building these packages yourself on your Mac or are you installing from NPM? |
I think the project just needs a |
When I had investigated this months ago, I was not able to reproduce on my Mac when installing the packages from NPM. It seemed related to the Node version at the time based on information provided. Given the latest discussion, there seems to be the possibility that because the published packages have CRLF in the cli.js or lib/cli.js or other files, this is potentially an issue. If that is really the case though it seems this would be an issue for all of the these packages which are published when run on Mac, and that does not seem to be the case. So, I feel skeptical that this is really the issue but wanted to gather the data so that I can know if there are steps we could take to resolve this issue. |
I believe it is a yarn vs npm thing. NPM does appear to convert line endings when linking the bin files into |
I also have the same issue - and can confirm it doesn't happen when using npm - only yarn. yarn: 1.17.3 currently I'm adding a postinstall script to our repo:
But I think the true fix is as @gordonmleigh describes. |
I'm also seeing this issue on macOS with both yarn and npx. Any progress on this? yarn: 1.22.11 |
I'm having the same issue and created a minimal example with Github Actions of this problem before landing here: Is there any progress on this topic? |
I am unfamiliar with some of the intricacies of npm and yarn in relating to the .bin folder and the line endings. We have code files cli.js in the root and the cli.ts in the src folder. The lib/cli.js is generated by the build and I'm not sure how the .bin files in node_modules folder relates to any these. Which code files would need to be modified to use LF in order for the right thing to happen on mac when using yarn (note I have not tried to reproduce this myself yet). |
Without trying this out myself, it should probably be enough to convert the Furthermore, the files probably should not be checked out with CRLF on Windows for building the packages for an NPM release. I.e. build them on a Linux or Mac machine or VM, in WSL, or set the Git repo to check out the files as they are in the repo ( |
TBH this is new territory for me, but I got it running locally on my Mac
So theoretically ™️ everything is fixed now. Assuming yarn uses the same logic everywhere and my mental model is somewhat correct. I'll push the updated files in a minute |
So this is what I'm seeing and learning:
I also found the command 'git add --renormalize .' will fix the index ends to be the standard LF that all the other files list. I think this is the correct change . . . but I'm not sure how to verify it before checking it in. |
Here my repo after following the guide and staging everything. Regarding OfficeDev#168
You can validate a part of the fix like I did here bockstaller/lineending_demo@c3fca79?diff=split I moved the build .tgz into my minimal example and install it manually, as described here. This fixes the problem in the |
Git has a way to normalize line endings for the working tree, but I don't think this is related to the issue with line endings in .bin files. The working tree will have line endings as CRLF on Windows whereas it is LF on Mac/Linux. When checked in, they are normalized to LF. However, I don't think this issue relates to the .bin files. It's likely either because the NPM packages are built on Windows and then published to NPM, so perhaps the .bin files which are published have CRLF because of that. It would help to have more clarity about the root cause of the problem. |
I'd like to investigate more and see if the source files make a difference, but I need clarity around how .bin files are generated and used and why that seems related to the problem. |
The files in the bin folder are copied there according to this configuration option: https://docs.npmjs.com/cli/v8/configuring-npm/package-json#bin But I did find this option https://www.typescriptlang.org/tsconfig#newLine, which allows to normalize the build outputs lineendings, independent of plattform. Testing it on my mac and windows machine showed that the build output, indeed changed from CRLF to LF with the option activated. |
I'm noticing that when I import office-adding-debugging to a project that on windows the file in the bin folder include 3 named office-addin-debugging, office-addin-debugging.cmd, and office-addin-debugging.ps1. The cmd file uses CRLF while the other two use LF. The code inside these files references the clit.js file in the root (which imports the one in the lib dir). But on mac it looks like a direct symlink to cli.js in the root. This is all based off using npm . . . but it seems like yarn is doing something different and I still need to try that out. vbudovski-plexus said that changing the line endings in the root cli.js file fixed it for them and that is the file that git identified as mixed in both the index and working versions (using --renormalize updated the index case to LF). |
I installed and used yarn on my Mac machine and was unable to reproduce the error myself (deleted and had it create the node_modules folder and everything in it). The files in .bin looked the same as those generated by npm on both mac and winodows respectivly. Something else must be going on. |
I setup a fresh Ubuntu-20.04 WSL instance and installed node/npm with yo and generator-office. When generated a project it had various dependencies from Office-Addin-Scripts. Most of the .TS files in the various src folders (within node_modules) all where saved with CRLF. The files in node_modules/.bin are symlinks to their respective files. As this is the first one I ran into issues with, I will use it as an example:
If I where to guess (and a few other files have this set):
I would change any endOfLine prettier setting to "LF". |
I don't think the issue isn't what is checked out with Git (the "working tree") but what is being published to NPM. When NPM install is run, the question is where the contents of the .bin folders come from and why it's not normalized to LF. |
Just saw the previous comment about the tsconfig newLine setting. That sounds promising. |
The lint jobs are ran before the build. Since endOfLine is set to auto, it will preserve the EOL settings for the file it is processing. If you change the endOfLine setting to LF from auto, the files that are generated in the build process (thus the .bin folder) will then have LF EOF characters. |
If the .TS file is ever saved as CRLF and the prettier rules stay as auto, then the files will never be changed to LF. Example: If you look at This will probably only be an issue if its built by someone who has core.autocrlf set to true. As on checkout: converts LF to CRLF. So when the user runs the install with that setting, they will get CRLF files. But if the package is built on a machine that has not changed core.autocrlf OR the build process runs lint:fix first (and the prettier files are chnged from auto to LF) then the resulting files will be correct. |
Building before changing Building after changing Running |
So after coming back to this and re-thinking through the comments I think I understand things a bit better now. I was thinking about maintaining line ending in the files themselves as they were stored in github an it's influence on npm, but now I understand that it more about the build output itself. While the file contents influence that (as indicated by using prettier and some of the things I was looking at) I think the better option is the complier flag for typescript (which I didn't understand before) that makes the js file output us LF reguardless of with the original code files (i.e. working directory) have. I am make a PR the updates the tsconfig files to do this and then the next time we update the packages they should be corrected. |
temp fix (expericned tis on fresh ubuntu machine):
|
This should be fixed in the current office-addin-dev-certs package (yo office output still needs to be updated). |
MacOS still appears to have the problem of getting
$ office-addin-debugging stop manifest.xml env: node\r: No such file or directory error Command failed with exit code 127.
The way to resolve the issue locally is to change the line ending in .bin -> office-addin-debugging from CRLF to LF.
Originally posted by @jpshankle in #160 (comment)
The text was updated successfully, but these errors were encountered: