@@ -189,19 +189,28 @@ class Generator extends Base {
189
189
} ) ;
190
190
191
191
this . env = this . options . env ;
192
- if ( ! this . env ) {
193
- throw new Error ( 'This generator requires an environment.' ) ;
194
- }
195
192
196
193
this . resolved = this . options . resolved || __dirname ;
197
194
this . description = this . description || '' ;
198
195
199
- // Determine the app root
200
- this . contextRoot = this . env . cwd ;
201
- this . destinationRoot ( this . options . destinationRoot || this . env . cwd ) ;
196
+ if ( this . env ) {
197
+ // Determine the app root
198
+ this . contextRoot = this . env . cwd ;
199
+ this . destinationRoot ( this . options . destinationRoot || this . env . cwd ) ;
200
+
201
+ // Ensure source/destination path, can be configured from subclasses
202
+ this . sourceRoot ( path . join ( path . dirname ( this . resolved ) , 'templates' ) ) ;
202
203
203
- // Ensure source/destination path, can be configured from subclasses
204
- this . sourceRoot ( path . join ( path . dirname ( this . resolved ) , 'templates' ) ) ;
204
+ this . fs = this . env . fs ;
205
+ }
206
+
207
+ // Add convenience debug object
208
+ this . _debug = createDebug (
209
+ this . options . namespace || 'yeoman:unknownnamespace'
210
+ ) ;
211
+
212
+ // Expose utilities for dependency-less generators.
213
+ this . _ = _ ;
205
214
206
215
if ( this . options . help ) {
207
216
return ;
@@ -232,8 +241,13 @@ class Generator extends Base {
232
241
this . features . uniqueBy = uniqueBy ;
233
242
}
234
243
244
+ if ( ! this . env ) {
245
+ throw new Error ( 'This generator requires an environment.' ) ;
246
+ }
247
+
235
248
// Ensure the environment support features this yeoman-generator version require.
236
249
if (
250
+ ! this . env ||
237
251
! this . env . adapter ||
238
252
! this . env . runLoop ||
239
253
! this . env . sharedFs ||
@@ -244,22 +258,15 @@ class Generator extends Base {
244
258
) ;
245
259
}
246
260
247
- this . fs = this . env . fs ;
248
-
249
- // Place holder for run-async callback.
250
- this . async = ( ) => ( ) => { } ;
251
-
252
261
// Mirror the adapter log method on the generator.
253
262
//
254
263
// example:
255
264
// this.log('foo');
256
265
// this.log.error('bar');
257
- this . log = this . env . adapter . log ;
266
+ this . log = this . env . adapter && this . env . adapter . log ;
258
267
259
- // Add convenience debug object
260
- this . _debug = createDebug (
261
- this . options . namespace || 'yeoman:unknownnamespace'
262
- ) ;
268
+ // Place holder for run-async callback.
269
+ this . async = ( ) => ( ) => { } ;
263
270
264
271
this . appname = this . determineAppname ( ) ;
265
272
@@ -292,9 +299,6 @@ class Generator extends Base {
292
299
293
300
this . compose = this . options . compose ;
294
301
295
- // Expose utilities for dependency-less generators.
296
- this . _ = _ ;
297
-
298
302
// Requires environment 3
299
303
if ( ! this . options . skipCheckEnv ) {
300
304
this . checkEnvironmentVersion ( '3.0.0' ) ;
0 commit comments