diff --git a/lib/emit.generated.js b/lib/emit.generated.js index a9a510c..335129b 100644 --- a/lib/emit.generated.js +++ b/lib/emit.generated.js @@ -202,7 +202,7 @@ function makeMutClosure(arg0, arg1, dtor, f) { } function __wbg_adapter_16(arg0, arg1, arg2) { wasm - ._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hc399077d245373c2( + ._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2eb231fdb129de9b( arg0, arg1, addHeapObject(arg2), @@ -283,7 +283,7 @@ function handleError(f, args) { } } function __wbg_adapter_25(arg0, arg1, arg2, arg3) { - wasm.wasm_bindgen__convert__closures__invoke2_mut__h3cf9829b75bbfd88( + wasm.wasm_bindgen__convert__closures__invoke2_mut__h0edd3e8b1a7686ec( arg0, arg1, addHeapObject(arg2), @@ -389,8 +389,8 @@ const imports = { __wbindgen_throw: function (arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); }, - __wbindgen_closure_wrapper422: function (arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 144, __wbg_adapter_16); + __wbindgen_closure_wrapper423: function (arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 138, __wbg_adapter_16); return addHeapObject(ret); }, }, diff --git a/lib/emit_bg.wasm b/lib/emit_bg.wasm index 59982a1..3a3b1d2 100644 Binary files a/lib/emit_bg.wasm and b/lib/emit_bg.wasm differ diff --git a/mod.ts b/mod.ts index 225718a..ff2ac13 100644 --- a/mod.ts +++ b/mod.ts @@ -146,6 +146,8 @@ export async function bundle( cacheSetting, cacheRoot, allowRemote, + type, + compilerOptions, } = options; let bundleLoad = load; if (!bundleLoad) { @@ -154,13 +156,17 @@ export async function bundle( } root = root instanceof URL ? root : toFileUrl(resolve(root)); const { bundle: jsBundle } = await instantiate(); - return jsBundle( + const result = await jsBundle( root.toString(), bundleLoad, - JSON.stringify(imports), - undefined, - undefined, + type, + imports, + compilerOptions, ); + return { + code: result.code, + map: result.maybe_map ?? undefined, + }; } /** Transpile TypeScript (or JavaScript) into JavaScript, returning a promise diff --git a/tests/__snapshots__/bundle/inline_source_maps_are_enabled_by_default.js b/tests/__snapshots__/bundle/inline_source_maps_are_enabled_by_default.js new file mode 100644 index 0000000..2f81635 --- /dev/null +++ b/tests/__snapshots__/bundle/inline_source_maps_are_enabled_by_default.js @@ -0,0 +1,5 @@ +function hello() { + return "Hello there!"; +} +export { hello as default }; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZpbGU6Ly8vdGVzdGRhdGEvbW9kLnRzIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IGZ1bmN0aW9uIGhlbGxvKCk6IHN0cmluZyB7XG4gIHJldHVybiBcIkhlbGxvIHRoZXJlIVwiO1xufVxuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFlLFNBQVMsUUFBZ0I7SUFDdEMsT0FBTztBQUNUO0FBRkEsNEJBRUMifQ== diff --git a/tests/__snapshots__/bundle/setting_inlinesourcemap_does_not_produce_any_source_maps.js b/tests/__snapshots__/bundle/setting_inlinesourcemap_does_not_produce_any_source_maps.js new file mode 100644 index 0000000..5266bfa --- /dev/null +++ b/tests/__snapshots__/bundle/setting_inlinesourcemap_does_not_produce_any_source_maps.js @@ -0,0 +1,4 @@ +function hello() { + return "Hello there!"; +} +export { hello as default }; diff --git a/tests/__snapshots__/bundle/setting_inlinesourcemap_to_true_produces_inline_source_maps.js b/tests/__snapshots__/bundle/setting_inlinesourcemap_to_true_produces_inline_source_maps.js new file mode 100644 index 0000000..2f81635 --- /dev/null +++ b/tests/__snapshots__/bundle/setting_inlinesourcemap_to_true_produces_inline_source_maps.js @@ -0,0 +1,5 @@ +function hello() { + return "Hello there!"; +} +export { hello as default }; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZpbGU6Ly8vdGVzdGRhdGEvbW9kLnRzIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBkZWZhdWx0IGZ1bmN0aW9uIGhlbGxvKCk6IHN0cmluZyB7XG4gIHJldHVybiBcIkhlbGxvIHRoZXJlIVwiO1xufVxuIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFlLFNBQVMsUUFBZ0I7SUFDdEMsT0FBTztBQUNUO0FBRkEsNEJBRUMifQ== diff --git a/tests/__snapshots__/bundle/setting_sourcemap_to_true_and_inlinesourcemap_to_false_produces_external_source_maps.js b/tests/__snapshots__/bundle/setting_sourcemap_to_true_and_inlinesourcemap_to_false_produces_external_source_maps.js new file mode 100644 index 0000000..5266bfa --- /dev/null +++ b/tests/__snapshots__/bundle/setting_sourcemap_to_true_and_inlinesourcemap_to_false_produces_external_source_maps.js @@ -0,0 +1,4 @@ +function hello() { + return "Hello there!"; +} +export { hello as default }; diff --git a/tests/__snapshots__/bundle/setting_sourcemap_to_true_and_inlinesourcemap_to_false_produces_external_source_maps.js.map b/tests/__snapshots__/bundle/setting_sourcemap_to_true_and_inlinesourcemap_to_false_produces_external_source_maps.js.map new file mode 100644 index 0000000..9833742 --- /dev/null +++ b/tests/__snapshots__/bundle/setting_sourcemap_to_true_and_inlinesourcemap_to_false_produces_external_source_maps.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["file:///testdata/mod.ts"],"sourcesContent":["export default function hello(): string {\n return \"Hello there!\";\n}\n"],"names":[],"mappings":"AAAe,SAAS,QAAgB;IACtC,OAAO;AACT;AAFA,4BAEC"} \ No newline at end of file diff --git a/tests/__snapshots__/bundle/setting_sourcemap_to_true_is_not_enough_to_produce_external_source_maps_as_inline_takes_precedence.js b/tests/__snapshots__/bundle/setting_sourcemap_to_true_is_not_enough_to_produce_external_source_maps_as_inline_takes_precedence.js new file mode 100644 index 0000000..5266bfa --- /dev/null +++ b/tests/__snapshots__/bundle/setting_sourcemap_to_true_is_not_enough_to_produce_external_source_maps_as_inline_takes_precedence.js @@ -0,0 +1,4 @@ +function hello() { + return "Hello there!"; +} +export { hello as default }; diff --git a/tests/bundle_test.ts b/tests/bundle_test.ts index 00b2c38..051b906 100644 --- a/tests/bundle_test.ts +++ b/tests/bundle_test.ts @@ -1,5 +1,10 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. -import { assertStringIncludes } from "https://deno.land/std@0.182.0/testing/asserts.ts"; +import { + assert, + assertEquals, + assertExists, + assertStringIncludes, +} from "https://deno.land/std@0.182.0/testing/asserts.ts"; import { resolveFixture, testBundle } from "./utils.ts"; // FIXME: This repeats the test below. Consider supporting URLs without wrapping @@ -53,3 +58,82 @@ Deno.test({ ); }), }); + +Deno.test({ + name: "inline source maps are enabled by default", + fn: testBundle(resolveFixture("mod.ts"), undefined, ({ result }) => { + assertEquals(result.map, undefined); + assert( + result.code.split("\n").at(-2)?.startsWith( + "//# sourceMappingURL=data:application/json;base64,", + ), + ); + }), +}); + +Deno.test({ + name: "setting inlineSourceMap to true produces inline source maps", + fn: testBundle(resolveFixture("mod.ts"), { + compilerOptions: { + inlineSourceMap: true, + }, + }, ({ result }) => { + assertEquals(result.map, undefined); + assert( + result.code.split("\n").at(-2)?.startsWith( + "//# sourceMappingURL=data:application/json;base64,", + ), + ); + }), +}); + +Deno.test({ + name: "setting inlineSourceMap does not produce any source maps", + fn: testBundle(resolveFixture("mod.ts"), { + compilerOptions: { + inlineSourceMap: false, + }, + }, ({ result }) => { + assertEquals(result.map, undefined); + assert( + !result.code.includes( + "//# sourceMappingURL=data:application/json;base64,", + ), + ); + }), +}); + +Deno.test({ + name: + "setting sourceMap to true is not enough to produce external source maps as inline takes precedence", + fn: testBundle(resolveFixture("mod.ts"), { + compilerOptions: { + inlineSourceMap: false, + }, + }, ({ result }) => { + assertEquals(result.map, undefined); + assert( + !result.code.includes( + "//# sourceMappingURL=data:application/json;base64,", + ), + ); + }), +}); + +Deno.test({ + name: + "setting sourceMap to true and inlineSourceMap to false produces external source maps", + fn: testBundle(resolveFixture("mod.ts"), { + compilerOptions: { + sourceMap: true, + inlineSourceMap: false, + }, + }, ({ result }) => { + assertExists(result.map); + assert( + !result.code.includes( + "//# sourceMappingURL=data:application/json;base64,", + ), + ); + }), +});