Skip to content

Commit

Permalink
chore: convert config to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed May 23, 2019
1 parent 288165d commit 12d7f59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
29 changes: 20 additions & 9 deletions src/lib/config.js → src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
var config = require('snyk-config')(__dirname + '/../..');
import * as snykConfig from 'snyk-config';
import * as userConfig from './user-config';
import * as url from 'url';

var DEFAULT_TIMEOUT = 5 * 60; // in seconds
const DEFAULT_TIMEOUT = 5 * 60; // in seconds
interface Config {
API: string;
disableSuggestions: string;
org: string;
ROOT: string;
timeout: number;
PROJECT_NAME: string;
}

const config: Config = snykConfig(__dirname + '/../..');

// allow user config override of the api end point
var endpoint = require('./user-config').get('endpoint');
const endpoint = userConfig.get('endpoint');
if (endpoint) {
config.API = endpoint;
}

var disableSuggestions = require('./user-config').get('disableSuggestions');
const disableSuggestions = userConfig.get('disableSuggestions');
if (disableSuggestions) {
config.disableSuggestions = disableSuggestions;
}

var org = require('./user-config').get('org');
const org = userConfig.get('org');
if (!config.org && org) {
config.org = org;
}

// client request timeout
// to change, set this config key to the desired value in seconds
// invalid (non-numeric) value will fallback to the default
var timeout = require('./user-config').get('timeout');
const timeout = userConfig.get('timeout');
if (!config.timeout) {
config.timeout = +timeout ? +timeout : DEFAULT_TIMEOUT;
}

// this is a bit of an assumption that our web site origin is the same
// as our API origin, but for now it's okay - RS 2015-10-16
if (!config.ROOT) {
var url = require('url');
var apiUrl = url.parse(config.API);
const apiUrl = url.parse(config.API);
config.ROOT = apiUrl.protocol + '//' + apiUrl.host;
}

module.exports = config;
export = config;
2 changes: 1 addition & 1 deletion src/lib/snyk-test/run-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import moduleToObject = require('snyk-module');
import * as depGraphLib from '@snyk/dep-graph';

import analytics = require('../analytics');
import config = require('../config');
import * as config from '../config';
import detect = require('../../lib/detect');
import plugins = require('../plugins');
import {ModuleInfo} from '../module-info';
Expand Down

0 comments on commit 12d7f59

Please sign in to comment.