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

Fix: conditional exports types #108

Merged
merged 1 commit into from Nov 27, 2023

Conversation

emmercm
Copy link
Contributor

@emmercm emmercm commented Nov 17, 2023

I do not know why, but Jest + TypeScript will not run without this change. The error it will give is:

  ● Test suite failed to run

    index.ts:1:47 - error TS7016: Could not find a declaration file for module '@metalsmith/collections'. '<redacted>/metalsmith-plugins/node_modules/@metalsmith/collections/lib/index.cjs' implicitly has an 'any' type.
      Try `npm i --save-dev @types/metalsmith__collections` if it exists or add a new declaration (.d.ts) file containing `declare module '@metalsmith/collections';`

    1 import collections, { CollectionConfig } from '@metalsmith/collections';
                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~

I'd love to embed this plugin inside a new one, but I'm entirely blocked on this change, unfortunately.

@webketje
Copy link
Member

Thx! I had a look at your tsconfig.json and will test myself after the weekend, but could it be related to this? https://stackoverflow.com/questions/70296652/how-can-i-use-exports-in-package-json-for-nested-submodules-and-typescript#answer-74485520

What happens when moduleResolution is set to Node?

This is big, because if this works better I would make that change for all core plugins

@emmercm
Copy link
Contributor Author

emmercm commented Nov 18, 2023

Fascinating, "moduleResolution": "node" does solve the problem as well. I should note that tsc doesn't appear to be affected by this, only Jest, so it may be something to do with jest-resolve or ts-jest or something else.

I need to convert some of my tests to use @metalsmith/collections instead of metalsmith-auto-collections and metalsmith-collections. But it looks like I'm not making use of any other core plugins within my plugins monorepo, and I haven't converted https://github.com/emmercm/www to TypeScript yet.

Do you have a list of other core plugins I can help test?

@webketje
Copy link
Member

This also seems related: microsoft/TypeScript#52363, and the change to make looks safe/ backwards-compatible so I think this can be added to all core plugins. To your question, the most important ones are @metalsmith/: markdown, permalinks, collections, layouts, in-place, sass, postcss, js-bundle, requests

@webketje webketje merged commit e8bb72a into metalsmith:main Nov 27, 2023
5 checks passed
@emmercm emmercm deleted the emmercm/exports-types-again branch December 6, 2023 03:32
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.

None yet

2 participants