@storm-software/config-tools 1.190.120 → 1.190.122
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 +1 -1
- package/bin/config.cjs +1272 -105
- package/bin/config.mjs +1271 -0
- package/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/config-file/get-config-file.cjs +63 -79
- package/dist/config-file/get-config-file.d.cts +5 -5
- package/dist/config-file/{get-config-file.d.ts → get-config-file.d.mts} +7 -5
- package/dist/config-file/get-config-file.mjs +66 -0
- package/dist/config-file/index.cjs +4 -1
- package/dist/config-file/index.d.cts +2 -3
- package/dist/config-file/index.d.mts +4 -0
- package/dist/config-file/index.mjs +5 -0
- package/dist/create-storm-config.cjs +105 -136
- package/dist/create-storm-config.d.cts +5 -5
- package/dist/{create-storm-config.d.ts → create-storm-config.d.mts} +7 -5
- package/dist/create-storm-config.mjs +113 -0
- package/dist/env/get-env.cjs +190 -214
- package/dist/env/get-env.d.cts +5 -5
- package/dist/env/{get-env.d.ts → get-env.d.mts} +7 -5
- package/dist/env/get-env.mjs +203 -0
- package/dist/env/index.cjs +7 -2
- package/dist/env/index.d.cts +3 -4
- package/dist/env/index.d.mts +5 -0
- package/dist/env/index.mjs +6 -0
- package/dist/env/set-env.cjs +218 -374
- package/dist/env/set-env.d.cts +8 -8
- package/dist/env/{set-env.d.ts → set-env.d.mts} +10 -8
- package/dist/env/set-env.mjs +231 -0
- package/dist/get-config.cjs +40 -29
- package/dist/get-config.d.cts +18 -18
- package/dist/{get-config.d.ts → get-config.d.mts} +20 -18
- package/dist/get-config.mjs +46 -0
- package/dist/index.cjs +98 -7
- package/dist/index.d.cts +27 -28
- package/dist/index.d.mts +29 -0
- package/dist/index.mjs +26 -0
- package/dist/logger/chalk.cjs +38 -29
- package/dist/logger/chalk.d.cts +18 -17
- package/dist/logger/chalk.d.mts +37 -0
- package/dist/logger/chalk.mjs +43 -0
- package/dist/logger/console-icons.cjs +15 -14
- package/dist/logger/console-icons.d.cts +5 -8
- package/dist/logger/console-icons.d.mts +7 -0
- package/dist/logger/console-icons.mjs +20 -0
- package/dist/logger/console.cjs +187 -183
- package/dist/logger/console.d.cts +25 -25
- package/dist/logger/{console.d.ts → console.d.mts} +27 -25
- package/dist/logger/console.mjs +185 -0
- package/dist/logger/create-logger.cjs +31 -24
- package/dist/logger/create-logger.d.cts +5 -6
- package/dist/logger/{create-logger.d.ts → create-logger.d.mts} +7 -6
- package/dist/logger/create-logger.mjs +34 -0
- package/dist/logger/format-timestamp.cjs +12 -4
- package/dist/logger/format-timestamp.d.cts +3 -2
- package/dist/logger/{format-timestamp.d.ts → format-timestamp.d.mts} +5 -2
- package/dist/logger/format-timestamp.mjs +16 -0
- package/dist/logger/get-log-level.cjs +50 -60
- package/dist/logger/get-log-level.d.cts +4 -5
- package/dist/logger/{get-log-level.d.ts → get-log-level.d.mts} +6 -5
- package/dist/logger/get-log-level.mjs +54 -0
- package/dist/logger/index.cjs +29 -7
- package/dist/logger/index.d.cts +8 -10
- package/dist/logger/index.d.mts +10 -0
- package/dist/logger/index.mjs +11 -0
- package/dist/logger/is-unicode-supported.cjs +6 -10
- package/dist/logger/is-unicode-supported.d.cts +3 -2
- package/dist/logger/is-unicode-supported.d.mts +6 -0
- package/dist/logger/is-unicode-supported.mjs +10 -0
- package/dist/types.cjs +26 -25
- package/dist/types.d.cts +39 -41
- package/dist/types.d.mts +53 -0
- package/dist/types.mjs +30 -0
- package/dist/utilities/apply-workspace-tokens.cjs +31 -70
- package/dist/utilities/apply-workspace-tokens.d.cts +4 -5
- package/dist/utilities/{apply-workspace-tokens.d.ts → apply-workspace-tokens.d.mts} +6 -5
- package/dist/utilities/apply-workspace-tokens.mjs +37 -0
- package/dist/utilities/colors.cjs +91 -74
- package/dist/utilities/colors.d.cts +4 -4
- package/dist/utilities/{colors.d.ts → colors.d.mts} +6 -4
- package/dist/utilities/colors.mjs +97 -0
- package/dist/utilities/correct-paths.cjs +166 -196
- package/dist/utilities/correct-paths.d.cts +4 -4
- package/dist/utilities/{correct-paths.d.ts → correct-paths.d.mts} +6 -4
- package/dist/utilities/correct-paths.mjs +190 -0
- package/dist/utilities/file-path-utils.cjs +42 -27
- package/dist/utilities/file-path-utils.d.cts +15 -14
- package/dist/utilities/{file-path-utils.d.ts → file-path-utils.d.mts} +17 -14
- package/dist/utilities/file-path-utils.mjs +48 -0
- package/dist/utilities/find-up.cjs +12 -18
- package/dist/utilities/find-up.d.cts +3 -2
- package/dist/utilities/{find-up.d.ts → find-up.d.mts} +5 -2
- package/dist/utilities/find-up.mjs +19 -0
- package/dist/utilities/find-workspace-root.cjs +64 -69
- package/dist/utilities/find-workspace-root.d.cts +3 -2
- package/dist/utilities/{find-workspace-root.d.ts → find-workspace-root.d.mts} +5 -2
- package/dist/utilities/find-workspace-root.mjs +73 -0
- package/dist/utilities/get-default-config.cjs +69 -91
- package/dist/utilities/get-default-config.d.cts +4 -4
- package/dist/utilities/{get-default-config.d.ts → get-default-config.d.mts} +6 -4
- package/dist/utilities/get-default-config.mjs +74 -0
- package/dist/utilities/index.cjs +49 -9
- package/dist/utilities/index.d.cts +10 -14
- package/dist/utilities/index.d.mts +12 -0
- package/dist/utilities/index.mjs +13 -0
- package/dist/utilities/process-handler.cjs +32 -47
- package/dist/utilities/process-handler.d.cts +4 -4
- package/dist/utilities/process-handler.d.mts +9 -0
- package/dist/utilities/process-handler.mjs +38 -0
- package/dist/utilities/run.cjs +62 -36
- package/dist/utilities/run.d.cts +5 -6
- package/dist/utilities/{run.d.ts → run.d.mts} +7 -6
- package/dist/utilities/run.mjs +64 -0
- package/dist/utilities/toml.cjs +27 -32
- package/dist/utilities/toml.d.cts +148 -147
- package/dist/utilities/toml.d.mts +192 -0
- package/dist/utilities/toml.mjs +33 -0
- package/package.json +105 -157
- package/bin/config.js +0 -108
- package/dist/config-file/get-config-file.js +0 -83
- package/dist/config-file/index.d.ts +0 -3
- package/dist/config-file/index.js +0 -1
- package/dist/create-storm-config.js +0 -147
- package/dist/env/get-env.js +0 -226
- package/dist/env/index.d.ts +0 -4
- package/dist/env/index.js +0 -2
- package/dist/env/set-env.js +0 -386
- package/dist/get-config.js +0 -35
- package/dist/index.d.ts +0 -28
- package/dist/index.js +0 -7
- package/dist/logger/chalk.d.ts +0 -34
- package/dist/logger/chalk.js +0 -34
- package/dist/logger/console-icons.d.ts +0 -8
- package/dist/logger/console-icons.js +0 -17
- package/dist/logger/console.js +0 -191
- package/dist/logger/create-logger.js +0 -27
- package/dist/logger/format-timestamp.js +0 -6
- package/dist/logger/get-log-level.js +0 -64
- package/dist/logger/index.d.ts +0 -10
- package/dist/logger/index.js +0 -7
- package/dist/logger/is-unicode-supported.d.ts +0 -3
- package/dist/logger/is-unicode-supported.js +0 -12
- package/dist/types.d.ts +0 -53
- package/dist/types.js +0 -28
- package/dist/utilities/apply-workspace-tokens.js +0 -76
- package/dist/utilities/colors.js +0 -81
- package/dist/utilities/correct-paths.js +0 -231
- package/dist/utilities/file-path-utils.js +0 -33
- package/dist/utilities/find-up.js +0 -23
- package/dist/utilities/find-workspace-root.js +0 -77
- package/dist/utilities/get-default-config.js +0 -95
- package/dist/utilities/index.d.ts +0 -14
- package/dist/utilities/index.js +0 -9
- package/dist/utilities/process-handler.d.ts +0 -7
- package/dist/utilities/process-handler.js +0 -53
- package/dist/utilities/run.js +0 -38
- package/dist/utilities/toml.d.ts +0 -189
- package/dist/utilities/toml.js +0 -42
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/utilities/correct-paths.ts
|
|
3
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
2
4
|
function normalizeWindowsPath(input = "") {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
5
|
+
if (!input) return input;
|
|
6
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
7
7
|
}
|
|
8
8
|
const _UNC_REGEX = /^[/\\]{2}/;
|
|
9
9
|
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
@@ -11,221 +11,191 @@ const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
|
|
|
11
11
|
const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
|
|
12
12
|
const _EXTNAME_RE = /.(\.[^./]+|\.)$/;
|
|
13
13
|
const _PATH_ROOT_RE = /^[/\\]|^[a-zA-Z]:[/\\]/;
|
|
14
|
+
/**
|
|
15
|
+
* Constant for path separator.
|
|
16
|
+
*
|
|
17
|
+
* Always equals to `"/"`.
|
|
18
|
+
*/
|
|
14
19
|
const sep = "/";
|
|
15
20
|
const correctPaths = function(path) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (_DRIVE_LETTER_RE.test(path)) {
|
|
34
|
-
path += "/";
|
|
35
|
-
}
|
|
36
|
-
if (isUNCPath) {
|
|
37
|
-
if (!isPathAbsolute) {
|
|
38
|
-
return `//./${path}`;
|
|
39
|
-
}
|
|
40
|
-
return `//${path}`;
|
|
41
|
-
}
|
|
42
|
-
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
21
|
+
if (!path || path.length === 0) return ".";
|
|
22
|
+
path = normalizeWindowsPath(path);
|
|
23
|
+
const isUNCPath = path?.match(_UNC_REGEX);
|
|
24
|
+
const isPathAbsolute = isAbsolute(path);
|
|
25
|
+
const trailingSeparator = path[path.length - 1] === "/";
|
|
26
|
+
path = normalizeString(path, !isPathAbsolute);
|
|
27
|
+
if (path.length === 0) {
|
|
28
|
+
if (isPathAbsolute) return "/";
|
|
29
|
+
return trailingSeparator ? "./" : ".";
|
|
30
|
+
}
|
|
31
|
+
if (trailingSeparator) path += "/";
|
|
32
|
+
if (_DRIVE_LETTER_RE.test(path)) path += "/";
|
|
33
|
+
if (isUNCPath) {
|
|
34
|
+
if (!isPathAbsolute) return `//./${path}`;
|
|
35
|
+
return `//${path}`;
|
|
36
|
+
}
|
|
37
|
+
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
43
38
|
};
|
|
44
39
|
const joinPaths = function(...segments) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
} else {
|
|
57
|
-
path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
path += seg;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return correctPaths(path);
|
|
40
|
+
let path = "";
|
|
41
|
+
for (const seg of segments) {
|
|
42
|
+
if (!seg) continue;
|
|
43
|
+
if (path.length > 0) {
|
|
44
|
+
const pathTrailing = path[path.length - 1] === "/";
|
|
45
|
+
const segLeading = seg[0] === "/";
|
|
46
|
+
if (pathTrailing && segLeading) path += seg.slice(1);
|
|
47
|
+
else path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
48
|
+
} else path += seg;
|
|
49
|
+
}
|
|
50
|
+
return correctPaths(path);
|
|
64
51
|
};
|
|
65
52
|
function cwd() {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
return "/";
|
|
53
|
+
if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
|
|
54
|
+
return "/";
|
|
70
55
|
}
|
|
71
56
|
const resolve = function(...arguments_) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
85
|
-
return `/${resolvedPath}`;
|
|
86
|
-
}
|
|
87
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
57
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
58
|
+
let resolvedPath = "";
|
|
59
|
+
let resolvedAbsolute = false;
|
|
60
|
+
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
61
|
+
const path = index >= 0 ? arguments_[index] : cwd();
|
|
62
|
+
if (!path || path.length === 0) continue;
|
|
63
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
64
|
+
resolvedAbsolute = isAbsolute(path);
|
|
65
|
+
}
|
|
66
|
+
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
67
|
+
if (resolvedAbsolute && !isAbsolute(resolvedPath)) return `/${resolvedPath}`;
|
|
68
|
+
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
88
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
|
|
72
|
+
*
|
|
73
|
+
* @param path - The path to normalise.
|
|
74
|
+
* @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
|
|
75
|
+
* @returns the normalised path string.
|
|
76
|
+
*/
|
|
89
77
|
function normalizeString(path, allowAboveRoot) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
138
|
-
}
|
|
139
|
-
lastSlash = index;
|
|
140
|
-
dots = 0;
|
|
141
|
-
} else if (char === "." && dots !== -1) {
|
|
142
|
-
++dots;
|
|
143
|
-
} else {
|
|
144
|
-
dots = -1;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return res;
|
|
78
|
+
let res = "";
|
|
79
|
+
let lastSegmentLength = 0;
|
|
80
|
+
let lastSlash = -1;
|
|
81
|
+
let dots = 0;
|
|
82
|
+
let char = null;
|
|
83
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
84
|
+
if (index < path.length) char = path[index];
|
|
85
|
+
else if (char === "/") break;
|
|
86
|
+
else char = "/";
|
|
87
|
+
if (char === "/") {
|
|
88
|
+
if (lastSlash === index - 1 || dots === 1) {} else if (dots === 2) {
|
|
89
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
90
|
+
if (res.length > 2) {
|
|
91
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
92
|
+
if (lastSlashIndex === -1) {
|
|
93
|
+
res = "";
|
|
94
|
+
lastSegmentLength = 0;
|
|
95
|
+
} else {
|
|
96
|
+
res = res.slice(0, lastSlashIndex);
|
|
97
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
98
|
+
}
|
|
99
|
+
lastSlash = index;
|
|
100
|
+
dots = 0;
|
|
101
|
+
continue;
|
|
102
|
+
} else if (res.length > 0) {
|
|
103
|
+
res = "";
|
|
104
|
+
lastSegmentLength = 0;
|
|
105
|
+
lastSlash = index;
|
|
106
|
+
dots = 0;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (allowAboveRoot) {
|
|
111
|
+
res += res.length > 0 ? "/.." : "..";
|
|
112
|
+
lastSegmentLength = 2;
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
|
|
116
|
+
else res = path.slice(lastSlash + 1, index);
|
|
117
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
118
|
+
}
|
|
119
|
+
lastSlash = index;
|
|
120
|
+
dots = 0;
|
|
121
|
+
} else if (char === "." && dots !== -1) ++dots;
|
|
122
|
+
else dots = -1;
|
|
123
|
+
}
|
|
124
|
+
return res;
|
|
148
125
|
}
|
|
149
126
|
const isAbsolute = function(p) {
|
|
150
|
-
|
|
127
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
151
128
|
};
|
|
152
129
|
const toNamespacedPath = function(p) {
|
|
153
|
-
|
|
130
|
+
return normalizeWindowsPath(p);
|
|
154
131
|
};
|
|
155
132
|
const extname = function(p) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
133
|
+
if (p === "..") return "";
|
|
134
|
+
const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
|
|
135
|
+
return match && match[1] || "";
|
|
159
136
|
};
|
|
160
137
|
const relative = function(from, to) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
_from.shift();
|
|
172
|
-
_to.shift();
|
|
173
|
-
}
|
|
174
|
-
return [..._from.map(() => ".."), ..._to].join("/");
|
|
138
|
+
const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
139
|
+
const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
140
|
+
if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) return _to.join("/");
|
|
141
|
+
const _fromCopy = [..._from];
|
|
142
|
+
for (const segment of _fromCopy) {
|
|
143
|
+
if (_to[0] !== segment) break;
|
|
144
|
+
_from.shift();
|
|
145
|
+
_to.shift();
|
|
146
|
+
}
|
|
147
|
+
return [..._from.map(() => ".."), ..._to].join("/");
|
|
175
148
|
};
|
|
176
149
|
const dirname = function(p) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
return segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
|
150
|
+
const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
|
151
|
+
if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
|
|
152
|
+
return segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
|
182
153
|
};
|
|
183
154
|
const format = function(p) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
155
|
+
const ext = p.ext ? p.ext.startsWith(".") ? p.ext : `.${p.ext}` : "";
|
|
156
|
+
const segments = [
|
|
157
|
+
p.root,
|
|
158
|
+
p.dir,
|
|
159
|
+
p.base ?? (p.name ?? "") + ext
|
|
160
|
+
].filter(Boolean);
|
|
161
|
+
return normalizeWindowsPath(p.root ? resolve(...segments) : segments.join("/"));
|
|
191
162
|
};
|
|
192
163
|
const basename = function(p, extension) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
164
|
+
const segments = normalizeWindowsPath(p).split("/");
|
|
165
|
+
let lastSegment = "";
|
|
166
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
167
|
+
const val = segments[i];
|
|
168
|
+
if (val) {
|
|
169
|
+
lastSegment = val;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
|
|
203
174
|
};
|
|
204
175
|
const parse = function(p) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
176
|
+
const root = _PATH_ROOT_RE.exec(p)?.[0]?.replace(/\\/g, "/") || "";
|
|
177
|
+
const base = basename(p);
|
|
178
|
+
const extension = extname(base);
|
|
179
|
+
return {
|
|
180
|
+
root,
|
|
181
|
+
dir: dirname(p),
|
|
182
|
+
base,
|
|
183
|
+
ext: extension,
|
|
184
|
+
name: base.slice(0, base.length - extension.length)
|
|
185
|
+
};
|
|
215
186
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
exports.basename = basename; exports.correctPaths = correctPaths; exports.dirname = dirname; exports.extname = extname; exports.format = format; exports.isAbsolute = isAbsolute; exports.joinPaths = joinPaths; exports.normalizeString = normalizeString; exports.normalizeWindowsPath = normalizeWindowsPath; exports.parse = parse; exports.relative = relative; exports.resolve = resolve; exports.sep = sep; exports.toNamespacedPath = toNamespacedPath;
|
|
187
|
+
//#endregion
|
|
188
|
+
exports.basename = basename;
|
|
189
|
+
exports.correctPaths = correctPaths;
|
|
190
|
+
exports.dirname = dirname;
|
|
191
|
+
exports.extname = extname;
|
|
192
|
+
exports.format = format;
|
|
193
|
+
exports.isAbsolute = isAbsolute;
|
|
194
|
+
exports.joinPaths = joinPaths;
|
|
195
|
+
exports.normalizeString = normalizeString;
|
|
196
|
+
exports.normalizeWindowsPath = normalizeWindowsPath;
|
|
197
|
+
exports.parse = parse;
|
|
198
|
+
exports.relative = relative;
|
|
199
|
+
exports.resolve = resolve;
|
|
200
|
+
exports.sep = sep;
|
|
201
|
+
exports.toNamespacedPath = toNamespacedPath;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
//#region src/utilities/correct-paths.d.ts
|
|
3
3
|
declare function normalizeWindowsPath(input?: string): string;
|
|
4
4
|
/**
|
|
5
5
|
* Constant for path separator.
|
|
@@ -26,5 +26,5 @@ declare const dirname: typeof path.dirname;
|
|
|
26
26
|
declare const format: typeof path.format;
|
|
27
27
|
declare const basename: typeof path.basename;
|
|
28
28
|
declare const parse: typeof path.parse;
|
|
29
|
-
|
|
30
|
-
export { basename, correctPaths, dirname, extname, format, isAbsolute, joinPaths, normalizeString, normalizeWindowsPath, parse, relative, resolve, sep, toNamespacedPath };
|
|
29
|
+
//#endregion
|
|
30
|
+
export { basename, correctPaths, dirname, extname, format, isAbsolute, joinPaths, normalizeString, normalizeWindowsPath, parse, relative, resolve, sep, toNamespacedPath };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import __tsdown_shims_path from 'node:path';
|
|
2
|
+
import __tsdown_shims_url from 'node:url';
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
//#region src/utilities/correct-paths.d.ts
|
|
3
5
|
declare function normalizeWindowsPath(input?: string): string;
|
|
4
6
|
/**
|
|
5
7
|
* Constant for path separator.
|
|
@@ -26,5 +28,5 @@ declare const dirname: typeof path.dirname;
|
|
|
26
28
|
declare const format: typeof path.format;
|
|
27
29
|
declare const basename: typeof path.basename;
|
|
28
30
|
declare const parse: typeof path.parse;
|
|
29
|
-
|
|
30
|
-
export { basename, correctPaths, dirname, extname, format, isAbsolute, joinPaths, normalizeString, normalizeWindowsPath, parse, relative, resolve, sep, toNamespacedPath };
|
|
31
|
+
//#endregion
|
|
32
|
+
export { basename, correctPaths, dirname, extname, format, isAbsolute, joinPaths, normalizeString, normalizeWindowsPath, parse, relative, resolve, sep, toNamespacedPath };
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import "node:path";
|
|
2
|
+
import "node:url";
|
|
3
|
+
import.meta.url;
|
|
4
|
+
//#region src/utilities/correct-paths.ts
|
|
5
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
6
|
+
function normalizeWindowsPath(input = "") {
|
|
7
|
+
if (!input) return input;
|
|
8
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
9
|
+
}
|
|
10
|
+
const _UNC_REGEX = /^[/\\]{2}/;
|
|
11
|
+
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
12
|
+
const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
|
|
13
|
+
const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
|
|
14
|
+
const _EXTNAME_RE = /.(\.[^./]+|\.)$/;
|
|
15
|
+
const _PATH_ROOT_RE = /^[/\\]|^[a-zA-Z]:[/\\]/;
|
|
16
|
+
/**
|
|
17
|
+
* Constant for path separator.
|
|
18
|
+
*
|
|
19
|
+
* Always equals to `"/"`.
|
|
20
|
+
*/
|
|
21
|
+
const sep = "/";
|
|
22
|
+
const correctPaths = function(path) {
|
|
23
|
+
if (!path || path.length === 0) return ".";
|
|
24
|
+
path = normalizeWindowsPath(path);
|
|
25
|
+
const isUNCPath = path?.match(_UNC_REGEX);
|
|
26
|
+
const isPathAbsolute = isAbsolute(path);
|
|
27
|
+
const trailingSeparator = path[path.length - 1] === "/";
|
|
28
|
+
path = normalizeString(path, !isPathAbsolute);
|
|
29
|
+
if (path.length === 0) {
|
|
30
|
+
if (isPathAbsolute) return "/";
|
|
31
|
+
return trailingSeparator ? "./" : ".";
|
|
32
|
+
}
|
|
33
|
+
if (trailingSeparator) path += "/";
|
|
34
|
+
if (_DRIVE_LETTER_RE.test(path)) path += "/";
|
|
35
|
+
if (isUNCPath) {
|
|
36
|
+
if (!isPathAbsolute) return `//./${path}`;
|
|
37
|
+
return `//${path}`;
|
|
38
|
+
}
|
|
39
|
+
return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
|
|
40
|
+
};
|
|
41
|
+
const joinPaths = function(...segments) {
|
|
42
|
+
let path = "";
|
|
43
|
+
for (const seg of segments) {
|
|
44
|
+
if (!seg) continue;
|
|
45
|
+
if (path.length > 0) {
|
|
46
|
+
const pathTrailing = path[path.length - 1] === "/";
|
|
47
|
+
const segLeading = seg[0] === "/";
|
|
48
|
+
if (pathTrailing && segLeading) path += seg.slice(1);
|
|
49
|
+
else path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
50
|
+
} else path += seg;
|
|
51
|
+
}
|
|
52
|
+
return correctPaths(path);
|
|
53
|
+
};
|
|
54
|
+
function cwd() {
|
|
55
|
+
if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
|
|
56
|
+
return "/";
|
|
57
|
+
}
|
|
58
|
+
const resolve = function(...arguments_) {
|
|
59
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
60
|
+
let resolvedPath = "";
|
|
61
|
+
let resolvedAbsolute = false;
|
|
62
|
+
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
63
|
+
const path = index >= 0 ? arguments_[index] : cwd();
|
|
64
|
+
if (!path || path.length === 0) continue;
|
|
65
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
66
|
+
resolvedAbsolute = isAbsolute(path);
|
|
67
|
+
}
|
|
68
|
+
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
69
|
+
if (resolvedAbsolute && !isAbsolute(resolvedPath)) return `/${resolvedPath}`;
|
|
70
|
+
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Resolves a string path, resolving '.' and '.' segments and allowing paths above the root.
|
|
74
|
+
*
|
|
75
|
+
* @param path - The path to normalise.
|
|
76
|
+
* @param allowAboveRoot - Whether to allow the resulting path to be above the root directory.
|
|
77
|
+
* @returns the normalised path string.
|
|
78
|
+
*/
|
|
79
|
+
function normalizeString(path, allowAboveRoot) {
|
|
80
|
+
let res = "";
|
|
81
|
+
let lastSegmentLength = 0;
|
|
82
|
+
let lastSlash = -1;
|
|
83
|
+
let dots = 0;
|
|
84
|
+
let char = null;
|
|
85
|
+
for (let index = 0; index <= path.length; ++index) {
|
|
86
|
+
if (index < path.length) char = path[index];
|
|
87
|
+
else if (char === "/") break;
|
|
88
|
+
else char = "/";
|
|
89
|
+
if (char === "/") {
|
|
90
|
+
if (lastSlash === index - 1 || dots === 1) {} else if (dots === 2) {
|
|
91
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
92
|
+
if (res.length > 2) {
|
|
93
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
|
94
|
+
if (lastSlashIndex === -1) {
|
|
95
|
+
res = "";
|
|
96
|
+
lastSegmentLength = 0;
|
|
97
|
+
} else {
|
|
98
|
+
res = res.slice(0, lastSlashIndex);
|
|
99
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
100
|
+
}
|
|
101
|
+
lastSlash = index;
|
|
102
|
+
dots = 0;
|
|
103
|
+
continue;
|
|
104
|
+
} else if (res.length > 0) {
|
|
105
|
+
res = "";
|
|
106
|
+
lastSegmentLength = 0;
|
|
107
|
+
lastSlash = index;
|
|
108
|
+
dots = 0;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (allowAboveRoot) {
|
|
113
|
+
res += res.length > 0 ? "/.." : "..";
|
|
114
|
+
lastSegmentLength = 2;
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
if (res.length > 0) res += `/${path.slice(lastSlash + 1, index)}`;
|
|
118
|
+
else res = path.slice(lastSlash + 1, index);
|
|
119
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
120
|
+
}
|
|
121
|
+
lastSlash = index;
|
|
122
|
+
dots = 0;
|
|
123
|
+
} else if (char === "." && dots !== -1) ++dots;
|
|
124
|
+
else dots = -1;
|
|
125
|
+
}
|
|
126
|
+
return res;
|
|
127
|
+
}
|
|
128
|
+
const isAbsolute = function(p) {
|
|
129
|
+
return _IS_ABSOLUTE_RE.test(p);
|
|
130
|
+
};
|
|
131
|
+
const toNamespacedPath = function(p) {
|
|
132
|
+
return normalizeWindowsPath(p);
|
|
133
|
+
};
|
|
134
|
+
const extname = function(p) {
|
|
135
|
+
if (p === "..") return "";
|
|
136
|
+
const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
|
|
137
|
+
return match && match[1] || "";
|
|
138
|
+
};
|
|
139
|
+
const relative = function(from, to) {
|
|
140
|
+
const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
141
|
+
const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
142
|
+
if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) return _to.join("/");
|
|
143
|
+
const _fromCopy = [..._from];
|
|
144
|
+
for (const segment of _fromCopy) {
|
|
145
|
+
if (_to[0] !== segment) break;
|
|
146
|
+
_from.shift();
|
|
147
|
+
_to.shift();
|
|
148
|
+
}
|
|
149
|
+
return [..._from.map(() => ".."), ..._to].join("/");
|
|
150
|
+
};
|
|
151
|
+
const dirname = function(p) {
|
|
152
|
+
const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
|
153
|
+
if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) segments[0] += "/";
|
|
154
|
+
return segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
|
155
|
+
};
|
|
156
|
+
const format = function(p) {
|
|
157
|
+
const ext = p.ext ? p.ext.startsWith(".") ? p.ext : `.${p.ext}` : "";
|
|
158
|
+
const segments = [
|
|
159
|
+
p.root,
|
|
160
|
+
p.dir,
|
|
161
|
+
p.base ?? (p.name ?? "") + ext
|
|
162
|
+
].filter(Boolean);
|
|
163
|
+
return normalizeWindowsPath(p.root ? resolve(...segments) : segments.join("/"));
|
|
164
|
+
};
|
|
165
|
+
const basename = function(p, extension) {
|
|
166
|
+
const segments = normalizeWindowsPath(p).split("/");
|
|
167
|
+
let lastSegment = "";
|
|
168
|
+
for (let i = segments.length - 1; i >= 0; i--) {
|
|
169
|
+
const val = segments[i];
|
|
170
|
+
if (val) {
|
|
171
|
+
lastSegment = val;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
|
|
176
|
+
};
|
|
177
|
+
const parse = function(p) {
|
|
178
|
+
const root = _PATH_ROOT_RE.exec(p)?.[0]?.replace(/\\/g, "/") || "";
|
|
179
|
+
const base = basename(p);
|
|
180
|
+
const extension = extname(base);
|
|
181
|
+
return {
|
|
182
|
+
root,
|
|
183
|
+
dir: dirname(p),
|
|
184
|
+
base,
|
|
185
|
+
ext: extension,
|
|
186
|
+
name: base.slice(0, base.length - extension.length)
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
//#endregion
|
|
190
|
+
export { basename, correctPaths, dirname, extname, format, isAbsolute, joinPaths, normalizeString, normalizeWindowsPath, parse, relative, resolve, sep, toNamespacedPath };
|