Skip to content

Stop preloading require calls and using them to do Auto Extension Resoluton #5325

@mstoykov

Description

@mstoykov

Current status

After the current auto extension resolution was added, the mechanism doing it will look at the code and try to find what modules will be imported. And then use that to check if the script will break, due to missing extensions and instead get a binary with those.

One the things it does though is to look at the code and load require calls as well, where that is possible.

But require calls are dynamic, there is no gurauntee that the code will be hit or not, and if it will load the module at all during running.

As part of moving from esbuild implementaiton to one just using the internal k6 resolution, this needs to be copied over as in #5319 .

This likely has quite a lot of quarks that just fairly few people have hit for now, and also likely fairly few people use require and extensions.

Proposal

Drop this in k6 v2. Still have usage data on this before that.
Potentially have an option to disable this even before we remove it in case a user needs to disable it.

Examples:

main.js

require("k6/x/something");

class S {
        l() {
                require("./another.js");
                require("k6/x/another");
        }
}


if (true){
        let s = new S()
}
export const l = 2;

another.js:

import "k6/x/faker"

running with k6 v1.3.0 will give you:

INFO[0000] Automatic extension resolution is enabled. The current k6 binary doesn't satisfy all dependencies, it's required to provision a custom binary.  deps="k6/x/another*;k6/x/faker*;k6/x/something*"
ERRO[0001] Failed to provision a k6 binary with required dependencies. Please, make sure to report this issue by opening a bug report.  error="invalid build parameters: unknown dependency : k6/x/another"
ERRO[0001] invalid build parameters: unknown dependency : k6/x/another

with #5319

INFO[0000] Automatic extension resolution is enabled. The current k6 binary doesn't satisfy all dependencies, it's required to provision a custom binary.  deps="map[k6:* k6/x/another:<nil> k6/x/faker:<nil> k6/x/something:<nil>]"
ERRO[0001] Failed to provision a k6 binary with required dependencies. Please, make sure to report this issue by opening a bug report.  error="invalid build parameters: unknown dependency : k6/x/something"
ERRO[0001] invalid build parameters: unknown dependency : k6/x/something

But as you can see from this code - the calls will never be done to load another.js or any of the extensions apart from k6/x/something

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changefor PRs that need to be mentioned in the breaking changes section of the release notesevaluation neededproposal needs to be validated or tested before fully implementing it in k6

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions