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
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
<!-- deno-fmt-ignore-file -->
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
|
-
|
|
5
4
|
All notable changes to this project will be documented in this file.
|
|
6
5
|
|
|
7
6
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
8
7
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
9
8
|
|
|
9
|
+
## [2.2.1] - 2023-01-25
|
|
10
|
+
### Fixed
|
|
11
|
+
- Allow list elements in the descriptions of releases and changelogs [#30].
|
|
12
|
+
|
|
13
|
+
## [2.2.0] - 2023-01-18
|
|
14
|
+
### Added
|
|
15
|
+
- New option `format` to configure the output option [#28].
|
|
16
|
+
- `Release.setYanked` function [#26].
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
- Removed unnecessary new line after the title [#27].
|
|
20
|
+
|
|
10
21
|
## [2.1.0] - 2022-04-03
|
|
11
22
|
### Added
|
|
12
23
|
- Support for `[YANKED]` releases [#25]
|
|
@@ -29,7 +40,13 @@ New version merging Deno and Node code using Deno's `dnt` package.
|
|
|
29
40
|
[#21]: https://github.com/oscarotero/keep-a-changelog/issues/21
|
|
30
41
|
[#23]: https://github.com/oscarotero/keep-a-changelog/issues/23
|
|
31
42
|
[#25]: https://github.com/oscarotero/keep-a-changelog/issues/25
|
|
43
|
+
[#26]: https://github.com/oscarotero/keep-a-changelog/issues/26
|
|
44
|
+
[#27]: https://github.com/oscarotero/keep-a-changelog/issues/27
|
|
45
|
+
[#28]: https://github.com/oscarotero/keep-a-changelog/issues/28
|
|
46
|
+
[#30]: https://github.com/oscarotero/keep-a-changelog/issues/30
|
|
32
47
|
|
|
48
|
+
[2.2.1]: https://github.com/oscarotero/keep-a-changelog/compare/v2.2.0...v2.2.1
|
|
49
|
+
[2.2.0]: https://github.com/oscarotero/keep-a-changelog/compare/v2.1.0...v2.2.0
|
|
33
50
|
[2.1.0]: https://github.com/oscarotero/keep-a-changelog/compare/v2.0.1...v2.1.0
|
|
34
51
|
[2.0.1]: https://github.com/oscarotero/keep-a-changelog/compare/v2.0.0...v2.0.1
|
|
35
52
|
[2.0.0]: https://github.com/oscarotero/keep-a-changelog/releases/tag/v2.0.0
|
package/README.md
CHANGED
|
@@ -56,6 +56,17 @@ const changelog = new Changelog("My project")
|
|
|
56
56
|
console.log(changelog.toString());
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
+
### Custom output format
|
|
60
|
+
|
|
61
|
+
By default, the output format of the markdown is "compact", that removes the
|
|
62
|
+
space after the headings. You can change it to follow the
|
|
63
|
+
[`markdownlint`](https://github.com/DavidAnson/markdownlint) rules:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
const changelog = new Changelog();
|
|
67
|
+
changelog.format = "markdownlint";
|
|
68
|
+
```
|
|
69
|
+
|
|
59
70
|
### Custom tag names
|
|
60
71
|
|
|
61
72
|
By default, the tag names are `v` + version number. For example, the tag for the
|
|
@@ -73,10 +84,10 @@ By default and according to the
|
|
|
73
84
|
[keepachangelog](http://keepachangelog.com/en/1.0.0/) format, the change types
|
|
74
85
|
are `Added`, `Changed`, `Deprecated`, `Removed`, `Fixed`, and `Security`.
|
|
75
86
|
|
|
76
|
-
In case you'd like add another type
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
87
|
+
In case you'd like add another type, you need to extend the `Release` class to
|
|
88
|
+
support new types. Additionally, you have to tell the `parser` that it should
|
|
89
|
+
create instances of your new extended `Release` in order to parse your changelog
|
|
90
|
+
correctly.
|
|
80
91
|
|
|
81
92
|
For example, we would like to add a type `Maintenance`. Extend the provided
|
|
82
93
|
`Release` class:
|
|
@@ -160,6 +171,7 @@ Available options:
|
|
|
160
171
|
|
|
161
172
|
| Option | Description |
|
|
162
173
|
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
174
|
+
| `--format` | The output format for the generated markdown. It can be `markdownlint` or `compact`. The default value is `compact`. |
|
|
163
175
|
| `--file` | The markdown file of the changelog. The default value is `CHANGELOG.md`. |
|
|
164
176
|
| `--url` | The base url used to build the diff urls of the different releases. It is taken from the existing diff urls in the markdown. If no urls are found, try to catch it using the url of the git remote repository. |
|
|
165
177
|
| `--https` | Set to false to use `http` instead `https` in the url (`--https=false`). |
|
package/esm/bin.js
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import "./_dnt.polyfills.js";
|
|
3
3
|
import * as dntShim from "./_dnt.shims.js";
|
|
4
|
-
import { join } from "./deps/deno.land/std@0.
|
|
4
|
+
import { join } from "./deps/deno.land/std@0.173.0/path/mod.js";
|
|
5
5
|
import { Changelog, parser, Release } from "./mod.js";
|
|
6
|
-
import { parse as parseFlag } from "./deps/deno.land/std@0.
|
|
6
|
+
import { parse as parseFlag } from "./deps/deno.land/std@0.173.0/flags/mod.js";
|
|
7
7
|
import { parse as parseIni } from "./deps/deno.land/x/ini@v2.1.0/mod.js";
|
|
8
8
|
const argv = parseFlag(dntShim.Deno.args, {
|
|
9
9
|
default: {
|
|
10
10
|
file: "CHANGELOG.md",
|
|
11
|
+
format: "compact",
|
|
11
12
|
release: null,
|
|
12
13
|
url: null,
|
|
13
14
|
https: true,
|
|
14
15
|
quiet: false,
|
|
15
16
|
},
|
|
17
|
+
string: ["file", "format", "release", "url"],
|
|
16
18
|
boolean: ["https", "init", "latest-release", "quiet"],
|
|
17
19
|
});
|
|
18
20
|
const file = join(dntShim.Deno.cwd(), argv.file);
|
|
19
21
|
try {
|
|
20
22
|
if (argv.init) {
|
|
21
23
|
const changelog = new Changelog("Changelog").addRelease(new Release("0.1.0", new Date(), "First version"));
|
|
24
|
+
changelog.format = argv.format;
|
|
22
25
|
save(file, changelog, true);
|
|
23
26
|
dntShim.Deno.exit(0);
|
|
24
27
|
}
|
|
25
28
|
const changelog = parser(dntShim.Deno.readTextFileSync(file));
|
|
29
|
+
changelog.format = argv.format;
|
|
26
30
|
if (argv["latest-release"]) {
|
|
27
31
|
const release = changelog.releases.find((release) => release.date && release.version);
|
|
28
32
|
if (release) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
/**
|
|
4
|
+
* All internal non-test code, that is files that do not have `test` or `bench` in the name, must use the assertion functions within `_utils/asserts.ts` and not `testing/asserts.ts`. This is to create a separation of concerns between internal and testing assertions.
|
|
5
|
+
*/
|
|
6
|
+
export class DenoStdInternalError extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "DenoStdInternalError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** Make an assertion, if not `true`, then throw. */
|
|
13
|
+
export function assert(expr, msg = "") {
|
|
14
|
+
if (!expr) {
|
|
15
|
+
throw new DenoStdInternalError(msg);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Use this to assert unreachable code. */
|
|
19
|
+
export function unreachable() {
|
|
20
|
+
throw new DenoStdInternalError("unreachable");
|
|
21
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2018-
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
3
|
import * as dntShim from "../../../../_dnt.shims.js";
|
|
4
4
|
export const osType = (() => {
|
|
@@ -9,9 +9,10 @@ export const osType = (() => {
|
|
|
9
9
|
}
|
|
10
10
|
// deno-lint-ignore no-explicit-any
|
|
11
11
|
const { navigator } = dntShim.dntGlobalThis;
|
|
12
|
-
if (navigator?.appVersion?.includes?.("Win")
|
|
12
|
+
if (navigator?.appVersion?.includes?.("Win")) {
|
|
13
13
|
return "windows";
|
|
14
14
|
}
|
|
15
15
|
return "linux";
|
|
16
16
|
})();
|
|
17
17
|
export const isWindows = osType === "windows";
|
|
18
|
+
export const isLinux = osType === "linux";
|
|
@@ -1,5 +1,37 @@
|
|
|
1
|
-
// Copyright 2018-
|
|
2
|
-
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
/**
|
|
3
|
+
* Command line arguments parser based on
|
|
4
|
+
* [minimist](https://github.com/minimistjs/minimist).
|
|
5
|
+
*
|
|
6
|
+
* This module is browser compatible.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
|
|
11
|
+
*
|
|
12
|
+
* console.dir(parse(Deno.args));
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* ```sh
|
|
16
|
+
* $ deno run https://deno.land/std/examples/flags.ts -a beep -b boop
|
|
17
|
+
* { _: [], a: 'beep', b: 'boop' }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* ```sh
|
|
21
|
+
* $ deno run https://deno.land/std/examples/flags.ts -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
|
|
22
|
+
* { _: [ 'foo', 'bar', 'baz' ],
|
|
23
|
+
* x: 3,
|
|
24
|
+
* y: 4,
|
|
25
|
+
* n: 5,
|
|
26
|
+
* a: true,
|
|
27
|
+
* b: true,
|
|
28
|
+
* c: true,
|
|
29
|
+
* beep: 'boop' }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @module
|
|
33
|
+
*/
|
|
34
|
+
import { assert } from "../_util/asserts.js";
|
|
3
35
|
const { hasOwn } = Object;
|
|
4
36
|
function get(obj, key) {
|
|
5
37
|
if (hasOwn(obj, key)) {
|
|
@@ -24,35 +56,52 @@ function hasKey(obj, keys) {
|
|
|
24
56
|
o = (get(o, key) ?? {});
|
|
25
57
|
});
|
|
26
58
|
const key = keys[keys.length - 1];
|
|
27
|
-
return key
|
|
59
|
+
return hasOwn(o, key);
|
|
28
60
|
}
|
|
29
|
-
/** Take a set of command line arguments, with
|
|
30
|
-
* return an object
|
|
61
|
+
/** Take a set of command line arguments, optionally with a set of options, and
|
|
62
|
+
* return an object representing the flags found in the passed arguments.
|
|
63
|
+
*
|
|
64
|
+
* By default, any arguments starting with `-` or `--` are considered boolean
|
|
65
|
+
* flags. If the argument name is followed by an equal sign (`=`) it is
|
|
66
|
+
* considered a key-value pair. Any arguments which could not be parsed are
|
|
67
|
+
* available in the `_` property of the returned object.
|
|
68
|
+
*
|
|
69
|
+
* By default, the flags module tries to determine the type of all arguments
|
|
70
|
+
* automatically and the return type of the `parse` method will have an index
|
|
71
|
+
* signature with `any` as value (`{ [x: string]: any }`).
|
|
31
72
|
*
|
|
73
|
+
* If the `string`, `boolean` or `collect` option is set, the return value of
|
|
74
|
+
* the `parse` method will be fully typed and the index signature of the return
|
|
75
|
+
* type will change to `{ [x: string]: unknown }`.
|
|
76
|
+
*
|
|
77
|
+
* Any arguments after `'--'` will not be parsed and will end up in `parsedArgs._`.
|
|
78
|
+
*
|
|
79
|
+
* Numeric-looking arguments will be returned as numbers unless `options.string`
|
|
80
|
+
* or `options.boolean` is set for that argument name.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
32
83
|
* ```ts
|
|
33
|
-
*
|
|
34
|
-
*
|
|
84
|
+
* import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
|
|
85
|
+
* const parsedArgs = parse(Deno.args);
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
|
|
91
|
+
* const parsedArgs = parse(["--foo", "--bar=baz", "./quux.txt"]);
|
|
92
|
+
* // parsedArgs: { foo: true, bar: "baz", _: ["./quux.txt"] }
|
|
35
93
|
* ```
|
|
36
94
|
*/
|
|
37
|
-
export function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, default: defaults = {}, stopEarly = false, string = [], unknown = (i) => i, } = {}) {
|
|
95
|
+
export function parse(args, { "--": doubleDash = false, alias = {}, boolean = false, default: defaults = {}, stopEarly = false, string = [], collect = [], negatable = [], unknown = (i) => i, } = {}) {
|
|
96
|
+
const aliases = {};
|
|
38
97
|
const flags = {
|
|
39
98
|
bools: {},
|
|
40
99
|
strings: {},
|
|
41
100
|
unknownFn: unknown,
|
|
42
101
|
allBools: false,
|
|
102
|
+
collect: {},
|
|
103
|
+
negatable: {},
|
|
43
104
|
};
|
|
44
|
-
if (boolean !== undefined) {
|
|
45
|
-
if (typeof boolean === "boolean") {
|
|
46
|
-
flags.allBools = !!boolean;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
const booleanArgs = typeof boolean === "string" ? [boolean] : boolean;
|
|
50
|
-
for (const key of booleanArgs.filter(Boolean)) {
|
|
51
|
-
flags.bools[key] = true;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const aliases = {};
|
|
56
105
|
if (alias !== undefined) {
|
|
57
106
|
for (const key in alias) {
|
|
58
107
|
const val = getForce(alias, key);
|
|
@@ -67,8 +116,29 @@ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = fa
|
|
|
67
116
|
}
|
|
68
117
|
}
|
|
69
118
|
}
|
|
119
|
+
if (boolean !== undefined) {
|
|
120
|
+
if (typeof boolean === "boolean") {
|
|
121
|
+
flags.allBools = !!boolean;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const booleanArgs = typeof boolean === "string"
|
|
125
|
+
? [boolean]
|
|
126
|
+
: boolean;
|
|
127
|
+
for (const key of booleanArgs.filter(Boolean)) {
|
|
128
|
+
flags.bools[key] = true;
|
|
129
|
+
const alias = get(aliases, key);
|
|
130
|
+
if (alias) {
|
|
131
|
+
for (const al of alias) {
|
|
132
|
+
flags.bools[al] = true;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
70
138
|
if (string !== undefined) {
|
|
71
|
-
const stringArgs = typeof string === "string"
|
|
139
|
+
const stringArgs = typeof string === "string"
|
|
140
|
+
? [string]
|
|
141
|
+
: string;
|
|
72
142
|
for (const key of stringArgs.filter(Boolean)) {
|
|
73
143
|
flags.strings[key] = true;
|
|
74
144
|
const alias = get(aliases, key);
|
|
@@ -79,6 +149,34 @@ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = fa
|
|
|
79
149
|
}
|
|
80
150
|
}
|
|
81
151
|
}
|
|
152
|
+
if (collect !== undefined) {
|
|
153
|
+
const collectArgs = typeof collect === "string"
|
|
154
|
+
? [collect]
|
|
155
|
+
: collect;
|
|
156
|
+
for (const key of collectArgs.filter(Boolean)) {
|
|
157
|
+
flags.collect[key] = true;
|
|
158
|
+
const alias = get(aliases, key);
|
|
159
|
+
if (alias) {
|
|
160
|
+
for (const al of alias) {
|
|
161
|
+
flags.collect[al] = true;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (negatable !== undefined) {
|
|
167
|
+
const negatableArgs = typeof negatable === "string"
|
|
168
|
+
? [negatable]
|
|
169
|
+
: negatable;
|
|
170
|
+
for (const key of negatableArgs.filter(Boolean)) {
|
|
171
|
+
flags.negatable[key] = true;
|
|
172
|
+
const alias = get(aliases, key);
|
|
173
|
+
if (alias) {
|
|
174
|
+
for (const al of alias) {
|
|
175
|
+
flags.negatable[al] = true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
82
180
|
const argv = { _: [] };
|
|
83
181
|
function argDefined(key, arg) {
|
|
84
182
|
return ((flags.allBools && /^--[^=]+$/.test(arg)) ||
|
|
@@ -86,8 +184,9 @@ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = fa
|
|
|
86
184
|
!!get(flags.strings, key) ||
|
|
87
185
|
!!get(aliases, key));
|
|
88
186
|
}
|
|
89
|
-
function setKey(obj,
|
|
187
|
+
function setKey(obj, name, value, collect = true) {
|
|
90
188
|
let o = obj;
|
|
189
|
+
const keys = name.split(".");
|
|
91
190
|
keys.slice(0, -1).forEach(function (key) {
|
|
92
191
|
if (get(o, key) === undefined) {
|
|
93
192
|
o[key] = {};
|
|
@@ -95,11 +194,13 @@ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = fa
|
|
|
95
194
|
o = get(o, key);
|
|
96
195
|
});
|
|
97
196
|
const key = keys[keys.length - 1];
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
typeof get(o, key) === "boolean") {
|
|
197
|
+
const collectable = collect && !!get(flags.collect, name);
|
|
198
|
+
if (!collectable) {
|
|
101
199
|
o[key] = value;
|
|
102
200
|
}
|
|
201
|
+
else if (get(o, key) === undefined) {
|
|
202
|
+
o[key] = [value];
|
|
203
|
+
}
|
|
103
204
|
else if (Array.isArray(get(o, key))) {
|
|
104
205
|
o[key].push(value);
|
|
105
206
|
}
|
|
@@ -107,26 +208,23 @@ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = fa
|
|
|
107
208
|
o[key] = [get(o, key), value];
|
|
108
209
|
}
|
|
109
210
|
}
|
|
110
|
-
function setArg(key, val, arg = undefined) {
|
|
211
|
+
function setArg(key, val, arg = undefined, collect) {
|
|
111
212
|
if (arg && flags.unknownFn && !argDefined(key, arg)) {
|
|
112
213
|
if (flags.unknownFn(arg, key, val) === false)
|
|
113
214
|
return;
|
|
114
215
|
}
|
|
115
216
|
const value = !get(flags.strings, key) && isNumber(val) ? Number(val) : val;
|
|
116
|
-
setKey(argv, key
|
|
217
|
+
setKey(argv, key, value, collect);
|
|
117
218
|
const alias = get(aliases, key);
|
|
118
219
|
if (alias) {
|
|
119
220
|
for (const x of alias) {
|
|
120
|
-
setKey(argv, x
|
|
221
|
+
setKey(argv, x, value, collect);
|
|
121
222
|
}
|
|
122
223
|
}
|
|
123
224
|
}
|
|
124
225
|
function aliasIsBoolean(key) {
|
|
125
226
|
return getForce(aliases, key).some((x) => typeof get(flags.bools, x) === "boolean");
|
|
126
227
|
}
|
|
127
|
-
for (const key of Object.keys(flags.bools)) {
|
|
128
|
-
setArg(key, defaults[key] === undefined ? false : defaults[key]);
|
|
129
|
-
}
|
|
130
228
|
let notFlags = [];
|
|
131
229
|
// all args after "--" are not parsed
|
|
132
230
|
if (args.includes("--")) {
|
|
@@ -147,10 +245,10 @@ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = fa
|
|
|
147
245
|
setArg(key, value, arg);
|
|
148
246
|
}
|
|
149
247
|
}
|
|
150
|
-
else if (/^--no-.+/.test(arg)) {
|
|
248
|
+
else if (/^--no-.+/.test(arg) && get(flags.negatable, arg.replace(/^--no-/, ""))) {
|
|
151
249
|
const m = arg.match(/^--no-(.+)/);
|
|
152
250
|
assert(m != null);
|
|
153
|
-
setArg(m[1], false, arg);
|
|
251
|
+
setArg(m[1], false, arg, false);
|
|
154
252
|
}
|
|
155
253
|
else if (/^--.+/.test(arg)) {
|
|
156
254
|
const m = arg.match(/^--(.+)/);
|
|
@@ -230,16 +328,27 @@ export function parse(args, { "--": doubleDash = false, alias = {}, boolean = fa
|
|
|
230
328
|
}
|
|
231
329
|
}
|
|
232
330
|
}
|
|
233
|
-
for (const key of Object.
|
|
331
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
234
332
|
if (!hasKey(argv, key.split("."))) {
|
|
235
|
-
setKey(argv, key
|
|
333
|
+
setKey(argv, key, value);
|
|
236
334
|
if (aliases[key]) {
|
|
237
335
|
for (const x of aliases[key]) {
|
|
238
|
-
setKey(argv, x
|
|
336
|
+
setKey(argv, x, value);
|
|
239
337
|
}
|
|
240
338
|
}
|
|
241
339
|
}
|
|
242
340
|
}
|
|
341
|
+
for (const key of Object.keys(flags.bools)) {
|
|
342
|
+
if (!hasKey(argv, key.split("."))) {
|
|
343
|
+
const value = get(flags.collect, key) ? [] : false;
|
|
344
|
+
setKey(argv, key, value, false);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
for (const key of Object.keys(flags.strings)) {
|
|
348
|
+
if (!hasKey(argv, key.split(".")) && get(flags.collect, key)) {
|
|
349
|
+
setKey(argv, key, [], false);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
243
352
|
if (doubleDash) {
|
|
244
353
|
argv["--"] = [];
|
|
245
354
|
for (const key of notFlags) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2018-
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
3
|
import { SEP } from "./separator.js";
|
|
4
4
|
/** Determines the common path from a set of paths, using an optional separator,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2018-
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
3
|
import { isWindows, osType } from "../_util/os.js";
|
|
4
4
|
import { SEP, SEP_PATTERN } from "./separator.js";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// Copyright the Browserify authors. MIT License.
|
|
3
|
+
// Ported mostly from https://github.com/browserify/path-browserify/
|
|
4
|
+
/**
|
|
5
|
+
* Utilities for working with OS-specific file paths.
|
|
6
|
+
*
|
|
7
|
+
* Codes in the examples uses POSIX path but it automatically use Windows path
|
|
8
|
+
* on Windows. Use methods under `posix` or `win32` object instead to handle non
|
|
9
|
+
* platform specific path like:
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { posix, win32 } from "https://deno.land/std@$STD_VERSION/path/mod.ts";
|
|
12
|
+
* const p1 = posix.fromFileUrl("file:///home/foo");
|
|
13
|
+
* const p2 = win32.fromFileUrl("file:///home/foo");
|
|
14
|
+
* console.log(p1); // "/home/foo"
|
|
15
|
+
* console.log(p2); // "\\home\\foo"
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* This module is browser compatible.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
import { isWindows } from "../_util/os.js";
|
|
23
|
+
import * as _win32 from "./win32.js";
|
|
24
|
+
import * as _posix from "./posix.js";
|
|
25
|
+
const path = isWindows ? _win32 : _posix;
|
|
26
|
+
export const win32 = _win32;
|
|
27
|
+
export const posix = _posix;
|
|
28
|
+
export const { basename, delimiter, dirname, extname, format, fromFileUrl, isAbsolute, join, normalize, parse, relative, resolve, sep, toFileUrl, toNamespacedPath, } = path;
|
|
29
|
+
export * from "./common.js";
|
|
30
|
+
export { SEP, SEP_PATTERN } from "./separator.js";
|
|
31
|
+
export * from "./_interface.js";
|
|
32
|
+
export * from "./glob.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
1
2
|
// Copyright the Browserify authors. MIT License.
|
|
2
3
|
// Ported from https://github.com/browserify/path-browserify/
|
|
3
4
|
// This module is browser compatible.
|
|
@@ -51,6 +52,8 @@ export function resolve(...pathSegments) {
|
|
|
51
52
|
}
|
|
52
53
|
/**
|
|
53
54
|
* Normalize the `path`, resolving `'..'` and `'.'` segments.
|
|
55
|
+
* Note that resolving these segments does not necessarily mean that all will be eliminated.
|
|
56
|
+
* A `'..'` at the top-level will be preserved, and an empty path is canonically `'.'`.
|
|
54
57
|
* @param path to be normalized
|
|
55
58
|
*/
|
|
56
59
|
export function normalize(path) {
|
|
@@ -199,8 +202,8 @@ export function toNamespacedPath(path) {
|
|
|
199
202
|
return path;
|
|
200
203
|
}
|
|
201
204
|
/**
|
|
202
|
-
* Return the directory
|
|
203
|
-
* @param path to determine
|
|
205
|
+
* Return the directory path of a `path`.
|
|
206
|
+
* @param path to determine the directory path for
|
|
204
207
|
*/
|
|
205
208
|
export function dirname(path) {
|
|
206
209
|
assertPath(path);
|
|
@@ -248,7 +251,7 @@ export function basename(path, ext = "") {
|
|
|
248
251
|
let firstNonSlashEnd = -1;
|
|
249
252
|
for (i = path.length - 1; i >= 0; --i) {
|
|
250
253
|
const code = path.charCodeAt(i);
|
|
251
|
-
if (code
|
|
254
|
+
if (isPosixPathSeparator(code)) {
|
|
252
255
|
// If we reached a path separator that was not part of a set of path
|
|
253
256
|
// separators at the end of the string, stop now
|
|
254
257
|
if (!matchedSlash) {
|
|
@@ -258,38 +261,38 @@ export function basename(path, ext = "") {
|
|
|
258
261
|
}
|
|
259
262
|
else {
|
|
260
263
|
if (firstNonSlashEnd === -1) {
|
|
261
|
-
// We saw the first non-path separator,
|
|
262
|
-
//
|
|
264
|
+
// We saw the first non-path separator, mark this as the end of our
|
|
265
|
+
// path component in case we don't match a whole suffix
|
|
263
266
|
matchedSlash = false;
|
|
264
267
|
firstNonSlashEnd = i + 1;
|
|
268
|
+
end = firstNonSlashEnd;
|
|
265
269
|
}
|
|
266
270
|
if (extIdx >= 0) {
|
|
267
|
-
// Try to match the explicit
|
|
271
|
+
// Try to match the explicit suffix
|
|
268
272
|
if (code === ext.charCodeAt(extIdx)) {
|
|
269
273
|
if (--extIdx === -1) {
|
|
270
|
-
// We matched
|
|
274
|
+
// We matched whole suffix, so mark this as the end of our path
|
|
271
275
|
// component
|
|
272
276
|
end = i;
|
|
273
277
|
}
|
|
274
278
|
}
|
|
275
279
|
else {
|
|
276
|
-
//
|
|
277
|
-
//
|
|
280
|
+
// Suffix character does not match, so bail out early
|
|
281
|
+
// from checking rest of characters
|
|
278
282
|
extIdx = -1;
|
|
279
|
-
end = firstNonSlashEnd;
|
|
280
283
|
}
|
|
281
284
|
}
|
|
282
285
|
}
|
|
283
286
|
}
|
|
287
|
+
if (end === -1)
|
|
288
|
+
return "";
|
|
284
289
|
if (start === end)
|
|
285
290
|
end = firstNonSlashEnd;
|
|
286
|
-
else if (end === -1)
|
|
287
|
-
end = path.length;
|
|
288
291
|
return path.slice(start, end);
|
|
289
292
|
}
|
|
290
293
|
else {
|
|
291
294
|
for (i = path.length - 1; i >= 0; --i) {
|
|
292
|
-
if (path.charCodeAt(i)
|
|
295
|
+
if (isPosixPathSeparator(path.charCodeAt(i))) {
|
|
293
296
|
// If we reached a path separator that was not part of a set of path
|
|
294
297
|
// separators at the end of the string, stop now
|
|
295
298
|
if (!matchedSlash) {
|
|
@@ -310,8 +313,9 @@ export function basename(path, ext = "") {
|
|
|
310
313
|
}
|
|
311
314
|
}
|
|
312
315
|
/**
|
|
313
|
-
* Return the extension of the `path
|
|
316
|
+
* Return the extension of the `path` with leading period.
|
|
314
317
|
* @param path with extension
|
|
318
|
+
* @returns extension (ex. for `file.ts` returns `.ts`)
|
|
315
319
|
*/
|
|
316
320
|
export function extname(path) {
|
|
317
321
|
assertPath(path);
|
|
@@ -465,7 +469,7 @@ export function parse(path) {
|
|
|
465
469
|
* Converts a file URL to a path string.
|
|
466
470
|
*
|
|
467
471
|
* ```ts
|
|
468
|
-
* import { fromFileUrl } from "
|
|
472
|
+
* import { fromFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
|
|
469
473
|
* fromFileUrl("file:///home/foo"); // "/home/foo"
|
|
470
474
|
* ```
|
|
471
475
|
* @param url of a file URL
|
|
@@ -481,7 +485,7 @@ export function fromFileUrl(url) {
|
|
|
481
485
|
* Converts a path string to a file URL.
|
|
482
486
|
*
|
|
483
487
|
* ```ts
|
|
484
|
-
* import { toFileUrl } from "
|
|
488
|
+
* import { toFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
|
|
485
489
|
* toFileUrl("/home/foo"); // new URL("file:///home/foo")
|
|
486
490
|
* ```
|
|
487
491
|
* @param path to convert to file URL
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2018-
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
3
|
import { isWindows } from "../_util/os.js";
|
|
4
4
|
export const SEP = isWindows ? "\\" : "/";
|