project-path-resolver
v0.1.0
Published
TS package, to get `project root dir path` and `script list with call order`, work stable
Maintainers
Readme
this is a npm package of TS, can get project root dir path and script list with call order.
it can get project root —— not modules root like other npm packages.
Features
- Feature 1: different path to run script/project, always get same and right result.

- Feature 2: no depend
- Feature 3: it support pnpm all mode
- Feature 4: work stable and well, also for issue below:
- package
find-project-rootwill return incorrect path, when you run modules/script out of the project. - here a local package project(just call
A), and callproject-root-directorypackage in it. When you import/requireAin another projectBviapnpm link, now it will get incorrect result inA—— isAbut expectB.
- package
- Feature 5: support absolute or relative path for called script.
- Feature 6: support convert
pnpm modules pathtogeneral path(with project root).
Installation
To install the package, use the following command:
npm install project-path-resolver
yarn add project-path-resolver
pnpm add project-path-resolverUsage
Import the package in your project as follows:
const { getProjectRootPath, getScriptCallList, getScriptListInCallStack } = require("project-path-resolver");import { getProjectRootPath, getScriptCallList, getScriptListInCallStack } from "project-path-resolver";Use it as follows:
// get project root dir path
console.log("ProjectRoot:", getProjectRootPath());
console.log("ProjectRoot:", getProjectRootPath({ rootFileName: "package.json" }));
console.log("ProjectRoot:", getProjectRootPath({ scriptListInCallStack: getScriptListInCallStack() }));
console.log(
"ProjectRoot:",
getProjectRootPath({ rootFileName: "package.json", scriptListInCallStack: getScriptListInCallStack() })
);
// get script list with call order
console.log("ScriptCallList:", getScriptCallList({ absolute: true, pnpmTranslate: true }));
console.log("ScriptCallList:", getScriptCallList({ absolute: true, pnpmTranslate: false }));
console.log("ScriptCallList:", getScriptCallList({ absolute: false, pnpmTranslate: false }));
console.log("ScriptCallList:", getScriptCallList({ absolute: false, pnpmTranslate: true }));Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes and push the branch.
- Submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
