(input: CmdRunContext)
| 12 | const WARN_CONCURRENCY_COUNT = 30; |
| 13 | |
| 14 | export default async function execute(input: CmdRunContext) { |
| 15 | const effectiveConcurrency = Math.min( |
| 16 | input.flags.concurrency, |
| 17 | input.tasks.length, |
| 18 | ); |
| 19 | |
| 20 | if (effectiveConcurrency >= WARN_CONCURRENCY_COUNT) { |
| 21 | console.warn( |
| 22 | chalk.yellow( |
| 23 | `⚠️ High concurrency (${effectiveConcurrency}) may cause failures in some environments.`, |
| 24 | ), |
| 25 | ); |
| 26 | } |
| 27 | |
| 28 | console.log(chalk.hex(colors.orange)(`[Localization]`)); |
| 29 | |
| 30 | return new Listr<CmdRunContext>( |
| 31 | [ |
| 32 | { |
| 33 | title: "Initializing localization engine", |
| 34 | task: async (ctx, task) => { |
| 35 | task.title = `Localization engine ${chalk.hex(colors.green)("ready")} (${ctx.localizer!.id})`; |
| 36 | }, |
| 37 | }, |
| 38 | { |
| 39 | title: `Processing localization tasks ${chalk.dim( |
| 40 | `(tasks: ${input.tasks.length}, concurrency: ${effectiveConcurrency})`, |
| 41 | )}`, |
| 42 | task: async (ctx, task) => { |
| 43 | if (input.tasks.length < 1) { |
| 44 | task.title = `Skipping, nothing to localize.`; |
| 45 | task.skip(); |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | // Preload checksums for all unique bucket path patterns before starting any workers |
| 50 | const initialChecksumsMap = new Map<string, Record<string, string>>(); |
| 51 | const uniqueBucketPatterns = _.uniq( |
| 52 | ctx.tasks.map((t) => t.bucketPathPattern), |
| 53 | ); |
| 54 | for (const bucketPathPattern of uniqueBucketPatterns) { |
| 55 | const deltaProcessor = createDeltaProcessor(bucketPathPattern); |
| 56 | const checksums = await deltaProcessor.loadChecksums(); |
| 57 | initialChecksumsMap.set(bucketPathPattern, checksums); |
| 58 | } |
| 59 | |
| 60 | const i18nLimiter = pLimit(effectiveConcurrency); |
| 61 | const ioLimiter = pLimit(1); |
| 62 | |
| 63 | const perFileIoLimiters = new Map<string, LimitFunction>(); |
| 64 | const getFileIoLimiter = ( |
| 65 | bucketPathPattern: string, |
| 66 | ): LimitFunction => { |
| 67 | const lockKey = bucketPathPattern; |
| 68 | |
| 69 | if (!perFileIoLimiters.has(lockKey)) { |
| 70 | perFileIoLimiters.set(lockKey, pLimit(1)); |
| 71 | } |
no test coverage detected