Skip to content

Commit ba0b3ee

Browse files
committed
Add support for --build --verbose invocations
This is super handy for debugging when a `--build` is failing for some reason. The default reporting from `tsc` or `glint` itself isn't always helpful: it tends to bottom out with a *symptom* like "some type is not defined" without any way to get to the root cause of *why* that type is not defined. Having `--verbose` available for a `--build` invocation surfaces additional information, including which `references` are being built or not, and why.
1 parent 84f23ef commit ba0b3ee

File tree

2 files changed

+182
-0
lines changed

2 files changed

+182
-0
lines changed

packages/core/__tests__/cli/build.test.ts

+175
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,89 @@ describe('CLI: single-pass build mode typechecking', () => {
131131
"
132132
`);
133133
});
134+
135+
describe('with `--verbose`', () => {
136+
test('prints verbose output for a valid basic project', async () => {
137+
let code = stripIndent`
138+
import '@glint/environment-ember-template-imports';
139+
import Component from '@glimmer/component';
140+
141+
type ApplicationArgs = {
142+
version: string;
143+
};
144+
145+
export default class Application extends Component<{ Args: ApplicationArgs }> {
146+
private startupTime = new Date().toISOString();
147+
148+
<template>
149+
Welcome to app v{{@version}}.
150+
The current time is {{this.startupTime}}.
151+
</template>
152+
}
153+
`;
154+
155+
project.write(INPUT_SFC, code);
156+
157+
let checkResult = await project.build({ reject: false, flags: ['--verbose'] });
158+
159+
expect(checkResult.exitCode).toBe(0);
160+
expect(checkResult.stdout).toMatchInlineSnapshot(`
161+
"5:05:42 PM - Projects in this build:
162+
* tsconfig.json
163+
164+
5:05:42 PM - Project 'tsconfig.json' is out of date because output file 'dist/tsconfig.tsbuildinfo' does not exist
165+
166+
5:05:42 PM - Building project '/Users/ckrycho/dev/typed-ember/glint/test-packages/ephemeral/050b3ab021eb4/tsconfig.json'...
167+
"
168+
`);
169+
expect(checkResult.stderr).toEqual('');
170+
});
171+
172+
test('prints verbose output for a project with a basic template type error', async () => {
173+
let code = stripIndent`
174+
import '@glint/environment-ember-template-imports';
175+
import Component from '@glimmer/component';
176+
177+
type ApplicationArgs = {
178+
version: string;
179+
};
180+
181+
const truncate = (length: number, s: string): string =>
182+
s.slice(0, length);
183+
184+
export default class Application extends Component<{ Args: ApplicationArgs }> {
185+
private startupTime = new Date().toISOString();
186+
187+
<template>
188+
Welcome to app v{{@version}}.
189+
The current time is {{truncate this.startupTime 12}}.
190+
</template>
191+
}
192+
`;
193+
194+
project.write(INPUT_SFC, code);
195+
196+
let checkResult = await project.build({ reject: false, flags: ['--verbose'] });
197+
198+
expect(checkResult.exitCode).toBe(1);
199+
expect(checkResult.stdout).toMatchInlineSnapshot(`
200+
"5:06:23 PM - Projects in this build:
201+
* tsconfig.json
202+
203+
5:06:23 PM - Project 'tsconfig.json' is out of date because output file 'dist/tsconfig.tsbuildinfo' does not exist
204+
205+
5:06:23 PM - Building project '/Users/ckrycho/dev/typed-ember/glint/test-packages/ephemeral/4039021e6fc86/tsconfig.json'...
206+
"
207+
`);
208+
expect(stripAnsi(checkResult.stderr)).toMatchInlineSnapshot(`
209+
"src/index.gts:16:36 - error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
210+
211+
16 The current time is {{truncate this.startupTime 12}}.
212+
~~~~~~~~~~~~~~~~
213+
"
214+
`);
215+
});
216+
});
134217
});
135218

136219
describe('composite projects', () => {
@@ -1067,6 +1150,98 @@ describe('CLI: single-pass build mode typechecking', () => {
10671150
});
10681151
});
10691152
});
1153+
1154+
describe('with `--verbose`', () => {
1155+
test('for a valid composite subproject with a reference', async () => {
1156+
let checkResult = await projects.children.a.build({ reject: false, flags: ['--verbose'] });
1157+
1158+
expect(checkResult.stdout).toMatchInlineSnapshot(`
1159+
"8:47:43 AM - Projects in this build:
1160+
* ../c/tsconfig.json
1161+
* tsconfig.json
1162+
1163+
8:47:43 AM - Project '../c/tsconfig.json' is out of date because output file '../c/tsconfig.tsbuildinfo' does not exist
1164+
1165+
8:47:43 AM - Building project '/Users/ckrycho/dev/typed-ember/glint/test-packages/ephemeral/9c9b34b0f5557/c/tsconfig.json'...
1166+
1167+
8:47:44 AM - Project 'tsconfig.json' is out of date because output file 'tsconfig.tsbuildinfo' does not exist
1168+
1169+
8:47:44 AM - Building project '/Users/ckrycho/dev/typed-ember/glint/test-packages/ephemeral/9c9b34b0f5557/a/tsconfig.json'...
1170+
"
1171+
`);
1172+
});
1173+
1174+
test('for a project transitively referenced by the root with a template type error, built from the main project', async () => {
1175+
let rootCode = stripIndent`
1176+
import Component from '@glimmer/component';
1177+
import A from '@glint-test/a';
1178+
import B from '@glint-test/b';
1179+
1180+
type ApplicationArgs = {
1181+
version: string;
1182+
};
1183+
1184+
export default class Application extends Component<{ Args: ApplicationArgs }> {
1185+
private startupTime = new Date().toISOString();
1186+
1187+
<template>
1188+
Welcome to app v{{@version}}.
1189+
The current time is {{this.startupTime}}.
1190+
</template>
1191+
}
1192+
`;
1193+
1194+
let aCode = stripIndent`
1195+
import C from '@glint-test/c';
1196+
const A = 'hello ' + C;
1197+
export default A;
1198+
`;
1199+
1200+
let bCode = stripIndent`
1201+
const B = 'ahoy';
1202+
export default B;
1203+
`;
1204+
1205+
let cCode = stripIndent`
1206+
const double = (n: number) => n * 2;
1207+
const useDouble = <template>{{double "hello"}}</template>;
1208+
const C = 'world';
1209+
export default C;
1210+
`;
1211+
1212+
projects.main.write(INPUT_SFC, rootCode);
1213+
projects.children.a.write(INPUT_SFC, aCode);
1214+
projects.children.b.write(INPUT_SFC, bCode);
1215+
projects.children.c.write(INPUT_SFC, cCode);
1216+
1217+
let checkResult = await projects.main.build({ reject: false, flags: ['--verbose'] });
1218+
1219+
expect(checkResult.stdout).toMatchInlineSnapshot(`
1220+
"8:49:55 AM - Projects in this build:
1221+
* ../c/tsconfig.json
1222+
* ../a/tsconfig.json
1223+
* ../b/tsconfig.json
1224+
* tsconfig.json
1225+
1226+
8:49:55 AM - Project '../c/tsconfig.json' is out of date because output file '../c/tsconfig.tsbuildinfo' does not exist
1227+
1228+
8:49:55 AM - Building project '/Users/ckrycho/dev/typed-ember/glint/test-packages/ephemeral/7d5585b51d249/c/tsconfig.json'...
1229+
1230+
8:49:56 AM - Project '../a/tsconfig.json' can't be built because its dependency '../c' has errors
1231+
1232+
8:49:56 AM - Skipping build of project '/Users/ckrycho/dev/typed-ember/glint/test-packages/ephemeral/7d5585b51d249/a/tsconfig.json' because its dependency '/Users/ckrycho/dev/typed-ember/glint/test-packages/ephemeral/7d5585b51d249/c' has errors
1233+
1234+
8:49:56 AM - Project '../b/tsconfig.json' is out of date because output file '../b/tsconfig.tsbuildinfo' does not exist
1235+
1236+
8:49:56 AM - Building project '/Users/ckrycho/dev/typed-ember/glint/test-packages/ephemeral/7d5585b51d249/b/tsconfig.json'...
1237+
1238+
8:49:56 AM - Project 'tsconfig.json' can't be built because its dependency '../a' was not built
1239+
1240+
8:49:56 AM - Skipping build of project '/Users/ckrycho/dev/typed-ember/glint/test-packages/ephemeral/7d5585b51d249/main/tsconfig.json' because its dependency '/Users/ckrycho/dev/typed-ember/glint/test-packages/ephemeral/7d5585b51d249/a' was not built
1241+
"
1242+
`);
1243+
});
1244+
});
10701245
});
10711246
});
10721247

packages/core/src/cli/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ const argv = yargs(process.argv.slice(2))
5454
description: `Show what would be built (or deleted, if specified with '--clean'). Same as the TS \`--dry\` flag.`,
5555
type: 'boolean',
5656
})
57+
.option('verbose', {
58+
implies: 'build',
59+
description:
60+
'Prints out verbose logging to explain what’s going on (may be combined with any other flag). Same as the TS `--verbose` flag.',
61+
type: 'boolean',
62+
})
5763
.option('incremental', {
5864
description:
5965
'Save .tsbuildinfo files to allow for incremental compilation of projects. Same as the TS `--incremental` flag.',
@@ -87,6 +93,7 @@ if (argv.build) {
8793
clean: argv.clean,
8894
force: argv.force,
8995
dry: argv.dry,
96+
verbose: argv.verbose,
9097
};
9198

9299
if ('incremental' in argv) {

0 commit comments

Comments
 (0)