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

feat: add support for targetting specific workspaces #1212

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MalickBurger
Copy link

@MalickBurger MalickBurger commented Aug 23, 2024

fixes #1126

@MalickBurger MalickBurger requested a review from a team as a code owner August 23, 2024 11:58
@MalickBurger MalickBurger force-pushed the feat/workspace-support branch from 4ac8c52 to a26d8da Compare August 23, 2024 12:16
Copy link
Member

@jkowalleck jkowalleck left a comment

Choose a reason for hiding this comment

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

some things require chen. see my remarks.

also, please add proper unit tests

CONTRIBUTING.md Outdated Show resolved Hide resolved
@@ -166,6 +167,12 @@ function makeCommand (process: NodeJS.Process): Command {
).default(
Enums.ComponentType.Application
)
).addOption(
new Option(
Copy link
Member

@jkowalleck jkowalleck Aug 25, 2024

Choose a reason for hiding this comment

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

for the things we pass truth to npm, it is intended to mimic the CLI of npm - so that the CLI args are familiar to the users.

the proposed option workspaces here does not do so.

compare with npm ls:

List installed packages

Usage:
npm ls <package-spec>

Options:
[-a|--all] [--json] [-l|--long] [-p|--parseable] [-g|--global] [--depth <depth>]
[--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]] [--link]
[--package-lock-only] [--no-unicode]
[-w|--workspace <workspace-name> [-w|--workspace <workspace-name> ...]]
[-ws|--workspaces] [--include-workspace-root] [--install-links]

alias: list

Run "npm help ls" for more info

src/builders.ts Show resolved Hide resolved
@MalickBurger
Copy link
Author

some things require chen. see my remarks.

also, please add proper unit tests

Happy to do the changes. I would think some integration tests would be required for this change as it is not really feasible to test it in isolation due to the logic effectively sitting on the npm ls side.

I agree with the requirement of testing. I spent some time initially before making the PR going through the existing unit and integration tests and it is not very clear to me how we should go about adding tests for new functionality. For example, I do not see tests for several of the CLI options (such as --short-PURLs).

Could you provide a bit of a guide regarding how we should lay out tests for new functionality going forward as well as a brief of how the existing integration tests work and how they are structured. I intend on making additional PRs in the future for other issues and features so this would be very beneficial for me (and I'm sure other community members).

@jkowalleck
Copy link
Member

jkowalleck commented Aug 26, 2024

@MalickBurger, for adding additional integration tests,

  1. you would add new setups here, if needed: https://github.com/CycloneDX/cyclonedx-node-npm/tree/main/demo
  2. Then, add the appropriate npm ls ... run here: https://github.com/CycloneDX/cyclonedx-node-npm/blob/main/.github/workflows/npm-ls_demo-results.yml
  3. have the npm ls ... result data gathered via a CI (Github action/workflow).
    you can dispatch the action in your repo here: https://github.com/MalickBurger/cyclonedx-node-npm/actions by dispatching the workflow (you might need to enable workflows for your repo)
  4. download the action artifacts and add them here: https://github.com/CycloneDX/cyclonedx-node-npm/tree/main/tests/_data/npm-ls_demo-results
  5. remove unnecessary data via https://github.com/CycloneDX/cyclonedx-node-npm/tree/main/tests/_data/npm-ls_demo-results/_duplicates-cleaner (might require a back-merge or rebase to pull the scripts in)

since you are planning on adding conditional parameters in the npm ls call, you need to incorporate this in the existing testing processes somehow.

jkowalleck added a commit that referenced this pull request Sep 4, 2024
caused by #1212

---------

Signed-off-by: Jan Kowalleck <[email protected]>
@MalickBurger
Copy link
Author

@MalickBurger, for adding additional integration tests,

  1. you would add new setups here, if needed: https://github.com/CycloneDX/cyclonedx-node-npm/tree/main/demo
  2. Then, add the appropriate npm ls ... run here: https://github.com/CycloneDX/cyclonedx-node-npm/blob/main/.github/workflows/npm-ls_demo-results.yml
  3. have the npm ls ... result data gathered via a CI (Github action/workflow).
    you can dispatch the action in your repo here: https://github.com/MalickBurger/cyclonedx-node-npm/actions by dispatching the workflow (you might need to enable workflows for your repo)
  4. download the action artifacts and add them here: https://github.com/CycloneDX/cyclonedx-node-npm/tree/main/tests/_data/npm-ls_demo-results
  5. remove unnecessary data via https://github.com/CycloneDX/cyclonedx-node-npm/tree/main/tests/_data/npm-ls_demo-results/_duplicates-cleaner (might require a back-merge or rebase to pull the scripts in)

since you are planning on adding conditional parameters in the npm ls call, you need to incorporate this in the existing testing processes somehow.

Looking at this, could you provide some testing support for an existing argument that is passed to npm ls by the plugin which I could then base my additional tests on? It would be easier and cleaner for a code maintainer to set these up so there is a standard to follow going forward for community members.

@jkowalleck
Copy link
Member

@MalickBurger, for adding additional integration tests,

  1. you would add new setups here, if needed: https://github.com/CycloneDX/cyclonedx-node-npm/tree/main/demo
  2. Then, add the appropriate npm ls ... run here: https://github.com/CycloneDX/cyclonedx-node-npm/blob/main/.github/workflows/npm-ls_demo-results.yml
  3. have the npm ls ... result data gathered via a CI (Github action/workflow).
    you can dispatch the action in your repo here: https://github.com/MalickBurger/cyclonedx-node-npm/actions by dispatching the workflow (you might need to enable workflows for your repo)
  4. download the action artifacts and add them here: https://github.com/CycloneDX/cyclonedx-node-npm/tree/main/tests/_data/npm-ls_demo-results
  5. remove unnecessary data via https://github.com/CycloneDX/cyclonedx-node-npm/tree/main/tests/_data/npm-ls_demo-results/_duplicates-cleaner (might require a back-merge or rebase to pull the scripts in)

since you are planning on adding conditional parameters in the npm ls call, you need to incorporate this in the existing testing processes somehow.

Looking at this, could you provide some testing support for an existing argument that is passed to npm ls by the plugin which I could then base my additional tests on? It would be easier and cleaner for a code maintainer to set these up so there is a standard to follow going forward for community members.

will do. just bare with me, it may take a while

@jkowalleck
Copy link
Member

will do. just bare with me, it may take a while

I am currently working on a solution. Will ping as soon as I have something for you.

src/cli.ts Outdated Show resolved Hide resolved
@jkowalleck
Copy link
Member

jkowalleck commented Oct 31, 2024

@MalickBurger ,

I've overhauled the integration tests.
It would currently be enough to add your tests, showcasing that the intended parameters are sent to npm-ls. This could be done here: https://github.com/CycloneDX/cyclonedx-node-npm/blob/main/tests/integration/cli.args-pass-through.test.js

you might add something like

// region workspace
['workspace not supported npm 6', `6.${rMinor}.${rPatch}`, ['--workspace my-wsA', '--workspace my-wsB'], [...npm6ArgsGeneral]],
['workspace npm 7', `7.${rMinor}.${rPatch}`, ['--workspace my-wsA', '--workspace my-wsB'], [...npm7ArgsGeneral, '--workspace my-wsA', '--workspace my-wsB']],
['workspace npm 8', `8.${rMinor}.${rPatch}`, ['--workspace my-wsA', '--workspace my-wsB'], [...npm8ArgsGeneral, '--workspace my-wsA', '--workspace my-wsB']],
['workspace npm 9', `9.${rMinor}.${rPatch}`, ['--workspace my-wsA', '--workspace my-wsB'], [...npm9ArgsGeneral, '--workspace my-wsA', '--workspace my-wsB']],
['workspace npm 10', `10.${rMinor}.${rPatch}`, ['--workspace my-wsA', '--workspace my-wsB'], [...npm10ArgsGeneral, '--workspace my-wsA', '--workspace my-wsB']]
// endregion workspace

PS: i've also prepared demo data for additional integration tests. I might add them as soon as the basic pass-through tests are done

@MalickBurger MalickBurger force-pushed the feat/workspace-support branch from d95dee9 to 052b2a6 Compare November 4, 2024 10:45
@MalickBurger MalickBurger force-pushed the feat/workspace-support branch from 052b2a6 to e7c1f1d Compare December 11, 2024 14:16
@jkowalleck
Copy link
Member

@MalickBurger , i see you've rebased this feature branch recently.
Are planning on integrating the needed tests as described here ?

@MalickBurger
Copy link
Author

@MalickBurger , i see you've rebased this feature branch recently. Are planning on integrating the needed tests as described here ?

Hi @jkowalleck, yes I have been busy recently but am getting back to this now. Will be posting updates soon.

@jkowalleck jkowalleck self-requested a review December 11, 2024 14:55
@jkowalleck jkowalleck added the enhancement New feature or request label Dec 11, 2024
@MalickBurger MalickBurger force-pushed the feat/workspace-support branch from e7c1f1d to a5ff5bc Compare December 12, 2024 13:00
).default([], 'empty')
).addOption(
new Option(
'-no-ws, --no-workspaces',
Copy link
Member

Choose a reason for hiding this comment

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

why is this needed?
which version of npm ls knowns this?

)
).addOption(
new Option(
'-wr, --include-workspace-root',
Copy link
Member

Choose a reason for hiding this comment

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

where does the -wr come from?

it is intended to use similar args like nom ls does, so adoption is easy.
which version of npm knows -wr here?

// endregion workspace
// region include-workspace-root
['workspace root not supported npm 6', `6.${rMinor}.${rPatch}`, ['-w', 'my-wsA', '--include-workspace-root'], [...npm6ArgsGeneral]],
['workspace root npm 7', `7.${rMinor}.${rPatch}`, ['--workspace', 'my-wsA', '-w', 'my-wsB', '--include-workspace-root'], [...npm7ArgsGeneral, '--workspace=my-wsA', '--workspace=my-wsB', '--include-workspace-root=true']],
Copy link
Member

Choose a reason for hiding this comment

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

workspace root not supported npm 7

@@ -52,6 +52,9 @@ interface CommandOptions {
outputFile: string
validate: boolean | undefined
mcType: Enums.ComponentType
workspace: string[]
Copy link
Member

Choose a reason for hiding this comment

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

please move the worksapce-related options up so they appear right below the omit

@@ -173,6 +176,22 @@ function makeCommand (process: NodeJS.Process): Command {
).default(
Enums.ComponentType.Application
)
).addOption(
Copy link
Member

Choose a reason for hiding this comment

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

please move the worksapce-related options up so they appear right below the omit

@jkowalleck
Copy link
Member

merged in the latest master, fixed some merge conflicts.
did another round of review. result: there are open questions and issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] support workspaces
2 participants