@shapeshift-labs/frontier-lang-cli 0.3.1 → 0.3.3
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/bench/smoke.mjs +11 -0
- package/benchmarks/package-bench.mjs +1 -0
- package/dist/index.js +72 -4
- package/package.json +11 -5
package/bench/smoke.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { performance } from 'node:perf_hooks';
|
|
2
|
+
import { runCli } from '../dist/index.js';
|
|
3
|
+
|
|
4
|
+
const start = performance.now();
|
|
5
|
+
let bytes = 0;
|
|
6
|
+
for (let index = 0; index < 100; index += 1) {
|
|
7
|
+
const lines = [];
|
|
8
|
+
await runCli(['emit', 'test/fixture.frontier', '--target', index % 2 ? 'javascript' : 'typescript'], { log: (value = '') => lines.push(String(value)) });
|
|
9
|
+
bytes += lines.join('\n').length;
|
|
10
|
+
}
|
|
11
|
+
console.log(JSON.stringify({ emits: 100, bytes, durationMs: Number((performance.now() - start).toFixed(2)) }));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '../bench/smoke.mjs';
|
package/dist/index.js
CHANGED
|
@@ -4,16 +4,64 @@ import { fileURLToPath } from 'node:url';
|
|
|
4
4
|
import { parseFrontierFile, parseFrontierSource } from '@shapeshift-labs/frontier-lang-parser';
|
|
5
5
|
import { checkDocument } from '@shapeshift-labs/frontier-lang-checker';
|
|
6
6
|
import { hashDocumentBase } from '@shapeshift-labs/frontier-lang-kernel';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
compileFrontierDocument,
|
|
9
|
+
createUniversalAstFromDocument,
|
|
10
|
+
importNativeSource,
|
|
11
|
+
projectFrontierAst,
|
|
12
|
+
readUniversalAstJson,
|
|
13
|
+
resolveCapabilityAdapters,
|
|
14
|
+
writeUniversalAstJson
|
|
15
|
+
} from '@shapeshift-labs/frontier-lang-compiler';
|
|
8
16
|
|
|
9
17
|
export async function runCli(argv = process.argv.slice(2), io = console) {
|
|
10
18
|
const [command, file, ...rest] = argv;
|
|
11
19
|
if (!command || command === 'help' || command === '--help') return help(io);
|
|
12
20
|
if (!file && command !== 'version') throw new Error(`Missing input file for ${command}`);
|
|
13
21
|
const source = file ? readFileSync(file, 'utf8') : '';
|
|
22
|
+
if (command === 'from-json') {
|
|
23
|
+
const envelope = readUniversalAstJson(source);
|
|
24
|
+
const target = readOption(rest, '--target') ?? 'typescript';
|
|
25
|
+
const result = compileFrontierDocument(envelope.document, { target, check: { strictEffects: rest.includes('--strict-effects') } });
|
|
26
|
+
if (rest.includes('--ast')) return output(io, result.ast);
|
|
27
|
+
return io.log(result.output);
|
|
28
|
+
}
|
|
29
|
+
if (command === 'import') {
|
|
30
|
+
const language = readOption(rest, '--language') ?? inferLanguage(file);
|
|
31
|
+
return outputMaybeFile(io, rest, importNativeSource({
|
|
32
|
+
language,
|
|
33
|
+
parser: readOption(rest, '--parser'),
|
|
34
|
+
sourcePath: file,
|
|
35
|
+
sourceHash: readOption(rest, '--source-hash'),
|
|
36
|
+
sourceText: source,
|
|
37
|
+
nativeAstMetadata: { sourceBytes: source.length }
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
14
40
|
const document = file ? parseFrontierFile(file, source) : parseFrontierSource(source);
|
|
15
|
-
if (command === '
|
|
16
|
-
|
|
41
|
+
if (command === 'to-json') {
|
|
42
|
+
return io.log(writeUniversalAstJson(createUniversalAstFromDocument(document, {
|
|
43
|
+
id: readOption(rest, '--id'),
|
|
44
|
+
evidence: [{ id: 'frontier_lang_cli_to_json', kind: 'import', status: 'passed', path: file, summary: 'Converted Frontier source to universal AST JSON envelope.' }]
|
|
45
|
+
})));
|
|
46
|
+
}
|
|
47
|
+
if (command === 'roundtrip') {
|
|
48
|
+
const target = readOption(rest, '--target') ?? 'typescript';
|
|
49
|
+
const envelope = createUniversalAstFromDocument(document, {
|
|
50
|
+
id: readOption(rest, '--id'),
|
|
51
|
+
evidence: [{ id: 'frontier_lang_cli_roundtrip', kind: 'test', status: 'passed', path: file, summary: `Parsed Frontier source and emitted ${target}.` }]
|
|
52
|
+
});
|
|
53
|
+
const result = compileFrontierDocument(envelope.document, { target, check: { strictEffects: rest.includes('--strict-effects') } });
|
|
54
|
+
return outputMaybeFile(io, rest, {
|
|
55
|
+
ok: result.ok,
|
|
56
|
+
target: result.target,
|
|
57
|
+
hash: result.hash,
|
|
58
|
+
envelope,
|
|
59
|
+
diagnostics: result.diagnostics,
|
|
60
|
+
output: result.output
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (command === 'parse') return outputMaybeFile(io, rest, document);
|
|
64
|
+
if (command === 'check') return outputMaybeFile(io, rest, checkDocument(document, { strictEffects: rest.includes('--strict-effects') }));
|
|
17
65
|
if (command === 'hash') return io.log(hashDocumentBase(document));
|
|
18
66
|
if (command === 'ast') {
|
|
19
67
|
const target = readOption(rest, '--target') ?? 'typescript';
|
|
@@ -39,8 +87,28 @@ export async function runCli(argv = process.argv.slice(2), io = console) {
|
|
|
39
87
|
throw new Error(`Unknown command: ${command}`);
|
|
40
88
|
}
|
|
41
89
|
function output(io, value) { io.log(JSON.stringify(value, null, 2)); }
|
|
42
|
-
function
|
|
90
|
+
function outputMaybeFile(io, args, value) {
|
|
91
|
+
const json = JSON.stringify(value, null, 2);
|
|
92
|
+
const outIndex = args.indexOf('--out');
|
|
93
|
+
if (outIndex >= 0 && args[outIndex + 1]) writeFileSync(args[outIndex + 1], json + '\n'); else io.log(json);
|
|
94
|
+
}
|
|
95
|
+
function help(io) { io.log('frontier-lang <parse|check|hash|ast|capabilities|to-json|from-json|import|roundtrip|emit|emit-ts|emit-js|emit-rust|emit-python|emit-c> <file> [--target target] [--language language] [--parser parser] [--platform platform] [--ast] [--out file] [--strict-effects]'); }
|
|
43
96
|
function readOption(args, flag) { const index = args.indexOf(flag); return index >= 0 ? args[index + 1] : undefined; }
|
|
97
|
+
function inferLanguage(file) {
|
|
98
|
+
if (!file) return 'unknown';
|
|
99
|
+
if (/\.[cm]?tsx?$/.test(file)) return 'typescript';
|
|
100
|
+
if (/\.m?jsx?$/.test(file)) return 'javascript';
|
|
101
|
+
if (/\.rs$/.test(file)) return 'rust';
|
|
102
|
+
if (/\.py$/.test(file)) return 'python';
|
|
103
|
+
if (/\.c$/.test(file)) return 'c';
|
|
104
|
+
if (/\.cpp$|\.cc$|\.cxx$|\.hpp$|\.h$/.test(file)) return 'cpp';
|
|
105
|
+
if (/\.go$/.test(file)) return 'go';
|
|
106
|
+
if (/\.java$/.test(file)) return 'java';
|
|
107
|
+
if (/\.kt$/.test(file)) return 'kotlin';
|
|
108
|
+
if (/\.cs$/.test(file)) return 'csharp';
|
|
109
|
+
if (/\.swift$/.test(file)) return 'swift';
|
|
110
|
+
return 'unknown';
|
|
111
|
+
}
|
|
44
112
|
|
|
45
113
|
function isDirectInvocation() {
|
|
46
114
|
if (!process.argv[1]) return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshift-labs/frontier-lang-cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Command line interface for parsing, checking, hashing, and emitting Frontier Lang projects.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,11 +16,14 @@
|
|
|
16
16
|
"dist",
|
|
17
17
|
"examples",
|
|
18
18
|
"README.md",
|
|
19
|
-
"LICENSE"
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"bench",
|
|
21
|
+
"benchmarks/package-bench.mjs"
|
|
20
22
|
],
|
|
21
23
|
"scripts": {
|
|
22
24
|
"build": "node scripts/build.mjs",
|
|
23
25
|
"test": "npm run build && node test/smoke.mjs",
|
|
26
|
+
"typecheck": "node ./node_modules/typescript/bin/tsc --noEmit -p test/tsconfig.json",
|
|
24
27
|
"fuzz": "npm run build && node fuzz/smoke.mjs",
|
|
25
28
|
"bench": "npm run build && node bench/smoke.mjs",
|
|
26
29
|
"prepare": "npm run build",
|
|
@@ -50,12 +53,15 @@
|
|
|
50
53
|
"access": "public"
|
|
51
54
|
},
|
|
52
55
|
"dependencies": {
|
|
53
|
-
"@shapeshift-labs/frontier-lang-kernel": "0.3.0",
|
|
54
|
-
"@shapeshift-labs/frontier-lang-parser": "0.3.0",
|
|
55
56
|
"@shapeshift-labs/frontier-lang-checker": "0.3.0",
|
|
56
|
-
"@shapeshift-labs/frontier-lang-compiler": "0.2.
|
|
57
|
+
"@shapeshift-labs/frontier-lang-compiler": "0.2.3",
|
|
58
|
+
"@shapeshift-labs/frontier-lang-kernel": "0.3.1",
|
|
59
|
+
"@shapeshift-labs/frontier-lang-parser": "0.3.0"
|
|
57
60
|
},
|
|
58
61
|
"bin": {
|
|
59
62
|
"frontier-lang": "dist/index.js"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"typescript": "^5.9.3"
|
|
60
66
|
}
|
|
61
67
|
}
|