babel-plugin-tiny-import
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -12,5 +12,5 @@ | ||
} | ||
const { basename, resolve, resolvePackageAsAbsolute, filename } = opts | ||
if (typeof resolve === 'function') { | ||
return resolve(path, opts); | ||
const { basename, resolve: _resolve, resolvePackageAsAbsolute, filename } = opts | ||
if (typeof _resolve === 'function') { | ||
return _resolve(path, opts); | ||
} | ||
@@ -30,2 +30,3 @@ | ||
basedir: filename ? nps.dirname(filename): undefined, | ||
preserveSymlinks: false, | ||
...(typeof resolvePackageAsAbsolute === 'object' ? resolvePackageAsAbsolute : {}) | ||
@@ -89,3 +90,3 @@ }) | ||
var key = node.left.property.name; | ||
var moduleName = resolve(node.right.arguments[0].value, obj.basename); | ||
var moduleName = resolve(node.right.arguments[0].value, obj); | ||
@@ -92,0 +93,0 @@ map[key] = moduleName |
@@ -66,3 +66,5 @@ /** | ||
function packModuleMapper(moduleMapper) { | ||
function packModuleMapper(state) { | ||
let { moduleMapper, resolveFromRelative = true } = state.opts || {}; | ||
const resolveFromFile = state.file && state.file.opts && state.file.opts.filename || state.filename; | ||
assertModuleMapper(moduleMapper); | ||
@@ -85,10 +87,22 @@ | ||
} | ||
return moduleMapper; | ||
return function () { | ||
const finalResult = moduleMapper.apply(this, arguments) | ||
if (!finalResult) { | ||
return finalResult | ||
} | ||
if (finalResult.moduleName && resolveFromRelative && resolveFromFile && nps.posix.isAbsolute(finalResult.moduleName)) { | ||
return { | ||
...finalResult, | ||
moduleName: nps.posix.join('.', nps.relative(resolveFromFile, finalResult.moduleName)), | ||
} | ||
} | ||
return finalResult | ||
}; | ||
} | ||
function getImportOrExportDeclarationMultipleNodes(map, { | ||
moduleMapper, moduleName, state, isImport = true | ||
moduleName, state, isImport = true | ||
}) { | ||
var ignoreMap = state.ignoreMap; | ||
moduleMapper = packModuleMapper(moduleMapper); | ||
const moduleMapper = packModuleMapper(state); | ||
@@ -225,3 +239,2 @@ return Object.keys(map).map(function (local) { | ||
getImportOrExportDeclarationMultipleNodes(map, { | ||
moduleMapper: state.opts.moduleMapper, | ||
moduleName: path.node.source.value, | ||
@@ -241,3 +254,3 @@ state: this, | ||
getImportOrExportDeclarationMultipleNodes(map, { | ||
moduleMapper: state.opts.moduleMapper, moduleName: path.node.source.value, state: this, | ||
moduleName: path.node.source.value, state: this, | ||
isImport: false | ||
@@ -271,3 +284,3 @@ }), | ||
}); | ||
var moduleMapper = packModuleMapper(state.opts.moduleMapper); | ||
var moduleMapper = packModuleMapper(state); | ||
var moduleName = node.init.arguments[0].value; | ||
@@ -274,0 +287,0 @@ var restArguments = node.init.arguments.slice(1); |
{ | ||
"name": "babel-plugin-tiny-import", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "split import from wrap package", | ||
@@ -5,0 +5,0 @@ "private": false, |
22584
444