mirror of
https://github.com/developit/microbundle.git
synced 2026-01-18 13:56:35 +00:00
Fix shebang preservation (#417)
This commit is contained in:
parent
700d9549ac
commit
1779edf4cd
27
src/index.js
27
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({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user