From 7b3350f5c7bc8aea87bb8556e7b71194081b7f87 Mon Sep 17 00:00:00 2001 From: eythaann Date: Sun, 3 Dec 2023 20:20:41 -0500 Subject: [PATCH] enh: Save --- .../conditions/infrastructure.spec-types.ts | 4 +- lib/plugins/src/index.ts | 57 --------------- package-lock.json | 11 ++- package.json | 8 +-- plugins/dist/index.js | 58 +++++++++++++++ plugins/dist/index.js.map | 1 + {lib/plugins => plugins}/package.json | 0 plugins/src/index.ts | 70 +++++++++++++++++++ {lib/plugins => plugins}/tsconfig.json | 2 +- tsconfig.json | 2 +- 10 files changed, 145 insertions(+), 68 deletions(-) delete mode 100644 lib/plugins/src/index.ts create mode 100644 plugins/dist/index.js create mode 100644 plugins/dist/index.js.map rename {lib/plugins => plugins}/package.json (100%) create mode 100644 plugins/src/index.ts rename {lib/plugins => plugins}/tsconfig.json (97%) diff --git a/lib/modules/conditions/infrastructure.spec-types.ts b/lib/modules/conditions/infrastructure.spec-types.ts index bd9f261..0c9a763 100644 --- a/lib/modules/conditions/infrastructure.spec-types.ts +++ b/lib/modules/conditions/infrastructure.spec-types.ts @@ -7,7 +7,7 @@ describeType('If', () => { }); testType('Should return false case', () => { - assertType>().equals(); + assertType>().equals(); assertType>().equals(); }); -}); \ No newline at end of file +}); diff --git a/lib/plugins/src/index.ts b/lib/plugins/src/index.ts deleted file mode 100644 index 3dcefbe..0000000 --- a/lib/plugins/src/index.ts +++ /dev/null @@ -1,57 +0,0 @@ -function init(modules: { typescript: typeof import('typescript/lib/tsserverlibrary') }) { - const ts = modules.typescript; - - function create(info: ts.server.PluginCreateInfo) { - const print = (s: any) => { - info.project.projectService.logger.info('Readable-Types:: ' + String(s)); - }; - - print('readable-types-plugin loaded :D'); - - // Set up decorator object - const proxy: ts.LanguageService = Object.create(null); - for (const key of Object.keys(info.languageService) as Array) { - const x = info.languageService[key]!; - // @ts-expect-error - JS runtime trickery which is tricky to type tersely - proxy[key] = (...args: Array<{}>) => x.apply(info.languageService, args); - } - - const typeChecker = info.languageService.getProgram()?.getTypeChecker(); - - proxy.getSemanticDiagnostics = (fileName) => { - const sourceFile = info.languageService.getProgram()?.getSourceFile(fileName); - const diagnostics = info.languageService.getSemanticDiagnostics(fileName); - - if (sourceFile) { - ts.forEachChild(sourceFile, function visit(node) { - if (ts.isCallExpression(node)) { - const signature = typeChecker?.getResolvedSignature(node); - if (signature) { - const returnType = typeChecker?.typeToString(typeChecker.getReturnTypeOfSignature(signature)); - 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 proxy; - } - - return { create }; -} - -export = init; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index a44f0ad..62ba11c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.0.0", "license": "MIT", "dependencies": { - "readable-types-plugin": "file:./lib/plugins", + "readable-types-plugin": "file:./plugins", "typescript": "^4.8" }, "devDependencies": { @@ -26,6 +26,7 @@ }, "lib/plugins": { "name": "my-plugin", + "extraneous": true, "license": "MIT" }, "node_modules/@babel/code-frame": { @@ -2775,7 +2776,7 @@ } }, "node_modules/readable-types-plugin": { - "resolved": "lib/plugins", + "resolved": "plugins", "link": true }, "node_modules/redent": { @@ -3408,6 +3409,10 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "plugins": { + "name": "my-plugin", + "license": "MIT" } }, "dependencies": { @@ -5447,7 +5452,7 @@ } }, "readable-types-plugin": { - "version": "file:lib/plugins" + "version": "file:plugins" }, "redent": { "version": "3.0.0", diff --git a/package.json b/package.json index 2fee302..ebe861f 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { diff --git a/plugins/dist/index.js b/plugins/dist/index.js new file mode 100644 index 0000000..4106183 --- /dev/null +++ b/plugins/dist/index.js @@ -0,0 +1,58 @@ +"use strict"; +const proxyObj = (obj) => { + const proxy = Object.create(null); + for (const key of Object.keys(obj)) { + const x = obj[key]; + proxy[key] = ((...args) => x.apply(obj, args)); + } + return proxy; +}; +function init(modules) { + const ts = modules.typescript; + function create(info) { + var _a; + const { languageService: tsLanguageService } = info; + const print = (s) => { + info.project.projectService.logger.info('Readable-Types:: ' + String(s)); + }; + print('readable-types-plugin loaded :D'); + const languageService = proxyObj(tsLanguageService); + const typeChecker = (_a = tsLanguageService.getProgram()) === null || _a === void 0 ? void 0 : _a.getTypeChecker(); + languageService.getSyntacticDiagnostics = (fileName) => { + var _a; + print('Getting Diagnostics for: ' + fileName); + const diagnostics = tsLanguageService.getSyntacticDiagnostics(fileName); + const sourceFile = (_a = tsLanguageService.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(fileName); + if (!sourceFile) { + print('SourceFile not found'); + return diagnostics; + } + ts.forEachChild(sourceFile, function visit(node) { + if (ts.isCallExpression(node)) { + const signature = typeChecker === null || typeChecker === void 0 ? void 0 : typeChecker.getResolvedSignature(node); + if (signature) { + const returnType = typeChecker === null || typeChecker === void 0 ? void 0 : 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 }; +} +module.exports = init; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/plugins/dist/index.js.map b/plugins/dist/index.js.map new file mode 100644 index 0000000..3dfbc4c --- /dev/null +++ b/plugins/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,MAAM,QAAQ,GAAG,CAAgC,GAAM,EAAK,EAAE;IAC5D,MAAM,KAAK,GAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACrC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAmB,EAAE;QACpD,MAAM,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACnB,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAQ,CAAC;KAC9D;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,SAAS,IAAI,CAAC,OAAwE;IACpF,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;IAE9B,SAAS,MAAM,CAAC,IAAgC;;QAC9C,MAAM,EAAE,eAAe,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC;QAEpD,MAAM,KAAK,GAAG,CAAC,CAAM,EAAE,EAAE;YACvB,IAAI,CAAC,OAAO,CAAC,cAAc,C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CAAC,QAAQ,EAAE;gCACtB,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE;gCACvB,WAAW,EAAE,mBAAmB,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;gCACpF,QAAQ,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK;gCACrC,YAAY;gCACZ,IAAI,EAAE,qBAAqB;6BAC5B,CAAC,CAAC;yBACJ;qBACF;iBACF;gBAED,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC/B,CAAC,CAAC,CAAC;YAEH,OAAO,WAAW,CAAC;QACrB,CAAC,CAAC;QAEF,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC;AAED,iBAAS,IAAI,CAAC"} \ No newline at end of file diff --git a/lib/plugins/package.json b/plugins/package.json similarity index 100% rename from lib/plugins/package.json rename to plugins/package.json diff --git a/plugins/src/index.ts b/plugins/src/index.ts new file mode 100644 index 0000000..01b2b02 --- /dev/null +++ b/plugins/src/index.ts @@ -0,0 +1,70 @@ +const proxyObj = >(obj: T): T => { + const proxy: T = Object.create(null); + for (const key of Object.keys(obj) as Array) { + 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; \ No newline at end of file diff --git a/lib/plugins/tsconfig.json b/plugins/tsconfig.json similarity index 97% rename from lib/plugins/tsconfig.json rename to plugins/tsconfig.json index f2623e4..493bf1b 100644 --- a/lib/plugins/tsconfig.json +++ b/plugins/tsconfig.json @@ -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. */ diff --git a/tsconfig.json b/tsconfig.json index 5d84be9..371f139 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "noImplicitReturns": true, "noImplicitThis": true, "noImplicitAny": true, + "noUncheckedIndexedAccess": false, "strict": true, "noEmit": true, "noErrorTruncation": true, @@ -14,7 +15,6 @@ }, "include": [ "./lib", - "./plugins", ], "exclude": [ "node_modules"