From a5e30551363ffcea2a71354de9f47c5dd1492d1f Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Mon, 20 Dec 2021 23:16:31 +0000 Subject: [PATCH 1/6] implement custom builds, for `dev` and `publish` 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`. --- packages/wrangler/src/dev.tsx | 59 +++++++++++++++++++++++++++++--- packages/wrangler/src/index.tsx | 26 ++++++++++++-- packages/wrangler/src/publish.ts | 20 +++++++++++ 3 files changed, 99 insertions(+), 6 deletions(-) diff --git a/packages/wrangler/src/dev.tsx b/packages/wrangler/src/dev.tsx index b12866eeb5..7f8b03a659 100644 --- a/packages/wrangler/src/dev.tsx +++ b/packages/wrangler/src/dev.tsx @@ -1,5 +1,6 @@ import esbuild from "esbuild"; import { readFile } from "fs/promises"; +import { existsSync } from "fs"; import type { DirectoryResult } from "tmp-promise"; import tmp from "tmp-promise"; import type { CfPreviewToken } from "./api/preview"; @@ -16,7 +17,6 @@ import onExit from "signal-exit"; import { syncAssets } from "./sites"; import clipboardy from "clipboardy"; import http from "node:http"; -import serveStatic from "serve-static"; import commandExists from "command-exists"; import assert from "assert"; import { getAPIToken } from "./user"; @@ -24,6 +24,7 @@ import fetch from "node-fetch"; import makeModuleCollector from "./module-collection"; import { withErrorBoundary, useErrorHandler } from "react-error-boundary"; import { createHttpProxy } from "./proxy"; +import { execa } from "execa"; type CfScriptFormat = void | "modules" | "service-worker"; @@ -42,6 +43,7 @@ type Props = { compatibilityDate: void | string; compatibilityFlags: void | string[]; usageModel: void | "bundled" | "unbound"; + buildCommand: { command: void | string; cwd: void | string }; }; function Dev(props: Props): JSX.Element { @@ -54,8 +56,13 @@ function Dev(props: Props): JSX.Element { const apiToken = getAPIToken(); const directory = useTmpDir(); + // is there isn't a build command, we just return the entry immediately + // ideally there would be a conditional here, but the rules of hooks + // kinda forbid that, so we thread the entry through useCustomBuild + const entry = useCustomBuild(props.entry, props.buildCommand); + const bundle = useEsbuild({ - entry: props.entry, + entry, destination: directory, staticRoot: props.public, jsxFactory: props.jsxFactory, @@ -361,6 +368,50 @@ function useTmpDir(): string | void { return directory?.path; } +function useCustomBuild( + expectedEntry: string, + props: { + command: void | string; + cwd: void | string; + } +): void | string { + const [entry, setEntry] = useState( + // if there's no build command, just return the expected entry + props.command ? null : expectedEntry + ); + const { command, cwd } = props; + useEffect(() => { + if (!command) return; + let cmd, interval; + console.log("running:", command); + const commandPieces = command.split(" "); + cmd = execa(commandPieces[0], commandPieces.slice(1), { + ...(cwd && { cwd }), + stderr: "inherit", + stdout: "inherit", + }); + + // check every so often whether `expectedEntry` exists + // if it does, we're done + interval = setInterval(() => { + if (existsSync(expectedEntry)) { + clearInterval(interval); + setEntry(expectedEntry); + } + }, 200); + // TODO: we could probably timeout here after a while + + return () => { + if (cmd) { + cmd.kill(); + cmd = undefined; + } + clearInterval(interval); + }; + }, [command, cwd]); + return entry; +} + type EsbuildBundle = { id: number; path: string; @@ -371,7 +422,7 @@ type EsbuildBundle = { }; function useEsbuild(props: { - entry: string; + entry: void | string; destination: string | void; staticRoot: void | string; jsxFactory: string | void; @@ -382,7 +433,7 @@ function useEsbuild(props: { useEffect(() => { let result: esbuild.BuildResult; async function build() { - if (!destination) return; + if (!destination || !entry) return; const moduleCollector = makeModuleCollector(); result = await esbuild.build({ entryPoints: [entry], diff --git a/packages/wrangler/src/index.tsx b/packages/wrangler/src/index.tsx index 8a4adda024..48e2d44e66 100644 --- a/packages/wrangler/src/index.tsx +++ b/packages/wrangler/src/index.tsx @@ -390,7 +390,7 @@ export async function main(argv: string[]): Promise { // dev yargs.command( - "dev ", + "dev [-- build]", "👂 Start a local server for developing your worker", (yargs) => { return yargs @@ -399,6 +399,10 @@ export async function main(argv: string[]): Promise { describe: "name of the script", type: "string", }) + .positional("build", { + type: "string", + description: "The command to run a build", + }) .option("format", { choices: ["modules", "service-worker"] as const, describe: "Choose an entry type", @@ -487,11 +491,21 @@ export async function main(argv: string[]): Promise { } // TODO: if not already published, publish a draft worker } + let buildCommand; + if (args["--"]) { + // args.build doesn't actually have the command, so we read it from `--` + buildCommand = { command: (args["--"] as string[]).join(" ") }; + } else if (config.build?.command) { + buildCommand = { command: config.build.command, cwd: config.build.cwd }; + } else { + buildCommand = { command: undefined }; + } render( { // publish yargs.command( - "publish [script]", + "publish [script] [-- build]", "🆙 Publish your Worker to Cloudflare.", (yargs) => { return yargs @@ -544,6 +558,10 @@ export async function main(argv: string[]): Promise { describe: "script to upload", type: "string", }) + .positional("build", { + type: "string", + description: "The command to run a build", + }) .option("name", { describe: "name to use when uploading", type: "string", @@ -607,6 +625,9 @@ export async function main(argv: string[]): Promise { // -- snip, end -- + // args.build doesn't actually have the command, so we read it from `--` + const buildCommand = (args["--"] as string[] | undefined)?.join(" "); + await publish({ config: args.config as Config, name: args.name, @@ -618,6 +639,7 @@ export async function main(argv: string[]): Promise { routes: args.routes, public: args.public, site: args.site, + buildCommand, }); } ); diff --git a/packages/wrangler/src/publish.ts b/packages/wrangler/src/publish.ts index f2f94b0fbd..862580dc7b 100644 --- a/packages/wrangler/src/publish.ts +++ b/packages/wrangler/src/publish.ts @@ -9,6 +9,7 @@ import cfetch from "./cfetch"; import assert from "node:assert"; import { syncAssets } from "./sites"; import makeModuleCollector from "./module-collection"; +import { execa } from "execa"; type CfScriptFormat = void | "modules" | "service-worker"; @@ -25,6 +26,7 @@ type Props = { legacyEnv?: boolean; jsxFactory: void | string; jsxFragment: void | string; + buildCommand: void | string; }; function sleep(ms: number) { @@ -76,6 +78,24 @@ export default async function publish(props: Props): Promise { const destination = await tmp.dir({ unsafeCleanup: true }); + if (props.buildCommand) { + const buildCommandPieces = props.buildCommand.split(" "); + console.log("running:", props.buildCommand); + await execa(buildCommandPieces[0], buildCommandPieces.slice(1), { + stdout: "inherit", + stderr: "inherit", + }); + } else if (props.config.build?.command) { + // TODO: add a deprecation message here? + console.log("running:", props.config.build.command); + const buildCommandPieces = props.config.build.command.split(" "); + await execa(buildCommandPieces[0], buildCommandPieces.slice(1), { + stdout: "inherit", + stderr: "inherit", + ...(props.config.build?.cwd && { cwd: props.config.build.cwd }), + }); + } + const moduleCollector = makeModuleCollector(); const result = await esbuild.build({ ...(props.public From bbfa3f9ab1d82085af2f5c99a068f4ca53582402 Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Mon, 20 Dec 2021 23:19:25 +0000 Subject: [PATCH 2/6] Add a changeset --- .changeset/orange-cars-sip.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/orange-cars-sip.md diff --git a/.changeset/orange-cars-sip.md b/.changeset/orange-cars-sip.md new file mode 100644 index 0000000000..53fa531a19 --- /dev/null +++ b/.changeset/orange-cars-sip.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +Custom builds for `dev` and `publish` From c87040d1e257d11d3da336e58f8a70e93194b27e Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Mon, 20 Dec 2021 23:23:28 +0000 Subject: [PATCH 3/6] fix lint error --- packages/wrangler/src/dev.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/wrangler/src/dev.tsx b/packages/wrangler/src/dev.tsx index 7f8b03a659..c95e52ab72 100644 --- a/packages/wrangler/src/dev.tsx +++ b/packages/wrangler/src/dev.tsx @@ -407,6 +407,7 @@ function useCustomBuild( cmd = undefined; } clearInterval(interval); + interval = undefined; }; }, [command, cwd]); return entry; From c4d40b4e57363f3d84e34699a09e7578175070d7 Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Mon, 20 Dec 2021 23:25:36 +0000 Subject: [PATCH 4/6] update snapshot tests --- packages/wrangler/src/__tests__/index.test.ts | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/wrangler/src/__tests__/index.test.ts b/packages/wrangler/src/__tests__/index.test.ts index 8461ed433a..835d927efc 100644 --- a/packages/wrangler/src/__tests__/index.test.ts +++ b/packages/wrangler/src/__tests__/index.test.ts @@ -36,15 +36,15 @@ describe("wrangler", () => { "wrangler Commands: - wrangler init [name] 📥 Create a wrangler.toml configuration file - wrangler dev 👂 Start a local server for developing your worker - wrangler publish [script] 🆙 Publish your Worker to Cloudflare. - wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker. - wrangler secret 🤫 Generate a secret that can be referenced in the worker script - wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces - wrangler kv:key 🔑 Individually manage Workers KV key-value pairs - wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once - wrangler pages ⚡️ Configure Cloudflare Pages + wrangler init [name] 📥 Create a wrangler.toml configuration file + wrangler dev [-- build] 👂 Start a local server for developing your worker + wrangler publish [script] [-- build] 🆙 Publish your Worker to Cloudflare. + wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker. + wrangler secret 🤫 Generate a secret that can be referenced in the worker script + wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces + wrangler kv:key 🔑 Individually manage Workers KV key-value pairs + wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once + wrangler pages ⚡️ Configure Cloudflare Pages Flags: -c, --config Path to .toml configuration file [string] @@ -67,15 +67,15 @@ describe("wrangler", () => { "wrangler Commands: - wrangler init [name] 📥 Create a wrangler.toml configuration file - wrangler dev 👂 Start a local server for developing your worker - wrangler publish [script] 🆙 Publish your Worker to Cloudflare. - wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker. - wrangler secret 🤫 Generate a secret that can be referenced in the worker script - wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces - wrangler kv:key 🔑 Individually manage Workers KV key-value pairs - wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once - wrangler pages ⚡️ Configure Cloudflare Pages + wrangler init [name] 📥 Create a wrangler.toml configuration file + wrangler dev [-- build] 👂 Start a local server for developing your worker + wrangler publish [script] [-- build] 🆙 Publish your Worker to Cloudflare. + wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker. + wrangler secret 🤫 Generate a secret that can be referenced in the worker script + wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces + wrangler kv:key 🔑 Individually manage Workers KV key-value pairs + wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once + wrangler pages ⚡️ Configure Cloudflare Pages Flags: -c, --config Path to .toml configuration file [string] From 875843a0a491bd398ee34e511ca570c7723da8bf Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Tue, 21 Dec 2021 11:40:34 +0000 Subject: [PATCH 5/6] remove `--`, add `watch_dir` - 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 --- .github/workflows/tests-typecheck.yml | 1 - .prettierignore | 1 + package.json | 3 +- packages/example-worker-app/.gitignore | 1 + packages/example-worker-app/{ => src}/dep.js | 0 .../example-worker-app/{ => src}/index.js | 0 packages/wrangler/src/__tests__/index.test.ts | 36 ++++++++-------- packages/wrangler/src/dev.tsx | 41 ++++++++++++++++--- packages/wrangler/src/index.tsx | 27 ++---------- packages/wrangler/src/publish.ts | 10 +---- 10 files changed, 61 insertions(+), 59 deletions(-) create mode 100644 packages/example-worker-app/.gitignore rename packages/example-worker-app/{ => src}/dep.js (100%) rename packages/example-worker-app/{ => src}/index.js (100%) diff --git a/.github/workflows/tests-typecheck.yml b/.github/workflows/tests-typecheck.yml index b5b4605bb2..fd775057ae 100644 --- a/.github/workflows/tests-typecheck.yml +++ b/.github/workflows/tests-typecheck.yml @@ -35,4 +35,3 @@ jobs: - name: Test run: npm run test - working-directory: packages/wrangler diff --git a/.prettierignore b/.prettierignore index 3a8d0d84a3..c9359e9dc4 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,3 @@ packages/wrangler/vendor/ packages/wrangler/wrangler-dist/ +packages/example-worker-app/dist/ \ No newline at end of file diff --git a/package.json b/package.json index 7ab81cb35e..d04308fa8a 100644 --- a/package.json +++ b/package.json @@ -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" }, "engines": { "node": ">=16.0.0" diff --git a/packages/example-worker-app/.gitignore b/packages/example-worker-app/.gitignore new file mode 100644 index 0000000000..1521c8b765 --- /dev/null +++ b/packages/example-worker-app/.gitignore @@ -0,0 +1 @@ +dist diff --git a/packages/example-worker-app/dep.js b/packages/example-worker-app/src/dep.js similarity index 100% rename from packages/example-worker-app/dep.js rename to packages/example-worker-app/src/dep.js diff --git a/packages/example-worker-app/index.js b/packages/example-worker-app/src/index.js similarity index 100% rename from packages/example-worker-app/index.js rename to packages/example-worker-app/src/index.js diff --git a/packages/wrangler/src/__tests__/index.test.ts b/packages/wrangler/src/__tests__/index.test.ts index 835d927efc..8461ed433a 100644 --- a/packages/wrangler/src/__tests__/index.test.ts +++ b/packages/wrangler/src/__tests__/index.test.ts @@ -36,15 +36,15 @@ describe("wrangler", () => { "wrangler Commands: - wrangler init [name] 📥 Create a wrangler.toml configuration file - wrangler dev [-- build] 👂 Start a local server for developing your worker - wrangler publish [script] [-- build] 🆙 Publish your Worker to Cloudflare. - wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker. - wrangler secret 🤫 Generate a secret that can be referenced in the worker script - wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces - wrangler kv:key 🔑 Individually manage Workers KV key-value pairs - wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once - wrangler pages ⚡️ Configure Cloudflare Pages + wrangler init [name] 📥 Create a wrangler.toml configuration file + wrangler dev 👂 Start a local server for developing your worker + wrangler publish [script] 🆙 Publish your Worker to Cloudflare. + wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker. + wrangler secret 🤫 Generate a secret that can be referenced in the worker script + wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces + wrangler kv:key 🔑 Individually manage Workers KV key-value pairs + wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once + wrangler pages ⚡️ Configure Cloudflare Pages Flags: -c, --config Path to .toml configuration file [string] @@ -67,15 +67,15 @@ describe("wrangler", () => { "wrangler Commands: - wrangler init [name] 📥 Create a wrangler.toml configuration file - wrangler dev [-- build] 👂 Start a local server for developing your worker - wrangler publish [script] [-- build] 🆙 Publish your Worker to Cloudflare. - wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker. - wrangler secret 🤫 Generate a secret that can be referenced in the worker script - wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces - wrangler kv:key 🔑 Individually manage Workers KV key-value pairs - wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once - wrangler pages ⚡️ Configure Cloudflare Pages + wrangler init [name] 📥 Create a wrangler.toml configuration file + wrangler dev 👂 Start a local server for developing your worker + wrangler publish [script] 🆙 Publish your Worker to Cloudflare. + wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker. + wrangler secret 🤫 Generate a secret that can be referenced in the worker script + wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces + wrangler kv:key 🔑 Individually manage Workers KV key-value pairs + wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once + wrangler pages ⚡️ Configure Cloudflare Pages Flags: -c, --config Path to .toml configuration file [string] diff --git a/packages/wrangler/src/dev.tsx b/packages/wrangler/src/dev.tsx index c95e52ab72..6f13aef4ee 100644 --- a/packages/wrangler/src/dev.tsx +++ b/packages/wrangler/src/dev.tsx @@ -25,6 +25,7 @@ import makeModuleCollector from "./module-collection"; import { withErrorBoundary, useErrorHandler } from "react-error-boundary"; import { createHttpProxy } from "./proxy"; import { execa } from "execa"; +import { watch } from "chokidar"; type CfScriptFormat = void | "modules" | "service-worker"; @@ -43,7 +44,11 @@ type Props = { compatibilityDate: void | string; compatibilityFlags: void | string[]; usageModel: void | "bundled" | "unbound"; - buildCommand: { command: void | string; cwd: void | string }; + buildCommand: { + command?: undefined | string; + cwd?: undefined | string; + watch_dir?: undefined | string; + }; }; function Dev(props: Props): JSX.Element { @@ -56,7 +61,7 @@ function Dev(props: Props): JSX.Element { const apiToken = getAPIToken(); const directory = useTmpDir(); - // is there isn't a build command, we just return the entry immediately + // if there isn't a build command, we just return the entry immediately // ideally there would be a conditional here, but the rules of hooks // kinda forbid that, so we thread the entry through useCustomBuild const entry = useCustomBuild(props.entry, props.buildCommand); @@ -371,15 +376,16 @@ function useTmpDir(): string | void { function useCustomBuild( expectedEntry: string, props: { - command: void | string; - cwd: void | string; + command?: undefined | string; + cwd?: undefined | string; + watch_dir?: undefined | string; } ): void | string { const [entry, setEntry] = useState( // if there's no build command, just return the expected entry props.command ? null : expectedEntry ); - const { command, cwd } = props; + const { command, cwd, watch_dir } = props; useEffect(() => { if (!command) return; let cmd, interval; @@ -390,13 +396,36 @@ function useCustomBuild( stderr: "inherit", stdout: "inherit", }); + if (watch_dir) { + watch(watch_dir, { persistent: true, ignoreInitial: true }).on( + "all", + (_event, _path) => { + console.log("Restarting build..."); + cmd.kill(); + cmd = execa(commandPieces[0], commandPieces.slice(1), { + ...(cwd && { cwd }), + stderr: "inherit", + stdout: "inherit", + }); + } + ); + } // check every so often whether `expectedEntry` exists // if it does, we're done + const startedAt = Date.now(); interval = setInterval(() => { if (existsSync(expectedEntry)) { clearInterval(interval); setEntry(expectedEntry); + } else { + const elapsed = Date.now() - startedAt; + // timeout after 30 seconds of waiting + if (elapsed > 1000 * 60 * 30) { + console.error("⎔ Build timed out."); + clearInterval(interval); + cmd.kill(); + } } }, 200); // TODO: we could probably timeout here after a while @@ -409,7 +438,7 @@ function useCustomBuild( clearInterval(interval); interval = undefined; }; - }, [command, cwd]); + }, [command, cwd, expectedEntry, watch_dir]); return entry; } diff --git a/packages/wrangler/src/index.tsx b/packages/wrangler/src/index.tsx index 48e2d44e66..892eac2d5c 100644 --- a/packages/wrangler/src/index.tsx +++ b/packages/wrangler/src/index.tsx @@ -390,7 +390,7 @@ export async function main(argv: string[]): Promise { // dev yargs.command( - "dev [-- build]", + "dev ", "👂 Start a local server for developing your worker", (yargs) => { return yargs @@ -399,10 +399,6 @@ export async function main(argv: string[]): Promise { describe: "name of the script", type: "string", }) - .positional("build", { - type: "string", - description: "The command to run a build", - }) .option("format", { choices: ["modules", "service-worker"] as const, describe: "Choose an entry type", @@ -491,21 +487,12 @@ export async function main(argv: string[]): Promise { } // TODO: if not already published, publish a draft worker } - let buildCommand; - if (args["--"]) { - // args.build doesn't actually have the command, so we read it from `--` - buildCommand = { command: (args["--"] as string[]).join(" ") }; - } else if (config.build?.command) { - buildCommand = { command: config.build.command, cwd: config.build.cwd }; - } else { - buildCommand = { command: undefined }; - } render( { // publish yargs.command( - "publish [script] [-- build]", + "publish [script]", "🆙 Publish your Worker to Cloudflare.", (yargs) => { return yargs @@ -558,10 +545,6 @@ export async function main(argv: string[]): Promise { describe: "script to upload", type: "string", }) - .positional("build", { - type: "string", - description: "The command to run a build", - }) .option("name", { describe: "name to use when uploading", type: "string", @@ -625,9 +608,6 @@ export async function main(argv: string[]): Promise { // -- snip, end -- - // args.build doesn't actually have the command, so we read it from `--` - const buildCommand = (args["--"] as string[] | undefined)?.join(" "); - await publish({ config: args.config as Config, name: args.name, @@ -639,7 +619,6 @@ export async function main(argv: string[]): Promise { routes: args.routes, public: args.public, site: args.site, - buildCommand, }); } ); diff --git a/packages/wrangler/src/publish.ts b/packages/wrangler/src/publish.ts index 862580dc7b..de8b523597 100644 --- a/packages/wrangler/src/publish.ts +++ b/packages/wrangler/src/publish.ts @@ -26,7 +26,6 @@ type Props = { legacyEnv?: boolean; jsxFactory: void | string; jsxFragment: void | string; - buildCommand: void | string; }; function sleep(ms: number) { @@ -78,14 +77,7 @@ export default async function publish(props: Props): Promise { const destination = await tmp.dir({ unsafeCleanup: true }); - if (props.buildCommand) { - const buildCommandPieces = props.buildCommand.split(" "); - console.log("running:", props.buildCommand); - await execa(buildCommandPieces[0], buildCommandPieces.slice(1), { - stdout: "inherit", - stderr: "inherit", - }); - } else if (props.config.build?.command) { + if (props.config.build?.command) { // TODO: add a deprecation message here? console.log("running:", props.config.build.command); const buildCommandPieces = props.config.build.command.split(" "); From 4ae5c275c7ff6e54cf009081d246d06df09137d1 Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Tue, 21 Dec 2021 18:14:44 +0000 Subject: [PATCH 6/6] log the name of the file that changed during a custom build --- packages/wrangler/src/dev.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/wrangler/src/dev.tsx b/packages/wrangler/src/dev.tsx index 6f13aef4ee..16d4dfc916 100644 --- a/packages/wrangler/src/dev.tsx +++ b/packages/wrangler/src/dev.tsx @@ -373,6 +373,8 @@ function useTmpDir(): string | void { return directory?.path; } +function runCommand() {} + function useCustomBuild( expectedEntry: string, props: { @@ -400,7 +402,7 @@ function useCustomBuild( watch(watch_dir, { persistent: true, ignoreInitial: true }).on( "all", (_event, _path) => { - console.log("Restarting build..."); + console.log(`The file ${path} changed, restarting build...`); cmd.kill(); cmd = execa(commandPieces[0], commandPieces.slice(1), { ...(cwd && { cwd }),