Skip to content

Commit d919492

Browse files
committed
ci(definitely-typed): fix build
1 parent 62d3a99 commit d919492

File tree

5 files changed

+101
-61
lines changed

5 files changed

+101
-61
lines changed

definitelyTypedTests/package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

definitelyTypedTests/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"install-types": "node src/installTypes.js",
1111
"process-all-types": "node index.js TYPES_COUNT=all PROCESS_COUNT=20 OUTPUT=true",
1212
"process-types": "node index.js",
13+
"ts-check:src": "tsc --noEmit",
1314
"post-process-types": "node src/postProcessTypes.js",
1415
"dry-process-specific-types": "cross-var npm run process-types TYPES=$TYPES_SPECIFIED"
1516
},
@@ -19,7 +20,9 @@
1920
"cross-var": "^1.1.0",
2021
"dotenv": "^8.2.0",
2122
"ttypescript": "^1.5.12",
22-
"typescript": "^4.1.3",
2323
"upath": "^2.0.1"
24+
},
25+
"devDependencies": {
26+
"typescript": "^4.3.5"
2427
}
2528
}

definitelyTypedTests/src/transformer/customFunctions/create-definitely-typed-mock.ts

Lines changed: 82 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,101 @@ import { Scope } from '../../../../src/transformer/scope/scope';
1010
import { core } from '../../../../src/transformer/core/core';
1111
import { DefinitelyTypedTransformerLogger } from '../logger';
1212

13-
type CompatibleStatement = ts.InterfaceDeclaration | ts.FunctionDeclaration | ts.ClassDeclaration | ts.ModuleDeclaration;
13+
type CompatibleStatement =
14+
| ts.InterfaceDeclaration
15+
| ts.FunctionDeclaration
16+
| ts.ClassDeclaration
17+
| ts.ModuleDeclaration;
1418

