Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ export class TypeScriptPlugin {
}

get rootFileNames() {
return typescript.extractFileNames(
return _.union(typescript.extractFileNames(
this.originalServicePath,
this.serverless.service.provider.name,
this.functions
)
), typescript.getTypescriptCompileFiles(this.originalServicePath))
}

prepare() {
Expand Down
24 changes: 23 additions & 1 deletion src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function run(fileNames: string[], options: ts.CompilerOptions): Pro
if (!diagnostic.file) {
console.log(diagnostic)
}
const {line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start)
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start)
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')
console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`)
})
Expand Down Expand Up @@ -144,3 +144,25 @@ export function getTypescriptConfig(

return makeDefaultTypescriptConfig()
}

export function getTypescriptCompileFiles(
cwd: string,
): string[] {
const configFilePath = path.join(cwd, 'tsconfig.json')

if (fs.existsSync(configFilePath)) {

const configFileText = fs.readFileSync(configFilePath).toString()
const result = ts.parseConfigFileTextToJson(configFilePath, configFileText)
if (result.error) {
throw new Error(JSON.stringify(result.error))
}

const configParseResult = ts.parseJsonConfigFileContent(result.config, ts.sys, path.dirname(configFilePath))
if (configParseResult.errors.length > 0) {
throw new Error(JSON.stringify(configParseResult.errors))
}
return configParseResult.fileNames.map(f => f.replace(cwd + '/', ''))
}
return []
}
11 changes: 11 additions & 0 deletions tests/typescript.getTypescriptCompileFiles.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {getTypescriptCompileFiles} from '../src/typescript'
import * as path from 'path'
describe('getTypescriptCompileFiles', () => {
it(`returns all typescript compile files including the tsconfig.json include`, () => {
expect(
getTypescriptCompileFiles(path.resolve(__dirname, '../'))
).toEqual(
['src/Serverless.d.ts', 'src/index.ts', 'src/typescript.ts', 'src/watchFiles.ts']
)
})
})
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"sourceMap": true,
"outDir": "dist"
},
"include": [
"src/**.ts"
],
"exclude": [
"node_modules"
]
}
}