Skip to content

Commit 5745c43

Browse files
Merge branch 'master' into remove-lodash-typeof-checks
2 parents bcf4870 + 89997b9 commit 5745c43

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/cli/domain/handle-dependencies/get-compiler.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from 'path';
2+
import { Template } from '../../../types';
23

34
import cleanRequire from '../../../utils/clean-require';
45
import { Logger } from '../../logger';
@@ -11,11 +12,11 @@ export default function getCompiler(
1112
logger: Logger;
1213
pkg: { devDependencies: Dictionary<string> };
1314
},
14-
cb: Callback<string, string | number>
15+
cb: Callback<Template, string | number>
1516
): void {
1617
const { compilerDep, componentPath, logger, pkg } = options;
1718
const compilerPath = path.join(componentPath, 'node_modules', compilerDep);
18-
const compiler = cleanRequire(compilerPath, { justTry: true });
19+
const compiler = cleanRequire<Template>(compilerPath, { justTry: true });
1920

2021
if (compiler) {
2122
return cb(null, compiler);

src/cli/domain/handle-dependencies/install-compiler.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import isTemplateValid from '../../../utils/is-template-valid';
33
import * as npm from '../../../utils/npm-utils';
44
import strings from '../../../resources/index';
55
import { Logger } from '../../logger';
6+
import { Template } from '../../../types';
67

78
export default function installCompiler(
89
options: {
@@ -11,7 +12,7 @@ export default function installCompiler(
1112
dependency: string;
1213
logger: Logger;
1314
},
14-
cb: Callback<string, string | number>
15+
cb: Callback<Template, string | number>
1516
): void {
1617
const { compilerPath, componentPath, dependency, logger } = options;
1718

@@ -27,9 +28,9 @@ export default function installCompiler(
2728

2829
npm.installDependency(npmOptions, err => {
2930
err ? logger.err('FAIL') : logger.ok('OK');
30-
const compiler = cleanRequire(compilerPath, { justTry: true });
31+
const compiler = cleanRequire<Template>(compilerPath, { justTry: true });
3132
const isOk = isTemplateValid(compiler);
3233
const errorMsg = 'There was a problem while installing the compiler';
33-
cb(!err && isOk ? null : errorMsg, compiler);
34+
cb(!err && isOk ? null : errorMsg, compiler as Template);
3435
});
3536
}

src/utils/clean-require.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
import tryRequire from 'try-require';
22

3+
export default function cleanRequire(
4+
path: string,
5+
opts: { justTry: true; resolve: true }
6+
): string | undefined;
7+
export default function cleanRequire(
8+
path: string,
9+
opts: { justTry?: false; resolve: true }
10+
): string;
11+
export default function cleanRequire<T = unknown>(
12+
path: string,
13+
opts: { justTry: true; resolve?: false }
14+
): T | undefined;
15+
export default function cleanRequire<T = unknown>(
16+
path: string,
17+
opts: { justTry?: false; resolve?: false }
18+
): T;
319
export default function cleanRequire(
420
path: string,
521
{ justTry = false, resolve = false }: { justTry?: boolean; resolve?: boolean }
6-
): any {
22+
) {
723
const shouldThrow = !justTry;
824

925
if (require.cache && !!require.cache[path]) {

0 commit comments

Comments
 (0)