Skip to content

Make exp release script work again #3301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changeset/warm-suns-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

Make exp release script work again
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"build": "lerna run --scope @firebase/* --scope firebase --scope rxfire build",
"build:exp": "lerna run --scope @firebase/*-exp --scope firebase-exp build",
"build:release": "lerna run --scope @firebase/* --scope firebase --ignore @firebase/*-exp --ignore firebase-exp prepare",
"build:exp:release": "lerna run --scope @firebase/*-exp --scope firebase-exp prepare && yarn --cwd packages-exp/app-exp typings:public",
"build:exp:release": "yarn --cwd packages/app build:deps && lerna run --scope @firebase/*-exp --scope firebase-exp prepare && yarn --cwd packages-exp/app-exp typings:public",
"link:packages": "lerna exec --scope @firebase/* --scope firebase --scope rxfire -- yarn link",
"stage:packages": "./scripts/prepublish.sh",
"repl": "node tools/repl.js",
Expand Down
6 changes: 3 additions & 3 deletions packages-exp/app-exp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"test:browser": "karma start --single-run",
"test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha src/**/*.test.ts --config ../../config/mocharc.node.js",
"type-check": "tsc -p . --noEmit",
"prepare": "rollup -c rollup.config.release.js",
"prepare": "rollup -c rollup.config.release.js && yarn api-report",
"api-report": "api-extractor run --local --verbose",
"predoc": "node ../../scripts/exp/remove-exp.js temp",
"doc": "api-documenter markdown --input temp --output docs",
"build:doc": "yarn build && yarn doc",
"typings:public": "node ./use_public_typings.js --public",
"typings:internal": "node ./use_public_typings.js"
"typings:public": "node ./use_typings.js --public",
"typings:internal": "node ./use_typings.js"
},
"dependencies": {
"@firebase/app-types-exp": "0.0.800",
Expand Down
2 changes: 1 addition & 1 deletion packages-exp/functions-exp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
"test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'src/{,!(browser)/**/}*.test.ts' --file src/index.node.ts --config ../../config/mocharc.node.js",
"test:emulator": "env FIREBASE_FUNCTIONS_EMULATOR_ORIGIN=http://localhost:5005 run-p test:node",
"prepare": "yarn build",
"prepare": "rollup -c rollup.config.release.js && yarn api-report",
"api-report": "api-extractor run --local --verbose",
"predoc": "node ../../scripts/exp/remove-exp.js temp",
"doc": "api-documenter markdown --input temp --output docs",
Expand Down
5 changes: 1 addition & 4 deletions packages-exp/functions-exp/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ const es5Builds = [
*/
{
input: 'src/index.ts',
output: [
{ file: pkg.browser, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'es', sourcemap: true }
],
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
},
Expand Down
107 changes: 107 additions & 0 deletions packages-exp/functions-exp/rollup.config.release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import typescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
import json from 'rollup-plugin-json';
import pkg from './package.json';
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';

const deps = Object.keys(
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
);

/**
* ES5 Builds
*/
const es5BuildPlugins = [
typescriptPlugin({
typescript,
clean: true,
abortOnError: false,
transformers: [importPathTransformer]
}),
json()
];

const es5Builds = [
/**
* Browser Builds
*/
{
input: 'src/index.ts',
output: [{ file: pkg.browser, format: 'es', sourcemap: true }],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
treeshake: {
moduleSideEffects: false
}
},
/**
* Node.js Build
*/
{
input: 'src/index.ts',
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
plugins: es5BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
treeshake: {
moduleSideEffects: false
}
}
];

/**
* ES2017 Builds
*/
const es2017BuildPlugins = [
typescriptPlugin({
typescript,
tsconfigOverride: {
compilerOptions: {
target: 'es2017'
}
},
abortOnError: false,
clean: true,
transformers: [importPathTransformer]
}),
json({
preferConst: true
})
];

const es2017Builds = [
/**
* Browser Builds
*/
{
input: 'src/index.ts',
output: {
file: pkg.esm2017,
format: 'es',
sourcemap: true
},
plugins: es2017BuildPlugins,
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
treeshake: {
moduleSideEffects: false
}
}
];

export default [...es5Builds, ...es2017Builds];
3 changes: 2 additions & 1 deletion packages-exp/functions-types-exp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"license": "Apache-2.0",
"scripts": {
"test": "tsc",
"test:ci": "node ../../scripts/run_tests_in_ci.js"
"test:ci": "node ../../scripts/run_tests_in_ci.js",
"prepare": "node ../../scripts/exp/remove-exp.js ./index.d.ts"
},
"files": [
"index.d.ts"
Expand Down
72 changes: 36 additions & 36 deletions scripts/exp/release.js → scripts/exp/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@
* limitations under the License.
*/

const { spawn, exec } = require('child-process-promise');
const ora = require('ora');
const { projectRoot } = require('../utils');
const simpleGit = require('simple-git/promise');
const git = simpleGit(projectRoot);
const { mapWorkspaceToPackages } = require('../release/utils/workspace');
const { inc } = require('semver');
const { readFile: _readFile, writeFile: _writeFile } = require('fs');
const { promisify } = require('util');
import { spawn, exec } from 'child-process-promise';
import ora from 'ora';
import { projectRoot } from '../utils';
import simpleGit from 'simple-git/promise';

import { mapWorkspaceToPackages } from '../release/utils/workspace';
import { inc } from 'semver';
import { readFile as _readFile, writeFile as _writeFile } from 'fs';
import { promisify } from 'util';
import chalk from 'chalk';
import Listr from 'listr';

const readFile = promisify(_readFile);
const writeFile = promisify(_writeFile);
const chalk = require('chalk');
const Listr = require('listr');

const git = simpleGit(projectRoot);
const FIREBASE_UMBRELLA_PACKAGE_NAME = 'firebase-exp';

async function publishExpPackages() {
Expand All @@ -43,11 +44,6 @@ async function publishExpPackages() {
*/
await buildPackages();

/**
* run tests
*/
await runTests();

// path to exp packages
const packagePaths = await mapWorkspaceToPackages([
`${projectRoot}/packages-exp/*`
Expand All @@ -73,7 +69,7 @@ async function publishExpPackages() {
* 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();
const firebaseExpVersion = new Map<string, string>();
firebaseExpVersion.set(
FIREBASE_UMBRELLA_PACKAGE_NAME,
versions.get(FIREBASE_UMBRELLA_PACKAGE_NAME)
Expand Down Expand Up @@ -110,14 +106,7 @@ async function buildPackages() {
});
}

async function runTests() {
await spawn('yarn', ['test:exp'], {
cwd: projectRoot,
stdio: 'inherit'
});
}

async function updatePackageNamesAndVersions(packagePaths) {
async function updatePackageNamesAndVersions(packagePaths: string[]) {
// get package name -> next version mapping
const versions = new Map();
for (const path of packagePaths) {
Expand Down Expand Up @@ -145,7 +134,7 @@ async function updatePackageNamesAndVersions(packagePaths) {
return versions;
}

async function publishToNpm(packagePaths) {
async function publishToNpm(packagePaths: string[]) {
const taskArray = await Promise.all(
packagePaths.map(async pp => {
const { version, name } = await readPackageJson(pp);
Expand All @@ -165,12 +154,15 @@ async function publishToNpm(packagePaths) {
return tasks.run();
}

async function publishPackage(packagePath) {
async function publishPackage(packagePath: string) {
const args = ['publish', '--access', 'public', '--tag', 'exp'];
await spawn('npm', args, { cwd: packagePath });
}

async function resetWorkingTreeAndBumpVersions(packagePaths, versions) {
async function resetWorkingTreeAndBumpVersions(
packagePaths: string[],
versions: Map<string, string>
) {
console.log('Resetting working tree');
await git.checkout('.');

Expand All @@ -182,9 +174,17 @@ async function resetWorkingTreeAndBumpVersions(packagePaths, versions) {
}

async function updatePackageJsons(
packagePaths,
versions,
{ removeExpInName, updateVersions, makePublic }
packagePaths: string[],
versions: Map<string, string>,
{
removeExpInName,
updateVersions,
makePublic
}: {
removeExpInName: boolean;
updateVersions: boolean;
makePublic: boolean;
}
) {
for (const path of packagePaths) {
const packageJsonPath = `${path}/package.json`;
Expand All @@ -210,7 +210,7 @@ async function updatePackageJsons(
// update dep version and remove -exp in dep names
// don't care about devDependencies because they are irrelavant when using the package
const dependencies = packageJson.dependencies || {};
const newDependenciesObj = {};
const newDependenciesObj: { [key: string]: string } = {};
for (const d of Object.keys(dependencies)) {
const dNextVersion = versions.get(d);
const nameWithoutExp = removeExpInPackageName(d);
Expand All @@ -237,7 +237,7 @@ async function updatePackageJsons(
}
}

async function commitAndPush(versions) {
async function commitAndPush(versions: Map<string, string>) {
await exec('git add */package.json yarn.lock');

const firebaseExpVersion = versions.get(FIREBASE_UMBRELLA_PACKAGE_NAME);
Expand All @@ -255,7 +255,7 @@ async function commitAndPush(versions) {
});
}

function removeExpInPackageName(name) {
function removeExpInPackageName(name: string) {
const regex = /^(.*firebase.*)-exp(.*)$/g;

const captures = regex.exec(name);
Expand All @@ -266,7 +266,7 @@ function removeExpInPackageName(name) {
return `${captures[1]}${captures[2]}`;
}

async function readPackageJson(packagePath) {
async function readPackageJson(packagePath: string) {
/**
* Can't require here because require caches the file
* in memory, so it may not contain the updates that are made by e.g. git commands
Expand Down
24 changes: 16 additions & 8 deletions scripts/exp/remove-exp.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,30 @@ const { readdirSync, statSync, readFileSync, writeFileSync } = require('fs');

// can be used in command line
if (argv._[0]) {
const dir = path.resolve(argv._[0]);
removeExpSuffix(dir);
const dirOrFile = path.resolve(argv._[0]);
if (statSync(dirOrFile).isFile()) {
removeExpSuffixFromFile(dirOrFile);
} else {
removeExpSuffix(dir);
}
}

function removeExpSuffix(dir) {
for (const file of readdirSync(dir)) {
const filePath = `${dir}/${file}`;
if (statSync(filePath).isFile()) {
const content = readFileSync(filePath, 'utf-8');

// replace -exp with empty string
const modified = content.replace(/-exp/g, '');

writeFileSync(filePath, modified, 'utf-8');
removeExpSuffixFromFile(filePath);
}
}
}

function removeExpSuffixFromFile(filePath) {
const content = readFileSync(filePath, 'utf-8');

// replace -exp with empty string
const modified = content.replace(/-exp/g, '');

writeFileSync(filePath, modified, 'utf-8');
}

exports.removeExpSuffix = removeExpSuffix;