SvelteKit does not respect YARN_BINARY env var in build

I’ve noticed with the switch from Svelte to SvelteKit, that OFFLINE_BUILD=1 and YARN_BINARY=$(which yarn) will result in anki not building successfully.

Investigating a bit, I’ve noticed how in build/ninja_gen/src/node.rs, the function in question has ./yarn hardcoded in as opposed to reading in the env var if appropriate.

Currently it looks like this:

impl BuildAction for SveltekitBuild {
    fn command(&self) -> &str {
        if std::env::var("HMR").is_err() {
            if cfg!(windows) {
                "cmd /c yarn build"
            } else {
                "./yarn build"
            }
        } else {
            "echo"
        }
    }

    fn files(&mut self, build: &mut impl build::FilesHandle) {
        build.add_inputs("node_modules", inputs![":node_modules"]);
        build.add_inputs("", &self.deps);
        build.add_inputs("", inputs!["yarn.lock"]);
        build.add_output_stamp("sveltekit.marker");
        build.add_outputs_ext("folder", vec!["sveltekit"], true);
    }
}

hence, adjusting the function to

impl BuildAction for SveltekitBuild {
    fn command(&self) -> &str {
        if std::env::var("HMR").is_err() {
            if cfg!(windows) {
                "cmd /c yarn build"
            } else {
                "$yarn build"
            }
        } else {
            "echo"
        }
    }

    fn files(&mut self, build: &mut impl build::FilesHandle) {
        build.add_inputs("node_modules", inputs![":node_modules"]);
        build.add_inputs("yarn", inputs![":yarn:bin"]);
        build.add_inputs("", &self.deps);
        build.add_inputs("", inputs!["yarn.lock"]);
        build.add_output_stamp("sveltekit.marker");
        build.add_outputs_ext("folder", vec!["sveltekit"], true);
    }
}

Would fix this issue.

@dae let me know if I should/can raise a PR to fix this.

1 Like

PR has been merged in 24.06.1