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(nx-ignore): allow a custom type in CLI to populate the print-affected call #129

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/nx-ignore/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,28 @@ const { affected } = require('nx/src/command-line/affected');

const args = process.argv.slice(2);
const project = args.find((s) => !s.startsWith('-')) as string;
const customType = args.find(
(s) => s.startsWith('--type=') || s.startsWith('--type ')
) as string;
const customBase = args.find(
(s) => s.startsWith('--base=') || s.startsWith('--base ')
) as string;
const vercelBase = process.env['VERCEL_GIT_PREVIOUS_SHA'];
const isVerbose = args.some((s) => s === '--verbose');
const headSha = 'HEAD';
const type = customType || 'app';
const allowedTypes = ['app', 'lib'];
let baseSha = customBase ? customBase.slice(7) : vercelBase || 'HEAD^';

if (customType && !allowedTypes.includes(customType)) {
console.log(
`≫ Invalid type "${customType}" passed to nx-ignore script. Allowed types: ${allowedTypes.join(
', '
)}`
);
process.exit(1);
}

if (!project) {
console.log('≫ No project passed to nx-ignore script');
process.exit(1);
Expand Down Expand Up @@ -73,7 +87,7 @@ async function main() {
// Since Nx currently looks for "nx" package under workspace root, the CLI doesn't work on Vercel.
// Call the file directly instead of going through Nx CLI.
await affected('print-affected', {
type: 'app',
type,
base: baseSha,
head: headSha,
_: '',
Expand Down