Skip to content

Commit 826616c

Browse files
committed
Make urlCache as a part of load context (#707)
1 parent db04503 commit 826616c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/load.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ export function resolveSchema(url: string): URL {
5454
interface LoadOptions extends GlobalContext {
5555
rootURL: URL;
5656
schemas: SchemaMap;
57+
urlCache?: Set<string>; // URL cache (prevent URLs from being loaded over and over)
5758
}
5859

59-
// temporary cache for load()
60-
let urlCache = new Set<string>(); // URL cache (prevent URLs from being loaded over and over)
61-
6260
/** Load a schema from local path or remote URL */
6361
export default async function load(
6462
schema: URL | PartialSchema,
6563
options: LoadOptions
6664
): Promise<{ [url: string]: PartialSchema }> {
65+
const urlCache = options.urlCache || new Set<string>();
66+
6767
const isJSON = schema instanceof URL === false; // if this is dynamically-passed-in JSON, we’ll have to change a few things
6868
let schemaID = isJSON ? new URL(VIRTUAL_JSON_URL).href : schema.href;
6969

@@ -136,7 +136,7 @@ export default async function load(
136136

137137
const nextURL = isRemoteURL ? new URL(refURL) : new URL(slash(refURL), schema as URL);
138138
refPromises.push(
139-
load(nextURL, options).then((subschemas) => {
139+
load(nextURL, { ...options, urlCache }).then((subschemas) => {
140140
for (const subschemaURL of Object.keys(subschemas)) {
141141
schemas[subschemaURL] = subschemas[subschemaURL];
142142
}

0 commit comments

Comments
 (0)