From 61f989795bbad3994d013ef170ad82fb8351dc0f Mon Sep 17 00:00:00 2001 From: Dor Fire Date: Mon, 12 Jul 2021 22:35:46 +0300 Subject: [PATCH 1/3] Added binPrefix option, to support running via Bazel --- src/cli.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index d16ad903..151e9401 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -35,6 +35,7 @@ export interface Logger { export interface Options { dryRun: boolean; + binPrefix: string; gtsRootDir: string; targetRootDir: string; yes: boolean; @@ -69,6 +70,7 @@ const cli = meow({ -n, --no Assume a no answer for every prompt. --dry-run Don't make any actual changes. --yarn Use yarn instead of npm. + --bin-prefix Directory containing node_modules. Used for running eslint. Examples $ gts init -y @@ -81,6 +83,7 @@ const cli = meow({ yes: {type: 'boolean', alias: 'y'}, no: {type: 'boolean', alias: 'n'}, dryRun: {type: 'boolean'}, + binDir: {type: 'string'}, yarn: {type: 'boolean'}, }, }); @@ -115,9 +118,9 @@ export async function run(verb: string, files: string[]): Promise { const options = { dryRun: cli.flags.dryRun || false, + binPrefix: cli.flags.binPrefix || '.', // Paths are relative to the transpiled output files. gtsRootDir: path.resolve(__dirname, '../..'), - targetRootDir: process.cwd(), yes: cli.flags.yes || cli.flags.y || false, no: cli.flags.no || cli.flags.n || false, logger, @@ -145,7 +148,7 @@ export async function run(verb: string, files: string[]): Promise { case 'lint': case 'check': { try { - await execa('node', ['./node_modules/eslint/bin/eslint', ...flags], { + await execa('node', [options.binPrefix + '/node_modules/eslint/bin/eslint', ...flags], { stdio: 'inherit', }); return true; @@ -158,7 +161,7 @@ export async function run(verb: string, files: string[]): Promise { try { await execa( 'node', - ['./node_modules/eslint/bin/eslint', fixFlag, ...flags], + [options.binPrefix + '/node_modules/eslint/bin/eslint', fixFlag, ...flags], { stdio: 'inherit', } From 5aeb95061d8724f98fcb7d7219ecd22a904714b1 Mon Sep 17 00:00:00 2001 From: Dor Fire Date: Mon, 12 Jul 2021 22:40:43 +0300 Subject: [PATCH 2/3] Fixed flag --- src/cli.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli.ts b/src/cli.ts index 151e9401..c0fb1fda 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -83,7 +83,7 @@ const cli = meow({ yes: {type: 'boolean', alias: 'y'}, no: {type: 'boolean', alias: 'n'}, dryRun: {type: 'boolean'}, - binDir: {type: 'string'}, + binPrefix: {type: 'string'}, yarn: {type: 'boolean'}, }, }); From 64d98b7fd483aebee5e12e13ba58e0ac62c2dc13 Mon Sep 17 00:00:00 2001 From: Dor Fire Date: Mon, 12 Jul 2021 22:42:16 +0300 Subject: [PATCH 3/3] Reverted change --- src/cli.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cli.ts b/src/cli.ts index c0fb1fda..7d14335d 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -121,6 +121,7 @@ export async function run(verb: string, files: string[]): Promise { binPrefix: cli.flags.binPrefix || '.', // Paths are relative to the transpiled output files. gtsRootDir: path.resolve(__dirname, '../..'), + targetRootDir: process.cwd(), yes: cli.flags.yes || cli.flags.y || false, no: cli.flags.no || cli.flags.n || false, logger,