Skip to content

Commit bd77b12

Browse files
bors[bot]marvinhagemeisterdevelopitForsakenHarmony
committed
Merge #265
265: Remove import pruning r=ForsakenHarmony a=marvinhagemeister Fixes #264 **EDIT:** PR #262 likely needs to be merged first, as that one fixes the failing CI. Co-authored-by: Marvin Hagemeister <[email protected]> Co-authored-by: Jason Miller <[email protected]> Co-authored-by: Leah <[email protected]>
2 parents 0013f24 + 2dd10e5 commit bd77b12

File tree

6 files changed

+42
-20
lines changed

6 files changed

+42
-20
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"rollup-plugin-postcss": "^1.6.1",
6969
"rollup-plugin-preserve-shebang": "^0.1.6",
7070
"rollup-plugin-sizes": "^0.4.2",
71-
"rollup-plugin-strict-alias": "^1.0.0",
7271
"rollup-plugin-terser": "^3.0.0",
7372
"rollup-plugin-typescript2": "^0.18.0",
7473
"sade": "^1.4.0",

src/index.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import nodeResolve from 'rollup-plugin-node-resolve';
1212
import buble from 'rollup-plugin-buble';
1313
import { terser } from 'rollup-plugin-terser';
1414
import postcss from 'rollup-plugin-postcss';
15-
import alias from 'rollup-plugin-strict-alias';
1615
import gzipSize from 'gzip-size';
1716
import brotliSize from 'brotli-size';
1817
import prettyBytes from 'pretty-bytes';
@@ -291,19 +290,6 @@ function createConfig(options, entry, format, writeMeta) {
291290
let nameCache = {};
292291
let mangleOptions = options.pkg.mangle || false;
293292

294-
let exportType;
295-
if (format !== 'es') {
296-
try {
297-
let file = fs.readFileSync(entry, 'utf-8');
298-
let hasDefault = /\bexport\s*default\s*[a-zA-Z_$]/.test(file);
299-
let hasNamed =
300-
/\bexport\s*(let|const|var|async|function\*?)\s*[a-zA-Z_$*]/.test(
301-
file,
302-
) || /^\s*export\s*\{/m.test(file);
303-
if (hasDefault && hasNamed) exportType = 'default';
304-
} catch (e) {}
305-
}
306-
307293
const useTypescript = extname(entry) === '.ts' || extname(entry) === '.tsx';
308294

309295
const externalPredicate = new RegExp(`^(${external.join('|')})($|/)`);
@@ -323,7 +309,7 @@ function createConfig(options, entry, format, writeMeta) {
323309

324310
let config = {
325311
inputOptions: {
326-
input: exportType ? resolve(__dirname, '../src/lib/__entry__.js') : entry,
312+
input: entry,
327313
external: id => {
328314
if (id === 'babel-plugin-transform-async-to-promises/helpers') {
329315
return false;
@@ -335,9 +321,6 @@ function createConfig(options, entry, format, writeMeta) {
335321
},
336322
plugins: []
337323
.concat(
338-
alias({
339-
__microbundle_entry__: entry,
340-
}),
341324
postcss({
342325
plugins: [
343326
autoprefixer(),
@@ -495,7 +478,6 @@ function createConfig(options, entry, format, writeMeta) {
495478
},
496479

497480
outputOptions: {
498-
exports: exportType ? 'default' : undefined,
499481
paths: aliases,
500482
globals,
501483
strict: options.strict === true,

test/__snapshots__/index.test.js.snap

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,33 @@ Build \\"customSrc\\" to dist:
347347
212 B: custom-src.umd.js.br"
348348
`;
349349

350+
exports[`fixtures default-named 1`] = `
351+
"Used script: microbundle
352+
353+
Directory tree:
354+
355+
default-named
356+
dist
357+
default-named.js
358+
default-named.js.map
359+
default-named.mjs
360+
default-named.mjs.map
361+
default-named.umd.js
362+
default-named.umd.js.map
363+
package.json
364+
src
365+
index.js
366+
367+
368+
Build \\"defaultNamed\\" to dist:
369+
59 B: default-named.js.gz
370+
42 B: default-named.js.br
371+
70 B: default-named.mjs.gz
372+
58 B: default-named.mjs.br
373+
162 B: default-named.umd.js.gz
374+
124 B: default-named.umd.js.br"
375+
`;
376+
350377
exports[`fixtures esnext-ts 1`] = `
351378
"Used script: microbundle --raw
352379
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "default-named"
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const foo = 42;
2+
export default function bar() {}

test/index.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,13 @@ describe('fixtures', () => {
9696
.startsWith('#!'),
9797
).toEqual(true);
9898
});
99+
100+
it('should keep named and default export', () => {
101+
const mod = require(resolve(
102+
FIXTURES_DIR,
103+
'default-named/dist/default-named.js',
104+
));
105+
106+
expect(Object.keys(mod)).toEqual(['foo', 'default']);
107+
});
99108
});

0 commit comments

Comments
 (0)