vitejs / vitejs/launch-editor

No fallback on windows ... always fails on windows if no editor is open

Open
#96 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
721
Forks
94
Avg merge
2h 11m
Merged PRs (30d)
5

Description

Since it is uncommon for windows to have EDITOR or VISUAL set, I added:

( There also seems no way to prevent launch-editor from wrapping my error-callback to not log a not format matching error like the rest of my cli app ... )

import launchEditorX from 'launch-editor';
import open from 'open';

function launchEditor(file: string, errCb?:(file:string, errorMessage:string | null) => void): void {

    function reject(file:string, errorMessage:string | null) {
        // log that the user needs to select an editor himself
        console.error(colors.red(figures.warning), 'Please select an editor yourself.');
        
        // just throw the file at the OS and try to let it handle it
        // (in this project, these will be text files, so we do not care)
        open(file, { wait: false });
    }

    // set the VISUAL env as default if none is available, looking at you windows
    // DO NOT use LAUNCH_EDITOR, since we do not always enforce notepad, just use as fallback. 
    if (!process.env.VISUAL && !process.env.EDITOR)
        process.env.VISUAL = 
            /^win/.test(process.platform) ? "notepad" : // this is required!
            "vim"; // VISUAL | EDITOR should not require this

    // try already opened editors, fall back to env VISUAL | EDITOR
    launchEditorX(file, errCb ?? reject);
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin with the launch-editor entry point and compare its Windows behavior when EDITOR and VISUAL are unset with the fallback shown in the issue. Check how the error callback is handled, including whether it produces the unwanted format-matching log. Confirm the behavior on Windows with no editor environment variables and no editor already open.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.