Skip to content

Commit dc2ceee

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 dc2ceee

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

tools/build.js

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createWriteStream } from 'node:fs'
2-
import { cp, rm } from 'node:fs/promises'
3-
import { join, resolve } from 'node:path'
2+
import { cp, readFile, rm } from 'node:fs/promises'
43
import { Readable } from 'stream'
54
import { finished } from 'stream/promises'
65

@@ -126,8 +125,38 @@ await Promise.all([
126125
cp('src/build/templates', join(OUT_DIR, 'build/templates'), { recursive: true, force: true }),
127126
])
128127

128+
async function ensureNoRegionalBlobsModuleDuplicates() {
129+
const REGIONAL_BLOB_STORE_CONTENT_TO_FIND = 'fetchBeforeNextPatchedIt'
130+
131+
const filesToTest = await glob('dist/**/*.{js,cjs}')
132+
const unexpectedModulesContainingFetchBeforeNextPatchedIt = []
133+
let foundInExpectedModule = false
134+
for (const fileToTest of filesToTest) {
135+
const content = await readFile(fileToTest, 'utf-8')
136+
if (content.includes(REGIONAL_BLOB_STORE_CONTENT_TO_FIND)) {
137+
if (fileToTest.endsWith('run/regional-blob-store.cjs')) {
138+
foundInExpectedModule = true
139+
} else {
140+
unexpectedModulesContainingFetchBeforeNextPatchedIt.push(fileToTest)
141+
}
142+
}
143+
}
144+
if (!foundInExpectedModule) {
145+
throw new Error(
146+
'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.',
147+
)
148+
}
149+
if (unexpectedModulesContainingFetchBeforeNextPatchedIt.length !== 0) {
150+
throw new Error(
151+
`Bundling produced unexpected duplicates of 'regional-blob-store' module in following built modules:\n${unexpectedModulesContainingFetchBeforeNextPatchedIt.map((filePath) => ` - ${filePath}`).join('\n')}`,
152+
)
153+
}
154+
}
155+
129156
if (watch) {
130157
console.log('Starting compilation in watch mode...')
131158
} else {
159+
await ensureNoRegionalBlobsModuleDuplicates()
160+
132161
console.log('Finished building 🎉')
133162
}

0 commit comments

Comments
 (0)