diff --git a/index.d.ts b/index.d.ts index 35e1fdd..7829b7a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -7,7 +7,7 @@ export type Options = { @default process.cwd() */ - cwd?: string; + cwd?: URL | string; } & Except; export type NormalizeOptions = { @@ -16,7 +16,7 @@ export type NormalizeOptions = { @default process.cwd() */ - cwd?: string; + cwd?: URL | string; } & Except; export interface ReadResult { diff --git a/index.test-d.ts b/index.test-d.ts index fa7e838..ef950ef 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -5,12 +5,18 @@ expectType>(readPackageUp()); expectType>( readPackageUp({cwd: '.'}), ); +expectType>( + readPackageUp({cwd: new URL('file:///path/to/cwd/')}), +); expectType>( readPackageUp({normalize: true}), ); expectType>( readPackageUp({cwd: '.', normalize: true}), ); +expectType>( + readPackageUp({cwd: new URL('file:///path/to/cwd/'), normalize: true}), +); expectType>( readPackageUp({normalize: false}), ); @@ -22,12 +28,18 @@ expectType(readPackageUpSync()); expectType( readPackageUpSync({cwd: '.'}), ); +expectType( + readPackageUpSync({cwd: new URL('file:///path/to/cwd/')}), +); expectType( readPackageUpSync({normalize: true}), ); expectType( readPackageUpSync({cwd: '.', normalize: true}), ); +expectType( + readPackageUpSync({cwd: new URL('file:///path/to/cwd/'), normalize: true}), +); expectType( readPackageUpSync({normalize: false}), ); diff --git a/package.json b/package.json index 68f2771..e54950f 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,8 @@ "path" ], "dependencies": { - "find-up": "^6.2.0", - "read-pkg": "^7.0.0", + "find-up": "^6.3.0", + "read-pkg": "^7.1.0", "type-fest": "^2.5.0" }, "devDependencies": { diff --git a/readme.md b/readme.md index f92e2a3..ca0e55a 100644 --- a/readme.md +++ b/readme.md @@ -48,7 +48,7 @@ Type: `object` ##### cwd -Type: `string`\ +Type: `URL | string`\ Default: `process.cwd()` The directory to start looking for a package.json file. diff --git a/test.js b/test.js index a24568e..c17d4e1 100644 --- a/test.js +++ b/test.js @@ -9,6 +9,10 @@ test('async', async t => { const result = await readPackageUp({cwd}); t.is(result.packageJson.name, 'read-pkg-up'); t.is(result.path, packagePath); + t.deepEqual( + await readPackageUp({cwd: new URL(cwd, import.meta.url)}), + result, + ); t.is(await readPackageUp({cwd: '/'}), undefined); }); @@ -17,6 +21,10 @@ test('sync', t => { const result = readPackageUpSync({cwd}); t.is(result.packageJson.name, 'read-pkg-up'); t.is(result.path, packagePath); + t.deepEqual( + readPackageUpSync({cwd: new URL(cwd, import.meta.url)}), + result, + ); t.is(readPackageUpSync({cwd: '/'}), undefined); });