@vyriy/path 0.1.18 → 0.1.21
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 +3 -13
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/path.d.ts +1 -5
- package/path.js +2 -6
- package/types.d.ts +1 -6
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @vyriy/path
|
|
2
2
|
|
|
3
|
-
Shared path
|
|
3
|
+
Shared path utility for Vyriy projects.
|
|
4
4
|
|
|
5
5
|
## Purpose
|
|
6
6
|
|
|
7
|
-
This package provides a small
|
|
7
|
+
This package provides a small path resolver rooted at the current project directory. It resolves paths relative to `PROJECT_CWD` when that environment variable is set, and otherwise falls back to `process.cwd()`.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -23,21 +23,11 @@ yarn add @vyriy/path
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
25
|
```ts
|
|
26
|
-
import {
|
|
26
|
+
import { path } from '@vyriy/path';
|
|
27
27
|
|
|
28
28
|
const packageRoot = path('packages', 'path');
|
|
29
|
-
const packageName = directory('packages', 'path');
|
|
30
|
-
|
|
31
|
-
mkdir('tmp', 'artifacts');
|
|
32
|
-
|
|
33
|
-
const entries = readdir('packages');
|
|
34
|
-
const empty = isEmpty('tmp');
|
|
35
29
|
```
|
|
36
30
|
|
|
37
31
|
## API
|
|
38
32
|
|
|
39
33
|
- `path(...segments)` resolves an absolute path from `PROJECT_CWD` or `process.cwd()`.
|
|
40
|
-
- `directory(...segments)` returns the final path segment name.
|
|
41
|
-
- `readdir(...segments)` returns directory entries from the resolved path.
|
|
42
|
-
- `isEmpty(...segments)` returns `true` when the directory contains only ignored entries: `README.md` and `.git`.
|
|
43
|
-
- `mkdir(...segments)` creates the resolved directory recursively.
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './path.js';
|
|
2
|
-
export * from './types.js';
|
|
2
|
+
export type * from './types.js';
|
package/package.json
CHANGED
package/path.d.ts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Path } from './types.js';
|
|
2
2
|
export declare const path: Path;
|
|
3
|
-
export declare const directory: Directory;
|
|
4
|
-
export declare const readdir: Readdir;
|
|
5
|
-
export declare const isEmpty: IsEmpty;
|
|
6
|
-
export declare const mkdir: Mkdir;
|
package/path.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { realpathSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
3
|
export const path = (...pathSegments) => resolve(realpathSync(process.env.PROJECT_CWD || process.cwd()), ...pathSegments);
|
|
4
|
-
export const directory = (...pathSegments) => basename(path(...pathSegments));
|
|
5
|
-
export const readdir = (...pathSegments) => readdirSync(path(...pathSegments));
|
|
6
|
-
export const isEmpty = (...pathSegments) => !readdir(...pathSegments).filter((name) => !['README.md', '.git'].includes(name)).length;
|
|
7
|
-
export const mkdir = (...pathSegments) => mkdirSync(path(...pathSegments), { recursive: true });
|
package/types.d.ts
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export type Path = (...pathSegments: PathSegments) => string;
|
|
3
|
-
export type Directory = (...pathSegments: PathSegments) => string;
|
|
4
|
-
export type Readdir = (...pathSegments: PathSegments) => string[];
|
|
5
|
-
export type IsEmpty = (...pathSegments: PathSegments) => boolean;
|
|
6
|
-
export type Mkdir = (...pathSegments: PathSegments) => void;
|
|
1
|
+
export type Path = (...pathSegments: readonly string[]) => string;
|