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

feat(build)!: use tsup #54

Closed
wants to merge 16 commits into from
Closed

feat(build)!: use tsup #54

wants to merge 16 commits into from

Conversation

c43721
Copy link
Contributor

@c43721 c43721 commented Feb 3, 2022

Fixes #50

Build goes from 2 seconds to 20ms. Also cleans dist each time you run build.

Breaking changes:
uses esbuild to build instead of tsc
dev command no longer registers commands. It will auto-recompile + restart the bot if changes are made.

@MarcusOtter
Copy link
Owner

MarcusOtter commented Feb 3, 2022

This looks super cool, I'll make sure to give tsup a proper read through and test this out before merging, but awesome work!

dev command no longer registers commands

This is actually pretty important since the commands won't update and you can't try the bot otherwise (if the commands are being developed). How do you think we should solve this? 🤔 Hot reloading seems awesome, I just wish there was a way we could have the best of both worlds.

I guess one very hacky thing I have in mind is to read what the current commands are and store that in a json file, then every hot reload it will read that object and see if anything needs to be changed, and if so deploy the new changes to the development guild.

@c43721
Copy link
Contributor Author

c43721 commented Feb 3, 2022

Keeping track of command data is super annoying, so I forwent hot reloading commands since it could lead to API absue (think- you change a typo on a command then started to work on logic for that command).

We'd have to do something like sapphire/framework does and auto register based on what API responds. That's doable but requires custom code, not something I wish to do.

@c43721
Copy link
Contributor Author

c43721 commented Feb 3, 2022

alright technically I can copy/paste their code but would mean that we'd have 2 licensed since they use MIT

@MarcusOtter
Copy link
Owner

MarcusOtter commented Feb 3, 2022

I don't think that matters @c43721

From MIT:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

As long as we keep the copyright & permission notice in the file, we are allowed to sublicense the code.

More info: https://softwareengineering.stackexchange.com/questions/105912/can-you-change-code-distributed-under-the-mit-license-and-re-distribute-it-unde

@c43721
Copy link
Contributor Author

c43721 commented Feb 3, 2022

shows how much I know about licenses

@c43721
Copy link
Contributor Author

c43721 commented Feb 5, 2022

this now registers commands on startup, but does not hot reload. There's a deploy:dev command to deploy development commands from scripts (since dev registers once + watches build)

@c43721
Copy link
Contributor Author

c43721 commented Feb 22, 2022

never make me merge changes again...
@MarcusOtter Is there a chance this could get a review this week? @nchristopher anything changes you would like by chance?

package.json Outdated
"deploy": "npm run undeploy && node ./scripts/deploy-commands.js --global"
"build": "tsup",
"start": "npm run build && node --enable-source-maps .",
"dev": "npm run deploy:dev && tsup --watch --onSuccess \"node --enable-source-maps .",
Copy link
Contributor

@n1ckoates n1ckoates Feb 22, 2022

Choose a reason for hiding this comment

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

This string isn't terminated, resulting in the below error when executing npm run dev.

> discord-needle@1.0.0 dev
> npm run deploy:dev && tsup --watch --onSuccess "node --enable-source-maps .

sh: 1: Syntax error: Unterminated quoted string
Suggested change
"dev": "npm run deploy:dev && tsup --watch --onSuccess \"node --enable-source-maps .",
"dev": "npm run deploy:dev && tsup --watch --onSuccess \"node --enable-source-maps .\"",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦

@MarcusOtter
Copy link
Owner

never make me merge changes again...

oops 😄 I can fix the conflicts and review this week hopefully, I was unsure about the status of this PR which is why I haven't touched it

@c43721
Copy link
Contributor Author

c43721 commented Feb 22, 2022

Good for a review now, FYI.

Copy link
Contributor

@n1ckoates n1ckoates left a comment

Choose a reason for hiding this comment

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

It seems that config.json is being built as config.js, which causes imports to fail.

@c43721
Copy link
Contributor Author

c43721 commented Mar 6, 2022

it should work :/

I didn't test this so I'll take another look eventually

@c43721
Copy link
Contributor Author

c43721 commented Mar 6, 2022

@MarcusOtter Has merge conflicts :(

@n1ckoates
Copy link
Contributor

/scripts/deploy-commands.js needs to be modified to only use .js files otherwise it will attempt to deploy commands from .map.

@MarcusOtter
Copy link
Owner

MarcusOtter commented Mar 6, 2022

/scripts/deploy-commands.js needs to be modified to only use .js files otherwise it will attempt to deploy commands from .map.

I did this already with #100
https://github.com/MarcusOtter/discord-needle/pull/100/files#diff-4b6f85f2408aa620bf4897cb7a2f87fd4ee9fc30d8e36cc46bb4184e5681a5e9L61-R62

@c43721
Copy link
Contributor Author

c43721 commented Mar 6, 2022

tsconfig cannot have baseUrl for this to work

@n1ckoates
Copy link
Contributor

@c43721 Your fork's branch needs to be updated in order to fix command deploys.

@@ -16,7 +16,7 @@
// ________________________________________________________________________________________________

import { SlashCommandBuilder } from "@discordjs/builders";
import { ChannelType } from "discord-api-types";
import { ChannelType } from "discord-api-types/v9";
Copy link
Contributor

Choose a reason for hiding this comment

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

This change should be done everywhere else we import discord-api-types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should. I would like to do this in a follow up though

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be done in #94.

@MarcusOtter
Copy link
Owner

I'm not sure what the state of this is, should we turn it into a draft for now? Does it need my review? Last thing I heard was something about fixing imports, otherwise builds break, does that still apply?

@MarcusOtter MarcusOtter marked this pull request as draft March 21, 2022 20:02
@c43721
Copy link
Contributor Author

c43721 commented Apr 16, 2022

Something something JSON.. I'll close since this is so far behind and I'll re-open/

@c43721 c43721 closed this Apr 16, 2022
@c43721 c43721 deleted the feat/use-esbuild branch June 25, 2022 01:58
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.

💡 use esbuild via tsup (or swc)
3 participants