@optique/run 1.0.0-dev.729 → 1.0.0-dev.737
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/dist/valueparser.cjs +9 -3
- package/dist/valueparser.d.cts +2 -0
- package/dist/valueparser.d.ts +2 -0
- package/dist/valueparser.js +10 -4
- package/package.json +2 -2
package/dist/valueparser.cjs
CHANGED
|
@@ -14,6 +14,8 @@ const node_fs = require_rolldown_runtime.__toESM(require("node:fs"));
|
|
|
14
14
|
*
|
|
15
15
|
* @param options Configuration options for path validation.
|
|
16
16
|
* @returns A ValueParser that validates and returns string paths.
|
|
17
|
+
* @throws {TypeError} If any entry in {@link PathOptionsBase.extensions} does
|
|
18
|
+
* not start with a dot (e.g., `"json"` instead of `".json"`).
|
|
17
19
|
*
|
|
18
20
|
* @example
|
|
19
21
|
* ```typescript
|
|
@@ -43,6 +45,9 @@ const node_fs = require_rolldown_runtime.__toESM(require("node:fs"));
|
|
|
43
45
|
function path(options = {}) {
|
|
44
46
|
const { metavar = "PATH", type = "either", allowCreate = false, extensions } = options;
|
|
45
47
|
(0, __optique_core_nonempty.ensureNonEmptyString)(metavar);
|
|
48
|
+
if (extensions) {
|
|
49
|
+
for (const ext of extensions) if (!ext.startsWith(".")) throw new TypeError(`Each extension must start with a dot, got: ${JSON.stringify(ext)}`);
|
|
50
|
+
}
|
|
46
51
|
const mustExist = "mustExist" in options ? options.mustExist : false;
|
|
47
52
|
const mustNotExist = "mustNotExist" in options ? options.mustNotExist : false;
|
|
48
53
|
return {
|
|
@@ -50,9 +55,10 @@ function path(options = {}) {
|
|
|
50
55
|
metavar,
|
|
51
56
|
parse(input) {
|
|
52
57
|
if (extensions && extensions.length > 0) {
|
|
53
|
-
const
|
|
54
|
-
if (!extensions.
|
|
55
|
-
const
|
|
58
|
+
const base = /[/\\]$/.test(input) ? "" : (0, node_path.basename)(input);
|
|
59
|
+
if (!extensions.some((ext) => base.endsWith(ext))) {
|
|
60
|
+
const ext = (0, node_path.extname)(input);
|
|
61
|
+
const actualExt = ext || (base.startsWith(".") ? base : "no extension");
|
|
56
62
|
return {
|
|
57
63
|
success: false,
|
|
58
64
|
error: options.errors?.invalidExtension ? typeof options.errors.invalidExtension === "function" ? options.errors.invalidExtension(input, extensions, actualExt) : options.errors.invalidExtension : __optique_core_message.message`Expected file with extension ${(0, __optique_core_message.text)(extensions.join(", "))}, got ${(0, __optique_core_message.text)(actualExt)}.`
|
package/dist/valueparser.d.cts
CHANGED
|
@@ -143,6 +143,8 @@ type PathOptions = PathOptionsMustExist | PathOptionsMustNotExist | PathOptionsN
|
|
|
143
143
|
*
|
|
144
144
|
* @param options Configuration options for path validation.
|
|
145
145
|
* @returns A ValueParser that validates and returns string paths.
|
|
146
|
+
* @throws {TypeError} If any entry in {@link PathOptionsBase.extensions} does
|
|
147
|
+
* not start with a dot (e.g., `"json"` instead of `".json"`).
|
|
146
148
|
*
|
|
147
149
|
* @example
|
|
148
150
|
* ```typescript
|
package/dist/valueparser.d.ts
CHANGED
|
@@ -143,6 +143,8 @@ type PathOptions = PathOptionsMustExist | PathOptionsMustNotExist | PathOptionsN
|
|
|
143
143
|
*
|
|
144
144
|
* @param options Configuration options for path validation.
|
|
145
145
|
* @returns A ValueParser that validates and returns string paths.
|
|
146
|
+
* @throws {TypeError} If any entry in {@link PathOptionsBase.extensions} does
|
|
147
|
+
* not start with a dot (e.g., `"json"` instead of `".json"`).
|
|
146
148
|
*
|
|
147
149
|
* @example
|
|
148
150
|
* ```typescript
|
package/dist/valueparser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dirname, extname } from "node:path";
|
|
1
|
+
import { basename, dirname, extname } from "node:path";
|
|
2
2
|
import { message, text } from "@optique/core/message";
|
|
3
3
|
import { ensureNonEmptyString } from "@optique/core/nonempty";
|
|
4
4
|
import { existsSync, statSync } from "node:fs";
|
|
@@ -13,6 +13,8 @@ import { existsSync, statSync } from "node:fs";
|
|
|
13
13
|
*
|
|
14
14
|
* @param options Configuration options for path validation.
|
|
15
15
|
* @returns A ValueParser that validates and returns string paths.
|
|
16
|
+
* @throws {TypeError} If any entry in {@link PathOptionsBase.extensions} does
|
|
17
|
+
* not start with a dot (e.g., `"json"` instead of `".json"`).
|
|
16
18
|
*
|
|
17
19
|
* @example
|
|
18
20
|
* ```typescript
|
|
@@ -42,6 +44,9 @@ import { existsSync, statSync } from "node:fs";
|
|
|
42
44
|
function path(options = {}) {
|
|
43
45
|
const { metavar = "PATH", type = "either", allowCreate = false, extensions } = options;
|
|
44
46
|
ensureNonEmptyString(metavar);
|
|
47
|
+
if (extensions) {
|
|
48
|
+
for (const ext of extensions) if (!ext.startsWith(".")) throw new TypeError(`Each extension must start with a dot, got: ${JSON.stringify(ext)}`);
|
|
49
|
+
}
|
|
45
50
|
const mustExist = "mustExist" in options ? options.mustExist : false;
|
|
46
51
|
const mustNotExist = "mustNotExist" in options ? options.mustNotExist : false;
|
|
47
52
|
return {
|
|
@@ -49,9 +54,10 @@ function path(options = {}) {
|
|
|
49
54
|
metavar,
|
|
50
55
|
parse(input) {
|
|
51
56
|
if (extensions && extensions.length > 0) {
|
|
52
|
-
const
|
|
53
|
-
if (!extensions.
|
|
54
|
-
const
|
|
57
|
+
const base = /[/\\]$/.test(input) ? "" : basename(input);
|
|
58
|
+
if (!extensions.some((ext) => base.endsWith(ext))) {
|
|
59
|
+
const ext = extname(input);
|
|
60
|
+
const actualExt = ext || (base.startsWith(".") ? base : "no extension");
|
|
55
61
|
return {
|
|
56
62
|
success: false,
|
|
57
63
|
error: options.errors?.invalidExtension ? typeof options.errors.invalidExtension === "function" ? options.errors.invalidExtension(input, extensions, actualExt) : options.errors.invalidExtension : message`Expected file with extension ${text(extensions.join(", "))}, got ${text(actualExt)}.`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/run",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.737+e9077af1",
|
|
4
4
|
"description": "Type-safe combinatorial command-line interface parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
},
|
|
71
71
|
"sideEffects": false,
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@optique/core": "1.0.0-dev.
|
|
73
|
+
"@optique/core": "1.0.0-dev.737+e9077af1"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/node": "^20.19.9",
|