GithubHelp home page GithubHelp logo

nomaed / dts-builder Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 4.0 59 KB

Builds a single d.ts file library from generated d.ts sources

License: MIT License

TypeScript 83.05% JavaScript 16.95%
typescript definitions type-definitions dts library

dts-builder's People

Contributors

nomaed avatar ramana-chavakula avatar skymakerolof avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

dts-builder's Issues

external modules imported and written wrongly

Code:

await dtsBuilder.generateBundles([
        {
            name: 'discord-basebot',
            sourceDir: '../out/bin/typings',
            destDir: '../out/bin',
            externals: [
                '..\\node_modules\\@discordjs\\collection\\dist\\index.d.ts',
                '..\\node_modules\\@types\\chalk-animation\\index.d.ts',
                '..\\node_modules\\discord.js\\typings\\index.d.ts'
            ],
        }
    ]);

The first issue. If there external modules (for ex: node_modules) which ends with index.d.ts then all files will be written as index.d.ts.
How to import node_modules so we can use them?

The second issue.
Client.d.ts which was generated by tsc

import Discord from "discord.js";

export declare class Client extends Discord.Client { /* ...code */}

When I use dts-builder in generated declaration file my-module-name.d.ts there's no import Discord from "discord.js"; so Client class has any type
How to solve this?
image

imports from external libraries are not emitted

My library exports types that use types from external libraries. For example

import {OnChanges} from '@angular/core';
export class MyComponent implements OnChanges {}

The bundled declaration file does not contain the import. That results in type errors or implicit any.

export class MyComponent implements OnChanges {}
                                    ~~~~~~~~~ Cannot find name 'OnChanges'

Related project API Extractor

@nomaed FYI we've been working on a tool API Extractor that seems to have some overlap with the goals of dts-builder. It might be interesting to compare the features and goals of the two projects, and see if anything can be shared between them.

Using the word 'import' in code or comment causes error

The optimizeImports function is too sensitive to the word "import" in function.ts, line 101. If the code contains

...
    /** name of the import */
    import : string;
...

Then it throws "optimizeImports() could not deal with the following..."

I hacked my local copy to just do console.warn instead of throwing an error. Maybe that's acceptable, unless you have a more robust approach.

P.S. Thanks for this tool.

Library name converted to lower case

When I configure dts-builder with a name of 'Main', the module and namespace which are created are both called 'main' instead. This is a problem, as I'm trying to gradually convert code from being namespaced to being modular, so I need to be able to keep the same namespace name.

Option to avoid external namespace wrapper

Currently the generated d.ts file is wrapped by a general namespace which takes the name from the "name" parameter of the configuration passed to "generateBundles()".

It would be good to have a flag to avoid generating that external namespace, in case your library already declares the desired namespaces itslef.

dts-builder won't create a directory provided by the `destDir` option and throw "ENOENT: no such file or directory" error if it doesn't exist

my config:

const dtsBuilder = require('dts-builder');
const projectRoot = 'pathtomyproject';
dtsBuilder.generateBundles([{
  name: 'types',
  alias: 'alias',
  sourceDir: `${projectRoot}/built`,
  destDir: `${projectRoot}/dist/types`,
  externals: [
    `${projectRoot}/src/my.d.ts`,
  ]
}])

Expected behavior:
dts-builder should create the MY_PROJECT_PATH/dist/types/ directory if it doesn't exist.

Actual behavior: Error is thrown:
console output:

MY_PROJECT_PATH/node_modules/dts-builder/dist/index.js:168
throw new Error(err.message);
^

Error: ENOENT: no such file or directory, open 'MY_PROJECT_PATH/dist/types/my.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.