dts-bundle-generator
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -177,3 +177,4 @@ #!/usr/bin/env node | ||
if (compilerOptions.skipLibCheck) { | ||
logger_1.warnLog('BEWARE: The generated file could not be properly checked due enabled "skipLibCheck" compiler option'); | ||
compilerOptions.skipLibCheck = false; | ||
logger_1.warnLog('Compiler option "skipLibCheck" is disabled to properly check generated output'); | ||
} | ||
@@ -180,0 +181,0 @@ var program = ts.createProgram(outFilesToCheck, compilerOptions); |
@@ -19,2 +19,3 @@ "use strict"; | ||
var typescript_1 = require("./helpers/typescript"); | ||
var fix_path_1 = require("./helpers/fix-path"); | ||
var module_info_1 = require("./module-info"); | ||
@@ -30,4 +31,3 @@ var generate_output_1 = require("./generate-output"); | ||
var sourceFiles = program.getSourceFiles().filter(function (file) { | ||
// tslint:disable-next-line:no-unnecessary-type-assertion | ||
return !program.isSourceFileDefaultLibrary(file); | ||
return !isSourceFileDefaultLibrary(program, file); | ||
}); | ||
@@ -64,3 +64,5 @@ logger_1.verboseLog("Input source files:\n " + sourceFiles.map(function (file) { return file.fileName; }).join('\n ')); | ||
isStatementUsed: function (statement) { return isNodeUsed(statement, rootFileExportSymbols, typesUsageEvaluator, typeChecker); }, | ||
shouldStatementBeImported: function (statement) { return shouldNodeBeImported(statement, rootFileExportSymbols, typesUsageEvaluator); }, | ||
shouldStatementBeImported: function (statement) { | ||
return shouldNodeBeImported(statement, rootFileExportSymbols, typesUsageEvaluator, typeChecker, isSourceFileDefaultLibrary.bind(null, program)); | ||
}, | ||
shouldDeclareGlobalBeInlined: function (currentModule) { return Boolean(outputOptions.inlineDeclareGlobals) && currentModule.type === 0 /* ShouldBeInlined */; }, | ||
@@ -217,3 +219,3 @@ getModuleInfo: function (fileName) { return module_info_1.getModuleInfo(fileName, criteria); }, | ||
function resolveModuleFileName(currentFileName, moduleName) { | ||
return moduleName.startsWith('.') ? path.join(currentFileName, '..', moduleName) : "node_modules/" + moduleName + "/"; | ||
return moduleName.startsWith('.') ? fix_path_1.fixPath(path.join(currentFileName, '..', moduleName)) : "node_modules/" + moduleName + "/"; | ||
} | ||
@@ -265,3 +267,7 @@ function addTypesReference(library, typesReferences) { | ||
if (typescript_1.isNodeNamedDeclaration(node)) { | ||
return rootFileExports.some(function (rootExport) { return typesUsageEvaluator.isTypeUsedBySymbol(node, rootExport); }); | ||
var nodeSymbol_1 = getNodeSymbol(node, typeChecker); | ||
if (nodeSymbol_1 === null) { | ||
return false; | ||
} | ||
return rootFileExports.some(function (rootExport) { return typesUsageEvaluator.isSymbolUsedBySymbol(nodeSymbol_1, rootExport); }); | ||
} | ||
@@ -275,4 +281,24 @@ else if (ts.isVariableStatement(node)) { | ||
} | ||
function shouldNodeBeImported(node, rootFileExports, typesUsageEvaluator) { | ||
var symbolsUsingNode = typesUsageEvaluator.getSymbolsUsingNode(node); | ||
function shouldNodeBeImported(node, rootFileExports, typesUsageEvaluator, typeChecker, isDefaultLibrary) { | ||
var nodeSymbol = getNodeSymbol(node, typeChecker); | ||
if (nodeSymbol === null) { | ||
return false; | ||
} | ||
var symbolDeclarations = typescript_1.getDeclarationsForSymbol(nodeSymbol); | ||
var isSymbolDeclaredInDefaultLibrary = symbolDeclarations.some(function (declaration) { return isDefaultLibrary(declaration.getSourceFile()); }); | ||
if (isSymbolDeclaredInDefaultLibrary) { | ||
// we shouldn't import a node declared in the default library (such dom, es2015) | ||
// yeah, actually we should check that node is declared only in the default lib | ||
// but it seems we can check that at least one declaration is from default lib | ||
// to treat the node as un-importable | ||
// because we can't re-export declared somewhere else node with declaration merging | ||
// also, if some lib file will not be added to the project | ||
// for example like it is described in the react declaration file (e.g. React Native) | ||
// then here we still have a bug with "importing global declaration from a package" | ||
// (see https://github.com/timocov/dts-bundle-generator/issues/71) | ||
// but I don't think it is a big problem for now | ||
// and it's possible that it will be fixed in https://github.com/timocov/dts-bundle-generator/issues/59 | ||
return false; | ||
} | ||
var symbolsUsingNode = typesUsageEvaluator.getSymbolsUsingSymbol(nodeSymbol); | ||
if (symbolsUsingNode === null) { | ||
@@ -290,1 +316,15 @@ throw new Error('Something went wrong - value cannot be null'); | ||
} | ||
function isSourceFileDefaultLibrary(program, file) { | ||
// tslint:disable-next-line:no-unnecessary-type-assertion | ||
return program.isSourceFileDefaultLibrary(file); | ||
} | ||
function getNodeSymbol(node, typeChecker) { | ||
if (node.name === undefined) { | ||
return null; | ||
} | ||
var symbol = typeChecker.getSymbolAtLocation(node.name); | ||
if (symbol === undefined) { | ||
return null; | ||
} | ||
return typescript_1.getActualSymbol(symbol, typeChecker); | ||
} |
{ | ||
"name": "dts-bundle-generator", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "DTS Bundle Generator", | ||
@@ -15,3 +15,3 @@ "main": "bundle-generator.js", | ||
"typescript": ">=2.6.1", | ||
"yargs": "~11.0.0" | ||
"yargs": "~11.1.0" | ||
}, | ||
@@ -18,0 +18,0 @@ "license": "MIT", |
@@ -11,17 +11,7 @@ "use strict"; | ||
} | ||
TypesUsageEvaluator.prototype.isTypeUsedBySymbol = function (typeNode, by) { | ||
if (typeNode.name === undefined) { | ||
// anon? | ||
return false; | ||
} | ||
return this.isSymbolUsedBySymbol(this.getSymbol(typeNode.name), by); | ||
}; | ||
TypesUsageEvaluator.prototype.isSymbolUsedBySymbol = function (symbol, by) { | ||
return this.isSymbolUsedBySymbolImpl(this.getActualSymbol(symbol), this.getActualSymbol(by), new Set()); | ||
}; | ||
TypesUsageEvaluator.prototype.getSymbolsUsingNode = function (typeNode) { | ||
if (typeNode.name === undefined) { | ||
return null; | ||
} | ||
return this.nodesParentsMap.get(this.getSymbol(typeNode.name)) || null; | ||
TypesUsageEvaluator.prototype.getSymbolsUsingSymbol = function (symbol) { | ||
return this.nodesParentsMap.get(this.getActualSymbol(symbol)) || null; | ||
}; | ||
@@ -28,0 +18,0 @@ TypesUsageEvaluator.prototype.isSymbolUsedBySymbolImpl = function (fromSymbol, toSymbol, visitedSymbols) { |
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
70572
1364
+ Addedcross-spawn@6.0.5(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexeca@1.0.0(transitive)
+ Addedget-stream@4.1.0(transitive)
+ Addedinvert-kv@2.0.0(transitive)
+ Addedlcid@2.0.0(transitive)
+ Addedmap-age-cleaner@0.1.3(transitive)
+ Addedmem@4.3.0(transitive)
+ Addedmimic-fn@2.1.0(transitive)
+ Addednice-try@1.0.5(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedos-locale@3.1.0(transitive)
+ Addedp-defer@1.0.0(transitive)
+ Addedp-is-promise@2.1.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedyargs@11.1.1(transitive)
- Removedcross-spawn@5.1.0(transitive)
- Removedexeca@0.7.0(transitive)
- Removedget-stream@3.0.0(transitive)
- Removedinvert-kv@1.0.0(transitive)
- Removedlcid@1.0.0(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removedmem@1.1.0(transitive)
- Removedmimic-fn@1.2.0(transitive)
- Removedos-locale@2.1.0(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedyallist@2.1.2(transitive)
- Removedyargs@11.0.0(transitive)
Updatedyargs@~11.1.0