Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@favware/rollup-type-bundler

Package Overview
Dependencies
Maintainers
2
Versions
344
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@favware/rollup-type-bundler - npm Package Compare versions

Comparing version 0.0.1-next.ff875c4.0 to 1.0.0

18

dist/cli.js

@@ -10,2 +10,3 @@ #!/usr/bin/env node

import { fileExistsAsync } from '#lib/promisified';
import { doActionAndLog } from '#lib/utils';
import { cyan } from 'colorette';

@@ -20,3 +21,3 @@ import { Command } from 'commander';

.version(packageJson.version)
.requiredOption('-d, --dist <dist>', 'The dist directory to target')
.option('-d, --dist <dist>', 'The dist directory to target')
.option('-b, --build-script [buildScript]', 'The build script to call after cleaning your dist directory', 'build')

@@ -35,4 +36,3 @@ .option('-v, --verbose', 'Print verbose information', false)

const packageJsonPath = join(packageCwd, 'package.json');
const packageJsonExistsInCwd = await fileExistsAsync(packageJsonPath);
logVerboseInfo(['Checking if package.json exists in the current working directory'], options.verbose);
const packageJsonExistsInCwd = await doActionAndLog('Checking if package.json exists in the current working directory', fileExistsAsync(packageJsonPath));
if (!packageJsonExistsInCwd) {

@@ -51,4 +51,3 @@ logVerboseError({

*/
logVerboseInfo(['Cleaning the configured "dist" path'], options.verbose);
await cleanDist(options);
await doActionAndLog('Cleaning the configured "dist" path', cleanDist(options));
/**

@@ -59,4 +58,3 @@ |---------------------------------------------------------------------------------|

*/
logVerboseInfo(['Compiling your TypeScript source code'], options.verbose);
await buildCode(options);
await doActionAndLog('Compiling your TypeScript source code', buildCode(options));
/**

@@ -67,4 +65,3 @@ |-------------------------------------|

*/
logVerboseInfo(['Bundling TypeScript types'], options.verbose);
await bundleTypes(options);
await doActionAndLog('Bundling TypeScript types', bundleTypes(options));
/**

@@ -75,4 +72,3 @@ |-------------------------------------------------|

*/
logVerboseInfo(['Cleaning extraneous types from the "dist" path'], options.verbose);
await cleanExtraneousTypes(options);
await doActionAndLog('Cleaning extraneous types from the "dist" path', cleanExtraneousTypes(options));
//# sourceMappingURL=cli.js.map

@@ -22,4 +22,4 @@ import { indent, packageCwd } from '#lib/constants';

'An error occurred while building the TypeScript code',
`${indent}If you provided a custom build script with "-b" or "--build-script", or through "buildScript" in a config file, then make that script actually exists in your "package.json"`,
`${indent}If you did not provide this option, then make sure there is a script called "build" in your "package.json"`
`${indent}If you provided a custom build script with "-b" or "--build-script", or through "buildScript" in a config file, then make that script actually exists in your "package.json".`,
`${indent}If you did not provide this option, then make sure there is a script called "build" in your "package.json".`
],

@@ -32,3 +32,3 @@ verbose: options.verbose,

].filter(Boolean),
exitAfterLog: true
logWithThrownError: true
});

@@ -35,0 +35,0 @@ }

@@ -0,4 +1,7 @@

import { fileExistsAsync } from '#lib/promisified';
import { join } from 'path';
import { rollup } from 'rollup';
import dts from 'rollup-plugin-dts';
import { fileURLToPath, URL } from 'url';
import { setTimeout as sleep } from 'timers/promises';
import { fileURLToPath } from 'url';
/**

@@ -9,3 +12,7 @@ * Bundles all the TypeScript types with {@link rollup}

export async function bundleTypes(options) {
const typingsFile = fileURLToPath(new URL('index.d.ts', options.dist));
const typingsFile = join(fileURLToPath(options.dist), 'index.d.ts');
// Sleep repeated 1 second until the `index.d.ts` file exists
do {
await sleep(1000);
} while (!(await fileExistsAsync(typingsFile)));
await rollup({

@@ -12,0 +19,0 @@ input: typingsFile,

@@ -16,3 +16,3 @@ import { rm } from 'fs/promises';

verboseText: ['The error message that was thrown is: ', error],
exitAfterLog: true
logWithThrownError: true
});

@@ -19,0 +19,0 @@ }

import { logVerboseError } from '#lib/logVerbose';
import { opendir, rm } from 'fs/promises';
import { join, sep } from 'path';
import { basename, join, sep } from 'path';
import { fileURLToPath } from 'url';

@@ -32,3 +32,3 @@ /**

for await (const path of scan(options.dist, cb)) {
if (!path.endsWith(`dist${sep}index.d.ts`)) {
if (!path.endsWith(`${basename(fileURLToPath(options.dist))}${sep}index.d.ts`)) {
await rm(path);

@@ -40,6 +40,6 @@ }

logVerboseError({
text: ['An error occurred while removing one or more of the extraneous types from the `dist` directory', 'Please remove them manually'],
text: ['An error occurred while removing one or more of the extraneous types from the `dist` directory.', 'Please remove them manually'],
verbose: options.verbose,
verboseText: ['I was scanning this dist path: ', options.dist.toString(), 'Furthermore, the exact error that occurred is: ', err],
exitAfterLog: true
logWithThrownError: true
});

@@ -46,0 +46,0 @@ }

@@ -10,9 +10,9 @@ import { join } from 'path';

/** Path to the config file in .json format */
export const rollupTypeBundlerRcJsonPath = join(rollupTypeBundlerRcPath, '.json');
export const rollupTypeBundlerRcJsonPath = `${rollupTypeBundlerRcPath}.json`;
/** Path to the config file in .yml format */
export const rollupTypeBundlerRcYmlPath = join(rollupTypeBundlerRcPath, '.yml');
export const rollupTypeBundlerRcYmlPath = `${rollupTypeBundlerRcPath}.yml`;
/** Path to the config file in .yaml format */
export const rollupTypeBundlerRcYamlPath = join(rollupTypeBundlerRcPath, '.yaml');
export const rollupTypeBundlerRcYamlPath = `${rollupTypeBundlerRcPath}.yaml`;
/** 4 spaces indent for logging */
export const indent = ' '.repeat(4);
//# sourceMappingURL=constants.js.map

@@ -6,9 +6,14 @@ import { cyan, red } from 'colorette';

*/
export function logVerboseError({ text, verbose = false, verboseText = [], exitAfterLog: exitOnLog = false }) {
let combinedText = text;
export function logVerboseError({ text, verbose = false, verboseText = [], exitAfterLog = false, logWithThrownError = false }) {
if (verbose) {
combinedText = combinedText.concat(verboseText);
text = text.concat(verboseText);
}
console.error(red(combinedText.join('\n')));
if (exitOnLog) {
const message = red(text.join('\n'));
if (logWithThrownError) {
throw new Error(message);
}
else {
console.error('\n', message);
}
if (exitAfterLog && !logWithThrownError) {
process.exit(1);

@@ -19,5 +24,5 @@ }

if (verbose) {
console.info(cyan(text.join('\n')));
console.log(cyan(text.join('\n')));
}
}
//# sourceMappingURL=logVerbose.js.map

@@ -37,3 +37,4 @@ import { packageCwd, rollupTypeBundlerRcJsonPath, rollupTypeBundlerRcPath, rollupTypeBundlerRcYamlPath, rollupTypeBundlerRcYmlPath } from '#lib/constants';

err
]
],
exitAfterLog: true
});

@@ -61,3 +62,4 @@ }

err
]
],
exitAfterLog: true
});

@@ -75,2 +77,11 @@ }

