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!: update multiformats, publish as ESM #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

achingbrain
Copy link

Updates multiformats module to 10.x.x. This module is now published as ESM-only so I had to update tsconfig.json to do the same here otherwise this module gets transpiled to CJS which then explodes at runtime when trying to import the ESM-only multiformats.

I removed ts-jest as I just couldn't get it to work with ESM-only modules, instead using babel's @babel/preset-typescript to compile ts to js.

There were also two snapshots directories - __snapshots__ and __SNAPSHOTS__ in this repo which wreak havoc on case-insensitive filesystems like MacOS, hopefully there's only one directory now.

Updates multiformats module to 10.x.x.  This module is now published
as ESM-only so I had to update `tsconfig.json` to do the same here
otherwise this module gets transpiled to CJS which then explodes at
runtime when trying to import the ESM-only multiformats.

I removed ts-jest as I just couldn't get it to work with ESM-only
modules, instead using babel's `@babel/preset-typescript` to compile
ts to js.

There were also two snapshots directories - `__snapshots__` and
`__SNAPSHOTS__` in this repo which wreak havoc on case-insensitive
filesystems like MacOS, hopefully there's only one directory now.
@bshambaugh
Copy link
Owner

Hey @achingbrain , thanks for looking at this and greatly improving the quality of this repository. As a status update, I just pulled this PR to my local machine and ran it through the linter. As usual, at least for me, I get ESM and CJS complaints for code bases. I'll try to update here as I fiddle around a bit more to be confident what needs to be there. Sergey, over at Ceramic, recently helped me clean up nist-weierstrauss. I'll go over to that repo for inspiration, snyc with you, etc...and get this done..

:~/Documents/exploringCIDs/elliptic-piece/did-key-creator$ npm run lint

> [email protected] lint
> ./node_modules/.bin/eslint ./src --ext .js,.jsx,.ts,.tsx


Oops! Something went wrong! :(

ESLint: 7.23.0

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/.eslintrc.js from /home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/@eslint/eslintrc/lib/config-array-factory.js not supported.
.eslintrc.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename .eslintrc.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at module.exports (/home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/import-fresh/index.js:32:59)
    at loadJSConfigFile (/home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/@eslint/eslintrc/lib/config-array-factory.js:225:16)
    at loadConfigFile (/home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/@eslint/eslintrc/lib/config-array-factory.js:309:20)
    at ConfigArrayFactory.loadInDirectory (/home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/@eslint/eslintrc/lib/config-array-factory.js:502:34)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js:379:46)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js:398:20)
    at CascadingConfigArrayFactory.getConfigArrayForFile (/home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js:300:18)
    at FileEnumerator._iterateFilesRecursive (/home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/eslint/lib/cli-engine/file-enumerator.js:445:49)
    at _iterateFilesRecursive.next (<anonymous>)
    at FileEnumerator.iterateFiles (/home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/eslint/lib/cli-engine/file-enumerator.js:296:49)
    at iterateFiles.next (<anonymous>)
    at CLIEngine.executeOnFiles (/home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/eslint/lib/cli-engine/cli-engine.js:770:48)
    at ESLint.lintFiles (/home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/eslint/lib/eslint/eslint.js:530:23)
    at Object.execute (/home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/eslint/lib/cli.js:299:36)
    at main (/home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/eslint/bin/eslint.js:142:52)
    at Object.<anonymous> (/home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/eslint/bin/eslint.js:146:2)

@bshambaugh
Copy link
Owner

hmm.. as a note to myself..it may be one in the same problem... how to express ESM may just be something I need I learn about.
compare:
bshambaugh/nist-weierstrauss#2

@bshambaugh
Copy link
Owner

bshambaugh commented Oct 28, 2022

I created a parallel branch [1] to test this out with some of the configuration that came from https://github.com/bshambaugh/nist-weierstrauss .

[1] https://github.com/bshambaugh/did-key-creator/tree/scratch-main-pr4

I am still getting the error like above:
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/.eslintrc.js from /home/ubuntu/Documents/exploringCIDs/elliptic-piece/did-key-creator/node_modules/@eslint/eslintrc/lib/config-array-factory.js not supported. .
......

I actually did reference did-key-creator from https://github.com/ceramicnetwork/js-did/blob/main/packages/key-did-resolver/README.md (because it provided a means to kick off the resolver) and it was used in the tests for
https://github.com/decentralized-identity/did-jwt/blob/master/src/__tests__/JWT.test.ts (a Ceramic dependency)
thus it was in devDependencies https://github.com/decentralized-identity/did-jwt/blob/master/package.json
and CJS vs ESM was a problem in bshambaugh/nist-weierstrauss#2 (another Ceramic dependency)

so in short, @ukstv might be interested in helping address this problem.

Good catch addressing the snapshots and SNAPSHOTS case sensitive problem in this repository. I'm unsure. Is this an urgent enough problem that I should try to get that out before this PR is even complete?

@bshambaugh
Copy link
Owner

bshambaugh commented Oct 31, 2022

Status update. I'm still fidgeting with CJS and ESM. Bear with me as the migration to ESM has been compared to Python 2 vs 3.
I'm still learning.

https://www.claritician.com/typescript-lib-vs-target-what-s-the-difference (comparing target and lib properties in tsconfig)
https://gist.github.com/bshambaugh/12dacbf186a3009fc5ccb28743878669 (tsc help docs)

edit: another status update, general docs: https://www.typescriptlang.org/tsconfig. I'm learning. Hopefully I'm closer.
I made some changes to https://github.com/bshambaugh/nist-weierstrauss today, supporting (hopefully ESM). Hopefully this serves as a guide here.

@bshambaugh
Copy link
Owner

bshambaugh commented Nov 3, 2022

Hey @achingbrain , I started from scratch and created a new version 1.2.0 for https://www.npmjs.com/package/did-key-creator . It seems to be usable for my purposes and it corrects for the duplicate snapshot and ESM issue. Feel free to try it and let me know if you have any issues.

Also, let me know how I might credit you.

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