Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit dcb5df3
Merge: 356a32c 6739271
Author: Will Temple <witemple@microsoft.com>
Date:   Fri Jan 28 17:22:23 2022 -0500

    Merge remote-tracking branch 'upstream/main' into witemple-msft/rollup2

commit 356a32c
Merge: 6527b28 b88c0ba
Author: Will Temple <witemple@microsoft.com>
Date:   Fri Jan 28 16:51:32 2022 -0500

    Merge remote-tracking branch 'upstream/main' into witemple-msft/rollup2

commit 6527b28
Merge: db7197b 55ad309
Author: Will Temple <witemple@microsoft.com>
Date:   Fri Jan 28 16:13:56 2022 -0500

    Merge remote-tracking branch 'upstream/main' into witemple-msft/rollup2

commit db7197b
Author: Will Temple <witemple@microsoft.com>
Date:   Fri Jan 28 11:03:50 2022 -0500

    Enable communication-phone-numbers browser tests

commit 9336dc1
Merge: 097c9d2 7ea04a8
Author: Will Temple <witemple@microsoft.com>
Date:   Thu Jan 27 16:17:54 2022 -0500

    Merge branch 'witemple-msft/rollup2' of github.com:Azure/azure-sdk-for-js into witemple-msft/rollup2

commit 097c9d2
Merge: a022f51 9ef90e4
Author: Will Temple <witemple@microsoft.com>
Date:   Thu Jan 27 16:17:29 2022 -0500

    Merge remote-tracking branch 'upstream/main' into witemple-msft/rollup2

commit 7ea04a8
Author: Will Temple <witemple@microsoft.com>
Date:   Wed Jan 26 17:00:14 2022 -0500

    Update common/tools/dev-tool/src/config/rollup.base.config.ts

    Co-authored-by: Harsha Nalluru <sanallur@microsoft.com>

commit a022f51
Merge: 64599af c702456
Author: Will Temple <witemple@microsoft.com>
Date:   Wed Jan 26 16:42:10 2022 -0500

    Merge remote-tracking branch 'upstream/main' into witemple-msft/rollup2

commit 64599af
Merge: bdd4bca 0c4d2af
Author: Will Temple <witemple@microsoft.com>
Date:   Tue Jan 25 17:29:58 2022 -0500

    Merge remote-tracking branch 'upstream/main' into witemple-msft/rollup2

commit bdd4bca
Merge: e834674 97b77df
Author: Will Temple <witemple@microsoft.com>
Date:   Tue Jan 25 11:26:58 2022 -0800

    Merge remote-tracking branch 'upstream/main' into witemple-msft/rollup2

commit e834674
Author: Will Temple <witemple@microsoft.com>
Date:   Tue Jan 25 11:19:29 2022 -0800

    fixed schema-registry-avro

commit 26425ec
Author: Will Temple <witemple@microsoft.com>
Date:   Mon Jan 24 12:53:58 2022 -0800

    Remove util dependency from monitor-query

commit 50beb01
Author: Will Temple <witemple@microsoft.com>
Date:   Mon Jan 24 14:36:30 2022 -0500

    Removed dangling 'util' dependency

commit d28baf0
Author: Will Temple <witemple@microsoft.com>
Date:   Mon Jan 24 12:38:56 2022 -0500

    Make warning inhibitors work on Windows

commit 5c4c828
Author: Will Temple <witemple@microsoft.com>
Date:   Mon Jan 24 08:31:07 2022 -0800

    Fixed recorder build:test

commit 81a9d6d
Merge: cc7f212 2144ad4
Author: Will Temple <witemple@microsoft.com>
Date:   Fri Jan 21 15:16:24 2022 -0800

    Merge remote-tracking branch 'upstream/main' into witemple-msft/rollup2

commit cc7f212
Author: Will Temple <witemple@microsoft.com>
Date:   Fri Jan 21 15:16:08 2022 -0800

    iot-device-update-rest: migrated

commit 88212d2
Author: Will Temple <witemple@microsoft.com>
Date:   Fri Jan 21 14:13:51 2022 -0800

    keyvault-keys: disable node polyfill

commit 3c1302b
Author: Will Temple <witemple@microsoft.com>
Date:   Fri Jan 21 14:10:17 2022 -0800

    keyvault-admin: disabled browser node polyfill

commit 818cf06
Author: Will Temple <witemple@microsoft.com>
Date:   Fri Jan 21 13:35:29 2022 -0800

    Add basePath configuration to shared script config, inhibit empty warnings from node-resolve

commit 8d18789
Author: Will Temple <witemple@microsoft.com>
Date:   Fri Jan 21 12:15:58 2022 -0800

    Removed errant rollup.config.js entries

commit d4833d4
Author: Will Temple <witemple@microsoft.com>
Date:   Fri Jan 21 11:47:45 2022 -0800

    Remove my launch config

commit e63d4e5
Merge: 37cb4bc d9fe264
Author: Will Temple <witemple@microsoft.com>
Date:   Fri Jan 21 11:45:31 2022 -0800

    Merge remote-tracking branch 'upstream/main' into witemple-msft/rollup2

commit 37cb4bc
Author: Will Temple <witemple@microsoft.com>
Date:   Fri Jan 21 11:44:20 2022 -0800

    Added shim plugin for source maps

commit 98579cc
Merge: 9132065 e3db6c4
Author: Will Temple <witemple@microsoft.com>
Date:   Thu Jan 20 09:44:42 2022 -0800

    Merge remote-tracking branch 'upstream/main' into witemple-msft/rollup2

commit 9132065
Author: Will Temple <witemple@microsoft.com>
Date:   Fri Jan 14 14:39:32 2022 -0500

    Changed weird regex to path.split.join

commit 9c20ebb
Author: Will Temple <witemple@microsoft.com>
Date:   Thu Jan 13 17:25:21 2022 -0500

    Removed communication-chat browser test config, as it's not needed

commit 2a8364d
Author: Will Temple <witemple@microsoft.com>
Date:   Thu Jan 13 17:06:02 2022 -0500

    Deleted rollup.config.js for packages on the shared script.

commit 3fc9575
Author: Will Temple <witemple@microsoft.com>
Date:   Thu Jan 13 17:01:31 2022 -0500

    template: removed rollup

commit 85d7050
Author: Will Temple <witemple@microsoft.com>
Date:   Thu Jan 13 16:54:55 2022 -0500

    synapse: silence rollup output

commit ae9f7a6
Author: Will Temple <witemple@microsoft.com>
Date:   Thu Jan 13 16:30:53 2022 -0500

    Some updates to the bundle command

commit 11cee51
Author: Will Temple <witemple@microsoft.com>
Date:   Thu Jan 13 16:30:33 2022 -0500

    Migrate more packages to shared rollup script

commit 0c4d89c
Merge: f1ccb03 78f849d
Author: Will Temple <witemple@microsoft.com>
Date:   Thu Jan 13 13:00:13 2022 -0500

    Merge remote-tracking branch 'upstream/main' into dev-tool/rollup2

commit f1ccb03
Author: Will Temple <witemple@microsoft.com>
Date:   Thu Jan 13 12:11:27 2022 -0500

    [dev-tool] Add rollup-plugin-polyfill-node

commit 1a8ec9b
Author: Will Temple <witemple@microsoft.com>
Date:   Wed Jan 12 19:07:43 2022 -0500

    preferBuiltins: false for browser

commit fe81f4c
Author: Will Temple <witemple@microsoft.com>
Date:   Wed Jan 12 18:20:38 2022 -0500

    arm-compute: fix new warning

commit a75eca0
Author: Will Temple <witemple@microsoft.com>
Date:   Wed Jan 12 16:20:54 2022 -0500

    Fixed build error in dev-tool

commit d890a89
Author: Will Temple <witemple@microsoft.com>
Date:   Wed Jan 12 16:18:36 2022 -0500

    Resoved merge conflict

commit a64fa41
Author: Will Temple <witemple@microsoft.com>
Date:   Wed Jan 12 16:12:16 2022 -0500

    Remove mixed rollup commands, leaving only rollup.test.config.js

commit f159571
Author: Will Temple <witemple@microsoft.com>
Date:   Wed Jan 12 14:43:55 2022 -0500

    Remove all rollup dependencies

commit 6517014
Author: Will Temple <witemple@microsoft.com>
Date:   Wed Jan 12 14:11:28 2022 -0500

    Remove ordinary rollup commands.

commit f43cc70
Author: Will Temple <witemple@microsoft.com>
Date:   Wed Jan 12 12:48:19 2022 -0500

    Removed configs that opt-out of browser bundles

commit 24357be
Merge: 86250f0 20df85c
Author: Will Temple <witemple@microsoft.com>
Date:   Wed Jan 12 12:31:49 2022 -0500

    Merge remote-tracking branch 'upstream/main' into dev-tool/rollup2

commit 86250f0
Merge: 26c241e 8dcc094
Author: Will Temple <witemple@microsoft.com>
Date:   Wed Jan 12 12:27:43 2022 -0500

    Merge remote-tracking branch 'upstream/main' into dev-tool/rollup2

commit 26c241e
Merge: a0a98ee 12b1941
Author: Will Temple <witemple@microsoft.com>
Date:   Tue Dec 14 18:37:30 2021 -0500

    Merge remote-tracking branch 'upstream/main' into dev-tool/rollup2

commit a0a98ee
Author: Will Temple <witemple@microsoft.com>
Date:   Tue Dec 14 17:39:12 2021 -0500

    Make consistent

commit c8f6ffe
Author: Will Temple <witemple@microsoft.com>
Date:   Tue Dec 14 17:29:05 2021 -0500

    Migrate template

commit d56bcc5
Author: Will Temple <witemple@microsoft.com>
Date:   Wed Dec 8 11:46:16 2021 -0500

    [dev-tool] Add "bundle" command
  • Loading branch information
witemple-msft committed Jan 28, 2022
1 parent 6739271 commit 212f4f4
Show file tree
Hide file tree
Showing 239 changed files with 1,472 additions and 1,770 deletions.
1,324 changes: 784 additions & 540 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions common/tools/dev-tool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
"yaml": "~1.10.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "11.0.2",
"@rollup/plugin-json": "^4.0.0",
"@rollup/plugin-multi-entry": "^3.0.0",
"@rollup/plugin-node-resolve": "^8.0.0",
"@rollup/plugin-commonjs": "21.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-multi-entry": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.6",
"@types/concurrently": "^6.3.0",
"@types/chai": "^4.1.6",
"@types/chai-as-promised": "^7.1.0",
Expand All @@ -70,8 +70,9 @@
"eslint": "^7.15.0",
"mocha": "^7.1.1",
"rimraf": "^3.0.0",
"rollup": "^1.16.3",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-visualizer": "^4.0.4"
"rollup": "^2.60.2",
"rollup-plugin-polyfill-node": "^0.8.0",
"rollup-plugin-sourcemaps": "^0.6.2",
"rollup-plugin-visualizer": "^5.5.2"
}
}
147 changes: 147 additions & 0 deletions common/tools/dev-tool/src/commands/run/bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import path from "path";

import * as rollup from "rollup";
import nodeBuiltins from "builtin-modules";

import nodeResolve from "@rollup/plugin-node-resolve";
import cjs from "@rollup/plugin-commonjs";
import sourcemaps from "rollup-plugin-sourcemaps";
import nodePolyfills from "rollup-plugin-polyfill-node";
import json from "@rollup/plugin-json";
import multiEntry from "@rollup/plugin-multi-entry";

import { leafCommand, makeCommandInfo } from "../../framework/command";
import { resolveProject, resolveRoot } from "../../util/resolveProject";
import { createPrinter } from "../../util/printer";
import { makeOnWarnForTesting, sourcemapsExtra } from "../../config/rollup.base.config";

const log = createPrinter("bundle");

export const commandInfo = makeCommandInfo(
"bundle",
"bundle a package using the default settings",
{
production: {
kind: "boolean",
default: true,
description: "build a CommonJS production bundle",
},
"browser-test": {
kind: "boolean",
default: true,
description: "build a bundle for browser testing",
},
"polyfill-node": {
kind: "boolean",
default: true,
description: "include a polyfill for Node.js builtin modules",
},
}
);

export default leafCommand(commandInfo, async (options) => {
const info = await resolveProject(process.cwd());

if (!info.packageJson.module) {
log.error(info.name, "does not specify a `module` field.");
return false;
}

const basePath = path
.relative(process.cwd(), path.dirname(path.parse(info.packageJson.module).dir))
.split(path.sep)
.join("/");

if (options.production) {
const baseConfig: rollup.RollupOptions = {
// Use the package's module field if it has one
input: info.packageJson.module,
external: [
...nodeBuiltins,
...Object.keys(info.packageJson.dependencies),
...Object.keys(info.packageJson.devDependencies),
],
preserveSymlinks: false,
plugins: [nodeResolve(), sourcemaps()],
};

try {
const bundle = await rollup.rollup(baseConfig);

await bundle.write({
file: "dist/index.js",
format: "cjs",
sourcemap: true,
exports: "named",
});
} catch (error) {
log.error(error);
return false;
}

log.success("Created production CommonJS bundle.");
}

if (options["browser-test"]) {
const pnpmStore = path
.relative(
process.cwd(),
path.join(await resolveRoot(), "common", "temp", "node_modules", ".pnpm")
)
.split(path.sep)
.join("/");

log.debug("Computed PNPM store relative path:", pnpmStore);

// Get a glob for a package name in the PNPM store
const globFromStore = (name: string): string =>
[pnpmStore, name.split("/").join("+"), "@*", "**/*.js"].join("/");

const browserTestConfig = {
input: {
include: [[basePath, "test", "**", "*.spec.js"].join("/")],
exclude: [[basePath, "test", "**", "node", "**"].join("/")],
},
preserveSymlinks: false,
plugins: [
multiEntry({ exports: false }),
nodeResolve({
mainFields: ["module", "browser"],
preferBuiltins: false,
}),
...(options["polyfill-node"] ? [nodePolyfills({ sourceMap: true })] : []),
cjs({
dynamicRequireTargets: [globFromStore("chai")],
}),
json(),
sourcemapsExtra(),
],
onwarn: makeOnWarnForTesting(),
// Disable tree-shaking of test code. In rollup-plugin-node-resolve@5.0.0,
// rollup started respecting the "sideEffects" field in package.json. Since
// our package.json sets "sideEffects=false", this also applies to test
// code, which causes all tests to be removed by tree-shaking.
treeshake: false,
};

try {
const browserBundle = await rollup.rollup(browserTestConfig as any);

await browserBundle.write({
file: `dist-test/index.browser.js`,
format: "umd",
sourcemap: true,
});
} catch (error) {
log.error(error);
return false;
}

log.success("Created browser testing bundle.");
}

return true;
});
1 change: 1 addition & 0 deletions common/tools/dev-tool/src/commands/run/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export default subCommand(commandInfo, {
"test:node-ts-input": () => import("./testNodeTSInput"),
"test:node-js-input": () => import("./testNodeJSInput"),
"test:browser": () => import("./testBrowser"),
bundle: () => import("./bundle")
});
2 changes: 1 addition & 1 deletion common/tools/dev-tool/src/commands/run/testBrowser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license
// Licensed under the MIT license.

import { leafCommand, makeCommandInfo } from "../../framework/command";
import { runTestsWithProxyTool } from "../../util/testUtils";
Expand Down
116 changes: 91 additions & 25 deletions common/tools/dev-tool/src/config/rollup.base.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { RollupWarning, WarningHandler } from "rollup";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PluginContext, RollupWarning, WarningHandler } from "rollup";

import nodeResolve from "@rollup/plugin-node-resolve";
import cjs from "@rollup/plugin-commonjs";
Expand All @@ -8,6 +11,9 @@ import json from "@rollup/plugin-json";
import * as path from "path";

import nodeBuiltins from "builtin-modules";
import { createPrinter } from "../util/printer";

const { debug } = createPrinter("rollup.base.config");

