Skip to content

fix: reject a missing --name and never take a flag as a value - #94

Merged
Shinrai merged 4 commits into
nextfrom
fix/cli-arg-parsing
Nov 29, 2026
Merged

Shinrai merged 4 commits into
nextfrom
fix/cli-arg-parsing

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

No new features

🐛 Bug Fixes

📦 Dependencies

No dependency updates

🔧 Other Changes

👥 Contributors

Fails on current code: path <op> without --name edits a variable named after the op, and set NAME --scope x stores --scope. Refs #90
path <op> without --name edited a variable named after the op, and
set NAME --scope x stored "--scope". Parse flags and positional words
separately: a flag never consumes another flag, and a missing name, value,
values or backup id is an error that prints usage.

Resolves #90
@cldmv-bot cldmv-bot Bot added ! fix → next v4 flow: fix contributor PR targeting the next integration branch area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure labels Nov 29, 2026
Fails on current code: the CLI and the backends accept any scope, and the Windows backend treats an unknown one as system. Refs #95
The CLI and both backends accepted any scope: the POSIX backend returned
undefined, and the Windows backend treated an unknown one as system and wrote
HKLM. Validate against session, user and system before anything is read or
written, in the backends, backup.list and the CLI, and fail with the valid
values. A --scope with no value is an error instead of a silent session.

Resolves #95
@Shinrai
Shinrai merged commit 50455c0 into next Nov 29, 2026
33 checks passed
@cldmv-bot
cldmv-bot Bot deleted the fix/cli-arg-parsing branch November 29, 2026 06:32
cldmv-bot Bot added a commit that referenced this pull request Nov 30, 2026
# `@cldmv/envm` v1.2.0 Changelog

**Release Date**: November 2026
**Release Type**: Minor
**Branch**: `release/1.2.0`

---

## Overview

`require("@cldmv/envm")` now returns the `envManager` object itself, so `require(x).set(…)` works. It still carries `.envManager`, and gains `.default`, so every v1.1.0 call keeps working. The CommonJS entry is the generic CLDMV shim, and `dist/` is built one file per module instead of as tsup bundles, so the CLI no longer ships a second copy of the library.

This release also fixes three bugs. A typo'd or missing scope was accepted and silently did nothing, or wrote the system registry on Windows. The CLI could take a flag as a value or edit the wrong variable. And `backup.purge()` never deleted backups by age. Test coverage goes from about 33% to about 98%.

---

## ✨ Features

### `require()` returns `envManager` itself ([#87](#87), [#89](#89))

`src/index.cjs` is now the generic CLDMV CommonJS shim. After the Node.js version guard it loads `./index.mjs` through `require(esm)`. The ESM entry has one export, `envManager`, so the shim returns that object, with `.default` and `.envManager` both pointing back at it. v1.1.0's entry was `module.exports = require("./index.mjs")`, which returned the module namespace.

[#87](#87) switched to the shim when it still returned the bare object with no names, which would have broken `require(x).envManager` and `const { envManager } = require(x)`. [#89](#89) puts `.default` and the ESM name back on it before any release, so nothing that worked in v1.1.0 breaks. Measured against the built package:

| `require("@cldmv/envm")`            | v1.1.0           | v1.2.0                                      |
| ----------------------------------- | ---------------- | ------------------------------------------- |
| result                              | `{ envManager }` | the `envManager` object                     |
| `.envManager.set`                   | function         | function (`.envManager` is the same object) |
| `const { envManager } = require(x)` | works            | works                                       |
| `.set`                              | `undefined`      | function                                    |
| `.default`                          | `undefined`      | the same object                             |

ESM `import { envManager } from "@cldmv/envm"` is unchanged.

---

## 🐛 Bug Fixes

### An unknown or missing scope is refused ([#94](#94), fixes [#95](#95))

Scope must be `session`, `user` or `system`, but nothing checked it. On POSIX, `envManager.set("FOO", "bar", { scope: "usre" })` did nothing and reported nothing. On Windows, anything that wasn't `session` or `user` read and wrote `HKLM\SYSTEM\...\Environment`. The CLI ran with the bad scope, and `--scope` with no value became `session`. The new `src/scope.mjs` checks the scope in both platform backends, in backup listing and in the CLI before anything is read or written. A bad scope now throws `Invalid scope "bogus". Valid scopes: session, user, system`, and the CLI reports a `--scope` with no value as missing.

### The CLI no longer takes a flag as a value or edits the wrong variable ([#94](#94), fixes [#90](#90))

`envm set FOO --scope user` stored the literal value `--scope`, and `envm path append --values /q` without `--name` appended to a variable called `append`, leaving PATH alone. The CLI now parses its arguments properly. A value flag never takes another `--flag` as its value, and the positional name after `path` is read after the op. A missing name, value, `--values` or backup id fails with a usage message instead of running with `undefined`.

### `backup.purge()` deletes backups by age ([#93](#93), fixes [#91](#91))

The backup file timestamp was turned back into a date by replacing every dash with a colon, including those in the date part, so the result was always an Invalid Date and `maxAgeDays` never removed anything. Only the time part's dashes are converted now, so backups older than `maxAgeDays` are purged. The CLI's exit-time purge is fixed by the same change.

---

## 🔧 Build

### `dist/` is one file per module, no bundle ([#97](#97), fixes [#85](#85))

The two tsup bundles are replaced by `scripts/build.mjs`, which runs esbuild over every `src/**/*.mjs` file with `bundle: false` and the `node14` target. Each module is minified on its own with names kept and written to the same path under `dist/`. `dist/cli.mjs` imports the library from `dist/` instead of carrying its own copy, and `src/index.cjs` is still copied verbatim. The entry points and `exports` are unchanged.

---

## 🔧 CI & tooling

- Test coverage goes from about 33% to about 98%, with tests for the POSIX and Windows backends, backups, the PATH helpers and the CLI ([#92](#92), fixes [#3](#3)).
- `test:cjs` runs the CommonJS entry check, and the new `test:dist` runs the Vitest suite against the built `dist/` ([#76](#76)).
- The Vitest config sets the `envm-dev` condition with `devCondition()`, replacing a `test.nodeOptions` setting that Vitest ignored ([#74](#74)).
- `ci.yml` is synced with the CLDMV/.github v4.43.0 template ([#84](#84)), and superseded CI runs on `next` and `hotfixes` are cancelled ([#88](#88), fixes [#86](#86)).
- The `sync-release-notes` companion workflow keeps GitHub Release bodies and tags in step with these changelog files ([#82](#82)).
- File headers are restamped with fix-headers 2.6.1 and 2.6.2, which write `@Filename` without a leading slash ([#96](#96), [#98](#98)).

## 📚 Documentation

- **NEW:** [docs/changelog/v1/v1.2.0.md](https://github.com/CLDMV/envm/blob/v1.2.0/docs/changelog/v1/v1.2.0.md), this changelog.
- README: the CommonJS section shows `require()` returning `envManager` ([#87](#87), [#89](#89)), and What's New is promoted to v1.2.0.

## 🔧 Dependencies

Development dependencies only; envm still has no runtime dependencies.

- **CLDMV dev tools** ([#78](#78), [#96](#96), [#98](#98)): `@cldmv/vitest-runner` 1.5.6 → 1.11.5, `@cldmv/configs` 1.3.0 → 1.5.1 and `@cldmv/fix-headers` 2.2.4 → 2.6.2, with `@cldmv/jsonv` and `@cldmv/prettier-plugin-jsonv` → 1.2.4.
- `vitest` and `@vitest/coverage-v8` 5.0.5 → 5.1.2 ([#77](#77), [#96](#96)).
- `esbuild` added and `tsup` removed ([#97](#97)).

---

## Upgrade notes

- No breaking changes. Drop-in for v1.1.0: `require(x).envManager`, `const { envManager } = require(x)` and ESM `import` work as before, and `require(x).set(…)` and `require(x).default` are new.
- A scope other than `session`, `user` or `system` now throws instead of silently doing nothing, or writing system scope on Windows. Check any computed scope values.
- `envm set NAME --scope …` with no value now fails with a usage message instead of storing `--scope`.



<details>
<summary>👥 Contributors</summary>

- @Shinrai

</details>

---

<!-- coverage-start -->

![coverage](https://img.shields.io/badge/coverage-97.9%25-brightgreen?style=for-the-badge&logo=vitest&logoColor=white)

| Metric | Coverage |
|--------|----------|
| Statements | 99.2% |
| Branches   | 95.0% |
| Functions  | 98.6% |
| Lines      | 99.1% |

*Avg: **97.9%** · `4f52d80` · Node lts/**

<!-- coverage-end -->

<!-- co-authors -->

Co-authored-by: Shinrai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure ! fix → next v4 flow: fix contributor PR targeting the next integration branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant