inquirerer 2.1.11 → 2.1.13

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2025 Interweb, Inc. <developers@interweb.co>
3
+ Copyright (c) 2025 Constructive <developers@constructive.io>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -5,10 +5,10 @@
5
5
  </p>
6
6
 
7
7
  <p align="center" width="100%">
8
- <a href="https://github.com/hyperweb-io/dev-utils/actions/workflows/ci.yml">
9
- <img height="20" src="https://github.com/hyperweb-io/dev-utils/actions/workflows/ci.yml/badge.svg" />
8
+ <a href="https://github.com/constructive-io/dev-utils/actions/workflows/ci.yml">
9
+ <img height="20" src="https://github.com/constructive-io/dev-utils/actions/workflows/ci.yml/badge.svg" />
10
10
  </a>
11
- <a href="https://github.com/hyperweb-io/dev-utils/blob/main/LICENSE">
11
+ <a href="https://github.com/constructive-io/dev-utils/blob/main/LICENSE">
12
12
  <img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/>
13
13
  </a>
14
14
  <a href="https://www.npmjs.com/package/inquirerer"><img height="20" src="https://img.shields.io/npm/dt/inquirerer"></a>
@@ -133,6 +133,7 @@ interface BaseQuestion {
133
133
  description?: string; // Additional context
134
134
  default?: any; // Default value
135
135
  defaultFrom?: string; // Dynamic default from resolver (e.g., 'git.user.name')
136
+ setFrom?: string; // Auto-set value from resolver, bypassing prompt entirely
136
137
  useDefault?: boolean; // Skip prompt and use default
137
138
  required?: boolean; // Validation requirement
138
139
  validate?: (input: any, answers: any) => boolean | Validation;
@@ -751,9 +752,10 @@ Inquirerer comes with several built-in resolvers ready to use:
751
752
  When resolving default values, inquirerer follows this priority:
752
753
 
753
754
  1. **CLI Arguments** - Values passed via command line (highest priority)
754
- 2. **`defaultFrom`** - Dynamically resolved values
755
- 3. **`default`** - Static default values
756
- 4. **`undefined`** - No default available
755
+ 2. **`setFrom`** - Auto-set values (bypasses prompt entirely)
756
+ 3. **`defaultFrom`** - Dynamically resolved default values
757
+ 4. **`default`** - Static default values
758
+ 5. **`undefined`** - No default available
757
759
 
758
760
  ```typescript
759
761
  {
@@ -764,6 +766,75 @@ When resolving default values, inquirerer follows this priority:
764
766
  }
765
767
  ```
766
768
 
769
+ ### `setFrom` vs `defaultFrom`
770
+
771
+ Both `setFrom` and `defaultFrom` use resolvers to get values, but they behave differently:
772
+
773
+ | Feature | `defaultFrom` | `setFrom` |
774
+ |---------|---------------|-----------|
775
+ | Sets value as | Default (user can override) | Final value (no prompt) |
776
+ | User prompted? | Yes, with pre-filled default | No, question is skipped |
777
+ | Use case | Suggested values | Auto-computed values |
778
+
779
+ **`defaultFrom`** - The resolved value becomes the default, but the user is still prompted and can change it:
780
+
781
+ ```typescript
782
+ {
783
+ type: 'text',
784
+ name: 'authorName',
785
+ message: 'Author name?',
786
+ defaultFrom: 'git.user.name' // User sees "Author name? [John Doe]" and can change it
787
+ }
788
+ ```
789
+
790
+ **`setFrom`** - The resolved value is set directly and the question is skipped entirely:
791
+
792
+ ```typescript
793
+ {
794
+ type: 'text',
795
+ name: 'year',
796
+ message: 'Copyright year?',
797
+ setFrom: 'date.year' // Automatically set to "2025", no prompt shown
798
+ }
799
+ ```
800
+
801
+ #### When to use each
802
+
803
+ Use `defaultFrom` when:
804
+ - The value is a suggestion the user might want to change
805
+ - User confirmation is desired
806
+
807
+ Use `setFrom` when:
808
+ - The value should be computed automatically
809
+ - No user input is needed (e.g., timestamps, computed fields)
810
+ - You want to reduce the number of prompts
811
+
812
+ #### Combined example
813
+
814
+ ```typescript
815
+ const questions = [
816
+ {
817
+ type: 'text',
818
+ name: 'authorName',
819
+ message: 'Author name?',
820
+ defaultFrom: 'git.user.name' // User can override
821
+ },
822
+ {
823
+ type: 'text',
824
+ name: 'createdAt',
825
+ setFrom: 'date.iso' // Auto-set, no prompt
826
+ },
827
+ {
828
+ type: 'text',
829
+ name: 'copyrightYear',
830
+ setFrom: 'date.year' // Auto-set, no prompt
831
+ }
832
+ ];
833
+
834
+ // User only sees prompt for authorName
835
+ // createdAt and copyrightYear are set automatically
836
+ ```
837
+
767
838
  ### Custom Resolvers
768
839
 
769
840
  Register your own custom resolvers for project-specific needs:
@@ -987,7 +1058,7 @@ await cli.run();
987
1058
  1. Clone the repository:
988
1059
 
989
1060
  ```bash
990
- git clone https://github.com/hyperweb-io/dev-utils.git
1061
+ git clone https://github.com/constructive-io/dev-utils.git
991
1062
  ```
992
1063
 
993
1064
  2. Install dependencies:
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 setFrom values - these bypass prompting entirely
350
+ await this.resolveSetValues(questions, obj);
349
351
  // first loop through the question, and set any overrides in case other questions use objs for validation
350
352
  this.applyOverrides(argv, obj, questions);
351
353
  // Check for required arguments when no terminal is available (non-interactive mode)
@@ -446,6 +448,23 @@ export class Inquirerer {
446
448
  }
447
449
  }
