From 421c663dc453ebe5e06aa52f0185d8a47e989ed4 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 26 Dec 2024 12:53:22 +0100 Subject: [PATCH] build: patch `string-width` for node 14 support --- build.config.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/build.config.ts b/build.config.ts index 2bdbacf6..87e64a03 100644 --- a/build.config.ts +++ b/build.config.ts @@ -10,6 +10,20 @@ export default defineBuildConfig({ // @ts-ignore output.exports = "named"; } + + // Node.js 14 support + // https://github.com/unjs/consola/issues/204 + options.plugins.push({ + name: "icu-compat", + transform(code, id) { + if (id.endsWith("string-width/index.js")) { + return code.replace( + "const segmenter = new Intl.Segmenter();", + "const segmenter = globalThis.Intl?.Segmenter ? new Intl.Segmenter() : { segment: (str) => str.split('') };", + ); + } + }, + }); }, }, });