From 45a53a982154dbee9810f17426856a132057c1dc Mon Sep 17 00:00:00 2001 From: ssube Date: Fri, 30 Aug 2019 00:24:12 -0500 Subject: [PATCH] fix(build): switch to relative imports --- src/config/args.ts | 2 +- src/config/index.ts | 10 +++++----- src/config/schema.ts | 8 ++++---- src/config/type/Env.ts | 2 +- src/config/type/Include.ts | 2 +- src/config/type/Regexp.ts | 2 +- src/config/type/Stream.ts | 2 +- src/index.ts | 24 +++++++++++++++--------- src/parser/YamlParser.ts | 4 ++-- src/rule.ts | 10 +++++----- src/visitor/context.ts | 2 +- src/visitor/index.ts | 4 ++-- test/TestRule.ts | 4 ++-- test/harness.ts | 4 +++- test/parser/TestYamlParser.ts | 4 ++-- test/visitor/TestContext.ts | 3 ++- 16 files changed, 48 insertions(+), 39 deletions(-) diff --git a/src/config/args.ts b/src/config/args.ts index 3652b12..3e08427 100644 --- a/src/config/args.ts +++ b/src/config/args.ts @@ -1,6 +1,6 @@ import { Options, showCompletionScript, usage } from 'yargs'; -import { VERSION_INFO } from 'src/version'; +import { VERSION_INFO } from '../version'; export const CONFIG_ARGS_NAME = 'config-name'; export const CONFIG_ARGS_PATH = 'config-path'; diff --git a/src/config/index.ts b/src/config/index.ts index 3ffbbe3..539ef5c 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,11 +1,11 @@ import { isNil, isString } from 'lodash'; import { join } from 'path'; -import { CONFIG_ENV, CONFIG_SCHEMA } from 'src/config/schema'; -import { includeSchema } from 'src/config/type/Include'; -import { NotFoundError } from 'src/error/NotFoundError'; -import { YamlParser } from 'src/parser/YamlParser'; -import { readFileSync } from 'src/source'; +import { CONFIG_ENV, CONFIG_SCHEMA } from './schema'; +import { includeSchema } from './type/Include'; +import { NotFoundError } from '../error/NotFoundError'; +import { YamlParser } from '../parser/YamlParser'; +import { readFileSync } from '../source'; includeSchema.schema = CONFIG_SCHEMA; diff --git a/src/config/schema.ts b/src/config/schema.ts index c9adbd1..2e11bba 100644 --- a/src/config/schema.ts +++ b/src/config/schema.ts @@ -1,9 +1,9 @@ import { DEFAULT_SAFE_SCHEMA, Schema } from 'js-yaml'; -import { envType } from 'src/config/type/Env'; -import { includeType } from 'src/config/type/Include'; -import { regexpType } from 'src/config/type/Regexp'; -import { streamType } from 'src/config/type/Stream'; +import { envType } from './type/Env'; +import { includeType } from './type/Include'; +import { regexpType } from './type/Regexp'; +import { streamType } from './type/Stream'; export const CONFIG_ENV = 'SALTY_HOME'; export const CONFIG_SCHEMA = Schema.create([DEFAULT_SAFE_SCHEMA], [ diff --git a/src/config/type/Env.ts b/src/config/type/Env.ts index 9301ee1..ee281e4 100644 --- a/src/config/type/Env.ts +++ b/src/config/type/Env.ts @@ -1,6 +1,6 @@ import { Type as YamlType } from 'js-yaml'; -import { NotFoundError } from 'src/error/NotFoundError'; +import { NotFoundError } from '../../error/NotFoundError'; export const envType = new YamlType('!env', { kind: 'scalar', diff --git a/src/config/type/Include.ts b/src/config/type/Include.ts index f1b153b..d21df55 100644 --- a/src/config/type/Include.ts +++ b/src/config/type/Include.ts @@ -3,7 +3,7 @@ import { SAFE_SCHEMA, safeLoad, Type as YamlType } from 'js-yaml'; import { BaseError } from 'noicejs'; import { join } from 'path'; -import { NotFoundError } from 'src/error/NotFoundError'; +import { NotFoundError } from '../../error/NotFoundError'; // work around the circular dependency by setting the schema later export const includeSchema = { diff --git a/src/config/type/Regexp.ts b/src/config/type/Regexp.ts index 89521e3..47f2317 100644 --- a/src/config/type/Regexp.ts +++ b/src/config/type/Regexp.ts @@ -1,7 +1,7 @@ import { Type as YamlType } from 'js-yaml'; import { isNil } from 'lodash'; -import { InvalidArgumentError } from 'src/error/InvalidArgumentError'; +import { InvalidArgumentError } from '../../error/InvalidArgumentError'; export const REGEXP_REGEXP = /\/(.*)\/([gimuy]*)/; diff --git a/src/config/type/Stream.ts b/src/config/type/Stream.ts index 6d28626..07147cf 100644 --- a/src/config/type/Stream.ts +++ b/src/config/type/Stream.ts @@ -1,6 +1,6 @@ import { Type as YamlType } from 'js-yaml'; -import { NotFoundError } from 'src/error/NotFoundError'; +import { NotFoundError } from '../../error/NotFoundError'; const ALLOWED_STREAMS = new Set([ 'stdout', diff --git a/src/index.ts b/src/index.ts index 4705633..de62182 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,14 +1,20 @@ import { createLogger } from 'bunyan'; -import { loadConfig } from 'src/config'; -import { CONFIG_ARGS_NAME, CONFIG_ARGS_PATH, parseArgs } from 'src/config/args'; -import { YamlParser } from 'src/parser/YamlParser'; -import { loadRules, resolveRules, visitRules } from 'src/rule'; -import { loadSource, writeSource } from 'src/source'; -import { VERSION_INFO } from 'src/version'; -import { VisitorContext } from 'src/visitor/context'; +import { loadConfig } from './config'; +import { CONFIG_ARGS_NAME, CONFIG_ARGS_PATH, parseArgs } from './config/args'; +import { YamlParser } from './parser/YamlParser'; +import { loadRules, resolveRules, visitRules } from './rule'; +import { loadSource, writeSource } from './source'; +import { VERSION_INFO } from './version'; +import { VisitorContext } from './visitor/context'; -const MODES = ['check', 'fix', 'list']; +enum MODES { + check = 'check', + fix = 'fix', + list = 'list', +} + +const MODES_LIST: Array = [MODES.check, MODES.fix, MODES.list]; const STATUS_SUCCESS = 0; const STATUS_ERROR = 1; @@ -22,7 +28,7 @@ export async function main(argv: Array): Promise { logger.info({ args }, 'main arguments'); // check mode - if (!MODES.includes(mode)) { + if (!MODES_LIST.includes(mode)) { logger.error({ mode }, 'unsupported mode'); return STATUS_ERROR; } diff --git a/src/parser/YamlParser.ts b/src/parser/YamlParser.ts index 3e9a2e3..c081074 100644 --- a/src/parser/YamlParser.ts +++ b/src/parser/YamlParser.ts @@ -1,7 +1,7 @@ import { safeDump, safeLoadAll } from 'js-yaml'; -import { CONFIG_SCHEMA } from 'src/config/schema'; -import { Parser } from 'src/parser'; +import { CONFIG_SCHEMA } from '../config/schema'; +import { Parser } from '../parser'; export class YamlParser implements Parser { dump(...data: Array): string { diff --git a/src/rule.ts b/src/rule.ts index 85c1377..f34c44d 100644 --- a/src/rule.ts +++ b/src/rule.ts @@ -3,11 +3,11 @@ import { JSONPath } from 'jsonpath-plus'; import { cloneDeep, intersection, isNil } from 'lodash'; import { LogLevel } from 'noicejs'; -import { YamlParser } from 'src/parser/YamlParser'; -import { readFileSync } from 'src/source'; -import { Visitor } from 'src/visitor'; -import { VisitorContext } from 'src/visitor/context'; -import { VisitorResult } from 'src/visitor/result'; +import { YamlParser } from './parser/YamlParser'; +import { readFileSync } from './source'; +import { Visitor } from './visitor'; +import { VisitorContext } from './visitor/context'; +import { VisitorResult } from './visitor/result'; export interface RuleData { // metadata diff --git a/src/visitor/context.ts b/src/visitor/context.ts index 2242669..af683db 100644 --- a/src/visitor/context.ts +++ b/src/visitor/context.ts @@ -1,7 +1,7 @@ import * as Ajv from 'ajv'; import { Logger } from 'noicejs'; -import { VisitorResult } from 'src/visitor/result'; +import { VisitorResult } from './result'; export interface VisitorContextOptions { coerce: boolean; diff --git a/src/visitor/index.ts b/src/visitor/index.ts index 42dfe41..6ede915 100644 --- a/src/visitor/index.ts +++ b/src/visitor/index.ts @@ -1,5 +1,5 @@ -import { VisitorContext } from 'src/visitor/context'; -import { VisitorResult } from 'src/visitor/result'; +import { VisitorContext } from './context'; +import { VisitorResult } from './result'; export interface Visitor { /** diff --git a/test/TestRule.ts b/test/TestRule.ts index 2812cc5..a66e59a 100644 --- a/test/TestRule.ts +++ b/test/TestRule.ts @@ -2,8 +2,8 @@ import { expect } from 'chai'; import { ConsoleLogger } from 'noicejs'; import { mock } from 'sinon'; -import { makeSelector, resolveRules, Rule, visitRules } from 'src/rule'; -import { VisitorContext } from 'src/visitor/context'; +import { makeSelector, resolveRules, Rule, visitRules } from '../src/rule'; +import { VisitorContext } from '../src/visitor/context'; const TEST_RULES = [new Rule({ name: 'foo', diff --git a/test/harness.ts b/test/harness.ts index aa9671c..abc3b64 100644 --- a/test/harness.ts +++ b/test/harness.ts @@ -1 +1,3 @@ -console.log('test harness'); \ No newline at end of file +import sourceMapSupport from 'source-map-support' + +sourceMapSupport.install() diff --git a/test/parser/TestYamlParser.ts b/test/parser/TestYamlParser.ts index 062dd28..a64b380 100644 --- a/test/parser/TestYamlParser.ts +++ b/test/parser/TestYamlParser.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import { mock } from 'sinon'; -import { YamlParser } from 'src/parser/YamlParser'; + +import { YamlParser } from '../../src/parser/YamlParser'; describe('yaml parser', () => { describe('dump documents', () => { diff --git a/test/visitor/TestContext.ts b/test/visitor/TestContext.ts index a3bdb4b..6aed394 100644 --- a/test/visitor/TestContext.ts +++ b/test/visitor/TestContext.ts @@ -1,7 +1,8 @@ import { expect } from 'chai'; -import { VisitorContext } from 'src/visitor/context'; import { ConsoleLogger } from 'noicejs'; +import { VisitorContext } from '../../src/visitor/context'; + describe('visitor context', () => { it('should merge results', () => { const firstCtx = new VisitorContext({