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 typescript support for aepp-sdk #1113

Closed

Conversation

the-icarus
Copy link
Contributor

I added basic typescript support for the aepp-sdk so we are able to code in typescript and also users of the sdk get type completion in typescript.

This is an initial pull request which already contains transformation where I already converted utils/account-formatter.js and utils/bignumber.js to typescript.

There are still open discussions how we want to build the SDK. With the current setup javascript users might only able to use the build assets from dist so I guess we still need to adjust the build process but this is something I want to discuss with the current developers/maintainers of the SDK.

Happy to receive your feedback.

@davidyuk davidyuk self-requested a review February 22, 2021 07:03
@the-icarus the-icarus marked this pull request as draft February 22, 2021 16:52
@the-icarus
Copy link
Contributor Author

the-icarus commented Feb 22, 2021

Hi @davidyuk ,
I changed the PR to be a draft.
There are still some things to discuss and to change. I updated the build so during the npm pack and npm publish phase it will run tsc to process everything by the typescript compiler and get type definition files for all source files. Those are added to the dist/ folder.
I also want to change the package structure. Currently, everything is contained in a release. In my option only the build sources (everything in dist/) should be part of a release. This will exclude stuff like tests, raw docs,... from release which will lead to a clean npm package. please share your thoughts on this. As a first step we can compile and publish in a way that we don't break the implementation of our users.

@the-icarus the-icarus marked this pull request as ready for review March 1, 2021 16:32
@the-icarus
Copy link
Contributor Author

@davidyuk I made a final change and customized the npm pack so the generated code .js + .d.ts files are at the same location as the original code. This will allow us to add typescript without introducing breaking changes to our users.

Happy to receive your feedback!

@the-icarus
Copy link
Contributor Author

@davidyuk Any update regarding the review?

@omar-saadoun
Copy link

Hi @davidyuk please check this

@davidyuk davidyuk mentioned this pull request Mar 25, 2021
Copy link
Member

@davidyuk davidyuk left a comment

Choose a reason for hiding this comment

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

All these notices are resolved in #1131. @the-icarus please take a look at that PR.

.babelrc Show resolved Hide resolved
@@ -21,3 +21,4 @@ coverage.*
/examples/**/dist
.history
.site
*.tgz
Copy link
Member

Choose a reason for hiding this comment

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

npm pack is an edge case, I don't think that ignore files shouldn't be aware of it

@@ -0,0 +1,2 @@
es_src
Copy link
Member

Choose a reason for hiding this comment

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

.npmignore overrides .gitignore, currently it brings extra files to the packed package, for example, I got a local package about 40mb because of node_modules of examples. So, if .npmignore is used, it should contain all records from .gitignore. Alternatively, I'm proposing to use a files property of package.json to add only necessary folders (dist and es).

@@ -56,7 +56,7 @@ export const DENOMINATION_MAGNITUDE = {
* @param {String} [options.denomination='aettos'] denomination of amount, can be ['ae', 'aettos']
* @return {String}
*/
export const toAe = (value, { denomination = AE_AMOUNT_FORMATS.AETTOS } = {}) => formatAmount(value, { denomination, targetDenomination: AE_AMOUNT_FORMATS.AE })
export const toAe = (value: string | number | BigNumber, { denomination = AE_AMOUNT_FORMATS.AETTOS } = {}) => formatAmount(value, { denomination, targetDenomination: AE_AMOUNT_FORMATS.AE })
Copy link
Member

Choose a reason for hiding this comment

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

this line is too long, I'm planning to limit it by linter in future

@@ -3,42 +3,32 @@
* @module @aeternity/aepp-sdk/es/utils/bignumber
* @example import { parseBigNumber, asBigNumber, isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber'
*/
import BigNumber from 'bignumber.js'
import BigNumber from 'bignumber.js';
Copy link
Member

Choose a reason for hiding this comment

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

; is not allowed by our linter rules, need to switch from standard to ts-standard for linting

"prepare": "npm run build",
"genChangelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"prepublishOnly": "npm run docs:docco && npm run docs:api"
"prepublishOnly": "npm run docs:docco && npm run docs:api",
"prepack": "tsc && node tooling/prepack.js",
Copy link
Member

Choose a reason for hiding this comment

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

proposing to move tsc to build script

@@ -2,7 +2,8 @@
"name": "@aeternity/aepp-sdk",
"version": "7.7.0",
"description": "SDK for the æternity blockchain",
"main": "dist/aepp-sdk.js",
"main": "dist/index.js",
Copy link
Member

Choose a reason for hiding this comment

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

this file is es/index.js, as I understand this change needs to be reverted

"@babel/register": "7.10.1",
"@babel/runtime": "^7.10.2",
"@types/bignumber.js": "^5.0.0",
Copy link
Member

Choose a reason for hiding this comment

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

proposing to remove this package because of warning:

npm WARN deprecated @types/bignumber.js@5.0.0: This is a stub types definition for bignumber.js (https://github.com/MikeMcl/bignumber.js/). bignumber.js provides its own type definitions, so you don't need @types/bignumber.js installed!

"outDir": "./dist/es",
"noImplicitAny": true,
"module": "es6",
"target": "es2017",
Copy link
Member

Choose a reason for hiding this comment

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

switching it to es5 should solve #196

@@ -0,0 +1,5 @@
const fs = require('fs-extra')

fs.move('es', 'es_src')
Copy link
Member

Choose a reason for hiding this comment

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

Proposing a more radical change: to rename current es to src (as it should be) and to build typescript straight to /es

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@davidyuk
Copy link
Member

refactored version merged in #1131

@davidyuk davidyuk closed this Apr 20, 2021
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.

None yet

4 participants