Skip to content

Esmification #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

root: true
extends: "@jsdevtools"
parserOptions:
sourceType: module
env:
node: true
browser: true
2 changes: 0 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// https://karma-runner.github.io/0.12/config/configuration-file.html
// https://jstools.dev/karma-config/

"use strict";

const { karmaConfig } = require("@jsdevtools/karma-config");
const { host } = require("@jsdevtools/host-environment");

Expand Down
10 changes: 4 additions & 6 deletions lib/bundle.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"use strict";
import $Ref from "./ref";
import Pointer from "./pointer";
import url from "./util/url";

const $Ref = require("./ref");
const Pointer = require("./pointer");
const url = require("./util/url");

module.exports = bundle;
export default bundle;

/**
* Bundles all external JSON references into the main JSON schema, thus resulting in a schema that
Expand Down
11 changes: 5 additions & 6 deletions lib/dereference.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"use strict";
import $Ref from "./ref";
import Pointer from "./pointer";
import { ono } from "@jsdevtools/ono";

const $Ref = require("./ref");
const Pointer = require("./pointer");
const { ono } = require("@jsdevtools/ono");
const url = require("./util/url");
import url from "./util/url";

module.exports = dereference;
export default dereference;

/**
* Crawls the JSON schema, finds all JSON references, and dereferences them.
Expand Down
1 change: 1 addition & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { JSONSchema4, JSONSchema4Type, JSONSchema6, JSONSchema6Type, JSONSchema7, JSONSchema7Type } from "json-schema";

export = $RefParser;
Expand Down
48 changes: 28 additions & 20 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
/* eslint-disable no-unused-vars */
"use strict";
import $Refs from "./refs";
import _parse from "./parse";
import normalizeArgs from "./normalize-args";
import resolveExternal from "./resolve-external";
import _bundle from "./bundle";
import _dereference from "./dereference";
import url from "./util/url";
import {
InvalidPointerError,
isHandledError,
JSONParserError,
JSONParserErrorGroup,
MissingPointerError,
ParserError,
ResolverError,
UnmatchedParserError,
UnmatchedResolverError
} from "./util/errors";

const $Refs = require("./refs");
const _parse = require("./parse");
const normalizeArgs = require("./normalize-args");
const resolveExternal = require("./resolve-external");
const _bundle = require("./bundle");
const _dereference = require("./dereference");
const url = require("./util/url");
const { JSONParserError, InvalidPointerError, MissingPointerError, ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError, JSONParserErrorGroup } = require("./util/errors");
const maybe = require("call-me-maybe");
const { ono } = require("@jsdevtools/ono");
import maybe from "call-me-maybe";
import { ono } from "@jsdevtools/ono";

module.exports = $RefParser;
module.exports.default = $RefParser;
module.exports.JSONParserError = JSONParserError;
module.exports.InvalidPointerError = InvalidPointerError;
module.exports.MissingPointerError = MissingPointerError;
module.exports.ResolverError = ResolverError;
module.exports.ParserError = ParserError;
module.exports.UnmatchedParserError = UnmatchedParserError;
module.exports.UnmatchedResolverError = UnmatchedResolverError;
export default $RefParser;
export { JSONParserError };
export { InvalidPointerError };
export { MissingPointerError };
export { ResolverError };
export { ParserError };
export { UnmatchedParserError };
export { UnmatchedResolverError };

/**
* This class parses a JSON schema, builds a map of its JSON references and their resolved values,
Expand Down
6 changes: 2 additions & 4 deletions lib/normalize-args.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"use strict";
import Options from "./options";

const Options = require("./options");

module.exports = normalizeArgs;
export default normalizeArgs;

/**
* Normalizes the given arguments, accounting for optional args.
Expand Down
17 changes: 7 additions & 10 deletions lib/options.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
/* eslint lines-around-comment: [2, {beforeBlockComment: false}] */
"use strict";
import jsonParser from "./parsers/json";
import yamlParser from "./parsers/yaml";
import textParser from "./parsers/text";
import binaryParser from "./parsers/binary";
import fileResolver from "./resolvers/file";
import httpResolver from "./resolvers/http";

const jsonParser = require("./parsers/json");
const yamlParser = require("./parsers/yaml");
const textParser = require("./parsers/text");
const binaryParser = require("./parsers/binary");
const fileResolver = require("./resolvers/file");
const httpResolver = require("./resolvers/http");

module.exports = $RefParserOptions;
export default $RefParserOptions;

