@stryke/path 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,25 +6,28 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.correctPath = correctPath;
7
7
  exports.normalizeString = normalizeString;
8
8
  exports.normalizeWindowsPath = normalizeWindowsPath;
9
+ exports.toAbsolutePath = toAbsolutePath;
10
+ exports.toRelativePath = toRelativePath;
9
11
  var _isFile = require("./is-file.cjs");
12
+ var _joinPaths = require("./join-paths.cjs");
10
13
  var _regex = require("./regex.cjs");
11
14
  var _slash = require("./slash.cjs");
12
15
  function normalizeWindowsPath(e = "") {
13
- return e && (0, _slash.slash)(e).replace(_regex.DRIVE_LETTER_START_REGEX, s => s.toUpperCase());
16
+ return e && (0, _slash.slash)(e).replace(_regex.DRIVE_LETTER_START_REGEX, n => n.toUpperCase());
14
17
  }
15
18
  function correctPath(e) {
16
19
  if (!e || e.length === 0) return ".";
17
20
  e = normalizeWindowsPath(e);
18
- const s = e.match(_regex.UNC_REGEX),
19
- n = (0, _isFile.isAbsolutePath)(e),
20
- l = e.endsWith("/");
21
- return e = normalizeString(e, !n), e.length === 0 ? n ? "/" : l ? "./" : "." : (l && (e += "/"), _regex.DRIVE_LETTER_REGEX.test(e) && (e += "/"), s ? n ? `//${e}` : `//./${e}` : !e.startsWith("/") && n && !_regex.DRIVE_LETTER_REGEX.test(e) ? `/${e}` : e);
21
+ const n = e.match(_regex.UNC_REGEX),
22
+ r = (0, _isFile.isAbsolutePath)(e),
23
+ i = e.endsWith("/");
24
+ return e = normalizeString(e, !r), e.length === 0 ? r ? "/" : i ? "./" : "." : (i && (e += "/"), _regex.DRIVE_LETTER_REGEX.test(e) && (e += "/"), n ? r ? `//${e}` : `//./${e}` : !e.startsWith("/") && r && !_regex.DRIVE_LETTER_REGEX.test(e) ? `/${e}` : e);
22
25
  }
