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(TypeScript): Move DeviceDescriptors to TS #5595

Merged
merged 2 commits into from Apr 14, 2020

Commits on Apr 14, 2020

  1. feat(TypeScript): Move DeviceDescriptors to TS

    This commit moves `src/DeviceDescriptors` to be authored in TypeScript.
    This file was chosen due to its simplicity so that we can focus on
    getting a mixed JS/TS codebase playing nicely before migrating the more
    complex files.
    
    The file itself was a bit odd: although the array of devices was
    exported via `module.exports` that was never referenced by any
    consumers; each device was also exported via `module.exports[name] =
    device` and that is how it's consumed. The Puppeteer docs suggest using
    it like so:
    
    ```js
    puppeteer.devices['iPhone 6']
    ```
    
    So instead of exporting the array and then setting a bunch of properties
    on that, we instead define the array and export an object of keys where
    each key is a device. This is a breaking change (see the footer for
    details).
    
    Rather than export an object I'd much rather export a Map, but that
    would be a larger breaking change and I'm keen to avoid those for the time
    being.
    
    Note that we have to use special TypeScript specific syntax for the
    export that enables it to work in a CommonJS codebase [1] but again I'd
    rather this than move to ESM at this time. TypeScript still outputs
    CommonJS into `lib/` as you would expect.
    
    BREAKING CHANGE: We no longer export an array of devices, so any users
    relying on doing:
    
    ```js
    puppeter.devices.forEach(...)
    ```
    
    Will now see a breakage. The fix is to use
    `Object.{keys/entries/values}` to iterate instead.
    
    [1]: https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require
    jackfranklin committed Apr 14, 2020
    Copy the full SHA
    9a12c04 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    230c618 View commit details
    Browse the repository at this point in the history