Skip to content

Commit

Permalink
fix: update linting and bump all versions
Browse files Browse the repository at this point in the history
  • Loading branch information
BelfordZ committed Oct 5, 2022
1 parent 6de3ce7 commit 4e81683
Show file tree
Hide file tree
Showing 10 changed files with 10,022 additions and 5,709 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Expand Up @@ -8,5 +8,13 @@ module.exports = {
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
overrides: [
{
files: ["src/*.ts"],
rules: {
"@typescript-eslint/no-explicit-any": "off"
}
}
]
};
2 changes: 1 addition & 1 deletion .node-version
@@ -1 +1 @@
12.19.0
16.17.0
1 change: 0 additions & 1 deletion jest.config.js
Expand Up @@ -4,6 +4,5 @@ module.exports = {
resetMocks: true,
restoreMocks: true,
rootDir: './src',
testEnvironment: 'jsdom',
preset: 'ts-jest'
};
15,662 changes: 9,990 additions & 5,672 deletions package-lock.json

Large diffs are not rendered by default.

29 changes: 16 additions & 13 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "@json-schema-tools/reference-resolver",
"version": "0.0.0-development",
"description": "",
"description": "Turns a $ref into a JSONSchema",
"main": "build/index.js",
"browser": "build/index-web.js",
"publishConfig": {
Expand All @@ -10,7 +10,8 @@
"scripts": {
"build": "npm run build:code && typedoc --out docs && touch docs/.nojekyll",
"build:code": "tsc",
"lint": "tslint --fix -p .",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"test": "npm run test:unit && npm run test:web",
"test:unit": "npm run lint && jest --coverage",
"test:web": "npm run build:code && webpack && rm -rf dist"
Expand All @@ -29,17 +30,19 @@
"!build/**/*.test.*"
],
"devDependencies": {
"@json-schema-tools/meta-schema": "^1.6.18",
"@types/isomorphic-fetch": "0.0.36",
"@types/jest": "^26.0.23",
"@types/node": "^18.0.4",
"jest": "^24.9.0",
"ts-jest": "^24.3.0",
"tslint": "^6.1.3",
"typedoc": "^0.21.0",
"typescript": "4.3.5",
"webpack": "^5.38.1",
"webpack-cli": "^4.7.2"
"@json-schema-tools/meta-schema": "^1.7.0",
"@types/isomorphic-fetch": "^0.0.36",
"@types/jest": "^29.1.1",
"@types/node": "^18.8.2",
"@typescript-eslint/eslint-plugin": "^5.39.0",
"@typescript-eslint/parser": "^5.39.0",
"eslint": "^8.24.0",
"jest": "^29.1.2",
"ts-jest": "^29.0.3",
"typedoc": "^0.23.15",
"typescript": "^4.8.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},
"dependencies": {
"@json-schema-spec/json-pointer": "^0.1.2",
Expand Down
4 changes: 2 additions & 2 deletions src/default-protocol-handler-map.ts
Expand Up @@ -3,7 +3,7 @@ import { InvalidRemoteURLError, NonJsonRefError } from "./errors";
import { JSONSchema } from "@json-schema-tools/meta-schema";
import fetch from "isomorphic-fetch";

const fetchHandler = async (uri: string, root: JSONSchema): Promise<JSONSchema> => {
const fetchHandler = async (uri: string): Promise<JSONSchema> => {
let schemaReq;
try {
schemaReq = await fetch(uri);
Expand All @@ -14,7 +14,7 @@ const fetchHandler = async (uri: string, root: JSONSchema): Promise<JSONSchema>
try {
return await schemaReq.json() as JSONSchema;
} catch (e) {
throw new NonJsonRefError({ $ref: uri }, e.message);
throw new NonJsonRefError({ $ref: uri }, (e as Error).message);
}
};

Expand Down
1 change: 0 additions & 1 deletion src/index-web.ts
@@ -1,4 +1,3 @@
import fetch from "isomorphic-fetch";
import defaultProtocolHandlerMap from "./default-protocol-handler-map";
import ReferenceResolver, { ProtocolHandlerMap } from "./reference-resolver";

Expand Down
7 changes: 3 additions & 4 deletions src/index.ts
@@ -1,13 +1,12 @@
import ReferenceResolver, { ProtocolHandlerMap } from "./reference-resolver";
import * as fs from "fs";
import { JSONSchema, JSONSchemaObject } from "@json-schema-tools/meta-schema";
import { InvalidRemoteURLError, NonJsonRefError } from "./errors";
import defaultProtocolHandlerMap from "./default-protocol-handler-map";
import path from "path";

const fileExistsAndReadable = (f: string): Promise<boolean> => {
return new Promise((resolve) => {
return fs.access(f, fs.constants.F_OK | fs.constants.R_OK, (e: any) => { //tslint:disable-line
return fs.access(f, fs.constants.F_OK | fs.constants.R_OK, (e: any) => {
if (e) { return resolve(false); }
return resolve(true);
});
Expand All @@ -20,10 +19,10 @@ const readFile = (f: string): Promise<string> => {

const nodeProtocolHandlerMap: ProtocolHandlerMap = {
...defaultProtocolHandlerMap,
"file": async (uri,root: JSONSchema) => {
"file": async (uri, root: JSONSchema) => {
let filePath = uri;
const ref = (root as JSONSchemaObject).$ref;
if(ref && ref !== uri && await fileExistsAndReadable(ref)) filePath = `${path.parse(ref).dir}/${uri}`;
if (ref && ref !== uri && await fileExistsAndReadable(ref)) filePath = `${path.parse(ref).dir}/${uri}`;
if (await fileExistsAndReadable(filePath) === true) {
const fileContents = await readFile(filePath);
return JSON.parse(fileContents) as JSONSchema;
Expand Down
4 changes: 2 additions & 2 deletions src/reference-resolver.ts
Expand Up @@ -12,7 +12,7 @@ const isUrlLike = (s: string) => {

export interface ProtocolHandlerMap {
[protocol: string]: (uri: string, root: JSONSchema) => Promise<JSONSchema | undefined>;
};
}

export default class ReferenceResolver {
constructor(public protocolHandlerMap: ProtocolHandlerMap) { }
Expand Down Expand Up @@ -43,7 +43,7 @@ export default class ReferenceResolver {
try {
relativePathSchema = await this.protocolHandlerMap.file(hashlessRef, root);
} catch (e) {
throw new NonJsonRefError({ $ref: ref }, e.message);
throw new NonJsonRefError({ $ref: ref }, (e as Error).message);
}
if (relativePathSchema !== undefined) {
let schema: JSONSchema = relativePathSchema;
Expand Down
13 changes: 0 additions & 13 deletions tslint.json

This file was deleted.

0 comments on commit 4e81683

Please sign in to comment.