1
- import EventEmitter from 'node:events' ;
2
1
import { createRequire } from 'node:module' ;
3
2
import { basename , isAbsolute , join , relative , resolve } from 'node:path' ;
4
3
import process from 'node:process' ;
@@ -35,13 +34,13 @@ import { type ConflicterOptions } from '@yeoman/conflicter';
35
34
import { defaults , pick } from 'lodash-es' ;
36
35
import { ComposedStore } from './composed-store.js' ;
37
36
import Store from './store.js' ;
37
+ import Environment from './environment.js' ;
38
38
import type YeomanCommand from './util/command.js' ;
39
39
import { asNamespace , defaultLookups } from './util/namespace.js' ;
40
40
import { type LookupOptions , lookupGenerators } from './generator-lookup.js' ;
41
41
import { UNKNOWN_NAMESPACE , UNKNOWN_RESOLVED , defaultQueues } from './constants.js' ;
42
42
import { resolveModulePath } from './util/resolve.js' ;
43
43
import { commitSharedFsTask } from './commit.js' ;
44
- // eslint-disable-next-line import/order
45
44
import { packageManagerInstallTask } from './package-manager.js' ;
46
45
47
46
const require = createRequire ( import . meta. url ) ;
@@ -51,7 +50,7 @@ const ENVIRONMENT_VERSION = require('../package.json').version;
51
50
52
51
const debug = createdLogger ( 'yeoman:environment' ) ;
53
52
54
- type EnvironmentOptions = BaseEnvironmentOptions &
53
+ export type EnvironmentOptions = BaseEnvironmentOptions &
55
54
Omit < TerminalAdapterOptions , 'promptModule' > & {
56
55
adapter ?: InputOutputAdapter ;
57
56
logCwd ?: string ;
@@ -116,7 +115,7 @@ const getInstantiateOptions = (args?: any, options?: any): InstantiateOptions =>
116
115
return { generatorOptions : options } ;
117
116
} ;
118
117
119
- export default class EnvironmentBase extends EventEmitter implements BaseEnvironment {
118
+ export default class EnvironmentBase extends Environment implements BaseEnvironment {
120
119
cwd : string ;
121
120
adapter : QueuedAdapter ;
122
121
sharedFs : MemFs < MemFsEditorFile > ;
@@ -137,7 +136,12 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
137
136
protected _rootGenerator ?: BaseGenerator ;
138
137
protected compatibilityMode ?: false | 'v4' ;
139
138
140
- constructor ( options : EnvironmentOptions = { } ) {
139
+ constructor ( options ?: EnvironmentOptions ) ;
140
+ constructor ( options : EnvironmentOptions = { } , adapterCompat ?: InputOutputAdapter ) {
141
+ if ( adapterCompat ) {
142
+ options . adapter = adapterCompat ;
143
+ }
144
+
141
145
super ( ) ;
142
146
143
147
this . setMaxListeners ( 100 ) ;
@@ -198,6 +202,11 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
198
202
this . experimental = experimental || process . argv . includes ( '--experimental' ) ;
199
203
200
204
this . alias ( / ^ ( [ ^ : ] + ) $ / , '$1:app' ) ;
205
+
206
+ this . loadSharedOptions ( this . options ) ;
207
+ if ( this . sharedOptions . skipLocalCache === undefined ) {
208
+ this . sharedOptions . skipLocalCache = true ;
209
+ }
201
210
}
202
211
203
212
async applyTransforms ( transformStreams : Transform [ ] , options : ApplyTransformsOptions = { } ) : Promise < void > {
@@ -546,9 +555,9 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
546
555
* @param packagePath - PackagePath to the generator npm package (optional)
547
556
* @return environment - This environment
548
557
*/
549
- register ( filePath : string , meta ?: Partial < BaseGeneratorMeta > | undefined ) : void ;
550
- register ( generator : unknown , meta : BaseGeneratorMeta ) : void ;
551
- register ( pathOrStub : unknown , meta ?: Partial < BaseGeneratorMeta > | BaseGeneratorMeta , ...args : any [ ] ) : this {
558
+ register ( filePath : string , meta ?: Partial < BaseGeneratorMeta > | undefined ) : GeneratorMeta ;
559
+ register ( generator : unknown , meta : BaseGeneratorMeta ) : GeneratorMeta ;
560
+ register ( pathOrStub : unknown , meta ?: Partial < BaseGeneratorMeta > | BaseGeneratorMeta , ...args : any [ ] ) : GeneratorMeta {
552
561
if ( typeof pathOrStub === 'string' ) {
553
562
if ( typeof meta === 'object' ) {
554
563
return this . registerGeneratorPath ( pathOrStub , meta . namespace , meta . packagePath ) ;
@@ -832,7 +841,7 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
832
841
* @param packagePath - PackagePath to the generator npm package (optional)
833
842
* @return environment - This environment
834
843
*/
835
- protected registerGeneratorPath ( generatorPath : string , namespace ?: string , packagePath ?: string ) : this {
844
+ protected registerGeneratorPath ( generatorPath : string , namespace ?: string , packagePath ?: string ) : GeneratorMeta {
836
845
if ( typeof generatorPath !== 'string' ) {
837
846
throw new TypeError ( 'You must provide a generator name to register.' ) ;
838
847
}
@@ -850,13 +859,13 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
850
859
// Generator is already registered and matches the current namespace.
851
860
const generatorMeta = this . store . getMeta ( namespace ) ;
852
861
if ( generatorMeta && generatorMeta . resolved === generatorPath ) {
853
- return this ;
862
+ return generatorMeta ;
854
863
}
855
864
856
865
const meta = this . store . add ( { namespace, resolved : generatorPath , packagePath } ) ;
857
866
858
867
debug ( 'Registered %s (%s) on package %s (%s)' , namespace , generatorPath , meta . packageNamespace , packagePath ) ;
859
- return this ;
868
+ return meta ;
860
869
}
861
870
862
871
/**
@@ -869,7 +878,7 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
869
878
* @param resolved - The file path to the generator
870
879
* @param packagePath - The generator's package path
871
880
*/
872
- protected registerStub ( Generator : any , namespace : string , resolved = UNKNOWN_RESOLVED , packagePath ?: string ) : this {
881
+ protected registerStub ( Generator : any , namespace : string , resolved = UNKNOWN_RESOLVED , packagePath ?: string ) : GeneratorMeta {
873
882
if ( typeof Generator !== 'function' && typeof Generator . createGenerator !== 'function' ) {
874
883
throw new TypeError ( 'You must provide a stub function to register.' ) ;
875
884
}
@@ -878,9 +887,9 @@ export default class EnvironmentBase extends EventEmitter implements BaseEnviron
878
887
throw new TypeError ( 'You must provide a namespace to register.' ) ;
879
888
}
880
889
881
- this . store . add ( { namespace, resolved, packagePath } , Generator ) ;
890
+ const meta = this . store . add ( { namespace, resolved, packagePath } , Generator ) ;
882
891
883
892
debug ( 'Registered %s (%s) on package (%s)' , namespace , resolved , packagePath ) ;
884
- return this ;
893
+ return meta ;
885
894
}
886
895
}
0 commit comments