Socket
Socket
Sign inDemoInstall

dts-bundle-generator

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dts-bundle-generator - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

3

bin/dts-bundle-generator.js

@@ -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) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc