Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"rollup-plugin-postcss": "^1.6.1",
"rollup-plugin-preserve-shebang": "^0.1.6",
"rollup-plugin-sizes": "^0.4.2",
"rollup-plugin-strict-alias": "^1.0.0",
"rollup-plugin-terser": "^3.0.0",
"rollup-plugin-typescript2": "^0.18.0",
"sade": "^1.4.0",
Expand Down
20 changes: 1 addition & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import nodeResolve from 'rollup-plugin-node-resolve';
import buble from 'rollup-plugin-buble';
import { terser } from 'rollup-plugin-terser';
import postcss from 'rollup-plugin-postcss';
import alias from 'rollup-plugin-strict-alias';
import gzipSize from 'gzip-size';
import brotliSize from 'brotli-size';
import prettyBytes from 'pretty-bytes';
Expand Down Expand Up @@ -291,19 +290,6 @@ function createConfig(options, entry, format, writeMeta) {
let nameCache = {};
let mangleOptions = options.pkg.mangle || false;

let exportType;
if (format !== 'es') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make it an option instead of deleting?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could put this code behind an option. In either case it needs to be disabled for TypeScript because this breaks the generated typing definitions.

try {
let file = fs.readFileSync(entry, 'utf-8');
let hasDefault = /\bexport\s*default\s*[a-zA-Z_$]/.test(file);
let hasNamed =
/\bexport\s*(let|const|var|async|function\*?)\s*[a-zA-Z_$*]/.test(
file,
) || /^\s*export\s*\{/m.test(file);
if (hasDefault && hasNamed) exportType = 'default';
} catch (e) {}
}

const useTypescript = extname(entry) === '.ts' || extname(entry) === '.tsx';

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

let config = {
inputOptions: {
input: exportType ? resolve(__dirname, '../src/lib/__entry__.js') : entry,
input: entry,
external: id => {
if (id === 'babel-plugin-transform-async-to-promises/helpers') {
return false;
Expand All @@ -335,9 +321,6 @@ function createConfig(options, entry, format, writeMeta) {
},
plugins: []
.concat(
alias({
__microbundle_entry__: entry,
}),
postcss({
plugins: [
autoprefixer(),
Expand Down Expand Up @@ -495,7 +478,6 @@ function createConfig(options, entry, format, writeMeta) {
},

outputOptions: {
exports: exportType ? 'default' : undefined,
paths: aliases,
globals,
strict: options.strict === true,
Expand Down
27 changes: 27 additions & 0 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,33 @@ Build \\"customSrc\\" to dist:
212 B: custom-src.umd.js.br"
`;

exports[`fixtures default-named 1`] = `
"Used script: microbundle

Directory tree:

default-named
dist
default-named.js
default-named.js.map
default-named.mjs
default-named.mjs.map
default-named.umd.js
default-named.umd.js.map
package.json
src
index.js


Build \\"defaultNamed\\" to dist:
59 B: default-named.js.gz
42 B: default-named.js.br
70 B: default-named.mjs.gz
58 B: default-named.mjs.br
162 B: default-named.umd.js.gz
124 B: default-named.umd.js.br"
`;

exports[`fixtures esnext-ts 1`] = `
"Used script: microbundle --raw

Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/default-named/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "default-named"
}
2 changes: 2 additions & 0 deletions test/fixtures/default-named/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const foo = 42;
export default function bar() {}
9 changes: 9 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,13 @@ describe('fixtures', () => {
.startsWith('#!'),
).toEqual(true);
});

it('should keep named and default export', () => {
const mod = require(resolve(
FIXTURES_DIR,
'default-named/dist/default-named.js',
));

expect(Object.keys(mod)).toEqual(['foo', 'default']);
});
});