Skip to content

Commit a3c4e37

Browse files
Merge remote-tracking branch 'origin/master' into 0.8.0
2 parents 246bc22 + 93a28e2 commit a3c4e37

File tree

8 files changed

+81
-16
lines changed

8 files changed

+81
-16
lines changed

babel.config.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,12 @@ module.exports = {
33
[
44
'@babel/preset-env',
55
{
6-
exclude: [
7-
'transform-async-to-generator',
8-
'proposal-async-generator-functions',
9-
'transform-regenerator',
10-
],
116
loose: true,
127
targets: {
13-
chrome: '58',
14-
ie: '11',
8+
node: 'current',
159
},
1610
},
1711
],
1812
],
19-
plugins: [
20-
['babel-plugin-transform-async-to-promises', { inlineHelpers: true }],
21-
'@babel/plugin-syntax-jsx',
22-
],
13+
plugins: ['@babel/plugin-syntax-jsx'],
2314
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"husky": "^1.1.2",
9191
"jest": "^23.6.0",
9292
"lint-staged": "^8.0.0",
93-
"prettier": "^1.13.0",
93+
"prettier": "^1.15.3",
9494
"regenerator-runtime": "^0.12.1",
9595
"rimraf": "^2.6.2",
9696
"shell-quote": "^1.6.1",

src/cli.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env node
2+
13
import microbundle from '.';
24
import prog from './prog';
35
import { stdout } from './utils';

src/index.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ function createConfig(options, entry, format, writeMeta) {
319319
}
320320
loadNameCache();
321321

322+
let shebang;
323+
322324
let config = {
323325
inputOptions: {
324326
input: exportType ? resolve(__dirname, '../src/lib/__entry__.js') : entry,
@@ -375,14 +377,39 @@ function createConfig(options, entry, format, writeMeta) {
375377
babelrc: false,
376378
exclude: 'node_modules/**',
377379
plugins: [
378-
'@babel/plugin-syntax-jsx',
380+
require.resolve('@babel/plugin-syntax-jsx'),
379381
[
380-
'babel-plugin-transform-async-to-promises',
382+
require.resolve('babel-plugin-transform-async-to-promises'),
381383
{ inlineHelpers: true, externalHelpers: true },
382384
],
383-
['@babel/plugin-proposal-class-properties', { loose: true }],
385+
[
386+
require.resolve('@babel/plugin-proposal-class-properties'),
387+
{ loose: true },
388+
],
384389
],
385390
}),
391+
{
392+
// Custom plugin that removes shebang from code because newer
393+
// versions of bublé bundle their own private version of `acorn`
394+
// and I don't know a way to patch in the option `allowHashBang`
395+
// to acorn.
396+
// See: https://github.com/Rich-Harris/buble/pull/165
397+
transform(code) {
398+
let reg = /^#!(.*)/;
399+
let match = code.match(reg);
400+
401+
if (match !== null) {
402+
shebang = '#!' + match[0];
403+
}
404+
405+
code = code.replace(reg, '');
406+
407+
return {
408+
code,
409+
map: null,
410+
};
411+
},
412+
},
386413
buble({
387414
exclude: 'node_modules/**',
388415
jsx: options.jsx || 'h',
@@ -459,7 +486,9 @@ function createConfig(options, entry, format, writeMeta) {
459486
config._code = code;
460487
},
461488
},
462-
shebangPlugin(),
489+
shebangPlugin({
490+
shebang,
491+
}),
463492
)
464493
.filter(Boolean),
465494
},

test/__snapshots__/index.test.js.snap

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,3 +480,30 @@ Build \\"raw\\" to dist:
480480
1493 B: raw.umd.js.gz
481481
1245 B: raw.umd.js.br"
482482
`;
483+
484+
exports[`fixtures shebang 1`] = `
485+
"Used script: microbundle
486+
487+
Directory tree:
488+
489+
shebang
490+
dist
491+
shebang.js
492+
shebang.js.map
493+
shebang.mjs
494+
shebang.mjs.map
495+
shebang.umd.js
496+
shebang.umd.js.map
497+
package.json
498+
src
499+
index.js
500+
501+
502+
Build \\"shebang\\" to dist:
503+
85 B: shebang.js.gz
504+
62 B: shebang.js.br
505+
89 B: shebang.mjs.gz
506+
70 B: shebang.mjs.br
507+
177 B: shebang.umd.js.gz
508+
149 B: shebang.umd.js.br"
509+
`;

test/fixtures/shebang/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "shebang"
3+
}

test/fixtures/shebang/src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
export function foo() {
4+
return 'hello world';
5+
}

test/index.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,12 @@ describe('fixtures', () => {
8888
).toMatchSnapshot();
8989
});
9090
});
91+
92+
it('should keep shebang', () => {
93+
expect(
94+
fs
95+
.readFileSync(resolve(FIXTURES_DIR, 'shebang/dist/shebang.js'), 'utf8')
96+
.startsWith('#!'),
97+
).toEqual(true);
98+
});
9199
});

0 commit comments

Comments
 (0)