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

Add CommonJS build script #223

Merged
merged 10 commits into from
Oct 8, 2024
Merged

Conversation

FelipeSilva916
Copy link
Contributor

@FelipeSilva916 FelipeSilva916 commented Oct 4, 2024

Description

This pull request adds a CommonJS (CJS) build script to the @oddbird/popover-polyfill package. This change allows the polyfill to be used in environments that require CommonJS modules.
This pull request includes a small change to the package.json file to add a new build script for CommonJS format.

This PR Takes care of the following issue: #222

Build script addition:

  • package.json: Added a new script "build:cjs" to bundle the source file src/index.ts into CommonJS format with source maps.

Steps to test/reproduce

This pull request includes an update to the build scripts in the package.json file to support CommonJS module format.

Added to package.json

    "build:cjs": "esbuild --bundle src/index.ts --outfile=dist/popover.cjs.js --format=cjs --sourcemap",

Copy link

netlify bot commented Oct 4, 2024

Deploy Preview for popover-polyfill ready!

Name Link
🔨 Latest commit 9741e9e
🔍 Latest deploy log https://app.netlify.com/sites/popover-polyfill/deploys/67055766cbcb8b000828cecc
😎 Deploy Preview https://deploy-preview-223--popover-polyfill.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@FelipeSilva916 FelipeSilva916 marked this pull request as ready for review October 4, 2024 18:52
@jgerigmeyer jgerigmeyer linked an issue Oct 4, 2024 that may be closed by this pull request
Copy link
Member

@jgerigmeyer jgerigmeyer left a comment

Choose a reason for hiding this comment

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

@FelipeSilva916 Thanks! Because the default index.ts entry point has no exports, it looks like the resulting CJS build is identical to the existing ESM built, except that it has "use strict";. Is this actually useful for CJS environments? I was assuming #222 was requesting a CJS bundle of index-fn.ts, which would differ meaningfully between ESM and CJS.

cc @myasonik

I think we'll also want to document this in the README file, as well as add a require path to the exports setting in package.json.

package.json Outdated Show resolved Hide resolved
@FelipeSilva916
Copy link
Contributor Author

@jgerigmeyer What are your thoughts on the updates so far?

Copy link
Member

@jgerigmeyer jgerigmeyer left a comment

Choose a reason for hiding this comment

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

@FelipeSilva916 Would #224 work for you as an alternative?

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/index-fn.ts Outdated Show resolved Hide resolved
@FelipeSilva916
Copy link
Contributor Author

@FelipeSilva916 Would #224 work for you as an alternative?

@jgerigmeyer Let me give that a try

Copy link
Member

@jgerigmeyer jgerigmeyer left a comment

Choose a reason for hiding this comment

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

@FelipeSilva916 If you revert the remaining changes to index-fn.ts (or explain to me why they're needed?), I'm fine merging this.

src/index-fn.ts Outdated Show resolved Hide resolved
src/index-fn.ts Outdated Show resolved Hide resolved
FelipeSilva916 and others added 2 commits October 8, 2024 09:01
Co-authored-by: Jonny Gerig Meyer <jonny@oddbird.net>
Co-authored-by: Jonny Gerig Meyer <jonny@oddbird.net>
Copy link
Member

@jgerigmeyer jgerigmeyer left a comment

Choose a reason for hiding this comment

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

Looks good -- thanks!

@jgerigmeyer jgerigmeyer merged commit e93b631 into oddbird:main Oct 8, 2024
7 checks passed
@jgerigmeyer jgerigmeyer mentioned this pull request Oct 8, 2024
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.

CJS support
2 participants