UNPKG

1.03 kBJavaScriptView Raw
1import { resolve } from "path"
2import { hrefToPathname, pathnameToRelativePath } from "@jsenv/href"
3import {
4 pathnameToOperatingSystemPath,
5 operatingSystemPathToPathname,
6} from "@jsenv/operating-system-path"
7
8let jsenvBundlingProjectPath
9if (typeof __filename === "string") {
10 jsenvBundlingProjectPath = resolve(__filename, "../../../") // get ride of dist/node/main.js
11} else {
12 const selfPathname = hrefToPathname(import.meta.url)
13 const selfPath = pathnameToOperatingSystemPath(selfPathname)
14 jsenvBundlingProjectPath = resolve(selfPath, "../../") // get ride of src/JSENV_PATH.js
15}
16
17export { jsenvBundlingProjectPath }
18
19export const jsenvBundlingProjectPathname = operatingSystemPathToPathname(jsenvBundlingProjectPath)
20
21export const jsenvBundlingRelativePathInception = ({
22 jsenvBundlingRelativePath,
23 projectPathname,
24}) => {
25 const jsenvPathname = `${jsenvBundlingProjectPathname}${jsenvBundlingRelativePath}`
26 const relativePath = pathnameToRelativePath(jsenvPathname, projectPathname)
27 return relativePath
28}