dts-bundle-generator
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -43,4 +43,4 @@ #!/usr/bin/env node | ||
type: 'array', | ||
description: 'Array of the package names from node_modules to inline typings from it.\n' + | ||
'Used types will just be inlined into output file', | ||
description: 'Array of package names from node_modules to inline typings from.\n' + | ||
'Used types will be inlined into the output file', | ||
coerce: toStringsArray, | ||
@@ -50,5 +50,5 @@ }) | ||
type: 'array', | ||
description: 'Array of the package names from node_modules to import typings from it.\n' + | ||
'Used types will be imported by "import { First, Second } from \'library-name\';".\n' + | ||
'By default all libraries will be imported (except inlined and libraries from @types)', | ||
description: 'Array of package names from node_modules to import typings from.\n' + | ||
'Used types will be imported using "import { First, Second } from \'library-name\';".\n' + | ||
'By default all libraries will be imported (except inlined libraries and libraries from @types)', | ||
coerce: toStringsArray, | ||
@@ -58,4 +58,4 @@ }) | ||
type: 'array', | ||
description: 'Array of the package names from @types to import typings from it via triple-slash reference directive.\n' + | ||
'By default all packages are allowed and will be used according their usages', | ||
description: 'Array of package names from @types to import typings from via the triple-slash reference directive.\n' + | ||
'By default all packages are allowed and will be used according to their usages', | ||
coerce: toStringsArray, | ||
@@ -65,7 +65,7 @@ }) | ||
type: 'string', | ||
description: 'The name of UMD module. If specified `export as namespace ModuleName;` will be emitted', | ||
description: 'Name of the UMD module. If specified then `export as namespace ModuleName;` will be emitted', | ||
}) | ||
.option('project', { | ||
type: 'string', | ||
description: 'The path to a tsconfig.json file that will be used to compile files', | ||
description: 'Path to the tsconfig.json file that will be used for the compilation', | ||
}) | ||
@@ -85,5 +85,5 @@ .option('sort', { | ||
default: false, | ||
description: '(EXPERIMENTAL) Disables resolving symlinks to original path. See https://github.com/timocov/dts-bundle-generator/issues/39 to more information', | ||
description: '(EXPERIMENTAL) Disables resolving of symlinks to the original path. See https://github.com/timocov/dts-bundle-generator/issues/39 for more information', | ||
}) | ||
.config('config', 'File path to generator config file') | ||
.config('config', 'File path to the generator config file') | ||
.version() | ||
@@ -90,0 +90,0 @@ .strict() |
@@ -39,3 +39,3 @@ "use strict"; | ||
var sourceFiles = program.getSourceFiles().filter(function (file) { | ||
return module_info_1.getModuleInfo(file.fileName, criteria).type !== 0 /* ShouldNotBeUsed */; | ||
return !program.isSourceFileDefaultLibrary(file); | ||
}); | ||
@@ -58,3 +58,3 @@ logger_1.verboseLog("Input source files:\n " + sourceFiles.map(function (file) { return file.fileName; }).join('\n ')); | ||
shouldStatementBeImported: function (statement) { return shouldNodeBeImported(statement, rootFileExports, typesUsageEvaluator); }, | ||
shouldDeclareGlobalBeInlined: function (currentModule) { return Boolean(options.inlineDeclareGlobals) && currentModule.type === 1 /* ShouldBeInlined */; }, | ||
shouldDeclareGlobalBeInlined: function (currentModule) { return Boolean(options.inlineDeclareGlobals) && currentModule.type === 0 /* ShouldBeInlined */; }, | ||
getModuleInfo: function (fileName) { return module_info_1.getModuleInfo(fileName, criteria); }, | ||
@@ -108,5 +108,2 @@ getDeclarationsForExportedAssignment: function (exportAssignment) { | ||
function updateResult(params, result) { | ||
if (params.currentModule.type === 0 /* ShouldNotBeUsed */) { | ||
return; | ||
} | ||
for (var _i = 0, _a = params.statements; _i < _a.length; _i++) { | ||
@@ -122,3 +119,3 @@ var statement = _a[_i]; | ||
} | ||
if (params.currentModule.type === 4 /* ShouldBeUsedForModulesOnly */) { | ||
if (params.currentModule.type === 3 /* ShouldBeUsedForModulesOnly */) { | ||
continue; | ||
@@ -130,3 +127,3 @@ } | ||
} | ||
if (ts.isExportAssignment(statement) && statement.isExportEquals && params.currentModule.type === 2 /* ShouldBeImported */) { | ||
if (ts.isExportAssignment(statement) && statement.isExportEquals && params.currentModule.type === 1 /* ShouldBeImported */) { | ||
updateResultForImportedEqExportAssignment(statement, params, result); | ||
@@ -140,9 +137,9 @@ continue; | ||
switch (params.currentModule.type) { | ||
case 3 /* ShouldBeReferencedAsTypes */: | ||
case 2 /* ShouldBeReferencedAsTypes */: | ||
addTypesReference(params.currentModule.typesLibraryName, result.typesReferences); | ||
break; | ||
case 2 /* ShouldBeImported */: | ||
case 1 /* ShouldBeImported */: | ||
updateImportsForStatement(statement, params, result); | ||
break; | ||
case 1 /* ShouldBeInlined */: | ||
case 0 /* ShouldBeInlined */: | ||
result.statements.push(statement); | ||
@@ -159,3 +156,3 @@ break; | ||
var moduleFileName = resolveModuleFileName(statement.getSourceFile().fileName, statement.moduleSpecifier.text); | ||
return params.getModuleInfo(moduleFileName).type === 2 /* ShouldBeImported */; | ||
return params.getModuleInfo(moduleFileName).type === 1 /* ShouldBeImported */; | ||
} | ||
@@ -189,5 +186,2 @@ updateResult(params, result); | ||
function updateResultForModuleDeclaration(moduleDecl, params, result) { | ||
if (params.currentModule.type === 0 /* ShouldNotBeUsed */) { | ||
return; | ||
} | ||
if (moduleDecl.body === undefined || !ts.isModuleBlock(moduleDecl.body)) { | ||
@@ -199,5 +193,2 @@ return; | ||
var moduleInfo = params.getModuleInfo(moduleFileName); | ||
if (moduleInfo.type === 0 /* ShouldNotBeUsed */) { | ||
return; | ||
} | ||
// if we have declaration of external module inside internal one | ||
@@ -221,3 +212,3 @@ // we need to just add it to result without any processing | ||
function updateImportsForStatement(statement, params, result) { | ||
if (params.currentModule.type !== 2 /* ShouldBeImported */) { | ||
if (params.currentModule.type !== 1 /* ShouldBeImported */) { | ||
return; | ||
@@ -224,0 +215,0 @@ } |
@@ -19,3 +19,2 @@ "use strict"; | ||
} | ||
// `as ts.Diagnostic[]` we need to correct compile with TypeScript 2.5.1 | ||
logger_1.errorLog(ts.formatDiagnostics(diagnostics, formatDiagnosticsHost).trim()); | ||
@@ -22,0 +21,0 @@ throw new Error(failMessage); |
@@ -28,18 +28,15 @@ "use strict"; | ||
} | ||
return { type: 1 /* ShouldBeInlined */, fileName: originalFileName, isExternal: false }; | ||
return { type: 0 /* ShouldBeInlined */, fileName: originalFileName, isExternal: false }; | ||
} | ||
if (node_modules_helpers_1.isTypescriptLibFile(currentFilePath)) { | ||
return { type: 0 /* ShouldNotBeUsed */ }; | ||
} | ||
var typesLibraryName = node_modules_helpers_1.getTypesLibraryName(currentFilePath); | ||
if (shouldLibraryBeInlined(npmLibraryName, typesLibraryName, criteria.inlinedLibraries)) { | ||
return { type: 1 /* ShouldBeInlined */, fileName: originalFileName, isExternal: true }; | ||
return { type: 0 /* ShouldBeInlined */, fileName: originalFileName, isExternal: true }; | ||
} | ||
if (shouldLibraryBeImported(npmLibraryName, typesLibraryName, criteria.importedLibraries)) { | ||
return { type: 2 /* ShouldBeImported */, fileName: originalFileName, libraryName: typesLibraryName || npmLibraryName, isExternal: true }; | ||
return { type: 1 /* ShouldBeImported */, fileName: originalFileName, libraryName: typesLibraryName || npmLibraryName, isExternal: true }; | ||
} | ||
if (typesLibraryName !== null && isLibraryAllowed(typesLibraryName, criteria.allowedTypesLibraries)) { | ||
return { type: 3 /* ShouldBeReferencedAsTypes */, fileName: originalFileName, typesLibraryName: typesLibraryName, isExternal: true }; | ||
return { type: 2 /* ShouldBeReferencedAsTypes */, fileName: originalFileName, typesLibraryName: typesLibraryName, isExternal: true }; | ||
} | ||
return { type: 4 /* ShouldBeUsedForModulesOnly */, fileName: originalFileName, isExternal: true }; | ||
return { type: 3 /* ShouldBeUsedForModulesOnly */, fileName: originalFileName, isExternal: true }; | ||
} | ||
@@ -46,0 +43,0 @@ function shouldLibraryBeInlined(npmLibraryName, typesLibraryName, inlinedLibraries) { |
@@ -29,5 +29,1 @@ "use strict"; | ||
exports.getTypesLibraryName = getTypesLibraryName; | ||
function isTypescriptLibFile(fileName) { | ||
return /node_modules[\\\/]typescript[\\\/]lib[\\\/]lib(\..+)?\.d\.ts$/i.test(fileName); | ||
} | ||
exports.isTypescriptLibFile = isTypescriptLibFile; |
{ | ||
"name": "dts-bundle-generator", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "DTS Bundle Generator", | ||
@@ -12,3 +12,3 @@ "main": "bundle-generator.js", | ||
"dependencies": { | ||
"typescript": "^2.5.1", | ||
"typescript": "^2.6.1", | ||
"yargs": "~11.0.0" | ||
@@ -15,0 +15,0 @@ }, |
@@ -1,5 +0,14 @@ | ||
[![npm version](https://badge.fury.io/js/dts-bundle-generator.svg)](https://badge.fury.io/js/dts-bundle-generator) [![Build Status](https://travis-ci.org/timocov/dts-bundle-generator.svg?branch=master)](https://travis-ci.org/timocov/dts-bundle-generator) | ||
<!-- markdownlint-disable MD033 --> | ||
<div align="center"> | ||
<a href="https://github.com/timocov/dts-bundle-generator"> | ||
<img width="250px" height="250px" src=".github/logo.svg"> | ||
</a> | ||
</div> | ||
# DTS Bundle Generator | ||
[![npm version](https://badge.fury.io/js/dts-bundle-generator.svg)](https://badge.fury.io/js/dts-bundle-generator) | ||
[![Build Status](https://travis-ci.org/timocov/dts-bundle-generator.svg?branch=master)](https://travis-ci.org/timocov/dts-bundle-generator) | ||
Small tool to generate a dts bundle from your ts code. | ||
@@ -66,18 +75,16 @@ | ||
[boolean] [default: false] | ||
--external-inlines Array of the package names from node_modules to inline typings from | ||
it. | ||
Used types will just be inlined into output file [array] | ||
--external-imports Array of the package names from node_modules to import typings from | ||
it. | ||
Used types will be imported by "import { First, Second } from | ||
--external-inlines Array of package names from node_modules to inline typings from. | ||
Used types will be inlined into the output file [array] | ||
--external-imports Array of package names from node_modules to import typings from. | ||
Used types will be imported using "import { First, Second } from | ||
'library-name';". | ||
By default all libraries will be imported (except inlined and | ||
libraries from @types) [array] | ||
--external-types Array of the package names from @types to import typings from it via | ||
By default all libraries will be imported (except inlined libraries | ||
and libraries from @types) [array] | ||
--external-types Array of package names from @types to import typings from via the | ||
triple-slash reference directive. | ||
By default all packages are allowed and will be used according their | ||
usages [array] | ||
--umd-module-name The name of UMD module. If specified `export as namespace | ||
By default all packages are allowed and will be used according to | ||
their usages [array] | ||
--umd-module-name Name of the UMD module. If specified then `export as namespace | ||
ModuleName;` will be emitted [string] | ||
--project The path to a tsconfig.json file that will be used to compile files | ||
--project Path to the tsconfig.json file that will be used for the compilation | ||
[string] | ||
@@ -88,6 +95,6 @@ --sort Sort output nodes [boolean] [default: false] | ||
`--external-inlines`) [boolean] [default: false] | ||
--disable-symlinks-following (EXPERIMENTAL) Disables resolving symlinks to original path. See | ||
https://github.com/timocov/dts-bundle-generator/issues/39 to more | ||
information [boolean] [default: false] | ||
--config File path to generator config file | ||
--disable-symlinks-following (EXPERIMENTAL) Disables resolving of symlinks to the original path. | ||
See https://github.com/timocov/dts-bundle-generator/issues/39 for | ||
more information [boolean] [default: false] | ||
--config File path to the generator config file | ||
--version Show version number [boolean] | ||
@@ -112,3 +119,4 @@ ``` | ||
If you have modules you can create definitions by default via `tsc`, but `tsc` generates them for each module separately. Yeah, you can use `outFile` (for `amd` and `system`) but generated code looks like this: | ||
If you have modules then you can create definitions by default using `tsc`, but `tsc` generates them for each module separately. | ||
Yeah, you can use `outFile` (for `amd` and `system`), but generated code looks like this: | ||
@@ -132,9 +140,8 @@ ```ts | ||
1. There is not a single usage of `A` (maybe you do not want to export it?) | ||
1. `A' is not used at all and most probably you do not want to export it. | ||
1. If you bundle your code in a way when all modules are merged (like when using Webpack or Rollup) then there should be no such modules as `a` or `b` (actually `entry` too) in the resulting file. | ||
1. If you bundle your code this way all the modules are merged (like when using Webpack or Rollup) and there are no such modules as `a` or `b` (actually `entry` too). | ||
## Known limitations | ||
1. Do not rename types when import. If you use something like this: | ||
1. Do not rename types on import. If you use something like this | ||
@@ -146,3 +153,3 @@ ```ts | ||
you will get an error because this tool does not follow your renaming (and actually cannot). | ||
you will get an error, because this tool does not follow your renaming (and actually cannot do that). | ||
@@ -158,3 +165,5 @@ 1. Do not use types from `* as name`-imports: | ||
**NOTE:** some libraries with typings in `@types` (for example `react` or `react-dom`) has named exported namespace. As soon typings for this libraries will be imported via triple-slash directive you should import this libraries with renaming. For example for source | ||
**NOTE:** some libraries with typings in `@types` (for example `react` or `react-dom`) has named exported namespace. | ||
Since typings for these libraries are imported via triple-slash directive, you should import these libraries with renaming. | ||
For example for source | ||
@@ -161,0 +170,0 @@ ```ts |
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
182
49367
890
Updatedtypescript@^2.6.1