bcomnes / sublime-standard-format

:sparkles: Runs standard --fix against the javascript in your ST3 window on save or manually.
https://packagecontrol.io/packages/StandardFormat
MIT License
60 stars 21 forks source link

ts-standard: Unable to locate the project file #79

Closed carlpett closed 3 years ago

carlpett commented 3 years ago

I'm trying to use this plugin with ts-standard (standard for TypeScript), but running into a problem which I think is due to the plugin chdir:ing to the file location: https://github.com/bcomnes/sublime-standard-format/blob/cddd2d7225afa4f4be0496b0c3ad7ba906c8e08b/standard-format.py#L285

The ts-standard executable needs to read the tsconfig.json file in the project root, and since we're leaving the root dir, it simply fails the save hook:

b'Unable to locate the project file. A project file (tsconfig.json or tsconfig.eslint.json) is reqired in order to use ts-standard.\n'
standard-format error: Unable to locate the project file. A project file (tsconfig.json or tsconfig.eslint.json) is reqired in order to use ts-standard.

My StandardFormat.sublime-settings looks like this:

{
    "extensions": ["ts", "js", "jsx"],
    "commands": [
        ["ts-standard", "--stdin", "--stdin-filename", "TODO", "--fix"]
    ]
}

Two possible solutions I can see would be either to keep the working directory in the project root (might not be simple in multi-directory projects?), or support some type of replacement tokens in the commands (I'll end up needing the file name somehow anyway due to requirements by ts-standard).

Thoughts?

bcomnes commented 3 years ago

Hey I'm on vacation and will try to find some time to read through this when I have some downtime.

bcomnes commented 3 years ago

Sorry, been a while since you opened this, hopefully you didn't fully move on.

I think the idea of keeping the working directory in the root of the project is a fair assumption, although it might have some side effects in some cases. I'll read through how this works again and see if that could make sense.

bcomnes commented 3 years ago

Looking specifically for the dir that contains tsconfig.json is super ts specfic. Would it be safe to change the process to the nearest dir containing package.json found above the file being formatted?

We could make this customizable if we have to, but I think I will start with trying that.

carlpett commented 3 years ago

I sounds like it should be safe for all my use cases, I'm not sure if there are edge cases around multi-level repos or something though? But I'd be happy enough with that approach :)

carlpett commented 3 years ago

And thanks for coming back to this! :heart:

bcomnes commented 3 years ago

You are right. Lerna being the example.

The ideal would be ts-standard being more flexible on finding config files, but I think project / folder root might help out a lot.

bcomnes commented 3 years ago

https://github.com/bcomnes/sublime-standard-format/releases/tag/v6.4.2 will be hitting package control soon (hopefully in a few hours). Let me know how that works for you.

carlpett commented 3 years ago

Works nicely, thanks! With this in place I found another bit needed for ts-standard support, a PR is coming for that.

bcomnes commented 3 years ago

Sweet yeah let me know