piuccio / sublime-esformatter

JavaScript formatter plugin for Sublime Text
MIT License
28 stars 20 forks source link

ignores locally installed esformatter #74

Open airtonix opened 8 years ago

airtonix commented 8 years ago

https://packagecontrol.io/packages/EsFormatter says:

You can either install esformatter globally or under your current project's node_modules folder. This complicates the setup slightly but you can configure things anyway you want.

So the situation is this:

~/Projects/foo/bar feature/baz*
❯ ls -al ./node_modules/esformatter/bin
total 12
drwxr-xr-x. 2 zeno.jiricek zeno.jiricek 4096 Oct 17  2015 .
drwxr-xr-x. 7 zeno.jiricek zeno.jiricek 4096 Aug 10 14:27 ..
-rwxr-xr-x. 1 zeno.jiricek zeno.jiricek 1491 Oct 17  2015 esformatter

Esformatter Settings are this:

{
    "format_on_save": true
}

Yet I get an alert window dialog saying:

It looks like esformatter is not installed.
Please make sure that it is installed globally or in project node_modules folder
airtonix commented 8 years ago

Looks like this is happening because your code only tries to discover the global npm root.

Changing it to something like this should work:


def getNpmGlobalRoot():
    # determine NPM global root
    try:
        return subprocess.check_output(["npm", "root", "-g"]).rstrip().decode('utf-8')
    except:
        # NPM not installed or not accessible
        return None

def getNpmLocalRoot():
    # determine NPM local root
    try:
        return subprocess.check_output(["npm", "root"]).rstrip().decode('utf-8')
    except:
        # NPM not installed or not accessible
        return None

# Extend NODE_PATH to make globally installed esformatter requirable
npmRoot = getNpmLocalRoot() or getNpmGlobalRoot()
airtonix commented 8 years ago

meh, even when i globally install esformatter it fails.

ghost commented 8 years ago

Same here, it fails for globally installed esformatter. I think it might be happening because I am using nvm to install node?

BennyTian commented 7 years ago

same issues ...

prusswan commented 6 years ago

For Ubuntu/Mint it looks like only system npm (the one installed with apt-get) with global install of esformatter will work properly. It might work with nvm with some hacking of env configuration, but a proper fix is needed to work with yarn/nvm.