vadimdemedes/ink

Bundling the CLI for reduced footprint failing in v4.x

nclsndr opened this issue ยท 4 comments

I previously used ink@3.x along with @vercel/ncc to bundle all the deps of a cli, thus reducing the dependency graph within my users' node_modules.

I just upgrade ink to 4.x, and I do not find a way to bundle it without producing a non 0 exit code at runtime. It seems we're conflicting upon the top level await behaviour vs what the process is actually "waiting" for.

Here a bare example using ncc

I also tried: Rollup, a manual Webpack 5 config. They are all having issues in that direction.

Did anyone has this kind of issue already?


Generally speaking, how do you ship CLI in JS when they'll be installed locally in (mono)repos?

We successfully bundle ink 4.x with tsup (which uses esbuild under the hood).
We declare react-devtools-core and yoga-wasm-web as externals.

Declaring react-devtools-core as externals does nothing. It's also impossible for me to build, see #614.

There might be something wrong with your setup, all I can say is that for us it works - we bundle ink and react-devtools-core stays external.
Here's our tsup config:

{
  entry: ['src/index.{ts,tsx}'],
  target: 'node16.20',
  format: 'esm',
  outDir: 'build',
  sourcemap: true,
  minify: true,
  shims: true,
  // https://github.com/evanw/esbuild/issues/1921
  banner: {
    js: `
      import { createRequire as _createRequire } from 'node:module';
      const require = _createRequire(import.meta.url);
    `,
  },
  external: [
    'react-devtools-core',
    'yoga-wasm-web',
  ],
}

I was able to make my build work by commenting out the devtools import after building:

node_modules/.bin/esbuild src/index.js \
  ...
  --external:react-devtools-core \
  --external:yoga-wasm-web \
  --define:process.env.NODE_ENV=\"production\"

sed -i '' 's#^import devtools#//import devtools#' dist/my-cmd.js

Feels like a hack, but I'm happy that after a few hours of tinkering it finally works. I'll see what else breaks tomorrow ๐Ÿ˜„