Skip to content

Commit

Permalink
Merge pull request #6 from praos-health/fix/layer-artifacts
Browse files Browse the repository at this point in the history
fix: fixed issue with layer artifacts not being included
  • Loading branch information
praoshealth authored Sep 24, 2024
2 parents 6696b89 + a39b67b commit 18649cf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@praos-health/serverless-plugin-typescript",
"version": "2.1.5",
"version": "2.1.6",
"license": "MIT",
"main": "dist/src/index.js",
"files": [
Expand Down
29 changes: 22 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,33 @@ export class TypeScriptPlugin {
async moveArtifacts(): Promise<void> {
const { service } = this.serverless

// https://github.com/serverless/serverless-plugin-typescript/issues/270
const sourcePath = path.join(this.originalServicePath, BUILD_FOLDER, SERVERLESS_FOLDER)
const destinationPath = path.join(this.originalServicePath, SERVERLESS_FOLDER)

await fs.copy(
path.join(this.originalServicePath, BUILD_FOLDER, SERVERLESS_FOLDER),
path.join(this.originalServicePath, SERVERLESS_FOLDER)
sourcePath,
destinationPath
)

// After this function returns, the build folder will be deleted
// because the files have been copied into the .serverless folder.
// However, serverless will still be looking for that build folder
// at deploy time because it doesn't know that it has been deleted.
// This updates the reference.
const layerNames = service.getAllLayers()
layerNames.forEach(name => {
service.layers[name].package.artifact = path.join(
this.originalServicePath,
SERVERLESS_FOLDER,
path.basename(service.layers[name].package.artifact)
)
const existingArtifactPath = service.layers[name].package.artifact;
// Only reset this reference if the artifact was originally copied by
// this plugin. Otherwise, leave it alone, because the user (or another plugin)
// has set this to a specific location.
if (path.dirname(existingArtifactPath) === sourcePath) {
service.layers[name].package.artifact = path.join(
this.originalServicePath,
SERVERLESS_FOLDER,
path.basename(existingArtifactPath)
)
}
})

if (this.options.function) {
Expand Down

0 comments on commit 18649cf

Please sign in to comment.