<commit_before>// @ts-check
const {PLATFORM, getDestDir} = require('./paths');
const reload = require('./reload');
const {createTask} = require('./task');
const {readFile, writeFile} = require('./utils');

const srcDir = 'src';

async function readJSON(path) {
    const file = await readFile(path);
    return JSON.parse(file);
}

async function writeJSON(path, json) {
    const content = JSON.stringify(json, null, 4);
    return await writeFile(path, content);
}

async function patchManifest(platform) {
    const manifest = await readJSON(`${srcDir}/manifest.json`);
    const manifestPatch = platform === PLATFORM.CHROME ? {} : await readJSON(`${srcDir}/manifest-${platform}.json`);
    const pacthed = {...manifest, ...manifestPatch};
    if (platform === PLATFORM.CHROME_MV3) {
        pacthed.browser_action = undefined;
    }
    return pacthed;
}

async function manifests({platforms, debug}) {
    for (const platform of Object.values(PLATFORM).filter((platform) => platforms[platform])) {
        const manifest = await patchManifest(platform);
        const destDir = getDestDir({debug, platform});
        await writeJSON(`${destDir}/manifest.json`, manifest);
    }
}

module.exports = createTask(
    'bundle-manifest',
    manifests,
).addWatcher(<commit_msg>Fix typo within patchManifest (#9266)<commit_after>// @ts-check
const {PLATFORM, getDestDir} = require('./paths');
const reload = require('./reload');
const {createTask} = require('./task');
const {readFile, writeFile} = require('./utils');

const srcDir = 'src';

async function readJSON(path) {
    const file = await readFile(path);
    return JSON.parse(file);
}

async function writeJSON(path, json) {
    const content = JSON.stringify(json, null, 4);
    return await writeFile(path, content);
}

async function patchManifest(platform) {
    const manifest = await readJSON(`${srcDir}/manifest.json`);
    const manifestPatch = platform === PLATFORM.CHROME ? {} : await readJSON(`${srcDir}/manifest-${platform}.json`);
    const patched = {...manifest, ...manifestPatch};
    if (platform === PLATFORM.CHROME_MV3) {
        patched.browser_action = undefined;
    }
    return patched;
}

async function manifests({platforms, debug}) {
    for (const platform of Object.values(PLATFORM).filter((platform) => platforms[platform])) {
        const manifest = await patchManifest(platform);
        const destDir = getDestDir({debug, platform});
        await writeJSON(`${destDir}/manifest.json`, manifest);
    }
}

module.exports = createTask(
    'bundle-manifest',
    manifests,
).addWatcher(
{'fraction_non_alphanumeric': 0.15310077519379844, 'fraction_numerical': 0.0031007751937984496, 'mean_word_length': 4.110891089108911, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7626221', 'n_tokens_mistral': 770, 'n_tokens_neox': 753, 'n_words': 185}