const distPath = Reflect.get(options, 'dist');
if (!distPath) {
logVerboseError({
text: [
'You did not provide a path to your "dist" folder. Please do so either with the "--dist" flag, or by creating a config file.',
"For more information, see this project's README here: https://github.com/favware/rollup-type-bundler#usage "
],
exitAfterLog: true
});
}
return {

@@ -77,0 +88,0 @@ ...options,

@@ -0,1 +1,2 @@

import { cyan, green, red } from 'colorette';
import { readFile } from 'fs/promises';

@@ -17,2 +18,15 @@ import { load } from 'js-yaml';

}
export async function doActionAndLog(preActionLog, action) {
process.stdout.write(cyan(`${preActionLog}... `));
try {
const returnValue = (await action);
console.log(green('✅ Done'));
return returnValue;
}
catch (error) {
console.log(red('❌ Error'));
console.error(error.message);
process.exit(1);
}
}
//# sourceMappingURL=utils.js.map
{
"name": "@favware/rollup-type-bundler",
"version": "0.0.1-next.ff875c4.0",
"version": "1.0.0",
"description": "A small CLI tool to bundle types with rollup",

@@ -22,3 +22,6 @@ "author": "@favware",

"dist",
"!dist/*.tsbuildinfo"
"!dist/*.tsbuildinfo",
"!dist/**/*.js.map",
"!dist/**/*.d.ts",
"!dist/**/*.d.ts.map"
],

