Giter Site home page Giter Site logo

sitepen / dts-generator Goto Github PK

View Code? Open in Web Editor NEW
522.0 34.0 64.0 159 KB

Generates a single .d.ts bundle containing external module declarations exported from TypeScript module files.

JavaScript 2.78% TypeScript 94.56% Shell 1.10% Batchfile 1.56%
typescript

dts-generator's Introduction

.d.ts generator

Build Status

Generates a single .d.ts bundle containing external module declarations exported from TypeScript module files.

What does this mean?

If you have a project with lots of individual TypeScript files that are designed to be consumed as external modules, the TypeScript compiler doesn’t allow you to actually create a single bundle out of them. This package leverages the TypeScript language services in TypeScript 1.4+ to generate a single .d.ts file containing multiple declare module 'foo' declarations. This allows you to distribute a single .d.ts file along with your compiled JavaScript that users can simply reference from the TypeScript compiler using a /// <reference path /> comment.

.d.ts generator will also correctly merge non-external-module files, and any already-existing .d.ts files.

Usage

  1. npm install dts-generator

  2. Generate your d.ts bundle:

    Programmatically:

require('dts-generator').default({
		name: 'package-name',
		project: '/path/to/package-directory',
		out: 'package-name.d.ts'
});

Command-line:

dts-generator --name package-name --project /path/to/package-directory --out package-name.d.ts

Grunt:

module.exports = function (grunt) {
	grunt.loadNpmTasks('dts-generator');
	grunt.initConfig({
		dtsGenerator: {
			options: {
				name: 'package-name',
				project: '/path/to/package-directory',
				out: 'package-name.d.ts'
			},
			default: {
				src: [ '/path/to/package-directory/**/*.ts' ]
			}
		}
	});
};
  1. Reference your generated d.ts bundle from somewhere in your consumer module and import away!:
/// <reference path="typings/package-name.d.ts" />

import Foo = require('package-name/Foo');

// ...

Options

  • baseDir?: string: The base directory for the package being bundled. Any dependencies discovered outside this directory will be excluded from the bundle. Note this is no longer the preferred way to configure dts-generator, it automatically gets its value from compiler option rootDir if specified in tsconfig.json, otherwise it gets value from project. Please see option project.
  • exclude?: string[]: A list of glob patterns, relative to baseDir, that should be excluded from the bundle. Use the --exclude flag one or more times on the command-line. Defaults to [ "node_modules/**/*.d.ts" ].
  • externs?: string[]: A list of external module reference paths that should be inserted as reference comments. Use the --extern flag one or more times on the command-line.
  • types?: string[]: A list of external @types package dependencies that should be inserted as reference comments. Use the --types flag one or more times on the command-line.
  • files: string[]: A list of files from the baseDir to bundle.
  • eol?: string: The end-of-line character that should be used when outputting code. Defaults to os.EOL.
  • indent?: string: The character(s) that should be used to indent the declarations in the output. Defaults to \t.
  • main?: string: The module ID that should be used as the exported value of the package’s “main” module.
  • moduleResolution?: ts.ModuleResolutionKind: The type of module resolution to use when generating the bundle.
  • name: string: The name of the package. Used to determine the correct exported package name for modules.
  • out: string: The filename where the generated bundle will be created.
  • project?: string: The base directory for the project being bundled. It is assumed that this directory contains a tsconfig.json which will be parsed to determine the files that should be bundled as well as other configuration information like target
  • target?: ts.ScriptTarget: The target environment for generated code. Defaults to ts.ScriptTarget.Latest.
  • resolveModuleId: (params: ResolveModuleIdParams) => string: An optional callback provided by the invoker to customize the declared module ids the output d.ts files. For details see resolving module ids.
  • resolveModuleImport: (params: ResolveModuleImportParams) => string: An optional callback provided by the invoker to customize the imported module ids in the output d.ts files. For details see resolving module ids.

Known issues

  • Output bundle code formatting is not perfect yet

Thanks

@fdecampredon for the idea to dump output from the compiler emitter back into the compiler parser instead of trying to figure out how to influence the code emitter.

Licensing

© 2015-2019 SitePen, Inc. New BSD License.

