Skip to content

Commit

Permalink
feat: allow no fs factory
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Apr 3, 2024
1 parent ba6ec94 commit 10354f6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-apricots-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rdf-transform-graph-imports": patch
---

Make the `FsUtilsFactory` optional. An exception wil be thrown when an enviornment does not provide that factory and a filesystem import is loaded
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This package provides a stream transform which replaces import statements with c

## Installation

Install the package itself and a RDF/JS environment which provides the factories [`NamespaceFactory`](https://github.com/rdfjs-base/namespace), [`FsUtilsFactory`](https://github.com/zazuko/rdf-utils-fs), and [`FetchFactory`](https://github.com/rdfjs-base/fetch-lite). If unsure, try [`@zazuko/env-node`](https://npm.im/@zazuko/env-node).
Install the package itself and an RDF/JS environment which provides the factories [`NamespaceFactory`](https://github.com/rdfjs-base/namespace), [`FetchFactory`](https://github.com/rdfjs-base/fetch-lite), and, optionally, [`FsUtilsFactory`](https://github.com/zazuko/rdf-utils-fs). If unsure, try [`@zazuko/env-node`](https://npm.im/@zazuko/env-node).

```bash
npm install rdf-transform-graph-imports @zazuko/env-node
Expand Down
2 changes: 1 addition & 1 deletion lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import type FsUtilsFactory from '@zazuko/rdf-utils-fs/Factory.js'
import type { FetchFactory } from '@rdfjs/fetch-lite/Factory.js'
import type ClownfaceFactory from 'clownface/Factory.js'

type Environment = RdfjsEnvironment<NamespaceFactory | FsUtilsFactory | FetchFactory | ClownfaceFactory>
type Environment = RdfjsEnvironment<NamespaceFactory | FsUtilsFactory | FetchFactory | ClownfaceFactory> | RdfjsEnvironment<NamespaceFactory | FetchFactory | ClownfaceFactory>
export default Environment
4 changes: 4 additions & 0 deletions lib/fetchImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import Environment from './env.js'

export default async function (env: Environment, importTarget: string | URL) {
if (typeof importTarget === 'string') {
if (!('fromFile' in env)) {
throw new Error('Importing from file is not supported')
}

return env.fromFile(importTarget, { implicitBaseIRI: true })
}

Expand Down

0 comments on commit 10354f6

Please sign in to comment.