diff --git a/.changeset/hungry-news-admire.md b/.changeset/hungry-news-admire.md new file mode 100644 index 00000000..c62ae577 --- /dev/null +++ b/.changeset/hungry-news-admire.md @@ -0,0 +1,5 @@ +--- +'microbundle': patch +--- + +Add support for generating inline sourcemaps diff --git a/src/index.js b/src/index.js index 3887c51a..29988aba 100644 --- a/src/index.js +++ b/src/index.js @@ -57,7 +57,11 @@ export default async function microbundle(inputOptions) { options.name = finalName; options.pkg.name = pkgName; - if (options.sourcemap !== false) { + if (options.sourcemap === 'inline') { + console.log( + 'Warning: inline sourcemaps should only be used for debugging purposes.', + ); + } else if (options.sourcemap !== false) { options.sourcemap = true; } diff --git a/src/prog.js b/src/prog.js index 2211d217..a40a99c2 100644 --- a/src/prog.js +++ b/src/prog.js @@ -55,7 +55,7 @@ export default handler => { .option('--strict', 'Enforce undefined global context and add "use strict"') .option('--name', 'Specify name exposed in UMD builds') .option('--cwd', 'Use an alternative working directory', '.') - .option('--sourcemap', 'Generate source map', true) + .option('--sourcemap', 'Generate source map') .option( '--css-modules', 'Turns on css-modules for all .css imports. Passing a string will override the scopeName. eg --css-modules="_[hash]"', diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index f5e70e8f..168a0273 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -1675,6 +1675,51 @@ exports[`fixtures build esnext-ts with microbundle 6`] = ` " `; +exports[`fixtures build inline-source-map with microbundle 1`] = ` +"Used script: microbundle --sourcemap inline + +Directory tree: + +inline-source-map + dist + inline-source-map.esm.js + inline-source-map.js + inline-source-map.umd.js + package.json + src + index.js + two.js + + +Build \\"inlineSourceMap\\" to dist: +187 B: inline-source-map.js.gz +138 B: inline-source-map.js.br +188 B: inline-source-map.esm.js.gz +139 B: inline-source-map.esm.js.br +279 B: inline-source-map.umd.js.gz +219 B: inline-source-map.umd.js.br" +`; + +exports[`fixtures build inline-source-map with microbundle 2`] = `3`; + +exports[`fixtures build inline-source-map 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)}};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=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lLXNvdXJjZS1tYXAuZXNtLmpzIiwic291cmNlcyI6WyIuLi9zcmMvdHdvLmpzIiwiLi4vc3JjL2luZGV4LmpzIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBhc3luYyBmdW5jdGlvbiB0d28oLi4uYXJncykge1xuXHRyZXR1cm4gYXJncy5yZWR1Y2UoKHRvdGFsLCB2YWx1ZSkgPT4gdG90YWwgKyB2YWx1ZSwgMCk7XG59XG4iLCJpbXBvcnQgeyB0d28gfSBmcm9tICcuL3R3byc7XG5cbmV4cG9ydCBkZWZhdWx0IGFzeW5jIGZ1bmN0aW9uKC4uLmFyZ3MpIHtcblx0cmV0dXJuIFthd2FpdCB0d28oLi4uYXJncyksIGF3YWl0IHR3byguLi5hcmdzKV07XG59XG4iXSwibmFtZXMiOlsidHdvIiwicmVkdWNlIiwidG90YWwiLCJ2YWx1ZSIsImFyZ3MiXSwibWFwcGluZ3MiOiJJQUFzQkEsaUNBQ3JCLHVCQUFPLGlCQUFLQyxPQUFPLFNBQUNDLEVBQU9DLFVBQVVELEVBQVFDLEdBQU8sSUFEckQsa0ZDRWlDQywwQ0FDbEJKLGVBQU9JLDRDQUFhSixlQUFPSSxxQkFBekMsTUFBTyxVQURSIn0= +" +`; + +exports[`fixtures build inline-source-map 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=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lLXNvdXJjZS1tYXAuanMiLCJzb3VyY2VzIjpbIi4uL3NyYy90d28uanMiLCIuLi9zcmMvaW5kZXguanMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGFzeW5jIGZ1bmN0aW9uIHR3byguLi5hcmdzKSB7XG5cdHJldHVybiBhcmdzLnJlZHVjZSgodG90YWwsIHZhbHVlKSA9PiB0b3RhbCArIHZhbHVlLCAwKTtcbn1cbiIsImltcG9ydCB7IHR3byB9IGZyb20gJy4vdHdvJztcblxuZXhwb3J0IGRlZmF1bHQgYXN5bmMgZnVuY3Rpb24oLi4uYXJncykge1xuXHRyZXR1cm4gW2F3YWl0IHR3byguLi5hcmdzKSwgYXdhaXQgdHdvKC4uLmFyZ3MpXTtcbn1cbiJdLCJuYW1lcyI6WyJ0d28iLCJyZWR1Y2UiLCJ0b3RhbCIsInZhbHVlIiwiYXJncyJdLCJtYXBwaW5ncyI6IklBQXNCQSxpQ0FDckIsdUJBQU8saUJBQUtDLE9BQU8sU0FBQ0MsRUFBT0MsVUFBVUQsRUFBUUMsR0FBTyxJQURyRCxrRkNFaUNDLDBDQUNsQkosZUFBT0ksNENBQWFKLGVBQU9JLHFCQUF6QyxNQUFPLFVBRFIifQ== +" +`; + +exports[`fixtures build inline-source-map with microbundle 5`] = ` +"!function(e,r){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?module.exports=r():\\"function\\"==typeof define&&define.amd?define(r):(e=e||self).inlineSourceMap=r()}(this,function(){var e=function(){try{var e=arguments;return Promise.resolve([].slice.call(e).reduce(function(e,r){return e+r},0))}catch(e){return Promise.reject(e)}};return function(){try{var r=arguments,n=[].slice.call(r);return Promise.resolve(e.apply(void 0,n)).then(function(r){return Promise.resolve(e.apply(void 0,n)).then(function(e){return[r,e]})})}catch(e){return Promise.reject(e)}}}); +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lLXNvdXJjZS1tYXAudW1kLmpzIiwic291cmNlcyI6WyIuLi9zcmMvdHdvLmpzIiwiLi4vc3JjL2luZGV4LmpzIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBhc3luYyBmdW5jdGlvbiB0d28oLi4uYXJncykge1xuXHRyZXR1cm4gYXJncy5yZWR1Y2UoKHRvdGFsLCB2YWx1ZSkgPT4gdG90YWwgKyB2YWx1ZSwgMCk7XG59XG4iLCJpbXBvcnQgeyB0d28gfSBmcm9tICcuL3R3byc7XG5cbmV4cG9ydCBkZWZhdWx0IGFzeW5jIGZ1bmN0aW9uKC4uLmFyZ3MpIHtcblx0cmV0dXJuIFthd2FpdCB0d28oLi4uYXJncyksIGF3YWl0IHR3byguLi5hcmdzKV07XG59XG4iXSwibmFtZXMiOlsidHdvIiwicmVkdWNlIiwidG90YWwiLCJ2YWx1ZSIsImFyZ3MiXSwibWFwcGluZ3MiOiI0TEFBc0JBLGlDQUNyQix1QkFBTyxpQkFBS0MsT0FBTyxTQUFDQyxFQUFPQyxVQUFVRCxFQUFRQyxHQUFPLElBRHJELDBFQ0VpQ0MsMENBQ2xCSixlQUFPSSw0Q0FBYUosZUFBT0kscUJBQXpDLE1BQU8sVUFEUiJ9 +" +`; + exports[`fixtures build jsx with microbundle 1`] = ` "Used script: microbundle diff --git a/test/fixtures/inline-source-map/package.json b/test/fixtures/inline-source-map/package.json new file mode 100644 index 00000000..7f4b57c2 --- /dev/null +++ b/test/fixtures/inline-source-map/package.json @@ -0,0 +1,6 @@ +{ + "name": "inline-source-map", + "scripts": { + "build": "microbundle --sourcemap inline" + } +} diff --git a/test/fixtures/inline-source-map/src/index.js b/test/fixtures/inline-source-map/src/index.js new file mode 100644 index 00000000..a756a0a4 --- /dev/null +++ b/test/fixtures/inline-source-map/src/index.js @@ -0,0 +1,5 @@ +import { two } from './two'; + +export default async function(...args) { + return [await two(...args), await two(...args)]; +} diff --git a/test/fixtures/inline-source-map/src/two.js b/test/fixtures/inline-source-map/src/two.js new file mode 100644 index 00000000..9f1f741b --- /dev/null +++ b/test/fixtures/inline-source-map/src/two.js @@ -0,0 +1,3 @@ +export async function two(...args) { + return args.reduce((total, value) => total + value, 0); +}