New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@srcmap/remapping-wasm

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@srcmap/remapping-wasm - npm Package Compare versions

Comparing version
0.2.2
to
0.2.3
+21
web/package.json
{
"name": "srcmap-remapping-wasm",
"type": "module",
"description": "WebAssembly bindings for srcmap-remapping",
"version": "0.2.3",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/BartWaardenburg/srcmap"
},
"files": [
"srcmap_remapping_wasm_bg.wasm",
"srcmap_remapping_wasm.js",
"srcmap_remapping_wasm.d.ts"
],
"main": "srcmap_remapping_wasm.js",
"types": "srcmap_remapping_wasm.d.ts",
"sideEffects": [
"./snippets/*"
]
}
# @srcmap/remapping-wasm
[![npm](https://img.shields.io/npm/v/@srcmap/remapping-wasm.svg)](https://www.npmjs.com/package/@srcmap/remapping-wasm)
[![CI](https://github.com/BartWaardenburg/srcmap/actions/workflows/ci.yml/badge.svg)](https://github.com/BartWaardenburg/srcmap/actions/workflows/ci.yml)
High-performance source map concatenation and composition powered by Rust via WebAssembly.
**Concatenation** merges source maps from multiple bundled files into one, adjusting line offsets. **Composition** chains source maps through multiple transforms (e.g. TS -> JS -> minified) into a single map pointing to original sources. Alternative to [`@ampproject/remapping`](https://github.com/nicolo-ribaudo/source-map-js).
## Install
```bash
npm install @srcmap/remapping-wasm
```
Works in Node.js, browsers, and any WebAssembly-capable runtime. No native compilation required.
## Usage
### Concatenation
Merge source maps from multiple files into a single combined map:
```js
import { ConcatBuilder } from '@srcmap/remapping-wasm'
const builder = new ConcatBuilder('bundle.js')
// Add source maps with their line offsets in the output
builder.addMap(chunkASourceMapJson, 0) // chunk A starts at line 0
builder.addMap(chunkBSourceMapJson, 1000) // chunk B starts at line 1000
const combinedJson = builder.toJSON()
```
### Composition / Remapping
Chain source maps through a transform pipeline into a single map:
```js
import { remap } from '@srcmap/remapping-wasm'
// Your build: original.ts -> intermediate.js -> minified.js
// You have: minified.js.map (outer) and intermediate.js.map (inner)
const composedJson = remap(minifiedSourceMapJson, (source) => {
// Called for each source in the outer map
if (source === 'intermediate.js') {
return intermediateSourceMapJson // upstream source map JSON
}
return null // no upstream map, keep as-is
})
```
## API
### `new ConcatBuilder(file?: string)`
Create a builder for concatenating source maps.
| Method | Returns | Description |
|--------|---------|-------------|
| `addMap(json, lineOffset)` | `void` | Add a source map JSON at the given line offset |
| `toJSON()` | `string` | Generate the concatenated source map JSON |
### `remap(outerJson, loader)`
Compose source maps through a transform chain.
| Parameter | Type | Description |
|-----------|------|-------------|
| `outerJson` | `string` | The final-stage source map JSON |
| `loader` | `(source: string) => string \| null` | Returns upstream source map JSON, or `null` |
Returns the composed source map as a JSON string.
## Build targets
```bash
# Node.js (default)
npm run build
# Browser (ES module + .wasm)
npm run build:web
# Bundler (e.g. webpack, vite)
npm run build:bundler
```
## Part of [srcmap](https://github.com/BartWaardenburg/srcmap)
High-performance source map tooling written in Rust. See also:
- [`@srcmap/sourcemap-wasm`](https://www.npmjs.com/package/@srcmap/sourcemap-wasm) - Source map parser (WASM)
- [`@srcmap/generator-wasm`](https://www.npmjs.com/package/@srcmap/generator-wasm) - Source map generator (WASM)
- [`@srcmap/symbolicate-wasm`](https://www.npmjs.com/package/@srcmap/symbolicate-wasm) - Stack trace symbolication (WASM)
## License
MIT

Sorry, the diff of this file is not supported yet

/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export const __wbg_concatbuilder_free: (a: number, b: number) => void;
export const concatbuilder_addMap: (a: number, b: number, c: number, d: number, e: number) => void;
export const concatbuilder_new: (a: number, b: number) => number;
export const concatbuilder_toJSON: (a: number, b: number) => void;
export const remap: (a: number, b: number, c: number, d: number) => void;
export const __wbindgen_export: (a: number, b: number) => number;
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
export const __wbindgen_export3: (a: number) => void;
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
export const __wbindgen_export4: (a: number, b: number, c: number) => void;
/* tslint:disable */
/* eslint-disable */
export class ConcatBuilder {
free(): void;
[Symbol.dispose](): void;
/**
* Add a source map (as JSON string) at the given line offset.
*/
addMap(json: string, line_offset: number): void;
/**
* Create a new concatenation builder.
*/
constructor(file?: string | null);
/**
* Finish and return the concatenated source map as a JSON string.
*/
toJSON(): string;
}
/**
* Compose/remap source maps through a transform chain.
*
* `outer_json` is the final-stage source map as a JSON string.
* `loader` is a function that receives a source filename and should return
* the upstream source map JSON string, or null/undefined if none.
*
* Returns the remapped source map as a JSON string.
*/
export function remap(outer_json: string, loader: Function): string;
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly __wbg_concatbuilder_free: (a: number, b: number) => void;
readonly concatbuilder_addMap: (a: number, b: number, c: number, d: number, e: number) => void;
readonly concatbuilder_new: (a: number, b: number) => number;
readonly concatbuilder_toJSON: (a: number, b: number) => void;
readonly remap: (a: number, b: number, c: number, d: number) => void;
readonly __wbindgen_export: (a: number, b: number) => number;
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_export3: (a: number) => void;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly __wbindgen_export4: (a: number, b: number, c: number) => 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>;
/* @ts-self-types="./srcmap_remapping_wasm.d.ts" */
export class ConcatBuilder {
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
ConcatBuilderFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_concatbuilder_free(ptr, 0);
}
/**
* Add a source map (as JSON string) at the given line offset.
* @param {string} json
* @param {number} line_offset
*/
addMap(json, line_offset) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
const len0 = WASM_VECTOR_LEN;
wasm.concatbuilder_addMap(retptr, this.__wbg_ptr, ptr0, len0, line_offset);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
if (r1) {
throw takeObject(r0);
}
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}
/**
* Create a new concatenation builder.
* @param {string | null} [file]
*/
constructor(file) {
var ptr0 = isLikeNone(file) ? 0 : passStringToWasm0(file, wasm.__wbindgen_export, wasm.__wbindgen_export2);
var len0 = WASM_VECTOR_LEN;
const ret = wasm.concatbuilder_new(ptr0, len0);
this.__wbg_ptr = ret >>> 0;
ConcatBuilderFinalization.register(this, this.__wbg_ptr, this);
return this;
}
/**
* Finish and return the concatenated source map as a JSON string.
* @returns {string}
*/
toJSON() {
let deferred1_0;
let deferred1_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.concatbuilder_toJSON(retptr, this.__wbg_ptr);
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
deferred1_0 = r0;
deferred1_1 = r1;
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
}
}
}
if (Symbol.dispose) ConcatBuilder.prototype[Symbol.dispose] = ConcatBuilder.prototype.free;
/**
* Compose/remap source maps through a transform chain.
*
* `outer_json` is the final-stage source map as a JSON string.
* `loader` is a function that receives a source filename and should return
* the upstream source map JSON string, or null/undefined if none.
*
* Returns the remapped source map as a JSON string.
* @param {string} outer_json
* @param {Function} loader
* @returns {string}
*/
export function remap(outer_json, loader) {
let deferred3_0;
let deferred3_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(outer_json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
const len0 = WASM_VECTOR_LEN;
wasm.remap(retptr, ptr0, len0, addBorrowedObject(loader));
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
var ptr2 = r0;
var len2 = r1;
if (r3) {
ptr2 = 0; len2 = 0;
throw takeObject(r2);
}
deferred3_0 = ptr2;
deferred3_1 = len2;
return getStringFromWasm0(ptr2, len2);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
heap[stack_pointer++] = undefined;
wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
}
}
function __wbg_get_imports() {
const import0 = {
__proto__: null,
__wbg_Error_83742b46f01ce22d: function(arg0, arg1) {
const ret = Error(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
},
__wbg___wbindgen_is_null_0b605fc6b167c56f: function(arg0) {
const ret = getObject(arg0) === null;
return ret;
},
__wbg___wbindgen_is_undefined_52709e72fb9f179c: function(arg0) {
const ret = getObject(arg0) === undefined;
return ret;
},
__wbg___wbindgen_string_get_395e606bd0ee4427: function(arg0, arg1) {
const obj = getObject(arg1);
const ret = typeof(obj) === 'string' ? obj : undefined;
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
var len1 = WASM_VECTOR_LEN;
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
},
__wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
},
__wbg_call_2d781c1f4d5c0ef8: function() { return handleError(function (arg0, arg1, arg2) {
const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
return addHeapObject(ret);
}, arguments); },
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
// Cast intrinsic for `Ref(String) -> Externref`.
const ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
},
__wbindgen_object_drop_ref: function(arg0) {
takeObject(arg0);
},
};
return {
__proto__: null,
"./srcmap_remapping_wasm_bg.js": import0,
};
}
const ConcatBuilderFinalization = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(ptr => wasm.__wbg_concatbuilder_free(ptr >>> 0, 1));
function addHeapObject(obj) {
if (heap_next === heap.length) heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
return idx;
}
function addBorrowedObject(obj) {
if (stack_pointer == 1) throw new Error('out of js stack');
heap[--stack_pointer] = obj;
return stack_pointer;
}
function dropObject(idx) {
if (idx < 1028) return;
heap[idx] = heap_next;
heap_next = idx;
}
let cachedDataViewMemory0 = null;
function getDataViewMemory0() {
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
}
return cachedDataViewMemory0;
}
function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return decodeText(ptr, len);
}
let cachedUint8ArrayMemory0 = null;
function getUint8ArrayMemory0() {
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8ArrayMemory0;
}
function getObject(idx) { return heap[idx]; }
function handleError(f, args) {
try {
return f.apply(this, args);
} catch (e) {
wasm.__wbindgen_export3(addHeapObject(e));
}
}
let heap = new Array(1024).fill(undefined);
heap.push(undefined, null, true, false);
let heap_next = heap.length;
function isLikeNone(x) {
return x === undefined || x === null;
}
function passStringToWasm0(arg, malloc, realloc) {
if (realloc === undefined) {
const buf = cachedTextEncoder.encode(arg);
const ptr = malloc(buf.length, 1) >>> 0;
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
WASM_VECTOR_LEN = buf.length;
return ptr;
}
let len = arg.length;
let ptr = malloc(len, 1) >>> 0;
const mem = getUint8ArrayMemory0();
let offset = 0;
for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 0x7F) break;
mem[ptr + offset] = code;
}
if (offset !== len) {
if (offset !== 0) {
arg = arg.slice(offset);
}
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
const ret = cachedTextEncoder.encodeInto(arg, view);
offset += ret.written;
ptr = realloc(ptr, len, offset, 1) >>> 0;
}
WASM_VECTOR_LEN = offset;
return ptr;
}
let stack_pointer = 1024;
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
cachedTextDecoder.decode();
const MAX_SAFARI_DECODE_BYTES = 2146435072;
let numBytesDecoded = 0;
function decodeText(ptr, len) {
numBytesDecoded += len;
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
cachedTextDecoder.decode();
numBytesDecoded = len;
}
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}
const cachedTextEncoder = new TextEncoder();
if (!('encodeInto' in cachedTextEncoder)) {
cachedTextEncoder.encodeInto = function (arg, view) {
const buf = cachedTextEncoder.encode(arg);
view.set(buf);
return {
read: arg.length,
written: buf.length
};
};
}
let WASM_VECTOR_LEN = 0;
let wasmModule, wasm;
function __wbg_finalize_init(instance, module) {
wasm = instance.exports;
wasmModule = module;
cachedDataViewMemory0 = null;
cachedUint8ArrayMemory0 = null;
return wasm;
}
async function __wbg_load(module, imports) {
if (typeof Response === 'function' && module instanceof Response) {
if (typeof WebAssembly.instantiateStreaming === 'function') {
try {
return await WebAssembly.instantiateStreaming(module, imports);
} catch (e) {
const validResponse = module.ok && expectedResponseType(module.type);
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
} else { throw e; }
}
}
const bytes = await module.arrayBuffer();
return await WebAssembly.instantiate(bytes, imports);
} else {
const instance = await WebAssembly.instantiate(module, imports);
if (instance instanceof WebAssembly.Instance) {
return { instance, module };
} else {
return instance;
}
}
function expectedResponseType(type) {
switch (type) {
case 'basic': case 'cors': case 'default': return true;
}
return false;
}
}
function initSync(module) {
if (wasm !== undefined) return wasm;
if (module !== undefined) {
if (Object.getPrototypeOf(module) === Object.prototype) {
({module} = module)
} else {
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
}
}
const imports = __wbg_get_imports();
if (!(module instanceof WebAssembly.Module)) {
module = new WebAssembly.Module(module);
}
const instance = new WebAssembly.Instance(module, imports);
return __wbg_finalize_init(instance, module);
}
async function __wbg_init(module_or_path) {
if (wasm !== undefined) return wasm;
if (module_or_path !== undefined) {
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
({module_or_path} = module_or_path)
} else {
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
}
}
if (module_or_path === undefined) {
module_or_path = new URL('srcmap_remapping_wasm_bg.wasm', import.meta.url);
}
const imports = __wbg_get_imports();
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
module_or_path = fetch(module_or_path);
}
const { instance, module } = await __wbg_load(await module_or_path, imports);
return __wbg_finalize_init(instance, module);
}
export { initSync, __wbg_init as default };
+1
-1
{
"name": "@srcmap/remapping-wasm",
"version": "0.2.2",
"version": "0.2.3",
"description": "High-performance source map concatenation and remapping powered by Rust (WebAssembly)",

@@ -5,0 +5,0 @@ "type": "module",

{
"name": "srcmap-remapping-wasm",
"description": "WebAssembly bindings for srcmap-remapping",
"version": "0.2.2",
"version": "0.2.3",
"license": "MIT",

@@ -6,0 +6,0 @@ "repository": {

Sorry, the diff of this file is not supported yet