Skip to content

Commit 06da48b

Browse files
justin808claude
andauthored
Decouple dump warning flags for env-label fallback (#25)
* Decouple dump warning suppression flags * Add combined-flag test and clarify --no-warn-env-label scope - Add test verifying --no-warn-sensitive and --no-warn-env-label work independently when used together - Clarify in help text that --no-warn-env-label only applies in build-matrix mode and is ignored for single-file dumps Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ddee4d4 commit 06da48b

5 files changed

Lines changed: 106 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Release and review helpers:
1212

1313
## [Unreleased]
1414

15+
### Changed
16+
17+
- Decoupled dump warning controls: `--no-warn-sensitive` now only suppresses sensitive-output warnings, and new `--no-warn-env-label` suppresses build-matrix `NODE_ENV` environment-label notes. [Issue #23](https://github.com/shakacode/pack-config-diff/issues/23)
18+
1519
## [v1.0.0] - 2026-03-15
1620

1721
### Added

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pack-config-diff dump webpack.config.js --format=yaml --mode=development --outpu
9393

9494
> Security note: `dump` output without `--clean` may include sensitive plugin/env values. Use `--clean` when sharing snapshots.
9595
> For trusted internal automation, add `--no-warn-sensitive` to suppress the warning.
96+
> For build-matrix dumps, add `--no-warn-env-label` to suppress only the `NODE_ENV` fallback environment-label note.
9697
9798
### More examples
9899

@@ -133,6 +134,9 @@ pack-config-diff dump --build=prod --config-file=config/pack-config-diff-builds.
133134

134135
# Dump every build in the matrix
135136
pack-config-diff dump --all-builds --config-file=config/pack-config-diff-builds.yml
137+
138+
# Keep sensitive warning but suppress build NODE_ENV label note
139+
pack-config-diff dump --build=dev --config-file=config/pack-config-diff-builds.yml --no-warn-env-label
136140
```
137141

138142
## What can `--left` and `--right` be?

docs/cli-reference.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ Security note: dump output without `--clean` can include sensitive values from p
188188
### `--no-warn-sensitive`
189189

190190
Suppress the warning shown when running `dump` without `--clean`. Useful for trusted internal automation where warning noise is undesirable.
191+
This does not affect build-matrix environment-label notes.
192+
193+
### `--no-warn-env-label`
194+
195+
Suppress the build-matrix note shown when metadata `environment` falls back to `build.environment.NODE_ENV`.
196+
This does not suppress the sensitive-output warning from `dump` without `--clean`.
191197

192198
## Build matrix options (`dump`)
193199

src/cli.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ interface ParsedDumpArgs {
4545
env: string[];
4646
clean: boolean;
4747
warnSensitive: boolean;
48+
warnEnvLabel: boolean;
4849
build?: string;
4950
allBuilds: boolean;
5051
listBuilds: boolean;
@@ -111,6 +112,7 @@ Dump Options:
111112
--env=<KEY=VALUE> Set env var before loading config (repeatable)
112113
--clean Strip plugin internals and compact functions before dump (recommended for secrets safety)
113114
--no-warn-sensitive Suppress the sensitive-output warning when running dump without --clean
115+
--no-warn-env-label Suppress the build NODE_ENV environment-label note (only applies in build-matrix mode; ignored for single-file dump)
114116
115117
Build Matrix Options (dump):
116118
--config-file=<file> Build config file (default: config/pack-config-diff-builds.yml)
@@ -320,6 +322,7 @@ function parseDumpArgs(args: string[]): ParsedDumpArgs {
320322
env: [],
321323
clean: false,
322324
warnSensitive: true,
325+
warnEnvLabel: true,
323326
allBuilds: false,
324327
listBuilds: false,
325328
buildConfigFile: DEFAULT_BUILD_CONFIG_FILE,
@@ -438,6 +441,9 @@ function parseDumpArgs(args: string[]): ParsedDumpArgs {
438441
case "--no-warn-sensitive":
439442
parsed.warnSensitive = false;
440443
break;
444+
case "--no-warn-env-label":
445+
parsed.warnEnvLabel = false;
446+
break;
441447
case "--config-file":
442448
if (!nextValue) {
443449
throw new Error("Missing value for --config-file");
@@ -741,7 +747,7 @@ function runDumpFromBuildConfig(parsed: ParsedDumpArgs): number {
741747
try {
742748
const resolvedEnvironment = resolveBuildEnvironmentLabel(build, parsed);
743749
const envLabel = resolvedEnvironment.label;
744-
if (resolvedEnvironment.source === "build-node-env" && parsed.warnSensitive) {
750+
if (resolvedEnvironment.source === "build-node-env" && parsed.warnEnvLabel) {
745751
console.error(
746752
`[pack-config-diff] Using build "${build.name}" NODE_ENV="${envLabel}" as dump environment label. Pass --environment to override.`,
747753
);

test/cli.integration.test.js

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ describe("CLI integration", () => {
487487
expect(errorOutput).not.toContain("Warning: dump output without --clean");
488488
});
489489

490-
test("dump --build --no-warn-sensitive suppresses NODE_ENV label note", () => {
490+
test("dump --build warns when metadata environment label falls back to build NODE_ENV", () => {
491491
const configPath = path.join(tempDir, "webpack.config.js");
492492
const buildConfig = path.join(tempDir, "pack-config-diff-builds.yml");
493493

@@ -504,33 +504,109 @@ describe("CLI integration", () => {
504504
"utf8",
505505
);
506506

507-
const defaultCode = run([
507+
const code = run(["dump", "--build=dev", `--config-file=${buildConfig}`, "--format=json"]);
508+
509+
expect(code).toBe(0);
510+
const errorOutput = errorSpy.mock.calls.map((args) => String(args[0])).join("\n");
511+
expect(errorOutput).toContain('Using build "dev" NODE_ENV="development" as dump environment');
512+
});
513+
514+
test("dump --build --no-warn-sensitive keeps NODE_ENV label note", () => {
515+
const configPath = path.join(tempDir, "webpack.config.js");
516+
const buildConfig = path.join(tempDir, "pack-config-diff-builds.yml");
517+
518+
fs.writeFileSync(configPath, "module.exports = { mode: 'production' }\n", "utf8");
519+
fs.writeFileSync(
520+
buildConfig,
521+
[
522+
"builds:",
523+
" dev:",
524+
` config: "${configPath}"`,
525+
" environment:",
526+
" NODE_ENV: development",
527+
].join("\n"),
528+
"utf8",
529+
);
530+
531+
const code = run([
508532
"dump",
509533
"--build=dev",
510534
`--config-file=${buildConfig}`,
511535
"--format=json",
536+
"--no-warn-sensitive",
512537
]);
513538

514-
expect(defaultCode).toBe(0);
515-
let errorOutput = errorSpy.mock.calls.map((args) => String(args[0])).join("\n");
539+
expect(code).toBe(0);
540+
const errorOutput = errorSpy.mock.calls.map((args) => String(args[0])).join("\n");
516541
expect(errorOutput).toContain('Using build "dev" NODE_ENV="development" as dump environment');
542+
expect(errorOutput).not.toContain("Warning: dump output without --clean");
543+
});
544+
545+
test("dump --build --no-warn-env-label suppresses NODE_ENV label note", () => {
546+
const configPath = path.join(tempDir, "webpack.config.js");
547+
const buildConfig = path.join(tempDir, "pack-config-diff-builds.yml");
548+
549+
fs.writeFileSync(configPath, "module.exports = { mode: 'production' }\n", "utf8");
550+
fs.writeFileSync(
551+
buildConfig,
552+
[
553+
"builds:",
554+
" dev:",
555+
` config: "${configPath}"`,
556+
" environment:",
557+
" NODE_ENV: development",
558+
].join("\n"),
559+
"utf8",
560+
);
561+
562+
const code = run([
563+
"dump",
564+
"--build=dev",
565+
`--config-file=${buildConfig}`,
566+
"--format=json",
567+
"--no-warn-env-label",
568+
]);
517569

518-
logSpy.mockClear();
519-
errorSpy.mockClear();
570+
expect(code).toBe(0);
571+
const errorOutput = errorSpy.mock.calls.map((args) => String(args[0])).join("\n");
572+
expect(errorOutput).not.toContain(
573+
'Using build "dev" NODE_ENV="development" as dump environment',
574+
);
575+
expect(errorOutput).toContain("Warning: dump output without --clean");
576+
});
520577

521-
const suppressedCode = run([
578+
test("dump --build --no-warn-sensitive --no-warn-env-label suppresses both warnings independently", () => {
579+
const configPath = path.join(tempDir, "webpack.config.js");
580+
const buildConfig = path.join(tempDir, "pack-config-diff-builds.yml");
581+
582+
fs.writeFileSync(configPath, "module.exports = { mode: 'production' }\n", "utf8");
583+
fs.writeFileSync(
584+
buildConfig,
585+
[
586+
"builds:",
587+
" dev:",
588+
` config: "${configPath}"`,
589+
" environment:",
590+
" NODE_ENV: development",
591+
].join("\n"),
592+
"utf8",
593+
);
594+
595+
const code = run([
522596
"dump",
523597
"--build=dev",
524598
`--config-file=${buildConfig}`,
525599
"--format=json",
526600
"--no-warn-sensitive",
601+
"--no-warn-env-label",
527602
]);
528603

529-
expect(suppressedCode).toBe(0);
530-
errorOutput = errorSpy.mock.calls.map((args) => String(args[0])).join("\n");
604+
expect(code).toBe(0);
605+
const errorOutput = errorSpy.mock.calls.map((args) => String(args[0])).join("\n");
531606
expect(errorOutput).not.toContain(
532607
'Using build "dev" NODE_ENV="development" as dump environment',
533608
);
609+
expect(errorOutput).not.toContain("Warning: dump output without --clean");
534610
});
535611

536612
test("dump --annotate injects inline docs for known keys", () => {

0 commit comments

Comments
 (0)