From bf052317069077f1c7fdcc290b2d669610f5fd83 Mon Sep 17 00:00:00 2001 From: Sumedh Bhattacharya Date: Wed, 16 Sep 2020 13:17:36 -0700 Subject: [PATCH 1/3] init with changes --- package.json | 39 ++++++ .../src/bumpVersion/bumpVersion.ts | 57 ++++++--- tools/build-tools/src/common/fluidRepo.ts | 115 ++++++++++++++++++ tools/build-tools/src/common/fluidRepoBase.ts | 65 ---------- tools/build-tools/src/common/fluidUtils.ts | 17 ++- tools/build-tools/src/common/monoRepo.ts | 4 +- .../build-tools/src/fluidBuild/fluidBuild.ts | 6 +- .../src/fluidBuild/fluidPackageCheck.ts | 5 +- .../{fluidRepo.ts => fluidRepoBuild.ts} | 10 +- tools/build-tools/src/fluidBuild/options.ts | 4 +- .../src/fluidBuild/symlinkUtils.ts | 8 +- .../src/fluidBuild/tasks/concurrentNpmTask.ts | 3 +- .../src/fluidBuild/tasks/leaf/webpackTask.ts | 4 +- .../build-tools/src/fluidBuild/tasks/task.ts | 2 +- .../genMonoRepoPackageJson.ts | 10 +- .../build-tools/src/layerCheck/layerCheck.ts | 6 +- 16 files changed, 235 insertions(+), 120 deletions(-) create mode 100644 tools/build-tools/src/common/fluidRepo.ts delete mode 100644 tools/build-tools/src/common/fluidRepoBase.ts rename tools/build-tools/src/fluidBuild/{fluidRepo.ts => fluidRepoBuild.ts} (94%) diff --git a/package.json b/package.json index 24fb1bdeb25f..cd51fc39a0f7 100644 --- a/package.json +++ b/package.json @@ -106,5 +106,44 @@ "rimraf": "^2.6.2", "run-script-os": "^1.0.7", "typescript": "~3.7.4" + }, + "fluidBuild": { + "repoPackages": { + "client": [ + { + "directory": "common" + }, + { + "directory": "tools/generator-fluid" + } + ], + "server": { + "required": [ + { + "directory": "server/tinylicious" + } + ], + "optional": [ + { + "directory": "server", + "ignoredDirs": [ + "routerlicious" + ] + } + ] + } + }, + "serverPath": "server/routerlicious", + "releaseOrder": { + "preRepo": [ + ["@fluidframework/eslint-config-fluid", "@fluidframework/build-common"], + ["@fluidframework/common-definitions"], + ["@fluidframework/common-utils"] + ], + "postRepo": [ + ["generator-fluid", "tinylicious"] + ] + }, + "generatorName": "generator-fluid" } } diff --git a/tools/build-tools/src/bumpVersion/bumpVersion.ts b/tools/build-tools/src/bumpVersion/bumpVersion.ts index fda6e050ec95..6a341c94e6de 100644 --- a/tools/build-tools/src/bumpVersion/bumpVersion.ts +++ b/tools/build-tools/src/bumpVersion/bumpVersion.ts @@ -7,14 +7,15 @@ import * as path from "path"; import { commonOptions, commonOptionString, parseOption } from "../common/commonOptions"; import { Timer } from "../common/timer"; -import { getResolvedFluidRoot } from "../common/fluidUtils"; -import { FluidRepoBase } from "../common/fluidRepoBase"; +import { getResolvedFluidRoot, getPackageManifest } from "../common/fluidUtils"; +import { FluidRepo } from "../common/fluidRepo"; import { MonoRepo, MonoRepoKind } from "../common/monoRepo"; import * as semver from "semver"; import { Package } from "../common/npmPackage"; import { logVerbose } from "../common/logging"; import { GitRepo, fatal, exec, execNoError } from "./utils"; import * as os from "os"; +import { assert } from "console"; function printUsage() { console.log( @@ -442,7 +443,7 @@ class ReferenceVersionBag extends VersionBag { class BumpVersion { private readonly timer: Timer; - private readonly repo: FluidRepoBase; + private readonly repo: FluidRepo; private readonly fullPackageMap: Map; private readonly generatorPackage: Package; private readonly templatePackage: Package; @@ -457,7 +458,7 @@ class BumpVersion { this.timer = new Timer(commonOptions.timer); // Load the package - this.repo = new FluidRepoBase(this.gitRepo.resolvedRoot, false); + this.repo = new FluidRepo(this.gitRepo.resolvedRoot, false); this.timer.time("Package scan completed"); this.fullPackageMap = this.repo.createPackageMap(); @@ -542,9 +543,9 @@ class BumpVersion { // Determine the kind of bump const branchName = this.originalBranchName; - if (branchName !== "main" && !branchName!.startsWith("release/")) { - fatal(`Unrecognized branch '${branchName}'`); - } + // if (branchName !== "main" && !branchName!.startsWith("release/")) { + // fatal(`Unrecognized branch '${branchName}'`); + // } return branchName === "main" ? "minor" : "patch"; } @@ -563,7 +564,8 @@ class BumpVersion { if (releaseName === MonoRepoKind[MonoRepoKind.Client]) { processMonoRepo(this.repo.clientMonoRepo); } else if (releaseName === MonoRepoKind[MonoRepoKind.Server]) { - processMonoRepo(this.repo.serverMonoRepo); + assert(this.repo.serverMonoRepo, "Attempted to collect server info on a Fluid repo with no server directory"); + processMonoRepo(this.repo.serverMonoRepo!); } else { const pkg = this.fullPackageMap.get(releaseName); if (!pkg) { @@ -648,7 +650,8 @@ class BumpVersion { if (name === MonoRepoKind[MonoRepoKind.Client]) { await processMonoRepo(this.repo.clientMonoRepo); } else if (name === MonoRepoKind[MonoRepoKind.Server]) { - await processMonoRepo(this.repo.serverMonoRepo); + assert(this.repo.serverMonoRepo, "Attempted show server versions on a Fluid repo with no server directory"); + await processMonoRepo(this.repo.serverMonoRepo!); } else { pkg = this.fullPackageMap.get(name); if (!pkg) { @@ -679,7 +682,8 @@ class BumpVersion { if (serverNeedBump) { console.log(" Bumping server version"); - await bumpMonoRepo(this.repo.serverMonoRepo); + assert(this.repo.serverMonoRepo, "Attempted server version bump on a Fluid repo with no server directory"); + await bumpMonoRepo(this.repo.serverMonoRepo!); } for (const pkg of packageNeedBump) { @@ -1006,13 +1010,13 @@ class BumpVersion { } /** - * Create release branch based on the repo state, bump minor version immediately + * Create release branch based on the repo state, bump minor version immediately * and push it to `main` and the new release branch to remote */ public async createReleaseBranch() { // Create release branch based on client version const releaseName = MonoRepoKind[MonoRepoKind.Client]; - + const depVersions = await this.collectBumpInfo(releaseName); const releaseVersion = depVersions.repoVersions.get(releaseName); if (!releaseVersion) { @@ -1115,13 +1119,25 @@ class BumpVersion { await this.createBranch(pendingReleaseBranch); } - // TODO: Don't hard code order - await this.releasePackage(depVersions, ["@fluidframework/eslint-config-fluid", "@fluidframework/build-common"]); - await this.releasePackage(depVersions, ["@fluidframework/common-definitions"]); - await this.releasePackage(depVersions, ["@fluidframework/common-utils"]); - await this.releaseMonoRepo(depVersions, this.repo.serverMonoRepo); + const packageManifest = getPackageManifest(this.repo.resolvedRoot); + + if (packageManifest.releaseOrder?.preRepo !== undefined) { + packageManifest.releaseOrder.preRepo.forEach(async packages => + await this.releasePackage(depVersions, packages) + ); + } + + if (this.repo.serverMonoRepo) { + await this.releaseMonoRepo(depVersions, this.repo.serverMonoRepo); + } + await this.releaseMonoRepo(depVersions, this.repo.clientMonoRepo); - await this.releasePackage(depVersions, [generatorFluidPackageName, "tinylicious"]); + + if (packageManifest.releaseOrder?.postRepo !== undefined) { + packageManifest.releaseOrder.postRepo.forEach(async packages => + await this.releasePackage(depVersions, packages) + ); + } // ------------------------------------------------------------------------------------------------------------------ // Create the minor version bump for development in a temporary merge/ on top of the release commit @@ -1173,7 +1189,8 @@ class BumpVersion { } } else if (name === MonoRepoKind[MonoRepoKind.Server]) { serverNeedBump = true; - const ret = await this.repo.serverMonoRepo.install(); + assert(this.repo.serverMonoRepo, "Attempted to bump server version on a Fluid repo with no server directory"); + const ret = await this.repo.serverMonoRepo!.install(); if (ret.error) { fatal("Install failed"); } @@ -1241,7 +1258,7 @@ class BumpVersion { if (updateLockPackage.length !== 0) { if (updateLock) { // Fix package lock - if (!await FluidRepoBase.ensureInstalled(updateLockPackage, false)) { + if (!await FluidRepo.ensureInstalled(updateLockPackage, false)) { fatal("Install Failed"); } } else { diff --git a/tools/build-tools/src/common/fluidRepo.ts b/tools/build-tools/src/common/fluidRepo.ts new file mode 100644 index 000000000000..8b0b91783a05 --- /dev/null +++ b/tools/build-tools/src/common/fluidRepo.ts @@ -0,0 +1,115 @@ +/*! + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +import * as path from "path"; +import { Package, Packages } from "./npmPackage"; +import { MonoRepo, MonoRepoKind } from "./monoRepo"; +import { getPackageManifest } from "./fluidUtils"; +import { assert } from "console"; + +export interface IPackageManifest { + repoPackages: { + client: IFluidRepoPackage[], + server: { + required: IFluidRepoPackage[], + optional?: IFluidRepoPackage[], + } + }, + serverPath?: string, + releaseOrder?: { + preRepo?: string[][], + postRepo?: string[][] + }, + generatorName?: string +} + +export interface IFluidRepoPackage { + directory: string, + ignoredDirs?: string[] +} + +export class FluidRepo { + public readonly clientMonoRepo: MonoRepo; + public readonly serverMonoRepo?: MonoRepo; + + public readonly packages: Packages; + constructor(public readonly resolvedRoot: string, services: boolean) { + const packageManifest = getPackageManifest(resolvedRoot); + this.clientMonoRepo = new MonoRepo(MonoRepoKind.Client, this.resolvedRoot); + if (packageManifest.serverPath) { + this.serverMonoRepo = new MonoRepo(MonoRepoKind.Server, path.join(this.resolvedRoot, packageManifest.serverPath)); + } + + let additionalPackages: Package[] = []; + + packageManifest.repoPackages.client.forEach((fluidPackage: IFluidRepoPackage) => { + additionalPackages = [ + ...additionalPackages, + ...Packages.loadDir(path.join(resolvedRoot, fluidPackage.directory), undefined, fluidPackage.ignoredDirs) + ] + }); + + if (services) { + assert(packageManifest.repoPackages.server.optional, "Requested optional server packages without passing parameters in package.json"); + packageManifest.repoPackages.server.optional!.forEach((fluidPackage: IFluidRepoPackage) => { + additionalPackages = [ + ...additionalPackages, + ...Packages.loadDir(path.join(resolvedRoot, fluidPackage.directory), undefined, fluidPackage.ignoredDirs) + ] + }); + } else { + packageManifest.repoPackages.server.required.forEach((fluidPackage: IFluidRepoPackage) => { + additionalPackages = [ + ...additionalPackages, + ...Packages.loadDir(path.join(resolvedRoot, fluidPackage.directory), undefined, fluidPackage.ignoredDirs) + ] + }); + } + + console.log(JSON.stringify(additionalPackages)); + + this.packages = new Packages( + [ + ...this.clientMonoRepo.packages, + ...(this.serverMonoRepo?.packages || []), + ...additionalPackages, + ] + ); + } + + public createPackageMap() { + return new Map(this.packages.packages.map(pkg => [pkg.name, pkg])); + } + + public reload() { + this.packages.packages.forEach(pkg => pkg.reload()); + } + + public static async ensureInstalled(packages: Package[], check: boolean = true) { + const installedMonoRepo = new Set(); + const installPromises: Promise[] = []; + for (const pkg of packages) { + if (!check || !await pkg.checkInstall(false)) { + if (pkg.monoRepo) { + if (!installedMonoRepo.has(pkg.monoRepo)) { + installedMonoRepo.add(pkg.monoRepo); + installPromises.push(pkg.monoRepo.install()); + } + } else { + installPromises.push(pkg.install()); + } + } + } + const rets = await Promise.all(installPromises); + return !rets.some(ret => ret.error); + } + + public async install(nohoist: boolean = false) { + if (nohoist) { + return this.packages.noHoistInstall(this.resolvedRoot); + } + return FluidRepo.ensureInstalled(this.packages.packages); + } +}; diff --git a/tools/build-tools/src/common/fluidRepoBase.ts b/tools/build-tools/src/common/fluidRepoBase.ts deleted file mode 100644 index 026688f1f2db..000000000000 --- a/tools/build-tools/src/common/fluidRepoBase.ts +++ /dev/null @@ -1,65 +0,0 @@ -/*! - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - */ - -import * as path from "path"; -import { Package, Packages } from "./npmPackage"; -import { MonoRepo, MonoRepoKind } from "./monoRepo"; - -export class FluidRepoBase { - public readonly clientMonoRepo: MonoRepo; - public readonly serverMonoRepo: MonoRepo; - - public readonly packages: Packages; - constructor(public readonly resolvedRoot: string, services: boolean) { - this.clientMonoRepo = new MonoRepo(MonoRepoKind.Client, this.resolvedRoot); - this.serverMonoRepo = new MonoRepo(MonoRepoKind.Server, path.join(this.resolvedRoot, "server/routerlicious")); - this.packages = new Packages( - [ - ...Packages.loadDir(path.join(this.resolvedRoot, "common")), - ...this.serverMonoRepo.packages, - ...this.clientMonoRepo.packages, - ...Packages.loadDir(path.join(this.resolvedRoot, "tools/generator-fluid")), - ...services ? - Packages.loadDir(path.join(this.resolvedRoot, "server"), undefined, ["routerlicious"]): - Packages.loadDir(path.join(this.resolvedRoot, "server/tinylicious")), - - ] - ); - } - - public createPackageMap() { - return new Map(this.packages.packages.map(pkg => [pkg.name, pkg])); - } - - public reload() { - this.packages.packages.forEach(pkg => pkg.reload()); - } - - public static async ensureInstalled(packages: Package[], check: boolean = true) { - const installedMonoRepo = new Set(); - const installPromises: Promise[] = []; - for (const pkg of packages) { - if (!check || !await pkg.checkInstall(false)) { - if (pkg.monoRepo) { - if (!installedMonoRepo.has(pkg.monoRepo)) { - installedMonoRepo.add(pkg.monoRepo); - installPromises.push(pkg.monoRepo.install()); - } - } else { - installPromises.push(pkg.install()); - } - } - } - const rets = await Promise.all(installPromises); - return !rets.some(ret => ret.error); - } - - public async install(nohoist: boolean = false) { - if (nohoist) { - return this.packages.noHoistInstall(this.resolvedRoot); - } - return FluidRepoBase.ensureInstalled(this.packages.packages); - } -}; \ No newline at end of file diff --git a/tools/build-tools/src/common/fluidUtils.ts b/tools/build-tools/src/common/fluidUtils.ts index 2b92356fa032..253538bc2aa8 100644 --- a/tools/build-tools/src/common/fluidUtils.ts +++ b/tools/build-tools/src/common/fluidUtils.ts @@ -3,10 +3,12 @@ * Licensed under the MIT License. */ +import * as fs from "fs"; import { commonOptions } from "./commonOptions"; import { existsSync, realpathAsync, readJsonAsync, lookUpDir } from "./utils"; import * as path from "path"; import { logVerbose } from "./logging"; +import { IPackageManifest } from "./fluidRepo"; async function isFluidRootLerna(dir: string) { const filename = path.join(dir, "lerna.json"); @@ -14,9 +16,10 @@ async function isFluidRootLerna(dir: string) { logVerbose(`InferRoot: lerna.json not found`); return false; } - - if (!existsSync(path.join(dir, "server", "routerlicious", "lerna.json"))) { - logVerbose(`InferRoot: server/routerlicious/lerna.json not found`); + const rootPackageManifest = await getPackageManifest(dir); + if (rootPackageManifest.serverPath !== undefined + && !existsSync(path.join(dir, rootPackageManifest.serverPath, "lerna.json"))) { + logVerbose(`InferRoot: ${dir}/${rootPackageManifest.serverPath}/lerna.json not found`); return false; } @@ -87,4 +90,10 @@ export async function getResolvedFluidRoot() { // Use realpath.native to get the case-sensitive path on windows return await realpathAsync(resolvedRoot); -} \ No newline at end of file +} + +export function getPackageManifest(rootDir: string): IPackageManifest { + const pkgString = fs.readFileSync(`${rootDir}/package.json`); + console.log(JSON.parse(pkgString as any).fluidBuild); + return JSON.parse(pkgString as any).fluidBuild; +} diff --git a/tools/build-tools/src/common/monoRepo.ts b/tools/build-tools/src/common/monoRepo.ts index 436147376481..1c8eeabb9d69 100644 --- a/tools/build-tools/src/common/monoRepo.ts +++ b/tools/build-tools/src/common/monoRepo.ts @@ -5,7 +5,7 @@ import { Package, Packages } from "./npmPackage"; import * as path from "path"; -import { execWithErrorAsync, rimrafWithErrorAsync, existsSync, readJsonSync, readFileAsync, ExecAsyncResult, writeFileAsync} from "./utils"; +import { execWithErrorAsync, rimrafWithErrorAsync, existsSync, readJsonSync } from "./utils"; export enum MonoRepoKind { Client, @@ -47,4 +47,4 @@ export class MonoRepo { public async uninstall() { return rimrafWithErrorAsync(this.getNodeModulePath(), this.repoPath); } -}; \ No newline at end of file +}; diff --git a/tools/build-tools/src/fluidBuild/fluidBuild.ts b/tools/build-tools/src/fluidBuild/fluidBuild.ts index 99c70e314d3d..d04fad9efb55 100644 --- a/tools/build-tools/src/fluidBuild/fluidBuild.ts +++ b/tools/build-tools/src/fluidBuild/fluidBuild.ts @@ -4,7 +4,7 @@ */ import { commonOptions } from "../common/commonOptions"; -import { FluidRepo } from "./fluidRepo"; +import { FluidRepoBuild } from "./fluidRepoBuild"; import { getResolvedFluidRoot } from "../common/fluidUtils"; import { logStatus } from "../common/logging"; import { Timer } from "../common/timer"; @@ -32,7 +32,7 @@ async function main() { } // Load the package - const repo = new FluidRepo(resolvedRoot, options.services); + const repo = new FluidRepoBuild(resolvedRoot, options.services); timer.time("Package scan completed"); // Set matched package based on options filter @@ -92,7 +92,7 @@ async function main() { await repo.checkPackages(options.fix); timer.time("Check scripts completed"); - + if (options.clean || options.build !== false) { logStatus(`Symlink in ${options.fullSymlink ? "full" : options.fullSymlink === false ? "isolated" : "non-dependent"} mode`); diff --git a/tools/build-tools/src/fluidBuild/fluidPackageCheck.ts b/tools/build-tools/src/fluidBuild/fluidPackageCheck.ts index 9bc70fc917c1..b56691658465 100644 --- a/tools/build-tools/src/fluidBuild/fluidPackageCheck.ts +++ b/tools/build-tools/src/fluidBuild/fluidPackageCheck.ts @@ -3,7 +3,6 @@ * Licensed under the MIT License. */ -import { FluidRepo } from "./fluidRepo"; import { MonoRepoKind } from "../common/monoRepo"; import { Package } from "../common/npmPackage"; import * as path from "path"; @@ -39,7 +38,7 @@ export class FluidPackageCheck { return fix; } - public static checkScripts(repo: FluidRepo, pkg: Package, fix: boolean) { + public static checkScripts(pkg: Package, fix: boolean) { const fixed = [ FluidPackageCheck.checkSort(pkg, fix), FluidPackageCheck.checkBuildScripts(pkg, fix), @@ -57,7 +56,7 @@ export class FluidPackageCheck { } /** - * Verify that all packages with 'test' scripts require the 'mocha-test-setup' package + * Verify that all packages with 'test' scripts require the 'mocha-test-setup' package * and have --unhandled-rejections=strict flag so to failed test with unhandled rejection */ private static checkTestScripts(pkg: Package, fix: boolean) { diff --git a/tools/build-tools/src/fluidBuild/fluidRepo.ts b/tools/build-tools/src/fluidBuild/fluidRepoBuild.ts similarity index 94% rename from tools/build-tools/src/fluidBuild/fluidRepo.ts rename to tools/build-tools/src/fluidBuild/fluidRepoBuild.ts index d1d4fede928b..2668cf099f20 100644 --- a/tools/build-tools/src/fluidBuild/fluidRepo.ts +++ b/tools/build-tools/src/fluidBuild/fluidRepoBuild.ts @@ -6,7 +6,7 @@ import { Package, Packages } from "../common/npmPackage"; import { globFn } from "../common/utils"; import { FluidPackageCheck } from "./fluidPackageCheck"; -import { FluidRepoBase } from "../common/fluidRepoBase"; +import { FluidRepo } from "../common/fluidRepo"; import { MonoRepoKind } from "../common/monoRepo"; import { NpmDepChecker } from "./npmDepChecker"; import { ISymlinkOptions, symlinkPackage } from "./symlinkUtils"; @@ -20,7 +20,7 @@ export interface IPackageMatchedOptions { server: boolean; }; -export class FluidRepo extends FluidRepoBase { +export class FluidRepoBuild extends FluidRepo { constructor(resolvedRoot: string, services: boolean) { super(resolvedRoot, services); } @@ -32,11 +32,11 @@ export class FluidRepo extends FluidRepoBase { public async uninstall() { const cleanPackageNodeModules = this.packages.cleanNodeModules(); const removePromise = Promise.all( - [this.clientMonoRepo.uninstall(), this.serverMonoRepo.uninstall()] + [this.clientMonoRepo.uninstall(), this.serverMonoRepo?.uninstall()] ); const r = await Promise.all([cleanPackageNodeModules, removePromise]); - return r[0] && !r[1].some(ret => ret.error); + return r[0] && !r[1].some(ret => ret?.error); }; public setMatched(options: IPackageMatchedOptions) { @@ -63,7 +63,7 @@ export class FluidRepo extends FluidRepoBase { public async checkPackages(fix: boolean) { for (const pkg of this.packages.packages) { - if (FluidPackageCheck.checkScripts(this, pkg, fix)) { + if (FluidPackageCheck.checkScripts(pkg, fix)) { await pkg.savePackageJson(); } await FluidPackageCheck.checkNpmIgnore(pkg, fix); diff --git a/tools/build-tools/src/fluidBuild/options.ts b/tools/build-tools/src/fluidBuild/options.ts index 834f9c45da1a..d0f8518f7f25 100644 --- a/tools/build-tools/src/fluidBuild/options.ts +++ b/tools/build-tools/src/fluidBuild/options.ts @@ -5,7 +5,7 @@ import * as os from "os"; import { commonOptionString, parseOption } from "../common/commonOptions" -import { IPackageMatchedOptions } from "./fluidRepo"; +import { IPackageMatchedOptions } from "./fluidRepoBuild"; import { ISymlinkOptions } from "./symlinkUtils"; interface FastBuildOptions extends IPackageMatchedOptions, ISymlinkOptions { @@ -273,4 +273,4 @@ export function parseOptions(argv: string[]) { if (options.buildScriptNames.length === 0) { options.buildScriptNames = ["build"]; } -} \ No newline at end of file +} diff --git a/tools/build-tools/src/fluidBuild/symlinkUtils.ts b/tools/build-tools/src/fluidBuild/symlinkUtils.ts index cdf6c1759faf..ff64afc1f3ee 100644 --- a/tools/build-tools/src/fluidBuild/symlinkUtils.ts +++ b/tools/build-tools/src/fluidBuild/symlinkUtils.ts @@ -5,7 +5,7 @@ import * as path from "path"; import { Package } from "../common/npmPackage"; -import { logVerbose, logStatus } from "../common/logging"; +import { logVerbose } from "../common/logging"; import { existsSync, mkdirAsync, @@ -16,7 +16,7 @@ import { lstatAsync, realpathAsync, } from "../common/utils"; -import { FluidRepo } from "./fluidRepo"; +import { FluidRepoBuild } from "./fluidRepoBuild"; import * as semver from "semver"; import * as fs from "fs"; import { MonoRepo } from "../common/monoRepo"; @@ -124,7 +124,7 @@ export interface ISymlinkOptions { fullSymlink: boolean | undefined; }; -export async function symlinkPackage(repo: FluidRepo, pkg: Package, buildPackages: Map, options: ISymlinkOptions) { +export async function symlinkPackage(repo: FluidRepoBuild, pkg: Package, buildPackages: Map, options: ISymlinkOptions) { let count = 0; const monoRepoNodeModulePath = pkg.monoRepo?.getNodeModulePath(); @@ -214,4 +214,4 @@ export async function symlinkPackage(repo: FluidRepo, pkg: Package, buildPackage } } return { pkg, count }; -} \ No newline at end of file +} diff --git a/tools/build-tools/src/fluidBuild/tasks/concurrentNpmTask.ts b/tools/build-tools/src/fluidBuild/tasks/concurrentNpmTask.ts index 3120b622d61e..05813ee1ead3 100644 --- a/tools/build-tools/src/fluidBuild/tasks/concurrentNpmTask.ts +++ b/tools/build-tools/src/fluidBuild/tasks/concurrentNpmTask.ts @@ -4,7 +4,6 @@ */ import { AsyncPriorityQueue } from "async"; -import { logVerbose } from "../../common/logging"; import { NPMTask } from "./npmTask"; import { Task, TaskExec } from "./task"; import { BuildResult, BuildPackage } from "../buildGraph"; @@ -34,4 +33,4 @@ export class ConcurrentNPMTask extends NPMTask { this.logVerboseTask(`End Concurrent Child Tasks`); return retResult; } -} \ No newline at end of file +} diff --git a/tools/build-tools/src/fluidBuild/tasks/leaf/webpackTask.ts b/tools/build-tools/src/fluidBuild/tasks/leaf/webpackTask.ts index 6475abe168fc..217db79279b6 100644 --- a/tools/build-tools/src/fluidBuild/tasks/leaf/webpackTask.ts +++ b/tools/build-tools/src/fluidBuild/tasks/leaf/webpackTask.ts @@ -4,7 +4,7 @@ */ import { LeafTask, LeafWithDoneFileTask } from "./leafTask"; -import { globFn, toPosixPath, readFileAsync, existsSync } from "../../../common/utils"; +import { globFn, toPosixPath } from "../../../common/utils"; import { TscTask } from "./tscTask"; import * as path from "path"; @@ -90,4 +90,4 @@ export class WebpackTask extends LeafWithDoneFileTask { return path.join(this.package.directory, configFile); } -} \ No newline at end of file +} diff --git a/tools/build-tools/src/fluidBuild/tasks/task.ts b/tools/build-tools/src/fluidBuild/tasks/task.ts index de1041188b13..a89853774f1e 100644 --- a/tools/build-tools/src/fluidBuild/tasks/task.ts +++ b/tools/build-tools/src/fluidBuild/tasks/task.ts @@ -68,4 +68,4 @@ export abstract class Task { public get forced() { return options.force && (options.matchedOnly !== true || this.package.matched); } -}; \ No newline at end of file +}; diff --git a/tools/build-tools/src/genMonoRepoPackageJson/genMonoRepoPackageJson.ts b/tools/build-tools/src/genMonoRepoPackageJson/genMonoRepoPackageJson.ts index 83e34966bb25..647a4c944ff4 100644 --- a/tools/build-tools/src/genMonoRepoPackageJson/genMonoRepoPackageJson.ts +++ b/tools/build-tools/src/genMonoRepoPackageJson/genMonoRepoPackageJson.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. */ -import { FluidRepoBase } from "../common/fluidRepoBase"; +import { FluidRepo } from "../common/fluidRepo"; import { MonoRepo, MonoRepoKind } from "../common/monoRepo"; import { Timer } from "../common/timer"; import { getResolvedFluidRoot } from "../common/fluidUtils"; @@ -85,7 +85,7 @@ async function generateMonoRepoPackageLockJson(monoRepo: MonoRepo, repoPackageJs const markNonDev = (name: string, item: any) => { totalDevCount--; delete item.dev; - if (item.dependencies) { + if (item.dependencies) { // mark unhoisted dependencies recursively for (const dep in item.dependencies) { markNonDev(dep, item.dependencies[dep]); @@ -199,11 +199,13 @@ async function main() { const resolvedRoot = await getResolvedFluidRoot(); // Load the package - const repo = new FluidRepoBase(resolvedRoot, false); + const repo = new FluidRepo(resolvedRoot, false); timer.time("Package scan completed"); await generateMonoRepoInstallPackageJson(repo.clientMonoRepo); - await generateMonoRepoInstallPackageJson(repo.serverMonoRepo); + if (repo.serverMonoRepo) { + await generateMonoRepoInstallPackageJson(repo.serverMonoRepo); + } }; main().catch(error => { diff --git a/tools/build-tools/src/layerCheck/layerCheck.ts b/tools/build-tools/src/layerCheck/layerCheck.ts index af1c6de42612..5f05976b6369 100644 --- a/tools/build-tools/src/layerCheck/layerCheck.ts +++ b/tools/build-tools/src/layerCheck/layerCheck.ts @@ -7,8 +7,8 @@ import { LayerGraph } from "./layerGraph"; import { commonOptions, commonOptionString, parseOption } from "../common/commonOptions"; import { Timer } from "../common/timer"; import { getResolvedFluidRoot } from "../common/fluidUtils"; -import { writeFileAsync, appendFileAsync } from "../common/utils"; -import { FluidRepoBase } from "../common/fluidRepoBase"; +import { writeFileAsync } from "../common/utils"; +import { FluidRepo } from "../common/fluidRepo"; import path from "path"; function printUsage() { @@ -93,7 +93,7 @@ async function main() { const resolvedRoot = await getResolvedFluidRoot(); // Load the package - const packages = new FluidRepoBase(resolvedRoot, false).packages; + const packages = new FluidRepo(resolvedRoot, false).packages; timer.time("Package scan completed"); try { From ef310bd2c3b1bbbc268ba732cdeb1f50589e0f7d Mon Sep 17 00:00:00 2001 From: Sumedh Bhattacharya Date: Wed, 16 Sep 2020 14:00:24 -0700 Subject: [PATCH 2/3] bump version promise ordering --- .../src/bumpVersion/bumpVersion.ts | 29 ++++++++++--------- tools/build-tools/src/common/fluidRepo.ts | 2 -- tools/build-tools/src/common/fluidUtils.ts | 1 - 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tools/build-tools/src/bumpVersion/bumpVersion.ts b/tools/build-tools/src/bumpVersion/bumpVersion.ts index 6a341c94e6de..848027d9f28b 100644 --- a/tools/build-tools/src/bumpVersion/bumpVersion.ts +++ b/tools/build-tools/src/bumpVersion/bumpVersion.ts @@ -8,7 +8,7 @@ import * as path from "path"; import { commonOptions, commonOptionString, parseOption } from "../common/commonOptions"; import { Timer } from "../common/timer"; import { getResolvedFluidRoot, getPackageManifest } from "../common/fluidUtils"; -import { FluidRepo } from "../common/fluidRepo"; +import { FluidRepo, IPackageManifest } from "../common/fluidRepo"; import { MonoRepo, MonoRepoKind } from "../common/monoRepo"; import * as semver from "semver"; import { Package } from "../common/npmPackage"; @@ -47,8 +47,6 @@ let paramVersion: semver.SemVer | undefined; let paramBumpName: string | undefined; let paramBumpVersion: VersionChangeType | undefined; -const generatorFluidPackageName = "generator-fluid"; - function parseNameVersion(arg: string | undefined) { let name = arg; let extra = false; @@ -447,6 +445,7 @@ class BumpVersion { private readonly fullPackageMap: Map; private readonly generatorPackage: Package; private readonly templatePackage: Package; + private readonly packageManifest: IPackageManifest; private readonly newBranches: string[] = []; private readonly newTags: string[] = []; @@ -462,10 +461,12 @@ class BumpVersion { this.timer.time("Package scan completed"); this.fullPackageMap = this.repo.createPackageMap(); + this.packageManifest = getPackageManifest(this.repo.resolvedRoot); // TODO: Is there a way to generate this automatically? - const generatorPackage = this.fullPackageMap.get(generatorFluidPackageName); - if (!generatorPackage) { fatal(`Unable to find ${generatorFluidPackageName} package`) }; + if (!this.packageManifest.generatorName) { fatal(`Unable to find generator package name in package.json`)} + const generatorPackage = this.fullPackageMap.get(this.packageManifest.generatorName); + if (!generatorPackage) { fatal(`Unable to find ${this.packageManifest.generatorName} package`) }; this.generatorPackage = generatorPackage; this.templatePackage = new Package(path.join(generatorPackage.directory, "app", "templates", "package.json")); } @@ -1119,13 +1120,13 @@ class BumpVersion { await this.createBranch(pendingReleaseBranch); } - const packageManifest = getPackageManifest(this.repo.resolvedRoot); - - if (packageManifest.releaseOrder?.preRepo !== undefined) { - packageManifest.releaseOrder.preRepo.forEach(async packages => - await this.releasePackage(depVersions, packages) + const preRepoPromises: Promise[] = []; + if (this.packageManifest.releaseOrder?.preRepo !== undefined) { + this.packageManifest.releaseOrder.preRepo.forEach(async packages => + preRepoPromises.push(this.releasePackage(depVersions, packages)) ); } + await Promise.all(preRepoPromises); if (this.repo.serverMonoRepo) { await this.releaseMonoRepo(depVersions, this.repo.serverMonoRepo); @@ -1133,11 +1134,13 @@ class BumpVersion { await this.releaseMonoRepo(depVersions, this.repo.clientMonoRepo); - if (packageManifest.releaseOrder?.postRepo !== undefined) { - packageManifest.releaseOrder.postRepo.forEach(async packages => - await this.releasePackage(depVersions, packages) + const postRepoPromises: Promise[] = []; + if (this.packageManifest.releaseOrder?.postRepo !== undefined) { + this.packageManifest.releaseOrder.postRepo.forEach(async packages => + postRepoPromises.push(this.releasePackage(depVersions, packages)) ); } + await Promise.all(postRepoPromises); // ------------------------------------------------------------------------------------------------------------------ // Create the minor version bump for development in a temporary merge/ on top of the release commit diff --git a/tools/build-tools/src/common/fluidRepo.ts b/tools/build-tools/src/common/fluidRepo.ts index 8b0b91783a05..8c0c8da7b027 100644 --- a/tools/build-tools/src/common/fluidRepo.ts +++ b/tools/build-tools/src/common/fluidRepo.ts @@ -68,8 +68,6 @@ export class FluidRepo { }); } - console.log(JSON.stringify(additionalPackages)); - this.packages = new Packages( [ ...this.clientMonoRepo.packages, diff --git a/tools/build-tools/src/common/fluidUtils.ts b/tools/build-tools/src/common/fluidUtils.ts index 253538bc2aa8..84fd6b54db5d 100644 --- a/tools/build-tools/src/common/fluidUtils.ts +++ b/tools/build-tools/src/common/fluidUtils.ts @@ -94,6 +94,5 @@ export async function getResolvedFluidRoot() { export function getPackageManifest(rootDir: string): IPackageManifest { const pkgString = fs.readFileSync(`${rootDir}/package.json`); - console.log(JSON.parse(pkgString as any).fluidBuild); return JSON.parse(pkgString as any).fluidBuild; } From 8480265fc2a806ae957c6fdcaa6e85bebbf35887 Mon Sep 17 00:00:00 2001 From: Sumedh Bhattacharya Date: Wed, 16 Sep 2020 14:06:31 -0700 Subject: [PATCH 3/3] branch check --- tools/build-tools/src/bumpVersion/bumpVersion.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/build-tools/src/bumpVersion/bumpVersion.ts b/tools/build-tools/src/bumpVersion/bumpVersion.ts index 848027d9f28b..8c5a149908af 100644 --- a/tools/build-tools/src/bumpVersion/bumpVersion.ts +++ b/tools/build-tools/src/bumpVersion/bumpVersion.ts @@ -544,9 +544,9 @@ class BumpVersion { // Determine the kind of bump const branchName = this.originalBranchName; - // if (branchName !== "main" && !branchName!.startsWith("release/")) { - // fatal(`Unrecognized branch '${branchName}'`); - // } + if (branchName !== "main" && !branchName!.startsWith("release/")) { + fatal(`Unrecognized branch '${branchName}'`); + } return branchName === "main" ? "minor" : "patch"; }