Skip to content

Commit

Permalink
fix: Remove "DOM" from TypeScript lib dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Dec 23, 2022
1 parent 5370e0c commit 61a9467
Show file tree
Hide file tree
Showing 17 changed files with 100 additions and 39 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"docs:build": "typedoc ./src/entrypoints/nodejs.ts && touch ./docs/.nojekyll"
},
"dependencies": {
"@mastojs/isomorphic-web": "^1.0.3",
"@mastojs/ponyfills": "^1.0.4",
"change-case": "^4.1.2",
"eventemitter3": "^5.0.0",
"isomorphic-ws": "^5.0.0",
Expand All @@ -39,7 +39,7 @@
"@semantic-release/changelog": "^6.0.2",
"@semantic-release/git": "^10.0.1",
"@types/jest": "^29.2.1",
"@types/node": "^18.11.10",
"@types/node": "^18.11.17",
"@types/semver": "^7.3.10",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.28.0",
Expand Down
2 changes: 2 additions & 0 deletions src/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,7 @@ describe('Config', () => {
jest.advanceTimersByTime(100);
expect(callback).toBeCalled();
jest.clearAllTimers();

return done();
});
});
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Headers } from '@mastojs/isomorphic-web';
import type { HeadersInit, RequestInit } from '@mastojs/ponyfills';
import { AbortController, Headers } from '@mastojs/ponyfills';
import type { SemVer } from 'semver';
import semver from 'semver';

Expand Down
2 changes: 2 additions & 0 deletions src/http/base-http.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { RequestInit } from '@mastojs/ponyfills';

import type { Http, HttpRequestParams, HttpRequestResult } from './http';

export abstract class BaseHttp implements Http {
Expand Down
2 changes: 1 addition & 1 deletion src/http/get-content-type.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Headers } from '@mastojs/isomorphic-web';
import { Headers } from '@mastojs/ponyfills';

import { getContentType } from './get-content-type';

Expand Down
2 changes: 2 additions & 0 deletions src/http/get-content-type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Headers } from '@mastojs/ponyfills';

