Skip to content

Commit

Permalink
Remove utils dependency to Node types (#7286)
Browse files Browse the repository at this point in the history
  • Loading branch information
qtiki authored and bigtimebuddy committed Mar 15, 2021
1 parent 5f392a3 commit bd5bae0
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
1 change: 0 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@pixi/constants": "6.0.0",
"@pixi/settings": "6.0.0",
"@types/earcut": "^2.1.0",
"@types/node": "^12.0.0",
"earcut": "^2.2.2",
"eventemitter3": "^3.1.0",
"url": "^0.11.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export { EventEmitter };
*/
export { default as earcut } from 'earcut';

import { parse, format, resolve } from 'url';
import { parse, format, resolve } from './url';

/**
* Node.js compatible URL utilities.
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/network/determineCrossOrigin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _url from 'url';
import * as _url from '../url';

let tempAnchor: HTMLAnchorElement|undefined;

Expand Down
76 changes: 76 additions & 0 deletions packages/utils/src/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* This file contains redeclared types for Node `url` and `querystring` modules. These modules
* don't provide their own typings but instead are a part of the full Node typings. The purpose of
* this file is to redeclare the required types to avoid having the whole Node types as a
* dependency.
*/

import { parse as _parse, format as _format, resolve as _resolve } from 'url';

export interface ParsedUrlQuery {
[key: string]: string | string[];
}

export interface ParsedUrlQueryInput {
[key: string]: unknown;
}

export interface UrlObjectCommon {
auth?: string;
hash?: string;
host?: string;
hostname?: string;
href?: string;
path?: string;
pathname?: string;
protocol?: string;
search?: string;
slashes?: boolean;
}

// Input to `url.format`
export interface UrlObject extends UrlObjectCommon {
port?: string | number;
query?: string | null | ParsedUrlQueryInput;
}

// Output of `url.parse`
export interface Url extends UrlObjectCommon {
port?: string;
query?: string | null | ParsedUrlQuery;
}

export interface UrlWithParsedQuery extends Url {
query: ParsedUrlQuery;
}

export interface UrlWithStringQuery extends Url {
query: string | null;
}

export interface URLFormatOptions {
auth?: boolean;
fragment?: boolean;
search?: boolean;
unicode?: boolean;
}

export type ParseFunction = {
(urlStr: string): UrlWithStringQuery;
(urlStr: string, parseQueryString: false | undefined, slashesDenoteHost?: boolean): UrlWithStringQuery;
(urlStr: string, parseQueryString: true, slashesDenoteHost?: boolean): UrlWithParsedQuery;
(urlStr: string, parseQueryString: boolean, slashesDenoteHost?: boolean): Url;
};

export type FormatFunction = {
(URL: URL, options?: URLFormatOptions): string;
(urlObject: UrlObject | string): string;
};

export type ResolveFunction = {
(from: string, to: string): string;
};

export const parse: ParseFunction = _parse;
export const format: FormatFunction = _format;
export const resolve: ResolveFunction = _resolve;

0 comments on commit bd5bae0

Please sign in to comment.