From: Haoqun Jiang Date: Thu, 7 Oct 2021 06:39:40 +0000 (+0800) Subject: feat: sort dependencies before writing to disk X-Git-Tag: v3.0.0-beta.4~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10f4d2e8d51c412fe7b10c8d4dcad4c22bb60c29;p=thirdparty%2Fvuejs%2Fcreate-vue.git feat: sort dependencies before writing to disk So that users' subsequent `npm add` calls won't mess the `package.json`. --- diff --git a/playground/jsx-router-vuex-with-tests/package.json b/playground/jsx-router-vuex-with-tests/package.json index f0a58767..4d926163 100644 --- a/playground/jsx-router-vuex-with-tests/package.json +++ b/playground/jsx-router-vuex-with-tests/package.json @@ -17,12 +17,12 @@ "vuex": "^4.0.2" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", - "@vitejs/plugin-vue-jsx": "^1.1.8", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", + "@vitejs/plugin-vue-jsx": "^1.1.8", "cypress": "^8.4.1", - "start-server-and-test": "^1.14.0" + "start-server-and-test": "^1.14.0", + "vite": "^2.5.10" } } diff --git a/playground/jsx-router-vuex/package.json b/playground/jsx-router-vuex/package.json index 0b78e2c2..aac1267c 100644 --- a/playground/jsx-router-vuex/package.json +++ b/playground/jsx-router-vuex/package.json @@ -14,7 +14,7 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", - "@vitejs/plugin-vue-jsx": "^1.1.8" + "@vitejs/plugin-vue-jsx": "^1.1.8", + "vite": "^2.5.10" } } diff --git a/playground/jsx-router-with-tests/package.json b/playground/jsx-router-with-tests/package.json index 2c7dc52c..698bc44d 100644 --- a/playground/jsx-router-with-tests/package.json +++ b/playground/jsx-router-with-tests/package.json @@ -16,12 +16,12 @@ "vue-router": "^4.0.11" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", - "@vitejs/plugin-vue-jsx": "^1.1.8", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", + "@vitejs/plugin-vue-jsx": "^1.1.8", "cypress": "^8.4.1", - "start-server-and-test": "^1.14.0" + "start-server-and-test": "^1.14.0", + "vite": "^2.5.10" } } diff --git a/playground/jsx-router/package.json b/playground/jsx-router/package.json index 8ded6f1f..c40a5ba7 100644 --- a/playground/jsx-router/package.json +++ b/playground/jsx-router/package.json @@ -13,7 +13,7 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", - "@vitejs/plugin-vue-jsx": "^1.1.8" + "@vitejs/plugin-vue-jsx": "^1.1.8", + "vite": "^2.5.10" } } diff --git a/playground/jsx-vuex-with-tests/package.json b/playground/jsx-vuex-with-tests/package.json index 5419d5bd..dc940746 100644 --- a/playground/jsx-vuex-with-tests/package.json +++ b/playground/jsx-vuex-with-tests/package.json @@ -16,12 +16,12 @@ "vuex": "^4.0.2" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", - "@vitejs/plugin-vue-jsx": "^1.1.8", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", + "@vitejs/plugin-vue-jsx": "^1.1.8", "cypress": "^8.4.1", - "start-server-and-test": "^1.14.0" + "start-server-and-test": "^1.14.0", + "vite": "^2.5.10" } } diff --git a/playground/jsx-vuex/package.json b/playground/jsx-vuex/package.json index 98f2cdc0..96197f1e 100644 --- a/playground/jsx-vuex/package.json +++ b/playground/jsx-vuex/package.json @@ -13,7 +13,7 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", - "@vitejs/plugin-vue-jsx": "^1.1.8" + "@vitejs/plugin-vue-jsx": "^1.1.8", + "vite": "^2.5.10" } } diff --git a/playground/jsx-with-tests/package.json b/playground/jsx-with-tests/package.json index 94715659..9a71515d 100644 --- a/playground/jsx-with-tests/package.json +++ b/playground/jsx-with-tests/package.json @@ -15,12 +15,12 @@ "vue": "^3.2.14" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", - "@vitejs/plugin-vue-jsx": "^1.1.8", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", + "@vitejs/plugin-vue-jsx": "^1.1.8", "cypress": "^8.4.1", - "start-server-and-test": "^1.14.0" + "start-server-and-test": "^1.14.0", + "vite": "^2.5.10" } } diff --git a/playground/jsx/package.json b/playground/jsx/package.json index 6ef981a2..58d163da 100644 --- a/playground/jsx/package.json +++ b/playground/jsx/package.json @@ -12,7 +12,7 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", - "@vitejs/plugin-vue-jsx": "^1.1.8" + "@vitejs/plugin-vue-jsx": "^1.1.8", + "vite": "^2.5.10" } } diff --git a/playground/router-vuex-with-tests/package.json b/playground/router-vuex-with-tests/package.json index ec1f28f2..8e529978 100644 --- a/playground/router-vuex-with-tests/package.json +++ b/playground/router-vuex-with-tests/package.json @@ -17,11 +17,11 @@ "vuex": "^4.0.2" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", "cypress": "^8.4.1", - "start-server-and-test": "^1.14.0" + "start-server-and-test": "^1.14.0", + "vite": "^2.5.10" } } diff --git a/playground/router-with-tests/package.json b/playground/router-with-tests/package.json index 22ff7ce1..77f004cf 100644 --- a/playground/router-with-tests/package.json +++ b/playground/router-with-tests/package.json @@ -16,11 +16,11 @@ "vue-router": "^4.0.11" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", "cypress": "^8.4.1", - "start-server-and-test": "^1.14.0" + "start-server-and-test": "^1.14.0", + "vite": "^2.5.10" } } diff --git a/playground/typescript-jsx-router-vuex-with-tests/package.json b/playground/typescript-jsx-router-vuex-with-tests/package.json index 628d74c5..9d7e769c 100644 --- a/playground/typescript-jsx-router-vuex-with-tests/package.json +++ b/playground/typescript-jsx-router-vuex-with-tests/package.json @@ -18,14 +18,14 @@ "vuex": "^4.0.2" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", - "@vitejs/plugin-vue-jsx": "^1.1.8", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", + "@vitejs/plugin-vue-jsx": "^1.1.8", "cypress": "^8.4.1", "start-server-and-test": "^1.14.0", - "typescript": "~4.4.3", + "typescript": "~4.3.5", + "vite": "^2.5.10", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript-jsx-router-vuex/package.json b/playground/typescript-jsx-router-vuex/package.json index c80923e4..6c75c616 100644 --- a/playground/typescript-jsx-router-vuex/package.json +++ b/playground/typescript-jsx-router-vuex/package.json @@ -15,9 +15,9 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", "@vitejs/plugin-vue-jsx": "^1.1.8", - "typescript": "~4.4.3", + "typescript": "~4.3.5", + "vite": "^2.5.10", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript-jsx-router-with-tests/package.json b/playground/typescript-jsx-router-with-tests/package.json index f04733c4..202eea67 100644 --- a/playground/typescript-jsx-router-with-tests/package.json +++ b/playground/typescript-jsx-router-with-tests/package.json @@ -17,14 +17,14 @@ "vue-router": "^4.0.11" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", - "@vitejs/plugin-vue-jsx": "^1.1.8", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", + "@vitejs/plugin-vue-jsx": "^1.1.8", "cypress": "^8.4.1", "start-server-and-test": "^1.14.0", - "typescript": "~4.4.3", + "typescript": "~4.3.5", + "vite": "^2.5.10", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript-jsx-router/package.json b/playground/typescript-jsx-router/package.json index 91aba406..cc3549f9 100644 --- a/playground/typescript-jsx-router/package.json +++ b/playground/typescript-jsx-router/package.json @@ -14,9 +14,9 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", "@vitejs/plugin-vue-jsx": "^1.1.8", - "typescript": "~4.4.3", + "typescript": "~4.3.5", + "vite": "^2.5.10", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript-jsx-vuex-with-tests/package.json b/playground/typescript-jsx-vuex-with-tests/package.json index 459ddcda..ec59c6d5 100644 --- a/playground/typescript-jsx-vuex-with-tests/package.json +++ b/playground/typescript-jsx-vuex-with-tests/package.json @@ -17,14 +17,14 @@ "vuex": "^4.0.2" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", - "@vitejs/plugin-vue-jsx": "^1.1.8", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", + "@vitejs/plugin-vue-jsx": "^1.1.8", "cypress": "^8.4.1", "start-server-and-test": "^1.14.0", - "typescript": "~4.4.3", + "typescript": "~4.3.5", + "vite": "^2.5.10", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript-jsx-vuex/package.json b/playground/typescript-jsx-vuex/package.json index f9e22a86..96b51edc 100644 --- a/playground/typescript-jsx-vuex/package.json +++ b/playground/typescript-jsx-vuex/package.json @@ -14,9 +14,9 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", "@vitejs/plugin-vue-jsx": "^1.1.8", - "typescript": "~4.4.3", + "typescript": "~4.3.5", + "vite": "^2.5.10", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript-jsx-with-tests/package.json b/playground/typescript-jsx-with-tests/package.json index cdbde2f2..42ccce56 100644 --- a/playground/typescript-jsx-with-tests/package.json +++ b/playground/typescript-jsx-with-tests/package.json @@ -16,14 +16,14 @@ "vue": "^3.2.14" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", - "@vitejs/plugin-vue-jsx": "^1.1.8", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", + "@vitejs/plugin-vue-jsx": "^1.1.8", "cypress": "^8.4.1", "start-server-and-test": "^1.14.0", - "typescript": "~4.4.3", + "typescript": "~4.3.5", + "vite": "^2.5.10", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript-jsx/package.json b/playground/typescript-jsx/package.json index a97d9bb4..26a97304 100644 --- a/playground/typescript-jsx/package.json +++ b/playground/typescript-jsx/package.json @@ -13,9 +13,9 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", "@vitejs/plugin-vue-jsx": "^1.1.8", - "typescript": "~4.4.3", + "typescript": "~4.3.5", + "vite": "^2.5.10", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript-router-vuex-with-tests/package.json b/playground/typescript-router-vuex-with-tests/package.json index 9df9339f..e483d34a 100644 --- a/playground/typescript-router-vuex-with-tests/package.json +++ b/playground/typescript-router-vuex-with-tests/package.json @@ -18,13 +18,13 @@ "vuex": "^4.0.2" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", "cypress": "^8.4.1", "start-server-and-test": "^1.14.0", - "typescript": "~4.4.3", + "typescript": "~4.3.5", + "vite": "^2.5.10", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript-router-vuex/package.json b/playground/typescript-router-vuex/package.json index af49f99d..dcfc29be 100644 --- a/playground/typescript-router-vuex/package.json +++ b/playground/typescript-router-vuex/package.json @@ -15,8 +15,8 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^1.9.0", + "typescript": "~4.3.5", "vite": "^2.5.10", - "typescript": "~4.4.3", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript-router-with-tests/package.json b/playground/typescript-router-with-tests/package.json index d2c03184..1380ab38 100644 --- a/playground/typescript-router-with-tests/package.json +++ b/playground/typescript-router-with-tests/package.json @@ -17,13 +17,13 @@ "vue-router": "^4.0.11" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", "cypress": "^8.4.1", "start-server-and-test": "^1.14.0", - "typescript": "~4.4.3", + "typescript": "~4.3.5", + "vite": "^2.5.10", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript-router/package.json b/playground/typescript-router/package.json index 9b04f569..28b96d1e 100644 --- a/playground/typescript-router/package.json +++ b/playground/typescript-router/package.json @@ -14,8 +14,8 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^1.9.0", + "typescript": "~4.3.5", "vite": "^2.5.10", - "typescript": "~4.4.3", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript-vuex-with-tests/package.json b/playground/typescript-vuex-with-tests/package.json index 24dff70e..c1c61d37 100644 --- a/playground/typescript-vuex-with-tests/package.json +++ b/playground/typescript-vuex-with-tests/package.json @@ -17,13 +17,13 @@ "vuex": "^4.0.2" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", "cypress": "^8.4.1", "start-server-and-test": "^1.14.0", - "typescript": "~4.4.3", + "typescript": "~4.3.5", + "vite": "^2.5.10", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript-vuex/package.json b/playground/typescript-vuex/package.json index 2914296b..19f0c31b 100644 --- a/playground/typescript-vuex/package.json +++ b/playground/typescript-vuex/package.json @@ -14,8 +14,8 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^1.9.0", + "typescript": "~4.3.5", "vite": "^2.5.10", - "typescript": "~4.4.3", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript-with-tests/package.json b/playground/typescript-with-tests/package.json index 6b11e932..99851e55 100644 --- a/playground/typescript-with-tests/package.json +++ b/playground/typescript-with-tests/package.json @@ -16,13 +16,13 @@ "vue": "^3.2.14" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", "cypress": "^8.4.1", "start-server-and-test": "^1.14.0", - "typescript": "~4.4.3", + "typescript": "~4.3.5", + "vite": "^2.5.10", "vue-tsc": "^0.3.0" } } diff --git a/playground/typescript/package.json b/playground/typescript/package.json index 9f7cdeb1..2ff1e120 100644 --- a/playground/typescript/package.json +++ b/playground/typescript/package.json @@ -13,8 +13,8 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^1.9.0", + "typescript": "~4.3.5", "vite": "^2.5.10", - "typescript": "~4.4.3", "vue-tsc": "^0.3.0" } } diff --git a/playground/vuex-with-tests/package.json b/playground/vuex-with-tests/package.json index a7ace752..b6bf55b8 100644 --- a/playground/vuex-with-tests/package.json +++ b/playground/vuex-with-tests/package.json @@ -16,11 +16,11 @@ "vuex": "^4.0.2" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", "cypress": "^8.4.1", - "start-server-and-test": "^1.14.0" + "start-server-and-test": "^1.14.0", + "vite": "^2.5.10" } } diff --git a/playground/with-tests/package.json b/playground/with-tests/package.json index 762402f7..ebae5b13 100644 --- a/playground/with-tests/package.json +++ b/playground/with-tests/package.json @@ -15,11 +15,11 @@ "vue": "^3.2.14" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.9.0", - "vite": "^2.5.10", "@cypress/vite-dev-server": "^2.1.0", "@cypress/vue": "^3.0.3", + "@vitejs/plugin-vue": "^1.9.0", "cypress": "^8.4.1", - "start-server-and-test": "^1.14.0" + "start-server-and-test": "^1.14.0", + "vite": "^2.5.10" } } diff --git a/utils/renderTemplate.js b/utils/renderTemplate.js index e9d4a3ac..09640051 100644 --- a/utils/renderTemplate.js +++ b/utils/renderTemplate.js @@ -2,6 +2,7 @@ import fs from 'fs' import path from 'path' import deepMerge from './deepMerge.js' +import sortDependencies from './sortDependencies.js' /** * Renders a template folder/file to the file system, @@ -28,7 +29,9 @@ function renderTemplate(src, dest) { if (filename === 'package.json' && fs.existsSync(dest)) { // merge instead of overwriting - const pkg = deepMerge(JSON.parse(fs.readFileSync(dest)), JSON.parse(fs.readFileSync(src))) + const existing = JSON.parse(fs.readFileSync(dest)) + const newPackage = JSON.parse(fs.readFileSync(src)) + const pkg = sortDependencies(deepMerge(existing, newPackage)) fs.writeFileSync(dest, JSON.stringify(pkg, null, 2) + '\n') return } diff --git a/utils/sortDependencies.js b/utils/sortDependencies.js new file mode 100644 index 00000000..60d07dd4 --- /dev/null +++ b/utils/sortDependencies.js @@ -0,0 +1,22 @@ +export default function sortDependencies(packageJson) { + const sorted = {} + + const depTypes = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'] + + for (const depType of depTypes) { + if (packageJson[depType]) { + sorted[depType] = {} + + Object.keys(packageJson[depType]) + .sort() + .forEach((name) => { + sorted[depType][name] = packageJson[depType][name] + }) + } + } + + return { + ...packageJson, + ...sorted + } +}