-
-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webpack-cli): import flags from webpack core (#1630)
- Loading branch information
Showing
31 changed files
with
1,550 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
const { run } = require('../utils/test-utils'); | ||
|
||
describe('--no-amd flag', () => { | ||
it('should accept --no-amd', () => { | ||
const { stderr, stdout } = run(__dirname, ['--no-amd']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain('amd: false'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
const { run } = require('../utils/test-utils'); | ||
|
||
describe('--bail flag', () => { | ||
it('should set bail to true', () => { | ||
const { stderr, stdout } = run(__dirname, ['--bail']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain('bail: true'); | ||
}); | ||
|
||
it('should set bail to false', () => { | ||
const { stderr, stdout } = run(__dirname, ['--no-bail']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain('bail: false'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
'use strict'; | ||
|
||
const { run } = require('../utils/test-utils'); | ||
|
||
describe('cache related flags from core', () => { | ||
it('should be successful with --cache ', () => { | ||
const { stderr, stdout } = run(__dirname, ['--cache']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`type: 'memory'`); | ||
}); | ||
|
||
it('should be successful with --no-cache ', () => { | ||
const { stderr, stdout } = run(__dirname, ['--no-cache']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain('cache: false'); | ||
}); | ||
|
||
it('should set cache.type', () => { | ||
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`type: 'filesystem'`); | ||
}); | ||
|
||
it('should set cache.cacheDirectory with --cache-cache-directory', () => { | ||
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-cache-directory', '/test-cache-path']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain('test-cache-path'); | ||
}); | ||
|
||
it('should set cache.cacheLocation with --cache-cache-locations', () => { | ||
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-cache-location', '/test-locate-cache']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain('test-locate-cache'); | ||
}); | ||
|
||
it('should set cache.hashAlgorithm with --cache-hash-algorithm', () => { | ||
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-hash-algorithm', 'sha256']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`hashAlgorithm: 'sha256'`); | ||
}); | ||
|
||
it('should set cache.managedPaths with --cache-managed-paths', () => { | ||
const { stderr, stdout } = run(__dirname, ['--cache-type', 'memory', '--cache-managed-paths', '/test-manage-path']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain('test-manage-path'); | ||
}); | ||
|
||
it('should reset cache.managedPaths with --cache-managed-paths-reset', () => { | ||
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-managed-paths-reset']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`managedPaths: []`); | ||
}); | ||
|
||
it('should set cache.name with --cache-name', () => { | ||
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-name', 'cli-test']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`name: 'cli-test'`); | ||
}); | ||
|
||
it('should set cache.store with --cache-store', () => { | ||
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-store', 'pack']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`store: 'pack'`); | ||
}); | ||
|
||
it('should set cache.version with --cache-version', () => { | ||
const { stderr, stdout } = run(__dirname, ['--cache-type', 'filesystem', '--cache-version', '1.1.3']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`version: '1.1.3'`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
const { run } = require('../utils/test-utils'); | ||
|
||
describe('--context flag', () => { | ||
it('should allow to set context', () => { | ||
const { stderr, stdout } = run(__dirname, ['--context', '/test-context-path']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain('test-context-path'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
const { run } = require('../utils/test-utils'); | ||
|
||
describe('--dependencies and related flags', () => { | ||
it('should allow to set dependencies option', () => { | ||
const { stderr, stdout } = run(__dirname, ['--dependencies', 'lodash']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`dependencies: [ 'lodash' ]`); | ||
}); | ||
|
||
it('should reset dependencies option', () => { | ||
const { stderr, stdout } = run(__dirname, ['--dependencies-reset']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain('dependencies: []'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
const { run } = require('../utils/test-utils'); | ||
|
||
describe('--devtool flag', () => { | ||
it('should set devtool option', () => { | ||
const { stderr, stdout } = run(__dirname, ['--devtool', 'source-map']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`devtool: 'source-map'`); | ||
}); | ||
|
||
it('should throw error for invalid config', () => { | ||
const { stderr } = run(__dirname, ['--devtool', 'invalid']); | ||
|
||
expect(stderr).toContain('ValidationError: Invalid configuration object'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
const { run, hyphenToUpperCase } = require('../utils/test-utils'); | ||
const { flagsFromCore } = require('../../packages/webpack-cli/lib/utils/cli-flags'); | ||
|
||
const experimentsFlags = flagsFromCore.filter(({ name }) => name.startsWith('experiments-')); | ||
|
||
describe('experiments option related flag', () => { | ||
experimentsFlags.forEach((flag) => { | ||
// extract property name from flag name | ||
const property = flag.name.split('experiments-')[1]; | ||
const propName = hyphenToUpperCase(property); | ||
|
||
it(`should config ${flag.name} correctly`, () => { | ||
const { stderr, stdout } = run(__dirname, [`--${flag.name}`]); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`${propName}: true`); | ||
}); | ||
|
||
it(`should config --no-${flag.name} correctly`, () => { | ||
const { stderr, stdout } = run(__dirname, [`--no-${flag.name}`]); | ||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`${propName}: false`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const { run } = require('../utils/test-utils'); | ||
|
||
describe('externals related flag', () => { | ||
it('should set externals properly', () => { | ||
const { stderr, stdout } = run(__dirname, ['--externals', './main.js']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`externals: [ './main.js' ]`); | ||
}); | ||
|
||
it('should set externalsType properly', () => { | ||
const { stderr, stdout } = run(__dirname, ['--externals', 'var']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`externalsType: 'var'`); | ||
}); | ||
|
||
it('should accept --external-type values', () => { | ||
const { stderr, stdout } = run(__dirname, ['--externals-type', 'var']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`externalsType: 'var'`); | ||
}); | ||
|
||
it('should reset externals', () => { | ||
const { stderr, stdout } = run(__dirname, ['--externals-reset']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`externals: []`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
const { run } = require('../utils/test-utils'); | ||
|
||
describe('externals related flag', () => { | ||
it('should set infrastructureLogging.debug properly', () => { | ||
const { stderr, stdout } = run(__dirname, ['--infrastructure-logging-debug', 'myPlugin']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`debug: [ 'myPlugin' ]`); | ||
}); | ||
|
||
it('should reset infrastructureLogging.debug to []', () => { | ||
const { stderr, stdout } = run(__dirname, ['--infrastructure-logging-debug-reset']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`debug: []`); | ||
}); | ||
|
||
it('should set infrastructureLogging.level properly', () => { | ||
const { stderr, stdout } = run(__dirname, ['--infrastructure-logging-level', 'log']); | ||
|
||
expect(stderr).toBeFalsy(); | ||
expect(stdout).toContain(`level: 'log'`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('core-flags tests'); |
Oops, something went wrong.