Giter VIP home page Giter VIP logo

bunchee's People

Contributors

arzafran avatar await-ovo avatar dependabot[bot] avatar devjiwonchoi avatar himself65 avatar huozhi avatar hyoban avatar juliusmarminge avatar kdy1 avatar kwaa avatar nnecec avatar piotr-cz avatar promer94 avatar sinchang avatar sukkaw avatar thecuvii avatar thgh avatar timneutkens avatar tmilewski avatar tundera avatar ycjcl868 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

bunchee's Issues

regeneratorRuntime is not defined (`--target node`)

When I try to bundle a JavaScript library that uses async functions and then use that library, I get ReferenceError: regeneratorRuntime is not defined, even when using --target node.

I found that the issue is resolved by adding { target: { node: "16" } } to the options of babel-preset-o in createInputConfig in src/rollup-config.ts, since instead of the async/await keywords being transformed to use regeneratorRuntime, they are just passed through to the output as is. Though I'm not sure exactly what value node should be instead of "16". Also, perhaps esmodules: true should be also added to target like it was before? (see below)

targets: {
node: '4',
esmodules: true,
},

Polish error trace in watch mode

Instead of logging the full error object with properties like frame, loc, code, log the frame as trace first, then log other properties in a certain format, for better and easier viewing

Treate sub folder import as externals

if sub folder imports is from deps/peerDeps, treate as externals

import NextHead from 'next/head'

expected: not bundle sub imports like next/head into dist

Image support

Hi! Thanks for great library.

Does bunchee have image support?

cli: support compile multiple sources to multiple dist

currently can only use bunchee with main and module fields in the package.json, bundle file to one dist

bunchee src/index.js

but sometimes we want to bundle multi src to multi dist

bunchee src/index.js -cjs -esm -d ./dist/ && bunchee src/react.js -d ./

# then I'll have

--
 |- dist
     |- index.cjs.js
     |- index.esm.js
|- react.cjs.js
|- react.esm.js

Handle warning of rollup

Rollup warning when using bunchee:

implicitly using "default" export mode, which means for CommonJS output that its default export is assigned to "module.exports". For many tools, such CommonJS output. will not be interchangeable with the original ES module. If this is intended, explicitly set "output. exports" to either "auto" or "default", otherwise you might want to consider changing the signature of "..." to use named exports only.

Watch mode seems not working

Repro Steps

  1. git clone https://github.com/promer94/test-bunchee.git
  2. yarn install && yarn watch
  3. modify the src/index.ts, the output got rebuild but keep the same result

Additional Context

bunchee version 1.5.4
node version 12.18.3

Simplify multi exports compilation config

In v2 alpha we introduced a bunchee configuration in package.json which quite makes the zero-config idea, ideally we could remove it and still keep it as before but use some convention of folder as the entry points

Solution

To keep both typescript generated type files and dist are in the aligned structure, bunchee should find the entry files in top-level directories by the exported paths.

E.g., If there's ./lite export condition in exports field, bunchee should look up <rootDir>/lite.[extension] file as the entry file, extension can be one of the popular and supported file extentions like js, ts, jsx, tsx, mjs or cjs.

Then the generated dist file path should be specified from exports['./lite'], it can be any path in the dist folder such as ./dist/lite.js. The generated entry file types should be flattern into ./dist folder without nested directory. e.g.
Source file ./index.ts will be compiled to ./dist/index.js', which can now easily match ./dist/index.d.ts. This avoid the case that your source files are from ./srcfolder, then it still be deeply nested in the dist folder like./dist/src/index.d.ts`.

Use preserve shebang plugin instead of bin argument

learn from comments while contributing to tsdx project, shebang should be preserved since it's allowed in nodejs, but currently acorn version of rollup cannot perform on parsing this.

  • bin path can be isolated from main / module path
  • bin field could be an object mapping to few commands
  • user can keep shebang in source code instead of manually adding it to output

Babel target: transform all

current babel config targets on node 4.x syntaxes, still have some ES^ syntaxes that not been transformed, such as template literials

Working with conditional exports

Hello! I'm working on a package that depends on the WebCrypto API, and I'd like to use require('node:crypto').webcrypto conditionally on Node.js environments.

Although my use case is quite a niche, I think using conditional exports enables useful things that weren't possible before: using N-API bindings on Node.js, providing Node.js-specific APIs and more.

Would you consider adding this feature? I'm not sure about the design, but I'm thinking something like a constant with the matched condition.

Parsing the extended compiler options from tsconfig.json

Sor far bunchee is using thses ts API to access the tsconfig

tsconfigJSON = ts.readConfigFile(tsConfigPath, ts.sys.readFile).config;
tsCompilerOptions = ts.parseJsonConfigFileContent(tsconfigJSON, ts.sys, "./").options;

But turns out the extended ones in subpath are not accessible, it can only read the config without the inherited values from parnet config.

Resolve jsx extension

Bug

Currently jsx syntaxes in .js ext file are available to use. but jsx extension is failed to resolve.

Expected

.jsx ext files should be resolved successfully by bundler

Please support generator syntax

Hey bunchee maintainer! I am trying to use bunchee to compile my generator code but it just can't! Could you please add support for that feature? thank you!

Doesn't honor tsconfig "target" property

Hi @huozhi,

I have set up bunchee according to the README, to bundle a TypeScript library that I'm working on. When I run it, the bundle is created without issues, however, it seems bunchee is not respecting the "target" property in tsconfig.json and instead defaults to using es5 as bundling target.

This is my tsconfig.json:

{
  "extends": "@tsconfig/node16-strictest/tsconfig.json",
  "compilerOptions": {
    "outDir": "build",
    "target": "ES6",
    "declaration": true,
    "noUncheckedIndexedAccess": false
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules"]
}

This is my bunchee config in the package.json:

{
  "type": "module",
  "main": "build/main.cjs",
  "types": "build/main.d.ts",
  "exports": {
    "require": "./build/main.cjs",
    "import": "./build/main.esm.js",
    "default": "./build/main.esm.js"
  },
  "scripts": {
    "build": "bunchee src/main.ts",
  },
  "devDependencies": {
    "bunchee": "^2.1.7",
  },
}

The code generated in the build/ directory contains some autogenerated polyfills which are not needed for ES6 code, which is an indication that the bundling is targeting ES5 instead of the ES6 target specified in the tsconfig.json. If I change the build script in package.json to bunchee --target es2015 src/main.ts, the generated bundle is different and doesn't contain all of those ES5 polyfills.

Maximum call stack size exceeded on version >=2.0.2

Hi,

When I try to run xswr, a library built with bunchee version >=2.0.2 on a Next.js website, a "Maximum call stack exceeded" is thrown

Reproduction:

  1. clone xswr: git clone https://github.com/hazae41/xswr && cd xswr
  2. install dependencies: npm install
  3. update bunchee: npm install --save-dev bunchee
  4. build xswr: npm run build
  5. link xswr: npm link
  6. go to the test directory: cd test/next
  7. install dependencies: npm install
  8. remove xswr: npm remove @hazae41/xswr
  9. link xswr: npm link @hazae41/xswr
  10. run test with Next dev: npm run dev
  11. go to http://localhost:3000
  12. click some page and the error is thrown

This doesn't happen on 2.0.1, 2.0.0, 1.9.1

Thank you!

Support iife format for CLI

iife format is not a standard output for organized modules like cjs / esm but will be useful for the case like building a polyfill script that can run directly in browser

Don't transform class

Is there a way to prevent transforming classes?

Current behaviour:

Input:

import { LitElement, html } from 'lit';
import { customElement, property } from 'lit/decorators.js';

@customElement('custom-button')
export class Button extends LitElement {
  render() {
    return html`<button><slot /></button>`;
  }
}

Output:

var Button = /** @class */ function(_super) {
    __extends(Button, _super);
    function Button() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Button.prototype.render = function() {
        return html(templateObject_1 || (templateObject_1 = __makeTemplateObject([
            "<button><slot /></button>"
        ], [
            "<button><slot /></button>"
        ])));
    };
    Button = __decorate([
        customElement('custom-button')
    ], Button);
    return Button;
}(LitElement);

Expected: preserve class
Thank you so much!

Unexpected token `implements`

Trying to build a TypeScript file. implements keyword seems not to be supported.

yarn run v1.22.10
$ bunchee src/index.ts -m --no-sourcemap
/home/ubuntu/repos/wedi/src/index.ts .ts true
 9: } from './typings';
10: 
11: export class DependencyCollection implements Disposable {
                                      ^
12:     public disposed: boolean = false;
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
    at error (/home/ubuntu/repos/wedi/node_modules/rollup/dist/shared/node-entry.js:5400:30)
    at Module.error (/home/ubuntu/repos/wedi/node_modules/rollup/dist/shared/node-entry.js:9820:16)
    at tryParse (/home/ubuntu/repos/wedi/node_modules/rollup/dist/shared/node-entry.js:9713:23)
    at Module.setSource (/home/ubuntu/repos/wedi/node_modules/rollup/dist/shared/node-entry.js:10076:33)
    at /home/ubuntu/repos/wedi/node_modules/rollup/dist/shared/node-entry.js:12362:20
    at async Promise.all (index 0)
    at async Promise.all (index 0)
    at async Promise.all (index 0)
    at async Promise.all (index 0)

Replace the content

Customize to replace some code with new text, not limited to process.env but also open to other code replacement. Need some examples

Provide --env <env1,env2,...> as arg to pick the env you need to inline in the code

Does "react-jsx" work?

This is a very cool tool, thanks for creating it! I was wondering about compiling React, is setting "jsx": "react-jsx" in tsconfig.json supposed to work? I'm getting the following error message when I try to compile a .tsx file:

Error: @rollup/plugin-typescript TS2686: 'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.

Let me know if you need a repro.

Parse subpath exports from exports sugar

Today we need to add a package.json for a subpath folder if you want to build based on that working directory, for instance:

// pkg/a/package.json

{
   "name": "pkg-a",
   "exports": {}
}

In this way, you can build the assets based on the subpath pkg/a and generate output according to "exports" path in that package.json. Then we refer those outputs in the toplevel package.json for the corresponding subpath imports.
But this might confuse some tooling to understand the structure of the library better. Since node.js introduced the exports sugar, any subpath needs to provide a package.json just for getting assets output paths. bunchee should be able to auto detect it

Proposal

Introducing a new exports paths auto-detection feature for top level package.json.

Example

Assume we have a toplevel package foo with package.json which contains a subpath import foo/die

{
   "name": "foo",
   "exports": {
      "./die": {
          "import": "...",
          "require": "...",
          "types": "...",
      }
   }
}

Then you have your source folder of foo/die/ with entry file foo/die/index.js. In this case bunchee should read the output paths infomation from exports field if the current build working directory matches the any exports path

Compiling TypeScript with Iterable<T>

Hello @huozhi

I am trying to bundle a typescript file src/index.ts which contain code on iterables, i.e., Iterable<T> and IterableIterator<T> types are used. I have the package.json setup as mentioned.

I tried to compile it as follows:

$ bunchee src/index.ts

And recieved the following error:

C:\Documents\extra-array>bunchee -f esm --runtime node --target esnext src/index.ts                     
src/index.ts(161,14): error TS2802: Type 'Iterable<T>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
src/index.ts(171,36): error TS2802: Type 'Iterable<T>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
src/index.ts(848,10): error TS2802: Type 'IterableIterator<T[]>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
src/index.ts(849,17): error TS2802: Type 'IterableIterator<T[]>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
src/index.ts(868,12): error TS2802: Type 'IterableIterator<T[]>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
src/index.ts(876,19): error TS2802: Type 'IterableIterator<T[]>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
src/index.ts(1244,17): error TS2802: Type 'IterableIterator<number>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
src/index.ts(1260,17): error TS2802: Type 'IterableIterator<number>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
src/index.ts(1275,14): error TS2802: Type 'IterableIterator<number>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
src/index.ts(2287,15): error TS2802: Type 'Iterable<T>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.

I retried the following commands, but recieved the same errors as above.

$ bunchee -f esm --runtime node --target es2015 src/index.ts
$ bunchee -f esm --runtime node --target es2018 src/index.ts
$ bunchee -f esm --runtime node --target esnext src/index.ts
$ bunchee -f esm --runtime node --target esnext --downlevelIteration src/index.ts

Maybe this has something to do with passing arguments to swc.

Regards.

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.