Skip to content

Commit

Permalink
Use cross-spawn to build and view
Browse files Browse the repository at this point in the history
Also use cross-spawn for calling texdoc.
Related to #2010
  • Loading branch information
jlelong committed Mar 31, 2020
1 parent 333ff24 commit 6de96d5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/components/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as vscode from 'vscode'
import * as path from 'path'
import * as fs from 'fs-extra'
import * as cp from 'child_process'
import * as cs from 'cross-spawn'
import * as tmp from 'tmp'
import * as pdfjsLib from 'pdfjs-dist'
import {Mutex} from '../lib/await-semaphore'
Expand Down Expand Up @@ -99,7 +100,7 @@ export class Builder {
}
this.extension.logger.addLogMessage(`Build using the external command: ${command} ${args.length > 0 ? args.join(' '): ''}`)
this.extension.logger.addLogMessage(`cwd: ${wd}`)
this.currentProcess = cp.spawn(command, args, {cwd: wd})
this.currentProcess = cs.spawn(command, args, {cwd: wd})
const pid = this.currentProcess.pid
this.extension.logger.addLogMessage(`External build process spawned. PID: ${pid}.`)

Expand Down Expand Up @@ -259,7 +260,7 @@ export class Builder {
command += ' ' + args[0]
}
this.extension.logger.addLogMessage(`cwd: ${path.dirname(rootFile)}`)
this.currentProcess = cp.spawn(command, [], {cwd: path.dirname(rootFile), env: envVars, shell: true})
this.currentProcess = cs.spawn(command, [], {cwd: path.dirname(rootFile), env: envVars, shell: true})
} else {
let workingDirectory: string
if (steps[index].command === 'latexmk' && rootFile === this.extension.manager.localRootFile && this.extension.manager.rootDir) {
Expand All @@ -268,7 +269,7 @@ export class Builder {
workingDirectory = path.dirname(rootFile)
}
this.extension.logger.addLogMessage(`cwd: ${workingDirectory}`)
this.currentProcess = cp.spawn(steps[index].command, steps[index].args, {cwd: workingDirectory, env: envVars})
this.currentProcess = cs.spawn(steps[index].command, steps[index].args, {cwd: workingDirectory, env: envVars})
}
const pid = this.currentProcess.pid
this.extension.logger.addLogMessage(`LaTeX build process spawned. PID: ${pid}.`)
Expand Down
4 changes: 2 additions & 2 deletions src/components/texdoc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from 'vscode'
import * as cp from 'child_process'
import * as cs from 'cross-spawn'
import {Extension} from 'src/main'

export class TeXDoc {
Expand All @@ -14,7 +14,7 @@ export class TeXDoc {
const texdocPath = configuration.get('texdoc.path') as string
const texdocArgs = Object.assign([], configuration.get('texdoc.args') as string[])
texdocArgs.push(pkg)
const proc = cp.spawn(texdocPath, texdocArgs)
const proc = cs.spawn(texdocPath, texdocArgs)

let stdout = ''
proc.stdout.on('data', newStdout => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode'
import * as fs from 'fs'
import * as ws from 'ws'
import * as path from 'path'
import * as cp from 'child_process'
import * as cs from 'cross-spawn'
import {sleep} from '../utils/utils'

import {Extension} from '../main'
Expand Down Expand Up @@ -229,7 +229,7 @@ export class Viewer {
args = args.map(arg => arg.replace('%PDF%', pdfFile))
}
this.extension.manager.setEnvVar()
cp.spawn(command, args, {cwd: path.dirname(sourceFile), detached: true})
cs.spawn(command, args, {cwd: path.dirname(sourceFile), detached: true})
this.extension.logger.addLogMessage(`Open external viewer for ${pdfFile}`)
}

Expand Down

0 comments on commit 6de96d5

Please sign in to comment.