Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Nov 3, 2021
1 parent 5a4c9fb commit 627d0cc
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/@yarn-tool/resolve-package/index.d.ts
@@ -1,9 +1,15 @@
import type { IPackageJson } from '@ts-type/package-dts';
export declare function resolvePackage(name: string, options?: {
/**
* @see RequireResolve
*/
paths?: string[];
}): {
name: string;
pkgRoot: string;
pkg: IPackageJson<any>;
pkgConfigLocation: string;
entryPointLocation: string;
resolveLocation(path: string, ...paths: string[]): string;
};
export default resolvePackage;
12 changes: 10 additions & 2 deletions packages/@yarn-tool/resolve-package/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions packages/@yarn-tool/resolve-package/index.ts
@@ -1,14 +1,29 @@
import { dirname } from 'upath2';
import { dirname, normalize, sep, resolve } from 'upath2';
import type { IPackageJson } from '@ts-type/package-dts';
import { sync as pkgDir } from 'pkg-dir';

export function resolvePackage(name: string, options?: { paths?: string[]; })
export function resolvePackage(name: string, options?: {
/**
* @see RequireResolve
*/
paths?: string[];
})
{
let pkgRoot = dirname(require.resolve(`${name}/package.json`, options));
const entryPointLocation = require.resolve(name, options);
const pkgRoot = pkgDir(entryPointLocation);

const pkgConfigLocation: string = resolve(pkgRoot, 'package.json');

return {
name,
pkgRoot,
pkg: require(`${pkgRoot}/package.json`) as any as IPackageJson,
pkg: require(pkgConfigLocation) as any as IPackageJson,
pkgConfigLocation,
entryPointLocation,
resolveLocation(path: string, ...paths: string[])
{
return resolve(pkgRoot, path, ...paths)
},
}
}

Expand Down
27 changes: 26 additions & 1 deletion packages/@yarn-tool/resolve-package/package.json
@@ -1,7 +1,31 @@
{
"name": "@yarn-tool/resolve-package",
"version": "1.0.35",
"description": "",
"description": "resolve package root and package.json paths",
"keywords": [
"resolve",
"package",
"json",
"root",
"npm",
"entry",
"find",
"up",
"find-up",
"findup",
"look-up",
"look",
"file",
"search",
"match",
"parent",
"parents",
"folder",
"directory",
"walk",
"walking",
"path"
],
"homepage": "https://github.com/bluelovers/ws-yarn-workspaces/tree/master/packages/@yarn-tool/resolve-package#readme",
"bugs": {
"url": "https://github.com/bluelovers/ws-yarn-workspaces/issues"
Expand Down Expand Up @@ -30,6 +54,7 @@
},
"dependencies": {
"@ts-type/package-dts": "^1.0.51",
"pkg-dir": "< 6 >= 5",
"tslib": "^2.3.1",
"upath2": "^3.1.10"
},
Expand Down

0 comments on commit 627d0cc

Please sign in to comment.