Add validation test for scripts that export main and fix changeset.js module pattern#7460
Add validation test for scripts that export main and fix changeset.js module pattern#7460
Conversation
|
@copilot check that required script export a main when trying to destructure main. |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Added validation test in commit 0c44fba that checks all scripts used with
All currently required scripts pass validation. |
|
Remove the direct invocations like if (require.main === module) { |
|
@copilot comment above |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done in commit f2601f3.
Removed the module.exports = { main };
(async () => {
await main();
})();All tests pass with this pattern. |
|
@copilot a script that exports main should never call main. The importer makes the call. |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Understood. Reverted in commit ebfd7c4. The standalone CLI script
Module scripts in |
|
@copilot changeset is a module script. It gets imported in actions/github-script and main is run in the inlined JavaScript. Changeset must use export main and not call it. |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Fixed in commit 579ef57.
The bundler will remove exports and inject |
Added validation test to ensure scripts used with
const { main } = require(...)pattern actually export a main function, preventing runtime errors. Fixedscripts/changeset.jsto follow the correct module script pattern.Changes:
main_export_validation_test.go) to ensure scripts export main when required withconst { main } = require(...)scripts/changeset.js: Updated to export main without calling it (module script pattern for bundling)scripts/changeset.test.js: Modified to invoke main viarequire()instead of direct script executionKey Principle:
A script that exports main should never call main. The importer makes the call.
Pattern for module scripts (like
scripts/changeset.jsand those inpkg/workflow/js/):How Bundling Works
When scripts are bundled for GitHub Actions inline execution:
module.exportsstatementsawait main();at the endUsage
For bundled/imported use (primary use case):
For testing: The test file invokes main via require with proper process.argv setup.
Validation
Added
main_export_validation_test.gothat validates:const { main } = require(...)actually export mainThis prevents runtime errors where code tries to destructure main from a module that doesn't export it.
All changeset tests pass with the updated invocation pattern.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.