@ctx-core/source-map 0.1.3 → 0.2.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.
package/package.json CHANGED
@@ -1,56 +1,57 @@
1
1
  {
2
- "name": "@ctx-core/source-map",
3
- "version": "0.1.3",
4
- "description": "Extensions to source-map...like sourcemap_writable_stream_",
5
- "type": "module",
6
- "keywords": [
7
- "ctx-core",
8
- "source-map"
9
- ],
10
- "homepage": "https://github.com/ctx-core/source-map#readme",
11
- "bugs": {
12
- "url": "https://github.com/ctx-core/source-map/issues"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "https://github.com/ctx-core/source-map.git"
17
- },
18
- "license": "Apache-2.0",
19
- "author": "Brian Takita",
20
- "files": [
21
- "*.d.ts",
22
- "*.js",
23
- "*.json",
24
- "sourcemap_writable_stream"
25
- ],
26
- "types": "./index.d.ts",
27
- "exports": {
28
- ".": "./index.js",
29
- "./package.json": "./package.json"
30
- },
31
- "dependencies": {
32
- "ctx-core": "^5.19.1",
33
- "source-map": "^0.7.4"
34
- },
35
- "devDependencies": {
36
- "c8": "^9.1.0",
37
- "check-dts": "^0.7.2",
38
- "tsx": "^4.7.0",
39
- "typescript": "next",
40
- "uvu": "^0.5.6"
41
- },
42
- "publishConfig": {
43
- "access": "public",
44
- "cache": "~/.npm"
45
- },
46
- "sideEffects": false,
47
- "scripts": {
48
- "build": ":",
49
- "clean": ":",
50
- "exec": "$@",
51
- "test": "pnpm test:unit && pnpm test:types",
52
- "test:types": "check-dts",
53
- "test:unit": "tsx node_modules/uvu/bin.js . '\\.test\\.(ts|js)$'",
54
- "test:unit:coverage": "c8 pnpm test:unit"
55
- }
56
- }
2
+ "name": "@ctx-core/source-map",
3
+ "version": "0.2.1",
4
+ "description": "Extensions to source-map...like sourcemap_writable_stream_",
5
+ "type": "module",
6
+ "keywords": [
7
+ "ctx-core",
8
+ "source-map"
9
+ ],
10
+ "homepage": "https://github.com/ctx-core/source-map#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/ctx-core/source-map/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/ctx-core/source-map.git"
17
+ },
18
+ "license": "Apache-2.0",
19
+ "author": "Brian Takita",
20
+ "files": [
21
+ "*.d.ts",
22
+ "*.js",
23
+ "*.json",
24
+ "sourcemap_writable_stream"
25
+ ],
26
+ "types": "./index.d.ts",
27
+ "exports": {
28
+ ".": "./index.js",
29
+ "./package.json": "./package.json"
30
+ },
31
+ "scripts": {
32
+ "build": ":",
33
+ "clean": ":",
34
+ "exec": "$@",
35
+ "prepublishOnly": "pnpm clean && pnpm build && pnpm test",
36
+ "test": "pnpm test:unit && pnpm test:types",
37
+ "test:types": "check-dts",
38
+ "test:unit": "tsx node_modules/uvu/bin.js . '\\.test\\.(ts|js)$'",
39
+ "test:unit:coverage": "c8 pnpm test:unit"
40
+ },
41
+ "dependencies": {
42
+ "ctx-core": "^5.19.1",
43
+ "source-map": "^0.7.4"
44
+ },
45
+ "devDependencies": {
46
+ "c8": "^9.1.0",
47
+ "check-dts": "^0.7.2",
48
+ "tsx": "^4.7.0",
49
+ "typescript": "next",
50
+ "uvu": "^0.5.6"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public",
54
+ "cache": "~/.npm"
55
+ },
56
+ "sideEffects": false
57
+ }
@@ -1,3 +1,4 @@
1
1
  /// <reference lib="dom" />
