miaoda-expo-devkit 0.1.1-beta.20 → 0.1.1-beta.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -14591,28 +14591,46 @@ var import_node_fs = __toESM(require("fs"));
|
|
|
14591
14591
|
var import_node_path = __toESM(require("path"));
|
|
14592
14592
|
var import_helper_module_imports = __toESM(require_lib4());
|
|
14593
14593
|
var LUCIDE_REACT_NATIVE = "lucide-react-native";
|
|
14594
|
+
function resolveIconsLocation(moduleDir) {
|
|
14595
|
+
const lucideDistPath = import_node_path.default.dirname(import_node_path.default.dirname(require.resolve(LUCIDE_REACT_NATIVE)));
|
|
14596
|
+
if (moduleDir === "cjs") {
|
|
14597
|
+
const withSubdir = import_node_path.default.join(lucideDistPath, "cjs/icons");
|
|
14598
|
+
const hasSubdir = import_node_fs.default.existsSync(withSubdir);
|
|
14599
|
+
return {
|
|
14600
|
+
dir: hasSubdir ? withSubdir : import_node_path.default.join(lucideDistPath, "cjs"),
|
|
14601
|
+
ext: ".js",
|
|
14602
|
+
importBasePath: hasSubdir ? `${LUCIDE_REACT_NATIVE}/dist/cjs/icons` : `${LUCIDE_REACT_NATIVE}/dist/cjs`
|
|
14603
|
+
};
|
|
14604
|
+
}
|
|
14605
|
+
const dir = import_node_path.default.join(lucideDistPath, "esm/icons");
|
|
14606
|
+
const hasMjs = import_node_fs.default.readdirSync(dir).some((f) => f.endsWith(".mjs"));
|
|
14607
|
+
return {
|
|
14608
|
+
dir,
|
|
14609
|
+
ext: hasMjs ? ".mjs" : ".js",
|
|
14610
|
+
importBasePath: `${LUCIDE_REACT_NATIVE}/dist/esm/icons`
|
|
14611
|
+
};
|
|
14612
|
+
}
|
|
14594
14613
|
var iconMapCache = /* @__PURE__ */ new Map();
|
|
14595
14614
|
function buildIconMap(moduleDir) {
|
|
14596
14615
|
const cached = iconMapCache.get(moduleDir);
|
|
14597
14616
|
if (cached) return cached;
|
|
14598
|
-
const
|
|
14599
|
-
const lucideDistPath = import_node_path.default.dirname(import_node_path.default.dirname(lucideMain));
|
|
14600
|
-
const ext = moduleDir === "esm" ? ".mjs" : ".js";
|
|
14601
|
-
const iconsDir = import_node_path.default.join(lucideDistPath, `${moduleDir}/icons`);
|
|
14617
|
+
const { dir, ext, importBasePath } = resolveIconsLocation(moduleDir);
|
|
14602
14618
|
const map = /* @__PURE__ */ new Map();
|
|
14603
|
-
for (const file of import_node_fs.default.readdirSync(
|
|
14604
|
-
if (!file.endsWith(ext) || file.endsWith(
|
|
14619
|
+
for (const file of import_node_fs.default.readdirSync(dir)) {
|
|
14620
|
+
if (!file.endsWith(ext) || file.endsWith(".map")) continue;
|
|
14605
14621
|
const slug = import_node_path.default.basename(file, ext);
|
|
14606
14622
|
map.set(slug.replace(/-/g, ""), slug);
|
|
14607
14623
|
}
|
|
14608
|
-
|
|
14609
|
-
|
|
14624
|
+
const data = { map, importBasePath };
|
|
14625
|
+
iconMapCache.set(moduleDir, data);
|
|
14626
|
+
return data;
|
|
14610
14627
|
}
|
|
14611
14628
|
function resolveModule(useES, name) {
|
|
14612
14629
|
const moduleDir = useES ? "esm" : "cjs";
|
|
14613
|
-
const
|
|
14630
|
+
const { map, importBasePath } = buildIconMap(moduleDir);
|
|
14631
|
+
const slug = map.get(name.toLowerCase());
|
|
14614
14632
|
if (slug) {
|
|
14615
|
-
return `${
|
|
14633
|
+
return `${importBasePath}/${slug}`;
|
|
14616
14634
|
}
|
|
14617
14635
|
throw new Error(
|
|
14618
14636
|
`lucide icon ${name} was not a known icon. Please check the icon name is correct.`
|
|
@@ -14637,6 +14655,13 @@ function lucideReactNativePlugin({ types: t }) {
|
|
|
14637
14655
|
function matchesLucideIcon(nodePath, localName) {
|
|
14638
14656
|
return specifiedLocal4Imported[localName] && nodePath.scope.hasBinding(localName) && nodePath.scope.getBinding(localName)?.path.type === "ImportSpecifier";
|
|
14639
14657
|
}
|
|
14658
|
+
function replaceIconRef(nodePath, useES, makeNode) {
|
|
14659
|
+
const localName = nodePath.node.name;
|
|
14660
|
+
const iconImportedName = specifiedLocal4Imported[localName];
|
|
14661
|
+
if (!iconImportedName || !matchesLucideIcon(nodePath, localName) || isSpecialTypes(t, nodePath.parent)) return;
|
|
14662
|
+
const newNode = importMethod(useES, iconImportedName, nodePath, localName);
|
|
14663
|
+
nodePath.replaceWith(makeNode(newNode.name, nodePath.node));
|
|
14664
|
+
}
|
|
14640
14665
|
return {
|
|
14641
14666
|
name: LUCIDE_REACT_NATIVE,
|
|
14642
14667
|
visitor: {
|
|
@@ -14699,23 +14724,14 @@ function lucideReactNativePlugin({ types: t }) {
|
|
|
14699
14724
|
},
|
|
14700
14725
|
// 处理 JSX 中的图标使用:<Star /> <BookHeart size={24} />
|
|
14701
14726
|
JSXIdentifier(nodePath, state) {
|
|
14702
|
-
|
|
14703
|
-
const { useES = false } = state.opts;
|
|
14704
|
-
const iconImportedName = specifiedLocal4Imported[localName];
|
|
14705
|
-
if (matchesLucideIcon(nodePath, localName) && !isSpecialTypes(t, nodePath.parent) && iconImportedName) {
|
|
14706
|
-
const newNode = importMethod(useES, iconImportedName, nodePath, localName);
|
|
14707
|
-
nodePath.replaceWith(t.jsxIdentifier(newNode.name));
|
|
14708
|
-
}
|
|
14727
|
+
replaceIconRef(nodePath, state.opts.useES ?? false, (name) => t.jsxIdentifier(name));
|
|
14709
14728
|
},
|
|
14710
14729
|
// 处理非 JSX 场景中的图标引用:React.createElement(Star)、const icon = Star
|
|
14711
14730
|
Identifier(nodePath, state) {
|
|
14712
|
-
|
|
14713
|
-
|
|
14714
|
-
|
|
14715
|
-
|
|
14716
|
-
const newNode = importMethod(useES, iconImportedName, nodePath, localName);
|
|
14717
|
-
nodePath.replaceWith({ type: newNode.type, name: newNode.name });
|
|
14718
|
-
}
|
|
14731
|
+
replaceIconRef(nodePath, state.opts.useES ?? false, (name, orig) => ({
|
|
14732
|
+
type: orig.type,
|
|
14733
|
+
name
|
|
14734
|
+
}));
|
|
14719
14735
|
}
|
|
14720
14736
|
}
|
|
14721
14737
|
};
|
package/dist/babel/preset.js
CHANGED
|
@@ -42,10 +42,8 @@ function presetExpoDevkit(api, options = {}) {
|
|
|
42
42
|
"nativewind/babel"
|
|
43
43
|
],
|
|
44
44
|
plugins: [
|
|
45
|
-
// lucide tree-shaking
|
|
46
|
-
|
|
47
|
-
// ? [[require.resolve('./plugin-lucide-react-native'), lucide]]
|
|
48
|
-
// : []),
|
|
45
|
+
// lucide tree-shaking:所有环境都需要,Metro 不具备 tree-shaking 能力
|
|
46
|
+
...lucide !== false ? [[require.resolve("./plugin-lucide-react-native"), lucide]] : [],
|
|
49
47
|
// jsx-source 仅开发环境注入,生产无需调试元数据
|
|
50
48
|
...isDev ? [[require.resolve("./plugin-jsx-source"), { rootDir, excludePaths }]] : []
|
|
51
49
|
]
|