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(types): emit and publish type definitions to npm #243

Merged
merged 2 commits into from
Jan 18, 2021
Merged

fix(types): emit and publish type definitions to npm #243

merged 2 commits into from
Jan 18, 2021

Conversation

etienne-martin
Copy link
Contributor

Related to this issue: #9

  • Type definitions are now emitted to the ./dist folder using tsc.
  • Types are now included in the tarball when running npm publish or npm pack.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 15, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 52b9233:

Sandbox Source
Vanilla Configuration

@etienne-martin etienne-martin changed the title Emit and publish type definitions Emit and publish type definitions to npm Jan 15, 2021
@etienne-martin etienne-martin changed the title Emit and publish type definitions to npm feat(typescript): Emit and publish type definitions to npm Jan 15, 2021
@etienne-martin etienne-martin changed the title feat(typescript): Emit and publish type definitions to npm feat(types): Emit and publish type definitions to npm Jan 15, 2021
@eunjae-lee eunjae-lee requested a review from yannickcr January 18, 2021 10:33
Copy link
Contributor

@yannickcr yannickcr left a comment

Choose a reason for hiding this comment

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

Thanks for your work @etienne-martin !

I made a small change to separate the tsconfig file in two different configurations (one for type checking and one for declaration file generation) so we keep the original behavior for the yarn type-check command.

Beside that it seems good to me 🙂

@etienne-martin
Copy link
Contributor Author

Great, thank you!

@eunjae-lee eunjae-lee changed the title feat(types): Emit and publish type definitions to npm fix(types): emit and publish type definitions to npm Jan 18, 2021
Copy link
Contributor

@eunjae-lee eunjae-lee left a comment

Choose a reason for hiding this comment

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

@etienne-martin Thank you for your contribution 🎉

For the record, I've run yarn lint && yarn test && yarn type-check && yarn build on my computer, since the community PRs are not run by CircleCI.

@eunjae-lee eunjae-lee merged commit 074f037 into algolia:master Jan 18, 2021
// shim for node modules in React Native
// see https://github.com/facebook/react-native/issues/5079
type empty = {};
export default empty;
Copy link
Contributor

Choose a reason for hiding this comment

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

do these not get generated by the tsc, instead, what if we gitignore it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They don't because index-node.cjs.js, index-browser.cjs.js and empty-module.cjs.js live outside of the ./lib folder and are plain JavaScript files.

Copy link
Contributor

Choose a reason for hiding this comment

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

not sure what you mean

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The package.json points to these entry files, and TypeScript will look for the equivalent but with the .d.ts extension.

Copy link
Contributor Author

@etienne-martin etienne-martin Jan 18, 2021

Choose a reason for hiding this comment

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

Ideally I'd get rid of those files sitting at the root of the project and point the package.json to the entry points in the ./dist folder but I didn't want to change everything.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean that tsc generates these files at publish time, why do they need to be committed on git?

Copy link
Contributor

Choose a reason for hiding this comment

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

and are plain JavaScript files.

I see now, makes sense! in the future they should be moved to ts

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. I will work on it next time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another thing is, I'd use the ts-expect package against the build output to test that the types are emitted properly. That would ensure that the chain package.json --> enty-*.js --> entry-*.d.ts is working properly.

Because right now, there are unit test for the source code, but there's nothing that checks that the build output is in good health.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wasn't aware of that. Thanks for the information. I will check it out :)

@etienne-martin etienne-martin deleted the publish-types branch January 19, 2021 12:50
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.

4 participants