dts-generator's People

Contributors

basarat avatar bjouhier avatar bmustiata avatar cmichaelgraham avatar cryptiklemur avatar csnover avatar dandv avatar dgoldstein0 avatar dploeger avatar dylans avatar hirikarate avatar jason0x43 avatar jdonaghue avatar jpsfs avatar jzalucki avatar kenotron avatar kitsonk avatar msssk avatar mtraynham avatar ritzingerp avatar vratislav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dts-generator's Issues

Support glob pattern

Would be a nice feature when I'm able to use the glob pattern in the files option, e.g.:

require('dts-generator').generate({
    name: 'angular2-bootstrap',
    baseDir: './src',
    files: ['./**/*.ts'],
    out: DIR_CONFIG.dest.declaration
  });

Use of tsconfig forces double naming

It looks like we are required to set the project and the name config attributes. Since my typescript is held in a subfolder then the output d.ts file paths are name/subfolder, which happen to be the same name. I used to be able to set a baseDir that would get right of the subfolder name so that the output would be "name/subfilepath". This way the d.ts files would match up with the exact path of the project files. As it is, it's not usuable. I'm not sure what settings I need to get this working.

Folder Structure
/project/file.ts

Usage
import * from 'project/file'

dts-generator output
configname/project/file

How do I get rid of either the project directory or the leading name to get the d.ts files to match the usage in the project?

If i don't supply a name then an exception is thrown. If i supply an empty string for a name, all paths are prefixed with a '/' which is also incorrect.

Libraries examples?

I'm curious to see how libraries handle the generation of declarations and if they tweak them further on their build process (which I am having to currently).

Are there any open source libraries using this tool?

alternate to current `main` parameter's syntax

I'd like you to implement an option for an alternate to the current syntax generated for the main parameter. This is what I would like it to look like:

declare module 'aurelia-metadata' {
    export * from 'aurelia-metadata/index';
}

If you were to do that (and with the more complete fix here), i will be able to automatically generate the Aurelia type definition files.

here's the code i use at the end of the generate function to output the above syntax:

        if (options.main) {
            output.write(("declare module '" + options.name + "' {") + eol + indent);
            output.write(("export * from '" + options.main + "';") + eol);
            output.write('}' + eol);
            sendMessage("Aliased main module " + options.name + " to " + options.main);
        }

Grunt-dts-generator?

I was able to get this working with Grunt pretty easily, with file globbing:

    grunt.registerMultiTask('dts-generator', 'Export TypeScript .d.ts definition', function () {
        function globOption(option, baseDir) {
            return option ? grunt.file.expand({cwd: baseDir}, option) : [];
        }
        var async = this.async();
        var options = this.options({});
        var baseDir = options['baseDir'] = options['baseDir'] || process.cwd();
        options['files'] = globOption(options['files'], baseDir);
        options['excludes'] = globOption(options['excludes'], baseDir);
        require('dts-generator')
            .generate(options)
            .then(async.bind(true), async.bind(false));
    });

Not Windows Compatible

  • Silent error when generating to do with backslashes created from pathUtil.resolve(options.baseDir)
  • Generated d.ts has backslashes in require statements

not installed (windows 8)

> [email protected] install E:\Dmitry\git\math\math-interval-parser\node_m
odules\dts-generator
> node -e "require('child_process').exec(require.resolve('typescript/bin/tsc') +
 ' -m commonjs -t es5 bin/dts-generator.ts index.ts', function(error, stdout, st
derr){stdout&&process.stdout.write(stdout);stderr&&process.stderr.write(stderr);
if(error)process.exit(1);})"


[eval]:1
"require('child_process').exec(require.resolve('typescript/bin/tsc')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected token ILLEGAL
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:532:25)
    at startup (node.js:80:7)
    at node.js:902:3

Can't build d.ts errors. Npm release?

Hi, Thanks for putting this together it looks really cool. I tried building from master and easy-install branches but get 1000's of errors during the tsc step. It looks like bad d.ts references.
E.g.

typings/typescript/lib.dom.d.ts(11873,5): error TS2300: Duplicate identifier 'statusMessage'.

Do you have a pre-built version available in npm or are planning to release?

Warn on Non Exported Interfaces

Currently, when dts-generator encounters an interface that is not exported, but it depended upon by something that it is exported, it silently fails to emit anything instead of warning the user that they may need to export additional interfaces as they probably intended.

For example, a developer would likely expect this to emit something via dts-generator:

interface Foo {}

export class Bar {
    foo: Foo;
}

In theory, it would be useful to emit a warning of some type that the exported class is relying upon a non-exported interface.

Traversing through node tree

Chosen method of traversing thourgh nodes in source code tree is actually skipping some nodes. I think it should use just pure recurence for walking in the tree istead of updates of current position in source file.

Resolve relative paths

I have a project where I'm creating a .d.ts file for angular2. Using dts-generator, I'm able to create one, but with one issue: all relative paths are not resolved. I had to manually resolve the 394 relative paths by hand. Is there a way to make dts-generator resolve the paths to dependent imports?

Here's my project: https://github.com/dougludlow/angular2-typings

I can't get anything in my output having tried many options

I am registering a task directly, and the output file is appearing, but it is not putting anything in it. Are there options for it giving more verbose output or anything?

I am using typescript-1.5.0-beta

grunt.registerTask('dts-generator', 'Generates dts files for library use of typescript from common', function () {
            require('dts-generator').generate({
                name: 'payx-common',
                baseDir: 'src/ts/data',
                // files: grunt.file.expand( 'src/ts/**/*.ts' ),
                files: [ 'BaseRemote.ts', 'BaseStatic.ts' ],
                out: 'target/temp/ts/payx-common.d.ts'
            });
        });

Wrong readme and proper dts-generator usage

after updating to 1.6.2 it breaks the way I used dts generator before. Readme says we should do:

require('dts-generator')({
    name: 'package-name',
    project: '/path/to/package-directory',
    out: 'package-name.d.ts'
});

However when using it this way it complains that require('dts-generator') does not return function. Fix is:

require('dts-generator').default({
    name: 'package-name',
    project: '/path/to/package-directory',
    out: 'package-name.d.ts'
});

Gulp support

How can dts-generator be used in Gulp tasks? Is there any kind of support, like Grunt has?
Now it can be used with

var dts = require('dts-generator');

gulp.task('definitions', function(done) {
  dts.default({
    name: 'my-module',
    project: '.',
    out: 'my-module.d.ts'
  }).then(done);
});

but if it were supporting NodeJS streams, Gulp workflow with .pipe() could be used., e.g.

gulp.task('definitions', function(done) {
  return gulp.src(path.to.src)
  .pipe(dts.default({
    name: 'my-module',
    project: '.'
  })
  .pipe(gulp.dest('my-module.d.ts'));
});

or similar.

Option to specify a folder of external d.ts definitions

The dts-bundle project allows you to specify a folder of external d.ts definition files to use for 3rd party dependencies without needing an explicit /// <reference /> in your code.
This is really useful for large projects with lots of external libraries.

Output file format

Would it be possible to change the format of output .d.ts file? Now each class is wrapped in module having source path in names. I think it would be more elegant if it would be like follows:

module MyModuleName {
    require(externalPackageA);
    require(externalPackageB);
    class A {}
    class B {}
    intrerface A{}
    interface B{}
}

Add a way to specify the package’s main module

packages in AMD and package.json in Node.js provide a mechanism for defining a “main” module that is loaded when the package is loaded. dts-generator should generate something like this:

Input:

generator.generate({ baseDir: 'foo', name: 'foo', main: 'index', out: 'foo.d.ts' });

Output:

declare module 'foo/index' {
  // ...
}

// this part here:
declare module 'foo' {
  import main = require('foo/index');
  export = main;
}

Is 1.6-pre published?

I've tried to npm install it without luck and it doesn't look like it is installed.

I've tried downloading and building it but get a large number of build errors (I couldn't install tsd since it calls out to github and that fails but it looks like you have the dts files checked in).

Does 1.6 pre work and if so is it possible to publish? I just wanted to see if it resolved an issue where it looks like the previous version + typescript 1.6 generated dts files (for the project) results in ":any" not existing in the generated dts file and compile time failures. Thanks!

