summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2021-04-13 09:11:19 -0700
committerMatthew Miller <matthew@millerti.me>2021-04-13 09:11:19 -0700
commit59678bff70b388f9237b05748a6cad3d65c3c20f (patch)
tree0cd0ded462003fb69ce2231da6eb181c7dc993b9
parente6557e2c1afaf357098972b9850883ab1a554fd3 (diff)
parent8d48bfdc574ec6f616f3264c767a16f4fcf2086f (diff)
Merge branch 'master' into fix/issue-111-cert-hExtV-parse-error
-rw-r--r--.gitignore1
-rw-r--r--CHANGELOG.md13
-rw-r--r--example/public/login/index.html2
-rw-r--r--example/public/register/index.html2
-rw-r--r--lerna.json2
-rw-r--r--packages/browser/.npmignore2
-rw-r--r--packages/browser/README.md95
-rw-r--r--packages/browser/package.json23
-rw-r--r--packages/browser/rollup.config.js115
-rw-r--r--packages/browser/tsconfig.es5.json29
-rw-r--r--packages/browser/tsconfig.json20
-rw-r--r--packages/browser/webpack.config.js45
-rw-r--r--packages/server/package.json2
13 files changed, 284 insertions, 67 deletions
diff --git a/.gitignore b/.gitignore
index 3db653e..9c2be68 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@ coverage/
.DS_Store
docs/
.env
+.idea
example/*.key
example/*.crt
example/fido-conformance-mds/*
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a146df1..93cee18 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,18 @@
# Changelog
+## v2.2.1
+
+**Packges:**
+
+- @simplewebauthn/browser@2.2.1
+- @simplewebauthn/server@2.2.1
+
+**Changes:**
+
+- **[browser]** Adds support for older browsers (IE10/IE11, Edge Legacy, etc...) with additional build artifacts targeting ES5
+ - See updated "Installation" and "Building for Production" sections of the [README.md](https://github.com/MasterKale/SimpleWebAuthn/blob/master/packages/browser/README.md)
+- **[server]** Internal code cleanup
+
## v2.2.0
**Packages:**
diff --git a/example/public/login/index.html b/example/public/login/index.html
index 413911d..5fa709e 100644
--- a/example/public/login/index.html
+++ b/example/public/login/index.html
@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <script src="https://unpkg.com/@simplewebauthn/browser@2.1.0/dist/simplewebauthn-browser.min.js"></script>
+ <script src="https://unpkg.com/@simplewebauthn/browser/dist/es5/index.umd.min.js"></script>W
<link rel="stylesheet" href="../styles.css" />
<title>SimpleWebAuthn Example Site | Login</title>
</head>
diff --git a/example/public/register/index.html b/example/public/register/index.html
index ee16e2b..c5d065d 100644
--- a/example/public/register/index.html
+++ b/example/public/register/index.html
@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <script src="https://unpkg.com/@simplewebauthn/browser@2.1.0/dist/simplewebauthn-browser.min.js"></script>
+ <script src="https://unpkg.com/@simplewebauthn/browser/dist/es5/index.umd.min.js"></script>W
<link rel="stylesheet" href="../styles.css" />
<title>SimpleWebAuthn Example Site | Register</title>
</head>
diff --git a/lerna.json b/lerna.json
index a1bfcc8..b61b61a 100644
--- a/lerna.json
+++ b/lerna.json
@@ -1,5 +1,5 @@
{
- "version": "2.2.0",
+ "version": "2.2.1",
"npmClient": "npm",
"command": {
"publish": {
diff --git a/packages/browser/.npmignore b/packages/browser/.npmignore
index d2360e9..2674962 100644
--- a/packages/browser/.npmignore
+++ b/packages/browser/.npmignore
@@ -2,6 +2,6 @@ src
node_modules
coverage
.gitignore
-tsconfig.json
+tsconfig.*
*.config.js
__mocks__
diff --git a/packages/browser/README.md b/packages/browser/README.md
index cc1e25b..563dd2d 100644
--- a/packages/browser/README.md
+++ b/packages/browser/README.md
@@ -1,13 +1,22 @@
<!-- omit in toc -->
+
# @simplewebauthn/browser
![WebAuthn](https://img.shields.io/badge/WebAuthn-Simplified-blueviolet?style=for-the-badge&logo=WebAuthn)
[![npm (scoped)](https://img.shields.io/npm/v/@simplewebauthn/browser?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@simplewebauthn/browser)
-![Browser Support](https://img.shields.io/badge/Browser-ES2018+-brightgreen?style=for-the-badge&logo=Mozilla+Firefox)
+![Browser Support](https://img.shields.io/badge/Browser-ES5+-brightgreen?style=for-the-badge&logo=Mozilla+Firefox)
-- [Installation](#installation)
- - [UMD](#umd)
-- [Usage](#usage)
+- [@simplewebauthn/browser](#simplewebauthnbrowser)
+ - [Installation](#installation)
+ - [UMD](#umd)
+ - [ES2018](#es2018)
+ - [ES5](#es5)
+ - [Usage](#usage)
+ - [Building for Production](#building-for-production)
+ - [ES2018](#es2018-1)
+ - [ES5](#es5-1)
+ - [Webpack support](#webpack-support)
+ - [Rollup support](#rollup-support)
## Installation
@@ -19,14 +28,86 @@ npm install @simplewebauthn/browser
### UMD
-This package can also be installed via **unpkg** by including the following script in your page's `<head>` element:
+This package can also be installed via **unpkg** by including the following script in your page's `<head>` element. The library's methods will be available on the global **`SimpleWebAuthnBrowser`** object.
+
+> NOTE: The only difference between the two packages below is that the ES5 bundle includes TypeScript's `tslib` runtime code. This adds some bundle size overhead, but _does_ enable use of `supportsWebAuthn()` in older browsers to show appropriate UI when WebAuthn is unavailable.
+
+#### ES2018
+
+If you only need to support modern browsers, include the `ES2018` version:
```html
-<script src="https://unpkg.com/@simplewebauthn/browser/dist/simplewebauthn-browser.min.js"></script>
+
+<script src="https://unpkg.com/@simplewebauthn/browser/dist/es2018/index.umd.min.js"></script>
```
-The library's methods will be available on the global `SimpleWebAuthnBrowser` object.
+#### ES5
+
+If you need to support WebAuthn feature detection in deprecated browsers like IE11 and Edge Legacy, include the `ES5` version:
+
+```html
+
+<script src="https://unpkg.com/@simplewebauthn/browser/dist/es5/index.umd.min.js"></script>
+```
## Usage
You can find in-depth documentation on this package here: https://simplewebauthn.dev/docs/packages/browser
+
+## Building for Production
+
+Two unbundled versions of this library are offered for your convenience, one targeting `ES2018` and a second targeting `ES5`.
+
+### ES2018
+
+The `ES2018` version is suitable for use when only **modern browsers** need to be supported. TypeScript and JavaScript codebases alike can import and use this library without any special build configuration considerations.
+
+### ES5
+
+The `ES5` version can also be used in both TypeScript and JavaScript codebases. However, you will need to ensure that your bundler pulls in the ES5 version of the library when building your application!
+
+You will also need to ensure that the `tslib` dependency gets pulled into your build artifact:
+
+- If you are authoring your application in TypeScript then this package will be **automatically** included so long as your **tsconfig.json** sets `"target": "ES5"`.
+- If your application is written in Javascript then you will need to install this package **manually** by adding it to `dependencies` in your project's **package. json**:
+
+```sh
+$> npm install tslib
+```
+
+#### Webpack support
+
+If your Webpack config's `"target"` is set to `"web"` ([the default value](https://webpack.js.org/configuration/target/)) then you're done - Webpack will pull in the ES5 build from the `"browser"` property in @simplewebauthn/browser's **package.json**.
+
+If you've set a different value for `"target"`, though, then you'll need to indicate additional files for WebPack to resolve via the [`"resolve.mainFields"`](https://webpack.js.org/configuration/resolve/#resolvemainfields) property in your Webpack config:
+
+```js
+module.exports = {
+ //...
+ resolve: {
+ mainFields: [ 'browser', 'module', 'main' ],
+ },
+};
+```
+
+`'browser'` must come first in the list to ensure that the `ES5` version of this library is bundled. Additional values can be added afterwards as needed.
+
+#### Rollup support
+
+The [`@rollup/plugin-node-resolve`](https://github.com/rollup/rollup-plugin-node-resolve#usage) plugin can be added to your Rollup config to read in the `browser` entry from @simplewebauthn/browser's **package.json**:
+
+```js
+// rollup.config.js
+import resolve from 'rollup-plugin-node-resolve';
+
+export default {
+ // input: ...
+ // output: ...
+ plugins: [
+ //...
+ resolve({ mainFields: [ 'browser', 'module', 'main' ] }),
+ ]
+}
+```
+
+`'browser'` must come first in the list to ensure that the `ES5` version of this library is bundled. Additional values can be added afterwards as needed.
diff --git a/packages/browser/package.json b/packages/browser/package.json
index 1eaabea..3524ce6 100644
--- a/packages/browser/package.json
+++ b/packages/browser/package.json
@@ -1,9 +1,10 @@
{
"name": "@simplewebauthn/browser",
- "version": "2.1.0",
+ "version": "2.2.1",
"description": "SimpleWebAuthn for Browsers",
- "main": "dist/simplewebauthn-browser.min.js",
- "types": "dist/index.d.ts",
+ "main": "dist/es2018/index.js",
+ "browser": "dist/es5/index.js",
+ "types": "dist/types/index.d.ts",
"author": "Matthew Miller <matthew@millerti.me>",
"license": "MIT",
"repository": {
@@ -16,7 +17,7 @@
"access": "public"
},
"scripts": {
- "build": "rimraf dist && webpack",
+ "build": "rimraf dist && rollup -c",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "npm test -- --coverage",
@@ -28,12 +29,18 @@
"fido",
"umd"
],
+ "peerDependencies": {
+ "tslib": "^2.2.0"
+ },
"devDependencies": {
+ "@rollup/plugin-commonjs": "^18.0.0",
+ "@rollup/plugin-node-resolve": "^11.2.1",
+ "@rollup/plugin-typescript": "^8.2.1",
"@simplewebauthn/typescript-types": "file:../typescript-types",
- "ts-loader": "^7.0.5",
- "webpack": "^4.44.0",
- "webpack-auto-inject-version": "^1.2.2",
- "webpack-cli": "^3.3.12"
+ "rollup": "^2.44.0",
+ "rollup-plugin-terser": "^7.0.2",
+ "rollup-plugin-version-injector": "^1.3.2",
+ "tslib": "^2.2.0"
},
"gitHead": "33ccf8c6c9add811c87d3089e24156c2342b3498"
}
diff --git a/packages/browser/rollup.config.js b/packages/browser/rollup.config.js
new file mode 100644
index 0000000..3428748
--- /dev/null
+++ b/packages/browser/rollup.config.js
@@ -0,0 +1,115 @@
+import typescript from '@rollup/plugin-typescript';
+import commonjs from '@rollup/plugin-commonjs';
+import nodeResolve from '@rollup/plugin-node-resolve';
+import { terser } from 'rollup-plugin-terser';
+// import versionInjector from 'rollup-plugin-version-injector';
+
+/**
+ * Rollup plugin to clean `tslib` comment in `UMD` bundle targeting `ES5`
+ */
+const cleanTslibCommentInUMDBundleTargetingES5 = () => {
+ return {
+ name: 'cleanTslibCommentInUMDBundleTargetingES5',
+ renderChunk: async code => {
+ const comment = `
+/*! *****************************************************************************
+\tCopyright (c) Microsoft Corporation.
+
+\tPermission to use, copy, modify, and/or distribute this software for any
+\tpurpose with or without fee is hereby granted.
+
+\tTHE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+\tREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+\tAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+\tINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+\tLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+\tOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+\tPERFORMANCE OF THIS SOFTWARE.
+\t***************************************************************************** */
+`;
+ return code.indexOf(comment) > -1 ? code.replace(comment, '') : null;
+ },
+ };
+};
+
+/**
+ * Re-enable version injection when this gets resolved:
+ *
+ * https://github.com/djhouseknecht/rollup-plugin-version-injector/issues/22
+ *
+ * To avoid a repeat of the first half of this:
+ *
+ * https://github.com/MasterKale/SimpleWebAuthn/issues/56
+ */
+// const swanVersionInjector = versionInjector({
+// injectInComments: {
+// fileRegexp: /\.(js)$/,
+// // [@simplewebauthn/browser] Version: 2.1.0 - Saturday, February 6th, 2021, 4:10:31 PM
+// tag: '[@simplewebauthn/browser] Version: {version} - {date}',
+// dateFormat: 'dddd, mmmm dS, yyyy, h:MM:ss TT',
+// },
+// });
+
+/**
+ * Rollup configuration to generate the following:
+ * - ES2018 bundle
+ * - ES5 bundle
+ * - Type declarations
+ */
+export default [
+ {
+ input: 'src/index.ts',
+ output: [
+ {
+ dir: 'dist',
+ format: 'esm',
+ entryFileNames: 'es2018/[name].js',
+ preferConst: true,
+ },
+ {
+ dir: 'dist',
+ format: 'umd',
+ name: 'SimpleWebAuthnBrowser',
+ entryFileNames: 'es2018/[name].umd.min.js',
+ plugins: [terser()],
+ },
+ ],
+ plugins: [
+ typescript({ tsconfig: './tsconfig.json' }),
+ nodeResolve(),
+ // swanVersionInjector,
+ ],
+ },
+ {
+ input: 'src/index.ts',
+ output: {
+ dir: 'dist',
+ format: 'cjs',
+ entryFileNames: 'es5/[name].js',
+ exports: 'auto',
+ },
+ plugins: [
+ typescript({ tsconfig: './tsconfig.es5.json' }),
+ commonjs({ extensions: ['.ts'] }),
+ nodeResolve(),
+ // swanVersionInjector,
+ ],
+ external: ['tslib'],
+ },
+ {
+ input: 'src/index.ts',
+ output: {
+ dir: 'dist',
+ format: 'umd',
+ name: 'SimpleWebAuthnBrowser',
+ entryFileNames: 'es5/[name].umd.min.js',
+ plugins: [terser(), cleanTslibCommentInUMDBundleTargetingES5()],
+ },
+ plugins: [
+ typescript({ tsconfig: './tsconfig.es5.json' }),
+ commonjs({ extensions: ['.ts'] }),
+ nodeResolve(),
+ // swanVersionInjector,
+ ],
+ },
+];
diff --git a/packages/browser/tsconfig.es5.json b/packages/browser/tsconfig.es5.json
new file mode 100644
index 0000000..3d1a328
--- /dev/null
+++ b/packages/browser/tsconfig.es5.json
@@ -0,0 +1,29 @@
+{
+ "extends": "./tsconfig.json",
+ "compilerOptions": {
+ "target": "ES5",
+ "module": "COMMONJS",
+ "moduleResolution": "node",
+ "lib": [
+ "ES5",
+ "DOM"
+ ],
+ "baseUrl": "./src",
+ "declaration": false,
+ "declarationDir": null,
+ "declarationMap": false,
+ "downlevelIteration": true,
+ "removeComments": true,
+ "sourceMap": false,
+ "importHelpers": true,
+ "noEmit": true
+ },
+ "include": [
+ "./src/**/*.ts"
+ ],
+ "exclude": [
+ "./src/**/*.test.ts",
+ "./src/setupTests.ts",
+ "./src/**/__mocks__"
+ ]
+}
diff --git a/packages/browser/tsconfig.json b/packages/browser/tsconfig.json
index 8b6f0a5..aec3091 100644
--- a/packages/browser/tsconfig.json
+++ b/packages/browser/tsconfig.json
@@ -1,11 +1,27 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
+ "target": "ES2018",
+ "module": "ES2020",
+ "moduleResolution": "node",
"lib": [
"ES2018",
"DOM"
],
"baseUrl": "./src",
- "outDir": "./dist"
- }
+ "declaration": true,
+ "declarationDir": "./dist/types",
+ "declarationMap": false,
+ "removeComments": true,
+ "sourceMap": false,
+ "noEmit": true,
+ },
+ "include": [
+ "./src/**/*.ts"
+ ],
+ "exclude": [
+ "./src/**/*.test.ts",
+ "./src/setupTests.ts",
+ "./src/**/__mocks__"
+ ]
}
diff --git a/packages/browser/webpack.config.js b/packages/browser/webpack.config.js
deleted file mode 100644
index 1c060c3..0000000
--- a/packages/browser/webpack.config.js
+++ /dev/null
@@ -1,45 +0,0 @@
-const path = require('path');
-const WebpackAutoInject = require('webpack-auto-inject-version');
-
-const packageJSON = require('./package.json');
-const outputPath = path.resolve(__dirname, 'dist');
-
-module.exports = {
- entry: './src/index.ts',
- mode: 'production',
- devtool: 'source-map',
- module: {
- rules: [
- {
- test: /.ts$/,
- use: 'ts-loader',
- exclude: /node_modules/,
- },
- ],
- },
- resolve: {
- extensions: ['.ts', '.js'],
- },
- output: {
- path: outputPath,
- filename: 'simplewebauthn-browser.min.js',
- library: 'SimpleWebAuthnBrowser',
- libraryTarget: 'umd',
- globalObject: 'this',
- },
- plugins: [
- new WebpackAutoInject({
- SHORT: packageJSON.name,
- PACKAGE_JSON_INDENT: 2,
- components: {
- AutoIncreaseVersion: false,
- },
- componentsOptions: {
- InjectAsComment: {
- tag: 'Version: {version} - {date}',
- multiLineCommentType: true,
- },
- },
- }),
- ],
-};
diff --git a/packages/server/package.json b/packages/server/package.json
index a8c06a8..cb41a43 100644
--- a/packages/server/package.json
+++ b/packages/server/package.json
@@ -1,6 +1,6 @@
{
"name": "@simplewebauthn/server",
- "version": "2.2.0",
+ "version": "2.2.1",
"description": "SimpleWebAuthn for Servers",
"main": "dist/index.js",
"types": "dist/index.d.ts",