@travetto/manifest 3.3.0 → 3.3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/path.ts +31 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/manifest",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "description": "Support for project indexing, manifesting, along with file watching",
5
5
  "keywords": [
6
6
  "path",
package/src/path.ts CHANGED
@@ -1,17 +1,35 @@
1
- import { extname, dirname, resolve, basename, join } from 'path/posix';
2
- import { sep } from 'path';
1
+ import type * as pathMod from 'path';
2
+ import { extname, dirname, basename, resolve, join } from 'path/posix';
3
+ import { sep, resolve as nativeResolve, join as nativeJoin } from 'path';
3
4
 
4
- const posix = (file: string): string => file.replaceAll('\\', '/');
5
+ /**
6
+ * Converts a given file name by replace all slashes, with forward slashes
7
+ */
8
+ const toPosix = (file: string): string => file.replaceAll('\\', '/');
9
+ /**
10
+ * Converts a given file name by replace all slashes, with platform dependent path separators
11
+ */
12
+ const toNative = (file: string): string => file.replaceAll('/', sep);
5
13
 
6
- const cwd = (): string => posix(process.cwd());
14
+ const cwd = (): string => toPosix(process.cwd());
7
15
 
8
- export const path = {
16
+ type PathModType =
17
+ { toPosix: typeof toPosix, toNative: typeof toNative } &
18
+ Pick<typeof pathMod, 'basename' | 'dirname' | 'extname' | 'join' | 'resolve'> &
19
+ Pick<typeof process, 'cwd'>;
20
+
21
+ export const path: PathModType = {
9
22
  cwd,
10
- toPosix: posix,
11
- basename: (file: string, suffix?: string): string => basename(posix(file), suffix),
12
- extname: (file: string): string => extname(posix(file)),
13
- dirname: (file: string): string => dirname(posix(file)),
14
- resolve: (...args: string[]): string => resolve(cwd(), ...args.map(f => posix(f))),
15
- join: (root: string, ...args: string[]): string => join(posix(root), ...args.map(f => posix(f))),
16
- toNative: (file: string): string => file.replaceAll('/', sep)
17
- };
23
+ toPosix,
24
+ toNative,
25
+ basename: (file, suffix) => basename(toPosix(file), suffix),
26
+ extname: file => extname(toPosix(file)),
27
+ dirname: file => dirname(toPosix(file)),
28
+ resolve: (...args) => resolve(cwd(), ...args.map(toPosix)),
29
+ join: (...args) => join(...args.map(toPosix)),
30
+ };
31
+
32
+ if (process.platform === 'win32') {
33
+ path.resolve = (...args: string[]): string => toPosix(nativeResolve(cwd(), ...args.map(toPosix)));
34
+ path.join = (root: string, ...args: string[]): string => toPosix(nativeJoin(toPosix(root), ...args.map(toPosix)));
35
+ }