Skip to content

Instantly share code, notes, and snippets.

@dannyfritz
Last active November 25, 2021 17:46
Show Gist options
  • Save dannyfritz/54a62558ecc77bf0ec4f547083e9e099 to your computer and use it in GitHub Desktop.
Save dannyfritz/54a62558ecc77bf0ec4f547083e9e099 to your computer and use it in GitHub Desktop.
Rebuild all dependent packages when a package is modified.
#!/usr/bin/env node
import process from "process";
import { spawn } from "child_process";
import chokidar from "chokidar";
import { readPackageUp } from "read-pkg-up";
// import { run } from '@pnpm/plugin-commands-script-runners';
chokidar
.watch(".", {
ignored: ["**/node_modules", "**/dist", ".git", ".parcel-cache"],
ignoreInitial: true,
followSymlinks: false,
})
.on("all", async (event, path) => {
console.log(event, path);
const packageJson = await readPackageUp({ cwd: path });
const packageName = packageJson.packageJson.name;
console.log(`Package Changed: ${packageName}`);
const child = spawn("pnpm", ["run", "-r", "build", "--filter", `...${packageName}`]);
child.stdout.on("data", (data) => {
process.stdout.write(`EXEC: ${data}`);
});
child.stderr.on("data", (data) => {
process.stderr.write(`EXEC_ERR: ${data}`);
});
child.on("close", (code) => {
process.stdout.write(`EXEC: exited with code ${code}`);
});
})
.on("ready", () => console.log("Watching for changes..."));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment