@nyar/nyar 0.0.0 → 0.0.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/README.md +20 -0
- package/bin/nyar.js +53 -53
- package/package.json +9 -10
- package/readme.md +20 -20
- package/src/index.ts +38 -38
- package/src/platform.ts +68 -68
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# @nyar/nyar
|
|
2
|
+
|
|
3
|
+
Cross-platform npm facade for the Nyar VM CLI and host APIs. Native and Wasm sidecars are published as separate platform packages under `projects/packages/`.
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { createNyarHost } from "@nyar/nyar";
|
|
9
|
+
|
|
10
|
+
const host = await createNyarHost();
|
|
11
|
+
await host.runBytecode(bytes);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Platform-specific binaries (`nyar-win32-x64`, `nyar-linux-x64`, `nyar-darwin-*`, `nyar-unknown-wasm32`) are resolved automatically when this package is installed on a matching host.
|
|
15
|
+
|
|
16
|
+
Build collect steps (`pnpm build:napi`, `pnpm build:wasm`) live in repository maintainer docs, not on this registry page.
|
|
17
|
+
|
|
18
|
+
## License
|
|
19
|
+
|
|
20
|
+
MIT
|
package/bin/nyar.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { spawnSync } from 'node:child_process';
|
|
3
|
-
import { createRequire } from 'node:module';
|
|
4
|
-
|
|
5
|
-
import { hostPlatformKey, resolveCollect } from '../src/platform.ts';
|
|
6
|
-
|
|
7
|
-
const require = createRequire(import.meta.url);
|
|
8
|
-
const pkg = require('../package.json');
|
|
9
|
-
|
|
10
|
-
function printUsage() {
|
|
11
|
-
console.error(`@nyar/nyar ${pkg.version} (${hostPlatformKey()})`);
|
|
12
|
-
console.error('Usage: nyar <command> [args...]');
|
|
13
|
-
console.error('Commands:');
|
|
14
|
-
console.error(' host-info Print resolved platform collect metadata');
|
|
15
|
-
console.error(' version Print package version');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function cmdHostInfo() {
|
|
19
|
-
const collect = resolveCollect();
|
|
20
|
-
console.log(JSON.stringify({ version: pkg.version, host: hostPlatformKey(), collect }, null, 2));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function cmdVersion() {
|
|
24
|
-
console.log(pkg.version);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const [command, ...rest] = process.argv.slice(2);
|
|
28
|
-
|
|
29
|
-
if (!command || command === '--help' || command === '-h') {
|
|
30
|
-
printUsage();
|
|
31
|
-
process.exit(command ? 0 : 1);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (command === 'version' || command === '--version' || command === '-V') {
|
|
35
|
-
cmdVersion();
|
|
36
|
-
process.exit(0);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (command === 'host-info') {
|
|
40
|
-
cmdHostInfo();
|
|
41
|
-
process.exit(0);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Forward unknown commands to wasmtime when the wasm collect is present (maintainer / CI path).
|
|
45
|
-
const collect = resolveCollect();
|
|
46
|
-
if (collect.kind === 'wasm' && rest.length > 0) {
|
|
47
|
-
const result = spawnSync('wasmtime', [collect.entry, ...rest], { stdio: 'inherit', shell: false });
|
|
48
|
-
process.exit(result.status ?? 1);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
console.error(`nyar: unknown command '${command}'`);
|
|
52
|
-
printUsage();
|
|
53
|
-
process.exit(1);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
|
|
5
|
+
import { hostPlatformKey, resolveCollect } from '../src/platform.ts';
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const pkg = require('../package.json');
|
|
9
|
+
|
|
10
|
+
function printUsage() {
|
|
11
|
+
console.error(`@nyar/nyar ${pkg.version} (${hostPlatformKey()})`);
|
|
12
|
+
console.error('Usage: nyar <command> [args...]');
|
|
13
|
+
console.error('Commands:');
|
|
14
|
+
console.error(' host-info Print resolved platform collect metadata');
|
|
15
|
+
console.error(' version Print package version');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function cmdHostInfo() {
|
|
19
|
+
const collect = resolveCollect();
|
|
20
|
+
console.log(JSON.stringify({ version: pkg.version, host: hostPlatformKey(), collect }, null, 2));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function cmdVersion() {
|
|
24
|
+
console.log(pkg.version);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
28
|
+
|
|
29
|
+
if (!command || command === '--help' || command === '-h') {
|
|
30
|
+
printUsage();
|
|
31
|
+
process.exit(command ? 0 : 1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (command === 'version' || command === '--version' || command === '-V') {
|
|
35
|
+
cmdVersion();
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (command === 'host-info') {
|
|
40
|
+
cmdHostInfo();
|
|
41
|
+
process.exit(0);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Forward unknown commands to wasmtime when the wasm collect is present (maintainer / CI path).
|
|
45
|
+
const collect = resolveCollect();
|
|
46
|
+
if (collect.kind === 'wasm' && rest.length > 0) {
|
|
47
|
+
const result = spawnSync('wasmtime', [collect.entry, ...rest], { stdio: 'inherit', shell: false });
|
|
48
|
+
process.exit(result.status ?? 1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
console.error(`nyar: unknown command '${command}'`);
|
|
52
|
+
printUsage();
|
|
53
|
+
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nyar/nyar",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Nyar VM
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Nyar VM — cross-platform CLI (assembled from platform collects).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.ts",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@nyar/nyar-unknown-wasm32": "0.0.
|
|
21
|
+
"@nyar/nyar-unknown-wasm32": "0.0.1"
|
|
22
22
|
},
|
|
23
23
|
"optionalDependencies": {
|
|
24
|
-
"@nyar/nyar-win32-x64": "0.0.
|
|
25
|
-
"@nyar/nyar-
|
|
26
|
-
"@nyar/nyar-
|
|
27
|
-
"@nyar/nyar-darwin-arm64": "0.0.
|
|
24
|
+
"@nyar/nyar-win32-x64": "0.0.1",
|
|
25
|
+
"@nyar/nyar-linux-x64": "0.0.1",
|
|
26
|
+
"@nyar/nyar-darwin-x64": "0.0.1",
|
|
27
|
+
"@nyar/nyar-darwin-arm64": "0.0.1"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|
|
30
30
|
"node": ">=20"
|
|
@@ -42,6 +42,5 @@
|
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}
|
|
45
|
+
}
|
|
46
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
# @nyar/nyar
|
|
2
|
-
|
|
3
|
-
Cross-platform npm facade for the Nyar VM CLI and host APIs. Native and Wasm sidecars are published as separate platform packages under `projects/packages/`.
|
|
4
|
-
|
|
5
|
-
## Example
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { createNyarHost } from "@nyar/nyar";
|
|
9
|
-
|
|
10
|
-
const host = await createNyarHost();
|
|
11
|
-
await host.runBytecode(bytes);
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
Platform-specific binaries (`nyar-win32-x64`, `nyar-linux-x64`, `nyar-darwin-*`, `nyar-unknown-wasm32`) are resolved automatically when this package is installed on a matching host.
|
|
15
|
-
|
|
16
|
-
Build collect steps (`pnpm build:napi`, `pnpm build:wasm`) live in repository maintainer docs, not on this registry page.
|
|
17
|
-
|
|
18
|
-
## License
|
|
19
|
-
|
|
20
|
-
MIT
|
|
1
|
+
# @nyar/nyar
|
|
2
|
+
|
|
3
|
+
Cross-platform npm facade for the Nyar VM CLI and host APIs. Native and Wasm sidecars are published as separate platform packages under `projects/packages/`.
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { createNyarHost } from "@nyar/nyar";
|
|
9
|
+
|
|
10
|
+
const host = await createNyarHost();
|
|
11
|
+
await host.runBytecode(bytes);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Platform-specific binaries (`nyar-win32-x64`, `nyar-linux-x64`, `nyar-darwin-*`, `nyar-unknown-wasm32`) are resolved automatically when this package is installed on a matching host.
|
|
15
|
+
|
|
16
|
+
Build collect steps (`pnpm build:napi`, `pnpm build:wasm`) live in repository maintainer docs, not on this registry page.
|
|
17
|
+
|
|
18
|
+
## License
|
|
19
|
+
|
|
20
|
+
MIT
|
package/src/index.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
-
|
|
3
|
-
import { type NyarCollect, resolveCollect } from './platform.ts';
|
|
4
|
-
|
|
5
|
-
export { hostPlatformKey, type NyarCollect, resolveCollect } from './platform.ts';
|
|
6
|
-
|
|
7
|
-
export type NyarHost = {
|
|
8
|
-
/** Resolved platform collect metadata for diagnostics and tooling. */
|
|
9
|
-
collect: NyarCollect;
|
|
10
|
-
/** Load bytecode bytes (0.0.0 placeholder — execution wiring lands with Node-API host exports). */
|
|
11
|
-
runBytecode(bytes: Uint8Array): Promise<void>;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Create a Nyar host for the current platform.
|
|
16
|
-
*
|
|
17
|
-
* Native collects are preferred when the matching optional dependency is installed;
|
|
18
|
-
* otherwise the Wasm GC collect from `@nyar/nyar-unknown-wasm32` is used.
|
|
19
|
-
*/
|
|
20
|
-
export async function createNyarHost(): Promise<NyarHost> {
|
|
21
|
-
const collect = resolveCollect();
|
|
22
|
-
return {
|
|
23
|
-
collect,
|
|
24
|
-
async runBytecode(bytes: Uint8Array) {
|
|
25
|
-
if (bytes.length === 0) {
|
|
26
|
-
throw new Error('nyar host received empty bytecode payload');
|
|
27
|
-
}
|
|
28
|
-
// 0.0.0 ships collect layout only; bytecode execution is wired in the next host export drop.
|
|
29
|
-
await readFile(collect.entry);
|
|
30
|
-
throw new Error(
|
|
31
|
-
`nyar host collect resolved (${collect.kind} via ${collect.packageName}) but bytecode execution is not wired in 0.0.0`,
|
|
32
|
-
);
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** @deprecated Use {@link createNyarHost}. */
|
|
38
|
-
export const NYAR_CLI_PLACEHOLDER = 'nyar';
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
|
|
3
|
+
import { type NyarCollect, resolveCollect } from './platform.ts';
|
|
4
|
+
|
|
5
|
+
export { hostPlatformKey, type NyarCollect, resolveCollect } from './platform.ts';
|
|
6
|
+
|
|
7
|
+
export type NyarHost = {
|
|
8
|
+
/** Resolved platform collect metadata for diagnostics and tooling. */
|
|
9
|
+
collect: NyarCollect;
|
|
10
|
+
/** Load bytecode bytes (0.0.0 placeholder — execution wiring lands with Node-API host exports). */
|
|
11
|
+
runBytecode(bytes: Uint8Array): Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create a Nyar host for the current platform.
|
|
16
|
+
*
|
|
17
|
+
* Native collects are preferred when the matching optional dependency is installed;
|
|
18
|
+
* otherwise the Wasm GC collect from `@nyar/nyar-unknown-wasm32` is used.
|
|
19
|
+
*/
|
|
20
|
+
export async function createNyarHost(): Promise<NyarHost> {
|
|
21
|
+
const collect = resolveCollect();
|
|
22
|
+
return {
|
|
23
|
+
collect,
|
|
24
|
+
async runBytecode(bytes: Uint8Array) {
|
|
25
|
+
if (bytes.length === 0) {
|
|
26
|
+
throw new Error('nyar host received empty bytecode payload');
|
|
27
|
+
}
|
|
28
|
+
// 0.0.0 ships collect layout only; bytecode execution is wired in the next host export drop.
|
|
29
|
+
await readFile(collect.entry);
|
|
30
|
+
throw new Error(
|
|
31
|
+
`nyar host collect resolved (${collect.kind} via ${collect.packageName}) but bytecode execution is not wired in 0.0.0`,
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @deprecated Use {@link createNyarHost}. */
|
|
38
|
+
export const NYAR_CLI_PLACEHOLDER = 'nyar';
|
package/src/platform.ts
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
|
-
import { arch, platform } from 'node:os';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
|
|
5
|
-
const HOST_KEY = `${platform()}-${arch()}`;
|
|
6
|
-
|
|
7
|
-
const OPTIONAL_NATIVE_PACKAGES: Record<string, string> = {
|
|
8
|
-
'win32-x64': '@nyar/nyar-win32-x64',
|
|
9
|
-
'linux-x64': '@nyar/nyar-linux-x64',
|
|
10
|
-
'darwin-x64': '@nyar/nyar-darwin-x64',
|
|
11
|
-
'darwin-arm64': '@nyar/nyar-darwin-arm64',
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const WASM_PACKAGE = '@nyar/nyar-unknown-wasm32';
|
|
15
|
-
|
|
16
|
-
export type NyarCollectKind = 'native' | 'wasm';
|
|
17
|
-
|
|
18
|
-
export type NyarCollect = {
|
|
19
|
-
kind: NyarCollectKind;
|
|
20
|
-
packageName: string;
|
|
21
|
-
entry: string;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export function hostPlatformKey(): string {
|
|
25
|
-
return HOST_KEY;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function resolveNativeCollectPackage(): string | undefined {
|
|
29
|
-
return OPTIONAL_NATIVE_PACKAGES[HOST_KEY];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function resolveWasmCollectPackage(): string {
|
|
33
|
-
return WASM_PACKAGE;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function requireOptional(packageName: string): { resolve(request: string): string } | undefined {
|
|
37
|
-
const require = createRequire(fileURLToPath(import.meta.url));
|
|
38
|
-
try {
|
|
39
|
-
require.resolve(packageName);
|
|
40
|
-
return createRequire(require.resolve(`${packageName}/package.json`));
|
|
41
|
-
} catch {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function resolveCollect(): NyarCollect {
|
|
47
|
-
const nativePackage = resolveNativeCollectPackage();
|
|
48
|
-
if (nativePackage) {
|
|
49
|
-
const req = requireOptional(nativePackage);
|
|
50
|
-
if (req) {
|
|
51
|
-
const entry =
|
|
52
|
-
HOST_KEY === 'win32-x64'
|
|
53
|
-
? req.resolve('./nyar_napi.dll')
|
|
54
|
-
: req.resolve(`./libnyar_napi.${HOST_KEY.startsWith('darwin') ? 'dylib' : 'so'}`);
|
|
55
|
-
return { kind: 'native', packageName: nativePackage, entry };
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const wasmReq = requireOptional(WASM_PACKAGE);
|
|
60
|
-
if (!wasmReq) {
|
|
61
|
-
throw new Error(`missing required dependency ${WASM_PACKAGE}; install workspace collects before publishing`);
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
kind: 'wasm',
|
|
65
|
-
packageName: WASM_PACKAGE,
|
|
66
|
-
entry: wasmReq.resolve(`${WASM_PACKAGE}/nyar.wasm`),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { arch, platform } from 'node:os';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
const HOST_KEY = `${platform()}-${arch()}`;
|
|
6
|
+
|
|
7
|
+
const OPTIONAL_NATIVE_PACKAGES: Record<string, string> = {
|
|
8
|
+
'win32-x64': '@nyar/nyar-win32-x64',
|
|
9
|
+
'linux-x64': '@nyar/nyar-linux-x64',
|
|
10
|
+
'darwin-x64': '@nyar/nyar-darwin-x64',
|
|
11
|
+
'darwin-arm64': '@nyar/nyar-darwin-arm64',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const WASM_PACKAGE = '@nyar/nyar-unknown-wasm32';
|
|
15
|
+
|
|
16
|
+
export type NyarCollectKind = 'native' | 'wasm';
|
|
17
|
+
|
|
18
|
+
export type NyarCollect = {
|
|
19
|
+
kind: NyarCollectKind;
|
|
20
|
+
packageName: string;
|
|
21
|
+
entry: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function hostPlatformKey(): string {
|
|
25
|
+
return HOST_KEY;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function resolveNativeCollectPackage(): string | undefined {
|
|
29
|
+
return OPTIONAL_NATIVE_PACKAGES[HOST_KEY];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function resolveWasmCollectPackage(): string {
|
|
33
|
+
return WASM_PACKAGE;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function requireOptional(packageName: string): { resolve(request: string): string } | undefined {
|
|
37
|
+
const require = createRequire(fileURLToPath(import.meta.url));
|
|
38
|
+
try {
|
|
39
|
+
require.resolve(packageName);
|
|
40
|
+
return createRequire(require.resolve(`${packageName}/package.json`));
|
|
41
|
+
} catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function resolveCollect(): NyarCollect {
|
|
47
|
+
const nativePackage = resolveNativeCollectPackage();
|
|
48
|
+
if (nativePackage) {
|
|
49
|
+
const req = requireOptional(nativePackage);
|
|
50
|
+
if (req) {
|
|
51
|
+
const entry =
|
|
52
|
+
HOST_KEY === 'win32-x64'
|
|
53
|
+
? req.resolve('./nyar_napi.dll')
|
|
54
|
+
: req.resolve(`./libnyar_napi.${HOST_KEY.startsWith('darwin') ? 'dylib' : 'so'}`);
|
|
55
|
+
return { kind: 'native', packageName: nativePackage, entry };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const wasmReq = requireOptional(WASM_PACKAGE);
|
|
60
|
+
if (!wasmReq) {
|
|
61
|
+
throw new Error(`missing required dependency ${WASM_PACKAGE}; install workspace collects before publishing`);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
kind: 'wasm',
|
|
65
|
+
packageName: WASM_PACKAGE,
|
|
66
|
+
entry: wasmReq.resolve(`${WASM_PACKAGE}/nyar.wasm`),
|
|
67
|
+
};
|
|
68
|
+
}
|