Skip to content

Commit 810f4d2

Browse files
authored
chore(dependencies) update dependencies to the latest version (#315)
* chore - update dependencies to the latest version and fix definitely typed transformer and add github action to make sure build will not break * chore - add npm install * chore - add missing library
1 parent d704f2c commit 810f4d2

File tree

7 files changed

+17499
-11652
lines changed

7 files changed

+17499
-11652
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Definuitely Type build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
9+
strategy:
10+
matrix:
11+
node-version: [10.x]
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Use Node.js ${{ matrix.node-version }}
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
- name: run definitely typed build
20+
run: |
21+
npm install
22+
npm run build
23+
npm run build:transformer:definitelyTyped
24+
env:
25+
CI: true
26+
27+

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
node-version: ${{ matrix.node-version }}
1919
- name: install ts auto mock and run test
2020
run: |
21+
sudo apt-get update
22+
sudo apt-get install -y libgbm-dev
2123
npm install
2224
npm run build
2325
npm test

definitelyTypedTests/src/transformer/transformer.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,33 @@ export { transformer };
2424

2525
type CompatibleStatement = ts.InterfaceDeclaration | ts.FunctionDeclaration | ts.ClassDeclaration | ts.ModuleDeclaration;
2626

27-
function visitNode(node: ts.CallExpression, declaration: ts.FunctionDeclaration): ts.Node {
28-
const typeQueryNode: ts.TypeNode = node.typeArguments[0];
27+
function visitNode(node: ts.CallExpression & { typeArguments: ts.NodeArray<ts.TypeNode> }, declaration: ts.FunctionDeclaration): ts.Node {
28+
const [nodeToMock]: ts.NodeArray<ts.TypeNode> = node.typeArguments;
2929

30-
if (isCreateDefinitelyTypedMock(declaration) && ts.isTypeQueryNode(typeQueryNode)) {
30+
if (isCreateDefinitelyTypedMock(declaration) && ts.isTypeQueryNode(nodeToMock)) {
3131
const typeChecker: ts.TypeChecker = TypeChecker();
32-
const typeQuerySymbol: ts.Symbol = typeChecker.getSymbolAtLocation(typeQueryNode.exprName);
32+
const typeQuerySymbol: ts.Symbol | undefined = typeChecker.getSymbolAtLocation(nodeToMock.exprName);
33+
34+
if (!typeQuerySymbol) {
35+
return getMock(nodeToMock, node);
36+
}
37+
3338
const typeQuerySymbolDeclaration: ts.ImportEqualsDeclaration = typeQuerySymbol.declarations[0] as ts.ImportEqualsDeclaration;
34-
const symbolAlias: ts.Symbol = typeChecker.getSymbolAtLocation(typeQuerySymbolDeclaration.name);
39+
const symbolAlias: ts.Symbol | undefined = typeChecker.getSymbolAtLocation(typeQuerySymbolDeclaration.name);
40+
41+
if (!symbolAlias) {
42+
return getMock(nodeToMock, node);
43+
}
44+
3545
const symbol: ts.Symbol = typeChecker.getAliasedSymbol(symbolAlias);
3646

47+
3748
if (!symbol.declarations) {
3849
const moduleName: string =
3950
((typeQuerySymbolDeclaration.moduleReference as ts.ExternalModuleReference).expression as ts.StringLiteral).text;
4051
const pathModule = path.resolve(moduleName);
4152
const moduleWithoutExportsFile: ts.SourceFile = GetProgram().getSourceFiles().find((file: ts.SourceFile) =>
42-
file.fileName.includes(`${pathModule}/index.d.ts`));
53+
file.fileName.includes(`${pathModule}/index.d.ts`)) as ts.SourceFile;
4354

4455
const compatibleStatements: ts.Statement[] = moduleWithoutExportsFile.statements.filter(
4556
(statement: ts.Statement) => statement.kind === ts.SyntaxKind.InterfaceDeclaration
@@ -72,12 +83,12 @@ function visitNode(node: ts.CallExpression, declaration: ts.FunctionDeclaration)
7283
return node;
7384
}
7485

75-
return getMock(typeQueryNode, node);
86+
return getMock(nodeToMock, node);
7687
}
7788

7889
return node;
7990
}
8091

8192
function isCreateDefinitelyTypedMock(declaration: ts.FunctionDeclaration): boolean {
82-
return declaration.name && declaration.name.getText() === 'createDefinitelyTypedMock';
93+
return !!declaration.name && declaration.name.getText() === 'createDefinitelyTypedMock';
8394
}

0 commit comments

Comments
 (0)