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

Move tar outside of dependencies #338

Merged
merged 17 commits into from
Jul 21, 2022
Merged

Conversation

TwistedTwigleg
Copy link
Contributor

@TwistedTwigleg TwistedTwigleg commented Jul 13, 2022

Description of changes:

Mirror of #335 but merged with latest changes in main and the package lock regenerated with npm.

Moves cmake-js and tar outside of dependencies and modifies the build script to download tar and cmake-js, use it, and store it in a sub-folder for reuse that is completely separate from the main node modules. This prevents cmake-js and tar from sticking around when it is only needed for building the source and not in the functionality of the CRT itself (and in the case of tar, it is needed only for a single download once to get the source).

With this change, cmake-js and tar is not sticking around in the node dependencies forever when it is only needed for build-time operations.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@TwistedTwigleg
Copy link
Contributor Author

TwistedTwigleg commented Jul 13, 2022

Wait on merging even if CI is successful for now - need to double check things.

@TwistedTwigleg TwistedTwigleg added the pr/do-not-merge This PR should not be merged at this time. label Jul 13, 2022
…installed and only if we need them to make a build. This makes them a pseudo dependency, but it should not download for those that either have cmake-js already in their node_modules or do not need to install from source
@lgtm-com

This comment was marked as outdated.

@TwistedTwigleg TwistedTwigleg removed the pr/do-not-merge This PR should not be merged at this time. label Jul 15, 2022
@TwistedTwigleg TwistedTwigleg changed the title Move tar cmake outside (mirror) Move tar outside of dependencies Jul 15, 2022
Copy link
Contributor

@xiazhvera xiazhvera left a comment

Choose a reason for hiding this comment

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

Seems good to me! Probably need improve the error check if necessary.

scripts/build.js Outdated
console.log("Downloading " + package_name + " from npm for build...");
// Try to intall the given package and ONLY the given package. Will throw an exception if there is an error.
if (package_version != null) {
child_process.execSync("npm install --no-package-lock --save-dev --ignore-scripts " + package_name + "@" + package_version);
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems really sketchy

I realize the whole premise of downloading code and compiling it as part of the install process is already a tough pill to swallow, but is it going to far to install additional NPM dependencies that aren't declared in package.json?

Let's talk with someone that has deeper familiarity with what is considered acceptable in Javascript-Land

But if this is acceptable, we could do it with cmake-js as well 🤷‍♀️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will leave it for now until and see if I can get more feedback to make sure the change is okay with those experienced in Javascript 👍

Copy link

Choose a reason for hiding this comment

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

For good or bad, this doesn't faze me as a JS developer.

I suggest doing this in a subfolder workspace such as your_package_location/scripts/.
You can leave a dummy package.json with private:true which will allow temporary modules to be installed there if they are not part of the user's workspace.

That way, the workflow could look like this:

  • user runs npm install aws-crt
  • the aws-crt package is downloaded to their node_modules (root)
    • aws-crt postinstall tries to use the root cmake-js et. al. runtime packages
    • if not present or of the wrong version, download them into a subfolder of aws-crt so as not to affect the user's root workspace node_modules / package.json / package-lock.json etc.
    • if not able to download, let the user know they will need to install certain dev dependencies and re-run the aws-crt install script.

This would avoid bringing non-runtime packages into both the user's development workspace (root node_modules) as well as the user's potential runtime distribution (package.json->dependencies).

scripts/build.js Outdated

// Do we have it in node modules? If so, then use that!
try {
if (fs.existsSync("./node_modules/" + package_name)) {
Copy link

Choose a reason for hiding this comment

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

you can use require.resolve if you want to check for a module and aren't specifically looking in the immediate node_modules directory.

@lgtm-com

This comment was marked as outdated.

@lgtm-com

This comment was marked as outdated.


axios: null,
clean_up_axios: false,
axios_version: "0.24.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not a fan of this hard-coded version...

  • We cannot tell if any CVE or something happens to that package at that version unless manually checking the code, which could be a concern
  • If the lib was existed, and it's not this version, we will not know.

But, I cannot think of a better way😞.
Does any other nodejs lib using the similar approach to fetch dependency dynamically? How do they deal with the version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, I would need to look around and see.

We could put it in our dev dependencies and then pull it out of the package.json that way. Then it would get automatically code scanned by Dependabot.

Though the dependencies here are completely isolated from the rest of the node modules by being in the node_modules folder of the scripts/build_dependencies folder. So even if there was a vulnerability, it would only be for building the source and not the output or anything a customer/consumer of the CRT would see.
Not saying it is something we shouldn't fix, but the security impact is minimal because it just gets downloaded and used only for a build.

Copy link
Contributor

@TingDaoK TingDaoK Jul 20, 2022

Choose a reason for hiding this comment

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

I am not totally against it. I think we need to do more research, or how do JS experts think about this? If they think it's okay, just ignore me by all means.🫣

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did some looking, and it looks like the general consensus is "don't do it" based on other Javascript packages and such. I got around this by putting it in the devDependencies and then loading the package.json and getting the version number from there. Now we have the advantage of getting Dependabot code scanning, can easily change the version in a single place, and it is more in line with what I have seen in other Javascript packages/modules.


axios: null,
clean_up_axios: false,
axios_version: "0.24.0",
Copy link
Contributor

@TingDaoK TingDaoK Jul 20, 2022

Choose a reason for hiding this comment

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

I am not totally against it. I think we need to do more research, or how do JS experts think about this? If they think it's okay, just ignore me by all means.🫣

…from there, actually fix tar and that whole download path for good
@TwistedTwigleg
Copy link
Contributor Author

Thanks for the reviews everyone! Merging into main...

@TwistedTwigleg TwistedTwigleg merged commit 001193e into main Jul 21, 2022
@TwistedTwigleg TwistedTwigleg deleted the move-tar-cmake-outside branch July 21, 2022 18:07
@TingDaoK TingDaoK mentioned this pull request Aug 1, 2023
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