Skip to content

Update JavaScript developer instructions to clarify export pattern for top-level .cjs files#7461

Merged
pelikhan merged 3 commits intomainfrom
copilot/update-js-dev-instruction
Dec 24, 2025
Merged

Update JavaScript developer instructions to clarify export pattern for top-level .cjs files#7461
pelikhan merged 3 commits intomainfrom
copilot/update-js-dev-instruction

Conversation

Copy link
Contributor

Copilot AI commented Dec 24, 2025

The JavaScript refactoring skill documentation incorrectly showed top-level .cjs scripts calling await main() directly. The bundler automatically injects this call during inline execution, so scripts should only export main.

Changes

  • Added "Top-Level Script Pattern" section explaining correct pattern with side-by-side comparison:

    // ✅ Correct - export only
    async function main() {
      core.info("Running the script");
    }
    module.exports = { main };
    
    // ❌ Incorrect - don't call it
    await main(); // Bundler handles this
  • Updated all code examples in Step 5 and Complete Example sections to use module.exports = { main } without calling await main()

  • Added clarification to Pattern 2 (Main Workflow Script) explicitly stating scripts must export but not call main

  • Documented rationale: Bundler injects execution, enables testing by allowing imports without execution, maintains consistency with codebase (create_issue.cjs, add_comment.cjs, etc.)

Context

This pattern enables:

  • Tests to import and call main() with mocks without side effects
  • Bundler to inject await main() at execution time in GitHub Actions
  • Clean separation between module definition and execution
Original prompt

Update JavaScript developer instruction to create top level .cjs file that export main but do not call it.


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

Copilot AI and others added 2 commits December 24, 2025 03:53
….cjs export pattern

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Add new "Top-Level Script Pattern" section explaining the correct pattern
- Show correct pattern: export main but don't call it
- Show incorrect pattern: calling await main() in the file
- Explain why: bundler injects await main() during inline execution
- Update all examples to use correct pattern (module.exports only)
- Add clarification to Pattern 2 section about main workflow scripts
- Provide real examples from codebase (create_issue.cjs, add_comment.cjs, etc.)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Update JavaScript developer instruction for .cjs file Update JavaScript developer instructions to clarify export pattern for top-level .cjs files Dec 24, 2025
Copilot AI requested a review from pelikhan December 24, 2025 04:01
@pelikhan pelikhan marked this pull request as ready for review December 24, 2025 04:44
@pelikhan pelikhan merged commit 282804a into main Dec 24, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/update-js-dev-instruction branch December 24, 2025 04:44
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.

2 participants