From 5ef54514e2747fd08b13147b7120edc0f365e81d Mon Sep 17 00:00:00 2001 From: Konstantin Shutkin Date: Wed, 11 Oct 2023 22:43:15 +0200 Subject: [PATCH] feat: allow options to be function --- .changeset/eight-actors-guess.md | 5 +++++ plugin-externals/src/index.ts | 3 +++ plugin-externals/src/types.ts | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changeset/eight-actors-guess.md diff --git a/.changeset/eight-actors-guess.md b/.changeset/eight-actors-guess.md new file mode 100644 index 0000000..746d171 --- /dev/null +++ b/.changeset/eight-actors-guess.md @@ -0,0 +1,5 @@ +--- +"@rollup-extras/plugin-externals": minor +--- + +allow options to be function diff --git a/plugin-externals/src/index.ts b/plugin-externals/src/index.ts index e13283d..326d02a 100644 --- a/plugin-externals/src/index.ts +++ b/plugin-externals/src/index.ts @@ -10,6 +10,9 @@ import packageDirectory from 'pkg-dir'; const factories = { logger }; export default function(options: ExternalsPluginOptions = {}) { + if (typeof options === 'function') { + options = { external: options }; + } const { pluginName, external, logger, verbose } = getOptionsObject(options, { pluginName: '@rollup-extras/plugin-externals', verbose: false diff --git a/plugin-externals/src/types.ts b/plugin-externals/src/types.ts index c88a89e..86b042c 100644 --- a/plugin-externals/src/types.ts +++ b/plugin-externals/src/types.ts @@ -4,4 +4,4 @@ export type ExternalsPluginOptions = { pluginName?: string, verbose?: boolean, external?: (id: string, external: boolean, importer?: string) => boolean -}; \ No newline at end of file +} | ((id: string, external: boolean, importer?: string) => boolean); \ No newline at end of file