Skip to content

Support packaging functions individually #136

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 32 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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<void> {
Expand Down Expand Up @@ -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<void> {
Expand Down