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

Sortier not working on macintosh #352

Closed
RikardGehlin opened this issue Mar 4, 2019 · 17 comments
Closed

Sortier not working on macintosh #352

RikardGehlin opened this issue Mar 4, 2019 · 17 comments
Assignees

Comments

@RikardGehlin
Copy link

Our team is using sortier in our lint-staged. It works fine for the people ona windows machine but breaks for those on a macbook pro.

Expected output

For sortier to do its thing and sort stuff :)

Actual output (or error message)

screenshot 2019-03-04 at 4 24 24 pm

@k2snowman69
Copy link
Member

Hmmm I don't think this has to do with OSX because I'm definitely using this on my mac right now. I'm also confused as to why you aren't seeing an error message being outputted because in general there should be something. I can look into that in a separate issue... let's get this working for you :-).

Could you attempt to run sortier manually on the files being edited? Maybe you'll get a clearer error from sortier?

First is to figure out the command being executed. To do this you can do is enable debug mode in lint-staged by passing the --debug flag. If you want to do this via husky it would look like this:

{
    hooks: {
      'pre-commit': 'lint-staged --debug'
    }
  }

Somewhere in the output there should be the command for sortier. Mine looks like this (I blanked out the project name)

sortier [started]
  lint-staged:task bin: /Users/rickyp/dev/_____/react/node_modules/.bin/sortier +3ms
  lint-staged:task args: [ '/Users/rickyp/dev/_____/react/src-example/components/app/app.tsx' ] +0ms
  lint-staged:task opts: { reject: false } +0ms

With that, hopefully you can run sortier directly and see why it is failing.

@k2snowman69
Copy link
Member

Opened #353 to determine how to get lint-staged to stop on failure.

@RikardGehlin
Copy link
Author

I've uploaded a log from my colleague when he's running sortier with the debug flag. Hope that helps a bit :)

sortier.log

@k2snowman69
Copy link
Member

Thanks, I'm going to try a few attempts to repro this locally and hopefully come up with something for you. Considering package.json is a json file, I doubt the issue is there so odds are it's something to do with the storybook webpack config because I personally haven't tried that.

While I'm trying that today, you're also welcome to run sortier directly on those files and see if it provides you some sort of error or not. To do that on OSX you can simply run it from the node_modules bin. For example, I've added a error in my package.json and this is the command I ran along with the output.

node_modules/.bin/sortier ./package.json 

/Users/________/website/node_modules/cosmiconfig/dist/loaders.js:18
    throw err;
    ^
JSONError: JSON Error in /Users/________/website/package.json:
Unexpected string in JSON at position 1448 while parsing '{  "author": "",  "dependencies": {  '
    at module.exports (/Users/________/website/node_modules/parse-json/index.js:26:19)
    at Object.loadJson (/Users/________/website/node_modules/cosmiconfig/dist/loaders.js:15:12)
    at Explorer.loadPackageProp (/Users/________/website/node_modules/cosmiconfig/dist/createExplorer.js:175:35)
    at Explorer.loadFileContent (/Users/________/website/node_modules/cosmiconfig/dist/createExplorer.js:226:12)
    at Explorer.createCosmiconfigResultSync (/Users/________/website/node_modules/cosmiconfig/dist/createExplorer.js:259:31)
    at Explorer.loadSearchPlaceSync (/Users/________/website/node_modules/cosmiconfig/dist/createExplorer.js:157:17)
    at Explorer.searchDirectorySync (/Users/________/website/node_modules/cosmiconfig/dist/createExplorer.js:135:21)
    at run (/Users/________/website/node_modules/cosmiconfig/dist/createExplorer.js:107:27)
    at cacheWrapper (/Users/________/website/node_modules/cosmiconfig/dist/cacheWrapper.js:14:18)
    at Explorer.searchFromDirectorySync (/Users/________/website/node_modules/cosmiconfig/dist/createExplorer.js:116:14)

@k2snowman69
Copy link
Member

Okay, so I setup a . storybook local project on my machine to see if there was something weird about their setup and their webpack config that would be causing sortier to fail and I didn't see anything. The contents of the storyboard webpack config I ran it over looked like this:

const path = require("path");
const mainConfig = require("../webpack.config.js");

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          {
            loader: "style-loader"
          },
          {
            loader: "css-loader",
            options: {
              modules: true,
              importLoaders: 1,
              localIdentName: "[name]_[local]_[hash:base64]",
              sourceMap: true
            }
          },
          {
            loader: "postcss-loader"
          }
        ],
        include: path.resolve(__dirname, "../src")
      }
    ]
  }
};

I also ran it over a package.json and that seemed to work fine as well. So I guess let me know how running it directly works for you.

Another option is that the issue maybe with husky and lint-staged so I would check to make sure those are up to date as well.

