From 3c97db3a18bc40905667e829ab03f45a89b0778e Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Thu, 9 Dec 2021 11:00:32 -0800 Subject: [PATCH] [rollup] - Fix bug in circular dependency warning suppression (#19012) ## What - Fix incorrect logic when suppressing chai's circular dependency warnings - Move to the common dev-tool configuration where possible ## Why This is a longstanding issue that we have, where an incorrect logic was copy-pasted to other places. I figured while cleaning this up that any package I touch can just convert over to the shared dev-tool configuration. Where I was unable to do that, I just fixed this bug to avoid too many changes in one PR. Fixes #14292 Resolves #17818 Resolves #17816 Resolves #17815 Resolves #17814 Resolves #17813 Resolves #17810 --- common/config/rush/pnpm-lock.yaml | 19 +- .../dev-tool/src/config/rollup.base.config.ts | 2 +- .../ai-anomaly-detector/package.json | 15 +- .../ai-anomaly-detector/rollup.base.config.js | 137 -------------- .../ai-anomaly-detector/rollup.config.js | 14 +- .../ai-anomaly-detector/rollup.test.config.js | 3 - .../test/utils/recordedClients.ts | 3 - .../app-configuration/rollup.base.config.js | 5 +- .../test/public/utils/testHelpers.ts | 5 - .../communication-chat/rollup.base.config.js | 2 +- .../rollup.base.config.js | 2 +- .../rollup.base.config.js | 2 +- .../rollup.base.config.js | 2 +- .../rollup.base.config.js | 2 +- .../rollup.base.config.js | 2 +- .../communication-sms/rollup.base.config.js | 2 +- .../digital-twins-core/package.json | 19 +- .../digital-twins-core/rollup.base.config.js | 155 --------------- .../digital-twins-core/rollup.config.js | 14 +- .../digital-twins-core/rollup.test.config.js | 13 -- sdk/eventgrid/eventgrid/package.json | 4 +- sdk/eventgrid/eventgrid/rollup.base.config.js | 134 ------------- sdk/eventgrid/eventgrid/rollup.config.js | 15 +- sdk/eventgrid/eventgrid/rollup.test.config.js | 3 - .../test/public/utils/recordedClient.ts | 6 - sdk/eventhub/event-hubs/package.json | 6 +- sdk/eventhub/event-hubs/rollup.base.config.js | 164 ---------------- sdk/eventhub/event-hubs/rollup.config.js | 17 +- sdk/eventhub/event-hubs/rollup.test.config.js | 16 -- .../event-processor-host/package.json | 8 +- .../rollup.base.config.js | 119 ------------ .../event-processor-host/rollup.config.js | 18 +- .../rollup.test.config.js | 6 - .../package.json | 14 +- .../rollup.base.config.js | 167 ---------------- .../rollup.config.js | 17 +- .../rollup.test.config.js | 16 -- .../package.json | 14 +- .../rollup.base.config.js | 167 ---------------- .../rollup.config.js | 17 +- .../rollup.test.config.js | 16 -- sdk/quantum/quantum-jobs/package.json | 17 +- .../quantum-jobs/rollup.base.config.js | 144 -------------- sdk/quantum/quantum-jobs/rollup.config.js | 18 +- .../quantum-jobs/rollup.test.config.js | 18 -- sdk/search/search-documents/package.json | 13 +- .../search-documents/rollup.base.config.js | 138 -------------- sdk/search/search-documents/rollup.config.js | 14 +- .../search-documents/rollup.test.config.js | 3 - sdk/servicebus/service-bus/package.json | 15 +- .../service-bus/rollup.base.config.js | 179 ------------------ sdk/servicebus/service-bus/rollup.config.js | 17 +- .../service-bus/rollup.test.config.js | 16 -- 53 files changed, 66 insertions(+), 1888 deletions(-) delete mode 100644 sdk/anomalydetector/ai-anomaly-detector/rollup.base.config.js delete mode 100644 sdk/anomalydetector/ai-anomaly-detector/rollup.test.config.js delete mode 100644 sdk/digitaltwins/digital-twins-core/rollup.base.config.js delete mode 100644 sdk/digitaltwins/digital-twins-core/rollup.test.config.js delete mode 100644 sdk/eventgrid/eventgrid/rollup.base.config.js delete mode 100644 sdk/eventgrid/eventgrid/rollup.test.config.js delete mode 100644 sdk/eventhub/event-hubs/rollup.base.config.js delete mode 100644 sdk/eventhub/event-hubs/rollup.test.config.js delete mode 100644 sdk/eventhub/event-processor-host/rollup.base.config.js delete mode 100644 sdk/eventhub/event-processor-host/rollup.test.config.js delete mode 100644 sdk/eventhub/eventhubs-checkpointstore-blob/rollup.base.config.js delete mode 100644 sdk/eventhub/eventhubs-checkpointstore-blob/rollup.test.config.js delete mode 100644 sdk/eventhub/eventhubs-checkpointstore-table/rollup.base.config.js delete mode 100644 sdk/eventhub/eventhubs-checkpointstore-table/rollup.test.config.js delete mode 100644 sdk/quantum/quantum-jobs/rollup.base.config.js delete mode 100644 sdk/quantum/quantum-jobs/rollup.test.config.js delete mode 100644 sdk/search/search-documents/rollup.base.config.js delete mode 100644 sdk/search/search-documents/rollup.test.config.js delete mode 100644 sdk/servicebus/service-bus/rollup.base.config.js delete mode 100644 sdk/servicebus/service-bus/rollup.test.config.js diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 0a554e9578c8..e14b70992fb8 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -1661,6 +1661,7 @@ packages: /@opentelemetry/node/0.22.0_@opentelemetry+api@1.0.3: resolution: {integrity: sha512-+HhGbDruQ7cwejVOIYyxRa28uosnG8W95NiQZ6qE8PXXPsDSyGeftAPbtYpGit0H2f5hrVcMlwmWHeAo9xkSLA==} engines: {node: '>=8.0.0'} + deprecated: Package renamed to @opentelemetry/sdk-trace-node peerDependencies: '@opentelemetry/api': ^1.0.0 dependencies: @@ -8399,7 +8400,7 @@ packages: dev: false file:projects/ai-anomaly-detector.tgz: - resolution: {integrity: sha512-k60gU9MY6seTzTWHkWIZ2sH7xdTTfZMz99y00dJRNs11gu/sfqyn1MgCh3xMSvCB9FkTazsLd6oPGklpNDMpnw==, tarball: file:projects/ai-anomaly-detector.tgz} + resolution: {integrity: sha512-8zK6kKlIk/JYDC8Cpl7YKLvef5nOSfhL91pk8kEZ4xw1/BbeU+ZIVHlzB4ciIIstJMrqWTRnRCQiajmOccNupQ==, tarball: file:projects/ai-anomaly-detector.tgz} name: '@rush-temp/ai-anomaly-detector' version: 0.0.0 dependencies: @@ -8647,7 +8648,7 @@ packages: dev: false file:projects/app-configuration.tgz: - resolution: {integrity: sha512-h9nLQwnEqw1OjRBrG2YmgFUD/wOCQe+fC+/45l/Kpeh2QBkLKXeJslgi5fme0YsUC0wmSsZqYaQZtn9mOCLjlw==, tarball: file:projects/app-configuration.tgz} + resolution: {integrity: sha512-HBZl2EancfACeRLK2hWk+nCAgXrptXnS9hX5E5SLleYzlPHovsJRBWf3bv0NopaHCgFPdRcAw5xwKa1C2tPz2g==, tarball: file:projects/app-configuration.tgz} name: '@rush-temp/app-configuration' version: 0.0.0 dependencies: @@ -11274,7 +11275,7 @@ packages: dev: false file:projects/digital-twins-core.tgz: - resolution: {integrity: sha512-JbiaAZTKbpTEXkwM3tXpIGF37Byi68uXKyabs92a93o5jbFaJEnlENvQjQ+xpAQR7kg/Yy1Bt/wOfEj8JopBWQ==, tarball: file:projects/digital-twins-core.tgz} + resolution: {integrity: sha512-LUm22jksNdxH1YVaRs5AGV46xuZ0dlNe2Ghuhfj2UkFrdimYbbqVBqceRsOmygzQncWwotAEqwW0t+agqr/knA==, tarball: file:projects/digital-twins-core.tgz} name: '@rush-temp/digital-twins-core' version: 0.0.0 dependencies: @@ -11447,7 +11448,7 @@ packages: dev: false file:projects/event-processor-host.tgz: - resolution: {integrity: sha512-1bsUaKknmTfFOC0w6wjYVciwePXLbmv5WQ8+YE0WLn04UW7kZala/RhlIolUx1TlS35vDKb73NHLz87KGe3g9w==, tarball: file:projects/event-processor-host.tgz} + resolution: {integrity: sha512-laogoDpT1udxqofK9IBRPOpvYQ/NBJcIVc9V6gPx1LB8pvbCZEkSTm0kLy1QDeI7iEyqRke4OXFcfNF/kSxing==, tarball: file:projects/event-processor-host.tgz} name: '@rush-temp/event-processor-host' version: 0.0.0 dependencies: @@ -11565,7 +11566,7 @@ packages: dev: false file:projects/eventhubs-checkpointstore-blob.tgz: - resolution: {integrity: sha512-Xy7VJKNs9xSRvm8bpeiwnhIxeqFC38msj+rzdOPsbGOTKAHShf9GWzkt6icvkNWjTUarp0vjQIb90qIhnx6InA==, tarball: file:projects/eventhubs-checkpointstore-blob.tgz} + resolution: {integrity: sha512-0eUlLaPKDNrmy9rO+dhIqEs2nyap9EUEhreSguDGf6XHnRXv6khUYxE6HhOPgkqEVw0RdT2KEDnRyNd4Ln3D6Q==, tarball: file:projects/eventhubs-checkpointstore-blob.tgz} name: '@rush-temp/eventhubs-checkpointstore-blob' version: 0.0.0 dependencies: @@ -11631,7 +11632,7 @@ packages: dev: false file:projects/eventhubs-checkpointstore-table.tgz: - resolution: {integrity: sha512-XqPBz9OE+MtEICebS8nkcYVz8VaLgcjCrYoOvt/O5lkiuzsIJ5epCvwGG9Q0kk5HiOEjVvH63dlLzqrwH1VB9g==, tarball: file:projects/eventhubs-checkpointstore-table.tgz} + resolution: {integrity: sha512-7TfDPvP47kYCnypCRVDath61kPdiTKykx5ZVgFRPBfTOCYQpNeoPVFVMDmCcaa3OB4VOQaogGwsz8L18CzOimg==, tarball: file:projects/eventhubs-checkpointstore-table.tgz} name: '@rush-temp/eventhubs-checkpointstore-table' version: 0.0.0 dependencies: @@ -13001,7 +13002,7 @@ packages: dev: false file:projects/quantum-jobs.tgz: - resolution: {integrity: sha512-36C2mZUJMdHi31RmxsAYWIPKGx9Qbjx0/jm36UatiDvJIZOvT5D/W+Un3kfIiNIoL910MFW5TyKkipEmvUdMsw==, tarball: file:projects/quantum-jobs.tgz} + resolution: {integrity: sha512-RLW7PtmPkoOi+WDgc6OfeIcp8y+pCJLKAG+DOM6LR9sy37u3IR1O0cD1LgkD+MHjnmW3pZpEiSRYZjZ1K500CA==, tarball: file:projects/quantum-jobs.tgz} name: '@rush-temp/quantum-jobs' version: 0.0.0 dependencies: @@ -13157,7 +13158,7 @@ packages: dev: false file:projects/search-documents.tgz: - resolution: {integrity: sha512-1vVVrXpDsNF6D0jfxy6e4EIJz1anhCYtCki2uiP6bMX171TGLMFWCNpKk0Xxw2FMeJqAIVt4/UcoOpOy0dby1w==, tarball: file:projects/search-documents.tgz} + resolution: {integrity: sha512-mwmuvS/Y1AJF2VZiBBiUymuDe52iBz4Kwm9DrfRVFGSyRgyKuMaymSuo5Q6Q/FnSRFDnYLRMTFcetQGXAr1JFQ==, tarball: file:projects/search-documents.tgz} name: '@rush-temp/search-documents' version: 0.0.0 dependencies: @@ -13217,7 +13218,7 @@ packages: dev: false file:projects/service-bus.tgz: - resolution: {integrity: sha512-k0NCGj25Mmp4w98MNi3B+2+sdwYOd0oWiWYLsUcH8YstzS/PuSlbZ6A67IGJeJptdzCQhUZkRctfEXKGrn34hQ==, tarball: file:projects/service-bus.tgz} + resolution: {integrity: sha512-ytqGlI90K4bkj/C9qGW6iS3O+ePWtrKA7esCS6Q+Gkn1tcNGwPUitzwX3Jd7bmTih0DaEr3ByUk1ahZ2G4+8kQ==, tarball: file:projects/service-bus.tgz} name: '@rush-temp/service-bus' version: 0.0.0 dependencies: diff --git a/common/tools/dev-tool/src/config/rollup.base.config.ts b/common/tools/dev-tool/src/config/rollup.base.config.ts index 819e92ff75d7..77095eaea117 100644 --- a/common/tools/dev-tool/src/config/rollup.base.config.ts +++ b/common/tools/dev-tool/src/config/rollup.base.config.ts @@ -125,7 +125,7 @@ export function makeBrowserTestConfig(): RollupOptions { // Chai's strange internal architecture makes it impossible to statically // analyze its exports. chai: ["version", "use", "util", "config", "expect", "should", "assert"], - ...openTelemetryCommonJs() + events: ["EventEmitter"] } }), json(), diff --git a/sdk/anomalydetector/ai-anomaly-detector/package.json b/sdk/anomalydetector/ai-anomaly-detector/package.json index e08e8f1f4508..0d8ee5a33897 100644 --- a/sdk/anomalydetector/ai-anomaly-detector/package.json +++ b/sdk/anomalydetector/ai-anomaly-detector/package.json @@ -14,7 +14,7 @@ "build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", "build:samples": "echo Obsolete.", - "build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1", + "build:test": "tsc -p . && rollup -c 2>&1", "build": "npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local", "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "clean": "rimraf dist dist-* temp types *.tgz *.log", @@ -22,7 +22,7 @@ "extract-api": "tsc -p . && api-extractor run --local", "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "integration-test:browser": "karma start --single-run", - "integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 5000000 --full-trace dist-esm/test/**/*.spec.js", + "integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 5000000 --full-trace \"dist-esm/test/{,!(browser)/**/}*.spec.js\"", "integration-test": "npm run integration-test:node && npm run integration-test:browser", "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]", "lint": "eslint package.json api-extractor.json src test --ext .ts", @@ -31,7 +31,7 @@ "test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node", "test": "npm run build:test && npm run unit-test && npm run integration-test", "unit-test:browser": "karma start --single-run", - "unit-test:node": "mocha --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace dist-test/index.node.js", + "unit-test:node": "mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"", "unit-test": "npm run unit-test:node && npm run unit-test:browser", "docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src" }, @@ -73,11 +73,6 @@ "@azure/identity": "^2.0.1", "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@microsoft/api-extractor": "^7.18.11", - "@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-replace": "^2.2.0", "@types/chai": "^4.1.6", "@types/mocha": "^7.0.2", "@types/node": "^12.0.0", @@ -104,10 +99,6 @@ "prettier": "^1.16.4", "rimraf": "^3.0.0", "rollup": "^1.16.3", - "rollup-plugin-shim": "^1.0.0", - "rollup-plugin-sourcemaps": "^0.4.2", - "rollup-plugin-terser": "^5.1.1", - "rollup-plugin-visualizer": "^4.0.4", "typescript": "~4.2.0", "util": "^0.12.1", "@azure-tools/test-recorder": "^1.0.0", diff --git a/sdk/anomalydetector/ai-anomaly-detector/rollup.base.config.js b/sdk/anomalydetector/ai-anomaly-detector/rollup.base.config.js deleted file mode 100644 index 2a2015a0ee5c..000000000000 --- a/sdk/anomalydetector/ai-anomaly-detector/rollup.base.config.js +++ /dev/null @@ -1,137 +0,0 @@ -import path from "path"; -import nodeResolve from "@rollup/plugin-node-resolve"; -import multiEntry from "@rollup/plugin-multi-entry"; -import cjs from "@rollup/plugin-commonjs"; -import json from "@rollup/plugin-json"; -import replace from "@rollup/plugin-replace"; -import { terser } from "rollup-plugin-terser"; -import shim from "rollup-plugin-shim"; -import sourcemaps from "rollup-plugin-sourcemaps"; -import viz from "rollup-plugin-visualizer"; -import { openTelemetryCommonJs } from "@azure/dev-tool/shared-config/rollup"; - -const pkg = require("./package.json"); -const depNames = Object.keys(pkg.dependencies); -const devDepNames = Object.keys(pkg.devDependencies); -const input = "dist-esm/src/index.js"; -const production = process.env.NODE_ENV === "production"; - -export function nodeConfig(test = false) { - const externalNodeBuiltins = []; - const baseConfig = { - input: input, - external: depNames.concat(externalNodeBuiltins), - output: { file: "dist/index.js", format: "cjs", sourcemap: true }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""], - - // replace dynamic checks with if (true) since this is for node only. - // Allows rollup's dead code elimination to be more aggressive. - "if (isNode)": "if (true)" - }), - nodeResolve({ preferBuiltins: true }), - json(), - cjs() - ] - }; - - if (test) { - // Entry points - test files under the `test` folder(common for both browser and node), node specific test files - baseConfig.input = ["dist-esm/test/*.spec.js", "dist-esm/test/node/*.spec.js"]; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - - // different output file - baseConfig.output.file = "dist-test/index.node.js"; - - // mark devdeps as external - baseConfig.external.push(...devDepNames); - - // 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. - baseConfig.treeshake = false; - } else if (production) { - baseConfig.plugins.push(terser()); - } - - return baseConfig; -} - -export function browserConfig(test = false) { - const baseConfig = { - input: input, - external: ["fs-extra", "nock", "path"], - output: { - file: "dist-browser/ai-anomaly-detector.js", - format: "umd", - name: "Azure.CogniteveServicesAnomalyDetector", - sourcemap: true, - globals: { "@azure/core-http": "Azure.Core.HTTP" } - }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""], - - // replace dynamic checks with if (false) since this is for - // browser only. Rollup's dead code elimination will remove - // any code guarded by if (isNode) { ... } - "if (isNode)": "if (false)" - }), - shim({ - fs: `export default {}`, - path: `export function join() {}`, - stream: `export default {}`, - dotenv: `export function config() { }`, - os: ` - export function arch() { return "javascript" } - export function type() { return "Browser" } - export function release() { typeof navigator === 'undefined' ? '' : navigator.appVersion } - `, - constants: `export default {}` - }), - nodeResolve({ - mainFields: ["module", "browser"], - preferBuiltins: false - }), - json(), - cjs({ - namedExports: { - chai: ["assert"], - ...openTelemetryCommonJs() - } - }), - viz({ filename: "dist-browser/browser-stats.html", sourcemap: false }) - ] - }; - - if (test) { - // Entry points - test files under the `test` folder(common for both browser and node), browser specific test files - baseConfig.input = ["dist-esm/test/*.spec.js", "dist-esm/test/browser/*.spec.js"]; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - baseConfig.output.file = "dist-test/index.browser.js"; - - baseConfig.onwarn = (warning) => { - if ( - warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) - ) { - // Chai contains circular references, but they are not fatal and can be ignored. - return; - } - - console.error(`(!) ${warning.message}`); - }; - - // 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. - baseConfig.treeshake = false; - } - - return baseConfig; -} diff --git a/sdk/anomalydetector/ai-anomaly-detector/rollup.config.js b/sdk/anomalydetector/ai-anomaly-detector/rollup.config.js index 14652aa67ed8..5d7deee44c14 100644 --- a/sdk/anomalydetector/ai-anomaly-detector/rollup.config.js +++ b/sdk/anomalydetector/ai-anomaly-detector/rollup.config.js @@ -1,13 +1,3 @@ -import * as base from "./rollup.base.config"; +import { makeConfig } from "@azure/dev-tool/shared-config/rollup"; -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig()); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig()); -} - -export default inputs; +export default makeConfig(require("./package.json")); diff --git a/sdk/anomalydetector/ai-anomaly-detector/rollup.test.config.js b/sdk/anomalydetector/ai-anomaly-detector/rollup.test.config.js deleted file mode 100644 index 925a4421a53e..000000000000 --- a/sdk/anomalydetector/ai-anomaly-detector/rollup.test.config.js +++ /dev/null @@ -1,3 +0,0 @@ -import * as base from "./rollup.base.config"; - -export default [base.nodeConfig(true), base.browserConfig(true)]; diff --git a/sdk/anomalydetector/ai-anomaly-detector/test/utils/recordedClients.ts b/sdk/anomalydetector/ai-anomaly-detector/test/utils/recordedClients.ts index 6bc7d3fcabc0..79eaeaa85460 100644 --- a/sdk/anomalydetector/ai-anomaly-detector/test/utils/recordedClients.ts +++ b/sdk/anomalydetector/ai-anomaly-detector/test/utils/recordedClients.ts @@ -3,15 +3,12 @@ import { Context } from "mocha"; -import * as dotenv from "dotenv"; import { env, Recorder, record, RecorderEnvironmentSetup } from "@azure-tools/test-recorder"; import { ClientSecretCredential } from "@azure/identity"; import { AnomalyDetectorClient } from "../../src/AnomalyDetectorClient"; import { AzureKeyCredential } from "@azure/core-auth"; -dotenv.config(); - export interface RecordedRecognizerClient { client: AnomalyDetectorClient; recorder: Recorder; diff --git a/sdk/appconfiguration/app-configuration/rollup.base.config.js b/sdk/appconfiguration/app-configuration/rollup.base.config.js index 1654b233b2f5..32a5a51c3624 100644 --- a/sdk/appconfiguration/app-configuration/rollup.base.config.js +++ b/sdk/appconfiguration/app-configuration/rollup.base.config.js @@ -34,10 +34,7 @@ const ignoreKnownWarnings = (warning) => { return; } - if ( - warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) - ) { + if (warning.code === "CIRCULAR_DEPENDENCY" && warning.importer.includes("node_modules/chai")) { // Chai contains circular references, but they are not fatal and can be ignored. return; } diff --git a/sdk/appconfiguration/app-configuration/test/public/utils/testHelpers.ts b/sdk/appconfiguration/app-configuration/test/public/utils/testHelpers.ts index c9d2190a4576..f1ece0dcf913 100644 --- a/sdk/appconfiguration/app-configuration/test/public/utils/testHelpers.ts +++ b/sdk/appconfiguration/app-configuration/test/public/utils/testHelpers.ts @@ -17,12 +17,7 @@ import { } from "@azure-tools/test-recorder"; import * as assert from "assert"; -// allow loading from a .env file as an alternative to defining the variable -// in the environment -import * as dotenv from "dotenv"; - import { DefaultAzureCredential, TokenCredential } from "@azure/identity"; -dotenv.config(); let connectionStringNotPresentWarning = false; let tokenCredentialsNotPresentWarning = false; diff --git a/sdk/communication/communication-chat/rollup.base.config.js b/sdk/communication/communication-chat/rollup.base.config.js index ba527d8df5e2..2d792f9caf83 100644 --- a/sdk/communication/communication-chat/rollup.base.config.js +++ b/sdk/communication/communication-chat/rollup.base.config.js @@ -127,7 +127,7 @@ export function browserConfig(test = false) { baseConfig.onwarn = (warning) => { if ( warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) + warning.importer.includes("node_modules/chai") ) { // Chai contains circular references, but they are not fatal and can be ignored. return; diff --git a/sdk/communication/communication-common/rollup.base.config.js b/sdk/communication/communication-common/rollup.base.config.js index f7bfb300f21f..6ee749f1df77 100644 --- a/sdk/communication/communication-common/rollup.base.config.js +++ b/sdk/communication/communication-common/rollup.base.config.js @@ -105,7 +105,7 @@ export function browserConfig(test = false) { baseConfig.onwarn = (warning) => { if ( warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) + warning.importer.includes("node_modules/chai") ) { // Chai contains circular references, but they are not fatal and can be ignored. return; diff --git a/sdk/communication/communication-identity/rollup.base.config.js b/sdk/communication/communication-identity/rollup.base.config.js index ce5bb1b84d9b..02fdab7e850e 100644 --- a/sdk/communication/communication-identity/rollup.base.config.js +++ b/sdk/communication/communication-identity/rollup.base.config.js @@ -116,7 +116,7 @@ export function browserConfig(test = false) { baseConfig.onwarn = (warning) => { if ( warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) + warning.importer.includes("node_modules/chai") ) { // Chai contains circular references, but they are not fatal and can be ignored. return; diff --git a/sdk/communication/communication-network-traversal/rollup.base.config.js b/sdk/communication/communication-network-traversal/rollup.base.config.js index a3cd1cd0d6fe..2eb3551c485d 100644 --- a/sdk/communication/communication-network-traversal/rollup.base.config.js +++ b/sdk/communication/communication-network-traversal/rollup.base.config.js @@ -116,7 +116,7 @@ export function browserConfig(test = false) { baseConfig.onwarn = (warning) => { if ( warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) + warning.importer.includes("node_modules/chai") ) { // Chai contains circular references, but they are not fatal and can be ignored. return; diff --git a/sdk/communication/communication-phone-numbers/rollup.base.config.js b/sdk/communication/communication-phone-numbers/rollup.base.config.js index 79bd56531c75..ebe38f0a322f 100644 --- a/sdk/communication/communication-phone-numbers/rollup.base.config.js +++ b/sdk/communication/communication-phone-numbers/rollup.base.config.js @@ -126,7 +126,7 @@ export function browserConfig(test = false) { baseConfig.onwarn = (warning) => { if ( warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) + warning.importer.includes("node_modules/chai") ) { // Chai contains circular references, but they are not fatal and can be ignored. return; diff --git a/sdk/communication/communication-short-codes/rollup.base.config.js b/sdk/communication/communication-short-codes/rollup.base.config.js index e0ef2b172b30..7967d31c234a 100644 --- a/sdk/communication/communication-short-codes/rollup.base.config.js +++ b/sdk/communication/communication-short-codes/rollup.base.config.js @@ -126,7 +126,7 @@ export function browserConfig(test = false) { baseConfig.onwarn = (warning) => { if ( warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) + warning.importer.includes("node_modules/chai") ) { // Chai contains circular references, but they are not fatal and can be ignored. return; diff --git a/sdk/communication/communication-sms/rollup.base.config.js b/sdk/communication/communication-sms/rollup.base.config.js index d89795fac0c0..334242d13afe 100644 --- a/sdk/communication/communication-sms/rollup.base.config.js +++ b/sdk/communication/communication-sms/rollup.base.config.js @@ -124,7 +124,7 @@ export function browserConfig(test = false) { baseConfig.onwarn = (warning) => { if ( warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) + warning.importer.includes("node_modules/chai") ) { // Chai contains circular references, but they are not fatal and can be ignored. return; diff --git a/sdk/digitaltwins/digital-twins-core/package.json b/sdk/digitaltwins/digital-twins-core/package.json index d5ff1218a85d..92c529937bda 100644 --- a/sdk/digitaltwins/digital-twins-core/package.json +++ b/sdk/digitaltwins/digital-twins-core/package.json @@ -16,9 +16,9 @@ "build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1 && npm run extract-api", "build": "npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local", - "build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c rollup.test.config.js 2>&1", - "build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c rollup.test.config.js 2>&1", - "build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1", + "build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", + "build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", + "build:test": "tsc -p . && rollup -c 2>&1", "build:samples": "echo Obsolete.", "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", "clean": "rimraf dist dist-esm dist-browser test-dist test-browser types *.tgz *.log", @@ -28,7 +28,7 @@ "extract-api": "tsc -p . && api-extractor run --local", "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", "integration-test:browser": "npm run build:test:browser && cross-env TEST_MODE=live karma start --single-run", - "integration-test:node": "npm run build:test:node && nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 180000 --full-trace \"dist-esm/test/*.spec.js\" \"dist-esm/test/**/*.spec.js\" --harmony", + "integration-test:node": "npm run build:test:node && nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 180000 --full-trace \"dist-esm/test/{,!(browser)/**/}*.spec.js\"", "integration-test": "npm run integration-test:node && npm run integration-test:browser", "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]", "lint": "eslint package.json api-extractor.json src test --ext .ts", @@ -37,7 +37,7 @@ "test:browser": "npm run clean && npm run build:test:browser && npm run unit-test:browser", "test": "npm run clean && npm run build:test && npm run unit-test", "unit-test:browser": "karma start --single-run", - "unit-test:node": "mocha --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 180000 --full-trace \"dist-test/index.node.js\" --harmony", + "unit-test:node": "mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 180000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"", "unit-test": "npm run unit-test:node && npm run unit-test:browser", "docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src" }, @@ -77,11 +77,6 @@ "@azure/identity": "^2.0.1", "@azure-tools/test-recorder": "^1.0.0", "@microsoft/api-extractor": "^7.18.11", - "@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-replace": "^2.2.0", "@types/chai": "^4.1.6", "@types/mocha": "^7.0.2", "@types/node": "^12.0.0", @@ -110,10 +105,6 @@ "prettier": "^1.16.4", "rimraf": "^3.0.0", "rollup": "^1.16.3", - "rollup-plugin-shim": "^1.0.0", - "rollup-plugin-sourcemaps": "^0.4.2", - "rollup-plugin-terser": "^5.1.1", - "rollup-plugin-visualizer": "^4.0.4", "sinon": "^9.0.2", "typescript": "~4.2.0", "util": "^0.12.1", diff --git a/sdk/digitaltwins/digital-twins-core/rollup.base.config.js b/sdk/digitaltwins/digital-twins-core/rollup.base.config.js deleted file mode 100644 index 7f6ec13e7aa0..000000000000 --- a/sdk/digitaltwins/digital-twins-core/rollup.base.config.js +++ /dev/null @@ -1,155 +0,0 @@ -import nodeResolve from "@rollup/plugin-node-resolve"; -import multiEntry from "@rollup/plugin-multi-entry"; -import cjs from "@rollup/plugin-commonjs"; -import replace from "@rollup/plugin-replace"; -import { terser } from "rollup-plugin-terser"; -import sourcemaps from "rollup-plugin-sourcemaps"; -import shim from "rollup-plugin-shim"; -import json from "@rollup/plugin-json"; -import * as path from "path"; -import inject from "@rollup/plugin-inject"; -import { openTelemetryCommonJs } from "@azure/dev-tool/shared-config/rollup"; - -const pkg = require("./package.json"); -const depNames = Object.keys(pkg.dependencies); -const devDepNames = Object.keys(pkg.devDependencies); -const input = "dist-esm/src/index.js"; -const production = process.env.NODE_ENV === "production"; - -const ignoreKnownWarnings = (warning) => { - if ( - warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) - ) { - // Chai contains circular references, but they are not fatal and can be ignored. - return; - } - - console.error(`(!) ${warning.message}`); -}; - -export function nodeConfig(test = false) { - const externalNodeBuiltins = ["events", "path"]; - const baseConfig = { - input: input, - external: depNames.concat(externalNodeBuiltins), - output: { file: "dist/index.js", format: "cjs", sourcemap: true }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""], - // replace dynamic checks with if (true) since this is for node only. - // Allows rollup's dead code elimination to be more aggressive. - "if (isNode)": "if (true)" - }), - nodeResolve({ preferBuiltins: true }), - cjs() - ] - }; - - if (test) { - // Entry points - test files under the `test` folder(common for both browser and node), node specific test files - baseConfig.input = [ - "dist-esm/test/*.spec.js", - "dist-esm/test/unit/*.spec.js", - "dist-esm/test/public/*.spec.js" - ]; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - - // different output file - baseConfig.output.file = "dist-test/index.node.js"; - - // mark devdeps as external - baseConfig.external.push(...devDepNames); - - // 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. - baseConfig.treeshake = false; - } else if (production) { - baseConfig.plugins.push(terser()); - } - - return baseConfig; -} - -export function browserConfig(test = false) { - const baseConfig = { - input: input, - output: { - file: "dist-browser/digital-twins-core.js", - format: "umd", - name: "Azure.DigitialTwins", - globals: { - "@azure/core-http": "Azure.Core.HTTP" - }, - sourcemap: true - }, - external: ["nock", "fs-extra"], - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""] - }), - - nodeResolve({ - mainFields: ["module", "browser"], - preferBuiltins: false - }), - cjs({ - namedExports: { - chai: ["assert", "expect", "use"], - assert: ["ok", "equal", "strictEqual", "deepEqual", "fail", "throws", "notEqual"], - events: ["EventEmitter"], - ...openTelemetryCommonJs() - } - }), - - inject({ - modules: { - process: "process" - }, - exclude: ["./**/package.json"] - }), - - json() - ] - }; - - baseConfig.onwarn = ignoreKnownWarnings; - - if (test) { - baseConfig.input = [ - "dist-esm/test/*.spec.js", - "dist-esm/test/unit/*.spec.js", - "dist-esm/test/public/*.spec.js" - ]; - - baseConfig.external.unshift(...["process"]); - - baseConfig.output.globals = { - ...baseConfig.output.globals, - nock: "nock", - fs: "fs-extra", - "fs-extra": "fs", - process: "process", - path: "path" - }; - - baseConfig.plugins.unshift(multiEntry({ exports: false })); - baseConfig.plugins.unshift( - ...[shim({ path: `export function join() {}`, dotenv: `export function config() { }` })] - ); - - baseConfig.output.file = "dist-test/index.browser.js"; - - // 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. - baseConfig.treeshake = false; - } - - return baseConfig; -} diff --git a/sdk/digitaltwins/digital-twins-core/rollup.config.js b/sdk/digitaltwins/digital-twins-core/rollup.config.js index 14652aa67ed8..5d7deee44c14 100644 --- a/sdk/digitaltwins/digital-twins-core/rollup.config.js +++ b/sdk/digitaltwins/digital-twins-core/rollup.config.js @@ -1,13 +1,3 @@ -import * as base from "./rollup.base.config"; +import { makeConfig } from "@azure/dev-tool/shared-config/rollup"; -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig()); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig()); -} - -export default inputs; +export default makeConfig(require("./package.json")); diff --git a/sdk/digitaltwins/digital-twins-core/rollup.test.config.js b/sdk/digitaltwins/digital-twins-core/rollup.test.config.js deleted file mode 100644 index 3c36fbe42d68..000000000000 --- a/sdk/digitaltwins/digital-twins-core/rollup.test.config.js +++ /dev/null @@ -1,13 +0,0 @@ -import * as base from "./rollup.base.config"; - -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig({ test: true })); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig({ test: true })); -} - -export default inputs; diff --git a/sdk/eventgrid/eventgrid/package.json b/sdk/eventgrid/eventgrid/package.json index f3d96d26de4a..04099378fdbe 100644 --- a/sdk/eventgrid/eventgrid/package.json +++ b/sdk/eventgrid/eventgrid/package.json @@ -63,7 +63,7 @@ "build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", "build:samples": "echo Obsolete", - "build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1", + "build:test": "tsc -p . && rollup -c 2>&1", "build": "npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local", "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", "clean": "rimraf dist dist-browser dist-esm dist-test temp types *.tgz *.log", @@ -81,7 +81,7 @@ "test:node": "npm run clean && npm run build:test && npm run unit-test:node", "test": "npm run clean && npm run build:test && npm run unit-test", "unit-test:browser": "karma start --single-run", - "unit-test:node": "mocha --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"dist-test/index.node.js\"", + "unit-test:node": "mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"", "unit-test": "npm run unit-test:node && npm run unit-test:browser", "docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src" }, diff --git a/sdk/eventgrid/eventgrid/rollup.base.config.js b/sdk/eventgrid/eventgrid/rollup.base.config.js deleted file mode 100644 index 827d9a3c6070..000000000000 --- a/sdk/eventgrid/eventgrid/rollup.base.config.js +++ /dev/null @@ -1,134 +0,0 @@ -import path from "path"; -import nodeResolve from "@rollup/plugin-node-resolve"; -import multiEntry from "@rollup/plugin-multi-entry"; -import cjs from "@rollup/plugin-commonjs"; -import replace from "@rollup/plugin-replace"; -import shim from "rollup-plugin-shim"; -import { terser } from "rollup-plugin-terser"; -import sourcemaps from "rollup-plugin-sourcemaps"; -import viz from "rollup-plugin-visualizer"; -import { openTelemetryCommonJs } from "@azure/dev-tool/shared-config/rollup"; - -const pkg = require("./package.json"); -const depNames = Object.keys(pkg.dependencies); -const devDepNames = Object.keys(pkg.devDependencies); -const input = "dist-esm/src/index.js"; -const production = process.env.NODE_ENV === "production"; - -export function nodeConfig(test = false) { - const externalNodeBuiltins = []; - const baseConfig = { - input: input, - external: depNames.concat(externalNodeBuiltins), - output: { file: "dist/index.js", format: "cjs", sourcemap: true }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""], - values: { - // replace dynamic checks with if (true) since this is for node only. - // Allows rollup's dead code elimination to be more aggressive. - "if (isNode)": "if (true)" - } - }), - nodeResolve({ preferBuiltins: true }), - cjs() - ] - }; - - if (test) { - // Entry points - test files under the `test` folder(common for both browser and node), node specific test files - baseConfig.input = ["dist-esm/test/internal/**/*.spec.js", "dist-esm/test/public/**/*.spec.js"]; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - - // different output file - baseConfig.output.file = "dist-test/index.node.js"; - - // mark devdeps as external - baseConfig.external.push(...devDepNames); - - // 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. - baseConfig.treeshake = false; - } else if (production) { - baseConfig.plugins.push(terser()); - } - - return baseConfig; -} - -export function browserConfig(test = false, production = false) { - const baseConfig = { - input: input, - output: { - file: "dist-browser/azure-eventgrid.js", - format: "umd", - name: "Azure.MessagingEventGrid", - sourcemap: true - }, - preserveSymlinks: false, - external: ["fs-extra"], - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""], - values: { - // replace dynamic checks with if (false) since this is for - // browser only. Rollup's dead code elimination will remove - // any code guarded by if (isNode) { ... } - "if (isNode)": "if (false)" - } - }), - shim({ - constants: `export default {}`, - fs: `export default {}`, - os: `export default {}`, - dotenv: `export function config() { }`, - path: `export default {}` - }), - nodeResolve({ - mainFields: ["module", "browser"], - preferBuiltins: false - }), - cjs({ - namedExports: { - chai: ["assert", "expect", "use"], - events: ["EventEmitter"], - ...openTelemetryCommonJs() - } - }), - viz({ filename: "dist-browser/browser-stats.html", sourcemap: false }) - ] - }; - - if (test) { - // Entry points - test files under the `test` folder(common for both browser and node), browser specific test files - baseConfig.input = ["dist-esm/test/internal/**/*.spec.js", "dist-esm/test/public/**/*.spec.js"]; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - baseConfig.output.file = "dist-test/index.browser.js"; - - baseConfig.onwarn = (warning) => { - if ( - warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) - ) { - // Chai contains circular references, but they are not fatal and can be ignored. - return; - } - - console.error(`(!) ${warning.message}`); - }; - - // 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. - baseConfig.treeshake = false; - } else if (production) { - baseConfig.output.file = "dist-browser/azure-eventgrid.min.js"; - baseConfig.plugins.push(terser()); - } - - return baseConfig; -} diff --git a/sdk/eventgrid/eventgrid/rollup.config.js b/sdk/eventgrid/eventgrid/rollup.config.js index 49a26bd6fdd6..5d7deee44c14 100644 --- a/sdk/eventgrid/eventgrid/rollup.config.js +++ b/sdk/eventgrid/eventgrid/rollup.config.js @@ -1,14 +1,3 @@ -import * as base from "./rollup.base.config"; +import { makeConfig } from "@azure/dev-tool/shared-config/rollup"; -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig()); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig()); - inputs.push(base.browserConfig(false, true)); -} - -export default inputs; +export default makeConfig(require("./package.json")); diff --git a/sdk/eventgrid/eventgrid/rollup.test.config.js b/sdk/eventgrid/eventgrid/rollup.test.config.js deleted file mode 100644 index 925a4421a53e..000000000000 --- a/sdk/eventgrid/eventgrid/rollup.test.config.js +++ /dev/null @@ -1,3 +0,0 @@ -import * as base from "./rollup.base.config"; - -export default [base.nodeConfig(true), base.browserConfig(true)]; diff --git a/sdk/eventgrid/eventgrid/test/public/utils/recordedClient.ts b/sdk/eventgrid/eventgrid/test/public/utils/recordedClient.ts index d162b76d29ce..779fc6c48c60 100644 --- a/sdk/eventgrid/eventgrid/test/public/utils/recordedClient.ts +++ b/sdk/eventgrid/eventgrid/test/public/utils/recordedClient.ts @@ -2,18 +2,12 @@ // Licensed under the MIT license. import { Context } from "mocha"; -import * as dotenv from "dotenv"; import { env, Recorder, record, RecorderEnvironmentSetup } from "@azure-tools/test-recorder"; -import { isNode } from "./testUtils"; import { EventGridPublisherClient, InputSchema } from "../../../src"; import { KeyCredential } from "@azure/core-auth"; -if (isNode) { - dotenv.config(); -} - export interface RecordedClient { client: EventGridPublisherClient; recorder: Recorder; diff --git a/sdk/eventhub/event-hubs/package.json b/sdk/eventhub/event-hubs/package.json index b8e6f7561a83..4a2231553ae6 100644 --- a/sdk/eventhub/event-hubs/package.json +++ b/sdk/eventhub/event-hubs/package.json @@ -48,9 +48,9 @@ "build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", "build:samples": "echo Obsolete.", - "build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c rollup.test.config.js 2>&1", - "build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c rollup.test.config.js 2>&1", - "build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1 && npm run generate-certs", + "build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", + "build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", + "build:test": "tsc -p . && rollup -c 2>&1 && npm run generate-certs", "build:types": "downlevel-dts types/latest types/3.1", "build": "npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local && npm run build:types", "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", diff --git a/sdk/eventhub/event-hubs/rollup.base.config.js b/sdk/eventhub/event-hubs/rollup.base.config.js deleted file mode 100644 index 335dd2887d77..000000000000 --- a/sdk/eventhub/event-hubs/rollup.base.config.js +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -import nodeResolve from "@rollup/plugin-node-resolve"; -import multiEntry from "@rollup/plugin-multi-entry"; -import cjs from "@rollup/plugin-commonjs"; -import json from "@rollup/plugin-json"; -import replace from "@rollup/plugin-replace"; -import { terser } from "rollup-plugin-terser"; -import sourcemaps from "rollup-plugin-sourcemaps"; -import shim from "rollup-plugin-shim"; -import inject from "@rollup/plugin-inject"; -import { openTelemetryCommonJs } from "@azure/dev-tool/shared-config/rollup"; - -import path from "path"; - -const pkg = require("./package.json"); -const depNames = Object.keys(pkg.dependencies); -const input = "dist-esm/src/index.js"; -const production = process.env.NODE_ENV === "production"; - -export function nodeConfig(test = false) { - const externalNodeBuiltins = ["events", "util", "os", "url"]; - const baseConfig = { - input: input, - external: depNames.concat(externalNodeBuiltins), - output: { file: "dist/index.js", format: "cjs", sourcemap: true }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""], - // replace dynamic checks with if (true) since this is for node only. - // Allows rollup's dead code elimination to be more aggressive. - "if (isNode)": "if (true)" - }), - nodeResolve({ preferBuiltins: true }), - cjs(), - json() - ] - }; - - baseConfig.external.push("crypto"); - - if (test) { - // entry point is every test file - baseConfig.input = ["dist-esm/test/internal/**/*.spec.js", "dist-esm/test/public/**/*.spec.js"]; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - - // different output file - baseConfig.output.file = "dist-test/index.js"; - - // mark assert as external - baseConfig.external.push( - "assert", - "fs", - "path", - "os", - "tty", - "child_process", - "@azure/identity" - ); - - baseConfig.onwarn = (warning) => { - if ( - warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) - ) { - // Chai contains circular references, but they are not fatal and can be ignored. - return; - } - - console.error(`(!) ${warning.message}`); - }; - - // 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. - baseConfig.treeshake = false; - } else if (production) { - baseConfig.plugins.push(terser()); - } - - return baseConfig; -} - -export function browserConfig(test = false) { - const baseConfig = { - input: input, - external: ["ms-rest-js"], - output: { - file: "dist-browser/event-hubs.js", - format: "umd", - name: "Azure.Messaging.EventHubs", - sourcemap: true, - globals: { "ms-rest-js": "msRest" } - }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace( - // ms-rest-js is externalized so users must include it prior to using this bundle. - { - delimiters: ["", ""], - // replace dynamic checks with if (false) since this is for - // browser only. Rollup's dead code elimination will remove - // any code guarded by if (isNode) { ... } - "if (isNode)": "if (false)" - } - ), - ...(!test - ? [] - : [ - shim({ - // dotenv doesn't work in the browser, so replace it with a no-op function - dotenv: `export function config() { }` - }) - ]), - nodeResolve({ - mainFields: ["module", "browser"], - preferBuiltins: false - }), - - cjs({ - namedExports: { - ...openTelemetryCommonJs(), - chai: ["should", "assert"], - assert: ["equal", "deepEqual", "notEqual"] - } - }), - - // rhea and rhea-promise use the Buffer global which requires - // injection to shim properly - inject({ - modules: { - Buffer: ["buffer", "Buffer"], - process: "process" - }, - exclude: ["./**/package.json"] - }), - - json() - ] - }; - - if (test) { - baseConfig.input = [ - "dist-esm/test/public/*.spec.js", - "dist-esm/test/internal/*.spec.js", - "dist-esm/test/internal/impl/*.spec.js" - ]; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - baseConfig.output.file = "dist-test/index.browser.js"; - - // 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. - baseConfig.treeshake = false; - } else if (production) { - baseConfig.plugins.push(terser()); - } - - return baseConfig; -} diff --git a/sdk/eventhub/event-hubs/rollup.config.js b/sdk/eventhub/event-hubs/rollup.config.js index 01f209a32fa8..5d7deee44c14 100644 --- a/sdk/eventhub/event-hubs/rollup.config.js +++ b/sdk/eventhub/event-hubs/rollup.config.js @@ -1,16 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. +import { makeConfig } from "@azure/dev-tool/shared-config/rollup"; -import * as base from "./rollup.base.config"; - -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig()); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig()); -} - -export default inputs; +export default makeConfig(require("./package.json")); diff --git a/sdk/eventhub/event-hubs/rollup.test.config.js b/sdk/eventhub/event-hubs/rollup.test.config.js deleted file mode 100644 index 48ea762bf9e0..000000000000 --- a/sdk/eventhub/event-hubs/rollup.test.config.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -import * as base from "./rollup.base.config"; - -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig({ test: true })); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig({ test: true })); -} - -export default inputs; diff --git a/sdk/eventhub/event-processor-host/package.json b/sdk/eventhub/event-processor-host/package.json index 486d1de25d4e..2b66a15aeffd 100644 --- a/sdk/eventhub/event-processor-host/package.json +++ b/sdk/eventhub/event-processor-host/package.json @@ -36,7 +36,7 @@ "build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", "build:samples": "dev-tool samples prep && cd dist-samples && tsc", - "build:test": "tsc -p . && cross-env ONLY_NODE=true rollup -c rollup.test.config.js 2>&1", + "build:test": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", "build": "npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local", "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "clean": "rimraf dist dist-* typings *.tgz *.log", @@ -88,11 +88,6 @@ "@azure/dev-tool": "^1.0.0", "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@microsoft/api-extractor": "^7.18.11", - "@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-replace": "^2.2.0", "@types/async-lock": "^1.1.0", "@types/chai": "^4.1.6", "@types/chai-as-promised": "^7.1.0", @@ -116,7 +111,6 @@ "prettier": "^1.16.4", "rimraf": "^3.0.0", "rollup": "^1.16.3", - "rollup-plugin-sourcemaps": "^0.4.2", "ts-node": "^10.0.0", "typescript": "~4.2.0", "ws": "^7.1.1", diff --git a/sdk/eventhub/event-processor-host/rollup.base.config.js b/sdk/eventhub/event-processor-host/rollup.base.config.js deleted file mode 100644 index e841a51beda6..000000000000 --- a/sdk/eventhub/event-processor-host/rollup.base.config.js +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -import nodeResolve from "@rollup/plugin-node-resolve"; -import multiEntry from "@rollup/plugin-multi-entry"; -import cjs from "@rollup/plugin-commonjs"; -import json from "@rollup/plugin-json"; -import replace from "@rollup/plugin-replace"; -import sourcemaps from "rollup-plugin-sourcemaps"; - -import path from "path"; - -const pkg = require("./package.json"); -const depNames = Object.keys(pkg.dependencies); -const input = "dist-esm/src/index.js"; - -export function nodeConfig(test = false) { - const externalNodeBuiltins = ["events", "util"]; - const baseConfig = { - input: input, - external: depNames.concat(externalNodeBuiltins), - output: { file: "dist/index.js", format: "cjs", sourcemap: true }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""], - // replace dynamic checks with if (true) since this is for node only. - // Allows rollup's dead code elimination to be more aggressive. - "if (isNode)": "if (true)" - }), - nodeResolve({ preferBuiltins: true }), - cjs(), - json() - ] - }; - - baseConfig.external.push("crypto", "path"); - - if (test) { - // entry point is every test file - baseConfig.input = "dist-esm/test/**/*.spec.js"; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - - // different output file - baseConfig.output.file = "dist-test/index.js"; - - // mark assert as external - baseConfig.external.push("assert", "fs", "os", "tty", "child_process"); - - baseConfig.onwarn = (warning) => { - if ( - warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) - ) { - // Chai contains circular references, but they are not fatal and can be ignored. - return; - } - - console.error(`(!) ${warning.message}`); - }; - - // 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. - baseConfig.treeshake = false; - } - - return baseConfig; -} - -export function browserConfig(test = false) { - const baseConfig = { - input: input, - external: ["ms-rest-js"], - output: { - file: "browser/index.js", - format: "umd", - name: "ExampleClient", - sourcemap: true, - globals: { "ms-rest-js": "msRest" } - }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace( - // ms-rest-js is externalized so users must include it prior to using this bundle. - { - delimiters: ["", ""], - // replace dynamic checks with if (false) since this is for - // browser only. Rollup's dead code elimination will remove - // any code guarded by if (isNode) { ... } - "if (isNode)": "if (false)" - } - ), - nodeResolve({ - mainFields: ["module", "browser"], - preferBuiltins: false - }), - cjs({ - namedExports: { events: ["EventEmitter"] } - }), - json() - ] - }; - - if (test) { - baseConfig.input = "dist-esm/test/**/*.spec.js"; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - baseConfig.output.file = "dist-test/index.browser.js"; - - // 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. - baseConfig.treeshake = false; - } - - return baseConfig; -} diff --git a/sdk/eventhub/event-processor-host/rollup.config.js b/sdk/eventhub/event-processor-host/rollup.config.js index a62dabd573b4..96d051412a13 100644 --- a/sdk/eventhub/event-processor-host/rollup.config.js +++ b/sdk/eventhub/event-processor-host/rollup.config.js @@ -1,17 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. +import { makeConfig } from "@azure/dev-tool/shared-config/rollup"; -import * as base from "./rollup.base.config"; - -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig()); -} - -// Disable this until we are ready to run rollup for the browser. -// if (!process.env.ONLY_NODE) { -// inputs.push(base.browserConfig()); -// } - -export default inputs; +export default makeConfig(require("./package.json"), { disableBrowserBundle: true }); diff --git a/sdk/eventhub/event-processor-host/rollup.test.config.js b/sdk/eventhub/event-processor-host/rollup.test.config.js deleted file mode 100644 index fd819935cb22..000000000000 --- a/sdk/eventhub/event-processor-host/rollup.test.config.js +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -import * as base from "./rollup.base.config"; - -export default [base.nodeConfig(true) /*, base.browserConfig(true)*/]; diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/package.json b/sdk/eventhub/eventhubs-checkpointstore-blob/package.json index 1302b6d755c9..9feb61229ccf 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/package.json +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/package.json @@ -35,8 +35,8 @@ "build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", "build:samples": "echo Obsolete", - "build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c rollup.test.config.js 2>&1", - "build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c rollup.test.config.js 2>&1", + "build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", + "build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", "build:test": "npm run build:test:node", "build": "npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local", "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", @@ -70,12 +70,6 @@ "@azure/dev-tool": "^1.0.0", "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@microsoft/api-extractor": "^7.18.11", - "@rollup/plugin-commonjs": "11.0.2", - "@rollup/plugin-inject": "^4.0.0", - "@rollup/plugin-json": "^4.0.0", - "@rollup/plugin-multi-entry": "^3.0.0", - "@rollup/plugin-node-resolve": "^8.0.0", - "@rollup/plugin-replace": "^2.2.0", "@types/chai": "^4.1.6", "@types/chai-as-promised": "^7.1.0", "@types/chai-string": "^1.4.1", @@ -109,10 +103,6 @@ "prettier": "^1.16.4", "rimraf": "^3.0.0", "rollup": "^1.16.3", - "rollup-plugin-shim": "^1.0.0", - "rollup-plugin-sourcemaps": "^0.4.2", - "rollup-plugin-terser": "^5.1.1", - "rollup-plugin-visualizer": "^4.0.4", "ts-node": "^10.0.0", "typescript": "~4.2.0", "util": "^0.12.1", diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/rollup.base.config.js b/sdk/eventhub/eventhubs-checkpointstore-blob/rollup.base.config.js deleted file mode 100644 index 029e828b7f6b..000000000000 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/rollup.base.config.js +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -import nodeResolve from "@rollup/plugin-node-resolve"; -import multiEntry from "@rollup/plugin-multi-entry"; -import cjs from "@rollup/plugin-commonjs"; -import json from "@rollup/plugin-json"; -import replace from "@rollup/plugin-replace"; -import { terser } from "rollup-plugin-terser"; -import sourcemaps from "rollup-plugin-sourcemaps"; -import shim from "rollup-plugin-shim"; -import inject from "@rollup/plugin-inject"; - -import path from "path"; - -const pkg = require("./package.json"); -const depNames = Object.keys(pkg.dependencies); -const input = "dist-esm/src/index.js"; -const production = process.env.NODE_ENV === "production"; - -export function nodeConfig(test = false) { - const externalNodeBuiltins = ["events", "util", "os"]; - const additionalExternals = ["keytar"]; - const baseConfig = { - input: input, - external: depNames.concat(externalNodeBuiltins, additionalExternals), - output: { file: "dist/index.js", format: "cjs", sourcemap: true }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""], - // replace dynamic checks with if (true) since this is for node only. - // Allows rollup's dead code elimination to be more aggressive. - "if (isNode)": "if (true)" - }), - nodeResolve({ preferBuiltins: true }), - cjs(), - json() - ] - }; - - baseConfig.external.push("crypto"); - - if (test) { - // entry point is every test file - baseConfig.input = "dist-esm/test/**/*.spec.js"; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - - // different output file - baseConfig.output.file = "dist-test/index.js"; - - // mark assert as external - baseConfig.external.push( - "assert", - "fs", - "path", - "os", - "tty", - "child_process", - "@azure/identity" - ); - - baseConfig.onwarn = (warning) => { - if ( - warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) - ) { - // Chai contains circular references, but they are not fatal and can be ignored. - return; - } - - console.error(`(!) ${warning.message}`); - }; - - // 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. - baseConfig.treeshake = false; - } else if (production) { - baseConfig.plugins.push(terser()); - } - - return baseConfig; -} - -export function browserConfig(test = false) { - const baseConfig = { - input: input, - external: ["ms-rest-js"], - output: { - file: "dist-browser/eventhubs-checkpointstore-blob.js", - format: "umd", - name: "Azure.Messaging.EventHubs.CheckpointStore.Blob", - sourcemap: true, - globals: { "ms-rest-js": "msRest" } - }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace( - // ms-rest-js is externalized so users must include it prior to using this bundle. - { - delimiters: ["", ""], - // replace dynamic checks with if (false) since this is for - // browser only. Rollup's dead code elimination will remove - // any code guarded by if (isNode) { ... } - "if (isNode)": "if (false)" - } - ), - - // fs, net, and tls are used by rhea and need to be shimmed - // dotenv doesn't work in the browser, so replace it with a no-op function - shim({ - fs: `export default {}`, - net: `export default {}`, - tls: `export default {}`, - dotenv: `export function config() { }`, - os: ` - export function arch() { return "javascript" } - export function type() { return "Browser" } - export function release() { typeof navigator === 'undefined' ? '' : navigator.appVersion } - `, - path: `export default {}`, - dns: `export function resolve() { }` - }), - - nodeResolve({ - mainFields: ["module", "browser"], - preferBuiltins: false - }), - - cjs({ - namedExports: { - events: ["EventEmitter"] - } - }), - - // rhea and rhea-promise use the Buffer global which requires - // injection to shim properly - inject({ - modules: { - Buffer: ["buffer", "Buffer"], - process: "process" - }, - exclude: ["./**/package.json"] - }), - - json() - ] - }; - - if (test) { - baseConfig.input = "dist-esm/test/**/*.spec.js"; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - baseConfig.output.file = "dist-test/index.browser.js"; - - // 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. - baseConfig.treeshake = false; - } else if (production) { - baseConfig.plugins.push(terser()); - } - - return baseConfig; -} diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/rollup.config.js b/sdk/eventhub/eventhubs-checkpointstore-blob/rollup.config.js index 01f209a32fa8..5d7deee44c14 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/rollup.config.js +++ b/sdk/eventhub/eventhubs-checkpointstore-blob/rollup.config.js @@ -1,16 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. +import { makeConfig } from "@azure/dev-tool/shared-config/rollup"; -import * as base from "./rollup.base.config"; - -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig()); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig()); -} - -export default inputs; +export default makeConfig(require("./package.json")); diff --git a/sdk/eventhub/eventhubs-checkpointstore-blob/rollup.test.config.js b/sdk/eventhub/eventhubs-checkpointstore-blob/rollup.test.config.js deleted file mode 100644 index 48ea762bf9e0..000000000000 --- a/sdk/eventhub/eventhubs-checkpointstore-blob/rollup.test.config.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -import * as base from "./rollup.base.config"; - -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig({ test: true })); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig({ test: true })); -} - -export default inputs; diff --git a/sdk/eventhub/eventhubs-checkpointstore-table/package.json b/sdk/eventhub/eventhubs-checkpointstore-table/package.json index c692af8a07fe..093ff8018dce 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-table/package.json +++ b/sdk/eventhub/eventhubs-checkpointstore-table/package.json @@ -35,8 +35,8 @@ "build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", "build:samples": "echo not implemented", - "build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c rollup.test.config.js 2>&1", - "build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c rollup.test.config.js 2>&1", + "build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", + "build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", "build:test": "npm run build:test:node", "build": "npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local", "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", @@ -69,12 +69,6 @@ "@azure/dev-tool": "^1.0.0", "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@microsoft/api-extractor": "^7.18.11", - "@rollup/plugin-commonjs": "11.0.2", - "@rollup/plugin-inject": "^4.0.0", - "@rollup/plugin-json": "^4.0.0", - "@rollup/plugin-multi-entry": "^3.0.0", - "@rollup/plugin-node-resolve": "^8.0.0", - "@rollup/plugin-replace": "^2.2.0", "@types/chai": "^4.1.6", "@types/chai-as-promised": "^7.1.0", "@types/chai-string": "^1.4.1", @@ -108,10 +102,6 @@ "prettier": "^1.16.4", "rimraf": "^3.0.0", "rollup": "^1.16.3", - "rollup-plugin-shim": "^1.0.0", - "rollup-plugin-sourcemaps": "^0.4.2", - "rollup-plugin-terser": "^5.1.1", - "rollup-plugin-visualizer": "^4.0.4", "ts-node": "^10.0.0", "typescript": "~4.2.0", "util": "^0.12.1", diff --git a/sdk/eventhub/eventhubs-checkpointstore-table/rollup.base.config.js b/sdk/eventhub/eventhubs-checkpointstore-table/rollup.base.config.js deleted file mode 100644 index 35f7df4b47b5..000000000000 --- a/sdk/eventhub/eventhubs-checkpointstore-table/rollup.base.config.js +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -import nodeResolve from "@rollup/plugin-node-resolve"; -import multiEntry from "@rollup/plugin-multi-entry"; -import cjs from "@rollup/plugin-commonjs"; -import json from "@rollup/plugin-json"; -import replace from "@rollup/plugin-replace"; -import { terser } from "rollup-plugin-terser"; -import sourcemaps from "rollup-plugin-sourcemaps"; -import shim from "rollup-plugin-shim"; -import inject from "@rollup/plugin-inject"; - -import path from "path"; - -const pkg = require("./package.json"); -const depNames = Object.keys(pkg.dependencies); -const input = "dist-esm/src/index.js"; -const production = process.env.NODE_ENV === "production"; - -export function nodeConfig(test = false) { - const externalNodeBuiltins = ["events", "util", "os"]; - const additionalExternals = ["keytar"]; - const baseConfig = { - input: input, - external: depNames.concat(externalNodeBuiltins, additionalExternals), - output: { file: "dist/index.js", format: "cjs", sourcemap: true }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""], - // replace dynamic checks with if (true) since this is for node only. - // Allows rollup's dead code elimination to be more aggressive. - "if (isNode)": "if (true)" - }), - nodeResolve({ preferBuiltins: true }), - cjs(), - json() - ] - }; - - baseConfig.external.push("crypto"); - - if (test) { - // entry point is every test file - baseConfig.input = "dist-esm/test/**/*.spec.js"; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - - // different output file - baseConfig.output.file = "dist-test/index.js"; - - // mark assert as external - baseConfig.external.push( - "assert", - "fs", - "path", - "os", - "tty", - "child_process", - "@azure/identity" - ); - - baseConfig.onwarn = (warning) => { - if ( - warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) - ) { - // Chai contains circular references, but they are not fatal and can be ignored. - return; - } - - console.error(`(!) ${warning.message}`); - }; - - // 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. - baseConfig.treeshake = false; - } else if (production) { - baseConfig.plugins.push(terser()); - } - - return baseConfig; -} - -export function browserConfig(test = false) { - const baseConfig = { - input: input, - external: ["ms-rest-js"], - output: { - file: "dist-browser/eventhubs-checkpointstore-table.js", - format: "umd", - name: "Azure.Messaging.EventHubs.CheckpointStore.Table", - sourcemap: true, - globals: { "ms-rest-js": "msRest" } - }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace( - // ms-rest-js is externalized so users must include it prior to using this bundle. - { - delimiters: ["", ""], - // replace dynamic checks with if (false) since this is for - // browser only. Rollup's dead code elimination will remove - // any code guarded by if (isNode) { ... } - "if (isNode)": "if (false)" - } - ), - - // fs, net, and tls are used by rhea and need to be shimmed - // dotenv doesn't work in the browser, so replace it with a no-op function - shim({ - fs: `export default {}`, - net: `export default {}`, - tls: `export default {}`, - dotenv: `export function config() { }`, - os: ` - export function arch() { return "javascript" } - export function type() { return "Browser" } - export function release() { typeof navigator === 'undefined' ? '' : navigator.appVersion } - `, - path: `export default {}`, - dns: `export function resolve() { }` - }), - - nodeResolve({ - mainFields: ["module", "browser"], - preferBuiltins: false - }), - - cjs({ - namedExports: { - events: ["EventEmitter"] - } - }), - - // rhea and rhea-promise use the Buffer global which requires - // injection to shim properly - inject({ - modules: { - Buffer: ["buffer", "Buffer"], - process: "process" - }, - exclude: ["./**/package.json"] - }), - - json() - ] - }; - - if (test) { - baseConfig.input = "dist-esm/test/**/*.spec.js"; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - baseConfig.output.file = "dist-test/index.browser.js"; - - // 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. - baseConfig.treeshake = false; - } else if (production) { - baseConfig.plugins.push(terser()); - } - - return baseConfig; -} diff --git a/sdk/eventhub/eventhubs-checkpointstore-table/rollup.config.js b/sdk/eventhub/eventhubs-checkpointstore-table/rollup.config.js index 01f209a32fa8..5d7deee44c14 100644 --- a/sdk/eventhub/eventhubs-checkpointstore-table/rollup.config.js +++ b/sdk/eventhub/eventhubs-checkpointstore-table/rollup.config.js @@ -1,16 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. +import { makeConfig } from "@azure/dev-tool/shared-config/rollup"; -import * as base from "./rollup.base.config"; - -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig()); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig()); -} - -export default inputs; +export default makeConfig(require("./package.json")); diff --git a/sdk/eventhub/eventhubs-checkpointstore-table/rollup.test.config.js b/sdk/eventhub/eventhubs-checkpointstore-table/rollup.test.config.js deleted file mode 100644 index 48ea762bf9e0..000000000000 --- a/sdk/eventhub/eventhubs-checkpointstore-table/rollup.test.config.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -import * as base from "./rollup.base.config"; - -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig({ test: true })); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig({ test: true })); -} - -export default inputs; diff --git a/sdk/quantum/quantum-jobs/package.json b/sdk/quantum/quantum-jobs/package.json index 81ece87034ff..4591a68aea62 100644 --- a/sdk/quantum/quantum-jobs/package.json +++ b/sdk/quantum/quantum-jobs/package.json @@ -16,8 +16,8 @@ "build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1 && npm run extract-api", "build": "npm run clean && npm run build:node && npm run build:browser", - "build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c rollup.test.config.js 2>&1", - "build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c rollup.test.config.js 2>&1", + "build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", + "build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", "build:test": "npm run build:test:node && npm run build:test:browser", "build:samples": "echo Skipped.", "check-format": "echo skip format check as this package has only auto generated code", @@ -28,7 +28,7 @@ "extract-api": "tsc -p . && api-extractor run --local", "format": "echo skip format as this package has only auto generated code", "integration-test:browser": "echo skipped", - "integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 180000 --full-trace \"dist-esm/test/*.spec.js\" \"dist-esm/test/**/*.spec.js\" --harmony", + "integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 180000 --full-trace \"dist-esm/test/{,!(browser)/**/}*.spec.js\"", "integration-test": "npm run integration-test:node && npm run integration-test:browser", "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]", "lint": "eslint package.json api-extractor.json src test --ext .ts -f html -o search-lintReport.html || exit 0", @@ -37,7 +37,7 @@ "test:browser": "npm run clean && npm run build:test:browser && npm run unit-test:browser", "test": "npm run clean && npm run build:test && npm run unit-test", "unit-test:browser": "echo skipped", - "unit-test:node": "mocha --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 180000 --full-trace \"dist-test/index.node.js\" --harmony", + "unit-test:node": "mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 180000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"", "unit-test": "npm run unit-test:node && npm run unit-test:browser", "docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src" }, @@ -75,11 +75,6 @@ "@azure/identity": "^2.0.1", "@azure-tools/test-recorder": "^1.0.0", "@microsoft/api-extractor": "^7.18.11", - "@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-replace": "^2.2.0", "@types/chai": "^4.1.6", "@types/mocha": "^7.0.2", "@types/node": "^12.0.0", @@ -109,10 +104,6 @@ "prettier": "^1.16.4", "rimraf": "^3.0.0", "rollup": "^1.16.3", - "rollup-plugin-shim": "^1.0.0", - "rollup-plugin-sourcemaps": "^0.4.2", - "rollup-plugin-terser": "^5.1.1", - "rollup-plugin-visualizer": "^4.0.4", "sinon": "^9.0.2", "typescript": "~4.2.0", "util": "^0.12.1", diff --git a/sdk/quantum/quantum-jobs/rollup.base.config.js b/sdk/quantum/quantum-jobs/rollup.base.config.js deleted file mode 100644 index b2442f9fe536..000000000000 --- a/sdk/quantum/quantum-jobs/rollup.base.config.js +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - */ -import path from "path"; -import nodeResolve from "@rollup/plugin-node-resolve"; -import multiEntry from "@rollup/plugin-multi-entry"; -import cjs from "@rollup/plugin-commonjs"; -import json from "@rollup/plugin-json"; -import replace from "@rollup/plugin-replace"; -import shim from "rollup-plugin-shim"; -import { terser } from "rollup-plugin-terser"; -import sourcemaps from "rollup-plugin-sourcemaps"; -import viz from "rollup-plugin-visualizer"; -import { openTelemetryCommonJs } from "@azure/dev-tool/shared-config/rollup"; - -const pkg = require("./package.json"); -const depNames = Object.keys(pkg.dependencies); -const devDepNames = Object.keys(pkg.devDependencies); -const input = "dist-esm/src/index.js"; -const production = process.env.NODE_ENV === "production"; - -export function nodeConfig(test = false) { - const externalNodeBuiltins = ["events", "path"]; - const baseConfig = { - input: input, - external: depNames.concat(externalNodeBuiltins), - output: { file: "dist/index.js", format: "cjs", sourcemap: true }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""], - // replace dynamic checks with if (true) since this is for node only. - // Allows rollup's dead code elimination to be more aggressive. - "if (isNode)": "if (true)" - }), - nodeResolve({ preferBuiltins: true }), - json(), - cjs() - ] - }; - - if (test) { - // Entry points - test files under the `test` folder(common for both browser and node), node specific test files - baseConfig.input = [ - "dist-esm/test/public/*.spec.js", - "dist-esm/test/internal/*.spec.js", - "dist-esm/test/public/node/*.spec.js", - "dist-esm/test/internal/node/*.spec.js" - ]; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - - // different output file - baseConfig.output.file = "dist-test/index.node.js"; - - // mark devdeps as external - baseConfig.external.push(...devDepNames); - - // 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. - baseConfig.treeshake = false; - } else if (production) { - baseConfig.plugins.push(terser()); - } - - return baseConfig; -} - -export function browserConfig(test = false) { - const baseConfig = { - input: input, - output: { - file: "dist-browser/azure-quantum.js", - format: "umd", - name: "azquantumjobs", - sourcemap: true - }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""], - // replace dynamic checks with if (false) since this is for - // browser only. Rollup's dead code elimination will remove - // any code guarded by if (isNode) { ... } - "if (isNode)": "if (false)" - }), - shim({ - constants: `export default {}`, - fs: `export default {}`, - os: `export default {}`, - dotenv: `export function config() { }`, - path: `export default {}` - }), - nodeResolve({ - mainFields: ["module", "browser"], - preferBuiltins: false - }), - json(), - cjs({ - namedExports: { - events: ["EventEmitter"], - chai: ["assert"], - ...openTelemetryCommonJs() - } - }), - // disable the plugin in the rollup config to cut-out errors - viz({ filename: "dist-browser/browser-stats.html", sourcemap: false }) - ] - }; - - if (test) { - // Entry points - test files under the `test` folder(common for both browser and node), browser specific test files - baseConfig.input = [ - "dist-esm/test/public/*.spec.js", - "dist-esm/test/internal/*.spec.js", - "dist-esm/test/public/browser/*.spec.js", - "dist-esm/test/internal/browser/*.spec.js" - ]; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - baseConfig.output.file = "dist-test/index.browser.js"; - - baseConfig.onwarn = (warning) => { - if ( - warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) - ) { - // Chai contains circular references, but they are not fatal and can be ignored. - return; - } - - console.error(`(!) ${warning.message}`); - }; - - // 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. - baseConfig.treeshake = false; - } - - return baseConfig; -} diff --git a/sdk/quantum/quantum-jobs/rollup.config.js b/sdk/quantum/quantum-jobs/rollup.config.js index 809e2993c0eb..5d7deee44c14 100644 --- a/sdk/quantum/quantum-jobs/rollup.config.js +++ b/sdk/quantum/quantum-jobs/rollup.config.js @@ -1,17 +1,3 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - */ -import * as base from "./rollup.base.config"; +import { makeConfig } from "@azure/dev-tool/shared-config/rollup"; -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig()); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig()); -} - -export default inputs; +export default makeConfig(require("./package.json")); diff --git a/sdk/quantum/quantum-jobs/rollup.test.config.js b/sdk/quantum/quantum-jobs/rollup.test.config.js deleted file mode 100644 index a1a09aafafbe..000000000000 --- a/sdk/quantum/quantum-jobs/rollup.test.config.js +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) Microsoft Corporation. - * Licensed under the MIT License. - */ - -import * as base from "./rollup.base.config"; - -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig(true)); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig(true)); -} - -export default inputs; diff --git a/sdk/search/search-documents/package.json b/sdk/search/search-documents/package.json index fe2d5fb23118..86484d557f0f 100644 --- a/sdk/search/search-documents/package.json +++ b/sdk/search/search-documents/package.json @@ -12,7 +12,7 @@ "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", "build:samples": "echo Obsolete.", "execute:samples": "dev-tool samples run samples-dev", - "build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1", + "build:test": "tsc -p . && rollup -c 2>&1", "build": "npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local", "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", "clean": "rimraf dist dist-* temp types *.tgz *.log", @@ -28,7 +28,7 @@ "test:node": "npm run build:test && npm run unit-test:node", "test": "npm run build:test && npm run unit-test", "unit-test:browser": "karma start --single-run", - "unit-test:node": "mocha --reporter ../../../common/tools/mocha-multi-reporter.js dist-test/index.node.js --harmony", + "unit-test:node": "mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"", "unit-test": "npm run unit-test:node && npm run unit-test:browser", "docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src" }, @@ -89,9 +89,6 @@ "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@azure-tools/test-recorder": "^1.0.0", "@microsoft/api-extractor": "^7.18.11", - "@rollup/plugin-json": "^4.0.0", - "@rollup/plugin-multi-entry": "^3.0.0", - "@rollup/plugin-replace": "^2.2.0", "@types/chai": "^4.1.6", "@types/mocha": "^7.0.2", "@types/node": "^12.0.0", @@ -120,12 +117,6 @@ "prettier": "^1.16.4", "rimraf": "^3.0.0", "rollup": "^1.16.3", - "@rollup/plugin-commonjs": "11.0.2", - "@rollup/plugin-node-resolve": "^8.0.0", - "rollup-plugin-shim": "^1.0.0", - "rollup-plugin-sourcemaps": "^0.4.2", - "rollup-plugin-terser": "^5.1.1", - "rollup-plugin-visualizer": "^4.0.4", "sinon": "^9.0.2", "ts-node": "^10.0.0", "typescript": "~4.2.0", diff --git a/sdk/search/search-documents/rollup.base.config.js b/sdk/search/search-documents/rollup.base.config.js deleted file mode 100644 index 2d602594ad3b..000000000000 --- a/sdk/search/search-documents/rollup.base.config.js +++ /dev/null @@ -1,138 +0,0 @@ -import path from "path"; -import nodeResolve from "@rollup/plugin-node-resolve"; -import multiEntry from "@rollup/plugin-multi-entry"; -import cjs from "@rollup/plugin-commonjs"; -import replace from "@rollup/plugin-replace"; -import shim from "rollup-plugin-shim"; -import { terser } from "rollup-plugin-terser"; -import sourcemaps from "rollup-plugin-sourcemaps"; -import viz from "rollup-plugin-visualizer"; -import { openTelemetryCommonJs } from "@azure/dev-tool/shared-config/rollup"; - -const pkg = require("./package.json"); -const depNames = Object.keys(pkg.dependencies); -const devDepNames = Object.keys(pkg.devDependencies); -const input = "dist-esm/src/index.js"; -const production = process.env.NODE_ENV === "production"; - -export function nodeConfig(test = false) { - const externalNodeBuiltins = ["events", "path"]; - const baseConfig = { - input: input, - external: depNames.concat(externalNodeBuiltins), - output: { file: "dist/index.js", format: "cjs", sourcemap: true }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""], - // replace dynamic checks with if (true) since this is for node only. - // Allows rollup's dead code elimination to be more aggressive. - "if (isNode)": "if (true)" - }), - nodeResolve({ preferBuiltins: true }), - cjs() - ] - }; - - if (test) { - // Entry points - test files under the `test` folder(common for both browser and node), node specific test files - baseConfig.input = [ - "dist-esm/test/public/*.spec.js", - "dist-esm/test/internal/*.spec.js", - "dist-esm/test/public/node/*.spec.js", - "dist-esm/test/internal/node/*.spec.js" - ]; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - - // different output file - baseConfig.output.file = "dist-test/index.node.js"; - - // mark devdeps as external - baseConfig.external.push(...devDepNames); - - // 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. - baseConfig.treeshake = false; - } else if (production) { - baseConfig.plugins.push(terser()); - } - - return baseConfig; -} - -export function browserConfig(test = false) { - const baseConfig = { - input: input, - output: { - file: "dist-browser/azure-search.js", - format: "umd", - name: "SearchClient", - sourcemap: true, - globals: { "@azure/core-http": "Azure.Core.HTTP" } - }, - preserveSymlinks: false, - external: ["fs-extra"], - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""], - // replace dynamic checks with if (false) since this is for - // browser only. Rollup's dead code elimination will remove - // any code guarded by if (isNode) { ... } - "if (isNode)": "if (false)" - }), - shim({ - constants: `export default {}`, - fs: `export default {}`, - os: `export default {}`, - dotenv: `export function config() { }`, - path: `export default {}` - }), - nodeResolve({ - mainFields: ["module", "browser"], - preferBuiltins: false - }), - cjs({ - namedExports: { - chai: ["assert"], - ...openTelemetryCommonJs() - } - }), - // disable the plugin in the rollup config to cut-out errors - viz({ filename: "dist-browser/browser-stats.html", sourcemap: false }) - ] - }; - - if (test) { - // Entry points - test files under the `test` folder(common for both browser and node), browser specific test files - baseConfig.input = [ - "dist-esm/test/public/*.spec.js", - "dist-esm/test/internal/*.spec.js", - "dist-esm/test/public/browser/*.spec.js", - "dist-esm/test/internal/browser/*.spec.js" - ]; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - baseConfig.output.file = "dist-test/index.browser.js"; - - baseConfig.onwarn = (warning) => { - if ( - warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) - ) { - // Chai contains circular references, but they are not fatal and can be ignored. - return; - } - - console.error(`(!) ${warning.message}`); - }; - - // 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. - baseConfig.treeshake = false; - } - - return baseConfig; -} diff --git a/sdk/search/search-documents/rollup.config.js b/sdk/search/search-documents/rollup.config.js index 14652aa67ed8..5d7deee44c14 100644 --- a/sdk/search/search-documents/rollup.config.js +++ b/sdk/search/search-documents/rollup.config.js @@ -1,13 +1,3 @@ -import * as base from "./rollup.base.config"; +import { makeConfig } from "@azure/dev-tool/shared-config/rollup"; -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig()); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig()); -} - -export default inputs; +export default makeConfig(require("./package.json")); diff --git a/sdk/search/search-documents/rollup.test.config.js b/sdk/search/search-documents/rollup.test.config.js deleted file mode 100644 index 925a4421a53e..000000000000 --- a/sdk/search/search-documents/rollup.test.config.js +++ /dev/null @@ -1,3 +0,0 @@ -import * as base from "./rollup.base.config"; - -export default [base.nodeConfig(true), base.browserConfig(true)]; diff --git a/sdk/servicebus/service-bus/package.json b/sdk/servicebus/service-bus/package.json index ff515b739209..6a41e00d3286 100644 --- a/sdk/servicebus/service-bus/package.json +++ b/sdk/servicebus/service-bus/package.json @@ -48,8 +48,8 @@ "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", "build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", - "build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c rollup.test.config.js 2>&1", - "build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c rollup.test.config.js 2>&1", + "build:test:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", + "build:test:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", "build:test": "npm run build:test:node && npm run build:test:browser", "build:types": "downlevel-dts types/latest types/3.1", "build": "npm run clean && tsc -p . && rollup -c 2>&1 && npm run extract-api && npm run build:types", @@ -70,7 +70,7 @@ "test:node": "npm run clean && npm run build:test:node && npm run integration-test:node", "test": "npm run test:node && npm run test:browser", "unit-test:browser": "echo skipped", - "unit-test:node": "mocha -r esm -r ts-node/register --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/internal/unit/*.spec.ts\" \"test/internal/node/*.spec.ts\"", + "unit-test:node": "mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 1200000 --full-trace \"test/internal/unit/{,!(browser)/**/}*.spec.ts\"", "unit-test": "npm run unit-test:node && npm run unit-test:browser", "docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src" }, @@ -131,12 +131,6 @@ "@azure/test-utils": "^1.0.0", "@azure/test-utils-perf": "^1.0.0", "@microsoft/api-extractor": "^7.18.11", - "@rollup/plugin-commonjs": "11.0.2", - "@rollup/plugin-inject": "^4.0.0", - "@rollup/plugin-json": "^4.0.0", - "@rollup/plugin-multi-entry": "^3.0.0", - "@rollup/plugin-node-resolve": "^8.0.0", - "@rollup/plugin-replace": "^2.2.0", "@types/chai": "^4.1.6", "@types/chai-as-promised": "^7.1.0", "@types/debug": "^4.1.4", @@ -175,9 +169,6 @@ "puppeteer": "^10.2.0", "rimraf": "^3.0.0", "rollup": "^1.16.3", - "rollup-plugin-shim": "^1.0.0", - "rollup-plugin-sourcemaps": "^0.4.2", - "rollup-plugin-terser": "^5.1.1", "ts-node": "^10.0.0", "typescript": "~4.2.0", "ws": "^7.1.1", diff --git a/sdk/servicebus/service-bus/rollup.base.config.js b/sdk/servicebus/service-bus/rollup.base.config.js deleted file mode 100644 index a2c7e0c7e306..000000000000 --- a/sdk/servicebus/service-bus/rollup.base.config.js +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -import nodeResolve from "@rollup/plugin-node-resolve"; -import multiEntry from "@rollup/plugin-multi-entry"; -import cjs from "@rollup/plugin-commonjs"; -import json from "@rollup/plugin-json"; -import replace from "@rollup/plugin-replace"; -import { terser } from "rollup-plugin-terser"; -import sourcemaps from "rollup-plugin-sourcemaps"; -import shim from "rollup-plugin-shim"; -import path from "path"; -import inject from "@rollup/plugin-inject"; -import { openTelemetryCommonJs } from "@azure/dev-tool/shared-config/rollup"; - -const pkg = require("./package.json"); -const depNames = Object.keys(pkg.dependencies); -const input = "dist-esm/src/index.js"; - -const version = require("./package.json").version; -const banner = [ - "/*!", - ` * Azure Service Bus SDK for JavaScript, ${version}`, - " * Copyright (c) Microsoft and contributors. All rights reserved.", - " */" -].join("\n"); - -const ignoreKnownWarnings = (warning) => { - if (warning.code === "THIS_IS_UNDEFINED") { - // This error happens frequently due to TypeScript emitting `this` at the - // top-level of a module. In this case its fine if it gets rewritten to - // undefined, so ignore this error. - return; - } - - if ( - warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) - ) { - // Chai contains circular references, but they are not fatal and can be ignored. - return; - } - - console.error(`(!) ${warning.message}`); -}; - -export function nodeConfig({ test = false, production = false } = {}) { - const externalNodeBuiltins = ["events", "util", "os"]; - const baseConfig = { - input: input, - external: depNames.concat(externalNodeBuiltins), - output: { file: "dist/index.js", format: "cjs", sourcemap: true }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace({ - delimiters: ["", ""], - // replace dynamic checks with if (true) since this is for node only. - // Allows rollup's dead code elimination to be more aggressive. - "if (isNode)": "if (true)", - "if (!isNode)": "if (false)" - }), - nodeResolve({ preferBuiltins: true }), - cjs(), - json() - ] - }; - - if (test) { - // entry point is every test file - baseConfig.input = [ - "dist-esm/service-bus/test/internal/**/*.spec.js", - "dist-esm/service-bus/test/internal/node/*.spec.js", - "dist-esm/service-bus/test/public/**/*.spec.js" - ]; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - - // different output file - baseConfig.output.file = "dist-test/index.js"; - - // mark assert as external - baseConfig.external.push("assert", "fs", "path", "@azure/identity"); - - baseConfig.onwarn = ignoreKnownWarnings; - - // 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. - baseConfig.treeshake = false; - } else if (production) { - baseConfig.plugins.push(terser()); - } - - return baseConfig; -} - -export function browserConfig(test = false) { - const baseConfig = { - input: input, - external: [], - output: { - file: "dist-browser/service-bus.js", - format: "umd", - name: "Azure.Messaging.ServiceBus", - sourcemap: true - }, - preserveSymlinks: false, - plugins: [ - sourcemaps(), - replace( - // ms-rest-js is externalized so users must include it prior to using this bundle. - { - delimiters: ["", ""], - // replace dynamic checks with if (false) since this is for - // browser only. Rollup's dead code elimination will remove - // any code guarded by if (isNode) { ... } - "if (isNode)": "if (false)", - "if (!isNode)": "if (true)" - } - ), - // fs, net, and tls are used by rhea and need to be shimmed - // dotenv doesn't work in the browser, so replace it with a no-op function - shim({ - fs: `export default {}`, - net: `export default {}`, - tls: `export default {}`, - dotenv: `export function config() { }`, - path: `export default {}`, - dns: `export function resolve() { }`, - glob: `export default {}` - }), - - nodeResolve({ - mainFields: ["module", "browser"], - preferBuiltins: false - }), - cjs({ - namedExports: { - events: ["EventEmitter"], - long: ["ZERO"], - ...openTelemetryCommonJs(), - chai: ["should", "assert"], - assert: ["equal", "deepEqual", "notEqual"] - } - }), - - // rhea and rhea-promise use the Buffer global which requires - // injection to shim properly - inject({ - modules: { - Buffer: ["buffer", "Buffer"], - process: "process" - }, - exclude: ["./**/package.json"] - }), - - json() - ] - }; - - baseConfig.onwarn = ignoreKnownWarnings; - - if (test) { - baseConfig.input = [ - "dist-esm/test/public/**/*.spec.js", - "dist-esm/test/internal/*.spec.js", - "dist-esm/test/internal/unit/*.spec.js" - ]; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - baseConfig.output.file = "dist-test/index.browser.js"; - - // 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. - baseConfig.treeshake = false; - } - - return baseConfig; -} diff --git a/sdk/servicebus/service-bus/rollup.config.js b/sdk/servicebus/service-bus/rollup.config.js index 01f209a32fa8..5d7deee44c14 100644 --- a/sdk/servicebus/service-bus/rollup.config.js +++ b/sdk/servicebus/service-bus/rollup.config.js @@ -1,16 +1,3 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. +import { makeConfig } from "@azure/dev-tool/shared-config/rollup"; -import * as base from "./rollup.base.config"; - -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig()); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig()); -} - -export default inputs; +export default makeConfig(require("./package.json")); diff --git a/sdk/servicebus/service-bus/rollup.test.config.js b/sdk/servicebus/service-bus/rollup.test.config.js deleted file mode 100644 index 48ea762bf9e0..000000000000 --- a/sdk/servicebus/service-bus/rollup.test.config.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -import * as base from "./rollup.base.config"; - -const inputs = []; - -if (!process.env.ONLY_BROWSER) { - inputs.push(base.nodeConfig({ test: true })); -} - -if (!process.env.ONLY_NODE) { - inputs.push(base.browserConfig({ test: true })); -} - -export default inputs;