|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2021 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +/** |
| 19 | + * Add a patch changeset for `@firebase/app` to force its release, so that |
| 20 | + * the SDK_VERSION is up to date with the version of the umbrella package firebase. |
| 21 | + * |
| 22 | + * For background, see https://github.com/firebase/firebase-js-sdk/issues/4235 |
| 23 | + */ |
| 24 | + |
| 25 | +import { writeFileSync } from 'fs'; |
| 26 | +import { projectRoot } from './utils'; |
| 27 | +import { exec } from 'child-process-promise'; |
| 28 | + |
| 29 | +const CONTENT = ` |
| 30 | +--- |
| 31 | +'@firebase/app': patch |
| 32 | +--- |
| 33 | +
|
| 34 | +Update SDK_VERSION. |
| 35 | +`; |
| 36 | + |
| 37 | +const FILE_PATH = `${projectRoot}/.changeset/bump-sdk-version.md`; |
| 38 | + |
| 39 | +async function addChangeSet() { |
| 40 | + // check if a few firebase version is being released |
| 41 | + try { |
| 42 | + const { stdout } = await exec('yarn changeset status'); |
| 43 | + // only add a changeset for @firebase/app if |
| 44 | + // 1. we are publishing a new firebase version. and |
| 45 | + // 2. @firebase/app is not already being published |
| 46 | + const firebaseRelease = stdout.includes('- firebase\n'); |
| 47 | + const firebaseAppRelease = stdout.includes('- @firebase/app\n'); |
| 48 | + if (firebaseRelease && !firebaseAppRelease) { |
| 49 | + console.log('Creating a patch changeset for @firebase/app'); |
| 50 | + writeFileSync(FILE_PATH, CONTENT, { |
| 51 | + encoding: 'utf-8' |
| 52 | + }); |
| 53 | + } else if (firebaseAppRelease) { |
| 54 | + console.log( |
| 55 | + 'Skip creating a patch changeset for @firebase/app because it is already part of the release' |
| 56 | + ); |
| 57 | + } else { |
| 58 | + console.log( |
| 59 | + 'Skip creating a patch changeset for @firebase/app because firebase is not being released' |
| 60 | + ); |
| 61 | + } |
| 62 | + } catch (e) { |
| 63 | + // log the error, the exit without creating a changeset |
| 64 | + console.log('error:', e); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +addChangeSet(); |
0 commit comments