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: fix exported types #7742

Closed

Conversation

timocov
Copy link

@timocov timocov commented Nov 3, 2021

What kind of change does this PR introduce? bugfix

Did you add tests for your changes? No

If relevant, did you update the documentation? Not relevant

Summary

You cannot export functions if actually you export a class (methods of a class != separate functions).

Fixes #7529

Does this PR introduce a breaking change?

To use launch method (and any other methods from Puppeteer class) now you have to import puppeteer via import default export, i.e. import puppeteer from 'puppeteer'.

Other information

@google-cla google-cla bot added the cla: yes label Nov 3, 2021
@timocov timocov force-pushed the fix7529-incorrect-public-types branch from 5609147 to ad5ef2a Compare November 3, 2021 10:29
@timocov timocov changed the title fix(page): fix exported types fix: fix exported types Nov 5, 2021
@timocov timocov force-pushed the fix7529-incorrect-public-types branch from ad5ef2a to 752362e Compare November 5, 2021 22:17
@timocov
Copy link
Author

timocov commented Nov 5, 2021

Interesting. puppeteer exports its instance as a default export, but in some types tests the test files rely on the knowledge that the exports are actually commonjs. So we have common types which are working for both commonjs and esm, but they could work for esm only since export default doesn't exist in commonjs. At least from my understanding it looks so.

It seems that the export of the instance should be kind of export = or export default depending on the module type, but as soon as types are only one for all module types we need to choose one of them?

@jschfflr could you please help with that?

@timocov
Copy link
Author

timocov commented Nov 20, 2021

@whimboo @connorjclark @jackfranklin @OrKoN maybe you can help with ^^ please?

Copy link
Collaborator

@OrKoN OrKoN left a comment

Choose a reason for hiding this comment

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

Hey, thanks for the PR. Do you know if this will have any impact on CommonJS consumers? Do you see a way to fix the types without breaking changes for the consumers? Could you please rebase so that we can run CI?

You cannot export functions if actually you export a class (methods of a class != separate functions)

Issues: #7529

BREAKING CHANGE: to use `launch` method (and any other methods from Puppeteer class) now you have to import `puppeteer` via import default export, i.e. `import puppeteer from 'puppeteer'`
@timocov timocov force-pushed the fix7529-incorrect-public-types branch from 752362e to db4a695 Compare February 18, 2022 17:44
@timocov
Copy link
Author

timocov commented Feb 18, 2022

Could you please rebase so that we can run CI?

Done (but tbh I didn't check it locally since I was on a windows pc right now and it might just fail because of that).

Do you see a way to fix the types without breaking changes for the consumers?

I didn't see any way to do this. The types are incorrect and should be fixed so it would be a breaking change anyway.

Do you know if this will have any impact on CommonJS consumers?

Well, I think this is quite similar to what I asked in #7742 (comment) because I'm not too sure how it works internally.

@OrKoN
Copy link
Collaborator

OrKoN commented Feb 18, 2022

Thanks! I was under impression that src/api-docs-entry.ts is only used for the documentation generation so should not actually be shipped (at least there are comments indicating that). I will double check next week. I think comment https://github.com/puppeteer/puppeteer/blob/main/cjs-entry.js#L18 and cjs-entry.js might be causing the issue.

@OrKoN OrKoN self-requested a review February 23, 2022 20:40
@timocov
Copy link
Author

timocov commented Apr 20, 2022

@OrKoN have you had a chance to double check it? 🙂

@OrKoN
Copy link
Collaborator

OrKoN commented Apr 20, 2022

@timocov sorry, I have not managed yet. But it looks like the PR is failing CI checks anyway?

@timocov
Copy link
Author

timocov commented Apr 24, 2022

But it looks like the PR is failing CI checks anyway?

@OrKoN that's true, but to fix them we need to answer questions from #7742 (comment) I believe. It looks like a problem is still here, but it just works in some cases and no one mentioned it before. Probably it might be solved by using exports map (and provide different types files for different type of importing a package, but I'm not sure if tsc supports it yet. ¯_(ツ)_/¯

@jackfranklin
Copy link
Collaborator

jackfranklin commented Apr 25, 2022

Interesting. puppeteer exports its instance as a default export, but in some types tests the test files rely on the knowledge that the exports are actually commonjs. So we have common types which are working for both commonjs and esm, but they could work for esm only since export default doesn't exist in commonjs. At least from my understanding it looks so.

Reaching back to when I did the work to setup this build, I think this is because when we first released the types we had issues where it did work for CJS users, or ESM users, but not both. So this test suite exists to ensure that our type configuration supports all users and their setups. Long term I'd like to drop CJS and move to ESM, but that's a separate discussion.

RE api-docs-entry.ts, I think that should only be used by the code that takes all the TSDoc comments and generates the docs, and not as part of the main types that are used by the compiler when checking the code. But I'm reaching back to work that was done 12 months ago and it's not the most fresh in my memory, so I'd need to dig into the setup to remind myself.

@jrandolf
Copy link
Contributor

jrandolf commented May 9, 2022

This does not seem relevant anymore. A workaround is to use import * as puppeteer.

Closing this as this PR is stale.

@jrandolf jrandolf closed this May 9, 2022
@OrKoN
Copy link
Collaborator

OrKoN commented May 9, 2022

I think we still need to address that so that the types match the documentation.

@OrKoN OrKoN reopened this May 9, 2022
@jrandolf
Copy link
Contributor

jrandolf commented May 9, 2022

@OrKoN Wouldn't this affect people who already import using import * as puppeteer? This would be a breaking change (which could be fine since we have a major version coming up).

@OrKoN
Copy link
Collaborator

OrKoN commented May 9, 2022

yeah, it would be a breaking change. I think we need to do the following:

  1. make sure that our types match our implementation across CJS and ESM builds (currently, it's not the case)
  2. figure out the role of src/api-docs-entry.ts as it appears it was meant to be the aid for the documentation generator but it looks like it affects types we ship.

@jrandolf
Copy link
Contributor

jrandolf commented Jun 9, 2022

Closed in favor of #8493

@jrandolf jrandolf closed this Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: Cannot read property '_launcher' of undefined
4 participants