@@ -4,7 +4,7 @@ const inquirer = require('inquirer')
4
4
const EventEmitter = require ( 'events' )
5
5
const Generator = require ( './Generator' )
6
6
const cloneDeep = require ( 'lodash.clonedeep' )
7
- const sortObject = require ( './util/sortObject' )
7
+ // const sortObject = require('./util/sortObject')
8
8
const getVersions = require ( './util/getVersions' )
9
9
const PackageManager = require ( './util/ProjectPackageManager' )
10
10
const { clearConsole } = require ( './util/clearConsole' )
@@ -115,11 +115,11 @@ module.exports = class Creator extends EventEmitter {
115
115
// Currently we rely on the `plugins` object enumeration order,
116
116
// which depends on the order of the field initialization.
117
117
// FIXME: Remove this ugly hack after the plugin ordering API settled down
118
- if ( preset . plugins [ '@vue/cli-plugin-router' ] && preset . plugins [ '@vue/cli-plugin-typescript' ] ) {
119
- const tmp = preset . plugins [ '@vue/cli-plugin-typescript' ]
120
- delete preset . plugins [ '@vue/cli-plugin-typescript' ]
121
- preset . plugins [ '@vue/cli-plugin-typescript' ] = tmp
122
- }
118
+ // if (preset.plugins['@vue/cli-plugin-router'] && preset.plugins['@vue/cli-plugin-typescript']) {
119
+ // const tmp = preset.plugins['@vue/cli-plugin-typescript']
120
+ // delete preset.plugins['@vue/cli-plugin-typescript']
121
+ // preset.plugins['@vue/cli-plugin-typescript'] = tmp
122
+ // }
123
123
124
124
// legacy support for vuex
125
125
if ( preset . vuex ) {
@@ -370,9 +370,15 @@ module.exports = class Creator extends EventEmitter {
370
370
// { id: options } => [{ id, apply, options }]
371
371
async resolvePlugins ( rawPlugins , pkg ) {
372
372
// ensure cli-service is invoked first
373
- rawPlugins = sortObject ( rawPlugins , [ '@vue/cli-service' ] , true )
373
+ // rawPlugins = sortObject(rawPlugins, ['@vue/cli-service'], true)
374
+ /**
375
+ * @typedef {{before?: string|Array<string>, _before: Set<string> stage?: number)} } GeneratorApply
376
+ * @type {Array<{id: string, apply: GeneratorApply, options: any}> }
377
+ */
374
378
const plugins = [ ]
379
+
375
380
for ( const id of Object . keys ( rawPlugins ) ) {
381
+ /** @type {GeneratorApply }} */
376
382
const apply = loadModule ( `${ id } /generator` , this . context ) || ( ( ) => { } )
377
383
let options = rawPlugins [ id ] || { }
378
384
@@ -395,7 +401,35 @@ module.exports = class Creator extends EventEmitter {
395
401
}
396
402
}
397
403
398
- plugins . push ( { id, apply, options } )
404
+ // TODO: define function in @vue /cli-shared-utils
405
+ if ( typeof apply . before === 'string' ) {
406
+ apply . _before = new Set ( [ apply . before ] )
407
+ } else if ( Array . isArray ( apply . before ) ) {
408
+ apply . _before = new Set ( apply . before )
409
+ } else {
410
+ apply . _before = new Set ( )
411
+ }
412
+
413
+ let stage = 100
414
+ if ( typeof apply . stage === 'number' ) {
415
+ stage = apply . stage
416
+ }
417
+ let i = plugins . length
418
+ while ( i > 0 ) {
419
+ i --
420
+ const x = plugins [ i ]
421
+ plugins [ i + 1 ] = x
422
+ const xStage = x . apply . stage || 0
423
+ if ( xStage > stage ) {
424
+ continue
425
+ }
426
+ if ( xStage === stage && ! x . apply . _before . has ( id ) ) {
427
+ continue
428
+ }
429
+ i ++
430
+ break
431
+ }
432
+ plugins [ i ] = { id, apply, options }
399
433
}
400
434
return plugins
401
435
}
0 commit comments