From c77a7ba32dfa48b8dd19c67eeb3acda72387b24a Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Fri, 21 Jun 2024 08:35:48 +0200 Subject: [PATCH 1/2] fix(cli-config): include peer dependencies when finding dependencies --- packages/cli-config/src/findDependencies.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/cli-config/src/findDependencies.ts b/packages/cli-config/src/findDependencies.ts index cb0f5ecd0..eecf22b22 100644 --- a/packages/cli-config/src/findDependencies.ts +++ b/packages/cli-config/src/findDependencies.ts @@ -8,17 +8,17 @@ export default function findDependencies(root: string): Array { let pjson; try { - pjson = JSON.parse( - fs.readFileSync(path.join(root, 'package.json'), 'utf8'), - ); + const content = fs.readFileSync(path.join(root, 'package.json'), 'utf8'); + pjson = JSON.parse(content); } catch (e) { return []; } - const deps = [ + const deps = new Set([ ...Object.keys(pjson.dependencies || {}), + ...Object.keys(pjson.peerDependencies || {}), ...Object.keys(pjson.devDependencies || {}), - ]; + ]); - return deps; + return Array.from(deps); } From 5a142e9ac2895f4048e1f04649aba4c25b62ac89 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:23:01 +0200 Subject: [PATCH 2/2] add tests --- .../src/__tests__/findDependencies-test.ts | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/packages/cli-config/src/__tests__/findDependencies-test.ts b/packages/cli-config/src/__tests__/findDependencies-test.ts index 9f43f4437..84e3fafec 100644 --- a/packages/cli-config/src/__tests__/findDependencies-test.ts +++ b/packages/cli-config/src/__tests__/findDependencies-test.ts @@ -1,23 +1,35 @@ import findDependencies from '../findDependencies'; import {cleanup, writeFiles, getTempDirectory} from '../../../../jest/helpers'; -beforeEach(async () => { - cleanup(DIR); - jest.resetModules(); -}); +describe('findDependencies', () => { + const DIR = getTempDirectory('find_dependencies_test'); + + beforeEach(() => { + cleanup(DIR); + jest.resetModules(); + }); -afterEach(() => cleanup(DIR)); + afterEach(() => cleanup(DIR)); -const DIR = getTempDirectory('find_dependencies_test'); + test('returns packages from dependencies, peer and dev dependencies', () => { + writeFiles(DIR, { + 'package.json': JSON.stringify({ + dependencies: {'rnpm-plugin-test': '*'}, + peerDependencies: {'rnpm-plugin-test-2': '*'}, + devDependencies: {'rnpm-plugin-test-3': '*'}, + }), + }); + expect(findDependencies(DIR)).toHaveLength(3); + }); -test('returns plugins from both dependencies and dev dependencies', () => { - writeFiles(DIR, { - 'package.json': ` - { - "dependencies": {"rnpm-plugin-test": "*"}, - "devDependencies": {"rnpm-plugin-test-2": "*"} - } - `, + test('dedupes dependencies', () => { + writeFiles(DIR, { + 'package.json': JSON.stringify({ + dependencies: {'rnpm-plugin-test': '*'}, + peerDependencies: {'rnpm-plugin-test-2': '*'}, + devDependencies: {'rnpm-plugin-test-2': '*'}, + }), + }); + expect(findDependencies(DIR)).toHaveLength(2); }); - expect(findDependencies(DIR)).toHaveLength(2); });