15-
export const createDefinitelyTypedMockCustomFunction: CustomFunction = customFunctionWithTypeArgument(
16-
'create-definitely-typed-mock.d.ts',
17-
'createDefinitelyTypedMock',
18-
(node: ts.CallExpression, nodeToMock: ts.TypeNode): ts.Node => {
19-
if (core.ts.isTypeQueryNode(nodeToMock)) {
20-
SetCurrentCreateMock(node);
21-
const typeChecker: ts.TypeChecker = core.typeChecker;
22-
const typeQuerySymbol: ts.Symbol | undefined = typeChecker.getSymbolAtLocation(nodeToMock.exprName);
19+
export const createDefinitelyTypedMockCustomFunction: CustomFunction =
20+
customFunctionWithTypeArgument(
21+
'create-definitely-typed-mock.d.ts',
22+
'createDefinitelyTypedMock',
23+
(node: ts.CallExpression, nodeToMock: ts.TypeNode): ts.Node => {
24+
if (core.ts.isTypeQueryNode(nodeToMock)) {
25+
SetCurrentCreateMock(node);
26+
const typeChecker: ts.TypeChecker = core.typeChecker;
27+
const typeQuerySymbol: ts.Symbol | undefined =
28+
typeChecker.getSymbolAtLocation(nodeToMock.exprName);
2329

24-
if (!typeQuerySymbol) {
25-
return getMock(node, { nodeToMock });
26-
}
30+
if (!typeQuerySymbol) {
31+
return getMock(node, { nodeToMock });
32+
}
2733

28-
const typeQuerySymbolDeclaration: ts.ImportEqualsDeclaration = typeQuerySymbol.declarations[0] as ts.ImportEqualsDeclaration;
29-
const symbolAlias: ts.Symbol | undefined = typeChecker.getSymbolAtLocation(typeQuerySymbolDeclaration.name);
34+
const typeQuerySymbolDeclaration: ts.ImportEqualsDeclaration =
35+
typeQuerySymbol.declarations?.[0] as ts.ImportEqualsDeclaration;
36+
const symbolAlias: ts.Symbol | undefined =
37+
typeChecker.getSymbolAtLocation(typeQuerySymbolDeclaration.name);
3038

31-
if (!symbolAlias) {
32-
return getMock(node, { nodeToMock });
33-
}
39+
if (!symbolAlias) {
40+
return getMock(node, { nodeToMock });
41+
}
3442

35-
const symbol: ts.Symbol = typeChecker.getAliasedSymbol(symbolAlias);
43+
const symbol: ts.Symbol = typeChecker.getAliasedSymbol(symbolAlias);
3644

37-
if (!symbol.declarations) {
38-
const moduleName: string =
39-
((typeQuerySymbolDeclaration.moduleReference as ts.ExternalModuleReference).expression as ts.StringLiteral).text;
40-
const pathModule: string = path.resolve(moduleName);
41-
const moduleWithoutExportsFile: ts.SourceFile = core.program.getSourceFiles().find((file: ts.SourceFile) =>
42-
path.relative(file.fileName, path.join(pathModule, 'index.d.ts')) === ''
43-
) as ts.SourceFile;
45+
if (!symbol.declarations) {
46+
const moduleName: string = (
47+
(
48+
typeQuerySymbolDeclaration.moduleReference as ts.ExternalModuleReference
49+
).expression as ts.StringLiteral
50+
).text;
51+
const pathModule: string = path.resolve(moduleName);
52+
const moduleWithoutExportsFile: ts.SourceFile = core.program
53+
.getSourceFiles()
54+
.find(
55+
(file: ts.SourceFile) =>
56+
path.relative(
57+
file.fileName,
58+
path.join(pathModule, 'index.d.ts')
59+
) === ''
60+
) as ts.SourceFile;
4461

45-
const compatibleStatements: ts.Statement[] = moduleWithoutExportsFile.statements.filter(
46-
(statement: ts.Statement) => statement.kind === core.ts.SyntaxKind.InterfaceDeclaration
47-
|| statement.kind === core.ts.SyntaxKind.FunctionDeclaration
48-
|| statement.kind === core.ts.SyntaxKind.ClassDeclaration
49-
|| statement.kind === core.ts.SyntaxKind.ModuleDeclaration
50-
);
62+
const compatibleStatements: ts.Statement[] =
63+
moduleWithoutExportsFile.statements.filter(
64+
(statement: ts.Statement) =>
65+
statement.kind === core.ts.SyntaxKind.InterfaceDeclaration ||
66+
statement.kind === core.ts.SyntaxKind.FunctionDeclaration ||
67+
statement.kind === core.ts.SyntaxKind.ClassDeclaration ||
68+
statement.kind === core.ts.SyntaxKind.ModuleDeclaration
69+
);
5170

52-
if (compatibleStatements.length > 0) {
53-
return core.ts.createArrayLiteral(compatibleStatements.map(
54-
(workingStatement: CompatibleStatement) => {
55-
const name: ts.Identifier = workingStatement.name as ts.Identifier;
56-
const scope = new Scope();
71+
if (compatibleStatements.length > 0) {
72+
return core.ts.createArrayLiteral(
73+
compatibleStatements.map(
74+
(workingStatement: CompatibleStatement) => {
75+
const name: ts.Identifier =
76+
workingStatement.name as ts.Identifier;
77+
const scope = new Scope();
5778

58-
if (core.ts.isModuleDeclaration(workingStatement)) {
59-
return GetMockPropertiesFromDeclarations(
60-
GetPropertiesFromSourceFileOrModuleDeclaration((workingStatement as any).symbol, scope),
61-
[],
62-
scope
63-
);
64-
}
79+
if (core.ts.isModuleDeclaration(workingStatement)) {
80+
return GetMockPropertiesFromDeclarations(
81+
GetPropertiesFromSourceFileOrModuleDeclaration(
82+
(workingStatement as any).symbol,
83+
scope
84+
),
85+
[],
86+
scope
87+
);
88+
}
6589

66-
const nodeToMock: ts.TypeReferenceNode = core.ts.createTypeReferenceNode(name, undefined);
67-
return getMock(node, { nodeToMock });
90+
const nodeToMock: ts.TypeReferenceNode =
91+
core.ts.createTypeReferenceNode(name, undefined);
92+
return getMock(node, { nodeToMock });
93+
},
94+
[]
95+
)
96+
);
97+
}
98+
DefinitelyTypedTransformerLogger().moduleWithoutValidTypeStatements(
99+
moduleName
100+
);
68101

69-
}, []));
102+
return node;
70103
}
71-
DefinitelyTypedTransformerLogger().moduleWithoutValidTypeStatements(moduleName);
72104

73-
return node;
105+
return getMock(node, { nodeToMock });
74106
}
75107

76-
return getMock(node, { nodeToMock });
108+
return node;
77109
}
78-
79-
return node;
80-
}
81-
);
110+
);
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as ts from 'typescript';
2-
import {
3-
CustomFunction
4-
} from "../../../src/transformer/matcher/matcher";
2+
import { CustomFunction } from '../../../src/transformer/matcher/matcher';
53
import { baseTransformer } from '../../../src/transformer/base/base';
64
import { createDefinitelyTypedMockCustomFunction } from './customFunctions/create-definitely-typed-mock';
75

8-
const customFunctions: CustomFunction[] = [createDefinitelyTypedMockCustomFunction];
6+
const customFunctions: CustomFunction[] = [
7+
createDefinitelyTypedMockCustomFunction,
8+
];
99

1010
const transformer = baseTransformer(customFunctions, ts);
1111
export { transformer };

definitelyTypedTests/tsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../tsconfig.base.json",
3+
"compilerOptions": {
4+
"sourceMap": false
5+
},
6+
"include": ["src/**/*"]
7+
}

0 commit comments

Comments
 (0)