Skip to content

Commit

Permalink
feat[utils]: opt to use config schema from core (#1655)
Browse files Browse the repository at this point in the history
* chore: remove hardcoded config options from utils, use from core

* chore: use config schema from core

* chore: use config schema from core

* chore: use config schema from core

* chore: use config schema from core

* feat: use config schema from core
  • Loading branch information
anshumanv authored Jul 1, 2020
1 parent 28526a6 commit c2095ac
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 34 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"rimraf": "^3.0.2",
"ts-jest": "^25.3.0",
"typescript": "^3.9.5",
"webpack": "^4.42.0",
"webpack": "^4.43.0",
"yeoman-test": "^2.3.0"
}
}
3 changes: 3 additions & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"yeoman-environment": "2.8.1",
"yeoman-generator": "4.7.2"
},
"peerDependencies": {
"webpack": "4.x.x || 5.x.x"
},
"devDependencies": {
"@types/got": "9.6.9",
"@types/prettier": "1.19.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/utils/src/isWebpack5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { version } from 'webpack';

export const isWebpack5 = (): boolean => version.startsWith('5');
73 changes: 41 additions & 32 deletions packages/utils/src/prop-types.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
import { isWebpack5 } from './isWebpack5';
import { config } from 'webpack';

let configKeys;
if (isWebpack5()) {
configKeys = Object.keys(config.getNormalizedWebpackOptions({}));
} else {
configKeys = [
'amd',
'bail',
'cache',
'context',
'devServer',
'devtool',
'entry',
'externals',
'merge',
'mode',
'module',
'node',
'optimization',
'output',
'parallelism',
'performance',
'plugins',
'profile',
'recordsInputPath',
'recordsOutputPath',
'recordsPath',
'resolve',
'resolveLoader',
'splitChunks',
'stats',
'target',
'topScope',
'watch',
'watchOptions',
];
}

/**
*
* A Set of all accepted properties
*
* @returns {Set} A new set with accepted webpack properties
*/

export const PROP_TYPES: Set<string> = new Set([
'amd',
'bail',
'cache',
'context',
'devServer',
'devtool',
'entry',
'externals',
'merge',
'mode',
'module',
'node',
'optimization',
'output',
'parallelism',
'performance',
'plugins',
'profile',
'recordsInputPath',
'recordsOutputPath',
'recordsPath',
'resolve',
'resolveLoader',
'splitChunks',
'stats',
'target',
'topScope',
'watch',
'watchOptions',
]);
export const PROP_TYPES: Set<string> = new Set(configKeys);
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11959,7 +11959,7 @@ webpack-sources@^1.4.0, webpack-sources@^1.4.1:
source-list-map "^2.0.0"
source-map "~0.6.1"

webpack@4.x.x, webpack@^4.42.0:
webpack@4.x.x, webpack@^4.43.0:
version "4.43.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.43.0.tgz#c48547b11d563224c561dad1172c8aa0b8a678e6"
integrity sha512-GW1LjnPipFW2Y78OOab8NJlCflB7EFskMih2AHdvjbpKMeDJqEgSx24cXXXiPS65+WSwVyxtDsJH6jGX2czy+g==
Expand Down

0 comments on commit c2095ac

Please sign in to comment.