keep-a-changelog 2.1.0 → 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 +18 -1
- package/README.md +16 -4
- package/esm/bin.js +6 -2
- package/esm/deps/deno.land/std@0.173.0/_util/asserts.js +21 -0
- package/esm/deps/deno.land/{std@0.120.0 → std@0.173.0}/_util/os.js +3 -2
- package/esm/deps/deno.land/{std@0.120.0 → std@0.173.0}/flags/mod.js +145 -36
- package/esm/deps/deno.land/{std@0.120.0 → 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 → std@0.173.0}/path/_util.js +1 -0
- package/esm/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/common.js +1 -1
- package/esm/deps/deno.land/{std@0.120.0 → 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 → std@0.173.0}/path/posix.js +20 -16
- package/esm/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/separator.js +1 -1
- package/esm/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/win32.js +17 -15
- package/esm/deps/deno.land/{x/semver@v1.4.0 → std@0.173.0/semver}/mod.js +227 -334
- package/esm/src/Change.js +15 -15
- package/esm/src/Changelog.js +9 -1
- package/esm/src/Release.js +10 -0
- package/esm/src/deps.js +1 -1
- package/esm/src/parser.js +19 -3
- package/esm/test/changelog.custom.type.md +0 -1
- package/esm/test/changelog.expected.linted.md +208 -0
- package/esm/test/changelog.expected.md +3 -1
- package/esm/test/changelog.md +4 -0
- package/esm/test/empty.expected.md +0 -1
- package/package.json +13 -8
- package/script/bin.js +6 -2
- package/script/deps/deno.land/std@0.173.0/_util/asserts.js +27 -0
- package/script/deps/deno.land/{std@0.120.0 → std@0.173.0}/_util/os.js +4 -3
- package/script/deps/deno.land/{std@0.120.0 → std@0.173.0}/flags/mod.js +149 -40
- package/script/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/_constants.js +1 -0
- package/script/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/_interface.js +1 -1
- package/script/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/_util.js +1 -0
- package/script/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/common.js +1 -1
- package/script/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/glob.js +1 -1
- package/script/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/mod.js +19 -1
- package/script/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/posix.js +20 -16
- package/script/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/separator.js +1 -1
- package/script/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/win32.js +18 -16
- package/script/deps/deno.land/{x/semver@v1.4.0 → std@0.173.0/semver}/mod.js +232 -342
- package/script/src/Change.js +15 -15
- package/script/src/Changelog.js +9 -1
- package/script/src/Release.js +10 -0
- package/script/src/deps.js +1 -1
- package/script/src/parser.js +19 -3
- package/script/test/changelog.custom.type.md +0 -1
- package/script/test/changelog.expected.linted.md +208 -0
- package/script/test/changelog.expected.md +3 -1
- package/script/test/changelog.md +4 -0
- package/script/test/empty.expected.md +0 -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 → std@0.173.0}/path/_constants.d.ts +0 -0
- package/types/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/_interface.d.ts +1 -1
- package/types/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/_util.d.ts +0 -0
- package/types/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/common.d.ts +0 -0
- package/types/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/glob.d.ts +10 -5
- package/types/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/mod.d.ts +0 -0
- package/types/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/posix.d.ts +9 -5
- package/types/deps/deno.land/{std@0.120.0 → std@0.173.0}/path/separator.d.ts +0 -0
- package/types/deps/deno.land/{std@0.120.0 → 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/src/Changelog.d.ts +1 -0
- package/types/src/Release.d.ts +1 -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/script/deps/deno.land/std@0.120.0/_util/assert.js +0 -18
- 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
|
@@ -1,8 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.parse = void 0;
|
|
5
|
-
|
|
4
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
5
|
+
/**
|
|
6
|
+
* Command line arguments parser based on
|
|
7
|
+
* [minimist](https://github.com/minimistjs/minimist).
|
|
8
|
+
*
|
|
9
|
+
* This module is browser compatible.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
|
|
14
|
+
*
|
|
15
|
+
* console.dir(parse(Deno.args));
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* ```sh
|
|
19
|
+
* $ deno run https://deno.land/std/examples/flags.ts -a beep -b boop
|
|
20
|
+
* { _: [], a: 'beep', b: 'boop' }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* ```sh
|
|
24
|
+
* $ deno run https://deno.land/std/examples/flags.ts -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
|
|
25
|
+
* { _: [ 'foo', 'bar', 'baz' ],
|
|
26
|
+
* x: 3,
|
|
27
|
+
* y: 4,
|
|
28
|
+
* n: 5,
|
|
29
|
+
* a: true,
|
|
30
|
+
* b: true,
|
|
31
|
+
* c: true,
|
|
32
|
+
* beep: 'boop' }
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @module
|
|
36
|
+
*/
|
|
37
|
+
const asserts_js_1 = require("../_util/asserts.js");
|
|
6
38
|
const { hasOwn } = Object;
|
|
7
39
|
function get(obj, key) {
|
|
8
40
|
if (hasOwn(obj, key)) {
|
|
@@ -11,7 +43,7 @@ function get(obj, key) {
|
|
|
11
43
|
}
|
|
12
44
|
function getForce(obj, key) {
|
|
13
45
|
const v = get(obj, key);
|
|
14
|
-
(0,
|
|
46
|
+
(0, asserts_js_1.assert)(v != null);
|
|
15
47
|
return v;
|
|
16
48
|
}
|
|
17
49
|
function isNumber(x) {
|
|
@@ -27,35 +59,52 @@ function hasKey(obj, keys) {
|
|
|
27
59
|
o = (get(o, key) ?? {});
|
|
28
60
|
});
|
|
29
61
|
const key = keys[keys.length - 1];
|
|
30
|
-
return key
|
|
62
|
+
return hasOwn(o, key);
|
|
31
63
|
}
|
|
32
|
-
/** Take a set of command line arguments, with
|
|
33
|
-
* return an object
|
|
64
|
+
/** Take a set of command line arguments, optionally with a set of options, and
|
|
65
|
+
* return an object representing the flags found in the passed arguments.
|
|
66
|
+
*
|
|
67
|
+
* By default, any arguments starting with `-` or `--` are considered boolean
|
|
68
|
+
* flags. If the argument name is followed by an equal sign (`=`) it is
|
|
69
|
+
* considered a key-value pair. Any arguments which could not be parsed are
|
|
70
|
+
* available in the `_` property of the returned object.
|
|
71
|
+
*
|
|
72
|
+
* By default, the flags module tries to determine the type of all arguments
|
|
73
|
+
* automatically and the return type of the `parse` method will have an index
|
|
74
|
+
* signature with `any` as value (`{ [x: string]: any }`).
|
|
34
75
|
*
|
|
76
|
+
* If the `string`, `boolean` or `collect` option is set, the return value of
|
|
77
|
+
* the `parse` method will be fully typed and the index signature of the return
|
|
78
|
+
* type will change to `{ [x: string]: unknown }`.
|
|
79
|
+
*
|
|
80
|
+
* Any arguments after `'--'` will not be parsed and will end up in `parsedArgs._`.
|
|
81
|
+
*
|
|
82
|
+
* Numeric-looking arguments will be returned as numbers unless `options.string`
|
|
83
|
+
* or `options.boolean` is set for that argument name.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
35
86
|
* ```ts
|
|
36
|
-
*
|
|
37
|
-
*
|
|
87
|
+
* import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
|
|
88
|
+
* const parsedArgs = parse(Deno.args);
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
|
|
94
|
+
* const parsedArgs = parse(["--foo", "--bar=baz", "./quux.txt"]);
|
|
95
|
+
* // parsedArgs: { foo: true, bar: "baz", _: ["./quux.txt"] }
|
|
38
96
|
* ```
|
|
39
97
|
*/
|
|
40
|
-
function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, default: defaults = {}, stopEarly = false, string = [], unknown = (i) => i, } = {}) {
|
|
98
|
+
function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, default: defaults = {}, stopEarly = false, string = [], collect = [], negatable = [], unknown = (i) => i, } = {}) {
|
|
99
|
+
const aliases = {};
|
|
41
100
|
const flags = {
|
|
42
101
|
bools: {},
|
|
43
102
|
strings: {},
|
|
44
103
|
unknownFn: unknown,
|
|
45
104
|
allBools: false,
|
|
105
|
+
collect: {},
|
|
106
|
+
negatable: {},
|
|
46
107
|
};
|
|
47
|
-
if (boolean !== undefined) {
|
|
48
|
-
if (typeof boolean === "boolean") {
|
|
49
|
-
flags.allBools = !!boolean;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
const booleanArgs = typeof boolean === "string" ? [boolean] : boolean;
|
|
53
|
-
for (const key of booleanArgs.filter(Boolean)) {
|
|
54
|
-
flags.bools[key] = true;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
const aliases = {};
|
|
59
108
|
if (alias !== undefined) {
|
|
60
109
|
for (const key in alias) {
|
|
61
110
|
const val = getForce(alias, key);
|
|
@@ -70,8 +119,29 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
|
|
|
70
119
|
}
|
|
71
120
|
}
|
|
72
121
|
}
|
|
122
|
+
if (boolean !== undefined) {
|
|
123
|
+
if (typeof boolean === "boolean") {
|
|
124
|
+
flags.allBools = !!boolean;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
const booleanArgs = typeof boolean === "string"
|
|
128
|
+
? [boolean]
|
|
129
|
+
: boolean;
|
|
130
|
+
for (const key of booleanArgs.filter(Boolean)) {
|
|
131
|
+
flags.bools[key] = true;
|
|
132
|
+
const alias = get(aliases, key);
|
|
133
|
+
if (alias) {
|
|
134
|
+
for (const al of alias) {
|
|
135
|
+
flags.bools[al] = true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
73
141
|
if (string !== undefined) {
|
|
74
|
-
const stringArgs = typeof string === "string"
|
|
142
|
+
const stringArgs = typeof string === "string"
|
|
143
|
+
? [string]
|
|
144
|
+
: string;
|
|
75
145
|
for (const key of stringArgs.filter(Boolean)) {
|
|
76
146
|
flags.strings[key] = true;
|
|
77
147
|
const alias = get(aliases, key);
|
|
@@ -82,6 +152,34 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
|
|
|
82
152
|
}
|
|
83
153
|
}
|
|
84
154
|
}
|
|
155
|
+
if (collect !== undefined) {
|
|
156
|
+
const collectArgs = typeof collect === "string"
|
|
157
|
+
? [collect]
|
|
158
|
+
: collect;
|
|
159
|
+
for (const key of collectArgs.filter(Boolean)) {
|
|
160
|
+
flags.collect[key] = true;
|
|
161
|
+
const alias = get(aliases, key);
|
|
162
|
+
if (alias) {
|
|
163
|
+
for (const al of alias) {
|
|
164
|
+
flags.collect[al] = true;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (negatable !== undefined) {
|
|
170
|
+
const negatableArgs = typeof negatable === "string"
|
|
171
|
+
? [negatable]
|
|
172
|
+
: negatable;
|
|
173
|
+
for (const key of negatableArgs.filter(Boolean)) {
|
|
174
|
+
flags.negatable[key] = true;
|
|
175
|
+
const alias = get(aliases, key);
|
|
176
|
+
if (alias) {
|
|
177
|
+
for (const al of alias) {
|
|
178
|
+
flags.negatable[al] = true;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
85
183
|
const argv = { _: [] };
|
|
86
184
|
function argDefined(key, arg) {
|
|
87
185
|
return ((flags.allBools && /^--[^=]+$/.test(arg)) ||
|
|
@@ -89,8 +187,9 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
|
|
|
89
187
|
!!get(flags.strings, key) ||
|
|
90
188
|
!!get(aliases, key));
|
|
91
189
|
}
|
|
92
|
-
function setKey(obj,
|
|
190
|
+
function setKey(obj, name, value, collect = true) {
|
|
93
191
|
let o = obj;
|
|
192
|
+
const keys = name.split(".");
|
|
94
193
|
keys.slice(0, -1).forEach(function (key) {
|
|
95
194
|
if (get(o, key) === undefined) {
|
|
96
195
|
o[key] = {};
|
|
@@ -98,11 +197,13 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
|
|
|
98
197
|
o = get(o, key);
|
|
99
198
|
});
|
|
100
199
|
const key = keys[keys.length - 1];
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
typeof get(o, key) === "boolean") {
|
|
200
|
+
const collectable = collect && !!get(flags.collect, name);
|
|
201
|
+
if (!collectable) {
|
|
104
202
|
o[key] = value;
|
|
105
203
|
}
|
|
204
|
+
else if (get(o, key) === undefined) {
|
|
205
|
+
o[key] = [value];
|
|
206
|
+
}
|
|
106
207
|
else if (Array.isArray(get(o, key))) {
|
|
107
208
|
o[key].push(value);
|
|
108
209
|
}
|
|
@@ -110,26 +211,23 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
|
|
|
110
211
|
o[key] = [get(o, key), value];
|
|
111
212
|
}
|
|
112
213
|
}
|
|
113
|
-
function setArg(key, val, arg = undefined) {
|
|
214
|
+
function setArg(key, val, arg = undefined, collect) {
|
|
114
215
|
if (arg && flags.unknownFn && !argDefined(key, arg)) {
|
|
115
216
|
if (flags.unknownFn(arg, key, val) === false)
|
|
116
217
|
return;
|
|
117
218
|
}
|
|
118
219
|
const value = !get(flags.strings, key) && isNumber(val) ? Number(val) : val;
|
|
119
|
-
setKey(argv, key
|
|
220
|
+
setKey(argv, key, value, collect);
|
|
120
221
|
const alias = get(aliases, key);
|
|
121
222
|
if (alias) {
|
|
122
223
|
for (const x of alias) {
|
|
123
|
-
setKey(argv, x
|
|
224
|
+
setKey(argv, x, value, collect);
|
|
124
225
|
}
|
|
125
226
|
}
|
|
126
227
|
}
|
|
127
228
|
function aliasIsBoolean(key) {
|
|
128
229
|
return getForce(aliases, key).some((x) => typeof get(flags.bools, x) === "boolean");
|
|
129
230
|
}
|
|
130
|
-
for (const key of Object.keys(flags.bools)) {
|
|
131
|
-
setArg(key, defaults[key] === undefined ? false : defaults[key]);
|
|
132
|
-
}
|
|
133
231
|
let notFlags = [];
|
|
134
232
|
// all args after "--" are not parsed
|
|
135
233
|
if (args.includes("--")) {
|
|
@@ -140,7 +238,7 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
|
|
|
140
238
|
const arg = args[i];
|
|
141
239
|
if (/^--.+=/.test(arg)) {
|
|
142
240
|
const m = arg.match(/^--([^=]+)=(.*)$/s);
|
|
143
|
-
(0,
|
|
241
|
+
(0, asserts_js_1.assert)(m != null);
|
|
144
242
|
const [, key, value] = m;
|
|
145
243
|
if (flags.bools[key]) {
|
|
146
244
|
const booleanValue = value !== "false";
|
|
@@ -150,14 +248,14 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
|
|
|
150
248
|
setArg(key, value, arg);
|
|
151
249
|
}
|
|
152
250
|
}
|
|
153
|
-
else if (/^--no-.+/.test(arg)) {
|
|
251
|
+
else if (/^--no-.+/.test(arg) && get(flags.negatable, arg.replace(/^--no-/, ""))) {
|
|
154
252
|
const m = arg.match(/^--no-(.+)/);
|
|
155
|
-
(0,
|
|
156
|
-
setArg(m[1], false, arg);
|
|
253
|
+
(0, asserts_js_1.assert)(m != null);
|
|
254
|
+
setArg(m[1], false, arg, false);
|
|
157
255
|
}
|
|
158
256
|
else if (/^--.+/.test(arg)) {
|
|
159
257
|
const m = arg.match(/^--(.+)/);
|
|
160
|
-
(0,
|
|
258
|
+
(0, asserts_js_1.assert)(m != null);
|
|
161
259
|
const [, key] = m;
|
|
162
260
|
const next = args[i + 1];
|
|
163
261
|
if (next !== undefined &&
|
|
@@ -233,16 +331,27 @@ function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, de
|
|
|
233
331
|
}
|
|
234
332
|
}
|
|
235
333
|
}
|
|
236
|
-
for (const key of Object.
|
|
334
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
237
335
|
if (!hasKey(argv, key.split("."))) {
|
|
238
|
-
setKey(argv, key
|
|
336
|
+
setKey(argv, key, value);
|
|
239
337
|
if (aliases[key]) {
|
|
240
338
|
for (const x of aliases[key]) {
|
|
241
|
-
setKey(argv, x
|
|
339
|
+
setKey(argv, x, value);
|
|
242
340
|
}
|
|
243
341
|
}
|
|
244
342
|
}
|
|
245
343
|
}
|
|
344
|
+
for (const key of Object.keys(flags.bools)) {
|
|
345
|
+
if (!hasKey(argv, key.split("."))) {
|
|
346
|
+
const value = get(flags.collect, key) ? [] : false;
|
|
347
|
+
setKey(argv, key, value, false);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
for (const key of Object.keys(flags.strings)) {
|
|
351
|
+
if (!hasKey(argv, key.split(".")) && get(flags.collect, key)) {
|
|
352
|
+
setKey(argv, key, [], false);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
246
355
|
if (doubleDash) {
|
|
247
356
|
argv["--"] = [];
|
|
248
357
|
for (const key of notFlags) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright 2018-
|
|
2
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
3
3
|
// This module is browser compatible.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright 2018-
|
|
2
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
3
3
|
// This module is browser compatible.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.common = void 0;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright 2018-
|
|
2
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
3
3
|
// This module is browser compatible.
|
|
4
4
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
5
|
if (k2 === undefined) k2 = k;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
3
|
// Copyright the Browserify authors. MIT License.
|
|
3
4
|
// Ported mostly from https://github.com/browserify/path-browserify/
|
|
4
|
-
// This module is browser compatible.
|
|
5
5
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
6
|
if (k2 === undefined) k2 = k;
|
|
7
7
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -30,6 +30,24 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.SEP_PATTERN = exports.SEP = exports.toNamespacedPath = exports.toFileUrl = exports.sep = exports.resolve = exports.relative = exports.parse = exports.normalize = exports.join = exports.isAbsolute = exports.fromFileUrl = exports.format = exports.extname = exports.dirname = exports.delimiter = exports.basename = exports.posix = exports.win32 = void 0;
|
|
33
|
+
/**
|
|
34
|
+
* Utilities for working with OS-specific file paths.
|
|
35
|
+
*
|
|
36
|
+
* Codes in the examples uses POSIX path but it automatically use Windows path
|
|
37
|
+
* on Windows. Use methods under `posix` or `win32` object instead to handle non
|
|
38
|
+
* platform specific path like:
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { posix, win32 } from "https://deno.land/std@$STD_VERSION/path/mod.ts";
|
|
41
|
+
* const p1 = posix.fromFileUrl("file:///home/foo");
|
|
42
|
+
* const p2 = win32.fromFileUrl("file:///home/foo");
|
|
43
|
+
* console.log(p1); // "/home/foo"
|
|
44
|
+
* console.log(p2); // "\\home\\foo"
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* This module is browser compatible.
|
|
48
|
+
*
|
|
49
|
+
* @module
|
|
50
|
+
*/
|
|
33
51
|
const os_js_1 = require("../_util/os.js");
|
|
34
52
|
const _win32 = __importStar(require("./win32.js"));
|
|
35
53
|
const _posix = __importStar(require("./posix.js"));
|
|
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
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.
|
|
27
28
|
// Copyright the Browserify authors. MIT License.
|
|
28
29
|
// Ported from https://github.com/browserify/path-browserify/
|
|
29
30
|
// This module is browser compatible.
|
|
@@ -78,6 +79,8 @@ function resolve(...pathSegments) {
|
|
|
78
79
|
exports.resolve = resolve;
|
|
79
80
|
/**
|
|
80
81
|
* Normalize the `path`, resolving `'..'` and `'.'` segments.
|
|
82
|
+
* Note that resolving these segments does not necessarily mean that all will be eliminated.
|
|
83
|
+
* A `'..'` at the top-level will be preserved, and an empty path is canonically `'.'`.
|
|
81
84
|
* @param path to be normalized
|
|
82
85
|
*/
|
|
83
86
|
function normalize(path) {
|
|
@@ -231,8 +234,8 @@ function toNamespacedPath(path) {
|
|
|
231
234
|
}
|
|
232
235
|
exports.toNamespacedPath = toNamespacedPath;
|
|
233
236
|
/**
|
|
234
|
-
* Return the directory
|
|
235
|
-
* @param path to determine
|
|
237
|
+
* Return the directory path of a `path`.
|
|
238
|
+
* @param path to determine the directory path for
|
|
236
239
|
*/
|
|
237
240
|
function dirname(path) {
|
|
238
241
|
(0, _util_js_1.assertPath)(path);
|
|
@@ -281,7 +284,7 @@ function basename(path, ext = "") {
|
|
|
281
284
|
let firstNonSlashEnd = -1;
|
|
282
285
|
for (i = path.length - 1; i >= 0; --i) {
|
|
283
286
|
const code = path.charCodeAt(i);
|
|
284
|
-
if (
|
|
287
|
+
if ((0, _util_js_1.isPosixPathSeparator)(code)) {
|
|
285
288
|
// If we reached a path separator that was not part of a set of path
|
|
286
289
|
// separators at the end of the string, stop now
|
|
287
290
|
if (!matchedSlash) {
|
|
@@ -291,38 +294,38 @@ function basename(path, ext = "") {
|
|
|
291
294
|
}
|
|
292
295
|
else {
|
|
293
296
|
if (firstNonSlashEnd === -1) {
|
|
294
|
-
// We saw the first non-path separator,
|
|
295
|
-
//
|
|
297
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
298
|
+
// path component in case we don't match a whole suffix
|
|
296
299
|
matchedSlash = false;
|
|
297
300
|
firstNonSlashEnd = i + 1;
|
|
301
|
+
end = firstNonSlashEnd;
|
|
298
302
|
}
|
|
299
303
|
if (extIdx >= 0) {
|
|
300
|
-
// Try to match the explicit
|
|
304
|
+
// Try to match the explicit suffix
|
|
301
305
|
if (code === ext.charCodeAt(extIdx)) {
|
|
302
306
|
if (--extIdx === -1) {
|
|
303
|
-
// We matched
|
|
307
|
+
// We matched whole suffix, so mark this as the end of our path
|
|
304
308
|
// component
|
|
305
309
|
end = i;
|
|
306
310
|
}
|
|
307
311
|
}
|
|
308
312
|
else {
|
|
309
|
-
//
|
|
310
|
-
//
|
|
313
|
+
// Suffix character does not match, so bail out early
|
|
314
|
+
// from checking rest of characters
|
|
311
315
|
extIdx = -1;
|
|
312
|
-
end = firstNonSlashEnd;
|
|
313
316
|
}
|
|
314
317
|
}
|
|
315
318
|
}
|
|
316
319
|
}
|
|
320
|
+
if (end === -1)
|
|
321
|
+
return "";
|
|
317
322
|
if (start === end)
|
|
318
323
|
end = firstNonSlashEnd;
|
|
319
|
-
else if (end === -1)
|
|
320
|
-
end = path.length;
|
|
321
324
|
return path.slice(start, end);
|
|
322
325
|
}
|
|
323
326
|
else {
|
|
324
327
|
for (i = path.length - 1; i >= 0; --i) {
|
|
325
|
-
if (path.charCodeAt(i)
|
|
328
|
+
if ((0, _util_js_1.isPosixPathSeparator)(path.charCodeAt(i))) {
|
|
326
329
|
// If we reached a path separator that was not part of a set of path
|
|
327
330
|
// separators at the end of the string, stop now
|
|
328
331
|
if (!matchedSlash) {
|
|
@@ -344,8 +347,9 @@ function basename(path, ext = "") {
|
|
|
344
347
|
}
|
|
345
348
|
exports.basename = basename;
|
|
346
349
|
/**
|
|
347
|
-
* Return the extension of the `path
|
|
350
|
+
* Return the extension of the `path` with leading period.
|
|
348
351
|
* @param path with extension
|
|
352
|
+
* @returns extension (ex. for `file.ts` returns `.ts`)
|
|
349
353
|
*/
|
|
350
354
|
function extname(path) {
|
|
351
355
|
(0, _util_js_1.assertPath)(path);
|
|
@@ -502,7 +506,7 @@ exports.parse = parse;
|
|
|
502
506
|
* Converts a file URL to a path string.
|
|
503
507
|
*
|
|
504
508
|
* ```ts
|
|
505
|
-
* import { fromFileUrl } from "
|
|
509
|
+
* import { fromFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
|
|
506
510
|
* fromFileUrl("file:///home/foo"); // "/home/foo"
|
|
507
511
|
* ```
|
|
508
512
|
* @param url of a file URL
|
|
@@ -519,7 +523,7 @@ exports.fromFileUrl = fromFileUrl;
|
|
|
519
523
|
* Converts a path string to a file URL.
|
|
520
524
|
*
|
|
521
525
|
* ```ts
|
|
522
|
-
* import { toFileUrl } from "
|
|
526
|
+
* import { toFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
|
|
523
527
|
* toFileUrl("/home/foo"); // new URL("file:///home/foo")
|
|
524
528
|
* ```
|
|
525
529
|
* @param path to convert to file URL
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright 2018-
|
|
2
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
3
3
|
// This module is browser compatible.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.SEP_PATTERN = exports.SEP = void 0;
|
|
@@ -24,13 +24,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
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.
|
|
27
28
|
// Copyright the Browserify authors. MIT License.
|
|
28
29
|
// Ported from https://github.com/browserify/path-browserify/
|
|
29
30
|
// This module is browser compatible.
|
|
30
31
|
const dntShim = __importStar(require("../../../../_dnt.shims.js"));
|
|
31
32
|
const _constants_js_1 = require("./_constants.js");
|
|
32
33
|
const _util_js_1 = require("./_util.js");
|
|
33
|
-
const
|
|
34
|
+
const asserts_js_1 = require("../_util/asserts.js");
|
|
34
35
|
exports.sep = "\\";
|
|
35
36
|
exports.delimiter = ";";
|
|
36
37
|
/**
|
|
@@ -355,7 +356,7 @@ function join(...paths) {
|
|
|
355
356
|
// path.join('//server', 'share') -> '\\\\server\\share\\')
|
|
356
357
|
let needsReplace = true;
|
|
357
358
|
let slashCount = 0;
|
|
358
|
-
(0,
|
|
359
|
+
(0, asserts_js_1.assert)(firstPart != null);
|
|
359
360
|
if ((0, _util_js_1.isPathSeparator)(firstPart.charCodeAt(0))) {
|
|
360
361
|
++slashCount;
|
|
361
362
|
const firstLen = firstPart.length;
|
|
@@ -538,8 +539,8 @@ function toNamespacedPath(path) {
|
|
|
538
539
|
}
|
|
539
540
|
exports.toNamespacedPath = toNamespacedPath;
|
|
540
541
|
/**
|
|
541
|
-
* Return the directory
|
|
542
|
-
* @param path to determine
|
|
542
|
+
* Return the directory path of a `path`.
|
|
543
|
+
* @param path to determine the directory path for
|
|
543
544
|
*/
|
|
544
545
|
function dirname(path) {
|
|
545
546
|
(0, _util_js_1.assertPath)(path);
|
|
@@ -673,33 +674,33 @@ function basename(path, ext = "") {
|
|
|
673
674
|
}
|
|
674
675
|
else {
|
|
675
676
|
if (firstNonSlashEnd === -1) {
|
|
676
|
-
// We saw the first non-path separator,
|
|
677
|
-
//
|
|
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
|
|
678
679
|
matchedSlash = false;
|
|
679
680
|
firstNonSlashEnd = i + 1;
|
|
681
|
+
end = firstNonSlashEnd;
|
|
680
682
|
}
|
|
681
683
|
if (extIdx >= 0) {
|
|
682
|
-
// Try to match the explicit
|
|
684
|
+
// Try to match the explicit suffix
|
|
683
685
|
if (code === ext.charCodeAt(extIdx)) {
|
|
684
686
|
if (--extIdx === -1) {
|
|
685
|
-
// We matched
|
|
687
|
+
// We matched whole suffix, so mark this as the end of our path
|
|
686
688
|
// component
|
|
687
689
|
end = i;
|
|
688
690
|
}
|
|
689
691
|
}
|
|
690
692
|
else {
|
|
691
|
-
//
|
|
692
|
-
//
|
|
693
|
+
// Suffix character does not match, so bail out early
|
|
694
|
+
// from checking rest of characters
|
|
693
695
|
extIdx = -1;
|
|
694
|
-
end = firstNonSlashEnd;
|
|
695
696
|
}
|
|
696
697
|
}
|
|
697
698
|
}
|
|
698
699
|
}
|
|
700
|
+
if (end === -1)
|
|
701
|
+
return "";
|
|
699
702
|
if (start === end)
|
|
700
703
|
end = firstNonSlashEnd;
|
|
701
|
-
else if (end === -1)
|
|
702
|
-
end = path.length;
|
|
703
704
|
return path.slice(start, end);
|
|
704
705
|
}
|
|
705
706
|
else {
|
|
@@ -726,8 +727,9 @@ function basename(path, ext = "") {
|
|
|
726
727
|
}
|
|
727
728
|
exports.basename = basename;
|
|
728
729
|
/**
|
|
729
|
-
* Return the extension of the `path
|
|
730
|
+
* Return the extension of the `path` with leading period.
|
|
730
731
|
* @param path with extension
|
|
732
|
+
* @returns extension (ex. for `file.ts` returns `.ts`)
|
|
731
733
|
*/
|
|
732
734
|
function extname(path) {
|
|
733
735
|
(0, _util_js_1.assertPath)(path);
|
|
@@ -954,7 +956,7 @@ exports.parse = parse;
|
|
|
954
956
|
* Converts a file URL to a path string.
|
|
955
957
|
*
|
|
956
958
|
* ```ts
|
|
957
|
-
* import { fromFileUrl } from "
|
|
959
|
+
* import { fromFileUrl } from "https://deno.land/std@$STD_VERSION/path/win32.ts";
|
|
958
960
|
* fromFileUrl("file:///home/foo"); // "\\home\\foo"
|
|
959
961
|
* fromFileUrl("file:///C:/Users/foo"); // "C:\\Users\\foo"
|
|
960
962
|
* fromFileUrl("file://localhost/home/foo"); // "\\\\localhost\\home\\foo"
|
|
@@ -980,7 +982,7 @@ exports.fromFileUrl = fromFileUrl;
|
|
|
980
982
|
* Converts a path string to a file URL.
|
|
981
983
|
*
|
|
982
984
|
* ```ts
|
|
983
|
-
* import { toFileUrl } from "
|
|
985
|
+
* import { toFileUrl } from "https://deno.land/std@$STD_VERSION/path/win32.ts";
|
|
984
986
|
* toFileUrl("\\home\\foo"); // new URL("file:///home/foo")
|
|
985
987
|
* toFileUrl("C:\\Users\\foo"); // new URL("file:///C:/Users/foo")
|
|
986
988
|
* toFileUrl("\\\\127.0.0.1\\home\\foo"); // new URL("file://127.0.0.1/home/foo")
|