@srcmap/codec 0.2.3 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +3 -3
  2. package/index.d.ts +2 -2
  3. package/index.js +60 -58
  4. package/package.json +45 -45
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @srcmap/codec
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@srcmap/codec.svg)](https://www.npmjs.com/package/@srcmap/codec)
4
- [![CI](https://github.com/BartWaardenburg/srcmap/actions/workflows/ci.yml/badge.svg)](https://github.com/BartWaardenburg/srcmap/actions/workflows/ci.yml)
5
- [![Coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/BartWaardenburg/srcmap/badges/coverage.json)](https://github.com/BartWaardenburg/srcmap/actions/workflows/coverage.yml)
4
+ [![CI](https://github.com/fallow-rs/srcmap/actions/workflows/ci.yml/badge.svg)](https://github.com/fallow-rs/srcmap/actions/workflows/ci.yml)
5
+ [![Coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/fallow-rs/srcmap/badges/coverage.json)](https://github.com/fallow-rs/srcmap/actions/workflows/coverage.yml)
6
6
 
7
7
  High-performance VLQ source map codec powered by Rust via [NAPI](https://napi.rs).
8
8
 
@@ -56,7 +56,7 @@ Encode decoded mappings back into a VLQ string.
56
56
 
57
57
  API-compatible with `@jridgewell/sourcemap-codec` — same function signatures, same output format. Can be used as a drop-in replacement.
58
58
 
59
- ## Part of [srcmap](https://github.com/BartWaardenburg/srcmap)
59
+ ## Part of [srcmap](https://github.com/fallow-rs/srcmap)
60
60
 
61
61
  High-performance source map tooling written in Rust. See also:
62
62
  - [`@srcmap/sourcemap`](https://www.npmjs.com/package/@srcmap/sourcemap) - Source map parser (NAPI)
package/index.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * Compatible with `@jridgewell/sourcemap-codec` decode().
8
8
  */
9
- export declare function decode(mappings: string): number[][][]
9
+ export declare function decode(mappings: string): number[][][];
10
10
 
11
11
  /**
12
12
  * Encode decoded source map mappings back into a VLQ string.
@@ -16,4 +16,4 @@ export declare function decode(mappings: string): number[][][]
16
16
  *
17
17
  * Compatible with `@jridgewell/sourcemap-codec` encode().
18
18
  */
19
- export declare function encode(mappings: number[][][]): string
19
+ export declare function encode(mappings: number[][][]): string;
package/index.js CHANGED
@@ -1,112 +1,114 @@
1
1
  /* auto-generated NAPI-RS loader */
2
- const { existsSync, readFileSync } = require('fs')
3
- const { join } = require('path')
4
- const { platform, arch } = process
2
+ const { existsSync } = require("fs");
3
+ const { join } = require("path");
4
+ const { platform, arch } = process;
5
5
 
6
- let nativeBinding = null
6
+ let nativeBinding = null;
7
7
 
8
8
  const triples = {
9
- 'darwin-arm64': 'srcmap-codec.darwin-arm64.node',
10
- 'darwin-x64': 'srcmap-codec.darwin-x64.node',
11
- 'linux-x64-gnu': 'srcmap-codec.linux-x64-gnu.node',
12
- 'linux-x64-musl': 'srcmap-codec.linux-x64-musl.node',
13
- 'linux-arm64-gnu': 'srcmap-codec.linux-arm64-gnu.node',
14
- 'linux-arm64-musl': 'srcmap-codec.linux-arm64-musl.node',
15
- 'win32-x64-msvc': 'srcmap-codec.win32-x64-msvc.node',
16
- }
9
+ "darwin-arm64": "srcmap-codec.darwin-arm64.node",
10
+ "darwin-x64": "srcmap-codec.darwin-x64.node",
11
+ "linux-x64-gnu": "srcmap-codec.linux-x64-gnu.node",
12
+ "linux-x64-musl": "srcmap-codec.linux-x64-musl.node",
13
+ "linux-arm64-gnu": "srcmap-codec.linux-arm64-gnu.node",
14
+ "linux-arm64-musl": "srcmap-codec.linux-arm64-musl.node",
15
+ "win32-x64-msvc": "srcmap-codec.win32-x64-msvc.node",
16
+ };
17
17
 
18
18
  function getTripleKey() {
19
- const platformArch = `${platform}-${arch}`
20
- if (platform === 'linux') {
21
- const { familySync } = require('detect-libc')
22
- const libc = familySync() === 'musl' ? 'musl' : 'gnu'
23
- return `${platformArch}-${libc}`
19
+ const platformArch = `${platform}-${arch}`;
20
+ if (platform === "linux") {
21
+ const { familySync } = require("detect-libc");
22
+ const libc = familySync() === "musl" ? "musl" : "gnu";
23
+ return `${platformArch}-${libc}`;
24
24
  }
25
- return platformArch
25
+ return platformArch;
26
26
  }
27
27
 
28
- const tripleKey = getTripleKey()
29
- const bindingFile = triples[tripleKey]
28
+ const tripleKey = getTripleKey();
29
+ const bindingFile = triples[tripleKey];
30
30
 
31
31
  if (bindingFile) {
32
- const bindingPath = join(__dirname, bindingFile)
32
+ const bindingPath = join(__dirname, bindingFile);
33
33
  if (existsSync(bindingPath)) {
34
- nativeBinding = require(bindingPath)
34
+ nativeBinding = require(bindingPath);
35
35
  } else {
36
36
  try {
37
- nativeBinding = require(`@srcmap/codec-${tripleKey}`)
37
+ nativeBinding = require(`@srcmap/codec-${tripleKey}`);
38
38
  } catch {
39
- throw new Error(`Failed to load native binding for ${tripleKey}. File not found: ${bindingPath}`)
39
+ throw new Error(
40
+ `Failed to load native binding for ${tripleKey}. File not found: ${bindingPath}`,
41
+ );
40
42
  }
41
43
  }
42
44
  } else {
43
- throw new Error(`Unsupported platform: ${tripleKey}`)
45
+ throw new Error(`Unsupported platform: ${tripleKey}`);
44
46
  }
45
47
 
46
- module.exports.decode = nativeBinding.decode
47
- module.exports.encode = nativeBinding.encode
48
+ module.exports.decode = nativeBinding.decode;
49
+ module.exports.encode = nativeBinding.encode;
48
50
 
49
51
  // Experimental: JSON string approach
50
52
  module.exports.decodeJson = function decodeJson(mappings) {
51
- return JSON.parse(nativeBinding.decodeJson(mappings))
52
- }
53
+ return JSON.parse(nativeBinding.decodeJson(mappings));
54
+ };
53
55
  module.exports.encodeJson = function encodeJson(mappings) {
54
- return nativeBinding.encodeJson(JSON.stringify(mappings))
55
- }
56
+ return nativeBinding.encodeJson(JSON.stringify(mappings));
57
+ };
56
58
 
57
59
  // Experimental: Packed buffer approach
58
60
  module.exports.decodeBuf = function decodeBuf(mappings) {
59
- const buf = nativeBinding.decodeBuf(mappings)
60
- const i32 = new Int32Array(buf.buffer, buf.byteOffset, buf.byteLength >> 2)
61
- let pos = 0
61
+ const buf = nativeBinding.decodeBuf(mappings);
62
+ const i32 = new Int32Array(buf.buffer, buf.byteOffset, buf.byteLength >> 2);
63
+ let pos = 0;
62
64
 
63
- const nLines = i32[pos++]
64
- const lineSegCounts = new Array(nLines)
65
+ const nLines = i32[pos++];
66
+ const lineSegCounts = [];
65
67
  for (let i = 0; i < nLines; i++) {
66
- lineSegCounts[i] = i32[pos++]
68
+ lineSegCounts.push(i32[pos++]);
67
69
  }
68
70
 
69
- const result = new Array(nLines)
71
+ const result = [];
70
72
  for (let i = 0; i < nLines; i++) {
71
- const nSegs = lineSegCounts[i]
72
- const line = new Array(nSegs)
73
+ const nSegs = lineSegCounts[i];
74
+ const line = [];
73
75
  for (let j = 0; j < nSegs; j++) {
74
- const nFields = i32[pos++]
75
- const seg = new Array(nFields)
76
+ const nFields = i32[pos++];
77
+ const seg = [];
76
78
  for (let k = 0; k < nFields; k++) {
77
- seg[k] = i32[pos++]
79
+ seg.push(i32[pos++]);
78
80
  }
79
- line[j] = seg
81
+ line.push(seg);
80
82
  }
81
- result[i] = line
83
+ result.push(line);
82
84
  }
83
- return result
84
- }
85
+ return result;
86
+ };
85
87
  module.exports.encodeBuf = function encodeBuf(mappings) {
86
88
  // Pack nested arrays into flat i32 buffer
87
- let totalInts = 1 + mappings.length // n_lines + seg counts
89
+ let totalInts = 1 + mappings.length; // n_lines + seg counts
88
90
  for (const line of mappings) {
89
91
  for (const seg of line) {
90
- totalInts += 1 + seg.length // n_fields + values
92
+ totalInts += 1 + seg.length; // n_fields + values
91
93
  }
92
94
  }
93
95
 
94
- const buf = Buffer.alloc(totalInts * 4)
95
- const i32 = new Int32Array(buf.buffer, buf.byteOffset, totalInts)
96
- let pos = 0
96
+ const buf = Buffer.alloc(totalInts * 4);
97
+ const i32 = new Int32Array(buf.buffer, buf.byteOffset, totalInts);
98
+ let pos = 0;
97
99
 
98
- i32[pos++] = mappings.length
100
+ i32[pos++] = mappings.length;
99
101
  for (const line of mappings) {
100
- i32[pos++] = line.length
102
+ i32[pos++] = line.length;
101
103
  }
102
104
  for (const line of mappings) {
103
105
  for (const seg of line) {
104
- i32[pos++] = seg.length
106
+ i32[pos++] = seg.length;
105
107
  for (const val of seg) {
106
- i32[pos++] = val
108
+ i32[pos++] = val;
107
109
  }
108
110
  }
109
111
  }
110
112
 
111
- return nativeBinding.encodeBuf(buf)
112
- }
113
+ return nativeBinding.encodeBuf(buf);
114
+ };
package/package.json CHANGED
@@ -1,7 +1,26 @@
1
1
  {
2
2
  "name": "@srcmap/codec",
3
- "version": "0.2.3",
3
+ "version": "0.3.2",
4
4
  "description": "High-performance VLQ source map codec powered by Rust",
5
+ "keywords": [
6
+ "codec",
7
+ "napi",
8
+ "performance",
9
+ "rust",
10
+ "source-map",
11
+ "sourcemap",
12
+ "vlq"
13
+ ],
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/fallow-rs/srcmap.git"
18
+ },
19
+ "files": [
20
+ "index.js",
21
+ "index.d.ts",
22
+ "README.md"
23
+ ],
5
24
  "main": "index.js",
6
25
  "types": "index.d.ts",
7
26
  "exports": {
@@ -11,6 +30,30 @@
11
30
  "require": "./index.js"
12
31
  }
13
32
  },
33
+ "scripts": {
34
+ "artifacts": "napi artifacts",
35
+ "build": "napi build --release --platform --dts ../../target/napi-codec.d.ts",
36
+ "build:debug": "napi build --platform --dts ../../target/napi-codec.d.ts",
37
+ "test": "node --test __tests__/codec.test.mjs",
38
+ "test:coverage": "mkdir -p coverage && node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test-reporter=spec --test-reporter-destination=stdout __tests__/codec.test.mjs",
39
+ "prepublishOnly": "napi prepublish -t npm",
40
+ "version": "napi version"
41
+ },
42
+ "dependencies": {
43
+ "detect-libc": "^2.0.0"
44
+ },
45
+ "devDependencies": {
46
+ "@napi-rs/cli": "^3.0.0"
47
+ },
48
+ "optionalDependencies": {
49
+ "@srcmap/codec-darwin-arm64": "0.3.2",
50
+ "@srcmap/codec-darwin-x64": "0.3.2",
51
+ "@srcmap/codec-linux-arm64-gnu": "0.3.2",
52
+ "@srcmap/codec-linux-arm64-musl": "0.3.2",
53
+ "@srcmap/codec-linux-x64-gnu": "0.3.2",
54
+ "@srcmap/codec-linux-x64-musl": "0.3.2",
55
+ "@srcmap/codec-win32-x64-msvc": "0.3.2"
56
+ },
14
57
  "napi": {
15
58
  "binaryName": "srcmap-codec",
16
59
  "targets": [
@@ -22,48 +65,5 @@
22
65
  "aarch64-unknown-linux-musl",
23
66
  "x86_64-pc-windows-msvc"
24
67
  ]
25
- },
26
- "license": "MIT",
27
- "files": [
28
- "index.js",
29
- "index.d.ts",
30
- "README.md"
31
- ],
32
- "optionalDependencies": {
33
- "@srcmap/codec-darwin-x64": "0.1.3",
34
- "@srcmap/codec-darwin-arm64": "0.1.3",
35
- "@srcmap/codec-linux-x64-gnu": "0.1.3",
36
- "@srcmap/codec-linux-x64-musl": "0.1.3",
37
- "@srcmap/codec-linux-arm64-gnu": "0.1.3",
38
- "@srcmap/codec-linux-arm64-musl": "0.1.3",
39
- "@srcmap/codec-win32-x64-msvc": "0.1.3"
40
- },
41
- "dependencies": {
42
- "detect-libc": "^2.0.0"
43
- },
44
- "devDependencies": {
45
- "@napi-rs/cli": "^3.0.0"
46
- },
47
- "scripts": {
48
- "artifacts": "napi artifacts",
49
- "build": "napi build --release --platform",
50
- "build:debug": "napi build --platform",
51
- "test": "node --test __tests__/codec.test.mjs",
52
- "test:coverage": "mkdir -p coverage && node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test-reporter=spec --test-reporter-destination=stdout __tests__/codec.test.mjs",
53
- "prepublishOnly": "napi prepublish -t npm",
54
- "version": "napi version"
55
- },
56
- "repository": {
57
- "type": "git",
58
- "url": "git+https://github.com/BartWaardenburg/srcmap.git"
59
- },
60
- "keywords": [
61
- "sourcemap",
62
- "source-map",
63
- "vlq",
64
- "codec",
65
- "rust",
66
- "napi",
67
- "performance"
68
- ]
68
+ }
69
69
  }