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

chore: convert init command to TS #708

Merged

Conversation

gvarandas
Copy link

Summary:

Part of issue #683
Converted commands/init/* to typescript.

The conversion involved the following steps:

  • Renaming the files from .js to .ts;
  • Removing all the @flow annotations from the header;
  • Transforming the type definitions from flow syntax to typescript;
  • Adding explicit type definitions when needed (for most of the cases the inferred type sufficed);
  • Extracting some interfaces to explicit definitions to increase readability;

Test Plan:

  • Running yarn flow and yarn lint to guarantee static analysis with no errors
  • Running yarn test to guarantee unit test coverage (this also involved making sure that the new snapshots are generated in the correct .ts format).
  • Creating a new project using the local cli, following the guidelines from the CONTRIBUTING.md file.

@@ -22,7 +19,7 @@ afterEach(() => {
});

test('installTemplatePackage', async () => {
jest.spyOn(PackageManger, 'install').mockImplementationOnce(() => {});
jest.spyOn(PackageManger, 'install').mockImplementationOnce(() => null);
Copy link
Author

Choose a reason for hiding this comment

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

Changed the mock implementation to avoid type conflicts. There was no change in the overall outcome from the unit tests since we're not asserting the result from the mock.

@@ -63,7 +60,7 @@ test('copyTemplate', async () => {
const CWD = '.';

jest.spyOn(path, 'resolve').mockImplementationOnce((...e) => e.join('/'));
jest.spyOn(copyFiles, 'default').mockImplementationOnce(() => {});
jest.spyOn(copyFiles, 'default').mockImplementationOnce(() => null);
Copy link
Author

Choose a reason for hiding this comment

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

Same as the comment above.

])("'%s' is invalid name", ({name, error}: {name: string, error: Error}) => {
// @ts-ignore-next-line FIXME extending the Error class causes weird TS validation errors
// https://stackoverflow.com/questions/41102060/typescript-extending-error-class
])("'%s' is invalid name", ({name, error}: {name: string; error: Error}) => {
Copy link
Author

Choose a reason for hiding this comment

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

This is the only unsolved case from the conversion.
Apparently TS has weird issues when extending the Error class by not recognizing the correct properties.
Tried different solutions with no success. 😞

@@ -103,7 +103,7 @@ async function installPods({
}: {
projectName: string;
loader?: ora.Ora;
shouldUpdatePods: boolean;
shouldUpdatePods?: boolean;
Copy link
Author

@gvarandas gvarandas Sep 10, 2019

Choose a reason for hiding this comment

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

Updated the type definition for this property as a proposition since we're checking if it is passed or not in the method execution.
I'll be happy to revert this and explicitly pass the false option on commands/init/initCompat:88 if needed.

@gvarandas gvarandas force-pushed the chore/init-ts-migration branch from 147cbc3 to 849c1c2 Compare September 11, 2019 18:38
@thymikee thymikee force-pushed the chore/init-ts-migration branch from 849c1c2 to 10a45f5 Compare September 12, 2019 22:13
Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

👍

@@ -136,7 +140,7 @@ async function createFromTemplate({
projectName,
projectTitle,
placeholderName: templateConfig.placeholderName,
titlePlaceholder: templateConfig.titlePlaceholder,
placeholderTitle: templateConfig.titlePlaceholder,
Copy link
Member

Choose a reason for hiding this comment

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

Good catch. cc @Esemesek – 0.61 is right behind the corner, so I guess we'll need to keep this name for a while?

@thymikee thymikee merged commit 31e60f3 into react-native-community:master Sep 12, 2019
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.

2 participants