@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.
Files changed (157) hide show
  1. package/README.md +1 -1
  2. package/bin/config.cjs +1272 -105
  3. package/bin/config.mjs +1271 -0
  4. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  5. package/dist/config-file/get-config-file.cjs +63 -79
  6. package/dist/config-file/get-config-file.d.cts +5 -5
  7. package/dist/config-file/{get-config-file.d.ts → get-config-file.d.mts} +7 -5
  8. package/dist/config-file/get-config-file.mjs +66 -0
  9. package/dist/config-file/index.cjs +4 -1
  10. package/dist/config-file/index.d.cts +2 -3
  11. package/dist/config-file/index.d.mts +4 -0
  12. package/dist/config-file/index.mjs +5 -0
  13. package/dist/create-storm-config.cjs +105 -136
  14. package/dist/create-storm-config.d.cts +5 -5
  15. package/dist/{create-storm-config.d.ts → create-storm-config.d.mts} +7 -5
  16. package/dist/create-storm-config.mjs +113 -0
  17. package/dist/env/get-env.cjs +190 -214
  18. package/dist/env/get-env.d.cts +5 -5
  19. package/dist/env/{get-env.d.ts → get-env.d.mts} +7 -5
  20. package/dist/env/get-env.mjs +203 -0
  21. package/dist/env/index.cjs +7 -2
  22. package/dist/env/index.d.cts +3 -4
  23. package/dist/env/index.d.mts +5 -0
  24. package/dist/env/index.mjs +6 -0
  25. package/dist/env/set-env.cjs +218 -374
  26. package/dist/env/set-env.d.cts +8 -8
  27. package/dist/env/{set-env.d.ts → set-env.d.mts} +10 -8
  28. package/dist/env/set-env.mjs +231 -0
  29. package/dist/get-config.cjs +40 -29
  30. package/dist/get-config.d.cts +18 -18
  31. package/dist/{get-config.d.ts → get-config.d.mts} +20 -18
  32. package/dist/get-config.mjs +46 -0
  33. package/dist/index.cjs +98 -7
  34. package/dist/index.d.cts +27 -28
  35. package/dist/index.d.mts +29 -0
  36. package/dist/index.mjs +26 -0
  37. package/dist/logger/chalk.cjs +38 -29
  38. package/dist/logger/chalk.d.cts +18 -17
  39. package/dist/logger/chalk.d.mts +37 -0
  40. package/dist/logger/chalk.mjs +43 -0
  41. package/dist/logger/console-icons.cjs +15 -14
  42. package/dist/logger/console-icons.d.cts +5 -8
  43. package/dist/logger/console-icons.d.mts +7 -0
  44. package/dist/logger/console-icons.mjs +20 -0
  45. package/dist/logger/console.cjs +187 -183
  46. package/dist/logger/console.d.cts +25 -25
  47. package/dist/logger/{console.d.ts → console.d.mts} +27 -25
  48. package/dist/logger/console.mjs +185 -0
  49. package/dist/logger/create-logger.cjs +31 -24
  50. package/dist/logger/create-logger.d.cts +5 -6
  51. package/dist/logger/{create-logger.d.ts → create-logger.d.mts} +7 -6
  52. package/dist/logger/create-logger.mjs +34 -0
  53. package/dist/logger/format-timestamp.cjs +12 -4
  54. package/dist/logger/format-timestamp.d.cts +3 -2
  55. package/dist/logger/{format-timestamp.d.ts → format-timestamp.d.mts} +5 -2
  56. package/dist/logger/format-timestamp.mjs +16 -0
  57. package/dist/logger/get-log-level.cjs +50 -60
  58. package/dist/logger/get-log-level.d.cts +4 -5
  59. package/dist/logger/{get-log-level.d.ts → get-log-level.d.mts} +6 -5
  60. package/dist/logger/get-log-level.mjs +54 -0
  61. package/dist/logger/index.cjs +29 -7
  62. package/dist/logger/index.d.cts +8 -10
  63. package/dist/logger/index.d.mts +10 -0
  64. package/dist/logger/index.mjs +11 -0
  65. package/dist/logger/is-unicode-supported.cjs +6 -10
  66. package/dist/logger/is-unicode-supported.d.cts +3 -2
  67. package/dist/logger/is-unicode-supported.d.mts +6 -0
  68. package/dist/logger/is-unicode-supported.mjs +10 -0
  69. package/dist/types.cjs +26 -25
  70. package/dist/types.d.cts +39 -41
  71. package/dist/types.d.mts +53 -0
  72. package/dist/types.mjs +30 -0
  73. package/dist/utilities/apply-workspace-tokens.cjs +31 -70
  74. package/dist/utilities/apply-workspace-tokens.d.cts +4 -5
  75. package/dist/utilities/{apply-workspace-tokens.d.ts → apply-workspace-tokens.d.mts} +6 -5
  76. package/dist/utilities/apply-workspace-tokens.mjs +37 -0
  77. package/dist/utilities/colors.cjs +91 -74
  78. package/dist/utilities/colors.d.cts +4 -4
  79. package/dist/utilities/{colors.d.ts → colors.d.mts} +6 -4
  80. package/dist/utilities/colors.mjs +97 -0
  81. package/dist/utilities/correct-paths.cjs +166 -196
  82. package/dist/utilities/correct-paths.d.cts +4 -4
  83. package/dist/utilities/{correct-paths.d.ts → correct-paths.d.mts} +6 -4
  84. package/dist/utilities/correct-paths.mjs +190 -0
  85. package/dist/utilities/file-path-utils.cjs +42 -27
  86. package/dist/utilities/file-path-utils.d.cts +15 -14
  87. package/dist/utilities/{file-path-utils.d.ts → file-path-utils.d.mts} +17 -14
  88. package/dist/utilities/file-path-utils.mjs +48 -0
  89. package/dist/utilities/find-up.cjs +12 -18
  90. package/dist/utilities/find-up.d.cts +3 -2
  91. package/dist/utilities/{find-up.d.ts → find-up.d.mts} +5 -2
  92. package/dist/utilities/find-up.mjs +19 -0
  93. package/dist/utilities/find-workspace-root.cjs +64 -69
  94. package/dist/utilities/find-workspace-root.d.cts +3 -2
  95. package/dist/utilities/{find-workspace-root.d.ts → find-workspace-root.d.mts} +5 -2
  96. package/dist/utilities/find-workspace-root.mjs +73 -0
  97. package/dist/utilities/get-default-config.cjs +69 -91
  98. package/dist/utilities/get-default-config.d.cts +4 -4
  99. package/dist/utilities/{get-default-config.d.ts → get-default-config.d.mts} +6 -4
  100. package/dist/utilities/get-default-config.mjs +74 -0
  101. package/dist/utilities/index.cjs +49 -9
  102. package/dist/utilities/index.d.cts +10 -14
  103. package/dist/utilities/index.d.mts +12 -0
  104. package/dist/utilities/index.mjs +13 -0
  105. package/dist/utilities/process-handler.cjs +32 -47
  106. package/dist/utilities/process-handler.d.cts +4 -4
  107. package/dist/utilities/process-handler.d.mts +9 -0
  108. package/dist/utilities/process-handler.mjs +38 -0
  109. package/dist/utilities/run.cjs +62 -36
  110. package/dist/utilities/run.d.cts +5 -6
  111. package/dist/utilities/{run.d.ts → run.d.mts} +7 -6
  112. package/dist/utilities/run.mjs +64 -0
  113. package/dist/utilities/toml.cjs +27 -32
  114. package/dist/utilities/toml.d.cts +148 -147
  115. package/dist/utilities/toml.d.mts +192 -0
  116. package/dist/utilities/toml.mjs +33 -0
  117. package/package.json +105 -157
  118. package/bin/config.js +0 -108
  119. package/dist/config-file/get-config-file.js +0 -83
  120. package/dist/config-file/index.d.ts +0 -3
  121. package/dist/config-file/index.js +0 -1
  122. package/dist/create-storm-config.js +0 -147
  123. package/dist/env/get-env.js +0 -226
  124. package/dist/env/index.d.ts +0 -4
  125. package/dist/env/index.js +0 -2
  126. package/dist/env/set-env.js +0 -386
  127. package/dist/get-config.js +0 -35
  128. package/dist/index.d.ts +0 -28
  129. package/dist/index.js +0 -7
  130. package/dist/logger/chalk.d.ts +0 -34
  131. package/dist/logger/chalk.js +0 -34
  132. package/dist/logger/console-icons.d.ts +0 -8
  133. package/dist/logger/console-icons.js +0 -17
  134. package/dist/logger/console.js +0 -191
  135. package/dist/logger/create-logger.js +0 -27
  136. package/dist/logger/format-timestamp.js +0 -6
  137. package/dist/logger/get-log-level.js +0 -64
  138. package/dist/logger/index.d.ts +0 -10
  139. package/dist/logger/index.js +0 -7
  140. package/dist/logger/is-unicode-supported.d.ts +0 -3
  141. package/dist/logger/is-unicode-supported.js +0 -12
  142. package/dist/types.d.ts +0 -53
  143. package/dist/types.js +0 -28
  144. package/dist/utilities/apply-workspace-tokens.js +0 -76
  145. package/dist/utilities/colors.js +0 -81
  146. package/dist/utilities/correct-paths.js +0 -231
  147. package/dist/utilities/file-path-utils.js +0 -33
  148. package/dist/utilities/find-up.js +0 -23
  149. package/dist/utilities/find-workspace-root.js +0 -77
  150. package/dist/utilities/get-default-config.js +0 -95
  151. package/dist/utilities/index.d.ts +0 -14
  152. package/dist/utilities/index.js +0 -9
  153. package/dist/utilities/process-handler.d.ts +0 -7
  154. package/dist/utilities/process-handler.js +0 -53
  155. package/dist/utilities/run.js +0 -38
  156. package/dist/utilities/toml.d.ts +0 -189
  157. package/dist/utilities/toml.js +0 -42
@@ -1,9 +1,9 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
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
- if (!input) {
4
- return input;
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
- if (!path || path.length === 0) {
17
- return ".";
18
- }
19
- path = normalizeWindowsPath(path);
20
- const isUNCPath = _optionalChain([path, 'optionalAccess', _ => _.match, 'call', _2 => _2(_UNC_REGEX)]);
21
- const isPathAbsolute = isAbsolute(path);
22
- const trailingSeparator = path[path.length - 1] === "/";
23
- path = normalizeString(path, !isPathAbsolute);
24
- if (path.length === 0) {
25
- if (isPathAbsolute) {
26
- return "/";
27
- }
28
- return trailingSeparator ? "./" : ".";
29
- }
30
- if (trailingSeparator) {
31
- path += "/";
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
- let path = "";
46
- for (const seg of segments) {
47
- if (!seg) {
48
- continue;
49
- }
50
- if (path.length > 0) {
51
- const pathTrailing = path[path.length - 1] === "/";
52
- const segLeading = seg[0] === "/";
53
- const both = pathTrailing && segLeading;
54
- if (both) {
55
- path += seg.slice(1);
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
- if (typeof process !== "undefined" && typeof process.cwd === "function") {
67
- return process.cwd().replace(/\\/g, "/");
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
- arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
73
- let resolvedPath = "";
74
- let resolvedAbsolute = false;
75
- for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
76
- const path = index >= 0 ? arguments_[index] : cwd();
77
- if (!path || path.length === 0) {
78
- continue;
79
- }
80
- resolvedPath = `${path}/${resolvedPath}`;
81
- resolvedAbsolute = isAbsolute(path);
82
- }
83
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
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
- let res = "";
91
- let lastSegmentLength = 0;
92
- let lastSlash = -1;
93
- let dots = 0;
94
- let char = null;
95
- for (let index = 0; index <= path.length; ++index) {
96
- if (index < path.length) {
97
- char = path[index];
98
- } else if (char === "/") {
99
- break;
100
- } else {
101
- char = "/";
102
- }
103
- if (char === "/") {
104
- if (lastSlash === index - 1 || dots === 1) {
105
- } else if (dots === 2) {
106
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
107
- if (res.length > 2) {
108
- const lastSlashIndex = res.lastIndexOf("/");
109
- if (lastSlashIndex === -1) {
110
- res = "";
111
- lastSegmentLength = 0;
112
- } else {
113
- res = res.slice(0, lastSlashIndex);
114
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
115
- }
116
- lastSlash = index;
117
- dots = 0;
118
- continue;
119
- } else if (res.length > 0) {
120
- res = "";
121
- lastSegmentLength = 0;
122
- lastSlash = index;
123
- dots = 0;
124
- continue;
125
- }
126
- }
127
- if (allowAboveRoot) {
128
- res += res.length > 0 ? "/.." : "..";
129
- lastSegmentLength = 2;
130
- }
131
- } else {
132
- if (res.length > 0) {
133
- res += `/${path.slice(lastSlash + 1, index)}`;
134
- } else {
135
- res = path.slice(lastSlash + 1, index);
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
- return _IS_ABSOLUTE_RE.test(p);
127
+ return _IS_ABSOLUTE_RE.test(p);
151
128
  };
152
129
  const toNamespacedPath = function(p) {
153
- return normalizeWindowsPath(p);
130
+ return normalizeWindowsPath(p);
154
131
  };
155
132
  const extname = function(p) {
156
- if (p === "..") return "";
157
- const match = _EXTNAME_RE.exec(normalizeWindowsPath(p));
158
- return match && match[1] || "";
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
- const _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/");
162
- const _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
163
- if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0]) {
164
- return _to.join("/");
165
- }
166
- const _fromCopy = [..._from];
167
- for (const segment of _fromCopy) {
168
- if (_to[0] !== segment) {
169
- break;
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
- const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
178
- if (segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0])) {
179
- segments[0] += "/";
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
- const ext = p.ext ? p.ext.startsWith(".") ? p.ext : `.${p.ext}` : "";
185
- const segments = [p.root, p.dir, _nullishCoalesce(p.base, () => ( (_nullishCoalesce(p.name, () => ( ""))) + ext))].filter(
186
- Boolean
187
- );
188
- return normalizeWindowsPath(
189
- p.root ? resolve(...segments) : segments.join("/")
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
- const segments = normalizeWindowsPath(p).split("/");
194
- let lastSegment = "";
195
- for (let i = segments.length - 1; i >= 0; i--) {
196
- const val = segments[i];
197
- if (val) {
198
- lastSegment = val;
199
- break;
200
- }
201
- }
202
- return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
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
- const root = _optionalChain([_PATH_ROOT_RE, 'access', _3 => _3.exec, 'call', _4 => _4(p), 'optionalAccess', _5 => _5[0], 'optionalAccess', _6 => _6.replace, 'call', _7 => _7(/\\/g, "/")]) || "";
206
- const base = basename(p);
207
- const extension = extname(base);
208
- return {
209
- root,
210
- dir: dirname(p),
211
- base,
212
- ext: extension,
213
- name: base.slice(0, base.length - extension.length)
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 'node:path';
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 path from 'node:path';
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 };