From 57dbf687acf1517276173ea3139fce3af34e2f85 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 16 Feb 2021 10:35:26 -0800 Subject: [PATCH 1/4] Make a config option. --- src/Package.ts | 1 + src/Packemon.ts | 1 + src/rollup/config.ts | 5 ++--- src/schemas.ts | 1 + src/types.ts | 3 +++ 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Package.ts b/src/Package.ts index daa8fe378..ce7e9a9a4 100644 --- a/src/Package.ts +++ b/src/Package.ts @@ -224,6 +224,7 @@ export default class Package { inputs: config.inputs, namespace: config.namespace, platform, + sourceMaps: config.sourceMaps, support: config.support, }); }); diff --git a/src/Packemon.ts b/src/Packemon.ts index caeb285c3..841b28750 100644 --- a/src/Packemon.ts +++ b/src/Packemon.ts @@ -209,6 +209,7 @@ export default class Packemon { config.formats.map((format) => ({ format, platform: config.platform, + sourceMaps: config.sourceMaps, support: config.support, })), ); diff --git a/src/rollup/config.ts b/src/rollup/config.ts index 27a13ce18..78712c786 100644 --- a/src/rollup/config.ts +++ b/src/rollup/config.ts @@ -84,7 +84,7 @@ export function getRollupOutputConfig( features: FeatureFlags, build: BundleBuild, ): OutputOptions { - const { format, platform, support } = build; + const { format, platform, sourceMaps, support } = build; const name = artifact.outputName; const { ext, folder } = artifact.getOutputMetadata(format); @@ -111,8 +111,7 @@ export function getRollupOutputConfig( sourceMaps: false, }), ], - // Only enable source maps for browsers - sourcemap: Boolean(features.analyze) || platform !== 'node', + sourcemap: Boolean(features.analyze) || sourceMaps, sourcemapExcludeSources: true, }; diff --git a/src/schemas.ts b/src/schemas.ts index c4ab94b23..076bc0260 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -68,6 +68,7 @@ export const packemonBlueprint: Blueprint = { }), namespace: string(), platform: union([array(platform), platform], DEFAULT_PLATFORM), + sourceMaps: bool(), support, }; diff --git a/src/types.ts b/src/types.ts index 78d22dd93..c1c947db0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -62,6 +62,7 @@ export interface PackemonPackageConfig { inputs?: Record; namespace?: string; platform?: Platform | Platform[]; + sourceMaps?: boolean; support?: Support; } @@ -74,6 +75,7 @@ export interface PackageConfig { inputs: Record; namespace: string; platform: Platform; + sourceMaps: boolean; support: Support; } @@ -118,6 +120,7 @@ export interface BuildResult { export interface BundleBuild { format: Format; platform: Platform; + sourceMaps: boolean; support: Support; stats?: { size: number }; } From fb81370b3fb4fee9dc23c82cf559b8cfa9c67317 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 16 Feb 2021 10:47:35 -0800 Subject: [PATCH 2/4] Fix tests. --- src/Artifact.ts | 2 + src/Packemon.ts | 2 +- src/rollup/config.ts | 4 +- src/types.ts | 1 - tests/Package.test.ts | 44 ++++++++++++++++++++ tests/Packemon.test.ts | 4 ++ tests/__snapshots__/outputs.test.ts.snap | 52 ------------------------ tests/rollup/config.test.ts | 33 +++++---------- 8 files changed, 63 insertions(+), 79 deletions(-) diff --git a/src/Artifact.ts b/src/Artifact.ts index 9669aa414..118ddaefd 100644 --- a/src/Artifact.ts +++ b/src/Artifact.ts @@ -11,6 +11,8 @@ export default abstract class Artifact { readonly package: Package; + sourceMaps: boolean = false; + state: ArtifactState = 'pending'; constructor(pkg: Package, builds: T[]) { diff --git a/src/Packemon.ts b/src/Packemon.ts index 841b28750..d24b9bc3e 100644 --- a/src/Packemon.ts +++ b/src/Packemon.ts @@ -209,7 +209,6 @@ export default class Packemon { config.formats.map((format) => ({ format, platform: config.platform, - sourceMaps: config.sourceMaps, support: config.support, })), ); @@ -219,6 +218,7 @@ export default class Packemon { artifact.namespace = config.namespace; artifact.platform = config.platform; artifact.sharedLib = sharedLib; + artifact.sourceMaps = config.sourceMaps; artifact.support = config.support; pkg.addArtifact(artifact); diff --git a/src/rollup/config.ts b/src/rollup/config.ts index 78712c786..591abe8bc 100644 --- a/src/rollup/config.ts +++ b/src/rollup/config.ts @@ -84,7 +84,7 @@ export function getRollupOutputConfig( features: FeatureFlags, build: BundleBuild, ): OutputOptions { - const { format, platform, sourceMaps, support } = build; + const { format, platform, support } = build; const name = artifact.outputName; const { ext, folder } = artifact.getOutputMetadata(format); @@ -111,7 +111,7 @@ export function getRollupOutputConfig( sourceMaps: false, }), ], - sourcemap: Boolean(features.analyze) || sourceMaps, + sourcemap: Boolean(features.analyze) || artifact.sourceMaps, sourcemapExcludeSources: true, }; diff --git a/src/types.ts b/src/types.ts index c1c947db0..736b5130e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -120,7 +120,6 @@ export interface BuildResult { export interface BundleBuild { format: Format; platform: Platform; - sourceMaps: boolean; support: Support; stats?: { size: number }; } diff --git a/tests/Package.test.ts b/tests/Package.test.ts index 6f282ccea..ab8ffa3d6 100644 --- a/tests/Package.test.ts +++ b/tests/Package.test.ts @@ -755,6 +755,7 @@ describe('Package', () => { inputs: {}, platform: 'browser', namespace: '', + sourceMaps: false, support: 'stable', }, ]); @@ -777,6 +778,7 @@ describe('Package', () => { inputs: {}, platform: 'browser', namespace: 'test', + sourceMaps: false, support: 'stable', }, ]); @@ -799,6 +801,7 @@ describe('Package', () => { inputs: {}, platform: 'native', namespace: '', + sourceMaps: false, support: 'stable', }, ]); @@ -821,6 +824,7 @@ describe('Package', () => { inputs: {}, platform: 'node', namespace: '', + sourceMaps: false, support: 'stable', }, ]); @@ -843,6 +847,7 @@ describe('Package', () => { inputs: {}, platform: 'node', namespace: '', + sourceMaps: false, support: 'stable', }, ]); @@ -862,6 +867,7 @@ describe('Package', () => { inputs: {}, platform: 'browser', namespace: '', + sourceMaps: false, support: 'stable', }, { @@ -869,6 +875,7 @@ describe('Package', () => { inputs: {}, platform: 'node', namespace: '', + sourceMaps: false, support: 'stable', }, ]); @@ -889,6 +896,7 @@ describe('Package', () => { inputs: {}, platform: 'browser', namespace: '', + sourceMaps: false, support: 'stable', }, { @@ -896,6 +904,7 @@ describe('Package', () => { inputs: {}, platform: 'node', namespace: '', + sourceMaps: false, support: 'stable', }, { @@ -903,6 +912,41 @@ describe('Package', () => { inputs: {}, platform: 'native', namespace: '', + sourceMaps: false, + support: 'stable', + }, + ]); + }); + + it('can set separate source maps', () => { + pkg.setConfigs([ + { + inputs: {}, + platform: 'browser', + sourceMaps: true, + }, + { + inputs: {}, + platform: 'node', + sourceMaps: false, + }, + ]); + + expect(pkg.configs).toEqual([ + { + formats: ['lib', 'esm'], + inputs: {}, + platform: 'browser', + namespace: '', + sourceMaps: true, + support: 'stable', + }, + { + formats: ['lib'], + inputs: {}, + platform: 'node', + namespace: '', + sourceMaps: false, support: 'stable', }, ]); diff --git a/tests/Packemon.test.ts b/tests/Packemon.test.ts index 6725f2227..41d30b8b8 100644 --- a/tests/Packemon.test.ts +++ b/tests/Packemon.test.ts @@ -467,6 +467,7 @@ describe('Packemon', () => { inputs: { index: 'src/index.ts' }, namespace: '', platform: 'node', + sourceMaps: false, support: 'stable', }, { @@ -474,6 +475,7 @@ describe('Packemon', () => { inputs: { index: 'src/index.ts' }, namespace: '', platform: 'browser', + sourceMaps: false, support: 'current', }, ]); @@ -485,6 +487,7 @@ describe('Packemon', () => { inputs: { core: './src/core.ts' }, namespace: '', platform: 'node', + sourceMaps: false, support: 'stable', }, ]); @@ -496,6 +499,7 @@ describe('Packemon', () => { inputs: { index: 'src/index.ts' }, namespace: 'Test', platform: 'browser', + sourceMaps: false, support: 'stable', }, ]); diff --git a/tests/__snapshots__/outputs.test.ts.snap b/tests/__snapshots__/outputs.test.ts.snap index 2b162bb63..27277f5fb 100644 --- a/tests/__snapshots__/outputs.test.ts.snap +++ b/tests/__snapshots__/outputs.test.ts.snap @@ -96,7 +96,6 @@ function gen() { } export { createClient }; -//# sourceMappingURL=client.js.map ", ] `; @@ -173,7 +172,6 @@ function gen() { } exports.createClient = createClient; -//# sourceMappingURL=client.js.map ", ] `; @@ -227,7 +225,6 @@ async function wait() {} exports.spy = spy; exports.wait = wait; -//# sourceMappingURL=test.js.map ", ] `; @@ -301,7 +298,6 @@ Array [ return new Client(); } }); -//# sourceMappingURL=client.js.map ", ] `; @@ -491,7 +487,6 @@ var wait = function wait() { }; export { run, wait }; -//# sourceMappingURL=index-browser-current-esm.js.map ", ] `; @@ -516,7 +511,6 @@ async function run() { } export { run, wait }; -//# sourceMappingURL=index-browser-experimental-esm.js.map ", ] `; @@ -569,7 +563,6 @@ var wait = function wait() { }; export { run, wait }; -//# sourceMappingURL=index-browser-legacy-esm.js.map ", ] `; @@ -622,7 +615,6 @@ var wait = function wait() { }; export { run, wait }; -//# sourceMappingURL=index-browser-stable-esm.js.map ", ] `; @@ -681,7 +673,6 @@ Object.defineProperty(exports, '__esModule', { }); exports.run = run; exports.wait = wait; -//# sourceMappingURL=index-browser-current-lib.js.map ", ] `; @@ -713,7 +704,6 @@ async function run() { exports.run = run; exports.wait = wait; -//# sourceMappingURL=index-browser-experimental-lib.js.map ", ] `; @@ -772,7 +762,6 @@ Object.defineProperty(exports, '__esModule', { }); exports.run = run; exports.wait = wait; -//# sourceMappingURL=index-browser-legacy-lib.js.map ", ] `; @@ -831,7 +820,6 @@ Object.defineProperty(exports, '__esModule', { }); exports.run = run; exports.wait = wait; -//# sourceMappingURL=index-browser-stable-lib.js.map ", ] `; @@ -884,7 +872,6 @@ Object.defineProperty(exports, '__esModule', { }); exports.run = run; exports.wait = wait; -//# sourceMappingURL=index-native-current-lib.js.map ", ] `; @@ -916,7 +903,6 @@ async function run() { exports.run = run; exports.wait = wait; -//# sourceMappingURL=index-native-experimental-lib.js.map ", ] `; @@ -975,7 +961,6 @@ Object.defineProperty(exports, '__esModule', { }); exports.run = run; exports.wait = wait; -//# sourceMappingURL=index-native-legacy-lib.js.map ", ] `; @@ -1028,7 +1013,6 @@ Object.defineProperty(exports, '__esModule', { }); exports.run = run; exports.wait = wait; -//# sourceMappingURL=index-native-stable-lib.js.map ", ] `; @@ -1333,7 +1317,6 @@ Array [ _exports.wait = wait; }); -//# sourceMappingURL=index-browser-current-umd.js.map ", ] `; @@ -1378,7 +1361,6 @@ Array [ } } }); -//# sourceMappingURL=index-browser-experimental-umd.js.map ", ] `; @@ -1454,7 +1436,6 @@ Array [ _exports.wait = wait; }); -//# sourceMappingURL=index-browser-legacy-umd.js.map ", ] `; @@ -1530,7 +1511,6 @@ Array [ _exports.wait = wait; }); -//# sourceMappingURL=index-browser-stable-umd.js.map ", ] `; @@ -1679,7 +1659,6 @@ function runGen() { } export { gen, runGen }; -//# sourceMappingURL=index-browser-current-esm.js.map ", ] `; @@ -1698,7 +1677,6 @@ function runGen() { } export { gen, runGen }; -//# sourceMappingURL=index-browser-experimental-esm.js.map ", ] `; @@ -1747,7 +1725,6 @@ function runGen() { } export { gen, runGen }; -//# sourceMappingURL=index-browser-legacy-esm.js.map ", ] `; @@ -1796,7 +1773,6 @@ function runGen() { } export { gen, runGen }; -//# sourceMappingURL=index-browser-stable-esm.js.map ", ] `; @@ -1852,7 +1828,6 @@ function runGen() { exports.gen = gen; exports.runGen = runGen; -//# sourceMappingURL=index-browser-current-lib.js.map ", ] `; @@ -1878,7 +1853,6 @@ function runGen() { exports.gen = gen; exports.runGen = runGen; -//# sourceMappingURL=index-browser-experimental-lib.js.map ", ] `; @@ -1934,7 +1908,6 @@ function runGen() { exports.gen = gen; exports.runGen = runGen; -//# sourceMappingURL=index-browser-legacy-lib.js.map ", ] `; @@ -1990,7 +1963,6 @@ function runGen() { exports.gen = gen; exports.runGen = runGen; -//# sourceMappingURL=index-browser-stable-lib.js.map ", ] `; @@ -2016,7 +1988,6 @@ function runGen() { exports.gen = gen; exports.runGen = runGen; -//# sourceMappingURL=index-native-current-lib.js.map ", ] `; @@ -2042,7 +2013,6 @@ function runGen() { exports.gen = gen; exports.runGen = runGen; -//# sourceMappingURL=index-native-experimental-lib.js.map ", ] `; @@ -2098,7 +2068,6 @@ function runGen() { exports.gen = gen; exports.runGen = runGen; -//# sourceMappingURL=index-native-legacy-lib.js.map ", ] `; @@ -2124,7 +2093,6 @@ function runGen() { exports.gen = gen; exports.runGen = runGen; -//# sourceMappingURL=index-native-stable-lib.js.map ", ] `; @@ -2375,7 +2343,6 @@ Array [ } } }); -//# sourceMappingURL=index-browser-current-umd.js.map ", ] `; @@ -2414,7 +2381,6 @@ Array [ } } }); -//# sourceMappingURL=index-browser-experimental-umd.js.map ", ] `; @@ -2484,7 +2450,6 @@ Array [ } } }); -//# sourceMappingURL=index-browser-legacy-umd.js.map ", ] `; @@ -2554,7 +2519,6 @@ Array [ } } }); -//# sourceMappingURL=index-browser-stable-umd.js.map ", ] `; @@ -3439,7 +3403,6 @@ var Example = /*#__PURE__*/function (_EventEmitter) { }(EventEmitter); export { Example, emitter, test }; -//# sourceMappingURL=index-browser-current-esm.js.map ", ] `; @@ -4120,7 +4083,6 @@ class Example extends EventEmitter { } export { Example, emitter, test }; -//# sourceMappingURL=index-browser-experimental-esm.js.map ", ] `; @@ -4853,7 +4815,6 @@ var Example = /*#__PURE__*/function (_EventEmitter) { }(EventEmitter); export { Example, emitter, test }; -//# sourceMappingURL=index-browser-legacy-esm.js.map ", ] `; @@ -5586,7 +5547,6 @@ var Example = /*#__PURE__*/function (_EventEmitter) { }(EventEmitter); export { Example, emitter, test }; -//# sourceMappingURL=index-browser-stable-esm.js.map ", ] `; @@ -6326,7 +6286,6 @@ var Example = /*#__PURE__*/function (_EventEmitter) { exports.Example = Example; exports.emitter = emitter; exports.test = test; -//# sourceMappingURL=index-browser-current-lib.js.map ", ] `; @@ -7014,7 +6973,6 @@ class Example extends EventEmitter { exports.Example = Example; exports.emitter = emitter; exports.test = test; -//# sourceMappingURL=index-browser-experimental-lib.js.map ", ] `; @@ -7754,7 +7712,6 @@ var Example = /*#__PURE__*/function (_EventEmitter) { exports.Example = Example; exports.emitter = emitter; exports.test = test; -//# sourceMappingURL=index-browser-legacy-lib.js.map ", ] `; @@ -8494,7 +8451,6 @@ var Example = /*#__PURE__*/function (_EventEmitter) { exports.Example = Example; exports.emitter = emitter; exports.test = test; -//# sourceMappingURL=index-browser-stable-lib.js.map ", ] `; @@ -9182,7 +9138,6 @@ class Example extends EventEmitter { exports.Example = Example; exports.emitter = emitter; exports.test = test; -//# sourceMappingURL=index-native-current-lib.js.map ", ] `; @@ -9870,7 +9825,6 @@ class Example extends EventEmitter { exports.Example = Example; exports.emitter = emitter; exports.test = test; -//# sourceMappingURL=index-native-experimental-lib.js.map ", ] `; @@ -10610,7 +10564,6 @@ var Example = /*#__PURE__*/function (_EventEmitter) { exports.Example = Example; exports.emitter = emitter; exports.test = test; -//# sourceMappingURL=index-native-legacy-lib.js.map ", ] `; @@ -11298,7 +11251,6 @@ class Example extends EventEmitter { exports.Example = Example; exports.emitter = emitter; exports.test = test; -//# sourceMappingURL=index-native-stable-lib.js.map ", ] `; @@ -12295,7 +12247,6 @@ Array [ _exports.Example = Example; }); -//# sourceMappingURL=index-browser-current-umd.js.map ", ] `; @@ -12999,7 +12950,6 @@ Array [ _exports.Example = Example; }); -//# sourceMappingURL=index-browser-experimental-umd.js.map ", ] `; @@ -13755,7 +13705,6 @@ Array [ _exports.Example = Example; }); -//# sourceMappingURL=index-browser-legacy-umd.js.map ", ] `; @@ -14511,7 +14460,6 @@ Array [ _exports.Example = Example; }); -//# sourceMappingURL=index-browser-stable-umd.js.map ", ] `; diff --git a/tests/rollup/config.test.ts b/tests/rollup/config.test.ts index 90997bcb2..a04453b03 100644 --- a/tests/rollup/config.test.ts +++ b/tests/rollup/config.test.ts @@ -140,7 +140,7 @@ describe('getRollupConfig()', () => { paths: {}, plugins: [`babelOutput(${fixturePath}, *)`], preferConst: false, - sourcemap: true, + sourcemap: false, sourcemapExcludeSources: true, }, { @@ -154,7 +154,7 @@ describe('getRollupConfig()', () => { paths: {}, plugins: [`babelOutput(${fixturePath}, *)`], preferConst: true, - sourcemap: true, + sourcemap: false, sourcemapExcludeSources: true, }, { @@ -593,8 +593,9 @@ describe('getRollupOutputConfig()', () => { }); describe('sourcemaps', () => { - it('enables when platform is `browser`', () => { + it('enables when artifact `sourceMaps` is true', () => { artifact.platform = 'browser'; + artifact.sourceMaps = true; expect( getRollupOutputConfig( @@ -610,18 +611,15 @@ describe('getRollupOutputConfig()', () => { ); }); - it('enables when platform is `native`', () => { - artifact.platform = 'native'; + it('disables when artifact `sourceMaps` is false', () => { + artifact.platform = 'node'; + artifact.sourceMaps = false; expect( - getRollupOutputConfig( - artifact, - {}, - { format: 'lib', platform: 'native', support: 'stable' }, - ), + getRollupOutputConfig(artifact, {}, { format: 'lib', platform: 'node', support: 'stable' }), ).toEqual( expect.objectContaining({ - sourcemap: true, + sourcemap: false, sourcemapExcludeSources: true, }), ); @@ -641,17 +639,6 @@ describe('getRollupOutputConfig()', () => { }), ); }); - - it('disables when platform is `node`', () => { - expect( - getRollupOutputConfig(artifact, {}, { format: 'lib', platform: 'node', support: 'stable' }), - ).toEqual( - expect.objectContaining({ - sourcemap: false, - sourcemapExcludeSources: true, - }), - ); - }); }); it('passes `namespace` to Babel as UMD name', () => { @@ -676,7 +663,7 @@ describe('getRollupOutputConfig()', () => { paths: {}, plugins: [`babelOutput(${fixturePath}, FooBar)`], preferConst: true, - sourcemap: true, + sourcemap: false, sourcemapExcludeSources: true, }); }); From b921408b1650ba4292c6b577364005cdbc327515 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 16 Feb 2021 10:52:39 -0800 Subject: [PATCH 3/4] Add source map tests. --- tests/__fixtures__/examples/source-maps.ts | 1 + tests/__snapshots__/outputs.test.ts.snap | 305 +++++++++++++++++++++ tests/outputs.test.ts | 2 + 3 files changed, 308 insertions(+) create mode 100644 tests/__fixtures__/examples/source-maps.ts diff --git a/tests/__fixtures__/examples/source-maps.ts b/tests/__fixtures__/examples/source-maps.ts new file mode 100644 index 000000000..b0400ee9b --- /dev/null +++ b/tests/__fixtures__/examples/source-maps.ts @@ -0,0 +1 @@ +function foo() {} diff --git a/tests/__snapshots__/outputs.test.ts.snap b/tests/__snapshots__/outputs.test.ts.snap index 27277f5fb..3b65cd1ae 100644 --- a/tests/__snapshots__/outputs.test.ts.snap +++ b/tests/__snapshots__/outputs.test.ts.snap @@ -14463,3 +14463,308 @@ Array [ ", ] `; + +exports[`Outputs transforms for case: Source maps 1`] = ` +Array [ + "/cjs/index-node-current-cjs.cjs", + "// Generated with Packemon: https://packemon.dev +// Platform: node, Support: current, Format: cjs +'use strict'; +//# sourceMappingURL=index-node-current-cjs.cjs.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 2`] = ` +Array [ + "/cjs/index-node-experimental-cjs.cjs", + "// Generated with Packemon: https://packemon.dev +// Platform: node, Support: experimental, Format: cjs +'use strict'; +//# sourceMappingURL=index-node-experimental-cjs.cjs.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 3`] = ` +Array [ + "/cjs/index-node-legacy-cjs.cjs", + "// Generated with Packemon: https://packemon.dev +// Platform: node, Support: legacy, Format: cjs +'use strict'; +//# sourceMappingURL=index-node-legacy-cjs.cjs.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 4`] = ` +Array [ + "/cjs/index-node-stable-cjs.cjs", + "// Generated with Packemon: https://packemon.dev +// Platform: node, Support: stable, Format: cjs +'use strict'; +//# sourceMappingURL=index-node-stable-cjs.cjs.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 5`] = ` +Array [ + "/esm/index-browser-current-esm.js", + "// Generated with Packemon: https://packemon.dev +// Platform: browser, Support: current, Format: esm +//# sourceMappingURL=index-browser-current-esm.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 6`] = ` +Array [ + "/esm/index-browser-experimental-esm.js", + "// Generated with Packemon: https://packemon.dev +// Platform: browser, Support: experimental, Format: esm +//# sourceMappingURL=index-browser-experimental-esm.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 7`] = ` +Array [ + "/esm/index-browser-legacy-esm.js", + "// Generated with Packemon: https://packemon.dev +// Platform: browser, Support: legacy, Format: esm +//# sourceMappingURL=index-browser-legacy-esm.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 8`] = ` +Array [ + "/esm/index-browser-stable-esm.js", + "// Generated with Packemon: https://packemon.dev +// Platform: browser, Support: stable, Format: esm +//# sourceMappingURL=index-browser-stable-esm.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 9`] = ` +Array [ + "/lib/index-browser-current-lib.js", + "// Generated with Packemon: https://packemon.dev +// Platform: browser, Support: current, Format: lib +'use strict'; +//# sourceMappingURL=index-browser-current-lib.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 10`] = ` +Array [ + "/lib/index-browser-experimental-lib.js", + "// Generated with Packemon: https://packemon.dev +// Platform: browser, Support: experimental, Format: lib +'use strict'; +//# sourceMappingURL=index-browser-experimental-lib.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 11`] = ` +Array [ + "/lib/index-browser-legacy-lib.js", + "// Generated with Packemon: https://packemon.dev +// Platform: browser, Support: legacy, Format: lib +'use strict'; +//# sourceMappingURL=index-browser-legacy-lib.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 12`] = ` +Array [ + "/lib/index-browser-stable-lib.js", + "// Generated with Packemon: https://packemon.dev +// Platform: browser, Support: stable, Format: lib +'use strict'; +//# sourceMappingURL=index-browser-stable-lib.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 13`] = ` +Array [ + "/lib/index-native-current-lib.js", + "// Generated with Packemon: https://packemon.dev +// Platform: native, Support: current, Format: lib +'use strict'; +//# sourceMappingURL=index-native-current-lib.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 14`] = ` +Array [ + "/lib/index-native-experimental-lib.js", + "// Generated with Packemon: https://packemon.dev +// Platform: native, Support: experimental, Format: lib +'use strict'; +//# sourceMappingURL=index-native-experimental-lib.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 15`] = ` +Array [ + "/lib/index-native-legacy-lib.js", + "// Generated with Packemon: https://packemon.dev +// Platform: native, Support: legacy, Format: lib +'use strict'; +//# sourceMappingURL=index-native-legacy-lib.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 16`] = ` +Array [ + "/lib/index-native-stable-lib.js", + "// Generated with Packemon: https://packemon.dev +// Platform: native, Support: stable, Format: lib +'use strict'; +//# sourceMappingURL=index-native-stable-lib.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 17`] = ` +Array [ + "/lib/index-node-current-lib.js", + "// Generated with Packemon: https://packemon.dev +// Platform: node, Support: current, Format: lib +'use strict'; +//# sourceMappingURL=index-node-current-lib.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 18`] = ` +Array [ + "/lib/index-node-experimental-lib.js", + "// Generated with Packemon: https://packemon.dev +// Platform: node, Support: experimental, Format: lib +'use strict'; +//# sourceMappingURL=index-node-experimental-lib.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 19`] = ` +Array [ + "/lib/index-node-legacy-lib.js", + "// Generated with Packemon: https://packemon.dev +// Platform: node, Support: legacy, Format: lib +'use strict'; +//# sourceMappingURL=index-node-legacy-lib.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 20`] = ` +Array [ + "/lib/index-node-stable-lib.js", + "// Generated with Packemon: https://packemon.dev +// Platform: node, Support: stable, Format: lib +'use strict'; +//# sourceMappingURL=index-node-stable-lib.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 21`] = ` +Array [ + "/mjs/index-node-current-mjs.mjs", + "// Generated with Packemon: https://packemon.dev +// Platform: node, Support: current, Format: mjs +//# sourceMappingURL=index-node-current-mjs.mjs.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 22`] = ` +Array [ + "/mjs/index-node-experimental-mjs.mjs", + "// Generated with Packemon: https://packemon.dev +// Platform: node, Support: experimental, Format: mjs +//# sourceMappingURL=index-node-experimental-mjs.mjs.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 23`] = ` +Array [ + "/mjs/index-node-legacy-mjs.mjs", + "// Generated with Packemon: https://packemon.dev +// Platform: node, Support: legacy, Format: mjs +//# sourceMappingURL=index-node-legacy-mjs.mjs.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 24`] = ` +Array [ + "/mjs/index-node-stable-mjs.mjs", + "// Generated with Packemon: https://packemon.dev +// Platform: node, Support: stable, Format: mjs +//# sourceMappingURL=index-node-stable-mjs.mjs.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 25`] = ` +Array [ + "/package.json", + Object { + "name": "examples", + }, +] +`; + +exports[`Outputs transforms for case: Source maps 26`] = ` +Array [ + "/umd/index-browser-current-umd.js", + "// Generated with Packemon: https://packemon.dev +// Platform: browser, Support: current, Format: umd +//# sourceMappingURL=index-browser-current-umd.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 27`] = ` +Array [ + "/umd/index-browser-experimental-umd.js", + "// Generated with Packemon: https://packemon.dev +// Platform: browser, Support: experimental, Format: umd +//# sourceMappingURL=index-browser-experimental-umd.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 28`] = ` +Array [ + "/umd/index-browser-legacy-umd.js", + "// Generated with Packemon: https://packemon.dev +// Platform: browser, Support: legacy, Format: umd +//# sourceMappingURL=index-browser-legacy-umd.js.map +", +] +`; + +exports[`Outputs transforms for case: Source maps 29`] = ` +Array [ + "/umd/index-browser-stable-umd.js", + "// Generated with Packemon: https://packemon.dev +// Platform: browser, Support: stable, Format: umd +//# sourceMappingURL=index-browser-stable-umd.js.map +", +] +`; diff --git a/tests/outputs.test.ts b/tests/outputs.test.ts index 62a865e64..b7028b8db 100644 --- a/tests/outputs.test.ts +++ b/tests/outputs.test.ts @@ -117,6 +117,7 @@ describe('Outputs', () => { 'async-await.ts': 'Async/Await', 'generators.ts': 'Generators', 'node-polyfills.ts': 'Node polyfills', + 'source-maps.ts': 'Source maps', }; FORMATS.forEach((format) => { @@ -156,6 +157,7 @@ describe('Outputs', () => { artifact.support = build.support; artifact.outputName = `index-${build.platform}-${build.support}-${build.format}`; artifact.inputFile = file; + artifact.sourceMaps = file === 'source-maps.ts'; pkg.addArtifact(artifact); }); From bf875d01bf7042027d0bc95f6004e8743e4a9329 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 16 Feb 2021 10:57:04 -0800 Subject: [PATCH 4/4] Update docs. --- website/docs/build.md | 2 +- website/docs/config.md | 11 +++++++++++ website/docs/index.md | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/website/docs/build.md b/website/docs/build.md index dd120f29d..03633d01e 100644 --- a/website/docs/build.md +++ b/website/docs/build.md @@ -219,7 +219,7 @@ The following plugins are enabled per package. - Parses and transforms source code using Babel. - Excludes test related files from transformation. - Inlines runtime helpers in the output file. - - Generates source maps (browser only). + - Generates source maps if `sourceMaps` is true. - `rollup-plugin-node-externals` - Defines `externals` based on `package.json` dependencies. - Includes `dependencies`, `devDependencies`, `peerDependencies`, and `optionalDependencies`. diff --git a/website/docs/config.md b/website/docs/config.md index 560af967f..26627a849 100644 --- a/website/docs/config.md +++ b/website/docs/config.md @@ -29,6 +29,7 @@ with caution. { "inputs": { "web": "src/web.ts" }, "platform": "browser", + "sourceMaps": true, "support": "current" }, { @@ -160,6 +161,16 @@ need to configure this. > These inputs can be automatically mapped to `package.json` `exports` using the `--addExports` CLI > option. Do note that this feature is still experimental. +## Source maps + +Enable source map generation for all formats within the current configuration block. + +```json +{ + "sourceMaps": true +} +``` + ## Namespace For browsers only, this would be the name of the UMD global variable. diff --git a/website/docs/index.md b/website/docs/index.md index 0c723a46d..4cd2d7005 100644 --- a/website/docs/index.md +++ b/website/docs/index.md @@ -20,7 +20,7 @@ provide sane defaults and configurations, verify package requirements, and much - Transforms packages with Babel's `preset-env` and the configured platform targets. Only ship and polyfill what's truly necessary! - Generate and combine TypeScript declarations into a single public-only API representation. -- Generates compact source maps for browser based builds. +- Generates compact source maps for platform + format based builds. ## Requirements