@tamagui/babel-plugin-fully-specified
Advanced tools
Comparing version 1.111.8 to 1.111.9
@@ -6,8 +6,4 @@ import { existsSync, lstatSync } from "node:fs"; | ||
esExtensionDefault: ".mjs", | ||
tryExtensions: [ | ||
".js" | ||
], | ||
esExtensions: [ | ||
".mjs" | ||
] | ||
tryExtensions: [".js"], | ||
esExtensions: [".mjs"] | ||
}; | ||
@@ -17,47 +13,57 @@ function FullySpecified(api, rawOptions) { | ||
var options = { | ||
...DEFAULT_OPTIONS, | ||
...rawOptions | ||
}, importDeclarationVisitor = function(path, state) { | ||
var filePath = state.file.opts.filename; | ||
if (filePath) { | ||
var { node } = path; | ||
if (node.importKind !== "type") { | ||
var originalModuleSpecifier = node.source.value, fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(originalModuleSpecifier, { | ||
filePath, | ||
options | ||
}); | ||
fullySpecifiedModuleSpecifier && (node.source.value = fullySpecifiedModuleSpecifier); | ||
...DEFAULT_OPTIONS, | ||
...rawOptions | ||
}, | ||
importDeclarationVisitor = function (path, state) { | ||
var filePath = state.file.opts.filename; | ||
if (filePath) { | ||
var { | ||
node | ||
} = path; | ||
if (node.importKind !== "type") { | ||
var originalModuleSpecifier = node.source.value, | ||
fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(originalModuleSpecifier, { | ||
filePath, | ||
options | ||
}); | ||
fullySpecifiedModuleSpecifier && (node.source.value = fullySpecifiedModuleSpecifier); | ||
} | ||
} | ||
} | ||
}, exportDeclarationVisitor = function(path, state) { | ||
var filePath = state.file.opts.filename; | ||
if (filePath) { | ||
var { node } = path; | ||
if (node.exportKind !== "type") { | ||
var source = node.source; | ||
if (source) { | ||
var originalModuleSpecifier = source.value, fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(originalModuleSpecifier, { | ||
filePath, | ||
options | ||
}); | ||
fullySpecifiedModuleSpecifier && (source.value = fullySpecifiedModuleSpecifier); | ||
}, | ||
exportDeclarationVisitor = function (path, state) { | ||
var filePath = state.file.opts.filename; | ||
if (filePath) { | ||
var { | ||
node | ||
} = path; | ||
if (node.exportKind !== "type") { | ||
var source = node.source; | ||
if (source) { | ||
var originalModuleSpecifier = source.value, | ||
fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(originalModuleSpecifier, { | ||
filePath, | ||
options | ||
}); | ||
fullySpecifiedModuleSpecifier && (source.value = fullySpecifiedModuleSpecifier); | ||
} | ||
} | ||
} | ||
} | ||
}, importVisitor = function(path, state) { | ||
var filePath = state.file.opts.filename; | ||
if (filePath) { | ||
var parent = path.parent; | ||
if (parent.type === "CallExpression") { | ||
var firstArgOfImportCall = parent.arguments[0]; | ||
if (firstArgOfImportCall.type === "StringLiteral") { | ||
var originalModuleSpecifier = firstArgOfImportCall.value, fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(originalModuleSpecifier, { | ||
filePath, | ||
options | ||
}); | ||
fullySpecifiedModuleSpecifier && (firstArgOfImportCall.value = fullySpecifiedModuleSpecifier); | ||
}, | ||
importVisitor = function (path, state) { | ||
var filePath = state.file.opts.filename; | ||
if (filePath) { | ||
var parent = path.parent; | ||
if (parent.type === "CallExpression") { | ||
var firstArgOfImportCall = parent.arguments[0]; | ||
if (firstArgOfImportCall.type === "StringLiteral") { | ||
var originalModuleSpecifier = firstArgOfImportCall.value, | ||
fullySpecifiedModuleSpecifier = getFullySpecifiedModuleSpecifier(originalModuleSpecifier, { | ||
filePath, | ||
options | ||
}); | ||
fullySpecifiedModuleSpecifier && (firstArgOfImportCall.value = fullySpecifiedModuleSpecifier); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
return { | ||
@@ -74,8 +80,39 @@ name: "babel-plugin-fully-specified", | ||
function getFullySpecifiedModuleSpecifier(originalModuleSpecifier, param) { | ||
var { filePath, options } = param, fileExt = extname(filePath), fileDir = dirname(filePath), isDirectory = isLocalDirectory(resolve(fileDir, originalModuleSpecifier)), currentModuleExtension = extname(originalModuleSpecifier), { tryExtensions, esExtensions, esExtensionDefault, ensureFileExists } = options, targetModule = evaluateTargetModule({ | ||
moduleSpecifier: originalModuleSpecifier, | ||
filenameDirectory: fileDir, | ||
filenameExtension: fileExt, | ||
var { | ||
filePath, | ||
options | ||
} = param, | ||
fileExt = extname(filePath), | ||
fileDir = dirname(filePath), | ||
isDirectory = isLocalDirectory(resolve(fileDir, originalModuleSpecifier)), | ||
currentModuleExtension = extname(originalModuleSpecifier), | ||
{ | ||
tryExtensions, | ||
esExtensions, | ||
esExtensionDefault, | ||
ensureFileExists | ||
} = options, | ||
targetModule = evaluateTargetModule({ | ||
moduleSpecifier: originalModuleSpecifier, | ||
filenameDirectory: fileDir, | ||
filenameExtension: fileExt, | ||
currentModuleExtension, | ||
isDirectory, | ||
tryExtensions, | ||
esExtensions, | ||
esExtensionDefault, | ||
ensureFileExists | ||
}); | ||
return targetModule === !1 ? null : targetModule; | ||
} | ||
function isLocalDirectory(absoluteDirectory) { | ||
return existsSync(absoluteDirectory) && lstatSync(absoluteDirectory).isDirectory(); | ||
} | ||
function evaluateTargetModule(param) { | ||
var { | ||
moduleSpecifier, | ||
currentModuleExtension, | ||
isDirectory, | ||
filenameDirectory, | ||
filenameExtension, | ||
tryExtensions, | ||
@@ -85,21 +122,14 @@ esExtensions, | ||
ensureFileExists | ||
}); | ||
return targetModule === !1 ? null : targetModule; | ||
} | ||
function isLocalDirectory(absoluteDirectory) { | ||
return existsSync(absoluteDirectory) && lstatSync(absoluteDirectory).isDirectory(); | ||
} | ||
function evaluateTargetModule(param) { | ||
var { moduleSpecifier, currentModuleExtension, isDirectory, filenameDirectory, filenameExtension, tryExtensions, esExtensions, esExtensionDefault, ensureFileExists } = param; | ||
if (currentModuleExtension && !esExtensions.includes(currentModuleExtension)) | ||
return !1; | ||
} = param; | ||
if (currentModuleExtension && !esExtensions.includes(currentModuleExtension)) return !1; | ||
isDirectory && !existsSync(resolve(filenameDirectory, currentModuleExtension ? moduleSpecifier : moduleSpecifier + esExtensionDefault)) && (moduleSpecifier = `${moduleSpecifier}/index`); | ||
var targetFile = resolve(filenameDirectory, moduleSpecifier); | ||
if (ensureFileExists) { | ||
var _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0; | ||
var _iteratorNormalCompletion = !0, | ||
_didIteratorError = !1, | ||
_iteratorError = void 0; | ||
try { | ||
for (var _iterator = tryExtensions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) { | ||
var extension = _step.value; | ||
if (existsSync(targetFile + extension)) | ||
return moduleSpecifier + esExtensionDefault; | ||
if (existsSync(targetFile + extension)) return moduleSpecifier + esExtensionDefault; | ||
} | ||
@@ -112,4 +142,3 @@ } catch (err) { | ||
} finally { | ||
if (_didIteratorError) | ||
throw _iteratorError; | ||
if (_didIteratorError) throw _iteratorError; | ||
} | ||
@@ -120,5 +149,3 @@ } | ||
} | ||
export { | ||
FullySpecified as default | ||
}; | ||
//# sourceMappingURL=index.js.map | ||
export { FullySpecified as default }; | ||
//# sourceMappingURL=index.native.js.map |
{ | ||
"name": "@tamagui/babel-plugin-fully-specified", | ||
"version": "1.111.8", | ||
"version": "1.111.9", | ||
"source": "src/index.ts", | ||
@@ -5,0 +5,0 @@ "types": "./types/index.d.ts", |
Sorry, the diff of this file is not supported yet
54986
30
980