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
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
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
|
+
|
|
21
|
+
## [2.1.0] - 2022-04-03
|
|
22
|
+
### Added
|
|
23
|
+
- Support for `[YANKED]` releases [#25]
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
- Updated dependencies
|
|
27
|
+
|
|
10
28
|
## [2.0.1] - 2022-01-09
|
|
11
29
|
### Fixed
|
|
12
30
|
- Updated deps.
|
|
@@ -21,6 +39,14 @@ New version merging Deno and Node code using Deno's `dnt` package.
|
|
|
21
39
|
|
|
22
40
|
[#21]: https://github.com/oscarotero/keep-a-changelog/issues/21
|
|
23
41
|
[#23]: https://github.com/oscarotero/keep-a-changelog/issues/23
|
|
24
|
-
|
|
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
|
|
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
|
|
50
|
+
[2.1.0]: https://github.com/oscarotero/keep-a-changelog/compare/v2.0.1...v2.1.0
|
|
25
51
|
[2.0.1]: https://github.com/oscarotero/keep-a-changelog/compare/v2.0.0...v2.0.1
|
|
26
52
|
[2.0.0]: https://github.com/oscarotero/keep-a-changelog/releases/tag/v2.0.0
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ console.log(changelog.toString());
|
|
|
22
22
|
## Usage in Deno
|
|
23
23
|
|
|
24
24
|
```js
|
|
25
|
-
import { parser } from "https://deno.land/x/changelog@
|
|
25
|
+
import { parser } from "https://deno.land/x/changelog@v2.0.0/mod.ts";
|
|
26
26
|
|
|
27
27
|
//Parse a changelog file
|
|
28
28
|
const changelog = parser(await Deno.readTextFile("CHANGELOG.md"));
|
|
@@ -34,7 +34,10 @@ console.log(changelog.toString());
|
|
|
34
34
|
### Create a new changelog
|
|
35
35
|
|
|
36
36
|
```js
|
|
37
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
Changelog,
|
|
39
|
+
Release,
|
|
40
|
+
} from "https://deno.land/x/changelog@v2.0.0/mod.ts";
|
|
38
41
|
|
|
39
42
|
const changelog = new Changelog("My project")
|
|
40
43
|
.addRelease(
|
|
@@ -53,6 +56,17 @@ const changelog = new Changelog("My project")
|
|
|
53
56
|
console.log(changelog.toString());
|
|
54
57
|
```
|
|
55
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
|
+
|
|
56
70
|
### Custom tag names
|
|
57
71
|
|
|
58
72
|
By default, the tag names are `v` + version number. For example, the tag for the
|
|
@@ -70,10 +84,10 @@ By default and according to the
|
|
|
70
84
|
[keepachangelog](http://keepachangelog.com/en/1.0.0/) format, the change types
|
|
71
85
|
are `Added`, `Changed`, `Deprecated`, `Removed`, `Fixed`, and `Security`.
|
|
72
86
|
|
|
73
|
-
In case you'd like add another type
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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.
|
|
77
91
|
|
|
78
92
|
For example, we would like to add a type `Maintenance`. Extend the provided
|
|
79
93
|
`Release` class:
|
|
@@ -157,6 +171,7 @@ Available options:
|
|
|
157
171
|
|
|
158
172
|
| Option | Description |
|
|
159
173
|
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
174
|
+
| `--format` | The output format for the generated markdown. It can be `markdownlint` or `compact`. The default value is `compact`. |
|
|
160
175
|
| `--file` | The markdown file of the changelog. The default value is `CHANGELOG.md`. |
|
|
161
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. |
|
|
162
177
|
| `--https` | Set to false to use `http` instead `https` in the url (`--https=false`). |
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
|
|
2
|
+
if (!Object.hasOwn) {
|
|
3
|
+
Object.defineProperty(Object, "hasOwn", {
|
|
4
|
+
value: function (object, property) {
|
|
5
|
+
if (object == null) {
|
|
6
|
+
throw new TypeError("Cannot convert undefined or null to object");
|
|
7
|
+
}
|
|
8
|
+
return Object.prototype.hasOwnProperty.call(Object(object), property);
|
|
9
|
+
},
|
|
10
|
+
configurable: true,
|
|
11
|
+
enumerable: false,
|
|
12
|
+
writable: true,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export {};
|
package/esm/bin.js
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import "./_dnt.polyfills.js";
|
|
2
3
|
import * as dntShim from "./_dnt.shims.js";
|
|
3
|
-
import { join } from "./deps/
|
|
4
|
+
import { join } from "./deps/deno.land/std@0.173.0/path/mod.js";
|
|
4
5
|
import { Changelog, parser, Release } from "./mod.js";
|
|
5
|
-
import { parse as parseFlag } from "./deps/
|
|
6
|
-
import { parse as parseIni } from "./deps/
|
|
6
|
+
import { parse as parseFlag } from "./deps/deno.land/std@0.173.0/flags/mod.js";
|
|
7
|
+
import { parse as parseIni } from "./deps/deno.land/x/ini@v2.1.0/mod.js";
|
|
7
8
|
const argv = parseFlag(dntShim.Deno.args, {
|
|
8
9
|
default: {
|
|
9
10
|
file: "CHANGELOG.md",
|
|
11
|
+
format: "compact",
|
|
10
12
|
release: null,
|
|
11
13
|
url: null,
|
|
12
14
|
https: true,
|
|
13
15
|
quiet: false,
|
|
14
16
|
},
|
|
17
|
+
string: ["file", "format", "release", "url"],
|
|
15
18
|
boolean: ["https", "init", "latest-release", "quiet"],
|
|
16
19
|
});
|
|
17
20
|
const file = join(dntShim.Deno.cwd(), argv.file);
|
|
18
21
|
try {
|
|
19
22
|
if (argv.init) {
|
|
20
23
|
const changelog = new Changelog("Changelog").addRelease(new Release("0.1.0", new Date(), "First version"));
|
|
24
|
+
changelog.format = argv.format;
|
|
21
25
|
save(file, changelog, true);
|
|
22
26
|
dntShim.Deno.exit(0);
|
|
23
27
|
}
|
|
24
28
|
const changelog = parser(dntShim.Deno.readTextFileSync(file));
|
|
25
|
-
|
|
29
|
+
changelog.format = argv.format;
|
|
30
|
+
if (argv["latest-release"]) {
|
|
26
31
|
const release = changelog.releases.find((release) => release.date && release.version);
|
|
27
32
|
if (release) {
|
|
28
33
|
console.log(release.version?.toString());
|
|
@@ -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,3 +1,5 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
1
3
|
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
4
|
export const osType = (() => {
|
|
3
5
|
// deno-lint-ignore no-explicit-any
|
|
@@ -7,9 +9,10 @@ export const osType = (() => {
|
|
|
7
9
|
}
|
|
8
10
|
// deno-lint-ignore no-explicit-any
|
|
9
11
|
const { navigator } = dntShim.dntGlobalThis;
|
|
10
|
-
if (navigator?.appVersion?.includes?.("Win")
|
|
12
|
+
if (navigator?.appVersion?.includes?.("Win")) {
|
|
11
13
|
return "windows";
|
|
12
14
|
}
|
|
13
15
|
return "linux";
|
|
14
16
|
})();
|
|
15
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,7 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// Copyright the Browserify authors. MIT License.
|
|
3
|
+
// Ported from https://github.com/browserify/path-browserify/
|
|
4
|
+
// This module is browser compatible.
|
|
1
5
|
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
6
|
import { CHAR_DOT, CHAR_FORWARD_SLASH } from "./_constants.js";
|
|
3
7
|
import { _format, assertPath, encodeWhitespace, isPosixPathSeparator, normalizeString, } from "./_util.js";
|
|
@@ -48,6 +52,8 @@ export function resolve(...pathSegments) {
|
|
|
48
52
|
}
|
|
49
53
|
/**
|
|
50
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 `'.'`.
|
|
51
57
|
* @param path to be normalized
|
|
52
58
|
*/
|
|
53
59
|
export function normalize(path) {
|
|
@@ -196,8 +202,8 @@ export function toNamespacedPath(path) {
|
|
|
196
202
|
return path;
|
|
197
203
|
}
|
|
198
204
|
/**
|
|
199
|
-
* Return the directory
|
|
200
|
-
* @param path to determine
|
|
205
|
+
* Return the directory path of a `path`.
|
|
206
|
+
* @param path to determine the directory path for
|
|
201
207
|
*/
|
|
202
208
|
export function dirname(path) {
|
|
203
209
|
assertPath(path);
|
|
@@ -245,7 +251,7 @@ export function basename(path, ext = "") {
|
|
|
245
251
|
let firstNonSlashEnd = -1;
|
|
246
252
|
for (i = path.length - 1; i >= 0; --i) {
|
|
247
253
|
const code = path.charCodeAt(i);
|
|
248
|
-
if (code
|
|
254
|
+
if (isPosixPathSeparator(code)) {
|
|
249
255
|
// If we reached a path separator that was not part of a set of path
|
|
250
256
|
// separators at the end of the string, stop now
|
|
251
257
|
if (!matchedSlash) {
|
|
@@ -255,38 +261,38 @@ export function basename(path, ext = "") {
|
|
|
255
261
|
}
|
|
256
262
|
else {
|
|
257
263
|
if (firstNonSlashEnd === -1) {
|
|
258
|
-
// We saw the first non-path separator,
|
|
259
|
-
//
|
|
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
|
|
260
266
|
matchedSlash = false;
|
|
261
267
|
firstNonSlashEnd = i + 1;
|
|
268
|
+
end = firstNonSlashEnd;
|
|
262
269
|
}
|
|
263
270
|
if (extIdx >= 0) {
|
|
264
|
-
// Try to match the explicit
|
|
271
|
+
// Try to match the explicit suffix
|
|
265
272
|
if (code === ext.charCodeAt(extIdx)) {
|
|
266
273
|
if (--extIdx === -1) {
|
|
267
|
-
// We matched
|
|
274
|
+
// We matched whole suffix, so mark this as the end of our path
|
|
268
275
|
// component
|
|
269
276
|
end = i;
|
|
270
277
|
}
|
|
271
278
|
}
|
|
272
279
|
else {
|
|
273
|
-
//
|
|
274
|
-
//
|
|
280
|
+
// Suffix character does not match, so bail out early
|
|
281
|
+
// from checking rest of characters
|
|
275
282
|
extIdx = -1;
|
|
276
|
-
end = firstNonSlashEnd;
|
|
277
283
|
}
|
|
278
284
|
}
|
|
279
285
|
}
|
|
280
286
|
}
|
|
287
|
+
if (end === -1)
|
|
288
|
+
return "";
|
|
281
289
|
if (start === end)
|
|
282
290
|
end = firstNonSlashEnd;
|
|
283
|
-
else if (end === -1)
|
|
284
|
-
end = path.length;
|
|
285
291
|
return path.slice(start, end);
|
|
286
292
|
}
|
|
287
293
|
else {
|
|
288
294
|
for (i = path.length - 1; i >= 0; --i) {
|
|
289
|
-
if (path.charCodeAt(i)
|
|
295
|
+
if (isPosixPathSeparator(path.charCodeAt(i))) {
|
|
290
296
|
// If we reached a path separator that was not part of a set of path
|
|
291
297
|
// separators at the end of the string, stop now
|
|
292
298
|
if (!matchedSlash) {
|
|
@@ -307,8 +313,9 @@ export function basename(path, ext = "") {
|
|
|
307
313
|
}
|
|
308
314
|
}
|
|
309
315
|
/**
|
|
310
|
-
* Return the extension of the `path
|
|
316
|
+
* Return the extension of the `path` with leading period.
|
|
311
317
|
* @param path with extension
|
|
318
|
+
* @returns extension (ex. for `file.ts` returns `.ts`)
|
|
312
319
|
*/
|
|
313
320
|
export function extname(path) {
|
|
314
321
|
assertPath(path);
|
|
@@ -462,7 +469,7 @@ export function parse(path) {
|
|
|
462
469
|
* Converts a file URL to a path string.
|
|
463
470
|
*
|
|
464
471
|
* ```ts
|
|
465
|
-
* import { fromFileUrl } from "
|
|
472
|
+
* import { fromFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
|
|
466
473
|
* fromFileUrl("file:///home/foo"); // "/home/foo"
|
|
467
474
|
* ```
|
|
468
475
|
* @param url of a file URL
|
|
@@ -478,7 +485,7 @@ export function fromFileUrl(url) {
|
|
|
478
485
|
* Converts a path string to a file URL.
|
|
479
486
|
*
|
|
480
487
|
* ```ts
|
|
481
|
-
* import { toFileUrl } from "
|
|
488
|
+
* import { toFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
|
|
482
489
|
* toFileUrl("/home/foo"); // new URL("file:///home/foo")
|
|
483
490
|
* ```
|
|
484
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 ? "\\" : "/";
|