interface PackageJson {
name: string;
Expand All @@ -16,49 +22,115 @@ interface PackageJson {
devDependencies: Record<string, string>;
}

/**
* The default sourcemaps plugin does not provide very much information in warnings, so this shim allows us to capture
* the active sourcemaps loading context.
*
* This allows us to selectively disable warnings about missing source maps, for example in core-asynciterator-polyfill.
*/
export function sourcemapsExtra() {
const _sourcemaps = sourcemaps();

const load = _sourcemaps.load;

if (!load) return _sourcemaps;

return Object.assign(_sourcemaps, {
load(this: PluginContext, id: string) {
const shim = new Proxy(this, {
get(context, p, ...rest) {
if (p === "warn") {
const warn = context.warn;
return (warning: unknown) => {
const warningObject = (
typeof warning === "string" ? { message: warning } : warning
) as RollupWarning;

warningObject.id = id;

warn(warningObject);
};
}
return Reflect.get(context, p, ...rest);
},
});

return load.call(shim, id);
},
});
}

// #region Warning Handler

/**
* A function that can determine whether a rollupwarning should be ignored. If
* A function that can determine whether a rollup warning should be ignored. If
* the function returns `true`, then the warning will not be displayed.
*/
export type WarningInhibitor = (warning: RollupWarning) => boolean;

function ignoreNiseSinonEvalWarnings(warning: RollupWarning): boolean {
function ignoreNiseSinonEval(warning: RollupWarning): boolean {
return (
warning.code === "EVAL" &&
(warning.id?.includes("node_modules/nise") || warning.id?.includes("node_modules/sinon")) ===
true
(warning.id?.includes(["node_modules", "nise"].join(path.sep)) ||
warning.id?.includes(["node_modules", "sinon"].join(path.sep))) === true
);
}

function ignoreChaiCircularDependencyWarnings(warning: RollupWarning): boolean {
function ignoreChaiCircularDependency(warning: RollupWarning): boolean {
return (
warning.code === "CIRCULAR_DEPENDENCY" &&
warning.importer?.includes("node_modules/chai") === true
warning.importer?.includes(["node_modules", "chai"].join(path.sep)) === true
);
}

function ignoreOpenTelemetryThisIsUndefinedWarnings(warning: RollupWarning): boolean {
function ignoreOpenTelemetryThisIsUndefined(warning: RollupWarning): boolean {
return (
warning.code === "THIS_IS_UNDEFINED" && warning.id?.includes("@opentelemetry/api") === true
warning.code === "THIS_IS_UNDEFINED" &&
warning.id?.includes(["node_modules", "@opentelemetry", "api"].join(path.sep)) === true
);
}

/**
* v1.0.0 of @azure/core-asynciterator-polyfill does not provide a source map.
*
* This was a bug, and this function works around that bug.
*/
function ignoreAsyncIteratorPolyfillSourceMaps(warning: RollupWarning): boolean {
return (
warning.code === "PLUGIN_WARNING" &&
warning.plugin === "sourcemaps" &&
warning.id?.includes("@azure+core-asynciterator-polyfill@1.0.0") === true
);
}

/**
* We ignore these warnings because some packages explicitly browser-map node builtins to `false`. Rollup will then
* complain that node-resolve's empty module does not export symbols from them, but as long as the package doesn't
* actually use those symbols at runtime in the browser tests, it should be fine.
*/
function ignoreMissingExportsFromEmpty(warning: RollupWarning): boolean {
return (
// I absolutely cannot explain why, but node-resolve's internal module ID for empty.js begins with a null byte.
warning.code === "MISSING_EXPORT" && warning.exporter?.trim() === "\0node-resolve:empty.js"
);
}

const warningInhibitors: Array<(warning: RollupWarning) => boolean> = [
ignoreChaiCircularDependencyWarnings,
ignoreNiseSinonEvalWarnings,
ignoreOpenTelemetryThisIsUndefinedWarnings,
ignoreChaiCircularDependency,
ignoreNiseSinonEval,
ignoreOpenTelemetryThisIsUndefined,
ignoreAsyncIteratorPolyfillSourceMaps,
ignoreMissingExportsFromEmpty,
];

/**
* Construct a warning handler for the shared rollup configuration
* that ignores certain warnings that are not relevant to testing.
*/
function makeOnWarnForTesting(): (warning: RollupWarning, warn: WarningHandler) => void {
export function makeOnWarnForTesting(): (warning: RollupWarning, warn: WarningHandler) => void {
return (warning, warn) => {
// If every inhibitor returns false (i.e. no inhibitors), then show the warning
if (warningInhibitors.every((inhib) => !inhib(warning))) {
if (!warningInhibitors.some((inhibited) => inhibited(warning))) {
debug("Warning:", warning.code, warning.id, warning.loc);
warn(warning);
}
};
Expand Down Expand Up @@ -87,17 +159,11 @@ export function makeBrowserTestConfig(pkg: PackageJson): RollupOptions {
multiEntry({ exports: false }),
nodeResolve({
mainFields: ["module", "browser"],
preferBuiltins: false,
}),
cjs({
namedExports: {
// Chai's strange internal architecture makes it impossible to statically
// analyze its exports.
chai: ["version", "use", "util", "config", "expect", "should", "assert"],
events: ["EventEmitter"],
},
}),
cjs(),
json(),
sourcemaps(),
sourcemapsExtra(),
//viz({ filename: "dist-test/browser-stats.html", sourcemap: true })
],
onwarn: makeOnWarnForTesting(),
Expand Down Expand Up @@ -138,7 +204,7 @@ export function makeConfig(
],
output: { file: "dist/index.js", format: "cjs", sourcemap: true },
preserveSymlinks: false,
plugins: [sourcemaps(), nodeResolve(), cjs()],
plugins: [sourcemaps(), nodeResolve(), cjs(), json()],
};

const config: RollupOptions[] = [baseConfig as RollupOptions];
Expand Down
2 changes: 2 additions & 0 deletions common/tools/dev-tool/src/util/resolveProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ declare global {
name: string;
version: string;
description: string;
main: string;
module?: string;
bin?: Record<string, string>;
files: string[];
scripts: Record<string, string>;
Expand Down
2 changes: 2 additions & 0 deletions common/tools/dev-tool/test/samples/files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ describe("File content tests", async function () {
version,
packageJson: {
...ownPackageJson,
// Required by the PackageJson definition type, but not required for this test
main: "",
version,
keywords: [name],
"//sampleConfiguration": {
Expand Down
Loading

0 comments on commit 212f4f4

Please sign in to comment.