Skip to content

Commit

Permalink
Merge pull request #1 from Gozala/test
Browse files Browse the repository at this point in the history
Ability to provide project path
  • Loading branch information
Gozala authored Oct 13, 2020
2 parents b72003d + c9e5986 commit e441441
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 6 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
name: main

on: [push]
on:
push:
branches:
- master
- main
- default
pull_request:
branches:
- '**'

jobs:
test:
Expand All @@ -23,5 +31,11 @@ jobs:
${{ runner.os }}-node-
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Typecheck
uses: ./
- name: Typecheck projectFixtures/sub
uses: ./
with:
project: projectFixtures/sub
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions projectFixtures/sub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "sub",
"private": "true",
"devDependencies": {
"typescript": "4.0.3"
}
}
12 changes: 12 additions & 0 deletions projectFixtures/sub/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const main = async () => {
greet("world")
}


/**
*
* @param {string} name
*/
const greet = (name) => {
return `Hello ${name}`
}
35 changes: 35 additions & 0 deletions projectFixtures/sub/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"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
}
24 changes: 20 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { loadTSModule } from './loadTSModule'
async function main() {
try {
const project = getInput('project') || 'tsconfig.json'
const tscPath = getInput('tsc')
const projectPath = path.resolve(process.cwd(), project)
if (!fs.existsSync(projectPath)) {
throw new Error(`No such TS config file: ${projectPath}`)
const projectPath = resolveProjectPath(path.resolve(process.cwd(), project))

if (projectPath == null) {
throw new Error(`No valid typescript project was not found at: ${projectPath}`)
}

const ts = await loadTSModule(projectPath)
Expand All @@ -34,4 +34,20 @@ async function main() {
}
}

/**
* 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
}
}

main()

0 comments on commit e441441

Please sign in to comment.