forked from andoshin11/typescript-error-reporter-action
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Gozala/project-refs
rewrite the reporter
- Loading branch information
Showing
21 changed files
with
290 additions
and
847 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
node_modules | ||
lib | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const module_1 = __importDefault(require("module")); | ||
const path = __importStar(require("path")); | ||
const fs = __importStar(require("fs")); | ||
const core_1 = require("@actions/core"); | ||
const reporter_1 = require("./reporter"); | ||
async function main() { | ||
try { | ||
const project = core_1.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 (e) { | ||
console.error(e); | ||
core_1.setFailed(e); | ||
} | ||
} | ||
/** | ||
* Attempts to resolve ts config file and returns either path to it or `null`. | ||
*/ | ||
const resolveProjectPath = (projectPath) => { | ||
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) => { | ||
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); | ||
if (errors > 0) { | ||
core_1.setFailed(`Found ${errors} errors!`); | ||
} | ||
}; | ||
const performIncrementalCompilation = (ts, projectPath) => { | ||
const report = reporter_1.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, config) => { | ||
const report = reporter_1.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 = [...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) => options.incremental || options.composite; | ||
const loadTS = (projectPath) => { | ||
try { | ||
const require = module_1.default.createRequire(projectPath); | ||
const ts = require('typescript'); | ||
console.log(`Using local typescript@${ts.version}`); | ||
return ts; | ||
} | ||
catch (error) { | ||
const ts = require('typescript'); | ||
console.log(`Failed to find project specific typescript, falling back to bundled typescript@${ts.version}`); | ||
return ts; | ||
} | ||
}; | ||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseLocation = exports.readProperties = exports.reporter = void 0; | ||
const command_1 = require("@actions/core/lib/command"); | ||
exports.reporter = (ts) => (diagnostic) => { | ||
switch (diagnostic.category) { | ||
case ts.DiagnosticCategory.Error: { | ||
return command_1.issueCommand('error', exports.readProperties(diagnostic), ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')); | ||
} | ||
case ts.DiagnosticCategory.Warning: { | ||
return command_1.issueCommand('warning', exports.readProperties(diagnostic), ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')); | ||
} | ||
} | ||
}; | ||
exports.readProperties = ({ start, file }) => { | ||
const fileName = file && file.fileName; | ||
if (!fileName) | ||
return {}; | ||
if (!start) | ||
return { file: fileName }; | ||
const content = file.getFullText(); | ||
const { line, column } = exports.parseLocation(content, start); | ||
return { file: fileName, line: `${line}`, col: `${column}` }; | ||
}; | ||
exports.parseLocation = (content, position) => { | ||
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 }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,29 @@ | ||
{ | ||
"name": "typescript-error-reporter-action", | ||
"version": "1.0.0", | ||
"main": "dist/index.js", | ||
"main": "lib/index.js", | ||
"author": "andoshin11 <shinglish11@gmail.com>", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/andoshin11/typescript-error-reporter-action.git" | ||
"url": "git+https://github.com/gozala/typescript-error-reporter-action.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/andoshin11/typescript-error-reporter-action/issues" | ||
"url": "https://github.com/gozala/typescript-error-reporter-action/issues" | ||
}, | ||
"homepage": "https://github.com/andoshin11/typescript-error-reporter-action#readme", | ||
"homepage": "https://github.com/gozala/typescript-error-reporter-action#readme", | ||
"scripts": { | ||
"build": "tsc", | ||
"watch": "tsc -w", | ||
"bundle": "webpack", | ||
"test:type": "tsc --noEmit --incremental false", | ||
"pack:libDTS": "node scripts/packLibDTS.js" | ||
"clean": "rm -rf lib", | ||
"test:type": "tsc --noEmit --incremental false" | ||
}, | ||
"devDependencies": { | ||
"@types/concat-stream": "^1.6.0", | ||
"@types/glob": "^7.1.3", | ||
"@types/node": "^14.11.8", | ||
"@types/yarnpkg__lockfile": "^1.1.4", | ||
"hard-source-webpack-plugin": "^0.13.1", | ||
"ts-loader": "^8.0.4", | ||
"typescript": "^4.0.3", | ||
"webpack": "^4.44.2", | ||
"webpack-cli": "^3.3.12" | ||
"typescript": "^4.0.3" | ||
}, | ||
"dependencies": { | ||
"@actions/core": "^1.2.6", | ||
"@yarnpkg/lockfile": "^1.1.0", | ||
"concat-stream": "^2.0.0", | ||
"glob": "^7.1.6" | ||
"@actions/core": "^1.2.6" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.