Skip to content

Commit 4864ecb

Browse files
committed
refactor: replace read-package-up with custom implementation
- Removed `read-package-up` dependency from multiple package.json files and replaced it with a custom `readPackageUp` function in `@wdio/native-utils`. - Updated imports across various files to utilize the new implementation and ensure consistency with `NormalizedPackageJson`. - Added `find-up` dependency version 6.3.0 to facilitate the new package resolution logic.
1 parent c12ad90 commit 4864ecb

13 files changed

Lines changed: 32 additions & 119 deletions

File tree

e2e/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"@wdio/types": "catalog:",
6767
"cross-env": "^10.1.0",
6868
"p-limit": "^7.3.0",
69-
"read-package-up": "^12.0.0",
7069
"typescript": "^5.9.3",
7170
"zod": "^4.3.6"
7271
}

packages/bundler/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@rollup/plugin-typescript": "^12.3.0",
4040
"commander": "^14.0.3",
4141
"debug": "^4.4.3",
42-
"read-package-up": "^12.0.0",
42+
"find-up": "^6.3.0",
4343
"rollup": "^4.59.0",
4444
"rollup-plugin-node-externals": "^8.1.2",
4545
"tsx": "^4.21.0",
@@ -48,6 +48,7 @@
4848
"devDependencies": {
4949
"@types/debug": "^4.1.12",
5050
"@types/node": "^25.3.0",
51+
"@wdio/native-types": "workspace:*",
5152
"@vitest/coverage-v8": "^4.0.18",
5253
"shx": "^0.4.0",
5354
"terser": "^5.46.0",

packages/bundler/src/plugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { normalize } from 'node:path';
2-
import type { NormalizedPackageJson } from 'read-package-up';
32
import type { Plugin } from 'rollup';
3+
import type { NormalizedPackageJson } from './readPackageUp.js';
44
import { type InjectDependencyPluginOptions, injectDependency } from './utils';
55

66
export const MODULE_TYPE = {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Inlined here to avoid a circular build dependency: bundler builds native-utils,
2+
// so native-utils cannot be imported by bundler at build time.
3+
// The canonical implementation lives in @wdio/native-utils/src/package.ts.
4+
import { readFileSync } from 'node:fs';
5+
import type { NormalizedPackageJson, NormalizedReadResult } from '@wdio/native-types';
6+
import { findUpSync } from 'find-up';
7+
8+
export type { NormalizedPackageJson, NormalizedReadResult };
9+
10+
export function readPackageUpSync(options: { cwd?: string } = {}): NormalizedReadResult | undefined {
11+
const filePath = findUpSync('package.json', { cwd: options.cwd || process.cwd() });
12+
if (!filePath) return undefined;
13+
return { packageJson: JSON.parse(readFileSync(filePath, 'utf-8')), path: filePath };
14+
}

packages/bundler/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { existsSync } from 'node:fs';
22
import { basename, dirname, join, posix, relative } from 'node:path';
33
import nodeResolve from '@rollup/plugin-node-resolve';
4-
import { type NormalizedReadResult, readPackageUpSync } from 'read-package-up';
54
import { type PluginContext, rollup } from 'rollup';
5+
import { type NormalizedReadResult, readPackageUpSync } from './readPackageUp.js';
66

77
const normalizeToPosix = (path: string) => {
88
// Handle both forward and backslashes

packages/electron-service/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
"fast-copy": "^4.0.2",
6666
"get-port": "^7.1.0",
6767
"puppeteer-core": "^24.37.5",
68-
"read-package-up": "^12.0.0",
6968
"recast": "^0.23.9",
7069
"tinyspy": "^4.0.4",
7170
"webdriverio": "catalog:default"

packages/native-types/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"@wdio/types": "catalog:default",
4444
"builder-util": "^26.8.0",
4545
"electron": "catalog:default",
46-
"read-package-up": "^12.0.0",
4746
"shx": "^0.4.0",
4847
"typescript": "^5.9.3",
4948
"webdriverio": "catalog:default"

packages/native-types/src/electron.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,9 @@ import type { Capabilities, Options } from '@wdio/types';
55
import type { ArchType } from 'builder-util';
66
import type * as Electron from 'electron';
77

8-
export type PackageJson = {
9-
name?: string;
10-
version?: string;
11-
description?: string;
12-
main?: string;
13-
type?: string;
14-
dependencies?: Record<string, string>;
15-
devDependencies?: Record<string, string>;
16-
[key: string]: unknown;
17-
};
8+
import type { NormalizedPackageJson } from './package.js';
9+
10+
export type PackageJson = NormalizedPackageJson;
1811

1912
import type {
2013
AbstractFn,

packages/native-types/src/package.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ export type NormalizedPackageJson = {
1313
executableName?: string;
1414
[key: string]: unknown;
1515
};
16+
config?: { forge?: unknown; [key: string]: unknown };
1617
forge?: unknown;
1718
exports?: Record<string, unknown>;
1819
module?: string;
20+
productName?: string;
1921
[key: string]: unknown;
2022
};
2123

packages/native-utils/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"find-up": "^6.3.0",
4747
"find-versions": "^6.0.0",
4848
"json5": "^2.2.3",
49-
"read-package-up": "^12.0.0",
5049
"smol-toml": "^1.6.0",
5150
"tsx": "^4.21.0",
5251
"yaml": "^2.8.2"

0 commit comments

Comments
 (0)