Skip to content

devcheck.mjs: dev-condition detection misses execArgv, and installed-package guard misses scoped installs #270

Description

@Shinrai

While fixing the same machinery in @cldmv/holdmytask (PR #12, fix/devcheck-normal-module) and @cldmv/uuid (CLDMV/uuid#9), two bugs in slothlet's devcheck.mjs came up that apply here too. Slothlet's devcheck is deliberately more elaborate than the plain "normal module" version (it ships src/, deletes it in a later CI phase, distinguishes generic-development vs slothlet-dev, uses the !existsSync(distPath) guard), so this issue is scoped to only the parts that are genuinely wrong for slothlet — not a wholesale port of the holdmytask version.

Bugs

1. Dev-condition detection only checks NODE_OPTIONS, misses execArgv

const hasSlothletDev = nodeOptions.indexOf("--conditions=slothlet-dev") !== -1;

node --conditions=slothlet-dev file.mjs puts the flag in process.execArgv, not NODE_OPTIONS — and that's how vitest passes conditions to its workers too (a worker's NODE_OPTIONS is undefined while execArgv carries --conditions slothlet-dev). The CLI form and the vitest-worker form therefore aren't detected, so devcheck can spuriously fire (or a --conditions-on-CLI dev gets a false warning). Fold execArgv into the haystack:

const flags = (process.env.NODE_OPTIONS || "") + " " + process.execArgv.join(" ");
const hasSlothletDev = flags.includes("slothlet-dev");
const hasGenericDev = flags.includes("--conditions=development") || flags.includes("--conditions development");

2. Installed-package guard misses scoped installs

const parentFolder = path.basename(path.dirname(__dirname));
const isInstalledPackage = parentFolder === "node_modules";

slothlet installs as node_modules/@cldmv/slothlet, so path.dirname(__dirname) is the @cldmv scope dir and basename is @cldmv, not node_modules — the guard never trips for slothlet's own scoped package. It's partly masked by the !existsSync(distPath) guard for registry installs, but a git/tarball install (which ships src/ and no dist/) would slip through and process.exit(1) inside a consumer. Detect a node_modules segment anywhere above the file:

const isInstalledPackage = __dirname.split(path.sep).includes("node_modules");

3. (Optional) no devcheck tests

slothlet's devcheck has richer branching (the wrong-settings vs no-settings messages, the dist guard) and no tests. holdmytask PR #12 added a spawn-based tests/DevCheck.test.vitest.mjs that could be adapted to slothlet's branches if worth it.

Explicitly NOT in scope for slothlet

  • The NODE_ENV-coupling fix and the "condition-only trigger" from the holdmytask/uuid issues — slothlet's model differs (it intentionally accepts generic-dev to warn and redirect, and its resolution/CI-cleanup story isn't the plain normal-module one), so its trigger shape may be correct as-is. Only the execArgv detection (Release v2.0.0 - Major architectural rewrite with universal… #1) and scoped-install guard (chore(master): release 2.0.0 #2) are clear bugs here.
  • The !existsSync(distPath) guard — correct for slothlet (unlike a plain normal module, where nagging-after-build is intended).

Reference: holdmytask PR #12; CLDMV/uuid#9.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumShould be addressed in the normal course of developmentstatus: confirmedThe issue has been verified and reproduced by a maintainertype: bugSomething is broken or not behaving as expected

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions