@srcmap/sourcemap 0.1.1

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/index.d.ts +42 -0
  2. package/index.js +45 -0
  3. package/package.json +61 -0
package/index.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ export interface OriginalPosition {
2
+ source: string | null
3
+ line: number
4
+ column: number
5
+ name: string | null
6
+ }
7
+
8
+ export interface GeneratedPosition {
9
+ line: number
10
+ column: number
11
+ }
12
+
13
+ export declare class SourceMap {
14
+ /** Parse a source map from a JSON string. Supports regular and indexed (sectioned) maps. */
15
+ constructor(json: string)
16
+
17
+ /** Look up the original source position for a generated position. 0-based line and column. */
18
+ originalPositionFor(line: number, column: number): OriginalPosition | null
19
+
20
+ /** Look up the generated position for an original source position. 0-based line and column. */
21
+ generatedPositionFor(source: string, line: number, column: number): GeneratedPosition | null
22
+
23
+ /**
24
+ * Batch lookup: find original positions for multiple generated positions.
25
+ * Takes a flat array [line0, col0, line1, col1, ...].
26
+ * Returns a flat array [srcIdx0, line0, col0, nameIdx0, srcIdx1, ...].
27
+ * -1 means no mapping found / no name.
28
+ */
29
+ originalPositionsFor(positions: number[]): number[]
30
+
31
+ /** Source file paths. */
32
+ get sources(): string[]
33
+
34
+ /** Name identifiers. */
35
+ get names(): string[]
36
+
37
+ /** Total number of decoded mapping segments. */
38
+ get mappingCount(): number
39
+
40
+ /** Number of generated lines. */
41
+ get lineCount(): number
42
+ }
package/index.js ADDED
@@ -0,0 +1,45 @@
1
+ const { existsSync } = require('fs')
2
+ const { join } = require('path')
3
+ const { platform, arch } = process
4
+
5
+ let nativeBinding = null
6
+
7
+ const triples = {
8
+ 'darwin-arm64': 'srcmap-sourcemap.darwin-arm64.node',
9
+ 'darwin-x64': 'srcmap-sourcemap.darwin-x64.node',
10
+ 'linux-x64-gnu': 'srcmap-sourcemap.linux-x64-gnu.node',
11
+ 'linux-x64-musl': 'srcmap-sourcemap.linux-x64-musl.node',
12
+ 'linux-arm64-gnu': 'srcmap-sourcemap.linux-arm64-gnu.node',
13
+ 'linux-arm64-musl': 'srcmap-sourcemap.linux-arm64-musl.node',
14
+ 'win32-x64-msvc': 'srcmap-sourcemap.win32-x64-msvc.node',
15
+ }
16
+
17
+ function getTripleKey() {
18
+ const platformArch = `${platform}-${arch}`
19
+ if (platform === 'linux') {
20
+ const { familySync } = require('detect-libc')
21
+ const libc = familySync() === 'musl' ? 'musl' : 'gnu'
22
+ return `${platformArch}-${libc}`
23
+ }
24
+ return platformArch
25
+ }
26
+
27
+ const tripleKey = getTripleKey()
28
+ const bindingFile = triples[tripleKey]
29
+
30
+ if (bindingFile) {
31
+ const bindingPath = join(__dirname, bindingFile)
32
+ if (existsSync(bindingPath)) {
33
+ nativeBinding = require(bindingPath)
34
+ } else {
35
+ try {
36
+ nativeBinding = require(`@srcmap/sourcemap-${tripleKey}`)
37
+ } catch {
38
+ throw new Error(`Failed to load native binding for ${tripleKey}. File not found: ${bindingPath}`)
39
+ }
40
+ }
41
+ } else {
42
+ throw new Error(`Unsupported platform: ${tripleKey}`)
43
+ }
44
+
45
+ module.exports.SourceMap = nativeBinding.SourceMap
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@srcmap/sourcemap",
3
+ "version": "0.1.1",
4
+ "description": "High-performance source map parser and consumer powered by Rust",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./index.d.ts",
10
+ "import": "./index.js",
11
+ "require": "./index.js"
12
+ }
13
+ },
14
+ "napi": {
15
+ "binaryName": "srcmap-sourcemap",
16
+ "targets": [
17
+ "x86_64-apple-darwin",
18
+ "aarch64-apple-darwin",
19
+ "x86_64-unknown-linux-gnu",
20
+ "x86_64-unknown-linux-musl",
21
+ "aarch64-unknown-linux-gnu",
22
+ "aarch64-unknown-linux-musl",
23
+ "x86_64-pc-windows-msvc"
24
+ ]
25
+ },
26
+ "license": "MIT",
27
+ "files": [
28
+ "index.js",
29
+ "index.d.ts"
30
+ ],
31
+ "optionalDependencies": {
32
+ "@srcmap/sourcemap-darwin-x64": "0.1.1",
33
+ "@srcmap/sourcemap-darwin-arm64": "0.1.1",
34
+ "@srcmap/sourcemap-linux-x64-gnu": "0.1.1",
35
+ "@srcmap/sourcemap-linux-x64-musl": "0.1.1",
36
+ "@srcmap/sourcemap-linux-arm64-gnu": "0.1.1",
37
+ "@srcmap/sourcemap-linux-arm64-musl": "0.1.1",
38
+ "@srcmap/sourcemap-win32-x64-msvc": "0.1.1"
39
+ },
40
+ "devDependencies": {
41
+ "@napi-rs/cli": "^3.0.0"
42
+ },
43
+ "scripts": {
44
+ "build": "napi build --release --platform",
45
+ "build:debug": "napi build --platform"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/bartwaardenburg/srcmap"
50
+ },
51
+ "keywords": [
52
+ "sourcemap",
53
+ "source-map",
54
+ "parser",
55
+ "consumer",
56
+ "lookup",
57
+ "rust",
58
+ "napi",
59
+ "performance"
60
+ ]
61
+ }