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 infrastructure and few components conversion #1797

Merged
merged 8 commits into from
Jan 16, 2020

Conversation

priyajeet
Copy link
Contributor

@priyajeet priyajeet commented Dec 11, 2019

This PR introduces typescript into BUIE. It includes:

  • Infra for TS, configs etc
  • PrimaryButton, Button, RadarAnimation, LoadingIndicator are migrated to TSX

Parent projects doing local symlink-ing with BUIE will need to update their configs to allow TS.

@boxcla
Copy link

boxcla commented Dec 11, 2019

Verified that @priyajeet has signed the CLA. Thanks for the pull request!

.eslintrc.js Outdated Show resolved Hide resolved
"flow.useNPMPackagedFlow": true,
"flow.enabled": true,
"eslint.autoFixOnSave": true,
"javascript.validate.enable": false,
Copy link
Contributor Author

@priyajeet priyajeet Dec 11, 2019

Choose a reason for hiding this comment

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

Enabling this to true breaks hell loose, with TSC trying to check .js files ignoring tsconfig.json. But once migrated, we would want this enabled by default.

i18n/en-US.properties Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@tjgupta tjgupta left a comment

Choose a reason for hiding this comment

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

Seems ok, but it's gonna be a mess to have both flow and TS going at the same time though. I wonder if we can do a war room and plow through it to get most of it in one shot...

src/components/index.ts Outdated Show resolved Hide resolved
@priyajeet priyajeet force-pushed the typescript branch 3 times, most recently from 5e62132 to a0616aa Compare December 12, 2019 21:00
@@ -18,16 +18,44 @@ module.exports = {
'react/no-access-state-in-setstate': 'off', // fixme
'react/no-array-index-key': 'off', // fixme
'react/no-this-in-sfc': 'off',
'import/no-unresolved': 'off', // fixme
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to keep eslint happy from when a JS file tries to import a TS module

.eslintrc.js Outdated
{
files: ['*.stories.tsx', '*.test.tsx'],
rules: {
'import/no-extraneous-dependencies': 'off'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we dont want to consider stories as something needed at runtime. So imports dont need to be in deps section and can remain in dev deps.

@priyajeet priyajeet force-pushed the typescript branch 2 times, most recently from d86e1b3 to a125dd7 Compare December 12, 2019 23:26
.eslintrc.js Outdated
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off', // fixme
'import/extensions': 'off',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This rule forces extension on imports ==> import Button from '../button.js'

@priyajeet priyajeet marked this pull request as ready for review December 16, 2019 23:18
@priyajeet priyajeet requested a review from a team December 16, 2019 23:18
const titleID = `${this.id}-title`;

// Make sure parent doesn't accidentally override these values
const svgProps: Record<string, string | number | React.ReactNode> = omit(rest, ['role', 'aria-labelledby']);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dealing with rest and omit is tricky.

Copy link
Contributor

Choose a reason for hiding this comment

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

where does the Record type come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its native to TypeScript

@@ -0,0 +1,41 @@
// @flow
Copy link
Contributor

@alexkrolick alexkrolick Dec 17, 2019

Choose a reason for hiding this comment

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

I don't think these .flow files were checked in before, they were generated and put next to the ES module dist exports for the npm package

Copy link
Contributor Author

@priyajeet priyajeet Dec 18, 2019

Choose a reason for hiding this comment

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

These flow files are to keep VSCode happy with flow+ts together while you are working within BUIE. Its similar to the ones we generated at publish time but those were only for consuming projects. These ones are for BUIE itself now. These will all be temporary and will be nuked eventually after migration.

await writeFile(outputJs, `${moduleHeader}${moduleString}`);
await writeFile(outputJs, `${moduleHeader}${moduleString}`); // deprecate eventually
await writeFile(outputTs, `${moduleTSHeader}${moduleString}`);
execSync(`yarn eslint --fix ${outputTs}`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only linting ts for now. Helps not needing eslint disable directives.

return <div className="avatar-image" />;
}

jest.mock('../AvatarImage', () => MockAvatarImage);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this was here so it didn't make an actual network call for the invalid images

@@ -0,0 +1,83 @@
/* File auto-generated */
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the strictest possible constant definition in TS? In flow you can also do this to make it a constant string instead of regular string:

const black: '#000' = '#000'

Copy link
Contributor Author

@priyajeet priyajeet Dec 18, 2019

Choose a reason for hiding this comment

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

Good question, I can make it generate that. Ideally (we can do this eventually) this should be an enum like this:

enum bdlVars {
    WHITE = '#fff',
    BLACK = '#000',
    ...
}

And then accessed via bdlVars.WHITE

@@ -5,7 +5,6 @@ module.exports = {
rules: {
camelcase: 'off',
'class-methods-use-this': 'off',
'formatjs/enforce-description': 'error', // fixme
Copy link
Contributor Author

@priyajeet priyajeet Dec 21, 2019

Choose a reason for hiding this comment

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

moved to @box/frontend

},
plugins: ['formatjs'],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to @box/frontend

@priyajeet priyajeet changed the title feat: typescript feat: typescript infrastructure and few components conversion Jan 15, 2020
@@ -1,4 +1,6 @@
const path = require('path');
// const typescriptDocGen = require('react-docgen-typescript');
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need these commented lines? Same for the exports below.

Copy link
Contributor Author

@priyajeet priyajeet Jan 15, 2020

Choose a reason for hiding this comment

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

They are currently left there for reference/documentation. Will be nuked eventually. Just dont want to go hunting the web again if that needs to be introduced.

tsconfig.json Outdated
},
"extends": "@box/frontend/ts/tsconfig",
Copy link
Contributor Author

@priyajeet priyajeet Jan 16, 2020

Choose a reason for hiding this comment

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

If paths came directly from the base config, that will be relative to that config/project and not this current inheriting project. tsconfig is missing tokens like <rootDir> that can be used in the path to avoid ambiguity. See microsoft/TypeScript#25430

jstoffan
jstoffan previously approved these changes Jan 16, 2020
tsconfig.json Outdated
"files": ["./.storybook/typings.d.ts"]
"exclude": ["src/**/*.js", "node_modules", "es", "dist"],
"files": [".storybook/typings.d.ts"],
"include": ["src/**/*"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than using both exclude and include, could we do "include": ["src/**/*.ts", "src/**/*.tsx"]?

@mergify mergify bot merged commit d04ce54 into box:master Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants