@srcmap/codec 0.1.1 → 0.1.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 (3) hide show
  1. package/package.json +9 -9
  2. package/index.d.ts +0 -19
  3. package/index.js +0 -112
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@srcmap/codec",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "High-performance VLQ source map codec powered by Rust",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -29,13 +29,13 @@
29
29
  "index.d.ts"
30
30
  ],
31
31
  "optionalDependencies": {
32
- "@srcmap/codec-darwin-x64": "0.1.1",
33
- "@srcmap/codec-darwin-arm64": "0.1.1",
34
- "@srcmap/codec-linux-x64-gnu": "0.1.1",
35
- "@srcmap/codec-linux-x64-musl": "0.1.1",
36
- "@srcmap/codec-linux-arm64-gnu": "0.1.1",
37
- "@srcmap/codec-linux-arm64-musl": "0.1.1",
38
- "@srcmap/codec-win32-x64-msvc": "0.1.1"
32
+ "@srcmap/codec-darwin-x64": "0.1.2",
33
+ "@srcmap/codec-darwin-arm64": "0.1.2",
34
+ "@srcmap/codec-linux-x64-gnu": "0.1.2",
35
+ "@srcmap/codec-linux-x64-musl": "0.1.2",
36
+ "@srcmap/codec-linux-arm64-gnu": "0.1.2",
37
+ "@srcmap/codec-linux-arm64-musl": "0.1.2",
38
+ "@srcmap/codec-win32-x64-msvc": "0.1.2"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@napi-rs/cli": "^3.0.0"
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "repository": {
51
51
  "type": "git",
52
- "url": "https://github.com/bartwaardenburg/srcmap"
52
+ "url": "https://github.com/BartWaardenburg/srcmap"
53
53
  },
54
54
  "keywords": [
55
55
  "sourcemap",
package/index.d.ts DELETED
@@ -1,19 +0,0 @@
1
- /**
2
- * Decode a VLQ-encoded source map mappings string.
3
- *
4
- * Returns an array of lines, each containing an array of segments.
5
- * Each segment is an array of 1, 4, or 5 numbers.
6
- *
7
- * Compatible with `@jridgewell/sourcemap-codec` decode().
8
- */
9
- export declare function decode(mappings: string): number[][][]
10
-
11
- /**
12
- * Encode decoded source map mappings back into a VLQ string.
13
- *
14
- * Takes an array of lines, each containing an array of segments.
15
- * Each segment should be an array of 1, 4, or 5 numbers.
16
- *
17
- * Compatible with `@jridgewell/sourcemap-codec` encode().
18
- */
19
- export declare function encode(mappings: number[][][]): string
package/index.js DELETED
@@ -1,112 +0,0 @@
1
- /* auto-generated NAPI-RS loader */
2
- const { existsSync, readFileSync } = require('fs')
3
- const { join } = require('path')
4
- const { platform, arch } = process
5
-
6
- let nativeBinding = null
7
-
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
- }
17
-
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}`
24
- }
25
- return platformArch
26
- }
27
-
28
- const tripleKey = getTripleKey()
29
- const bindingFile = triples[tripleKey]
30
-
31
- if (bindingFile) {
32
- const bindingPath = join(__dirname, bindingFile)
33
- if (existsSync(bindingPath)) {
34
- nativeBinding = require(bindingPath)
35
- } else {
36
- try {
37
- nativeBinding = require(`@srcmap/codec-${tripleKey}`)
38
- } catch {
39
- throw new Error(`Failed to load native binding for ${tripleKey}. File not found: ${bindingPath}`)
40
- }
41
- }
42
- } else {
43
- throw new Error(`Unsupported platform: ${tripleKey}`)
44
- }
45
-
46
- module.exports.decode = nativeBinding.decode
47
- module.exports.encode = nativeBinding.encode
48
-
49
- // Experimental: JSON string approach
50
- module.exports.decodeJson = function decodeJson(mappings) {
51
- return JSON.parse(nativeBinding.decodeJson(mappings))
52
- }
53
- module.exports.encodeJson = function encodeJson(mappings) {
54
- return nativeBinding.encodeJson(JSON.stringify(mappings))
55
- }
56
-
57
- // Experimental: Packed buffer approach
58
- 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
62
-
63
- const nLines = i32[pos++]
64
- const lineSegCounts = new Array(nLines)
65
- for (let i = 0; i < nLines; i++) {
66
- lineSegCounts[i] = i32[pos++]
67
- }
68
-
69
- const result = new Array(nLines)
70
- for (let i = 0; i < nLines; i++) {
71
- const nSegs = lineSegCounts[i]
72
- const line = new Array(nSegs)
73
- for (let j = 0; j < nSegs; j++) {
74
- const nFields = i32[pos++]
75
- const seg = new Array(nFields)
76
- for (let k = 0; k < nFields; k++) {
77
- seg[k] = i32[pos++]
78
- }
79
- line[j] = seg
80
- }
81
- result[i] = line
82
- }
83
- return result
84
- }
85
- module.exports.encodeBuf = function encodeBuf(mappings) {
86
- // Pack nested arrays into flat i32 buffer
87
- let totalInts = 1 + mappings.length // n_lines + seg counts
88
- for (const line of mappings) {
89
- for (const seg of line) {
90
- totalInts += 1 + seg.length // n_fields + values
91
- }
92
- }
93
-
94
- const buf = Buffer.alloc(totalInts * 4)
95
- const i32 = new Int32Array(buf.buffer, buf.byteOffset, totalInts)
96
- let pos = 0
97
-
98
- i32[pos++] = mappings.length
99
- for (const line of mappings) {
100
- i32[pos++] = line.length
101
- }
102
- for (const line of mappings) {
103
- for (const seg of line) {
104
- i32[pos++] = seg.length
105
- for (const val of seg) {
106
- i32[pos++] = val
107
- }
108
- }
109
- }
110
-
111
- return nativeBinding.encodeBuf(buf)
112
- }