Skip to content

Commit d6e48b8

Browse files
committed
compile all files using the right tsconfig.json
- tsc-wrapper.js is just a wrapper on top of tsc for VS Code, that walks up the dirtree until a tsconfig.json is found and compiles at that path. necessary for tasks.json configuration - test compilation will also work with this, but there's an issue with test/tsconfig.json
1 parent f170da3 commit d6e48b8

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

.settings/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
".git",
1414
".tscache",
1515
"bower_components",
16+
"bin",
1617
"build",
1718
"lib",
1819
"node_modules"

.settings/tasks.json

+5-14
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,14 @@
66
// ${fileExtname}: the current opened file's extension
77
// ${cwd}: the current working directory of the spawned process
88

9-
// A task runner that calls the Typescipt compiler (tsc) and compiles based on a tsconfig.json file
9+
// A task runner that calls scripts/tsc-wrapper.js. The wrapper script traverses
10+
// up the file system until a valid `tsconfig.json` is found, and runs `tsc` from
11+
// node_modules with that path as the root
1012
{
1113
"version": "0.1.0",
12-
13-
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
14-
"command": "${workspaceRoot}/node_modules/typescript/bin/tsc",
15-
16-
// The command is a shell script
14+
"command": "${workspaceRoot}/scripts/tsc-wrapper.js",
1715
"isShellCommand": true,
18-
19-
// Show the output window only if unrecognized errors occur.
2016
"showOutput": "silent",
21-
22-
// Tell the tsc compiler to use the tsconfig.json from the open folder.
23-
"args": ["-p", "${fileDirname}"],
24-
25-
// use the standard tsc problem matcher to find compile problems
26-
// in the output.
17+
"args": ["${workspaceRoot}", "${fileDirname}"],
2718
"problemMatcher": "$tsc"
2819
}

scripts/tsc-wrapper.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env node
2+
3+
/* global process */
4+
5+
var execSync = require("child_process").execSync;
6+
var findup = require("findup-sync");
7+
var path = require("path");
8+
var spawnSync = require("child_process").spawnSync;
9+
10+
/* print a buffer to a stream */
11+
function print(buffer, stream) {
12+
if (buffer != null) {
13+
var output = buffer.toString("utf8");
14+
stream.write(output);
15+
}
16+
}
17+
18+
var argv = process.argv;
19+
if (argv.length < 4) {
20+
console.error("insufficient arguments to tsc wrapper");
21+
process.exit(1);
22+
}
23+
24+
var workspacePath = argv[2];
25+
var filePath = argv[3];
26+
27+
var configPath = path.dirname(findup("tsconfig.json", { cwd: filePath, nocase: true }));
28+
if (configPath == null) {
29+
console.error("tsconfig.json not found");
30+
process.exit(2);
31+
}
32+
33+
var tscPath = path.join(workspacePath, "node_modules", "typescript", "bin", "tsc");
34+
var tsc = spawnSync(tscPath, ["-p", configPath]);
35+
36+
print(tsc.stdout, process.stdout);
37+
print(tsc.stderr, process.stderr);
38+
process.exit(tsc.status);

0 commit comments

Comments
 (0)