@k2snowman69 k2snowman69 self-assigned this Mar 17, 2019
@k2snowman69
Copy link
Member

Just a reminder, waiting on a response here :-)

@royderksroute42
Copy link

royderksroute42 commented Mar 20, 2019

Hi there, i've been following this since thread for a while and i'd like to chip in!
I would really like to get this sorted (pun intended).
If i run sortier from my node_modules the following happens (the same as with husy/lint staged:

yarn sortier ./package.json
yarn run v1.13.0
$ /Users/<redacted>/node_modules/.bin/sortier ./package.json
env: node\r: No such file or directory
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Using the VSCode plugin earlier everything worked great.

    "@snowcoders/sortier": "2.5.1",
    "husky": "^1.3.1",
    "lint-staged": "3.5.1",

This stackoverflow drew my attention, as the answer seems to be related to having created the file on a windows machine.
https://stackoverflow.com/questions/30344858/node-script-executable-not-working-on-mac-env-node-r-no-such-file-or-directo

The output says node\r, maybe the \r is the carriage-return at fault?

Let me know how i can help further!

@k2snowman69
Copy link
Member

Thanks @royderksroute42! I do sometimes publish from my windows machine so this could possibly be the issue which I'm thankful for because I was running out of ideas!

I won't have a chance until tonight (12 hours from now) to see if I can resolve it but odds are if it is a carriage return at fault it is going to require a publish of 2.5.2. I'll keep this thread posted with my results :-)

@royderksroute42
Copy link

I could test it myself if you can give me a linenr and filename (not much time for digging in to find where it is located exactly).

@RikardGehlin
Copy link
Author

Hi,
I am sorry but I had to go away urgently for some family business. I will be back at work next week and can help out a bit more then.

@k2snowman69
Copy link
Member

@RikardGehlin Wish you all the best!

Based on what @royderksroute42 mentioned, this looks like there are two possible bugs

Overall it seems the issue is that since I mainly publish from my windows box my bin/index.js ends with /r/n. It doesn't seem to matter what the rest of the files are (based on other documentation I've read) just whatever file the bin is pointing to.

I've followed the steps in a blog I found and created https://github.com/snowcoders/sortier/blob/master/.gitattributes then published @snowcoders/[email protected]. Hopefully this should fix up any and all issues

If this doesn't fix up the problem (or we run into another line ending problem) I'm going to take the path of prettier and just apply lf line endings to everything, not just that one particular file.

@royderksroute42 Can you pull down @snowcoders/[email protected] and give that a shot?

@royderksroute42
Copy link

yarn add @snowcoders/[email protected]
...
yarn sortier ./package.json
yarn run v1.13.0
$ /Users/<stuff>/node_modules/.bin/sortier ./package.json
✨  Done in 0.63s.

🥇

@royderksroute42
Copy link

Hmmm, using Husky/lintstaged doesn't seem to work yet.

Can't find node in PATH, trying to find a node binary on your system
husky > pre-commit (node v11.6.0)
�[?25l[10:15:00] Running tasks for *.{ts,js,tsx} [started]
[10:15:00] eslint --fix [started]
[10:15:13] eslint --fix [completed]
[10:15:13] sortier [started]
[10:15:13] sortier [failed]
[10:15:13] → 🚫 sortier found some errors. Please fix them and try committing again.

env: node\r: No such file or directory

[10:15:13] Running tasks for *.{ts,js,tsx} [failed]
[10:15:13] → 🚫 sortier found some errors. Please fix them and try committing again.

env: node\r: No such file or directory

�[?25h🚫 sortier found some errors. Please fix them and try committing again.

env: node\r: No such file or directory

�[?25hhusky > pre-commit hook failed (add --no-verify to bypass)

{
  "linters": {
    "*.{ts,js,tsx}": [
      "eslint --fix",
      "sortier",
      "git add"
    ]
  },
  "ignore": []
}

@k2snowman69
Copy link
Member

k2snowman69 commented Mar 21, 2019

Can you check the line endings for the .bin/sortier file directly? In VS Code you can do this by simply opening the file and seeing the line ending in the bottom right hand corner (Here you se LF). I just want to make sure the bin file got updated.
Screen Shot 2019-03-21 at 8 07 59 AM

Also, what version of npm and node are you running, just for my knowledge?

@royderksroute42
Copy link

Don't know what happend this morning, must have been reset to before 2.5.2
It's working now, although it's failing on json files but no idea if its related.
I'd consider it fixed, as json files aren't supposed to be sortied in my use-case and it works when used directly

@k2snowman69
Copy link
Member

When you say json files are failing, are you talking about package.json or can you provide an example? I doubt it's related as well but just want to make sure.

@k2snowman69
Copy link
Member

Closing this due to age and that the original issue was resolved. If you figure out what the JSON issue was, let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants