Code Monkey home page Code Monkey logo

tsup's Introduction

tsup

npm version npm downloads

Bundle your TypeScript library with no config, powered by esbuild.

๐Ÿ‘€ What can it bundle?

Anything that's supported by Node.js natively, namely .js, .json, .mjs. And TypeScript .ts, .tsx. CSS support is experimental.

โš™๏ธ Install

Install it locally in your project folder:

npm i tsup -D
# Or Yarn
yarn add tsup --dev
# Or pnpm
pnpm add tsup -D

You can also install it globally but it's not recommended.

๐Ÿ“– Usage

Bundle files

tsup [...files]

Files are written into ./dist.

You can bundle multiple files in one go:

tsup src/index.ts src/cli.ts

This will output dist/index.js and dist/cli.js.

๐Ÿ“š Documentation

For complete usages, please dive into the docs.

For all configuration options, please see the API docs.

๐Ÿ’ฌ Discussions

Head over to the discussions to share your ideas.

Sponsors

Ship UIs faster with automated workflows for Storybook

sponsors

Project Stats

Alt

License

MIT ยฉ EGOIST

tsup's People

Contributors

amitdahan avatar archergu avatar await-ovo avatar chelestewang avatar ckohen avatar dependabot-preview[bot] avatar dependabot[bot] avatar egoist avatar eric-burel avatar gavinsharp avatar jastor11 avatar jgoux avatar leonardssh avatar leumasme avatar ocavue avatar pabloszx avatar rayzr522 avatar renovate[bot] avatar rluvaton avatar sachinraja avatar sapphi-red avatar segevfiner avatar steveluscher avatar superchupudev avatar sxzz avatar talljack avatar tmkx avatar wzhkobe2408 avatar zhmushan avatar zvictor 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

tsup's Issues

question: types have all the same icons in VS Code

not sure if that is something to fix in this lib, but it looks like packages using tsc for decleration files have better icon support in vs code. How to I get the same icons, functions have the purble f
3rd party lib form npm has
image

my own lib using tsup to make declaration files (createRoutes is an function)
image

Silently fails to build

The problem

Hello, I was trying to transfer my lib from using Rollup to Tsup, but it fails silently, both for ESM and CJS, with no any errors in stderr.

Command:

tsup src/index.ts --format cjs,esm --dts

Result:

image

Reproduction repository: https://github.com/talentlessguy/parsec

note that it builds fine with rollup + rollup-plugin-typescript2

Solution

Catch all errors and output them in the stderr

Infer output formats from package.json

When no --format flag is specified..

tsup src/index.ts

..tsup can look in package.json for clues.

  • The main, module, types/typings, and unpkg/jsdelivr fields all imply the preferred output paths, even allowing for custom bundle names.
  • When module exists, tsup creates an ESM bundle.
  • When types or typings exist, tsup creates a .d.ts bundle.
  • When unpkg or jsdelivr exist, tsup creates a UMD bundle.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

Declaration files don't work with multiple entrypoints

This is my tsup config:

"tsup": {
    "splitting": false,
    "sourcemap": true,
    "clean": true,
    "dts": true,
    "format": [
      "esm",
      "cjs"
    ],
    "entryPoints": [
      "src/index.ts",
      "src/cli/index.ts"
    ]
  },

When I run build, the file dist/index.d.ts only has #!/usr/bin/env node as contents (even though this is not the CLI declaration file), nothing else. There is no file dist/cli/index.d.ts. If I run it with only a single entrypoint: src/index.ts, the dist/index.d.ts file is generated properly to correspond to src/index.ts.

--bundle doesn't work for every package

Dynamic require calls are not handled and will throw errors at runtime, due to limitations of @rollup/plugin-commonjs, require.cache will be undefined too if you use --bundle, I plan to fix those issues in coming versions of tsup.

help: how to bundle .svelte & ts files in the same repo

Hey there, I am trying to bundle normal ts files used in node & svelte files in the same repo.
It works, however declaration files do not get generated. I narrowed it down to some settings in my tsconfig, but setting the types field to svelte breaks.
Currently getting.. do you have help how to set this up correctly?

DTS  Build error
TypeError: Cannot destructure property 'column' of 'locate(...)' as it is undefined.
   at Module.addLocationToLogProps (C:\Users\Alexander\Documents\projects\svelteuse\router\node_modules\rollup\dist\shared\rollup.js:10295:15)
   at Module.error (C:\Users\Alexander\Documents\projects\svelteuse\router\node_modules\rollup\dist\shared\rollup.js:9764:14)
   at Module.getVariableForExportName (C:\Users\Alexander\Documents\projects\svelteuse\router\node_modules\rollup\dist\shared\rollup.js:9928:29)
   at Module.includeAllExports (C:\Users\Alexander\Documents\projects\svelteuse\router\node_modules\rollup\dist\shared\rollup.js:10000:35)
   at Graph.includeStatements (C:\Users\Alexander\Documents\projects\svelteuse\router\node_modules\rollup\dist\shared\rollup.js:19405:24)
   at Graph.build (C:\Users\Alexander\Documents\projects\svelteuse\router\node_modules\rollup\dist\shared\rollup.js:19339:14)
   at async rollupInternal (C:\Users\Alexander\Documents\projects\svelteuse\router\node_modules\rollup\dist\shared\rollup.js:20297:9)
   at async runRollup (C:\Users\Alexander\Documents\projects\svelteuse\router\node_modules\tsup\dist\rollup.js:6090:20)
   at async startRollup (C:\Users\Alexander\Documents\projects\svelteuse\router\node_modules\tsup\dist\rollup.js:6124:5)

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

[Question] Support config file like tsup.config.js

Hi Egoist, thank you for the great lib! But I wonder how about this?
tsup.config.js

module.export = {
 target: 'es2021',
 sourcemap: true,
 format: ['esm','cjs']
 ....
}

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

'ModuleName' is not exported by

This line causes the following error.

import { Database as Connection } from 'better-sqlite3';
> tsup index.ts --dts --bundle

Error: 'Database' is not exported by node_modules/@types/better-sqlite3/index.d.ts, imported by lib/drivers/sqlite.ts
    at error (/Users/xo/code/scratchdb/database/node_modules/rollup/dist/shared/rollup.js:161:30)
    at Module.error (/Users/xo/code/scratchdb/database/node_modules/rollup/dist/shared/rollup.js:15097:16)
    at handleMissingExport (/Users/xo/code/scratchdb/database/node_modules/rollup/dist/shared/rollup.js:14994:28)
    at Module.traceVariable (/Users/xo/code/scratchdb/database/node_modules/rollup/dist/shared/rollup.js:15478:24)
    at ModuleScope.findVariable (/Users/xo/code/scratchdb/database/node_modules/rollup/dist/shared/rollup.js:14047:39)
    at FunctionScope.findVariable (/Users/xo/code/scratchdb/database/node_modules/rollup/dist/shared/rollup.js:9527:38)
    at Identifier$1.bind (/Users/xo/code/scratchdb/database/node_modules/rollup/dist/shared/rollup.js:9938:40)
    at AssignmentPattern.bind (/Users/xo/code/scratchdb/database/node_modules/rollup/dist/shared/rollup.js:9571:23)
    at AssignmentPattern.bind (/Users/xo/code/scratchdb/database/node_modules/rollup/dist/shared/rollup.js:11615:15)
    at FunctionDeclaration.bind (/Users/xo/code/scratchdb/database/node_modules/rollup/dist/shared/rollup.js:9567:31)

This is the better-sqlite3 definition file it's referencing.

// Type definitions for better-sqlite3 5.4
// Project: http://github.com/JoshuaWise/better-sqlite3
// Definitions by: Ben Davies <https://github.com/Morfent>
//                 Mathew Rumsey <https://github.com/matrumz>
//                 Santiago Aguilar <https://github.com/sant123>
//                 Alessandro Vergani <https://github.com/loghorn>
//                 Andrew Kaiser <https://github.com/andykais>
//                 Mark Stewart <https://github.com/mrkstwrt>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0

import Integer = require("integer");

type VariableArgFunction = (...params: any[]) => any;
type ArgumentTypes<F extends VariableArgFunction> = F extends (...args: infer A) => any
  ? A
  : never;

declare namespace BetterSqlite3 {
    interface Statement<BindParameters extends any[]> {
        database: Database;
        source: string;
        reader: boolean;

        run(...params: BindParameters): Database.RunResult;
        get(...params: BindParameters): any;
        all(...params: BindParameters): any[];
        iterate(...params: BindParameters): IterableIterator<any>;
        pluck(toggleState?: boolean): this;
        expand(toggleState?: boolean): this;
        raw(toggleState?: boolean): this;
        bind(...params: BindParameters): this;
        columns(): ColumnDefinition[];
        safeIntegers(toggleState?: boolean): this;
    }

    interface ColumnDefinition {
        name: string;
        column: string | null;
        table: string | null;
        database: string | null;
        type: string | null;
    }

    interface Transaction<F extends VariableArgFunction> {
        (...params: ArgumentTypes<F>): ReturnType<F>;
        default(...params: ArgumentTypes<F>): ReturnType<F>;
        deferred(...params: ArgumentTypes<F>): ReturnType<F>;
        immediate(...params: ArgumentTypes<F>): ReturnType<F>;
        exclusive(...params: ArgumentTypes<F>): ReturnType<F>;
    }

    interface Database {
        memory: boolean;
        readonly: boolean;
        name: string;
        open: boolean;
        inTransaction: boolean;

        // tslint:disable-next-line no-unnecessary-generics
        prepare<BindParameters extends any[] | {} = any[]>(source: string): BindParameters extends any[]
          ? Statement<BindParameters>
          : Statement<[BindParameters]>;
        transaction<F extends VariableArgFunction>(fn: F): Transaction<F>;
        exec(source: string): this;
        pragma(source: string, options?: Database.PragmaOptions): any;
        checkpoint(databaseName?: string): this;
        function(name: string, cb: (...params: any[]) => any): this;
        function(name: string, options: Database.RegistrationOptions, cb: (...params: any[]) => any): this;
        aggregate(name: string, options: Database.AggregateOptions): this;
        loadExtension(path: string): this;
        close(): this;
        defaultSafeIntegers(toggleState?: boolean): this;
        backup(destinationFile: string, options?: Database.BackupOptions): Promise<Database.BackupMetadata>;
    }

    interface DatabaseConstructor {
        new(filename: string, options?: Database.Options): Database;
        (filename: string, options?: Database.Options): Database;
        prototype: Database;

        Integer: typeof Integer;
        SqliteError: typeof SqliteError;
    }
}

declare class SqliteError implements Error {
    name: string;
    message: string;
    code: string;
    constructor(message: string, code: string);
}

declare namespace Database {
    interface RunResult {
        changes: number;
        lastInsertRowid: Integer.IntLike;
    }

    interface Options {
        memory?: boolean;
        readonly?: boolean;
        fileMustExist?: boolean;
        timeout?: number;
        verbose?: (message?: any, ...additionalArgs: any[]) => void;
    }

    interface PragmaOptions {
        simple?: boolean;
    }

    interface RegistrationOptions {
        varargs?: boolean;
        deterministic?: boolean;
        safeIntegers?: boolean;
    }

    interface AggregateOptions extends RegistrationOptions {
        start?: any;
        step: (total: any, next: any) => any;
        inverse?: (total: any, dropped: any) => any;
        result?: (total: any) => any;
    }

    interface BackupMetadata {
        totalPages: number;
        remainingPages: number;
    }
    interface BackupOptions {
        progress: (info: BackupMetadata) => number;
    }

    type Integer = typeof Integer;
    type SqliteError = typeof SqliteError;
    type Statement<BindParameters extends any[] | {} = any[]> = BindParameters extends any[]
      ? BetterSqlite3.Statement<BindParameters>
      : BetterSqlite3.Statement<[BindParameters]>;
    type ColumnDefinition = BetterSqlite3.ColumnDefinition;
    type Transaction = BetterSqlite3.Transaction<VariableArgFunction>;
    type Database = BetterSqlite3.Database;
}

declare const Database: BetterSqlite3.DatabaseConstructor;
export = Database;

Support ES modules

Node.js has native esm support now, it makes sense to generate an additional .mjs bundle.

So by using --esm you will have two bundled files, index.js and index.mjs

export issues with cjs

When I bundle

import { CentraRequest, HTTPMethod } from './lib/CentraRequest';
import { URL } from 'url';
/**
 *
 *
 * @param {(URL | string)} url
 * @param {HTTPMethod} [method='GET']
 */
export = (url: URL | string, method: HTTPMethod = 'GET') => new CentraRequest(url, method);;

I get module.exports.default = the function rather than module.exports = function which is the intended behavior.

Are there any solutions or workarounds to this?

Add lint command

Require eslint as peerDependency

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

Silent flag?

Any chance on a silent flag being added to silence the logging?

For example.

> rm -rf dist && tsup src/index.ts --format esm,cjs,iife --legacy-output --dts

 CLI  Using tsconfig: /Users/xo/.npm/_cacache/tmp/git-clone-77b5acfa/tsconfig.json
 CLI  Target: es2020
 ESM  Build start
 CJS  Build start
 IIFE  Build start
 ESM  Build success in 9ms
 CJS  Build success in 57ms
 IIFE  Build success in 56ms
 DTS  Build start
 DTS  Build success in 1300ms

Support out-file option

Hi,

Would be great to be able to decide the output file name, could be a great addition to --out-dir

What do you think ?

Resolve is needed for run-time

Trying to use this without resolve installed throws this.

(node:12916) UnhandledPromiseRejectionWarning: Error: Cannot find module 'resolve'
Require stack:
- /Users/xo/code/scratchdb/database/node_modules/tsup/dist/index.js
- /Users/xo/code/scratchdb/database/node_modules/tsup/dist/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:625:15)
    at Function.Module._load (internal/modules/cjs/loader.js:527:27)
    at Module.require (internal/modules/cjs/loader.js:683:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at getRollupConfig (/Users/xo/code/scratchdb/database/node_modules/tsup/dist/index.js:12406:34)
    at createRollupConfigs (/Users/xo/code/scratchdb/database/node_modules/tsup/dist/index.js:12424:26)
    at CAC.<anonymous> (/Users/xo/code/scratchdb/database/node_modules/tsup/dist/cli.js:710:32)
(node:12916) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:12916) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

when running via npx it uses the wrong path

npx tsup ./src/index.ts --format esm,cjs,iife --dts --minify

Even after installing typescript it wouldn't solve the issue, adding tsup to the current project and then trying with the local version fixed the issue.

Error: Cannot find module 'typescript'
Require stack:
- /Users/xo/.npm/_npx/96410/lib/node_modules/tsup/node_modules/rollup-plugin-dts/dist/rollup-plugin-dts.js
- /Users/xo/.npm/_npx/96410/lib/node_modules/tsup/dist/rollup.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/xo/.npm/_npx/96410/lib/node_modules/tsup/node_modules/rollup-plugin-dts/dist/rollup-plugin-dts.js:6:10)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
Emitted 'error' event on process instance at:
    at emitUnhandledRejectionOrErr (internal/event_target.js:543:11)
    at MessagePort.[nodejs.internal.kHybridDispatch] (internal/event_target.js:358:9)
    at MessagePort.exports.emitMessage (internal/per_context/messageport.js:18:26) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/xo/.npm/_npx/96410/lib/node_modules/tsup/node_modules/rollup-plugin-dts/dist/rollup-plugin-dts.js',
    '/Users/xo/.npm/_npx/96410/lib/node_modules/tsup/dist/rollup.js'
  ]
}

