drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
23.21k stars 565 forks source link

[drizzle-kit] Reduce drizzle-kit bundle size #2722

Open kravetsone opened 1 month ago

kravetsone commented 1 month ago

https://npmgraph.js.org/?q=drizzle-kit#zoom=h&deps=devDependencies

image

for now unpacked size is too much - 8.41 MB

By reducing dependencies and their weight, we will put ourselves on the path to the future of JS, as well as increase the performance of the CLI

Continuation of this issue https://github.com/drizzle-team/drizzle-kit-mirror/issues/485

bin.cjs size analyze

image

How to use metafile and analyze

Optimization list

kravetsone commented 1 month ago

We should replace zx with something else

because it used only for non first-class feature

import envPaths from 'env-paths';
import { mkdirSync } from 'fs';
import { access, readFile } from 'fs/promises';
import { join } from 'path';
import { $ } from 'zx';

const p = envPaths('drizzle-studio', {
    suffix: '',
});

$.verbose = false;
$.cwd = p.data;
mkdirSync(p.data, { recursive: true });

export const certs = async () => {
    const res = await $`mkcert --help`.nothrow();

    // ~/.local/share/drizzle-studio
    const keyPath = join(p.data, 'localhost-key.pem');
    const certPath = join(p.data, 'localhost.pem');

    if (res.exitCode === 0) {
        try {
            await Promise.all([access(keyPath), access(certPath)]);
        } catch (e) {
            await $`mkcert localhost`.nothrow();
        }
        const [key, cert] = await Promise.all([
            readFile(keyPath, { encoding: 'utf-8' }),
            readFile(certPath, { encoding: 'utf-8' }),
        ]);
        return key && cert ? { key, cert } : null;
    }
    return null;
};

certs();

image

https://bundlephobia.com/package/zx@8.1.4

https://npmgraph.js.org/?q=zx#deps=devDependencies

A lot of dependencies in bundle come from it

image

zx 7.2.2 └── yaml 2.4.2

image

zx 7.2.2 └─┬ node-fetch 3.3.1 ├─┬ fetch-blob 3.2.0 │ └── web-streams-polyfill 3.2.1 └─┬ formdata-polyfill 4.0.10 └─┬ fetch-blob 3.2.0 └── web-streams-polyfill 3.2.1 image

But node-fetch also depends on it

zx 7.2.2 └─┬ globby 13.2.2 └── fast-glob 3.3.2

So we have two glob packages

image

And etc