Skip to content

Commit

Permalink
refactor: do not use require (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX authored May 8, 2019
1 parent 3b6b508 commit a17c19d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/loaders/http/httpLoader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FilesystemNodeType } from '@stoplight/graphite/backends/filesystem';
import { IHttpOperation } from '@stoplight/types';
import axios from 'axios';
import trimStart = require('lodash/trimStart');
import { trimStart } from 'lodash';
import { extname } from 'path';
import { IHttpLoaderOpts } from '../../types';
import { GraphFacade } from '../../utils/graphFacade';
Expand Down
12 changes: 5 additions & 7 deletions packages/core/src/utils/configMergerFactory.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { compact, merge } from 'lodash';
import { PartialPrismConfig, PrismConfig, PrismConfigFactory, resolveConfig } from '..';

const _compact = require('lodash/compact');
const _merge = require('lodash/merge');

/**
* Merges all passed configs. Each next config wil override each previous config.
*/
Expand All @@ -14,18 +12,18 @@ export function configMergerFactory<C, I>(
return (input: I, defaultConfig?: PartialPrismConfig<C, I>): C => {
const resolvedConfigs =
// remove any falsy resolved configs
_compact(
compact(
// remove falsy config props
_compact([baseConfig, ...configs])
compact([baseConfig, ...configs])
// resolve each config (resolveConfig is async)
.map((c: C) => resolveConfig(input, c, defaultConfig)),
.map(c => resolveConfig(input, c, defaultConfig)),
);

if (!resolvedConfigs.length) {
throw new Error('All configurations passed to the factory are undefined.');
}

// merge the configs over each other, in order
return _merge({}, ...resolvedConfigs);
return merge({}, ...resolvedConfigs);
};
}
2 changes: 1 addition & 1 deletion packages/core/src/utils/graphFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { IHttpOperation } from '@stoplight/types';
import * as fs from 'fs';
import { extname, resolve } from 'path';

import compact = require('lodash/compact');
import { compact } from 'lodash';

export class GraphFacade {
private fsBackend: FileSystemBackend;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-ignore
import * as jsf from 'json-schema-faker';
import cloneDeep = require('lodash/cloneDeep');
import { cloneDeep } from 'lodash';
import { IExampleGenerator } from './IExampleGenerator';

jsf.option({
Expand Down
2 changes: 1 addition & 1 deletion packages/http/src/router/__tests__/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IHttpMethod } from '@stoplight/prism-http';
import { Chance } from 'chance';
import defaults = require('lodash/defaults');
import { defaults } from 'lodash';

const chance = new Chance();
const httpMethods: IHttpMethod[] = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'];
Expand Down

0 comments on commit a17c19d

Please sign in to comment.