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

Use for await in install function #1474

Merged
merged 1 commit into from
Nov 3, 2024
Merged

Conversation

origami-z
Copy link
Contributor

When using ncu within a script (top level function with "type": "module") with always install option, it doesn't actually run the install command after upgrading package.json

const upgraded = await ncu.run({
    upgrade: true,
    install: "always",
});
console.log("upgraded", upgraded); // { "mypackage": "^2.0.0", ... }
process.exit(0);

I debugged through node_modules/npm-check-updates/build/index.js, I can see the function within forEach (

const packageManager = await getPackageManagerForInstall(options, pkgFile)
) is getting called. So I suspect the whole install function is not properly getting awaited.

The part I don't quite understand is why running directly through npx works fine, maybe due to the cli scripts are wrapped in iife and vite bundled it in a smarter way?

MacOS, node - v20.13.1

When using ncu within a script (top level function with `"type": "module"`) with always install option, it doesn't actually run the install command after upgrading `package.json`

```
const upgraded = await ncu.run({
    upgrade: true,
    install: "always",
});
console.log("upgraded", upgraded); // { "mypackage": "^2.0.0", ... }
process.exit(0);
```

I debugged through `node_modules/npm-check-updates/build/index.js`, I can see the function within `forEach` (https://github.com/raineorshine/npm-check-updates/blob/b7c3106c9b1ba96608165f808dcd726ba76286bc/src/index.ts#L148) is getting called. So I suspect the whole `install` function is not properly getting awaited. 

The part I don't quite understand is why running directly through `npx` works fine, maybe due to the `cli` scripts are wrapped in iife and vite bundled it in a smarter way?


MacOS, node - v20.13.1
Copy link
Owner

@raineorshine raineorshine left a comment

Choose a reason for hiding this comment

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

Yes, interesting question. It certainly seems like they should all be awaited. Let's try it.

@raineorshine raineorshine merged commit f090a05 into raineorshine:main Nov 3, 2024
7 checks passed
@origami-z origami-z deleted the patch-1 branch November 3, 2024 09:51
@origami-z
Copy link
Contributor Author

Tried with v17.1.10, install works

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.

2 participants