@synergenius/flow-weaver 0.12.1 → 0.12.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.
@@ -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
- const code = lines.join('\n');
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,11 @@
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
+ * Uses a lazy import so esbuild is only loaded when actually needed.
7
+ */
8
+ export declare function stripTypeScript(code: string): string;
1
9
  /**
2
10
  * Generates inline runtime code for standalone execution
3
11
  *
@@ -6,16 +14,18 @@
6
14
  *
7
15
  * @param production - Whether to generate production-optimized code (no debug events)
8
16
  * @param exportClasses - Whether to add 'export' keyword to classes (for shared modules)
17
+ * @param outputFormat - Output format: 'typescript' (default) or 'javascript' (strips types)
9
18
  */
10
- export declare function generateInlineRuntime(production: boolean, exportClasses?: boolean): string;
19
+ export declare function generateInlineRuntime(production: boolean, exportClasses?: boolean, outputFormat?: TOutputFormat): string;
11
20
  import type { TModuleFormat } from '../ast/types.js';
12
21
  /**
13
22
  * Generates inline WebSocket debug client for auto-detection from env var
14
23
  * Only included in development mode builds
15
24
  *
16
25
  * @param moduleFormat - The module format to use for imports ('esm' or 'cjs')
26
+ * @param outputFormat - Output format: 'typescript' (default) or 'javascript' (strips types)
17
27
  */
18
- export declare function generateInlineDebugClient(moduleFormat?: TModuleFormat): string;
28
+ export declare function generateInlineDebugClient(moduleFormat?: TModuleFormat, outputFormat?: TOutputFormat): string;
19
29
  /**
20
30
  * Generates a standalone runtime module file for multi-workflow bundles.
21
31
  * This exports all runtime types and classes so individual workflow files can import them.
@@ -1,4 +1,23 @@
1
1
  import { getGeneratedBranding } from '../generated-branding.js';
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
+ * Uses a lazy import so esbuild is only loaded when actually needed.
7
+ */
8
+ export function stripTypeScript(code) {
9
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
10
+ const { transformSync } = require('esbuild');
11
+ const result = transformSync(code, {
12
+ loader: 'ts',
13
+ target: 'es2020',
14
+ // Keep the code readable (no minification)
15
+ minify: false,
16
+ // Preserve formatting as much as possible
17
+ keepNames: true,
18
+ });
19
+ return result.code;
20
+ }
2
21
  /**
3
22
  * Generates inline runtime code for standalone execution
4
23
  *
@@ -7,8 +26,9 @@ import { getGeneratedBranding } from '../generated-branding.js';
7
26
  *
8
27
  * @param production - Whether to generate production-optimized code (no debug events)
9
28
  * @param exportClasses - Whether to add 'export' keyword to classes (for shared modules)
29
+ * @param outputFormat - Output format: 'typescript' (default) or 'javascript' (strips types)
10
30
  */
11
- export function generateInlineRuntime(production, exportClasses = false) {
31
+ export function generateInlineRuntime(production, exportClasses = false, outputFormat = 'typescript') {
12
32
  const exportKeyword = exportClasses ? 'export ' : '';
13
33
  const lines = [];
14
34
  // Type definitions
@@ -464,15 +484,20 @@ export function generateInlineRuntime(production, exportClasses = false) {
464
484
  }
465
485
  lines.push('}');
466
486
  lines.push('');
467
- return lines.join('\n');
487
+ const output = lines.join('\n');
488
+ if (outputFormat === 'javascript') {
489
+ return stripTypeScript(output);
490
+ }
491
+ return output;
468
492
  }
469
493
  /**
470
494
  * Generates inline WebSocket debug client for auto-detection from env var
471
495
  * Only included in development mode builds
472
496
  *
473
497
  * @param moduleFormat - The module format to use for imports ('esm' or 'cjs')
498
+ * @param outputFormat - Output format: 'typescript' (default) or 'javascript' (strips types)
474
499
  */
475
- export function generateInlineDebugClient(moduleFormat = 'esm') {
500
+ export function generateInlineDebugClient(moduleFormat = 'esm', outputFormat = 'typescript') {
476
501
  const lines = [];
477
502
  lines.push('// ============================================================================');
478
503
  lines.push('// Inline Debug Client (auto-created from FLOW_WEAVER_DEBUG env var)');
@@ -545,7 +570,11 @@ export function generateInlineDebugClient(moduleFormat = 'esm') {
545
570
  lines.push('}');
546
571
  lines.push('/* eslint-enable @typescript-eslint/no-explicit-any, no-console */');
547
572
  lines.push('');
548
- return lines.join('\n');
573
+ const output = lines.join('\n');
574
+ if (outputFormat === 'javascript') {
575
+ return stripTypeScript(output);
576
+ }
577
+ return output;
549
578
  }
550
579
  /**
551
580
  * Generates a standalone runtime module file for multi-workflow bundles.