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

feat: Build and export library in CommonJS format #1

Merged
merged 4 commits into from
Feb 9, 2025

Conversation

eliot-akira
Copy link

@eliot-akira eliot-akira commented Feb 7, 2025

This pull request adds a build script to compile the library to CommonJS format using a minimal Rollup setup; and an exports property in package.json (here) so the published NPM package can be consumed in both CJS and ESM formats.

This is related to:

The build/test pipeline in the above PR currently fails due to the step build.docs using CommonJS require.

nps is executing `build.docs` : node ./__tests__/__helpers__/generate-docs.cjs
...
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/vsts/work/1/s/node_modules/@isomorphic-git/path-browserify/index.js
require() of ES modules is not supported.

Using the GitHub URL to add @isomorphic-git/path-browserify as a dependency will only work if the repo includes the built index.cjs.


Next steps:

@jcubic

@eliot-akira eliot-akira force-pushed the build-export-commonjs branch from 7589d05 to b662656 Compare February 8, 2025 15:24
@eliot-akira eliot-akira changed the title Build and export library in CommonJS format feat: Build and export library in CommonJS format Feb 8, 2025
@jcubic
Copy link

jcubic commented Feb 8, 2025

There are some errors from npm install in GitHub workflow.

@eliot-akira
Copy link
Author

It looks like package-lock.json went out of sync somehow. npm install didn't fix it, so I removed my local node_modules and package-lock.json and regenerated it.

@jcubic jcubic merged commit 3ee850b into isomorphic-git:main Feb 9, 2025
1 check passed
@jcubic
Copy link

jcubic commented Feb 9, 2025

Is it ready to publish to NPM?

@eliot-akira
Copy link
Author

eliot-akira commented Feb 9, 2025

Yes, I think after the README is updated (#2) it's ready to be published.

I did a manual test locally using npm link in the isomorphic-git repo (isomorphic-git/isomorphic-git#2035), and as far as I can tell, all build and test steps are able to complete successfully using this fork (ESM and CommonJS).

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