Skip to content

Commit f156b6d

Browse files
committed
Refactor with-intl files
1 parent 4a9419d commit f156b6d

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

packages/php-wasm/node/src/lib/extensions/intl/with-intl.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ export async function withIntl(
1111
version: SupportedPHPVersion = LatestSupportedPHPVersion,
1212
options: EmscriptenOptions
1313
): Promise<EmscriptenOptions> {
14-
const extensionName = 'intl.so';
15-
const extensionPath = await getIntlExtensionModule(version);
16-
const extension = fs.readFileSync(extensionPath);
17-
14+
/*
15+
* The Intl extension is hard-coded to look for the `icudt74l` filename,
16+
* which means the ICU data file must use that exact name.
17+
*/
1818
const dataName = 'icu.dat';
1919
const dataPath = `${__dirname}/shared/${dataName}`;
2020
const ICUData = fs.readFileSync(dataPath);
2121

22+
const extensionName = 'intl.so';
23+
const extensionPath = await getIntlExtensionModule(version);
24+
const extension = fs.readFileSync(extensionPath);
25+
2226
return {
2327
...options,
2428
ENV: {
@@ -75,9 +79,6 @@ export async function withIntl(
7579
* via the ICU_DATA environment variable.
7680
* By default, this variable is set to '/internal/shared',
7781
* which corresponds to the actual file location.
78-
*
79-
* The Intl extension is hard-coded to look for the `icudt74l` filename,
80-
* which means the ICU data file must use that exact name.
8182
*/
8283
if (
8384
!FSHelpers.fileExists(
@@ -87,7 +88,7 @@ export async function withIntl(
8788
) {
8889
phpRuntime.FS.mkdirTree(phpRuntime.ENV.ICU_DATA);
8990
phpRuntime.FS.writeFile(
90-
`${phpRuntime.ENV.ICU_DATA}/icudt74l.dat`,
91+
`${phpRuntime.ENV.ICU_DATA}/${dataName}`,
9192
new Uint8Array(ICUData)
9293
);
9394
}

packages/php-wasm/web/src/lib/extensions/intl/with-intl.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,21 @@ export async function withIntl(
1313
): Promise<EmscriptenOptions> {
1414
const memoizedFetch = createMemoizedFetch(fetch);
1515

16+
/*
17+
* The Intl extension is hard-coded to look for the `icudt74l` filename,
18+
* which means the ICU data file must use that exact name.
19+
*/
20+
const dataName = 'icudt74l.dat';
1621
const extensionName = 'intl.so';
17-
const dataName = 'icu.dat';
1822

19-
const extensionPath = await getIntlExtensionModule(version);
2023
// @ts-ignore
2124
const dataPath = (await import('../../../../public/shared/icu.dat'))
2225
.default;
26+
const extensionPath = await getIntlExtensionModule(version);
2327

24-
const [extension, ICUData] = await Promise.all([
25-
memoizedFetch(extensionPath).then((response) => response.arrayBuffer()),
28+
const [ICUData, extension] = await Promise.all([
2629
memoizedFetch(dataPath).then((response) => response.arrayBuffer()),
30+
memoizedFetch(extensionPath).then((response) => response.arrayBuffer()),
2731
]);
2832

2933
return {
@@ -82,19 +86,16 @@ export async function withIntl(
8286
* via the ICU_DATA environment variable.
8387
* By default, this variable is set to '/internal/shared',
8488
* which corresponds to the actual file location.
85-
*
86-
* The Intl extension is hard-coded to look for the `icudt74l` filename,
87-
* which means the ICU data file must use that exact name.
8889
*/
8990
if (
9091
!FSHelpers.fileExists(
9192
phpRuntime.FS,
92-
`${phpRuntime.ENV.ICU_DATA}/icudt74l.dat`
93+
`${phpRuntime.ENV.ICU_DATA}/${dataName}`
9394
)
9495
) {
9596
phpRuntime.FS.mkdirTree(phpRuntime.ENV.ICU_DATA);
9697
phpRuntime.FS.writeFile(
97-
`${phpRuntime.ENV.ICU_DATA}/icudt74l.dat`,
98+
`${phpRuntime.ENV.ICU_DATA}/${dataName}`,
9899
new Uint8Array(ICUData)
99100
);
100101
}

0 commit comments

Comments
 (0)