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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
extends: ["prettier"],

parserOptions: {
ecmaVersion: 9,
ecmaVersion: 2020,
},

globals: {
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/cargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,43 @@ jobs:
toolchain: ${{ matrix.toolchain }}
override: true
default: true
# `override: true` sets a directory override on the repo root, but the
# nearer wasm-mappings/rust-toolchain.toml takes precedence over it, so
# select the matrix toolchain explicitly.
- run: JOB=${{ matrix.job }} ./ci/script.sh
env:
RUSTUP_TOOLCHAIN: ${{ matrix.toolchain }}

dist:
name: WASM binary is reproducible
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# No toolchain override here on purpose: the build must use the version
# pinned in wasm-mappings/rust-toolchain.toml for the byte comparison
# to be meaningful.
# wasm-pack vendors its own wasm-bindgen; wasm-opt must be the binaryen
# version build.sh pins, since wasm-pack's fallback download is older
# and produces different bytes.
- name: Install wasm-pack
env:
WASM_PACK_VERSION: v0.15.0
WASM_PACK_SHA256: c09f971ecaed9a2efc80fdcea7a00ef6b53c7fadc8c57d1f61b53a6aa66b668a
run: |
name="wasm-pack-${WASM_PACK_VERSION}-x86_64-unknown-linux-musl"
curl -sSfL -o "$RUNNER_TEMP/wasm-pack.tar.gz" \
"https://github.com/rustwasm/wasm-pack/releases/download/${WASM_PACK_VERSION}/${name}.tar.gz"
echo "${WASM_PACK_SHA256} $RUNNER_TEMP/wasm-pack.tar.gz" | sha256sum -c -
tar -xzf "$RUNNER_TEMP/wasm-pack.tar.gz" -C "$RUNNER_TEMP"
echo "$RUNNER_TEMP/${name}" >> "$GITHUB_PATH"
- name: Install binaryen
env:
BINARYEN_VERSION: "132"
BINARYEN_SHA256: 195ddc94f9bc89f45abdabb0b9eea86023d727ba90eac8b35b80f2544fc30572
run: |
curl -sSfL -o "$RUNNER_TEMP/binaryen.tar.gz" \
"https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz"
echo "${BINARYEN_SHA256} $RUNNER_TEMP/binaryen.tar.gz" | sha256sum -c -
tar -xzf "$RUNNER_TEMP/binaryen.tar.gz" -C "$RUNNER_TEMP"
echo "$RUNNER_TEMP/binaryen-version_${BINARYEN_VERSION}/bin" >> "$GITHUB_PATH"
- run: JOB=wasm-dist ./ci/script.sh
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [12, 14, 16, 18]
node-version: [18, 20, 22]

steps:
- uses: actions/checkout@v3
Expand Down
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
bench/
test/source-map-tests/
coverage/
node_modules/
target/

# Generated by wasm-mappings/build.sh; reformatting would break the
# byte-for-byte check in the `wasm-dist` CI job.
lib/mappings-glue.js
lib/mappings-glue.d.ts
lib/mappings-glue-browser.mjs
lib/mappings-glue-browser.d.mts
wasm-mappings/source-map-mappings-wasm-api/pkg-node/
wasm-mappings/source-map-mappings-wasm-api/pkg-web/
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## Unreleased

- Require Node.js 18 or later. `lib/mappings.wasm` is now built with
wasm-pack and uses WebAssembly multi-value and reference types, which
older Node.js versions do not support.

## 0.8.0

- [#528] https://github.com/mozilla/source-map/pull/528
Expand Down
76 changes: 47 additions & 29 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,17 @@ If you are filing an issue for a bug or other misbehavior, please provide:

## Building From Source

Install Node.js `12` or greater and then run
Install Node.js `18` or greater and then run

$ git clone https://github.com/mozilla/source-map.git
$ cd source-map/
$ npm install

Next, run

$ npm run build

This will create the following files:

- `dist/source-map.js` - The plain browser build.
There is no build step for the JavaScript: the package is used directly from
`source-map.js` and `lib/`. The only generated files are `lib/mappings.wasm` and
its glue, which are committed; see
[Updating the `lib/mappings.wasm` WebAssembly Module](#updating-the-libmappingswasm-webassembly-module)
if you need to change them.

## Submitting Pull Requests

Expand All @@ -65,16 +63,17 @@ force push to the remote branch to update the pull request.

## Running Tests

The test suite is written for node.js. Install node.js `12` or greater and
The test suite is written for node.js. Install node.js `18` or greater and
then run the tests with `npm test`:

```shell
$ npm test
> source-map@0.7.3 test /Users/fitzgen/src/source-map
> node test/run-tests.js

> source-map@0.8.0 test
> git submodule update --init --recursive; node test/run-tests.js

137 / 137 tests passed.

190 / 190 tests passed.
```

## Writing New Tests
Expand Down Expand Up @@ -134,40 +133,59 @@ Ensure that you have the Rust toolchain installed:
$ curl https://sh.rustup.rs -sSf | sh
```

The `wasm32-unknown-unknown` target is nightly-only at the time of writing. Use
`rustup` to ensure you have it installed:
The exact toolchain version is pinned in `wasm-mappings/rust-toolchain.toml`
and `rustup` will install it on demand, including the
`wasm32-unknown-unknown` target.
Note: The pin exists because CI rebuilds the
committed artifacts and fails if they differ byte-for-byte, which only works
if everyone builds with the same compiler.

Install [`wasm-pack`](https://wasm-bindgen.github.io/wasm-pack/) version
0.15.0, the version CI uses, which vendors its own `wasm-bindgen`:

```
$ rustup toolchain install nightly
$ rustup target add wasm32-unknown-unknown --toolchain nightly
$ cargo install wasm-pack --version 0.15.0 --locked
```

Move to wasm sources folder:
You also need `wasm-opt` from [binaryen](https://github.com/WebAssembly/binaryen)
**version 132** on your `PATH` (for example `brew install binaryen`, or a
[release download](https://github.com/WebAssembly/binaryen/releases/tag/version_132)).
`build.sh` refuses to run with any other version: without one on `PATH`,
wasm-pack falls back to downloading an older binaryen, whose output does not
match the committed `lib/mappings.wasm`.

Make sure the crate's tests pass:

```
$ cd wasm-mappings/
$ cargo test
```

Make sure the crate's tests pass:
Then rebuild the shipped artifacts:

```
$ cargo test
$ ./build.sh
```

Ensure that you have the following wasm post-processing tools installed:
This writes five files into `lib/`:

- `wasm-nm`: https://github.com/fitzgen/wasm-nm
- `wasm-gc`: https://github.com/alexcrichton/wasm-gc
- `wasm-snip`: https://github.com/fitzgen/wasm-snip
- `wasm-opt`: https://github.com/WebAssembly/binaryen
| File | Purpose |
| ----------------------------- | -------------------------------------------- |
| `mappings.wasm` | the WebAssembly module itself |
| `mappings-glue.js` | `wasm-bindgen` glue for Node (CommonJS) |
| `mappings-glue.d.ts` | types for the above node glue file |
| `mappings-glue-browser.mjs` | `wasm-bindgen` glue for browsers (ES module) |
| `mappings-glue-browser.d.mts` | types for the above browser glue file |

(These dependencies should automatically be installed by cargo)
All five are generated and committed; do not edit them by hand. `package.json`'s
`browser` field swaps `lib/read-wasm.js` for `lib/read-wasm-browser.js`, which
is what selects between the Node and browser glue.

Build Rust crate as a `.wasm` file:
Set `PROFILING=1` to enable the crate's `profiling` feature, which wraps each
query in a `console.time` / `console.timeEnd` pair:

```
$ cd source-map-mappings-wasm-api/
$ ./build.py -o ../../lib/mappings.wasm
$ PROFILING=1 ./build.sh
```

See further information in [wasm-mappings/CONTRIBUTING.md].
See further information in [wasm-mappings/CONTRIBUTING.md](wasm-mappings/CONTRIBUTING.md).
4 changes: 2 additions & 2 deletions bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"build": "webpack"
},
"dependencies": {
"webpack": "^4.9.1",
"webpack-cli": "^3.1"
"webpack": "^5.0.0",
"webpack-cli": "^4.0.0"
}
}
97 changes: 97 additions & 0 deletions lib/mappings-glue-browser.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* tslint:disable */
/* eslint-disable */

/**
* A parsed `mappings` string, ready to be queried.
*
* JS owns this handle and must call `free()` on it when finished.
*/
export class Mappings {
private constructor();
free(): void;
[Symbol.dispose](): void;
/**
* Find all mappings for the given original location and invoke `cb` on
* each of them.
*
* When `has_original_column` is false, `original_column` is ignored and
* every mapping with a matching source and original line is yielded.
*/
allGeneratedLocationsFor(source: number, original_line: number, has_original_column: boolean, original_column: number, cb: any): void;
/**
* Invoke `cb` on each mapping, in order of generated location.
*/
byGeneratedLocation(cb: any): void;
/**
* Invoke `cb` on each mapping that has original location information, in
* order of original location.
*/
byOriginalLocation(cb: any): void;
/**
* Compute column spans for the mappings.
*/
computeColumnSpans(): void;
/**
* Find the mapping for the given original location, if any exists, and
* invoke `cb` with it once.
*/
generatedLocationFor(source: number, original_line: number, original_column: number, bias: number, cb: any): void;
/**
* Find the mapping for the given generated location, if any exists, and
* invoke `cb` with it once.
*/
originalLocationFor(generated_line: number, generated_column: number, bias: number, cb: any): void;
}

/**
* Parse a source map's `mappings` string.
*
* On failure, rejects with the numeric `source_map_mappings::Error` code.
* Replaces the old `allocate_mappings` / `parse_mappings` / `get_last_error`
* trio: `wasm-bindgen` copies the string into wasm memory itself, so JS no
* longer has to hand-manage a buffer.
*/
export function parseMappings(mappings: string): Mappings;

export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;

export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly __wbg_mappings_free: (a: number, b: number) => void;
readonly mappings_allGeneratedLocationsFor: (a: number, b: number, c: number, d: number, e: number, f: any) => [number, number];
readonly mappings_byGeneratedLocation: (a: number, b: any) => [number, number];
readonly mappings_byOriginalLocation: (a: number, b: any) => [number, number];
readonly mappings_computeColumnSpans: (a: number) => void;
readonly mappings_generatedLocationFor: (a: number, b: number, c: number, d: number, e: number, f: any) => [number, number];
readonly mappings_originalLocationFor: (a: number, b: number, c: number, d: number, e: any) => [number, number];
readonly parseMappings: (a: number, b: number) => [number, number, number];
readonly __wbindgen_exn_store: (a: number) => void;
readonly __externref_table_alloc: () => number;
readonly __wbindgen_externrefs: WebAssembly.Table;
readonly __externref_table_dealloc: (a: number) => void;
readonly __wbindgen_malloc: (a: number, b: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_start: () => void;
}

export type SyncInitInput = BufferSource | WebAssembly.Module;

/**
* Instantiates the given `module`, which can either be bytes or
* a precompiled `WebAssembly.Module`.
*
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
*
* @returns {InitOutput}
*/
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;

/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
*
* @returns {Promise<InitOutput>}
*/
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
Loading
Loading