|
2 | 2 | // so native-utils cannot be imported by bundler at build time. |
3 | 3 | // The canonical implementation lives in @wdio/native-utils/src/package.ts. |
4 | 4 | import { readFileSync } from 'node:fs'; |
5 | | -import type { NormalizedPackageJson, NormalizedReadResult } from '@wdio/native-types'; |
6 | 5 | import { findUpSync } from 'find-up'; |
7 | 6 |
|
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 | +} |
9 | 28 |
|
10 | 29 | export function readPackageUpSync(options: { cwd?: string } = {}): NormalizedReadResult | undefined { |
11 | 30 | const filePath = findUpSync('package.json', { cwd: options.cwd || process.cwd() }); |
12 | 31 | 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 }; |
14 | 33 | } |
0 commit comments