Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow importing library as ESM #2004

Closed
wants to merge 1 commit into from

Conversation

mohd-akram
Copy link
Contributor

@mohd-akram mohd-akram commented Sep 19, 2023

This allows importing the library directly from an ESM, without requiring a build step. One change was required for a test to pass in index.runtime.js - a copy of the runtime module object is made to allow overriding checkRevision (ESMs don't allow modifying import objects). The source-map module is replaced via subpath imports rather than via runtime checking since require is not available in a ESM.

Before creating a pull-request, please check https://github.com/handlebars-lang/handlebars.js/blob/master/CONTRIBUTING.md first.

Generally we like to see pull requests that

  • Please don't start pull requests for security issues. Instead, file a report at https://www.npmjs.com/advisories/report?package=handlebars
  • Maintain the existing code style
  • Are focused on a single change (i.e. avoid large refactoring or style adjustments in untouched code if not the primary goal of the pull request)
  • Have good commit messages
  • Have tests
  • Have the typings (types/index.d.ts) updated on every API change. If you need help, updating those, please mention that in the PR description.
  • Don't significantly decrease the current code coverage (see coverage/lcov-report/index.html)
  • Currently, the 4.x-branch contains the latest version. Please target that branch in the PR.

@mohd-akram mohd-akram marked this pull request as draft September 19, 2023 19:16
@jaylinski
Copy link
Member

Nice work, I had this on my backlog too. But we won't merge this in 4.x in order to keep it backwards-compatible. Please target the PR at the master-branch.

@mohd-akram
Copy link
Contributor Author

Yes, I hoped it could be done in 4.x but reached the same conclusion. Will be retargeting and adjusting the PR - it needs some changes most likely - but need to merge the CI and build PRs first.

@mohd-akram mohd-akram changed the base branch from 4.x to master September 21, 2023 11:50
@mohd-akram mohd-akram force-pushed the support-esm branch 2 times, most recently from 57c2bc6 to dc73290 Compare September 21, 2023 12:04
@mohd-akram
Copy link
Contributor Author

Rebased on master, but closing for now as it depends on updating the build system, as well as fixing @handlebars/parser's exports (it does not properly provide ESM support as it is missing an exports field in its package.json) for integration tests to pass.

@mohd-akram mohd-akram closed this Sep 21, 2023
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.

None yet

2 participants