Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !8219

Add template support for any package.json keys (#8082)

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/tomvalorsa/add-template-package-key into master Dec 22, 2019
  • Overview 12
  • Commits 4
  • Pipelines 0
  • Changes 5

Created by: tomvalorsa

This PR adds support for any package.json keys in a template.json file. It uses a blacklist of specific keys that shouldn’t be touched, and explicitly lists which keys will be merged with existing config - any other keys will be replaced as discussed in #8082 (closed).

Some notes:

  • explicit merging of "scripts" and "dependencies" kept intact
  • templatePackage keys that aren’t blacklisted or specified as merge keys will be added to appPackage
    • this also replaces existing entries in appPackage with the new values specified in templatePackage
  • stock templates have been updated to reflect the change in template.json, "kitchensink" fixture also updated
  • docs have been updated

Some thoughts:

  • some of the names used feel a bit chunky, open to suggestions!
  • I chose "browserslist" as the example for the docs page based on #8209 but can change if there’s a clearer example (a real example felt better than "some key": "some value")
  • I added a couple of deprecation notes as "TODOs" as a I saw this convention elsewhere in react-scripts/init.js. These are based on the plan to deprecate the old template style here. Let me know if this should live somewhere else, or if there’s a specific format you follow
  • not sure how you manage changelogs but if you’re using issue titles the related issue doesn’t really represent this PR anymore so it should be changed

Test plan:

I created a custom template that was a direct copy of cra-template, and then tested different scenarios. There are various tests split across different branches (one per branch). N.B. the changes here are just related to template.json on each of these branches. Quick summary:

  • master - direct copy of cra-template
  • test-01-package-key - added a different dependency to package.dependencies to ensure it was installed correctly
  • test-02-scripts-key - added scripts to add and replace to package.scripts
  • test-03-old-deps-scripts - added deps and scripts in the old format to ensure it still works
  • test-04-old-and-new-deps-and-scripts - added both new and old formats to ensure the new format takes precedence
  • test-05-blacklist-keys - added all of the blacklist keys to ensure they aren’t copied over
  • test-06-custom-keys-to-replace-extend - added some custom, non-blacklisted keys to ensure they are copied over
  • test-07-empty-old-config - tried with an empty config
  • test-08-empty-new-config - tried with an empty package
  • I also ran with cra-template-typescript

All of the above worked as expected, I’m happy to run again and provide screenshots if needed. I ran these tests by cloning my custom template and running the following command, changing branches in the custom template dir as necessary:

npx create-react-app test-app --scripts-version=file:path/to/react-scripts --template=file:path/to/custom/template

I wasn’t sure how to run other tests in the repo so I’m pushing this up now to see if CI passes.

Any feedback would be greatly appreciated :)

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/tomvalorsa/add-template-package-key