Skip to content

Commit b7797ab

Browse files
craigmichaelmartinclaude
authored andcommitted
refactor: remove redundant options param from copyConfigKeyEntry
context.options already carries stdout, so the separate second parameter was duplicating it — every caller was passing context.options anyway. Pull stdout directly from context.options inside the function and update the call site and tests accordingly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a0b9284 commit b7797ab

File tree

3 files changed

+65
-76
lines changed

3 files changed

+65
-76
lines changed

packages/app/src/cli/services/build/steps/include-assets-step.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,13 @@ export async function executeIncludeAssetsStep(
140140
const rawDest = entry.destination ? sanitizeRelativePath(entry.destination, warn) : undefined
141141
const sanitizedDest = rawDest === '' ? undefined : rawDest
142142
// eslint-disable-next-line no-await-in-loop
143-
const result = await copyConfigKeyEntry(
144-
{
145-
key: entry.key,
146-
baseDir: extension.directory,
147-
outputDir,
148-
context,
149-
destination: sanitizedDest,
150-
},
151-
options,
152-
)
143+
const result = await copyConfigKeyEntry({
144+
key: entry.key,
145+
baseDir: extension.directory,
146+
outputDir,
147+
context,
148+
destination: sanitizedDest,
149+
})
153150
result.pathMap.forEach((val, key) => aggregatedPathMap.set(key, val))
154151
configKeyCount += result.filesCopied
155152
}

packages/app/src/cli/services/build/steps/include-assets/copy-config-key-entry.test.ts

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import {inTemporaryDirectory, writeFile, fileExists, mkdir, readFile} from '@sho
33
import {joinPath} from '@shopify/cli-kit/node/path'
44
import {describe, expect, test, vi, beforeEach} from 'vitest'
55

6-
const makeContext = (configuration: Record<string, unknown>) => ({
6+
const makeContext = (configuration: Record<string, unknown>, stdout: any = {write: vi.fn()}) => ({
77
extension: {configuration} as any,
8-
options: {} as any,
8+
options: {stdout} as any,
99
stepResults: new Map(),
1010
})
1111

@@ -26,11 +26,8 @@ describe('copyConfigKeyEntry', () => {
2626
const outDir = joinPath(tmpDir, 'out')
2727
await mkdir(outDir)
2828

29-
const context = makeContext({static_root: 'public'})
30-
const result = await copyConfigKeyEntry(
31-
{key: 'static_root', baseDir: tmpDir, outputDir: outDir, context},
32-
{stdout: mockStdout},
33-
)
29+
const context = makeContext({static_root: 'public'}, mockStdout)
30+
const result = await copyConfigKeyEntry({key: 'static_root', baseDir: tmpDir, outputDir: outDir, context})
3431

3532
expect(result.filesCopied).toBe(2)
3633
await expect(fileExists(joinPath(outDir, 'index.html'))).resolves.toBe(true)
@@ -49,11 +46,8 @@ describe('copyConfigKeyEntry', () => {
4946
const outDir = joinPath(tmpDir, 'out')
5047
await mkdir(outDir)
5148

52-
const context = makeContext({schema_path: 'src/schema.json'})
53-
const result = await copyConfigKeyEntry(
54-
{key: 'schema_path', baseDir: tmpDir, outputDir: outDir, context},
55-
{stdout: mockStdout},
56-
)
49+
const context = makeContext({schema_path: 'src/schema.json'}, mockStdout)
50+
const result = await copyConfigKeyEntry({key: 'schema_path', baseDir: tmpDir, outputDir: outDir, context})
5751

5852
expect(result.filesCopied).toBe(1)
5953
await expect(fileExists(joinPath(outDir, 'schema.json'))).resolves.toBe(true)
@@ -74,11 +68,8 @@ describe('copyConfigKeyEntry', () => {
7468
// Pre-create the first candidate to force a rename
7569
await writeFile(joinPath(outDir, 'tools-a.json'), 'existing')
7670

77-
const context = makeContext({files: ['tools-a.json', 'tools-b.json']})
78-
const result = await copyConfigKeyEntry(
79-
{key: 'files', baseDir: tmpDir, outputDir: outDir, context},
80-
{stdout: mockStdout},
81-
)
71+
const context = makeContext({files: ['tools-a.json', 'tools-b.json']}, mockStdout)
72+
const result = await copyConfigKeyEntry({key: 'files', baseDir: tmpDir, outputDir: outDir, context})
8273

8374
expect(result.filesCopied).toBe(2)
8475
// tools-a.json was taken, so the copy lands as tools-a-1.json
@@ -92,11 +83,8 @@ describe('copyConfigKeyEntry', () => {
9283
const outDir = joinPath(tmpDir, 'out')
9384
await mkdir(outDir)
9485

95-
const context = makeContext({})
96-
const result = await copyConfigKeyEntry(
97-
{key: 'static_root', baseDir: tmpDir, outputDir: outDir, context},
98-
{stdout: mockStdout},
99-
)
86+
const context = makeContext({}, mockStdout)
87+
const result = await copyConfigKeyEntry({key: 'static_root', baseDir: tmpDir, outputDir: outDir, context})
10088

10189
expect(result.filesCopied).toBe(0)
10290
expect(result.pathMap.size).toBe(0)
@@ -109,11 +97,8 @@ describe('copyConfigKeyEntry', () => {
10997
await mkdir(outDir)
11098

11199
// 'nonexistent' directory is NOT created, so fileExists returns false naturally
112-
const context = makeContext({assets_dir: 'nonexistent'})
113-
const result = await copyConfigKeyEntry(
114-
{key: 'assets_dir', baseDir: tmpDir, outputDir: outDir, context},
115-
{stdout: mockStdout},
116-
)
100+
const context = makeContext({assets_dir: 'nonexistent'}, mockStdout)
101+
const result = await copyConfigKeyEntry({key: 'assets_dir', baseDir: tmpDir, outputDir: outDir, context})
117102

118103
expect(result.filesCopied).toBe(0)
119104
expect(result.pathMap.size).toBe(0)
@@ -137,11 +122,8 @@ describe('copyConfigKeyEntry', () => {
137122
const outDir = joinPath(tmpDir, 'out')
138123
await mkdir(outDir)
139124

140-
const context = makeContext({roots: ['public', 'assets']})
141-
const result = await copyConfigKeyEntry(
142-
{key: 'roots', baseDir: tmpDir, outputDir: outDir, context},
143-
{stdout: mockStdout},
144-
)
125+
const context = makeContext({roots: ['public', 'assets']}, mockStdout)
126+
const result = await copyConfigKeyEntry({key: 'roots', baseDir: tmpDir, outputDir: outDir, context})
145127

146128
// Promise.all runs copies sequentially; glob on the shared outDir may see files
147129
// from the other copy, so the total count is at least 3 (one per real file).
@@ -161,11 +143,14 @@ describe('copyConfigKeyEntry', () => {
161143
const outDir = joinPath(tmpDir, 'out')
162144
await mkdir(outDir)
163145

164-
const context = makeContext({icons_dir: 'icons'})
165-
await copyConfigKeyEntry(
166-
{key: 'icons_dir', baseDir: tmpDir, outputDir: outDir, context, destination: 'static/icons'},
167-
{stdout: mockStdout},
168-
)
146+
const context = makeContext({icons_dir: 'icons'}, mockStdout)
147+
await copyConfigKeyEntry({
148+
key: 'icons_dir',
149+
baseDir: tmpDir,
150+
outputDir: outDir,
151+
context,
152+
destination: 'static/icons',
153+
})
169154

170155
await expect(fileExists(joinPath(outDir, 'static', 'icons', 'icon.svg'))).resolves.toBe(true)
171156
})
@@ -186,10 +171,12 @@ describe('copyConfigKeyEntry', () => {
186171
{targeting: [{schema: 'schema-c.json'}]},
187172
],
188173
})
189-
const result = await copyConfigKeyEntry(
190-
{key: 'extensions[].targeting[].schema', baseDir: tmpDir, outputDir: outDir, context},
191-
{stdout: mockStdout},
192-
)
174+
const result = await copyConfigKeyEntry({
175+
key: 'extensions[].targeting[].schema',
176+
baseDir: tmpDir,
177+
outputDir: outDir,
178+
context,
179+
})
193180

194181
expect(result.filesCopied).toBe(3)
195182
await expect(fileExists(joinPath(outDir, 'schema-a.json'))).resolves.toBe(true)
@@ -203,15 +190,20 @@ describe('copyConfigKeyEntry', () => {
203190
const outDir = joinPath(tmpDir, 'out')
204191
await mkdir(outDir)
205192

206-
const context = makeContext({
207-
extensions: {targeting: {schema: 'schema.json'}},
208-
})
209-
210-
const result = await copyConfigKeyEntry(
211-
{key: 'extensions[].targeting[].schema', baseDir: tmpDir, outputDir: outDir, context},
212-
{stdout: mockStdout},
193+
const context = makeContext(
194+
{
195+
extensions: {targeting: {schema: 'schema.json'}},
196+
},
197+
mockStdout,
213198
)
214199

200+
const result = await copyConfigKeyEntry({
201+
key: 'extensions[].targeting[].schema',
202+
baseDir: tmpDir,
203+
outputDir: outDir,
204+
context,
205+
})
206+
215207
expect(result.filesCopied).toBe(0)
216208
expect(result.pathMap.size).toBe(0)
217209
})
@@ -228,10 +220,12 @@ describe('copyConfigKeyEntry', () => {
228220
const context = makeContext({
229221
extensions: [{targeting: [{tools: 'tools.json'}, {tools: 'tools.json'}]}],
230222
})
231-
const result = await copyConfigKeyEntry(
232-
{key: 'extensions[].targeting[].tools', baseDir: tmpDir, outputDir: outDir, context},
233-
{stdout: mockStdout},
234-
)
223+
const result = await copyConfigKeyEntry({
224+
key: 'extensions[].targeting[].tools',
225+
baseDir: tmpDir,
226+
outputDir: outDir,
227+
context,
228+
})
235229

236230
expect(result.filesCopied).toBe(1)
237231
await expect(fileExists(joinPath(outDir, 'tools.json'))).resolves.toBe(true)

packages/app/src/cli/services/build/steps/include-assets/copy-config-key-entry.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@ import type {BuildContext} from '../../client-steps.js'
2020
* value to its output-relative location. File sources map to a single string.
2121
* Directory sources map to a `string[]` of every output-relative file path.
2222
*/
23-
export async function copyConfigKeyEntry(
24-
config: {
25-
key: string
26-
baseDir: string
27-
outputDir: string
28-
context: BuildContext
29-
destination?: string
30-
},
31-
options: {stdout: NodeJS.WritableStream},
32-
): Promise<{filesCopied: number; pathMap: Map<string, string | string[]>}> {
23+
export async function copyConfigKeyEntry(config: {
24+
key: string
25+
baseDir: string
26+
outputDir: string
27+
context: BuildContext
28+
destination?: string
29+
}): Promise<{filesCopied: number; pathMap: Map<string, string | string[]>}> {
3330
const {key, baseDir, outputDir, context, destination} = config
31+
const {stdout} = context.options
3432
const value = getNestedValue(context.extension.configuration, key)
3533
let paths: string[]
3634
if (typeof value === 'string') {
@@ -42,7 +40,7 @@ export async function copyConfigKeyEntry(
4240
}
4341

4442
if (paths.length === 0) {
45-
outputDebug(`No value for configKey '${key}', skipping\n`, context.options.stdout)
43+
outputDebug(`No value for configKey '${key}', skipping\n`, stdout)
4644
return {filesCopied: 0, pathMap: new Map()}
4745
}
4846

@@ -62,7 +60,7 @@ export async function copyConfigKeyEntry(
6260
const fullPath = joinPath(baseDir, sourcePath)
6361
const exists = await fileExists(fullPath)
6462
if (!exists) {
65-
options.stdout.write(`Warning: path '${sourcePath}' does not exist, skipping\n`)
63+
stdout.write(`Warning: path '${sourcePath}' does not exist, skipping\n`)
6664
continue
6765
}
6866

@@ -73,7 +71,7 @@ export async function copyConfigKeyEntry(
7371
if (sourceIsDir) {
7472
await copyDirectoryContents(fullPath, destDir)
7573
const copied = await glob(['**/*'], {cwd: destDir, absolute: false})
76-
options.stdout.write(`Included '${sourcePath}'\n`)
74+
stdout.write(`Included '${sourcePath}'\n`)
7775
const relFiles = copied.map((file) => relativePath(outputDir, joinPath(destDir, file)))
7876
pathMap.set(sourcePath, relFiles)
7977
filesCopied += copied.length
@@ -82,7 +80,7 @@ export async function copyConfigKeyEntry(
8280
const uniqueDestPath = await findUniqueDestPath(destDir, basename(fullPath))
8381
await copyFile(fullPath, uniqueDestPath)
8482
const outputRelative = relativePath(outputDir, uniqueDestPath)
85-
options.stdout.write(`Included '${sourcePath}'\n`)
83+
stdout.write(`Included '${sourcePath}'\n`)
8684
pathMap.set(sourcePath, outputRelative)
8785
filesCopied += 1
8886
}

0 commit comments

Comments
 (0)