@nyar/valkyrie 0.0.0 → 0.0.14

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,34 @@
1
+ # @nyar/valkyrie
2
+
3
+ Valkyrie npm 包装层。安装后提供 `asgard` 与 `legion` 两个命令;命令的参数解析、
4
+ 编译与执行由 `valkyrie-napi` 原生绑定承担,Rust 实现位于
5
+ `projects/nyar.rs/languages/rusty-valkyrie`,绑定 crate 为
6
+ `projects/nyar.rs/ffis/valkyrie-napi`。本包不重复实现 CLI 或编译逻辑。
7
+
8
+ ## 依赖顺序
9
+
10
+ ```text
11
+ @nyar/valkyrie ──► @nyar/valkyrie-<platform> ──► valkyrie-napi ──► rusty-valkyrie product
12
+ ```
13
+
14
+ 平台包按当前 OS/arch 选择;`@nyar/valkyrie` 不依赖 `@nyar/nyar`,Nyar 宿主 API
15
+ 与 Valkyrie 产品面各自独立。
16
+
17
+ ## 用法
18
+
19
+ ```bash
20
+ legion --help
21
+ asgard --help
22
+ ```
23
+
24
+ `--help` / `--version` 等选项由 Rust 侧解析,JS 入口只转发命令名与 argv。
25
+
26
+ ## 导出
27
+
28
+ - `PACKAGE_NAME` / `PACKAGE_VERSION`:包装层身份与版本
29
+ - `COMMANDS`:本包提供的命令名
30
+ - `runValkyrieCli`:来自本包 `valkyrie-napi` 绑定的命令执行入口
31
+
32
+ ## License
33
+
34
+ MIT
package/bin/asgard.mjs CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node --experimental-strip-types
1
+ #!/usr/bin/env node
2
2
  /**
3
3
  * `asgard` 命令入口。
4
4
  *
@@ -6,6 +6,6 @@
6
6
  * 转发命令名与 argv,不复制 `--help` / `--version` 等 CLI 语义。
7
7
  */
8
8
 
9
- import {runValkyrieCli} from '../src/index.ts';
9
+ import {runValkyrieCli} from '../dist/index.js';
10
10
 
11
11
  process.exit(await runValkyrieCli('asgard', process.argv.slice(2)));
package/bin/legion.mjs CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node --experimental-strip-types
1
+ #!/usr/bin/env node
2
2
  /**
3
3
  * `legion` 命令入口。
4
4
  *
@@ -6,6 +6,6 @@
6
6
  * 转发命令名与 argv,不复制 `--help` / `--version` 等 CLI 语义。
7
7
  */
8
8
 
9
- import {runValkyrieCli} from '../src/index.ts';
9
+ import {runValkyrieCli} from '../dist/index.js';
10
10
 
