From e3ab00cec98a85a80db8453720dcafe22b42cf4d Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Wed, 13 Jan 2021 15:53:23 -0800 Subject: [PATCH 01/10] execute npm publish with dryRun flag when it's a dry run --- scripts/exp/release.ts | 50 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/scripts/exp/release.ts b/scripts/exp/release.ts index 4c18eda2186..737d47a3266 100644 --- a/scripts/exp/release.ts +++ b/scripts/exp/release.ts @@ -80,31 +80,28 @@ async function publishExpPackages({ dryRun }: { dryRun: boolean }) { const versions = await updatePackageNamesAndVersions(packagePaths); /** - * Do not publish to npm and create tags if it's a dryrun + * Release packages to NPM */ - if (!dryRun) { - /** - * Release packages to NPM - */ - await publishToNpm(packagePaths); + await publishToNpm(packagePaths, dryRun); - /** - * reset the working tree to recover package names with -exp in the package.json files, - * then bump patch version of firebase-exp (the umbrella package) only - */ - const firebaseExpVersion = new Map(); - firebaseExpVersion.set( - FIREBASE_UMBRELLA_PACKAGE_NAME, - versions.get(FIREBASE_UMBRELLA_PACKAGE_NAME) - ); - const firebaseExpPath = packagePaths.filter(p => - p.includes(FIREBASE_UMBRELLA_PACKAGE_NAME) - ); - await resetWorkingTreeAndBumpVersions( - firebaseExpPath, - firebaseExpVersion - ); + /** + * reset the working tree to recover package names with -exp in the package.json files, + * then bump patch version of firebase-exp (the umbrella package) only + */ + const firebaseExpVersion = new Map(); + firebaseExpVersion.set( + FIREBASE_UMBRELLA_PACKAGE_NAME, + versions.get(FIREBASE_UMBRELLA_PACKAGE_NAME) + ); + const firebaseExpPath = packagePaths.filter(p => + p.includes(FIREBASE_UMBRELLA_PACKAGE_NAME) + ); + await resetWorkingTreeAndBumpVersions(firebaseExpPath, firebaseExpVersion); + /** + * Do not push to remote if it's a dryrun + */ + if (!dryRun) { /** * push to github */ @@ -242,13 +239,13 @@ async function updatePackageNamesAndVersions(packagePaths: string[]) { return versions; } -async function publishToNpm(packagePaths: string[]) { +async function publishToNpm(packagePaths: string[], dryRun = false) { const taskArray = await Promise.all( packagePaths.map(async pp => { const { version, name } = await readPackageJson(pp); return { title: `📦 ${name}@${version}`, - task: () => publishPackage(pp) + task: () => publishPackage(pp, dryRun) }; }) ); @@ -262,8 +259,11 @@ async function publishToNpm(packagePaths: string[]) { return tasks.run(); } -async function publishPackage(packagePath: string) { +async function publishPackage(packagePath: string, dryRun: boolean) { const args = ['publish', '--access', 'public', '--tag', 'exp']; + if (dryRun) { + args.push('--dry-run'); + } await spawn('npm', args, { cwd: packagePath }); } From 47cab3ef652c36ece69b03ee4d7a4d04b9595832 Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Wed, 13 Jan 2021 16:10:06 -0800 Subject: [PATCH 02/10] add build:release script to messaging-exp --- package.json | 1 + packages-exp/messaging-exp/package.json | 1 + 2 files changed, 2 insertions(+) diff --git a/package.json b/package.json index 303e616dca2..53a7f96f3cb 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "stage:packages": "./scripts/prepublish.sh", "repl": "node tools/repl.js", "release": "ts-node-script scripts/release/cli.ts", + "release:exp": "ts-node-script scripts/exp/release.ts", "pretest": "node tools/pretest.js", "test": "lerna run --concurrency 4 --stream test", "test:ci": "lerna run --concurrency 4 test:ci", diff --git a/packages-exp/messaging-exp/package.json b/packages-exp/messaging-exp/package.json index 1416ac91661..461a0e046f1 100644 --- a/packages-exp/messaging-exp/package.json +++ b/packages-exp/messaging-exp/package.json @@ -16,6 +16,7 @@ "lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'", "build": "rollup -c && yarn api-report", "build:deps": "lerna run --scope @firebase/'{app-exp,messaging-exp}' --include-dependencies build", + "build:release": "rollup -c rollup.config.release.js && yarn api-report", "dev": "rollup -c -w", "test": "run-p test:karma type-check lint ", "test:integration": "run-p test:karma type-check lint && cd ../../integration/messaging && npm run-script test", From 286a249049da3e93de375c2bf8d62d123ec33c8f Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Wed, 13 Jan 2021 17:57:17 -0800 Subject: [PATCH 03/10] run build:release in prepare script --- packages-exp/messaging-exp/package.json | 2 +- scripts/exp/release.ts | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages-exp/messaging-exp/package.json b/packages-exp/messaging-exp/package.json index 461a0e046f1..690c249367b 100644 --- a/packages-exp/messaging-exp/package.json +++ b/packages-exp/messaging-exp/package.json @@ -23,7 +23,7 @@ "test:ci": "node ../../scripts/run_tests_in_ci.js", "test:karma": "karma start --single-run", "test:debug": "karma start --browsers=Chrome --auto-watch", - "prepare": "yarn build", + "prepare": "yarn build:release", "api-report": "api-extractor run --local --verbose", "type-check": "tsc --noEmit" }, diff --git a/scripts/exp/release.ts b/scripts/exp/release.ts index 737d47a3266..2cd933d1530 100644 --- a/scripts/exp/release.ts +++ b/scripts/exp/release.ts @@ -196,6 +196,9 @@ async function buildPackages() { } ); + // remove packages/installations/dist, otherwise packages that depend on packages-exp/installations-exp (e.g. Perf, FCM) + // will incorrectly reference packages/installations. + // Build firebase-exp await spawn( 'yarn', @@ -260,11 +263,23 @@ async function publishToNpm(packagePaths: string[], dryRun = false) { } async function publishPackage(packagePath: string, dryRun: boolean) { + console.log('publishing ', packagePath); const args = ['publish', '--access', 'public', '--tag', 'exp']; if (dryRun) { args.push('--dry-run'); } - await spawn('npm', args, { cwd: packagePath }); + const prm = spawn('npm', args, { cwd: packagePath }); + + const childProcess = prm.childProcess; + console.log('[spawn] childProcess.pid: ', childProcess.pid); + childProcess.stdout?.on('data', function (data) { + console.log('[spawn] stdout: ', data.toString()); + }); + childProcess.stderr?.on('data', function (data) { + console.log('[spawn] stderr: ', data.toString()); + }); + + await prm; } async function resetWorkingTreeAndBumpVersions( From 2637ab16022697a9e542d0b5ded886f508b0817a Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Thu, 14 Jan 2021 13:53:18 -0800 Subject: [PATCH 04/10] remove installations dist if it exists --- scripts/exp/release.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/exp/release.ts b/scripts/exp/release.ts index 2cd933d1530..5ccfbbcd100 100644 --- a/scripts/exp/release.ts +++ b/scripts/exp/release.ts @@ -22,7 +22,8 @@ import simpleGit from 'simple-git/promise'; import { mapWorkspaceToPackages } from '../release/utils/workspace'; import { inc } from 'semver'; -import { writeFile as _writeFile } from 'fs'; +import { writeFile as _writeFile, rmdirSync, existsSync } from 'fs'; +import { resolve } from 'path'; import { promisify } from 'util'; import chalk from 'chalk'; import Listr from 'listr'; @@ -198,6 +199,13 @@ async function buildPackages() { // remove packages/installations/dist, otherwise packages that depend on packages-exp/installations-exp (e.g. Perf, FCM) // will incorrectly reference packages/installations. + const installationsDistDirPath = resolve( + projectRoot, + 'packages/installations/dist' + ); + if (existsSync(installationsDistDirPath)) { + rmdirSync(installationsDistDirPath, { recursive: true }); + } // Build firebase-exp await spawn( From 61918bc74bf67d8524ac2a69f59ce661d1ed6089 Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Thu, 14 Jan 2021 13:57:04 -0800 Subject: [PATCH 05/10] remove --- scripts/exp/prepare-firestore-for-exp-release.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/exp/prepare-firestore-for-exp-release.ts b/scripts/exp/prepare-firestore-for-exp-release.ts index 166e9c95997..f7a7b70f906 100644 --- a/scripts/exp/prepare-firestore-for-exp-release.ts +++ b/scripts/exp/prepare-firestore-for-exp-release.ts @@ -84,8 +84,8 @@ export async function prepare() { ); // remove -exp in typings files - await replaceAppTypesExpInFile(expTypingPath); - await replaceAppTypesExpInFile(liteTypingPath); + // await replaceAppTypesExpInFile(expTypingPath); + // await replaceAppTypesExpInFile(liteTypingPath); } async function replaceAppTypesExpInFile(filePath: string): Promise { From 478e05e50dd0c90094bf46a7b911fd998be11c51 Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Thu, 14 Jan 2021 14:16:44 -0800 Subject: [PATCH 06/10] Add prompt points to make debugging issues easier --- scripts/exp/release.ts | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/scripts/exp/release.ts b/scripts/exp/release.ts index 5ccfbbcd100..8201d49ac84 100644 --- a/scripts/exp/release.ts +++ b/scripts/exp/release.ts @@ -17,6 +17,7 @@ import { spawn, exec } from 'child-process-promise'; import ora from 'ora'; +import { createPromptModule } from 'inquirer'; import { projectRoot, readPackageJson } from '../utils'; import simpleGit from 'simple-git/promise'; @@ -30,6 +31,7 @@ import Listr from 'listr'; import { prepare as prepareFirestoreForRelease } from './prepare-firestore-for-exp-release'; import * as yargs from 'yargs'; +const prompt = createPromptModule(); const argv = yargs .options({ dryRun: { @@ -97,16 +99,44 @@ async function publishExpPackages({ dryRun }: { dryRun: boolean }) { const firebaseExpPath = packagePaths.filter(p => p.includes(FIREBASE_UMBRELLA_PACKAGE_NAME) ); - await resetWorkingTreeAndBumpVersions(firebaseExpPath, firebaseExpVersion); + + const reset = await prompt([ + { + type: 'confirm', + name: 'resetWorkingTree', + message: 'Do you want to reset the working tree?', + default: true + } + ]); + + if (reset) { + await resetWorkingTreeAndBumpVersions( + firebaseExpPath, + firebaseExpVersion + ); + } else { + process.exit(0); + } /** * Do not push to remote if it's a dryrun */ if (!dryRun) { + const proceed = await prompt([ + { + type: 'confirm', + name: 'commitAndPush', + message: + 'Do you want to commit and push the exp version update to remote?', + default: true + } + ]); /** * push to github */ - await commitAndPush(versions); + if (proceed) { + await commitAndPush(versions); + } } } catch (err) { /** From ce599018df5af0b38c0cb0c1d2559a723fa5afef Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Thu, 14 Jan 2021 14:32:19 -0800 Subject: [PATCH 07/10] confirm versions before publishing --- scripts/exp/release.ts | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/scripts/exp/release.ts b/scripts/exp/release.ts index 8201d49ac84..6d5da9f46fa 100644 --- a/scripts/exp/release.ts +++ b/scripts/exp/release.ts @@ -82,6 +82,24 @@ async function publishExpPackages({ dryRun }: { dryRun: boolean }) { */ const versions = await updatePackageNamesAndVersions(packagePaths); + let versionCheckMessage = + '\r\nAre you sure these are the versions you want to publish?\r\n'; + for (const [pkgName, version] of versions) { + versionCheckMessage += `${pkgName} : ${version}\n`; + } + const { versionCheck } = await prompt([ + { + type: 'confirm', + name: 'versionCheck', + message: versionCheckMessage, + default: false + } + ]); + + if (!versionCheck) { + throw new Error('Version check failed'); + } + /** * Release packages to NPM */ @@ -100,7 +118,7 @@ async function publishExpPackages({ dryRun }: { dryRun: boolean }) { p.includes(FIREBASE_UMBRELLA_PACKAGE_NAME) ); - const reset = await prompt([ + const { resetWorkingTree } = await prompt([ { type: 'confirm', name: 'resetWorkingTree', @@ -109,7 +127,7 @@ async function publishExpPackages({ dryRun }: { dryRun: boolean }) { } ]); - if (reset) { + if (resetWorkingTree) { await resetWorkingTreeAndBumpVersions( firebaseExpPath, firebaseExpVersion @@ -122,7 +140,7 @@ async function publishExpPackages({ dryRun }: { dryRun: boolean }) { * Do not push to remote if it's a dryrun */ if (!dryRun) { - const proceed = await prompt([ + const { commitAndPush } = await prompt([ { type: 'confirm', name: 'commitAndPush', @@ -134,7 +152,7 @@ async function publishExpPackages({ dryRun }: { dryRun: boolean }) { /** * push to github */ - if (proceed) { + if (commitAndPush) { await commitAndPush(versions); } } From 401c9e4eb0f7bc64b82132d40ee8847b4245edf5 Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Thu, 14 Jan 2021 14:33:26 -0800 Subject: [PATCH 08/10] remove debugging code --- scripts/exp/release.ts | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/scripts/exp/release.ts b/scripts/exp/release.ts index 6d5da9f46fa..f1987965b6b 100644 --- a/scripts/exp/release.ts +++ b/scripts/exp/release.ts @@ -319,23 +319,11 @@ async function publishToNpm(packagePaths: string[], dryRun = false) { } async function publishPackage(packagePath: string, dryRun: boolean) { - console.log('publishing ', packagePath); const args = ['publish', '--access', 'public', '--tag', 'exp']; if (dryRun) { args.push('--dry-run'); } - const prm = spawn('npm', args, { cwd: packagePath }); - - const childProcess = prm.childProcess; - console.log('[spawn] childProcess.pid: ', childProcess.pid); - childProcess.stdout?.on('data', function (data) { - console.log('[spawn] stdout: ', data.toString()); - }); - childProcess.stderr?.on('data', function (data) { - console.log('[spawn] stderr: ', data.toString()); - }); - - await prm; + await spawn('npm', args, { cwd: packagePath }); } async function resetWorkingTreeAndBumpVersions( From 6b721f6cbb9b6febaaab591b290ec3d856c1eb3b Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Thu, 14 Jan 2021 14:48:04 -0800 Subject: [PATCH 09/10] remove prepare script to speed up npm publish --- packages-exp/auth-compat-exp/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages-exp/auth-compat-exp/package.json b/packages-exp/auth-compat-exp/package.json index 54450ca9dab..3bc0c0a0c18 100644 --- a/packages-exp/auth-compat-exp/package.json +++ b/packages-exp/auth-compat-exp/package.json @@ -20,8 +20,7 @@ "test:all": "run-p test:browser test:node", "test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all", "test:browser": "karma start --single-run", - "test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha src/**/*.test.* --config ../../config/mocharc.node.js", - "prepare": "yarn build:release" + "test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha src/**/*.test.* --config ../../config/mocharc.node.js" }, "peerDependencies": { "@firebase/app-compat": "0.x", From 2b813267aa56b97a9572eef8e914ca24e3614f4b Mon Sep 17 00:00:00 2001 From: Feiyang1 Date: Thu, 14 Jan 2021 15:51:57 -0800 Subject: [PATCH 10/10] remove unused code --- .../exp/prepare-firestore-for-exp-release.ts | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/scripts/exp/prepare-firestore-for-exp-release.ts b/scripts/exp/prepare-firestore-for-exp-release.ts index f7a7b70f906..29d46a68db3 100644 --- a/scripts/exp/prepare-firestore-for-exp-release.ts +++ b/scripts/exp/prepare-firestore-for-exp-release.ts @@ -76,24 +76,4 @@ export async function prepare() { `${JSON.stringify(packageJson, null, 2)}\n`, { encoding: 'utf-8' } ); - - const expTypingPath = `${packagePath}/${packageJson.typings}`; - const liteTypingPath = path.resolve( - `${packagePath}/lite`, - litePackageJson.typings - ); - - // remove -exp in typings files - // await replaceAppTypesExpInFile(expTypingPath); - // await replaceAppTypesExpInFile(liteTypingPath); -} - -async function replaceAppTypesExpInFile(filePath: string): Promise { - const fileContent = await readFile(filePath, { encoding: 'utf-8' }); - const newFileContent = fileContent.replace( - '@firebase/app-types-exp', - '@firebase/app-types' - ); - - await writeFile(filePath, newFileContent, { encoding: 'utf-8' }); }