/* Rollup Riot.js Plugin, @license MIT */ 'use strict'; var compiler = require('@riotjs/compiler'); var pluginutils = require('@rollup/pluginutils'); const justExt = (file) => { const match = /[^/\\]\.([^./\\]*)$/.exec(file); return match ? match[1] : '' }; function getFilter(opts) { const filter = pluginutils.createFilter(opts.include, opts.exclude); const exts = Array.isArray(opts.ext) ? opts.ext : [opts.ext || 'riot']; if (!exts.length) { return filter } exts.forEach((e, i, arr) => { if (e[0] === '.') { arr[i] = e.substr(1); } }); return (name) => filter(name) && exts.indexOf(justExt(name)) > -1 } /* eslint-disable fp/no-delete */ function riot(options) { // clone options options = Object.assign({}, options); const filter = getFilter(options) // drop properties not necessary for Riot compiler ;['ext', 'include', 'parsers', 'sourcemap'].forEach((key) => { delete options[key]; }); return { transform(src, id) { if (!filter(id)) { return null } const { code, map } = compiler.compile(src, { file: id, ...options, }); return { code, map } }, } } module.exports = riot;