cargo-messages 0.0.48 → 0.0.49

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 (2) hide show
  1. package/cjs/index.cjs +16 -15
  2. package/package.json +1 -1
package/cjs/index.cjs CHANGED
@@ -1,17 +1,18 @@
1
1
  const { currentTarget } = require('@neon-rs/load');
2
2
 
3
- let addon;
4
- switch (currentTarget()) {
5
- case 'darwin-x64': addon = require('@cargo-messages/darwin-64'); break;
6
- default: throw new Error(`no binary @cargo-messages module found for ${currentTarget()}`);
7
- }
3
+ let saved = null;
8
4
 
9
- const {
10
- fromStdin,
11
- fromFile,
12
- findArtifact,
13
- findFileByCrateType
14
- } = addon;
5
+ function addon() {
6
+ if (saved) {
7
+ return saved;
8
+ }
9
+ const target = currentTarget();
10
+ switch (target) {
11
+ case 'darwin-x64': saved = require('@cargo-messages/darwin-x64'); break;
12
+ default: throw new Error(`no binary @cargo-messages module found for ${target}`);
13
+ }
14
+ return addon();
15
+ }
15
16
 
16
17
  const PRIVATE = {};
17
18
 
@@ -28,7 +29,7 @@ class CargoArtifact {
28
29
  }
29
30
 
30
31
  findFileByCrateType(crateType) {
31
- return findFileByCrateType(this._kernel, crateType);
32
+ return addon().findFileByCrateType(this._kernel, crateType);
32
33
  }
33
34
  }
34
35
 
@@ -38,12 +39,12 @@ class CargoMessages {
38
39
  this._mount = options.mount || null;
39
40
  this._manifestPath = options.manifestPath || null;
40
41
  this._kernel = options.file
41
- ? fromFile(options.file, this._mount, this._manifestPath)
42
- : fromStdin(this._mount, this._manifestPath);
42
+ ? addon().fromFile(options.file, this._mount, this._manifestPath)
43
+ : addon().fromStdin(this._mount, this._manifestPath);
43
44
  }
44
45
 
45
46
  findArtifact(crateName) {
46
- const found = findArtifact(this._kernel, crateName);
47
+ const found = addon().findArtifact(this._kernel, crateName);
47
48
  return found
48
49
  ? new CargoArtifact(PRIVATE, found)
49
50
  : null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cargo-messages",
3
3
  "private": false,
4
- "version": "0.0.48",
4
+ "version": "0.0.49",
5
5
  "description": "A streaming reader for JSON messages emitted from Cargo.",
6
6
  "type": "module",
7
7
  "exports": {