diff --git a/packages/core/integration-tests/package.json b/packages/core/integration-tests/package.json index 46bcda355a63..7c436a52e559 100644 --- a/packages/core/integration-tests/package.json +++ b/packages/core/integration-tests/package.json @@ -54,6 +54,7 @@ "sugarss": "^3.0.3", "tailwindcss": "^3.0.2", "tempy": "^0.3.0", + "wasm-sourcemap": "^1.0.0", "ws": "^7.0.0" } } diff --git a/packages/core/integration-tests/test/integration/resolver-can-invalidateonenvchange/node_modules/parcel-resolver-can-invalidateonenvchange/index.js b/packages/core/integration-tests/test/integration/resolver-can-invalidateonenvchange/node_modules/parcel-resolver-can-invalidateonenvchange/index.js index ade8fcd2fd78..efe8416bcde3 100644 --- a/packages/core/integration-tests/test/integration/resolver-can-invalidateonenvchange/node_modules/parcel-resolver-can-invalidateonenvchange/index.js +++ b/packages/core/integration-tests/test/integration/resolver-can-invalidateonenvchange/node_modules/parcel-resolver-can-invalidateonenvchange/index.js @@ -1,5 +1,3 @@ -// @flow - const {Resolver} = require('@parcel/plugin'); const path = require('path'); const {default: NodeResolver} = require('@parcel/node-resolver-core'); diff --git a/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/.parcelrc b/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/.parcelrc new file mode 100644 index 000000000000..cf3e04cadc49 --- /dev/null +++ b/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/.parcelrc @@ -0,0 +1,6 @@ +{ + "extends": "@parcel/config-default", + "transformers": { + "*.wasm": ["parcel-transformer-test"] + } +} diff --git a/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/index.js b/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/index.js new file mode 100644 index 000000000000..4c76c2639d5d --- /dev/null +++ b/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/index.js @@ -0,0 +1 @@ +console.log(new URL("index.wasm", import.meta.url)) diff --git a/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/index.wasm b/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/index.wasm new file mode 100644 index 000000000000..15e682fb0cba Binary files /dev/null and b/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/index.wasm differ diff --git a/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/node_modules/parcel-transformer-test/index.js b/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/node_modules/parcel-transformer-test/index.js new file mode 100644 index 000000000000..4b94395d9d6c --- /dev/null +++ b/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/node_modules/parcel-transformer-test/index.js @@ -0,0 +1,16 @@ +const {Transformer} = require('@parcel/plugin'); +const {default: SourceMap} = require('@parcel/source-map'); + +module.exports = new Transformer({ + transform({asset, options}) { + let map = SourceMap.generateEmptyMap({ + projectRoot: options.projectRoot, + sourceName: 'index.as.ts', + sourceContent: `export function add(a : i32, b : i32): i32 { + return b + a +}`, + }); + asset.setMap(map); + return [asset]; + }, +}); diff --git a/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/node_modules/parcel-transformer-test/package.json b/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/node_modules/parcel-transformer-test/package.json new file mode 100644 index 000000000000..17b6afe6dc05 --- /dev/null +++ b/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/node_modules/parcel-transformer-test/package.json @@ -0,0 +1,4 @@ +{ + "name": "parcel-transformer-test", + "version": "1.0.0" +} diff --git a/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/yarn.lock b/packages/core/integration-tests/test/integration/wasm-sourcemap-transformer/yarn.lock new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/core/integration-tests/test/plugin.js b/packages/core/integration-tests/test/plugin.js index 9dd9731ab335..dfd4f97f7374 100644 --- a/packages/core/integration-tests/test/plugin.js +++ b/packages/core/integration-tests/test/plugin.js @@ -15,6 +15,8 @@ import { overlayFS, run, } from '@parcel/test-utils'; +import * as wasmmap from 'wasm-sourcemap'; +import {relativePath} from '@parcel/utils'; describe('plugin', function () { it("continue transformer pipeline on type change that doesn't change the pipeline", async function () { @@ -310,4 +312,21 @@ parcel-transformer-b`, await assertAsset('const replaced = 1;'); await assertAsset('const replaced = 2;'); }); + + it('should output sourcemaps when packaging Wasm', async () => { + let b = await bundle( + path.join(__dirname, '/integration/wasm-sourcemap-transformer/index.js'), + ); + let wasmPath = nullthrows( + b.getBundles().find(b => b.type === 'wasm'), + ).filePath; + let mapPath = wasmPath + '.map'; + assert(await fs.exists(mapPath)); + + let wasm = await fs.readFile(wasmPath); + assert.equal( + wasmmap.GetSourceMapURL(wasm), + relativePath(distDir, mapPath, false), + ); + }); }); diff --git a/yarn.lock b/yarn.lock index 93093d29c9b9..299148ecc622 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14120,6 +14120,11 @@ w3c-xmlserializer@^3.0.0: dependencies: xml-name-validator "^4.0.0" +wasm-sourcemap@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/wasm-sourcemap/-/wasm-sourcemap-1.0.0.tgz#c9aa3a2105eb2f15b838687b5aebeac4e0c9a07c" + integrity sha512-IiOoUHnsI6bVVbs8Q+JO6cj7KtxwGiiS5nJGDbZXfj6srbIDzjjbZk9WMAusvynTzzlPlMgJhb/4SGz92ZgXsA== + wcwidth@^1.0.0, wcwidth@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8"