Skip to content

Commit

Permalink
Merge pull request #14 from rdf-ext/esm
Browse files Browse the repository at this point in the history
feat!: switched to esm, updated dependencies
  • Loading branch information
bergos authored Oct 31, 2023
2 parents f5bce33 + 3503ad7 commit 2a382db
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 75 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/ci.yaml

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Test
on:
- pull_request
- push
jobs:
test:
runs-on: ubuntu-20.04
strategy:
matrix:
node:
- '18'
- '20'
- '21'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm test
- uses: codecov/codecov-action@v3
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Thomas Bergwinkl

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# rdf-utils-fs

[![Build Status](https://travis-ci.org/rdf-ext/rdf-utils-fs.svg?branch=master)](https://travis-ci.org/rdf-ext/rdf-utils-dataset)
[![npm version](https://badge.fury.io/js/rdf-utils-fs.svg)](https://badge.fury.io/js/rdf-utils-dataset)
[![build status](https://img.shields.io/github/actions/workflow/status/rdf-ext/rdf-utils-fs/test.yaml?branch=master)](https://github.com/rdf-ext/rdf-utils-fs/actions/workflows/test.yaml)
[![npm version](https://img.shields.io/npm/v/rdf-utils-fs.svg)](https://www.npmjs.com/package/rdf-utils-fs)

File system utils for RDF/JS.

Expand All @@ -13,12 +13,18 @@ Each util function can be loaded as property from the main module or by loading

Loading the function from the main module:

const resource = require('rdf-utils-fs').fromFile
```javascript
import { fromFile } from 'rdf-utils-fs'
import { toFile } from 'rdf-utils-fs'
```

Loading the function from the file with the function name:

const resource = require('rdf-utils-fs/fromFile')

```javascript
import fromFile from 'rdf-utils-fs/fromFile.js'
import toFile from 'rdf-utils-fs/toFile.js'
```

## Functions

### fromFile(filename, options)
Expand Down
2 changes: 1 addition & 1 deletion defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ defaults.extensions = {
ttl: 'text/turtle'
}

module.exports = defaults
export default defaults
10 changes: 5 additions & 5 deletions fromFile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { createReadStream } = require('fs')
const { extname } = require('path')
const formats = require('@rdfjs/formats-common')
const defaults = require('./defaults')
import { createReadStream } from 'node:fs'
import { extname } from 'node:path'
import formats from '@rdfjs/formats-common'
import defaults from './defaults.js'

function fromFile (filename, { extensions, ...options } = {}) {
const combinedExtensions = {
Expand All @@ -25,4 +25,4 @@ function fromFile (filename, { extensions, ...options } = {}) {
return parser.import(createReadStream(filename), options)
}

module.exports = fromFile
export default fromFile
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
fromFile: require('./fromFile'),
toFile: require('./toFile')
import fromFile from './fromFile.js'
import toFile from './toFile.js'

export {
fromFile,
toFile
}
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
"name": "rdf-utils-fs",
"version": "2.3.1",
"description": "RDF/JS file system utils",
"type": "module",
"main": "index.js",
"scripts": {
"coverage": "codecov",
"test": "stricter-standard && c8 --reporter=lcov --reporter=text-summary mocha"
},
"repository": {
"type": "git",
"url": "git://github.com/rdf-ext/rdf-utils-fs.git"
"url": "https://github.com/rdf-ext/rdf-utils-fs.git"
},
"keywords": [
"rdf",
Expand All @@ -24,16 +25,15 @@
},
"homepage": "https://github.com/rdf-ext/rdf-utils-fs",
"dependencies": {
"@rdfjs/formats-common": "^2.2.0",
"readable-stream": "^3.6.0"
"@rdfjs/formats-common": "^3.1.0",
"readable-stream": "^4.4.2"
},
"devDependencies": {
"c8": "^7.9.0",
"codecov": "^3.8.3",
"isstream": "^0.1.2",
"mocha": "^9.1.2",
"rdf-ext": "^1.3.5",
"shelljs": "^0.8.4",
"stricter-standard": "^0.2.0"
"c8": "^8.0.1",
"is-stream": "^3.0.0",
"mocha": "^10.2.0",
"rdf-ext": "^2.4.0",
"shelljs": "^0.8.5",
"stricter-standard": "^0.3.0"
}
}
23 changes: 11 additions & 12 deletions test/fromFile.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
const { strictEqual, throws } = require('assert')
const { resolve } = require('path')
const { isReadable } = require('isstream')
const { describe, it } = require('mocha')
const rdf = require('rdf-ext')
const fromFile = require('../fromFile')
const example = require('./support/example')
import { strictEqual, throws } from 'node:assert'
import { isReadableStream } from 'is-stream'
import { describe, it } from 'mocha'
import rdf from 'rdf-ext'
import fromFile from '../fromFile.js'
import * as example from './support/example.js'

describe('fromFile', () => {
it('should create a quad stream', async () => {
const stream = fromFile(resolve(__dirname, 'support/example.nt'))
const stream = fromFile(new URL('support/example.nt', import.meta.url).pathname)

stream.resume()

strictEqual(isReadable(stream), true)
strictEqual(isReadableStream(stream), true)
})

it('should forward options to parser', async () => {
const stream = fromFile(resolve(__dirname, 'support/example.ttl'), { baseIRI: 'http://example.org/' })
const stream = fromFile(new URL('support/example.ttl', import.meta.url).pathname, { baseIRI: 'http://example.org/' })
const dataset = await rdf.dataset().import(stream)

strictEqual(dataset.toCanonical(), example.defaultGraph().toCanonical())
Expand All @@ -27,7 +26,7 @@ describe('fromFile', () => {
trig: 'application/trig'
}

const stream = fromFile(resolve(__dirname, 'support/example.nt'), { extensions })
const stream = fromFile(new URL('support/example.nt', import.meta.url).pathname, { extensions })
const dataset = await rdf.dataset().import(stream)

strictEqual(dataset.toCanonical(), example.defaultGraph().toCanonical())
Expand All @@ -42,7 +41,7 @@ describe('fromFile', () => {
]
for (const [extension, expected] of commonExtensions) {
it(`should load ${extension} out of the box`, async () => {
const stream = fromFile(resolve(__dirname, `support/example.${extension}`))
const stream = fromFile(new URL(`support/example.${extension}`, import.meta.url).pathname)
const dataset = await rdf.dataset().import(stream)

strictEqual(dataset.toCanonical(), expected().toCanonical())
Expand Down
4 changes: 2 additions & 2 deletions test/support/example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const rdf = require('rdf-ext')
import rdf from 'rdf-ext'

function defaultGraph () {
return rdf.dataset([rdf.quad(
Expand All @@ -17,7 +17,7 @@ function namedGraph () {
)])
}

module.exports = {
export {
defaultGraph,
namedGraph
}
15 changes: 15 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { strictEqual } from 'node:assert'
import { describe, it } from 'mocha'
import fromFile from '../fromFile.js'
import * as rdfUtilsFs from '../index.js'
import toFile from '../toFile.js'

describe('rdf-utils-fs', () => {
it('should export fromFile', () => {
strictEqual(rdfUtilsFs.fromFile, fromFile)
})

it('should export toFile', () => {
strictEqual(rdfUtilsFs.toFile, toFile)
})
})
17 changes: 8 additions & 9 deletions test/toFile.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const { strictEqual, throws } = require('assert')
const { readFileSync } = require('fs')
const { resolve } = require('path')
const { describe, it } = require('mocha')
const shell = require('shelljs')
const toFile = require('../toFile')
const example = require('./support/example')
import { strictEqual, throws } from 'node:assert'
import { readFile } from 'node:fs/promises'
import { describe, it } from 'mocha'
import shell from 'shelljs'
import toFile from '../toFile.js'
import * as example from './support/example.js'

describe('toFile', () => {
shell.mkdir('-p', 'tmp')
Expand All @@ -16,8 +15,8 @@ describe('toFile', () => {
it('should create a quad stream', async () => {
const filename = 'tmp/test.nt'
await toFile(example.defaultGraph().toStream(), filename)
const content = readFileSync(filename).toString().trim()
const expected = readFileSync(resolve(__dirname, 'support/example.nt')).toString().trim()
const content = (await readFile(filename)).toString().trim()
const expected = (await readFile(new URL('support/example.nt', import.meta.url).pathname)).toString().trim()

strictEqual(content, expected)
})
Expand Down
18 changes: 9 additions & 9 deletions toFile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { createWriteStream } = require('fs')
const { extname } = require('path')
const { promisify } = require('util')
const formats = require('@rdfjs/formats-common')
const { finished } = require('readable-stream')
const config = require('./defaults')

function toFile (stream, filename, { extensions = config.extensions, ...options } = {}) {
import { createWriteStream } from 'node:fs'
import { extname } from 'node:path'
import { promisify } from 'node:util'
import formats from '@rdfjs/formats-common'
import { finished } from 'readable-stream'
import defaults from './defaults.js'

function toFile (stream, filename, { extensions = defaults.extensions, ...options } = {}) {
const extension = extname(filename).split('.').pop()
const mediaType = extensions[extension]

Expand All @@ -26,4 +26,4 @@ function toFile (stream, filename, { extensions = config.extensions, ...options
return promisify(finished)(output)
}

module.exports = toFile
export default toFile

0 comments on commit 2a382db

Please sign in to comment.