Skip to content

Commit 13d623c

Browse files
authored
Replace default export with named export rdfDereferencer for better ESM support (#53)
1 parent 4af09b7 commit 13d623c

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

bin/Runner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {IActorDereferenceRdfOutput} from "@comunica/bus-dereference-rdf";
33
import {quadToStringQuad} from "rdf-string";
44
import * as RDF from '@rdfjs/types';
5-
import rdfDereferencer from "..";
5+
import {rdfDereferencer} from "..";
66

77
// tslint:disable:no-console
88
// tslint:disable:no-var-requires
@@ -19,7 +19,7 @@ Usage:
1919
process.exit(1);
2020
}
2121

22-
rdfDereferencer.dereference(args[0], { localFiles: true })
22+
rdfDereferencer.dereference(args[0], {localFiles: true})
2323
.then((out: IActorDereferenceRdfOutput) => {
2424
process.stdout.write('[');
2525
let first = true;

lib/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { RdfDereferencerBase } from './RdfDereferencerBase';
1+
import {RdfDereferencerBase} from './RdfDereferencerBase';
2+
23
export * from "./RdfDereferencer";
34
export * from "./RdfDereferencerBase";
4-
// tslint:disable:no-var-requires
5-
export default <RdfDereferencerBase> require('../engine-default');
5+
const rdfDereferencer = <RdfDereferencerBase>require('../engine-default');
6+
export {rdfDereferencer};

test/RdfDereferencer-test.ts

+19-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Readable} from "stream";
66
import {RdfDereferencer} from "../lib/RdfDereferencer";
77
import 'cross-fetch';
88

9-
import dereferencer from "..";
9+
import {rdfDereferencer} from "..";
1010
import { mocked } from 'ts-jest/utils';
1111

1212
// Mock fetch
@@ -40,18 +40,18 @@ describe('dereferencer', () => {
4040
});
4141

4242
it('should be an RdfDereferencer instance', () => {
43-
expect(dereferencer).toBeInstanceOf(RdfDereferencer);
43+
expect(rdfDereferencer).toBeInstanceOf(RdfDereferencer);
4444
});
4545

4646
it('should error on 404 responses', async () => {
4747
mockSetup({ statusCode: 404 });
48-
return expect(dereferencer.dereference('http://example.org/')).rejects
48+
return expect(rdfDereferencer.dereference('http://example.org/')).rejects
4949
.toThrow(new Error('Could not retrieve http://example.org/ (HTTP status 404):\nempty response'));
5050
});
5151

5252
it('should error on errors', async () => {
5353
mockSetup({ error: true });
54-
return expect(dereferencer.dereference('http://example.org/')).rejects
54+
return expect(rdfDereferencer.dereference('http://example.org/')).rejects
5555
.toThrow(new Error('fetch error'));
5656
});
5757

@@ -62,7 +62,7 @@ describe('dereferencer', () => {
6262
`);
6363
body.push(null);
6464
mockSetup({ statusCode: 200, body, headers: { 'content-type': 'text/turtle' } });
65-
const out = await dereferencer.dereference('http://example.org/');
65+
const out = await rdfDereferencer.dereference('http://example.org/');
6666
expect(out.metadata.triples).toBeTruthy();
6767
expect(out.url).toEqual('http://example.org/');
6868
return expect(arrayifyStream(out.data)).resolves.toBeRdfIsomorphic([
@@ -80,7 +80,7 @@ describe('dereferencer', () => {
8080

8181
const myFetch: typeof fetch = async (url) => getMock({ statusCode: 200, body, headers: { 'content-type': 'text/turtle' } }) as any;
8282

83-
const out = await dereferencer.dereference('http://example.org/', { fetch: myFetch });
83+
const out = await rdfDereferencer.dereference('http://example.org/', { fetch: myFetch });
8484
expect(out.metadata.triples).toBeTruthy();
8585
expect(out.url).toEqual('http://example.org/');
8686
return expect(arrayifyStream(out.data)).resolves.toBeRdfIsomorphic([
@@ -96,7 +96,7 @@ describe('dereferencer', () => {
9696
`);
9797
body.push(null);
9898
mockSetup({ statusCode: 200, body, url: 'http://example.org/bla.ttl' });
99-
const out = await dereferencer.dereference('http://example.org/bla.ttl');
99+
const out = await rdfDereferencer.dereference('http://example.org/bla.ttl');
100100
expect(out.metadata.triples).toBeTruthy();
101101
expect(out.url).toEqual('http://example.org/bla.ttl');
102102
return expect(arrayifyStream(out.data)).resolves.toBeRdfIsomorphic([
@@ -112,7 +112,7 @@ describe('dereferencer', () => {
112112
`);
113113
body.push(null);
114114
mockSetup({ statusCode: 200, body, headers: { 'content-type': 'text/turtle', 'content-location': 'http://example.org/bla' } });
115-
const out = await dereferencer.dereference('http://example.org/');
115+
const out = await rdfDereferencer.dereference('http://example.org/');
116116
expect(out.metadata.triples).toBeTruthy();
117117
expect(out.url).toEqual('http://example.org/');
118118
return expect(arrayifyStream(out.data)).resolves.toBeRdfIsomorphic([
@@ -128,7 +128,7 @@ describe('dereferencer', () => {
128128
`);
129129
body.push(null);
130130
mockSetup({ statusCode: 200, body, headers: { 'content-type': 'text/turtle' } });
131-
const out = await dereferencer.dereference('http://example.org/');
131+
const out = await rdfDereferencer.dereference('http://example.org/');
132132
expect(out.metadata.triples).toBeTruthy();
133133
expect(out.url).toEqual('http://example.org/');
134134
return expect(arrayifyStream(out.data))
@@ -142,7 +142,7 @@ describe('dereferencer', () => {
142142
`);
143143
body.push(null);
144144
mockSetup({ statusCode: 200, body, headers: { 'content-type': 'unknown' } });
145-
return expect(dereferencer.dereference('http://example.org/')).rejects
145+
return expect(rdfDereferencer.dereference('http://example.org/')).rejects
146146
.toThrow();
147147
});
148148

@@ -159,7 +159,7 @@ describe('dereferencer', () => {
159159
`);
160160
body.push(null);
161161
mockSetup({ statusCode: 200, body, headers: { 'content-type': 'application/ld+json' } });
162-
const out = await dereferencer.dereference('http://example.org/');
162+
const out = await rdfDereferencer.dereference('http://example.org/');
163163
expect(out.metadata).toBeFalsy();
164164
expect(out.url).toEqual('http://example.org/');
165165
return expect(arrayifyStream(out.data))
@@ -177,7 +177,7 @@ describe('dereferencer', () => {
177177
`);
178178
body.push(null);
179179
mockSetup({ statusCode: 200, body, headers: new Headers({ 'content-type': 'text/turtle' }) });
180-
const out = await dereferencer.dereference('http://example.org/', { method: 'GET' });
180+
const out = await rdfDereferencer.dereference('http://example.org/', { method: 'GET' });
181181
expect(fetch).toHaveBeenCalledWith('http://example.org/', {
182182
agent: expect.anything(),
183183
headers: expect.anything(),
@@ -195,7 +195,7 @@ describe('dereferencer', () => {
195195
`);
196196
body.push(null);
197197
mockSetup({ statusCode: 200, body, headers: new Headers({ 'content-type': 'text/turtle' }) });
198-
const out = await dereferencer.dereference('http://example.org/', { headers: { _a: 'A', _b: 'B' } });
198+
const out = await rdfDereferencer.dereference('http://example.org/', { headers: { _a: 'A', _b: 'B' } });
199199
expect(fetch).toHaveBeenCalledWith('http://example.org/', {
200200
agent: expect.anything(),
201201
headers: expect.anything(),
@@ -215,7 +215,7 @@ describe('dereferencer', () => {
215215
`);
216216
body.push(null);
217217
mockSetup({ statusCode: 200, body, headers: new Headers({ 'content-type': 'text/turtle' }) });
218-
const out = await dereferencer.dereference('http://example.org/', { method: 'POST' });
218+
const out = await rdfDereferencer.dereference('http://example.org/', { method: 'POST' });
219219
expect(fetch).toHaveBeenCalledWith('http://example.org/', {
220220
agent: expect.anything(),
221221
headers: expect.anything(),
@@ -227,7 +227,7 @@ describe('dereferencer', () => {
227227
});
228228

229229
it('should handle relative local .ttl files', async () => {
230-
const out = await dereferencer.dereference('test/assets/example.ttl', { localFiles: true });
230+
const out = await rdfDereferencer.dereference('test/assets/example.ttl', { localFiles: true });
231231
expect(out.metadata.triples).toBeTruthy();
232232
expect(out.url).toEqual(join(process.cwd(), 'test/assets/example.ttl'));
233233
return expect(arrayifyStream(out.data)).resolves.toBeRdfIsomorphic([
@@ -237,12 +237,12 @@ describe('dereferencer', () => {
237237
});
238238

239239
it('should error on relative local .ttl files without localFiles flag', async () => {
240-
await expect(dereferencer.dereference('test/assets/example.ttl')).rejects.toThrow(
240+
await expect(rdfDereferencer.dereference('test/assets/example.ttl')).rejects.toThrow(
241241
new Error('Tried to dereference a local file without enabling localFiles option: test/assets/example.ttl'));
242242
});
243243

244244
it('should handle absolute local .ttl files', async () => {
245-
const out = await dereferencer.dereference(join(process.cwd(), 'test/assets/example.ttl'), { localFiles: true });
245+
const out = await rdfDereferencer.dereference(join(process.cwd(), 'test/assets/example.ttl'), { localFiles: true });
246246
expect(out.metadata.triples).toBeTruthy();
247247
expect(out.url).toEqual(join(process.cwd(), 'test/assets/example.ttl'));
248248
return expect(arrayifyStream(out.data)).resolves.toBeRdfIsomorphic([
@@ -252,7 +252,7 @@ describe('dereferencer', () => {
252252
});
253253

254254
it('should handle absolute local .shaclc files', async () => {
255-
const out = await dereferencer.dereference(join(process.cwd(), 'test/assets/example.shaclc'), { localFiles: true });
255+
const out = await rdfDereferencer.dereference(join(process.cwd(), 'test/assets/example.shaclc'), { localFiles: true });
256256
expect(out.metadata.triples).toBeTruthy();
257257
expect(out.url).toEqual(join(process.cwd(), 'test/assets/example.shaclc'));
258258
return expect(arrayifyStream(out.data)).resolves.toBeRdfIsomorphic([
@@ -262,7 +262,7 @@ describe('dereferencer', () => {
262262
});
263263

264264
it('should error on absolute local .ttl files without localFiles flag', async () => {
265-
await expect(dereferencer.dereference(join(process.cwd(), 'test/assets/example.ttl'))).rejects.toThrow(
265+
await expect(rdfDereferencer.dereference(join(process.cwd(), 'test/assets/example.ttl'))).rejects.toThrow(
266266
new Error('Tried to dereference a local file without enabling localFiles option: '
267267
+ join(process.cwd(), 'test/assets/example.ttl')));
268268
});

0 commit comments

Comments
 (0)