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

added export for nip49 #373

Closed
wants to merge 1 commit into from
Closed

added export for nip49 #373

wants to merge 1 commit into from

Conversation

Egge21M
Copy link
Contributor

@Egge21M Egge21M commented Feb 25, 2024

closes #372

NIP49 is included in bundle, but can not be imported as its not exported.

@fiatjaf
Copy link
Collaborator

fiatjaf commented Feb 25, 2024

I want to move to having all the imports be done as import * as nip49 from 'nostr-tools/nip49' instead of bundling everything always. Not adding new libraries to the bundle is part of nudging people into doing that.

@fiatjaf
Copy link
Collaborator

fiatjaf commented Feb 25, 2024

It's exposed by this magic trick here:

nostr-tools/package.json

Lines 163 to 167 in 63ccc8b

"./nip49": {
"import": "./lib/esm/nip49.js",
"require": "./lib/cjs/nip49.js",
"types": "./lib/types/nip49.d.ts"
},

I agree that JavaScript is hell.

For it to work you probably need a recent module bundler and if you're using TypeScript then you need this in your tsconfig.json:

{
  ...,
  "compilerOptions": {
    ...,
    "module": "ESNext",
    "moduleResolution": "bundler"
  }
}

@Egge21M
Copy link
Contributor Author

Egge21M commented Feb 25, 2024

I want to move to having all the imports be done as import * as nip49 from 'nostr-tools/nip49' instead of bundling everything always. Not adding new libraries to the bundle is part of nudging people into doing that.

Oh got it! Thanks for pointing that out. Wouldn't modern bundlers tree shake anything that's not required anyways?

This is perfect however. Will close PR and issue.

@fiatjaf
Copy link
Collaborator

fiatjaf commented Feb 26, 2024

Wouldn't modern bundlers tree shake anything that's not required anyways?

I can't explain why, but in my experience no.

My best guess is that they're unable to tree-shake when you're importing from a file that is itself importing (with *) a bunch of other things (like index.ts) because they don't know what kind of side-effects could be happening in these imports.

So we must import directly from these subfiles and never do the * in them.

@fiatjaf fiatjaf closed this Feb 26, 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.

NIP49 is part of package but not exported by index.js / bundle
2 participants