From 22133f40f50c65e066d9345c75a60c83407c47fa Mon Sep 17 00:00:00 2001 From: Jeff Fisher Date: Tue, 23 Jun 2020 15:30:15 -0700 Subject: [PATCH] [core-client] Create package for AutoRest specific code (#9620) Create a new package we can use for helpers for generated code. --- common/config/rush/pnpm-lock.yaml | 53 ++++++++ dataplane.code-workspace | 4 + rush.json | 5 + sdk/core/core-client/.eslintrc.json | 4 + sdk/core/core-client/.vscode/launch.json | 28 ++++ sdk/core/core-client/.vscode/tasks.json | 16 +++ sdk/core/core-client/CHANGELOG.md | 3 + sdk/core/core-client/LICENSE | 21 +++ sdk/core/core-client/README.md | 35 +++++ sdk/core/core-client/api-extractor.json | 31 +++++ sdk/core/core-client/karma.conf.js | 120 +++++++++++++++++ sdk/core/core-client/package.json | 123 ++++++++++++++++++ .../core-client/review/core-client.api.md | 13 ++ sdk/core/core-client/rollup.base.config.js | 120 +++++++++++++++++ sdk/core/core-client/rollup.config.js | 13 ++ sdk/core/core-client/rollup.test.config.js | 3 + sdk/core/core-client/samples/.gitkeep | 0 sdk/core/core-client/src/index.ts | 6 + sdk/core/core-client/test/helloWorld.spec.ts | 11 ++ sdk/core/core-client/tsconfig.json | 8 ++ 20 files changed, 617 insertions(+) create mode 100644 sdk/core/core-client/.eslintrc.json create mode 100644 sdk/core/core-client/.vscode/launch.json create mode 100644 sdk/core/core-client/.vscode/tasks.json create mode 100644 sdk/core/core-client/CHANGELOG.md create mode 100644 sdk/core/core-client/LICENSE create mode 100644 sdk/core/core-client/README.md create mode 100644 sdk/core/core-client/api-extractor.json create mode 100644 sdk/core/core-client/karma.conf.js create mode 100644 sdk/core/core-client/package.json create mode 100644 sdk/core/core-client/review/core-client.api.md create mode 100644 sdk/core/core-client/rollup.base.config.js create mode 100644 sdk/core/core-client/rollup.config.js create mode 100644 sdk/core/core-client/rollup.test.config.js create mode 100644 sdk/core/core-client/samples/.gitkeep create mode 100644 sdk/core/core-client/src/index.ts create mode 100644 sdk/core/core-client/test/helloWorld.spec.ts create mode 100644 sdk/core/core-client/tsconfig.json diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 023a54c5f66..3421f3d2a4d 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -7,6 +7,7 @@ dependencies: '@rush-temp/core-arm': 'file:projects/core-arm.tgz' '@rush-temp/core-asynciterator-polyfill': 'file:projects/core-asynciterator-polyfill.tgz' '@rush-temp/core-auth': 'file:projects/core-auth.tgz' + '@rush-temp/core-client': 'file:projects/core-client.tgz' '@rush-temp/core-http': 'file:projects/core-http.tgz' '@rush-temp/core-https': 'file:projects/core-https.tgz' '@rush-temp/core-lro': 'file:projects/core-lro.tgz' @@ -7670,6 +7671,57 @@ packages: integrity: sha512-i2QFSjrS1hTQZZZNL5JoYk3cfdydWOs6eZNq6bzRBuhICjXfOHx5TARU8q0VsN4KCfvueMQzuocD6SE5ugVAEA== tarball: 'file:projects/core-auth.tgz' version: 0.0.0 + 'file:projects/core-client.tgz': + dependencies: + '@microsoft/api-extractor': 7.7.11 + '@opentelemetry/api': 0.6.1 + '@rollup/plugin-commonjs': 11.0.2_rollup@1.32.1 + '@rollup/plugin-json': 4.1.0_rollup@1.32.1 + '@rollup/plugin-multi-entry': 3.0.1_rollup@1.32.1 + '@rollup/plugin-node-resolve': 8.0.1_rollup@1.32.1 + '@rollup/plugin-replace': 2.3.3_rollup@1.32.1 + '@types/chai': 4.2.11 + '@types/mocha': 7.0.2 + '@types/node': 8.10.61 + '@typescript-eslint/eslint-plugin': 2.34.0_2ce5ff4d4c428c35a55f8b98c167bebb + '@typescript-eslint/parser': 2.34.0_eslint@6.8.0+typescript@3.9.5 + chai: 4.2.0 + cross-env: 7.0.2 + downlevel-dts: 0.4.0 + eslint: 6.8.0 + eslint-config-prettier: 6.11.0_eslint@6.8.0 + eslint-plugin-no-null: 1.0.2_eslint@6.8.0 + eslint-plugin-no-only-tests: 2.4.0 + eslint-plugin-promise: 4.2.1 + inherits: 2.0.4 + karma: 4.4.1 + karma-chrome-launcher: 3.1.0 + karma-coverage: 2.0.2 + karma-edge-launcher: 0.4.2_karma@4.4.1 + karma-env-preprocessor: 0.1.1 + karma-firefox-launcher: 1.3.0 + karma-ie-launcher: 1.0.0_karma@4.4.1 + karma-junit-reporter: 2.0.1_karma@4.4.1 + karma-mocha: 1.3.0 + karma-mocha-reporter: 2.2.5_karma@4.4.1 + karma-remap-istanbul: 0.6.0_karma@4.4.1 + mocha: 7.2.0 + mocha-junit-reporter: 1.23.3_mocha@7.2.0 + prettier: 1.19.1 + rimraf: 3.0.2 + rollup: 1.32.1 + rollup-plugin-sourcemaps: 0.4.2_rollup@1.32.1 + rollup-plugin-terser: 5.3.0_rollup@1.32.1 + rollup-plugin-visualizer: 4.0.4_rollup@1.32.1 + tslib: 2.0.0 + typescript: 3.9.5 + util: 0.12.3 + dev: false + name: '@rush-temp/core-client' + resolution: + integrity: sha512-YxuXJ37MWTcVyeknL1LwiaHLjoC0PFP2V/CTggVUT6b1LDpJlKnN6Owbw3f1FvBfbrZcniWWneli75KQjfh70w== + tarball: 'file:projects/core-client.tgz' + version: 0.0.0 'file:projects/core-http.tgz': dependencies: '@azure/core-tracing': 1.0.0-preview.8 @@ -9071,6 +9123,7 @@ specifiers: '@rush-temp/core-arm': 'file:./projects/core-arm.tgz' '@rush-temp/core-asynciterator-polyfill': 'file:./projects/core-asynciterator-polyfill.tgz' '@rush-temp/core-auth': 'file:./projects/core-auth.tgz' + '@rush-temp/core-client': 'file:./projects/core-client.tgz' '@rush-temp/core-http': 'file:./projects/core-http.tgz' '@rush-temp/core-https': 'file:./projects/core-https.tgz' '@rush-temp/core-lro': 'file:./projects/core-lro.tgz' diff --git a/dataplane.code-workspace b/dataplane.code-workspace index be77b25efbb..654ff7b37d8 100644 --- a/dataplane.code-workspace +++ b/dataplane.code-workspace @@ -24,6 +24,10 @@ "name": "core-auth", "path": "sdk\\core\\core-auth" }, + { + "name": "core-client", + "path": "sdk\\core\\core-client" + }, { "name": "core-http", "path": "sdk\\core\\core-http" diff --git a/rush.json b/rush.json index 7edfb8faf6d..5649b94406d 100644 --- a/rush.json +++ b/rush.json @@ -367,6 +367,11 @@ "projectFolder": "sdk/core/core-auth", "versionPolicyName": "core" }, + { + "packageName": "@azure/core-client", + "projectFolder": "sdk/core/core-client", + "versionPolicyName": "core" + }, { "packageName": "@azure/core-http", "projectFolder": "sdk/core/core-http", diff --git a/sdk/core/core-client/.eslintrc.json b/sdk/core/core-client/.eslintrc.json new file mode 100644 index 00000000000..47d9fc35be4 --- /dev/null +++ b/sdk/core/core-client/.eslintrc.json @@ -0,0 +1,4 @@ +{ + "plugins": ["@azure/azure-sdk"], + "extends": ["plugin:@azure/azure-sdk/azure-sdk-base"] +} diff --git a/sdk/core/core-client/.vscode/launch.json b/sdk/core/core-client/.vscode/launch.json new file mode 100644 index 00000000000..a48155453e9 --- /dev/null +++ b/sdk/core/core-client/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Current TS File", + "args": ["${fileBasename}"], + "runtimeArgs": ["--nolazy", "-r", "ts-node/register"], + "cwd": "${fileDirname}", + "sourceMaps": true, + "protocol": "inspector" + }, + { + "type": "node", + "request": "launch", + "name": "Run unit tests", + "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", + "args": ["--timeout", "999999", "--colors", "${workspaceFolder}/dist-test/index.node.js"], + "cwd": "${workspaceFolder}", + "internalConsoleOptions": "openOnSessionStart", + "skipFiles": ["/**/async_hooks.js", "/**/*.js"] + } + ] +} diff --git a/sdk/core/core-client/.vscode/tasks.json b/sdk/core/core-client/.vscode/tasks.json new file mode 100644 index 00000000000..83bb44526db --- /dev/null +++ b/sdk/core/core-client/.vscode/tasks.json @@ -0,0 +1,16 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Build Node", + "type": "npm", + "script": "build:node", + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} diff --git a/sdk/core/core-client/CHANGELOG.md b/sdk/core/core-client/CHANGELOG.md new file mode 100644 index 00000000000..b6532e70d7b --- /dev/null +++ b/sdk/core/core-client/CHANGELOG.md @@ -0,0 +1,3 @@ +# Release History + +## 1.0.0.preview.1 (UNRELEASED) diff --git a/sdk/core/core-client/LICENSE b/sdk/core/core-client/LICENSE new file mode 100644 index 00000000000..ea8fb151602 --- /dev/null +++ b/sdk/core/core-client/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/sdk/core/core-client/README.md b/sdk/core/core-client/README.md new file mode 100644 index 00000000000..b8b1c58fb00 --- /dev/null +++ b/sdk/core/core-client/README.md @@ -0,0 +1,35 @@ +# Azure Core Service client library for JavaScript (Experimental) + +This library is primarily intended to be used in code generated by [AutoRest](https://github.com/Azure/Autorest) and [`autorest.typescript`](https://github.com/Azure/autorest.typescript). + +## Getting started + +### Requirements + +- [Node.js](https://nodejs.org) version > 8.x + +### Installation + +This package is primarily used in generated code and not meant to be consumed directly by end users. + +## Key concepts + +TODO: talk about OperationSpec? + +## Examples + +Examples can be found in the `samples` folder. + +## Next steps + +TODO: need some good content here + +## Troubleshooting + +If you run into issues while using this library, please feel free to [file an issue](https://github.com/Azure/azure-sdk-for-js/issues/new). + +## Contributing + +If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test the code. + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcore%2Fcore-client%2FREADME.png) diff --git a/sdk/core/core-client/api-extractor.json b/sdk/core/core-client/api-extractor.json new file mode 100644 index 00000000000..90f948eff0d --- /dev/null +++ b/sdk/core/core-client/api-extractor.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + "mainEntryPointFilePath": "types/latest/src/index.d.ts", + "docModel": { + "enabled": false + }, + "apiReport": { + "enabled": true, + "reportFolder": "./review" + }, + "dtsRollup": { + "enabled": true, + "untrimmedFilePath": "", + "publicTrimmedFilePath": "./types/latest/core-client.d.ts" + }, + "messages": { + "tsdocMessageReporting": { + "default": { + "logLevel": "none" + } + }, + "extractorMessageReporting": { + "ae-missing-release-tag": { + "logLevel": "none" + }, + "ae-unresolved-link": { + "logLevel": "none" + } + } + } +} diff --git a/sdk/core/core-client/karma.conf.js b/sdk/core/core-client/karma.conf.js new file mode 100644 index 00000000000..6c429c6c876 --- /dev/null +++ b/sdk/core/core-client/karma.conf.js @@ -0,0 +1,120 @@ +// https://github.com/karma-runner/karma-chrome-launcher +process.env.CHROME_BIN = require("puppeteer").executablePath(); + +module.exports = function(config) { + config.set({ + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: "./", + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ["mocha"], + + plugins: [ + "karma-mocha", + "karma-mocha-reporter", + "karma-chrome-launcher", + "karma-edge-launcher", + "karma-firefox-launcher", + "karma-ie-launcher", + "karma-env-preprocessor", + "karma-coverage", + "karma-remap-istanbul", + "karma-junit-reporter" + ], + + // list of files / patterns to load in the browser + files: [ + // Uncomment the cdn link below for the polyfill service to support IE11 missing features + // Promise,String.prototype.startsWith,String.prototype.endsWith,String.prototype.repeat,String.prototype.includes,Array.prototype.includes,Object.keys + // "https://cdn.polyfill.io/v2/polyfill.js?features=Symbol,Promise,String.prototype.startsWith,String.prototype.endsWith,String.prototype.repeat,String.prototype.includes,Array.prototype.includes,Object.keys|always", + "dist-test/index.browser.js" + ], + + // list of files / patterns to exclude + exclude: [], + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + "**/*.js": ["env"], + // IMPORTANT: COMMENT following line if you want to debug in your browsers!! + // Preprocess source file to calculate code coverage, however this will make source file unreadable + "test-browser/index.js": ["coverage"] + }, + + // inject following environment values into browser testing with window.__env__ + // environment values MUST be exported or set with same console running "karma start" + // https://www.npmjs.com/package/karma-env-preprocessor + // EXAMPLE: envPreprocessor: ["ACCOUNT_NAME", "ACCOUNT_SAS"], + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ["mocha", "coverage", "karma-remap-istanbul", "junit"], + + coverageReporter: { + // specify a common output directory + dir: "coverage-browser/", + reporters: [{ type: "json", subdir: ".", file: "coverage.json" }] + }, + + remapIstanbulReporter: { + src: "coverage-browser/coverage.json", + reports: { + lcovonly: "coverage-browser/lcov.info", + html: "coverage-browser/html/report", + "text-summary": null, + cobertura: "./coverage-browser/cobertura-coverage.xml" + } + }, + + junitReporter: { + outputDir: "", // results will be saved as $outputDir/$browserName.xml + outputFile: "test-results.browser.xml", // if included, results will be saved as $outputDir/$browserName/$outputFile + suite: "", // suite will become the package name attribute in xml testsuite element + useBrowserName: false, // add browser name to report and classes names + nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element + classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element + properties: {} // key value pair of properties to add to the section of the report + }, + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: false, + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + // 'ChromeHeadless', 'Chrome', 'Firefox', 'Edge', 'IE' + browsers: ["ChromeHeadless"], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: true, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: 1, + + browserNoActivityTimeout: 600000, + browserDisconnectTimeout: 10000, + browserDisconnectTolerance: 3, + + client: { + mocha: { + // change Karma's debug.html to the mocha web reporter + reporter: "html", + timeout: "600000" + } + } + }); +}; diff --git a/sdk/core/core-client/package.json b/sdk/core/core-client/package.json new file mode 100644 index 00000000000..144f52398b0 --- /dev/null +++ b/sdk/core/core-client/package.json @@ -0,0 +1,123 @@ +{ + "name": "@azure/core-client", + "version": "1.0.0-preview.1", + "private": true, + "description": "Core library for interfacing with AutoRest generated code", + "sdk-type": "client", + "main": "dist/index.js", + "module": "dist-esm/src/index.js", + "types": "types/latest/core-client.d.ts", + "typesVersions": { + "<3.6": { + "types/latest/*": [ + "types/3.1/*" + ] + } + }, + "scripts": { + "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", + "build:browser": "npm run build:ts && cross-env ONLY_BROWSER=true rollup -c 2>&1", + "build:node": "npm run build:ts && cross-env ONLY_NODE=true rollup -c 2>&1", + "build:samples": "cd samples && tsc -p .", + "build:test": "npm run build:ts && npm run bundle:test", + "build:test:browser": "npm run build:ts && npm run bundle:test:browser", + "build:test:node": "npm run build:ts && npm run bundle:test:node", + "build:ts": "tsc -p .", + "build:types": "downlevel-dts types/latest/ types/3.1/", + "build": "npm run build:ts && rollup -c 2>&1 && api-extractor run --local && npm run build:types", + "bundle:test": "rollup -c rollup.test.config.js 2>&1", + "bundle:test:browser": "cross-env ONLY_BROWSER=true rollup -c rollup.test.config.js 2>&1", + "bundle:test:node": "cross-env ONLY_NODE=true rollup -c rollup.test.config.js 2>&1", + "check-format": "prettier --list-different \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", + "clean": "rimraf dist dist-* types *.tgz *.log", + "execute:samples": "echo skipped", + "extract-api": "npm run build:ts && api-extractor run --local", + "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"", + "integration-test:browser": "echo skipped", + "integration-test:node": "echo skipped", + "integration-test": "npm run integration-test:node && npm run integration-test:browser", + "lint:fix": "eslint package.json tsconfig.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]", + "lint": "eslint package.json tsconfig.json api-extractor.json src test --ext .ts -f html -o coreClient-lintReport.html || exit 0", + "pack": "npm pack 2>&1", + "prebuild": "npm run clean", + "test:browser": "npm run build:test:browser && npm run unit-test:browser && npm run integration-test:browser", + "test:node": "npm run build:test:node && npm run unit-test:node && npm run integration-test:node", + "test": "npm run clean && npm run build:ts && npm run bundle:test:node && npm run unit-test:node && npm run bundle:test:browser && npm run unit-test:browser && npm run integration-test:node && npm run integration-test:browser", + "unit-test:browser": "karma start --single-run", + "unit-test:node": "mocha --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js dist-test/index.node.js", + "unit-test": "npm run unit-test:node && npm run unit-test:browser" + }, + "files": [ + "dist/", + "dist-esm/src/", + "types/latest/core-client.d.ts", + "types/3.1/core-client.d.ts", + "README.md", + "LICENSE" + ], + "repository": "github:Azure/azure-sdk-for-js", + "keywords": [ + "azure", + "cloud", + "Azure" + ], + "author": "Microsoft Corporation", + "license": "MIT", + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "engines": { + "node": ">=8.0.0" + }, + "homepage": "https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-client/", + "sideEffects": false, + "prettier": "@azure/eslint-plugin-azure-sdk/prettier.json", + "dependencies": { + "@opentelemetry/api": "^0.6.1", + "tslib": "^2.0.0" + }, + "devDependencies": { + "@microsoft/api-extractor": "7.7.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": "^8.0.0", + "@typescript-eslint/eslint-plugin": "^2.0.0", + "@typescript-eslint/parser": "^2.0.0", + "@azure/eslint-plugin-azure-sdk": "^3.0.0", + "chai": "^4.2.0", + "downlevel-dts": "~0.4.0", + "cross-env": "^7.0.2", + "eslint": "^6.1.0", + "eslint-config-prettier": "^6.0.0", + "eslint-plugin-no-null": "^1.0.2", + "eslint-plugin-no-only-tests": "^2.3.0", + "eslint-plugin-promise": "^4.1.1", + "inherits": "^2.0.3", + "karma": "^4.0.1", + "karma-chrome-launcher": "^3.0.0", + "karma-coverage": "^2.0.0", + "karma-edge-launcher": "^0.4.2", + "karma-env-preprocessor": "^0.1.1", + "karma-firefox-launcher": "^1.1.0", + "karma-ie-launcher": "^1.0.0", + "karma-junit-reporter": "^2.0.1", + "karma-mocha": "^1.3.0", + "karma-mocha-reporter": "^2.2.5", + "karma-remap-istanbul": "^0.6.0", + "mocha": "^7.1.1", + "mocha-junit-reporter": "^1.18.0", + "prettier": "^1.16.4", + "rimraf": "^3.0.0", + "rollup": "^1.16.3", + "rollup-plugin-sourcemaps": "^0.4.2", + "rollup-plugin-terser": "^5.1.1", + "rollup-plugin-visualizer": "^4.0.4", + "typescript": "~3.9.3", + "util": "^0.12.1" + } +} diff --git a/sdk/core/core-client/review/core-client.api.md b/sdk/core/core-client/review/core-client.api.md new file mode 100644 index 00000000000..a8292bf6593 --- /dev/null +++ b/sdk/core/core-client/review/core-client.api.md @@ -0,0 +1,13 @@ +## API Report File for "@azure/core-client" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +// @public (undocumented) +export function helloWorld(): string; + + +// (No @packageDocumentation comment for this package) + +``` diff --git a/sdk/core/core-client/rollup.base.config.js b/sdk/core/core-client/rollup.base.config.js new file mode 100644 index 00000000000..434aa86d87d --- /dev/null +++ b/sdk/core/core-client/rollup.base.config.js @@ -0,0 +1,120 @@ +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 { terser } from "rollup-plugin-terser"; +import sourcemaps from "rollup-plugin-sourcemaps"; +import viz from "rollup-plugin-visualizer"; + +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/*.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, + output: { + file: "dist-browser/azure-core-client.js", + format: "umd", + name: "Azure.Core.Client", + sourcemap: true + }, + preserveSymlinks: false, + 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)" + } + }), + nodeResolve({ + mainFields: ["module", "browser"], + preferBuiltins: false + }), + cjs({ + namedExports: { + chai: ["assert"], + "@opentelemetry/api": ["CanonicalCode", "SpanKind", "TraceFlags"] + } + }), + 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/core/core-client/rollup.config.js b/sdk/core/core-client/rollup.config.js new file mode 100644 index 00000000000..14652aa67ed --- /dev/null +++ b/sdk/core/core-client/rollup.config.js @@ -0,0 +1,13 @@ +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; diff --git a/sdk/core/core-client/rollup.test.config.js b/sdk/core/core-client/rollup.test.config.js new file mode 100644 index 00000000000..925a4421a53 --- /dev/null +++ b/sdk/core/core-client/rollup.test.config.js @@ -0,0 +1,3 @@ +import * as base from "./rollup.base.config"; + +export default [base.nodeConfig(true), base.browserConfig(true)]; diff --git a/sdk/core/core-client/samples/.gitkeep b/sdk/core/core-client/samples/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/sdk/core/core-client/src/index.ts b/sdk/core/core-client/src/index.ts new file mode 100644 index 00000000000..2656b82da86 --- /dev/null +++ b/sdk/core/core-client/src/index.ts @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +export function helloWorld(): string { + return "Hello world!"; +} diff --git a/sdk/core/core-client/test/helloWorld.spec.ts b/sdk/core/core-client/test/helloWorld.spec.ts new file mode 100644 index 00000000000..57a39c76b11 --- /dev/null +++ b/sdk/core/core-client/test/helloWorld.spec.ts @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { assert } from "chai"; +import { helloWorld } from "../src"; + +describe("helloWorld", () => { + it("returns hello world", () => { + assert.strictEqual(helloWorld(), "Hello world!"); + }); +}); diff --git a/sdk/core/core-client/tsconfig.json b/sdk/core/core-client/tsconfig.json new file mode 100644 index 00000000000..4a53cc51141 --- /dev/null +++ b/sdk/core/core-client/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../../tsconfig.package", + "compilerOptions": { + "outDir": "./dist-esm", + "declarationDir": "./types/latest" + }, + "exclude": ["node_modules", "types", "temp", "browser", "dist", "dist-esm", "./samples/**/*.ts"] +}