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

Fix types path and make linter yell #922

Merged
merged 8 commits into from
Sep 26, 2023
Merged

Fix types path and make linter yell #922

merged 8 commits into from
Sep 26, 2023

Conversation

webpro
Copy link
Contributor

@webpro webpro commented Sep 18, 2023

The "types" field should point to what API Extractor generates in the dist folder.

There is one issue though, added a note.

@changeset-bot
Copy link

changeset-bot bot commented Sep 18, 2023

🦋 Changeset detected

Latest commit: c253604

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@kadena-dev/lint-package Patch
@kadena/chainweb-stream-client Patch
@kadena/chainweb-node-client Patch
@kadena/cryptography-utils Patch
@kadena/pactjs-cli Patch
@kadena/chainwebjs Patch
@kadena/cookbook Patch
@kadena/kda-cli Patch
@kadena/pactjs Patch
@kadena/graph Patch
@kadena/types Patch
@kadena/tools Patch
@kadena/client-examples Patch
@kadena/client Patch
kadena.js Patch
@kadena/pactjs-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Sep 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

5 Ignored Deployments
Name Status Preview Comments Updated (UTC)
alpha-docs ⬜️ Ignored (Inspect) Visit Preview Sep 26, 2023 10:26am
docs-storybook ⬜️ Ignored (Inspect) Visit Preview Sep 26, 2023 10:26am
immutable-records ⬜️ Ignored (Inspect) Visit Preview Sep 26, 2023 10:26am
react-ui ⬜️ Ignored (Inspect) Visit Preview Sep 26, 2023 10:26am
tools ⬜️ Ignored (Inspect) Visit Preview Sep 26, 2023 10:26am

@webpro webpro force-pushed the chore/types-dist-and-lint branch from c7ec451 to 25f6b15 Compare September 18, 2023 17:51
@@ -24,7 +24,7 @@
}
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"types": "dist/pactjs.d.ts",
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 one causes trouble:

[typescript] Encountered 2 TypeScript issues:
[typescript] Error: src/tests/mkCap.test.ts:54:57 - (TS2339) Property 'toPactInteger' does not exist on type 'PactNumber'.
[typescript] Error: src/tests/mkCap.test.ts:55:62 - (TS2339) Property 'toPactDecimal' does not exist on type 'PactNumber'.
 ---- Compile encountered an error (1577ms) ---- 
-------------------- Finished (1.756s) --------------------
Encountered 2 errors:
  [typescript] src/tests/mkCap.test.ts:54:57 - (TS2339) Property 'toPactInteger' does not exist on type 'PactNumber'.
  [typescript] src/tests/mkCap.test.ts:55:62 - (TS2339) Property 'toPactDecimal' does not exist on type 'PactNumber'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is probably caused by the triple slash directive in PactNumber.ts that ends up in lib/PactNumber.d.ts, but not in dist/pactjs.d.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

API Extractor seems to not handle the triple slash directive:

/// <reference path="./extend-bignumber.ts" />

It's just gone (I think it should inline extend-bignumber.ts). To me this seems normal and valid usage of TypeScript. AE seems to support only types and lib references.

I did try a few things with files in tsconfig.json and bundledPackages in api-extractor.json, but to no avail.

Not proud of it, but this does seem to do the trick:

"build": "heft build --clean && cat src/extend-bignumber.ts >> dist/pactjs.d.ts"

There are other ways around this, but making exceptions to the types": "dist/[pkg].d.ts" rule or other TypeScript hacks to me sound even worse.

Any ideas welcome, though!

If we don't come up with a real fix and merge this I could open an issue in the rushstack repo.

Copy link
Member

Choose a reason for hiding this comment

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

If we add the contents of extend-bignumber.ts in PactNumber.ts, would that work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately not, declaration gets stripped, not sure how to work around this.

@webpro webpro force-pushed the chore/types-dist-and-lint branch from 5e23758 to b828c4c Compare September 20, 2023 12:25
@webpro webpro force-pushed the chore/types-dist-and-lint branch from b828c4c to 1c8eb92 Compare September 20, 2023 13:49
@webpro webpro marked this pull request as ready for review September 20, 2023 15:12
@javadkh2
Copy link
Collaborator

javadkh2 commented Sep 20, 2023

Why? I'd rather use a file generated by typescript itself. it also come with a source map file.

The "types" field should point to what API Extractor generates in the dist folder.

@webpro
Copy link
Contributor Author

webpro commented Sep 20, 2023

Why? I'd rather use a file generated by typescript itself. it also come with a source map file.

The "types" field should point to what API Extractor generates in the dist folder.

This was a request from @alber70g. You can look at https://api-extractor.com for some reasoning under "DTS rollup". It makes sense, until we hit issues like in this PR.

Tbh not a fan myself, just using tsc output is what everyone else does indeed, and would eliminate similar issues.

@javadkh2
Copy link
Collaborator

Why? I'd rather use a file generated by typescript itself. it also come with a source map file.

The "types" field should point to what API Extractor generates in the dist folder.

This was a request from @alber70g. You can look at https://api-extractor.com for some reasoning under "DTS rollup". It makes sense, until we hit issues like in this PR.

Tbh not a fan myself, just using tsc output is what everyone else does indeed, and would eliminate similar issues.

we already use all of the good aspects of it. but by using it in the package.json will break source mapping.

@@ -7,6 +7,7 @@
"license": "ISC",
"author": "",
"main": "index.js",
"types": "dist/cookbook.d.ts",
Copy link
Member

Choose a reason for hiding this comment

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

I think this one doesn't exist, since there's no heft-build right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I've also removed this config/api-extractor.json

@@ -7,6 +7,7 @@
"license": "ISC",
"author": "",
"main": "index.js",
"types": "dist/graph.d.ts",
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to have this? It's a private package, that's not going to be used in code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I've also removed this config/api-extractor.json

@@ -24,7 +24,7 @@
}
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"types": "dist/pactjs.d.ts",
Copy link
Member

Choose a reason for hiding this comment

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

If we add the contents of extend-bignumber.ts in PactNumber.ts, would that work?

@webpro webpro merged commit c8bbec3 into main Sep 26, 2023
@webpro webpro deleted the chore/types-dist-and-lint branch September 26, 2023 14:03
jessevanmuijden pushed a commit that referenced this pull request Sep 28, 2023
* Fix `types` in every package.json

* Make `types` field violation an error

* Remove unused .js files

* Add docs

* Update changelog

* Fix up changelog

* Not proud

* Remove unused api-extractor configs + package.json#types
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.

4 participants