Skip to content

Commit

Permalink
enh: Save
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Dec 4, 2023
1 parent ce26687 commit 7b3350f
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 68 deletions.
4 changes: 2 additions & 2 deletions lib/modules/conditions/infrastructure.spec-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describeType('If', () => {
});

testType('Should return false case', () => {
assertType<ExplicitCondition<{ condition: false; then: string; else: number }>>().equals<number>();
assertType<ExplicitCondition<{ condition: false; then: string; else: number }>>().equals<string>();
assertType<ExplicitCondition<{ condition: never; then: string; else: number }>>().equals<number>();
});
});
});
57 changes: 0 additions & 57 deletions lib/plugins/src/index.ts

This file was deleted.

11 changes: 8 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"types": "./lib/index.d.ts",
"main": "./lib/plugins/dist/index.js",
"scripts": {
"build:plugin": "tsc -p ./lib/plugins",
"typeChecking": "npm run build:plugin && tsc",
"build:plugin": "tsc -p ./plugins",
"typeChecking": "tsc -p ./",
"debugTypes": "tsc --generateTrace ./outDir",
"lint": "eslint \"./lib/**/*.{ts,tsx}\" --max-warnings 0",
"lint:fix": "eslint \"./lib/**/*.{ts,tsx}\" --max-warnings 0 --fix",
"prepare": "husky install",
"postversion": "git push && git push --tags --no-verify && npm publish",
"prepublish": "tsc -p ./lib/plugins"
"prepublish": "tsc -p ./plugins"
},
"repository": {
"type": "git",
Expand All @@ -36,7 +36,7 @@
"url": "https://github.com/Eythaann/readable-types/issues"
},
"dependencies": {
"readable-types-plugin": "file:./lib/plugins",
"readable-types-plugin": "file:./plugins",
"typescript": "^4.8"
},
"devDependencies": {
Expand Down
58 changes: 58 additions & 0 deletions plugins/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions plugins/dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
70 changes: 70 additions & 0 deletions plugins/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const proxyObj = <T extends Record<string, any>>(obj: T): T => {
const proxy: T = Object.create(null);
for (const key of Object.keys(obj) as Array<keyof T>) {
const x = obj[key];
proxy[key] = ((...args: any[]) => x.apply(obj, args)) as any;
}
return proxy;
};

function init(modules: { typescript: typeof import('typescript/lib/tsserverlibrary') }) {
const ts = modules.typescript;

function create(info: ts.server.PluginCreateInfo) {
const { languageService: tsLanguageService } = info;

const print = (s: any) => {
info.project.projectService.logger.info('Readable-Types:: ' + String(s));
};

print('readable-types-plugin loaded :D');

const languageService = proxyObj(tsLanguageService);

const typeChecker = tsLanguageService.getProgram()?.getTypeChecker();

languageService.getSemanticDiagnostics = (fileName) => {
print('Getting Diagnostics for: ' + fileName);
const diagnostics = tsLanguageService.getSemanticDiagnostics(fileName);

const sourceFile = tsLanguageService.getProgram()?.getSourceFile(fileName);
if (!sourceFile) {
print('SourceFile not found');
return diagnostics;
}

ts.forEachChild(sourceFile, function visit(node) {
if (ts.isCallExpression(node)) {
const signature = typeChecker?.getResolvedSignature(node);
if (signature) {
const returnType = typeChecker?.typeToString(typeChecker.getReturnTypeOfSignature(signature));

print('returntype: ' + returnType);

if (returnType && returnType.includes('RTT_FAIL')) {
diagnostics.push({
file: sourceFile,
start: node.getStart(),
length: node.getWidth(),
messageText: 'Test is failing: ' + returnType.slice(returnType.indexOf('<') + 1, -1),
category: ts.DiagnosticCategory.Error,
//@ts-ignore
code: 'readable-test-types',
});
}
}
}

ts.forEachChild(node, visit);
});

return diagnostics;
};

return languageService;
}

return { create };
}

export = init;
2 changes: 1 addition & 1 deletion lib/plugins/tsconfig.json → plugins/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"paths": ["./src/**"],
"paths": ["./plugins/**"],
"exclude": ["example"],
"compilerOptions": {
"target": "es2017", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"noUncheckedIndexedAccess": false,
"strict": true,
"noEmit": true,
"noErrorTruncation": true,
Expand All @@ -14,7 +15,6 @@
},
"include": [
"./lib",
"./plugins",
],
"exclude": [
"node_modules"
Expand Down

0 comments on commit 7b3350f

Please sign in to comment.