From 0af966e167263da8798664ef593f327683f1b670 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 15 Jun 2023 07:04:03 +0000 Subject: [PATCH] Automatic compilation --- .github/workflows/main.yml | 36 ------- .github/workflows/release.yml | 31 ------ .gitignore | 2 - LICENSE.txt | 21 ---- README.md | 74 -------------- dist/index.js | 30 +++--- package-lock.json | 63 ------------ package.json | 29 ------ projectFixtures/simple/package-lock.json | 50 ---------- projectFixtures/simple/package.json | 15 --- projectFixtures/simple/src/index.ts | 13 --- projectFixtures/simple/tsconfig.json | 14 --- projectFixtures/sub/package-lock.json | 34 ------- projectFixtures/sub/package.json | 7 -- projectFixtures/sub/src/main.js | 12 --- projectFixtures/sub/tsconfig.json | 35 ------- src/index.ts | 122 ----------------------- src/reporter.ts | 40 -------- tsconfig.json | 22 ---- 19 files changed, 15 insertions(+), 635 deletions(-) delete mode 100644 .github/workflows/main.yml delete mode 100644 .github/workflows/release.yml delete mode 100644 .gitignore delete mode 100644 LICENSE.txt delete mode 100644 README.md delete mode 100644 package-lock.json delete mode 100644 package.json delete mode 100644 projectFixtures/simple/package-lock.json delete mode 100644 projectFixtures/simple/package.json delete mode 100644 projectFixtures/simple/src/index.ts delete mode 100644 projectFixtures/simple/tsconfig.json delete mode 100644 projectFixtures/sub/package-lock.json delete mode 100644 projectFixtures/sub/package.json delete mode 100644 projectFixtures/sub/src/main.js delete mode 100644 projectFixtures/sub/tsconfig.json delete mode 100644 src/index.ts delete mode 100644 src/reporter.ts delete mode 100644 tsconfig.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 2b8399b..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: main - -on: - push: - branches: - - master - - main - - default - pull_request: - branches: - - "**" - -jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: - - 18 - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup node ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - - name: Install dependencies - run: npm install - - name: Build - run: npm run build - - name: Typecheck - uses: ./ - - name: Typecheck projectFixtures/sub - uses: ./ - with: - project: projectFixtures/sub diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index cb734c1..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Release - -on: - release: - types: [published, edited] - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: - - 18 - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Setup node ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - - name: Install dependencies - run: npm install - - name: Build - run: npm run build - - name: Release - uses: JasonEtco/build-and-tag-action@v1 - with: - setup: "" - env: - GITHUB_TOKEN: ${{ github.token }} diff --git a/.gitignore b/.gitignore deleted file mode 100644 index eb03e3e..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -*.log diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index efedb1d..0000000 --- a/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 Shin Ando - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/README.md b/README.md deleted file mode 100644 index dbb6ec1..0000000 --- a/README.md +++ /dev/null @@ -1,74 +0,0 @@ -# TypeScript Error Reporter Action ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/gozala/typescript-error-reporter-action) ![GitHub](https://img.shields.io/github/license/gozala/typescript-error-reporter-action) - -Ensuring type safety is one of the most important responsibilities of modern software developers. - -This action uses the [TypeScript Compiler API](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API) to run a static type check on your code and display the results of the check. - -![TypeScript Error Reporter Action](https://user-images.githubusercontent.com/8381075/78413929-a40f0680-7654-11ea-8365-0ef72fb4d6b3.png) - -## Example Configuration - -`.github/workflows/test.yml`: - -```yaml -name: Test - -on: [push, pull_request] - -jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [13.x] - steps: - - uses: actions/checkout@v1 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - name: Install dependencies - run: yarn install --frozen-lockfile - - name: Typecheck - uses: gozala/typescript-error-reporter-action@v1.0.5 -``` - -`tsconfig.json`: - -```json -{ - "compilerOptions": { - "target": "es5", - "module": "commonjs", - "strict": true, - "skipLibCheck": true, - "moduleResolution": "node", - "types": ["node"], - "lib": ["ES2017"] - }, - "include": ["src/**/*.ts"] -} -``` - -## Passing `project` parameter - -If you're working with a monorepo or your `tsconfig.json` is not in the root repo, -or you use different config file, you can provide a `project` parmeter with a -path to the repo itself: - -```yaml -- name: Typecheck - uses: gozala/typescript-error-reporter-action@v1.0.5 - with: - project: packages/subpackage/tsconfig.json -``` -## Passing `error_fail_threshold` parameter - -If you're incrementally adopting typescript in a project, you may not want to fail the entire workflow on a single typescript error. `error_fail_threshold` allows you to pass the maximum number of errors at which the step passes. Defaults to 0: - -```yaml -- name: Typecheck - uses: gozala/typescript-error-reporter-action@v1.0.9 - with: - error_fail_threshold: 100 -``` diff --git a/dist/index.js b/dist/index.js index 7b1e162..13b9ef2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2,7 +2,7 @@ /******/ "use strict"; /******/ var __webpack_modules__ = ({ -/***/ 301: +/***/ 899: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { @@ -15,7 +15,7 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", ({ value: true })); const os = __importStar(__nccwpck_require__(37)); -const utils_1 = __nccwpck_require__(688); +const utils_1 = __nccwpck_require__(655); /** * Commands * @@ -87,7 +87,7 @@ function escapeProperty(s) { /***/ }), -/***/ 508: +/***/ 614: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { @@ -108,9 +108,9 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -const command_1 = __nccwpck_require__(301); -const file_command_1 = __nccwpck_require__(51); -const utils_1 = __nccwpck_require__(688); +const command_1 = __nccwpck_require__(899); +const file_command_1 = __nccwpck_require__(282); +const utils_1 = __nccwpck_require__(655); const os = __importStar(__nccwpck_require__(37)); const path = __importStar(__nccwpck_require__(17)); /** @@ -331,7 +331,7 @@ exports.getState = getState; /***/ }), -/***/ 51: +/***/ 282: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { @@ -348,7 +348,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); /* eslint-disable @typescript-eslint/no-explicit-any */ const fs = __importStar(__nccwpck_require__(147)); const os = __importStar(__nccwpck_require__(37)); -const utils_1 = __nccwpck_require__(688); +const utils_1 = __nccwpck_require__(655); function issueCommand(command, message) { const filePath = process.env[`GITHUB_${command}`]; if (!filePath) { @@ -366,7 +366,7 @@ exports.issueCommand = issueCommand; /***/ }), -/***/ 688: +/***/ 655: /***/ ((__unused_webpack_module, exports) => { @@ -391,7 +391,7 @@ exports.toCommandValue = toCommandValue; /***/ }), -/***/ 342: +/***/ 713: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { @@ -425,8 +425,8 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); const module_1 = __importDefault(__nccwpck_require__(188)); const path = __importStar(__nccwpck_require__(17)); const fs = __importStar(__nccwpck_require__(147)); -const core_1 = __nccwpck_require__(508); -const reporter_1 = __nccwpck_require__(172); +const core_1 = __nccwpck_require__(614); +const reporter_1 = __nccwpck_require__(499); async function main() { try { const project = (0, core_1.getInput)("project") || "tsconfig.json"; @@ -520,13 +520,13 @@ main(); /***/ }), -/***/ 172: +/***/ 499: /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { Object.defineProperty(exports, "__esModule", ({ value: true })); exports.parseLocation = exports.readProperties = exports.reporter = void 0; -const command_1 = __nccwpck_require__(301); +const command_1 = __nccwpck_require__(899); const reporter = (ts) => (diagnostic) => { switch (diagnostic.category) { case ts.DiagnosticCategory.Error: { @@ -639,7 +639,7 @@ module.exports = require("path"); /******/ // startup /******/ // Load entry module and return exports /******/ // This entry module is referenced by other modules so it can't be inlined -/******/ var __webpack_exports__ = __nccwpck_require__(342); +/******/ var __webpack_exports__ = __nccwpck_require__(713); /******/ module.exports = __webpack_exports__; /******/ /******/ })() diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index beb2c9a..0000000 --- a/package-lock.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "name": "typescript-error-reporter-action", - "version": "1.0.0", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "name": "typescript-error-reporter-action", - "version": "1.0.0", - "license": "MIT", - "dependencies": { - "@actions/core": "^1.2.6" - }, - "devDependencies": { - "@types/node": "^20.3.1", - "typescript": "^5.1.3" - } - }, - "node_modules/@actions/core": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz", - "integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA==" - }, - "node_modules/@types/node": { - "version": "20.3.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.3.1.tgz", - "integrity": "sha512-EhcH/wvidPy1WeML3TtYFGR83UzjxeWRen9V402T8aUGYsCHOmfoisV3ZSg03gAFIbLq8TnWOJ0f4cALtnSEUg==", - "dev": true - }, - "node_modules/typescript": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.3.tgz", - "integrity": "sha512-XH627E9vkeqhlZFQuL+UsyAXEnibT0kWR2FWONlr4sTjvxyJYnyefgrkyECLzM5NenmKzRAy2rR/OlYLA1HkZw==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - } - }, - "dependencies": { - "@actions/core": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz", - "integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA==" - }, - "@types/node": { - "version": "20.3.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.3.1.tgz", - "integrity": "sha512-EhcH/wvidPy1WeML3TtYFGR83UzjxeWRen9V402T8aUGYsCHOmfoisV3ZSg03gAFIbLq8TnWOJ0f4cALtnSEUg==", - "dev": true - }, - "typescript": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.3.tgz", - "integrity": "sha512-XH627E9vkeqhlZFQuL+UsyAXEnibT0kWR2FWONlr4sTjvxyJYnyefgrkyECLzM5NenmKzRAy2rR/OlYLA1HkZw==", - "dev": true - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index c806768..0000000 --- a/package.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "typescript-error-reporter-action", - "version": "1.0.0", - "main": "dist/index.js", - "author": "andoshin11 ", - "license": "MIT", - "repository": { - "type": "git", - "url": "git+https://github.com/gozala/typescript-error-reporter-action.git" - }, - "bugs": { - "url": "https://github.com/gozala/typescript-error-reporter-action/issues" - }, - "homepage": "https://github.com/gozala/typescript-error-reporter-action#readme", - "scripts": { - "start": "npx @vercel/ncc run ./src/index.ts", - "build": "npx @vercel/ncc build src/index.ts", - "watch": "tsc -w", - "clean": "rm -rf lib && rm -rf dist", - "test:type": "tsc --noEmit --incremental false" - }, - "devDependencies": { - "@types/node": "^20.3.1", - "typescript": "^5.1.3" - }, - "dependencies": { - "@actions/core": "^1.2.6" - } -} diff --git a/projectFixtures/simple/package-lock.json b/projectFixtures/simple/package-lock.json deleted file mode 100644 index 39d1fb8..0000000 --- a/projectFixtures/simple/package-lock.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "name": "simple", - "version": "1.0.0", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "name": "simple", - "version": "1.0.0", - "license": "MIT", - "devDependencies": { - "@types/node": "^13.9.0", - "typescript": "^3.8.3" - } - }, - "node_modules/@types/node": { - "version": "13.9.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.9.0.tgz", - "integrity": "sha512-0ARSQootUG1RljH2HncpsY2TJBfGQIKOOi7kxzUY6z54ePu/ZD+wJA8zI2Q6v8rol2qpG/rvqsReco8zNMPvhQ==", - "dev": true - }, - "node_modules/typescript": { - "version": "3.8.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz", - "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=4.2.0" - } - } - }, - "dependencies": { - "@types/node": { - "version": "13.9.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.9.0.tgz", - "integrity": "sha512-0ARSQootUG1RljH2HncpsY2TJBfGQIKOOi7kxzUY6z54ePu/ZD+wJA8zI2Q6v8rol2qpG/rvqsReco8zNMPvhQ==", - "dev": true - }, - "typescript": { - "version": "3.8.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz", - "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==", - "dev": true - } - } -} diff --git a/projectFixtures/simple/package.json b/projectFixtures/simple/package.json deleted file mode 100644 index 79fd38e..0000000 --- a/projectFixtures/simple/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "simple", - "version": "1.0.0", - "main": "index.js", - "license": "MIT", - "scripts": { - "test": "node ../../lib/bin/cli.js run", - "test:check": "node ../../dist/index.js" - }, - "devDependencies": { - "@types/node": "^13.9.0", - "typescript": "^3.8.3" - }, - "dependencies": {} -} diff --git a/projectFixtures/simple/src/index.ts b/projectFixtures/simple/src/index.ts deleted file mode 100644 index a34ccc8..0000000 --- a/projectFixtures/simple/src/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -// import * as https from 'https' <- this import statement will crash the compiler somehow :thinking_face: - -function say(input: 'fuga') { - console.log(input) -} - -// say('hello') - -const hoge = 'hoge' -hoge = 'fuga' - -const fuga = 'fuga' -fuga = 'hoge' diff --git a/projectFixtures/simple/tsconfig.json b/projectFixtures/simple/tsconfig.json deleted file mode 100644 index 431751a..0000000 --- a/projectFixtures/simple/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "compilerOptions": { - "declaration": true, - "target": "esnext", - "module": "commonjs", - "strict": true, - "skipLibCheck": true, - "types": ["node"], - "typeRoots": ["./node_modules/@types"], - "outDir": "lib" - }, - "include": ["src/**/*.ts"], - "exclude": ["node_modules"] -} diff --git a/projectFixtures/sub/package-lock.json b/projectFixtures/sub/package-lock.json deleted file mode 100644 index 153d513..0000000 --- a/projectFixtures/sub/package-lock.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "sub", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "name": "sub", - "devDependencies": { - "typescript": "4.0.3" - } - }, - "node_modules/typescript": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.3.tgz", - "integrity": "sha512-tEu6DGxGgRJPb/mVPIZ48e69xCn2yRmCgYmDugAVwmJ6o+0u1RI18eO7E7WBTLYLaEVVOhwQmcdhQHweux/WPg==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=4.2.0" - } - } - }, - "dependencies": { - "typescript": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.3.tgz", - "integrity": "sha512-tEu6DGxGgRJPb/mVPIZ48e69xCn2yRmCgYmDugAVwmJ6o+0u1RI18eO7E7WBTLYLaEVVOhwQmcdhQHweux/WPg==", - "dev": true - } - } -} diff --git a/projectFixtures/sub/package.json b/projectFixtures/sub/package.json deleted file mode 100644 index 277f110..0000000 --- a/projectFixtures/sub/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "sub", - "private": "true", - "devDependencies": { - "typescript": "4.0.3" - } -} diff --git a/projectFixtures/sub/src/main.js b/projectFixtures/sub/src/main.js deleted file mode 100644 index 8de1970..0000000 --- a/projectFixtures/sub/src/main.js +++ /dev/null @@ -1,12 +0,0 @@ -export const main = async () => { - greet("world") -} - - -/** - * - * @param {string} name - */ -const greet = (name) => { - return `Hello ${name}` -} diff --git a/projectFixtures/sub/tsconfig.json b/projectFixtures/sub/tsconfig.json deleted file mode 100644 index 54b8e44..0000000 --- a/projectFixtures/sub/tsconfig.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "compilerOptions": { - "allowJs": true, - "checkJs": true, - "forceConsistentCasingInFileNames": true, - "noImplicitReturns": false, - "noImplicitAny": true, - "noImplicitThis": true, - "noFallthroughCasesInSwitch": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "strictFunctionTypes": false, - "strictNullChecks": true, - "strictPropertyInitialization": true, - "strictBindCallApply": true, - "strict": true, - "alwaysStrict": true, - "esModuleInterop": true, - "target": "ES2018", - "moduleResolution": "node", - "declaration": true, - "declarationMap": true, - "outDir": "dist", - "skipLibCheck": true, - "stripInternal": true, - "resolveJsonModule": true - }, - "include": [ - "src" - ], - "exclude": [ - "node_modules" - ], - "compileOnSave": false -} diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index 93073c1..0000000 --- a/src/index.ts +++ /dev/null @@ -1,122 +0,0 @@ -import Module from "module" -import * as path from "path" -import * as fs from "fs" -import { getInput, setFailed } from "@actions/core" -import { reporter } from "./reporter" -import type { CompilerOptions, Diagnostic, ParsedCommandLine } from "typescript" - -type TS = typeof import("typescript") - -async function main() { - try { - const project = getInput("project") || "tsconfig.json" - - const projectPath = resolveProjectPath(path.resolve(process.cwd(), project)) - - if (projectPath == null) { - throw new Error( - `No valid typescript project was not found at: ${projectPath}` - ) - } - - typecheck(projectPath) - } catch (error) { - console.error(error) - setFailed(error as Error) - } -} - -/** - * Attempts to resolve ts config file and returns either path to it or `null`. - */ -const resolveProjectPath = (projectPath: string) => { - try { - if (fs.statSync(projectPath).isFile()) { - return projectPath - } else { - const configPath = path.resolve(projectPath, "tsconfig.json") - return fs.statSync(configPath).isFile() ? configPath : null - } - } catch { - return null - } -} - -const typecheck = (projectPath: string) => { - const ts = loadTS(projectPath) - const json = ts.readConfigFile(projectPath, ts.sys.readFile) - const config = ts.parseJsonConfigFileContent( - json.config, - ts.sys, - path.dirname(projectPath), - undefined, - path.basename(projectPath) - ) - - const errors = isIncrementalCompilation(config.options) - ? performIncrementalCompilation(ts, projectPath) - : performCompilation(ts, config) - - const errThreshold = Number(getInput("error_fail_threshold") || 0) - const logString = `Found ${errors} errors!` - console.log(logString) - if (errors > errThreshold) { - setFailed(logString) - } -} - -const performIncrementalCompilation = (ts: TS, projectPath: string) => { - const report = reporter(ts) - - const host = ts.createSolutionBuilderHost(ts.sys, undefined, report, report) - const builder = ts.createSolutionBuilder(host, [projectPath], { - noEmit: true, - }) - return builder.build() -} - -const performCompilation = (ts: TS, config: ParsedCommandLine) => { - const report = reporter(ts) - const host = ts.createCompilerHost(config.options) - const program = ts.createProgram({ - rootNames: config.fileNames, - options: config.options, - projectReferences: config.projectReferences, - configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics(config), - }) - - const configuration = program.getConfigFileParsingDiagnostics() - let all: Diagnostic[] = [...program.getSyntacticDiagnostics()] - if (all.length === 0) { - all = [ - ...program.getOptionsDiagnostics(), - ...program.getGlobalDiagnostics(), - ] - - if (all.length == 0) { - all = [...program.getSemanticDiagnostics()] - } - } - const diagnostics = ts.sortAndDeduplicateDiagnostics(all) - diagnostics.forEach(report) - - return all.length -} - -const isIncrementalCompilation = (options: CompilerOptions) => - options.incremental || options.composite - -const loadTS = (projectPath: string): TS => { - try { - const require = Module.createRequire(projectPath) - const ts = require("typescript") - return ts - } catch (error) { - throw Object.assign( - new Error(`Failed to find project specific typescript at ${projectPath}`), - { cause: error } - ) - } -} - -main() diff --git a/src/reporter.ts b/src/reporter.ts deleted file mode 100644 index 0628a78..0000000 --- a/src/reporter.ts +++ /dev/null @@ -1,40 +0,0 @@ -import type { Diagnostic } from 'typescript' -import { issueCommand } from '@actions/core/lib/command' -type TS = typeof import('typescript') - -export const reporter = (ts:TS) => (diagnostic:Diagnostic) => { - switch (diagnostic.category) { - case ts.DiagnosticCategory.Error: { - return issueCommand('error', readProperties(diagnostic), ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')) - } - case ts.DiagnosticCategory.Warning: { - return issueCommand('warning', readProperties(diagnostic), ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')) - } - } -} - -export const readProperties = ({ start, file }:Diagnostic) => { - const fileName = file && file.fileName - if (!fileName) return {} - if (!start) return { file: fileName } - - const content = file!.getFullText() - const { line, column } = parseLocation(content, start) - return { file: fileName, line: `${line}`, col: `${column}` } -} - -export const parseLocation = (content:string, position:number) => { - let l = 1 - let c = 0 - for (let i = 0; i < content.length && i < position; i++) { - const cc = content[i] - if (cc === '\n') { - c = 0 - l++ - } else { - c++ - } - } - - return { line: l, column: c }; -} diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index c0b8a12..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "compilerOptions": { - "target": "esnext", - "module": "commonjs", - "strict": true, - "types": [ - "node" - ], - "lib": [ - "ES2017" - ], - "esModuleInterop": true, - "moduleResolution": "node", - "outDir": "lib" - }, - "include": [ - "src/**/*.ts" - ], - "exclude": [ - "node_modules" - ] -}