main
Last change
on this file since 65b6638 was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | import { isEmpty } from 'ramda';
|
---|
| 2 | import * as plugins from "../util/plugins.mjs";
|
---|
| 3 | import ResolveError from "../errors/ResolveError.mjs";
|
---|
| 4 | import UnmatchedResolverError from "../errors/UnmatchedResolverError.mjs";
|
---|
| 5 | /**
|
---|
| 6 | * Reads the given file, using the configured resolver plugins.
|
---|
| 7 | */
|
---|
| 8 | // eslint-disable-next-line import/prefer-default-export
|
---|
| 9 | export const readFile = async (file, options) => {
|
---|
| 10 | const optsBoundResolvers = options.resolve.resolvers.map(resolver => {
|
---|
| 11 | const clonedResolver = Object.create(resolver);
|
---|
| 12 | return Object.assign(clonedResolver, options.resolve.resolverOpts);
|
---|
| 13 | });
|
---|
| 14 | const resolvers = await plugins.filter('canRead', file, optsBoundResolvers);
|
---|
| 15 |
|
---|
| 16 | // we couldn't find any resolver for this File
|
---|
| 17 | if (isEmpty(resolvers)) {
|
---|
| 18 | throw new UnmatchedResolverError(file.uri);
|
---|
| 19 | }
|
---|
| 20 | try {
|
---|
| 21 | const {
|
---|
| 22 | result
|
---|
| 23 | } = await plugins.run('read', [file], resolvers);
|
---|
| 24 | return result;
|
---|
| 25 | } catch (error) {
|
---|
| 26 | throw new ResolveError(`Error while reading file "${file.uri}"`, {
|
---|
| 27 | cause: error
|
---|
| 28 | });
|
---|
| 29 | }
|
---|
| 30 | }; |
---|
Note:
See
TracBrowser
for help on using the repository browser.