Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 1 addition & 54 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@
"ajv-formats": "^2.1.1",
"avsc": "^5.7.5",
"js-yaml": "^4.1.0",
"jsonpath-plus": "^10.0.7",
"node-fetch": "2.6.7"
"jsonpath-plus": "^10.0.7"
},
"devDependencies": {
"@asyncapi/avro-schema-parser": "^3.0.22",
Expand All @@ -70,7 +69,6 @@
"@types/jest": "^27.4.1",
"@types/js-yaml": "^4.0.5",
"@types/node": "^18.16.1",
"@types/node-fetch": "^2.6.2",
"@typescript-eslint/eslint-plugin": "^5.36.2",
"@typescript-eslint/parser": "^5.36.2",
"browserify": "^16.3.0",
Expand All @@ -90,13 +88,5 @@
"webpack": "^5.94.0",
"webpack-bundle-analyzer": "^4.6.1",
"webpack-cli": "^4.10.0"
},
"browserify": {
"transform": [
"browserify-shim"
]
},
"browserify-shim": {
"node-fetch": "global:fetch"
}
}
18 changes: 2 additions & 16 deletions packages/parser/src/from.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { readFile } from 'fs';
import { promisify } from 'util';

import type { RequestInit } from 'node-fetch';
import type { Parser } from './parser';
import type { ParseOptions, ParseOutput } from './parse';
import type { ValidateOptions } from './validate';
Expand All @@ -12,10 +11,9 @@ interface FromResult {
validate: (options?: ValidateOptions) => Promise<Diagnostic[]>;
}

export function fromURL(parser: Parser, source: string, options?: RequestInit): FromResult {
export function fromURL(parser: Parser, source: string, options?: Parameters<typeof fetch>[1]): FromResult {
async function fetchUrl(): Promise<Input> {
const fetchFn = await getFetch();
return (await fetchFn(source, options as any)).text();
return (await fetch(source, options)).text();
}

return {
Expand Down Expand Up @@ -46,15 +44,3 @@ export function fromFile(parser: Parser, source: string, options?: Parameters<ty
}
};
}

let __fetchFn: typeof fetch | undefined;
async function getFetch(): Promise<typeof fetch> {
if (__fetchFn) {
return __fetchFn;
}

if (typeof fetch === 'undefined') {
return __fetchFn = (await import('node-fetch')).default as unknown as typeof fetch;
}
return (__fetchFn = fetch);
}
Loading