From de27a607aa8aa02415b46ce395bcb9bddee66344 Mon Sep 17 00:00:00 2001 From: Sam Jones Date: Tue, 20 Dec 2022 16:37:43 +0100 Subject: [PATCH 1/4] feat: allow a custom type in CLI to populate print-affected call --- packages/nx-ignore/src/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/nx-ignore/src/index.ts b/packages/nx-ignore/src/index.ts index 7642fc88e..4bcd93850 100644 --- a/packages/nx-ignore/src/index.ts +++ b/packages/nx-ignore/src/index.ts @@ -9,14 +9,24 @@ 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 = ['apps', 'libs'] let baseSha = customBase ? customBase.slice(7) : vercelBase || 'HEAD^'; +if(!allowedTypes.includes(type)) { + console.log(`≫ Invalid type "${type}" 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); @@ -73,7 +83,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, _: '', From 44a1bee76cc29656010a226dc925d6120620c6b2 Mon Sep 17 00:00:00 2001 From: Sam Jones Date: Tue, 20 Dec 2022 16:42:37 +0100 Subject: [PATCH 2/4] fix: update allowedTypes array --- packages/nx-ignore/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nx-ignore/src/index.ts b/packages/nx-ignore/src/index.ts index 4bcd93850..0a22f3561 100644 --- a/packages/nx-ignore/src/index.ts +++ b/packages/nx-ignore/src/index.ts @@ -19,7 +19,7 @@ const vercelBase = process.env['VERCEL_GIT_PREVIOUS_SHA']; const isVerbose = args.some((s) => s === '--verbose'); const headSha = 'HEAD'; const type = customType || 'app' -const allowedTypes = ['apps', 'libs'] +const allowedTypes = ['app', 'lib'] let baseSha = customBase ? customBase.slice(7) : vercelBase || 'HEAD^'; if(!allowedTypes.includes(type)) { From 8a08c509f94a1054577c41205aec5ed1fa44b4da Mon Sep 17 00:00:00 2001 From: Sam Jones Date: Tue, 20 Dec 2022 16:43:57 +0100 Subject: [PATCH 3/4] fix: only check customType argument when it's defined --- packages/nx-ignore/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nx-ignore/src/index.ts b/packages/nx-ignore/src/index.ts index 0a22f3561..f97240947 100644 --- a/packages/nx-ignore/src/index.ts +++ b/packages/nx-ignore/src/index.ts @@ -22,8 +22,8 @@ const type = customType || 'app' const allowedTypes = ['app', 'lib'] let baseSha = customBase ? customBase.slice(7) : vercelBase || 'HEAD^'; -if(!allowedTypes.includes(type)) { - console.log(`≫ Invalid type "${type}" passed to nx-ignore script. Allowed types: ${allowedTypes.join(', ')}`); +if(customType && !allowedTypes.includes(customType)) { + console.log(`≫ Invalid type "${customType}" passed to nx-ignore script. Allowed types: ${allowedTypes.join(', ')}`); process.exit(1); } From 2a9fad7b344ab9e350cbedb732c6a23a95501a00 Mon Sep 17 00:00:00 2001 From: Sam Jones Date: Tue, 20 Dec 2022 16:44:30 +0100 Subject: [PATCH 4/4] fix: lint --- packages/nx-ignore/src/index.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/nx-ignore/src/index.ts b/packages/nx-ignore/src/index.ts index f97240947..8e3ceb1fb 100644 --- a/packages/nx-ignore/src/index.ts +++ b/packages/nx-ignore/src/index.ts @@ -18,12 +18,16 @@ const customBase = args.find( 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'] +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(', ')}`); +if (customType && !allowedTypes.includes(customType)) { + console.log( + `≫ Invalid type "${customType}" passed to nx-ignore script. Allowed types: ${allowedTypes.join( + ', ' + )}` + ); process.exit(1); }