Skip to content

Add error code extract and transform#138

Merged
jaredpalmer merged 11 commits into
masterfrom
feat/error-codes
Jul 11, 2019
Merged

Add error code extract and transform#138
jaredpalmer merged 11 commits into
masterfrom
feat/error-codes

Conversation

@jaredpalmer

@jaredpalmer jaredpalmer commented Jun 10, 2019

Copy link
Copy Markdown
Owner

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

@jaredpalmer jaredpalmer requested review from TrySound and swyxio June 10, 2019 18:31

@TrySound TrySound left a comment

Copy link
Copy Markdown
Collaborator

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

swyxio commented Jun 11, 2019

Copy link
Copy Markdown
Collaborator

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.

Comment thread src/errors/extractErrors.ts Outdated

@swyxio swyxio left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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

swyxio commented Jun 11, 2019

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Owner Author

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

@swyxio

swyxio commented Jul 11, 2019

Copy link
Copy Markdown
Collaborator

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

@jaredpalmer

Copy link
Copy Markdown
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

swyxio commented Jul 11, 2019

Copy link
Copy Markdown
Collaborator

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

jaredpalmer commented Jul 11, 2019

Copy link
Copy Markdown
Owner Author

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
Copy Markdown
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

swyxio commented Jul 12, 2019

Copy link
Copy Markdown
Collaborator

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