Skip to content

Commit

Permalink
Make exec/spawn calls Windows-friendly
Browse files Browse the repository at this point in the history
* Call `node {script}` rather than calling the script directly.
* Also remove some unused functions from common

fixes #8
  • Loading branch information
jason0x43 committed Jan 11, 2018
1 parent 9e7f56e commit db198d6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 57 deletions.
54 changes: 4 additions & 50 deletions src/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { readFileSync } from 'fs';
import { ChildProcess } from 'child_process';
import {
cp,
echo,
Expand Down Expand Up @@ -38,22 +37,6 @@ export interface FilePattern {
pattern: string;
}

/**
* Compile a project
*/
export function compile(
tsconfig: string,
watch = false
): ExecOutputReturnValue | ChildProcess {
let cmd = `tsc -p "${tsconfig}"`;
let opts: ExecOptions = {};
if (watch) {
cmd += ' --watch';
opts.async = true;
}
return exec(cmd, opts);
}

/**
* Copy the files denoted by an array of glob patterns into a given directory.
*/
Expand Down Expand Up @@ -177,7 +160,10 @@ export function lint(tsconfigFile: string) {
let tslintJson = test('-f', 'tslint.json')
? 'tslint.json'
: resolve(join(__dirname, 'tslint.json'));
return exec(`tslint -c "${tslintJson}" --project "${tsconfigFile}"`);
const tslint = require.resolve('tslint/bin/tslint');
return exec(
`node "${tslint}" -c "${tslintJson}" --project "${tsconfigFile}"`
);
}

/**
Expand Down Expand Up @@ -228,38 +214,6 @@ export function readTsconfigFile(filename: string) {
return config;
}

/**
* Run stylus
*/
export function stylus(
files: string[],
watch = false
): ExecReturnValue | ChildProcess {
let cmd = `stylus "${files.join('","')}"`;
let opts: ExecOptions = {};
if (watch) {
cmd += ' --watch';
opts.async = true;
}
return exec(cmd, opts);
}

/**
* Run webpack
*/
export function webpack(
config: string,
watch = false
): ExecReturnValue | ChildProcess {
let cmd = `webpack --config "${config}"`;
let opts: ExecOptions = {};
if (watch) {
cmd += ' --watch';
opts.async = true;
}
return exec(cmd, opts);
}

export class ExecError extends Error {
code: number;
stdout: string;
Expand Down
24 changes: 18 additions & 6 deletions src/intern-dev-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ const watchMode = args[0] === 'watch';
// -----------------------------------------------------------------
if (internDev.stylus) {
try {
const stylus = require.resolve('stylus/bin/stylus');
if (watchMode) {
const proc = spawn('stylus', internDev.stylus.concat('--watch'));
const proc = spawn('node', [
stylus,
...internDev.stylus,
'--watch'
]);
watchProcess('stylus', proc);
} else {
const proc = spawnSync('stylus', internDev.stylus);
const proc = spawnSync('node', [stylus, ...internDev.stylus]);
logProcess('stylus', proc);
}
} catch (error) {
Expand Down Expand Up @@ -78,11 +83,12 @@ try {

log(`Compiling ${dirname(tsconfig)}`);
const tag = `tsc:${dirname(tsconfig)}`;
const tsc = require.resolve('typescript/bin/tsc');
if (watchMode) {
const proc = spawn('tsc', ['-p', tsconfig, '--watch']);
const proc = spawn('node', [tsc, '-p', tsconfig, '--watch']);
watchProcess(tag, proc, /\berror TS\d+:/);
} else {
const proc = spawnSync('tsc', ['-p', tsconfig]);
const proc = spawnSync('node', [tsc, '-p', tsconfig]);
logProcess(tag, proc, /\berror TS\d+:/);
}
});
Expand All @@ -96,15 +102,21 @@ try {
const webpackConfig = glob(internDev.webpack || 'webpack.config.*')[0];
if (webpackConfig) {
try {
const webpack = require.resolve('webpack/bin/webpack');
if (watchMode) {
const proc = spawn('webpack', [
const proc = spawn('node', [
webpack,
'--config',
webpackConfig,
'--watch'
]);
watchProcess('webpack', proc, /^ERROR\b/);
} else {
const proc = spawnSync('webpack', ['--config', webpackConfig]);
const proc = spawnSync('node', [
webpack,
'--config',
webpackConfig
]);
logProcess('webpack', proc, /^ERROR\b/);
}
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion src/intern-dev-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ let mode = 'node';
let config = 'tests/intern.js';

function run(runner: string) {
let command = [`intern-${runner}`].concat(args);
const intern = require.resolve(`intern-${runner}`);
let command = ['node', `"${intern}"`].concat(args);

if (!args.some(arg => arg.indexOf('config=') === 0)) {
command.push('config=' + join(buildDir, config));
Expand Down

0 comments on commit db198d6

Please sign in to comment.