Skip to content

Commit

Permalink
feat: add enabled flag to CodeSigningPlugin (#409)
Browse files Browse the repository at this point in the history
* feat: add enabled flag to CodeSigningPlugin

* chore: add changeset

* test: add test for enabled flag

---------

Co-authored-by: Rafał Zakrzewski <[email protected]>
  • Loading branch information
jbroma and RafikiTiki authored Aug 3, 2023
1 parent 3bcce76 commit d4d7dc7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-gorillas-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack": minor
---

Added enabled flag to CodeSigningPlugin, this is useful when you want to disable the plugin in development environment and only keep it in production. For now this flag defaults to true to prevent a breaking change.
12 changes: 12 additions & 0 deletions packages/repack/src/webpack/plugins/CodeSigningPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type { WebpackPlugin } from '../../types';
* {@link CodeSigningPlugin} configuration options.
*/
export interface CodeSigningPluginConfig {
/** Whether the plugin is enabled. Defaults to true */
enabled?: boolean;
/** Output path to a directory, where signed bundles should be saved. */
outputPath: string;
/** Path to the private key. */
Expand All @@ -33,6 +35,16 @@ export class CodeSigningPlugin implements WebpackPlugin {
* @param compiler Webpack compiler instance.
*/
apply(compiler: webpack.Compiler) {
/**
* For now this flag defaults to true to avoid a breaking change.
*
* TODO: In next major revision, we should consider removing the default here
* and align this option with other plugins.
*/
if (this.config.enabled === false) {
return;
}

const pluginName = CodeSigningPlugin.name;
// reserve 1280 bytes for the token even if it's smaller
// to leave some space for future additions to the JWT without breaking compatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,17 @@ describe('CodeSigningPlugin', () => {
)
).toThrowError();
});

it('skips applying plugin when enabled flag is explicitly set to false', async () => {
const pluginInstance = new CodeSigningPlugin({
enabled: false,
outputPath: path.join('output', 'signed'),
privateKeyPath: '__fixtures__/testRS256.pem',
});

pluginInstance.apply(compilerMock as unknown as webpack.Compiler);

expect(compilerMock.hooks.thisCompilation.tap).not.toHaveBeenCalled();
expect(compilerMock.hooks.afterEmit.tapPromise).not.toHaveBeenCalled();
});
});

0 comments on commit d4d7dc7

Please sign in to comment.