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

implement custom builds, for dev and publish #149

Merged
merged 6 commits into from
Dec 21, 2021
Merged

Conversation

threepointone
Copy link
Contributor

@threepointone threepointone commented Dec 20, 2021

The code here is a bit jank, but we should probably refactor the way we pass arguments to dev and publish to 'fix' it properly. Anyway.

This PR adds custom builds to wrangler2 (https://developers.cloudflare.com/workers/cli-wrangler/configuration#build).

  • In wrangler.toml, you can configure build.command andbuild.cwd and and it'll be called before publish or dev. We also optionally watch build.watch_dir for changes during dev. There's some discussion to be had whether we're going to deprecate this config commands, but we'll support it until then anyway.

I swear I'll start writing tests for publish before the year is over. Maybe even dev.

closes #120

@changeset-bot
Copy link

changeset-bot bot commented Dec 20, 2021

🦋 Changeset detected

Latest commit: 4ae5c27

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

This PR includes changesets to release 1 package
Name Type
wrangler 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

packages/wrangler/src/dev.tsx Outdated Show resolved Hide resolved
@@ -371,7 +424,7 @@ type EsbuildBundle = {
};

function useEsbuild(props: {
entry: string;
entry: void | string;
Copy link
Contributor

Choose a reason for hiding this comment

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

OOC - what's the difference between void and undefined in this type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to revisit very void and replace it with undefined. I just got trigger happy and regret it now.

@threepointone
Copy link
Contributor Author

I made some changes -

  • removed the -- option completely. This is better accomplished with a bash script, and we should have great documentation, and a terminal log, showing how to do it. We can do that in a separate PR.
  • I also added support for config.build.watch_dir. We can deprecate it when (and if!) we deprecate config.build altogether.

I'll edit the main PR description as well.

@threepointone threepointone mentioned this pull request Dec 21, 2021
@GregBrimble
Copy link
Member

Any thoughts on -- in pages dev? Feels slightly different to me, but maybe we value a shared interface across wrangler more?

@threepointone
Copy link
Contributor Author

Pages dev has an additional requirement of 'detecting' what ports were opened and proxying them, etc, so I can see the requirement there. That said, I'd revisit the choice of the blank --, and maybe consider using --build instead. That's a product decision for you folks tho, and I assume your users have feedback about it too.

@threepointone
Copy link
Contributor Author

(That said, I'd like for pages dev to use wrangler dev at some point, so I imagine we'll converge on some solution.)

@@ -30,7 +30,8 @@
"scripts": {
"lint": "eslint packages/**",
"check": "prettier packages/** --check && tsc && npm run lint",
"prettify": "prettier packages/** --write"
"prettify": "prettier packages/** --write",
"test": "npm run test --workspace=wrangler"
Copy link
Contributor

Choose a reason for hiding this comment

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

While this is fine for now, we should think about a more generalised solution for when the other packages in this workspace have tests to run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Strongly agreed, just did this as a quick dx win for myself rn.

watch(watch_dir, { persistent: true, ignoreInitial: true }).on(
"all",
(_event, _path) => {
console.log("Restarting build...");
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps log the path of the changed file that caused the rebuild?

Something like?

console.log(`The file ${path} changed`);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done and done

Comment on lines +406 to +411
cmd = execa(commandPieces[0], commandPieces.slice(1), {
...(cwd && { cwd }),
stderr: "inherit",
stdout: "inherit",
});
Copy link
Contributor

Choose a reason for hiding this comment

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

This block is now repeated - let's move it into its own function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just one statement, doesn't pass my threshold for a new abstraction yet imo

The code here is a bit jank, but we should probably refactor the way we pass arguments to dev and publish to 'fix' it properly. Anyway.

This PR adds custom builds to wrangler2 (https://developers.cloudflare.com/workers/cli-wrangler/configuration#build).
- In `wrangler.toml`, you can configure `build.command` and `build.cwd` and it'll be called before `publish` or `dev`. There's some discussion to be had whether we're going to deprecate this config commands, but we'll support it until then anyway.
- We _don't_ support `build.watch_dir`. We could, and I'm happy to add it after we discuss; but the idea is that watching shouldn't be wrangler's responsibility (which we've already broken with plain `dev`, and `pages dev`, so maybe we're wrong)
- You can pass the command after a last `--` in the cli (no support for `cwd` there). eg - `wrangler dev output/index.js -- some-build-command --out output/index.js`.
- removed the `--` option. We should have documentation showing how to do this with bash etc.
- Added support for `watch_dir`
- also added a definition for running tests from the root because it was annoying me to keep changing dirs to run tests
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.

custom builds
4 participants