Skip to content

Commit

Permalink
Switch to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
evert committed Sep 12, 2024
1 parent ee9ef50 commit 7042061
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dist/build: ${SOURCE_FILES}
./node_modules/.bin/tsc
touch dist/build

browser/oauth2-client.min.js: ${SOURCE_FILES}
browser/oauth2-client.min.js: ${SOURCE_FILES} webpack.config.js
mkdir -p browser
./node_modules/.bin/webpack

Expand Down
8 changes: 4 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OAuth2Token } from './token';
import { OAuth2Token } from './token.js';
import {
AuthorizationCodeRequest,
ClientCredentialsRequest,
Expand All @@ -10,9 +10,9 @@ import {
RevocationRequest,
ServerMetadataResponse,
TokenResponse,
} from './messages';
import { OAuth2HttpError } from './error';
import { OAuth2AuthorizationCodeClient } from './client/authorization-code';
} from './messages.js';
import { OAuth2HttpError } from './error.js';
import { OAuth2AuthorizationCodeClient } from './client/authorization-code.js';


type ClientCredentialsParams = {
Expand Down
12 changes: 6 additions & 6 deletions src/client/authorization-code.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OAuth2Client } from '../client';
import { OAuth2Token } from '../token';
import { AuthorizationCodeRequest } from '../messages';
import { OAuth2Error } from '../error';
import { OAuth2Client } from '../client.js';
import { OAuth2Token } from '../token.js';
import { AuthorizationCodeRequest } from '../messages.js';
import { OAuth2Error } from '../error.js';

type GetAuthorizeUrlParams = {
/**
Expand Down Expand Up @@ -238,8 +238,8 @@ async function getWebCrypto(): Promise<typeof window.crypto> {
}
// Node
// eslint-disable-next-line @typescript-eslint/no-var-requires
const crypto = require('crypto');
return crypto.webcrypto;
const crypto = await import('crypto');
return crypto.webcrypto as typeof window.crypto;

}

Expand Down
2 changes: 1 addition & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OAuth2ErrorCode } from './messages';
import { OAuth2ErrorCode } from './messages.js';

/**
* An error class for any error the server emits.
Expand Down
4 changes: 2 additions & 2 deletions src/fetch-wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OAuth2Token } from './token';
import { OAuth2Client } from './client';
import { OAuth2Token } from './token.js';
import { OAuth2Client } from './client.js';

type FetchMiddleware = (request: Request, next: (request: Request) => Promise<Response>) => Promise<Response>;

Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { OAuth2Client } from './client';
export { OAuth2AuthorizationCodeClient, generateCodeVerifier } from './client/authorization-code';
export { OAuth2Fetch } from './fetch-wrapper';
export { OAuth2Token } from './token';
export { OAuth2Error, OAuth2HttpError } from './error';
export { OAuth2Client } from './client.js';
export { OAuth2AuthorizationCodeClient, generateCodeVerifier } from './client/authorization-code.js';
export { OAuth2Fetch } from './fetch-wrapper.js';
export { OAuth2Error, OAuth2HttpError } from './error.js';

export { IntrospectionResponse } from './messages';
export type { IntrospectionResponse } from './messages.js';
export type { OAuth2Token } from './token.js';
12 changes: 9 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ export default [
output: {
path: import.meta.dirname + '/browser',
filename: 'oauth2-client.min.js',
library: 'OAuth2Client',
libraryTarget: 'umd'
library: {
type: 'module',
},
},
experiments: {
outputModule: true,
},

resolve: {
extensionAlias: {
'.js': ['.ts', '.js']
},
extensions: ['.web.ts', '.web.js', '.ts', '.js', '.json'],
fallback: { 'crypto': false }
},
Expand Down

0 comments on commit 7042061

Please sign in to comment.