Skip to content

Commit

Permalink
build: patch string-width for node 14 support
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 26, 2024
1 parent 4429f8f commit 421c663
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('') };",
);
}
},
});
},
},
});

0 comments on commit 421c663

Please sign in to comment.