Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

fix: apply chmod at pkg creation time #3800

Merged
merged 1 commit into from
Nov 21, 2022

Conversation

castarco
Copy link
Contributor

@castarco castarco commented Nov 19, 2022

Summary

  • Apply chmod at package creation time instead of doing it when running the postinstall hook.
  • I did not disabled postinstall hook entirely because it can give interesting information to users, I just removed the part where it applies chmod (because it's supposed to be done before, at package creation time).

Fixes #3799 .

Test Plan

Testing this change is not trivial because it impacts CD pipelines. My suggestion:

  1. make an alpha/beta/rc release, to avoid risking users' installations.
  2. Modify your local .npmrc file, by adding this line: ignore-scripts=true
  3. Install this alpha/beta/rc package version, and check that the installed binary has execution permissions, even when the postinstall hook has not been triggered because of our change on the .npmrc config file.

As a side note, it would be great if some of the steps that are being executed in the CD pipeline were extracted into scripts that we could run locally. This way it would be easier to test some of these details. I'm not doing that in this PR because I believe it deserves some prior discussion, and I don't want to mix too many things in a single PR.


Signed-off-by: Andres Correa Casablanca [email protected]

@netlify
Copy link

netlify bot commented Nov 19, 2022

Deploy Preview for docs-rometools canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit fc19e89
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/6379277abeda4e0009c1c671

apply chmod at package creation time instead of doing it when running
the postinstall hook.

Signed-off-by: Andres Correa Casablanca <[email protected]>
@castarco castarco marked this pull request as ready for review November 19, 2022 18:59
@castarco castarco requested a review from a team November 19, 2022 18:59
@@ -44,6 +44,7 @@ function generateNativePackage(platform, arch) {

console.log(`Copy binary ${binaryTarget}`);
fs.copyFileSync(binarySource, binaryTarget);
fs.chmodSync(binaryTarget, 0o755);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same way there is a try-catch block for the chmodSync call in the postinstall hook code, we could do the same here, because in theory it can fail the same way. However, that applies to every IO operation in this script (like copy), but that's not done here (I guess because it doesn't improve much on the potential error messages we could have, and because the pipeline would have crashed anyway).

Copy link
Contributor

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Nice. Didn't know that npm preserves execution permissions.

I wasn't able to find any documentation but this old issue confirms that it used to work (and should be fixed by now).

This may fix #3621

@@ -25,17 +25,6 @@ if (binName) {
`The Rome CLI postinstall script failed to resolve the binary file "${binName}". Running Rome from the npm package will probably not work correctly.`,
);
}

if (binPath) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to move the resolution failure messages to the rome start script instead and avoid using postinstall scripts altogether?

Copy link
Contributor

Choose a reason for hiding this comment

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

The rome script already implements one out of the two error messages in the postinstall hook, so we could bring them in sync. But I still think we should keep that script, the call to chmod was only added there as a hack but its original purpose was to check that Rome is installed correctly and immediately alert the user if an issue was found, instead of having to wait for them to run the rome command.

@@ -25,17 +25,6 @@ if (binName) {
`The Rome CLI postinstall script failed to resolve the binary file "${binName}". Running Rome from the npm package will probably not work correctly.`,
);
}

if (binPath) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The rome script already implements one out of the two error messages in the postinstall hook, so we could bring them in sync. But I still think we should keep that script, the call to chmod was only added there as a hack but its original purpose was to check that Rome is installed correctly and immediately alert the user if an issue was found, instead of having to wait for them to run the rome command.

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

Successfully merging this pull request may close these issues.

🐛 chmod should be performed at pkg creation time instead of with postinstall hook
3 participants