diff --git a/packages/graph/src/graph/package-graph/graph.ts b/packages/graph/src/graph/package-graph/graph.ts index a06e0b027..94d65d4eb 100644 --- a/packages/graph/src/graph/package-graph/graph.ts +++ b/packages/graph/src/graph/package-graph/graph.ts @@ -80,6 +80,7 @@ export class PackageGraph implements SDK.PackageGraphInstance { return pkg; } + // TODO: add test for this function. const readPackageJson = ( file: string, readFile?: SDK.GetPackageFile, @@ -97,8 +98,10 @@ export class PackageGraph implements SDK.PackageGraphInstance { readFile(join(current, 'package.json')) || PackageUtil.getPackageMetaFromModulePath(file); } - if (!readFile || !result?.name) { + if (!readFile) { result = PackageUtil.getPackageMetaFromModulePath(file); + } else if (!result?.name) { + result = undefined; } } diff --git a/packages/graph/tests/module-graph.spec.ts b/packages/graph/tests/module-graph.spec.ts index 804d0be7d..203b17956 100644 --- a/packages/graph/tests/module-graph.spec.ts +++ b/packages/graph/tests/module-graph.spec.ts @@ -2,7 +2,7 @@ import path from 'path'; import { expect, describe, it } from 'vitest'; import type { SDK } from '@rsdoctor/types'; import { Module, ModuleGraph, PackageGraph } from '../src/graph'; - +// TODO: simplyfy the module-graph-basic.json data size. const resolveFixture = (...paths: string[]) => { return path.resolve(__dirname, 'fixture', ...paths); }; @@ -73,7 +73,7 @@ describe('module graph', () => { const pkgGraph = PackageGraph.fromModuleGraph(moduleGraph, '.'); const pkgData = pkgGraph.toData(); - expect(pkgData.packages[0].root).toBeTruthy(); // TODO: test error + expect(pkgData.packages[0].root).toBeTruthy(); pkgData.packages.forEach((pkg) => (pkg.root = '')); expect(pkgData).toMatchSnapshot(); });