Skip to content

Commit ce4246c

Browse files
authored
fix: conditionally require lint, format (#49)
PR-URL: #49
1 parent 5e3c3f2 commit ce4246c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/cli.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import * as meow from 'meow';
1818
import * as updateNotifier from 'update-notifier';
1919
import {init} from './init';
20-
import {lint} from './lint';
21-
import {format} from './format';
2220
import {clean} from './clean';
2321

2422
export interface Logger {
@@ -35,6 +33,9 @@ export interface Options {
3533
logger: Logger;
3634
}
3735

36+
export type VerbFunction = (options: Options, fix?: boolean) =>
37+
Promise<boolean>;
38+
3839
const logger: Logger = console;
3940

4041
const cli = meow(`
@@ -74,9 +75,15 @@ async function run(verb: string): Promise<boolean> {
7475
yes: cli.flags.yes || cli.flags.y || false,
7576
logger: logger
7677
};
78+
// Linting/formatting depend on typescript. We don't want to load the
79+
// typescript module during init, since it might not exist.
80+
// See: https://github.com/google/ts-style/issues/48
81+
if (verb === 'init') {
82+
return await init(options);
83+
}
84+
const lint: VerbFunction = require('./lint');
85+
const format: VerbFunction = require('./format');
7786
switch (verb) {
78-
case 'init':
79-
return await init(options);
8087
case 'check':
8188
return (await lint(options) && await format(options));
8289
case 'fix':

0 commit comments

Comments
 (0)