nomaed / dts-builder Goto Github PK
View Code? Open in Web Editor NEWBuilds a single d.ts file library from generated d.ts sources
License: MIT License
Builds a single d.ts file library from generated d.ts sources
License: MIT License
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?
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'
@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.
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.
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.
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.
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'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.