Skip to content

Commit

Permalink
fix: set metafile flag in a way that prevents Serverless v3.x from ov…
Browse files Browse the repository at this point in the history
…erwriting it

Closes #8
  • Loading branch information
coyoteecd authored and adriencaccia committed Aug 18, 2022
1 parent 0e65d0c commit 7b7f11a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions plugin/serverlessAnalyzeBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ export class ServerlessAnalyzeBundlePlugin implements Plugin {
},
};
this.hooks = {
'before:package:initialize': () => {
const { analyze } = this.options;
if (analyze === undefined) {
return;
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
this.serverless.service.custom.esbuild.metafile = true;
},
'after:package:finalize': async () => {
const { analyze } = this.options;
if (analyze === undefined) {
Expand All @@ -48,5 +40,15 @@ export class ServerlessAnalyzeBundlePlugin implements Plugin {
await this.bundleVisualizer();
},
};

// The plugin requires metafile option to be true
// We set it here (and not within a hook) because Serverless Framework keeps copies of service configuration
// therefore overwriting changes made by hook functions
const { analyze } = this.options;
if (analyze === undefined) {
return;
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
this.serverless.service.custom.esbuild.metafile = true;
}
}

0 comments on commit 7b7f11a

Please sign in to comment.