Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: export TSConfig in Interfaces #43

Merged
merged 2 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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