Mirror: Modular GraphQL.js import paths without the hassle.

Replace esm option with extension

Changed files
+7 -2
+7 -2
index.js
···
-
module.exports = function babelPluginModularGraphql({ types: t }, { esm } = { esm: false }) {
+
module.exports = function babelPluginModularGraphql({ types: t }, options = {}) {
+
let extension = (options.extension || '').trim();
+
if (extension && extension[0] !== '.') {
+
extension = '.' + extension;
+
}
+
const importMap = require('./import-map.json');
const importMapOverrides = require('./import-map-overrides.json');
const PKG_NAME = 'graphql';
···
const from = declaration ? declaration.from : PKG_NAME;
if (!acc[from]) {
-
acc[from] = t.importDeclaration([], t.stringLiteral(from + esm ? '.mjs' : '.js'));
+
acc[from] = t.importDeclaration([], t.stringLiteral(from + extension));
}
const localName = specifier.local.name;