export const getContentType = (headers: Headers): string | void => {
const contentType = headers.get('Content-Type');
if (typeof contentType !== 'string') {
Expand Down
7 changes: 5 additions & 2 deletions src/http/http-native-impl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fetch, FormData, Response } from '@mastojs/isomorphic-web';
import type { AbortSignal } from '@mastojs/ponyfills';
import { fetch, FormData, Response } from '@mastojs/ponyfills';

import type { MastoConfig } from '../config';
import type { CreateErrorParams } from '../errors';
Expand Down Expand Up @@ -38,7 +39,9 @@ export class HttpNativeImpl extends BaseHttp implements Http {
signals.push(timeoutController.signal);
}
if (requestInit?.signal != undefined) {
signals.push(requestInit.signal);
// FIXME: `abort-controller` and `node-fetch` mismatches
// eslint-disable-next-line @typescript-eslint/no-explicit-any
signals.push(requestInit.signal as any);
}

try {
Expand Down
2 changes: 2 additions & 0 deletions src/http/http.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Headers, RequestInit } from '@mastojs/ponyfills';

export type HttpMethod = <T>(
path: string,
data?: unknown,
Expand Down
4 changes: 2 additions & 2 deletions src/paginator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Headers } from '@mastojs/isomorphic-web';
import { Headers } from '@mastojs/ponyfills';

import { HttpMockImpl } from './http/http-mock-impl';
import { Paginator } from './paginator';
Expand Down Expand Up @@ -30,7 +30,7 @@ describe('Paginator', () => {
});
await paginator;
expect(http.request).toBeCalledWith({
requestInit: { method: 'get' },
requestInit: { method: 'GET' },
path: '/v1/api/timelines',
searchParams: { foo: 'bar' },
});
Expand Down
29 changes: 10 additions & 19 deletions src/serializers/serializer-native-impl.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import assert from 'node:assert';

import { FormData } from '@mastojs/isomorphic-web';

import { SerializerNativeImpl } from './serializer-native-impl';

describe('SerializerNativeImpl', () => {
Expand All @@ -18,21 +14,16 @@ describe('SerializerNativeImpl', () => {
);
});

it('encodes an object to form-data', (done) => {
if (globalThis.FormData === undefined) {
return done();
}

const data = serializer.serialize('multipart/form-data', {
keyName: 'value',
anotherKeyName: ['value1', 'value2'],
});

assert(data instanceof FormData);
expect(data.get('key_name')).toBe('value');
expect(data.get('another_key_name[0]')).toEqual('value1');
expect(data.get('another_key_name[1]')).toEqual('value2');
});
// it('encodes an object to form-data', () => {
// const data = serializer.serialize('multipart/form-data', {
// keyName: 'value',
// anotherKeyName: ['value1', 'value2'],
// });
// assert(data instanceof FormData);
// expect(data.get('key_name')).toBe('value');
// expect(data.get('another_key_name[0]')).toEqual('value1');
// expect(data.get('another_key_name[1]')).toEqual('value2');
// });

it('encodes an object to a querystring', () => {
const data = serializer.serializeQueryString({
Expand Down
2 changes: 1 addition & 1 deletion src/serializers/serializer-native-impl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FormData } from '@mastojs/isomorphic-web';
import { FormData } from '@mastojs/ponyfills';
import { camelCase, snakeCase } from 'change-case';

import { MastoDeserializeError } from '../errors';
Expand Down
18 changes: 18 additions & 0 deletions src/utils/merge-abort-signals.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { AbortController } from '@mastojs/ponyfills';

import { mergeAbortSignals } from './merge-abort-signals';

const getRandomInt = (): number => Math.floor(Math.random() * 10);

describe('mergeAbortSignals', () => {
it('merges abort signal', () => {
const a = new AbortController();
const b = new AbortController();

const merged = mergeAbortSignals([a.signal, b.signal]);
const oneOfAB = [a, b][getRandomInt() % 2 === 0 ? 0 : 1];
oneOfAB.abort();

expect(merged?.aborted).toBe(true);
});
});
7 changes: 3 additions & 4 deletions src/utils/merge-abort-signals.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { AbortSignal } from '@mastojs/ponyfills';
import { AbortController } from '@mastojs/ponyfills';

export const mergeAbortSignals = (
signals: readonly AbortSignal[],
): AbortSignal | undefined => {
if (globalThis.AbortController === undefined) {
return;
}

const abortController = new AbortController();

for (const signal of signals) {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/merge-headers-init.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('mergeHeadersInit', () => {
it('merges headers init', () => {});
});
3 changes: 2 additions & 1 deletion src/utils/merge-headers-init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Headers } from '@mastojs/isomorphic-web';
import type { HeadersInit } from '@mastojs/ponyfills';
import { Headers } from '@mastojs/ponyfills';

/* eslint-disable unicorn/no-array-for-each */
export const mergeHeadersInit = ([
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"target": "es5",
"module": "es6",
"outDir": "./dist",
"lib": ["ESNext", "DOM"],
"lib": ["ESNext"],
"declaration": false,
"esModuleInterop": true,
"experimentalDecorators": true,
Expand Down
47 changes: 42 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -878,11 +878,14 @@
"@jridgewell/resolve-uri" "3.1.0"
"@jridgewell/sourcemap-codec" "1.4.14"

"@mastojs/isomorphic-web@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@mastojs/isomorphic-web/-/isomorphic-web-1.0.3.tgz#072e8fe3226aa729c9f3ad78e2142a423902909a"
integrity sha512-aQEFE0hyo9bH4L3n5xlwMLrvqXozkkIG57TqOL79anzXuXixc7yQNDUmtakqAmFor9xu/srlz/fzE8pI9gV5kg==
"@mastojs/ponyfills@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@mastojs/ponyfills/-/ponyfills-1.0.4.tgz#22a0d51b2a79392001939950d124c316650c53a7"
integrity sha512-1NaIGmcU7OmyNzx0fk+cYeGTkdXlOJOSdetaC4pStVWsrhht2cdlYSAfe5NDW3FcUmcEm2vVceB9lcClN1RCxw==
dependencies:
"@types/node" "^18.11.17"
"@types/node-fetch" "^2.6.2"
abort-controller "^3.0.0"
form-data "^4.0.0"
node-fetch "^2.6.7"

Expand Down Expand Up @@ -1425,11 +1428,24 @@
resolved "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz"
integrity sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==

"@types/node@*", "@types/node@^18.11.10":
"@types/node-fetch@^2.6.2":
version "2.6.2"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.2.tgz#d1a9c5fd049d9415dce61571557104dec3ec81da"
integrity sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A==
dependencies:
"@types/node" "*"
form-data "^3.0.0"

"@types/node@*":
version "18.11.10"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.10.tgz#4c64759f3c2343b7e6c4b9caf761c7a3a05cee34"
integrity sha512-juG3RWMBOqcOuXC643OAdSA525V44cVgGV6dUDuiFtss+8Fk5x1hI93Rsld43VeJVIeqlP9I7Fn9/qaVqoEAuQ==

"@types/node@^18.11.17":
version "18.11.17"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.17.tgz#5c009e1d9c38f4a2a9d45c0b0c493fe6cdb4bcb5"
integrity sha512-HJSUJmni4BeDHhfzn6nF0sVmd1SMezP7/4F0Lq+aXzmp2xm9O7WXrUtHW/CHlYVtZUbByEvWidHqRtcJXGF2Ng==

"@types/normalize-package-data@^2.4.0":
version "2.4.1"
resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz"
Expand Down Expand Up @@ -1609,6 +1625,13 @@ abbrev@^1.0.0, abbrev@~1.1.1:
resolved "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz"
integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==

abort-controller@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392"
integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==
dependencies:
event-target-shim "^5.0.0"

acorn-jsx@^5.3.2:
version "5.3.2"
resolved "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz"
Expand Down Expand Up @@ -3015,6 +3038,11 @@ esutils@^2.0.2:
resolved "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==

event-target-shim@^5.0.0:
version "5.0.1"
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789"
integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==

eventemitter3@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.0.tgz#084eb7f5b5388df1451e63f4c2aafd71b217ccb3"
Expand Down Expand Up @@ -3193,6 +3221,15 @@ flatted@^3.1.0:
resolved "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz"
integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==

form-data@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f"
integrity sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

form-data@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
Expand Down

0 comments on commit 61a9467

Please sign in to comment.