cargo-messages 0.0.8

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/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # cargo-messages
2
+
3
+ **cargo-messages:** A streaming reader for JSON messages emitted from Cargo
4
+
5
+ This project was bootstrapped by [create-neon](https://www.npmjs.com/package/create-neon).
6
+
7
+ ## Installing cargo-messages
8
+
9
+ Installing cargo-messages requires a [supported version of Node and Rust](https://github.com/neon-bindings/neon#platform-support).
10
+
11
+ You can install the project with npm. In the project directory, run:
12
+
13
+ ```sh
14
+ $ npm install
15
+ ```
16
+
17
+ This fully installs the project, including installing any dependencies and running the build.
18
+
19
+ ## Building cargo-messages
20
+
21
+ If you have already installed the project and only want to run the build, run:
22
+
23
+ ```sh
24
+ $ npm run build
25
+ ```
26
+
27
+ This command uses the [cargo-cp-artifact](https://github.com/neon-bindings/cargo-cp-artifact) utility to run the Rust build and copy the built library into `./index.node`.
28
+
29
+ ## Exploring cargo-messages
30
+
31
+ After building cargo-messages, you can explore its exports at the Node REPL:
32
+
33
+ ```sh
34
+ $ npm install
35
+ $ node
36
+ > require('.').hello()
37
+ "hello node"
38
+ ```
39
+
40
+ ## Available Scripts
41
+
42
+ In the project directory, you can run:
43
+
44
+ ### `npm install`
45
+
46
+ Installs the project, including running `npm run build`.
47
+
48
+ ### `npm build`
49
+
50
+ Builds the Node addon (`index.node`) from source.
51
+
52
+ Additional [`cargo build`](https://doc.rust-lang.org/cargo/commands/cargo-build.html) arguments may be passed to `npm build` and `npm build-*` commands. For example, to enable a [cargo feature](https://doc.rust-lang.org/cargo/reference/features.html):
53
+
54
+ ```
55
+ npm run build -- --feature=beetle
56
+ ```
57
+
58
+ #### `npm build-debug`
59
+
60
+ Alias for `npm build`.
61
+
62
+ #### `npm build-release`
63
+
64
+ Same as [`npm build`](#npm-build) but, builds the module with the [`release`](https://doc.rust-lang.org/cargo/reference/profiles.html#release) profile. Release builds will compile slower, but run faster.
65
+
66
+ ### `npm test`
67
+
68
+ Runs the unit tests by calling `cargo test`. You can learn more about [adding tests to your Rust code](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) from the [Rust book](https://doc.rust-lang.org/book/).
69
+
70
+ ## Project Layout
71
+
72
+ The directory structure of this project is:
73
+
74
+ ```
75
+ cargo-messages/
76
+ ├── Cargo.toml
77
+ ├── README.md
78
+ ├── index.node
79
+ ├── package.json
80
+ ├── src/
81
+ | └── lib.rs
82
+ └── target/
83
+ ```
84
+
85
+ ### Cargo.toml
86
+
87
+ The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command.
88
+
89
+ ### README.md
90
+
91
+ This file.
92
+
93
+ ### index.node
94
+
95
+ The Node addon—i.e., a binary Node module—generated by building the project. This is the main module for this package, as dictated by the `"main"` key in `package.json`.
96
+
97
+ Under the hood, a [Node addon](https://nodejs.org/api/addons.html) is a [dynamically-linked shared object](https://en.wikipedia.org/wiki/Library_(computing)#Shared_libraries). The `"build"` script produces this file by copying it from within the `target/` directory, which is where the Rust build produces the shared object.
98
+
99
+ ### package.json
100
+
101
+ The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command.
102
+
103
+ ### src/
104
+
105
+ The directory tree containing the Rust source code for the project.
106
+
107
+ ### src/lib.rs
108
+
109
+ The Rust library's main module.
110
+
111
+ ### target/
112
+
113
+ Binary artifacts generated by the Rust build.
114
+
115
+ ## Learn More
116
+
117
+ To learn more about Neon, see the [Neon documentation](https://neon-bindings.com).
118
+
119
+ To learn more about Rust, see the [Rust documentation](https://www.rust-lang.org).
120
+
121
+ To learn more about Node, see the [Node documentation](https://nodejs.org).
package/cjs/index.cjs ADDED
@@ -0,0 +1,50 @@
1
+ const path = require("path");
2
+ const { load, currentTarget } = require('@neon-rs/load');
3
+
4
+ const {
5
+ fromStdin,
6
+ fromFile,
7
+ findArtifact,
8
+ findFileByCrateType
9
+ } = load(path.join(__dirname, "..")) || require(`@cargo-messages/${currentTarget()}`);
10
+
11
+ const PRIVATE = {};
12
+
13
+ function enforcePrivate(nonce, className) {
14
+ if (nonce !== PRIVATE) {
15
+ throw new Error(`${className} constructor is private`);
16
+ }
17
+ }
18
+
19
+ class CargoArtifact {
20
+ constructor(nonce, kernel) {
21
+ enforcePrivate(nonce, 'CargoArtifact');
22
+ this._kernel = kernel;
23
+ }
24
+
25
+ findFileByCrateType(crateType) {
26
+ return findFileByCrateType(this._kernel, crateType);
27
+ }
28
+ }
29
+
30
+ class CargoMessages {
31
+ constructor(options) {
32
+ options = options || {};
33
+ this._mount = options.mount || null;
34
+ this._manifestPath = options.manifestPath || null;
35
+ this._kernel = options.file
36
+ ? fromFile(options.file, this._mount, this._manifestPath)
37
+ : fromStdin(this._mount, this._manifestPath);
38
+ }
39
+
40
+ findArtifact(crateName) {
41
+ const found = findArtifact(this._kernel, crateName);
42
+ return found
43
+ ? new CargoArtifact(PRIVATE, found)
44
+ : null;
45
+ }
46
+ }
47
+
48
+ module.exports = {
49
+ CargoMessages
50
+ };
package/esm/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { createRequire } from "node:module";
2
+
3
+ const require = createRequire(import.meta.url);
4
+
5
+ export const CargoMessages = require("../cjs/index.cjs").CargoMessages;
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "cargo-messages",
3
+ "private": false,
4
+ "version": "0.0.8",
5
+ "description": "A streaming reader for JSON messages emitted from Cargo.",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "import": {
10
+ "types": "./types/esm/index.d.ts",
11
+ "default": "./esm/index.js"
12
+ },
13
+ "require": {
14
+ "types": "./types/cjs/index.d.ts",
15
+ "default": "./cjs/index.cjs"
16
+ }
17
+ }
18
+ },
19
+ "types": "./types/cjs/index.d.ts",
20
+ "main": "./cjs/index.cjs",
21
+ "files": [
22
+ "README.md",
23
+ "cjs/index.cjs",
24
+ "types/cjs/index.d.ts",
25
+ "esm/index.js",
26
+ "types/esm/index.d.ts"
27
+ ],
28
+ "scripts": {
29
+ "test": "cargo test",
30
+ "debug": "cargo build --message-format=json | neon dist",
31
+ "build": "cargo build --message-format=json --release | neon dist",
32
+ "cross": "cross build --message-format=json --release | neon dist -m /target",
33
+ "pack-build": "neon pack-build",
34
+ "prepack": "neon install-builds"
35
+ },
36
+ "author": "David Herman <david.herman@gmail.com>",
37
+ "license": "MIT",
38
+ "devDependencies": {
39
+ "@neon-rs/cli": "0.0.5"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/dherman/neon-rs.git"
44
+ },
45
+ "keywords": [
46
+ "Rust",
47
+ "Neon"
48
+ ],
49
+ "bugs": {
50
+ "url": "https://github.com/dherman/neon-rs/issues"
51
+ },
52
+ "homepage": "https://github.com/dherman/neon-rs#readme",
53
+ "dependencies": {
54
+ "@neon-rs/load": "^0.0.5"
55
+ },
56
+ "neon": {
57
+ "targets": {
58
+ "x86_64-pc-windows-msvc": "@cargo-messages/win32-x64-msvc",
59
+ "aarch64-pc-windows-msvc": "@cargo-messages/win32-arm64-msvc",
60
+ "x86_64-apple-darwin": "@cargo-messages/darwin-x64",
61
+ "aarch64-apple-darwin": "@cargo-messages/darwin-arm64",
62
+ "x86_64-unknown-linux-gnu": "@cargo-messages/linux-x64-gnu",
63
+ "armv7-unknown-linux-gnueabihf": "@cargo-messages/linux-arm-gnueabihf",
64
+ "armv7-linux-androideabi": "@cargo-messages/android-arm-eabi"
65
+ }
66
+ },
67
+ "optionalDependencies": {
68
+ "@cargo-messages/android-arm-eabi": "0.0.8",
69
+ "@cargo-messages/darwin-arm64": "0.0.8",
70
+ "@cargo-messages/darwin-x64": "0.0.8",
71
+ "@cargo-messages/linux-arm-gnueabihf": "0.0.8",
72
+ "@cargo-messages/linux-x64-gnu": "0.0.8",
73
+ "@cargo-messages/win32-arm64-msvc": "0.0.8",
74
+ "@cargo-messages/win32-x64-msvc": "0.0.8"
75
+ }
76
+ }
@@ -0,0 +1,19 @@
1
+ export type CrateType =
2
+ | 'dylib'
3
+ | 'cdylib'
4
+ | 'rlib';
5
+
6
+ export interface CargoArtifact {
7
+ findFileByCrateType(crateType: CrateType): string | null;
8
+ }
9
+
10
+ export type CargoMessageOptions = {
11
+ mount?: string,
12
+ manifestPath?: string,
13
+ file?: string
14
+ };
15
+
16
+ export class CargoMessages {
17
+ constructor(options?: CargoMessageOptions);
18
+ findArtifact(crateName: string): CargoArtifact | null;
19
+ }
@@ -0,0 +1,3 @@
1
+ import { CrateType, CargoArtifact, CargoMessageOptions, CargoMessages } from '../cjs/index.d.ts';
2
+
3
+ export { CrateType, CargoArtifact, CargoMessageOptions, CargoMessages };