yeoman-generator 8.1.0 → 8.1.2

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.
@@ -118,7 +118,7 @@ export declare class BaseGenerator<ConfigType extends Record<any, any> = Record<
118
118
  * @param storage Storage object or name (generator property) to be used by default to store/fetch responses.
119
119
  * @return prompt promise
120
120
  */
121
- prompt<A extends PromptAnswers = PromptAnswers>(questions: PromptQuestions<A>, storage?: string | Storage): Promise<A>;
121
+ prompt<A extends PromptAnswers = PromptAnswers>(questions: PromptQuestions<A>, storage?: string | Storage<any>): Promise<A>;
122
122
  /**
123
123
  * Adds an option to the set of generator expected options, only used to
124
124
  * generate generator usage. By default, generators get all the cli options
@@ -12,7 +12,7 @@ export type PromptQuestion<T extends PromptAnswers = PromptAnswers> = PromptQues
12
12
  /**
13
13
  * The storage to store the answer.
14
14
  */
15
- storage?: Storage;
15
+ storage?: Storage<any>;
16
16
 
17
17
  /**
18
18
  * A value indicating whether to store the user's previous answer for others projects.
package/dist/types.d.ts CHANGED
@@ -14,6 +14,8 @@ import type Generator from './index.js';
14
14
  export type StorageValue = JsonValue;
15
15
  export type GeneratorPipelineOptions = PipelineOptions<MemFsEditorFile> & ProgressOptions & { pendingFiles?: boolean };
16
16
 
17
+ export type StorageTransform<A extends Record<string, any>> = (content: A, name?: string) => A;
18
+
17
19
  /**
18
20
  * Queue options.
19
21
  */
@@ -107,7 +109,7 @@ export type BaseFeatures = FeaturesApi & {
107
109
  inheritTasks?: boolean;
108
110
 
109
111
  /** Transform the configuration before reading. */
110
- configTransform?: (config: any) => any;
112
+ configTransform?: StorageTransform<Record<string, any>>;
111
113
  };
112
114
 
113
115
  export type BaseOptions = OptionsApi & {
@@ -1,7 +1,7 @@
1
1
  import type { Get } from 'type-fest';
2
2
  import type { MemFsEditor } from 'mem-fs-editor';
3
- import type { StorageValue } from '../types.js';
4
- export type StorageOptions<StorageRecord extends Record<string, any> = Record<string, any>> = {
3
+ import type { StorageTransform, StorageValue } from '../types.js';
4
+ export type StorageOptions = {
5
5
  name?: string;
6
6
  /**
7
7
  * Set true to treat name as a lodash path.
@@ -22,7 +22,7 @@ export type StorageOptions<StorageRecord extends Record<string, any> = Record<st
22
22
  /**
23
23
  * Transform the content of the storage when reading it. This can be used to sanitize or modify the data before it is returned.
24
24
  */
25
- transform?: (content: StorageRecord) => StorageRecord;
25
+ transform?: StorageTransform<Record<string, any>>;
26
26
  };
27
27
  /**
28
28
  * Storage instances handle a json file where Generator authors can store data.
@@ -50,11 +50,11 @@ declare class Storage<StorageRecord extends Record<string, any> = Record<string,
50
50
  disableCache: boolean;
51
51
  disableCacheByFile: boolean;
52
52
  sorted: boolean;
53
- transform?: (content: StorageRecord) => StorageRecord;
54
53
  existed: boolean;
55
54
  _cachedStore?: StorageRecord;
56
- constructor(name: string | undefined, fs: MemFsEditor, configPath: string, options?: StorageOptions<StorageRecord>);
57
- constructor(fs: MemFsEditor, configPath: string, options?: StorageOptions<StorageRecord>);
55
+ private transform?;
56
+ constructor(name: string | undefined, fs: MemFsEditor, configPath: string, options?: StorageOptions);
57
+ constructor(fs: MemFsEditor, configPath: string, options?: StorageOptions);
58
58
  /**
59
59
  * @protected
60
60
  * @return the store content
@@ -86,7 +86,9 @@ declare class Storage<StorageRecord extends Record<string, any> = Record<string,
86
86
  * @param key The key under which the value is stored.
87
87
  * @return The stored value. Any JSON valid type could be returned
88
88
  */
89
- get<const Key extends keyof StorageRecord>(key: Key): StorageRecord[Key];
89
+ get<const Key extends keyof StorageRecord>(key: Key, { raw }?: {
90
+ raw?: boolean;
91
+ }): StorageRecord[Key];
90
92
  /**
91
93
  * Get a stored value from a lodash path
92
94
  * @param path The path under which the value is stored.
@@ -6,7 +6,7 @@ import sortKeys from 'sort-keys';
6
6
  */
7
7
  const proxyHandler = {
8
8
  get(storage, property, _receiver) {
9
- return storage.get(property);
9
+ return storage.get(property, { raw: true });
10
10
  },
11
11
  set(storage, property, value, _receiver) {
12
12
  if (typeof property === 'string') {
@@ -19,7 +19,7 @@ const proxyHandler = {
19
19
  return Reflect.ownKeys(storage._store);
20
20
  },
21
21
  has(storage, prop) {
22
- return storage.get(prop) !== undefined;
22
+ return storage.get(prop, { raw: true }) !== undefined;
23
23
  },
24
24
  getOwnPropertyDescriptor(storage, key) {
25
25
  return {
@@ -55,9 +55,9 @@ class Storage {
55
55
  disableCache;
56
56
  disableCacheByFile;
57
57
  sorted;
58
- transform;
59
58
  existed;
60
59
  _cachedStore;
60
+ transform;
61
61
  constructor(name, fs, configPath, options = {}) {
62
62
  let editor;
63
63
  let actualName;
@@ -171,7 +171,10 @@ class Storage {
171
171
  * @param key The key under which the value is stored.
172
172
  * @return The stored value. Any JSON valid type could be returned
173
173
  */
174
- get(key) {
174
+ get(key, { raw } = {}) {
175
+ if (raw) {
176
+ return this._store[key];
177
+ }
175
178
  return this.transformedStore()[key];
176
179
  }
177
180
  /**
@@ -262,7 +265,7 @@ class Storage {
262
265
  }
263
266
  transformedStore({ forceClone = false } = {}) {
264
267
  if (this.transform) {
265
- return this.transform(cloneDeep(this._store));
268
+ return this.transform(cloneDeep(this._store), this.name);
266
269
  }
267
270
  if (forceClone) {
268
271
  return cloneDeep(this._store);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeoman-generator",
3
- "version": "8.1.0",
3
+ "version": "8.1.2",
4
4
  "description": "Rails-inspired generator system that provides scaffolding for your apps",
5
5
  "keywords": [
6
6
  "development",