-
Notifications
You must be signed in to change notification settings - Fork 617
Windows support #1033
Windows support #1033
Conversation
package.json
Outdated
@@ -83,7 +82,7 @@ | |||
"lint": "tslint `find src -name '*.ts*'` `find test -name '*.ts*'`", | |||
"cleanup": "rm -rf compiled/src", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to use portable rimraf
for that command.
package.json
Outdated
@@ -83,7 +82,7 @@ | |||
"lint": "tslint `find src -name '*.ts*'` `find test -name '*.ts*'`", | |||
"cleanup": "rm -rf compiled/src", | |||
"copy-html": "mkdir -p compiled/src/views && cp src/views/index.html compiled/src/views", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite in portable way (because Windows have no mkdir
and cp
).
package.json
Outdated
@@ -83,7 +82,7 @@ | |||
"lint": "tslint `find src -name '*.ts*'` `find test -name '*.ts*'`", | |||
"cleanup": "rm -rf compiled/src", | |||
"copy-html": "mkdir -p compiled/src/views && cp src/views/index.html compiled/src/views", | |||
"compile": "npm run cleanup && npm run tsc && npm run copy-html", | |||
"compile": "npm run tsc", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to put these commands back after fix.
src/PTY.ts
Outdated
import {loginShell} from "./utils/Shell"; | ||
import {debug} from "./utils/Common"; | ||
|
||
let smth = true ? null : pty.createTerminal(undefined, undefined, undefined); | ||
type ITerminal = typeof smth; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to do that hack because:
a) node-pty
doesn't export its ITerminal
type
b) microsoft/TypeScript#6606 isn't (yet?) implemented, so we cannot directly do type ITerminal = typeof(pty.createTerminal(undefined, undefined, undefined))
Both could be solved by either exporting the proper types from node-pty
library or writing our own type definitions (it's not that complex).
|
||
// TODO: write proper signatures. | ||
// TODO: use generators. | ||
// TODO: terminate. https://github.com/atom/atom/blob/v1.0.15/src/task.coffee#L151 | ||
constructor(words: EscapedShellWord[], env: ProcessEnvironment, dimensions: Dimensions, dataHandler: (d: string) => void, exitHandler: (c: number) => void) { | ||
const shellArguments = [...loginShell.noConfigSwitches, "-i", "-c", words.join(" ")]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠ Warning: Unix-specific options were replaced by Windows-specific; need to find a portable way to express this option set.
- (It has been fixed)
src/PTY.ts
Outdated
dataHandler(data); | ||
}); | ||
(this.terminal as any).on("exit", (code: number) => { | ||
console.log('PTY: exit'); | ||
exitHandler(code); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, ITerminal
doesn't declare its on
method. So I had to do these ugly as any
casts.
src/PTY.ts
Outdated
@@ -65,9 +81,11 @@ export function executeCommand( | |||
...execOptions, | |||
env: _.extend({PWD: directory}, process.env), | |||
cwd: directory, | |||
shell: "/bin/bash", | |||
shell: "cmd", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠ Warning: honestly I'm not sure what's this option impact; probably need to use some portable path definition from loginShell
.
src/PTY.ts
Outdated
const sourceCommands = (await loginShell.existingConfigFiles()).map(fileName => `source ${fileName} &> /dev/null`); | ||
|
||
return await linedOutputOf(loginShell.executableName, ["-c", `'${[...sourceCommands, command].join("; ")}'`], process.env.HOME); | ||
return await linedOutputOf(loginShell.executableName, ["/c", `"${[...sourceCommands, command].join(" && ")}"`], process.env.HOME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠ Warning: Unix-specific options were replaced by Windows-specific; need to find a portable way to express this option set.
src/shell/Aliases.ts
Outdated
//lines.map(parseAlias).forEach(parsed => aliasesFromConfig[parsed.name] = parsed.value); | ||
} catch (error) { | ||
console.error(error); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠ Warning: As far as I know, Windows' cmd
shell doesn't have a concept of alias. That's why I had to comment these out. We'll need to add an option haveAliases
to loginShell
or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Windows PowerShell has aliasing feature which you can know more
by opening a PowerShell, then run
Get-Help about_Aliases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know about that, although I've decided to add only cmd
support for now. I love PowerShell, but alternate shell support on Windows is another issue, and I'd like to limit scope of this issue to just cmd.exe
.
src/shell/Environment.ts
Outdated
@@ -34,7 +34,7 @@ export const preprocessEnv = (lines: string[]) => { | |||
|
|||
export const processEnvironment: Dictionary<string> = {}; | |||
export async function loadEnvironment(): Promise<void> { | |||
const lines = preprocessEnv(await executeCommandWithShellConfig("env")); | |||
const lines = preprocessEnv(await executeCommandWithShellConfig("set")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠ Warning: Unix-specific command was replaced by a Windows-specific; need to find a portable way to express this command.
src/utils/Shell.ts
Outdated
}; | ||
|
||
const shell = () => { | ||
if (!process.env.SHELL) { | ||
process.env.SHELL = 'C:\\Windows\\System32\\cmd.exe'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug leftover; just drop this.
Although we'll probably better add Windows detection and fallback to cmd.exe
instead of /bin/bash
on Windows below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$SHELL
typically isn't set on Windows, they have a similar environment variable COMSPEC
but it defaults to the 32-bit version of cmd.exe, as does "cmd.exe" on the path. I've found defaulting to %windir%\Sysnative\cmd.exe
on 64-bit machine and %windir%\System32\cmd.exe
on 32-bit machines is the best way to go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good suggestion. I think I'll implement it, thanks.
tsconfig.json
Outdated
"noImplicitThis": true, | ||
"inlineSourceMap": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are disabled checks I was talking about in the PR description; ⚠ we need to put them all back.
b41b254
to
423a7bd
Compare
Squashed and cleaned the PR. Please review. |
81c5089
to
d9fe19b
Compare
Well, the tests are failing; obviously I've broken something. If anybody wants to help me to fix that issue — you're welcome, guys! |
I can see the current master branch is failing. I suppose you need to wait until a fix is done and then merge the new commits. |
d9fe19b
to
c06298e
Compare
Alright. Rebased my branch on top of current master, and everything is okay now. Ready for review. |
@ForNeVeR great job, thanks! I'm not able to test if it works, so I'll just merge it. Please mention me next time, so that I see your messages sooner. |
Thank you! I can confirm that it still works in master. |
In this branch, I've included the exact changes I've done to execute black-screen on my Windows machine.
There're many unwanted changes in this PR;
Issues remaining
node-pty
typings; waiting for my pull request Add "types" to package.json microsoft/node-pty#83 to be merged and published. We could write our own typings if necessary (e.g. maintainer won't answer for a while)."start": "bash housekeeping/start.sh",
with something more portable; we have nobash
on Windows.Most of the code come from quick hacks and fixes, so, please, help me to fix it properly and follow the project architecture.
Impact
This will close issue #800; we should urge Windows users to open new issues for every missing/misbehaving feature after that (e.g. PowerShell support, proper alias support on Windows etc. etc.)