Skip to content

Commit cb7aea1

Browse files
committed
perf: don't use middleware if has build
`ember serve` and `ember test` has a `path` flag to specify an existing ember build to use, without rebuilding. `ember-cli-typescript` will add typechecking middleware regardless of ember using an existing build, the typechecking middleware is not required. This can slow down the initial request to express server significantly. For instance one project spends 49 secs for initial typecheck on first request. ```sh $ DEBUG=*:* ember s --path dist ... – Serving on http://localhost:4200/admin/ ... ember-cli-typescript:typecheck-worker Typecheck complete (0 diagnostics) +49s ... ```
1 parent 3b1cd07 commit cb7aea1

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

ts/addon.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ export default addon({
4646
return `${__dirname}/blueprints`;
4747
},
4848

49-
serverMiddleware({ app }) {
50-
this._addTypecheckMiddleware(app);
49+
serverMiddleware({ app, options }) {
50+
if (!options?.path) {
51+
this._addTypecheckMiddleware(app);
52+
}
5153
},
5254

53-
testemMiddleware(app) {
54-
this._addTypecheckMiddleware(app);
55+
testemMiddleware(app, options) {
56+
if (!options?.path) {
57+
this._addTypecheckMiddleware(app);
58+
}
5559
},
5660

5761
async postBuild() {

ts/types/ember-cli/index.d.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ declare module 'ember-cli/lib/models/addon' {
1111
import UI from 'console-ui';
1212
import { Application } from 'express';
1313
import Project from 'ember-cli/lib/models/project';
14+
import { TaskOptions } from 'ember-cli/lib/models/task';
1415
import Command from 'ember-cli/lib/models/command';
1516
import EmberApp from 'ember-cli/lib/broccoli/ember-app';
1617
import PreprocessRegistry from 'ember-cli-preprocess-registry';
@@ -36,8 +37,8 @@ declare module 'ember-cli/lib/models/addon' {
3637
includedCommands(): Record<string, typeof Command | ExtendOptions<Command>> | void;
3738
shouldIncludeChildAddon(addon: Addon): boolean;
3839
isDevelopingAddon(): boolean;
39-
serverMiddleware(options: { app: Application }): void | Promise<void>;
40-
testemMiddleware(app: Application): void;
40+
serverMiddleware(options: { app: Application; options?: TaskOptions }): void | Promise<void>;
41+
testemMiddleware(app: Application, options?: TaskOptions): void;
4142
setupPreprocessorRegistry(type: 'self' | 'parent', registry: PreprocessRegistry): void;
4243
}
4344
}
@@ -49,6 +50,12 @@ declare module 'ember-cli/lib/models/blueprint' {
4950
export = Blueprint;
5051
}
5152

53+
declare module 'ember-cli/lib/models/task' {
54+
export interface TaskOptions {
55+
path?: string;
56+
}
57+
}
58+
5259
declare module 'ember-cli/lib/models/command' {
5360
import CoreObject from 'core-object';
5461
import UI from 'console-ui';

0 commit comments

Comments
 (0)