Skip to content
This repository was archived by the owner on Dec 4, 2022. It is now read-only.

Commit 623ede4

Browse files
committed
fix tests
1 parent fa222f8 commit 623ede4

File tree

2 files changed

+62
-11
lines changed

2 files changed

+62
-11
lines changed

src/dependency-builder/build-tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function resolveNodePackage(cwd: string, packageFullPath: string): Record
8383
// we will look for the package.json on the dependency but won't find it
8484
// if we propagate we will take the version from the root's package json which has nothing with the component version
8585
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
86-
const packageInfo = PackageJson.getPackageJsonSync(packageDir);
86+
const packageInfo = PackageJson.loadSync(packageDir);
8787

8888
// when running 'bitjs get-dependencies' command, packageInfo is sometimes empty
8989
// or when using custom-module-resolution it may be empty or the name/version are empty

src/package-json/package-json.ts

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,68 @@ function convertComponentsIdToValidPackageName(registryPrefix: string, id: strin
1212
return `${registryPrefix}/${id.replace(/\//g, '.')}`;
1313
}
1414

15+
export type PackageJsonProps = {
16+
name?: string;
17+
version?: string;
18+
homepage?: string;
19+
main?: string;
20+
dependencies?: Record<string, any>;
21+
devDependencies?: Record<string, any>;
22+
peerDependencies?: Record<string, any>;
23+
license?: string;
24+
scripts?: Record<string, any>;
25+
workspaces?: string[];
26+
private?: boolean;
27+
};
28+
1529
export default class PackageJson {
30+
name?: string;
31+
version?: string;
32+
homepage?: string;
33+
main?: string;
34+
dependencies?: Record<string, any>;
35+
devDependencies?: Record<string, any>;
36+
peerDependencies?: Record<string, any>;
37+
componentRootFolder?: string; // path where to write the package.json
38+
license?: string;
39+
scripts?: Record<string, any>;
40+
workspaces?: string[];
41+
42+
constructor(
43+
componentRootFolder: string,
44+
{
45+
name,
46+
version,
47+
homepage,
48+
main,
49+
dependencies,
50+
devDependencies,
51+
peerDependencies,
52+
license,
53+
scripts,
54+
workspaces
55+
}: PackageJsonProps
56+
) {
57+
this.name = name;
58+
this.version = version;
59+
this.homepage = homepage;
60+
this.main = main;
61+
this.dependencies = dependencies;
62+
this.devDependencies = devDependencies;
63+
this.peerDependencies = peerDependencies;
64+
this.componentRootFolder = componentRootFolder;
65+
this.license = license;
66+
this.scripts = scripts;
67+
this.workspaces = workspaces;
68+
}
69+
70+
static loadSync(componentRootFolder: string): PackageJson | null {
71+
const composedPath = composePath(componentRootFolder);
72+
if (!PackageJson.hasExisting(componentRootFolder)) return null;
73+
const componentJsonObject = fs.readJsonSync(composedPath);
74+
return new PackageJson(componentRootFolder, componentJsonObject);
75+
}
76+
1677
static hasExisting(componentRootFolder: string): boolean {
1778
const packageJsonPath = composePath(componentRootFolder);
1879
return fs.pathExistsSync(packageJsonPath);
@@ -72,16 +133,6 @@ export default class PackageJson {
72133
return null;
73134
}
74135

75-
/*
76-
* load package.json from path
77-
*/
78-
static async getPackageJsonSync(pathStr: string) {
79-
const getRawObject = () => fs.readJsonSync(composePath(pathStr));
80-
const exist = PackageJson.hasExisting(pathStr);
81-
if (exist) return getRawObject();
82-
return null;
83-
}
84-
85136
/*
86137
* save package.json in path
87138
*/

0 commit comments

Comments
 (0)