Skip to content

Commit 818a961

Browse files
authored
Fix issues in the exp release script (#4293)
* execute npm publish with dryRun flag when it's a dry run * add build:release script to messaging-exp * run build:release in prepare script * remove installations dist if it exists * remove * Add prompt points to make debugging issues easier * confirm versions before publishing * remove debugging code * remove prepare script to speed up npm publish * remove unused code
1 parent b98cd65 commit 818a961

File tree

4 files changed

+84
-43
lines changed

4 files changed

+84
-43
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"stage:packages": "./scripts/prepublish.sh",
3131
"repl": "node tools/repl.js",
3232
"release": "ts-node-script scripts/release/cli.ts",
33+
"release:exp": "ts-node-script scripts/exp/release.ts",
3334
"pretest": "node tools/pretest.js",
3435
"test": "lerna run --concurrency 4 --stream test",
3536
"test:ci": "lerna run --concurrency 4 test:ci",

packages-exp/messaging-exp/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'",
1717
"build": "rollup -c && yarn api-report",
1818
"build:deps": "lerna run --scope @firebase/'{app-exp,messaging-exp}' --include-dependencies build",
19+
"build:release": "rollup -c rollup.config.release.js && yarn api-report",
1920
"dev": "rollup -c -w",
2021
"test": "run-p test:karma type-check lint ",
2122
"test:integration": "run-p test:karma type-check lint && cd ../../integration/messaging && npm run-script test",

scripts/exp/prepare-firestore-for-exp-release.ts

-20
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,4 @@ export async function prepare() {
7474
`${JSON.stringify(packageJson, null, 2)}\n`,
7575
{ encoding: 'utf-8' }
7676
);
77-
78-
const expTypingPath = `${packagePath}/${packageJson.typings}`;
79-
const liteTypingPath = path.resolve(
80-
`${packagePath}/lite`,
81-
litePackageJson.typings
82-
);
83-
84-
// remove -exp in typings files
85-
await replaceAppTypesExpInFile(expTypingPath);
86-
await replaceAppTypesExpInFile(liteTypingPath);
87-
}
88-
89-
async function replaceAppTypesExpInFile(filePath: string): Promise<void> {
90-
const fileContent = await readFile(filePath, { encoding: 'utf-8' });
91-
const newFileContent = fileContent.replace(
92-
'@firebase/app-types-exp',
93-
'@firebase/app-types'
94-
);
95-
96-
await writeFile(filePath, newFileContent, { encoding: 'utf-8' });
9777
}

scripts/exp/release.ts

+82-23
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@
1717

1818
import { spawn, exec } from 'child-process-promise';
1919
import ora from 'ora';
20+
import { createPromptModule } from 'inquirer';
2021
import { projectRoot, readPackageJson } from '../utils';
2122
import simpleGit from 'simple-git/promise';
2223

2324
import { mapWorkspaceToPackages } from '../release/utils/workspace';
2425
import { inc } from 'semver';
25-
import { writeFile as _writeFile } from 'fs';
26+
import { writeFile as _writeFile, rmdirSync, existsSync } from 'fs';
27+
import { resolve } from 'path';
2628
import { promisify } from 'util';
2729
import chalk from 'chalk';
2830
import Listr from 'listr';
2931
import { prepare as prepareFirestoreForRelease } from './prepare-firestore-for-exp-release';
3032
import * as yargs from 'yargs';
3133

