From 1779edf4cd2df1a73c8bf93eaf633a1ec575a8a9 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Thu, 13 Jun 2019 17:46:57 -0400 Subject: [PATCH] Fix shebang preservation (#417) --- src/index.js | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/index.js b/src/index.js index f0071a0..e4cef22 100644 --- a/src/index.js +++ b/src/index.js @@ -353,7 +353,7 @@ async function getEntries({ input, cwd }) { return entries; } -// shebang cache map thing because the transform only gets run once +// shebang cache map because the transform only gets run once const shebang = {}; function createConfig(options, entry, format, writeMeta) { @@ -507,24 +507,13 @@ function createConfig(options, entry, format, writeMeta) { }), json(), { - // Custom plugin that removes shebang from code because newer - // versions of bublé bundle their own private version of `acorn` - // and I don't know a way to patch in the option `allowHashBang` - // to acorn. - // See: https://github.com/Rich-Harris/buble/pull/165 - transform(code) { - let reg = /^#!(.*)/; - let match = code.match(reg); - - shebang[options.name] = match ? '#!' + match[1] : ''; - - code = code.replace(reg, ''); - - return { - code, - map: null, - }; - }, + // We have to remove shebang so it doesn't end up in the middle of the code somewhere + transform: code => ({ + code: code.replace(/^#![^\n]*/, bang => { + shebang[options.name] = bang; + }), + map: null, + }), }, useTypescript && typescript({