ts-unused-exports
Advanced tools
Comparing version 2.0.6 to 2.0.7
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var fs_1 = require("fs"); | ||
var ts = require("typescript"); | ||
var path_1 = require("path"); | ||
var stripJsonComments = require("strip-json-comments"); | ||
var parser_1 = require("./parser"); | ||
var analyzer_1 = require("./analyzer"); | ||
var parseTsConfig = function (tsconfigPath) { | ||
var basePath = path_1.resolve(path_1.dirname(tsconfigPath)); | ||
try { | ||
var parseJsonResult = ts.parseConfigFileTextToJson(tsconfigPath, fs_1.readFileSync(tsconfigPath, { encoding: 'utf8' })); | ||
if (parseJsonResult.error) | ||
throw parseJsonResult.error; | ||
var result = ts.parseJsonConfigFileContent(parseJsonResult.config, ts.sys, basePath); | ||
if (result.errors.length) | ||
throw result.errors; | ||
return { | ||
baseUrl: result.raw | ||
&& result.raw.compilerOptions | ||
&& result.raw.compilerOptions.baseUrl, | ||
files: result.fileNames, | ||
}; | ||
} | ||
catch (e) { | ||
throw "\n Cannot parse '" + tsconfigPath + "'.\n\n " + JSON.stringify(e) + "\n "; | ||
} | ||
}; | ||
var loadTsConfig = function (tsconfigPath, explicitFiles) { | ||
var rawTsConfig = JSON.parse(stripJsonComments(fs_1.readFileSync(tsconfigPath, { encoding: 'utf8' }))); | ||
var tsConfig = explicitFiles | ||
? __assign({}, rawTsConfig, { files: explicitFiles }) : rawTsConfig; | ||
var files = tsConfig.files, compilerOptions = tsConfig.compilerOptions; | ||
if (!files) | ||
throw "\n The tsconfig does not contain a \"files\" key:\n\n " + tsconfigPath + "\n\n Consider either passing an explicit list of files or adding the \"files\" key.\n "; | ||
var baseUrl = compilerOptions && compilerOptions.baseUrl; | ||
return { baseUrl: baseUrl, files: files }; | ||
var _a = parseTsConfig(tsconfigPath), baseUrl = _a.baseUrl, files = _a.files; | ||
return { baseUrl: baseUrl, files: explicitFiles || files }; | ||
}; | ||
@@ -26,0 +32,0 @@ exports.default = (function (tsconfigPath, files) { |
@@ -179,2 +179,3 @@ "use strict"; | ||
var parsePaths = function (rootDir, paths, baseUrl, otherFiles) { | ||
var _a; | ||
var files = otherFiles.concat(paths | ||
@@ -191,3 +192,2 @@ .filter(function (p) { return p.indexOf('.d.') == -1; }) | ||
: files; | ||
var _a; | ||
}; | ||
@@ -194,0 +194,0 @@ exports.default = (function (rootDir, paths, baseUrl) { |
{ | ||
"name": "ts-unused-exports", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"description": "ts-unused-exports finds unused exported symbols in your Typescript project", | ||
@@ -32,5 +32,5 @@ "main": "lib/app.js", | ||
"devDependencies": { | ||
"@types/node": "^10.3.1", | ||
"@types/node": "^10.5.2", | ||
"@types/strip-json-comments": "0.0.28", | ||
"jasmine": "^2.4.1", | ||
"jasmine": "^2.99.0", | ||
"tslint": "^4.5.1" | ||
@@ -40,4 +40,4 @@ }, | ||
"strip-json-comments": "^2.0.1", | ||
"typescript": "^2.7.2" | ||
"typescript": "^2.9.2" | ||
} | ||
} |
@@ -14,2 +14,8 @@ const { join } = require('path'); | ||
}); | ||
it('understands tsconfig include', () => { | ||
const analysis = app(join(__dirname, 'data/tsconfig-include.json')); | ||
expect(analysis.exports).toEqual([ 'b', 'c', 'd', 'default' ]); | ||
}); | ||
}); |
import { readFileSync } from 'fs'; | ||
import { dirname } from 'path'; | ||
import stripJsonComments = require('strip-json-comments'); | ||
import * as ts from 'typescript'; | ||
import { dirname, resolve } from 'path'; | ||
import parseFiles from './parser'; | ||
import analyze from './analyzer'; | ||
interface TsConfig { | ||
compilerOptions?: { | ||
baseUrl?: string | ||
} | ||
files?: string[] | ||
} | ||
const parseTsConfig = (tsconfigPath:string) => { | ||
const basePath = resolve(dirname(tsconfigPath)); | ||
const loadTsConfig = ( | ||
tsconfigPath:string, | ||
explicitFiles:string[]|undefined | ||
) => { | ||
const rawTsConfig:TsConfig = JSON.parse( | ||
stripJsonComments( | ||
readFileSync(tsconfigPath, { encoding: 'utf8' }) | ||
) | ||
); | ||
try { | ||
const parseJsonResult = ts.parseConfigFileTextToJson( | ||
tsconfigPath, | ||
readFileSync(tsconfigPath, { encoding: 'utf8' }), | ||
); | ||
const tsConfig = explicitFiles | ||
? { ...rawTsConfig, files: explicitFiles } | ||
: rawTsConfig; | ||
if (parseJsonResult.error) throw parseJsonResult.error; | ||
const { files, compilerOptions } = tsConfig; | ||
const result = ts.parseJsonConfigFileContent( | ||
parseJsonResult.config, | ||
ts.sys, | ||
basePath, | ||
); | ||
if (result.errors.length) throw result.errors; | ||
if (!files) throw ` | ||
The tsconfig does not contain a "files" key: | ||
return { | ||
baseUrl: result.raw | ||
&& result.raw.compilerOptions | ||
&& result.raw.compilerOptions.baseUrl, | ||
files: result.fileNames, | ||
}; | ||
} catch (e) { | ||
throw ` | ||
Cannot parse '${tsconfigPath}'. | ||
${tsconfigPath} | ||
Consider either passing an explicit list of files or adding the "files" key. | ||
${JSON.stringify(e)} | ||
`; | ||
} | ||
}; | ||
const baseUrl = compilerOptions && compilerOptions.baseUrl; | ||
const loadTsConfig = ( | ||
tsconfigPath:string, | ||
explicitFiles:string[]|undefined | ||
) => { | ||
const { baseUrl, files } = parseTsConfig(tsconfigPath); | ||
return { baseUrl, files} ; | ||
return { baseUrl, files: explicitFiles || files }; | ||
}; | ||
@@ -42,0 +48,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
42058
51
1117
0
Updatedtypescript@^2.9.2