easypost-node
easypost-node copied to clipboard
Converts project to TypeScript
Description
This converts the project to TypeScript. In order to do this, a handful of kind of major-ish things needed to be done.
Add TypeScript build step
Instead of trying to get Webpack/Babel to compile the TypeScript, I made it so that TypeScript did the first compilation from TS -> JS. Doing it this way was both simpler, and we needed to do a TypeScript compilation anyway to create the TypeDefs. This process includes:
- Hand-copy
types/
TypeScript types to respective folders inservices/
folder - Delete hardcoded
types/
folder and addtypes
to.gitignore
- Add TS Build step to go from
src/
toout-tmp
andtypes-tmp
- These
-tmp
dirs are needed because the source relies on package.json, and so TypeScript wants to build toout/src/...
instead.
- These
- Once these are done, we copy
out-tmp/src
toout
andtypes-tmp/src
totypes
- Change webpack to build from the
out
dir instead ofsrc
dir
Tests
Because the tests are JS and relied on the JS src code, I just changed the tests to instead use the out
dir, since it should be effectively the same. This does mean that in order to run the tests, you need to build first.
Models
Now that we are using TypeScript, I thought the models directory was kind of redundant. Since they were mostly just "structs", classes with no methods or anything, they functioned the same as just a regular object would. And now that we have the types, we get most of the value they were giving anyway. Also this reduces the bundle size non-trivially.
I realize this is a huge change, and if it can't be accepted all at once, that is fine, and I am more than willing to work with you to do this incrementally or whatever
Testing
I ran the tests with my EasyPost API keys and they all passed.
EASYPOST_TEST_API_KEY="EZTK..." EASYPOST_PROD_API_KEY="EZAK..." npm run test
Pull Request Type
Please select the option(s) that are relevant to this PR.
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [x] Improvement (fixing a typo, updating readme, renaming a variable name, etc)