Fix shebang preservation (#417)

This commit is contained in:
Jason Miller 2019-06-13 17:46:57 -04:00 committed by Leah
parent 700d9549ac
commit 1779edf4cd

View File

@ -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({