11
11
  process.exit(await runValkyrieCli('legion', process.argv.slice(2)));
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * `@nyar/valkyrie` —— Valkyrie npm 包装层。
3
+ *
4
+ * 本包只声明命令与导出身份;CLI 解析、编译与平台绑定选择全部委托给
5
+ * `valkyrie-napi`,Rust 实现位于 `projects/nyar.rs/languages/rusty-valkyrie`。
6
+ */
7
+
8
+ /** npm 包名。 */
9
+ export const PACKAGE_NAME = '@nyar/valkyrie';
10
+
11
+ /** 包装层版本。 */
12
+ export const PACKAGE_VERSION = '0.0.14';
13
+
14
+ /** 本包安装后提供的命令。 */
15
+ export const COMMANDS = ['legion', 'asgard'] ;
16
+
17
+ /** 命令名。 */
18
+
19
+
20
+ export {runValkyrieCli, } from './native.js';
package/dist/native.js ADDED
@@ -0,0 +1,99 @@
1
+ import {createRequire} from 'node:module';
2
+ import {existsSync} from 'node:fs';
3
+ import {arch, platform} from 'node:os';
4
+ import path from 'node:path';
5
+ import {fileURLToPath} from 'node:url';
6
+
7
+ /** Valkyrie 编译器 CLI 产品名。 */
8
+
9
+
10
+ /** `valkyrie-napi` 导出的产品面。 */
11
+
12
+
13
+
14
+
15
+ const pkgRoot = path.dirname(fileURLToPath(import.meta.url));
16
+ const require = createRequire(import.meta.url);
17
+
18
+ /** Host triple used for platform-named native binaries (`valkyrie.<triple>.node`). */
19
+ export function platformTriple() {
20
+ const os = platform();
21
+ const cpu = arch();
22
+ if (os === 'win32' && cpu === 'x64') return 'win32-x64-msvc';
23
+ if (os === 'linux' && cpu === 'x64') return 'linux-x64-gnu';
24
+ if (os === 'darwin' && cpu === 'arm64') return 'darwin-arm64';
25
+ if (os === 'darwin' && cpu === 'x64') return 'darwin-x64';
26
+ return `${os}-${cpu}`;
27
+ }
28
+
29
+ /** npm platform short id (`win32-x64`, …) from host OS. */
30
+ export function platformShort(triple = platformTriple()) {
31
+ if (triple.startsWith('win32-')) return 'win32-x64';
32
+ if (triple.startsWith('linux-')) return 'linux-x64';
33
+ if (triple === 'darwin-arm64') return 'darwin-arm64';
34
+ if (triple === 'darwin-x64') return 'darwin-x64';
35
+ return triple;
36
+ }
37
+
38
+ /** Host triple used for platform-named native binaries (`valkyrie.<triple>.node`). */
39
+ export function nativeBinaryName(triple = platformTriple()) {
40
+ return `valkyrie.${triple}.node`;
41
+ }
42
+
43
+ /** 当前宿主 OS/arch 的 npm 平台标识。 */
44
+ export function hostPlatformKey() {
45
+ return `${platform()}-${arch()}`;
46
+ }
47
+
48
+ /**
49
+ * Resolve native `.node` via the platform optionalDependency (`@nyar/valkyrie-<short>`).
50
+ */
51
+ export function resolveNativePath() {
52
+ const triple = platformTriple();
53
+ const short = platformShort(triple);
54
+ const packageName = `@nyar/valkyrie-${short}`;
55
+ const binary = nativeBinaryName(triple);
56
+ const candidates = [];
57
+
58
+ try {
59
+ const pkgJson = require.resolve(`${packageName}/package.json`);
60
+ const pkgDir = path.dirname(pkgJson);
61
+ candidates.push(path.join(pkgDir, 'lib', binary));
62
+ candidates.push(path.join(pkgDir, binary));
63
+ } catch {
64
+ /* optional dep not installed */
65
+ }
66
+
67
+ candidates.push(path.join(pkgRoot, '..', '..', '..', 'platforms', `valkyrie-${short}`, 'lib', binary));
68
+ candidates.push(path.join(pkgRoot, '..', '..', '..', 'platforms', `valkyrie-${short}`, binary));
69
+ candidates.push(path.join(pkgRoot, '..', 'node_modules', packageName, 'lib', binary));
70
+ candidates.push(path.join(pkgRoot, 'node_modules', packageName, 'lib', binary));
71
+
72
+ for (const candidate of candidates) {
73
+ if (existsSync(candidate)) return candidate;
74
+ }
75
+
76
+ throw new Error(
77
+ `valkyrie native addon not found for ${packageName}. Run: node scripts/build.mjs napi\n` +
78
+ `Looked in:\n${candidates.map((c) => ` - ${c}`).join('\n')}\n` +
79
+ `(host ${hostPlatformKey()})`,
80
+ );
81
+ }
82
+
83
+ let nativeAddon ;
84
+
85
+ /** 加载当前平台的 valkyrie-napi 绑定。 */
86
+ export function loadNative() {
87
+ if (nativeAddon) return nativeAddon;
88
+ nativeAddon = require(resolveNativePath()) ;
89
+ return nativeAddon;
90
+ }
91
+
92
+ /**
93
+ * 通过 valkyrie-napi 执行 Valkyrie CLI,原样返回退出码。
94
+ *
95
+ * argv 不解析、不改写;`--help` / `--version` 等语义全部由 Rust CLI 承担。
96
+ */
97
+ export async function runValkyrieCli(product , argv ) {
98
+ return loadNative().runValkyrieCli(product, argv);
99
+ }
package/package.json CHANGED
@@ -1,20 +1,35 @@
1
1
  {
2
- "bin": {
3
- "asgard": "bin/asgard.mjs",
4
- "legion": "bin/legion.mjs"
5
- },
2
+ "name": "@nyar/valkyrie",
3
+ "version": "0.0.14",
6
4
  "description": "Valkyrie language package - Asgard and Legion commands",
7
- "engines": {
8
- "node": ">=20"
9
- },
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "main": "./dist/index.js",
10
8
  "exports": {
11
- ".": "./src/index.ts"
9
+ ".": "./dist/index.js"
10
+ },
11
+ "bin": {
12
+ "legion": "bin/legion.mjs",
13
+ "asgard": "bin/asgard.mjs"
12
14
  },
13
15
  "files": [
14
16
  "bin",
17
+ "dist",
15
18
  "src",
16
19
  "readme.md"
17
20
  ],
21
+ "scripts": {
22
+ "build": "node ../../../../scripts/build-npm-package-js.mjs projects/nyar.ts/emulators/valkyrie"
23
+ },
24
+ "optionalDependencies": {
25
+ "@nyar/valkyrie-darwin-arm64": "0.0.14",
26
+ "@nyar/valkyrie-darwin-x64": "0.0.14",
27
+ "@nyar/valkyrie-linux-x64": "0.0.14",
28
+ "@nyar/valkyrie-win32-x64": "0.0.14"
29
+ },
30
+ "engines": {
31
+ "node": ">=22.18.0"
32
+ },
18
33
  "keywords": [
19
34
  "nyar",
20
35
  "nyar-vm",
@@ -22,23 +37,12 @@
22
37
  "asgard",
23
38
  "legion"
24
39
  ],
25
- "license": "MIT",
26
- "main": "src/index.ts",
27
- "name": "@nyar/valkyrie",
28
- "optionalDependencies": {
29
- "@nyar/valkyrie-darwin-arm64": "0.0.0",
30
- "@nyar/valkyrie-darwin-x64": "0.0.0",
31
- "@nyar/valkyrie-linux-x64": "0.0.0",
32
- "@nyar/valkyrie-win32-x64": "0.0.0"
33
- },
34
- "publishConfig": {
35
- "access": "public"
36
- },
37
40
  "repository": {
38
- "directory": "projects/nyar.ts/emulators/valkyrie",
39
41
  "type": "git",
40
- "url": "git+https://github.com/nyar-vm/nyar-vm.git"
42
+ "url": "git+https://github.com/nyar-vm/nyar-vm.git",
43
+ "directory": "projects/nyar.ts/emulators/valkyrie"
41
44
  },
42
- "type": "module",
43
- "version": "0.0.0"
45
+ "publishConfig": {
46
+ "access": "public"
47
+ }
44
48
  }
package/src/index.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  export const PACKAGE_NAME = '@nyar/valkyrie';
10
10
 
11
11
  /** 包装层版本。 */
12
- export const PACKAGE_VERSION = '0.0.13';
12
+ export const PACKAGE_VERSION = '0.0.14';
13
13
 
14
14
  /** 本包安装后提供的命令。 */
15
15
  export const COMMANDS = ['legion', 'asgard'] as const;