Skip to content

Commit 7dab825

Browse files
committed
chore: add some validation to bundling to ensure we don't produce duplicate/inling of regional-blob-store module in unexptected built modules
1 parent 23b1f37 commit 7dab825

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tools/build.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,38 @@ await Promise.all([
126126
cp('src/build/templates', join(OUT_DIR, 'build/templates'), { recursive: true, force: true }),
127127
])
128128

129+
async function ensureNoRegionalBlobsModuleDuplicates() {
130+
const REGIONAL_BLOB_STORE_CONTENT_TO_FIND = 'fetchBeforeNextPatchedIt'
131+
132+
const filesToTest = await glob('dist/**/*.{js,cjs}')
133+
const unexpectedModulesContainingFetchBeforeNextPatchedIt = []
134+
let foundInExpectedModule = false
135+
for (const fileToTest of filesToTest) {
136+
const content = await readFile(fileToTest, 'utf-8')
137+
if (content.includes(REGIONAL_BLOB_STORE_CONTENT_TO_FIND)) {
138+
if (fileToTest.endsWith('run/regional-blob-store.cjs')) {
139+
foundInExpectedModule = true
140+
} else {
141+
unexpectedModulesContainingFetchBeforeNextPatchedIt.push(fileToTest)
142+
}
143+
}
144+
}
145+
if (!foundInExpectedModule) {
146+
throw new Error(
147+
'Expected to find fetchBeforeNextPatchedIt in run/regional-blob-store.cjs, but it was not found. This might indicate setup change that require bundling validation to be adjusted.',
148+
)
149+
}
150+
if (unexpectedModulesContainingFetchBeforeNextPatchedIt.length !== 0) {
151+
throw new Error(
152+
`Bundling produced unexpected duplicates of 'regional-blob-store' module in following built modules:\n${unexpectedModulesContainingFetchBeforeNextPatchedIt.map((filePath) => ` - ${filePath}`).join('\n')}`,
153+
)
154+
}
155+
}
156+
129157
if (watch) {
130158
console.log('Starting compilation in watch mode...')
131159
} else {
160+
await ensureNoRegionalBlobsModuleDuplicates()
161+
132162
console.log('Finished building 🎉')
133163
}

0 commit comments

Comments
 (0)