Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kravetsone opened this issue Aug 1, 2024 · 1 comment
Open

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

kravetsone opened this issue Aug 1, 2024 · 1 comment

Comments

@kravetsone
Copy link
Contributor

kravetsone commented Aug 1, 2024

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 drizzle-team/drizzle-kit-mirror#485

bin.cjs size analyze

image

How to use metafile and analyze

Optimization list

@kravetsone
Copy link
Contributor Author

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/[email protected]

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant