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

Lower case drive letter in Open New Command Prompt command on Windows #9448

Closed
rob3c opened this Issue Jul 18, 2016 · 21 comments

Comments

Projects
None yet
7 participants
@rob3c

rob3c commented Jul 18, 2016

BUG REPRO HERE: https://github.com/rob3c/tsc-tsnode-vscode-casing-bug-on-windows

Overview

Starting with the 2016-07-14 release of Visual Studio Code Insiders edition (and now released in regular VS Code 1.3.1), the behavior of the Open New Command Prompt command (ctrl+shift+C) changed on Windows. Now, it lower-cases the drive letter in the new console's prompt, and that seems to affect the ability of at least ts-node (and possibly other tools) to build typescript code when the forceConsistentCasingInFileNames compiler option is set in tsconfig.json.

Step 1 - Open two command prompts for comparison

  • Within VS Code, invoke the Open New Command Prompt command via ctrl+shift+C (or find it using View | Command Palette... in the menu). Notice that the drive letter in the prompt is lower case now!
  • Open a standard Windows Command Prompt outside of VS Code in the normal way, and navigate to this project's root folder. Notice that the standard console has a captial drive letter.

Step 2 - create some source files

// tsconfig.json
{
    "compilerOptions": {
        "forceConsistentCasingInFileNames": true,
        "module": "commonjs",
        "moduleResolution": "node",
        "outDir": "bin",
        "target": "es5"
    },
    "exclude": [
        "bin",
        "node_modules"
    ]
}
// foo.ts
export class Foo {
    constructor(public bar: string) {}
}
// index.ts
import { Foo } from './foo';
let foo = new Foo('bar');
console.log(JSON.stringify(foo));

Step 3 - Build successfully using typescript directly

> tsc

This builds successfully in both command prompt windows.

Step 4 - Break stuff!

> ts-node index.ts

This builds and runs successfully in the standard Windows command prompt that has an upper-case drive letter, but it breaks in the console window that VS Code opens with this error:

C:\dev\bug-repros\tsc-tsnode-vscode-casing-bug-on-windows\node_modules\ts-node\src\index.ts:280
        throw new TSError(diagnosticList)
              ^
TSError: ? Unable to compile TypeScript
index.ts (1,21): File name 'C:/dev/bug-repros/tsc-tsnode-vscode-casing-bug-on-windows/foo.ts' differs from already included file name 'c:/dev/bug-repros/tsc-tsnode-vscode-casing-bug-on-windows/foo.ts' only in casing (1149)
    at getOutput (C:\dev\bug-repros\tsc-tsnode-vscode-casing-bug-on-windows\node_modules\ts-node\src\index.ts:280:15)
    at compile (C:\dev\bug-repros\tsc-tsnode-vscode-casing-bug-on-windows\node_modules\ts-node\src\index.ts:289:14)
    at loader (C:\dev\bug-repros\tsc-tsnode-vscode-casing-bug-on-windows\node_modules\ts-node\src\index.ts:304:23)
    at Object.require.extensions.(anonymous function) [as .ts] (C:\dev\bug-repros\tsc-tsnode-vscode-casing-bug-on-windows\node_modules\ts-node\src\index.ts:321:14)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Function.Module.runMain (module.js:575:10)
    at Object.<anonymous> (C:\dev\bug-repros\tsc-tsnode-vscode-casing-bug-on-windows\node_modules\ts-node\src\_bin.ts:172:12)
    at Module._compile (module.js:541:32)

BUG REPRO HERE: https://github.com/rob3c/tsc-tsnode-vscode-casing-bug-on-windows

@kieferrm

This comment has been minimized.

Contributor

kieferrm commented Jul 21, 2016

More details:
This only happens when the window has an open folder, i.e. you opened a real workspace. When there is no open folder the drive letter is still upper case.

Assigning to @Tyriar since he was the most active in the terminal area recently.

@rob3c

This comment has been minimized.

rob3c commented Jul 21, 2016

@kieferrm thanks, I just confirmed that opening Code without any file or folder will keep the drive upper-case. However, I still see the drive lower-cased if I right-click on a single file in Explorer and choose Open with Code so that just the file is opened and the explorer panel says "you have not yet opened a folder". Maybe this helps narrow it down a little more?

@Tyriar Tyriar added this to the Backlog milestone Jul 21, 2016

@alexperovich

This comment has been minimized.

Member

alexperovich commented Aug 4, 2016

I am hitting this exact same issue using gulp-typescript to compile typescript files through a build task. Turning off the compiler option is a workaround but that can cause issues on non-windows.

@hh10k

This comment has been minimized.

hh10k commented Aug 6, 2016

VSCode using c:\ instead of the usual C:\ is annoying because it breaks all the code that makes incorrect assumptions about paths.

I think the real bug is this: Microsoft/TypeScript#10095

@Tyriar Tyriar changed the title from breaking change in Open New Command Prompt command on Windows to Lower case drive letter in Open New Command Prompt command on Windows Sep 5, 2016

@Tyriar Tyriar added the bug label Sep 5, 2016

@asadsahi

This comment has been minimized.

asadsahi commented Sep 5, 2016

@Tyriar Sorry if I have missed anything. Is there any fix for it?

Is there a solution to force open cmd/terminal with uppercase drive letter?

@Tyriar

This comment has been minimized.

Member

Tyriar commented Sep 5, 2016

@asadsahi no I don't think there is a work around yet.

@asadsahi

This comment has been minimized.

asadsahi commented Sep 5, 2016

Okay, Thanks @Tyriar will keep an eye on this issue.

Tyriar added a commit that referenced this issue Sep 5, 2016

@Tyriar

This comment has been minimized.

Member

Tyriar commented Sep 5, 2016

I've root caused this to a line in the URI.fsPath forcing a lowercase drive letter. This is apparently a design decision that cannot be changed so it needs to be worked around in the external terminal code. I have a fix for it but I'm having some issues building on my Windows machine currently. I hope to get this in for the September release (v1.6)

@Tyriar Tyriar modified the milestones: September 2016, Backlog Sep 5, 2016

@asadsahi

This comment has been minimized.

asadsahi commented Sep 5, 2016

Thanks @Tyriar can this be a specific fix for windows if other OS's need to have a lowercase drive letter? Can you explain what is design decision behind this?

@Tyriar

This comment has been minimized.

Member

Tyriar commented Sep 6, 2016

@asadsahi the URI core is used everywhere, changing at that layer is a no go. So a Windows-specific change will be made at a higher layer.

@asadsahi

This comment has been minimized.

asadsahi commented Sep 6, 2016

Ohh ok. Thanks @Tyriar .

@rob3c

This comment has been minimized.

rob3c commented Sep 6, 2016

Here's a temporary workaround of sorts for both integrated and external consoles:

c:\path\to\project> cd .. && cd C:\path\to\project
C:\path\to\project>

Here's the same thing in a more condensed relative format that doesn't require copying/typing the path as long as you remember the syntax, but that should be no problem considering how much you'll be typing it until this is fixed ;-)

c:\path\to\project> cd .. && cd C%cd:~1%
C:\path\to\project>

It leverages the ability to change the drive casing when changing directories, and the more condensed form shows the cd pseudo-variable is expanded before the command is executed, so it's not relative to the parent directory. Unfortunately, it doesn't work trying to cd into the current directory directly, which is why I went up a level first.

@Tyriar

This comment has been minimized.

Member

Tyriar commented Sep 6, 2016

Thanks a lot @rob3c! Much appreciated as this bug will be in stable for another month or so.

@asadsahi

This comment has been minimized.

asadsahi commented Sep 7, 2016

@rob3c @Tyriar sorry didn't catch that, how to get this workaround working with vscode? is there something in settings.json or any where we can set which will uppercase c drive when integrated terminal opened or terminal opened from vscode using Ctrl + Shift + C (for windows)?

@rob3c

This comment has been minimized.

rob3c commented Sep 7, 2016

@asadsahi unfortunately, it's not automated, so we have to manually type it in each time. Just open an integrated terminal, for example, and type this in: cd .. && cd C%cd:~1% (if you're not on a C drive, then change the uppercase C to the appropriate drive.) It's not perfect, but at least you can manually change the casing on both terminals without too much hassle until it's fixed.

@Tyriar

This comment has been minimized.

Member

Tyriar commented Sep 7, 2016

You may be able to use a .bat file which launches cmd and then runs cd .. && cd C%cd:~1% to automate it.

@asadsahi

This comment has been minimized.

asadsahi commented Sep 7, 2016

