Skip to content

Fix compute_text.cjs module export and invocation pattern#7445

Merged
pelikhan merged 5 commits intomainfrom
copilot/fix-compute-text-export
Dec 23, 2025
Merged

Fix compute_text.cjs module export and invocation pattern#7445
pelikhan merged 5 commits intomainfrom
copilot/fix-compute-text-export

Conversation

Copy link
Contributor

Copilot AI commented Dec 23, 2025

The compute_text.cjs script was missing proper module.exports declaration and had an incorrect invocation pattern that caused issues when the script was loaded via require() in the compiler-generated workflow steps.

Changes

  • pkg/workflow/js/compute_text.cjs: Replaced await main(); with module.exports = { main }; so the script exports the function without auto-executing it
  • pkg/workflow/compiler_activation_jobs.go: Updated to explicitly destructure and invoke main() when using require() mode:
    const { main } = require('/tmp/gh-aw/actions/compute_text.cjs');
    await main();
  • pkg/workflow/js/compute_text.test.cjs: Updated test to match the new export pattern

This aligns with the pattern used throughout the codebase for safe output scripts (e.g., add_comment.cjs, create_issue.cjs, create_discussion.cjs) and matches the invocation pattern in compiler_safe_outputs_core.go.

How It Works

When using require() mode (with setup action):

  1. The compiler generates code to require the module and destructure main: const { main } = require('...');
  2. The compiler explicitly calls the function: await main();
  3. The script only exports the function without auto-executing

When using inline mode (no setup action):

  1. The bundler strips module.exports statements (unnecessary in inline context)
  2. The bundled script is embedded directly in the YAML
  3. The inline script executes within the github-script context

This ensures the function is called exactly once in both modes and prevents double execution.

Testing

  • ✅ All 48 compute_text.test.cjs tests pass
  • ✅ Successfully recompiled all 123 workflow files
  • ✅ Verified compiled workflows show correct invocation pattern
Original prompt

Reference: https://github.com/githubnext/gh-aw/actions/runs/20472368702/job/58830337148#step:5:1

Fix compute text JavaScript to export main and invoke it in the inlined script.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
Copy link
Contributor

@copilot do not call await main from the script, call main from the action/github-script

Copilot AI and others added 2 commits December 23, 2025 22:04
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix compute text JavaScript export and invocation Fix compute_text.cjs module export for bundler compatibility Dec 23, 2025
Copilot AI requested a review from pelikhan December 23, 2025 22:13
…to call main explicitly

Per @pelikhan's feedback, the script should export main but not invoke it.
The compiler's require() call now properly destructures and invokes main().

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 23, 2025

@copilot do not call await main from the script, call main from the action/github-script

Fixed in cd25019. The script now exports main without invoking it, and the compiler explicitly calls main() when using require() mode, matching the pattern used by safe output scripts.

Copilot AI changed the title Fix compute_text.cjs module export for bundler compatibility Fix compute_text.cjs module export and invocation pattern Dec 23, 2025
@pelikhan pelikhan marked this pull request as ready for review December 23, 2025 22:29
@pelikhan pelikhan merged commit c5cd1ef into main Dec 23, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/fix-compute-text-export branch December 23, 2025 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants