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

Convert core components to TypeScript (Round 2) #9

Merged
merged 18 commits into from
Jun 27, 2019

Conversation

trblackw
Copy link
Contributor

@trblackw trblackw commented Jun 1, 2019

@nickmcmillan @vaibhavhrt Okay, everything now should be able to be merged smoothly considering index.js (now index.tsx) is hook-based. I apologize for the merge conflict hiccup.

@nickmcmillan
Copy link
Owner

@trblackw thanks for your work on this (and no stress about the merge conflict)!

However I'm having a little trouble getting this branch to run. I'm seeing the message ../dist/index.es.js Module not found: Can't resolve './styles.css'.

I've run yarn to ensure all dependencies are updated. Is there something else I'm missing?

@trblackw
Copy link
Contributor Author

trblackw commented Jun 3, 2019 via email

@trblackw
Copy link
Contributor Author

trblackw commented Jun 3, 2019 via email

@vaibhavhrt vaibhavhrt mentioned this pull request Jun 6, 2019
@vaibhavhrt
Copy link
Contributor

@trblackw waiting for you to complete this before I can start working on #11

@trblackw
Copy link
Contributor Author

trblackw commented Jun 12, 2019 via email

@vaibhavhrt
Copy link
Contributor

@trblackw you need to merge upstream/master

@trblackw
Copy link
Contributor Author

trblackw commented Jun 12, 2019

@nickmcmillan Forgive me because I'm not very familiar with working with forked copies of repos. I'm currently on master of my fork and getting this error when attempting to merge:
Screen Shot 2019-06-12 at 6 47 00 AM
I'm assuming there's some precursor steps I need to follow in order to be able to execute that command successfully?

edit: I did however just git pull [email protected]:nickmcmillan/react-physics-dragger.git and then resolve any merge conflicts and push.

@vaibhavhrt
Copy link
Contributor

Make sure you are on branch master:

git checkout master

Fetch remote:

git fetch

Merge remote:

git merge upstream/master

@trblackw
Copy link
Contributor Author

trblackw commented Jun 12, 2019

@vaibhavhrt What's weird is git fetch did not result in the fetching of the origin branch, which is why running git merge upstream/master was resulting in the screen shot I added above, I presume. I'm a bit of a git noob as well so I probably messed something up along the way. I see the conflicts have been resolved after what I just pushed, does that mean we're good to go?

I am noticing that Travis CI isn't very happy though
Screen Shot 2019-06-12 at 6 55 35 AM
These environment variables weren't something I messed with on my end

@vaibhavhrt
Copy link
Contributor

vaibhavhrt commented Jun 12, 2019

In conflict resolving you probably forced your changes instead of accepting incoming changes so eslint is giving errors.
Go src/package.json, find the lintJs commands in scripts section and add fix option to it:

"lintJs": "eslint **/*.{js,jsx} --fix"

Run it: npm run lintJs, it will fix travis errors.
undo changes in package.json, so it should be "lintJs": "eslint **/*.{js,jsx}" again.
Also make sure you have deleted src/index.js

@trblackw
Copy link
Contributor Author

trblackw commented Jun 12, 2019 via email

@vaibhavhrt
Copy link
Contributor

Actually forget my last comment, you actually messed up eslint settings, nothing wrong in resolving conflicts. We were using 2 spaces for tabs, you changed it 4 and trailing comma was allowed, you removed it too. See my review for fixing it.

@trblackw
Copy link
Contributor Author

trblackw commented Jun 12, 2019 via email

Copy link
Contributor

@vaibhavhrt vaibhavhrt left a comment

Choose a reason for hiding this comment

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

Fix these two 👇 , run npm run lintJs to make sure there are no more errors, if there is fix them.

"react/jsx-boolean-value": 0,

// allow comma-dangle in multiline objects & arrays
"comma-dangle": ["error", "only-multiline"]
Copy link
Contributor

@vaibhavhrt vaibhavhrt Jun 12, 2019

Choose a reason for hiding this comment

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

This line needs to be there, add it back.

"comma-dangle": ["error", "only-multiline"]

.eslintrc Outdated
"extends": [
"standard",
"standard-react",
"plugin:@typescript-eslint/recommended"
Copy link
Contributor

Choose a reason for hiding this comment

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

Extending this rule is probably forcing 4 spaces for indent. Add this line in rules section to make tab size 2 spaces:

"indent": ["error", 2],

See https://stackoverflow.com/a/48906878/9321755 for more details.

@trblackw
Copy link
Contributor Author

trblackw commented Jun 12, 2019 via email

@vaibhavhrt
Copy link
Contributor

vaibhavhrt commented Jun 12, 2019 via email

@trblackw
Copy link
Contributor Author

@vaibhavhrt okay I updated the eslint settings and fixed the affected files. I also just removed the tslint plugin because it was directly conflicting with eslint.

Copy link
Contributor

@vaibhavhrt vaibhavhrt left a comment

Choose a reason for hiding this comment

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

@trblackw add rollup.config.js in .eslintignore to ignore it(or fix the errors if you want).

@@ -1,5 +0,0 @@
{
"env": {
"jest": true
Copy link
Contributor

Choose a reason for hiding this comment

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

put this line in actual .eslintrc.

Copy link
Contributor

@vaibhavhrt vaibhavhrt left a comment

Choose a reason for hiding this comment

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

Also add react-scripts-ts as devDependency and then update the test scripts(in package.json) to run ts tests, right now it's not finding any tests as it's looking for tests with extension js.

"test": "cross-env CI=1 react-scripts-ts test --env=jsdom",
"test:watch": "react-scripts-ts test --env=jsdom",

package.json Outdated
"@types/jest": "^24.0.13",
"@types/react": "^16.8.19",
"@types/react-dom": "^16.8.4"
Copy link
Contributor

@vaibhavhrt vaibhavhrt Jun 12, 2019

Choose a reason for hiding this comment

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

@types dependencies are devDependencies as well. Move them to devDependencies

@trblackw
Copy link
Contributor Author

trblackw commented Jun 12, 2019 via email

@vaibhavhrt
Copy link
Contributor

Also add react-scripts-ts as devDependency and then update the test scripts(in package.json) to run ts tests, right now it's not finding any tests as it's looking for tests with extension js.

"test": "cross-env CI=1 react-scripts-ts test --env=jsdom",
"test:watch": "react-scripts-ts test --env=jsdom",

@trblackw
Copy link
Contributor Author

Oops, forgot that one. Should be good now @vaibhavhrt

@vaibhavhrt
Copy link
Contributor

Ok looks like ts requires a tsconfig.test.json to be able to run test suite.
Add a tsconfig.test.json in root directory with following contents.

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "module": "commonjs"
  }
}

@trblackw
Copy link
Contributor Author

@vaibhavhrt done

@vaibhavhrt
Copy link
Contributor

@trblackw test is now running which is good, but it's failing. I am not sure what's wrong, might need some investigation. Can you try to figure out what's wrong. You can run tests locally by npm run test to make sure it passes before pushing commits.
You can see error details by running tests locally or see the logs on tavis.

@trblackw
Copy link
Contributor Author

trblackw commented Jun 13, 2019 via email

@trblackw
Copy link
Contributor Author

@vaibhavhrt So I'm been trying to trouble shoot what's going on with the test that's failing in index.tsx, but I'm not super familiar with testing (sad face). Perhaps you might have a bit more insight into what's potentially going wrong here
Screen Shot 2019-06-16 at 9 00 54 AM

What's confusing to me is that the error message: Unexpected token (221:12) is actually on line 248 in my editor (perhaps this is normal because extra spaces are removed upon compilation or something?). My editor shows no visible issues with the code. The result message of the test is Test suite failed to run, which seems to contradict the previous unexpected token issue?

What do you think?

@vaibhavhrt
Copy link
Contributor

@trblackw I will clone your fork of this repo and take a look later. rn busy watching world cup

Copy link
Contributor

@vaibhavhrt vaibhavhrt left a comment

Choose a reason for hiding this comment

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

Problem is with tsconfig


import { roundNum } from './utils'
import { applyDragForce, applyBoundForce } from './force'
import getBoundaries from './getBoundaries'
// TypeScript does not like using the import statement for non js/ts files
const styles = require('./styles.css')
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually you can import css files, you just need to create a typings.d.ts in src with following content:

/**
 * Default CSS definition for typescript,
 * will be overridden with file-specific definitions by rollup
 */
declare module "*.css" {
  const content: { [className: string]: string };
  export default content;
}

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 didn't work for me. I'm leaving the rollup config modifications for now. test is now passing

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah no need to actually do this. I am just telling its possible.

src/index.tsx Outdated Show resolved Hide resolved
tsconfig.json Show resolved Hide resolved
@trblackw
Copy link
Contributor Author

@vaibhavhrt Okay after using the tsconfig.json you provided above the test is passing

@vaibhavhrt
Copy link
Contributor

Looks good to me now. @nickmcmillan you can review and merge.

@nickmcmillan
Copy link
Owner

nickmcmillan commented Jun 18, 2019

I'm still unable to get the example to run in this branch. Steps to reproduce are;

  1. Checkout this branch, run yarn to ensure dependencies are updated
  2. yarn start in the root folder
  3. cd example and yarn start to launch the development example

At this point I see the error message I'd mentioned here; #9 (comment) - which appears both in the terminal and in the browser.

  1. I implemented the solution @vaibhavhrt suggested here; Convert core components to TypeScript (Round 2) #9 (comment) which worked - I'm no longer seeing the error message.

In the browser, I'm seeing a new error message (screenshot attached) which suggests to me that Typescript is not being compiled, the browser is attempting to read TS directly.

Screenshot 2019-06-18 at 13 25 59

Am I missing something? Have you both tried testing the project example as per step #3 above and if so did it work?

I've noticed that the tool used to bootstrap this project (https://github.com/transitive-bullshit/create-react-library) also has a Typescript scaffolding option. Is this something worth considering as a last resort? (ie re-scaffolding the project using create-react-library with TS enabled)

@vaibhavhrt
Copy link
Contributor

@trblackw you can take a look at this repo, I am using ts there, it works (almost) perfectly, vaibhavhrt/react-github-buttons. My project was also bootstrapped using create-react-library but I used the typescript template, and manually updated all dev-dependencies.

@trblackw
Copy link
Contributor Author

@vaibhavhrt Why not just use create-react-app with the --typescript flag? I've worked with TypeScript a lot, mostly with the foundation set up with CRA and have never had issues. @nickmcmillan I'm curious why you used create-react-library?

@vaibhavhrt
Copy link
Contributor

@trblackw because it's a npm library not a react website/app. This repo is supposed to be pluggable into some other react app(may or may not be bootstrapped with CRA).
When creating an app we have an index.html but not in a library like this, because it will be used in some app which will have it index.html.
Web app (usually) have minified js, css etc, here in library we don't minify it. So that users can easily debug, and minify, gzip according to their choice.
In library we publish (usually) index.js and index.es.js to enable tree shaking.

@trblackw
Copy link
Contributor Author

trblackw commented Jun 18, 2019 via email

@vaibhavhrt
Copy link
Contributor

I am guessing something is wrong in rollup.config Take a look at the rollup config of my repo and try to see what's different in them. I am not expert enough in ts to figure out the solution just by looking at error, so you try changing things in rollup.config If you can't figure it out I will clone your fork again and take a look.

@trblackw
Copy link
Contributor Author

trblackw commented Jun 18, 2019 via email

@trblackw
Copy link
Contributor Author

@vaibhavhrt Haven't had any luck. Maybe you could take a look

@vaibhavhrt
Copy link
Contributor

ok, I will look when i get some time

@nickmcmillan nickmcmillan mentioned this pull request Jun 24, 2019
@nickmcmillan
Copy link
Owner

I think I have a working solution. @vaibhavhrt and @trblackw would you mind taking a look at this PR; #12 (which is branched of the work you've both done so far in this current PR)

Basically I re-initialised the create-react-library with TS enabled which provided a working foundation. I then copied the src files over from this PR, fixed a few errors, and it seems to be up and running ok (using the /example project).

@vaibhavhrt I don't think we need lintJs anymore and the eslint plugins that go with it. We can just use create-react-library's testing set up. So I've just made lintJS an alias for test so that Travis tests can pass.

@nickmcmillan nickmcmillan merged commit 4ac01f7 into nickmcmillan:master Jun 27, 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.

3 participants