Skip to content

Fix bundler generating invalid JavaScript for multi-line module.exports#3566

Merged
pelikhan merged 3 commits intomainfrom
copilot/fix-create-pull-request-bundling
Nov 10, 2025
Merged

Fix bundler generating invalid JavaScript for multi-line module.exports#3566
pelikhan merged 3 commits intomainfrom
copilot/fix-create-pull-request-bundling

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 10, 2025

The JavaScript bundler was leaving orphaned code when removing multi-line module.exports statements, causing syntax errors in bundled scripts like create_pull_request.cjs.

Root Cause

The removeExports function only removed lines matching ^\s*module\.exports\s*=, which stripped the opening line but left property names and closing braces:

// Before bundling:
module.exports = {
  updateActivationComment,
};

// After bundling (invalid):
  updateActivationComment,
};

Changes

pkg/workflow/bundler.go

  • Enhanced removeExports to track multi-line export blocks using brace counting
  • Removes entire module.exports = { ... } blocks including all contents

pkg/workflow/bundler_test.go

  • Added TestRemoveExportsMultiLine covering single/multi-property exports, nested objects, trailing commas

pkg/workflow/bundler_validation_test.go (new)

  • Added TestBundledScriptsHaveValidJavaScriptSyntax to validate all 18 bundled scripts with Node.js
  • Added TestBundleCreatePullRequestScript as specific regression test

The validation tests ensure all bundled scripts produce syntactically valid JavaScript, preventing runtime errors in GitHub Actions workflows.

Original prompt

Fix bundling of create_pull_request as it generates invalid JavaScript
.

https://github.com/githubnext/gh-aw/actions/runs/19233970504/job/54979405137#step:7:1

Add tests that apply bundler and make sure generate JavaScript is valid


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 10, 2025 14:30
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 bundling of create_pull_request to generate valid JavaScript Fix bundler generating invalid JavaScript for multi-line module.exports Nov 10, 2025
Copilot AI requested a review from pelikhan November 10, 2025 14:37
@pelikhan pelikhan marked this pull request as ready for review November 10, 2025 15:00
Copilot AI review requested due to automatic review settings November 10, 2025 15:00
@pelikhan pelikhan merged commit 9753025 into main Nov 10, 2025
76 checks passed
@pelikhan pelikhan deleted the copilot/fix-create-pull-request-bundling branch November 10, 2025 15:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a JavaScript bundler bug where multi-line module.exports statements were not being properly removed, causing syntax errors in compiled workflow files. The fix enhances the removeExports function to track and remove multi-line export blocks by counting braces, and adds comprehensive tests to prevent regression.

  • Enhanced bundler to handle multi-line module.exports = { ... } statements
  • Added validation tests to ensure all bundled scripts produce valid JavaScript
  • Improved documentation for runs-on and concurrency fields with agentic workflow context
  • Regenerated workflow lock files with corrected bundled JavaScript (removing orphaned export lines)

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/workflow/bundler.go Added multi-line module.exports tracking logic with brace counting to properly remove export blocks
pkg/workflow/bundler_test.go Added comprehensive unit tests for multi-line export removal with various edge cases
pkg/workflow/bundler_validation_test.go Added Node.js-based syntax validation tests for all bundled scripts
docs/src/content/docs/reference/frontmatter-full.md Enhanced documentation for runs-on and concurrency fields with agentic workflow guidance
.github/workflows/*.lock.yml (14 files) Regenerated workflow lock files removing orphaned updateActivationComment, and }; lines from bundled scripts

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/workflow/bundler.go
if moduleExportsDepth == 0 {
inModuleExports = false
// Skip this closing line and continue
continue
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The continue statement at line 205 is inside the inner for _, ch := range trimmed loop, so it will only skip to the next character iteration, not skip the rest of the line processing as intended by the comment "Skip this closing line and continue".

This should be a break statement to exit the inner character-processing loop, allowing the outer continue at line 210 to properly skip the entire line. The current code may process additional characters after finding the closing brace that ends the export block.

Suggested change
continue
break

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants