aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/trim-extension.cjs
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-webextension/trim-extension.cjs')
-rw-r--r--packages/taler-wallet-webextension/trim-extension.cjs23
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/taler-wallet-webextension/trim-extension.cjs b/packages/taler-wallet-webextension/trim-extension.cjs
new file mode 100644
index 000000000..4305e792b
--- /dev/null
+++ b/packages/taler-wallet-webextension/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);
+ }
+ },
+ }
+ };
+}