Skip to content

Commit

Permalink
Update and clean-up dependencies, remove npm CLI dependency in scripts (
Browse files Browse the repository at this point in the history
#20)

* Update actions to latest versions, run CI on more Node versions

* Use lts/-n for LTS Node versions

* Run linter before starting expensive tests

* Remove separate build step because install step already builds

* Cancel running workflows when new one is schedules for the same ref

* Use specific Node versions

* Convert and clean-up ESLint rules for @rubensworks/eslint-config

* Clean-up tsconfig includes/excludes

* Bump dependencies, replace pre-commit with husky, drop npm from scripts

* Add cast from readable-stream Readable to Node Readable

* Update yarn.lock

* Simplify ESLint includes and excludes

* Fix linter errors

* Fix linter errors in tests

---------

Co-authored-by: surilindur <surilindur@users.noreply.github.com>
  • Loading branch information
surilindur and surilindur authored Feb 15, 2024
1 parent dfbed48 commit 75e85a9
Show file tree
Hide file tree
Showing 31 changed files with 2,520 additions and 2,282 deletions.
6 changes: 0 additions & 6 deletions .eslintignore

This file was deleted.

14 changes: 0 additions & 14 deletions .eslintrc.js

This file was deleted.

39 changes: 39 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": [
"tsconfig.eslint.json"
]
},
"extends": [
"@rubensworks"
],
"ignorePatterns": [
"*.d.ts"
],
"rules": {
"no-implicit-coercion": "off",
"import/group-exports": "off",
"import/no-nodejs-modules": "off"
},
"overrides": [
{
"files": [
"lib/**/*VoID*"
],
"rules": {
"unicorn/filename-case": "off"
}
},
{
"files": [
"test/**/*.ts"
],
"rules": {
"import/no-commonjs": "off",
"import/no-unassigned-import": "off"
}
}
]
}
48 changes: 24 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
name: CI
on: [push, pull_request]

on:
- push
- pull_request

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-lint-modules-${{ hashFiles('**/yarn.lock') }}
- uses: actions/setup-node@v2
- uses: actions/setup-node@v4
with:
node-version: 14.x
- run: yarn install
node-version: 20.x
- run: yarn install --frozen-lockfile
- run: yarn run lint

test:
needs: lint
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node-version:
- 14.x
- 16.x
- 18.x
- 20.x
steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Ensure line endings are consistent
run: git config --global core.autocrlf input
- name: Check out repository
uses: actions/checkout@v2
- uses: actions/cache@v2
- run: git config --global core.autocrlf input
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-test-modules-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
run: yarn install
- name: Build project
run: yarn run build
- name: Run tests
run: yarn run test
- name: Submit coverage results
uses: coverallsapp/github-action@master
- run: yarn install --frozen-lockfile
- run: yarn run test
- uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.node-version }}
Expand All @@ -55,8 +56,7 @@ jobs:
needs: test
runs-on: ubuntu-latest
steps:
- name: Consolidate test coverage from different jobs
uses: coverallsapp/github-action@master
- uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
1 change: 1 addition & 0 deletions bin/runner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
import * as Path from 'path';
import { runCli } from '../lib/CliRunner';

runCli(Path.join(__dirname, '..'));
2 changes: 1 addition & 1 deletion lib/io/QuadSinkFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class QuadSinkFile implements IQuadSink {
path = path.replace(/[*|"<>?:]/ug, '_');

// Add file extension if we don't have one yet
if (this.fileExtension && !/\.[a-z]$/iu.exec(this.fileExtension)) {
if (this.fileExtension && !/\.[a-z]$/iu.test(this.fileExtension)) {
path = `${path}${this.fileExtension}`;
}

Expand Down
6 changes: 5 additions & 1 deletion lib/io/QuadSourceFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export class QuadSourceFile implements IQuadSource {
}

public getQuads(): RDF.Stream & Readable {
return rdfParser.parse(fs.createReadStream(this.filePath), { path: this.filePath, baseIRI: this.baseIRI });
// The parser from 'rdf-parse' uses Readable from 'readable-stream', hence this cast
return <RDF.Stream & Readable><unknown>rdfParser.parse(fs.createReadStream(this.filePath), {
path: this.filePath,
baseIRI: this.baseIRI,
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/quadmatcher/QuadMatcherPredicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export class QuadMatcherPredicate implements IQuadMatcher {
}

public matches(quad: RDF.Quad): boolean {
return Boolean(this.predicate.exec(quad.predicate.value));
return Boolean(this.predicate.test(quad.predicate.value));
}
}
2 changes: 1 addition & 1 deletion lib/quadmatcher/QuadMatcherResourceType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class QuadMatcherResourceType implements IQuadMatcher {
// Add buffer entry on applicable resource type
if (quad.subject.termType === 'NamedNode' &&
quad.predicate.value === 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' &&
quad.object.termType === 'NamedNode' && this.type.exec(quad.object.value)) {
quad.object.termType === 'NamedNode' && this.type.test(quad.object.value)) {
if (this.matchFullResource) {
this.matchingSubjects[quad.subject.value] = true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/strategy/FragmentationStrategyResourceObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class FragmentationStrategyResourceObject extends FragmentationStrategySt
}

// Match the target predicate
if (this.targetPredicate.exec(quad.predicate.value)) {
if (this.targetPredicate.test(quad.predicate.value)) {
if (quad.object.termType !== 'NamedNode') {
throw new Error(`Expected target predicate value of type NamedNode on resource '${quad.subject.value}', but got '${quad.object.value}' (${quad.object.termType})`);
}
Expand Down
1 change: 0 additions & 1 deletion lib/strategy/FragmentationStrategySubject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class FragmentationStrategySubject extends FragmentationStrategyStreamAda
private readonly blankNodeBuffer: FragmentationBlankNodeBuffer<'subject', 'object'>;
private readonly relativePath?: string;

// eslint-disable-next-line default-param-last
public constructor(eagerFlushing = true, relativePath?: string) {
super();
this.blankNodeBuffer = new FragmentationBlankNodeBuffer('subject', 'object', eagerFlushing);
Expand Down
2 changes: 1 addition & 1 deletion lib/transform/QuadTransformerAppendResourceAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export abstract class QuadTransformerAppendResourceAdapter implements IQuadTrans
// Append SCL policy to applicable resource type
if (quad.subject.termType === 'NamedNode' &&
quad.predicate.value === 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' &&
quad.object.termType === 'NamedNode' && this.type.exec(quad.object.value)) {
quad.object.termType === 'NamedNode' && this.type.test(quad.object.value)) {
this.appendQuads(quad, quads);
}

Expand Down
1 change: 0 additions & 1 deletion lib/transform/QuadTransformerCompositeVaryingResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export class QuadTransformerCompositeVaryingResource implements IQuadTransformer
// Determine a transformer based on the creator IRI
let creatorHash = 0;
for (let i = 0; i < resource.target.value.length; i++) {
// eslint-disable-next-line no-bitwise
creatorHash += resource.target.value.charCodeAt(i);
}
creatorHash = Math.abs(creatorHash);
Expand Down
2 changes: 1 addition & 1 deletion lib/transform/QuadTransformerRemapResourceIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class QuadTransformerRemapResourceIdentifier implements IQuadTransformer
const resource = this.resourceIdentifier.getBufferResource(quad);

// Try to set the id
if (this.identifierPredicate.exec(quad.predicate.value)) {
if (this.identifierPredicate.test(quad.predicate.value)) {
if (resource.id) {
throw new Error(`Illegal overwrite of identifier value on resource '${quad.subject.value}'`);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/transform/QuadTransformerSetIriExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class QuadTransformerSetIriExtension extends QuadTransformerTerms {
}

protected transformTerm(term: RDF.Term): RDF.Term {
if (term.termType === 'NamedNode' && (!this.iriPattern || this.iriPattern.exec(term.value))) {
if (term.termType === 'NamedNode' && (!this.iriPattern || this.iriPattern.test(term.value))) {
let value = term.value;
const extensionMatch = /\.[a-z]*$/iu.exec(value);
if (extensionMatch) {
Expand Down
4 changes: 2 additions & 2 deletions lib/transform/identifier/ResourceIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class ResourceIdentifier<T> {
public tryInitializingBuffer(quad: RDF.Quad): boolean {
if (quad.subject.termType === 'NamedNode' &&
quad.predicate.value === 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' &&
quad.object.termType === 'NamedNode' && this.type.exec(quad.object.value)) {
quad.object.termType === 'NamedNode' && this.type.test(quad.object.value)) {
this.buffer[quad.subject.value] = { quads: [ quad ], type: quad.object };

return true;
Expand All @@ -74,7 +74,7 @@ export class ResourceIdentifier<T> {
resource.quads.push(quad);

// Try to set the target
if (this.targetPredicate.exec(quad.predicate.value)) {
if (this.targetPredicate.test(quad.predicate.value)) {
if (quad.object.termType !== 'NamedNode') {
throw new Error(`Expected target value of type NamedNode on resource '${quad.subject.value}'`);
}
Expand Down
66 changes: 29 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,48 +35,40 @@
],
"dependencies": {
"@rdfjs/types": "*",
"@types/async-lock": "^1.1.2",
"@types/lru-cache": "^5.1.0",
"@types/mkdirp": "^1.0.1",
"async-lock": "^1.2.4",
"componentsjs": "^5.0.1",
"@types/async-lock": "^1.4.0",
"@types/lru-cache": "^5.0.0",
"@types/mkdirp": "^1.0.0",
"async-lock": "^1.4.0",
"componentsjs": "^5.0.0",
"lru-cache": "^6.0.0",
"mkdirp": "^1.0.4",
"mkdirp": "^1.0.0",
"rdf-parse": "^2.0.0",
"rdf-serialize": "^2.0.0",
"rdf-string": "^1.6.0",
"rdf-terms": "^1.8.2",
"relative-to-absolute-iri": "^1.0.6"
"rdf-terms": "^1.11.0",
"relative-to-absolute-iri": "^1.0.0"
},
"pre-commit": [
"build",
"lint",
"test"
],
"devDependencies": {
"@rubensworks/eslint-config": "^1.0.1",
"@types/jest": "^28.0.0",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"@rubensworks/eslint-config": "^2.0.0",
"@types/jest": "^29.0.0",
"arrayify-stream": "^2.0.0",
"componentsjs-generator": "^3.0.3",
"eslint": "^7.9.0",
"eslint-config-es": "3.23.0",
"eslint-import-resolver-typescript": "^2.3.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^25.0.0",
"eslint-plugin-tsdoc": "^0.2.7",
"eslint-plugin-unused-imports": "^2.0.0",
"jest": "^28.1.0",
"jest-rdf": "^1.7.0",
"componentsjs-generator": "^3.0.0",
"eslint": "^7.0.0",
"husky": "^4.3.0",
"jest": "^29.0.0",
"jest-rdf": "^1.0.0",
"manual-git-changelog": "^1.0.0",
"pre-commit": "^1.2.2",
"rdf-data-factory": "^1.1.0",
"stream-to-string": "^1.2.0",
"streamify-array": "^1.0.1",
"streamify-string": "^1.0.1",
"ts-jest": "^28.0.2",
"typescript": "^4.3.5"
"streamify-array": "^1.0.0",
"streamify-string": "^1.0.0",
"ts-jest": "^29.0.0",
"typescript": "^5.0.0"
},
"husky": {
"hooks": {
"pre-commit": "yarn run build && yarn run lint && yarn run test"
}
},
"jest": {
"transform": {
Expand All @@ -103,13 +95,13 @@
"scripts": {
"test": "jest ${1}",
"test-watch": "jest ${1} --watch",
"lint": "eslint . --ext .ts --cache",
"lint:fix": "eslint . --ext .ts --cache --fix",
"build": "npm run build:ts && npm run build:components",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"build": "yarn run build:ts && yarn run build:components",
"build:components": "componentsjs-generator -s lib -r rdfdf",
"build:ts": "tsc",
"validate": "npm ls",
"prepare": "npm run build",
"validate": "yarn ls",
"prepare": "yarn run build",
"version": "manual-git-changelog onversion"
}
}
1 change: 1 addition & 0 deletions test/unit/Fragmenter-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { QuadTransformerReplaceIri } from '../../lib/transform/QuadTransformerReplaceIri';

const streamifyArray = require('streamify-array');

const DF = new DataFactory();

describe('Fragmenter', () => {
Expand Down
6 changes: 4 additions & 2 deletions test/unit/io/ParallelFileWriter-test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as fs from 'fs';
import { PassThrough } from 'stream';
import mkdirp = require('mkdirp');
import { DataFactory } from 'rdf-data-factory';
import { ParallelFileWriter } from '../../../lib/io/ParallelFileWriter';
import mocked = jest.mocked;
const DF = new DataFactory();

const mkdirp = require('mkdirp');
const stringifyStream = require('stream-to-string');

const DF = new DataFactory();

jest.mock('fs');
jest.mock('mkdirp');

Expand Down
1 change: 1 addition & 0 deletions test/unit/io/QuadSinkCsv-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as mkdirp from 'mkdirp';
import { DataFactory } from 'rdf-data-factory';
import { QuadSinkCsv } from '../../../lib/io/QuadSinkCsv';
import mocked = jest.mocked;

const DF = new DataFactory();

jest.mock('fs');
Expand Down
1 change: 1 addition & 0 deletions test/unit/io/QuadSinkFile-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as readline from 'readline';
import type * as RDF from '@rdfjs/types';
import { DataFactory } from 'rdf-data-factory';
import { QuadSinkFile } from '../../../lib/io/QuadSinkFile';

const DF = new DataFactory();

jest.mock('../../../lib/io/ParallelFileWriter');
Expand Down
Loading

0 comments on commit 75e85a9

Please sign in to comment.