@shapeshift-labs/frontier-lang-cli 0.3.1 → 0.3.2

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.
@@ -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,14 +4,61 @@ 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 { compileFrontierDocument, projectFrontierAst, resolveCapabilityAdapters } from '@shapeshift-labs/frontier-lang-compiler';
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 output(io, importNativeSource({
32
+ language,
33
+ parser: readOption(rest, '--parser'),
34
+ sourcePath: file,
35
+ sourceHash: readOption(rest, '--source-hash'),
36
+ nativeAstMetadata: { sourceBytes: source.length }
37
+ }));
38
+ }
14
39
  const document = file ? parseFrontierFile(file, source) : parseFrontierSource(source);
40
+ if (command === 'to-json') {
41
+ return io.log(writeUniversalAstJson(createUniversalAstFromDocument(document, {
42
+ id: readOption(rest, '--id'),
43
+ evidence: [{ id: 'frontier_lang_cli_to_json', kind: 'import', status: 'passed', path: file, summary: 'Converted Frontier source to universal AST JSON envelope.' }]
44
+ })));
45
+ }
46
+ if (command === 'roundtrip') {
47
+ const target = readOption(rest, '--target') ?? 'typescript';
48
+ const envelope = createUniversalAstFromDocument(document, {
49
+ id: readOption(rest, '--id'),
50
+ evidence: [{ id: 'frontier_lang_cli_roundtrip', kind: 'test', status: 'passed', path: file, summary: `Parsed Frontier source and emitted ${target}.` }]
51
+ });
52
+ const result = compileFrontierDocument(envelope.document, { target, check: { strictEffects: rest.includes('--strict-effects') } });
53
+ return output(io, {
54
+ ok: result.ok,
55
+ target: result.target,
56
+ hash: result.hash,
57
+ envelope,
58
+ diagnostics: result.diagnostics,
59
+ output: result.output
60
+ });
61
+ }
15
62
  if (command === 'parse') return output(io, document);
16
63
  if (command === 'check') return output(io, checkDocument(document, { strictEffects: rest.includes('--strict-effects') }));
17
64
  if (command === 'hash') return io.log(hashDocumentBase(document));
@@ -39,8 +86,23 @@ export async function runCli(argv = process.argv.slice(2), io = console) {
39
86
  throw new Error(`Unknown command: ${command}`);
40
87
  }
41
88
  function output(io, value) { io.log(JSON.stringify(value, null, 2)); }
42
- function help(io) { io.log('frontier-lang <parse|check|hash|ast|capabilities|emit|emit-ts|emit-js|emit-rust|emit-python|emit-c> <file.frontier> [--target target] [--platform platform] [--ast] [--out file] [--strict-effects]'); }
89
+ 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
90
  function readOption(args, flag) { const index = args.indexOf(flag); return index >= 0 ? args[index + 1] : undefined; }
91
+ function inferLanguage(file) {
92
+ if (!file) return 'unknown';
93
+ if (/\.[cm]?tsx?$/.test(file)) return 'typescript';
94
+ if (/\.m?jsx?$/.test(file)) return 'javascript';
95
+ if (/\.rs$/.test(file)) return 'rust';
96
+ if (/\.py$/.test(file)) return 'python';
97
+ if (/\.c$/.test(file)) return 'c';
98
+ if (/\.cpp$|\.cc$|\.cxx$|\.hpp$|\.h$/.test(file)) return 'cpp';
99
+ if (/\.go$/.test(file)) return 'go';
100
+ if (/\.java$/.test(file)) return 'java';
101
+ if (/\.kt$/.test(file)) return 'kotlin';
102
+ if (/\.cs$/.test(file)) return 'csharp';
103
+ if (/\.swift$/.test(file)) return 'swift';
104
+ return 'unknown';
105
+ }
44
106
 
45
107
  function isDirectInvocation() {
46
108
  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.1",
3
+ "version": "0.3.2",
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.1"
57
+ "@shapeshift-labs/frontier-lang-compiler": "0.2.2",
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
  }