23
- function normalizeString(e, s) {
24
- let n = "",
25
- l = 0,
26
- i = -1,
27
- r = 0,
26
+ function normalizeString(e, n) {
27
+ let r = "",
28
+ i = 0,
29
+ l = -1,
30
+ s = 0,
28
31
  o = null;
29
32
  for (let t = 0; t <= e.length; ++t) {
30
33
  if (t < e.length) o = e[t];else {
@@ -32,21 +35,27 @@ function normalizeString(e, s) {
32
35
  o = "/";
33
36
  }
34
37
  if (o === "/") {
35
- if (!(i === t - 1 || r === 1)) if (r === 2) {
36
- if (n.length < 2 || l !== 2 || n[n.length - 1] !== "." || n[n.length - 2] !== ".") {
37
- if (n.length > 2) {
38
- const f = n.lastIndexOf("/");
39
- f === -1 ? (n = "", l = 0) : (n = n.slice(0, f), l = n.length - 1 - n.lastIndexOf("/")), i = t, r = 0;
38
+ if (!(l === t - 1 || s === 1)) if (s === 2) {
39
+ if (r.length < 2 || i !== 2 || r[r.length - 1] !== "." || r[r.length - 2] !== ".") {
40
+ if (r.length > 2) {
41
+ const u = r.lastIndexOf("/");
42
+ u === -1 ? (r = "", i = 0) : (r = r.slice(0, u), i = r.length - 1 - r.lastIndexOf("/")), l = t, s = 0;
40
43
  continue;
41
- } else if (n.length > 0) {
42
- n = "", l = 0, i = t, r = 0;
44
+ } else if (r.length > 0) {
45
+ r = "", i = 0, l = t, s = 0;
43
46
  continue;
44
47
  }
45
48
  }
46
- s && (n += n.length > 0 ? "/.." : "..", l = 2);
47
- } else n.length > 0 ? n += `/${e.slice(i + 1, t)}` : n = e.slice(i + 1, t), l = t - i - 1;
48
- i = t, r = 0;
49
- } else o === "." && r !== -1 ? ++r : r = -1;
49
+ n && (r += r.length > 0 ? "/.." : "..", i = 2);
50
+ } else r.length > 0 ? r += `/${e.slice(l + 1, t)}` : r = e.slice(l + 1, t), i = t - l - 1;
51
+ l = t, s = 0;
52
+ } else o === "." && s !== -1 ? ++s : s = -1;
50
53
  }
51
- return n;
54
+ return r;
55
+ }
56
+ function toAbsolutePath(e, n) {
57
+ return (0, _isFile.isAbsolutePath)(e) ? e : (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(n || process.cwd(), e), !0));
58
+ }
59
+ function toRelativePath(e, n) {
60
+ return !e || e.length === 0 ? "." : ((0, _isFile.isAbsolutePath)(e) ? e = (0, _slash.slash)(normalizeString(e, !0)) : e = (0, _slash.slash)(normalizeString((0, _joinPaths.joinPaths)(n || process.cwd(), e), !0)), e.startsWith("./") ? e.slice(2) : e);
52
61
  }
@@ -14,3 +14,19 @@ export declare function correctPath(path?: string): string;
14
14
  * @returns the normalize path string.
15
15
  */
16
16
  export declare function normalizeString(path: string, allowAboveRoot: boolean): string;
17
+ /**
18
+ * Converts a given path to an absolute path based on the current working directory.
19
+ *
20
+ * @param path - The path to convert to an absolute path.
21
+ * @param cwd - The current working directory to use as the base path if the path is not absolute.
22
+ * @returns The absolute path.
23
+ */
24
+ export declare function toAbsolutePath(path: string, cwd?: string): string;
25
+ /**
26
+ * Converts a given path to a relative path based on the current working directory.
27
+ *
28
+ * @param path - The path to convert to a relative path.
29
+ * @param cwd - The current working directory to use as the base path if the path is not absolute.
30
+ * @returns The relative path.
31
+ */
32
+ export declare function toRelativePath(path: string, cwd?: string): string;
@@ -1 +1 @@
1
- import{isAbsolutePath as c}from"./is-file";import{DRIVE_LETTER_REGEX as g,DRIVE_LETTER_START_REGEX as u,UNC_REGEX as E}from"./regex";import{slash as m}from"./slash";export function normalizeWindowsPath(e=""){return e&&m(e).replace(u,s=>s.toUpperCase())}export function correctPath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const s=e.match(E),n=c(e),l=e.endsWith("/");return e=normalizeString(e,!n),e.length===0?n?"/":l?"./":".":(l&&(e+="/"),g.test(e)&&(e+="/"),s?n?`//${e}`:`//./${e}`:!e.startsWith("/")&&n&&!g.test(e)?`/${e}`:e)}export function normalizeString(e,s){let n="",l=0,i=-1,r=0,o=null;for(let t=0;t<=e.length;++t){if(t<e.length)o=e[t];else{if(o==="/")break;o="/"}if(o==="/"){if(!(i===t-1||r===1))if(r===2){if(n.length<2||l!==2||n[n.length-1]!=="."||n[n.length-2]!=="."){if(n.length>2){const f=n.lastIndexOf("/");f===-1?(n="",l=0):(n=n.slice(0,f),l=n.length-1-n.lastIndexOf("/")),i=t,r=0;continue}else if(n.length>0){n="",l=0,i=t,r=0;continue}}s&&(n+=n.length>0?"/..":"..",l=2)}else n.length>0?n+=`/${e.slice(i+1,t)}`:n=e.slice(i+1,t),l=t-i-1;i=t,r=0}else o==="."&&r!==-1?++r:r=-1}return n}
1
+ import{isAbsolutePath as g}from"./is-file";import{joinPaths as c}from"./join-paths";import{DRIVE_LETTER_REGEX as m,DRIVE_LETTER_START_REGEX as E,UNC_REGEX as d}from"./regex";import{slash as f}from"./slash";export function normalizeWindowsPath(e=""){return e&&f(e).replace(E,n=>n.toUpperCase())}export function correctPath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const n=e.match(d),r=g(e),i=e.endsWith("/");return e=normalizeString(e,!r),e.length===0?r?"/":i?"./":".":(i&&(e+="/"),m.test(e)&&(e+="/"),n?r?`//${e}`:`//./${e}`:!e.startsWith("/")&&r&&!m.test(e)?`/${e}`:e)}export function normalizeString(e,n){let r="",i=0,l=-1,s=0,o=null;for(let t=0;t<=e.length;++t){if(t<e.length)o=e[t];else{if(o==="/")break;o="/"}if(o==="/"){if(!(l===t-1||s===1))if(s===2){if(r.length<2||i!==2||r[r.length-1]!=="."||r[r.length-2]!=="."){if(r.length>2){const u=r.lastIndexOf("/");u===-1?(r="",i=0):(r=r.slice(0,u),i=r.length-1-r.lastIndexOf("/")),l=t,s=0;continue}else if(r.length>0){r="",i=0,l=t,s=0;continue}}n&&(r+=r.length>0?"/..":"..",i=2)}else r.length>0?r+=`/${e.slice(l+1,t)}`:r=e.slice(l+1,t),i=t-l-1;l=t,s=0}else o==="."&&s!==-1?++s:s=-1}return r}export function toAbsolutePath(e,n){return g(e)?e:f(normalizeString(c(n||process.cwd(),e),!0))}export function toRelativePath(e,n){return!e||e.length===0?".":(g(e)?e=f(normalizeString(e,!0)):e=f(normalizeString(c(n||process.cwd(),e),!0)),e.startsWith("./")?e.slice(2):e)}
@@ -21,12 +21,13 @@ var _correctPath = require("./correct-path.cjs");
21
21
  var _getWorkspaceRoot = require("./get-workspace-root.cjs");
