-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: recursively merge package.json scripts field from build configuration #1372
Conversation
e309140
to
8682531
Compare
5b3287a
to
fdaadc0
Compare
.expectObjectNode(); | ||
|
||
ObjectNode mergedScripts = defaultPackageJson.expectObjectNode("scripts") | ||
.merge( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the merge on line 57 not sufficient for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a shallow merge, so this does the following:
Default:
{
"name": "A",
"scripts": {
"build": "..."
},
"metadata": "A"
}
User supplied:
{
"name": "B",
"scripts": {
"test": "..."
}
}
- create the merged
pkg.scripts
object.
{
"build": "...",
"test": "..."
}
- do the normal shallow merge
{
"name": "B",
"scripts": {
"test": "..."
},
"metadata": "A"
}
- write the merged
pkg.scripts
onto the shallow merge
{
"name": "B",
"scripts": {
"build": "...",
"test": "..."
},
"metadata": "A"
}
fdaadc0
to
6d03588
Compare
Aug 28: Need to address CI failures, I think they're related to this PR and not the intermittent kind Oct 7: fixed |
6d03588
to
ad64cbd
Compare
ad64cbd
to
e1fe413
Compare
Issue #, if available:
closes #1125
Description of changes:
One of the build options for code generation is:
packageJson
| required=No | Custom package.json properties that will be merged with the base package.json. The default value is an empty object.Because of shallow merging, it is difficult for example to merge script entries like
This PR changes the behavior to recursive merging for only the
scripts
field. I do not expect anyone to be relying on the existing shallow merge behavior, because every code generated field in"scripts"
is there for a reason.More specific customization of the package.json object can be done after the build, if needed.
Recursive merging is not done for other fields, to avoid mixing user and generated nested fields in e.g. authorship metadata or bundler instruction metadata.