|
1 | 1 | import { createWriteStream } from 'node:fs'
|
2 |
| -import { cp, rm } from 'node:fs/promises' |
| 2 | +import { cp, readFile, rm } from 'node:fs/promises' |
3 | 3 | import { join, resolve } from 'node:path'
|
4 | 4 | import { Readable } from 'stream'
|
5 | 5 | import { finished } from 'stream/promises'
|
@@ -126,8 +126,38 @@ await Promise.all([
|
126 | 126 | cp('src/build/templates', join(OUT_DIR, 'build/templates'), { recursive: true, force: true }),
|
127 | 127 | ])
|
128 | 128 |
|
| 129 | +async function ensureNoRegionalBlobsModuleDuplicates() { |
| 130 | + const REGIONAL_BLOB_STORE_CONTENT_TO_FIND = 'fetchBeforeNextPatchedIt' |
| 131 | + |
| 132 | + const filesToTest = await glob(join(OUT_DIR, '**/*.{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 | + |
129 | 157 | if (watch) {
|
130 | 158 | console.log('Starting compilation in watch mode...')
|
131 | 159 | } else {
|
| 160 | + await ensureNoRegionalBlobsModuleDuplicates() |
| 161 | + |
132 | 162 | console.log('Finished building 🎉')
|
133 | 163 | }
|
0 commit comments