@@ -25,0 +28,0 @@ "scripts": {

@@ -8,3 +8,2 @@ <div align="center">

[![GitHub](https://img.shields.io/github/license/favware/rollup-type-bundler)](https://github.com/favware/rollup-type-bundler/blob/main/LICENSE)
[![npm bundle size](https://img.shields.io/bundlephobia/min/@favware/rollup-type-bundler?logo=webpack&style=flat-square)](https://bundlephobia.com/result?p=@favware/rollup-type-bundler)
[![npm](https://img.shields.io/npm/v/@favware/rollup-type-bundler?color=crimson&logo=npm)](https://www.npmjs.com/package/@favware/rollup-type-bundler)

@@ -19,5 +18,13 @@ [![Depfu](https://badges.depfu.com/badges/97d09026f35f8886a8bca2e8c7caa533/count.svg)](https://depfu.com/github/favware/rollup-type-bundler?project_id=28226)

When creating a library with TypeScript you will often be able to just publish it with your current toolset, however once your library grows and grows then you might want to make it possible for people of your library to use [TypeScript Module Augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html) to merge additional types into the types that you provide.
When you create a library in TypeScript, you will often be able to just publish
it with your current toolset; however, once your library grows and grows, you
might want to make it possible for people of your library to use [TypeScript
Module Augmentation][tma] to merge additional types into the types that you
provide.
This however introduces a big issue in TypeScript. Even when re-exporting all your interfaces/types/classes in a root `index.d.ts` that you are referencing in `"types"` in your `package.json`, TypeScript still won't properly apply folder-nested (i.e. a type that's in `your-package/dist/lib/structures/SomeClass.d.ts`) module augmentation when augmenting with:
Unfortunately, this introduces a big issue in TypeScript. Even when
re-exporting all your interfaces/types/classes in a root `index.d.ts` that you
are referencing in `"types"` in your `package.json`, TypeScript still won't
properly apply folder-nested module augmentation (i.e. a type that's in
`your-package/dist/lib/structures/SomeClass.d.ts`) when augmenting like this:

@@ -28,3 +35,3 @@ ```ts

Without this package your users would have to augment the type with:
Without this package, your users would have to augment the type like this:

@@ -35,16 +42,30 @@ ```ts

this is extremely bad developer experience because you cannot apply all module augmentations in 1 block. To solve this issue, there is this library.
As you might guess, this is extremely bad developer experience because you
cannot apply all module augmentations in 1 block. That's where this rollup
module comes in - now, you can bundle types in a developer-friendly way and
make life easier for everyone involved.
[tma]: https://www.typescriptlang.org/docs/handbook/declaration-merging.html
### How this works
The library uses [rollup](https://www.npmjs.com/package/rollup) with [rollup-plugin-dts](https://www.npmjs.com/package/rollup-plugin-dts) under the hood. It will execute a few steps:
The library uses [rollup] with [rollup-plugin-dts] under the hood. It will
execute a few steps:
1. It cleans the configured dist directory (`--dist` flag or `dist` in config).
2. It calls the `--build-script` (or `buildScript` in config) to build your code with your compiler. This defaults to `build`.
3. It executes [rollup](https://www.npmjs.com/package/rollup) to bundle your types into 1 `index.d.ts` file, output to the configured `dist` directory.
4. It removes all other `.d.ts` and `.d.ts.map` files from your configured `dist` directory as they are now superfluous.
1. It cleans the configured distribution directory (`--dist` flag or `dist` in
config).
2. It calls the `--build-script` (or `buildScript` in config) to build your code
with your compiler. This defaults to `build`.
3. It executes [rollup] to bundle your types into 1 `index.d.ts` file, output to
the configured `dist` directory.
4. It removes all other `.d.ts` and `.d.ts.map` files from your configured
`dist` directory as they are now superfluous.
[rollup]: https://www.npmjs.com/package/rollup
[rollup-plugin-dts]: https://www.npmjs.com/package/rollup-plugin-dts
## Installation
You can use the following command to install this package, or replace `npm install -D` with your package manager of choice.
You can use the following command to install this package, or replace
`npm install -D` with your package manager of choice.

@@ -91,13 +112,9 @@ ```sh

Or you can provide most of these options through a configuration file. The following files are supported:
Or, you can set most of these options through a configuration file. This
file should be located at your current working directory (where you're
calling this package). It should be named `.rollup-type-bundlerrc`, optionally
suffixed with `.json`, `.yaml`, or `.yml`.
- `.rollup-type-bundlerrc`
- `.rollup-type-bundlerrc.json`
- `.rollup-type-bundlerrc.yaml`
- `.rollup-type-bundlerrc.yml`
### Config file fields
The file should either be located at the current working directory from where this rollup-type-bundler is called, or provided as a custom path with `--config`.
### Fields in config file
- `--dist` maps to `dist`

@@ -108,3 +125,5 @@ - `--build-script` maps to `buildScript`

When using `.rollup-type-bundlerrc` or `.rollup-type-bundlerrc.json` as your config file you can also use the JSON schema to get schema validation. Add to your config file:
When using `.rollup-type-bundlerrc` or `.rollup-type-bundlerrc.json` as
your config file you can also use the JSON schema to get schema
validation. To do so, add the following to your config file:

@@ -129,3 +148,3 @@ ```json

**Example Yaml file**:
**Example YAML file**:

@@ -143,5 +162,10 @@ ```yaml

Favware projects is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
Favware projects are and always will be open source, even if we don't get
donations. That being said, we know there are amazing people who may still
want to donate just to show their appreciation. Thank you very much in
advance!
We accept donations through Ko-fi, Paypal, Patreon, GitHub Sponsorships, and various crypto currencies. You can use the buttons below to donate through your method of choice.
We accept donations through Ko-fi, Paypal, Patreon, GitHub Sponsorships,
and various cryptocurrencies. You can use the buttons below to donate
through your method of choice.

@@ -168,2 +192,3 @@ | Donate With | Address |

<td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/favware/rollup-type-bundler/commits?author=Favna" title="Code">💻</a> <a href="#design-Favna" title="Design">🎨</a> <a href="#ideas-Favna" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-Favna" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-Favna" title="Maintenance">🚧</a> <a href="#platform-Favna" title="Packaging/porting to new platform">📦</a> <a href="#projectManagement-Favna" title="Project Management">📆</a></td>
<td align="center"><a href="https://github.com/Nytelife26"><img src="https://avatars.githubusercontent.com/u/22531310?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tyler J Russell</b></sub></a><br /><a href="https://github.com/favware/rollup-type-bundler/commits?author=Nytelife26" title="Documentation">📖</a></td>
</tr>

@@ -170,0 +195,0 @@ </table>

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc