Skip to content

Commit

Permalink
refactor: remove negative reset flags (#1868)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Oct 5, 2020
1 parent ae9539d commit 2b8415a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 91 deletions.
46 changes: 0 additions & 46 deletions packages/webpack-cli/README.md
Expand Up @@ -540,9 +540,6 @@ yarn add webpack-cli --dev
--no-amd Negates amd
--no-bail Negates bail
--no-cache Negates cache
--no-cache-immutable-paths-reset Negates cache-immutable-paths-reset
--no-dependencies-reset Negates dependencies-reset
--no-entry-reset Negates entry-reset
--no-experiments-asset Negates experiments-asset
--no-experiments-async-web-assembly Negates experiments-async-web-assembly
--no-experiments-import-async Negates experiments-import-async
Expand All @@ -551,13 +548,9 @@ yarn add webpack-cli --dev
--no-experiments-output-module Negates experiments-output-module
--no-experiments-sync-web-assembly Negates experiments-sync-web-assembly
--no-experiments-top-level-await Negates experiments-top-level-await
--no-externals-reset Negates externals-reset
--no-infrastructure-logging-debug-reset Negates infrastructure-logging-debug-reset
--no-module-expr-context-critical Negates module-expr-context-critical
--no-module-expr-context-recursive Negates module-expr-context-recursive
--no-module-no-parse-reset Negates module-no-parse-reset
--no-module-rules-side-effects Negates module-rules-side-effects
--no-module-rules-reset Negates module-rules-reset
--no-module-strict-export-presence Negates module-strict-export-presence
--no-module-strict-this-context-on-imports Negates module-strict-this-context-on-imports
--no-module-unknown-context-critical Negates module-unknown-context-critical
Expand Down Expand Up @@ -585,61 +578,27 @@ yarn add webpack-cli --dev
--no-optimization-split-chunks-hide-path-info Negates optimization-split-chunks-hide-path-info
--no-optimization-used-exports Negates optimization-used-exports
--no-output-compare-before-emit Negates output-compare-before-emit
--no-output-enabled-library-types-reset Negates output-enabled-library-types-reset
--no-output-iife Negates output-iife
--no-output-library-reset Negates output-library-reset
--no-output-library-root-reset Negates output-library-root-reset
--no-output-library-export-reset Negates output-library-export-reset
--no-output-library-name-reset Negates output-library-name-reset
--no-output-library-name-root-reset Negates output-library-name-root-reset
--no-output-library-umd-named-define Negates output-library-umd-named-define
--no-output-module Negates output-module
--no-output-pathinfo Negates output-pathinfo
--no-output-strict-module-exception-handling Negates output-strict-module-exception-handling
--no-performance Negates performance
--no-profile Negates profile
--no-resolve-alias-only-module Negates resolve-alias-only-module
--no-resolve-alias-reset Negates resolve-alias-reset
--no-resolve-alias-fields-reset Negates resolve-alias-fields-reset
--no-resolve-cache Negates resolve-cache
--no-resolve-cache-with-context Negates resolve-cache-with-context
--no-resolve-condition-names-reset Negates resolve-condition-names-reset
--no-resolve-description-files-reset Negates resolve-description-files-reset
--no-resolve-enforce-extension Negates resolve-enforce-extension
--no-resolve-exports-fields-reset Negates resolve-exports-fields-reset
--no-resolve-extensions-reset Negates resolve-extensions-reset
--no-resolve-fully-specified Negates resolve-fully-specified
--no-resolve-main-fields-reset Negates resolve-main-fields-reset
--no-resolve-main-files-reset Negates resolve-main-files-reset
--no-resolve-modules-reset Negates resolve-modules-reset
--no-resolve-restrictions-reset Negates resolve-restrictions-reset
--no-resolve-roots-reset Negates resolve-roots-reset
--no-resolve-symlinks Negates resolve-symlinks
--no-resolve-unsafe-cache Negates resolve-unsafe-cache
--no-resolve-use-sync-file-system-calls Negates resolve-use-sync-file-system-calls
--no-resolve-loader-alias-only-module Negates resolve-loader-alias-only-module
--no-resolve-loader-alias-reset Negates resolve-loader-alias-reset
--no-resolve-loader-alias-fields-reset Negates resolve-loader-alias-fields-reset
--no-resolve-loader-cache Negates resolve-loader-cache
--no-resolve-loader-cache-with-context Negates resolve-loader-cache-with-context
--no-resolve-loader-condition-names-reset Negates resolve-loader-condition-names-reset
--no-resolve-loader-description-files-reset Negates resolve-loader-description-files-reset
--no-resolve-loader-enforce-extension Negates resolve-loader-enforce-extension
--no-resolve-loader-exports-fields-reset Negates resolve-loader-exports-fields-reset
--no-resolve-loader-extensions-reset Negates resolve-loader-extensions-reset
--no-resolve-loader-fully-specified Negates resolve-loader-fully-specified
--no-resolve-loader-main-fields-reset Negates resolve-loader-main-fields-reset
--no-resolve-loader-main-files-reset Negates resolve-loader-main-files-reset
--no-resolve-loader-modules-reset Negates resolve-loader-modules-reset
--no-resolve-loader-restrictions-reset Negates resolve-loader-restrictions-reset
--no-resolve-loader-roots-reset Negates resolve-loader-roots-reset
--no-resolve-loader-symlinks Negates resolve-loader-symlinks
--no-resolve-loader-unsafe-cache Negates resolve-loader-unsafe-cache
--no-resolve-loader-use-sync-file-system-calls Negates resolve-loader-use-sync-file-system-calls
--no-snapshot-build-dependencies-hash Negates snapshot-build-dependencies-hash
--no-snapshot-build-dependencies-timestamp Negates snapshot-build-dependencies-timestamp
--no-snapshot-immutable-paths-reset Negates snapshot-immutable-paths-reset
--no-snapshot-managed-paths-reset Negates snapshot-managed-paths-reset
--no-snapshot-module-hash Negates snapshot-module-hash
--no-snapshot-module-timestamp Negates snapshot-module-timestamp
--no-snapshot-resolve-hash Negates snapshot-resolve-hash
Expand All @@ -665,11 +624,8 @@ yarn add webpack-cli --dev
--no-stats-error-details Negates stats-error-details
--no-stats-error-stack Negates stats-error-stack
--no-stats-errors Negates stats-errors
--no-stats-exclude-assets-reset Negates stats-exclude-assets-reset
--no-stats-exclude-modules-reset Negates stats-exclude-modules-reset
--no-stats-hash Negates stats-hash
--no-stats-ids Negates stats-ids
--no-stats-logging-debug-reset Negates stats-logging-debug-reset
--no-stats-logging-trace Negates stats-logging-trace
--no-stats-module-assets Negates stats-module-assets
--no-stats-module-trace Negates stats-module-trace
Expand All @@ -688,8 +644,6 @@ yarn add webpack-cli --dev
--no-stats-used-exports Negates stats-used-exports
--no-stats-version Negates stats-version
--no-stats-warnings Negates stats-warnings
--no-stats-warnings-filter-reset Negates stats-warnings-filter-reset
--no-watch-options-ignored-reset Negates watch-options-ignored-reset
--no-watch-options-stdin Negates watch-options-stdin
```

Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/utils/cli-flags.js
Expand Up @@ -250,7 +250,7 @@ let flagsFromCore =
meta.usage = `--${flag} <value>`;
} else {
meta.type = Boolean;
meta.negative = true;
meta.negative = !flag.endsWith('-reset');
meta.usage = `--${flag}`;
}
return {
Expand Down
23 changes: 11 additions & 12 deletions test/core-flags/module-flags.test.js
Expand Up @@ -28,18 +28,17 @@ describe('module config related flag', () => {
}
});

it(`should config --no-${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--no-${flag.name}`]);
expect(stderr).toBeFalsy();
if (flag.name.includes('-reset')) {
const option = propName.split('Reset')[0];
expect(stdout).toContain(`${option}: []`);
} else if (flag.name.includes('rules-')) {
expect(stdout).toContain('sideEffects: false');
} else {
expect(stdout).toContain(`${propName}: false`);
}
});
if (!flag.name.endsWith('-reset')) {
it(`should config --no-${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--no-${flag.name}`]);
expect(stderr).toBeFalsy();
if (flag.name.includes('rules-')) {
expect(stdout).toContain('sideEffects: false');
} else {
expect(stdout).toContain(`${propName}: false`);
}
});
}
}

if (flag.type === String) {
Expand Down
21 changes: 5 additions & 16 deletions test/core-flags/output-flags.test.js
Expand Up @@ -32,25 +32,14 @@ describe('output config related flag', () => {
}
});

it(`should config --no-${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--no-${flag.name}`]);
if (!flag.name.endsWith('-reset')) {
it(`should config --no-${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--no-${flag.name}`]);

if (flag.name.includes('loading-types-reset')) {
expect(stderr).toBeFalsy();
if (flag.name === 'output-enabled-wasm-loading-types-reset') {
expect(stdout).toContain(`enabledWasmLoadingTypes: [ 'fetch' ]`);
} else {
expect(stdout).toContain(`enabledChunkLoadingTypes: [ 'jsonp', 'import-scripts' ]`);
}
} else if (flag.name.includes('-reset')) {
const option = propName.split('Reset')[0];
expect(stderr).toBeFalsy();
expect(stdout).toContain(`${option}: []`);
} else {
expect(stderr).toBeFalsy();
expect(stdout).toContain(`${propName}: false`);
}
});
});
}
}

if (flag.type === Number) {
Expand Down
14 changes: 6 additions & 8 deletions test/core-flags/stats-flags.test.js
Expand Up @@ -24,16 +24,14 @@ describe('stats config related flag', () => {
}
});

it(`should config --no-${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--no-${flag.name}`]);
if (!flag.name.endsWith('-reset')) {
it(`should config --no-${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--no-${flag.name}`]);

expect(stderr).toBeFalsy();
if (flag.name.includes('reset')) {
expect(stdout).toContain(`stats: {}`);
} else {
expect(stderr).toBeFalsy();
expect(stdout).toContain(`stats: { ${propName}: false }`);
}
});
});
}
}

if (flag.type === Number) {
Expand Down
14 changes: 6 additions & 8 deletions test/core-flags/watch-flags.test.js
Expand Up @@ -23,16 +23,14 @@ describe('watch config related flag', () => {
}
});

it(`should config --no-${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--no-${flag.name}`]);
if (!flag.name.endsWith('-reset')) {
it(`should config --no-${flag.name} correctly`, () => {
const { stderr, stdout } = run(__dirname, [`--no-${flag.name}`]);

expect(stderr).toBeFalsy();
if (flag.name.includes('reset')) {
expect(stdout).toContain('watch: false');
} else {
expect(stderr).toBeFalsy();
expect(stdout).toContain(`watchOptions: { ${propName}: false }`);
}
});
});
}
}

if (flag.type === Number) {
Expand Down

0 comments on commit 2b8415a

Please sign in to comment.