Merging
Template producer functions return Creation objects.
When a --mode
is specified, a template may run multiple producer functions.
The two creations from those producer functions will need to be merged together.
Each type of creation has its own merging logic:
Files
File objects are recursively merged:
false
andundefined
values are ignored- Files are deduplicated if they have the same value, and an error is thrown if they do not
For example, given the following two files
Creations to be merged:
{ "LICENSE.txt": "# MIT", src: { "index.ts": `export * from "./types.ts"`, },}
{ "LICENSE.txt": "# MIT", src: { "types.ts": `export type Example = true;`, },}
The merged result would be:
{ "LICENSE.txt": "# MIT", src: { "index.ts": `export * from "./types.ts"`, "types.ts": `export type Example = true;`, },}
Requests
Requests are merged base on their id
and type
:
_ If two requests have different id
values, they are always considered separate
_ Otherwise, requests are merged based on their type
:
_ fetch
requests have init
merged with Object.assign()
if they contain the same url
_ octokit
requests have parameters
merged with Object.assign()
if they contain the same endpoint
For example, the following two requests
Creations would not be merged, because they have different endpoints:
[ { endpoint: "POST /repos/{owner}/{repo}/autolinks", parameters: { key_prefix: "TICKET-", owner: "JoshuaKGoldberg", repo: "create-typescript-app", url_template: "https://example.com/TICKET?query=<num>", } type: "octokit", }, { endpoint: "POST /repos/{owner}/{repo}/issues", parameters: { name: "good first issue", owner: "JoshuaKGoldberg", repo: "create-typescript-app", } type: "octokit", }]
However, the following two requests
Creations would be merged into one with the same endpoint:
[ { endpoint: "POST /repos/{owner}/{repo}/issues", parameters: { color: "#ffcc00", name: "good first issue (pending color)", owner: "JoshuaKGoldberg", repo: "create-typescript-app", } type: "octokit", }, { endpoint: "POST /repos/{owner}/{repo}/issues", parameters: { name: "good first issue", owner: "JoshuaKGoldberg", repo: "create-typescript-app", } type: "octokit", }]
The merged result would be:
[ { endpoint: "POST /repos/{owner}/{repo}/issues", parameters: { color: "#ffcc00", name: "good first issue", owner: "JoshuaKGoldberg", repo: "create-typescript-app", } type: "octokit", }]
Scripts
Scripts are deduplicated based on whether they include a phase
:
- “Phase” scripts are deduplicated if any’s arrays of
commands
are the same as any other - “Standalone” scripts provided as
string
are deduplicated and run in parallel after scripts with phases
For example, given the following two scripts
Creations to be merged:
[ { commands: ["pnpm install", "pnpm dedupe"], phase: 0, },];
[ `npx set-github-repository-labels --labels "$(cat labels.json)"`, { commands: ["pnpm install"], phase: 0, },];
The merged result would be:
[ { commands: ["pnpm install", "pnpm dedupe"], phase: 0, }, `npx set-github-repository-labels --labels "$(cat labels.json)"`,];
Suggestions
Suggestions are deduplicated by identity.
For example, given the following two suggestions
Creations to be merged:
[ "- set a CODECOV secret to an codecov repository token", "- set a NPM_TOKEN secret to an npm automation token",];
[ "- set an ACCESS_TOKEN secret to a GitHub PAT with repo and workflow permissions", "- set a NPM_TOKEN secret to an npm access token with automation permissions",];
The merged result would be:
[ "- set a CODECOV secret to an codecov repository token", "- set a NPM_TOKEN secret to an npm access token with automation permissions", "- set an ACCESS_TOKEN secret to a GitHub PAT with repo and workflow permissions",];