@elaraai/east-node-cli 1.0.68 → 1.0.70
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 +66 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +82 -0
- package/dist/cli.js.map +1 -1
- package/dist/export-functions.d.ts +29 -0
- package/dist/export-functions.d.ts.map +1 -0
- package/dist/export-functions.js +71 -0
- package/dist/export-functions.js.map +1 -0
- package/dist/export-functions.spec.d.ts +6 -0
- package/dist/export-functions.spec.d.ts.map +1 -0
- package/dist/export-functions.spec.js +104 -0
- package/dist/export-functions.spec.js.map +1 -0
- package/dist/loader.d.ts +19 -3
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +66 -8
- package/dist/loader.js.map +1 -1
- package/dist/loader.spec.js +47 -1
- package/dist/loader.spec.js.map +1 -1
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +22 -3
- package/dist/runner.js.map +1 -1
- package/dist/runner.spec.js +69 -1
- package/dist/runner.spec.js.map +1 -1
- package/dist/transpile.d.ts +58 -0
- package/dist/transpile.d.ts.map +1 -0
- package/dist/transpile.js +129 -0
- package/dist/transpile.js.map +1 -0
- package/dist/transpile.spec.d.ts +6 -0
- package/dist/transpile.spec.d.ts.map +1 -0
- package/dist/transpile.spec.js +110 -0
- package/dist/transpile.spec.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* `east-node transpile` (#628): an East IR file printed as the TypeScript
|
|
7
|
+
* `East.function` builder surface — `East.toSource` behind a CLI, the twin
|
|
8
|
+
* of `east-py transpile`.
|
|
9
|
+
*
|
|
10
|
+
* The printed module rebuilds the same IR (normalized) when imported, and a
|
|
11
|
+
* rebuild proves it here: the module is imported against this CLI's own
|
|
12
|
+
* `@elaraai/east` and the IR it builds is returned (and written, on the
|
|
13
|
+
* CLI) beside the source. That is the TypeScript leg of the cross-language
|
|
14
|
+
* round trip the east-py conformance suite drives: IR → python → IR →
|
|
15
|
+
* TypeScript → IR, every leg equal under `east-c ir normalize`.
|
|
16
|
+
*/
|
|
17
|
+
import { mkdirSync, mkdtempSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
18
|
+
import { tmpdir } from 'node:os';
|
|
19
|
+
import { basename, extname, join } from 'node:path';
|
|
20
|
+
import { pathToFileURL } from 'node:url';
|
|
21
|
+
import { encodeEastIR, encodeJSONFor, IRType, toSource } from '@elaraai/east';
|
|
22
|
+
import { loadIR } from './loader.js';
|
|
23
|
+
const IR_EXTENSIONS = new Set(['.beast2', '.beast', '.east', '.json']);
|
|
24
|
+
/**
|
|
25
|
+
* Prints an IR file as a TypeScript module, optionally rebuilding it.
|
|
26
|
+
*
|
|
27
|
+
* @param irPath - Path to the IR file (`.beast2`, `.beast`, `.east`, or `.json`)
|
|
28
|
+
* @param options - Export name, import specifier, and whether to rebuild
|
|
29
|
+
* @returns The module source, and the rebuilt IR when requested
|
|
30
|
+
* @throws When the file is not a function IR, or the IR has a shape the
|
|
31
|
+
* TypeScript surface cannot spell (`Unprintable`), or the printed module
|
|
32
|
+
* does not rebuild
|
|
33
|
+
*/
|
|
34
|
+
export async function transpile(irPath, options = {}) {
|
|
35
|
+
const name = options.name ?? 'main';
|
|
36
|
+
const importFrom = options.importFrom ?? '@elaraai/east';
|
|
37
|
+
const ir = loadIR(irPath);
|
|
38
|
+
const source = toSource(ir, { name, importFrom });
|
|
39
|
+
if (!options.rebuild)
|
|
40
|
+
return { source };
|
|
41
|
+
return { source, rebuilt: await rebuild(source, name, importFrom) };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Imports a printed module against this CLI's own `@elaraai/east` and
|
|
45
|
+
* returns what its export builds.
|
|
46
|
+
*
|
|
47
|
+
* The module's import line is the printer's own (`from "<importFrom>"`);
|
|
48
|
+
* it is retargeted at the resolved package so the module loads from a
|
|
49
|
+
* temporary directory that has no `node_modules`.
|
|
50
|
+
*/
|
|
51
|
+
async function rebuild(source, name, importFrom) {
|
|
52
|
+
const east = import.meta.resolve('@elaraai/east');
|
|
53
|
+
const retargeted = source.replace(`from ${JSON.stringify(importFrom)};`, `from ${JSON.stringify(east)};`);
|
|
54
|
+
const dir = mkdtempSync(join(tmpdir(), 'east-transpile-'));
|
|
55
|
+
try {
|
|
56
|
+
const path = join(dir, 'module.mjs');
|
|
57
|
+
writeFileSync(path, retargeted, 'utf-8');
|
|
58
|
+
const mod = await import(pathToFileURL(path).href);
|
|
59
|
+
const fn = mod[name];
|
|
60
|
+
if (fn === undefined || typeof fn.toIR !== 'function') {
|
|
61
|
+
throw new Error(`the printed module has no East function export named ${JSON.stringify(name)}`);
|
|
62
|
+
}
|
|
63
|
+
return fn.toIR();
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
rmSync(dir, { recursive: true, force: true });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Encodes a rebuilt IR for a path: `.beast2` / `.beast` as the IR bundle
|
|
71
|
+
* (source map included), `.json` as the raw IR JSON `east-node run` reads.
|
|
72
|
+
*
|
|
73
|
+
* @param eastIR - The rebuilt IR bundle
|
|
74
|
+
* @param outPath - The path it will be written to; its extension picks the format
|
|
75
|
+
* @returns The encoded bytes
|
|
76
|
+
*/
|
|
77
|
+
export function encodeRebuilt(eastIR, outPath) {
|
|
78
|
+
const ext = extname(outPath).toLowerCase();
|
|
79
|
+
if (ext === '.beast2' || ext === '.beast')
|
|
80
|
+
return encodeEastIR(eastIR);
|
|
81
|
+
if (ext === '.json')
|
|
82
|
+
return encodeJSONFor(IRType)(eastIR.ir);
|
|
83
|
+
throw new Error(`Unsupported rebuild extension "${ext}". Supported extensions: .beast2, .beast, .json`);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Transpiles every IR file in a directory: `<stem>.ts` under `outDir` for
|
|
87
|
+
* each `<stem>.<beast2|beast|east|json>`, and — when `rebuildDir` is given —
|
|
88
|
+
* `<stem>.beast2` there holding the IR each module builds.
|
|
89
|
+
*
|
|
90
|
+
* @param inDir - The directory of IR files (other files are ignored)
|
|
91
|
+
* @param outDir - Where the modules go (created)
|
|
92
|
+
* @param options - Export name, import specifier, and the rebuild directory
|
|
93
|
+
* @returns The stems transpiled, in order
|
|
94
|
+
* @throws On the first file that does not transpile, naming it
|
|
95
|
+
*/
|
|
96
|
+
export async function transpileDir(inDir, outDir, options = {}) {
|
|
97
|
+
const files = readdirSync(inDir).filter(f => IR_EXTENSIONS.has(extname(f).toLowerCase())).sort();
|
|
98
|
+
mkdirSync(outDir, { recursive: true });
|
|
99
|
+
if (options.rebuildDir !== undefined)
|
|
100
|
+
mkdirSync(options.rebuildDir, { recursive: true });
|
|
101
|
+
const stems = [];
|
|
102
|
+
for (const file of files) {
|
|
103
|
+
const stem = basename(file, extname(file));
|
|
104
|
+
let result;
|
|
105
|
+
try {
|
|
106
|
+
result = await transpile(join(inDir, file), { ...options, rebuild: options.rebuildDir !== undefined });
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
throw new Error(`${file}: ${err.message}`);
|
|
110
|
+
}
|
|
111
|
+
writeFileSync(join(outDir, `${stem}.ts`), result.source, 'utf-8');
|
|
112
|
+
if (options.rebuildDir !== undefined) {
|
|
113
|
+
const out = join(options.rebuildDir, `${stem}.beast2`);
|
|
114
|
+
writeFileSync(out, encodeRebuilt(result.rebuilt, out));
|
|
115
|
+
}
|
|
116
|
+
stems.push(stem);
|
|
117
|
+
}
|
|
118
|
+
return stems;
|
|
119
|
+
}
|
|
120
|
+
/** Whether a path is a directory. */
|
|
121
|
+
export function isDirectory(path) {
|
|
122
|
+
try {
|
|
123
|
+
return statSync(path).isDirectory();
|
|
124
|
+
}
|
|
125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EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,KAAM,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1D,CAAC;QACD,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClE,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YACnC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,IAAI,SAAS,CAAC,CAAC;YACvD,aAAa,CAAC,GAAG,EAAE,aAAa,CAAC,MAAM,CAAC,OAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;QAC5D,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,qCAAqC;AACrC,MAAM,UAAU,WAAW,CAAC,IAAY;IACpC,IAAI,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IACxC,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transpile.spec.d.ts","sourceRoot":"","sources":["../src/transpile.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Tests for `east-node transpile` (#628): an IR file prints as a TypeScript
|
|
7
|
+
* module that rebuilds the same IR, in file and directory mode, for every
|
|
8
|
+
* IR file format the loader reads.
|
|
9
|
+
*/
|
|
10
|
+
import { describe, it } from 'node:test';
|
|
11
|
+
import assert from 'node:assert/strict';
|
|
12
|
+
import { mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
13
|
+
import { tmpdir } from 'node:os';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { East, IntegerType, StringType, ArrayType, IRType, encodeEastIR, encodeJSONFor, decodeEastIR, toSource, isTypeValueEqual, } from '@elaraai/east';
|
|
16
|
+
import { transpile, transpileDir, encodeRebuilt } from './transpile.js';
|
|
17
|
+
const double = East.function([IntegerType], IntegerType, ($, x) => x.multiply(2n));
|
|
18
|
+
const greet = East.function([StringType, ArrayType(IntegerType)], StringType, ($, name, xs) => {
|
|
19
|
+
const total = $.let(0n);
|
|
20
|
+
$.for(xs, ($, x) => { $.assign(total, total.add(x)); });
|
|
21
|
+
return East.str `${name}: ${total}`;
|
|
22
|
+
});
|
|
23
|
+
function scratch() {
|
|
24
|
+
return mkdtempSync(join(tmpdir(), 'enc-transpile-'));
|
|
25
|
+
}
|
|
26
|
+
describe('east-node transpile', () => {
|
|
27
|
+
it('prints a beast2 IR file as a module that rebuilds the same IR', async () => {
|
|
28
|
+
const dir = scratch();
|
|
29
|
+
try {
|
|
30
|
+
const ir = double.toIR();
|
|
31
|
+
const path = join(dir, 'double.beast2');
|
|
32
|
+
writeFileSync(path, encodeEastIR(ir));
|
|
33
|
+
const { source, rebuilt } = await transpile(path, { rebuild: true });
|
|
34
|
+
assert.match(source, /^import \{ East, .* \} from "@elaraai\/east";$/m);
|
|
35
|
+
assert.match(source, /export const main = East\.function\(\[IntegerType\], IntegerType, \(\$, x\) => x\.multiply\(2n\)\);/);
|
|
36
|
+
assert.ok(rebuilt !== undefined);
|
|
37
|
+
// The rebuild is a fixpoint: printing it gives the same module back.
|
|
38
|
+
assert.equal(toSource(rebuilt, {}), toSource(ir, {}));
|
|
39
|
+
assert.ok(isTypeValueEqual(rebuilt.ir.value.type, ir.ir.value.type));
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
rmSync(dir, { recursive: true, force: true });
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
it('honours the export name and import specifier, and still rebuilds', async () => {
|
|
46
|
+
const dir = scratch();
|
|
47
|
+
try {
|
|
48
|
+
const path = join(dir, 'greet.json');
|
|
49
|
+
writeFileSync(path, encodeJSONFor(IRType)(greet.toIR().ir));
|
|
50
|
+
const { source, rebuilt } = await transpile(path, { name: 'greet', importFrom: '../east/index.js', rebuild: true });
|
|
51
|
+
assert.match(source, /from "\.\.\/east\/index\.js";/);
|
|
52
|
+
assert.match(source, /export const greet = East\.function\(/);
|
|
53
|
+
assert.match(source, /\$\.for\(xs, \(\$, x, _4, label\) => \{/); // the slot the body did not name stays _N (#639)
|
|
54
|
+
assert.equal(toSource(rebuilt, { name: 'greet' }), toSource(greet, { name: 'greet' }));
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
rmSync(dir, { recursive: true, force: true });
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
it('encodes a rebuilt IR by extension', async () => {
|
|
61
|
+
const dir = scratch();
|
|
62
|
+
try {
|
|
63
|
+
const path = join(dir, 'double.beast2');
|
|
64
|
+
writeFileSync(path, encodeEastIR(double.toIR()));
|
|
65
|
+
const { rebuilt } = await transpile(path, { rebuild: true });
|
|
66
|
+
const bundle = decodeEastIR(encodeRebuilt(rebuilt, join(dir, 'out.beast2')));
|
|
67
|
+
assert.equal(bundle.ir.type, 'Function');
|
|
68
|
+
const json = JSON.parse(Buffer.from(encodeRebuilt(rebuilt, join(dir, 'out.json'))).toString('utf-8'));
|
|
69
|
+
assert.equal(json.type, 'Function');
|
|
70
|
+
assert.throws(() => encodeRebuilt(rebuilt, join(dir, 'out.txt')), /Unsupported rebuild extension/);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
rmSync(dir, { recursive: true, force: true });
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
it('transpiles a directory, one module (and one rebuilt IR) per IR file', async () => {
|
|
77
|
+
const dir = scratch();
|
|
78
|
+
try {
|
|
79
|
+
const input = join(dir, 'in');
|
|
80
|
+
const out = join(dir, 'out');
|
|
81
|
+
const rebuilt = join(dir, 'rebuilt');
|
|
82
|
+
const { mkdirSync } = await import('node:fs');
|
|
83
|
+
mkdirSync(input);
|
|
84
|
+
writeFileSync(join(input, 'double.beast2'), encodeEastIR(double.toIR()));
|
|
85
|
+
writeFileSync(join(input, 'greet.json'), encodeJSONFor(IRType)(greet.toIR().ir));
|
|
86
|
+
writeFileSync(join(input, 'notes.txt'), 'not an IR file');
|
|
87
|
+
const stems = await transpileDir(input, out, { rebuildDir: rebuilt });
|
|
88
|
+
assert.deepEqual(stems, ['double', 'greet']);
|
|
89
|
+
assert.deepEqual(readdirSync(out).sort(), ['double.ts', 'greet.ts']);
|
|
90
|
+
assert.deepEqual(readdirSync(rebuilt).sort(), ['double.beast2', 'greet.beast2']);
|
|
91
|
+
assert.match(readFileSync(join(out, 'greet.ts'), 'utf-8'), /export const main = East\.function\(/);
|
|
92
|
+
assert.equal(toSource(decodeEastIR(readFileSync(join(rebuilt, 'greet.beast2'))), {}), toSource(greet, {}));
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
rmSync(dir, { recursive: true, force: true });
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
it('rejects an IR file whose root is not a function', async () => {
|
|
99
|
+
const dir = scratch();
|
|
100
|
+
try {
|
|
101
|
+
const path = join(dir, 'value.json');
|
|
102
|
+
writeFileSync(path, JSON.stringify({ type: 'Value', value: { type: { type: 'Integer', value: null }, loc_id: '0', value: { type: 'Integer', value: '1' } } }));
|
|
103
|
+
await assert.rejects(transpile(path), /must contain a function/);
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
rmSync(dir, { recursive: true, force: true });
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=transpile.spec.js.map
|
|
@@ -0,0 +1 @@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AAC,CAAC,CAAC;QAC/G,CAAC;gBAAS,CAAC;YACP,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iDAAiD,EAAE,KAAK,IAAI,EAAE;QAC7D,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;QACtB,IAAI,CAAC;YACD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;YACrC,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;YAC/J,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,yBAAyB,CAAC,CAAC;QACrE,CAAC;gBAAS,CAAC;YACP,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elaraai/east-node-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.70",
|
|
4
4
|
"description": "Command-line interface for running East IR programs with Node.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"east-node": "./bin/east-node.mjs"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"tar-stream": "^3.1.7"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@elaraai/east": "1.0.
|
|
47
|
+
"@elaraai/east": "1.0.70"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/node": "^22.18.1",
|