2
- import type { Writable } from 'node:stream'
3
- export function sourcemap_writable_stream_(write_stream:Writable):WritableStream
2
+ export function sourcemap_writable_stream_(
3
+ write:(str:string)=>(unknown|Promise<unknown>)
4
+ ):WritableStream
@@ -3,7 +3,12 @@ import { TextDecoderStream } from 'ctx-core/stream'
3
3
  import { line__transform_stream_ } from 'ctx-core/string'
4
4
  import { readFile } from 'node:fs/promises'
5
5
  import { SourceMapConsumer } from 'source-map'
6
- export function sourcemap_writable_stream_(write_stream) {
6
+ /**
7
+ * @param {(str:string)=>(unknown|Promise<unknown>)}write
8
+ * @returns {WritableStream<any>}
9
+ * @private
10
+ */
11
+ export function sourcemap_writable_stream_(write) {
7
12
  let outstream_controller
8
13
  const path_R_SourceMapConsumer = {}
9
14
  new ReadableStream({
@@ -18,7 +23,7 @@ export function sourcemap_writable_stream_(write_stream) {
18
23
  const match =
19
24
  stream_line.match(/^\s+at ([^(]+ )?\(?(.*):(.*):([^)]*)\)?/)
20
25
  if (!match) {
21
- write_stream.write(stream_line + '\n')
26
+ await write(stream_line + '\n')
22
27
  return
23
28
  }
24
29
  const [
@@ -29,7 +34,7 @@ export function sourcemap_writable_stream_(write_stream) {
29
34
  column_str
30
35
  ] = match
31
36
  if (!path || !await file_exists_(path + '.map')) {
32
- write_stream.write(stream_line + '\n')
37
+ await write(stream_line + '\n')
33
38
  return
34
39
  }
35
40
  const methodName = methodName_match ? methodName_match.trim() : ''
@@ -41,12 +46,12 @@ export function sourcemap_writable_stream_(write_stream) {
41
46
  JSON.parse(
42
47
  await readFile(path + '.map').then(buf=>'' + buf)))
43
48
  if (line == null || line < 1) {
44
- write_stream.write(' ' + (methodName || '[unknown]') + '\n')
49
+ await write(' ' + (methodName || '[unknown]') + '\n')
45
50
  } else {
46
51
  const pos =
47
52
  smc.originalPositionFor({ line, column })
48
53
  if (pos && pos.line != null) {
49
- write_stream.write(
54
+ await write(
50
55
  ' at '
51
56
  + (pos.name || methodName || '[unknown]')
52
57
  + ' (' + pos.source + ':' + pos.line + ':' + pos.column + ')\n')
@@ -54,7 +59,7 @@ export function sourcemap_writable_stream_(write_stream) {
54
59
  }
55
60
  } catch (err) {
56
61
  console.error(err)
57
- write_stream.write(' at FAILED_TO_PARSE_LINE\n')
62
+ await write(' at FAILED_TO_PARSE_LINE\n')
58
63
  }
59
64
  }
60
65
  }))
@@ -25,11 +25,6 @@ error: test error
25
25
 
26
26
  `.trim()
27
27
  const write_stream_out_a:string[] = []
28
- const write_stream = new Writable()
29
- write_stream.write = (str:string)=>{
30
- write_stream_out_a.push(str)
31
- return true
32
- }
33
28
  await new ReadableStream({
34
29
  start(controller) {
35
30
  controller.enqueue(stderr_text)
@@ -37,7 +32,8 @@ error: test error
37
32
  }
38
33
  })
39
34
  .pipeThrough(new TextEncoderStream())
40
- .pipeTo(sourcemap_writable_stream_(write_stream))
35
+ .pipeTo(sourcemap_writable_stream_(
36
+ str=>write_stream_out_a.push(str)))
41
37
  await sleep(100)
42
38
  equal(write_stream_out_a.join(''), `
43
39
  server__build|watch