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

feat: migrate to smaller exec package #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

43081j
Copy link

@43081j 43081j commented Aug 19, 2024

Migrates from execa to tinyexec, a much lighter alternative.

Also changes two of the async functions to use async/await instead of then chaining.

Migrates from `execa` to `tinyexec`, a much lighter alternative.

Also changes two of the async functions to use async/await instead of
then chaining.
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] environment, shell 0 42.6 kB 43081j

View full report↗︎

@benmccann
Copy link

I don't think that either execa or tinyexec are needed. Here's what we do in create-svelte:

/**
 * Supports npm, pnpm, Yarn, cnpm, bun and any other package manager that sets the
 * npm_config_user_agent env variable.
 * Thanks to https://github.com/zkochan/packages/tree/main/which-pm-runs for this code!
 */
function get_package_manager() {
    if (!process.env.npm_config_user_agent) {
        return undefined;
    }
    const user_agent = process.env.npm_config_user_agent;
    const pm_spec = user_agent.split(' ')[0];
    const separator_pos = pm_spec.lastIndexOf('/');
    const name = pm_spec.substring(0, separator_pos);
    return name === 'npminstall' ? 'cnpm' : name;
}

@43081j
Copy link
Author

43081j commented Aug 20, 2024

happy to change it to that if we can get agreement from @egoist

seems to make sense to me if they all set that var

export async function getNpmVersion(pm: PM) {
const res = await x(pm || "npm", ["--version"]);

return res.stdout;
Copy link

Choose a reason for hiding this comment

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

In case we settle on using tinyexec instead of the solution proposed by Ben, we should consider calling .trim() here, as I think execa trims the trailing whitespace by default (found this out when some tests in other projects broke when I changed from execa to tinyexec and didn't call .trim()).

Copy link
Author

Choose a reason for hiding this comment

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

Good catch! It's probably worth us opening an issue in the tinyexec repo to at least document this too (if you don't get chance, I'll open it)

Copy link

Choose a reason for hiding this comment

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

Opened tinylibs/tinyexec#36. 🙂

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.

3 participants