Skip to content

Use import statement instead of require() - #120

Draft
mcdonnnj wants to merge 5 commits into
developfrom
improvement/use_import_instead_of_require
Draft

Use import statement instead of require()#120
mcdonnnj wants to merge 5 commits into
developfrom
improvement/use_import_instead_of_require

Conversation

@mcdonnnj

Copy link
Copy Markdown
Member

🗣 Description

This pull request replaces use of Node.js's require() function with the now standard import syntax.

💭 Motivation and context

It is good to stay up-to-date. This is also necessary to move this action toward being an ECMAScript module.

🧪 Testing

I tested this locally with local-action

✅ Pre-approval checklist

  • This PR has an informative and human-readable title.
  • Changes are limited to a single goal - eschew scope creep!
  • All relevant type-of-change labels have been added.
  • I have read the CONTRIBUTING document.
  • These code changes follow cisagov code standards.
  • All new and existing tests pass.
  • Bump major, minor, patch, pre-release, and/or build versions as appropriate via the bump_version script if this repository is versioned and the changes in this PR warrant a version bump.

✅ Post-merge checklist

  • Create a release (necessary if and only if the version was bumped).

The `import` syntax is the modern standard in JavaScript so there is no
reason to use Node.js's solution from before `import` was added to the
JavaScript language specification.
@mcdonnnj
mcdonnnj requested a review from Copilot April 23, 2026 18:57
@mcdonnnj mcdonnnj self-assigned this Apr 23, 2026
@mcdonnnj mcdonnnj added the improvement This issue or pull request will add or improve functionality, maintainability, or ease of use label Apr 23, 2026
@mcdonnnj
mcdonnnj requested review from dav3r, felddy and jsf9k as code owners April 23, 2026 18:57
@github-actions github-actions Bot added version bump This issue or pull request increments the version number dependencies Pull requests that update a dependency file javascript Pull requests that update JavaScript code labels Apr 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates the action’s source to use ES module import syntax instead of CommonJS require(), as a step toward an eventual ESM migration, and refreshes the bundled dist/ output accordingly.

Changes:

  • Replace require() usage with import in src/main.js and src/index.js
  • Rebuild the bundled action output in dist/index.js
  • Bump the package version to 1.3.0

Reviewed changes

Copilot reviewed 3 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/main.js Switches to import statements for action dependencies
src/index.js Switches entrypoint to import the run function
package.json Version bump to 1.3.0
package-lock.json Lockfile version alignment with package.json bump
dist/index.js Updated ncc/webpack bundle reflecting source module changes

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

Comment thread src/main.js
Comment on lines +1 to +2
import * as core from "@actions/core";
import { toolVersions } from "./versions";

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

src/main.js now uses ESM import syntax but still exports via module.exports. When bundled by ncc/webpack this is treated as an ES module and the generated runtime decorates module.exports to throw, causing the action to fail at runtime. Convert this module to ESM exports (e.g., export { run } / export async function run) or revert back to CommonJS require/module.exports consistently.

Copilot uses AI. Check for mistakes.
Comment thread src/index.js
* The entrypoint for the action.
*/
const { run } = require("./main");
import { run } from "./main";

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

src/index.js imports a named export run from ./main, but main.js currently exports via module.exports = { run }. With the new ESM-style imports this interop is fragile and, as currently bundled, results in the generated code treating main as an ES module while it still assigns module.exports. Make main.js an ES module export (and import accordingly), or keep both files in CommonJS. Also, if the intent is to run these sources as native ESM later, Node will require explicit .js extensions in relative imports.

Suggested change
import { run } from "./main";
const { run } = require("./main");

Copilot uses AI. Check for mistakes.
@mcdonnnj
mcdonnnj force-pushed the improvement/use_import_instead_of_require branch from 21e5ef4 to a5f4f07 Compare April 23, 2026 19:11
@github-actions github-actions Bot added the github-actions Pull requests that update GitHub Actions code label Apr 23, 2026
@mcdonnnj
mcdonnnj force-pushed the improvement/use_import_instead_of_require branch from a5f4f07 to 08f8e1e Compare April 23, 2026 19:15
The `export` syntax is the modern standard in JavaScript and is
necessary to convert the action to an ECMAScript module.
This is done by specifying `"type": "module"` in the `package.json`
file.
Generate the distribution files by running `npm run package`. This is
necessary for changes to the codebase to take effect.
@mcdonnnj
mcdonnnj force-pushed the improvement/use_import_instead_of_require branch 2 times, most recently from 97aa373 to 76f51c7 Compare April 23, 2026 19:52
@mcdonnnj
mcdonnnj marked this pull request as draft April 24, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file github-actions Pull requests that update GitHub Actions code improvement This issue or pull request will add or improve functionality, maintainability, or ease of use javascript Pull requests that update JavaScript code version bump This issue or pull request increments the version number

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants