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

fix:GH-1502 name root from package json #1503

Merged

Conversation

ivanasabi
Copy link
Contributor

@ivanasabi ivanasabi commented Dec 18, 2024

Closes #1502

@ivanasabi ivanasabi requested a review from prabhu as a code owner December 18, 2024 20:58
@ivanasabi ivanasabi force-pushed the bugfix/GH-1502-name-root-from-package-json branch from d9ca0f7 to 88aeb33 Compare December 18, 2024 21:02
ppurl = new PackageURL(
"npm",
options.projectGroup || tmpParentComponent.group,
"project-name" in options ? options.projectName : tmpParentComponent.name,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows the use of the --project-name property

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does options.projectName || tmpParentComponent.name work?

Copy link
Contributor Author

@ivanasabi ivanasabi Dec 23, 2024

Choose a reason for hiding this comment

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

No, your solution doesn’t work. options.projectName is always set to the folder name.
The only way I can check if --project-name was provided is by verifying whether project-name is contained in the options.
When --project-name is not provided, project-name doesn’t appear as an option.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting observation! Will make a note of this. Thank you!

@ivanasabi
Copy link
Contributor Author

ivanasabi commented Dec 18, 2024

These are the evidences of code modification:

Before code modification
before-modification.json

package.json

{
  "name": "skippr",
  "version": "1.2.0",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-concat": "^0.5.0",
    "grunt-contrib-cssmin": "^0.10.0",
    "grunt-contrib-sass": "^0.7.3",
    "grunt-contrib-uglify": "^0.5.1",
    "grunt-contrib-watch": "^0.6.1"
  }
}

bom.json

    "component": {
      "group": "",
      "name": "skippr-folder",
      "version": "1.2.0",
      "type": "application",
      "purl": "pkg:npm/[email protected]",
      "bom-ref": "pkg:npm/[email protected]"
    }

After code modification (without --project-name param)
after-modification-code-without-param.json

package.json

{
  "name": "skippr",
  "version": "1.2.0",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-concat": "^0.5.0",
    "grunt-contrib-cssmin": "^0.10.0",
    "grunt-contrib-sass": "^0.7.3",
    "grunt-contrib-uglify": "^0.5.1",
    "grunt-contrib-watch": "^0.6.1"
  }
}

bom.json

    "component": {
      "name": "skippr",
      "group": "",
      "version": "1.2.0",
      "purl": "pkg:npm/[email protected]",
      "bom-ref": "pkg:npm/[email protected]",
      "type": "application"
    }

After code modification (with --project-name param)
-t js -o after-modification-code-without-param.json --project-name custom-name-test
after-modification-code-with-param.json

package.json

{
  "name": "skippr",
  "version": "1.2.0",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-concat": "^0.5.0",
    "grunt-contrib-cssmin": "^0.10.0",
    "grunt-contrib-sass": "^0.7.3",
    "grunt-contrib-uglify": "^0.5.1",
    "grunt-contrib-watch": "^0.6.1"
  }
}

bom.json

    "component": {
      "name": "custom-name-test",
      "group": "",
      "version": "1.2.0",
      "purl": "pkg:npm/[email protected]",
      "bom-ref": "pkg:npm/[email protected]",
      "type": "application"
    }

@prabhu
Copy link
Collaborator

prabhu commented Dec 20, 2024

I think we might need another fix to use the information from package.json if --project-name were not passed?

@ivanasabi
Copy link
Contributor Author

ivanasabi commented Dec 21, 2024

I think we might need another fix to use the information from package.json if --project-name were not passed?

Yes, if I understand you correctly, I cover the case where --project-name is not provided. You can see this in the example.

After code modification (without --project-name param)

after-modification-code-without-param.json

package.json

{

  "name": "skippr",

  "version": "1.2.0",

  "devDependencies": {

    "grunt": "~0.4.1",

    "grunt-contrib-concat": "^0.5.0",

    "grunt-contrib-cssmin": "^0.10.0",

    "grunt-contrib-sass": "^0.7.3",

    "grunt-contrib-uglify": "^0.5.1",

    "grunt-contrib-watch": "^0.6.1"

  }

}

bom.json

    "component": {

      "name": "skippr",

      "group": "",

      "version": "1.2.0",

      "purl": "pkg:npm/[email protected]",

      "bom-ref": "pkg:npm/[email protected]",

      "type": "application"

    }

Am I wrong? Can you give me more information about your concern?

@prabhu
Copy link
Collaborator

prabhu commented Dec 22, 2024

Looks good now. Must have seen a smaller diff. Can you look into this comment?

https://github.com/CycloneDX/cdxgen/pull/1503/files#r1894034307

@ivanasabi
Copy link
Contributor Author

Looks good now. Must have seen a smaller diff. Can you look into this comment?

https://github.com/CycloneDX/cdxgen/pull/1503/files#r1894034307

Yes, I have responded to your question.

Copy link
Collaborator

@prabhu prabhu left a comment

Choose a reason for hiding this comment

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

Thank you!

@prabhu prabhu merged commit 50a2d4f into CycloneDX:master Dec 23, 2024
3 checks passed
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.

[npm] cdxgen does not extract name from package.json
2 participants