From 9d8546a60b1872824dfde15c954d651768656375 Mon Sep 17 00:00:00 2001 From: Maor Leger Date: Mon, 13 Dec 2021 11:40:37 -0800 Subject: [PATCH] migrate web-pubsub --- .../testing-recorder-new/package.json | 11 +- .../rollup.base.config.js | 118 ------------------ .../testing-recorder-new/rollup.config.js | 18 +-- .../rollup.test.config.js | 6 - .../web-pubsub-express/package.json | 13 +- .../web-pubsub-express/rollup.base.config.js | 56 --------- .../web-pubsub-express/rollup.config.js | 4 +- .../web-pubsub-express/rollup.test.config.js | 3 - sdk/web-pubsub/web-pubsub/package.json | 13 +- .../web-pubsub/rollup.base.config.js | 56 --------- sdk/web-pubsub/web-pubsub/rollup.config.js | 4 +- .../web-pubsub/rollup.test.config.js | 3 - sdk/web-pubsub/web-pubsub/tsconfig.json | 4 + 13 files changed, 16 insertions(+), 293 deletions(-) delete mode 100644 sdk/test-utils/testing-recorder-new/rollup.base.config.js delete mode 100644 sdk/test-utils/testing-recorder-new/rollup.test.config.js delete mode 100644 sdk/web-pubsub/web-pubsub-express/rollup.base.config.js delete mode 100644 sdk/web-pubsub/web-pubsub-express/rollup.test.config.js delete mode 100644 sdk/web-pubsub/web-pubsub/rollup.base.config.js delete mode 100644 sdk/web-pubsub/web-pubsub/rollup.test.config.js diff --git a/sdk/test-utils/testing-recorder-new/package.json b/sdk/test-utils/testing-recorder-new/package.json index 42c1f5189228..36e4d55e62d4 100644 --- a/sdk/test-utils/testing-recorder-new/package.json +++ b/sdk/test-utils/testing-recorder-new/package.json @@ -12,7 +12,7 @@ "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", "build:samples": "echo Skipped.", "build:test": "tsc -p .", - "build": "npm run clean && tsc -p . && rollup -c rollup.test.config.js 2>&1", + "build": "npm run clean && tsc -p . && rollup -c 2>&1", "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", "clean": "rimraf dist dist-esm test-dist types *.tgz", "extract-api": "echo skipped", @@ -56,6 +56,7 @@ "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/test-utils/recorder/", "sideEffects": false, "private": true, + "dependencies": {}, "devDependencies": { "@azure/core-util": "^1.0.0-beta.1", "@azure/identity": "^2.0.1", @@ -65,10 +66,6 @@ "@azure/storage-queue": "^12.6.0", "@azure/dev-tool": "^1.0.0", "@azure/eslint-plugin-azure-sdk": "^3.0.0", - "@rollup/plugin-commonjs": "11.0.2", - "@rollup/plugin-multi-entry": "^3.0.0", - "@rollup/plugin-node-resolve": "^8.0.0", - "@rollup/plugin-replace": "^2.2.0", "@types/fs-extra": "^8.0.0", "@types/chai": "^4.1.6", "@types/md5": "^2.2.0", @@ -102,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", "xhr-mock": "^2.4.1", "uuid": "^8.3.0", diff --git a/sdk/test-utils/testing-recorder-new/rollup.base.config.js b/sdk/test-utils/testing-recorder-new/rollup.base.config.js deleted file mode 100644 index 53e2408d9480..000000000000 --- a/sdk/test-utils/testing-recorder-new/rollup.base.config.js +++ /dev/null @@ -1,118 +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 replace from "@rollup/plugin-replace"; -import sourcemaps from "rollup-plugin-sourcemaps"; -import shim from "rollup-plugin-shim"; -import * as path from "path"; -// import visualizer from "rollup-plugin-visualizer"; -import { openTelemetryCommonJs } from "@azure/dev-tool/shared-config/rollup"; - -const version = require("./package.json").version; -const banner = [ - "/*!", - ` * Azure Storage SDK for JavaScript - Blob, ${version}`, - " * Copyright (c) Microsoft and contributors. All rights reserved.", - " */" -].join("\n"); - -export function browserConfig(test = false) { - const baseConfig = { - input: "dist-esm/src/index.js", - output: { - file: "dist-browser/azure-testing-recorder-new.js", - banner: banner, - format: "umd", - name: "azblob", - 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)", - "if (!isNode)": "if (true)" - }), - // fs and os are not used by the browser bundle, so just shim it - // dotenv doesn't work in the browser, so replace it with a no-op function - shim({ - dotenv: `export function config() { }`, - fs: ` - export function stat() { } - export function createReadStream() { } - export function createWriteStream() { } - `, - os: ` - export const type = 1; - export const release = 1; - `, - util: ` - export function promisify() { } - ` - }), - nodeResolve({ - mainFields: ["module", "browser"], - preferBuiltins: false - }), - cjs({ - namedExports: { - events: ["EventEmitter"], - assert: [ - "ok", - "deepEqual", - "equal", - "fail", - "strictEqual", - "deepStrictEqual", - "notDeepEqual", - "notDeepStrictEqual" - ], - ...openTelemetryCommonJs() - } - }) - ], - onwarn(warning, warn) { - if ( - warning.code === "CIRCULAR_DEPENDENCY" && - warning.importer.indexOf(path.normalize("node_modules/@opentelemetry/api")) >= 0 - ) { - // opentelemetry contains circular references but it doesn't cause issues. - return; - } - - if ( - warning.code === "CIRCULAR_DEPENDENCY" || - warning.code === "UNRESOLVED_IMPORT" - // Unresolved imports in the browser may break apps with frameworks such as angular. - // Shim the modules with dummy src files for browser to avoid regressions. - ) { - throw new Error(warning.message); - } - warn(warning); - } - }; - - if (test) { - baseConfig.input = ["dist-esm/test/*.spec.js"]; - baseConfig.plugins.unshift(multiEntry({ exports: false })); - baseConfig.output.file = "dist-test/index.browser.js"; - - baseConfig.external = []; - - baseConfig.context = "null"; - - // 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/test-utils/testing-recorder-new/rollup.config.js b/sdk/test-utils/testing-recorder-new/rollup.config.js index fd25a0257a1f..5d7deee44c14 100644 --- a/sdk/test-utils/testing-recorder-new/rollup.config.js +++ b/sdk/test-utils/testing-recorder-new/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")); diff --git a/sdk/test-utils/testing-recorder-new/rollup.test.config.js b/sdk/test-utils/testing-recorder-new/rollup.test.config.js deleted file mode 100644 index 01cc4b90cb6a..000000000000 --- a/sdk/test-utils/testing-recorder-new/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.browserConfig(true)]; diff --git a/sdk/web-pubsub/web-pubsub-express/package.json b/sdk/web-pubsub/web-pubsub-express/package.json index 10febe5e5a01..ce287163fb20 100644 --- a/sdk/web-pubsub/web-pubsub-express/package.json +++ b/sdk/web-pubsub/web-pubsub-express/package.json @@ -11,7 +11,7 @@ "build:browser": "echo \"Browser is not supported.\" && exit 0", "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}\"", "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", @@ -28,7 +28,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": "echo \"Browser is not supported.\" && exit 0", - "unit-test:node": "mocha --reporter ../../../common/tools/mocha-multi-reporter.js dist-test/index.node.js", + "unit-test:node": "mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace \"test/{,!(browser)/**/}*.spec.ts\"", "unit-test": "npm run unit-test:node && npm run unit-test:browser" }, "files": [ @@ -64,11 +64,6 @@ "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@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/express": "^4.16.0", "@types/express-serve-static-core": "^4.17.19", @@ -101,10 +96,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", - "rollup-plugin-visualizer": "^4.0.4", "sinon": "^9.0.2", "source-map-support": "^0.5.9", "typescript": "~4.2.0" diff --git a/sdk/web-pubsub/web-pubsub-express/rollup.base.config.js b/sdk/web-pubsub/web-pubsub-express/rollup.base.config.js deleted file mode 100644 index 5a3f2152c8fe..000000000000 --- a/sdk/web-pubsub/web-pubsub-express/rollup.base.config.js +++ /dev/null @@ -1,56 +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"; - -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", "url", "express", "cloudevents"]; - 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/*.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; -} diff --git a/sdk/web-pubsub/web-pubsub-express/rollup.config.js b/sdk/web-pubsub/web-pubsub-express/rollup.config.js index 5ee6d226a64c..5d7deee44c14 100644 --- a/sdk/web-pubsub/web-pubsub-express/rollup.config.js +++ b/sdk/web-pubsub/web-pubsub-express/rollup.config.js @@ -1,3 +1,3 @@ -import * as base from "./rollup.base.config"; +import { makeConfig } from "@azure/dev-tool/shared-config/rollup"; -export default [base.nodeConfig()]; +export default makeConfig(require("./package.json")); diff --git a/sdk/web-pubsub/web-pubsub-express/rollup.test.config.js b/sdk/web-pubsub/web-pubsub-express/rollup.test.config.js deleted file mode 100644 index c6723abed962..000000000000 --- a/sdk/web-pubsub/web-pubsub-express/rollup.test.config.js +++ /dev/null @@ -1,3 +0,0 @@ -import * as base from "./rollup.base.config"; - -export default [base.nodeConfig(true)]; diff --git a/sdk/web-pubsub/web-pubsub/package.json b/sdk/web-pubsub/web-pubsub/package.json index d30a26d9c7f9..619e00b77487 100644 --- a/sdk/web-pubsub/web-pubsub/package.json +++ b/sdk/web-pubsub/web-pubsub/package.json @@ -11,7 +11,7 @@ "build:browser": "echo \"Browser is not supported.\" && exit 0", "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}\"", "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", @@ -28,7 +28,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": "echo \"Browser is not supported.\" && exit 0", - "unit-test:node": "mocha --exit --reporter ../../../common/tools/mocha-multi-reporter.js dist-test/index.node.js", + "unit-test:node": "mocha --exit -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace \"test/{,!(browser)/**/}*.spec.ts\"", "unit-test": "npm run unit-test:node && npm run unit-test:browser" }, "files": [ @@ -84,11 +84,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/jsonwebtoken": "~8.5.0", "@types/mocha": "^7.0.2", @@ -120,10 +115,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", - "rollup-plugin-visualizer": "^4.0.4", "sinon": "^9.0.2", "source-map-support": "^0.5.9", "typescript": "~4.2.0", diff --git a/sdk/web-pubsub/web-pubsub/rollup.base.config.js b/sdk/web-pubsub/web-pubsub/rollup.base.config.js deleted file mode 100644 index 77044b6d4db0..000000000000 --- a/sdk/web-pubsub/web-pubsub/rollup.base.config.js +++ /dev/null @@ -1,56 +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"; - -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", "url"]; - 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/*.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; -} diff --git a/sdk/web-pubsub/web-pubsub/rollup.config.js b/sdk/web-pubsub/web-pubsub/rollup.config.js index 5ee6d226a64c..5d7deee44c14 100644 --- a/sdk/web-pubsub/web-pubsub/rollup.config.js +++ b/sdk/web-pubsub/web-pubsub/rollup.config.js @@ -1,3 +1,3 @@ -import * as base from "./rollup.base.config"; +import { makeConfig } from "@azure/dev-tool/shared-config/rollup"; -export default [base.nodeConfig()]; +export default makeConfig(require("./package.json")); diff --git a/sdk/web-pubsub/web-pubsub/rollup.test.config.js b/sdk/web-pubsub/web-pubsub/rollup.test.config.js deleted file mode 100644 index c6723abed962..000000000000 --- a/sdk/web-pubsub/web-pubsub/rollup.test.config.js +++ /dev/null @@ -1,3 +0,0 @@ -import * as base from "./rollup.base.config"; - -export default [base.nodeConfig(true)]; diff --git a/sdk/web-pubsub/web-pubsub/tsconfig.json b/sdk/web-pubsub/web-pubsub/tsconfig.json index f76b300ce16b..a371cd3f2ad8 100644 --- a/sdk/web-pubsub/web-pubsub/tsconfig.json +++ b/sdk/web-pubsub/web-pubsub/tsconfig.json @@ -7,5 +7,9 @@ "@azure/web-pubsub": ["./src/index"] } }, + // Ensure dom.d.ts file is loaded when running mocha tests + "ts-node": { + "files": true + }, "include": ["src/**/*.ts", "test/**/*.ts", "samples-dev/**/*.ts"] }