yeoman-environment 4.4.3 → 5.0.0-beta.1
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/bin/bin.cjs +1 -0
- package/dist/cli/index.js +8 -8
- package/dist/cli/utils.d.ts +1 -1
- package/dist/cli/utils.js +5 -5
- package/dist/commands.d.ts +2 -2
- package/dist/commands.js +7 -8
- package/dist/commit.d.ts +1 -1
- package/dist/commit.js +1 -2
- package/dist/composed-store.d.ts +6 -5
- package/dist/composed-store.js +3 -3
- package/dist/constants.js +0 -2
- package/dist/environment-base.d.ts +16 -10
- package/dist/environment-base.js +95 -95
- package/dist/environment-full.d.ts +6 -9
- package/dist/environment-full.js +23 -26
- package/dist/generator-lookup.d.ts +2 -2
- package/dist/generator-lookup.js +7 -7
- package/dist/index.d.ts +10 -9
- package/dist/index.js +11 -8
- package/dist/module-lookup.d.ts +1 -1
- package/dist/module-lookup.js +12 -16
- package/dist/package-manager.d.ts +4 -3
- package/dist/store.d.ts +3 -3
- package/dist/store.js +61 -23
- package/dist/util/command.d.ts +4 -3
- package/dist/util/command.js +12 -9
- package/dist/util/namespace.js +3 -3
- package/dist/util/resolve.d.ts +1 -1
- package/dist/util/resolve.js +10 -8
- package/dist/util/util.d.ts +2 -3
- package/dist/util/util.js +17 -15
- package/package.json +56 -51
package/dist/environment-base.js
CHANGED
|
@@ -5,73 +5,74 @@ import process from 'node:process';
|
|
|
5
5
|
import { realpathSync } from 'node:fs';
|
|
6
6
|
import { QueuedAdapter } from '@yeoman/adapter';
|
|
7
7
|
import { create as createMemFs } from 'mem-fs';
|
|
8
|
+
import {} from 'mem-fs-editor';
|
|
8
9
|
import { FlyRepository } from 'fly-import';
|
|
9
10
|
import createdLogger from 'debug';
|
|
10
|
-
// @ts-expect-error grouped-queue don't have types
|
|
11
11
|
import GroupedQueue from 'grouped-queue';
|
|
12
12
|
import { isFilePending } from 'mem-fs-editor/state';
|
|
13
|
-
import {
|
|
13
|
+
import { filePipeline, transform } from '@yeoman/transform';
|
|
14
14
|
import { toNamespace } from '@yeoman/namespace';
|
|
15
15
|
import chalk from 'chalk';
|
|
16
|
+
import {} from '@yeoman/conflicter';
|
|
16
17
|
import { defaults, pick } from 'lodash-es';
|
|
17
|
-
import { ComposedStore } from
|
|
18
|
-
import Store from
|
|
19
|
-
import { asNamespace, defaultLookups } from
|
|
20
|
-
import { lookupGenerators } from
|
|
21
|
-
import { UNKNOWN_NAMESPACE, UNKNOWN_RESOLVED, defaultQueues } from
|
|
22
|
-
import { resolveModulePath } from
|
|
23
|
-
import { commitSharedFsTask } from
|
|
24
|
-
import { packageManagerInstallTask } from
|
|
25
|
-
|
|
26
|
-
import { splitArgsFromString } from './util/util.js';
|
|
18
|
+
import { ComposedStore } from "./composed-store.js";
|
|
19
|
+
import Store from "./store.js";
|
|
20
|
+
import { asNamespace, defaultLookups } from "./util/namespace.js";
|
|
21
|
+
import { lookupGenerators } from "./generator-lookup.js";
|
|
22
|
+
import { UNKNOWN_NAMESPACE, UNKNOWN_RESOLVED, defaultQueues } from "./constants.js";
|
|
23
|
+
import { resolveModulePath } from "./util/resolve.js";
|
|
24
|
+
import { commitSharedFsTask } from "./commit.js";
|
|
25
|
+
import { packageManagerInstallTask } from "./package-manager.js";
|
|
26
|
+
import { splitArgsFromString as splitArgumentsFromString } from "./util/util.js";
|
|
27
27
|
const require = createRequire(import.meta.url);
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
29
28
|
const ENVIRONMENT_VERSION = require('../package.json').version;
|
|
30
29
|
const debug = createdLogger('yeoman:environment');
|
|
31
|
-
const getInstantiateOptions = (
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const getInstantiateOptions = (firstArg, generatorOptions) => {
|
|
31
|
+
// First argument can be an array of string, a string, a ComposeOptions, a GeneratorOptions, old variant of ComposeOptions.
|
|
32
|
+
if (Array.isArray(firstArg) || typeof firstArg === 'string') {
|
|
33
|
+
return { generatorArgs: splitArgumentsFromString(firstArg), generatorOptions };
|
|
34
34
|
}
|
|
35
|
-
if (
|
|
36
|
-
if ('generatorOptions' in
|
|
37
|
-
return
|
|
35
|
+
if (firstArg !== undefined) {
|
|
36
|
+
if ('generatorOptions' in firstArg || 'generatorArgs' in firstArg) {
|
|
37
|
+
return firstArg;
|
|
38
38
|
}
|
|
39
|
-
if ('options' in
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
if ('options' in firstArg || 'arguments' in firstArg || 'args' in firstArg) {
|
|
40
|
+
// Backward compatibility
|
|
41
|
+
const { args: insideArguments, arguments: generatorArguments = insideArguments, options: generatorOptions, ...remainingOptions } = firstArg;
|
|
42
|
+
return { generatorArgs: splitArgumentsFromString(generatorArguments), generatorOptions: generatorOptions ?? remainingOptions };
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
|
-
return { generatorOptions
|
|
45
|
+
return { generatorOptions };
|
|
45
46
|
};
|
|
46
47
|
const getComposeOptions = (...varargs) => {
|
|
47
48
|
if (varargs.filter(Boolean).length === 0)
|
|
48
49
|
return {};
|
|
49
|
-
const [
|
|
50
|
-
if (typeof
|
|
51
|
-
return { schedule:
|
|
50
|
+
const [arguments_, options, composeOptions] = varargs;
|
|
51
|
+
if (typeof arguments_ === 'boolean') {
|
|
52
|
+
return { schedule: arguments_ };
|
|
52
53
|
}
|
|
53
|
-
let
|
|
54
|
+
let generatorArguments;
|
|
54
55
|
let generatorOptions;
|
|
55
|
-
if (
|
|
56
|
-
if (Array.isArray(
|
|
57
|
-
|
|
56
|
+
if (arguments_ !== undefined) {
|
|
57
|
+
if (Array.isArray(arguments_)) {
|
|
58
|
+
generatorArguments = arguments_;
|
|
58
59
|
}
|
|
59
|
-
else if (typeof
|
|
60
|
-
|
|
60
|
+
else if (typeof arguments_ === 'string') {
|
|
61
|
+
generatorArguments = splitArgumentsFromString(String(arguments_));
|
|
61
62
|
}
|
|
62
|
-
else if (typeof
|
|
63
|
-
if ('generatorOptions' in
|
|
64
|
-
return
|
|
63
|
+
else if (typeof arguments_ === 'object') {
|
|
64
|
+
if ('generatorOptions' in arguments_ || 'generatorArgs' in arguments_ || 'schedule' in arguments_) {
|
|
65
|
+
return arguments_;
|
|
65
66
|
}
|
|
66
|
-
generatorOptions =
|
|
67
|
+
generatorOptions = arguments_;
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
if (typeof options === 'boolean') {
|
|
70
|
-
return { generatorArgs, generatorOptions, schedule: options };
|
|
71
|
+
return { generatorArgs: generatorArguments, generatorOptions, schedule: options };
|
|
71
72
|
}
|
|
72
73
|
generatorOptions = generatorOptions ?? options;
|
|
73
74
|
if (typeof composeOptions === 'boolean') {
|
|
74
|
-
return { generatorArgs, generatorOptions, schedule: composeOptions };
|
|
75
|
+
return { generatorArgs: generatorArguments, generatorOptions, schedule: composeOptions };
|
|
75
76
|
}
|
|
76
77
|
return {};
|
|
77
78
|
};
|
|
@@ -102,6 +103,7 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
102
103
|
experimental;
|
|
103
104
|
_rootGenerator;
|
|
104
105
|
compatibilityMode;
|
|
106
|
+
contextStore = new Map();
|
|
105
107
|
constructor(options = {}) {
|
|
106
108
|
super();
|
|
107
109
|
this.setMaxListeners(100);
|
|
@@ -131,7 +133,6 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
131
133
|
registry: arboristRegistry,
|
|
132
134
|
},
|
|
133
135
|
});
|
|
134
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
135
136
|
this.experimental = experimental || process.argv.includes('--experimental');
|
|
136
137
|
this.alias(/^([^:]+)$/, '$1:app');
|
|
137
138
|
}
|
|
@@ -148,6 +149,7 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
148
149
|
...transformStreams,
|
|
149
150
|
transform(file => {
|
|
150
151
|
step('Completed', relative(this.logCwd, file.path));
|
|
152
|
+
// eslint-disable-next-line unicorn/no-useless-undefined
|
|
151
153
|
return undefined;
|
|
152
154
|
}),
|
|
153
155
|
]);
|
|
@@ -157,7 +159,7 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
157
159
|
* @param namespaceOrPath
|
|
158
160
|
* @return the generator meta registered under the namespace
|
|
159
161
|
*/
|
|
160
|
-
|
|
162
|
+
findMeta(namespaceOrPath) {
|
|
161
163
|
// Stop the recursive search if nothing is left
|
|
162
164
|
if (!namespaceOrPath) {
|
|
163
165
|
return;
|
|
@@ -172,12 +174,14 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
172
174
|
return maybeMeta;
|
|
173
175
|
}
|
|
174
176
|
try {
|
|
175
|
-
const resolved =
|
|
177
|
+
const resolved = resolveModulePath(namespaceOrPath);
|
|
176
178
|
if (resolved) {
|
|
177
179
|
return this.store.add({ resolved, namespace: this.namespace(resolved) });
|
|
178
180
|
}
|
|
179
181
|
}
|
|
180
|
-
catch {
|
|
182
|
+
catch {
|
|
183
|
+
// ignore error
|
|
184
|
+
}
|
|
181
185
|
return undefined;
|
|
182
186
|
}
|
|
183
187
|
/**
|
|
@@ -190,71 +194,53 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
190
194
|
* @param namespaceOrPath
|
|
191
195
|
* @return the generator registered under the namespace
|
|
192
196
|
*/
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return meta?.importGenerator();
|
|
197
|
+
get(namespaceOrPath) {
|
|
198
|
+
return this.findMeta(namespaceOrPath)?.importGenerator();
|
|
196
199
|
}
|
|
197
|
-
|
|
198
|
-
let constructor;
|
|
200
|
+
create(namespaceOrPath, ...arguments_) {
|
|
199
201
|
const namespace = typeof namespaceOrPath === 'string' ? toNamespace(namespaceOrPath) : undefined;
|
|
200
202
|
const checkGenerator = (Generator) => {
|
|
201
203
|
const generatorNamespace = Generator?.namespace;
|
|
202
|
-
if (namespace && generatorNamespace !== namespace.namespace && generatorNamespace !== UNKNOWN_NAMESPACE) {
|
|
204
|
+
if (namespace && generatorNamespace && generatorNamespace !== namespace.namespace && generatorNamespace !== UNKNOWN_NAMESPACE) {
|
|
203
205
|
// Update namespace object in case of aliased namespace.
|
|
204
206
|
try {
|
|
205
|
-
namespace.namespace =
|
|
207
|
+
namespace.namespace = generatorNamespace;
|
|
206
208
|
}
|
|
207
209
|
catch {
|
|
208
210
|
// Invalid namespace can be aliased to a valid one.
|
|
209
211
|
}
|
|
210
212
|
}
|
|
211
213
|
if (typeof Generator !== 'function') {
|
|
212
|
-
throw new TypeError(chalk.red(`You don't seem to have a generator with the name “${namespace?.generatorHint}” installed.`) +
|
|
213
|
-
|
|
214
|
-
'
|
|
215
|
-
|
|
216
|
-
chalk.yellow('
|
|
217
|
-
'
|
|
218
|
-
chalk.yellow('
|
|
219
|
-
'. \n' +
|
|
220
|
-
'Install them with ' +
|
|
221
|
-
chalk.yellow(`npm install ${namespace?.generatorHint}`) +
|
|
222
|
-
'.\n\n' +
|
|
223
|
-
'To see all your installed generators run ' +
|
|
224
|
-
chalk.yellow('yo --generators') +
|
|
225
|
-
'. ' +
|
|
226
|
-
'Adding the ' +
|
|
227
|
-
chalk.yellow('--help') +
|
|
228
|
-
' option will also show subgenerators. \n\n' +
|
|
229
|
-
'If ' +
|
|
230
|
-
chalk.yellow('yo') +
|
|
231
|
-
' cannot find the generator, run ' +
|
|
232
|
-
chalk.yellow('yo doctor') +
|
|
233
|
-
' to troubleshoot your system.');
|
|
214
|
+
throw new TypeError(`${chalk.red(`You don't seem to have a generator with the name “${namespace?.generatorHint}” installed.`)}\n` +
|
|
215
|
+
`But help is on the way:\n\n` +
|
|
216
|
+
`You can see available generators via ${chalk.yellow('npm search yeoman-generator')} or via ${chalk.yellow('http://yeoman.io/generators/')}. \n` +
|
|
217
|
+
`Install them with ${chalk.yellow(`npm install ${namespace?.generatorHint}`)}.\n\n` +
|
|
218
|
+
`To see all your installed generators run ${chalk.yellow('yo --generators')}. ` +
|
|
219
|
+
`Adding the ${chalk.yellow('--help')} option will also show subgenerators. \n\n` +
|
|
220
|
+
`If ${chalk.yellow('yo')} cannot find the generator, run ${chalk.yellow('yo doctor')} to troubleshoot your system.`);
|
|
234
221
|
}
|
|
235
222
|
return Generator;
|
|
236
223
|
};
|
|
237
|
-
if (typeof namespaceOrPath !== 'string') {
|
|
238
|
-
return this.instantiate(checkGenerator(namespaceOrPath), ...args);
|
|
239
|
-
}
|
|
240
224
|
if (typeof namespaceOrPath === 'string') {
|
|
241
|
-
const meta =
|
|
242
|
-
constructor =
|
|
225
|
+
const meta = this.findMeta(namespaceOrPath);
|
|
226
|
+
const constructor = meta?.importGenerator();
|
|
243
227
|
if (namespace && !constructor) {
|
|
244
228
|
// Await this.lookupLocalNamespaces(namespace);
|
|
245
229
|
// constructor = await this.get(namespace);
|
|
246
230
|
}
|
|
247
|
-
if (constructor) {
|
|
248
|
-
constructor.
|
|
231
|
+
if (constructor && 'then' in constructor) {
|
|
232
|
+
return constructor.then(g => {
|
|
233
|
+
return this.instantiate(checkGenerator(g), ...arguments_);
|
|
234
|
+
});
|
|
249
235
|
}
|
|
236
|
+
return this.instantiate(checkGenerator(constructor), ...arguments_);
|
|
250
237
|
}
|
|
251
238
|
else {
|
|
252
|
-
|
|
239
|
+
return this.instantiate(checkGenerator(namespaceOrPath), ...arguments_);
|
|
253
240
|
}
|
|
254
|
-
return this.instantiate(checkGenerator(constructor), ...args);
|
|
255
241
|
}
|
|
256
|
-
|
|
257
|
-
const composeOptions =
|
|
242
|
+
instantiate(constructor, ...arguments_) {
|
|
243
|
+
const composeOptions = arguments_.length > 0 ? getInstantiateOptions(...arguments_) : {};
|
|
258
244
|
const { namespace = UNKNOWN_NAMESPACE, resolved = UNKNOWN_RESOLVED, _meta } = constructor;
|
|
259
245
|
const environmentOptions = { env: this, resolved, namespace };
|
|
260
246
|
const generator = new constructor(composeOptions.generatorArgs ?? [], {
|
|
@@ -269,12 +255,12 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
269
255
|
...environmentOptions,
|
|
270
256
|
};
|
|
271
257
|
if (!composeOptions.generatorOptions?.help && generator._postConstruct) {
|
|
272
|
-
|
|
258
|
+
return Promise.resolve(generator._postConstruct()).then(() => generator);
|
|
273
259
|
}
|
|
274
260
|
return generator;
|
|
275
261
|
}
|
|
276
|
-
async composeWith(generator, ...
|
|
277
|
-
const options = getComposeOptions(...
|
|
262
|
+
async composeWith(generator, ...arguments_) {
|
|
263
|
+
const options = getComposeOptions(...arguments_);
|
|
278
264
|
const { schedule: passedSchedule = true, ...instantiateOptions } = options;
|
|
279
265
|
const generatorInstance = await this.create(generator, instantiateOptions);
|
|
280
266
|
// Convert to function to keep type compatibility with old @yeoman/types where schedule is boolean only
|
|
@@ -323,7 +309,7 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
323
309
|
* @return {Generator} The generator or singleton instance.
|
|
324
310
|
*/
|
|
325
311
|
async queueGenerator(generator, queueOptions) {
|
|
326
|
-
const schedule = typeof queueOptions === 'boolean' ? queueOptions : queueOptions?.schedule ?? false;
|
|
312
|
+
const schedule = typeof queueOptions === 'boolean' ? queueOptions : (queueOptions?.schedule ?? false);
|
|
327
313
|
const { added, identifier, generator: composedGenerator } = this.composedStore.addGenerator(generator);
|
|
328
314
|
if (!added) {
|
|
329
315
|
debug(`Using existing generator for namespace ${identifier}`);
|
|
@@ -339,10 +325,12 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
339
325
|
await generator.queueTasks();
|
|
340
326
|
return;
|
|
341
327
|
}
|
|
342
|
-
|
|
343
|
-
|
|
328
|
+
// Backward compatibility
|
|
329
|
+
const oldGenerator = generator;
|
|
330
|
+
if (!oldGenerator.options.forwardErrorToEnvironment) {
|
|
331
|
+
oldGenerator.on('error', (error) => this.emit('error', error));
|
|
344
332
|
}
|
|
345
|
-
|
|
333
|
+
oldGenerator.promise = oldGenerator.run();
|
|
346
334
|
};
|
|
347
335
|
if (schedule) {
|
|
348
336
|
this.queueTask('environment:run', async () => runGenerator());
|
|
@@ -366,20 +354,20 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
366
354
|
this._rootGenerator = this._rootGenerator ?? generator;
|
|
367
355
|
return this.start(generator.options);
|
|
368
356
|
}
|
|
369
|
-
register(pathOrStub, meta, ...
|
|
357
|
+
register(pathOrStub, meta, ...arguments_) {
|
|
370
358
|
if (typeof pathOrStub === 'string') {
|
|
371
359
|
if (typeof meta === 'object') {
|
|
372
360
|
return this.registerGeneratorPath(pathOrStub, meta.namespace, meta.packagePath);
|
|
373
361
|
}
|
|
374
362
|
// Backward compatibility
|
|
375
|
-
return this.registerGeneratorPath(pathOrStub, meta, ...
|
|
363
|
+
return this.registerGeneratorPath(pathOrStub, meta, ...arguments_);
|
|
376
364
|
}
|
|
377
365
|
if (pathOrStub) {
|
|
378
366
|
if (typeof meta === 'object') {
|
|
379
367
|
return this.registerStub(pathOrStub, meta.namespace, meta.resolved, meta.packagePath);
|
|
380
368
|
}
|
|
381
369
|
// Backward compatibility
|
|
382
|
-
return this.registerStub(pathOrStub, meta, ...
|
|
370
|
+
return this.registerStub(pathOrStub, meta, ...arguments_);
|
|
383
371
|
}
|
|
384
372
|
throw new TypeError('You must provide a generator name to register.');
|
|
385
373
|
}
|
|
@@ -499,7 +487,6 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
499
487
|
if (!meta) {
|
|
500
488
|
return;
|
|
501
489
|
}
|
|
502
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
503
490
|
return { ...meta };
|
|
504
491
|
}
|
|
505
492
|
alias(match, value) {
|
|
@@ -513,7 +500,7 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
513
500
|
if (typeof match !== 'string') {
|
|
514
501
|
throw new TypeError('string is required');
|
|
515
502
|
}
|
|
516
|
-
const aliases = [...this.aliases].
|
|
503
|
+
const aliases = [...this.aliases].toReversed();
|
|
517
504
|
return aliases.reduce((resolved, alias) => {
|
|
518
505
|
if (!alias.match.test(resolved)) {
|
|
519
506
|
return resolved;
|
|
@@ -564,7 +551,8 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
564
551
|
return new Promise((resolve, reject) => {
|
|
565
552
|
Object.assign(this.options, removePropertiesWithNullishValues(pick(options, ['skipInstall', 'nodePackageManager'])));
|
|
566
553
|
this.logCwd = options.logCwd ?? this.logCwd;
|
|
567
|
-
|
|
554
|
+
const conflicterOptionsProperties = ['force', 'bail', 'ignoreWhitespace', 'dryRun', 'skipYoResolve'];
|
|
555
|
+
this.conflicterOptions = defaults({}, pick(this.options, conflicterOptionsProperties), pick(options, conflicterOptionsProperties));
|
|
568
556
|
this.conflicterOptions.cwd = this.logCwd;
|
|
569
557
|
this.queueCommit();
|
|
570
558
|
this.queueTask('install', () => {
|
|
@@ -695,4 +683,16 @@ export default class EnvironmentBase extends EventEmitter {
|
|
|
695
683
|
debug('Registered %s (%s) on package (%s)', namespace, resolved, packagePath);
|
|
696
684
|
return meta;
|
|
697
685
|
}
|
|
686
|
+
/**
|
|
687
|
+
* @experimental
|
|
688
|
+
* Get a map to store shared data, usually a generator root path to share a map by path.
|
|
689
|
+
*/
|
|
690
|
+
getContextMap(key, factory = () => new Map()) {
|
|
691
|
+
if (this.contextStore.has(key)) {
|
|
692
|
+
return this.contextStore.get(key);
|
|
693
|
+
}
|
|
694
|
+
const context = factory();
|
|
695
|
+
this.contextStore.set(key, context);
|
|
696
|
+
return context;
|
|
697
|
+
}
|
|
698
698
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { BaseGeneratorConstructor } from '@yeoman/types';
|
|
2
|
-
import { type LookupOptions } from './generator-lookup.
|
|
3
|
-
import EnvironmentBase, { type EnvironmentOptions } from './environment-base.
|
|
1
|
+
import type { BaseGeneratorConstructor, BaseGeneratorOptions, GeneratorEnvironmentOptions } from '@yeoman/types';
|
|
2
|
+
import { type LookupOptions } from './generator-lookup.ts';
|
|
3
|
+
import EnvironmentBase, { type EnvironmentOptions } from './environment-base.ts';
|
|
4
4
|
declare class FullEnvironment extends EnvironmentBase {
|
|
5
5
|
constructor(options?: EnvironmentOptions);
|
|
6
6
|
/**
|
|
@@ -14,7 +14,7 @@ declare class FullEnvironment extends EnvironmentBase {
|
|
|
14
14
|
*
|
|
15
15
|
* @param {Object} options
|
|
16
16
|
*/
|
|
17
|
-
loadSharedOptions(options: EnvironmentOptions): Pick<EnvironmentOptions, "skipInstall" | "forceInstall" | "skipCache" | "skipLocalCache" | "skipParseOptions" | "localConfigOnly"
|
|
17
|
+
loadSharedOptions(options: EnvironmentOptions): Pick<EnvironmentOptions, "askAnswered" | "skipInstall" | "forceInstall" | "skipCache" | "skipLocalCache" | "skipParseOptions" | "localConfigOnly">;
|
|
18
18
|
/**
|
|
19
19
|
* @protected
|
|
20
20
|
* Outputs the general help and usage. Optionally, if generators have been
|
|
@@ -62,7 +62,7 @@ declare class FullEnvironment extends EnvironmentBase {
|
|
|
62
62
|
* @param {string} generatorNamespace
|
|
63
63
|
* @param {string[]} args
|
|
64
64
|
*/
|
|
65
|
-
execute(generatorNamespace: string,
|
|
65
|
+
execute(generatorNamespace: string, arguments_?: never[]): Promise<void>;
|
|
66
66
|
requireGenerator(namespace: string): Promise<BaseGeneratorConstructor | undefined>;
|
|
67
67
|
/**
|
|
68
68
|
* Install generators at the custom local repository and register.
|
|
@@ -107,10 +107,7 @@ declare class FullEnvironment extends EnvironmentBase {
|
|
|
107
107
|
* on the provided arguments, options and the list of registered generators.
|
|
108
108
|
*
|
|
109
109
|
* When the environment was unable to resolve a generator, an error is raised.
|
|
110
|
-
*
|
|
111
|
-
* @param {String|Array} args
|
|
112
|
-
* @param {Object} [options]
|
|
113
110
|
*/
|
|
114
|
-
run(
|
|
111
|
+
run(arguments_?: string | string[], options?: EnvironmentOptions & BaseGeneratorOptions & Partial<GeneratorEnvironmentOptions>): Promise<void>;
|
|
115
112
|
}
|
|
116
113
|
export default FullEnvironment;
|
package/dist/environment-full.js
CHANGED
|
@@ -3,10 +3,11 @@ import { join, resolve } from 'node:path';
|
|
|
3
3
|
import { requireNamespace, toNamespace } from '@yeoman/namespace';
|
|
4
4
|
import { flyImport } from 'fly-import';
|
|
5
5
|
import { defaults, pick, uniq } from 'lodash-es';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
6
|
+
import { valid } from 'semver';
|
|
7
|
+
import {} from "./generator-lookup.js";
|
|
8
|
+
import YeomanCommand from "./util/command.js";
|
|
9
|
+
import EnvironmentBase, {} from "./environment-base.js";
|
|
10
|
+
import { splitArgsFromString as splitArgumentsFromString } from "./util/util.js";
|
|
10
11
|
class FullEnvironment extends EnvironmentBase {
|
|
11
12
|
constructor(options = {}, adapterCompat) {
|
|
12
13
|
if (adapterCompat) {
|
|
@@ -138,7 +139,7 @@ class FullEnvironment extends EnvironmentBase {
|
|
|
138
139
|
* @param {string} generatorNamespace
|
|
139
140
|
* @param {string[]} args
|
|
140
141
|
*/
|
|
141
|
-
async execute(generatorNamespace,
|
|
142
|
+
async execute(generatorNamespace, arguments_ = []) {
|
|
142
143
|
const namespace = requireNamespace(generatorNamespace);
|
|
143
144
|
if (!(await this.get(namespace.namespace))) {
|
|
144
145
|
await this.lookup({
|
|
@@ -156,7 +157,7 @@ class FullEnvironment extends EnvironmentBase {
|
|
|
156
157
|
// Instantiate the generator for options
|
|
157
158
|
const generator = await this.create(namespace.namespace, { generatorArgs: [], generatorOptions: { help: true } });
|
|
158
159
|
namespaceCommand.registerGenerator(generator);
|
|
159
|
-
namespaceCommand.
|
|
160
|
+
namespaceCommand.parse(arguments_, { from: 'user' });
|
|
160
161
|
return this.run([namespace.namespace, ...namespaceCommand.args], {
|
|
161
162
|
...namespaceCommand.opts(),
|
|
162
163
|
});
|
|
@@ -164,21 +165,22 @@ class FullEnvironment extends EnvironmentBase {
|
|
|
164
165
|
async requireGenerator(namespace) {
|
|
165
166
|
if (namespace === undefined) {
|
|
166
167
|
try {
|
|
167
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
168
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
168
169
|
// @ts-ignore
|
|
169
|
-
|
|
170
|
+
// eslint-disable-next-line import-x/no-unresolved
|
|
171
|
+
const { default: Generator } = await import('yeoman-generator');
|
|
170
172
|
return Generator;
|
|
171
173
|
}
|
|
172
|
-
catch {
|
|
173
|
-
|
|
174
|
+
catch {
|
|
175
|
+
// ignore error
|
|
176
|
+
}
|
|
174
177
|
const { default: Generator } = await flyImport('yeoman-generator');
|
|
175
178
|
return Generator;
|
|
176
179
|
}
|
|
177
180
|
// Namespace is a version
|
|
178
|
-
if (
|
|
181
|
+
if (valid(namespace)) {
|
|
179
182
|
// Create a hash to install any version range in the local repository
|
|
180
183
|
const hash = createHash('shake256', { outputLength: 2 }).update(namespace, 'utf8').digest('hex');
|
|
181
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
182
184
|
const { default: Generator } = await flyImport(`@yeoman/generator-impl-${hash}@npm:yeoman-generator@${namespace}`);
|
|
183
185
|
return Generator;
|
|
184
186
|
}
|
|
@@ -286,14 +288,10 @@ class FullEnvironment extends EnvironmentBase {
|
|
|
286
288
|
* on the provided arguments, options and the list of registered generators.
|
|
287
289
|
*
|
|
288
290
|
* When the environment was unable to resolve a generator, an error is raised.
|
|
289
|
-
*
|
|
290
|
-
* @param {String|Array} args
|
|
291
|
-
* @param {Object} [options]
|
|
292
291
|
*/
|
|
293
|
-
async run(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
let name = args.shift();
|
|
292
|
+
async run(arguments_, options = {}) {
|
|
293
|
+
arguments_ = Array.isArray(arguments_) ? arguments_ : splitArgumentsFromString(arguments_);
|
|
294
|
+
let name = arguments_.shift();
|
|
297
295
|
if (!name) {
|
|
298
296
|
throw new Error('Must provide at least one argument, the generator namespace to invoke.');
|
|
299
297
|
}
|
|
@@ -305,18 +303,17 @@ class FullEnvironment extends EnvironmentBase {
|
|
|
305
303
|
try {
|
|
306
304
|
await this.prepareEnvironment(name);
|
|
307
305
|
}
|
|
308
|
-
catch {
|
|
306
|
+
catch {
|
|
307
|
+
// ignore error
|
|
308
|
+
}
|
|
309
309
|
}
|
|
310
310
|
const generator = await this.create(name, {
|
|
311
|
-
generatorArgs:
|
|
312
|
-
generatorOptions:
|
|
313
|
-
...options,
|
|
314
|
-
initialGenerator: true,
|
|
315
|
-
},
|
|
311
|
+
generatorArgs: arguments_,
|
|
312
|
+
generatorOptions: options,
|
|
316
313
|
});
|
|
317
314
|
if (options.help) {
|
|
318
315
|
console.log(generator.help());
|
|
319
|
-
return
|
|
316
|
+
return;
|
|
320
317
|
}
|
|
321
318
|
return this.runGenerator(generator);
|
|
322
319
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type ModuleLookupOptions } from './module-lookup.
|
|
1
|
+
import type { LookupOptions as LookupOptionsApi } from '@yeoman/types';
|
|
2
|
+
import { type ModuleLookupOptions } from './module-lookup.ts';
|
|
3
3
|
export type LookupOptions = LookupOptionsApi & ModuleLookupOptions & {
|
|
4
4
|
lookups?: string[];
|
|
5
5
|
};
|
package/dist/generator-lookup.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { extname, isAbsolute, join, posix } from 'node:path';
|
|
2
2
|
import { pathToFileURL } from 'node:url';
|
|
3
3
|
import { requireNamespace, toNamespace } from '@yeoman/namespace';
|
|
4
|
-
import {
|
|
5
|
-
import { asNamespace, defaultLookups } from
|
|
4
|
+
import { findPackagesIn, getNpmPaths, moduleLookupSync } from "./module-lookup.js";
|
|
5
|
+
import { asNamespace, defaultLookups } from "./util/namespace.js";
|
|
6
6
|
export const defaultExtensions = ['.ts', '.cts', '.mts', '.js', '.cjs', '.mjs'];
|
|
7
7
|
/**
|
|
8
8
|
* Search for generators and their sub generators.
|
|
@@ -32,7 +32,7 @@ export async function lookupGenerators(options = {}, register) {
|
|
|
32
32
|
const { lookups = defaultLookups } = options;
|
|
33
33
|
options = {
|
|
34
34
|
// Js generators should be after, last will override registered one.
|
|
35
|
-
filePatterns: lookups.flatMap(prefix => defaultExtensions.map(
|
|
35
|
+
filePatterns: lookups.flatMap(prefix => defaultExtensions.map(extension => `${prefix}/*/index${extension}`)),
|
|
36
36
|
filterPaths: false,
|
|
37
37
|
packagePatterns: ['generator-*'],
|
|
38
38
|
reverse: !options.singleResult,
|
|
@@ -48,7 +48,7 @@ export async function lookupGenerators(options = {}, register) {
|
|
|
48
48
|
return filePath;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
return
|
|
51
|
+
return;
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
@@ -64,12 +64,12 @@ export async function lookupGenerators(options = {}, register) {
|
|
|
64
64
|
* @return {String} generator
|
|
65
65
|
*/
|
|
66
66
|
export function lookupGenerator(namespace, options) {
|
|
67
|
-
options = typeof options === 'boolean' ? { localOnly: options } : options ?? {};
|
|
67
|
+
options = typeof options === 'boolean' ? { localOnly: options } : (options ?? {});
|
|
68
68
|
options.singleResult = options.singleResult ?? true;
|
|
69
69
|
options.filePatterns = options.filePatterns ?? defaultLookups.map(prefix => join(prefix, '*/index.{js,ts}'));
|
|
70
70
|
const ns = requireNamespace(namespace);
|
|
71
71
|
options.packagePatterns = options.packagePatterns ?? [ns.generatorHint];
|
|
72
|
-
options.npmPaths = options.npmPaths ?? getNpmPaths({ localOnly: options.localOnly }).
|
|
72
|
+
options.npmPaths = options.npmPaths ?? getNpmPaths({ localOnly: options.localOnly }).toReversed();
|
|
73
73
|
options.packagePatterns = options.packagePatterns ?? ['generator-*'];
|
|
74
74
|
options.packagePaths = options.packagePaths ?? findPackagesIn(options.npmPaths, options.packagePatterns);
|
|
75
75
|
let paths = options.singleResult ? undefined : [];
|
|
@@ -87,7 +87,7 @@ export function lookupGenerator(namespace, options) {
|
|
|
87
87
|
paths.push(returnPath);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
return
|
|
90
|
+
return;
|
|
91
91
|
});
|
|
92
92
|
if (options.singleResult) {
|
|
93
93
|
const generatorPath = paths;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { type EnvironmentOptions } from './environment-base.
|
|
2
|
-
import Environment from './environment-full.
|
|
3
|
-
export { default } from './environment-full.
|
|
4
|
-
export { default as EnvironmentBase } from './environment-base.
|
|
1
|
+
import { type EnvironmentOptions } from './environment-base.ts';
|
|
2
|
+
import Environment from './environment-full.ts';
|
|
3
|
+
export { default } from './environment-full.ts';
|
|
4
|
+
export { default as EnvironmentBase } from './environment-base.ts';
|
|
5
5
|
export declare const createEnv: (options?: EnvironmentOptions) => Environment;
|
|
6
|
-
export
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export
|
|
6
|
+
export declare const enforceUpdate: () => void;
|
|
7
|
+
export * from './commands.ts';
|
|
8
|
+
export * from './util/command.ts';
|
|
9
|
+
export * from './package-manager.ts';
|
|
10
|
+
export * from './commit.ts';
|
|
11
|
+
export { lookupGenerator } from './generator-lookup.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export { default
|
|
1
|
+
import {} from "./environment-base.js";
|
|
2
|
+
import Environment from "./environment-full.js";
|
|
3
|
+
export { default } from "./environment-full.js";
|
|
4
|
+
export { default as EnvironmentBase } from "./environment-base.js";
|
|
4
5
|
export const createEnv = (options) => new Environment(options);
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export
|
|
6
|
+
// Backward compatibility
|
|
7
|
+
export const enforceUpdate = () => { };
|
|
8
|
+
export * from "./commands.js";
|
|
9
|
+
export * from "./util/command.js";
|
|
10
|
+
export * from "./package-manager.js";
|
|
11
|
+
export * from "./commit.js";
|
|
12
|
+
export { lookupGenerator } from "./generator-lookup.js";
|
package/dist/module-lookup.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type ModuleLookupOptions = {
|
|
|
21
21
|
/**
|
|
22
22
|
* Search for npm packages.
|
|
23
23
|
*/
|
|
24
|
-
export declare function moduleLookupSync(options: ModuleLookupOptions, find: (
|
|
24
|
+
export declare function moduleLookupSync(options: ModuleLookupOptions, find: (argument: {
|
|
25
25
|
files: string[];
|
|
26
26
|
packagePath: string;
|
|
27
27
|
}) => string | undefined): {
|