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

chore: reduce bundle size #220

Merged
merged 14 commits into from
Aug 14, 2024
Merged

chore: reduce bundle size #220

merged 14 commits into from
Aug 14, 2024

Conversation

userquin
Copy link
Member

@userquin userquin commented Aug 12, 2024

Description

This PR includes:

Right now ni build is failing. ni tgz file from 107KB to 77KB

We should remove agent.ts module, not being used. (agent module re-exporting pm detector stuff)

Linked Issues

Additional context

@userquin userquin marked this pull request as ready for review August 13, 2024 14:46
@userquin
Copy link
Member Author

@benmccann suggests picocolors (cjs only), the size is a little smaller than yoctocolors (esm only).

@ryoppippi
Copy link

ryoppippi commented Aug 13, 2024

Created a pr using picocolors

@ryoppippi
Copy link

ryoppippi commented Aug 13, 2024

@userquin I think yoctocolors is better because yoctocolors is tree-shakable while picocolors is not

@userquin
Copy link
Member Author

don't merge yet, I'm going to include yoctocolors and cleanup

@userquin
Copy link
Member Author

There is no difference using picocolors or yoctocolors (tgz file):

imagen
on left picocolors, on right yoctocolors

@ryoppippi
Copy link

@userquin Thanks

@userquin
Copy link
Member Author

userquin commented Aug 13, 2024

I'm going to use tinyrainbow, we're using it in Vitest

(Upps: 263 bytes bigger using tinyrainbow)

@userquin userquin requested review from benmccann and antfu and removed request for benmccann August 13, 2024 16:06
src/detect.ts Outdated
@@ -75,7 +43,12 @@ export async function detect({ autoInstall, programmatic, cwd }: DetectOptions =
process.exit(1)
}

await ezspawn(`npm i -g ${agent.split('@')[0]}${version ? `@${version}` : ''}`, { stdio: 'inherit', cwd })
await x(`npm i -g ${agent.split('@')[0]}${version ? `@${version}` : ''}`, undefined, {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use arguments here (second argument in x call)?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should. Same as how child process works

x('npm', ['i', '-g', ...])

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also keep in mind this can throw if somehow the command fails (like if npm doesn't exist)
Not sure how that was being dealt with before. Maybe it's fine as is and something catches it further up

src/runner.ts Outdated
const getCmd = (a: Agent) => agents.includes(a) ? getCommand(a, 'agent', ['-v']) : `${a} -v`
const getV = (a: string, o: EzSpawnOptions = {}) => ezspawn(getCmd(a as Agent), o).then(e => e.stdout).then(e => e.startsWith('v') ? e : `v${e}`)
const getCmd = (a: Agent) => AGENTS.includes(a) ? getCommand(a, 'agent', ['-v']) : `${a} -v`
const getV = (a: string, o: Partial<TinyExecOptions> = {}) => x(getCmd(a as Agent), undefined, o).then(e => e.stdout).then(e => e.startsWith('v') ? e : `v${e}`)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we include in getVarguments here (second argument in x call)?

@@ -140,5 +146,10 @@ export async function run(fn: Runner, args: string[], options: DetectOptions = {
return
}

await ezspawn(command, { stdio: 'inherit', cwd })
await x(command, undefined, {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use arguments here (second argument in x call)?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll default to an empty array under the hood if you pass undefined like this. So should be fine

Copy link
Member Author

@userquin userquin Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like tinyexec doesn't support command string mode, check #224

For example, check CI actions here https://github.com/unocss/unocss/actions/runs/10388099755/job/28762993666

Co-authored-by: Superchupu <53496941+SuperchupuDev@users.noreply.github.com>
@43081j
Copy link

43081j commented Aug 13, 2024

You should stick to picocolors imo and open issues upstream if you think there's a limitation

It has been adopted by most other large projects (and more to come). Think it is better to align than take yet another rehash of the same algorithm/implementation

pico is also the fastest

@antfu antfu merged commit cfc84ce into main Aug 14, 2024
2 checks passed
@antfu antfu deleted the chore-reduce-bundle-size branch August 14, 2024 12:55
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

Successfully merging this pull request may close these issues.

6 participants