From eb9a2cb5e732948b49344fbb3d9d5d84e582c262 Mon Sep 17 00:00:00 2001 From: Anton Nikolaev Date: Tue, 31 Mar 2020 06:25:39 -0700 Subject: [PATCH] Bump versions for all npm packages on release Summary: Automatically bump versions for all local npm packages included as workspaces and fix local dependencies correspondingly. As a part of this I have also aligned versioning for all the packages by using the same version for all of them. Reviewed By: jknoxville Differential Revision: D20745632 fbshipit-source-id: 2d438c4b23ee72f7d7c068c5ce161063c7ceb9e5 --- desktop/app/package.json | 2 +- desktop/babel-transformer/package.json | 2 +- desktop/doctor/package.json | 2 +- desktop/headless-tests/package.json | 5 +- desktop/package.json | 3 + desktop/pkg/package.json | 4 +- desktop/scripts/bump-workspace-versions.ts | 67 ++++++++++++++++++++++ desktop/static/package.json | 4 +- desktop/yarn.lock | 26 ++++++--- scripts/prepare-release.sh | 10 ++-- 10 files changed, 105 insertions(+), 20 deletions(-) create mode 100644 desktop/scripts/bump-workspace-versions.ts diff --git a/desktop/app/package.json b/desktop/app/package.json index c39e5feeb..c65191f85 100644 --- a/desktop/app/package.json +++ b/desktop/app/package.json @@ -32,7 +32,7 @@ "expand-tilde": "^2.0.2", "express": "^4.15.2", "fb-watchman": "^2.0.0", - "flipper-doctor": "^0.7.0", + "flipper-doctor": "0.35.0", "fs-extra": "^8.0.1", "immer": "^6.0.0", "immutable": "^4.0.0-rc.12", diff --git a/desktop/babel-transformer/package.json b/desktop/babel-transformer/package.json index 02403066a..09c6b320a 100644 --- a/desktop/babel-transformer/package.json +++ b/desktop/babel-transformer/package.json @@ -1,6 +1,6 @@ { "name": "flipper-babel-transformer", - "version": "0.2.0", + "version": "0.35.0", "description": "Babel transformer for Flipper plugins", "repository": "facebook/flipper", "main": "lib/index.js", diff --git a/desktop/doctor/package.json b/desktop/doctor/package.json index 982d79541..2fc65bdda 100644 --- a/desktop/doctor/package.json +++ b/desktop/doctor/package.json @@ -1,6 +1,6 @@ { "name": "flipper-doctor", - "version": "0.7.0", + "version": "0.35.0", "description": "Utility for checking for issues with a flipper installation", "main": "lib/index.js", "flipper:source": "src", diff --git a/desktop/headless-tests/package.json b/desktop/headless-tests/package.json index 5df21e1bf..bf88c421f 100644 --- a/desktop/headless-tests/package.json +++ b/desktop/headless-tests/package.json @@ -1,7 +1,8 @@ { - "name": "headless-tests", - "version": "1.0.0", + "name": "flipper-headless-tests", + "version": "0.35.0", "main": "index.js", + "private": true, "scripts": { "test": "jest", "test:debug": "node --inspect node_modules/.bin/jest --runInBand" diff --git a/desktop/package.json b/desktop/package.json index 396a319f4..ec4efdd66 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -168,6 +168,8 @@ "jest-fetch-mock": "^3.0.0", "metro": "^0.58.0", "metro-resolver": "^0.58.0", + "p-filter": "^2.1.0", + "p-map": "^4.0.0", "prettier": "^2.0.0", "react-async": "^10.0.0", "recursive-readdir": "^2.2.2", @@ -209,6 +211,7 @@ "lint:eslint": "eslint . --ext .js,.ts,.tsx", "lint:flow": "flow check", "lint": "yarn lint:eslint && yarn lint:flow && yarn lint:tsc", + "bump-workspace-versions": "cross-env TS_NODE_FILES=true node --require ts-node/register scripts/bump-workspace-versions.ts", "everything": "yarn reset && yarn install && yarn lint && yarn test && yarn test-electron && yarn build --mac --mac-dmg --win --linux && yarn build-headless --mac --linux && yarn start" }, "optionalDependencies": { diff --git a/desktop/pkg/package.json b/desktop/pkg/package.json index 3c7e3511a..15b6ad8ec 100644 --- a/desktop/pkg/package.json +++ b/desktop/pkg/package.json @@ -1,6 +1,6 @@ { "name": "flipper-pkg", - "version": "0.0.0", + "version": "0.35.0", "description": "Utility for building and publishing Flipper plugins", "repository": "facebook/flipper", "main": "lib/index.js", @@ -20,7 +20,7 @@ "@types/node": "^13.7.5", "cli-ux": "^5.4.5", "fs-extra": "^8.1.0", - "flipper-babel-transformer": "0.2.0", + "flipper-babel-transformer": "0.35.0", "inquirer": "^7.0.5", "metro": "^0.58.0", "tslib": "^1" diff --git a/desktop/scripts/bump-workspace-versions.ts b/desktop/scripts/bump-workspace-versions.ts new file mode 100644 index 000000000..1b5a2a6bc --- /dev/null +++ b/desktop/scripts/bump-workspace-versions.ts @@ -0,0 +1,67 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +import {rootDir, pluginsDir} from './paths'; +import fs from 'fs-extra'; +import path from 'path'; +import {promisify} from 'util'; +import globImport from 'glob'; +import pfilter from 'p-filter'; +import pmap from 'p-map'; +const glob = promisify(globImport); + +const lastArg = process.argv[process.argv.length - 1]; +const version = + lastArg === __filename ? undefined : process.argv[process.argv.length - 1]; + +bump(version) + .then(() => process.exit(0)) + .catch((err) => { + console.error(err); + process.exit(1); + }); + +async function bump(version?: string) { + const rootPackageJson = await fs.readJson(path.join(rootDir, 'package.json')); + version = version || (rootPackageJson.version as string); + const packageGlobs = rootPackageJson.workspaces.packages as string[]; + const localPackages = await pmap( + await pfilter( + ([] as string[]).concat( + ...(await pmap(packageGlobs, (pattern) => + glob(path.join(rootDir, pattern, '')), + )), + ), + async (dir) => + !dir.startsWith(pluginsDir) && + (await fs.pathExists(path.join(dir, 'package.json'))), + ), + async (dir) => { + const json = await fs.readJson(path.join(dir, 'package.json')); + return { + dir, + json, + }; + }, + ); + const localPackageNames = localPackages.map(({json}) => json.name as string); + for (const {dir, json} of localPackages) { + json.version = version; + if (json.dependencies) { + for (const localPackageName of localPackageNames) { + if (json.dependencies[localPackageName] !== undefined) { + json.dependencies[localPackageName] = version; + } + } + } + await fs.writeJson(path.join(dir, 'package.json'), json, { + spaces: 2, + }); + } +} diff --git a/desktop/static/package.json b/desktop/static/package.json index f8cf4ba39..43aee4ad6 100644 --- a/desktop/static/package.json +++ b/desktop/static/package.json @@ -1,6 +1,6 @@ { "name": "flipper-static", - "version": "1.0.0", + "version": "0.35.0", "main": "index.js", "private": true, "license": "MIT", @@ -10,7 +10,7 @@ "fb-watchman": "^2.0.0", "fix-path": "^3.0.0", "fs-extra": "^8.1.0", - "flipper-babel-transformer": "0.2.0", + "flipper-babel-transformer": "0.35.0", "mem": "^6.0.0", "metro": "^0.58.0", "mkdirp": "^1.0.0", diff --git a/desktop/yarn.lock b/desktop/yarn.lock index dcac20e51..bb40b8d95 100644 --- a/desktop/yarn.lock +++ b/desktop/yarn.lock @@ -2286,9 +2286,9 @@ "@types/yargs-parser" "*" "@types/yargs@^15.0.0": - version "15.0.3" - resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-15.0.3.tgz#41453a0bc7ab393e995d1f5451455638edbd2baf" - integrity sha512-XCMQRK6kfpNBixHLyHUsGmXrpEmFFxzMrcnSXFMziHd8CoNJo8l16FkHyQq4x+xbM7E2XL83/O78OD8u+iZTdQ== + version "15.0.4" + resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-15.0.4.tgz#7e5d0f8ca25e9d5849f2ea443cf7c402decd8299" + integrity sha512-9T1auFmbPZoxHz0enUFlUuKRy3it01R+hlggyVUMtnCTQRunsQYifnSGb8hET4Xo8yiC0o0r1paW3ud5+rbURg== dependencies: "@types/yargs-parser" "*" @@ -8740,6 +8740,13 @@ p-each-series@^2.1.0: resolved "https://registry.yarnpkg.com/p-each-series/-/p-each-series-2.1.0.tgz#961c8dd3f195ea96c747e636b262b800a6b1af48" integrity sha512-ZuRs1miPT4HrjFa+9fRfOFXxGJfORgelKV9f9nNOWw2gl6gVsRaVDOQP0+MI0G0wGKns1Yacsu0GjOFbTK0JFQ== +p-filter@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/p-filter/-/p-filter-2.1.0.tgz#1b1472562ae7a0f742f0f3d3d3718ea66ff9c09c" + integrity sha512-ZBxxZ5sL2HghephhpGAQdoskxplTwr7ICaehZwLIlfL6acuVgZPm8yBNuRAFBGEqtD/hmUeq9eqLg2ys9Xr/yw== + dependencies: + p-map "^2.0.0" + p-finally@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" @@ -8795,6 +8802,11 @@ p-locate@^4.1.0: dependencies: p-limit "^2.2.0" +p-map@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/p-map/-/p-map-2.1.0.tgz#310928feef9c9ecc65b68b17693018a665cea175" + integrity sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw== + p-map@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/p-map/-/p-map-4.0.0.tgz#bb2f95a5eda2ec168ec9274e06a747c3e2904d2b" @@ -11961,9 +11973,9 @@ yargs@^14.2.0: yargs-parser "^15.0.0" yargs@^15.0.0, yargs@^15.0.1, yargs@^15.1.0: - version "15.1.0" - resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.1.0.tgz#e111381f5830e863a89550bd4b136bb6a5f37219" - integrity sha512-T39FNN1b6hCW4SOIk1XyTOWxtXdcen0t+XYrysQmChzSipvhBO8Bj0nK1ozAasdk24dNWuMZvr4k24nz+8HHLg== + version "15.3.1" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.3.1.tgz#9505b472763963e54afe60148ad27a330818e98b" + integrity sha512-92O1HWEjw27sBfgmXiixJWT5hRBp2eobqXicLtPBIDBhYB+1HpwZlXmbW2luivBJHBzki+7VyCLRtAkScbTBQA== dependencies: cliui "^6.0.0" decamelize "^1.2.0" @@ -11975,7 +11987,7 @@ yargs@^15.0.0, yargs@^15.0.1, yargs@^15.1.0: string-width "^4.2.0" which-module "^2.0.0" y18n "^4.0.0" - yargs-parser "^16.1.0" + yargs-parser "^18.1.1" yauzl@2.4.1: version "2.4.1" diff --git a/scripts/prepare-release.sh b/scripts/prepare-release.sh index 1575921b9..74a8d815b 100755 --- a/scripts/prepare-release.sh +++ b/scripts/prepare-release.sh @@ -52,12 +52,14 @@ FLIPPERKIT_VERSION_TAG='flipperkit_version' OLD_VERSION_POD_ARG=$(< "$FLIPPER_PODSPEC_PATH" grep "$FLIPPERKIT_VERSION_TAG =" ) OLD_VERSION="${OLD_VERSION_POD_ARG##* }" +source "$DIR"/setup-env.sh + # if we got called with a rev argument, we got triggered from our automatic sandcastle job if [ "$SANDCASTLE_REVISION" != "" ]; then # In future, bump majors instead of minors? echo "Automatically bumping version to next minor in package.json" - npm -C "$DESKTOP_DIR" version minor + yarn --cwd "$DESKTOP_DIR" version minor --no-git-tag-version VERSION=$(jq -r '.version' "$DESKTOP_DIR"/package.json) else echo "The currently released version is $OLD_VERSION. What should the version of the next release be?" @@ -66,11 +68,11 @@ fi echo "Preparing release $VERSION..." -# Updating "flipper" npm package to the same version -npm -C "$DESKTOP_DIR"app version "$VERSION" +# Update all the packages included as workspaces to the very same version +yarn --cwd "$DESKTOP_DIR" bump-workspace-versions "$VERSION" # Update react-native-flipper to the very same version -npm -C "$SONAR_DIR"react-native/react-native-flipper version "$VERSION" +yarn --cwd "$SONAR_DIR"/react-native/react-native-flipper version --new-version "$VERSION" --no-git-tag-version # This could be one expression with GNU sed, but I guess we want to support the BSD crap, too. SNAPSHOT_MINOR_VERSION=$(echo "$VERSION" | sed -Ee 's/([0-9]+)\.([0-9]+)\.([0-9]+)/\3 + 1/' | bc)