Skip to content

Commit 421c663

Browse files
committed
build: patch string-width for node 14 support
1 parent 4429f8f commit 421c663

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

build.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ export default defineBuildConfig({
1010
// @ts-ignore
1111
output.exports = "named";
1212
}
13+
14+
// Node.js 14 support
15+
// https://github.com/unjs/consola/issues/204
16+
options.plugins.push({
17+
name: "icu-compat",
18+
transform(code, id) {
19+
if (id.endsWith("string-width/index.js")) {
20+
return code.replace(
21+
"const segmenter = new Intl.Segmenter();",
22+
"const segmenter = globalThis.Intl?.Segmenter ? new Intl.Segmenter() : { segment: (str) => str.split('') };",
23+
);
24+
}
25+
},
26+
});
1327
},
1428
},
1529
});

0 commit comments

Comments
 (0)