diff options
| author | Sebastian <sebasjm@gmail.com> | 2023-03-02 13:51:03 -0300 |
|---|---|---|
| committer | Sebastian <sebasjm@gmail.com> | 2023-03-02 13:51:03 -0300 |
| commit | 2d5fbb22cdf6cde10004cea174fc90e71668746b (patch) | |
| tree | 21be3694b459fa59f110d87346160dd048d2a280 /packages/merchant-backend-ui/trim-extension.cjs | |
| parent | f446a5921487c7196904f9aab00fc189ac6a9e3b (diff) | |
fix #7714
Diffstat (limited to 'packages/merchant-backend-ui/trim-extension.cjs')
| -rw-r--r-- | packages/merchant-backend-ui/trim-extension.cjs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/merchant-backend-ui/trim-extension.cjs b/packages/merchant-backend-ui/trim-extension.cjs new file mode 100644 index 000000000..00e8f9f01 --- /dev/null +++ b/packages/merchant-backend-ui/trim-extension.cjs @@ -0,0 +1,23 @@ +// Simple plugin to trim extensions from the filename of relative import statements. +// Required to get linaria to work with `moduleResulution: "Node16"` imports. +// @author Florian Dold +module.exports = function({ types: t }) { + return { + name: "trim-extension", + visitor: { + ImportDeclaration: (x) => { + const src = x.node.source; + if (src.value.startsWith(".")) { + if (src.value.endsWith(".js")) { + const newVal = src.value.replace(/[.]js$/, "") + x.node.source = t.stringLiteral(newVal); + } + } + if (src.value.endsWith(".jsx")) { + const newVal = src.value.replace(/[.]jsx$/, "") + x.node.source = t.stringLiteral(newVal); + } + }, + } + }; +} |