Enable babel transform

By passing a flag --babel tsup should load @babel/core and babel.config.js from your project directory to transform the code. This should also disable built-in es5 transform since you can use @babel/preset-env instead.

Better config handling

Currently if your tsconfig.json is invalid the error thrown by tsup is a little cryptic.

I got this from a tailing comma in my tsconfig.json. Nothing pointed to it though.

โžœ  api git:(master) โœ— ./node_modules/.bin/tsup ./app/index.ts 
SyntaxError: Unexpected token } in JSON at position 5855
    at JSON.parse (<anonymous>)
    at Object.load (/Users/xo/code/_/api/node_modules/tsup/dist/chunk.4YE4QPOH.js:13508:17)
    ```

Bundle for Deno

  • Replace node's built-in modules with Deno equivalents
  • Emit bundled .d.ts file

Add sourcemap support

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

No support for spread operator

// LN 26
const { $extend, ...grants } = grant;
[esbuild] (app/modules/get-permissions.ts:26:19) This syntax is from ES2018 and is not available in ES2017

No loader is configured for ".node" files

I'm currently working on a project that is using tsup to bundle the backend express server for a vite project.

However, when attempting to call createViteServer I get 2 errors. The first being about not being able to resolve acorn (Adding --external acorn fixed that). However the other error I am not so sure about as such a simple fix for.

Unless I am missing something it seems like .node modules would need to be added to tsup in order to fix this/work around it?

> ../../node_modules/fsevents/fsevents.js:13:23: error: No loader is configured for ".node" files: ../../node_modules/fsevents/fsevents.node
    13 โ”‚ const Native = require("./fsevents.node");
       โ•ต                        ~~~~~~~~~~~~~~~~~

Add benchmark

Compare:

  • tsup with no flags with rollup-plugin-typescript2
  • tsup with --dts with rollup-plugin-typescript2 + declaration: true
  • tsup with --dts with rollup-plugin-typescript2 + rollup-plugin-dts

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

Error parsing native CSS file

Hi @egoist thanks for your great tool, it works well when I bundling libraries, but when I use it for bundling components, it reports error parsering in the CLI, actually the native CSS has been extracted to a single CSS file.

CLI

yarn run v1.22.10
$ tsup src/index.ts --format cjs,esm --legacy-output --dts --sourcemap --minify
 CLI  tsup v4.9.1
 CLI  Building entry: src/index.ts
 CLI  Using tsconfig: /Users/Ritchie/Developer/cloud/components/react-headless-ui/tsconfig.json
 CLI  Target: node12
 CJS  Build start
 ESM  Build start
 ESM  Build success in 51ms
 CJS  Build success in 60ms
 DTS  Build start
 DTS  Build error
Error parsing: /Users/Ritchie/Developer/cloud/components/react-headless-ui/src/LoadingIndicator.css:1:0
Unexpected token (Note that you need plugins to import files that are not JavaScript)
1: .rvv-loading {
   ^
2:   display: flex;
3:   position: absolute;
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Copy static files

Would be a useful feature if you're building a browser extension, you may want to copy manifest.json and other static files to the dist folder.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

feat: externalize package.json by default in tsup-node

While developing a CLI tool using semantic-release, I noticed the distributed version used 0.0.0-semantic-release instead of the correct version because bundling was done prior to versioning the release.

I can fix this by putting the build in a prepublishOnly hook but I think it also makes sense for tsup-node to leave package.json externalized.

Incorrect line reported when a multi-line comment is present

Error parsing: /Users/xo/code/unraid/graphql-api/app/graphql/index.ts:4:8
'makeExecutableSchema' is not exported by node_modules/graphql-tools/dist/index.js, imported by app/graphql/index.ts
2:  * Copyright 2019-2020 Lime Technology Inc.  All rights reserved.
3:  * Written by: Alexis Tyler
4:  */
      ^
5: 
6: import get from 'lodash.get';

The top of that file is as follows.

/*!
 * Copyright 2019-2020 Lime Technology Inc.  All rights reserved.
 * Written by: Alexis Tyler
 */

import get from 'lodash.get';
import { v4 as uuid } from 'uuid';
import * as core from '@unraid/core';
import { makeExecutableSchema, SchemaDirectiveVisitor } from 'graphql-tools'

Add `--umd [name]` flag

Although this project is designed for bundling Node.js library, I don't mind adding some basic support for generating a browser build in umd format.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

Add nicer "non-existent file path" error

Currently if you pass a file path that's non-existent you get this.

โžœ  nat-api git:(master) โœ— ./node_modules/.bin/tsup lib/index.ts --format esm,cjs,iife --dts
 CLI  Target: es2018
 ESM  Build start
 CJS  Build start
 IIFE  Build start
 IIFE  Build success in 22ms
 ESM  Build success in 77ms
 CJS  Build success in 76ms
 DTS  Build start
Error: You must supply options.input to rollup
    at Graph.generateModuleGraph (/Users/xo/code/OmgImAlexis/nat-api/node_modules/rollup/dist/shared/rollup.js:18433:19)
    at async Graph.build (/Users/xo/code/OmgImAlexis/nat-api/node_modules/rollup/dist/shared/rollup.js:18397:9)
    at async rollupInternal (/Users/xo/code/OmgImAlexis/nat-api/node_modules/rollup/dist/shared/rollup.js:19370:9)
    at async runRollup (/Users/xo/code/OmgImAlexis/nat-api/node_modules/tsup/dist/rollup.js:1427:20)
    at async MessagePort.<anonymous> (/Users/xo/code/OmgImAlexis/nat-api/node_modules/tsup/dist/rollup.js:1463:5)

Mark all node_modules as external

tsup right now has an issue with node modules with files inside the module that are not the main file (for example, import { foo } from "bar/baz"), and it always tries to bundle them, which pretty much always is a non-desired behavior. And even breaks when outputting to esm, since it tries to bundle commonjs inside the esm modules

evanw gave a solution as a plugin mentioned here: evanw/esbuild#619 (comment)

I tested it locally and it works fine, but I would need some feedback in how to enable this behaviour, the cleanest one I could thought off is reading the moduleResolution: "node" in the tsconfig, since having that it should assume you are dealing with outputting for Node.js, but maybe a very small flag in the CLI would be a good solution too, like "tsup src/index.ts --node"

Include Typescript as a dependency or peerDependency

When using yarn (v2) pnp and building types with the --dts command we get the following error

error: rollup-plugin-dts tried to access typescript (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.

I can see why typescript isn't a dependency since it's only used when generating types - perhaps it's best to just list it in peerDependencies - though I imagine it'd be best to permit ^3.9.7 as well as anything above ^4.0.0 if that's the case. Happy to submit a PR for this.

tsup register

Allow to run your TypeScript file directly with tsup register:

node -r tsup/register cli.ts

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

Move the bundle process to esbuild

Currently the bundle process is done by Rollup and tsbuild is only used for transpiling TypeScript, I plan to move to esbuild entirely when it has code splitting support for cjs format as well, however we will still need Rollup to generate declaration file.

-w, --watch option

So that we can iterate testing CLI apps in terminal super fast!

tsup src/cli.ts -w # start watching files and rebuild if changes occurred

Watching strategy

  1. only watch entry point (cons: won't build when files imported by entry point changes)
  2. watch basedir of entry point (cons: won't build when files imported by entry point outside of basedir)
  3. ?

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.