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

Add error code extract and transform #138

Merged
merged 11 commits into from
Jul 11, 2019
Merged

Add error code extract and transform #138

merged 11 commits into from
Jul 11, 2019

Conversation

jaredpalmer
Copy link
Owner

@jaredpalmer jaredpalmer commented Jun 10, 2019

Closes #78

  • Rip out React's error workflow
  • Add rollup and babel transforms that extract and swap errors
  • Creates ./errors/codes.json in the root of tsdx directory on the first run, anything that uses a function call of invariant will be extracted.
  • Outputs dev and prod error message functions at ./errors/ErrorDev.js and ./errors/ErrorProd.js. Once generated, user can freely edit them. To regenerate, just delete and run a build or watch.
  • Add a flag to build called --extractErrors

Copy link
Collaborator

@TrySound TrySound left a comment

Choose a reason for hiding this comment

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

Looks cool!

@jaredpalmer jaredpalmer changed the title WIP: Add error code extract and transform Add error code extract and transform Jun 10, 2019
@swyxio
Copy link
Collaborator

swyxio commented Jun 11, 2019

testing this out..

  1. (minor) when i try this, extra files _error.production.ts and _error.ts are produced. this leaks the abstraction a little. worth storing this somewhere else? in a dotfolder? too much work?

  2. (i have fixed this below) the error code file is not append only and depends on the order. this will cause a problem when moving invariants around and removing them. i assume this isnt what you want, error codes need to be immutable. i'll see what i can do to fix.

  3. (i have fixed this below) if i currently run --extractErrors without any args, i get let url = 'true' + code;. we should handle this case.

src/errors/extractErrors.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@swyxio swyxio left a comment

Choose a reason for hiding this comment

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

accidentally approved, should have requested changes. anyway im fixing this

@jaredpalmer
Copy link
Owner Author

We need to generate the files and roll it up so it either needs to be a separate runtime package or we need to inject it So it can be a relative import. The reason we need to generate it is so we can say “Minified Blank” error and have a custom url. Putting it in a dot folder could cause confusion. One possibility is for use to make an errors directory outside of src where this all lives.

@swyxio
Copy link
Collaborator

swyxio commented Jun 11, 2019

i dont feel strongly enough about it to do anything tbh :) anyway i think this is good to go. can work on more docs in a separate issue.

@jaredpalmer
Copy link
Owner Author

Slept on it. I think we should move everything to an errors directory

@swyxio
Copy link
Collaborator

swyxio commented Jul 11, 2019

i still want this i think. any blockers in your mind? i can resolve merge conflicts later

@jaredpalmer
Copy link
Owner Author

I just not sure it should be the default? Then again, it only does magical stuff if you use invariant() so idk. Maybe we just document the crap out of it

@swyxio
Copy link
Collaborator

swyxio commented Jul 11, 2019

i think it is already opt in tho? you made that change. needs people to actively run the errorExtraction flag.

and maybe add a bit more logging so people dont get surprised there is a new file.

@jaredpalmer
Copy link
Owner Author

jaredpalmer commented Jul 11, 2019

Lol I totally forgot. I've been crazy busy working on Formik 2 + the thing that's not out yet. Yeah let's merge this lil guy

@jaredpalmer
Copy link
Owner Author

@sw-yx made some changes. I think this is g2g

@jaredpalmer jaredpalmer merged commit a20429d into master Jul 11, 2019
@jaredpalmer jaredpalmer deleted the feat/error-codes branch July 11, 2019 16:05
@swyxio
Copy link
Collaborator

swyxio commented Jul 12, 2019

Formik World

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.

[Feature] append-only error code minification
3 participants