From ee3f3bfcac154097c3c371df8261cccfe5757e64 Mon Sep 17 00:00:00 2001 From: Dean Shub Date: Sat, 3 Jul 2021 15:27:18 +0300 Subject: [PATCH 1/6] Adding node api --- package.json | 5 +- src/__tests__/__snapshots__/main.spec.ts.snap | 102 ++++++++++++++++++ src/__tests__/main.spec.ts | 98 +++++++++++++++++ src/main.ts | 33 ++++++ tsconfig.json | 1 + 5 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 src/__tests__/__snapshots__/main.spec.ts.snap create mode 100644 src/__tests__/main.spec.ts create mode 100644 src/main.ts diff --git a/package.json b/package.json index f664451..119b2c8 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,8 @@ "name": "qnm", "version": "1.8.1", "description": "cli utility for querying the node_modules directory", + "main": "build/main.js", + "module": "src/main.ts", "bin": "bin/qnm.js", "repository": "ranyitz/qnm", "engines": { @@ -24,7 +26,8 @@ "lint": "eslint .", "watch": "newsh --split 'yarn tsc --watch' && yarn pkg --watch", "pkg": "ncc build build/cli.js -o dist --external tabtab", - "build": "yarn tsc && yarn pkg", + "build": "yarn clean && yarn tsc && yarn pkg", + "clean": "rm -rf build/ dist/", "test:watch": "jest --watch", "createVersion": "np" }, diff --git a/src/__tests__/__snapshots__/main.spec.ts.snap b/src/__tests__/__snapshots__/main.spec.ts.snap new file mode 100644 index 0000000..b738e8b --- /dev/null +++ b/src/__tests__/__snapshots__/main.spec.ts.snap @@ -0,0 +1,102 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Node API qnm ] should add dependents information on yarn installed package 1`] = ` +"import-from +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/yarn-install/node_modules/import-from/package.json3.0.0]8;; (import-cwd) +" +`; + +exports[`Node API qnm ] should show an indication in case there is a symlink 1`] = ` +"test +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/symlink/node_modules/test/package.json1.0.0]8;; -> ../../symlink-origin/node_modules/test (devDependencies, npm install test) +" +`; + +exports[`Node API qnm ] should show get matches when using the match command 1`] = ` +"test +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/single-module/node_modules/test/package.json1.0.0]8;; (devDependencies, npm install test) +" +`; + +exports[`Node API qnm ] should show the version and dependents info on a single module when called with a string 1`] = ` +"test +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/single-module/node_modules/test/package.json1.0.0]8;; (devDependencies, npm install test) +" +`; + +exports[`Node API qnm ] should work in monorepo and print subpackages modules 1`] = ` +"package-foo +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-foo/package.json1.0.0]8;; +" +`; + +exports[`Node API qnm ] should work in monorepo with yarn workspaces 1`] = ` +"package-foo +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo-with-workspaces/node_modules/package-foo/package.json1.0.0]8;; +" +`; + +exports[`Node API qnm list should list a monorepo 1`] = ` +"package-bar +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-bar/package.json1.0.0]8;; + +package-baz +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-baz/package.json1.0.0]8;; + +package-foo +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-foo/package.json1.0.0]8;; +" +`; + +exports[`Node API qnm list should list dependencies in a yarn installed package and show "why" information 1`] = ` +"import-cwd +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/yarn-install/node_modules/import-cwd/package.json3.0.0]8;; + +import-from +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/yarn-install/node_modules/import-from/package.json3.0.0]8;; (import-cwd) + +resolve-from +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/yarn-install/node_modules/resolve-from/package.json5.0.0]8;; (import-from) +" +`; + +exports[`Node API qnm list should show all modules in node_modules directory 1`] = ` +"@scope/test +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/mix-modules/node_modules/@scope/test/package.json1.0.0]8;; + +another +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/mix-modules/node_modules/another/package.json1.0.0]8;; + +test +├── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/mix-modules/node_modules/test/package.json1.0.0]8;; +└─┬ another + └── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/mix-modules/node_modules/another/node_modules/test/package.json1.0.0]8;; +" +`; + +exports[`Node API qnm list should show modules mentioned in package.json 1`] = ` +"dependency1 +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/indirect-dependencies/node_modules/dependency1/package.json1.0.0]8;; + +dependency2 +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/indirect-dependencies/node_modules/dependency2/package.json1.0.0]8;; + +devDependency1 +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/indirect-dependencies/node_modules/devDependency1/package.json1.0.0]8;; + +devDependency2 +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/indirect-dependencies/node_modules/devDependency2/package.json1.0.0]8;; +" +`; + +exports[`Node API qnm match should match in monorepo and print subpackages modules 1`] = ` +"package-bar +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-bar/package.json1.0.0]8;; + +package-baz +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-baz/package.json1.0.0]8;; + +package-foo +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-foo/package.json1.0.0]8;; +" +`; diff --git a/src/__tests__/main.spec.ts b/src/__tests__/main.spec.ts new file mode 100644 index 0000000..2a944fb --- /dev/null +++ b/src/__tests__/main.spec.ts @@ -0,0 +1,98 @@ +// @ts-ignore +import * as qnm from '../..'; +import { resolveFixture } from './utils'; + +describe('Node API', () => { + describe('qnm ]', () => { + it('should show the version and dependents info on a single module when called with a string', () => { + const cwd = resolveFixture('single-module'); + const output = qnm.match('test', cwd); + + expect(output).toMatchSnapshot(); + }); + + it('should show get matches when using the match command', () => { + const cwd = resolveFixture('single-module'); + const output = qnm.match('te', cwd); + + expect(output).toMatchSnapshot(); + }); + + it('should add dependents information on yarn installed package', () => { + const cwd = resolveFixture('yarn-install'); + const output = qnm.match('import-from', cwd ); + + expect(output).toMatchSnapshot(); + }); + + it('should show an indication in case there is a symlink', () => { + const cwd = resolveFixture('symlink'); + const output = qnm.match('test', cwd ); + + expect(output).toMatchSnapshot(); + }); + + it('should work in monorepo and print subpackages modules', () => { + const cwd = resolveFixture('monorepo'); + const output = qnm.match('package-foo', cwd); + + expect(output).toMatchSnapshot(); + }); + + it('should work in monorepo with yarn workspaces', () => { + const cwd = resolveFixture('monorepo-with-workspaces'); + const output = qnm.match('package-foo', cwd ); + + expect(output).toMatchSnapshot(); + }); + + it('should provide suggestion for scoped package with the same name', () => { + const cwd = resolveFixture('scoped-package'); + + try { + qnm.match('test', cwd); + } catch (error) { + expect(error.message).toMatch('Did you mean "@scope/test"'); + } + }); + }); + + describe('qnm list', () => { + it('should show all modules in node_modules directory', () => { + const cwd = resolveFixture('mix-modules'); + const output = qnm.list( cwd ); + + expect(output).toMatchSnapshot(); + }); + + it('should show modules mentioned in package.json', () => { + const cwd = resolveFixture('indirect-dependencies'); + const output = qnm.list(cwd, { deps: true }); + + expect(output).toMatchSnapshot(); + }); + + it('should list dependencies in a yarn installed package and show "why" information', () => { + const cwd = resolveFixture('yarn-install'); + const output = qnm.list( cwd ); + + expect(output).toMatchSnapshot(); + }); + + it('should list a monorepo', () => { + const cwd = resolveFixture('monorepo'); + const output = qnm.list(cwd ); + + expect(output).toMatchSnapshot(); + }); + }); + + describe('qnm match', () => { + it('should match in monorepo and print subpackages modules', () => { + const cwd = resolveFixture('monorepo'); + const output = qnm.match('packa', cwd ); + + expect(output).toMatchSnapshot(); + }); + }); +}); diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..aad8b44 --- /dev/null +++ b/src/main.ts @@ -0,0 +1,33 @@ +import Workspace from './workspace/workspace'; +import { CliOptions } from './cli'; + +import matchAction from './actions/match'; +import getAction from './actions/get'; +import listAction from './actions/list'; +import fuzzySearchAction from './actions/fuzzy-search'; + +type Options = Pick; + +export function match(match: string, cwd?: string, options?: Options) { + const workspace = Workspace.loadSync(cwd); + + return matchAction(workspace, match, options); +} + +export function get(name: string, cwd?: string, options?: Options) { + const workspace = Workspace.loadSync(cwd); + + return getAction(workspace, name, options); +} + +export function list(cwd?: string, options?: Options) { + const workspace = Workspace.loadSync(cwd); + + return listAction(workspace, options); +} + +export function search(cwd?: string, options: Options = {}) { + const workspace = Workspace.loadSync(cwd); + + return fuzzySearchAction(workspace, options); +} diff --git a/tsconfig.json b/tsconfig.json index 504eb60..0611ab2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "outDir": "build", "sourceMap": true, "strict": true, + "declaration": true, /* Additional Checks */ "noUnusedLocals": false, From 953754ebab386ec9e51508ddb17da3ee054161b1 Mon Sep 17 00:00:00 2001 From: Dean Shub Date: Sat, 3 Jul 2021 15:34:18 +0300 Subject: [PATCH 2/6] Adding docs --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 09837da..db057d8 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,17 @@ lodash └── 3.10.1 ``` +## Usage in node +Each function can also receive optional CWD and optional Options (deps, match) +```js +import * as qnm from 'qnm' +qnm.match('module') +qnm.get('module') +qnm.list() +qnm.search() +``` + + Which means you have 3 occurrences of lodash in your `node_modules`: 1. `./node_module/lodash` @@ -132,7 +143,7 @@ eslint-plugin-react ``` ### homepage -Opens package "homepage" property in your browser. +Opens package "homepage" property in your browser. ### install-completions From 529adbc4838770c81c15a6f5289d4375168daa02 Mon Sep 17 00:00:00 2001 From: Dean Shub Date: Sat, 3 Jul 2021 15:42:47 +0300 Subject: [PATCH 3/6] fix lint --- src/__tests__/main.spec.ts | 17 ++++++++--------- src/main.ts | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/__tests__/main.spec.ts b/src/__tests__/main.spec.ts index 2a944fb..67bb3bc 100644 --- a/src/__tests__/main.spec.ts +++ b/src/__tests__/main.spec.ts @@ -1,5 +1,4 @@ -// @ts-ignore -import * as qnm from '../..'; +import * as qnm from '../..'; // eslint-disable-line import/no-useless-path-segments import { resolveFixture } from './utils'; describe('Node API', () => { @@ -20,14 +19,14 @@ describe('Node API', () => { it('should add dependents information on yarn installed package', () => { const cwd = resolveFixture('yarn-install'); - const output = qnm.match('import-from', cwd ); + const output = qnm.match('import-from', cwd); expect(output).toMatchSnapshot(); }); it('should show an indication in case there is a symlink', () => { const cwd = resolveFixture('symlink'); - const output = qnm.match('test', cwd ); + const output = qnm.match('test', cwd); expect(output).toMatchSnapshot(); }); @@ -41,7 +40,7 @@ describe('Node API', () => { it('should work in monorepo with yarn workspaces', () => { const cwd = resolveFixture('monorepo-with-workspaces'); - const output = qnm.match('package-foo', cwd ); + const output = qnm.match('package-foo', cwd); expect(output).toMatchSnapshot(); }); @@ -60,7 +59,7 @@ describe('Node API', () => { describe('qnm list', () => { it('should show all modules in node_modules directory', () => { const cwd = resolveFixture('mix-modules'); - const output = qnm.list( cwd ); + const output = qnm.list(cwd); expect(output).toMatchSnapshot(); }); @@ -74,14 +73,14 @@ describe('Node API', () => { it('should list dependencies in a yarn installed package and show "why" information', () => { const cwd = resolveFixture('yarn-install'); - const output = qnm.list( cwd ); + const output = qnm.list(cwd); expect(output).toMatchSnapshot(); }); it('should list a monorepo', () => { const cwd = resolveFixture('monorepo'); - const output = qnm.list(cwd ); + const output = qnm.list(cwd); expect(output).toMatchSnapshot(); }); @@ -90,7 +89,7 @@ describe('Node API', () => { describe('qnm match', () => { it('should match in monorepo and print subpackages modules', () => { const cwd = resolveFixture('monorepo'); - const output = qnm.match('packa', cwd ); + const output = qnm.match('packa', cwd); expect(output).toMatchSnapshot(); }); diff --git a/src/main.ts b/src/main.ts index aad8b44..bcbdc73 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,10 +8,10 @@ import fuzzySearchAction from './actions/fuzzy-search'; type Options = Pick; -export function match(match: string, cwd?: string, options?: Options) { +export function match(matchPattern: string, cwd?: string, options?: Options) { const workspace = Workspace.loadSync(cwd); - return matchAction(workspace, match, options); + return matchAction(workspace, matchPattern, options); } export function get(name: string, cwd?: string, options?: Options) { From 241870c255faf963995fd7cbdc96ff4a3cbc24c8 Mon Sep 17 00:00:00 2001 From: Dean Shub Date: Sat, 3 Jul 2021 15:45:52 +0300 Subject: [PATCH 4/6] fix build --- src/__tests__/main.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/main.spec.ts b/src/__tests__/main.spec.ts index 67bb3bc..4264af3 100644 --- a/src/__tests__/main.spec.ts +++ b/src/__tests__/main.spec.ts @@ -1,4 +1,4 @@ -import * as qnm from '../..'; // eslint-disable-line import/no-useless-path-segments +import * as qnm from '../main'; import { resolveFixture } from './utils'; describe('Node API', () => { From 2bfbdf596c9f6c749828a0db28c1f556b5a3e388 Mon Sep 17 00:00:00 2001 From: Dean Shub Date: Sat, 3 Jul 2021 16:43:21 +0300 Subject: [PATCH 5/6] without colors --- src/__tests__/__snapshots__/main.spec.ts.snap | 58 ++++++------------- src/main.ts | 13 +++-- 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/src/__tests__/__snapshots__/main.spec.ts.snap b/src/__tests__/__snapshots__/main.spec.ts.snap index b738e8b..41faad5 100644 --- a/src/__tests__/__snapshots__/main.spec.ts.snap +++ b/src/__tests__/__snapshots__/main.spec.ts.snap @@ -2,101 +2,81 @@ exports[`Node API qnm ] should add dependents information on yarn installed package 1`] = ` "import-from -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/yarn-install/node_modules/import-from/package.json3.0.0]8;; (import-cwd) +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/yarn-install/node_modules/import-from/package.json3.0.0]8;; (import-cwd) " `; exports[`Node API qnm ] should show an indication in case there is a symlink 1`] = ` "test -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/symlink/node_modules/test/package.json1.0.0]8;; -> ../../symlink-origin/node_modules/test (devDependencies, npm install test) +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/symlink/node_modules/test/package.json1.0.0]8;; -> ../../symlink-origin/node_modules/test (devDependencies, npm install test) " `; exports[`Node API qnm ] should show get matches when using the match command 1`] = ` "test -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/single-module/node_modules/test/package.json1.0.0]8;; (devDependencies, npm install test) +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/single-module/node_modules/test/package.json1.0.0]8;; (devDependencies, npm install test) " `; exports[`Node API qnm ] should show the version and dependents info on a single module when called with a string 1`] = ` "test -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/single-module/node_modules/test/package.json1.0.0]8;; (devDependencies, npm install test) +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/single-module/node_modules/test/package.json1.0.0]8;; (devDependencies, npm install test) " `; exports[`Node API qnm ] should work in monorepo and print subpackages modules 1`] = ` "package-foo -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-foo/package.json1.0.0]8;; +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-foo/package.json1.0.0]8;; " `; exports[`Node API qnm ] should work in monorepo with yarn workspaces 1`] = ` "package-foo -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo-with-workspaces/node_modules/package-foo/package.json1.0.0]8;; +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo-with-workspaces/node_modules/package-foo/package.json1.0.0]8;; " `; -exports[`Node API qnm list should list a monorepo 1`] = ` -"package-bar -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-bar/package.json1.0.0]8;; +exports[`Node API qnm list should list a monorepo 1`] = `""`; -package-baz -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-baz/package.json1.0.0]8;; - -package-foo -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-foo/package.json1.0.0]8;; -" -`; - -exports[`Node API qnm list should list dependencies in a yarn installed package and show "why" information 1`] = ` -"import-cwd -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/yarn-install/node_modules/import-cwd/package.json3.0.0]8;; - -import-from -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/yarn-install/node_modules/import-from/package.json3.0.0]8;; (import-cwd) - -resolve-from -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/yarn-install/node_modules/resolve-from/package.json5.0.0]8;; (import-from) -" -`; +exports[`Node API qnm list should list dependencies in a yarn installed package and show "why" information 1`] = `""`; exports[`Node API qnm list should show all modules in node_modules directory 1`] = ` "@scope/test -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/mix-modules/node_modules/@scope/test/package.json1.0.0]8;; +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/mix-modules/node_modules/@scope/test/package.json1.0.0]8;; another -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/mix-modules/node_modules/another/package.json1.0.0]8;; +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/mix-modules/node_modules/another/package.json1.0.0]8;; test -├── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/mix-modules/node_modules/test/package.json1.0.0]8;; +├── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/mix-modules/node_modules/test/package.json1.0.0]8;; └─┬ another - └── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/mix-modules/node_modules/another/node_modules/test/package.json1.0.0]8;; + └── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/mix-modules/node_modules/another/node_modules/test/package.json1.0.0]8;; " `; exports[`Node API qnm list should show modules mentioned in package.json 1`] = ` "dependency1 -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/indirect-dependencies/node_modules/dependency1/package.json1.0.0]8;; +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/indirect-dependencies/node_modules/dependency1/package.json1.0.0]8;; dependency2 -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/indirect-dependencies/node_modules/dependency2/package.json1.0.0]8;; +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/indirect-dependencies/node_modules/dependency2/package.json1.0.0]8;; devDependency1 -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/indirect-dependencies/node_modules/devDependency1/package.json1.0.0]8;; +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/indirect-dependencies/node_modules/devDependency1/package.json1.0.0]8;; devDependency2 -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/indirect-dependencies/node_modules/devDependency2/package.json1.0.0]8;; +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/indirect-dependencies/node_modules/devDependency2/package.json1.0.0]8;; " `; exports[`Node API qnm match should match in monorepo and print subpackages modules 1`] = ` "package-bar -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-bar/package.json1.0.0]8;; +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-bar/package.json1.0.0]8;; package-baz -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-baz/package.json1.0.0]8;; +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-baz/package.json1.0.0]8;; package-foo -└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-foo/package.json1.0.0]8;; +└── ]8;;File:/Users/deansh/Projects/qnm/src/__tests__/fixtures/monorepo/node_modules/package-foo/package.json1.0.0]8;; " `; diff --git a/src/main.ts b/src/main.ts index bcbdc73..b8e682f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,6 @@ import Workspace from './workspace/workspace'; import { CliOptions } from './cli'; +import merge from 'lodash/merge' import matchAction from './actions/match'; import getAction from './actions/get'; @@ -8,26 +9,30 @@ import fuzzySearchAction from './actions/fuzzy-search'; type Options = Pick; +const defaultOptions = { + noColor: true, +} + export function match(matchPattern: string, cwd?: string, options?: Options) { const workspace = Workspace.loadSync(cwd); - return matchAction(workspace, matchPattern, options); + return matchAction(workspace, matchPattern, merge(defaultOptions, options)); } export function get(name: string, cwd?: string, options?: Options) { const workspace = Workspace.loadSync(cwd); - return getAction(workspace, name, options); + return getAction(workspace, name, merge(defaultOptions, options)); } export function list(cwd?: string, options?: Options) { const workspace = Workspace.loadSync(cwd); - return listAction(workspace, options); + return listAction(workspace, merge(defaultOptions, options)); } export function search(cwd?: string, options: Options = {}) { const workspace = Workspace.loadSync(cwd); - return fuzzySearchAction(workspace, options); + return fuzzySearchAction(workspace, merge(defaultOptions, options)); } From 8ec9b8202499b3b9b7c5d9a0203047f47b85bef7 Mon Sep 17 00:00:00 2001 From: Dean Shub Date: Sat, 3 Jul 2021 17:25:54 +0300 Subject: [PATCH 6/6] fix lint --- src/main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index b8e682f..a378397 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,6 @@ +import merge from 'lodash/merge'; import Workspace from './workspace/workspace'; import { CliOptions } from './cli'; -import merge from 'lodash/merge' import matchAction from './actions/match'; import getAction from './actions/get'; @@ -11,7 +11,7 @@ type Options = Pick; const defaultOptions = { noColor: true, -} +}; export function match(matchPattern: string, cwd?: string, options?: Options) { const workspace = Workspace.loadSync(cwd);