/**
* Options that determine how JSON schemas are parsed, resolved, and dereferenced.
Expand Down
11 changes: 5 additions & 6 deletions lib/parse.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"use strict";
import { ono } from "@jsdevtools/ono";

const { ono } = require("@jsdevtools/ono");
const url = require("./util/url");
const plugins = require("./util/plugins");
const { ResolverError, ParserError, UnmatchedParserError, UnmatchedResolverError, isHandledError } = require("./util/errors");
import url from "./util/url";
import plugins from "./util/plugins";
import { isHandledError, ParserError, ResolverError, UnmatchedParserError, UnmatchedResolverError } from "./util/errors";

module.exports = parse;
export default parse;

/**
* Reads and parses the specified file path or URL.
Expand Down
4 changes: 1 addition & 3 deletions lib/parsers/binary.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"use strict";

let BINARY_REGEXP = /\.(jpeg|jpg|gif|png|bmp|ico)$/i;

module.exports = {
export default {
/**
* The order that this parser will run, in relation to other parsers.
*
Expand Down
6 changes: 2 additions & 4 deletions lib/parsers/json.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"use strict";
import { ParserError } from "../util/errors";

const { ParserError } = require("../util/errors");

module.exports = {
export default {
/**
* The order that this parser will run, in relation to other parsers.
*
Expand Down
6 changes: 2 additions & 4 deletions lib/parsers/text.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"use strict";

const { ParserError } = require("../util/errors");
import { ParserError } from "../util/errors";

let TEXT_REGEXP = /\.(txt|htm|html|md|xml|js|min|map|css|scss|less|svg)$/i;

module.exports = {
export default {
/**
* The order that this parser will run, in relation to other parsers.
*
Expand Down
8 changes: 3 additions & 5 deletions lib/parsers/yaml.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"use strict";
import { ParserError } from "../util/errors";

const { ParserError } = require("../util/errors");
const yaml = require("js-yaml");
const { JSON_SCHEMA } = require("js-yaml");
import yaml, { JSON_SCHEMA } from "js-yaml";

module.exports = {
export default {
/**
* The order that this parser will run, in relation to other parsers.
*
Expand Down
9 changes: 4 additions & 5 deletions lib/pointer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"use strict";
import $Ref from "./ref";
import url from "./util/url";
import { InvalidPointerError, isHandledError, JSONParserError, MissingPointerError } from "./util/errors";

module.exports = Pointer;
export default Pointer;

const $Ref = require("./ref");
const url = require("./util/url");
const { JSONParserError, InvalidPointerError, MissingPointerError, isHandledError } = require("./util/errors");
const slashes = /\//g;
const tildes = /~/g;
const escapedSlash = /~1/g;
Expand Down
14 changes: 6 additions & 8 deletions lib/ref.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"use strict";
import Pointer from "./pointer";
import { InvalidPointerError, isHandledError, normalizeError } from "./util/errors";
import url from "./util/url";

module.exports = $Ref;

const Pointer = require("./pointer");
const { InvalidPointerError, isHandledError, normalizeError } = require("./util/errors");
const { safePointerToPath, stripHash, getHash } = require("./util/url");
export default $Ref;

/**
* This class represents a single JSON reference and its resolved value.
Expand Down Expand Up @@ -129,13 +127,13 @@ $Ref.prototype.resolve = function (path, options, friendlyPath, pathFromRoot) {
}

if (err.path === null) {
err.path = safePointerToPath(getHash(pathFromRoot));
err.path = url.safePointerToPath(url.getHash(pathFromRoot));
}

if (err instanceof InvalidPointerError) {
// this is a special case - InvalidPointerError is thrown when dereferencing external file,
// but the issue is caused by the source file that referenced the file that undergoes dereferencing
err.source = decodeURI(stripHash(pathFromRoot));
err.source = decodeURI(url.stripHash(pathFromRoot));
}

this.addError(err);
Expand Down
9 changes: 4 additions & 5 deletions lib/refs.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"use strict";
import { ono } from "@jsdevtools/ono";

const { ono } = require("@jsdevtools/ono");
const $Ref = require("./ref");
const url = require("./util/url");
import $Ref from "./ref";
import url from "./util/url";

module.exports = $Refs;
export default $Refs;

/**
* This class is a map of JSON references and their resolved values.
Expand Down
14 changes: 6 additions & 8 deletions lib/resolve-external.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"use strict";
import $Ref from "./ref";
import Pointer from "./pointer";
import parse from "./parse";
import url from "./util/url";
import { isHandledError } from "./util/errors";

const $Ref = require("./ref");
const Pointer = require("./pointer");
const parse = require("./parse");
const url = require("./util/url");
const { isHandledError } = require("./util/errors");

module.exports = resolveExternal;
export default resolveExternal;

/**
* Crawls the JSON schema, finds all external JSON references, and resolves their values.
Expand Down
12 changes: 6 additions & 6 deletions lib/resolvers/file.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";
const fs = require("fs");
const { ono } = require("@jsdevtools/ono");
const url = require("../util/url");
const { ResolverError } = require("../util/errors");
import fs from "fs";
import { ono } from "@jsdevtools/ono";

module.exports = {
import url from "../util/url";
import { ResolverError } from "../util/errors";

export default {
/**
* The order that this resolver will run, in relation to other resolvers.
*
Expand Down
13 changes: 6 additions & 7 deletions lib/resolvers/http.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"use strict";
import http from "http";
import https from "https";
import { ono } from "@jsdevtools/ono";

const http = require("http");
const https = require("https");
const { ono } = require("@jsdevtools/ono");
const url = require("../util/url");
const { ResolverError } = require("../util/errors");
import url from "../util/url";
import { ResolverError } from "../util/errors";

module.exports = {
export default {
/**
* The order that this resolver will run, in relation to other resolvers.
*
Expand Down
Loading