From 4c85bcd9f3ce2f5a23eb2cccccced5b59d3c96b7 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 31 Mar 2022 15:59:42 +0300 Subject: [PATCH] Sync local dependencies, script to automatically update version numbers --- demo/ember-demo/package.json | 140 ++++++++++++------------ demo/nextjs-demo/package-lock.json | 2 +- demo/nextjs-demo/package.json | 2 +- demo/nuxt3-demo/package-lock.json | 2 +- demo/nuxt3-demo/package.json | 2 +- demo/react-demo/package-lock.json | 4 +- demo/react-demo/package.json | 4 +- demo/sapper-demo/package-lock.json | 2 +- demo/sapper-demo/package.json | 2 +- demo/svelte-demo-vite/package-lock.json | 2 +- demo/svelte-demo-vite/package.json | 2 +- demo/svelte-demo/package-lock.json | 2 +- demo/svelte-demo/package.json | 2 +- demo/sveltekit-demo/package-lock.json | 2 +- demo/sveltekit-demo/package.json | 2 +- demo/vue-demo/package-lock.json | 4 +- demo/vue-demo/package.json | 4 +- monorepo/src/helpers/clean.ts | 2 +- monorepo/src/helpers/versions.ts | 89 +++++++++++++++ monorepo/src/index.ts | 4 + package.json | 3 +- packages/core/package-lock.json | 14 +-- packages/core/package.json | 2 +- 23 files changed, 194 insertions(+), 100 deletions(-) create mode 100644 monorepo/src/helpers/versions.ts diff --git a/demo/ember-demo/package.json b/demo/ember-demo/package.json index 4c0668d..5d326a4 100644 --- a/demo/ember-demo/package.json +++ b/demo/ember-demo/package.json @@ -1,72 +1,72 @@ { - "name": "ember-demo", - "version": "0.0.0", - "private": true, - "description": "Small description for ember-demo goes here", - "repository": "", - "license": "MIT", - "author": "", - "directories": { - "doc": "doc", - "test": "tests" - }, - "scripts": { - "build": "ember build --environment=production", - "lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"", - "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix", - "lint:hbs": "ember-template-lint .", - "lint:hbs:fix": "ember-template-lint . --fix", - "lint:js": "eslint . --cache", - "lint:js:fix": "eslint . --fix", - "start": "ember serve", - "test": "npm-run-all lint test:*", - "test:ember": "ember test" - }, - "devDependencies": { - "@ember/optional-features": "^2.0.0", - "@ember/test-helpers": "^2.6.0", - "@glimmer/component": "^1.0.4", - "@glimmer/tracking": "^1.0.4", - "@iconify-icons/mdi-light": "^1.1.1", - "@iconify/ember": "^1.0.3", - "babel-eslint": "^10.1.0", - "broccoli-asset-rev": "^3.0.0", - "ember-auto-import": "^2.2.4", - "ember-cli": "~4.1.0", - "ember-cli-app-version": "^5.0.0", - "ember-cli-babel": "^7.26.11", - "ember-cli-dependency-checker": "^3.2.0", - "ember-cli-htmlbars": "^6.0.1", - "ember-cli-inject-live-reload": "^2.1.0", - "ember-cli-sri": "^2.1.1", - "ember-cli-terser": "^4.0.2", - "ember-data": "~4.1.0", - "ember-export-application-global": "^2.0.1", - "ember-fetch": "^8.1.1", - "ember-load-initializers": "^2.1.2", - "ember-page-title": "^7.0.0", - "ember-qunit": "^5.1.5", - "ember-resolver": "^8.0.3", - "ember-source": "~4.1.0", - "ember-template-lint": "^3.15.0", - "ember-welcome-page": "^6.0.0", - "eslint": "^7.32.0", - "eslint-config-prettier": "^8.3.0", - "eslint-plugin-ember": "^10.5.8", - "eslint-plugin-node": "^11.1.0", - "eslint-plugin-prettier": "^4.0.0", - "eslint-plugin-qunit": "^7.2.0", - "loader.js": "^4.7.0", - "npm-run-all": "^4.1.5", - "prettier": "^2.5.1", - "qunit": "^2.17.2", - "qunit-dom": "^2.0.0", - "webpack": "^5.65.0" - }, - "engines": { - "node": "12.* || 14.* || >= 16" - }, - "ember": { - "edition": "octane" - } + "name": "ember-demo", + "version": "0.0.0", + "private": true, + "description": "Small description for ember-demo goes here", + "repository": "", + "license": "MIT", + "author": "", + "directories": { + "doc": "doc", + "test": "tests" + }, + "scripts": { + "build": "ember build --environment=production", + "lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"", + "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix", + "lint:hbs": "ember-template-lint .", + "lint:hbs:fix": "ember-template-lint . --fix", + "lint:js": "eslint . --cache", + "lint:js:fix": "eslint . --fix", + "start": "ember serve", + "test": "npm-run-all lint test:*", + "test:ember": "ember test" + }, + "devDependencies": { + "@ember/optional-features": "^2.0.0", + "@ember/test-helpers": "^2.6.0", + "@glimmer/component": "^1.0.4", + "@glimmer/tracking": "^1.0.4", + "@iconify-icons/mdi-light": "^1.1.1", + "@iconify/ember": "^1.1.0", + "babel-eslint": "^10.1.0", + "broccoli-asset-rev": "^3.0.0", + "ember-auto-import": "^2.2.4", + "ember-cli": "~4.1.0", + "ember-cli-app-version": "^5.0.0", + "ember-cli-babel": "^7.26.11", + "ember-cli-dependency-checker": "^3.2.0", + "ember-cli-htmlbars": "^6.0.1", + "ember-cli-inject-live-reload": "^2.1.0", + "ember-cli-sri": "^2.1.1", + "ember-cli-terser": "^4.0.2", + "ember-data": "~4.1.0", + "ember-export-application-global": "^2.0.1", + "ember-fetch": "^8.1.1", + "ember-load-initializers": "^2.1.2", + "ember-page-title": "^7.0.0", + "ember-qunit": "^5.1.5", + "ember-resolver": "^8.0.3", + "ember-source": "~4.1.0", + "ember-template-lint": "^3.15.0", + "ember-welcome-page": "^6.0.0", + "eslint": "^7.32.0", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-ember": "^10.5.8", + "eslint-plugin-node": "^11.1.0", + "eslint-plugin-prettier": "^4.0.0", + "eslint-plugin-qunit": "^7.2.0", + "loader.js": "^4.7.0", + "npm-run-all": "^4.1.5", + "prettier": "^2.5.1", + "qunit": "^2.17.2", + "qunit-dom": "^2.0.0", + "webpack": "^5.65.0" + }, + "engines": { + "node": "12.* || 14.* || >= 16" + }, + "ember": { + "edition": "octane" + } } diff --git a/demo/nextjs-demo/package-lock.json b/demo/nextjs-demo/package-lock.json index 44c99d6..026e8a9 100644 --- a/demo/nextjs-demo/package-lock.json +++ b/demo/nextjs-demo/package-lock.json @@ -8,7 +8,7 @@ "name": "@iconify-demo/nextjs", "version": "0.1.0", "dependencies": { - "@iconify/react": "^3.1.3", + "@iconify/react": "^3.2.0", "next": "^12.0.8", "react": "^17.0.2", "react-dom": "^17.0.2" diff --git a/demo/nextjs-demo/package.json b/demo/nextjs-demo/package.json index 47d26da..72cfe3f 100644 --- a/demo/nextjs-demo/package.json +++ b/demo/nextjs-demo/package.json @@ -8,7 +8,7 @@ "start": "next start" }, "dependencies": { - "@iconify/react": "^3.1.3", + "@iconify/react": "^3.2.0", "next": "^12.0.8", "react": "^17.0.2", "react-dom": "^17.0.2" diff --git a/demo/nuxt3-demo/package-lock.json b/demo/nuxt3-demo/package-lock.json index 3e5a5dd..ccc5c42 100644 --- a/demo/nuxt3-demo/package-lock.json +++ b/demo/nuxt3-demo/package-lock.json @@ -6,7 +6,7 @@ "": { "name": "@iconify-demo/nuxt3", "dependencies": { - "@iconify/vue": "^3.1.3" + "@iconify/vue": "^3.2.0" }, "devDependencies": { "nuxt3": "latest" diff --git a/demo/nuxt3-demo/package.json b/demo/nuxt3-demo/package.json index 669a467..14b1e8a 100644 --- a/demo/nuxt3-demo/package.json +++ b/demo/nuxt3-demo/package.json @@ -10,6 +10,6 @@ "nuxt3": "latest" }, "dependencies": { - "@iconify/vue": "^3.1.3" + "@iconify/vue": "^3.2.0" } } diff --git a/demo/react-demo/package-lock.json b/demo/react-demo/package-lock.json index 88490ca..e3dc09b 100644 --- a/demo/react-demo/package-lock.json +++ b/demo/react-demo/package-lock.json @@ -14,8 +14,8 @@ "devDependencies": { "@iconify-icons/mdi-light": "^1.1.1", "@iconify-icons/uil": "^1.1.2", - "@iconify/core": "^1.2.3", - "@iconify/react": "^3.1.3", + "@iconify/core": "^1.3.1", + "@iconify/react": "^3.2.0", "@types/react": "^17.0.33", "@types/react-dom": "^17.0.10", "@vitejs/plugin-react": "^1.0.7", diff --git a/demo/react-demo/package.json b/demo/react-demo/package.json index 7e10711..c055655 100644 --- a/demo/react-demo/package.json +++ b/demo/react-demo/package.json @@ -14,8 +14,8 @@ "devDependencies": { "@iconify-icons/mdi-light": "^1.1.1", "@iconify-icons/uil": "^1.1.2", - "@iconify/core": "^1.2.3", - "@iconify/react": "^3.1.3", + "@iconify/core": "^1.3.1", + "@iconify/react": "^3.2.0", "@types/react": "^17.0.33", "@types/react-dom": "^17.0.10", "@vitejs/plugin-react": "^1.0.7", diff --git a/demo/sapper-demo/package-lock.json b/demo/sapper-demo/package-lock.json index 8a130da..22aeb73 100644 --- a/demo/sapper-demo/package-lock.json +++ b/demo/sapper-demo/package-lock.json @@ -19,7 +19,7 @@ "@babel/preset-env": "^7.16.11", "@babel/runtime": "^7.16.7", "@iconify-icons/openmoji": "^1.1.20", - "@iconify/svelte": "^2.1.2", + "@iconify/svelte": "^2.2.0", "@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-commonjs": "^21.0.1", "@rollup/plugin-node-resolve": "^13.1.3", diff --git a/demo/sapper-demo/package.json b/demo/sapper-demo/package.json index 591696b..d8a56f8 100644 --- a/demo/sapper-demo/package.json +++ b/demo/sapper-demo/package.json @@ -24,7 +24,7 @@ "@babel/preset-env": "^7.16.11", "@babel/runtime": "^7.16.7", "@iconify-icons/openmoji": "^1.1.20", - "@iconify/svelte": "^2.1.2", + "@iconify/svelte": "^2.2.0", "@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-commonjs": "^21.0.1", "@rollup/plugin-node-resolve": "^13.1.3", diff --git a/demo/svelte-demo-vite/package-lock.json b/demo/svelte-demo-vite/package-lock.json index 0e45e83..ded21bd 100644 --- a/demo/svelte-demo-vite/package-lock.json +++ b/demo/svelte-demo-vite/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.0", "devDependencies": { "@iconify-icons/mdi-light": "^1.1.1", - "@iconify/svelte": "^2.1.2", + "@iconify/svelte": "^2.2.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.35", "@tsconfig/svelte": "^3.0.0", "svelte": "^3.46.2", diff --git a/demo/svelte-demo-vite/package.json b/demo/svelte-demo-vite/package.json index f0a9fc3..dccc86e 100644 --- a/demo/svelte-demo-vite/package.json +++ b/demo/svelte-demo-vite/package.json @@ -11,7 +11,7 @@ }, "devDependencies": { "@iconify-icons/mdi-light": "^1.1.1", - "@iconify/svelte": "^2.1.2", + "@iconify/svelte": "^2.2.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.35", "@tsconfig/svelte": "^3.0.0", "svelte": "^3.46.2", diff --git a/demo/svelte-demo/package-lock.json b/demo/svelte-demo/package-lock.json index 55303aa..0987fe8 100644 --- a/demo/svelte-demo/package-lock.json +++ b/demo/svelte-demo/package-lock.json @@ -13,7 +13,7 @@ "devDependencies": { "@iconify-icons/mdi-light": "^1.1.1", "@iconify-icons/uil": "^1.1.2", - "@iconify/svelte": "^2.1.2", + "@iconify/svelte": "^2.2.0", "@rollup/plugin-commonjs": "^16.0.0", "@rollup/plugin-node-resolve": "^10.0.0", "rollup": "^2.33.3", diff --git a/demo/svelte-demo/package.json b/demo/svelte-demo/package.json index 006ddfd..fe238bf 100644 --- a/demo/svelte-demo/package.json +++ b/demo/svelte-demo/package.json @@ -10,7 +10,7 @@ "devDependencies": { "@iconify-icons/mdi-light": "^1.1.1", "@iconify-icons/uil": "^1.1.2", - "@iconify/svelte": "^2.1.2", + "@iconify/svelte": "^2.2.0", "@rollup/plugin-commonjs": "^16.0.0", "@rollup/plugin-node-resolve": "^10.0.0", "rollup": "^2.33.3", diff --git a/demo/sveltekit-demo/package-lock.json b/demo/sveltekit-demo/package-lock.json index 1269322..6ac826c 100644 --- a/demo/sveltekit-demo/package-lock.json +++ b/demo/sveltekit-demo/package-lock.json @@ -14,7 +14,7 @@ }, "devDependencies": { "@iconify-icons/mdi-light": "^1.1.1", - "@iconify/svelte": "^2.1.2", + "@iconify/svelte": "^2.2.0", "@sveltejs/kit": "next", "@types/cookie": "^0.4.1", "svelte": "^3.46.2", diff --git a/demo/sveltekit-demo/package.json b/demo/sveltekit-demo/package.json index 7a0962e..5a3c908 100644 --- a/demo/sveltekit-demo/package.json +++ b/demo/sveltekit-demo/package.json @@ -11,7 +11,7 @@ }, "devDependencies": { "@iconify-icons/mdi-light": "^1.1.1", - "@iconify/svelte": "^2.1.2", + "@iconify/svelte": "^2.2.0", "@sveltejs/kit": "next", "@types/cookie": "^0.4.1", "svelte": "^3.46.2", diff --git a/demo/vue-demo/package-lock.json b/demo/vue-demo/package-lock.json index 2b97d08..9e0ddc3 100644 --- a/demo/vue-demo/package-lock.json +++ b/demo/vue-demo/package-lock.json @@ -13,8 +13,8 @@ "devDependencies": { "@iconify-icons/bx": "^1.1.5", "@iconify-icons/dashicons": "^1.1.1", - "@iconify/types": "^1.0.12", - "@iconify/vue": "^3.1.3", + "@iconify/types": "^1.1.0", + "@iconify/vue": "^3.2.0", "@vitejs/plugin-vue": "^2.1.0", "typescript": "^4.6.3", "vite": "^2.7.13" diff --git a/demo/vue-demo/package.json b/demo/vue-demo/package.json index 2bc155b..2114798 100644 --- a/demo/vue-demo/package.json +++ b/demo/vue-demo/package.json @@ -12,8 +12,8 @@ "devDependencies": { "@iconify-icons/bx": "^1.1.5", "@iconify-icons/dashicons": "^1.1.1", - "@iconify/types": "^1.0.12", - "@iconify/vue": "^3.1.3", + "@iconify/types": "^1.1.0", + "@iconify/vue": "^3.2.0", "@vitejs/plugin-vue": "^2.1.0", "typescript": "^4.6.3", "vite": "^2.7.13" diff --git a/monorepo/src/helpers/clean.ts b/monorepo/src/helpers/clean.ts index 9e68f4f..fc5f576 100644 --- a/monorepo/src/helpers/clean.ts +++ b/monorepo/src/helpers/clean.ts @@ -14,7 +14,7 @@ export function cleanWorkspace(workspace: PackageInfo) { if (!stat.isDirectory()) { return; } - } catch (err) { + } catch { return; } diff --git a/monorepo/src/helpers/versions.ts b/monorepo/src/helpers/versions.ts new file mode 100644 index 0000000..a5c2190 --- /dev/null +++ b/monorepo/src/helpers/versions.ts @@ -0,0 +1,89 @@ +import fs from 'fs'; +import { addLinksToWorkspace } from './add-links'; +import { addToPath, pathToString, relativePath } from './dirs'; +import { runNPMCommand } from './exec'; +import { consoleLog } from './log'; +import { PackageInfo } from './types'; +import { findWorkspaces } from './workspaces'; + +const props: string[] = [ + 'dependencies', + 'devDependencies', + 'optionalDependencies', +]; + +/** + * Change versions of local package + */ +export function updateVersions(workspace: PackageInfo) { + // Find all workspaces + const workspaces = findWorkspaces(); + + // Get package.json + const packageFilename = pathToString( + addToPath(workspace.path, 'package.json') + ); + + let data: Record; + try { + data = JSON.parse(fs.readFileSync(packageFilename, 'utf8')); + } catch { + return; + } + + const updated: Set = new Set(); + props.forEach((prop) => { + const dependencies = data[prop]; + if (typeof dependencies !== 'object') { + return; + } + + // Find local packages + workspaces.forEach((item) => { + if ( + item.name === workspace.name || + item.private || + typeof dependencies[item.name] !== 'string' + ) { + return; + } + + const newVersion = item.version; + const oldValue = dependencies[item.name] as string; + + // ^* + if (oldValue.slice(0, 1) === '^') { + const oldVersion = oldValue.slice(1); + if (oldVersion !== newVersion) { + // Change version + dependencies[item.name] = '^' + newVersion; + updated.add(item.name); + } + return; + } + + // exact version + if (oldValue.match(/^[0-9]/) && oldValue !== newVersion) { + dependencies[item.name] = newVersion; + updated.add(item.name); + } + }); + }); + + if (!updated.size) { + return; + } + + // Update package.json + const newContent = JSON.stringify(data, null, '\t') + '\n'; + fs.writeFileSync(packageFilename, newContent, 'utf8'); + consoleLog( + `Updated dependencies in ${relativePath(packageFilename)}: ${Array.from( + updated + ).join(', ')}` + ); + + // Reinstall dependencies to update package-lock.json + runNPMCommand(workspace, ['install']); + addLinksToWorkspace(workspace); +} diff --git a/monorepo/src/index.ts b/monorepo/src/index.ts index 0104482..4834ea4 100644 --- a/monorepo/src/index.ts +++ b/monorepo/src/index.ts @@ -4,6 +4,7 @@ import { cleanWorkspace } from './helpers/clean'; import { runNPMCommand } from './helpers/exec'; import { actionOptions, enablePrivateFilter } from './helpers/options'; import { removeLinksFromWorkspace } from './helpers/remove-links'; +import { updateVersions } from './helpers/versions'; /** * All actions @@ -24,6 +25,9 @@ const actionFunctions: Record void> = { addLinksToWorkspace(workspace); }); }, + versions: () => { + runAction('Updating versions of local packages', updateVersions); + }, }; /** diff --git a/package.json b/package.json index 405153b..7b12b94 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "unlink": "node monorepo unlink", "reinstall": "node monorepo clean install", "build": "node monorepo run build --if-present --public", - "test": "node monorepo run build --if-present --public" + "test": "node monorepo run build --if-present --public", + "versions": "node monorepo versions" }, "devDependencies": {} } diff --git a/packages/core/package-lock.json b/packages/core/package-lock.json index d0e43a6..053add2 100644 --- a/packages/core/package-lock.json +++ b/packages/core/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@iconify/api-redundancy": "^1.1.0", "@iconify/types": "^1.1.0", - "@iconify/utils": "^1.0.29" + "@iconify/utils": "^1.0.31" }, "devDependencies": { "@types/jest": "^27.4.1", @@ -796,9 +796,9 @@ "integrity": "sha512-Jh0llaK2LRXQoYsorIH8maClebsnzTcve+7U3rQUSnC11X4jtPnFuyatqFLvMxZ8MLG8dB4zfHsbPfuvxluONw==" }, "node_modules/@iconify/utils": { - "version": "1.0.29", - "resolved": "https://registry.npmjs.org/@iconify/utils/-/utils-1.0.29.tgz", - "integrity": "sha512-ReARQUYRAzuj0fvzUhHZlw38bMYq8u+oKsecMalk2Lp98b54uHtOcpEKTAdXwTwYV7MMxEGCa4pRmYofZtXdOw==", + "version": "1.0.31", + "resolved": "https://registry.npmjs.org/@iconify/utils/-/utils-1.0.31.tgz", + "integrity": "sha512-sBksCt6kI4WaMHwXo1c/MQVuQfWwwd87qHiAPASN8neoQvMCdYTLn+2khc3/OmYPbmg6kYisCxVLkAv0pcy9Ig==", "dependencies": { "@antfu/install-pkg": "^0.1.0", "@antfu/utils": "^0.5.0", @@ -7671,9 +7671,9 @@ "integrity": "sha512-Jh0llaK2LRXQoYsorIH8maClebsnzTcve+7U3rQUSnC11X4jtPnFuyatqFLvMxZ8MLG8dB4zfHsbPfuvxluONw==" }, "@iconify/utils": { - "version": "1.0.29", - "resolved": "https://registry.npmjs.org/@iconify/utils/-/utils-1.0.29.tgz", - "integrity": "sha512-ReARQUYRAzuj0fvzUhHZlw38bMYq8u+oKsecMalk2Lp98b54uHtOcpEKTAdXwTwYV7MMxEGCa4pRmYofZtXdOw==", + "version": "1.0.31", + "resolved": "https://registry.npmjs.org/@iconify/utils/-/utils-1.0.31.tgz", + "integrity": "sha512-sBksCt6kI4WaMHwXo1c/MQVuQfWwwd87qHiAPASN8neoQvMCdYTLn+2khc3/OmYPbmg6kYisCxVLkAv0pcy9Ig==", "requires": { "@antfu/install-pkg": "^0.1.0", "@antfu/utils": "^0.5.0", diff --git a/packages/core/package.json b/packages/core/package.json index 27ca3b6..f9a5dea 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -109,7 +109,7 @@ "dependencies": { "@iconify/api-redundancy": "^1.1.0", "@iconify/types": "^1.1.0", - "@iconify/utils": "^1.0.29" + "@iconify/utils": "^1.0.31" }, "devDependencies": { "@types/jest": "^27.4.1",