Skip to content

Commit

Permalink
fix(graph): duplicate pcks error
Browse files Browse the repository at this point in the history
fix(graph): duplicate pcks error
  • Loading branch information
easy1090 committed Dec 9, 2023
1 parent ab32629 commit 8a0c0ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/graph/src/graph/package-graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/graph/tests/module-graph.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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();
});
Expand Down

0 comments on commit 8a0c0ba

Please sign in to comment.