Skip to content

Conversation

@mstoykov
Copy link
Contributor

What?

Add a deps command.

This does include dependancies that might be needed for building a new binary with auto extension resolution, but also all imports.

Similar to auto extension resolution, this does take into account only imports not require calls.

Why?

This is useful to figure out if a given test will need to build custom binaries as well as look into dependancies in general.

Checklist

  • I have performed a self-review of my code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests for my changes.
  • I have run linter and tests locally (make check) and all pass.

Checklist: Documentation (only for k6 maintainers and if relevant)

Please do not merge this PR until the following items are filled out.

  • I have added the correct milestone and labels to the PR.
  • I have updated the release notes: link
  • I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
  • I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable

Related PR(s)/Issue(s)

Closes #5166

This does include dependancies that might be needed for building a new
binary with auto extension resolution, but also all imports.

Similar to auto extension resolution, this does take into account only
imports not `require` calls.

Closes #5166
@mstoykov mstoykov added this to the v1.5.0 milestone Nov 13, 2025
@mstoykov mstoykov requested a review from a team as a code owner November 13, 2025 10:01
@mstoykov mstoykov requested review from ankur22, inancgumus and pablochacin and removed request for a team November 13, 2025 10:01
@mstoykov mstoykov temporarily deployed to azure-trusted-signing November 13, 2025 10:07 — with GitHub Actions Inactive
@mstoykov mstoykov temporarily deployed to azure-trusted-signing November 13, 2025 10:09 — with GitHub Actions Inactive
@pablochacin
Copy link
Contributor

I feel the command is exposing too much of the internals that may result more confusing than useful.

For example this command returns the following output from the script below (don't mind if it makes sense to import here, it is to illustrate a point)

I'm not sure how useful the imports section is. And brings some questions: what's the difference between dependencies and imports?

{
 {
  "dependencies": {
    "k6/x/faker": "*"
  },
  "imports": [
    "file:///home/pablo/go/src/github.com/grafana/k6/faker.js",
    "k6",
    "k6/execution",
    "k6/x/faker"
  ],
  "customBuildRequired": true
}

faker.js

import faker from "k6/x/faker";
import exec from 'k6/execution';
import check from 'k6';

export default function () {
  console.log(faker.person.name());
}

@mstoykov
Copy link
Contributor Author

I've renamed dependancies to buildDependancies as that is what they are. The naming might need to change more, I guess.

But I do prefer to have a way to extract more info like what is imported and this seems to be the correct command for this. We could remove the imports key for now and reintroduce it later when we find a use for it, but I would still prefer to have the structure as is, so we can make that change without breaking it.

@mstoykov mstoykov temporarily deployed to azure-trusted-signing November 18, 2025 10:12 — with GitHub Actions Inactive
@mstoykov mstoykov temporarily deployed to azure-trusted-signing November 18, 2025 10:14 — with GitHub Actions Inactive
@pablochacin pablochacin requested a review from szkiba November 18, 2025 11:02
ankur22
ankur22 previously approved these changes Nov 18, 2025
Copy link
Contributor

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀 I tested it with a few test scripts and seems to work as expected.

RunE: func(cmd *cobra.Command, args []string) error {
test, err := loadLocalTestWithoutRunner(gs, cmd, args)
if err != nil {
var unsatisfiedErr binaryIsNotSatisfyingDependenciesError
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the expected behaviour when the error is a binaryIsNotSatisfyingDependenciesError? Looks like we're just ignoring it. Maybe we should log a debug log if we can ignore it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here the idea is that if this is the error - this means to run this we need a new binary with som extesnions.

But as we only care about the dependancies and that is already what we've got, here we just check that if this isn't the error, as in that case we need to return it.

@pablochacin
Copy link
Contributor

@mstoykov I see your point. If we are keeping this structure, could we revert the naming back to dependencies, this way it will be consistent with the name in the manifest that we are introducing in #4729 🙏

pablochacin
pablochacin previously approved these changes Nov 19, 2025
Copy link
Contributor

@pablochacin pablochacin left a comment

Choose a reason for hiding this comment

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

LGTM. I would prefer Dependencies instead of BuildDependencies, as mentioned in another comment. But this is not blocking.

@mstoykov mstoykov dismissed stale reviews from pablochacin and ankur22 via 2de24c6 November 20, 2025 14:23
@mstoykov mstoykov temporarily deployed to azure-trusted-signing November 20, 2025 14:29 — with GitHub Actions Inactive
@mstoykov mstoykov temporarily deployed to azure-trusted-signing November 20, 2025 14:31 — with GitHub Actions Inactive
@mstoykov
Copy link
Contributor Author

I am not aganst it being dependancies but I feel like this is a bit better, I guess lets see what the other reviewers think about it.

Copy link
Contributor

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

LGTM, but I think it should be dependencies instead of dependancies.

pablochacin
pablochacin previously approved these changes Nov 20, 2025
@mstoykov mstoykov changed the title Add deps command to return dependancies of a given script/archive Add deps command to return dependencies of a given script/archive Nov 20, 2025
@codebien
Copy link
Contributor

@mstoykov the CI is failing with errors relavant for this pull request

@mstoykov mstoykov temporarily deployed to azure-trusted-signing November 21, 2025 16:27 — with GitHub Actions Inactive
@mstoykov mstoykov temporarily deployed to azure-trusted-signing November 21, 2025 16:29 — with GitHub Actions Inactive
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.

Implement dependency analysis sub command

5 participants