@shapeshift-labs/frontier-lang-cli 0.3.17 → 0.3.19

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 CHANGED
@@ -9,6 +9,7 @@ frontier-lang capabilities app.frontier --target typescript --platform node
9
9
  frontier-lang import src/todo.ts --sidecar --out native-import.json
10
10
  frontier-lang native-diff src/todo.before.ts --after src/todo.after.ts --out native-change-set.json
11
11
  frontier-lang project-native native-import.json --source-only --out restored.ts
12
+ frontier-lang native-compile native-import.json --target rust --emit-on-blocked --source-only --out todo.rs
12
13
  frontier-lang native-coverage src/todo.ts
13
14
  ```
14
15
 
@@ -194,7 +195,7 @@ npm install -g @shapeshift-labs/frontier-lang-cli
194
195
  frontier-lang check examples/todo.frontier
195
196
  ```
196
197
 
197
- Commands: `parse`, `check`, `hash`, `ast`, `capabilities`, `to-json`, `from-json`, `import`, `project-native`, `native-coverage`, `native-diff`, `roundtrip`, `corpus-roundtrip`, `emit`, `emit-ts`, `emit-js`, `emit-rust`, `emit-python`, and `emit-c`.
198
+ Commands: `parse`, `check`, `hash`, `ast`, `capabilities`, `to-json`, `from-json`, `import`, `project-native`, `native-compile`, `native-coverage`, `native-diff`, `roundtrip`, `corpus-roundtrip`, `emit`, `emit-ts`, `emit-js`, `emit-rust`, `emit-python`, and `emit-c`.
198
199
 
199
200
  ```sh
200
201
  frontier-lang emit app.frontier --target rust --out app.rs
package/bench/smoke.mjs CHANGED
@@ -1,4 +1,7 @@
1
1
  import { performance } from 'node:perf_hooks';
2
+ import { mkdtempSync, writeFileSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
2
5
  import { runCli } from '../dist/index.js';
3
6
 
4
7
  const start = performance.now();
@@ -8,4 +11,13 @@ for (let index = 0; index < 100; index += 1) {
8
11
  await runCli(['emit', 'test/fixture.frontier', '--target', index % 2 ? 'javascript' : 'typescript'], { log: (value = '') => lines.push(String(value)) });
9
12
  bytes += lines.join('\n').length;
10
13
  }
11
- console.log(JSON.stringify({ emits: 100, bytes, durationMs: Number((performance.now() - start).toFixed(2)) }));
14
+ const nativeDir = mkdtempSync(join(tmpdir(), 'frontier-lang-cli-native-bench-'));
15
+ const nativePath = join(nativeDir, 'todo.js');
16
+ writeFileSync(nativePath, 'export function addTodo(title) { return { title }; }\n');
17
+ let nativeBytes = 0;
18
+ for (let index = 0; index < 25; index += 1) {
19
+ const lines = [];
20
+ await runCli(['native-compile', nativePath, '--target', index % 2 ? 'javascript' : 'rust', '--emit-on-blocked'], { log: (value = '') => lines.push(String(value)) });
21
+ nativeBytes += lines.join('\n').length;
22
+ }
23
+ console.log(JSON.stringify({ emits: 100, nativeCompiles: 25, bytes, nativeBytes, durationMs: Number((performance.now() - start).toFixed(2)) }));
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ import { parseFrontierFile, parseFrontierSource } from '@shapeshift-labs/frontie
6
6
  import { checkDocument } from '@shapeshift-labs/frontier-lang-checker';
7
7
  import { hashDocumentBase } from '@shapeshift-labs/frontier-lang-kernel';
8
8
  import {
9
+ compileNativeSource,
9
10
  compileFrontierDocument,
10
11
  createNativeSourcePreservation,
11
12
  createNativeImportCoverageMatrix,
@@ -54,6 +55,30 @@ export async function runCli(argv = process.argv.slice(2), io = console) {
54
55
  }
55
56
  return outputMaybeFile(io, rest, projection);
56
57
  }
58
+ if (command === 'native-compile') {
59
+ const parsed = tryParseJson(source);
60
+ const input = parsed ? readNativeImportForProjection(file, source, rest) : {
61
+ language: readOption(rest, '--language') ?? inferLanguage(file),
62
+ parser: readOption(rest, '--parser'),
63
+ sourcePath: readOption(rest, '--source-path') ?? file,
64
+ sourceHash: readOption(rest, '--source-hash'),
65
+ sourceText: source,
66
+ nativeAstMetadata: { sourceBytes: source.length, cli: true }
67
+ };
68
+ const result = compileNativeSource(input, {
69
+ target: readOption(rest, '--target'),
70
+ parser: readOption(rest, '--parser'),
71
+ emitOnBlocked: rest.includes('--emit-on-blocked'),
72
+ metadata: { cli: true, inputPath: file }
73
+ });
74
+ if (rest.includes('--source-only')) {
75
+ const outIndex = rest.indexOf('--out');
76
+ if (outIndex >= 0 && rest[outIndex + 1]) writeFileSync(rest[outIndex + 1], result.output);
77
+ else io.log(result.output);
78
+ return;
79
+ }
80
+ return outputMaybeFile(io, rest, result);
81
+ }
57
82
  if (command === 'native-coverage') {
58
83
  const language = readOption(rest, '--language') ?? inferLanguage(file);
59
84
  const imported = importNativeFile(file, source, rest, { language });
@@ -341,7 +366,7 @@ function idFragment(value) {
341
366
  return String(value ?? 'unknown').replace(/[^A-Za-z0-9]+/g, '_').replace(/^_+|_+$/g, '').toLowerCase() || 'unknown';
342
367
  }
343
368
 
344
- function help(io) { io.log('frontier-lang <parse|check|hash|ast|capabilities|to-json|from-json|import|project-native|native-coverage|native-diff|roundtrip|corpus-roundtrip|emit|emit-ts|emit-js|emit-rust|emit-python|emit-c> <file> [--after file] [--target target] [--language language] [--parser parser] [--platform platform] [--ast] [--sidecar] [--sidecar-only] [--source-only] [--stubs] [--out file] [--strict-effects]'); }
369
+ function help(io) { io.log('frontier-lang <parse|check|hash|ast|capabilities|to-json|from-json|import|project-native|native-compile|native-coverage|native-diff|roundtrip|corpus-roundtrip|emit|emit-ts|emit-js|emit-rust|emit-python|emit-c> <file> [--after file] [--target target] [--language language] [--parser parser] [--platform platform] [--ast] [--sidecar] [--sidecar-only] [--source-only] [--stubs] [--emit-on-blocked] [--out file] [--strict-effects]'); }
345
370
  function readOption(args, flag) { const index = args.indexOf(flag); return index >= 0 ? args[index + 1] : undefined; }
346
371
  function readIntegerOption(args, flag) {
347
372
  const value = readOption(args, flag);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshift-labs/frontier-lang-cli",
3
- "version": "0.3.17",
3
+ "version": "0.3.19",
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",
@@ -54,7 +54,7 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "@shapeshift-labs/frontier-lang-checker": "0.3.4",
57
- "@shapeshift-labs/frontier-lang-compiler": "0.2.19",
57
+ "@shapeshift-labs/frontier-lang-compiler": "0.2.20",
58
58
  "@shapeshift-labs/frontier-lang-kernel": "0.3.4",
59
59
  "@shapeshift-labs/frontier-lang-parser": "0.3.4"
60
60
  },