Skip to content

feat: convert to ESM#56

Open
damusix wants to merge 1 commit intohapijs:masterfrom
damusix:esm-refactor
Open

feat: convert to ESM#56
damusix wants to merge 1 commit intohapijs:masterfrom
damusix:esm-refactor

Conversation

@damusix
Copy link
Copy Markdown

@damusix damusix commented Feb 20, 2026

Summary

  • Convert package from CommonJS to native ES modules
  • All tests passing with no memory leaks

Test plan

  • All existing tests pass
  • No memory leaks detected

Convert package from CommonJS to native ES modules.
All tests passing with no memory leaks.
Copy link
Copy Markdown
Contributor

@kanongil kanongil left a comment

Choose a reason for hiding this comment

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

Moving to modules is probably a decent choice from an javascript ecosystem POV, but still a major pain for hapi. As such, I would rather keep it as is until the coverage and linting issue is better resolved.

Comment thread lib/index.js
};


export { header, Clip };
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.

I would much prefer if the exports are declared when defined, as it closer aligns with intentions of the style guide (to immediately know if a variable / function / class is exported).

Comment thread test/index.js
const { describe, it } = exports.lab = Lab.script();
const lab = Lab.script();
const { describe, it } = lab;
const expect = Code.expect;
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.

I would prefer if expect is imported directly.

Comment thread package.json
"type": "module",
"repository": "git://github.com/hapijs/ammo",
"main": "lib/index.js",
"exports": "./lib/index.js",
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.

We should probably also export package.json with a "./package.json": "./package.json" line.

Comment thread package.json
},
"scripts": {
"test": "lab -a @hapi/code -t 100 -L -Y",
"test": "lab -a @hapi/code -Y",
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.

Omitting coverage and linting is a big no-no IMO.

I know lab doesn't currently handle coverage checks for modules, so something needs to be done. Either we update the implementation, or find an acceptable alternative.

Same goes for linting, but it is probably more of a configuration issue.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yep yep, agreed. I'm omitting temporarily. This is still a TBD.

Comment thread package.json
"name": "@hapi/ammo",
"description": "HTTP Range processing utilities",
"version": "6.0.1",
"version": "7.0.0",
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.

While this is clearly a breaking change, the version should not be updated in the PR.

Comment thread package.json
"scripts": {
"test": "lab -a @hapi/code -t 100 -L -Y",
"test": "lab -a @hapi/code -Y",
"test-cov-html": "lab -a @hapi/code -r html -o coverage.html"
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.

npm run test-cov-html does not work.

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