Allow additional package keys and add blacklist (#8082) (#8219)

This commit is contained in:
Tom Valorsa
2020-01-12 12:10:03 +00:00
committed by Brody McKee
parent fa85f030de
commit 94932bedc0
5 changed files with 99 additions and 29 deletions

View File

@@ -118,11 +118,55 @@ module.exports = function(
templateJson = require(templateJsonPath);
}
const templatePackage = templateJson.package || {};
// Keys to ignore in templatePackage
const templatePackageBlacklist = [
'name',
'version',
'description',
'keywords',
'bugs',
'license',
'author',
'contributors',
'files',
'main',
'browser',
'bin',
'man',
'directories',
'repository',
'devDependencies',
'peerDependencies',
'bundledDependencies',
'optionalDependencies',
'engineStrict',
'os',
'cpu',
'preferGlobal',
'private',
'publishConfig',
];
// Keys from templatePackage that will be merged with appPackage
const templatePackageToMerge = ['dependencies', 'scripts'];
// Keys from templatePackage that will be added to appPackage,
// replacing any existing entries.
const templatePackageToReplace = Object.keys(templatePackage).filter(key => {
return (
!templatePackageBlacklist.includes(key) &&
!templatePackageToMerge.includes(key)
);
});
// Copy over some of the devDependencies
appPackage.dependencies = appPackage.dependencies || {};
// Setup the script rules
const templateScripts = templateJson.scripts || {};
// TODO: deprecate 'scripts' key directly on templateJson
const templateScripts = templatePackage.scripts || templateJson.scripts || {};
appPackage.scripts = Object.assign(
{
start: 'react-scripts start',
@@ -152,6 +196,11 @@ module.exports = function(
// Setup the browsers list
appPackage.browserslist = defaultBrowsers;
// Add templatePackage keys/values to appPackage, replacing existing entries
templatePackageToReplace.forEach(key => {
appPackage[key] = templatePackage[key];
});
fs.writeFileSync(
path.join(appPath, 'package.json'),
JSON.stringify(appPackage, null, 2) + os.EOL
@@ -221,7 +270,9 @@ module.exports = function(
}
// Install additional template dependencies, if present
const templateDependencies = templateJson.dependencies;
// TODO: deprecate 'dependencies' key directly on templateJson
const templateDependencies =
templatePackage.dependencies || templateJson.dependencies;
if (templateDependencies) {
args = args.concat(
Object.keys(templateDependencies).map(key => {