UNPKG

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