Skip to content

Commit 6e50673

Browse files
committed
refactor: enhance type definitions for package handling
- Introduced `NormalizedPackageJson` and `NormalizedReadResult` interfaces to improve type safety and clarity in package handling. - Updated the `readPackageUpSync` function to utilize the new type definitions, ensuring consistent and accurate package data retrieval.
1 parent 99e2708 commit 6e50673

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

packages/bundler/src/readPackageUp.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,32 @@
22
// so native-utils cannot be imported by bundler at build time.
33
// The canonical implementation lives in @wdio/native-utils/src/package.ts.
44
import { readFileSync } from 'node:fs';
5-
import type { NormalizedPackageJson, NormalizedReadResult } from '@wdio/native-types';
65
import { findUpSync } from 'find-up';
76

8-
export type { NormalizedPackageJson, NormalizedReadResult };
7+
export interface NormalizedPackageJson {
8+
name?: string;
9+
version?: string;
10+
description?: string;
11+
main?: string;
12+
module?: string;
13+
types?: string;
14+
exports?: unknown;
15+
type?: string;
16+
dependencies?: Record<string, string>;
17+
devDependencies?: Record<string, string>;
18+
optionalDependencies?: Record<string, string>;
19+
peerDependencies?: Record<string, string>;
20+
scripts?: Record<string, string>;
21+
[key: string]: unknown;
22+
}
23+
24+
export interface NormalizedReadResult {
25+
packageJson: NormalizedPackageJson;
26+
path: string;
27+
}
928

1029
export function readPackageUpSync(options: { cwd?: string } = {}): NormalizedReadResult | undefined {
1130
const filePath = findUpSync('package.json', { cwd: options.cwd || process.cwd() });
1231
if (!filePath) return undefined;
13-
return { packageJson: JSON.parse(readFileSync(filePath, 'utf-8')), path: filePath };
32+
return { packageJson: JSON.parse(readFileSync(filePath, 'utf-8')) as NormalizedPackageJson, path: filePath };
1433
}

0 commit comments

Comments
 (0)