Skip to content

Instantly share code, notes, and snippets.

@tknickman
Last active January 2, 2024 04:09
Show Gist options
  • Save tknickman/bc63ec30bec6366e1552ff8a37299db5 to your computer and use it in GitHub Desktop.
Save tknickman/bc63ec30bec6366e1552ff8a37299db5 to your computer and use it in GitHub Desktop.

Vercel Ignore Build Step Example

NOTE: I no longer use this script since the release of turbo-ignore (More details)

Example of a script called by vercel Ignored Build Step option to only build application in monorepo when changes have been detected.


node ../../scripts/ignore-step.js

More details available here

const childProcess = require("child_process");
// https://vercel.com/support/articles/how-do-i-use-the-ignored-build-step-field-on-vercel
const ABORT_BUILD_CODE = 0;
const CONTINUE_BUILD_CODE = 1;
const continueBuild = () => process.exit(CONTINUE_BUILD_CODE);
const abortBuild = () => process.exit(ABORT_BUILD_CODE);
const app = process.argv[2] || path.basename(path.resolve());
const stepCheck = () => {
// no app name (directory) was passed in via args
if (!app) {
return abortBuild();
}
// get all file names changed in last commit
const fileNameList = childProcess
.execSync("git diff --name-only HEAD~1")
.toString()
.trim()
.split("\n");
// check if any files in the app, or in any shared packages have changed
const shouldBuild = fileNameList.some(
(file) => file.startsWith(`apps/${app}`) || file.startsWith("packages/")
);
if (shouldBuild) {
return continueBuild();
}
return abortBuild();
};
stepCheck();
@Youhan
Copy link

Youhan commented Jan 2, 2024

Just wanted to say thank you!
and if you are using "type": "module", in your package.json file, then rename the file to ignore-step.cjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment