keep-a-changelog 2.0.1 → 2.2.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/CHANGELOG.md +28 -2
- package/README.md +21 -6
- package/esm/_dnt.polyfills.js +15 -0
- package/esm/bin.js +9 -4
- package/esm/deps/deno.land/std@0.173.0/_util/asserts.js +21 -0
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/_util/os.js +4 -1
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/flags/mod.js +145 -36
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_constants.js +1 -0
- package/esm/deps/deno.land/std@0.173.0/path/_interface.js +3 -0
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_util.js +1 -0
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/common.js +1 -1
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/glob.js +1 -1
- package/esm/deps/deno.land/std@0.173.0/path/mod.js +32 -0
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/posix.js +23 -16
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/separator.js +1 -1
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/win32.js +20 -15
- package/esm/deps/{deno_land/x/semver_v1.4.0 → deno.land/std@0.173.0/semver}/mod.js +227 -334
- package/esm/deps/{deno_land/std_0.51.0 → deno.land/std@0.51.0}/fs/eol.js +0 -0
- package/esm/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/ini.js +1 -1
- package/esm/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/mod.js +0 -0
- package/esm/mod.js +1 -0
- package/esm/src/Change.js +15 -15
- package/esm/src/Changelog.js +9 -1
- package/esm/src/Release.js +21 -4
- package/esm/src/deps.js +1 -1
- package/esm/src/parser.js +24 -5
- package/esm/test/changelog.custom.type.md +0 -1
- package/esm/test/changelog.expected.linted.md +208 -0
- package/esm/test/changelog.expected.md +6 -4
- package/esm/test/changelog.md +7 -3
- package/esm/test/empty.expected.md +0 -1
- package/package.json +13 -8
- package/script/_dnt.polyfills.js +16 -0
- package/script/_dnt.shims.js +66 -0
- package/script/bin.js +144 -0
- package/script/deps/deno.land/std@0.173.0/_util/asserts.js +27 -0
- package/script/deps/deno.land/std@0.173.0/_util/os.js +44 -0
- package/script/deps/deno.land/std@0.173.0/flags/mod.js +368 -0
- package/script/deps/deno.land/std@0.173.0/path/_constants.js +49 -0
- package/script/deps/deno.land/std@0.173.0/path/_interface.js +4 -0
- package/script/deps/deno.land/std@0.173.0/path/_util.js +125 -0
- package/script/deps/deno.land/std@0.173.0/path/common.js +40 -0
- package/script/deps/deno.land/std@0.173.0/path/glob.js +391 -0
- package/script/deps/deno.land/std@0.173.0/path/mod.js +63 -0
- package/script/deps/deno.land/std@0.173.0/path/posix.js +539 -0
- package/script/deps/deno.land/std@0.173.0/path/separator.js +8 -0
- package/script/deps/deno.land/std@0.173.0/path/win32.js +1007 -0
- package/script/deps/deno.land/std@0.173.0/semver/mod.js +1458 -0
- package/script/deps/deno.land/std@0.51.0/fs/eol.js +34 -0
- package/script/deps/deno.land/x/ini@v2.1.0/ini.js +256 -0
- package/script/deps/deno.land/x/ini@v2.1.0/mod.js +17 -0
- package/script/mod.js +15 -0
- package/{umd → script}/package.json +0 -0
- package/script/src/Change.js +51 -0
- package/script/src/Changelog.js +148 -0
- package/script/src/Release.js +227 -0
- package/script/src/deps.js +9 -0
- package/script/src/parser.js +184 -0
- package/{umd → script}/test/changelog.custom.type.md +0 -1
- package/script/test/changelog.expected.linted.md +208 -0
- package/{umd → script}/test/changelog.expected.md +6 -4
- package/{umd → script}/test/changelog.md +7 -3
- package/{umd → script}/test/empty.expected.md +0 -1
- package/types/_dnt.polyfills.d.ts +11 -0
- package/types/_dnt.shims.d.ts +0 -4
- package/types/bin.d.ts +1 -1
- package/types/deps/deno.land/std@0.173.0/_util/asserts.d.ts +10 -0
- package/types/deps/deno.land/std@0.173.0/_util/os.d.ts +4 -0
- package/types/deps/deno.land/std@0.173.0/flags/mod.d.ts +166 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_constants.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_interface.d.ts +1 -1
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_util.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/common.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/glob.d.ts +10 -5
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/mod.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/posix.d.ts +9 -5
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/separator.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/win32.d.ts +7 -5
- package/types/deps/deno.land/std@0.173.0/semver/mod.d.ts +398 -0
- package/types/deps/{deno_land/std_0.51.0 → deno.land/std@0.51.0}/fs/eol.d.ts +0 -0
- package/types/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/ini.d.ts +0 -0
- package/types/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/mod.d.ts +0 -0
- package/types/mod.d.ts +1 -0
- package/types/src/Changelog.d.ts +1 -0
- package/types/src/Release.d.ts +2 -0
- package/types/src/deps.d.ts +1 -1
- package/esm/deps/deno_land/std_0.120.0/_util/assert.js +0 -13
- package/esm/deps/deno_land/std_0.120.0/path/_interface.js +0 -3
- package/esm/deps/deno_land/std_0.120.0/path/mod.js +0 -14
- package/types/deps/deno_land/std_0.120.0/_util/assert.d.ts +0 -5
- package/types/deps/deno_land/std_0.120.0/_util/os.d.ts +0 -3
- package/types/deps/deno_land/std_0.120.0/flags/mod.d.ts +0 -50
- package/types/deps/deno_land/x/semver_v1.4.0/mod.d.ts +0 -116
- package/umd/_dnt.shims.js +0 -76
- package/umd/bin.js +0 -145
- package/umd/deps/deno_land/std_0.120.0/_util/assert.js +0 -28
- package/umd/deps/deno_land/std_0.120.0/_util/os.js +0 -47
- package/umd/deps/deno_land/std_0.120.0/flags/mod.js +0 -269
- package/umd/deps/deno_land/std_0.120.0/path/_constants.js +0 -58
- package/umd/deps/deno_land/std_0.120.0/path/_interface.js +0 -14
- package/umd/deps/deno_land/std_0.120.0/path/_util.js +0 -134
- package/umd/deps/deno_land/std_0.120.0/path/common.js +0 -50
- package/umd/deps/deno_land/std_0.120.0/path/glob.js +0 -397
- package/umd/deps/deno_land/std_0.120.0/path/mod.js +0 -51
- package/umd/deps/deno_land/std_0.120.0/path/posix.js +0 -538
- package/umd/deps/deno_land/std_0.120.0/path/separator.js +0 -18
- package/umd/deps/deno_land/std_0.120.0/path/win32.js +0 -1008
- package/umd/deps/deno_land/std_0.51.0/fs/eol.js +0 -44
- package/umd/deps/deno_land/x/ini_v2.1.0/ini.js +0 -262
- package/umd/deps/deno_land/x/ini_v2.1.0/mod.js +0 -23
- package/umd/deps/deno_land/x/semver_v1.4.0/mod.js +0 -1578
- package/umd/mod.js +0 -24
- package/umd/src/Change.js +0 -61
- package/umd/src/Changelog.js +0 -150
- package/umd/src/Release.js +0 -220
- package/umd/src/deps.js +0 -19
- package/umd/src/parser.js +0 -175
|
@@ -0,0 +1,1007 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.toFileUrl = exports.fromFileUrl = exports.parse = exports.format = exports.extname = exports.basename = exports.dirname = exports.toNamespacedPath = exports.relative = exports.join = exports.isAbsolute = exports.normalize = exports.resolve = exports.delimiter = exports.sep = void 0;
|
|
27
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
28
|
+
// Copyright the Browserify authors. MIT License.
|
|
29
|
+
// Ported from https://github.com/browserify/path-browserify/
|
|
30
|
+
// This module is browser compatible.
|
|
31
|
+
const dntShim = __importStar(require("../../../../_dnt.shims.js"));
|
|
32
|
+
const _constants_js_1 = require("./_constants.js");
|
|
33
|
+
const _util_js_1 = require("./_util.js");
|
|
34
|
+
const asserts_js_1 = require("../_util/asserts.js");
|
|
35
|
+
exports.sep = "\\";
|
|
36
|
+
exports.delimiter = ";";
|
|
37
|
+
/**
|
|
38
|
+
* Resolves path segments into a `path`
|
|
39
|
+
* @param pathSegments to process to path
|
|
40
|
+
*/
|
|
41
|
+
function resolve(...pathSegments) {
|
|
42
|
+
let resolvedDevice = "";
|
|
43
|
+
let resolvedTail = "";
|
|
44
|
+
let resolvedAbsolute = false;
|
|
45
|
+
for (let i = pathSegments.length - 1; i >= -1; i--) {
|
|
46
|
+
let path;
|
|
47
|
+
// deno-lint-ignore no-explicit-any
|
|
48
|
+
const { Deno } = dntShim.dntGlobalThis;
|
|
49
|
+
if (i >= 0) {
|
|
50
|
+
path = pathSegments[i];
|
|
51
|
+
}
|
|
52
|
+
else if (!resolvedDevice) {
|
|
53
|
+
if (typeof Deno?.cwd !== "function") {
|
|
54
|
+
throw new TypeError("Resolved a drive-letter-less path without a CWD.");
|
|
55
|
+
}
|
|
56
|
+
path = Deno.cwd();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
if (typeof Deno?.env?.get !== "function" || typeof Deno?.cwd !== "function") {
|
|
60
|
+
throw new TypeError("Resolved a relative path without a CWD.");
|
|
61
|
+
}
|
|
62
|
+
path = Deno.cwd();
|
|
63
|
+
// Verify that a cwd was found and that it actually points
|
|
64
|
+
// to our drive. If not, default to the drive's root.
|
|
65
|
+
if (path === undefined ||
|
|
66
|
+
path.slice(0, 3).toLowerCase() !== `${resolvedDevice.toLowerCase()}\\`) {
|
|
67
|
+
path = `${resolvedDevice}\\`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
(0, _util_js_1.assertPath)(path);
|
|
71
|
+
const len = path.length;
|
|
72
|
+
// Skip empty entries
|
|
73
|
+
if (len === 0)
|
|
74
|
+
continue;
|
|
75
|
+
let rootEnd = 0;
|
|
76
|
+
let device = "";
|
|
77
|
+
let isAbsolute = false;
|
|
78
|
+
const code = path.charCodeAt(0);
|
|
79
|
+
// Try to match a root
|
|
80
|
+
if (len > 1) {
|
|
81
|
+
if ((0, _util_js_1.isPathSeparator)(code)) {
|
|
82
|
+
// Possible UNC root
|
|
83
|
+
// If we started with a separator, we know we at least have an
|
|
84
|
+
// absolute path of some kind (UNC or otherwise)
|
|
85
|
+
isAbsolute = true;
|
|
86
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(1))) {
|
|
87
|
+
// Matched double path separator at beginning
|
|
88
|
+
let j = 2;
|
|
89
|
+
let last = j;
|
|
90
|
+
// Match 1 or more non-path separators
|
|
91
|
+
for (; j < len; ++j) {
|
|
92
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (j < len && j !== last) {
|
|
96
|
+
const firstPart = path.slice(last, j);
|
|
97
|
+
// Matched!
|
|
98
|
+
last = j;
|
|
99
|
+
// Match 1 or more path separators
|
|
100
|
+
for (; j < len; ++j) {
|
|
101
|
+
if (!(0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (j < len && j !== last) {
|
|
105
|
+
// Matched!
|
|
106
|
+
last = j;
|
|
107
|
+
// Match 1 or more non-path separators
|
|
108
|
+
for (; j < len; ++j) {
|
|
109
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
if (j === len) {
|
|
113
|
+
// We matched a UNC root only
|
|
114
|
+
device = `\\\\${firstPart}\\${path.slice(last)}`;
|
|
115
|
+
rootEnd = j;
|
|
116
|
+
}
|
|
117
|
+
else if (j !== last) {
|
|
118
|
+
// We matched a UNC root with leftovers
|
|
119
|
+
device = `\\\\${firstPart}\\${path.slice(last, j)}`;
|
|
120
|
+
rootEnd = j;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
rootEnd = 1;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if ((0, _util_js_1.isWindowsDeviceRoot)(code)) {
|
|
130
|
+
// Possible device root
|
|
131
|
+
if (path.charCodeAt(1) === _constants_js_1.CHAR_COLON) {
|
|
132
|
+
device = path.slice(0, 2);
|
|
133
|
+
rootEnd = 2;
|
|
134
|
+
if (len > 2) {
|
|
135
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(2))) {
|
|
136
|
+
// Treat separator following drive name as an absolute path
|
|
137
|
+
// indicator
|
|
138
|
+
isAbsolute = true;
|
|
139
|
+
rootEnd = 3;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else if ((0, _util_js_1.isPathSeparator)(code)) {
|
|
146
|
+
// `path` contains just a path separator
|
|
147
|
+
rootEnd = 1;
|
|
148
|
+
isAbsolute = true;
|
|
149
|
+
}
|
|
150
|
+
if (device.length > 0 &&
|
|
151
|
+
resolvedDevice.length > 0 &&
|
|
152
|
+
device.toLowerCase() !== resolvedDevice.toLowerCase()) {
|
|
153
|
+
// This path points to another device so it is not applicable
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (resolvedDevice.length === 0 && device.length > 0) {
|
|
157
|
+
resolvedDevice = device;
|
|
158
|
+
}
|
|
159
|
+
if (!resolvedAbsolute) {
|
|
160
|
+
resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
|
|
161
|
+
resolvedAbsolute = isAbsolute;
|
|
162
|
+
}
|
|
163
|
+
if (resolvedAbsolute && resolvedDevice.length > 0)
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
// At this point the path should be resolved to a full absolute path,
|
|
167
|
+
// but handle relative paths to be safe (might happen when process.cwd()
|
|
168
|
+
// fails)
|
|
169
|
+
// Normalize the tail path
|
|
170
|
+
resolvedTail = (0, _util_js_1.normalizeString)(resolvedTail, !resolvedAbsolute, "\\", _util_js_1.isPathSeparator);
|
|
171
|
+
return resolvedDevice + (resolvedAbsolute ? "\\" : "") + resolvedTail || ".";
|
|
172
|
+
}
|
|
173
|
+
exports.resolve = resolve;
|
|
174
|
+
/**
|
|
175
|
+
* Normalizes a `path`
|
|
176
|
+
* @param path to normalize
|
|
177
|
+
*/
|
|
178
|
+
function normalize(path) {
|
|
179
|
+
(0, _util_js_1.assertPath)(path);
|
|
180
|
+
const len = path.length;
|
|
181
|
+
if (len === 0)
|
|
182
|
+
return ".";
|
|
183
|
+
let rootEnd = 0;
|
|
184
|
+
let device;
|
|
185
|
+
let isAbsolute = false;
|
|
186
|
+
const code = path.charCodeAt(0);
|
|
187
|
+
// Try to match a root
|
|
188
|
+
if (len > 1) {
|
|
189
|
+
if ((0, _util_js_1.isPathSeparator)(code)) {
|
|
190
|
+
// Possible UNC root
|
|
191
|
+
// If we started with a separator, we know we at least have an absolute
|
|
192
|
+
// path of some kind (UNC or otherwise)
|
|
193
|
+
isAbsolute = true;
|
|
194
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(1))) {
|
|
195
|
+
// Matched double path separator at beginning
|
|
196
|
+
let j = 2;
|
|
197
|
+
let last = j;
|
|
198
|
+
// Match 1 or more non-path separators
|
|
199
|
+
for (; j < len; ++j) {
|
|
200
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
if (j < len && j !== last) {
|
|
204
|
+
const firstPart = path.slice(last, j);
|
|
205
|
+
// Matched!
|
|
206
|
+
last = j;
|
|
207
|
+
// Match 1 or more path separators
|
|
208
|
+
for (; j < len; ++j) {
|
|
209
|
+
if (!(0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
if (j < len && j !== last) {
|
|
213
|
+
// Matched!
|
|
214
|
+
last = j;
|
|
215
|
+
// Match 1 or more non-path separators
|
|
216
|
+
for (; j < len; ++j) {
|
|
217
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
if (j === len) {
|
|
221
|
+
// We matched a UNC root only
|
|
222
|
+
// Return the normalized version of the UNC root since there
|
|
223
|
+
// is nothing left to process
|
|
224
|
+
return `\\\\${firstPart}\\${path.slice(last)}\\`;
|
|
225
|
+
}
|
|
226
|
+
else if (j !== last) {
|
|
227
|
+
// We matched a UNC root with leftovers
|
|
228
|
+
device = `\\\\${firstPart}\\${path.slice(last, j)}`;
|
|
229
|
+
rootEnd = j;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
rootEnd = 1;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else if ((0, _util_js_1.isWindowsDeviceRoot)(code)) {
|
|
239
|
+
// Possible device root
|
|
240
|
+
if (path.charCodeAt(1) === _constants_js_1.CHAR_COLON) {
|
|
241
|
+
device = path.slice(0, 2);
|
|
242
|
+
rootEnd = 2;
|
|
243
|
+
if (len > 2) {
|
|
244
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(2))) {
|
|
245
|
+
// Treat separator following drive name as an absolute path
|
|
246
|
+
// indicator
|
|
247
|
+
isAbsolute = true;
|
|
248
|
+
rootEnd = 3;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else if ((0, _util_js_1.isPathSeparator)(code)) {
|
|
255
|
+
// `path` contains just a path separator, exit early to avoid unnecessary
|
|
256
|
+
// work
|
|
257
|
+
return "\\";
|
|
258
|
+
}
|
|
259
|
+
let tail;
|
|
260
|
+
if (rootEnd < len) {
|
|
261
|
+
tail = (0, _util_js_1.normalizeString)(path.slice(rootEnd), !isAbsolute, "\\", _util_js_1.isPathSeparator);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
tail = "";
|
|
265
|
+
}
|
|
266
|
+
if (tail.length === 0 && !isAbsolute)
|
|
267
|
+
tail = ".";
|
|
268
|
+
if (tail.length > 0 && (0, _util_js_1.isPathSeparator)(path.charCodeAt(len - 1))) {
|
|
269
|
+
tail += "\\";
|
|
270
|
+
}
|
|
271
|
+
if (device === undefined) {
|
|
272
|
+
if (isAbsolute) {
|
|
273
|
+
if (tail.length > 0)
|
|
274
|
+
return `\\${tail}`;
|
|
275
|
+
else
|
|
276
|
+
return "\\";
|
|
277
|
+
}
|
|
278
|
+
else if (tail.length > 0) {
|
|
279
|
+
return tail;
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
return "";
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else if (isAbsolute) {
|
|
286
|
+
if (tail.length > 0)
|
|
287
|
+
return `${device}\\${tail}`;
|
|
288
|
+
else
|
|
289
|
+
return `${device}\\`;
|
|
290
|
+
}
|
|
291
|
+
else if (tail.length > 0) {
|
|
292
|
+
return device + tail;
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
return device;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
exports.normalize = normalize;
|
|
299
|
+
/**
|
|
300
|
+
* Verifies whether path is absolute
|
|
301
|
+
* @param path to verify
|
|
302
|
+
*/
|
|
303
|
+
function isAbsolute(path) {
|
|
304
|
+
(0, _util_js_1.assertPath)(path);
|
|
305
|
+
const len = path.length;
|
|
306
|
+
if (len === 0)
|
|
307
|
+
return false;
|
|
308
|
+
const code = path.charCodeAt(0);
|
|
309
|
+
if ((0, _util_js_1.isPathSeparator)(code)) {
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
else if ((0, _util_js_1.isWindowsDeviceRoot)(code)) {
|
|
313
|
+
// Possible device root
|
|
314
|
+
if (len > 2 && path.charCodeAt(1) === _constants_js_1.CHAR_COLON) {
|
|
315
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(2)))
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
exports.isAbsolute = isAbsolute;
|
|
322
|
+
/**
|
|
323
|
+
* Join all given a sequence of `paths`,then normalizes the resulting path.
|
|
324
|
+
* @param paths to be joined and normalized
|
|
325
|
+
*/
|
|
326
|
+
function join(...paths) {
|
|
327
|
+
const pathsCount = paths.length;
|
|
328
|
+
if (pathsCount === 0)
|
|
329
|
+
return ".";
|
|
330
|
+
let joined;
|
|
331
|
+
let firstPart = null;
|
|
332
|
+
for (let i = 0; i < pathsCount; ++i) {
|
|
333
|
+
const path = paths[i];
|
|
334
|
+
(0, _util_js_1.assertPath)(path);
|
|
335
|
+
if (path.length > 0) {
|
|
336
|
+
if (joined === undefined)
|
|
337
|
+
joined = firstPart = path;
|
|
338
|
+
else
|
|
339
|
+
joined += `\\${path}`;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (joined === undefined)
|
|
343
|
+
return ".";
|
|
344
|
+
// Make sure that the joined path doesn't start with two slashes, because
|
|
345
|
+
// normalize() will mistake it for an UNC path then.
|
|
346
|
+
//
|
|
347
|
+
// This step is skipped when it is very clear that the user actually
|
|
348
|
+
// intended to point at an UNC path. This is assumed when the first
|
|
349
|
+
// non-empty string arguments starts with exactly two slashes followed by
|
|
350
|
+
// at least one more non-slash character.
|
|
351
|
+
//
|
|
352
|
+
// Note that for normalize() to treat a path as an UNC path it needs to
|
|
353
|
+
// have at least 2 components, so we don't filter for that here.
|
|
354
|
+
// This means that the user can use join to construct UNC paths from
|
|
355
|
+
// a server name and a share name; for example:
|
|
356
|
+
// path.join('//server', 'share') -> '\\\\server\\share\\')
|
|
357
|
+
let needsReplace = true;
|
|
358
|
+
let slashCount = 0;
|
|
359
|
+
(0, asserts_js_1.assert)(firstPart != null);
|
|
360
|
+
if ((0, _util_js_1.isPathSeparator)(firstPart.charCodeAt(0))) {
|
|
361
|
+
++slashCount;
|
|
362
|
+
const firstLen = firstPart.length;
|
|
363
|
+
if (firstLen > 1) {
|
|
364
|
+
if ((0, _util_js_1.isPathSeparator)(firstPart.charCodeAt(1))) {
|
|
365
|
+
++slashCount;
|
|
366
|
+
if (firstLen > 2) {
|
|
367
|
+
if ((0, _util_js_1.isPathSeparator)(firstPart.charCodeAt(2)))
|
|
368
|
+
++slashCount;
|
|
369
|
+
else {
|
|
370
|
+
// We matched a UNC path in the first part
|
|
371
|
+
needsReplace = false;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (needsReplace) {
|
|
378
|
+
// Find any more consecutive slashes we need to replace
|
|
379
|
+
for (; slashCount < joined.length; ++slashCount) {
|
|
380
|
+
if (!(0, _util_js_1.isPathSeparator)(joined.charCodeAt(slashCount)))
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
// Replace the slashes if needed
|
|
384
|
+
if (slashCount >= 2)
|
|
385
|
+
joined = `\\${joined.slice(slashCount)}`;
|
|
386
|
+
}
|
|
387
|
+
return normalize(joined);
|
|
388
|
+
}
|
|
389
|
+
exports.join = join;
|
|
390
|
+
/**
|
|
391
|
+
* It will solve the relative path from `from` to `to`, for instance:
|
|
392
|
+
* from = 'C:\\orandea\\test\\aaa'
|
|
393
|
+
* to = 'C:\\orandea\\impl\\bbb'
|
|
394
|
+
* The output of the function should be: '..\\..\\impl\\bbb'
|
|
395
|
+
* @param from relative path
|
|
396
|
+
* @param to relative path
|
|
397
|
+
*/
|
|
398
|
+
function relative(from, to) {
|
|
399
|
+
(0, _util_js_1.assertPath)(from);
|
|
400
|
+
(0, _util_js_1.assertPath)(to);
|
|
401
|
+
if (from === to)
|
|
402
|
+
return "";
|
|
403
|
+
const fromOrig = resolve(from);
|
|
404
|
+
const toOrig = resolve(to);
|
|
405
|
+
if (fromOrig === toOrig)
|
|
406
|
+
return "";
|
|
407
|
+
from = fromOrig.toLowerCase();
|
|
408
|
+
to = toOrig.toLowerCase();
|
|
409
|
+
if (from === to)
|
|
410
|
+
return "";
|
|
411
|
+
// Trim any leading backslashes
|
|
412
|
+
let fromStart = 0;
|
|
413
|
+
let fromEnd = from.length;
|
|
414
|
+
for (; fromStart < fromEnd; ++fromStart) {
|
|
415
|
+
if (from.charCodeAt(fromStart) !== _constants_js_1.CHAR_BACKWARD_SLASH)
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
// Trim trailing backslashes (applicable to UNC paths only)
|
|
419
|
+
for (; fromEnd - 1 > fromStart; --fromEnd) {
|
|
420
|
+
if (from.charCodeAt(fromEnd - 1) !== _constants_js_1.CHAR_BACKWARD_SLASH)
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
const fromLen = fromEnd - fromStart;
|
|
424
|
+
// Trim any leading backslashes
|
|
425
|
+
let toStart = 0;
|
|
426
|
+
let toEnd = to.length;
|
|
427
|
+
for (; toStart < toEnd; ++toStart) {
|
|
428
|
+
if (to.charCodeAt(toStart) !== _constants_js_1.CHAR_BACKWARD_SLASH)
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
// Trim trailing backslashes (applicable to UNC paths only)
|
|
432
|
+
for (; toEnd - 1 > toStart; --toEnd) {
|
|
433
|
+
if (to.charCodeAt(toEnd - 1) !== _constants_js_1.CHAR_BACKWARD_SLASH)
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
const toLen = toEnd - toStart;
|
|
437
|
+
// Compare paths to find the longest common path from root
|
|
438
|
+
const length = fromLen < toLen ? fromLen : toLen;
|
|
439
|
+
let lastCommonSep = -1;
|
|
440
|
+
let i = 0;
|
|
441
|
+
for (; i <= length; ++i) {
|
|
442
|
+
if (i === length) {
|
|
443
|
+
if (toLen > length) {
|
|
444
|
+
if (to.charCodeAt(toStart + i) === _constants_js_1.CHAR_BACKWARD_SLASH) {
|
|
445
|
+
// We get here if `from` is the exact base path for `to`.
|
|
446
|
+
// For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
|
|
447
|
+
return toOrig.slice(toStart + i + 1);
|
|
448
|
+
}
|
|
449
|
+
else if (i === 2) {
|
|
450
|
+
// We get here if `from` is the device root.
|
|
451
|
+
// For example: from='C:\\'; to='C:\\foo'
|
|
452
|
+
return toOrig.slice(toStart + i);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (fromLen > length) {
|
|
456
|
+
if (from.charCodeAt(fromStart + i) === _constants_js_1.CHAR_BACKWARD_SLASH) {
|
|
457
|
+
// We get here if `to` is the exact base path for `from`.
|
|
458
|
+
// For example: from='C:\\foo\\bar'; to='C:\\foo'
|
|
459
|
+
lastCommonSep = i;
|
|
460
|
+
}
|
|
461
|
+
else if (i === 2) {
|
|
462
|
+
// We get here if `to` is the device root.
|
|
463
|
+
// For example: from='C:\\foo\\bar'; to='C:\\'
|
|
464
|
+
lastCommonSep = 3;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
const fromCode = from.charCodeAt(fromStart + i);
|
|
470
|
+
const toCode = to.charCodeAt(toStart + i);
|
|
471
|
+
if (fromCode !== toCode)
|
|
472
|
+
break;
|
|
473
|
+
else if (fromCode === _constants_js_1.CHAR_BACKWARD_SLASH)
|
|
474
|
+
lastCommonSep = i;
|
|
475
|
+
}
|
|
476
|
+
// We found a mismatch before the first common path separator was seen, so
|
|
477
|
+
// return the original `to`.
|
|
478
|
+
if (i !== length && lastCommonSep === -1) {
|
|
479
|
+
return toOrig;
|
|
480
|
+
}
|
|
481
|
+
let out = "";
|
|
482
|
+
if (lastCommonSep === -1)
|
|
483
|
+
lastCommonSep = 0;
|
|
484
|
+
// Generate the relative path based on the path difference between `to` and
|
|
485
|
+
// `from`
|
|
486
|
+
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
487
|
+
if (i === fromEnd || from.charCodeAt(i) === _constants_js_1.CHAR_BACKWARD_SLASH) {
|
|
488
|
+
if (out.length === 0)
|
|
489
|
+
out += "..";
|
|
490
|
+
else
|
|
491
|
+
out += "\\..";
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
// Lastly, append the rest of the destination (`to`) path that comes after
|
|
495
|
+
// the common path parts
|
|
496
|
+
if (out.length > 0) {
|
|
497
|
+
return out + toOrig.slice(toStart + lastCommonSep, toEnd);
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
toStart += lastCommonSep;
|
|
501
|
+
if (toOrig.charCodeAt(toStart) === _constants_js_1.CHAR_BACKWARD_SLASH)
|
|
502
|
+
++toStart;
|
|
503
|
+
return toOrig.slice(toStart, toEnd);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
exports.relative = relative;
|
|
507
|
+
/**
|
|
508
|
+
* Resolves path to a namespace path
|
|
509
|
+
* @param path to resolve to namespace
|
|
510
|
+
*/
|
|
511
|
+
function toNamespacedPath(path) {
|
|
512
|
+
// Note: this will *probably* throw somewhere.
|
|
513
|
+
if (typeof path !== "string")
|
|
514
|
+
return path;
|
|
515
|
+
if (path.length === 0)
|
|
516
|
+
return "";
|
|
517
|
+
const resolvedPath = resolve(path);
|
|
518
|
+
if (resolvedPath.length >= 3) {
|
|
519
|
+
if (resolvedPath.charCodeAt(0) === _constants_js_1.CHAR_BACKWARD_SLASH) {
|
|
520
|
+
// Possible UNC root
|
|
521
|
+
if (resolvedPath.charCodeAt(1) === _constants_js_1.CHAR_BACKWARD_SLASH) {
|
|
522
|
+
const code = resolvedPath.charCodeAt(2);
|
|
523
|
+
if (code !== _constants_js_1.CHAR_QUESTION_MARK && code !== _constants_js_1.CHAR_DOT) {
|
|
524
|
+
// Matched non-long UNC root, convert the path to a long UNC path
|
|
525
|
+
return `\\\\?\\UNC\\${resolvedPath.slice(2)}`;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
else if ((0, _util_js_1.isWindowsDeviceRoot)(resolvedPath.charCodeAt(0))) {
|
|
530
|
+
// Possible device root
|
|
531
|
+
if (resolvedPath.charCodeAt(1) === _constants_js_1.CHAR_COLON &&
|
|
532
|
+
resolvedPath.charCodeAt(2) === _constants_js_1.CHAR_BACKWARD_SLASH) {
|
|
533
|
+
// Matched device root, convert the path to a long UNC path
|
|
534
|
+
return `\\\\?\\${resolvedPath}`;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return path;
|
|
539
|
+
}
|
|
540
|
+
exports.toNamespacedPath = toNamespacedPath;
|
|
541
|
+
/**
|
|
542
|
+
* Return the directory path of a `path`.
|
|
543
|
+
* @param path to determine the directory path for
|
|
544
|
+
*/
|
|
545
|
+
function dirname(path) {
|
|
546
|
+
(0, _util_js_1.assertPath)(path);
|
|
547
|
+
const len = path.length;
|
|
548
|
+
if (len === 0)
|
|
549
|
+
return ".";
|
|
550
|
+
let rootEnd = -1;
|
|
551
|
+
let end = -1;
|
|
552
|
+
let matchedSlash = true;
|
|
553
|
+
let offset = 0;
|
|
554
|
+
const code = path.charCodeAt(0);
|
|
555
|
+
// Try to match a root
|
|
556
|
+
if (len > 1) {
|
|
557
|
+
if ((0, _util_js_1.isPathSeparator)(code)) {
|
|
558
|
+
// Possible UNC root
|
|
559
|
+
rootEnd = offset = 1;
|
|
560
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(1))) {
|
|
561
|
+
// Matched double path separator at beginning
|
|
562
|
+
let j = 2;
|
|
563
|
+
let last = j;
|
|
564
|
+
// Match 1 or more non-path separators
|
|
565
|
+
for (; j < len; ++j) {
|
|
566
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
if (j < len && j !== last) {
|
|
570
|
+
// Matched!
|
|
571
|
+
last = j;
|
|
572
|
+
// Match 1 or more path separators
|
|
573
|
+
for (; j < len; ++j) {
|
|
574
|
+
if (!(0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
if (j < len && j !== last) {
|
|
578
|
+
// Matched!
|
|
579
|
+
last = j;
|
|
580
|
+
// Match 1 or more non-path separators
|
|
581
|
+
for (; j < len; ++j) {
|
|
582
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
585
|
+
if (j === len) {
|
|
586
|
+
// We matched a UNC root only
|
|
587
|
+
return path;
|
|
588
|
+
}
|
|
589
|
+
if (j !== last) {
|
|
590
|
+
// We matched a UNC root with leftovers
|
|
591
|
+
// Offset by 1 to include the separator after the UNC root to
|
|
592
|
+
// treat it as a "normal root" on top of a (UNC) root
|
|
593
|
+
rootEnd = offset = j + 1;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
else if ((0, _util_js_1.isWindowsDeviceRoot)(code)) {
|
|
600
|
+
// Possible device root
|
|
601
|
+
if (path.charCodeAt(1) === _constants_js_1.CHAR_COLON) {
|
|
602
|
+
rootEnd = offset = 2;
|
|
603
|
+
if (len > 2) {
|
|
604
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(2)))
|
|
605
|
+
rootEnd = offset = 3;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
else if ((0, _util_js_1.isPathSeparator)(code)) {
|
|
611
|
+
// `path` contains just a path separator, exit early to avoid
|
|
612
|
+
// unnecessary work
|
|
613
|
+
return path;
|
|
614
|
+
}
|
|
615
|
+
for (let i = len - 1; i >= offset; --i) {
|
|
616
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(i))) {
|
|
617
|
+
if (!matchedSlash) {
|
|
618
|
+
end = i;
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
// We saw the first non-path separator
|
|
624
|
+
matchedSlash = false;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (end === -1) {
|
|
628
|
+
if (rootEnd === -1)
|
|
629
|
+
return ".";
|
|
630
|
+
else
|
|
631
|
+
end = rootEnd;
|
|
632
|
+
}
|
|
633
|
+
return path.slice(0, end);
|
|
634
|
+
}
|
|
635
|
+
exports.dirname = dirname;
|
|
636
|
+
/**
|
|
637
|
+
* Return the last portion of a `path`. Trailing directory separators are ignored.
|
|
638
|
+
* @param path to process
|
|
639
|
+
* @param ext of path directory
|
|
640
|
+
*/
|
|
641
|
+
function basename(path, ext = "") {
|
|
642
|
+
if (ext !== undefined && typeof ext !== "string") {
|
|
643
|
+
throw new TypeError('"ext" argument must be a string');
|
|
644
|
+
}
|
|
645
|
+
(0, _util_js_1.assertPath)(path);
|
|
646
|
+
let start = 0;
|
|
647
|
+
let end = -1;
|
|
648
|
+
let matchedSlash = true;
|
|
649
|
+
let i;
|
|
650
|
+
// Check for a drive letter prefix so as not to mistake the following
|
|
651
|
+
// path separator as an extra separator at the end of the path that can be
|
|
652
|
+
// disregarded
|
|
653
|
+
if (path.length >= 2) {
|
|
654
|
+
const drive = path.charCodeAt(0);
|
|
655
|
+
if ((0, _util_js_1.isWindowsDeviceRoot)(drive)) {
|
|
656
|
+
if (path.charCodeAt(1) === _constants_js_1.CHAR_COLON)
|
|
657
|
+
start = 2;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
|
|
661
|
+
if (ext.length === path.length && ext === path)
|
|
662
|
+
return "";
|
|
663
|
+
let extIdx = ext.length - 1;
|
|
664
|
+
let firstNonSlashEnd = -1;
|
|
665
|
+
for (i = path.length - 1; i >= start; --i) {
|
|
666
|
+
const code = path.charCodeAt(i);
|
|
667
|
+
if ((0, _util_js_1.isPathSeparator)(code)) {
|
|
668
|
+
// If we reached a path separator that was not part of a set of path
|
|
669
|
+
// separators at the end of the string, stop now
|
|
670
|
+
if (!matchedSlash) {
|
|
671
|
+
start = i + 1;
|
|
672
|
+
break;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
if (firstNonSlashEnd === -1) {
|
|
677
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
678
|
+
// path component in case we don't match a whole suffix
|
|
679
|
+
matchedSlash = false;
|
|
680
|
+
firstNonSlashEnd = i + 1;
|
|
681
|
+
end = firstNonSlashEnd;
|
|
682
|
+
}
|
|
683
|
+
if (extIdx >= 0) {
|
|
684
|
+
// Try to match the explicit suffix
|
|
685
|
+
if (code === ext.charCodeAt(extIdx)) {
|
|
686
|
+
if (--extIdx === -1) {
|
|
687
|
+
// We matched whole suffix, so mark this as the end of our path
|
|
688
|
+
// component
|
|
689
|
+
end = i;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
else {
|
|
693
|
+
// Suffix character does not match, so bail out early
|
|
694
|
+
// from checking rest of characters
|
|
695
|
+
extIdx = -1;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
if (end === -1)
|
|
701
|
+
return "";
|
|
702
|
+
if (start === end)
|
|
703
|
+
end = firstNonSlashEnd;
|
|
704
|
+
return path.slice(start, end);
|
|
705
|
+
}
|
|
706
|
+
else {
|
|
707
|
+
for (i = path.length - 1; i >= start; --i) {
|
|
708
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(i))) {
|
|
709
|
+
// If we reached a path separator that was not part of a set of path
|
|
710
|
+
// separators at the end of the string, stop now
|
|
711
|
+
if (!matchedSlash) {
|
|
712
|
+
start = i + 1;
|
|
713
|
+
break;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
else if (end === -1) {
|
|
717
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
718
|
+
// path component
|
|
719
|
+
matchedSlash = false;
|
|
720
|
+
end = i + 1;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
if (end === -1)
|
|
724
|
+
return "";
|
|
725
|
+
return path.slice(start, end);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
exports.basename = basename;
|
|
729
|
+
/**
|
|
730
|
+
* Return the extension of the `path` with leading period.
|
|
731
|
+
* @param path with extension
|
|
732
|
+
* @returns extension (ex. for `file.ts` returns `.ts`)
|
|
733
|
+
*/
|
|
734
|
+
function extname(path) {
|
|
735
|
+
(0, _util_js_1.assertPath)(path);
|
|
736
|
+
let start = 0;
|
|
737
|
+
let startDot = -1;
|
|
738
|
+
let startPart = 0;
|
|
739
|
+
let end = -1;
|
|
740
|
+
let matchedSlash = true;
|
|
741
|
+
// Track the state of characters (if any) we see before our first dot and
|
|
742
|
+
// after any path separator we find
|
|
743
|
+
let preDotState = 0;
|
|
744
|
+
// Check for a drive letter prefix so as not to mistake the following
|
|
745
|
+
// path separator as an extra separator at the end of the path that can be
|
|
746
|
+
// disregarded
|
|
747
|
+
if (path.length >= 2 &&
|
|
748
|
+
path.charCodeAt(1) === _constants_js_1.CHAR_COLON &&
|
|
749
|
+
(0, _util_js_1.isWindowsDeviceRoot)(path.charCodeAt(0))) {
|
|
750
|
+
start = startPart = 2;
|
|
751
|
+
}
|
|
752
|
+
for (let i = path.length - 1; i >= start; --i) {
|
|
753
|
+
const code = path.charCodeAt(i);
|
|
754
|
+
if ((0, _util_js_1.isPathSeparator)(code)) {
|
|
755
|
+
// If we reached a path separator that was not part of a set of path
|
|
756
|
+
// separators at the end of the string, stop now
|
|
757
|
+
if (!matchedSlash) {
|
|
758
|
+
startPart = i + 1;
|
|
759
|
+
break;
|
|
760
|
+
}
|
|
761
|
+
continue;
|
|
762
|
+
}
|
|
763
|
+
if (end === -1) {
|
|
764
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
765
|
+
// extension
|
|
766
|
+
matchedSlash = false;
|
|
767
|
+
end = i + 1;
|
|
768
|
+
}
|
|
769
|
+
if (code === _constants_js_1.CHAR_DOT) {
|
|
770
|
+
// If this is our first dot, mark it as the start of our extension
|
|
771
|
+
if (startDot === -1)
|
|
772
|
+
startDot = i;
|
|
773
|
+
else if (preDotState !== 1)
|
|
774
|
+
preDotState = 1;
|
|
775
|
+
}
|
|
776
|
+
else if (startDot !== -1) {
|
|
777
|
+
// We saw a non-dot and non-path separator before our dot, so we should
|
|
778
|
+
// have a good chance at having a non-empty extension
|
|
779
|
+
preDotState = -1;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
if (startDot === -1 ||
|
|
783
|
+
end === -1 ||
|
|
784
|
+
// We saw a non-dot character immediately before the dot
|
|
785
|
+
preDotState === 0 ||
|
|
786
|
+
// The (right-most) trimmed path component is exactly '..'
|
|
787
|
+
(preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
|
|
788
|
+
return "";
|
|
789
|
+
}
|
|
790
|
+
return path.slice(startDot, end);
|
|
791
|
+
}
|
|
792
|
+
exports.extname = extname;
|
|
793
|
+
/**
|
|
794
|
+
* Generate a path from `FormatInputPathObject` object.
|
|
795
|
+
* @param pathObject with path
|
|
796
|
+
*/
|
|
797
|
+
function format(pathObject) {
|
|
798
|
+
if (pathObject === null || typeof pathObject !== "object") {
|
|
799
|
+
throw new TypeError(`The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`);
|
|
800
|
+
}
|
|
801
|
+
return (0, _util_js_1._format)("\\", pathObject);
|
|
802
|
+
}
|
|
803
|
+
exports.format = format;
|
|
804
|
+
/**
|
|
805
|
+
* Return a `ParsedPath` object of the `path`.
|
|
806
|
+
* @param path to process
|
|
807
|
+
*/
|
|
808
|
+
function parse(path) {
|
|
809
|
+
(0, _util_js_1.assertPath)(path);
|
|
810
|
+
const ret = { root: "", dir: "", base: "", ext: "", name: "" };
|
|
811
|
+
const len = path.length;
|
|
812
|
+
if (len === 0)
|
|
813
|
+
return ret;
|
|
814
|
+
let rootEnd = 0;
|
|
815
|
+
let code = path.charCodeAt(0);
|
|
816
|
+
// Try to match a root
|
|
817
|
+
if (len > 1) {
|
|
818
|
+
if ((0, _util_js_1.isPathSeparator)(code)) {
|
|
819
|
+
// Possible UNC root
|
|
820
|
+
rootEnd = 1;
|
|
821
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(1))) {
|
|
822
|
+
// Matched double path separator at beginning
|
|
823
|
+
let j = 2;
|
|
824
|
+
let last = j;
|
|
825
|
+
// Match 1 or more non-path separators
|
|
826
|
+
for (; j < len; ++j) {
|
|
827
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
|
|
828
|
+
break;
|
|
829
|
+
}
|
|
830
|
+
if (j < len && j !== last) {
|
|
831
|
+
// Matched!
|
|
832
|
+
last = j;
|
|
833
|
+
// Match 1 or more path separators
|
|
834
|
+
for (; j < len; ++j) {
|
|
835
|
+
if (!(0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
|
|
836
|
+
break;
|
|
837
|
+
}
|
|
838
|
+
if (j < len && j !== last) {
|
|
839
|
+
// Matched!
|
|
840
|
+
last = j;
|
|
841
|
+
// Match 1 or more non-path separators
|
|
842
|
+
for (; j < len; ++j) {
|
|
843
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(j)))
|
|
844
|
+
break;
|
|
845
|
+
}
|
|
846
|
+
if (j === len) {
|
|
847
|
+
// We matched a UNC root only
|
|
848
|
+
rootEnd = j;
|
|
849
|
+
}
|
|
850
|
+
else if (j !== last) {
|
|
851
|
+
// We matched a UNC root with leftovers
|
|
852
|
+
rootEnd = j + 1;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
else if ((0, _util_js_1.isWindowsDeviceRoot)(code)) {
|
|
859
|
+
// Possible device root
|
|
860
|
+
if (path.charCodeAt(1) === _constants_js_1.CHAR_COLON) {
|
|
861
|
+
rootEnd = 2;
|
|
862
|
+
if (len > 2) {
|
|
863
|
+
if ((0, _util_js_1.isPathSeparator)(path.charCodeAt(2))) {
|
|
864
|
+
if (len === 3) {
|
|
865
|
+
// `path` contains just a drive root, exit early to avoid
|
|
866
|
+
// unnecessary work
|
|
867
|
+
ret.root = ret.dir = path;
|
|
868
|
+
return ret;
|
|
869
|
+
}
|
|
870
|
+
rootEnd = 3;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
else {
|
|
874
|
+
// `path` contains just a drive root, exit early to avoid
|
|
875
|
+
// unnecessary work
|
|
876
|
+
ret.root = ret.dir = path;
|
|
877
|
+
return ret;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
else if ((0, _util_js_1.isPathSeparator)(code)) {
|
|
883
|
+
// `path` contains just a path separator, exit early to avoid
|
|
884
|
+
// unnecessary work
|
|
885
|
+
ret.root = ret.dir = path;
|
|
886
|
+
return ret;
|
|
887
|
+
}
|
|
888
|
+
if (rootEnd > 0)
|
|
889
|
+
ret.root = path.slice(0, rootEnd);
|
|
890
|
+
let startDot = -1;
|
|
891
|
+
let startPart = rootEnd;
|
|
892
|
+
let end = -1;
|
|
893
|
+
let matchedSlash = true;
|
|
894
|
+
let i = path.length - 1;
|
|
895
|
+
// Track the state of characters (if any) we see before our first dot and
|
|
896
|
+
// after any path separator we find
|
|
897
|
+
let preDotState = 0;
|
|
898
|
+
// Get non-dir info
|
|
899
|
+
for (; i >= rootEnd; --i) {
|
|
900
|
+
code = path.charCodeAt(i);
|
|
901
|
+
if ((0, _util_js_1.isPathSeparator)(code)) {
|
|
902
|
+
// If we reached a path separator that was not part of a set of path
|
|
903
|
+
// separators at the end of the string, stop now
|
|
904
|
+
if (!matchedSlash) {
|
|
905
|
+
startPart = i + 1;
|
|
906
|
+
break;
|
|
907
|
+
}
|
|
908
|
+
continue;
|
|
909
|
+
}
|
|
910
|
+
if (end === -1) {
|
|
911
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
912
|
+
// extension
|
|
913
|
+
matchedSlash = false;
|
|
914
|
+
end = i + 1;
|
|
915
|
+
}
|
|
916
|
+
if (code === _constants_js_1.CHAR_DOT) {
|
|
917
|
+
// If this is our first dot, mark it as the start of our extension
|
|
918
|
+
if (startDot === -1)
|
|
919
|
+
startDot = i;
|
|
920
|
+
else if (preDotState !== 1)
|
|
921
|
+
preDotState = 1;
|
|
922
|
+
}
|
|
923
|
+
else if (startDot !== -1) {
|
|
924
|
+
// We saw a non-dot and non-path separator before our dot, so we should
|
|
925
|
+
// have a good chance at having a non-empty extension
|
|
926
|
+
preDotState = -1;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
if (startDot === -1 ||
|
|
930
|
+
end === -1 ||
|
|
931
|
+
// We saw a non-dot character immediately before the dot
|
|
932
|
+
preDotState === 0 ||
|
|
933
|
+
// The (right-most) trimmed path component is exactly '..'
|
|
934
|
+
(preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)) {
|
|
935
|
+
if (end !== -1) {
|
|
936
|
+
ret.base = ret.name = path.slice(startPart, end);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
else {
|
|
940
|
+
ret.name = path.slice(startPart, startDot);
|
|
941
|
+
ret.base = path.slice(startPart, end);
|
|
942
|
+
ret.ext = path.slice(startDot, end);
|
|
943
|
+
}
|
|
944
|
+
// If the directory is the root, use the entire root as the `dir` including
|
|
945
|
+
// the trailing slash if any (`C:\abc` -> `C:\`). Otherwise, strip out the
|
|
946
|
+
// trailing slash (`C:\abc\def` -> `C:\abc`).
|
|
947
|
+
if (startPart > 0 && startPart !== rootEnd) {
|
|
948
|
+
ret.dir = path.slice(0, startPart - 1);
|
|
949
|
+
}
|
|
950
|
+
else
|
|
951
|
+
ret.dir = ret.root;
|
|
952
|
+
return ret;
|
|
953
|
+
}
|
|
954
|
+
exports.parse = parse;
|
|
955
|
+
/**
|
|
956
|
+
* Converts a file URL to a path string.
|
|
957
|
+
*
|
|
958
|
+
* ```ts
|
|
959
|
+
* import { fromFileUrl } from "https://deno.land/std@$STD_VERSION/path/win32.ts";
|
|
960
|
+
* fromFileUrl("file:///home/foo"); // "\\home\\foo"
|
|
961
|
+
* fromFileUrl("file:///C:/Users/foo"); // "C:\\Users\\foo"
|
|
962
|
+
* fromFileUrl("file://localhost/home/foo"); // "\\\\localhost\\home\\foo"
|
|
963
|
+
* ```
|
|
964
|
+
* @param url of a file URL
|
|
965
|
+
*/
|
|
966
|
+
function fromFileUrl(url) {
|
|
967
|
+
url = url instanceof URL ? url : new URL(url);
|
|
968
|
+
if (url.protocol != "file:") {
|
|
969
|
+
throw new TypeError("Must be a file URL.");
|
|
970
|
+
}
|
|
971
|
+
let path = decodeURIComponent(url.pathname.replace(/\//g, "\\").replace(/%(?![0-9A-Fa-f]{2})/g, "%25")).replace(/^\\*([A-Za-z]:)(\\|$)/, "$1\\");
|
|
972
|
+
if (url.hostname != "") {
|
|
973
|
+
// Note: The `URL` implementation guarantees that the drive letter and
|
|
974
|
+
// hostname are mutually exclusive. Otherwise it would not have been valid
|
|
975
|
+
// to append the hostname and path like this.
|
|
976
|
+
path = `\\\\${url.hostname}${path}`;
|
|
977
|
+
}
|
|
978
|
+
return path;
|
|
979
|
+
}
|
|
980
|
+
exports.fromFileUrl = fromFileUrl;
|
|
981
|
+
/**
|
|
982
|
+
* Converts a path string to a file URL.
|
|
983
|
+
*
|
|
984
|
+
* ```ts
|
|
985
|
+
* import { toFileUrl } from "https://deno.land/std@$STD_VERSION/path/win32.ts";
|
|
986
|
+
* toFileUrl("\\home\\foo"); // new URL("file:///home/foo")
|
|
987
|
+
* toFileUrl("C:\\Users\\foo"); // new URL("file:///C:/Users/foo")
|
|
988
|
+
* toFileUrl("\\\\127.0.0.1\\home\\foo"); // new URL("file://127.0.0.1/home/foo")
|
|
989
|
+
* ```
|
|
990
|
+
* @param path to convert to file URL
|
|
991
|
+
*/
|
|
992
|
+
function toFileUrl(path) {
|
|
993
|
+
if (!isAbsolute(path)) {
|
|
994
|
+
throw new TypeError("Must be an absolute path.");
|
|
995
|
+
}
|
|
996
|
+
const [, hostname, pathname] = path.match(/^(?:[/\\]{2}([^/\\]+)(?=[/\\](?:[^/\\]|$)))?(.*)/);
|
|
997
|
+
const url = new URL("file:///");
|
|
998
|
+
url.pathname = (0, _util_js_1.encodeWhitespace)(pathname.replace(/%/g, "%25"));
|
|
999
|
+
if (hostname != null && hostname != "localhost") {
|
|
1000
|
+
url.hostname = hostname;
|
|
1001
|
+
if (!url.hostname) {
|
|
1002
|
+
throw new TypeError("Invalid hostname.");
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
return url;
|
|
1006
|
+
}
|
|
1007
|
+
exports.toFileUrl = toFileUrl;
|