// Regenerate using the dev dependencies in the current lockfile. // Production uses the generated CommonJS data, including on Node 22.0. const fs = require('node:fs'); const path = require('node:path'); const root = path.dirname(require.resolve('get-east-asian-width')); const version = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')).version; if (version !== '1.5.0') throw new Error(`Expected locked get-east-asian-width 1.5.0; found ${version}`); const source = fs.readFileSync(path.join(root, 'lookup-data.js'), 'utf8'); const license = fs.readFileSync(path.join(root, 'license'), 'utf8'); let output = '// Generated by node scripts/generate-terminal-width-data.cjs\n' + '// Unicode 17.0.0 W/F data from get-east-asian-width 1.5.0:\n' + '// https://github.com/sindresorhus/get-east-asian-width/tree/v1.5.0\n' + '/*\n' + license.trim() + '\n*/\n\n'; for (const name of ['fullwidthRanges', 'wideRanges']) { const match = source.match(new RegExp(`const ${name} = (\\[[^\\]]+\\]);`)); if (!match) throw new Error(`Missing source data: ${name}`); const values = JSON.parse(match[1]); output += `const ${name} = [\n`; for (let i = 0; i < values.length; i += 12) output += ` ${values.slice(i, i + 12).join(', ')},\n`; output += '];\n\n'; } output += 'module.exports = { fullwidthRanges, wideRanges };\n'; const target = path.join(__dirname, '../electron/bridges/terminalWidthData.cjs'); if (process.argv.includes('--check')) { if (fs.readFileSync(target, 'utf8') !== output) throw new Error('Terminal width data is out of date'); } else fs.writeFileSync(target, output);