({
workPath,
files: appFiles,
pythonMajor,
pythonMinor,
}: {
workPath: string;
files: Files;
pythonMajor: number;
pythonMinor: number;
})
| 152 | } |
| 153 | |
| 154 | export async function collectAppBytecodeFiles({ |
| 155 | workPath, |
| 156 | files: appFiles, |
| 157 | pythonMajor, |
| 158 | pythonMinor, |
| 159 | }: { |
| 160 | workPath: string; |
| 161 | files: Files; |
| 162 | pythonMajor: number; |
| 163 | pythonMinor: number; |
| 164 | }): Promise<BytecodeCollectionResult> { |
| 165 | const pending: { bundlePath: string; srcFsPath: string }[] = []; |
| 166 | |
| 167 | for (const bundlePath of Object.keys(appFiles)) { |
| 168 | const pycRel = derivePycPath(bundlePath, pythonMajor, pythonMinor); |
| 169 | if (!pycRel) continue; |
| 170 | |
| 171 | pending.push({ |
| 172 | bundlePath: pycRel, |
| 173 | srcFsPath: join(workPath, pycRel.replaceAll('/', sep)), |
| 174 | }); |
| 175 | } |
| 176 | |
| 177 | const results = await Promise.all( |
| 178 | pending.map(async ({ bundlePath, srcFsPath }) => { |
| 179 | try { |
| 180 | const stats = await fs.promises.stat(srcFsPath); |
| 181 | return { bundlePath, srcFsPath, size: stats.size }; |
| 182 | } catch { |
| 183 | return null; |
| 184 | } |
| 185 | }) |
| 186 | ); |
| 187 | |
| 188 | const files: Files = {}; |
| 189 | const perItemSizes = new Map<string, number>(); |
| 190 | let totalSize = 0; |
| 191 | |
| 192 | for (const result of results) { |
| 193 | if (!result) continue; |
| 194 | files[result.bundlePath] = new FileFsRef({ |
| 195 | fsPath: result.srcFsPath, |
| 196 | size: result.size, |
| 197 | }); |
| 198 | perItemSizes.set(result.bundlePath, result.size); |
| 199 | totalSize += result.size; |
| 200 | } |
| 201 | |
| 202 | return { files, totalSize, perItemSizes }; |
| 203 | } |
no test coverage detected