'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var pluginutils = require('@rollup/pluginutils'); var MagicString = require('magic-string'); function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; } var MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString); function processCaptureOption(option) { // return null if option is null or undefined if (option == null) return null; // return option if it's a function if (typeof option === 'function') return option; // throw if option is not an object at this point if (typeof option !== 'object') throw new TypeError(`${option} is not a function nor an object`); // return capture function from object return captured => { option.shebang = captured; }; } function stripShebang(options = {}) { const { include = /\.[jt]s$/, exclude, capture, sourcemap } = options; // create filter const filter = pluginutils.createFilter(include, exclude); // normalize capture option const captureShebang = processCaptureOption(capture); // normalize sourcemap option const generateMap = sourcemap !== false; return { name: 'strip-shebang', transform(sourceCode, id) { // exit if filter doesn't pass the test if (!filter(id)) return; // check if shebang is present in the file const match = /^#!.*/.exec(sourceCode); // exit if shebang not resent if (!match) return; // get shebang from match const [shebang] = match; // store shebang if (captureShebang) { captureShebang(shebang); } // get shebang length const { length } = shebang; // return transformed string only if no sourcemap needs to be generated if (!generateMap) return sourceCode.substring(length); // create sourcemap manager const ms = new MagicString__default.default(sourceCode).remove(0, length); // return transformed string with sourcemap const code = ms.toString(); const map = ms.generateMap({ hires: true }); return { code, map }; } }; } exports.stripShebang = stripShebang; //# sourceMappingURL=strip-shebang.cjs.map