@stryke/path 0.5.0 → 0.5.1
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/dist/file-path-fns.cjs +25 -24
- package/dist/file-path-fns.d.ts +2 -2
- package/dist/file-path-fns.mjs +1 -1
- package/dist/resolve.cjs +3 -2
- package/dist/resolve.d.ts +14 -7
- package/dist/resolve.mjs +1 -1
- package/package.json +1 -1
package/dist/file-path-fns.cjs
CHANGED
|
@@ -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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
40
|
+
let i = "";
|
|
40
41
|
for (let n = e.length - 1; n >= 0; n--) {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
|
|
42
|
+
const r = e[n];
|
|
43
|
+
if (r) {
|
|
44
|
+
i = r;
|
|
44
45
|
break;
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
|
-
return
|
|
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
|
|
62
|
+
const i = (0, _correctPath.normalizeWindowsPath)(t).split("/");
|
|
62
63
|
let n = "",
|
|
63
|
-
|
|
64
|
-
for (let s =
|
|
65
|
-
const o = s >= 0 ?
|
|
66
|
-
!o || o.length === 0 || (n = (0, _joinPaths.joinPaths)(o, n),
|
|
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, !
|
|
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
|
-
|
|
82
|
-
n =
|
|
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
|
|
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:
|
|
91
|
+
base: r,
|
|
91
92
|
ext: o,
|
|
92
|
-
name:
|
|
93
|
+
name: r.slice(0, r.length - o.length)
|
|
93
94
|
};
|
|
94
95
|
}
|
|
95
96
|
function renameFile(t, e) {
|
|
96
|
-
const
|
|
97
|
-
return (0, _joinPaths.joinPaths)(
|
|
97
|
+
const i = parsePath(t);
|
|
98
|
+
return (0, _joinPaths.joinPaths)(i.dir, e.includes(".") ? e : e + i.ext);
|
|
98
99
|
}
|
package/dist/file-path-fns.d.ts
CHANGED
|
@@ -22,10 +22,10 @@ export interface FindFileNameOptions {
|
|
|
22
22
|
* ```
|
|
23
23
|
*
|
|
24
24
|
* @param filePath - The file path to process
|
|
25
|
-
* @param options -
|
|
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,
|
|
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
|
*
|
package/dist/file-path-fns.mjs
CHANGED
|
@@ -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,
|
|
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
|
|
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
|
|
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
|
-
*
|
|
52
|
+
* Resolve the path to a specified package asynchronously
|
|
53
53
|
*
|
|
54
|
-
* @
|
|
55
|
-
*
|
|
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
|
-
*
|
|
62
|
+
* Resolve the path to a specified package synchronously
|
|
60
63
|
*
|
|
61
|
-
* @
|
|
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
|
|
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}
|