Skip to content

Commit

Permalink
fix: use require.resolve instead of path.join to resolve the symlink …
Browse files Browse the repository at this point in the history
…probrem

#4 (comment)
  • Loading branch information
kimamula committed Jun 18, 2020
1 parent 8a92a56 commit 2f6088a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion test/compile/compile.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as ts from 'typescript';
import ts from 'typescript';
import transformer from '../../transformer';

export function compile(filePaths: string[], target = ts.ScriptTarget.ES5, writeFileCallback?: ts.WriteFileCallback) {
const program = ts.createProgram(filePaths, {
strict: true,
noEmitOnError: true,
suppressImplicitAnyIndexErrors: true,
esModuleInterop: true,
target
});
const transformers: ts.CustomTransformers = {
Expand Down
8 changes: 4 additions & 4 deletions test/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { keys } from '../index';
import * as assert from 'assert';
import * as path from 'path';
import * as fs from 'fs';
import assert from 'assert';
import path from 'path';
import fs from 'fs';
import { compile } from './compile/compile';
import * as ts from 'typescript';
import ts from 'typescript';

describe('keys', () => {
it('should return keys of given type', () => {
Expand Down
9 changes: 4 additions & 5 deletions transformer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ts from 'typescript';
import * as path from 'path';
import ts from 'typescript';
import path from 'path';

export default function transformer(program: ts.Program): ts.TransformerFactory<ts.SourceFile> {
return (context: ts.TransformationContext) => (file: ts.SourceFile) => visitNodeAndChildren(file, program, context);
Expand Down Expand Up @@ -58,7 +58,6 @@ function isKeysCallExpression(node: ts.Node, typeChecker: ts.TypeChecker): node
const { declaration } = signature;
return !!declaration
&& !ts.isJSDocSignature(declaration)
&& (path.join(declaration.getSourceFile().fileName) === indexTs)
&& !!declaration.name
&& declaration.name.getText() === 'keys';
&& require.resolve(declaration.getSourceFile().fileName) === indexTs
&& declaration.name?.getText() === 'keys';
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"strict": true,
"noEmitOnError": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true
},
"include": [
"transformer.ts",
Expand Down

0 comments on commit 2f6088a

Please sign in to comment.