Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] fix: Generate TypeScript templete when using Router #5697

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/@vue/cli/lib/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const debug = require('debug')
const GeneratorAPI = require('./GeneratorAPI')
const PackageManager = require('./util/ProjectPackageManager')
const sortObject = require('./util/sortObject')
const sortArrayPartially = require('./util/sortArrayPartially')
const writeFileTree = require('./util/writeFileTree')
const inferRootOptions = require('./util/inferRootOptions')
const normalizeFilePaths = require('./util/normalizeFilePaths')
Expand Down Expand Up @@ -143,6 +144,9 @@ module.exports = class Generator {
this.afterAnyInvokeCbs = []
this.postProcessFilesCbs = []

// `@vue/cli-plugin-router` must be executed before `@vue/cli-plugin-typescript`
this.plugins = sortArrayPartially(this.plugins, ['@vue/cli-plugin-router', '@vue/cli-plugin-typescript'])

// apply generators from plugins
for (const plugin of this.plugins) {
const { id, apply, options } = plugin
Expand Down
21 changes: 21 additions & 0 deletions packages/@vue/cli/lib/util/sortArrayPartially.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = function sortArrayPartially (array, idOrder) {
if (!array) return []
const res = array
const swappableIndexes = []
const subArrayItems = []

if (idOrder) {
idOrder.forEach(key => {
const index = array.findIndex((i) => i.id === key)
if (index !== -1) {
swappableIndexes.push(index)
subArrayItems.push(array[index])
}
})
}
swappableIndexes.sort().forEach((index, subIndex) => {
res[index] = subArrayItems[subIndex]
})

return res
}