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(pkg): add main field #678

Merged
merged 2 commits into from Mar 1, 2024
Merged

fix(pkg): add main field #678

merged 2 commits into from Mar 1, 2024

Conversation

wolfy1339
Copy link
Member

Some tools don't play well with only having the exports field present.
See octokit/core.js#662

Some tools don't play well with only having the `exports` field present.
See octokit/core.js#662
@wolfy1339 wolfy1339 added the Type: Bug Something isn't working as documented label Feb 27, 2024
gr2m
gr2m previously approved these changes Feb 27, 2024
Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

I don't like it but if that's what it takes to remove some upgrade pain, let's do it. Do you know what build tools are affected? If it's only ncc, maybe it's something that could/should be fixed on their side?

I'm a bit concerned that we will forget why the main key is there as we cannot add a comment. Should we maybe add a mini test to make sure it doesn't get removed by accident? Then the test can have comments and an explanation

@@ -61,6 +61,8 @@ async function main() {
{
...pkg,
files: ["dist-*/**", "bin/**"],
main: "dist-bundle/index.js",
types: "dist-types/index.d.ts",
exports: {
".": {
types: "./dist-types/index.d.ts",
Copy link
Contributor

Choose a reason for hiding this comment

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

did you try to replace with exports: "./dist-bundle/index.js" and just add the types key to the pkg root?

Copy link
Member Author

@wolfy1339 wolfy1339 Feb 27, 2024

Choose a reason for hiding this comment

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

It's not just ncc, typescript, and eslint as well are having some issues resolving Octokit packages.

I have tried that syntax and I had some issues.

Might just try again.

As for comments, we can leave one in the build file

Copy link
Contributor

Choose a reason for hiding this comment

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

As for comments, we can leave one in the build file

right!

@khitrenovich
Copy link

I see the similar change in most of the other @octokit packages had been merged. What are the plans for this one, please?

@wolfy1339
Copy link
Member Author

I haven't had a chance to do follow up tests to some suggestions in the comments.

It will get merged ASAP

@wolfy1339
Copy link
Member Author

I did some testing, and it seems that the idea suggested in #678 (comment) does not seem to work.

I tested this on this plugin, by modifying the package.json for @octokit/core in node_modules

  "exports": "./dist-src/index.js",
  "types": "./dist-types/index.d.ts",

Everything resolves fine in Jest when the tests are TypeScript.

However, TypeScript cannot resolve the module during the build, or in the IDE.

Could not find a declaration file for module '@octokit/core'. 'plugin-paginate-rest.js/node_modules/@octokit/core/dist-src/index.js' implicitly has an 'any' type.
  There are types at 'plugin-paginate-rest.js/node_modules/@octokit/core/dist-types/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@octokit/core' library may need to update its package.json or typings.ts(7016)

I have been following the Webpack guide on the exports field and the Pure ESM Package gist from sindresorhus

Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

thank you for digging into it

@wolfy1339 wolfy1339 merged commit f151af4 into main Mar 1, 2024
7 checks passed
@wolfy1339 wolfy1339 deleted the add-main branch March 1, 2024 01:03
Copy link
Contributor

github-actions bot commented Mar 1, 2024

🎉 This PR is included in version 9.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Type: Bug Something isn't working as documented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants