Skip to content

fix: make tsconfig include files compilation honour tsConfigFileLocation #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 14 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class TypeScriptPlugin {
this.originalServicePath,
this.serverless.service.provider.name,
this.functions
), typescript.getTypescriptCompileFiles(this.originalServicePath))
), typescript.getTypescriptCompileFiles(this.originalServicePath, this.getTsConfigFileLocation()))
}

prepare() {
Expand Down Expand Up @@ -162,6 +162,17 @@ export class TypeScriptPlugin {
watchFiles(this.rootFileNames, this.originalServicePath, this.compileTs.bind(this))
}

getTsConfigFileLocation() {
let tsConfigFileLocation
if (
this.serverless.service.custom !== undefined
&& this.serverless.service.custom.serverlessPluginTypescript !== undefined
) {
tsConfigFileLocation = this.serverless.service.custom.serverlessPluginTypescript.tsConfigFileLocation
}
return tsConfigFileLocation ?? 'tsconfig.json'
}

async compileTs(): Promise<string[]> {
this.prepare()
this.serverless.cli.log('Compiling with Typescript...')
Expand All @@ -172,16 +183,10 @@ export class TypeScriptPlugin {
// Fake service path so that serverless will know what to zip
this.serverless.config.servicePath = path.join(this.originalServicePath, BUILD_FOLDER)
}
let tsConfigFileLocation: string | undefined
if (
this.serverless.service.custom !== undefined
&& this.serverless.service.custom.serverlessPluginTypescript !== undefined
) {
tsConfigFileLocation = this.serverless.service.custom.serverlessPluginTypescript.tsConfigFileLocation
}

const tsconfig = typescript.getTypescriptConfig(
this.originalServicePath,
tsConfigFileLocation,
this.getTsConfigFileLocation(),
this.isWatching ? null : this.serverless.cli
)

Expand Down
4 changes: 2 additions & 2 deletions src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ export function getTypescriptConfig(
}

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

if (fs.existsSync(configFilePath)) {

Expand Down
2 changes: 1 addition & 1 deletion tests/typescript.getTypescriptCompileFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path'
describe('getTypescriptCompileFiles', () => {
it(`returns all typescript compile files including the tsconfig.json include`, () => {
expect(
getTypescriptCompileFiles(path.resolve(__dirname, '../'))
getTypescriptCompileFiles(path.resolve(__dirname, '../'), 'tsconfig.json')
).toEqual(
['src/Serverless.d.ts', 'src/index.ts', 'src/typescript.ts', 'src/watchFiles.ts']
)
Expand Down