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

Generate empty hardhat_contract.ts file on postinstall #260

Merged
merged 5 commits into from
Mar 27, 2023

Conversation

carletex
Copy link
Member

Just tinkering around. This PR might end on the trash :D

Since we merged #255 I was thinking about how we could improve it. I was thinking about generating an «empty» "hardhat_contracts.ts" file on yarn install.

This is a quick & dirty attempt to do so.

Does this make sense? I have some issues with contract.types.ts and am not sure if there is a workaround (is it breaking the narrow typing?)

cc @sverps

@sverps
Copy link
Collaborator

sverps commented Mar 24, 2023

Your approach of generating an empty record as sort of 'default' contracts file gave me some more ideas to try out. I pushed a commit to your branch, it seems to be working nicely now, and I believe this is exactly what we wanted to have (the project being in a compilable state after just running yarn without the need to mess in the config. This makes it even easier to build a dapp without contract.

I even managed to remove the contracts import from the scaffold.config, this pass-through is obsolete with this solution. I also moved the contract.types.ts file to a more logical location (since it is not only used by our hooks) and renamed it to better reflect what it is for.

The only thing that I didn't get to work was the postinstall script. For some reason, it doesn't trigger when I run yarn. I have to call it separately. So not sure what's going on there.

@technophile-04
Copy link
Collaborator

The only thing that I didn't get to work was the postinstall script. For some reason, it doesn't trigger when I run yarn. I have to call it separately. So not sure what's going on there.

Did some digging and I think Yarn has some issues, it only runs postinstall scripts when there are dependencies changes. checkout this -> yarnpkg/yarn#5476


I tried doing a fresh clone of the repo and ran yarn it generated the empty hardhat_contracts.ts file 🙌

@carletex
Copy link
Member Author

This looks great @sverps Thank you!

There is only one thing left

image

The tweak I made for the Faucet & the autoconnect don't work, since contracts = {} is not a falsy. I guess we could:

a) Object.keys(obj).length check in the condition.
b) Default file being something like: export default false as const; (not sure how easy would be to fix the types)

I did a in 9913f5b, but if the types b are easily fixable, happy to switch.

The only thing that I didn't get to work was the postinstall script. For some reason, it doesn't trigger when I run yarn. I have to call it separately. So not sure what's going on there.
Did some digging and I think Yarn has some issues, it only runs postinstall scripts when there are dependencies changes. checkout this -> yarnpkg/yarn#5476
I tried doing a fresh clone of the repo and ran yarn it generated the empty hardhat_contracts.ts file raised_hands

Yep, also noticed this. In our case, I think we don't mind... since it'll be generated on a fresh clone.

@carletex carletex marked this pull request as ready for review March 27, 2023 09:01
@carletex
Copy link
Member Author

Merging this since we are about to announce the SE-2 hackathon, and want this to be in :)

We can rethink some stuff later.

@carletex carletex merged commit 5038495 into main Mar 27, 2023
@carletex carletex deleted the empty-hardhat-contract branch March 27, 2023 17:10
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.

3 participants