Skip to content

Commit 54cdb8d

Browse files
authored
Merge pull request #984 from typed-ember/emit-precompile-errors
Ensure errors are emitted when ts:precompile fails
2 parents 0c56939 + 1a994a1 commit 54cdb8d

File tree

4 files changed

+92
-15
lines changed

4 files changed

+92
-15
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@commitlint/config-conventional": "8.2.0",
5959
"@ember/optional-features": "1.1.0",
6060
"@typed-ember/renovate-config": "1.2.1",
61+
"@types/capture-console": "^1.0.0",
6162
"@types/chai": "4.2.6",
6263
"@types/chai-as-promised": "7.1.2",
6364
"@types/console-ui": "2.2.3",
@@ -78,6 +79,7 @@
7879
"@typescript-eslint/eslint-plugin": "2.10.0",
7980
"@typescript-eslint/parser": "2.10.0",
8081
"broccoli-asset-rev": "3.0.0",
82+
"capture-console": "^1.0.1",
8183
"co": "4.6.0",
8284
"commitlint-azure-pipelines-cli": "1.0.2",
8385
"conventional-changelog-cli": "2.0.28",

ts/lib/commands/precompile.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,27 @@ export default command({
2525
return;
2626
}
2727

28-
// prettier-ignore
29-
await execa('tsc', [
30-
'--allowJs', 'false',
31-
'--noEmit', 'false',
32-
'--rootDir', rootDir || this.project.root,
33-
'--isolatedModules', 'false',
34-
'--declaration',
35-
'--declarationDir', outDir,
36-
'--emitDeclarationOnly',
37-
], {
38-
preferLocal: true
39-
});
28+
try {
29+
// prettier-ignore
30+
await execa('tsc', [
31+
'--allowJs', 'false',
32+
'--noEmit', 'false',
33+
'--rootDir', rootDir || this.project.root,
34+
'--isolatedModules', 'false',
35+
'--declaration',
36+
'--declarationDir', outDir,
37+
'--emitDeclarationOnly',
38+
'--pretty', 'true',
39+
], {
40+
preferLocal: true,
41+
42+
// Capture a string with stdout and stderr interleaved for error reporting
43+
all: true,
44+
});
45+
} catch (e) {
46+
console.error(`\n${e.all}\n`);
47+
throw e;
48+
}
4049

4150
let manifestPath = options.manifestPath;
4251
let packageName = this.project.pkg.name;

ts/tests/commands/precompile-test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as fs from 'fs-extra';
2-
2+
import { hook } from 'capture-console';
33
import ember from 'ember-cli-blueprint-test-helpers/lib/helpers/ember';
44
import blueprintHelpers from 'ember-cli-blueprint-test-helpers/helpers';
55
const setupTestHooks = blueprintHelpers.setupTestHooks;
@@ -38,6 +38,24 @@ describe('Acceptance: ts:precompile command', function() {
3838
expect(declaration).not.to.exist;
3939
});
4040

41+
it('emits errors to the console when precompilation fails', async () => {
42+
fs.ensureDirSync('app');
43+
fs.writeFileSync('app/test-file.ts', `export const testString: string = 123;`);
44+
45+
let output = '';
46+
let unhookStdout = hook(process.stdout, { quiet: true }, chunk => (output += chunk));
47+
let unhookStderr = hook(process.stderr, { quiet: true }, chunk => (output += chunk));
48+
try {
49+
await ember(['ts:precompile']);
50+
expect.fail('Precompilation should have failed');
51+
} catch {
52+
expect(output).to.include(`Type '123' is not assignable to type 'string'.`);
53+
} finally {
54+
unhookStdout();
55+
unhookStderr();
56+
}
57+
});
58+
4159
describe('custom project layout', function() {
4260
it('generates .d.ts files from the specified source tree', async () => {
4361
fs.ensureDirSync('src');

yarn.lock

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,13 @@
15031503
"@types/connect" "*"
15041504
"@types/node" "*"
15051505

1506+
"@types/capture-console@^1.0.0":
1507+
version "1.0.0"
1508+
resolved "https://registry.yarnpkg.com/@types/capture-console/-/capture-console-1.0.0.tgz#8730d90248d862c4ccdaf5a623bfee0272d9a934"
1509+
integrity sha512-v6XDGk++qgUNmL5oqjmrK/tYIRmekq9FO8vgVv4xAx9frJYTwWUI+iOa+2z48zw+ZHfVVTNxL1qT9wuZZUrDVg==
1510+
dependencies:
1511+
"@types/node" "*"
1512+
15061513
"@types/chai-as-promised@7.1.2":
15071514
version "7.1.2"
15081515
resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-7.1.2.tgz#2f564420e81eaf8650169e5a3a6b93e096e5068b"
@@ -2414,6 +2421,14 @@ arg@^4.1.0:
24142421
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.0.tgz#583c518199419e0037abb74062c37f8519e575f0"
24152422
integrity sha512-ZWc51jO3qegGkVh8Hwpv636EkbesNV5ZNQPCtRa+0qytRYPEs9IYT9qITY9buezqUH5uqyzlWLcufrzU2rffdg==
24162423

2424+
argle@~1.1.1:
2425+
version "1.1.1"
2426+
resolved "https://registry.yarnpkg.com/argle/-/argle-1.1.1.tgz#0cfe3bc032c36b2f48ba42b9c17f89f70607e994"
2427+
integrity sha1-DP47wDLDay9IukK5wX+J9wYH6ZQ=
2428+
dependencies:
2429+
lodash.isfunction "^3.0.8"
2430+
lodash.isnumber "^3.0.3"
2431+
24172432
argparse@^1.0.7, argparse@~1.0.2:
24182433
version "1.0.10"
24192434
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
@@ -2475,6 +2490,11 @@ array-union@^1.0.1:
24752490
dependencies:
24762491
array-uniq "^1.0.1"
24772492

2493+
array-uniq@1.0.2:
2494+
version "1.0.2"
2495+
resolved "https://registry.yarnpkg.com/array-uniq/-/array-uniq-1.0.2.tgz#5fcc373920775723cfd64d65c64bef53bf9eba6d"
2496+
integrity sha1-X8w3OSB3VyPP1k1lxkvvU7+eum0=
2497+
24782498
array-uniq@^1.0.1:
24792499
version "1.0.3"
24802500
resolved "https://registry.yarnpkg.com/array-uniq/-/array-uniq-1.0.3.tgz#af6ac877a25cc7f74e058894753858dfdb24fdb6"
@@ -4646,6 +4666,15 @@ caniuse-lite@^1.0.30001010:
46464666
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001011.tgz#0d6c4549c78c4a800bb043a83ca0cbe0aee6c6e1"
46474667
integrity sha512-h+Eqyn/YA6o6ZTqpS86PyRmNWOs1r54EBDcd2NTwwfsXQ8re1B38SnB+p2RKF8OUsyEIjeDU8XGec1RGO/wYCg==
46484668

4669+
capture-console@^1.0.1:
4670+
version "1.0.1"
4671+
resolved "https://registry.yarnpkg.com/capture-console/-/capture-console-1.0.1.tgz#db63c39ac73239019badd7fbb10143eda380ff71"
4672+
integrity sha1-22PDmscyOQGbrdf7sQFD7aOA/3E=
4673+
dependencies:
4674+
argle "~1.1.1"
4675+
lodash.isfunction "~3.0.8"
4676+
randomstring "~1.1.5"
4677+
46494678
capture-exit@^2.0.0:
46504679
version "2.0.0"
46514680
resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4"
@@ -9552,10 +9581,12 @@ imurmurhash@^0.1.4:
95529581
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
95539582

95549583
"in-repo-a@link:tests/dummy/lib/in-repo-a":
9555-
version "1.0.0"
9584+
version "0.0.0"
9585+
uid ""
95569586

95579587
"in-repo-b@link:tests/dummy/lib/in-repo-b":
9558-
version "1.0.0"
9588+
version "0.0.0"
9589+
uid ""
95599590

95609591
include-path-searcher@^0.1.0:
95619592
version "0.1.0"
@@ -10928,6 +10959,11 @@ lodash.isarray@^3.0.0:
1092810959
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55"
1092910960
integrity sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U=
1093010961

10962+
lodash.isfunction@^3.0.8, lodash.isfunction@~3.0.8:
10963+
version "3.0.9"
10964+
resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-3.0.9.tgz#06de25df4db327ac931981d1bdb067e5af68d051"
10965+
integrity sha512-AirXNj15uRIMMPihnkInB4i3NHeb4iBtNg9WRWuK2o31S+ePwwNmDPaTL3o7dTJ+VXNZim7rFs4rxN4YU1oUJw==
10966+
1093110967
lodash.isfunction@~2.3.0:
1093210968
version "2.3.0"
1093310969
resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-2.3.0.tgz#6b2973e47a647cf12e70d676aea13643706e5267"
@@ -10938,6 +10974,11 @@ lodash.ismatch@^4.4.0:
1093810974
resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37"
1093910975
integrity sha1-dWy1FQyjum8RCFp4hJZF8Yj4Xzc=
1094010976

10977+
lodash.isnumber@^3.0.3:
10978+
version "3.0.3"
10979+
resolved "https://registry.yarnpkg.com/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz#3ce76810c5928d03352301ac287317f11c0b1ffc"
10980+
integrity sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w=
10981+
1094110982
lodash.isobject@~2.3.0:
1094210983
version "2.3.0"
1094310984
resolved "https://registry.yarnpkg.com/lodash.isobject/-/lodash.isobject-2.3.0.tgz#2e16d3fc583da9831968953f2d8e6d73434f6799"
@@ -13424,6 +13465,13 @@ randomfill@^1.0.3:
1342413465
randombytes "^2.0.5"
1342513466
safe-buffer "^5.1.0"
1342613467

13468+
randomstring@~1.1.5:
13469+
version "1.1.5"
13470+
resolved "https://registry.yarnpkg.com/randomstring/-/randomstring-1.1.5.tgz#6df0628f75cbd5932930d9fe3ab4e956a18518c3"
13471+
integrity sha1-bfBij3XL1ZMpMNn+OrTpVqGFGMM=
13472+
dependencies:
13473+
array-uniq "1.0.2"
13474+
1342713475
range-parser@~1.2.0:
1342813476
version "1.2.0"
1342913477
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e"

0 commit comments

Comments
 (0)