34+
const prompt = createPromptModule();
3235
const argv = yargs
3336
.options({
3437
dryRun: {
@@ -79,36 +82,79 @@ async function publishExpPackages({ dryRun }: { dryRun: boolean }) {
7982
*/
8083
const versions = await updatePackageNamesAndVersions(packagePaths);
8184

85+
let versionCheckMessage =
86+
'\r\nAre you sure these are the versions you want to publish?\r\n';
87+
for (const [pkgName, version] of versions) {
88+
versionCheckMessage += `${pkgName} : ${version}\n`;
89+
}
90+
const { versionCheck } = await prompt([
91+
{
92+
type: 'confirm',
93+
name: 'versionCheck',
94+
message: versionCheckMessage,
95+
default: false
96+
}
97+
]);
98+
99+
if (!versionCheck) {
100+
throw new Error('Version check failed');
101+
}
102+
82103
/**
83-
* Do not publish to npm and create tags if it's a dryrun
104+
* Release packages to NPM
84105
*/
85-
if (!dryRun) {
86-
/**
87-
* Release packages to NPM
88-
*/
89-
await publishToNpm(packagePaths);
106+
await publishToNpm(packagePaths, dryRun);
90107

91-
/**
92-
* reset the working tree to recover package names with -exp in the package.json files,
93-
* then bump patch version of firebase-exp (the umbrella package) only
94-
*/
95-
const firebaseExpVersion = new Map<string, string>();
96-
firebaseExpVersion.set(
97-
FIREBASE_UMBRELLA_PACKAGE_NAME,
98-
versions.get(FIREBASE_UMBRELLA_PACKAGE_NAME)
99-
);
100-
const firebaseExpPath = packagePaths.filter(p =>
101-
p.includes(FIREBASE_UMBRELLA_PACKAGE_NAME)
102-
);
108+
/**
109+
* reset the working tree to recover package names with -exp in the package.json files,
110+
* then bump patch version of firebase-exp (the umbrella package) only
111+
*/
112+
const firebaseExpVersion = new Map<string, string>();
113+
firebaseExpVersion.set(
114+
FIREBASE_UMBRELLA_PACKAGE_NAME,
115+
versions.get(FIREBASE_UMBRELLA_PACKAGE_NAME)
116+
);
117+
const firebaseExpPath = packagePaths.filter(p =>
118+
p.includes(FIREBASE_UMBRELLA_PACKAGE_NAME)
119+
);
120+
121+
const { resetWorkingTree } = await prompt([
122+
{
123+
type: 'confirm',
124+
name: 'resetWorkingTree',
125+
message: 'Do you want to reset the working tree?',
126+
default: true
127+
}
128+
]);
129+
130+
if (resetWorkingTree) {
103131
await resetWorkingTreeAndBumpVersions(
104132
firebaseExpPath,
105133
firebaseExpVersion
106134
);
135+
} else {
136+
process.exit(0);
137+
}
107138

139+
/**
140+
* Do not push to remote if it's a dryrun
141+
*/
142+
if (!dryRun) {
143+
const { commitAndPush } = await prompt([
144+
{
145+
type: 'confirm',
146+
name: 'commitAndPush',
147+
message:
148+
'Do you want to commit and push the exp version update to remote?',
149+
default: true
150+
}
151+
]);
108152
/**
109153
* push to github
110154
*/
111-
await commitAndPush(versions);
155+
if (commitAndPush) {
156+
await commitAndPush(versions);
157+
}
112158
}
113159
} catch (err) {
114160
/**
@@ -199,6 +245,16 @@ async function buildPackages() {
199245
}
200246
);
201247

248+
// remove packages/installations/dist, otherwise packages that depend on packages-exp/installations-exp (e.g. Perf, FCM)
249+
// will incorrectly reference packages/installations.
250+
const installationsDistDirPath = resolve(
251+
projectRoot,
252+
'packages/installations/dist'
253+
);
254+
if (existsSync(installationsDistDirPath)) {
255+
rmdirSync(installationsDistDirPath, { recursive: true });
256+
}
257+
202258
// Build firebase-exp
203259
await spawn(
204260
'yarn',
@@ -242,13 +298,13 @@ async function updatePackageNamesAndVersions(packagePaths: string[]) {
242298
return versions;
243299
}
244300

245-
async function publishToNpm(packagePaths: string[]) {
301+
async function publishToNpm(packagePaths: string[], dryRun = false) {
246302
const taskArray = await Promise.all(
247303
packagePaths.map(async pp => {
248304
const { version, name } = await readPackageJson(pp);
249305
return {
250306
title: `📦 ${name}@${version}`,
251-
task: () => publishPackage(pp)
307+
task: () => publishPackage(pp, dryRun)
252308
};
253309
})
254310
);
@@ -262,8 +318,11 @@ async function publishToNpm(packagePaths: string[]) {
262318
return tasks.run();
263319
}
264320

265-
async function publishPackage(packagePath: string) {
321+
async function publishPackage(packagePath: string, dryRun: boolean) {
266322
const args = ['publish', '--access', 'public', '--tag', 'exp'];
323+
if (dryRun) {
324+
args.push('--dry-run');
325+
}
267326
await spawn('npm', args, { cwd: packagePath });
268327
}
269328

0 commit comments

Comments
 (0)