diff --git a/package.json b/package.json index ca33bc78..fd47809b 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@types/indent-string": "^3.2.0", "@types/lodash": "^4.14.120", "@types/mocha": "^5.2.5", - "@types/node": "^10.12.19", + "@types/node": "^10.12.20", "@types/proxyquire": "^1.3.28", "@types/wrap-ansi": "^3.0.0", "chai": "^4.2.0", diff --git a/src/ts-node.ts b/src/ts-node.ts index 7cdc0166..038825e0 100644 --- a/src/ts-node.ts +++ b/src/ts-node.ts @@ -1,16 +1,21 @@ import * as fs from 'fs' import * as path from 'path' import * as TSNode from 'ts-node' -import {parseConfigFileTextToJson} from 'typescript' import Debug from './debug' +const debug = Debug() + +let typescript: typeof import('typescript') +try { + typescript = require('typescript') +} catch (ex) { + debug('Cannot find typescript', ex) +} const tsconfigs: {[root: string]: TSConfig} = {} const rootDirs: string[] = [] const typeRoots = [`${__dirname}/../node_modules/@types`] -const debug = Debug() - export interface TSConfig { compilerOptions: { rootDir?: string @@ -60,8 +65,8 @@ function registerTSNode(root: string) { function loadTSConfig(root: string): TSConfig | undefined { const tsconfigPath = path.join(root, 'tsconfig.json') - if (fs.existsSync(tsconfigPath)) { - const tsconfig = parseConfigFileTextToJson( + if (fs.existsSync(tsconfigPath) && typescript) { + const tsconfig = typescript.parseConfigFileTextToJson( tsconfigPath, fs.readFileSync(tsconfigPath, 'utf8') ).config diff --git a/yarn.lock b/yarn.lock index 440aecc8..f8c5eecb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -121,10 +121,10 @@ dependencies: "@types/node" "*" -"@types/node@*", "@types/node@^10.12.19": - version "10.12.19" - resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.19.tgz#ca1018c26be01f07e66ac7fefbeb6407e4490c61" - integrity sha512-2NVovndCjJQj6fUUn9jCgpP4WSqr+u1SoUZMZyJkhGeBFsm6dE46l31S7lPUYt9uQ28XI+ibrJA1f5XyH5HNtA== +"@types/node@*", "@types/node@^10.12.20": + version "10.12.20" + resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.20.tgz#f79f959acd3422d0889bd1ead1664bd2d17cd367" + integrity sha512-9spv6SklidqxevvZyOUGjZVz4QRXGu2dNaLyXIFzFYZW0AGDykzPRIUFJXTlQXyfzAucddwTcGtJNim8zqSOPA== "@types/proxyquire@^1.3.28": version "1.3.28"