yeoman-environment 4.2.1 → 4.3.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.
@@ -60,6 +60,11 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
60
60
  feature: any;
61
61
  }>;
62
62
  applyTransforms(transformStreams: FilePipelineTransform[], options?: ApplyTransformsOptions): Promise<void>;
63
+ /**
64
+ * @param namespaceOrPath
65
+ * @return the generator meta registered under the namespace
66
+ */
67
+ findMeta(namespaceOrPath: string | YeomanNamespace): Promise<GeneratorMeta | undefined>;
63
68
  /**
64
69
  * Get a single generator from the registered list of generators. The lookup is
65
70
  * based on generator's namespace, "walking up" the namespaces until a matching
@@ -154,16 +154,10 @@ export default class EnvironmentBase extends EventEmitter {
154
154
  }, { name, disabled: !(options?.log ?? true) });
155
155
  }
156
156
  /**
157
- * Get a single generator from the registered list of generators. The lookup is
158
- * based on generator's namespace, "walking up" the namespaces until a matching
159
- * is found. Eg. if an `angular:common` namespace is registered, and we try to
160
- * get `angular:common:all` then we get `angular:common` as a fallback (unless
161
- * an `angular:common:all` generator is registered).
162
- *
163
157
  * @param namespaceOrPath
164
- * @return the generator registered under the namespace
158
+ * @return the generator meta registered under the namespace
165
159
  */
166
- async get(namespaceOrPath) {
160
+ async findMeta(namespaceOrPath) {
167
161
  // Stop the recursive search if nothing is left
168
162
  if (!namespaceOrPath) {
169
163
  return;
@@ -171,24 +165,35 @@ export default class EnvironmentBase extends EventEmitter {
171
165
  const parsed = toNamespace(namespaceOrPath);
172
166
  if (typeof namespaceOrPath !== 'string' || parsed) {
173
167
  const ns = parsed.namespace;
174
- const maybeGenerator = (await this.store.get(ns)) ?? this.store.get(this.alias(ns));
175
- return maybeGenerator;
168
+ return this.store.getMeta(ns) ?? this.store.getMeta(this.alias(ns));
176
169
  }
177
- const maybeGenerator = (await this.store.get(namespaceOrPath)) ?? (await this.store.get(this.alias(namespaceOrPath)));
178
- if (maybeGenerator) {
179
- return maybeGenerator;
170
+ const maybeMeta = this.store.getMeta(namespaceOrPath) ?? this.store.getMeta(this.alias(namespaceOrPath));
171
+ if (maybeMeta) {
172
+ return maybeMeta;
180
173
  }
181
174
  try {
182
175
  const resolved = await resolveModulePath(namespaceOrPath);
183
176
  if (resolved) {
184
- const namespace = this.namespace(resolved);
185
- this.store.add({ resolved, namespace });
186
- return (await this.store.get(namespace));
177
+ return this.store.add({ resolved, namespace: this.namespace(resolved) });
187
178
  }
188
179
  }
189
180
  catch { }
190
181
  return undefined;
191
182
  }
183
+ /**
184
+ * Get a single generator from the registered list of generators. The lookup is
185
+ * based on generator's namespace, "walking up" the namespaces until a matching
186
+ * is found. Eg. if an `angular:common` namespace is registered, and we try to
187
+ * get `angular:common:all` then we get `angular:common` as a fallback (unless
188
+ * an `angular:common:all` generator is registered).
189
+ *
190
+ * @param namespaceOrPath
191
+ * @return the generator registered under the namespace
192
+ */
193
+ async get(namespaceOrPath) {
194
+ const meta = await this.findMeta(namespaceOrPath);
195
+ return meta?.importGenerator();
196
+ }
192
197
  async create(namespaceOrPath, ...args) {
193
198
  let constructor;
194
199
  const namespace = typeof namespaceOrPath === 'string' ? toNamespace(namespaceOrPath) : undefined;
@@ -233,11 +238,15 @@ export default class EnvironmentBase extends EventEmitter {
233
238
  return this.instantiate(checkGenerator(namespaceOrPath), ...args);
234
239
  }
235
240
  if (typeof namespaceOrPath === 'string') {
236
- constructor = await this.get(namespaceOrPath);
241
+ const meta = await this.findMeta(namespaceOrPath);
242
+ constructor = await meta?.importGenerator();
237
243
  if (namespace && !constructor) {
238
244
  // Await this.lookupLocalNamespaces(namespace);
239
245
  // constructor = await this.get(namespace);
240
246
  }
247
+ if (constructor) {
248
+ constructor._meta = meta;
249
+ }
241
250
  }
242
251
  else {
243
252
  constructor = namespaceOrPath;
@@ -246,13 +255,14 @@ export default class EnvironmentBase extends EventEmitter {
246
255
  }
247
256
  async instantiate(constructor, ...args) {
248
257
  const composeOptions = args.length > 0 ? getInstantiateOptions(...args) : {};
249
- const { namespace = UNKNOWN_NAMESPACE, resolved = UNKNOWN_RESOLVED } = constructor;
258
+ const { namespace = UNKNOWN_NAMESPACE, resolved = UNKNOWN_RESOLVED, _meta } = constructor;
250
259
  const environmentOptions = { env: this, resolved, namespace };
251
260
  const generator = new constructor(composeOptions.generatorArgs ?? [], {
252
261
  ...this.sharedOptions,
253
262
  ...composeOptions.generatorOptions,
254
263
  ...environmentOptions,
255
264
  });
265
+ generator._meta = _meta;
256
266
  generator._environmentOptions = {
257
267
  ...this.options,
258
268
  ...this.sharedOptions,
package/dist/store.d.ts CHANGED
@@ -23,13 +23,13 @@ export default class Store {
23
23
  * @param {String} namespace
24
24
  * @return {Module}
25
25
  */
26
- get(namespace: string): Promise<GetGeneratorConstructor>;
26
+ get(namespace: string): Promise<GetGeneratorConstructor | undefined>;
27
27
  /**
28
28
  * Get the module registered under the given namespace
29
29
  * @param {String} namespace
30
30
  * @return {Module}
31
31
  */
32
- getMeta(namespace: string): GeneratorMeta;
32
+ getMeta(namespace: string): GeneratorMeta | undefined;
33
33
  /**
34
34
  * Returns the list of registered namespace.
35
35
  * @return {Array} Namespaces array
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yeoman-environment",
3
- "version": "4.2.1",
3
+ "version": "4.3.0",
4
4
  "description": "Handles the lifecyle and bootstrapping of generators in a specific environment",
5
5
  "keywords": [
6
6
  "development",