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

Execute npm cli commands with SEA #115

Open
marwie opened this issue Jan 27, 2025 · 6 comments
Open

Execute npm cli commands with SEA #115

marwie opened this issue Jan 27, 2025 · 6 comments

Comments

@marwie
Copy link

marwie commented Jan 27, 2025

Hello,

I'm currently exploring possibilities for node SEA apps

Is it possible to access npm cli commands from my custom binary (or bundle the npm cli together with my sea app)

E.g. a user downloads the custom binary my_bin
then invokes my_bin setup . to setup a project in the current directory
which internally will call the equivalent to npm install

Alternatively I'd be curious to hear what the best solution would be for such a case without reinventing the wheel

@marwie marwie changed the title Execute npm install with SEA Execute npm cli commands with SEA Jan 27, 2025
@marwie
Copy link
Author

marwie commented Jan 27, 2025

I tried bundling my app with npm as a dependency and calling the npm commands programmatically but this results in error: The programmatic API was removed in npm v8.0.0

/**
 * @param {string} directory
 */
export async function install(directory){
    const npm = await import("npm");
    const promise = new Promise(res => npm.commands.install([directory], (err, result, result2, result3) => {
        res(err == null);
    }));
    const res = await promise;
}

@marwie
Copy link
Author

marwie commented Feb 10, 2025

Related to #100

@GabenGar
Copy link

Why do you need npm install on an executable in the first place?

@marwie
Copy link
Author

marwie commented Feb 11, 2025

The idea was to bundle custom code that already exists as a node cli package with the node runtime - one of the usecases for the cli we have is to manage/install/build npm packages so we need to run npm commands (or invoke the same functionality ideally in another way).

Alternatively we could probably ship nodejs next to the cli tool - but we want to avoid requiring additional dependencies from users and control the installed node version.

@cspotcode
Copy link

I've had success doing this with yarn: bundling yarn and calling it programmatically.

I bet other alternative package managers would work, too.

@marwie
Copy link
Author

marwie commented Feb 11, 2025

Interesting, thanks for the heads up! I will test that!

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

3 participants