-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix SEGFAULT error by
new Intl.Segmenter().segment()
in the standal…
…one binary Baking the compatible ICU data with the Node binary.
- Loading branch information
Showing
2 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* For baking the ICU data into the standalone binary, we need to download the compatible ICU data from the ICU repository. */ | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { promisify } from 'node:util' | ||
import yauzl from 'yauzl' | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
const icuDir = path.join(__dirname, '../tmp/icu') | ||
await fs.promises.mkdir(icuDir, { recursive: true }) | ||
|
||
const zipFromBuffer = promisify(yauzl.fromBuffer) | ||
|
||
// Get the ICU version and endianness | ||
const [icuMajor, icuMinor] = process.versions.icu.split('.') | ||
const icuEndianness = process.config.variables.icu_endianness.toLowerCase() | ||
|
||
// Download the ICU data | ||
const response = await fetch( | ||
`https://github.com/unicode-org/icu/releases/download/release-${icuMajor}-${icuMinor}/icu4c-${icuMajor}_${icuMinor}-data-bin-${icuEndianness}.zip` | ||
) | ||
|
||
if (!response.ok) { | ||
throw new Error(`Failed to download ICU data: ${response.statusText}`) | ||
} | ||
|
||
// Extract the ICU data | ||
const zip = await zipFromBuffer(Buffer.from(await response.arrayBuffer()), { | ||
lazyEntries: true, | ||
}) | ||
|
||
const icuDat = await new Promise((res, rej) => { | ||
zip.on('error', (err) => rej(err)) | ||
zip.on('entry', async (entry) => { | ||
if (/icudt\d+.\.dat/.test(entry.fileName)) { | ||
zip.openReadStream(entry, (err, readStream) => { | ||
if (err) return rej(err) | ||
|
||
const output = path.join(icuDir, entry.fileName) | ||
|
||
readStream.pipe(fs.createWriteStream(output)) | ||
res(output) | ||
}) | ||
} else { | ||
zip.readEntry() | ||
} | ||
}) | ||
zip.on('end', () => rej(meta)) | ||
zip.readEntry() | ||
}) | ||
|
||
// Print the relative path to the ICU data from the project root | ||
console.log(path.relative(path.join(__dirname, '../'), icuDat)) |