|
1 | 1 | import * as url from "./util/url.js"; |
2 | | -import * as plugins from "./util/plugins.js"; |
| 2 | +import { filter, all, sort, run } from "./util/plugins.js"; |
3 | 3 | import { |
4 | 4 | ResolverError, |
5 | 5 | ParserError, |
@@ -77,13 +77,13 @@ async function readFile<S extends object = JSONSchema, O extends ParserOptions<S |
77 | 77 | // console.log('Reading %s', file.url); |
78 | 78 |
|
79 | 79 | // Find the resolvers that can read this file |
80 | | - let resolvers = plugins.all(options.resolve); |
81 | | - resolvers = plugins.filter(resolvers, "canRead", file); |
| 80 | + let resolvers = all(options.resolve); |
| 81 | + resolvers = filter(resolvers, "canRead", file, undefined, $refs); |
82 | 82 |
|
83 | 83 | // Run the resolvers, in order, until one of them succeeds |
84 | | - plugins.sort(resolvers); |
| 84 | + sort(resolvers); |
85 | 85 | try { |
86 | | - const data = await plugins.run(resolvers, "read", file, $refs); |
| 86 | + const data = await run(resolvers, "read", file, $refs); |
87 | 87 | return data; |
88 | 88 | } catch (err: any) { |
89 | 89 | if (!err && options.continueOnError) { |
@@ -123,14 +123,14 @@ async function parseFile<S extends object = JSONSchema, O extends ParserOptions< |
123 | 123 | // Find the parsers that can read this file type. |
124 | 124 | // If none of the parsers are an exact match for this file, then we'll try ALL of them. |
125 | 125 | // This handles situations where the file IS a supported type, just with an unknown extension. |
126 | | - const allParsers = plugins.all(options.parse); |
127 | | - const filteredParsers = plugins.filter(allParsers, "canParse", file); |
| 126 | + const allParsers = all(options.parse); |
| 127 | + const filteredParsers = filter(allParsers, "canParse", file); |
128 | 128 | const parsers = filteredParsers.length > 0 ? filteredParsers : allParsers; |
129 | 129 |
|
130 | 130 | // Run the parsers, in order, until one of them succeeds |
131 | | - plugins.sort(parsers); |
| 131 | + sort(parsers); |
132 | 132 | try { |
133 | | - const parser = await plugins.run<S, O>(parsers, "parse", file, $refs); |
| 133 | + const parser = await run<S, O>(parsers, "parse", file, $refs); |
134 | 134 | if (!parser.plugin.allowEmpty && isEmpty(parser.result)) { |
135 | 135 | throw new SyntaxError(`Error parsing "${file.url}" as ${parser.plugin.name}. \nParsed value is empty`); |
136 | 136 | } else { |
|
0 commit comments