What is the purpose of the 'target' option?

Hello. Thank you for your work on this tool. We are currently working on integrating it into our build.

We spent some time today debugging some weird behaviour which in the end turned out to be an error on our side: we had set "target" to "es5" thinking it should be a string, when it should have been a number, 1 for es5 or 2 for es6, which was very counter-intuitive.

But my real concern is the existence of the "target" option - what difference does the target environment (es5 or es6) have on .d.ts files?

Change API to better align to current TypeScript norms

The configuration of dts-generator does not easily align well to make it easy for someone who is currently using the TypeScript ecosystem with a tsconfig.json file.

We should consider breaking the API and providing a cleaner, more concise version of dts-generator that fits better into current TypeScript configurations.

Doesn't seem to work with ES6 import and d.ts files.

test.d.ts file:

import 'angular';
export default class Test  {
    constructor();
    test(name: string): void;
}

Generator config:

dtsGenerator.generate({
        name: 'Test',
        baseDir: 'wwwroot',
        files: [  'test.d.ts' ],
        externs:[ 'angular.d.ts' ],
        out: 'out.d.ts'
        //main: 'Planck'
    }

The angular.d.ts file was placed in the same directory as the test.d.ts file. This fails for any external d.ts file I try to import, angular, rx, jquery.

Exception Message:

Possibly unhandled TypeError: Cannot read property 'kind' of undefined
    at d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\dts-generator\index.js:163:33
    at visit (d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\dts-generator\index.js:54:27)
    at visitNode (d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\typescript\lib\typescript.js:7197:20)
    at Object.forEachChild (d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\typescript\lib\typescript.js:7468:21)
    at visit (d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\dts-generator\index.js:60:16)
    at visitEachNode (d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\typescript\lib\typescript.js:7209:30)
    at Object.forEachChild (d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\typescript\lib\typescript.js:7360:24)
    at visit (d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\dts-generator\index.js:60:16)
    at processTree (d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\dts-generator\index.js:63:5)
    at writeDeclaration (d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\dts-generator\index.js:152:27)
    at d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\dts-generator\index.js:124:17
    at Array.some (native)
    at d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\dts-generator\index.js:112:34
    at tryCatcher (d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\dts-generator\node_modules\bluebird\js\main\util.js:24:31)
    at Promise._resolveFromResolver (d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\dts-generator\node_modules\bluebird\js\main\promise.js:448:31)
    at new Promise (d:\dev\proj\slb\planck\Client.Web\Client.Web.Framework\node_modules\dts-generator\node_modules\bluebird\js\main\promise.js:55:37)
[20:12:00] Finished 'bundle-dts' after 6.55 s

Ignore private members

I have noticed that private members defined on typescript files are also included in the resultant d.ts definition files.
My question is: Considering these private members something that should not be used outside its containing class. Why are they included in the d.ts file? Should not be just ignored?
Does dts-generator plugin have any option to ignore these?

Module names are truncated/incomplete

I have a library that is being built as a bundle, and it is being used by other applications.
When trying to generate a single d.ts file, I see that I do get all of the "declare module ...." lines, but the names are cut.
In my code, I am not using modules, it's all a single module. It looks like the filename is used as the base for the declared module names.

This is what I'm getting:

  • declare module 'myLibgUtils' {... for definitions that come from file catalogUtils.ts
  • declare module 'myLibuery' {... for definitions that come from file MetricQuery.ts
  • declare module 'myLibls' {... for definitions that come from file modelUtils.ts

and shorter filename just get the name of the module I'm specifying in --name myLib.

The command I'm using:
$ node node_modules/.bin/dts-generator --name myLib --project ./src/packages/framework --out lib-tmp.d.ts

Versions:
dts-generator 1.7.0
node 5.11.1
typescript 1.8.10
OS 15.4.0 Darwin (OS X 10.11.4 El Capitan)

Question about main option

Hey @csnover,

I investigated this project a little more, and I like the direction you're headed. I think you could actually use webpack for single file bundles that have multi-entry points to directly benefit from this.

One question:

The purpose of the main option. Because all the definitions are prefixed with the name spec, main could useful to require the package itself. But... this is generating a definition that doesn't particularly exist in code. You attach it to the definition file, but a require on that would ultimately fail in a deployment because there isn't JS backing it.

Also, it wasn't actually generating that main module code for some reason. If I moved the main code to the top of that promise instead of after the sourceFiles output, it worked.

Thanks, and looks promising.

Error: A 'declare' modifier cannot be used in an already ambient context.

First off: Great tool! It seems like it is very close to working for my use case.

I'm using TypeScript 1.4.1, and it looks like dts-generator incorrectly nests declare statements. For example, here's the internal module generated from the declaration file for the external module 'gLong' in one of my projects:

declare module 'doppio/src/gLong' {
        declare class gLong {
          // ...
        }
        export = gLong;
}

It looks like dts-generator needs to remove inner declare modifiers.

Unable to use ES3 target option - propose using strings for setting the `target` option instead.

This line will fail if the target option is set to ts.ScriptTarget.ES3, because that value is 0 and will test false:
https://github.com/SitePen/dts-generator/blob/master/index.ts#L104

Futhermore, it's not completely safe for a user to require typescript and pass along that enum value, since it may come from a version of typescript which is different than the one imported by dts-generator. The safest/simplest way to fix both issues is to use a string for the target option.

support custom version of typescript

since library is using specific typescript version it does not work with latest versions of typescript (1.6.2). to prevent such problems you need to introduce "typescript" option to config so custom typescript version can be used. Similar way gulp-typescript is implemented

The --exclude option doesn't work on Windows.

This is due to the fact that the string comparison is between different path separator styles (TS's sourceFile.fileName seem to return things with /'s and the path.resolve and normalize seem to return paths with the OS path separator, ).

Upgrade to TypeScript 2.0

We need to upgrade dts-generator to support TypeScript 2.0. It is undermined though if TS2.0 can be supported and dts-generator would be backwards compatible with other versions of TS or if there needs to be a branch of different versions.

There is a summary of the breaking changes with TypeScript 2.0 that we should review and try to determine the impact on dts-generator. In particular readonly visibility type attribute and never bottom type are changes that do make the emitted types incompatible with prior version of TS, though it is uncertain the impact they have on dts-generator.

@agubler reported that some of the dts-generator typings generated for the conversion of dojo/core caused the typings to not be consumable by typings/typings. I don't know if he was able to narrow down the issue to dts-generator, typings/typings or something else.

A branch should be created and the upgrade should be attempted. Specifically trying to use that version of dts-generator against branch used in dojo/core#178 and the dojo/compose branch which have been upgraded to TS2.

generated bundle is empty

I'm attempting to build definition files for the following external modules:

// ClassA.ts
export class ClassA {
    public method() {
        return true;
    }
 }

// ModuleB.ts
import {ClassA} from './ClassA';

export interface IModuleB {
    ClassA: typeof ClassA
}

export var moduleB: IModuleB = {
    ClassA: ClassA
 };

// ModuleA.ts
import {moduleB, IModuleB} from './ModuleB';

export interface IModuleA {
    moduleB: IModuleB
 };


export var moduleA: IModuleA = {
    moduleB: moduleB
};

With the following dts-generator config:

grunt.registerTask('default', ['copy:main', 'ts', 'dts']);

grunt.task.registerTask('dts', 'dts', function() {
     require('dts-generator').default({
             name: 'package-name',
             project: 'src',
             out: 'package-name.d.ts',
             //src: [ 'build/**/*.ts' ], // I've tried both src & files options
             files: grunt.file.expand(['./build/**/*.ts'])
       });
});

As you can see above, I've tried using both src, and files, as well as providing my files via my tsconfig (which resides in src/).

I can't spot anything that I'm doing incorrectly - does anyone have any idea what I'm missing?

Generate single module definition

How can I tell dts-generator to bundle all files into a single module definition?
I'd like to achieve this:

declare module 'my-module' {
  export class Foo {
  }
  export class Bar {
  }
}

what I get instead is:

declare module 'my-module/foo' {
  export class Foo {
  }
}
declare module 'my-module/bar' {
  export class Bar {
  }
}

This is the command I run:

require('dts-generator').default({
  name: 'my-module',
  baseDir: '.',
  files: [ 'foo.ts', 'bar.ts' ],
  out: 'my-module.d.ts'
});

Testing and CI

We should have unit tests and CI for this. Opening issue for tracking.

Don't emit private members

Given something like this:

class Foo {
    private static BAR: string = 'Bar';
    private _fizzBuzz: string = 'fizzBuzz';
}

They seem to be emitted and untyped:

declare module 'test/Foo' {
    class Foo {
        static BAR:
        private _fizzBuzz;
    }
    export = Foo;
}

error TS4020

import * as Extented from 'dojo/Evented';

export class Test extends Extented {
}

this would cause error: error TS4020: Extends clause of exported class 'Test ' has or is using private name 'Extented'.

how can i fix it?
help me, please.

Consolidating reference paths, optional removal?

I'm using a single reference file in my project and every file has the reference at the top. Seems the generator is just combining the files as I see a lot of duplicate references.

At the same time, some seem to be missing (maybe different bug)...

It would be nice to optionally remove these altogether, because the reference path may be invalid for downstream projects. TypeScript throws errors when you use a definition file with invalid reference paths. It does not for missing paths.

The use case being:

  1. Develop a project with two files and a reference d.ts file
  2. Run dts-generator
  3. Reference generated dts file in bower.json and ship with bower so tsd link will work
    https://github.com/DefinitelyTyped/tsd#link-to-bundled-definitions
  4. tsd link will then reference all bower TypeScript definitions, linked in 'bower_components'

That typescript reference would probably no longer be valid...

ignore scripts/typings path by deafult

It's quite common while using external ts modulse to have their typings on scripts/typings or Scripts/typings path and these should be definitelly excluded by default w/o a need of adding that to --exclude option

Option to ignore external libraries

I have a module that depends on

import Q = require("q");

which the generated d.ts before combining looks like

import Q = require("q");
import implicitRequestOptions = require("./implicitRequestOptions");
import oAuthResult = require("./oAuthResult");
declare class oAuthClient {
    url: any;
    constructor(url?: any);
    setUrl(url: any): void;
    createSilentImplicitFlow(clientid: any, callback: any, scope: any, responseType?: string): Q.Promise<{}>;
    createImplicitFlowRequest(clientid: any, callback: any, scope: any, options: implicitRequestOptions): {
        url: string;
        state: string;
        nonce: string;
    };
    parseResult(queryStringOrParams: any): oAuthResult;
}
export = oAuthClient;

which causes

Running "dtsGenerator:default" (dtsGenerator) task
Warning: Cannot read property 'kind' of undefined� Use --force to continue.
Aborted due to warnings.

Is there a way to tell it to simply ignore the import Q = require("q"); and rely on the consumer library also to include "q" or how would i best handle this situation.

missing file

if i have my ts file in 'src', and do not give a rootDir './src', 'src' will be found in generated dts file. what ever project and baseDir are set.
when i use gulp, and if i use files in tsconfig, eg. src/index,, and file src/a.ts is referenced in src/index.ts generator will ignore src/a.ts

Disable the generation of ECMAScript APIs

Is there a way to disable the generation of ECMAScript APIs? My generated bundle.d.ts contains following:

////////////////////////////
/// ECMAScript APIs
/////////////////////////////

declare var NaN: number;


declare var Infinity: number;

/**
  * Evaluates JavaScript code and executes it. 
  * @param x A String value that contains valid JavaScript code.
  */
declare function eval(x: string): any;

/**
  * Converts A string to an integer.
  * @param s A string to convert into a number.
  * @param radix A value between 2 and 36 that specifies the base of the number in numString. 
  * If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal.
  * All other strings are considered decimal.
  */
declare function parseInt(s: string, radix?: number): number;

...

Glob feature breaks excludes list

Commit 6bf5367 fixing #26 unfortunately broke the use of relative paths with the exclusion list. As globbing occurs from the working directory, you effectively find the relative path injected twice:

baseDir: ./SomePath/SomeSubPath
excludes: [SomeFile.ts]

becomes:

./SomePath/SomeSubPath/SomePath/SomeSubPath/SomeFile.ts

Fix is simple, glob sync operation simply needs to take a relative path.

(index.ts line 124)
glob.sync(filename, {cwd: baseDir}).forEach(.....

I would fix this myself and submit a pull request, but unfortunately there is not much chance of getting the CLA agreement past my organization.

abstract classes are ignored

Example:

export abstract class ABase {
  myProp: string;

  constructor() {
    this.myProp = 'Abstract Base Class';
  }

  abstract myFunc(): void;
}

Abstract classes don't appear in the generated definition file at all. Is this intented ?
As a workaround, I have to generate definitions through typescript and copy-paste all abstract classes, but it would be great if dts-generator could do that.

Error: Arguments to path.resolve must be string Use --force to continue.

I'm getting the following error:

Running "dtsGenerator:build" (dtsGenerator) task
Warning: Arguments to path.resolve must be strings Use --force to continue.
Aborted due to warnings.

I've followed the grunt task setup described on your page modifying it slightly to fit my use-case but I'm having no luck:

dtsGenerator: {
    options: {
        name: 'package-name',
        project: 'build/',
        out: 'package-name.d.ts'
    },
    build: {
        src: [ 'build/**/*.ts' ]
    }
}

My TS is compiling as expected into build/src.

TypeError: Cannot read property 'kind' of undefined

I'm attempting to generate a .d.ts for angular2, but I'm getting the following exception:

Unhandled rejection TypeError: Cannot read property 'kind' of undefined
    at /Users/doug/Projects/dougludlow/angular2-typings/node_modules/dts-generator/index.js:216:33
    at visit (/Users/doug/Projects/dougludlow/angular2-typings/node_modules/dts-generator/index.js:54:27)
    at visitNode (/Users/doug/Projects/dougludlow/angular2-typings/node_modules/typescript/lib/typescript.js:7409:20)
    at Object.forEachChild (/Users/doug/Projects/dougludlow/angular2-typings/node_modules/typescript/lib/typescript.js:7686:21)
    at visit (/Users/doug/Projects/dougludlow/angular2-typings/node_modules/dts-generator/index.js:60:16)
    at visitEachNode (/Users/doug/Projects/dougludlow/angular2-typings/node_modules/typescript/lib/typescript.js:7421:30)
    at Object.forEachChild (/Users/doug/Projects/dougludlow/angular2-typings/node_modules/typescript/lib/typescript.js:7578:24)
    at visit (/Users/doug/Projects/dougludlow/angular2-typings/node_modules/dts-generator/index.js:60:16)
    at processTree (/Users/doug/Projects/dougludlow/angular2-typings/node_modules/dts-generator/index.js:63:5)
    at writeDeclaration (/Users/doug/Projects/dougludlow/angular2-typings/node_modules/dts-generator/index.js:205:27)
    at /Users/doug/Projects/dougludlow/angular2-typings/node_modules/dts-generator/index.js:176:17
    at Array.some (native)
    at /Users/doug/Projects/dougludlow/angular2-typings/node_modules/dts-generator/index.js:164:34
    at tryCatcher (/Users/doug/Projects/dougludlow/angular2-typings/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._resolveFromResolver (/Users/doug/Projects/dougludlow/angular2-typings/node_modules/bluebird/js/main/promise.js:480:31)
    at new Promise (/Users/doug/Projects/dougludlow/angular2-typings/node_modules/bluebird/js/main/promise.js:70:37)

I went to line 216 of injex.js, which resolves to line 279 in index.ts, and added a node.parent && before (node.parent.kind... which got rid of the error and allowed the .d.ts file to generate and it works. But I'm not familiar with the code and not sure what's going on here exactly. Can anyone offer any insight?

This is the file I'm using to generate the .d.ts:

var dts = require('dts-generator').default;

dts({
    name: 'angular2',
    baseDir: './wwwroot/jspm_packages/npm/[email protected]',
    out: 'typings/angular2/angular2.d.ts',
    files: [
        'core.d.ts',
        'http.d.ts',
        'common.d.ts',
        'router.d.ts',
        'testing.d.ts',
        'platform/browser.d.ts',
        'platform/server.d.ts'
    ]
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.