miaoda-expo-devkit 0.1.1-beta.3 → 0.1.1-beta.30

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.
package/README.md CHANGED
@@ -264,6 +264,7 @@ sentry-react-native-stub.js
264
264
  | `.` | `dist/index.js` | `SentryCapture`、`MetroSymbolicator`、全部类型 |
265
265
  | `./metro` | `dist/metro.js` | `withDevStubs`、`withEntryInjection` |
266
266
  | `./babel-plugin-jsx-source` | `dist/babel/plugin-jsx-source.js` | Babel 插件:为 JSX 注入 source 信息 |
267
+ | `./babel-preset` | `dist/babel/preset.js` | Babel Preset:集成 jsx-source 和 lucide 插件 |
267
268
  | `./sentry-react-native-stub` | `dist/stubs/sentry-react-native-stub.js` | `@sentry/react-native` 模块替换 stub |
268
269
  | `./no-op-logbox` | `dist/stubs/no-op-logbox.js` | LogBox no-op stub |
269
270
 
@@ -434,3 +435,81 @@ module.exports = {
434
435
  |---|---|---|---|
435
436
  | `rootDir` | `string` | - | 项目根目录,用于计算相对路径。不提供则使用绝对路径 |
436
437
  | `excludePaths` | `string[]` | `[]` | 跳过注入的路径模式列表(相对于 rootDir 的路径片段) |
438
+
439
+ ---
440
+
441
+ ## Babel 插件:lucide-react-native
442
+
443
+ Metro 没有 tree-shaking,直接写 `import { Star } from "lucide-react-native"` 会把整个图标库(约 1500 个图标)打进 bundle。`babel-plugin-lucide-react-native` 在编译阶段将具名导入改写为直接按文件导入,彻底规避这个问题。
444
+
445
+ **转换效果:**
446
+
447
+ ```ts
448
+ // 转换前
449
+ import { Star, BookOpen } from "lucide-react-native";
450
+
451
+ // 转换后(CJS,默认)
452
+ import _Star from "lucide-react-native/dist/cjs/icons/star";
453
+ import _BookOpen from "lucide-react-native/dist/cjs/icons/book-open";
454
+ ```
455
+
456
+ ### 配置
457
+
458
+ 推荐通过内置 Preset 一次性启用所有 Babel 插件:
459
+
460
+ ```js
461
+ // babel.config.js
462
+ module.exports = {
463
+ presets: [['miaoda-expo-devkit/babel-preset', { excludePaths: ['src/components/ui'] }]],
464
+ };
465
+ ```
466
+
467
+ 也可以单独使用:
468
+
469
+ ```js
470
+ module.exports = {
471
+ plugins: [['miaoda-expo-devkit/babel-plugin-lucide-react-native']],
472
+ };
473
+ ```
474
+
475
+ ### 选项
476
+
477
+ | 选项 | 类型 | 默认值 | 说明 |
478
+ |---|---|---|---|
479
+ | `useES` | `boolean` | `false` | 使用 ESM 格式(`dist/esm/icons/`)而非默认的 CJS |
480
+
481
+ ### 支持的写法
482
+
483
+ 插件可识别所有常见的图标引用写法:
484
+
485
+ ```ts
486
+ import { BookOpen, Star, Crown } from "lucide-react-native";
487
+
488
+ // JSX 直接使用
489
+ <BookOpen size={24} />
490
+
491
+ // 赋值给变量
492
+ const icon = BookOpen;
493
+
494
+ // 对象 value
495
+ const ITEMS = [{ icon: BookOpen }, { icon: Star }];
496
+
497
+ // 计算属性 key
498
+ const map = { [BookOpen]: 'read' };
499
+
500
+ // 数组、三元、函数参数
501
+ const list = [BookOpen, Star];
502
+ const active = flag ? BookOpen : Star;
503
+ renderIcon(Crown);
504
+
505
+ // 导入别名
506
+ import { BookOpen as ReadIcon } from "lucide-react-native";
507
+ <ReadIcon />
508
+
509
+ // re-export
510
+ export { Star, BookOpen as ReadIcon } from "lucide-react-native";
511
+ ```
512
+
513
+ ### 版本兼容性
514
+
515
+ 插件在运行时探测 `lucide-react-native` 的实际目录结构,自动适配新旧版本的路径差异(`>= 1.9` 新增 `icons/` 子目录;旧版 `1.8.x` 图标直接位于 `dist/cjs/`),lucide 升级时无需修改配置。
package/biome-config.json CHANGED
@@ -1,4 +1,15 @@
1
1
  {
2
+ "vcs": {
3
+ "enabled": true,
4
+ "clientKind": "git",
5
+ "useIgnoreFile": true
6
+ },
7
+ "files": {
8
+ "includes": [
9
+ "src/**/*.{js,jsx,ts,tsx,css,scss}",
10
+ "tailwind.config.js"
11
+ ]
12
+ },
2
13
  "linter": {
3
14
  "enabled": true,
4
15
  "rules": {
@@ -10,5 +21,17 @@
10
21
  },
11
22
  "formatter": {
12
23
  "enabled": false
13
- }
24
+ },
25
+ "overrides": [
26
+ {
27
+ "includes": ["tailwind.config.js"],
28
+ "linter": {
29
+ "rules": {
30
+ "style": {
31
+ "noCommonJs": "off"
32
+ }
33
+ }
34
+ }
35
+ }
36
+ ]
14
37
  }
@@ -14,8 +14,10 @@ import { types, PluginObj } from '@babel/core';
14
14
  *
15
15
  * 对于纯文本节点:
16
16
  * <div>hello world</div>
17
+ * <div>{"hello world"}</div>
17
18
  * 转换后:
18
19
  * <div dataSet={{"mdId": "path/to/file.tsx:10:4", "componentContent": "{\"text\":\"hello world\"}"}}>hello world</div>
20
+ * <div dataSet={{"mdId": "path/to/file.tsx:11:4", "componentContent": "{\"text\":\"hello world\"}"}}>{"hello world"}</div>
19
21
  *
20
22
  * 用法(babel.config.js):
21
23
  *
@@ -69,9 +69,18 @@ function getTextNodeContent(t, path) {
69
69
  const children = parent.children;
70
70
  if (children.length !== 1) return null;
71
71
  const child = children[0];
72
- if (!t.isJSXText(child)) return null;
73
- const text = child.value.trim();
74
- return text || null;
72
+ if (t.isJSXText(child)) {
73
+ const text = child.value.trim();
74
+ return text || null;
75
+ }
76
+ if (t.isJSXExpressionContainer(child) && t.isStringLiteral(child.expression)) {
77
+ const text = child.expression.value.trim();
78
+ return text || null;
79
+ }
80
+ if (t.isJSXExpressionContainer(child) && t.isNumericLiteral(child.expression)) {
81
+ return String(child.expression.value);
82
+ }
83
+ return null;
75
84
  }
76
85
  function shouldSkipElement(t, name) {
77
86
  if (t.isJSXIdentifier(name)) {
@@ -0,0 +1,31 @@
1
+ import babelCore from '@babel/core';
2
+
3
+ /**
4
+ * babel-plugin-lucide-react-native
5
+ *
6
+ * 将 lucide-react-native 的具名导入转换为按图标文件直接导入,绕过 Metro
7
+ * 缺乏 tree-shaking 的问题,避免将整个图标库打进 bundle。
8
+ *
9
+ * 转换示意:
10
+ * import { Star, BookHeart } from "lucide-react-native"
11
+ * →
12
+ * import _Star from "lucide-react-native/dist/cjs/icons/star"
13
+ * import _BookHeart from "lucide-react-native/dist/cjs/icons/book-heart"
14
+ */
15
+
16
+ type Core = typeof babelCore;
17
+ interface Config extends babelCore.PluginPass {
18
+ opts: {
19
+ /** 使用 ESM 格式(dist/esm)。默认 false,使用 CJS(dist/cjs)。 */
20
+ useES?: boolean;
21
+ /**
22
+ * lucide-react-native 包根目录的绝对路径(含 package.json 的那一层)。
23
+ * 不传时通过 require.resolve 自动定位,适用于生产场景。
24
+ * 测试时可传入特定版本的路径,验证不同版本的兼容性。
25
+ */
26
+ lucidePkgRoot?: string;
27
+ };
28
+ }
29
+ declare function lucideReactNativePlugin({ types: t }: Core): babelCore.PluginObj<Config>;
30
+
31
+ export { lucideReactNativePlugin as default };