-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[Identity] Enable @azure/identity to build for the browser #4165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7ee57e1
Move credential-specific auth code to individual classes
daviwil 21b5ed2
Don't include ClientCertificateCredential in browser build
daviwil 5ef989e
Set tsconfig target back to ES5 to enable Rollup browser build
daviwil e906a20
Add @azure/identity browser tests
daviwil 1e207d6
Stub ManagedIdentityCredential and EnvironmentCredential in the browser
daviwil d2409bd
Reorder public/private methods to make eslint happy
daviwil 08b4ba4
Use rollup-plugin-terser to handle ES6 classes in minification
daviwil b34f53d
Configure Karma for singleRun
daviwil 45b093b
Remove unneeded Karma launcher dependencies
daviwil 6c95764
Lift helper methods that don't need to be class methods
daviwil 4f3d20f
Minor Rollup config cleanup
daviwil bf83958
Throw errors from browser-unsupported credential types
daviwil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| // https://github.com/karma-runner/karma-chrome-launcher | ||
| process.env.CHROME_BIN = require("puppeteer").executablePath(); | ||
| require("dotenv").config({ path: "../.env" }); | ||
|
|
||
| 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-coverage", | ||
| "karma-junit-reporter", | ||
| "karma-json-to-file-reporter", | ||
| "karma-json-preprocessor" | ||
| ], | ||
|
|
||
| // list of files / patterns to load in the browser | ||
| files: [ | ||
| // polyfill service supporting 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", | ||
| "test-browser/index.js", | ||
| "recordings/browsers/**/*.json" | ||
| ], | ||
|
|
||
| // 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"], | ||
| "recordings/browsers/**/*.json": ["json"] | ||
| }, | ||
|
|
||
| // 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 | ||
| envPreprocessor: ["ACCOUNT_NAME", "ACCOUNT_SAS", "TEST_MODE"], | ||
|
|
||
| // test results reporter to use | ||
| // possible values: 'dots', 'progress' | ||
| // available reporters: https://npmjs.org/browse/keyword/karma-reporter | ||
| reporters: ["mocha", "coverage", "remap-coverage", "junit", "json-to-file"], | ||
|
|
||
| coverageReporter: { type: "in-memory" }, | ||
|
|
||
| // Coverage report settings | ||
| remapCoverageReporter: { | ||
| "text-summary": null, // to show summary in console | ||
| html: "./coverage-browser", | ||
| cobertura: "./coverage-browser/cobertura-coverage.xml" | ||
| }, | ||
|
|
||
| // Exclude coverage calculation for following files | ||
| remapOptions: { | ||
| exclude: /node_modules|test/g | ||
| }, | ||
|
|
||
| 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 <properties> section of the report | ||
| }, | ||
|
|
||
| jsonToFileReporter: { | ||
| filter: function(obj) { | ||
| if (obj.writeFile) { | ||
| const fs = require("fs-extra"); | ||
| // Create the directories recursively incase they don't exist | ||
| try { | ||
| // Stripping away the filename from the file path and retaining the directory structure | ||
| fs.ensureDirSync(obj.path.substring(0, obj.path.lastIndexOf("/") + 1)); | ||
| } catch (err) { | ||
| if (err.code !== "EEXIST") throw err; | ||
| } | ||
| fs.writeFile(obj.path, JSON.stringify(obj.content, null, " "), (err) => { | ||
| if (err) { | ||
| throw err; | ||
| } | ||
| }); | ||
| } | ||
| return false; | ||
| }, | ||
| outputPath: "." | ||
| }, | ||
|
|
||
| // 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, | ||
| browserConsoleLogOptions: { | ||
| // IMPORTANT: COMMENT the following line if you want to print debug logs in your browsers in record mode!! | ||
| terminal: process.env.TEST_MODE !== "record" | ||
| }, | ||
|
|
||
| client: { | ||
| mocha: { | ||
| // change Karma's debug.html to the mocha web reporter | ||
| reporter: "html", | ||
| timeout: "600000" | ||
| } | ||
| } | ||
| }); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ 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 { uglify } from "rollup-plugin-uglify"; | ||
| import { terser } from "rollup-plugin-terser"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change required for the other sdks?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably so, I'll open a separate PR to make that change everywhere then we can decide whether to merge it. |
||
| import sourcemaps from "rollup-plugin-sourcemaps"; | ||
| import viz from "rollup-plugin-visualizer"; | ||
|
|
||
|
|
@@ -36,6 +36,7 @@ export function nodeConfig(test = false) { | |
| if (test) { | ||
| // entry point is every test file | ||
| baseConfig.input = "dist-esm/test/**/*.spec.js"; | ||
| baseConfig.input = ["dist-esm/test/*.spec.js", "dist-esm/test/node/*.spec.js"]; | ||
| baseConfig.plugins.unshift(multiEntry({ exports: false })); | ||
|
|
||
| // different output file | ||
|
|
@@ -49,7 +50,7 @@ export function nodeConfig(test = false) { | |
| // applies to test code, which causes all tests to be removed by tree-shaking. | ||
| baseConfig.treeshake = false; | ||
| } else if (production) { | ||
| baseConfig.plugins.push(uglify()); | ||
| baseConfig.plugins.push(terser()); | ||
| } | ||
|
|
||
| return baseConfig; | ||
|
|
@@ -58,13 +59,11 @@ export function nodeConfig(test = false) { | |
| export function browserConfig(test = false, production = false) { | ||
| const baseConfig = { | ||
| input: input, | ||
| external: ["@azure/ms-rest-js"], | ||
| output: { | ||
| file: "browser/identity.js", | ||
| format: "umd", | ||
| name: "ExampleClient", | ||
| sourcemap: true, | ||
| globals: { "@azure/ms-rest-js": "msRest" } | ||
| name: "Azure.Identity", | ||
| sourcemap: true | ||
| }, | ||
| preserveSymlinks: false, | ||
| plugins: [ | ||
|
|
@@ -93,7 +92,7 @@ export function browserConfig(test = false, production = false) { | |
| }; | ||
|
|
||
| if (test) { | ||
| baseConfig.input = "dist-esm/test/**/*.spec.js"; | ||
| baseConfig.input = "dist-esm/test/*.spec.js"; | ||
|
daviwil marked this conversation as resolved.
|
||
| baseConfig.plugins.unshift(multiEntry({ exports: false })); | ||
| baseConfig.output.file = "test-browser/index.js"; | ||
|
|
||
|
|
@@ -103,7 +102,7 @@ export function browserConfig(test = false, production = false) { | |
| baseConfig.treeshake = false; | ||
| } else if (production) { | ||
| baseConfig.output.file = "browser/identity.min.js"; | ||
| baseConfig.plugins.push(uglify()); | ||
| baseConfig.plugins.push(terser()); | ||
| } | ||
|
|
||
| return baseConfig; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.