summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/trim-extension.cjs
blob: 256a9f48d9d6391a524e7ee6559c9f8f6a1e7ef6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Simple plugin to trim extensions from the filename of relative import statements.
// Required to get linaria to work with `moduleResolution: "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);
        }
      },
    },
  };
};