filing-cabinet
Advanced tools
Comparing version 2.5.1 to 2.6.0
79
index.js
@@ -129,2 +129,35 @@ 'use strict'; | ||
function getCompilerOptionsFromTsConfig(tsConfig) { | ||
if (!ts) { | ||
ts = require('typescript'); | ||
} | ||
let compilerOptions = {}; | ||
debug('given typescript config: ', tsConfig); | ||
if (!tsConfig) { | ||
debug('no tsconfig given, defaulting'); | ||
} else if (typeof tsConfig === 'string') { | ||
debug('string tsconfig given, parsing'); | ||
try { | ||
const tsParsedConfig = ts.readJsonConfigFile(tsConfig, ts.sys.readFile); | ||
compilerOptions = ts.parseJsonSourceFileConfigFileContent(tsParsedConfig, ts.sys, path.dirname(tsConfig)).options; | ||
debug('successfully parsed tsconfig'); | ||
} catch (e) { | ||
debug('could not parse tsconfig'); | ||
throw new Error('could not read tsconfig'); | ||
} | ||
} else { | ||
compilerOptions = ts.convertCompilerOptionsFromJson(tsConfig.compilerOptions).options; | ||
} | ||
debug('processed typescript config: ', tsConfig); | ||
debug('processed typescript config type: ', typeof tsConfig); | ||
return compilerOptions; | ||
} | ||
/** | ||
@@ -143,3 +176,3 @@ * @private | ||
*/ | ||
function jsLookup({dependency, filename, directory, config, webpackConfig, configPath, nodeModulesConfig, ast}) { | ||
function jsLookup({dependency, filename, directory, config, webpackConfig, configPath, nodeModulesConfig, ast, tsConfig}) { | ||
const type = module.exports._getJSType({ | ||
@@ -170,3 +203,3 @@ config: config, | ||
debug('using commonjs resolver'); | ||
return commonJSLookup({dependency, filename, directory, nodeModulesConfig}); | ||
return commonJSLookup({dependency, filename, directory, nodeModulesConfig, tsConfig}); | ||
@@ -180,3 +213,3 @@ case 'webpack': | ||
debug('using commonjs resolver for es6'); | ||
return commonJSLookup({dependency, filename, directory, nodeModulesConfig}); | ||
return commonJSLookup({dependency, filename, directory, nodeModulesConfig, tsConfig}); | ||
} | ||
@@ -188,31 +221,4 @@ } | ||
let compilerOptions = {}; | ||
let compilerOptions = getCompilerOptionsFromTsConfig(tsConfig); | ||
if (!ts) { | ||
ts = require('typescript'); | ||
} | ||
debug('given typescript config: ', tsConfig); | ||
if (!tsConfig) { | ||
debug('no tsconfig given, defaulting'); | ||
} else if (typeof tsConfig === 'string') { | ||
debug('string tsconfig given, parsing'); | ||
try { | ||
const tsParsedConfig = ts.readJsonConfigFile(tsConfig, ts.sys.readFile); | ||
compilerOptions = ts.parseJsonSourceFileConfigFileContent(tsParsedConfig, ts.sys, path.dirname(tsConfig)).options; | ||
debug('successfully parsed tsconfig'); | ||
} catch (e) { | ||
debug('could not parse tsconfig'); | ||
throw new Error('could not read tsconfig'); | ||
} | ||
} else { | ||
compilerOptions = ts.convertCompilerOptionsFromJson(tsConfig.compilerOptions).options; | ||
} | ||
debug('processed typescript config: ', tsConfig); | ||
debug('processed typescript config type: ', typeof tsConfig); | ||
// Preserve for backcompat. Consider removing this as a breaking change. | ||
@@ -247,3 +253,3 @@ if (!compilerOptions.module) { | ||
function commonJSLookup({dependency, filename, directory, nodeModulesConfig}) { | ||
function commonJSLookup({dependency, filename, directory, nodeModulesConfig, tsConfig}) { | ||
if (!resolve) { | ||
@@ -279,5 +285,12 @@ resolve = require('resolve'); | ||
const tsCompilerOptions = getCompilerOptionsFromTsConfig(tsConfig); | ||
const allowMIxedJsAndTs = tsCompilerOptions.allowJs; | ||
let extensions = ['.js', '.jsx']; | ||
if (allowMIxedJsAndTs) { | ||
extensions = extensions.concat(['.ts', '.tsx']); | ||
} | ||
try { | ||
result = resolve.sync(dependency, { | ||
extensions: ['.js', '.jsx'], | ||
extensions, | ||
basedir: directory, | ||
@@ -284,0 +297,0 @@ packageFilter: nodeModulesConfig && nodeModulesConfig.entry ? packageFilter : undefined, |
{ | ||
"name": "filing-cabinet", | ||
"version": "2.5.1", | ||
"version": "2.6.0", | ||
"description": "Find files based on partial paths", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -40,2 +40,3 @@ ### filing-cabinet [![npm](http://img.shields.io/npm/v/filing-cabinet.svg)](https://npmjs.org/package/filing-cabinet) [![npm](http://img.shields.io/npm/dm/filing-cabinet.svg)](https://npmjs.org/package/filing-cabinet) | ||
* `tsConfig`: (optional) path to a typescript configuration. Could also be an object representing a pre-parsed typescript config. | ||
* `noTypeDefinitions`: (optional) For typescript files, whether to prefer `*.js` over `*.d.ts`. | ||
@@ -42,0 +43,0 @@ ### Registered languages |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17119
353
75