Skip to content

Commit

Permalink
chore: convert project source to ESM (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
wKovacs64 committed Nov 4, 2023
1 parent 799669b commit c4ca77a
Show file tree
Hide file tree
Showing 36 changed files with 164 additions and 164 deletions.
80 changes: 0 additions & 80 deletions .bundlewatch.config.js

This file was deleted.

80 changes: 80 additions & 0 deletions .bundlewatch.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"files": [
{
"//": "Pre-bundled for Browser (UMD)",
"path": "dist/browser/hibp.umd.js",
"maxSize": "8.9 kB"
},
{
"//": "Pre-bundled for Browser (ESM)",
"path": "dist/browser/hibp.module.js",
"maxSize": "4.9 kB"
},
{
"//": "Bundled with Webpack (CJS)",
"path": "dist/cjs/breach.js",
"maxSize": "1 kB"
},
{
"path": "dist/cjs/breached-account.js",
"maxSize": "1.2 kB"
},
{
"path": "dist/cjs/breaches.js",
"maxSize": "1 kB"
},
{
"path": "dist/cjs/data-classes.js",
"maxSize": "1 kB"
},
{
"path": "dist/cjs/paste-account.js",
"maxSize": "1.1 kB"
},
{
"path": "dist/cjs/pwned-password.js",
"maxSize": "1.1 kB"
},
{
"path": "dist/cjs/pwned-password-range.js",
"maxSize": "1.3 kB"
},
{
"path": "dist/cjs/search.js",
"maxSize": "1.5 kB"
},
{
"//": "Bundled with Webpack (ESM)",
"path": "dist/esm/breach.mjs",
"maxSize": "1 kB"
},
{
"path": "dist/esm/breached-account.mjs",
"maxSize": "1.1 kB"
},
{
"path": "dist/esm/breaches.mjs",
"maxSize": "1 kB"
},
{
"path": "dist/esm/data-classes.mjs",
"maxSize": "1 kB"
},
{
"path": "dist/esm/paste-account.mjs",
"maxSize": "1 kB"
},
{
"path": "dist/esm/pwned-password.mjs",
"maxSize": "1 kB"
},
{
"path": "dist/esm/pwned-password-range.mjs",
"maxSize": "1.3 kB"
},
{
"path": "dist/esm/search.mjs",
"maxSize": "1.4 kB"
}
]
}
File renamed without changes.
2 changes: 1 addition & 1 deletion .github/workflows/bundlewatch-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ jobs:
- uses: bahmutov/npm-install@v1
- uses: jackyef/bundlewatch-gh-action@0.2.1
with:
bundlewatch-config: .bundlewatch.config.js
bundlewatch-config: .bundlewatch.config.json
bundlewatch-github-token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/bundlewatch-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
- uses: jackyef/bundlewatch-gh-action@0.2.1
with:
branch-base: main
bundlewatch-config: .bundlewatch.config.js
bundlewatch-config: .bundlewatch.config.json
bundlewatch-github-token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"./package.json": "./package.json"
},
"type": "module",
"main": "dist/cjs/hibp.js",
"module": "dist/esm/hibp.mjs",
"unpkg": "dist/browser/hibp.umd.js",
Expand Down Expand Up @@ -55,7 +56,7 @@
"prebuild": "npm run --silent clean",
"prepare": "npm run --silent build",
"prepublishOnly": "run-s --silent lint typecheck test test:browser:run",
"size": "bundlewatch --config .bundlewatch.config.js",
"size": "bundlewatch --config .bundlewatch.config.json",
"test": "vitest run",
"test:coverage": "vitest run --coverage",
"pretest:browser:open": "npm run --silent build:lib",
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/browser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable import/no-extraneous-dependencies */
import { test, expect } from '@playwright/test';
import type * as hibp from '../../src/hibp';
import type * as hibp from '../../src/hibp.js';

declare global {
interface Window {
Expand Down
6 changes: 2 additions & 4 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const prettierConfig = require('@wkovacs64/prettier-config');
import prettierConfig from '@wkovacs64/prettier-config';

module.exports = {
...prettierConfig,
};
export default prettierConfig;
File renamed without changes.
3 changes: 2 additions & 1 deletion scripts/fix-api-docs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs');
import fs from 'node:fs';

const filename = 'API.md';
const generatedApiDocs = fs.readFileSync(filename, 'utf8');
Expand All @@ -14,4 +14,5 @@ const newApiDocs = generatedApiDocs
/(Promise\.<Array\.<([A-Z].*)>>)/g,
(_match, g1, g2) => `<a href="#${g2.toLowerCase()}--object">${g1}</a>`,
);

fs.writeFileSync(filename, newApiDocs, 'utf8');
8 changes: 4 additions & 4 deletions src/__tests__/breach.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { http } from 'msw';
import { server } from '../mocks/server';
import { VERIFIED_BREACH } from '../../test/fixtures';
import { NOT_FOUND } from '../api/haveibeenpwned/responses';
import { breach } from '../breach';
import { server } from '../mocks/server.js';
import { VERIFIED_BREACH } from '../../test/fixtures.js';
import { NOT_FOUND } from '../api/haveibeenpwned/responses.js';
import { breach } from '../breach.js';

describe('breach', () => {
describe('found', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/breached-account.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { http } from 'msw';
import { server } from '../mocks/server';
import { VERIFIED_BREACH, UNVERIFIED_BREACH } from '../../test/fixtures';
import { UNAUTHORIZED } from '../api/haveibeenpwned/responses';
import type { ErrorData } from '../api/haveibeenpwned/types';
import { breachedAccount } from '../breached-account';
import { server } from '../mocks/server.js';
import { VERIFIED_BREACH, UNVERIFIED_BREACH } from '../../test/fixtures.js';
import { UNAUTHORIZED } from '../api/haveibeenpwned/responses.js';
import type { ErrorData } from '../api/haveibeenpwned/types.js';
import { breachedAccount } from '../breached-account.js';

describe('breachedAccount', () => {
const apiKey = 'my-api-key';
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/breaches.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { http } from 'msw';
import { server } from '../mocks/server';
import { VERIFIED_BREACH } from '../../test/fixtures';
import { breaches } from '../breaches';
import { server } from '../mocks/server.js';
import { VERIFIED_BREACH } from '../../test/fixtures.js';
import { breaches } from '../breaches.js';

describe('breaches', () => {
const BREACHES = [VERIFIED_BREACH];
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/data-classes.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { http } from 'msw';
import { server } from '../mocks/server';
import { dataClasses } from '../data-classes';
import { server } from '../mocks/server.js';
import { dataClasses } from '../data-classes.js';

describe('dataClasses', () => {
const DATA_CLASSES = ['some', 'data', 'classes'];
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/hibp.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as hibp from '../hibp';
import * as hibp from '../hibp.js';

describe('hibp', () => {
it('exports an object containing the advertised functions', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/paste-account.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { http } from 'msw';
import { server } from '../mocks/server';
import { EXAMPLE_PASTE } from '../../test/fixtures';
import { NOT_FOUND, UNAUTHORIZED } from '../api/haveibeenpwned/responses';
import type { ErrorData } from '../api/haveibeenpwned/types';
import { pasteAccount } from '../paste-account';
import { server } from '../mocks/server.js';
import { EXAMPLE_PASTE } from '../../test/fixtures.js';
import { NOT_FOUND, UNAUTHORIZED } from '../api/haveibeenpwned/responses.js';
import type { ErrorData } from '../api/haveibeenpwned/types.js';
import { pasteAccount } from '../paste-account.js';

describe('pasteAccount', () => {
const PASTE_ACCOUNT_DATA = [EXAMPLE_PASTE];
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/pwned-password-range.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { http } from 'msw';
import { server } from '../mocks/server';
import { EXAMPLE_PASSWORD_HASHES } from '../../test/fixtures';
import { pwnedPasswordRange } from '../pwned-password-range';
import { server } from '../mocks/server.js';
import { EXAMPLE_PASSWORD_HASHES } from '../../test/fixtures.js';
import { pwnedPasswordRange } from '../pwned-password-range.js';

describe('pwnedPasswordRange', () => {
describe('valid range', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/pwned-password.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { http } from 'msw';
import { server } from '../mocks/server';
import { EXAMPLE_PASSWORD_HASHES } from '../../test/fixtures';
import { pwnedPassword } from '../pwned-password';
import { server } from '../mocks/server.js';
import { EXAMPLE_PASSWORD_HASHES } from '../../test/fixtures.js';
import { pwnedPassword } from '../pwned-password.js';

describe('pwnedPassword', () => {
describe('pwned', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/search.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { http } from 'msw';
import { server } from '../mocks/server';
import { VERIFIED_BREACH, EXAMPLE_PASTE } from '../../test/fixtures';
import { search } from '../search';
import { UNAUTHORIZED } from '../api/haveibeenpwned/responses';
import type { ErrorData } from '../api/haveibeenpwned/types';
import { server } from '../mocks/server.js';
import { VERIFIED_BREACH, EXAMPLE_PASTE } from '../../test/fixtures.js';
import { search } from '../search.js';
import { UNAUTHORIZED } from '../api/haveibeenpwned/responses.js';
import type { ErrorData } from '../api/haveibeenpwned/types.js';

describe('search', () => {
const BREACHES = [{ Name: VERIFIED_BREACH.Name }];
Expand Down
6 changes: 3 additions & 3 deletions src/api/haveibeenpwned/__tests__/fetch-from-api.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { http } from 'msw';
import { server } from '../../../mocks/server';
import { server } from '../../../mocks/server.js';
import {
OK,
BAD_REQUEST,
UNAUTHORIZED,
FORBIDDEN,
BLOCKED,
TOO_MANY_REQUESTS,
} from '../responses';
import { fetchFromApi } from '../fetch-from-api';
} from '../responses.js';
import { fetchFromApi } from '../fetch-from-api.js';

describe('internal (haveibeenpwned): fetchFromApi', () => {
const apiKey = 'my-api-key';
Expand Down
6 changes: 3 additions & 3 deletions src/api/haveibeenpwned/fetch-from-api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import fetch from '../web-fetch';
import fetch from '../web-fetch.js';
import { name, version } from '../../../package.json';
import {
BAD_REQUEST,
UNAUTHORIZED,
FORBIDDEN,
NOT_FOUND,
TOO_MANY_REQUESTS,
} from './responses';
import type { ApiData, ErrorData } from './types';
} from './responses.js';
import type { ApiData, ErrorData } from './types.js';

/**
* Custom error thrown when the haveibeenpwned.com API responds with 429 Too
Expand Down
2 changes: 1 addition & 1 deletion src/api/haveibeenpwned/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* descriptive error for the consumer. (They are also leveraged in our tests.)
*/

import type { ResponseBody } from './types';
import type { ResponseBody } from './types.js';

/** @internal */
export interface HaveIBeenPwnedApiResponse {
Expand Down
6 changes: 3 additions & 3 deletions src/api/pwnedpasswords/__tests__/fetch-from-api.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { http } from 'msw';
import { server } from '../../../mocks/server';
import { BAD_REQUEST, OK } from '../responses';
import { fetchFromApi } from '../fetch-from-api';
import { server } from '../../../mocks/server.js';
import { BAD_REQUEST, OK } from '../responses.js';
import { fetchFromApi } from '../fetch-from-api.js';

describe('internal (pwnedpassword): fetchFromApi', () => {
describe('request failure', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/api/pwnedpasswords/fetch-from-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fetch from '../web-fetch';
import { BAD_REQUEST } from './responses';
import fetch from '../web-fetch.js';
import { BAD_REQUEST } from './responses.js';

/**
* Fetches data from the supplied API endpoint.
Expand Down
4 changes: 2 additions & 2 deletions src/breach.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Breach } from './api/haveibeenpwned/types';
import { fetchFromApi } from './api/haveibeenpwned/fetch-from-api';
import type { Breach } from './api/haveibeenpwned/types.js';
import { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';

/**
* An object representing a breach.
Expand Down
Loading

0 comments on commit c4ca77a

Please sign in to comment.