22
22
  var _isFile = require("./is-file.cjs");
23
23
  var _joinPaths = require("./join-paths.cjs");
24
- function findFileName(t, {
25
- requireExtension: e,
26
- withExtension: r
27
- } = {}) {
28
- const n = (0, _correctPath.normalizeWindowsPath)(t)?.split(t?.includes("\\") ? "\\" : "/")?.pop() ?? "";
29
- return e === !0 && !n.includes(".") ? _base.EMPTY_STRING : r === !1 && n.includes(".") ? n.split(".").slice(-1).join(".") || _base.EMPTY_STRING : n;
24
+ function findFileName(t, e = {}) {
25
+ const {
26
+ requireExtension: i = !1,
27
+ withExtension: n = !0
28
+ } = e,
29
+ r = (0, _correctPath.normalizeWindowsPath)(t)?.split(t?.includes("\\") ? "\\" : "/")?.pop() ?? "";
30
+ return i === !0 && !r.includes(".") ? _base.EMPTY_STRING : n === !1 && r.includes(".") ? r.split(".").slice(-1).join(".") || _base.EMPTY_STRING : r;
30
31
  }
31
32
  function findFilePath(t) {
32
33
  const e = (0, _correctPath.normalizeWindowsPath)(t);
@@ -36,15 +37,15 @@ function findFilePath(t) {
36
37
  }
37
38
  function findFolderName(t) {
38
39
  const e = findFilePath(t).split("/");
39
- let r = "";
40
+ let i = "";
40
41
  for (let n = e.length - 1; n >= 0; n--) {
41
- const i = e[n];
42
- if (i) {
43
- r = i;
42
+ const r = e[n];
43
+ if (r) {
44
+ i = r;
44
45
  break;
45
46
  }
46
47
  }
47
- return r ?? _base.EMPTY_STRING;
48
+ return i ?? _base.EMPTY_STRING;
48
49
  }
49
50
  function findFileExtension(t) {
50
51
  if (t === "..") return "";
@@ -58,14 +59,14 @@ function hasFilePath(t) {
58
59
  return !!findFilePath(t);
59
60
  }
60
61
  function resolvePath(t, e = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
61
- const r = (0, _correctPath.normalizeWindowsPath)(t).split("/");
62
+ const i = (0, _correctPath.normalizeWindowsPath)(t).split("/");
62
63
  let n = "",
63
- i = !1;
64
- for (let s = r.length - 1; s >= -1 && !i; s--) {
65
- const o = s >= 0 ? r[s] : e;
66
- !o || o.length === 0 || (n = (0, _joinPaths.joinPaths)(o, n), i = (0, _isFile.isAbsolutePath)(o));
64
+ r = !1;
65
+ for (let s = i.length - 1; s >= -1 && !r; s--) {
66
+ const o = s >= 0 ? i[s] : e;
67
+ !o || o.length === 0 || (n = (0, _joinPaths.joinPaths)(o, n), r = (0, _isFile.isAbsolutePath)(o));
67
68
  }
68
- return n = (0, _correctPath.normalizeString)(n, !i), i && !(0, _isFile.isAbsolutePath)(n) ? `/${n}` : n.length > 0 ? n : ".";
69
+ return n = (0, _correctPath.normalizeString)(n, !r), r && !(0, _isFile.isAbsolutePath)(n) ? `/${n}` : n.length > 0 ? n : ".";
69
70
  }
70
71
  function resolvePaths(...t) {
71
72
  return resolvePath((0, _joinPaths.joinPaths)(...t.map(e => (0, _correctPath.normalizeWindowsPath)(e))));
@@ -78,21 +79,21 @@ function relativeToWorkspaceRoot(t) {
78
79
  }
79
80
  function parsePath(t) {
80
81
  const e = /^[/\\]|^[a-z]:[/\\]/i.exec(t)?.[0]?.replace(/\\/g, "/") || "",
81
- r = (0, _correctPath.normalizeWindowsPath)(t),
82
- n = r.replace(/\/$/, "").split("/").slice(0, -1);
82
+ i = (0, _correctPath.normalizeWindowsPath)(t),
83
+ n = i.replace(/\/$/, "").split("/").slice(0, -1);
83
84
  n.length === 1 && /^[A-Z]:$/i.test(n[0]) && (n[0] += "/");
84
- const i = findFolderName(r),
85
+ const r = findFolderName(i),
85
86
  s = n.join("/") || ((0, _isFile.isAbsolutePath)(t) ? "/" : "."),
86
87
  o = findFileExtension(t);
87
88
  return {
88
89
  root: e,
89
90
  dir: s,
90
- base: i,
91
+ base: r,
91
92
  ext: o,
92
- name: i.slice(0, i.length - o.length)
93
+ name: r.slice(0, r.length - o.length)
93
94
  };
94
95
  }
95
96
  function renameFile(t, e) {
96
- const r = parsePath(t);
97
- return (0, _joinPaths.joinPaths)(r.dir, e.includes(".") ? e : e + r.ext);
97
+ const i = parsePath(t);
98
+ return (0, _joinPaths.joinPaths)(i.dir, e.includes(".") ? e : e + i.ext);
98
99
  }
@@ -22,10 +22,10 @@ export interface FindFileNameOptions {
22
22
  * ```
23
23
  *
24
24
  * @param filePath - The file path to process
25
- * @param options - The options to use when processing the file name
25
+ * @param options - Options to control the file name extraction
26
26
  * @returns The file name
27
27
  */
28
- export declare function findFileName(filePath: string, { requireExtension, withExtension }?: FindFileNameOptions): string;
28
+ export declare function findFileName(filePath: string, options?: FindFileNameOptions): string;
29
29
  /**
30
30
  * Find the full file path's directories from a file path.
31
31
  *
@@ -1 +1 @@
1
- import{EMPTY_STRING as a}from"@stryke/types/base";import{relative as f}from"node:path";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{getWorkspaceRoot as p}from"./get-workspace-root";import{isAbsolutePath as c}from"./is-file";import{joinPaths as u}from"./join-paths";export function findFileName(t,{requireExtension:e,withExtension:r}={}){const n=l(t)?.split(t?.includes("\\")?"\\":"/")?.pop()??"";return e===!0&&!n.includes(".")?a:r===!1&&n.includes(".")?n.split(".").slice(-1).join(".")||a:n}export function findFilePath(t){const e=l(t);return e.replace(findFileName(e,{requireExtension:!0}),"")}export function findFolderName(t){const e=findFilePath(t).split("/");let r="";for(let n=e.length-1;n>=0;n--){const i=e[n];if(i){r=i;break}}return r??a}export function findFileExtension(t){if(t==="..")return"";const e=/.(\.[^./]+|\.)$/.exec(l(t));return e&&e[1]||a}export function hasFileName(t){return!!findFileName(t)}export function hasFilePath(t){return!!findFilePath(t)}export function resolvePath(t,e=p()){const r=l(t).split("/");let n="",i=!1;for(let s=r.length-1;s>=-1&&!i;s--){const o=s>=0?r[s]:e;!o||o.length===0||(n=u(o,n),i=c(o))}return n=g(n,!i),i&&!c(n)?`/${n}`:n.length>0?n:"."}export function resolvePaths(...t){return resolvePath(u(...t.map(e=>l(e))))}export function relativePath(t,e){return f(t.replace(/\/$/,""),e.replace(/\/$/,""))}export function relativeToWorkspaceRoot(t){return relativePath(t,p())}export function parsePath(t){const e=/^[/\\]|^[a-z]:[/\\]/i.exec(t)?.[0]?.replace(/\\/g,"/")||"",r=l(t),n=r.replace(/\/$/,"").split("/").slice(0,-1);n.length===1&&/^[A-Z]:$/i.test(n[0])&&(n[0]+="/");const i=findFolderName(r),s=n.join("/")||(c(t)?"/":"."),o=findFileExtension(t);return{root:e,dir:s,base:i,ext:o,name:i.slice(0,i.length-o.length)}}export function renameFile(t,e){const r=parsePath(t);return u(r.dir,e.includes(".")?e:e+r.ext)}
1
+ import{EMPTY_STRING as a}from"@stryke/types/base";import{relative as f}from"node:path";import{normalizeString as g,normalizeWindowsPath as l}from"./correct-path";import{getWorkspaceRoot as p}from"./get-workspace-root";import{isAbsolutePath as c}from"./is-file";import{joinPaths as u}from"./join-paths";export function findFileName(t,e={}){const{requireExtension:i=!1,withExtension:n=!0}=e,r=l(t)?.split(t?.includes("\\")?"\\":"/")?.pop()??"";return i===!0&&!r.includes(".")?a:n===!1&&r.includes(".")?r.split(".").slice(-1).join(".")||a:r}export function findFilePath(t){const e=l(t);return e.replace(findFileName(e,{requireExtension:!0}),"")}export function findFolderName(t){const e=findFilePath(t).split("/");let i="";for(let n=e.length-1;n>=0;n--){const r=e[n];if(r){i=r;break}}return i??a}export function findFileExtension(t){if(t==="..")return"";const e=/.(\.[^./]+|\.)$/.exec(l(t));return e&&e[1]||a}export function hasFileName(t){return!!findFileName(t)}export function hasFilePath(t){return!!findFilePath(t)}export function resolvePath(t,e=p()){const i=l(t).split("/");let n="",r=!1;for(let s=i.length-1;s>=-1&&!r;s--){const o=s>=0?i[s]:e;!o||o.length===0||(n=u(o,n),r=c(o))}return n=g(n,!r),r&&!c(n)?`/${n}`:n.length>0?n:"."}export function resolvePaths(...t){return resolvePath(u(...t.map(e=>l(e))))}export function relativePath(t,e){return f(t.replace(/\/$/,""),e.replace(/\/$/,""))}export function relativeToWorkspaceRoot(t){return relativePath(t,p())}export function parsePath(t){const e=/^[/\\]|^[a-z]:[/\\]/i.exec(t)?.[0]?.replace(/\\/g,"/")||"",i=l(t),n=i.replace(/\/$/,"").split("/").slice(0,-1);n.length===1&&/^[A-Z]:$/i.test(n[0])&&(n[0]+="/");const r=findFolderName(i),s=n.join("/")||(c(t)?"/":"."),o=findFileExtension(t);return{root:e,dir:s,base:r,ext:o,name:r.slice(0,r.length-o.length)}}export function renameFile(t,e){const i=parsePath(t);return u(i.dir,e.includes(".")?e:e+i.ext)}
package/dist/resolve.cjs CHANGED
@@ -12,6 +12,7 @@ exports.resolveSafeSync = resolveSafeSync;
12
12
  exports.resolveSync = resolveSync;
13
13
  var _mlly = require("mlly");
14
14
  var _correctPath = require("./correct-path.cjs");
15
+ var _filePathFns = require("./file-path-fns.cjs");
15
16
  var _getWorkspaceRoot = require("./get-workspace-root.cjs");
16
17
  var _joinPaths = require("./join-paths.cjs");
17
18
  async function resolve(r, e = {}) {
@@ -50,9 +51,9 @@ async function importModule(r) {
50
51
  }
51
52
  async function resolvePackage(r, e = {}) {
52
53
  let t = await resolveSafe((0, _joinPaths.joinPaths)(r, "package.json"), e);
53
- return t || (t = await resolveSafe((0, _joinPaths.joinPaths)(r, "index.js"), e), t || (t = await resolveSafe(r, e))), t;
54
+ return t || (t = await resolveSafe((0, _joinPaths.joinPaths)(r, "index.js"), e), t || (t = await resolveSafe(r, e))), t ? (0, _filePathFns.findFilePath)(t) : void 0;
54
55
  }
55
56
  async function resolvePackageSync(r, e = {}) {
56
57
  let t = resolveSafeSync((0, _joinPaths.joinPaths)(r, "package.json"), e);
57
- return t || (t = resolveSafeSync((0, _joinPaths.joinPaths)(r, "index.js"), e), t || (t = resolveSafeSync(r, e))), t;
58
+ return t || (t = resolveSafeSync((0, _joinPaths.joinPaths)(r, "index.js"), e), t || (t = resolveSafeSync(r, e))), t ? (0, _filePathFns.findFilePath)(t) : void 0;
58
59
  }
package/dist/resolve.d.ts CHANGED
@@ -12,7 +12,7 @@ export interface PackageResolvingOptions {
12
12
  /**
13
13
  * Resolve the path to a specified module
14
14
  *
15
- * @param name - The name of the module
15
+ * @param path - The path to the module
16
16
  * @param options - The options to use when resolving the module
17
17
  * @returns A promise for the path to the module
18
18
  */
@@ -20,7 +20,7 @@ export declare function resolve(path: string, options?: PackageResolvingOptions)
20
20
  /**
21
21
  * Resolve the path to a specified module
22
22
  *
23
- * @param name - The name of the module
23
+ * @param path - The path to the module
24
24
  * @param options - The options to use when resolving the module
25
25
  * @returns The path to the module or undefined
26
26
  */
@@ -49,16 +49,23 @@ export declare function resolveSafeSync(name: string, options?: PackageResolving
49
49
  */
50
50
  export declare function importModule<T = any>(path: string): Promise<T>;
51
51
  /**
52
- * Import a module from a specified path with error handling
52
+ * Resolve the path to a specified package asynchronously
53
53
  *
54
- * @param path - The path to the module
55
- * @returns The module or undefined
54
+ * @remarks
55
+ * This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.
56
+ *
57
+ * @param name - The name of the module
58
+ * @returns A promise for the module or undefined
56
59
  */
57
60
  export declare function resolvePackage(name: string, options?: PackageResolvingOptions): Promise<string | undefined>;
58
61
  /**
59
- * Import a module from a specified path with error handling
62
+ * Resolve the path to a specified package synchronously
60
63
  *
61
- * @param path - The path to the module
64
+ * @remarks
65
+ * This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.
66
+ *
67
+ * @param name - The name of the module
68
+ * @param options - The options to use when resolving the module
62
69
  * @returns The module or undefined
63
70
  */
64
71
  export declare function resolvePackageSync(name: string, options?: PackageResolvingOptions): Promise<string | undefined>;
package/dist/resolve.mjs CHANGED
@@ -1 +1 @@
1
- import{interopDefault as i,resolvePath as c,resolvePathSync as p}from"mlly";import{correctPath as o}from"./correct-path";import{getWorkspaceRoot as a}from"./get-workspace-root";import{joinPaths as s}from"./join-paths";export async function resolve(r,e={}){const t=e.paths??[];t.length===0&&t.push(process.cwd());const n=a();return t.includes(n)||t.push(n),o(await c(r,{url:t}))}export function resolveSync(r,e={}){const t=e.paths??[];t.length===0&&t.push(process.cwd());const n=a();return t.includes(n)||t.push(n),o(p(r,{url:e.paths}))}export async function resolveSafe(r,e={}){try{return await resolve(r,e)}catch{return}}export function resolveSafeSync(r,e={}){try{return resolveSync(r,e)}catch{return}}export async function importModule(r){const e=await import(r);return e&&i(e)}export async function resolvePackage(r,e={}){let t=await resolveSafe(s(r,"package.json"),e);return t||(t=await resolveSafe(s(r,"index.js"),e),t||(t=await resolveSafe(r,e))),t}export async function resolvePackageSync(r,e={}){let t=resolveSafeSync(s(r,"package.json"),e);return t||(t=resolveSafeSync(s(r,"index.js"),e),t||(t=resolveSafeSync(r,e))),t}
1
+ import{interopDefault as c,resolvePath as p,resolvePathSync as f}from"mlly";import{correctPath as s}from"./correct-path";import{findFilePath as i}from"./file-path-fns";import{getWorkspaceRoot as a}from"./get-workspace-root";import{joinPaths as o}from"./join-paths";export async function resolve(r,e={}){const t=e.paths??[];t.length===0&&t.push(process.cwd());const n=a();return t.includes(n)||t.push(n),s(await p(r,{url:t}))}export function resolveSync(r,e={}){const t=e.paths??[];t.length===0&&t.push(process.cwd());const n=a();return t.includes(n)||t.push(n),s(f(r,{url:e.paths}))}export async function resolveSafe(r,e={}){try{return await resolve(r,e)}catch{return}}export function resolveSafeSync(r,e={}){try{return resolveSync(r,e)}catch{return}}export async function importModule(r){const e=await import(r);return e&&c(e)}export async function resolvePackage(r,e={}){let t=await resolveSafe(o(r,"package.json"),e);return t||(t=await resolveSafe(o(r,"index.js"),e),t||(t=await resolveSafe(r,e))),t?i(t):void 0}export async function resolvePackageSync(r,e={}){let t=resolveSafeSync(o(r,"package.json"),e);return t||(t=resolveSafeSync(o(r,"index.js"),e),t||(t=resolveSafeSync(r,e))),t?i(t):void 0}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "A package containing various utilities that expand the functionality of NodeJs's built-in `path` module",
6
6
  "repository": {