cargo-messages 0.0.133 → 0.0.135

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/lib/index.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  const addon = require('./load.cjs');
2
+ const readline = require('node:readline');
2
3
 
3
4
  const PRIVATE = {};
4
5
 
@@ -38,6 +39,50 @@ class CargoMessages {
38
39
  }
39
40
  }
40
41
 
42
+ class CargoReader {
43
+ constructor(input, options) {
44
+ options = options || {};
45
+ this._mount = options.mount || null;
46
+ this._manifestPath = options.manifestPath || null;
47
+ this._verbose = options.verbose || false;
48
+ this._input = input;
49
+ this._kernel = addon.createReader(this._mount, this._manifestPath, this._verbose);
50
+ }
51
+
52
+ async *[Symbol.asyncIterator]() {
53
+ const rl = readline.createInterface({
54
+ input: this._input
55
+ });
56
+ for await (const line of rl) {
57
+ const { kernel, kind } = addon.readline(line);
58
+ switch (kind) {
59
+ case 0:
60
+ yield new CompilerArtifact(PRIVATE, kernel);
61
+ break;
62
+
63
+ case 1:
64
+ case 2:
65
+ case 3:
66
+ case 4:
67
+ throw new Error(`message type not yet implemented (code: ${kind})`);
68
+ break;
69
+ }
70
+ }
71
+ }
72
+ }
73
+
74
+ class CompilerArtifact {
75
+ constructor(nonce, kernel) {
76
+ enforcePrivate(nonce, 'CompilerArtifact');
77
+ this._kernel = kernel;
78
+ }
79
+
80
+ crateName() {
81
+ return addon.compilerArtifactCrateName(this._kernel);
82
+ }
83
+ }
84
+
41
85
  module.exports = {
42
- CargoMessages
86
+ CargoMessages,
87
+ CargoReader
43
88
  };
package/lib/index.mjs CHANGED
@@ -1 +1 @@
1
- export { CargoMessages } from './index.cjs';
1
+ export { CargoMessages, CargoReader } from './index.cjs';
package/lib/load.cjs CHANGED
@@ -11,5 +11,8 @@ module.exports = require('@neon-rs/load').lazy({
11
11
  'findArtifact',
12
12
  'findFileByCrateType',
13
13
  'fromStdin',
14
- 'fromFile'
14
+ 'fromFile',
15
+ 'createReader',
16
+ 'compilerArtifactCrateName',
17
+ 'readline'
15
18
  ]);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cargo-messages",
3
3
  "private": false,
4
- "version": "0.0.133",
4
+ "version": "0.0.135",
5
5
  "description": "A streaming reader for JSON messages emitted from Cargo.",
6
6
  "type": "module",
7
7
  "exports": {
@@ -28,8 +28,8 @@
28
28
  "scripts": {
29
29
  "test": "cargo test",
30
30
  "debug": "cargo build --message-format=json | neon dist",
31
- "build": "cargo build --message-format=json --release > cross.log && cat cross.log | neon dist -v",
32
- "cross": "cross build --message-format=json --release > cross.log && cat cross.log | neon dist -v -m /target",
31
+ "build": "cargo build --message-format=json --release | neon dist -v",
32
+ "cross": "cross build --message-format=json --release | neon dist -v -m /target",
33
33
  "pack-build": "neon pack-build",
34
34
  "prepack": "neon install-builds",
35
35
  "version": "neon bump -v --binaries npm"
@@ -37,7 +37,7 @@
37
37
  "author": "David Herman <david.herman@gmail.com>",
38
38
  "license": "MIT",
39
39
  "devDependencies": {
40
- "@neon-rs/cli": "^0.0.131"
40
+ "@neon-rs/cli": "^0.0.134"
41
41
  },
42
42
  "repository": {
43
43
  "type": "git",
package/types/index.d.cts CHANGED
@@ -18,3 +18,22 @@ export class CargoMessages {
18
18
  constructor(options?: CargoMessageOptions);
19
19
  findArtifact(crateName: string): CargoArtifact | null;
20
20
  }
21
+
22
+ export type CargoReaderOptions = {
23
+ mount?: string,
24
+ manifestPath?: string,
25
+ verbose?: boolean,
26
+ }
27
+
28
+ export interface CargoMessage {
29
+
30
+ }
31
+
32
+ export interface CompilerArtifact extends CargoMessage {
33
+ crateName(): string;
34
+ }
35
+
36
+ export class CargoReader implements AsyncIterable<CargoMessage> {
37
+ constructor(options?: CargoReaderOptions);
38
+ [Symbol.asyncIterator](): AsyncIterator<CargoMessage>;
39
+ }
package/types/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { CrateType, CargoArtifact, CargoMessageOptions, CargoMessages } from './index.d.cts';
1
+ import { CrateType, CargoArtifact, CargoMessageOptions, CargoMessages, CargoReader, CargoReaderOptions, CompilerArtifact, CargoMessage } from './index.d.cts';
2
2
 
3
- export { CrateType, CargoArtifact, CargoMessageOptions, CargoMessages };
3
+ export { CrateType, CargoArtifact, CargoMessageOptions, CargoMessages, CargoReader, CargoReaderOptions, CompilerArtifact, CargoMessage };