@stryke/path 0.4.0 → 0.4.2

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.
package/README.md CHANGED
@@ -44,29 +44,31 @@ This package is part of Storm Software's **🌩️ Stryke** monorepo. Stryke pac
44
44
 
45
45
  <!-- END header -->
46
46
 
47
- # Stryke - Path Utilities
47
+ # Stryke - Path Helpers
48
48
 
49
49
  A package containing various utilities that expand the functionality of
50
- NodeJs&#39;s \`path\` module
50
+ NodeJs's built-in \`path\` module
51
51
 
52
52
  <!-- START doctoc -->
53
53
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
54
54
 
55
55
  ## Table of Contents
56
56
 
57
- - [Installing](#installing)
58
- - [Reduced Package Size](#reduced-package-size)
59
- - [Development](#development)
60
- - [Building](#building)
61
- - [Running unit tests](#running-unit-tests)
62
- - [Linting](#linting)
63
- - [Storm Workspaces](#storm-workspaces)
64
- - [Roadmap](#roadmap)
65
- - [Support](#support)
66
- - [License](#license)
67
- - [Changelog](#changelog)
68
- - [Contributing](#contributing)
69
- - [Contributors](#contributors)
57
+ - [Stryke - Path Helpers](#stryke---path-helpers)
58
+ - [Table of Contents](#table-of-contents)
59
+ - [Installing](#installing)
60
+ - [Reduced Package Size](#reduced-package-size)
61
+ - [Development](#development)
62
+ - [Building](#building)
63
+ - [Running unit tests](#running-unit-tests)
64
+ - [Linting](#linting)
65
+ - [Storm Workspaces](#storm-workspaces)
66
+ - [Roadmap](#roadmap)
67
+ - [Support](#support)
68
+ - [License](#license)
69
+ - [Changelog](#changelog)
70
+ - [Contributing](#contributing)
71
+ - [Contributors](#contributors)
70
72
 
71
73
  <!-- END doctoc -->
72
74
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.correctPaths = void 0;
6
+ exports.correctPath = correctPath;
7
7
  exports.normalizeString = normalizeString;
8
8
  exports.normalizeWindowsPath = normalizeWindowsPath;
9
9
  exports.slash = slash;
@@ -13,23 +13,22 @@ function slash(e) {
13
13
  }
14
14
  const c = /^[A-Z]:\//i;
15
15
  function normalizeWindowsPath(e = "") {
16
- return e && e.replace(/\\/g, "/").replace(c, i => i.toUpperCase());
16
+ return e && e.replace(/\\/g, "/").replace(c, s => s.toUpperCase());
17
17
  }
18
18
  const u = /^[/\\]{2}/,
19
19
  E = /^[A-Z]:$/i;
20
- const correctPaths = e => {
20
+ function correctPath(e) {
21
21
  if (!e || e.length === 0) return ".";
22
22
  e = normalizeWindowsPath(e);
23
- const i = e.match(u),
23
+ const s = e.match(u),
24
24
  n = (0, _isFile.isAbsolutePath)(e),
25
25
  t = e[e.length - 1] === "/";
26
- return e = normalizeString(e, !n), e.length === 0 ? n ? "/" : t ? "./" : "." : (t && (e += "/"), E.test(e) && (e += "/"), i ? n ? `//${e}` : `//./${e}` : n && !(0, _isFile.isAbsolutePath)(e) ? `/${e}` : e);
27
- };
28
- exports.correctPaths = correctPaths;
29
- function normalizeString(e, i) {
26
+ return e = normalizeString(e, !n), e.length === 0 ? n ? "/" : t ? "./" : "." : (t && (e += "/"), E.test(e) && (e += "/"), s ? n ? `//${e}` : `//./${e}` : n && !(0, _isFile.isAbsolutePath)(e) ? `/${e}` : e);
27
+ }
28
+ function normalizeString(e, s) {
30
29
  let n = "",
31
30
  t = 0,
32
- s = -1,
31
+ i = -1,
33
32
  r = 0,
34
33
  o = null;
35
34
  for (let l = 0; l <= e.length; ++l) {
@@ -38,20 +37,20 @@ function normalizeString(e, i) {
38
37
  o = "/";
39
38
  }
40
39
  if (o === "/") {
41
- if (!(s === l - 1 || r === 1)) if (r === 2) {
40
+ if (!(i === l - 1 || r === 1)) if (r === 2) {
42
41
  if (n.length < 2 || t !== 2 || n[n.length - 1] !== "." || n[n.length - 2] !== ".") {
43
42
  if (n.length > 2) {
44
43
  const f = n.lastIndexOf("/");
45
- f === -1 ? (n = "", t = 0) : (n = n.slice(0, f), t = n.length - 1 - n.lastIndexOf("/")), s = l, r = 0;
44
+ f === -1 ? (n = "", t = 0) : (n = n.slice(0, f), t = n.length - 1 - n.lastIndexOf("/")), i = l, r = 0;
46
45
  continue;
47
46
  } else if (n.length > 0) {
48
- n = "", t = 0, s = l, r = 0;
47
+ n = "", t = 0, i = l, r = 0;
49
48
  continue;
50
49
  }
51
50
  }
52
- i && (n += n.length > 0 ? "/.." : "..", t = 2);
53
- } else n.length > 0 ? n += `/${e.slice(s + 1, l)}` : n = e.slice(s + 1, l), t = l - s - 1;
54
- s = l, r = 0;
51
+ s && (n += n.length > 0 ? "/.." : "..", t = 2);
52
+ } else n.length > 0 ? n += `/${e.slice(i + 1, l)}` : n = e.slice(i + 1, l), t = l - i - 1;
53
+ i = l, r = 0;
55
54
  } else o === "." && r !== -1 ? ++r : r = -1;
56
55
  }
57
56
  return n;
@@ -6,7 +6,13 @@
6
6
  */
7
7
  export declare function slash(str: string): string;
8
8
  export declare function normalizeWindowsPath(input?: string): string;
9
- export declare const correctPaths: (path?: string) => string;
9
+ /**
10
+ * Corrects/normalized a file path.
11
+ *
12
+ * @param path - The path to correct.
13
+ * @returns The corrected path.
14
+ */
15
+ export declare function correctPath(path?: string): string;
10
16
  /**
11
17
  * Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
12
18
  *
@@ -0,0 +1 @@
1
+ import{isAbsolutePath as g}from"./is-file";export function slash(e){return e.replace(/\\/g,"/")}const c=/^[A-Z]:\//i;export function normalizeWindowsPath(e=""){return e&&e.replace(/\\/g,"/").replace(c,s=>s.toUpperCase())}const u=/^[/\\]{2}/,E=/^[A-Z]:$/i;export function correctPath(e){if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const s=e.match(u),n=g(e),t=e[e.length-1]==="/";return e=normalizeString(e,!n),e.length===0?n?"/":t?"./":".":(t&&(e+="/"),E.test(e)&&(e+="/"),s?n?`//${e}`:`//./${e}`:n&&!g(e)?`/${e}`:e)}export function normalizeString(e,s){let n="",t=0,i=-1,r=0,o=null;for(let l=0;l<=e.length;++l){if(l<e.length)o=e[l];else{if(o==="/")break;o="/"}if(o==="/"){if(!(i===l-1||r===1))if(r===2){if(n.length<2||t!==2||n[n.length-1]!=="."||n[n.length-2]!=="."){if(n.length>2){const f=n.lastIndexOf("/");f===-1?(n="",t=0):(n=n.slice(0,f),t=n.length-1-n.lastIndexOf("/")),i=l,r=0;continue}else if(n.length>0){n="",t=0,i=l,r=0;continue}}s&&(n+=n.length>0?"/..":"..",t=2)}else n.length>0?n+=`/${e.slice(i+1,l)}`:n=e.slice(i+1,l),t=l-i-1;i=l,r=0}else o==="."&&r!==-1?++r:r=-1}return n}
@@ -16,19 +16,19 @@ exports.renameFile = renameFile;
16
16
  exports.resolvePath = resolvePath;
17
17
  exports.resolvePaths = resolvePaths;
18
18
  var _base = require("@stryke/types/base");
19
- var _getWorkspaceRoot = require("../workspace/get-workspace-root");
19
+ var _correctPath = require("./correct-path.cjs");
20
+ var _getWorkspaceRoot = require("./get-workspace-root.cjs");
20
21
  var _isFile = require("./is-file.cjs");
21
22
  var _joinPaths = require("./join-paths.cjs");
22
- var _normalizePath = require("./normalize-path.cjs");
23
23
  function findFileName(n, {
24
24
  requireExtension: e,
25
25
  withExtension: r
26
26
  } = {}) {
27
- const t = (0, _normalizePath.normalizeWindowsPath)(n)?.split(n?.includes("\\") ? "\\" : "/")?.pop() ?? "";
27
+ const t = (0, _correctPath.normalizeWindowsPath)(n)?.split(n?.includes("\\") ? "\\" : "/")?.pop() ?? "";
28
28
  return e === !0 && !t.includes(".") ? _base.EMPTY_STRING : r === !1 && t.includes(".") ? t.split(".").slice(-1).join(".") || _base.EMPTY_STRING : t;
29
29
  }
30
30
  function findFilePath(n) {
31
- const e = (0, _normalizePath.normalizeWindowsPath)(n);
31
+ const e = (0, _correctPath.normalizeWindowsPath)(n);
32
32
  return e.replace(findFileName(e, {
33
33
  requireExtension: !0
34
34
  }), "");
@@ -47,7 +47,7 @@ function findFolderName(n) {
47
47
  }
48
48
  function findFileExtension(n) {
49
49
  if (n === "..") return "";
50
- const e = /.(\.[^./]+|\.)$/.exec((0, _normalizePath.normalizeWindowsPath)(n));
50
+ const e = /.(\.[^./]+|\.)$/.exec((0, _correctPath.normalizeWindowsPath)(n));
51
51
  return e && e[1] || _base.EMPTY_STRING;
52
52
  }
53
53
  function hasFileName(n) {
@@ -57,17 +57,17 @@ function hasFilePath(n) {
57
57
  return !!findFilePath(n);
58
58
  }
59
59
  function resolvePath(n, e = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
60
- const r = (0, _normalizePath.normalizeWindowsPath)(n).split("/");
60
+ const r = (0, _correctPath.normalizeWindowsPath)(n).split("/");
61
61
  let t = "",
62
62
  i = !1;
63
63
  for (let o = r.length - 1; o >= -1 && !i; o--) {
64
64
  const s = o >= 0 ? r[o] : e;
65
65
  !s || s.length === 0 || (t = (0, _joinPaths.joinPaths)(s, t), i = (0, _isFile.isAbsolutePath)(s));
66
66
  }
67
- return t = (0, _normalizePath.normalizeString)(t, !i), i && !(0, _isFile.isAbsolutePath)(t) ? `/${t}` : t.length > 0 ? t : ".";
67
+ return t = (0, _correctPath.normalizeString)(t, !i), i && !(0, _isFile.isAbsolutePath)(t) ? `/${t}` : t.length > 0 ? t : ".";
68
68
  }
69
69
  function resolvePaths(...n) {
70
- return resolvePath((0, _joinPaths.joinPaths)(...n.map(e => (0, _normalizePath.normalizeWindowsPath)(e))));
70
+ return resolvePath((0, _joinPaths.joinPaths)(...n.map(e => (0, _correctPath.normalizeWindowsPath)(e))));
71
71
  }
72
72
  function relativePath(n, e) {
73
73
  const r = resolvePath(n).replace(/^\/([A-Z]:)?$/i, "$1").split("/"),
@@ -85,7 +85,7 @@ function relativeToWorkspaceRoot(n) {
85
85
  }
86
86
  function parsePath(n) {
87
87
  const e = /^[/\\]|^[a-z]:[/\\]/i.exec(n)?.[0]?.replace(/\\/g, "/") || "",
88
- r = (0, _normalizePath.normalizeWindowsPath)(n),
88
+ r = (0, _correctPath.normalizeWindowsPath)(n),
89
89
  t = r.replace(/\/$/, "").split("/").slice(0, -1);
90
90
  t.length === 1 && /^[A-Z]:$/i.test(t[0]) && (t[0] += "/");
91
91
  const i = findFolderName(r),
@@ -83,7 +83,7 @@ export declare function hasFilePath(filePath: string): boolean;
83
83
  * @param cwd - The current working directory
84
84
  * @returns The resolved path
85
85
  */
86
- export declare function resolvePath(path: string, cwd?: any): string;
86
+ export declare function resolvePath(path: string, cwd?: string): string;
87
87
  /**
88
88
  * Resolve the file path to an absolute path.
89
89
  *
@@ -1 +1 @@
1
- import{EMPTY_STRING as a}from"@stryke/types/base";import{getWorkspaceRoot as f}from"../workspace/get-workspace-root";import{isAbsolutePath as c}from"./is-file";import{joinPaths as u}from"./join-paths";import{normalizeString as p,normalizeWindowsPath as l}from"./normalize-path";export function findFileName(n,{requireExtension:e,withExtension:r}={}){const t=l(n)?.split(n?.includes("\\")?"\\":"/")?.pop()??"";return e===!0&&!t.includes(".")?a:r===!1&&t.includes(".")?t.split(".").slice(-1).join(".")||a:t}export function findFilePath(n){const e=l(n);return e.replace(findFileName(e,{requireExtension:!0}),"")}export function findFolderName(n){const e=findFilePath(n).split("/");let r="";for(let t=e.length-1;t>=0;t--){const i=e[t];if(i){r=i;break}}return r??a}export function findFileExtension(n){if(n==="..")return"";const e=/.(\.[^./]+|\.)$/.exec(l(n));return e&&e[1]||a}export function hasFileName(n){return!!findFileName(n)}export function hasFilePath(n){return!!findFilePath(n)}export function resolvePath(n,e=f()){const r=l(n).split("/");let t="",i=!1;for(let o=r.length-1;o>=-1&&!i;o--){const s=o>=0?r[o]:e;!s||s.length===0||(t=u(s,t),i=c(s))}return t=p(t,!i),i&&!c(t)?`/${t}`:t.length>0?t:"."}export function resolvePaths(...n){return resolvePath(u(...n.map(e=>l(e))))}export function relativePath(n,e){const r=resolvePath(n).replace(/^\/([A-Z]:)?$/i,"$1").split("/"),t=resolvePath(e).replace(/^\/([A-Z]:)?$/i,"$1").split("/");if(t[0][1]===":"&&r[0][1]===":"&&r[0]!==t[0])return t.join("/");const i=[...r];for(const o of i){if(t[0]!==o)break;r.shift(),t.shift()}return[...r.map(()=>".."),...t].join("/")}export function relativeToWorkspaceRoot(n){return relativePath(n,f())}export function parsePath(n){const e=/^[/\\]|^[a-z]:[/\\]/i.exec(n)?.[0]?.replace(/\\/g,"/")||"",r=l(n),t=r.replace(/\/$/,"").split("/").slice(0,-1);t.length===1&&/^[A-Z]:$/i.test(t[0])&&(t[0]+="/");const i=findFolderName(r),o=t.join("/")||(c(n)?"/":"."),s=findFileExtension(n);return{root:e,dir:o,base:i,ext:s,name:i.slice(0,i.length-s.length)}}export function renameFile(n,e){const r=parsePath(n);return u(r.dir,e.includes(".")?e:e+r.ext)}
1
+ import{EMPTY_STRING as a}from"@stryke/types/base";import{normalizeString as p,normalizeWindowsPath as l}from"./correct-path";import{getWorkspaceRoot as f}from"./get-workspace-root";import{isAbsolutePath as c}from"./is-file";import{joinPaths as u}from"./join-paths";export function findFileName(n,{requireExtension:e,withExtension:r}={}){const t=l(n)?.split(n?.includes("\\")?"\\":"/")?.pop()??"";return e===!0&&!t.includes(".")?a:r===!1&&t.includes(".")?t.split(".").slice(-1).join(".")||a:t}export function findFilePath(n){const e=l(n);return e.replace(findFileName(e,{requireExtension:!0}),"")}export function findFolderName(n){const e=findFilePath(n).split("/");let r="";for(let t=e.length-1;t>=0;t--){const i=e[t];if(i){r=i;break}}return r??a}export function findFileExtension(n){if(n==="..")return"";const e=/.(\.[^./]+|\.)$/.exec(l(n));return e&&e[1]||a}export function hasFileName(n){return!!findFileName(n)}export function hasFilePath(n){return!!findFilePath(n)}export function resolvePath(n,e=f()){const r=l(n).split("/");let t="",i=!1;for(let o=r.length-1;o>=-1&&!i;o--){const s=o>=0?r[o]:e;!s||s.length===0||(t=u(s,t),i=c(s))}return t=p(t,!i),i&&!c(t)?`/${t}`:t.length>0?t:"."}export function resolvePaths(...n){return resolvePath(u(...n.map(e=>l(e))))}export function relativePath(n,e){const r=resolvePath(n).replace(/^\/([A-Z]:)?$/i,"$1").split("/"),t=resolvePath(e).replace(/^\/([A-Z]:)?$/i,"$1").split("/");if(t[0][1]===":"&&r[0][1]===":"&&r[0]!==t[0])return t.join("/");const i=[...r];for(const o of i){if(t[0]!==o)break;r.shift(),t.shift()}return[...r.map(()=>".."),...t].join("/")}export function relativeToWorkspaceRoot(n){return relativePath(n,f())}export function parsePath(n){const e=/^[/\\]|^[a-z]:[/\\]/i.exec(n)?.[0]?.replace(/\\/g,"/")||"",r=l(n),t=r.replace(/\/$/,"").split("/").slice(0,-1);t.length===1&&/^[A-Z]:$/i.test(t[0])&&(t[0]+="/");const i=findFolderName(r),o=t.join("/")||(c(n)?"/":"."),s=findFileExtension(n);return{root:e,dir:o,base:i,ext:s,name:i.slice(0,i.length-s.length)}}export function renameFile(n,e){const r=parsePath(n);return u(r.dir,e.includes(".")?e:e+r.ext)}
package/dist/index.cjs CHANGED
@@ -14,6 +14,17 @@ Object.keys(_assetExtensions).forEach(function (key) {
14
14
  }
15
15
  });
16
16
  });
17
+ var _correctPath = require("./correct-path.cjs");
18
+ Object.keys(_correctPath).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _correctPath[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _correctPath[key];
25
+ }
26
+ });
27
+ });
17
28
  var _delimiter = require("./delimiter.cjs");
18
29
  Object.keys(_delimiter).forEach(function (key) {
19
30
  if (key === "default" || key === "__esModule") return;
@@ -102,17 +113,6 @@ Object.keys(_joinPaths).forEach(function (key) {
102
113
  }
103
114
  });
104
115
  });
105
- var _normalizePath = require("./normalize-path.cjs");
106
- Object.keys(_normalizePath).forEach(function (key) {
107
- if (key === "default" || key === "__esModule") return;
108
- if (key in exports && exports[key] === _normalizePath[key]) return;
109
- Object.defineProperty(exports, key, {
110
- enumerable: true,
111
- get: function () {
112
- return _normalizePath[key];
113
- }
114
- });
115
- });
116
116
  var _resolve = require("./resolve.cjs");
117
117
  Object.keys(_resolve).forEach(function (key) {
118
118
  if (key === "default" || key === "__esModule") return;
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  * @packageDocumentation
8
8
  */
9
9
  export * from "./asset-extensions";
10
+ export * from "./correct-path";
10
11
  export * from "./delimiter";
11
12
  export * from "./exists";
12
13
  export * from "./file-path-fns";
@@ -15,5 +16,4 @@ export * from "./get-workspace-root";
15
16
  export * from "./is-file";
16
17
  export * from "./is-root-dir";
17
18
  export * from "./join-paths";
18
- export * from "./normalize-path";
19
19
  export * from "./resolve";
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export*from"./asset-extensions";export*from"./delimiter";export*from"./exists";export*from"./file-path-fns";export*from"./get-parent-path";export*from"./get-workspace-root";export*from"./is-file";export*from"./is-root-dir";export*from"./join-paths";export*from"./normalize-path";export*from"./resolve";
1
+ export*from"./asset-extensions";export*from"./correct-path";export*from"./delimiter";export*from"./exists";export*from"./file-path-fns";export*from"./get-parent-path";export*from"./get-workspace-root";export*from"./is-file";export*from"./is-root-dir";export*from"./join-paths";export*from"./resolve";
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.joinPaths = void 0;
7
- var _normalizePath = require("./normalize-path.cjs");
7
+ var _correctPath = require("./correct-path.cjs");
8
8
  const joinPaths = (...i) => {
9
9
  let t = "";
10
10
  for (const o of i) if (o) if (t.length > 0) {
@@ -12,6 +12,6 @@ const joinPaths = (...i) => {
12
12
  n = o[0] === "/";
13
13
  e && n ? t += o.slice(1) : t += e || n ? o : `/${o}`;
14
14
  } else t += o;
15
- return (0, _normalizePath.correctPaths)(t);
15
+ return (0, _correctPath.correctPath)(t);
16
16
  };
17
17
  exports.joinPaths = joinPaths;
@@ -1 +1 @@
1
- import{correctPaths as s}from"./normalize-path";export const joinPaths=(...i)=>{let t="";for(const o of i)if(o)if(t.length>0){const e=t[t.length-1]==="/",n=o[0]==="/";e&&n?t+=o.slice(1):t+=e||n?o:`/${o}`}else t+=o;return s(t)};
1
+ import{correctPath as h}from"./correct-path";export const joinPaths=(...i)=>{let t="";for(const o of i)if(o)if(t.length>0){const e=t[t.length-1]==="/",n=o[0]==="/";e&&n?t+=o.slice(1):t+=e||n?o:`/${o}`}else t+=o;return h(t)};
package/dist/resolve.cjs CHANGED
@@ -11,29 +11,28 @@ exports.resolveSafe = resolveSafe;
11
11
  exports.resolveSafeSync = resolveSafeSync;
12
12
  exports.resolveSync = resolveSync;
13
13
  var _mlly = require("mlly");
14
- var _nodeProcess = _interopRequireDefault(require("node:process"));
15
- var _utilities = require("../utilities");
16
- var _getWorkspaceRoot = require("../workspace/get-workspace-root");
17
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ var _correctPath = require("./correct-path.cjs");
15
+ var _getWorkspaceRoot = require("./get-workspace-root.cjs");
16
+ var _joinPaths = require("./join-paths.cjs");
18
17
  async function resolve(r, e = {}) {
19
18
  const t = e.paths ?? [];
20
- t.length === 0 && t.push(_nodeProcess.default.cwd());
19
+ t.length === 0 && t.push(process.cwd());
21
20
  const n = (0, _getWorkspaceRoot.getWorkspaceRoot)();
22
- return t.includes(n) || t.push(n), (0, _utilities.normalizePath)(await (0, _mlly.resolvePath)(r, {
21
+ return t.includes(n) || t.push(n), (0, _correctPath.correctPath)(await (0, _mlly.resolvePath)(r, {
23
22
  url: t
24
23
  }));
25
24
  }
26
25
  function resolveSync(r, e = {}) {
27
26
  const t = e.paths ?? [];
28
- t.length === 0 && t.push(_nodeProcess.default.cwd());
27
+ t.length === 0 && t.push(process.cwd());
29
28
  const n = (0, _getWorkspaceRoot.getWorkspaceRoot)();
30
- return t.includes(n) || t.push(n), (0, _utilities.normalizePath)((0, _mlly.resolvePathSync)(r, {
29
+ return t.includes(n) || t.push(n), (0, _correctPath.correctPath)((0, _mlly.resolvePathSync)(r, {
31
30
  url: e.paths
32
31
  }));
33
32
  }
34
- function resolveSafe(r, e = {}) {
33
+ async function resolveSafe(r, e = {}) {
35
34
  try {
36
- return resolve(r, e);
35
+ return await resolve(r, e);
37
36
  } catch {
38
37
  return;
39
38
  }
@@ -50,10 +49,10 @@ async function importModule(r) {
50
49
  return e && (0, _mlly.interopDefault)(e);
51
50
  }
52
51
  async function resolvePackage(r, e = {}) {
53
- let t = await resolveSafe((0, _utilities.joinPaths)(r, "package.json"), e);
54
- return t || (t = await resolveSafe((0, _utilities.joinPaths)(r, "index.js"), e), t || (t = await resolveSafe(r, e))), t;
52
+ 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;
55
54
  }
56
55
  async function resolvePackageSync(r, e = {}) {
57
- let t = await resolveSafeSync((0, _utilities.joinPaths)(r, "package.json"), e);
58
- return t || (t = await resolveSafeSync((0, _utilities.joinPaths)(r, "index.js"), e), t || (t = await resolveSafeSync(r, e))), t;
56
+ 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;
59
58
  }
package/dist/resolve.d.ts CHANGED
@@ -16,7 +16,7 @@ export interface PackageResolvingOptions {
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
  */
19
- export declare function resolve(path: string, options?: PackageResolvingOptions): Promise<any>;
19
+ export declare function resolve(path: string, options?: PackageResolvingOptions): Promise<string>;
20
20
  /**
21
21
  * Resolve the path to a specified module
22
22
  *
@@ -24,7 +24,7 @@ export declare function resolve(path: string, options?: PackageResolvingOptions)
24
24
  * @param options - The options to use when resolving the module
25
25
  * @returns The path to the module or undefined
26
26
  */
27
- export declare function resolveSync(path: string, options?: PackageResolvingOptions): any;
27
+ export declare function resolveSync(path: string, options?: PackageResolvingOptions): string;
28
28
  /**
29
29
  * Resolve the path to a specified module with error handling
30
30
  *
@@ -32,7 +32,7 @@ export declare function resolveSync(path: string, options?: PackageResolvingOpti
32
32
  * @param options - The options to use when resolving the module
33
33
  * @returns A promise for the path to the module
34
34
  */
35
- export declare function resolveSafe(name: string, options?: PackageResolvingOptions): Promise<any> | undefined;
35
+ export declare function resolveSafe(name: string, options?: PackageResolvingOptions): Promise<string | undefined>;
36
36
  /**
37
37
  * Resolve the path to a specified module with error handling
38
38
  *
@@ -40,7 +40,7 @@ export declare function resolveSafe(name: string, options?: PackageResolvingOpti
40
40
  * @param options - The options to use when resolving the module
41
41
  * @returns The path to the module or undefined
42
42
  */
43
- export declare function resolveSafeSync(name: string, options?: PackageResolvingOptions): any;
43
+ export declare function resolveSafeSync(name: string, options?: PackageResolvingOptions): string | undefined;
44
44
  /**
45
45
  * Import a module from a specified path
46
46
  *
@@ -54,11 +54,11 @@ export declare function importModule<T = any>(path: string): Promise<T>;
54
54
  * @param path - The path to the module
55
55
  * @returns The module or undefined
56
56
  */
57
- export declare function resolvePackage(name: string, options?: PackageResolvingOptions): Promise<any>;
57
+ export declare function resolvePackage(name: string, options?: PackageResolvingOptions): Promise<string | undefined>;
58
58
  /**
59
59
  * Import a module from a specified path with error handling
60
60
  *
61
61
  * @param path - The path to the module
62
62
  * @returns The module or undefined
63
63
  */
64
- export declare function resolvePackageSync(name: string, options?: PackageResolvingOptions): Promise<any>;
64
+ export declare function resolvePackageSync(name: string, options?: PackageResolvingOptions): Promise<string | undefined>;
package/dist/resolve.mjs CHANGED
@@ -1 +1 @@
1
- import{interopDefault as c,resolvePath as p,resolvePathSync as l}from"mlly";import s from"node:process";import{joinPaths as o,normalizePath as a}from"../utilities";import{getWorkspaceRoot as i}from"../workspace/get-workspace-root";export async function resolve(r,e={}){const t=e.paths??[];t.length===0&&t.push(s.cwd());const n=i();return t.includes(n)||t.push(n),a(await p(r,{url:t}))}export function resolveSync(r,e={}){const t=e.paths??[];t.length===0&&t.push(s.cwd());const n=i();return t.includes(n)||t.push(n),a(l(r,{url:e.paths}))}export function resolveSafe(r,e={}){try{return 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}export async function resolvePackageSync(r,e={}){let t=await resolveSafeSync(o(r,"package.json"),e);return t||(t=await resolveSafeSync(o(r,"index.js"),e),t||(t=await resolveSafeSync(r,e))),t}
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}
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@stryke/path",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
- "description": "A package containing various utilities that expand the functionality of NodeJs's `path` module",
5
+ "description": "A package containing various utilities that expand the functionality of NodeJs's built-in `path` module",
6
6
  "repository": {
7
7
  "type": "github",
8
8
  "url": "https://github.com/storm-software/stryke.git",
@@ -12,9 +12,12 @@
12
12
  "dependencies": {
13
13
  "@storm-software/config-tools": "latest",
14
14
  "mlly": "1.7.4",
15
- "@stryke/types": ">=0.6.0"
15
+ "@stryke/types": ">=0.6.1"
16
+ },
17
+ "devDependencies": {
18
+ "@stryke/types": "workspace:*",
19
+ "@types/node": "^22.13.1"
16
20
  },
17
- "devDependencies": { "@types/node": "^22.13.1" },
18
21
  "publishConfig": { "access": "public" },
19
22
  "sideEffects": false,
20
23
  "files": ["dist/**/*"],
@@ -73,20 +76,6 @@
73
76
  "default": "./dist/resolve.mjs"
74
77
  }
75
78
  },
76
- "./normalize-path": {
77
- "import": {
78
- "types": "./dist/normalize-path.d.ts",
79
- "default": "./dist/normalize-path.mjs"
80
- },
81
- "require": {
82
- "types": "./dist/normalize-path.d.ts",
83
- "default": "./dist/normalize-path.cjs"
84
- },
85
- "default": {
86
- "types": "./dist/normalize-path.d.ts",
87
- "default": "./dist/normalize-path.mjs"
88
- }
89
- },
90
79
  "./join-paths": {
91
80
  "import": {
92
81
  "types": "./dist/join-paths.d.ts",
@@ -207,6 +196,20 @@
207
196
  "default": "./dist/delimiter.mjs"
208
197
  }
209
198
  },
199
+ "./correct-path": {
200
+ "import": {
201
+ "types": "./dist/correct-path.d.ts",
202
+ "default": "./dist/correct-path.mjs"
203
+ },
204
+ "require": {
205
+ "types": "./dist/correct-path.d.ts",
206
+ "default": "./dist/correct-path.cjs"
207
+ },
208
+ "default": {
209
+ "types": "./dist/correct-path.d.ts",
210
+ "default": "./dist/correct-path.mjs"
211
+ }
212
+ },
210
213
  "./asset-extensions": {
211
214
  "import": {
212
215
  "types": "./dist/asset-extensions.d.ts",
@@ -1 +0,0 @@
1
- import{isAbsolutePath as g}from"./is-file";export function slash(e){return e.replace(/\\/g,"/")}const c=/^[A-Z]:\//i;export function normalizeWindowsPath(e=""){return e&&e.replace(/\\/g,"/").replace(c,i=>i.toUpperCase())}const u=/^[/\\]{2}/,E=/^[A-Z]:$/i;export const correctPaths=e=>{if(!e||e.length===0)return".";e=normalizeWindowsPath(e);const i=e.match(u),n=g(e),t=e[e.length-1]==="/";return e=normalizeString(e,!n),e.length===0?n?"/":t?"./":".":(t&&(e+="/"),E.test(e)&&(e+="/"),i?n?`//${e}`:`//./${e}`:n&&!g(e)?`/${e}`:e)};export function normalizeString(e,i){let n="",t=0,s=-1,r=0,o=null;for(let l=0;l<=e.length;++l){if(l<e.length)o=e[l];else{if(o==="/")break;o="/"}if(o==="/"){if(!(s===l-1||r===1))if(r===2){if(n.length<2||t!==2||n[n.length-1]!=="."||n[n.length-2]!=="."){if(n.length>2){const f=n.lastIndexOf("/");f===-1?(n="",t=0):(n=n.slice(0,f),t=n.length-1-n.lastIndexOf("/")),s=l,r=0;continue}else if(n.length>0){n="",t=0,s=l,r=0;continue}}i&&(n+=n.length>0?"/..":"..",t=2)}else n.length>0?n+=`/${e.slice(s+1,l)}`:n=e.slice(s+1,l),t=l-s-1;s=l,r=0}else o==="."&&r!==-1?++r:r=-1}return n}