@synergenius/flow-weaver 0.12.0 → 0.12.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.
- package/dist/api/compile.js +1 -3
- package/dist/api/generate.js +7 -3
- package/dist/api/inline-runtime.d.ts +11 -2
- package/dist/api/inline-runtime.js +31 -4
- package/dist/cli/flow-weaver.mjs +2623 -177
- package/dist/generated-version.d.ts +2 -0
- package/dist/generated-version.js +3 -0
- package/package.json +2 -1
package/dist/api/compile.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
|
-
import { createRequire } from 'node:module';
|
|
3
2
|
import * as path from 'node:path';
|
|
4
|
-
|
|
5
|
-
const { version: COMPILER_VERSION } = require('../../package.json');
|
|
3
|
+
import { VERSION as COMPILER_VERSION } from '../generated-version.js';
|
|
6
4
|
import { generateCode } from './generate.js';
|
|
7
5
|
import { generateInPlace } from './generate-in-place.js';
|
|
8
6
|
import { parseWorkflow } from './parse.js';
|
package/dist/api/generate.js
CHANGED
|
@@ -3,7 +3,7 @@ import { extractExitPorts, extractStartPorts, hasBranching } from '../ast/workfl
|
|
|
3
3
|
import { isExecutePort } from '../constants.js';
|
|
4
4
|
import { mapToTypeScript } from '../type-mappings.js';
|
|
5
5
|
import { SourceMapGenerator } from 'source-map';
|
|
6
|
-
import { generateInlineRuntime, generateInlineDebugClient } from './inline-runtime.js';
|
|
6
|
+
import { generateInlineRuntime, generateInlineDebugClient, stripTypeScript } from './inline-runtime.js';
|
|
7
7
|
import { validateWorkflowAsync } from '../generator/async-detection.js';
|
|
8
8
|
import { extractTypeDeclarationsFromFile } from './extract-types.js';
|
|
9
9
|
import * as path from 'node:path';
|
|
@@ -38,7 +38,7 @@ export function generateModuleExports(functionNames) {
|
|
|
38
38
|
return `module.exports = { ${functionNames.join(', ')} };`;
|
|
39
39
|
}
|
|
40
40
|
export function generateCode(ast, options) {
|
|
41
|
-
const { production = false, sourceMap = false, allWorkflows = [], moduleFormat = 'esm', externalRuntimePath, constants = [], externalNodeTypes = {}, generateStubs = false, } = options || {};
|
|
41
|
+
const { production = false, sourceMap = false, allWorkflows = [], moduleFormat = 'esm', externalRuntimePath, constants = [], externalNodeTypes = {}, generateStubs = false, outputFormat = 'typescript', } = options || {};
|
|
42
42
|
// Check for stub nodes — refuse to generate unless explicitly allowed
|
|
43
43
|
const stubNodeTypes = ast.nodeTypes.filter((nt) => nt.variant === 'STUB');
|
|
44
44
|
if (stubNodeTypes.length > 0 && !generateStubs) {
|
|
@@ -435,7 +435,11 @@ export function generateCode(ast, options) {
|
|
|
435
435
|
lines.push(generateModuleExports([ast.functionName]));
|
|
436
436
|
addLine();
|
|
437
437
|
}
|
|
438
|
-
|
|
438
|
+
let code = lines.join('\n');
|
|
439
|
+
// Strip TypeScript syntax when outputFormat is 'javascript'
|
|
440
|
+
if (outputFormat === 'javascript') {
|
|
441
|
+
code = stripTypeScript(code);
|
|
442
|
+
}
|
|
439
443
|
// Set source content for the source map
|
|
440
444
|
if (sourceMapGenerator && ast.sourceFile) {
|
|
441
445
|
const sourceContent = fs.readFileSync(ast.sourceFile, 'utf8');
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export type TOutputFormat = 'typescript' | 'javascript';
|
|
2
|
+
/**
|
|
3
|
+
* Strip TypeScript type syntax from code using esbuild.
|
|
4
|
+
* Removes type declarations, interfaces, declare statements, and type annotations
|
|
5
|
+
* while preserving runtime JavaScript code.
|
|
6
|
+
*/
|
|
7
|
+
export declare function stripTypeScript(code: string): string;
|
|
1
8
|
/**
|
|
2
9
|
* Generates inline runtime code for standalone execution
|
|
3
10
|
*
|
|
@@ -6,16 +13,18 @@
|
|
|
6
13
|
*
|
|
7
14
|
* @param production - Whether to generate production-optimized code (no debug events)
|
|
8
15
|
* @param exportClasses - Whether to add 'export' keyword to classes (for shared modules)
|
|
16
|
+
* @param outputFormat - Output format: 'typescript' (default) or 'javascript' (strips types)
|
|
9
17
|
*/
|
|
10
|
-
export declare function generateInlineRuntime(production: boolean, exportClasses?: boolean): string;
|
|
18
|
+
export declare function generateInlineRuntime(production: boolean, exportClasses?: boolean, outputFormat?: TOutputFormat): string;
|
|
11
19
|
import type { TModuleFormat } from '../ast/types.js';
|
|
12
20
|
/**
|
|
13
21
|
* Generates inline WebSocket debug client for auto-detection from env var
|
|
14
22
|
* Only included in development mode builds
|
|
15
23
|
*
|
|
16
24
|
* @param moduleFormat - The module format to use for imports ('esm' or 'cjs')
|
|
25
|
+
* @param outputFormat - Output format: 'typescript' (default) or 'javascript' (strips types)
|
|
17
26
|
*/
|
|
18
|
-
export declare function generateInlineDebugClient(moduleFormat?: TModuleFormat): string;
|
|
27
|
+
export declare function generateInlineDebugClient(moduleFormat?: TModuleFormat, outputFormat?: TOutputFormat): string;
|
|
19
28
|
/**
|
|
20
29
|
* Generates a standalone runtime module file for multi-workflow bundles.
|
|
21
30
|
* This exports all runtime types and classes so individual workflow files can import them.
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { getGeneratedBranding } from '../generated-branding.js';
|
|
2
|
+
import { transformSync } from 'esbuild';
|
|
3
|
+
/**
|
|
4
|
+
* Strip TypeScript type syntax from code using esbuild.
|
|
5
|
+
* Removes type declarations, interfaces, declare statements, and type annotations
|
|
6
|
+
* while preserving runtime JavaScript code.
|
|
7
|
+
*/
|
|
8
|
+
export function stripTypeScript(code) {
|
|
9
|
+
const result = transformSync(code, {
|
|
10
|
+
loader: 'ts',
|
|
11
|
+
target: 'es2020',
|
|
12
|
+
// Keep the code readable (no minification)
|
|
13
|
+
minify: false,
|
|
14
|
+
// Preserve formatting as much as possible
|
|
15
|
+
keepNames: true,
|
|
16
|
+
});
|
|
17
|
+
return result.code;
|
|
18
|
+
}
|
|
2
19
|
/**
|
|
3
20
|
* Generates inline runtime code for standalone execution
|
|
4
21
|
*
|
|
@@ -7,8 +24,9 @@ import { getGeneratedBranding } from '../generated-branding.js';
|
|
|
7
24
|
*
|
|
8
25
|
* @param production - Whether to generate production-optimized code (no debug events)
|
|
9
26
|
* @param exportClasses - Whether to add 'export' keyword to classes (for shared modules)
|
|
27
|
+
* @param outputFormat - Output format: 'typescript' (default) or 'javascript' (strips types)
|
|
10
28
|
*/
|
|
11
|
-
export function generateInlineRuntime(production, exportClasses = false) {
|
|
29
|
+
export function generateInlineRuntime(production, exportClasses = false, outputFormat = 'typescript') {
|
|
12
30
|
const exportKeyword = exportClasses ? 'export ' : '';
|
|
13
31
|
const lines = [];
|
|
14
32
|
// Type definitions
|
|
@@ -464,15 +482,20 @@ export function generateInlineRuntime(production, exportClasses = false) {
|
|
|
464
482
|
}
|
|
465
483
|
lines.push('}');
|
|
466
484
|
lines.push('');
|
|
467
|
-
|
|
485
|
+
const output = lines.join('\n');
|
|
486
|
+
if (outputFormat === 'javascript') {
|
|
487
|
+
return stripTypeScript(output);
|
|
488
|
+
}
|
|
489
|
+
return output;
|
|
468
490
|
}
|
|
469
491
|
/**
|
|
470
492
|
* Generates inline WebSocket debug client for auto-detection from env var
|
|
471
493
|
* Only included in development mode builds
|
|
472
494
|
*
|
|
473
495
|
* @param moduleFormat - The module format to use for imports ('esm' or 'cjs')
|
|
496
|
+
* @param outputFormat - Output format: 'typescript' (default) or 'javascript' (strips types)
|
|
474
497
|
*/
|
|
475
|
-
export function generateInlineDebugClient(moduleFormat = 'esm') {
|
|
498
|
+
export function generateInlineDebugClient(moduleFormat = 'esm', outputFormat = 'typescript') {
|
|
476
499
|
const lines = [];
|
|
477
500
|
lines.push('// ============================================================================');
|
|
478
501
|
lines.push('// Inline Debug Client (auto-created from FLOW_WEAVER_DEBUG env var)');
|
|
@@ -545,7 +568,11 @@ export function generateInlineDebugClient(moduleFormat = 'esm') {
|
|
|
545
568
|
lines.push('}');
|
|
546
569
|
lines.push('/* eslint-enable @typescript-eslint/no-explicit-any, no-console */');
|
|
547
570
|
lines.push('');
|
|
548
|
-
|
|
571
|
+
const output = lines.join('\n');
|
|
572
|
+
if (outputFormat === 'javascript') {
|
|
573
|
+
return stripTypeScript(output);
|
|
574
|
+
}
|
|
575
|
+
return output;
|
|
549
576
|
}
|
|
550
577
|
/**
|
|
551
578
|
* Generates a standalone runtime module file for multi-workflow bundles.
|