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
5 changes: 5 additions & 0 deletions .changeset/old-dodos-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'microbundle': patch
---

Fixes filename generation for es & modern outputs. Both 'jsnext:main' and 'esmodule' were incorrectly ignored.
8 changes: 2 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,15 @@ function getMain({ options, entry, format }) {
mainsByFormat.es = replaceName(
pkg.module && !pkg.module.match(/src\//)
? pkg.module
: pkg['jsnext:main'] || pkgTypeModule
? 'x.esm.js'
: 'x.esm.mjs',
: pkg['jsnext:main'] || (pkgTypeModule ? 'x.esm.js' : 'x.esm.mjs'),
mainNoExtension,
);

mainsByFormat.modern = replaceName(
(pkg.exports && walk(pkg.exports, pkgTypeModule)) ||
(pkg.syntax && pkg.syntax.esmodules) ||
pkg.esmodule ||
pkgTypeModule
? 'x.modern.js'
: 'x.modern.mjs',
(pkgTypeModule ? 'x.modern.js' : 'x.modern.mjs'),
mainNoExtension,
);
mainsByFormat.cjs = replaceName(
Expand Down
116 changes: 116 additions & 0 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1418,6 +1418,122 @@ exports[`fixtures build custom-babelrc with microbundle 5`] = `
"
`;

exports[`fixtures build custom-outputs with microbundle 1`] = `
"Used script: microbundle -f modern,es,umd,cjs

Directory tree:

custom-outputs
dist
custom-outputs.exportsx.mjs
custom-outputs.exportsx.mjs.map
custom-outputs.js
custom-outputs.js.map
custom-outputs.modulex.mjs
custom-outputs.modulex.mjs.map
custom-outputs.umdx.js
custom-outputs.umdx.js.map
package.json
src
index.js
two.js


Build \\"custom-outputs\\" to dist:
187 B: custom-outputs.js.gz
138 B: custom-outputs.js.br
113 B: custom-outputs.exportsx.mjs.gz
92 B: custom-outputs.exportsx.mjs.br
188 B: custom-outputs.modulex.mjs.gz
139 B: custom-outputs.modulex.mjs.br
273 B: custom-outputs.umdx.js.gz
203 B: custom-outputs.umdx.js.br"
`;

exports[`fixtures build custom-outputs with microbundle 2`] = `8`;

exports[`fixtures build custom-outputs with microbundle 3`] = `
"async function n(...n){return n.reduce((n,t)=>n+t,0)}async function t(...t){return[await n(...t),await n(...t)]}export default t;
//# sourceMappingURL=custom-outputs.exportsx.mjs.map
"
`;

exports[`fixtures build custom-outputs with microbundle 4`] = `
"var r=function(){try{var r=arguments;return Promise.resolve([].slice.call(r).reduce(function(r,e){return r+e},0))}catch(r){return Promise.reject(r)}};module.exports=function(){try{var e=arguments,t=[].slice.call(e);return Promise.resolve(r.apply(void 0,t)).then(function(e){return Promise.resolve(r.apply(void 0,t)).then(function(r){return[e,r]})})}catch(r){return Promise.reject(r)}};
//# sourceMappingURL=custom-outputs.js.map
"
`;

exports[`fixtures build custom-outputs with microbundle 5`] = `
"var r=function(){try{var r=arguments;return Promise.resolve([].slice.call(r).reduce(function(r,e){return r+e},0))}catch(r){return Promise.reject(r)}};export default function(){try{var e=arguments,t=[].slice.call(e);return Promise.resolve(r.apply(void 0,t)).then(function(e){return Promise.resolve(r.apply(void 0,t)).then(function(r){return[e,r]})})}catch(r){return Promise.reject(r)}}
//# sourceMappingURL=custom-outputs.modulex.mjs.map
"
`;

exports[`fixtures build custom-outputs with microbundle 6`] = `
"!function(e,t){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?module.exports=t():\\"function\\"==typeof define&&define.amd?define(t):(e||self).customOutputs=t()}(this,function(){var e=function(){try{var e=arguments;return Promise.resolve([].slice.call(e).reduce(function(e,t){return e+t},0))}catch(e){return Promise.reject(e)}};return function(){try{var t=arguments,r=[].slice.call(t);return Promise.resolve(e.apply(void 0,r)).then(function(t){return Promise.resolve(e.apply(void 0,r)).then(function(e){return[t,e]})})}catch(e){return Promise.reject(e)}}});
//# sourceMappingURL=custom-outputs.umdx.js.map
"
`;

exports[`fixtures build custom-outputs-alt with microbundle 1`] = `
"Used script: microbundle -f modern,es,umd,cjs

Directory tree:

custom-outputs-alt
dist
custom-outputs-alt.cjsmain.js
custom-outputs-alt.cjsmain.js.map
custom-outputs-alt.esmodule.mjs
custom-outputs-alt.esmodule.mjs.map
custom-outputs-alt.jsnextmain.mjs
custom-outputs-alt.jsnextmain.mjs.map
custom-outputs-alt.unpkg.js
custom-outputs-alt.unpkg.js.map
package.json
src
index.js
two.js


Build \\"custom-outputs-alt\\" to dist:
187 B: custom-outputs-alt.cjsmain.js.gz
138 B: custom-outputs-alt.cjsmain.js.br
113 B: custom-outputs-alt.esmodule.mjs.gz
92 B: custom-outputs-alt.esmodule.mjs.br
188 B: custom-outputs-alt.jsnextmain.mjs.gz
139 B: custom-outputs-alt.jsnextmain.mjs.br
277 B: custom-outputs-alt.unpkg.js.gz
226 B: custom-outputs-alt.unpkg.js.br"
`;

exports[`fixtures build custom-outputs-alt with microbundle 2`] = `8`;

exports[`fixtures build custom-outputs-alt with microbundle 3`] = `
"var r=function(){try{var r=arguments;return Promise.resolve([].slice.call(r).reduce(function(r,e){return r+e},0))}catch(r){return Promise.reject(r)}};module.exports=function(){try{var e=arguments,t=[].slice.call(e);return Promise.resolve(r.apply(void 0,t)).then(function(e){return Promise.resolve(r.apply(void 0,t)).then(function(r){return[e,r]})})}catch(r){return Promise.reject(r)}};
//# sourceMappingURL=custom-outputs-alt.cjsmain.js.map
"
`;

exports[`fixtures build custom-outputs-alt with microbundle 4`] = `
"async function n(...n){return n.reduce((n,t)=>n+t,0)}async function t(...t){return[await n(...t),await n(...t)]}export default t;
//# sourceMappingURL=custom-outputs-alt.esmodule.mjs.map
"
`;

exports[`fixtures build custom-outputs-alt with microbundle 5`] = `
"var r=function(){try{var r=arguments;return Promise.resolve([].slice.call(r).reduce(function(r,e){return r+e},0))}catch(r){return Promise.reject(r)}};export default function(){try{var e=arguments,t=[].slice.call(e);return Promise.resolve(r.apply(void 0,t)).then(function(e){return Promise.resolve(r.apply(void 0,t)).then(function(r){return[e,r]})})}catch(r){return Promise.reject(r)}}
//# sourceMappingURL=custom-outputs-alt.jsnextmain.mjs.map
"
`;

exports[`fixtures build custom-outputs-alt with microbundle 6`] = `
"!function(e,t){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?module.exports=t():\\"function\\"==typeof define&&define.amd?define(t):(e||self).customOutputsAlt=t()}(this,function(){var e=function(){try{var e=arguments;return Promise.resolve([].slice.call(e).reduce(function(e,t){return e+t},0))}catch(e){return Promise.reject(e)}};return function(){try{var t=arguments,r=[].slice.call(t);return Promise.resolve(e.apply(void 0,r)).then(function(t){return Promise.resolve(e.apply(void 0,r)).then(function(e){return[t,e]})})}catch(e){return Promise.reject(e)}}});
//# sourceMappingURL=custom-outputs-alt.unpkg.js.map
"
`;

exports[`fixtures build custom-source with microbundle 1`] = `
"Used script: microbundle

Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/custom-outputs-alt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "custom-outputs-alt",
"cjs:main": "dist/custom-outputs-alt.cjsmain.js",
"unpkg": "dist/custom-outputs-alt.unpkg.js",
"jsnext:main": "dist/custom-outputs-alt.jsnextmain.mjs",
"esmodule": "dist/custom-outputs-alt.esmodule.mjs",
"scripts": {
"build": "microbundle -f modern,es,umd,cjs"
}
}
5 changes: 5 additions & 0 deletions test/fixtures/custom-outputs-alt/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { two } from './two';

export default async function(...args) {
return [await two(...args), await two(...args)];
}
3 changes: 3 additions & 0 deletions test/fixtures/custom-outputs-alt/src/two.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function two(...args) {
return args.reduce((total, value) => total + value, 0);
}
10 changes: 10 additions & 0 deletions test/fixtures/custom-outputs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "custom-outputs",
"main": "dist/custom-outputs.js",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test doesn't actually test "main" correctly, as setting main creates a confusing mess of filenames (see #825 & #896).

"main": "dist/custom-outputs.cjsx.js" would make (say) the module output file path into dist/custom-outputs.cjsx.modulex.mjs. That is the "correct" output name at this time, but would be confusing as hell to debug as it doesn't match the package.json, so I've skipped it.

"umd:main": "dist/custom-outputs.umdx.js",
"module": "dist/custom-outputs.modulex.mjs",
"exports": "./dist/custom-outputs.exportsx.mjs",
"scripts": {
"build": "microbundle -f modern,es,umd,cjs"
}
}
5 changes: 5 additions & 0 deletions test/fixtures/custom-outputs/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { two } from './two';

export default async function(...args) {
return [await two(...args), await two(...args)];
}
3 changes: 3 additions & 0 deletions test/fixtures/custom-outputs/src/two.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function two(...args) {
return args.reduce((total, value) => total + value, 0);
}