yeoman-environment 4.2.0 → 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.
- package/dist/environment-base.d.ts +6 -1
- package/dist/environment-base.js +30 -19
- package/dist/store.d.ts +2 -2
- package/package.json +1 -1
|
@@ -17,7 +17,7 @@ export type EnvironmentLookupOptions = LookupOptions & {
|
|
|
17
17
|
/** Add a scope to the namespace if there is no scope */
|
|
18
18
|
registerToScope?: string;
|
|
19
19
|
/** Customize the namespace to be registered */
|
|
20
|
-
customizeNamespace?: (ns?: string) => string;
|
|
20
|
+
customizeNamespace?: (ns?: string) => string | undefined;
|
|
21
21
|
};
|
|
22
22
|
export type EnvironmentOptions = BaseEnvironmentOptions & Omit<TerminalAdapterOptions, 'promptModule'> & {
|
|
23
23
|
adapter?: InputOutputAdapter;
|
|
@@ -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
|
package/dist/environment-base.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
175
|
-
return maybeGenerator;
|
|
168
|
+
return this.store.getMeta(ns) ?? this.store.getMeta(this.alias(ns));
|
|
176
169
|
}
|
|
177
|
-
const
|
|
178
|
-
if (
|
|
179
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
@@ -434,6 +444,7 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
434
444
|
if (!namespace) {
|
|
435
445
|
namespace = customizeNamespace(asNamespace(resolved, { lookups }));
|
|
436
446
|
}
|
|
447
|
+
namespace = namespace;
|
|
437
448
|
if (registerToScope && !namespace.startsWith('@')) {
|
|
438
449
|
namespace = `@${registerToScope}/${namespace}`;
|
|
439
450
|
}
|
|
@@ -451,7 +462,7 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
451
462
|
}
|
|
452
463
|
generators.push({
|
|
453
464
|
resolved: filePath,
|
|
454
|
-
namespace,
|
|
465
|
+
namespace: namespace,
|
|
455
466
|
packagePath,
|
|
456
467
|
registered: false,
|
|
457
468
|
});
|
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
|