Skip to content

Commit

Permalink
refactor: use extension in relative imports (#2320)
Browse files Browse the repository at this point in the history
This is the new EMS way of doing things.

Closes #2292
  • Loading branch information
jimmywarting authored Nov 8, 2021
1 parent 5a7548e commit e5788a8
Show file tree
Hide file tree
Showing 55 changed files with 91 additions and 84 deletions.
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
],
"newlines-between": "always"
}],
"import/extensions": [
"error",
"always",
{
"ignorePackages": true
}
],
"prettier/prettier": "error",
"no-param-reassign": 0, // needs to be eliminated in future
"no-use-before-define": [2, "nofunc"] // needs to be eliminated in future
Expand Down
2 changes: 1 addition & 1 deletion src/commonjs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'; // eslint-disable-line

const { default: SwaggerClient } = require('./index');
const { default: SwaggerClient } = require('./index.js');

// add backwards compatibility with older versions of swagger-ui
// by exporting one single symbol.
Expand Down
14 changes: 7 additions & 7 deletions src/execute/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import isPlainObject from 'lodash/isPlainObject';
import url from 'url';
import cookie from 'cookie';

import stockHttp, { mergeInQueryOrForm } from '../http';
import createError from '../specmap/lib/create-error';
import SWAGGER2_PARAMETER_BUILDERS from './swagger2/parameter-builders';
import * as OAS3_PARAMETER_BUILDERS from './oas3/parameter-builders';
import oas3BuildRequest from './oas3/build-request';
import swagger2BuildRequest from './swagger2/build-request';
import { getOperationRaw, legacyIdFromPathMethod, isOAS3 } from '../helpers';
import stockHttp, { mergeInQueryOrForm } from '../http/index.js';
import createError from '../specmap/lib/create-error.js';
import SWAGGER2_PARAMETER_BUILDERS from './swagger2/parameter-builders.js';
import * as OAS3_PARAMETER_BUILDERS from './oas3/parameter-builders.js';
import oas3BuildRequest from './oas3/build-request.js';
import swagger2BuildRequest from './swagger2/build-request.js';
import { getOperationRaw, legacyIdFromPathMethod, isOAS3 } from '../helpers.js';

const arrayOrEmpty = (ar) => (Array.isArray(ar) ? ar : []);

Expand Down
4 changes: 2 additions & 2 deletions src/execute/oas3/parameter-builders.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import stylize, { encodeDisallowedCharacters } from './style-serializer';
import serialize from './content-serializer';
import stylize, { encodeDisallowedCharacters } from './style-serializer.js';
import serialize from './content-serializer.js';

export function path({ req, value, parameter }) {
const { name, style, explode, content } = parameter;
Expand Down
4 changes: 2 additions & 2 deletions src/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import qs from 'qs';
import jsYaml from 'js-yaml';
import { FormData, File, Blob } from 'formdata-node';

import { encodeDisallowedCharacters } from '../execute/oas3/style-serializer';
import foldFormDataToRequest from './fold-formdata-to-request.node';
import { encodeDisallowedCharacters } from '../execute/oas3/style-serializer.js';
import foldFormDataToRequest from './fold-formdata-to-request.node.js';

// For testing
export const self = {
Expand Down
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Url from 'url';

import Http, { makeHttp, serializeRes, serializeHeaders } from './http';
import Resolver, { clearCache } from './resolver';
import resolveSubtree from './subtree-resolver';
import { makeApisTagOperation } from './interfaces';
import { execute, buildRequest, baseUrl } from './execute';
import { opId } from './helpers';
import Http, { makeHttp, serializeRes, serializeHeaders } from './http/index.js';
import Resolver, { clearCache } from './resolver.js';
import resolveSubtree from './subtree-resolver/index.js';
import { makeApisTagOperation } from './interfaces.js';
import { execute, buildRequest, baseUrl } from './execute/index.js';
import { opId } from './helpers.js';

Swagger.http = Http;
Swagger.makeHttp = makeHttp.bind(null, Swagger.http);
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { eachOperation, opId } from './helpers';
import { eachOperation, opId } from './helpers.js';

const nullFn = () => null;

Expand Down
8 changes: 4 additions & 4 deletions src/resolver.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Http from './http';
import mapSpec, { plugins } from './specmap';
import { normalizeSwagger } from './helpers';
import { ACCEPT_HEADER_VALUE_FOR_DOCUMENTS } from './constants';
import Http from './http/index.js';
import mapSpec, { plugins } from './specmap/index.js';
import { normalizeSwagger } from './helpers.js';
import { ACCEPT_HEADER_VALUE_FOR_DOCUMENTS } from './constants.js';

export function makeFetchJSON(http, opts = {}) {
const { requestInterceptor, responseInterceptor } = opts;
Expand Down
12 changes: 6 additions & 6 deletions src/specmap/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import lib from './lib';
import refs from './lib/refs';
import allOf from './lib/all-of';
import parameters from './lib/parameters';
import properties from './lib/properties';
import ContextTree from './lib/context-tree';
import lib from './lib/index.js';
import refs from './lib/refs.js';
import allOf from './lib/all-of.js';
import parameters from './lib/parameters.js';
import properties from './lib/properties.js';
import ContextTree from './lib/context-tree.js';

const HARD_LIMIT = 100;
const noop = () => {};
Expand Down
2 changes: 1 addition & 1 deletion src/specmap/lib/all-of.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isEmpty from 'lodash/isEmpty';

import { isFreelyNamed, generateAbsoluteRefPatches } from '../helpers';
import { isFreelyNamed, generateAbsoluteRefPatches } from '../helpers.js';

export default {
key: 'allOf',
Expand Down
2 changes: 1 addition & 1 deletion src/specmap/lib/parameters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lib from '.';
import lib from './index.js';

export default {
key: 'parameters',
Expand Down
2 changes: 1 addition & 1 deletion src/specmap/lib/properties.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lib from '.';
import lib from './index.js';

export default {
key: 'properties',
Expand Down
8 changes: 4 additions & 4 deletions src/specmap/lib/refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'cross-fetch/polyfill'; /* global fetch */
import jsYaml from 'js-yaml';
import url from 'url';

import lib from '.';
import createError from './create-error';
import { isFreelyNamed, absolutifyPointer } from '../helpers';
import { ACCEPT_HEADER_VALUE_FOR_DOCUMENTS } from '../../constants';
import lib from './index.js';
import createError from './create-error.js';
import { isFreelyNamed, absolutifyPointer } from '../helpers.js';
import { ACCEPT_HEADER_VALUE_FOR_DOCUMENTS } from '../../constants.js';

const ABSOLUTE_URL_REGEXP = new RegExp('^([a-z]+://|//)', 'i');

Expand Down
4 changes: 2 additions & 2 deletions src/subtree-resolver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

import get from 'lodash/get';

import resolve from '../resolver';
import { normalizeSwagger } from '../helpers';
import resolve from '../resolver.js';
import { normalizeSwagger } from '../helpers.js';

export default async function resolveSubtree(obj, path, opts = {}) {
const {
Expand Down
2 changes: 1 addition & 1 deletion test/bugs/1719.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';
import fs from 'fs';
import jsYaml from 'js-yaml';

import resolveSubtree from '../../src/subtree-resolver';
import resolveSubtree from '../../src/subtree-resolver/index.js';

const testDoc = jsYaml.load(
fs.readFileSync(path.join('test', 'data', 'issue-1719-ref-object-reference.yaml'), 'utf8')
Expand Down
2 changes: 1 addition & 1 deletion test/bugs/editor-1661.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://github.com/swagger-api/swagger-editor/issues/1661

import Swagger from '../../src';
import Swagger from '../../src/index.js';

const spec = {
paths: {
Expand Down
2 changes: 1 addition & 1 deletion test/bugs/ui-4071.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// https://github.com/swagger-api/swagger-ui/issues/4071
import { buildRequest } from '../../src/execute';
import { buildRequest } from '../../src/execute/index.js';

const spec = {
openapi: '3.0.0',
Expand Down
2 changes: 1 addition & 1 deletion test/bugs/ui-4228.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://github.com/swagger-api/swagger-ui/issues/4228

import Swagger from '../../src';
import Swagger from '../../src/index.js';

const spec = {
paths: {
Expand Down
2 changes: 1 addition & 1 deletion test/bugs/ui-4466.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// https://github.com/swagger-api/swagger-ui/issues/4466
// https://github.com/swagger-api/swagger-ui/issues/4467

import resolveSubtree from '../../src/subtree-resolver';
import resolveSubtree from '../../src/subtree-resolver/index.js';

const spec = {
swagger: '2.0',
Expand Down
2 changes: 1 addition & 1 deletion test/build-artifacts/commonjs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// commonjs import is here by design to test native node.js require function on artifact
const SwaggerClient = require('../../lib/commonjs');
const SwaggerClient = require('../../lib/commonjs.js');

describe('babel commonjs artifact', () => {
test('should export a function', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/build-artifacts/es.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '@babel/runtime-corejs3/regenerator';
import SwaggerClient from '../../es';
import SwaggerClient from '../../es/index.js';

describe('babel ES6 imports artifact', () => {
test('should export a function', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/build-artifacts/umd.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from 'fs';
import path from 'path';

import SwaggerClient from '../../dist/swagger-client.browser';
import SwaggerClientMin from '../../dist/swagger-client.browser.min';
import SwaggerClient from '../../dist/swagger-client.browser.js';
import SwaggerClientMin from '../../dist/swagger-client.browser.min.js';

describe('webpack browser umd build', () => {
test('should export a function', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import url from 'url';
import path from 'path';
import fs from 'fs';

import Swagger from '../src/index';
import Swagger from '../src/index.js';

describe('http', () => {
let server;
Expand Down
2 changes: 1 addition & 1 deletion test/execute/baseurl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { baseUrl } from '../../src/execute';
import { baseUrl } from '../../src/execute/index.js';

// Supported shape... { spec, operationId, parameters, securities, fetch }
// One can use operationId or pathItem + method
Expand Down
4 changes: 2 additions & 2 deletions test/execute/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Readable } from 'stream';

import { execute, buildRequest, self as stubs } from '../../src/execute';
import { normalizeSwagger } from '../../src/helpers';
import { execute, buildRequest, self as stubs } from '../../src/execute/index.js';
import { normalizeSwagger } from '../../src/helpers.js';

// Supported shape... { spec, operationId, parameters, securities, fetch }
// One can use operationId or pathItem + method
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { normalizeSwagger, getOperationRaw, idFromPathMethod } from '../src/helpers';
import { normalizeSwagger, getOperationRaw, idFromPathMethod } from '../src/helpers.js';

describe('helpers', () => {
describe('idFromPathMethod', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/http/http-multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import fetchMock from 'fetch-mock';
import { File, Blob } from 'formdata-node';
import { fileFromPathSync } from 'formdata-node/lib/cjs/fileFromPath';

import { buildRequest } from '../../src/execute';
import sampleMultipartOpenApi2 from '../data/sample-multipart-oas2';
import sampleMultipartOpenApi3 from '../data/sample-multipart-oas3';
import { buildRequest } from '../../src/execute/index.js';
import sampleMultipartOpenApi2 from '../data/sample-multipart-oas2.js';
import sampleMultipartOpenApi3 from '../data/sample-multipart-oas3.js';

/**
* fetch-mock uses node-fetch under the hood
Expand Down
2 changes: 1 addition & 1 deletion test/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import http, {
serializeRes,
shouldDownloadAsText,
isFile,
} from '../../src/http';
} from '../../src/http/index.js';

describe('http', () => {
let xapp;
Expand Down
2 changes: 1 addition & 1 deletion test/index-authorizations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Swagger from '../src/index';
import Swagger from '../src/index.js';

describe('(instance) #execute', () => {
test('should be able to execute a simple operation', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import xmock from 'xmock';
import cloneDeep from 'lodash/cloneDeep';

import Swagger from '../src/index';
import Swagger from '../src/index.js';

describe('constructor', () => {
afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion test/interfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
makeApisTagOperationsOperationExecute,
makeApisTagOperation,
self as stubs,
} from '../src/interfaces';
} from '../src/interfaces.js';

describe('intefaces', () => {
afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion test/oas3/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import url from 'url';
import path from 'path';
import fs from 'fs';

import Swagger from '../../src/index';
import Swagger from '../../src/index.js';

describe('http - OpenAPI Specification 3.0', () => {
let server;
Expand Down
2 changes: 1 addition & 1 deletion test/oas3/execute/authorization.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import btoa from 'btoa';

import { buildRequest } from '../../../src/execute';
import { buildRequest } from '../../../src/execute/index.js';

// OAS 3.0 Authorization

Expand Down
2 changes: 1 addition & 1 deletion test/oas3/execute/build-request.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// https://github.com/swagger-api/swagger-js/issues/1116
import { buildRequest } from '../../../src/execute';
import { buildRequest } from '../../../src/execute/index.js';

describe('buildRequest - OAS 3.0.x', () => {
describe('test accept header', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/oas3/execute/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
import jsYaml from 'js-yaml';
import { escape } from 'querystring';

import { buildRequest, baseUrl } from '../../../src/execute';
import { buildRequest, baseUrl } from '../../../src/execute/index.js';

const petstoreSpec = jsYaml.load(
fs.readFileSync(path.join('test', 'oas3', 'data', 'petstore-oas3.yaml'), 'utf8')
Expand Down
2 changes: 1 addition & 1 deletion test/oas3/execute/style-explode/cookie.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildRequest } from '../../../../src/execute';
import { buildRequest } from '../../../../src/execute/index.js';

describe('OAS 3.0 - buildRequest w/ `style` & `explode` - cookie parameters', () => {
describe('primitive values', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/oas3/execute/style-explode/header.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildRequest } from '../../../../src/execute';
import { buildRequest } from '../../../../src/execute/index.js';

describe('OAS 3.0 - buildRequest w/ `style` & `explode` - header parameters', () => {
describe('primitive values', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/oas3/execute/style-explode/path.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildRequest } from '../../../../src/execute';
import { buildRequest } from '../../../../src/execute/index.js';

describe('OAS 3.0 - buildRequest w/ `style` & `explode` - path parameters', () => {
describe('primitive values', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/oas3/execute/style-explode/query.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildRequest } from '../../../../src/execute';
import { buildRequest } from '../../../../src/execute/index.js';

// Expecting the space to become `%20`, not `+`, because it's just better that way
// See: https://stackoverflow.com/a/40292688
Expand Down
2 changes: 1 addition & 1 deletion test/oas3/execute/style-serializer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { encodeDisallowedCharacters } from '../../../src/execute/oas3/style-serializer';
import { encodeDisallowedCharacters } from '../../../src/execute/oas3/style-serializer.js';

describe('OAS3 style serializer', () => {
describe('encodeDisallowedCharacters', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/oas3/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isOAS3, isSwagger2 } from '../../src/helpers';
import { isOAS3, isSwagger2 } from '../../src/helpers.js';

describe('helpers - OpenAPI Specification 3.0', () => {
describe('isOAS3', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import fs from 'fs';
import jsYaml from 'js-yaml';

import Swagger from '../src';
import Swagger from '../src/index.js';

describe('resolver', () => {
afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion test/resolver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fs from 'fs';
import Path from 'path';
import nock from 'nock';

import Swagger from '../../src/index';
import Swagger from '../../src/index.js';

const testDocuments = fs
.readdirSync(Path.join(__dirname))
Expand Down
2 changes: 1 addition & 1 deletion test/specmap/all-of.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import xmock from 'xmock';

import mapSpec, { plugins } from '../../src/specmap';
import mapSpec, { plugins } from '../../src/specmap/index.js';

describe('allOf', () => {
afterEach(() => {
Expand Down
Loading

0 comments on commit e5788a8

Please sign in to comment.