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

Provide ESM build #67

Open
NicBright opened this issue Feb 8, 2023 · 5 comments
Open

Provide ESM build #67

NicBright opened this issue Feb 8, 2023 · 5 comments

Comments

@NicBright
Copy link

NicBright commented Feb 8, 2023

Hi there

I wonder whether it would be possible for you to provide an ESM compatible build ... ? Why? It's all about the shift of going from require() to import / export style syntax ...

My special use case is this: I'm migrating our code base's unit tests (Jest) to ESM modules, see https://jestjs.io/docs/ecmascript-modules
For this to work, however, the packages need to conform to new ESM modules standards. For example, Jest will fail when it encounters old CommonJS style require() calls. In the case of spark-md5, it is not even possible (for me) to add it to Jest's transformIgnorePatterns (and have it be re-compiled) because (I'm not an UMD expert) it seems to me that the generated UMD file (spark-md5.js) is malformed. So for now I have to copy the whole source code of spark-md5 directly into my code base (in ESM module compatible way) as a workaround.

The new exports property in package.json helps with providing builds delivering modern ESM modules. Being backwards-compatible with old Node.js versions at the same time is easy because old Node.js versions will ignore the exports property and keep referring to package.json's main property instead (so you can still provide a CommonJS build and point to it via main property). If you don't know the new exports property, I recommend a short read of the following resources:

Best Regards,
Nicolas

@yutent
Copy link

yutent commented Feb 13, 2023

Hello, you can take a look at this package. It is a copy for spark-md5.js which Provide ESM.

import SparkMD5, { md5, md5Sum } from 'https://unpkg.com/[email protected]/dist/md5.js'

@mpellerin42
Copy link

I have the same request as @NicBright.
I just checked @yutent suggestion, but the package’s README is in chinese, and the corresponding github repo was deleted (seems like the author wasn't happy with Github enforcing 2FA…). So this is not an option for me.
While I was searching for an ESM solution, I found md5-es package, but it doesn't provide incremental usage as sparkMD5 does (which is the feature we're using on our code). So I still fill like an official sparkMD5 ESM version would be nice.

@yutent
Copy link

yutent commented Sep 26, 2023

I have the same request as @NicBright. I just checked @yutent suggestion, but the package’s README is in chinese, and the corresponding github repo was deleted (seems like the author wasn't happy with Github enforcing 2FA…). So this is not an option for me. While I was searching for an ESM solution, I found md5-es package, but it doesn't provide incremental usage as sparkMD5 does (which is the feature we're using on our code). So I still fill like an official sparkMD5 ESM version would be nice.

the repo is here, and just add an English Readme.

crypto.web.js

@mpellerin42
Copy link

the repo is here, and just add an English Readme.

crypto.web.js

thanks !

@diegovilar
Copy link

Just to point out that there is fork of js-spark-md5 that just changes what needs to be changed to make it ESM:

The diff is actually minimal: master...scx567888:js-spark-md5-es:master

You don't even have to change your imports if you alias the package in your package.json:

"dependencies": {
  "spark-md5": "npm:[email protected]"
},
"devDependencies": {
  "@types/spark-md5": "3.0.4"
}

I use PNPM, but I figure aliasing is the same in NPM and Yarn, or at least similiar.

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

No branches or pull requests

4 participants