diff --git a/src/plugin.js b/src/plugin.js index e319e2e..f88d1d2 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -28,46 +28,49 @@ const outputFileName = (filePath) => filePath * structure in the dist folder * * @param {?Object} options - * @param {?FastGlob.Options} options.glob - the fast-glob configuration object - * @param {?string} options.relative - the base path to remove in the dist folder - * @param {?TransformOutputPathFn} options.transformOutputPath - callback function to + * @param {?FastGlob?.Options} options.glob - the fast-glob configuration object + * @param {?string?} options.relative - the base path to remove in the dist folder + * @param {?TransformOutputPathFn?} options.transformOutputPath - callback function to * transform the destination file name before generation * @return {Plugin} - the rollup plugin config for enable support of multi-entry glob inputs * */ -export default ({ - glob: globOptions, - relative = defaultOptions.relative, - transformOutputPath, -} = defaultOptions) => ({ - name: pluginName, - options(conf) { - // flat to enable input to be a string or an array - // separate globs inputs string from others to enable input to be a mixed array too - const [globs, others] = partition([conf.input].flat(), isString); - // get files from the globs strings and return as a Rollup entries Object - const input = Object - .assign( - {}, - Object.fromEntries(fastGlob - .sync(globs, globOptions) - .map((name) => { - const filePath = path.relative(relative, name); - const isRelative = !filePath.startsWith('../'); - const relativeFilePath = (isRelative - ? filePath - : path.relative('./', name)); - if (transformOutputPath) { - return [outputFileName(transformOutputPath(relativeFilePath, name)), name]; - } - return [outputFileName(relativeFilePath), name]; - })), - // add no globs input to the result - ...others, - ); +export default (options = defaultOptions) => { + const { + glob: globOptions, + relative = defaultOptions.relative, + transformOutputPath, + } = options; + return ({ + name: pluginName, + options(conf) { + // flat to enable input to be a string or an array + // separate globs inputs string from others to enable input to be a mixed array too + const [globs, others] = partition([conf.input].flat(), isString); + // get files from the globs strings and return as a Rollup entries Object + const input = Object + .assign( + {}, + Object.fromEntries(fastGlob + .sync(globs, globOptions) + .map((name) => { + const filePath = path.relative(relative, name); + const isRelative = !filePath.startsWith('../'); + const relativeFilePath = (isRelative + ? filePath + : path.relative('./', name)); + if (transformOutputPath) { + return [outputFileName(transformOutputPath(relativeFilePath, name)), name]; + } + return [outputFileName(relativeFilePath), name]; + })), + // add no globs input to the result + ...others, + ); // return the new configuration with the glob input and the non string inputs - return { - ...conf, - input, - }; - }, -}); + return { + ...conf, + input, + }; + }, + }); +};