Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
Fix #422 - Get tslint working in release builds (#425)
Browse files Browse the repository at this point in the history
* Add execNodeScript command and leverage in typescript

* Create execNodeScript and use with tslint

* Clean up whitespace
  • Loading branch information
extr0py authored Apr 30, 2017
1 parent c18fb1f commit 0857c4d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 13 deletions.
1 change: 1 addition & 0 deletions browser/src/NeovimInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as cp from "child_process"
import { remote } from "electron"
import { EventEmitter } from "events"
import * as path from "path"

import * as Q from "q"
import * as Actions from "./actions"
import * as Config from "./Config"
Expand Down
40 changes: 40 additions & 0 deletions browser/src/Plugins/Api/Oni.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as ChildProcess from "child_process"
import { EventEmitter } from "events"

import { IPluginChannel } from "./Channel"
Expand Down Expand Up @@ -51,6 +52,44 @@ export class Oni extends EventEmitter implements Oni.Plugin.Api {
this._languageService = new DebouncedLanguageService(languageService)
}

public execNodeScript(scriptPath: string, args: string[] = [], options: ChildProcess.ExecOptions = {}, callback: (err: any, stdout: string, stderr: string) => void): ChildProcess.ChildProcess {
const requiredOptions = {
env: {
ELECTRON_RUN_AS_NODE: 1,
},
}

const opts = {
...options,
...requiredOptions,
}

const execOptions = [process.execPath, scriptPath].concat(args)
const execString = execOptions.map((s) => `"${s}"`).join(" ")

return ChildProcess.exec(execString, opts, callback)
}

/**
* Wrapper around `child_process.exec` to run using electron as opposed to node
*/
public spawnNodeScript(scriptPath: string, args: string[] = [], options: ChildProcess.SpawnOptions = {}): ChildProcess.ChildProcess {
const requiredOptions = {
env: {
ELECTRON_RUN_AS_NODE: 1,
},
}

const opts = {
...options,
...requiredOptions,
}

const allArgs = [scriptPath].concat(args)

return ChildProcess.spawn(process.execPath, allArgs, opts)
}

public setHighlights(file: string, key: string, highlights: Oni.Plugin.SyntaxHighlight[]) {
this._channel.send("set-syntax-highlights", null, {
file,
Expand All @@ -65,6 +104,7 @@ export class Oni extends EventEmitter implements Oni.Plugin.Api {
key,
})
}

private _handleNotification(arg: any): void {
if (arg.type === "buffer-update") {
this.emit("buffer-update", arg.payload)
Expand Down
10 changes: 4 additions & 6 deletions vim/core/oni-plugin-tslint/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ const exec = require("child_process").exec

const findParentDir = require("find-parent-dir")

const isWindows = os.platform() === "win32"
const tslintExecutable = isWindows ? "tslint.cmd" : "tslint"
const tslintPath = path.join(__dirname, "..", "..", "..", "..", "node_modules", ".bin", tslintExecutable)
const tslintPath = path.join(__dirname, "..", "..", "..", "..", "node_modules", "tslint", "lib", "tslint-cli.js")

let lastErrors = {}
let lastArgs = null
Expand Down Expand Up @@ -97,12 +95,12 @@ const activate = (Oni) => {
processArgs = processArgs.concat(["--fix"])
}

processArgs = processArgs.concat(["--force", "--format json"])
processArgs = processArgs.concat(["--force", "--format", "json"])

processArgs.push("--config", path.join(configPath, "tslint.json"))
processArgs = processArgs.concat(["--config", path.join(configPath, "tslint.json")])
processArgs = processArgs.concat(args)

return Q.nfcall(exec, tslintPath + " " + processArgs.join(" "), { cwd: workingDirectory })
return Q.nfcall(Oni.execNodeScript, tslintPath, processArgs, { cwd: workingDirectory })
.then((stdout, stderr) => {

const errorOutput = stdout.join(os.EOL).trim()
Expand Down
8 changes: 2 additions & 6 deletions vim/core/oni-plugin-typescript/src/TypeScriptServerHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class TypeScriptServerHost extends events.EventEmitter {
return this._tssProcess.pid
}

constructor() {
constructor(Oni: any) {
super()

// Other tries for creating process:
Expand All @@ -39,11 +39,7 @@ export class TypeScriptServerHost extends events.EventEmitter {
// This has some info on using eventPort: https://github.com/Microsoft/TypeScript/blob/master/src/server/server.ts
// which might be more reliable
// Can create the port using this here: https://github.com/Microsoft/TypeScript/blob/master/src/server/server.ts
this._tssProcess = childProcess.exec(`node "${tssPath}"`, { maxBuffer: 500 * 1024 * 1024 }, (err) => {
if (err) {
console.error(err)
}
})
this._tssProcess = Oni.spawnNodeScript(tssPath)
console.log("Process ID: " + this._tssProcess.pid) // tslint:disable-line no-console

this._rl = readline.createInterface({
Expand Down
2 changes: 1 addition & 1 deletion vim/core/oni-plugin-typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface IDisplayPart {

export const activate = (Oni) => {

const host = new TypeScriptServerHost()
const host = new TypeScriptServerHost(Oni)
const quickInfo = new QuickInfo(Oni, host)

const lastOpenFile = null
Expand Down

0 comments on commit 0857c4d

Please sign in to comment.