Skip to content

Commit

Permalink
fix: export TSConfig in Interfaces (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
RasPhilCo authored Sep 16, 2020
1 parent 10d3de9 commit 187f5b8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
13 changes: 1 addition & 12 deletions src/config/ts-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as fs from 'fs'
import * as path from 'path'
import * as TSNode from 'ts-node'

import {TSConfig} from '../interfaces/ts-config'
import {Debug} from './util'
// eslint-disable-next-line new-cap
const debug = Debug()
Expand All @@ -10,18 +11,6 @@ const tsconfigs: {[root: string]: TSConfig} = {}
const rootDirs: string[] = []
const typeRoots = [`${__dirname}/../node_modules/@types`]

export interface TSConfig {
compilerOptions: {
rootDir?: string;
rootDirs?: string[];
outDir?: string;
target?: string;
esModuleInterop?: boolean;
experimentalDecorators?: boolean;
emitDecoratorMetadata?: boolean;
};
}

function loadTSConfig(root: string): TSConfig | undefined {
const tsconfigPath = path.join(root, 'tsconfig.json')
let typescript: typeof import('typescript') | undefined
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export {Manifest} from './manifest'
export {PJSON} from './pjson'
export {Plugin, PluginOptions, Options} from './plugin'
export {Topic} from './topic'
export {TSConfig} from './ts-config'
11 changes: 11 additions & 0 deletions src/interfaces/ts-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface TSConfig {
compilerOptions: {
rootDir?: string;
rootDirs?: string[];
outDir?: string;
target?: string;
esModuleInterop?: boolean;
experimentalDecorators?: boolean;
emitDecoratorMetadata?: boolean;
};
}
10 changes: 5 additions & 5 deletions test/config/ts-node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ import * as path from 'path'
import * as proxyquire from 'proxyquire'
import * as tsNode from 'ts-node'

import {TSConfig} from '../../src/config/ts-node'
import {Interfaces} from '../../src'

import {expect, fancy} from './test'

const root = path.resolve(__dirname, 'fixtures/typescript')
const orig = 'src/hooks/init.ts'
let tsNodeRegisterCallArguments: any[] = []

const DEFAULT_TS_CONFIG: TSConfig = {
const DEFAULT_TS_CONFIG: Interfaces.TSConfig = {
compilerOptions: {},
}

const withMockTsConfig = (config: TSConfig = DEFAULT_TS_CONFIG) => {
const withMockTsConfig = (config: Interfaces.TSConfig = DEFAULT_TS_CONFIG) => {
const tsNodePlugin = proxyquire('../../src/config/ts-node', {fs: {
existsSync: () => true,
readFileSync: () => JSON.stringify(config),
}})

// This prints "loadTSConfig unstubbed" not "loadTSConfig proxyquire"!
tsNodePlugin.tsPath('poop', 'asdf')
// This prints "loadInterfaces.TSConfig unstubbed" not "loadInterfaces.TSConfig proxyquire"!
tsNodePlugin.tsPath('qwerty', 'asdf')

return fancy
.add('tsNodePlugin', () => tsNodePlugin)
Expand Down

0 comments on commit 187f5b8

Please sign in to comment.