"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "default", { enumerable: true, get: function() { return _default; } }); const _fastglob = /*#__PURE__*/ _interop_require_default(require("fast-glob")); const _path = /*#__PURE__*/ _interop_require_default(require("path")); function _interop_require_default(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const pluginName = 'rollup-plugin-multi-input'; const doYouNeedRollupMessage = ` \u001b[31mATTENTION:\u001b[0m Do you still need \u001b[34m${pluginName}\u001b[0m? Since Rollup 3, the \u001b[32m[preserveModules](https://rollupjs.org/configuration-options/#output-preservemodules)\u001b[0m and \u001b[32m[preserveModulesRoot](https://rollupjs.org/configuration-options/#output-preservemodulesroot)\u001b[0m options are available, which can often eliminate the necessity of \u001b[34m${pluginName}\u001b[0m. `; const isString = (value)=>typeof value === 'string'; /** * default multi-input Options * */ const defaultOptions = { // `path.sep` is used for windows support relative: `src${_path.default.sep}` }; // extract the output file name from a file name const outputFileName = (filePath)=>filePath.replace(/\.[^/.]+$/, '').replace(/\\/g, '/'); /** * multiInput is a rollup plugin to use multiple entry point and preserve the directory * structure in the dist folder * */ const multiInput = (options = defaultOptions)=>{ const { glob: globOptions, relative = defaultOptions.relative, transformOutputPath } = options; return { name: pluginName, buildStart () { if (this.info) { this.info(doYouNeedRollupMessage); } }, options (conf) { // flat to enable input to be a string or an array const inputs = [ conf.input ].flat(); // separate globs inputs string from others to enable input to be a mixed array too const globs = inputs.filter(isString); const others = inputs.filter((value)=>!isString(value)); const normalizedGlobs = globs.map((glob)=>glob.replace(/\\/g, '/')); // get files from the globs strings and return as a Rollup entries Object const entries = _fastglob.default.sync(normalizedGlobs, globOptions).map((name)=>{ const filePath = _path.default.relative(relative, name); const isRelative = !filePath.startsWith(`..${_path.default.sep}`); const relativeFilePath = isRelative ? filePath : _path.default.relative(`.${_path.default.sep}`, name); if (transformOutputPath) { return [ outputFileName(transformOutputPath(relativeFilePath, name)), name ]; } return [ outputFileName(relativeFilePath), name ]; }); const input = Object.assign({}, Object.fromEntries(entries), // add no globs input to the result ...others); // return the new configuration with the glob input and the non string inputs return { ...conf, input }; } }; }; const _default = multiInput;