Skip to content

Commit

Permalink
fix: use relative path for artifact file (#325)
Browse files Browse the repository at this point in the history
Absolute artifact paths break deployment in scenario where serverless package runs in one folder
and later serverless deploy runs in a different folder (happens in CI/CD systems).
Serverless Framework uses the artifact path to determine the location of the file to copy from.

Closes #324
  • Loading branch information
coyoteecd authored Jul 20, 2022
1 parent fd3d4e6 commit f7f1e9b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
7 changes: 1 addition & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,12 @@ class EsbuildServerlessPlugin implements ServerlessPlugin {

if (service.package.individually || this.options.function) {
Object.values(this.functions).forEach((func) => {
func.package.artifact = path.join(
this.serviceDirPath,
SERVERLESS_FOLDER,
path.basename(func.package.artifact)
);
func.package.artifact = path.join(SERVERLESS_FOLDER, path.basename(func.package.artifact));
});
return;
}

service.package.artifact = path.join(
this.serviceDirPath,
SERVERLESS_FOLDER,
path.basename(service.package.artifact)
);
Expand Down
12 changes: 6 additions & 6 deletions src/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('Move Artifacts', () => {
"events": Array [],
"handler": "hello1.handler",
"package": Object {
"artifact": "/workDir/.serverless/hello1",
"artifact": ".serverless/hello1",
},
},
}
Expand All @@ -112,14 +112,14 @@ describe('Move Artifacts', () => {
"events": Array [],
"handler": "hello1.handler",
"package": Object {
"artifact": "/workDir/.serverless/hello1",
"artifact": ".serverless/hello1",
},
},
"hello2": Object {
"events": Array [],
"handler": "hello2.handler",
"package": Object {
"artifact": "/workDir/.serverless/hello2",
"artifact": ".serverless/hello2",
},
},
}
Expand All @@ -145,14 +145,14 @@ describe('Move Artifacts', () => {
"events": Array [],
"handler": "hello1.handler",
"package": Object {
"artifact": "/workDir/.serverless/hello1",
"artifact": ".serverless/hello1",
},
},
"hello2": Object {
"events": Array [],
"handler": "hello2.handler",
"package": Object {
"artifact": "/workDir/.serverless/hello2",
"artifact": ".serverless/hello2",
},
},
}
Expand All @@ -166,7 +166,7 @@ describe('Move Artifacts', () => {

await plugin.moveArtifacts();

expect(plugin.serverless.service.package.artifact).toBe('/workDir/.serverless/hello');
expect(plugin.serverless.service.package.artifact).toBe('.serverless/hello');
});
});
});

0 comments on commit f7f1e9b

Please sign in to comment.