wallet-core/packages/taler-wallet-webextension/trim-extension.cjs

26 lines
762 B
JavaScript
Raw Normal View History

2023-02-16 02:49:27 +01:00
// Simple plugin to trim extensions from the filename of relative import statements.
2023-05-05 13:47:00 +02:00
// Required to get linaria to work with `moduleResolution: "Node16"` imports.
2023-02-16 02:49:27 +01:00
// @author Florian Dold
2023-05-05 13:47:00 +02:00
//
module.exports = function ({ types: t }) {
2023-02-16 02:49:27 +01:00
return {
name: "trim-extension",
visitor: {
ImportDeclaration: (x) => {
const src = x.node.source;
2023-02-16 03:23:42 +01:00
if (src.value.startsWith(".")) {
2023-02-16 02:49:27 +01:00
if (src.value.endsWith(".js")) {
2023-05-05 13:47:00 +02:00
const newVal = src.value.replace(/[.]js$/, "");
2023-02-16 02:49:27 +01:00
x.node.source = t.stringLiteral(newVal);
}
}
if (src.value.endsWith(".jsx")) {
2023-05-05 13:47:00 +02:00
const newVal = src.value.replace(/[.]jsx$/, "");
2023-02-16 02:49:27 +01:00
x.node.source = t.stringLiteral(newVal);
}
},
2023-05-05 13:47:00 +02:00
},
2023-02-16 02:49:27 +01:00
};
2023-05-05 13:47:00 +02:00
};