diff --git a/src/index.ts b/src/index.ts index 27e1769b..e2ceeb6c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -149,7 +149,7 @@ export class TypeScriptPlugin { await this.linkOrCopy(path.resolve('package.json'), outPkgPath, 'file') } - // include any "extras" from the "include" section + // include any "extras" from the "include" section of the main service if (this.serverless.service.package.include && this.serverless.service.package.include.length > 0) { const files = await globby(this.serverless.service.package.include) @@ -166,6 +166,25 @@ export class TypeScriptPlugin { } } } + + // include any "extras" from the "include" section of each function + for (const fnName in this.functions) { + const fn = this.functions[fnName] + if (fn.package.include !== undefined) { + for (const filename of fn.package.include) { + const destFileName = path.resolve(path.join(buildFolder, filename)) + const dirname = path.dirname(destFileName) + + if (!fs.existsSync(dirname)) { + fs.mkdirpSync(dirname) + } + + if (!fs.existsSync(destFileName)) { + fs.copySync(path.resolve(filename), path.resolve(path.join(buildFolder, filename))) + } + } + } + } } async moveArtifacts(): Promise { @@ -202,6 +221,18 @@ export class TypeScriptPlugin { serverlessFolder, path.basename(this.serverless.service.package.artifact) ) + + this.serverless.service.getAllFunctions().forEach(name => { + if (this.serverless.service.functions[name].package.artifact) { + this.serverless.service.functions[name].package.artifact = path.join( + this.originalServicePath, + serverlessFolder, + path.basename( + this.serverless.service.functions[name].package.artifact + ) + ) + } + }) } async cleanup(): Promise {