Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
dts-bundle
Advanced tools
Export TypeScript .d.ts files as an external module definition
This module is a naïve string-based approach at generating bundles from the .d.ts declaration files generated by a TypeScript compiler.
The main use-case is generating definition for npm/bower modules written in TypeScript (commonjs/amd) so the TypeScript code should following the external-module pattern (using import/export
's and --outDir
).
:warning: Experimental; use with care.
This module was born out of necessity and frustration. It is a little hacky but at least it seems to work..
npm install dts-bundle
--declaration
and --outDir
flags (and probably --module commonjs
too).Something like:
tsc src/index.ts --declaration --module commonjs --target es5 --outDir build
dts-bundle
Let's assume the project is called cool-project
and the main module is build/index.js
with a build/index.d.ts
:
var dts = require('dts-bundle');
dts.bundle({
name: 'cool-project',
main: 'build/index.d.ts'
});
This will traverse all references and imports for the .d.ts files of your sub-modules and write build/cool-project.d.ts
with the bundle of all 'local' imports.
Optional:
typescript
element:{
"name": "cool-project",
"version": "0.1.3",
"typescript": {
"definition": "build/cool-project.d.ts"
}
}
Using this makes the definition findable for tooling, for example the TypeScript Definitions package manager (from v0.6.x) can auto-link these into tsd.d.ts
bundle file.
There is also a Grunt plugin grunt-dts-bundle that goes well with Grunt based compilers, like grunt-ts or grunt-typescript.
Example of all options:
var opts = {
// Required
// name of module likein package.json
// - used to declare module & import/require
name: 'cool-project',
// path to entry-point (generated .d.ts file for main module)
// - either relative or absolute
main: 'build/index.d.ts',
// Optional
// base directory to be used for discovering type declarations (i.e. from this project itself)
// - default: dirname of main
baseDir: 'build',
// path of output file
// - default: "<baseDir>/<name>.d.ts"
out: 'dist/cool-project.d.ts',
// include typings outside of the 'baseDir' (i.e. like node.d.ts)
// - default: false
externals: false,
// filter to exclude typings, either a RegExp or a callback. match path relative to opts.baseDir
// - RegExp: a match excludes the file
// - function: (file:String, external:Boolean) return true to exclude, false to allow
// - always use forward-slashes (even on Windows)
// - default: *pass*
exclude: /^defs\/$/,
// delete all source typings (i.e. "<baseDir>/**/*.d.ts")
// - default: false
removeSource: false,
// newline to use in output file
newline: os.EOL,
// indentation to use in output file
// - default 4 spaces
indent: ' ',
// prefix for rewriting module names
// - default '__'
prefix: '__',
// separator for rewriting module 'path' names
// - default: forward slash (like sub-modules)
separator: '/',
// enable verbose mode, prints detailed info about all references and includes/excludes
// - default: false
verbose: false,
};
// require module
var dts = require('dts-bundle');
// run it
dts.bundle(opts);
definition-header
package)They are very welcome. Beware this module is a quick hack-job so good luck!
Copyright (c) 2014 Bart van der Schoor
Licensed under the MIT license.
FAQs
Export TypeScript .d.ts files as an external module definition
The npm package dts-bundle receives a total of 13,906 weekly downloads. As such, dts-bundle popularity was classified as popular.
We found that dts-bundle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.