Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit 93d20f8

Browse files
dkowismbyczkowski
authored andcommitted
Package using UMD to make it work in a Typescript/Webpack project (#125)
* Fix #93. I can use the NPM package in a Typescript/Webpack project Changed the library type to UMD. > libraryTarget: 'umd' - This exposes your library under all the module definitions, allowing it to work with CommonJS, AMD and as global variable. from https://webpack.js.org/configuration/output/#outputlibrarytarget
1 parent 8aa145f commit 93d20f8

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

jose-jwe-jws.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ interface IHeaders {
9494
interface IUtils {
9595
importRsaPublicKey(rsa_key: JWKRSA, alg: JoseAlgorithm): PromiseLike<CryptoKey>;
9696
importRsaPrivateKey(rsa_key: JWKRSA, alg: JoseAlgorithm): PromiseLike<CryptoKey>;
97+
importPublicKey(key: IJsonWebKey, alg: JoseAlgorithm): PromiseLike<CryptoKey>;
9798
}
9899

99100
interface IJose {
@@ -147,6 +148,10 @@ interface IJoseJWE {
147148
Decrypter: IDecrypter;
148149
}
149150

151+
interface Window {
152+
Jose: IJose;
153+
}
154+
150155
declare function setCrypto(cryptoProvider: Crypto): void;
151156
declare const Jose: IJose;
152157
declare var crypto: Crypto;

lib/jose-core.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ const JoseJWS = {
4545
Verifier
4646
};
4747

48-
const Jose = { JoseJWS, JoseJWE, WebCryptographer };
49-
50-
export default { Jose, WebCryptographer };
51-
export { Jose, JoseJWE, JoseJWS, WebCryptographer };
52-
5348
/**
5449
* Set crypto provider to use (window.crypto, node-webcrypto-ossl, node-webcrypto-pkcs11 etc.).
5550
*/
@@ -69,6 +64,11 @@ if (typeof window !== 'undefined') {
6964
}
7065
}
7166

67+
const Jose = { JoseJWS, JoseJWE, WebCryptographer, crypto, Utils };
68+
69+
export default { Jose, WebCryptographer };
70+
export { Jose, JoseJWE, JoseJWS, WebCryptographer };
71+
7272
/**
7373
* Use Node versions of atob, btoa functions outside the browser
7474
*/

lib/jose-jwe-webcryptographer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616

1717
// TODO(eslint): figure out how to properly include Jose or expose crypto object
18-
/* global Jose */
1918

2019
import * as Utils from './jose-utils';
20+
import { Jose } from './jose-core';
2121

2222
/**
2323
* The WebCryptographer uses http://www.w3.org/TR/WebCryptoAPI/ to perform

lib/jose-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616

1717
// TODO(eslint): figure out how to properly include Jose or expose crypto object
18-
/* global Jose */
1918

2019
import { WebCryptographer } from './jose-jwe-webcryptographer';
20+
import { Jose } from './jose-core';
2121
const webCryptographer = new WebCryptographer();
2222

2323
/**

webpack.prod.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ module.exports = {
1818

1919
output: {
2020
filename: 'jose.min.js',
21-
library:'Jose',
22-
libraryTarget: 'var',
21+
library: 'Jose',
22+
libraryTarget: 'umd',
2323
path: path.resolve(__dirname, 'dist')
2424
},
2525

@@ -40,4 +40,4 @@ module.exports = {
4040
name: true
4141
}
4242
}
43-
}
43+
}

0 commit comments

Comments
 (0)