Skip to content

Commit aeaff1e

Browse files
authored
Merge 10112ea into c38fc71
2 parents c38fc71 + 10112ea commit aeaff1e

File tree

9 files changed

+171
-54
lines changed

9 files changed

+171
-54
lines changed

.changeset/warm-suns-dream.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
---
3+
4+
Make exp release script work again

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"build": "lerna run --scope @firebase/* --scope firebase --scope rxfire build",
2626
"build:exp": "lerna run --scope @firebase/*-exp --scope firebase-exp build",
2727
"build:release": "lerna run --scope @firebase/* --scope firebase --ignore @firebase/*-exp --ignore firebase-exp prepare",
28-
"build:exp:release": "lerna run --scope @firebase/*-exp --scope firebase-exp prepare && yarn --cwd packages-exp/app-exp typings:public",
28+
"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",
2929
"link:packages": "lerna exec --scope @firebase/* --scope firebase --scope rxfire -- yarn link",
3030
"stage:packages": "./scripts/prepublish.sh",
3131
"repl": "node tools/repl.js",

packages-exp/app-exp/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
"test:browser": "karma start --single-run",
2424
"test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha src/**/*.test.ts --config ../../config/mocharc.node.js",
2525
"type-check": "tsc -p . --noEmit",
26-
"prepare": "rollup -c rollup.config.release.js",
26+
"prepare": "rollup -c rollup.config.release.js && yarn api-report",
2727
"api-report": "api-extractor run --local --verbose",
2828
"predoc": "node ../../scripts/exp/remove-exp.js temp",
2929
"doc": "api-documenter markdown --input temp --output docs",
3030
"build:doc": "yarn build && yarn doc",
31-
"typings:public": "node ./use_public_typings.js --public",
32-
"typings:internal": "node ./use_public_typings.js"
31+
"typings:public": "node ./use_typings.js --public",
32+
"typings:internal": "node ./use_typings.js"
3333
},
3434
"dependencies": {
3535
"@firebase/app-types-exp": "0.0.800",

packages-exp/functions-exp/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
2525
"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",
2626
"test:emulator": "env FIREBASE_FUNCTIONS_EMULATOR_ORIGIN=http://localhost:5005 run-p test:node",
27-
"prepare": "yarn build",
27+
"prepare": "rollup -c rollup.config.release.js && yarn api-report",
2828
"api-report": "api-extractor run --local --verbose",
2929
"predoc": "node ../../scripts/exp/remove-exp.js temp",
3030
"doc": "api-documenter markdown --input temp --output docs",

packages-exp/functions-exp/rollup.config.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ const es5Builds = [
4040
*/
4141
{
4242
input: 'src/index.ts',
43-
output: [
44-
{ file: pkg.browser, format: 'cjs', sourcemap: true },
45-
{ file: pkg.module, format: 'es', sourcemap: true }
46-
],
43+
output: [{ file: pkg.module, format: 'es', sourcemap: true }],
4744
plugins: es5BuildPlugins,
4845
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`))
4946
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* @license
3+
* Copyright 2019 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+
import typescriptPlugin from 'rollup-plugin-typescript2';
19+
import typescript from 'typescript';
20+
import json from 'rollup-plugin-json';
21+
import pkg from './package.json';
22+
import { importPathTransformer } from '../../scripts/exp/ts-transform-import-path';
23+
24+
const deps = Object.keys(
25+
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
26+
);
27+
28+
/**
29+
* ES5 Builds
30+
*/
31+
const es5BuildPlugins = [
32+
typescriptPlugin({
33+
typescript,
34+
clean: true,
35+
abortOnError: false,
36+
transformers: [importPathTransformer]
37+
}),
38+
json()
39+
];
40+
41+
const es5Builds = [
42+
/**
43+
* Browser Builds
44+
*/
45+
{
46+
input: 'src/index.ts',
47+
output: [{ file: pkg.browser, format: 'es', sourcemap: true }],
48+
plugins: es5BuildPlugins,
49+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
50+
treeshake: {
51+
moduleSideEffects: false
52+
}
53+
},
54+
/**
55+
* Node.js Build
56+
*/
57+
{
58+
input: 'src/index.ts',
59+
output: [{ file: pkg.main, format: 'cjs', sourcemap: true }],
60+
plugins: es5BuildPlugins,
61+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
62+
treeshake: {
63+
moduleSideEffects: false
64+
}
65+
}
66+
];
67+
68+
/**
69+
* ES2017 Builds
70+
*/
71+
const es2017BuildPlugins = [
72+
typescriptPlugin({
73+
typescript,
74+
tsconfigOverride: {
75+
compilerOptions: {
76+
target: 'es2017'
77+
}
78+
},
79+
abortOnError: false,
80+
clean: true,
81+
transformers: [importPathTransformer]
82+
}),
83+
json({
84+
preferConst: true
85+
})
86+
];
87+
88+
const es2017Builds = [
89+
/**
90+
* Browser Builds
91+
*/
92+
{
93+
input: 'src/index.ts',
94+
output: {
95+
file: pkg.esm2017,
96+
format: 'es',
97+
sourcemap: true
98+
},
99+
plugins: es2017BuildPlugins,
100+
external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)),
101+
treeshake: {
102+
moduleSideEffects: false
103+
}
104+
}
105+
];
106+
107+
export default [...es5Builds, ...es2017Builds];

packages-exp/functions-types-exp/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"license": "Apache-2.0",
88
"scripts": {
99
"test": "tsc",
10-
"test:ci": "node ../../scripts/run_tests_in_ci.js"
10+
"test:ci": "node ../../scripts/run_tests_in_ci.js",
11+
"prepare": "node ../../scripts/exp/remove-exp.js ./index.d.ts"
1112
},
1213
"files": [
1314
"index.d.ts"

scripts/exp/release.js renamed to scripts/exp/release.ts

+36-36
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@
1515
* limitations under the License.
1616
*/
1717

18-
const { spawn, exec } = require('child-process-promise');
19-
const ora = require('ora');
20-
const { projectRoot } = require('../utils');
21-
const simpleGit = require('simple-git/promise');
22-
const git = simpleGit(projectRoot);
23-
const { mapWorkspaceToPackages } = require('../release/utils/workspace');
24-
const { inc } = require('semver');
25-
const { readFile: _readFile, writeFile: _writeFile } = require('fs');
26-
const { promisify } = require('util');
18+
import { spawn, exec } from 'child-process-promise';
19+
import ora from 'ora';
20+
import { projectRoot } from '../utils';
21+
import simpleGit from 'simple-git/promise';
22+
23+
import { mapWorkspaceToPackages } from '../release/utils/workspace';
24+
import { inc } from 'semver';
25+
import { readFile as _readFile, writeFile as _writeFile } from 'fs';
26+
import { promisify } from 'util';
27+
import chalk from 'chalk';
28+
import Listr from 'listr';
29+
2730
const readFile = promisify(_readFile);
2831
const writeFile = promisify(_writeFile);
29-
const chalk = require('chalk');
30-
const Listr = require('listr');
31-
32+
const git = simpleGit(projectRoot);
3233
const FIREBASE_UMBRELLA_PACKAGE_NAME = 'firebase-exp';
3334

3435
async function publishExpPackages() {
@@ -43,11 +44,6 @@ async function publishExpPackages() {
4344
*/
4445
await buildPackages();
4546

46-
/**
47-
* run tests
48-
*/
49-
await runTests();
50-
5147
// path to exp packages
5248
const packagePaths = await mapWorkspaceToPackages([
5349
`${projectRoot}/packages-exp/*`
@@ -73,7 +69,7 @@ async function publishExpPackages() {
7369
* reset the working tree to recover package names with -exp in the package.json files,
7470
* then bump patch version of firebase-exp (the umbrella package) only
7571
*/
76-
const firebaseExpVersion = new Map();
72+
const firebaseExpVersion = new Map<string, string>();
7773
firebaseExpVersion.set(
7874
FIREBASE_UMBRELLA_PACKAGE_NAME,
7975
versions.get(FIREBASE_UMBRELLA_PACKAGE_NAME)
@@ -110,14 +106,7 @@ async function buildPackages() {
110106
});
111107
}
112108

113-
async function runTests() {
114-
await spawn('yarn', ['test:exp'], {
115-
cwd: projectRoot,
116-
stdio: 'inherit'
117-
});
118-
}
119-
120-
async function updatePackageNamesAndVersions(packagePaths) {
109+
async function updatePackageNamesAndVersions(packagePaths: string[]) {
121110
// get package name -> next version mapping
122111
const versions = new Map();
123112
for (const path of packagePaths) {
@@ -145,7 +134,7 @@ async function updatePackageNamesAndVersions(packagePaths) {
145134
return versions;
146135
}
147136

148-
async function publishToNpm(packagePaths) {
137+
async function publishToNpm(packagePaths: string[]) {
149138
const taskArray = await Promise.all(
150139
packagePaths.map(async pp => {
151140
const { version, name } = await readPackageJson(pp);
@@ -165,12 +154,15 @@ async function publishToNpm(packagePaths) {
165154
return tasks.run();
166155
}
167156

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

173-
async function resetWorkingTreeAndBumpVersions(packagePaths, versions) {
162+
async function resetWorkingTreeAndBumpVersions(
163+
packagePaths: string[],
164+
versions: Map<string, string>
165+
) {
174166
console.log('Resetting working tree');
175167
await git.checkout('.');
176168

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

184176
async function updatePackageJsons(
185-
packagePaths,
186-
versions,
187-
{ removeExpInName, updateVersions, makePublic }
177+
packagePaths: string[],
178+
versions: Map<string, string>,
179+
{
180+
removeExpInName,
181+
updateVersions,
182+
makePublic
183+
}: {
184+
removeExpInName: boolean;
185+
updateVersions: boolean;
186+
makePublic: boolean;
187+
}
188188
) {
189189
for (const path of packagePaths) {
190190
const packageJsonPath = `${path}/package.json`;
@@ -210,7 +210,7 @@ async function updatePackageJsons(
210210
// update dep version and remove -exp in dep names
211211
// don't care about devDependencies because they are irrelavant when using the package
212212
const dependencies = packageJson.dependencies || {};
213-
const newDependenciesObj = {};
213+
const newDependenciesObj: { [key: string]: string } = {};
214214
for (const d of Object.keys(dependencies)) {
215215
const dNextVersion = versions.get(d);
216216
const nameWithoutExp = removeExpInPackageName(d);
@@ -237,7 +237,7 @@ async function updatePackageJsons(
237237
}
238238
}
239239

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

243243
const firebaseExpVersion = versions.get(FIREBASE_UMBRELLA_PACKAGE_NAME);
@@ -255,7 +255,7 @@ async function commitAndPush(versions) {
255255
});
256256
}
257257

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

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

269-
async function readPackageJson(packagePath) {
269+
async function readPackageJson(packagePath: string) {
270270
/**
271271
* Can't require here because require caches the file
272272
* in memory, so it may not contain the updates that are made by e.g. git commands

scripts/exp/remove-exp.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,30 @@ const { readdirSync, statSync, readFileSync, writeFileSync } = require('fs');
2525

2626
// can be used in command line
2727
if (argv._[0]) {
28-
const dir = path.resolve(argv._[0]);
29-
removeExpSuffix(dir);
28+
const dirOrFile = path.resolve(argv._[0]);
29+
if (statSync(dirOrFile).isFile()) {
30+
removeExpSuffixFromFile(dirOrFile);
31+
} else {
32+
removeExpSuffix(dir);
33+
}
3034
}
3135

3236
function removeExpSuffix(dir) {
3337
for (const file of readdirSync(dir)) {
3438
const filePath = `${dir}/${file}`;
3539
if (statSync(filePath).isFile()) {
36-
const content = readFileSync(filePath, 'utf-8');
37-
38-
// replace -exp with empty string
39-
const modified = content.replace(/-exp/g, '');
40-
41-
writeFileSync(filePath, modified, 'utf-8');
40+
removeExpSuffixFromFile(filePath);
4241
}
4342
}
4443
}
4544

45+
function removeExpSuffixFromFile(filePath) {
46+
const content = readFileSync(filePath, 'utf-8');
47+
48+
// replace -exp with empty string
49+
const modified = content.replace(/-exp/g, '');
50+
51+
writeFileSync(filePath, modified, 'utf-8');
52+
}
53+
4654
exports.removeExpSuffix = removeExpSuffix;

0 commit comments

Comments
 (0)