Thanks @rob3c , @Tyriar Would you be able to help with an example bat file which we can run as part of lets say before build task in vscode?

@Tyriar

This comment has been minimized.

Member

Tyriar commented Sep 7, 2016

You can try something similar to #7263 (comment) but make the bat file:

cd .. && cd C%cd:~1%

Then set terminal.integrated.shell.windows to your bat file's location.

@rob3c

This comment has been minimized.

rob3c commented Sep 7, 2016

@Tyriar is right, you can automate it with a batch file in settings.json:

{
    // A relative path to the batch file works for the external terminal.
    // (project root here if using workspace settings, otherwise absolute path in global settings)
    // fix-casing-external.bat contents: `cd .. && cd C%cd:~1%` 
    "terminal.external.windowsExec": "fix-casing-external.bat",

    // The integrated terminal setting requires an absolute path.
    // You also need to invoke `%COMSPEC%` at the end so it doesn't close automatically.
    // fix-casing-integrated.bat contents: `cd .. && cd C%cd:~1% && %COMSPEC%`
    "terminal.integrated.shell.windows": "C:/absolute/path/to/fix-casing-integrated.bat"
}

If you use the same batch file for both, you'll need to type exit twice to exit the nested command line that was opened by the %COMSPEC% line when you're in the external console.

@asadsahi

This comment has been minimized.

asadsahi commented Sep 8, 2016

@rob3c @Tyriar Thanks once again.

Got both working with following config:

 // A relative path to the batch file works for the external terminal.
    // (project root here if using workspace settings, otherwise absolute path in global settings)
    // fix-casing-external.bat contents: `cd .. && cd C%cd:~1%` 
    "terminal.external.windowsExec": "C:\\Users\\asahi\\myproject\\.vscode\\terminal.bat",
    // The integrated terminal setting requires an absolute path.
    // You also need to invoke `%COMSPEC%` at the end so it doesn't close automatically.
    // fix-casing-integrated.bat contents: `cd .. && cd C%cd:~1% && %COMSPEC%`
    "terminal.integrated.shell.windows": "C:\\Users\\asahi\\myproject\\.vscode\\terminal.bat"

batch file content:

cd .. && cd C%cd:~1% && %COMSPEC%

@rob3c Didn't get what you mean by using exit twice? where would I use exit command? I tried using before/after %COMSPEC%` but that didn't open the terminals. Can you please explain that a little bit.

@rob3c

This comment has been minimized.

rob3c commented Sep 8, 2016

@asadsahi I meant if using the exit command to exit the command prompt once you're done with it (like ctrl+D in bash). Running cmd via %COMSPEC% while already inside a console nests the sessions, so typing exit inside the nested session only exits that session. If you put exit in your batch file, then you're telling it to exit the script, so don't do that :-) Glad you got it working!

Tyriar added a commit that referenced this issue Sep 9, 2016

Force upper case drive names in external terminal
This change needs to be made at this layer since a change to URI.fsPath
(the root cause) is too risky as lower case drives are relied upon.

Part of #9448

@Tyriar Tyriar closed this in a2ebd67 Sep 9, 2016

dwsmorris added a commit to dwsmorris/Eve that referenced this issue Nov 5, 2016

mhujer added a commit to mhujer/phpstan that referenced this issue May 8, 2017

FileExcluder should match case-insensitively on Windows
Otherwise running phpstan on itself fails when run in cmd opened
with c:/ instead of C:/

They had similar issue in VSCode
Microsoft/vscode#9448

mhujer added a commit to mhujer/phpstan that referenced this issue May 8, 2017

FileExcluder should match case-insensitively on Windows
Otherwise running phpstan on itself fails when run in cmd opened
with c:/ instead of C:/

They had similar issue in VSCode
Microsoft/vscode#9448

mhujer added a commit to mhujer/phpstan that referenced this issue May 8, 2017

FileExcluder should match case-insensitively on Windows
Otherwise running phpstan on itself fails when run in cmd opened
with c:/ instead of C:/

They had similar issue in VSCode
Microsoft/vscode#9448

ondrejmirtes added a commit to phpstan/phpstan that referenced this issue May 8, 2017

FileExcluder should match case-insensitively on Windows
Otherwise running phpstan on itself fails when run in cmd opened
with c:/ instead of C:/

They had similar issue in VSCode
Microsoft/vscode#9448

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.