Skip to content

Ensure errors are emitted when ts:precompile fails #984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@commitlint/config-conventional": "8.2.0",
"@ember/optional-features": "1.1.0",
"@typed-ember/renovate-config": "1.2.1",
"@types/capture-console": "^1.0.0",
"@types/chai": "4.2.6",
"@types/chai-as-promised": "7.1.2",
"@types/console-ui": "2.2.3",
Expand All @@ -78,6 +79,7 @@
"@typescript-eslint/eslint-plugin": "2.10.0",
"@typescript-eslint/parser": "2.10.0",
"broccoli-asset-rev": "3.0.0",
"capture-console": "^1.0.1",
"co": "4.6.0",
"commitlint-azure-pipelines-cli": "1.0.2",
"conventional-changelog-cli": "2.0.28",
Expand Down
33 changes: 21 additions & 12 deletions ts/lib/commands/precompile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,27 @@ export default command({
return;
}

// prettier-ignore
await execa('tsc', [
'--allowJs', 'false',
'--noEmit', 'false',
'--rootDir', rootDir || this.project.root,
'--isolatedModules', 'false',
'--declaration',
'--declarationDir', outDir,
'--emitDeclarationOnly',
], {
preferLocal: true
});
try {
// prettier-ignore
await execa('tsc', [
'--allowJs', 'false',
'--noEmit', 'false',
'--rootDir', rootDir || this.project.root,
'--isolatedModules', 'false',
'--declaration',
'--declarationDir', outDir,
'--emitDeclarationOnly',
'--pretty', 'true',
], {
preferLocal: true,

// Capture a string with stdout and stderr interleaved for error reporting
all: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a comment here explaining why we want this? Will make maintenance easier. (I just went and read the execa docs to figure it out, figure it'll save us time in the future from doing the same.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! execa is one of those that I've used enough places that I've lost any good sense of which options are self-describing and which aren't 🙃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sympathize!

});
} catch (e) {
console.error(`\n${e.all}\n`);
throw e;
}

let manifestPath = options.manifestPath;
let packageName = this.project.pkg.name;
Expand Down
20 changes: 19 additions & 1 deletion ts/tests/commands/precompile-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs-extra';

import { hook } from 'capture-console';
import ember from 'ember-cli-blueprint-test-helpers/lib/helpers/ember';
import blueprintHelpers from 'ember-cli-blueprint-test-helpers/helpers';
const setupTestHooks = blueprintHelpers.setupTestHooks;
Expand Down Expand Up @@ -38,6 +38,24 @@ describe('Acceptance: ts:precompile command', function() {
expect(declaration).not.to.exist;
});

it('emits errors to the console when precompilation fails', async () => {
fs.ensureDirSync('app');
fs.writeFileSync('app/test-file.ts', `export const testString: string = 123;`);

let output = '';
let unhookStdout = hook(process.stdout, { quiet: true }, chunk => (output += chunk));
let unhookStderr = hook(process.stderr, { quiet: true }, chunk => (output += chunk));
try {
await ember(['ts:precompile']);
expect.fail('Precompilation should have failed');
} catch {
expect(output).to.include(`Type '123' is not assignable to type 'string'.`);
} finally {
unhookStdout();
unhookStderr();
}
});

describe('custom project layout', function() {
it('generates .d.ts files from the specified source tree', async () => {
fs.ensureDirSync('src');
Expand Down
52 changes: 50 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,13 @@
"@types/connect" "*"
"@types/node" "*"

"@types/capture-console@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/capture-console/-/capture-console-1.0.0.tgz#8730d90248d862c4ccdaf5a623bfee0272d9a934"
integrity sha512-v6XDGk++qgUNmL5oqjmrK/tYIRmekq9FO8vgVv4xAx9frJYTwWUI+iOa+2z48zw+ZHfVVTNxL1qT9wuZZUrDVg==
dependencies:
"@types/node" "*"

"@types/[email protected]":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-7.1.2.tgz#2f564420e81eaf8650169e5a3a6b93e096e5068b"
Expand Down Expand Up @@ -2414,6 +2421,14 @@ arg@^4.1.0:
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.0.tgz#583c518199419e0037abb74062c37f8519e575f0"
integrity sha512-ZWc51jO3qegGkVh8Hwpv636EkbesNV5ZNQPCtRa+0qytRYPEs9IYT9qITY9buezqUH5uqyzlWLcufrzU2rffdg==

argle@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/argle/-/argle-1.1.1.tgz#0cfe3bc032c36b2f48ba42b9c17f89f70607e994"
integrity sha1-DP47wDLDay9IukK5wX+J9wYH6ZQ=
dependencies:
lodash.isfunction "^3.0.8"
lodash.isnumber "^3.0.3"

argparse@^1.0.7, argparse@~1.0.2:
version "1.0.10"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
Expand Down Expand Up @@ -2475,6 +2490,11 @@ array-union@^1.0.1:
dependencies:
array-uniq "^1.0.1"

[email protected]:
version "1.0.2"
resolved "https://registry.yarnpkg.com/array-uniq/-/array-uniq-1.0.2.tgz#5fcc373920775723cfd64d65c64bef53bf9eba6d"
integrity sha1-X8w3OSB3VyPP1k1lxkvvU7+eum0=

array-uniq@^1.0.1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/array-uniq/-/array-uniq-1.0.3.tgz#af6ac877a25cc7f74e058894753858dfdb24fdb6"
Expand Down Expand Up @@ -4646,6 +4666,15 @@ caniuse-lite@^1.0.30001010:
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001011.tgz#0d6c4549c78c4a800bb043a83ca0cbe0aee6c6e1"
integrity sha512-h+Eqyn/YA6o6ZTqpS86PyRmNWOs1r54EBDcd2NTwwfsXQ8re1B38SnB+p2RKF8OUsyEIjeDU8XGec1RGO/wYCg==

capture-console@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/capture-console/-/capture-console-1.0.1.tgz#db63c39ac73239019badd7fbb10143eda380ff71"
integrity sha1-22PDmscyOQGbrdf7sQFD7aOA/3E=
dependencies:
argle "~1.1.1"
lodash.isfunction "~3.0.8"
randomstring "~1.1.5"

capture-exit@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4"
Expand Down Expand Up @@ -9552,10 +9581,12 @@ imurmurhash@^0.1.4:
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=

"in-repo-a@link:tests/dummy/lib/in-repo-a":
version "1.0.0"
version "0.0.0"
uid ""

"in-repo-b@link:tests/dummy/lib/in-repo-b":
version "1.0.0"
version "0.0.0"
uid ""

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

lodash.isfunction@^3.0.8, lodash.isfunction@~3.0.8:
version "3.0.9"
resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-3.0.9.tgz#06de25df4db327ac931981d1bdb067e5af68d051"
integrity sha512-AirXNj15uRIMMPihnkInB4i3NHeb4iBtNg9WRWuK2o31S+ePwwNmDPaTL3o7dTJ+VXNZim7rFs4rxN4YU1oUJw==

lodash.isfunction@~2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/lodash.isfunction/-/lodash.isfunction-2.3.0.tgz#6b2973e47a647cf12e70d676aea13643706e5267"
Expand All @@ -10938,6 +10974,11 @@ lodash.ismatch@^4.4.0:
resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37"
integrity sha1-dWy1FQyjum8RCFp4hJZF8Yj4Xzc=

lodash.isnumber@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz#3ce76810c5928d03352301ac287317f11c0b1ffc"
integrity sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w=

lodash.isobject@~2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/lodash.isobject/-/lodash.isobject-2.3.0.tgz#2e16d3fc583da9831968953f2d8e6d73434f6799"
Expand Down Expand Up @@ -13424,6 +13465,13 @@ randomfill@^1.0.3:
randombytes "^2.0.5"
safe-buffer "^5.1.0"

randomstring@~1.1.5:
version "1.1.5"
resolved "https://registry.yarnpkg.com/randomstring/-/randomstring-1.1.5.tgz#6df0628f75cbd5932930d9fe3ab4e956a18518c3"
integrity sha1-bfBij3XL1ZMpMNn+OrTpVqGFGMM=
dependencies:
array-uniq "1.0.2"

range-parser@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e"
Expand Down