diff --git a/.gitignore b/.gitignore index 9bc3587512f..7abffac9a53 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ package-deps.json # Bundle analysis artifacts bundleAnalysis + +# Misc pipeline artifacts +artifacts diff --git a/tools/build-tools/bin/fluid-collect-bundle-analyses b/tools/build-tools/bin/fluid-collect-bundle-analyses new file mode 100644 index 00000000000..7b0c6a2d0ea --- /dev/null +++ b/tools/build-tools/bin/fluid-collect-bundle-analyses @@ -0,0 +1,2 @@ +#!/usr/bin/env node +require("../dist/bundleAnalysis/collectBundleAnalyses.js"); diff --git a/tools/build-tools/package-lock.json b/tools/build-tools/package-lock.json index 8b21eab60dd..85cddc452aa 100644 --- a/tools/build-tools/package-lock.json +++ b/tools/build-tools/package-lock.json @@ -43,6 +43,15 @@ "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz", "integrity": "sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==" }, + "@types/fs-extra": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-8.1.1.tgz", + "integrity": "sha512-TcUlBem321DFQzBNuz8p0CLLKp0VvF/XH9E4KHNmgwyp4E3AfgI5cjiIVZWlbfThBop2qxFIh4+LeY6hVWWZ2w==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/glob": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.1.tgz", @@ -123,6 +132,11 @@ "lodash": "^4.17.11" } }, + "at-least-node": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", + "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==" + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -264,6 +278,17 @@ "path-exists": "^4.0.0" } }, + "fs-extra": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.0.1.tgz", + "integrity": "sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==", + "requires": { + "at-least-node": "^1.0.0", + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^1.0.0" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -315,6 +340,11 @@ "slash": "^3.0.0" } }, + "graceful-fs": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", + "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==" + }, "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", @@ -367,6 +397,15 @@ "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==" }, + "jsonfile": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.0.1.tgz", + "integrity": "sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg==", + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^1.0.0" + } + }, "locate-path": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", @@ -625,6 +664,11 @@ "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.4.tgz", "integrity": "sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==" }, + "universalify": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz", + "integrity": "sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==" + }, "which-module": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", diff --git a/tools/build-tools/package.json b/tools/build-tools/package.json index dc2d0632b74..b05e16e1bcd 100644 --- a/tools/build-tools/package.json +++ b/tools/build-tools/package.json @@ -10,6 +10,7 @@ "fluid-build": "bin/fluid-build", "fluid-build-version": "bin/fluid-build-version", "fluid-bump-version": "bin/fluid-bump-version", + "fluid-collect-bundle-analyses": "bin/fluid-collect-bundle-analyses", "fluid-doc-stats": "bin/fluid-doc-stats", "fluid-layer-check": "bin/fluid-layer-check", "fluid-repo-policy-check": "bin/fluid-repo-policy-check" @@ -27,6 +28,7 @@ "async": "^2.6.2", "chalk": "^2.4.2", "commander": "^2.20.0", + "fs-extra": "^9.0.1", "glob": "^7.1.3", "lodash.isequal": "^4.5.0", "replace-in-file": "^6.0.0", @@ -37,6 +39,7 @@ }, "devDependencies": { "@types/async": "^2.4.1", + "@types/fs-extra": "^8.1.0", "@types/glob": "^7.1.1", "@types/lodash.isequal": "^4.5.5", "@types/node": "^11.9.4", diff --git a/tools/build-tools/src/bundleSizeAnalysis/collectBundleAnalyses.ts b/tools/build-tools/src/bundleSizeAnalysis/collectBundleAnalyses.ts new file mode 100644 index 00000000000..67b440ae9a9 --- /dev/null +++ b/tools/build-tools/src/bundleSizeAnalysis/collectBundleAnalyses.ts @@ -0,0 +1,47 @@ +/*! + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +import * as child_process from "child_process"; +import * as fse from "fs-extra"; +import * as path from "path"; + +// Find all bundle analysis artifacts and copy them into a central +// location to upload as build artifacts for later consumption +function main() { + // Get all the package locations + let lernaOutput; + try { + lernaOutput = JSON.parse(child_process.execSync("npx lerna list --all --json").toString()); + if (!Array.isArray(lernaOutput)) { + throw new Error("failed to get package information"); + } + } catch (e) { + console.error(e.toString()); + process.exit(-1); + } + + // Check each package location for a bundleAnalysis folder + // and copy it to a central location + const analysesDestPath = path.join(process.cwd(), "artifacts/bundleAnalysis"); + lernaOutput.forEach((pkg: {name: string, location: string}) => { + if (pkg.location === undefined) { + console.error("missing location in lerna package entry"); + process.exit(-1); + } + + const packageAnalysisPath = path.join(pkg.location, "bundleAnalysis"); + if (fse.existsSync(packageAnalysisPath)) { + try { + console.log(`found bundleAnalysis for ${pkg.name}`); + fse.copySync(packageAnalysisPath, path.join(analysesDestPath, pkg.name), {recursive: true}); + } catch (e) { + console.error(e.toString()); + process.exit(-1); + } + } + }); +} + +main();