448
450
  }
451
+ /**
452
+ * Resolves setFrom values for all questions that have setFrom specified.
453
+ * Sets the value directly in obj, bypassing the prompt entirely.
454
+ */
455
+ async resolveSetValues(questions, obj) {
456
+ for (const question of questions) {
457
+ if ('setFrom' in question && question.setFrom) {
458
+ // Only set if not already provided in args
459
+ if (!(question.name in obj)) {
460
+ const resolved = await this.resolverRegistry.resolve(question.setFrom);
461
+ if (resolved !== undefined) {
462
+ obj[question.name] = resolved;
463
+ }
464
+ }
465
+ }
466
+ }
467
+ }
449
468
  applyDefaultValues(questions, obj) {
450
469
  questions.forEach(question => {
451
470
  if ('default' in question) {
@@ -1,6 +1,7 @@
1
1
  import { gitResolvers } from './git';
2
2
  import { dateResolvers } from './date';
3
3
  import { npmResolvers } from './npm';
4
+ import { workspaceResolvers } from './workspace';
4
5
  /**
5
6
  * A registry for managing default value resolvers.
6
7
  * Allows registration of custom resolvers and provides resolution logic.
@@ -80,6 +81,7 @@ export const globalResolverRegistry = new DefaultResolverRegistry({
80
81
  ...gitResolvers,
81
82
  ...dateResolvers,
82
83
  ...npmResolvers,
84
+ ...workspaceResolvers,
83
85
  });
84
86
  /**
85
87
  * Convenience function to register a resolver on the global registry.
@@ -0,0 +1,114 @@
1
+ import { findAndRequirePackageJson } from 'find-and-require-package-json';
2
+ /**
3
+ * Find and read the nearest package.json starting from cwd.
4
+ * Returns undefined if not found (instead of throwing).
5
+ */
6
+ function findPackageJsonFromCwd() {
7
+ try {
8
+ return findAndRequirePackageJson(process.cwd());
9
+ }
10
+ catch {
11
+ return undefined;
12
+ }
13
+ }
14
+ /**
15
+ * Parse a GitHub URL and extract organization and repo name.
16
+ * Handles various formats:
17
+ * - https://github.com/org/repo
18
+ * - https://github.com/org/repo.git
19
+ * - git@github.com:org/repo.git
20
+ * - git://github.com/org/repo.git
21
+ */
22
+ function parseGitHubUrl(url) {
23
+ if (!url) {
24
+ return {};
25
+ }
26
+ // Handle git@github.com:org/repo.git format
27
+ const sshMatch = url.match(/git@github\.com:([^/]+)\/([^/.]+)(?:\.git)?/);
28
+ if (sshMatch) {
29
+ return { organization: sshMatch[1], name: sshMatch[2] };
30
+ }
31
+ // Handle https://github.com/org/repo or git://github.com/org/repo formats
32
+ const httpsMatch = url.match(/(?:https?|git):\/\/github\.com\/([^/]+)\/([^/.]+)(?:\.git)?/);
33
+ if (httpsMatch) {
34
+ return { organization: httpsMatch[1], name: httpsMatch[2] };
35
+ }
36
+ return {};
37
+ }
38
+ /**
39
+ * Get the repository URL from package.json.
40
+ * Handles both string and object formats.
41
+ */
42
+ function getRepositoryUrl(pkg) {
43
+ if (!pkg.repository) {
44
+ return undefined;
45
+ }
46
+ if (typeof pkg.repository === 'string') {
47
+ return pkg.repository;
48
+ }
49
+ return pkg.repository.url;
50
+ }
51
+ /**
52
+ * Parse author field which can be a string or object.
53
+ * String format: "Name <email> (url)" where email and url are optional
54
+ */
55
+ function parseAuthor(author) {
56
+ if (!author) {
57
+ return {};
58
+ }
59
+ if (typeof author === 'object') {
60
+ return { name: author.name, email: author.email };
61
+ }
62
+ // Parse string format: "Name <email> (url)"
63
+ const nameMatch = author.match(/^([^<(]+)/);
64
+ const emailMatch = author.match(/<([^>]+)>/);
65
+ return {
66
+ name: nameMatch ? nameMatch[1].trim() : undefined,
67
+ email: emailMatch ? emailMatch[1] : undefined,
68
+ };
69
+ }
70
+ /**
71
+ * Built-in workspace resolvers.
72
+ * These resolve values from the nearest package.json in the current working directory.
73
+ */
74
+ export const workspaceResolvers = {
75
+ 'workspace.repo.name': () => {
76
+ const pkg = findPackageJsonFromCwd();
77
+ if (!pkg)
78
+ return undefined;
79
+ const url = getRepositoryUrl(pkg);
80
+ if (!url)
81
+ return undefined;
82
+ return parseGitHubUrl(url).name;
83
+ },
84
+ 'workspace.repo.organization': () => {
85
+ const pkg = findPackageJsonFromCwd();
86
+ if (!pkg)
87
+ return undefined;
88
+ const url = getRepositoryUrl(pkg);
89
+ if (!url)
90
+ return undefined;
91
+ return parseGitHubUrl(url).organization;
92
+ },
93
+ 'workspace.author': () => {
94
+ const pkg = findPackageJsonFromCwd();
95
+ if (!pkg)
96
+ return undefined;
97
+ const parsed = parseAuthor(pkg.author);
98
+ return parsed.name;
99
+ },
100
+ 'workspace.author.name': () => {
101
+ const pkg = findPackageJsonFromCwd();
102
+ if (!pkg)
103
+ return undefined;
104
+ const parsed = parseAuthor(pkg.author);
105
+ return parsed.name;
106
+ },
107
+ 'workspace.author.email': () => {
108
+ const pkg = findPackageJsonFromCwd();
109
+ if (!pkg)
110
+ return undefined;
111
+ const parsed = parseAuthor(pkg.author);
112
+ return parsed.email;
113
+ },
114
+ };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "inquirerer",
3
- "version": "2.1.11",
4
- "author": "Dan Lynch <pyramation@gmail.com>",
3
+ "version": "2.1.13",
4
+ "author": "Constructive <pyramation@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",
8
8
  "types": "index.d.ts",
9
- "homepage": "https://github.com/hyperweb-io/dev-utils",
9
+ "homepage": "https://github.com/constructive-io/dev-utils",
10
10
  "license": "MIT",
11
11
  "publishConfig": {
12
12
  "access": "public",
@@ -14,10 +14,10 @@
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
17
- "url": "https://github.com/hyperweb-io/dev-utils"
17
+ "url": "https://github.com/constructive-io/dev-utils"
18
18
  },
19
19
  "bugs": {
20
- "url": "https://github.com/hyperweb-io/dev-utils/issues"
20
+ "url": "https://github.com/constructive-io/dev-utils/issues"
21
21
  },
22
22
  "scripts": {
23
23
  "copy": "makage assets",
@@ -30,16 +30,16 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "deepmerge": "^4.3.1",
33
- "find-and-require-package-json": "0.8.0",
33
+ "find-and-require-package-json": "0.8.1",
34
34
  "js-yaml": "^4.1.0",
35
35
  "minimist": "^1.2.8",
36
- "yanse": "0.1.6"
36
+ "yanse": "0.1.7"
37
37
  },
38
38
  "keywords": [],
39
39
  "devDependencies": {
40
40
  "@types/minimist": "^1.2.5",
41
- "clean-ansi": "0.1.3",
41
+ "clean-ansi": "0.1.4",
42
42
  "makage": "0.1.8"
43
43
  },
44
- "gitHead": "a704f3ec0e53747e4fba85c2018138439120f309"
44
+ "gitHead": "b22eaa525718494342576c1739b2b062c0ad6498"
45
45
  }
package/prompt.d.ts CHANGED
@@ -70,6 +70,11 @@ export declare class Inquirerer {
70
70
  * Updates the question.default property with the resolved value.
71
71
  */
72
72
  private resolveDynamicDefaults;
73
+ /**
74
+ * Resolves setFrom values for all questions that have setFrom specified.
75
+ * Sets the value directly in obj, bypassing the prompt entirely.
76
+ */
77
+ private resolveSetValues;
73
78
  private applyDefaultValues;
74
79
  private applyOverrides;
75
80
  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 setFrom values - these bypass prompting entirely
357
+ await this.resolveSetValues(questions, obj);
356
358
  // first loop through the question, and set any overrides in case other questions use objs for validation
357
359
  this.applyOverrides(argv, obj, questions);
358
360
  // Check for required arguments when no terminal is available (non-interactive mode)
@@ -453,6 +455,23 @@ class Inquirerer {
453
455
  }
454
456
  }
455
457
  }
458
+ /**
459
+ * Resolves setFrom values for all questions that have setFrom specified.
460
+ * Sets the value directly in obj, bypassing the prompt entirely.
461
+ */
462
+ async resolveSetValues(questions, obj) {
463
+ for (const question of questions) {
464
+ if ('setFrom' in question && question.setFrom) {
465
+ // Only set if not already provided in args
466
+ if (!(question.name in obj)) {
467
+ const resolved = await this.resolverRegistry.resolve(question.setFrom);
468
+ if (resolved !== undefined) {
469
+ obj[question.name] = resolved;
470
+ }
471
+ }
472
+ }
473
+ }
474
+ }
456
475
  applyDefaultValues(questions, obj) {
457
476
  questions.forEach(question => {
458
477
  if ('default' in question) {
@@ -17,6 +17,7 @@ export interface BaseQuestion {
17
17
  type: string;
18
18
  default?: any;
19
19
  defaultFrom?: string;
20
+ setFrom?: string;
20
21
  useDefault?: boolean;
21
22
  required?: boolean;
22
23
  message?: string;
@@ -6,6 +6,7 @@ exports.resolveDefault = resolveDefault;
6
6
  const git_1 = require("./git");
7
7
  const date_1 = require("./date");
8
8
  const npm_1 = require("./npm");
9
+ const workspace_1 = require("./workspace");
9
10
  /**
10
11
  * A registry for managing default value resolvers.
11
12
  * Allows registration of custom resolvers and provides resolution logic.
@@ -86,6 +87,7 @@ exports.globalResolverRegistry = new DefaultResolverRegistry({
86
87
  ...git_1.gitResolvers,
87
88
  ...date_1.dateResolvers,
88
89
  ...npm_1.npmResolvers,
90
+ ...workspace_1.workspaceResolvers,
89
91
  });
90
92
  /**
91
93
  * Convenience function to register a resolver on the global registry.
@@ -0,0 +1,6 @@
1
+ import type { ResolverRegistry } from './types';
2
+ /**
3
+ * Built-in workspace resolvers.
4
+ * These resolve values from the nearest package.json in the current working directory.
5
+ */
6
+ export declare const workspaceResolvers: ResolverRegistry;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.workspaceResolvers = void 0;
4
+ const find_and_require_package_json_1 = require("find-and-require-package-json");
5
+ /**
6
+ * Find and read the nearest package.json starting from cwd.
7
+ * Returns undefined if not found (instead of throwing).
8
+ */
9
+ function findPackageJsonFromCwd() {
10
+ try {
11
+ return (0, find_and_require_package_json_1.findAndRequirePackageJson)(process.cwd());
12
+ }
13
+ catch {
14
+ return undefined;
15
+ }
16
+ }
17
+ /**
18
+ * Parse a GitHub URL and extract organization and repo name.
19
+ * Handles various formats:
20
+ * - https://github.com/org/repo
21
+ * - https://github.com/org/repo.git
22
+ * - git@github.com:org/repo.git
23
+ * - git://github.com/org/repo.git
24
+ */
25
+ function parseGitHubUrl(url) {
26
+ if (!url) {
27
+ return {};
28
+ }
29
+ // Handle git@github.com:org/repo.git format
30
+ const sshMatch = url.match(/git@github\.com:([^/]+)\/([^/.]+)(?:\.git)?/);
31
+ if (sshMatch) {
32
+ return { organization: sshMatch[1], name: sshMatch[2] };
33
+ }
34
+ // Handle https://github.com/org/repo or git://github.com/org/repo formats
35
+ const httpsMatch = url.match(/(?:https?|git):\/\/github\.com\/([^/]+)\/([^/.]+)(?:\.git)?/);
36
+ if (httpsMatch) {
37
+ return { organization: httpsMatch[1], name: httpsMatch[2] };
38
+ }
39
+ return {};
40
+ }
41
+ /**
42
+ * Get the repository URL from package.json.
43
+ * Handles both string and object formats.
44
+ */
45
+ function getRepositoryUrl(pkg) {
46
+ if (!pkg.repository) {
47
+ return undefined;
48
+ }
49
+ if (typeof pkg.repository === 'string') {
50
+ return pkg.repository;
51
+ }
52
+ return pkg.repository.url;
53
+ }
54
+ /**
55
+ * Parse author field which can be a string or object.
56
+ * String format: "Name <email> (url)" where email and url are optional
57
+ */
58
+ function parseAuthor(author) {
59
+ if (!author) {
60
+ return {};
61
+ }
62
+ if (typeof author === 'object') {
63
+ return { name: author.name, email: author.email };
64
+ }
65
+ // Parse string format: "Name <email> (url)"
66
+ const nameMatch = author.match(/^([^<(]+)/);
67
+ const emailMatch = author.match(/<([^>]+)>/);
68
+ return {
69
+ name: nameMatch ? nameMatch[1].trim() : undefined,
70
+ email: emailMatch ? emailMatch[1] : undefined,
71
+ };
72
+ }
73
+ /**
74
+ * Built-in workspace resolvers.
75
+ * These resolve values from the nearest package.json in the current working directory.
76
+ */
77
+ exports.workspaceResolvers = {
78
+ 'workspace.repo.name': () => {
79
+ const pkg = findPackageJsonFromCwd();
80
+ if (!pkg)
81
+ return undefined;
82
+ const url = getRepositoryUrl(pkg);
83
+ if (!url)
84
+ return undefined;
85
+ return parseGitHubUrl(url).name;
86
+ },
87
+ 'workspace.repo.organization': () => {
88
+ const pkg = findPackageJsonFromCwd();
89
+ if (!pkg)
90
+ return undefined;
91
+ const url = getRepositoryUrl(pkg);
92
+ if (!url)
93
+ return undefined;
94
+ return parseGitHubUrl(url).organization;
95
+ },
96
+ 'workspace.author': () => {
97
+ const pkg = findPackageJsonFromCwd();
98
+ if (!pkg)
99
+ return undefined;
100
+ const parsed = parseAuthor(pkg.author);
101
+ return parsed.name;
102
+ },
103
+ 'workspace.author.name': () => {
104
+ const pkg = findPackageJsonFromCwd();
105
+ if (!pkg)
106
+ return undefined;
107
+ const parsed = parseAuthor(pkg.author);
108
+ return parsed.name;
109
+ },
110
+ 'workspace.author.email': () => {
111
+ const pkg = findPackageJsonFromCwd();
112
+ if (!pkg)
113
+ return undefined;
114
+ const parsed = parseAuthor(pkg.author);
115
+ return parsed.email;
116
+ },
117
+ };