inquirerer 2.1.13 → 2.2.0
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/README.md +13 -0
- package/esm/prompt.js +17 -0
- package/esm/resolvers/workspace.js +27 -0
- package/esm/utils.js +1 -1
- package/package.json +6 -6
- package/prompt.d.ts +5 -0
- package/prompt.js +17 -0
- package/question/types.d.ts +1 -0
- package/resolvers/workspace.js +27 -0
package/README.md
CHANGED
|
@@ -747,6 +747,19 @@ Inquirerer comes with several built-in resolvers ready to use:
|
|
|
747
747
|
| `date.now` | ISO timestamp | `"2025-11-23T15:30:45.123Z"` |
|
|
748
748
|
| `date.timestamp` | Unix timestamp (ms) | `"1732375845123"` |
|
|
749
749
|
|
|
750
|
+
#### Workspace (nearest package.json)
|
|
751
|
+
|
|
752
|
+
| Resolver | Description | Example Output |
|
|
753
|
+
|----------|-------------|----------------|
|
|
754
|
+
| `workspace.name` | Repo slug from `repository` URL (fallback: `package.json` `name`) | `"dev-utils"` |
|
|
755
|
+
| `workspace.repo.name` | Repo name from `repository` URL | `"dev-utils"` |
|
|
756
|
+
| `workspace.repo.organization` | Repo org/owner from `repository` URL | `"constructive-io"` |
|
|
757
|
+
| `workspace.organization.name` | Alias for `workspace.repo.organization` | `"constructive-io"` |
|
|
758
|
+
| `workspace.license` | License field from `package.json` | `"MIT"` |
|
|
759
|
+
| `workspace.author` | Author name from `package.json` | `"Constructive"` |
|
|
760
|
+
| `workspace.author.name` | Author name from `package.json` | `"Constructive"` |
|
|
761
|
+
| `workspace.author.email` | Author email from `package.json` | `"email@example.org"` |
|
|
762
|
+
|
|
750
763
|
### Priority Order
|
|
751
764
|
|
|
752
765
|
When resolving default values, inquirerer follows this priority:
|
package/esm/prompt.js
CHANGED
|
@@ -346,6 +346,8 @@ export class Inquirerer {
|
|
|
346
346
|
let obj = shouldMutate ? argv : { ...argv };
|
|
347
347
|
// Resolve dynamic defaults before processing questions
|
|
348
348
|
await this.resolveDynamicDefaults(questions);
|
|
349
|
+
// Resolve dynamic options before processing questions
|
|
350
|
+
await this.resolveOptionsFrom(questions);
|
|
349
351
|
// Resolve setFrom values - these bypass prompting entirely
|
|
350
352
|
await this.resolveSetValues(questions, obj);
|
|
351
353
|
// first loop through the question, and set any overrides in case other questions use objs for validation
|
|
@@ -465,6 +467,21 @@ export class Inquirerer {
|
|
|
465
467
|
}
|
|
466
468
|
}
|
|
467
469
|
}
|
|
470
|
+
/**
|
|
471
|
+
* Resolves optionsFrom values for all questions that have optionsFrom specified.
|
|
472
|
+
* Updates the question.options property with the resolved array.
|
|
473
|
+
*/
|
|
474
|
+
async resolveOptionsFrom(questions) {
|
|
475
|
+
for (const question of questions) {
|
|
476
|
+
if ('optionsFrom' in question && question.optionsFrom) {
|
|
477
|
+
const resolved = await this.resolverRegistry.resolve(question.optionsFrom);
|
|
478
|
+
if (resolved !== undefined && Array.isArray(resolved)) {
|
|
479
|
+
// Update question.options with resolved array
|
|
480
|
+
question.options = resolved;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
468
485
|
applyDefaultValues(questions, obj) {
|
|
469
486
|
questions.forEach(question => {
|
|
470
487
|
if ('default' in question) {
|
|
@@ -72,6 +72,19 @@ function parseAuthor(author) {
|
|
|
72
72
|
* These resolve values from the nearest package.json in the current working directory.
|
|
73
73
|
*/
|
|
74
74
|
export const workspaceResolvers = {
|
|
75
|
+
'workspace.name': () => {
|
|
76
|
+
const pkg = findPackageJsonFromCwd();
|
|
77
|
+
if (!pkg)
|
|
78
|
+
return undefined;
|
|
79
|
+
const url = getRepositoryUrl(pkg);
|
|
80
|
+
// Prefer repo slug when repository is set; fall back to package name
|
|
81
|
+
if (url) {
|
|
82
|
+
const parsed = parseGitHubUrl(url);
|
|
83
|
+
if (parsed.name)
|
|
84
|
+
return parsed.name;
|
|
85
|
+
}
|
|
86
|
+
return pkg.name;
|
|
87
|
+
},
|
|
75
88
|
'workspace.repo.name': () => {
|
|
76
89
|
const pkg = findPackageJsonFromCwd();
|
|
77
90
|
if (!pkg)
|
|
@@ -90,6 +103,20 @@ export const workspaceResolvers = {
|
|
|
90
103
|
return undefined;
|
|
91
104
|
return parseGitHubUrl(url).organization;
|
|
92
105
|
},
|
|
106
|
+
// Alias for repo.organization for template readability
|
|
107
|
+
'workspace.organization.name': () => {
|
|
108
|
+
const pkg = findPackageJsonFromCwd();
|
|
109
|
+
if (!pkg)
|
|
110
|
+
return undefined;
|
|
111
|
+
const url = getRepositoryUrl(pkg);
|
|
112
|
+
if (!url)
|
|
113
|
+
return undefined;
|
|
114
|
+
return parseGitHubUrl(url).organization;
|
|
115
|
+
},
|
|
116
|
+
'workspace.license': () => {
|
|
117
|
+
const pkg = findPackageJsonFromCwd();
|
|
118
|
+
return pkg?.license;
|
|
119
|
+
},
|
|
93
120
|
'workspace.author': () => {
|
|
94
121
|
const pkg = findPackageJsonFromCwd();
|
|
95
122
|
if (!pkg)
|
package/esm/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { green, blue } from 'yanse';
|
|
2
|
-
import { findAndRequirePackageJson } from
|
|
2
|
+
import { findAndRequirePackageJson } from 'find-and-require-package-json';
|
|
3
3
|
// Function to display the version information
|
|
4
4
|
export function displayVersion() {
|
|
5
5
|
const pkg = findAndRequirePackageJson(__dirname);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inquirerer",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"author": "Constructive <
|
|
3
|
+
"version": "2.2.0",
|
|
4
|
+
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "TypeScript-first library for building beautiful CLI interfaces with interactive prompts",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"module": "esm/index.js",
|
|
@@ -30,16 +30,16 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"deepmerge": "^4.3.1",
|
|
33
|
-
"find-and-require-package-json": "0.8.
|
|
33
|
+
"find-and-require-package-json": "0.8.2",
|
|
34
34
|
"js-yaml": "^4.1.0",
|
|
35
35
|
"minimist": "^1.2.8",
|
|
36
|
-
"yanse": "0.1.
|
|
36
|
+
"yanse": "0.1.8"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [],
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/minimist": "^1.2.5",
|
|
41
|
-
"clean-ansi": "0.1.
|
|
41
|
+
"clean-ansi": "0.1.5",
|
|
42
42
|
"makage": "0.1.8"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "4daa10528afcb41fa99f6e94646ce40354121794"
|
|
45
45
|
}
|
package/prompt.d.ts
CHANGED
|
@@ -75,6 +75,11 @@ export declare class Inquirerer {
|
|
|
75
75
|
* Sets the value directly in obj, bypassing the prompt entirely.
|
|
76
76
|
*/
|
|
77
77
|
private resolveSetValues;
|
|
78
|
+
/**
|
|
79
|
+
* Resolves optionsFrom values for all questions that have optionsFrom specified.
|
|
80
|
+
* Updates the question.options property with the resolved array.
|
|
81
|
+
*/
|
|
82
|
+
private resolveOptionsFrom;
|
|
78
83
|
private applyDefaultValues;
|
|
79
84
|
private applyOverrides;
|
|
80
85
|
private handleOverrides;
|
package/prompt.js
CHANGED
|
@@ -353,6 +353,8 @@ class Inquirerer {
|
|
|
353
353
|
let obj = shouldMutate ? argv : { ...argv };
|
|
354
354
|
// Resolve dynamic defaults before processing questions
|
|
355
355
|
await this.resolveDynamicDefaults(questions);
|
|
356
|
+
// Resolve dynamic options before processing questions
|
|
357
|
+
await this.resolveOptionsFrom(questions);
|
|
356
358
|
// Resolve setFrom values - these bypass prompting entirely
|
|
357
359
|
await this.resolveSetValues(questions, obj);
|
|
358
360
|
// first loop through the question, and set any overrides in case other questions use objs for validation
|
|
@@ -472,6 +474,21 @@ class Inquirerer {
|
|
|
472
474
|
}
|
|
473
475
|
}
|
|
474
476
|
}
|
|
477
|
+
/**
|
|
478
|
+
* Resolves optionsFrom values for all questions that have optionsFrom specified.
|
|
479
|
+
* Updates the question.options property with the resolved array.
|
|
480
|
+
*/
|
|
481
|
+
async resolveOptionsFrom(questions) {
|
|
482
|
+
for (const question of questions) {
|
|
483
|
+
if ('optionsFrom' in question && question.optionsFrom) {
|
|
484
|
+
const resolved = await this.resolverRegistry.resolve(question.optionsFrom);
|
|
485
|
+
if (resolved !== undefined && Array.isArray(resolved)) {
|
|
486
|
+
// Update question.options with resolved array
|
|
487
|
+
question.options = resolved;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
475
492
|
applyDefaultValues(questions, obj) {
|
|
476
493
|
questions.forEach(question => {
|
|
477
494
|
if ('default' in question) {
|
package/question/types.d.ts
CHANGED
package/resolvers/workspace.js
CHANGED
|
@@ -75,6 +75,19 @@ function parseAuthor(author) {
|
|
|
75
75
|
* These resolve values from the nearest package.json in the current working directory.
|
|
76
76
|
*/
|
|
77
77
|
exports.workspaceResolvers = {
|
|
78
|
+
'workspace.name': () => {
|
|
79
|
+
const pkg = findPackageJsonFromCwd();
|
|
80
|
+
if (!pkg)
|
|
81
|
+
return undefined;
|
|
82
|
+
const url = getRepositoryUrl(pkg);
|
|
83
|
+
// Prefer repo slug when repository is set; fall back to package name
|
|
84
|
+
if (url) {
|
|
85
|
+
const parsed = parseGitHubUrl(url);
|
|
86
|
+
if (parsed.name)
|
|
87
|
+
return parsed.name;
|
|
88
|
+
}
|
|
89
|
+
return pkg.name;
|
|
90
|
+
},
|
|
78
91
|
'workspace.repo.name': () => {
|
|
79
92
|
const pkg = findPackageJsonFromCwd();
|
|
80
93
|
if (!pkg)
|
|
@@ -93,6 +106,20 @@ exports.workspaceResolvers = {
|
|
|
93
106
|
return undefined;
|
|
94
107
|
return parseGitHubUrl(url).organization;
|
|
95
108
|
},
|
|
109
|
+
// Alias for repo.organization for template readability
|
|
110
|
+
'workspace.organization.name': () => {
|
|
111
|
+
const pkg = findPackageJsonFromCwd();
|
|
112
|
+
if (!pkg)
|
|
113
|
+
return undefined;
|
|
114
|
+
const url = getRepositoryUrl(pkg);
|
|
115
|
+
if (!url)
|
|
116
|
+
return undefined;
|
|
117
|
+
return parseGitHubUrl(url).organization;
|
|
118
|
+
},
|
|
119
|
+
'workspace.license': () => {
|
|
120
|
+
const pkg = findPackageJsonFromCwd();
|
|
121
|
+
return pkg?.license;
|
|
122
|
+
},
|
|
96
123
|
'workspace.author': () => {
|
|
97
124
|
const pkg = findPackageJsonFromCwd();
|
|
98
125
|
if (!pkg)
|