Skip to content

Commit 621e74d

Browse files
committed
Include the file list that match overridable imports
1 parent 2b9011e commit 621e74d

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

packages/pwa-kit-dev/bin/pwa-kit-dev.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,21 +547,45 @@ const main = async () => {
547547
return
548548
}
549549

550-
const unusedOverrides = allOverrideFiles.filter(
551-
(file) => !hasCorrespondingOverridableImport(file, imports, projectDir)
550+
// Separate override files into matched and unmatched using array methods
551+
const {matchedOverrides, unmatchedOverrides} = allOverrideFiles.reduce(
552+
(acc, file) => {
553+
const key = hasCorrespondingOverridableImport(file, imports, projectDir)
554+
? 'matchedOverrides'
555+
: 'unmatchedOverrides'
556+
acc[key].push(file)
557+
return acc
558+
},
559+
{matchedOverrides: [], unmatchedOverrides: []}
552560
)
553561

562+
// Report on matched overrides using template literals
554563
console.log(
555-
unusedOverrides.length
564+
matchedOverrides.length
565+
? chalk.green(
566+
`Found ${matchedOverrides.length} override files that match overridable imports:`
567+
)
568+
: chalk.yellow('No override files match any overridable imports.')
569+
)
570+
571+
matchedOverrides.forEach((file) =>
572+
console.log(` - ${chalk.cyan(p.relative(projectDir, file))}`)
573+
)
574+
575+
console.log('')
576+
577+
// Report on unmatched overrides using template literals
578+
console.log(
579+
unmatchedOverrides.length
556580
? chalk.yellow(
557-
`Found ${unusedOverrides.length} override files that don't match any overridable imports:`
581+
`Found ${unmatchedOverrides.length} override files that don't match any overridable imports:`
558582
)
559583
: chalk.green(
560584
`All ${allOverrideFiles.length} override files correspond to overridable imports.`
561585
)
562586
)
563587

564-
unusedOverrides.forEach((file) =>
588+
unmatchedOverrides.forEach((file) =>
565589
console.log(` - ${p.relative(projectDir, file)}`)
566590
)
567591

packages/pwa-kit-extension-sdk/src/shared/utils/overridables.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,33 +140,33 @@ export const hasCorrespondingOverridableImport = (
140140

141141
// Get the relative path from the overrides directory
142142
const relativePath = path.relative(baseDir, overrideFile)
143-
143+
144144
// Split the path into parts to extract extension name and component path
145145
const pathParts = relativePath.split(path.sep)
146-
146+
147147
// The first part should be the extension name
148148
const extensionName = pathParts[0]
149-
149+
150150
// Extract the file name without extension
151151
const fileName = path.basename(overrideFile).replace(/\.[^/.]+$/, '')
152-
152+
153153
// For each overridable import, check if it matches our override file
154154
return overridableImports.some(({importPath, extension}) => {
155155
// Clean up the import path (remove ./ prefix if present)
156156
const cleanImportPath = importPath.replace(/^\.\//, '')
157-
157+
158158
// Get the file name from the import path
159159
const importFileName = path.basename(cleanImportPath)
160-
160+
161161
// Check if the file name matches
162162
const fileNameMatches = importFileName === fileName
163-
163+
164164
// Check if the extension matches (if provided)
165165
const extensionMatches = extension ? extension.includes(extensionName) : false
166-
166+
167167
// For extension imports, we need both the file name and extension to match
168168
// For non-extension imports, just the file name needs to match
169-
return extension ? (fileNameMatches && extensionMatches) : fileNameMatches
169+
return extension ? fileNameMatches && extensionMatches : fileNameMatches
170170
})
171171
}
172172

0 commit comments

Comments
 (0)