miaoda-expo-devkit 0.1.1-beta.2 → 0.1.1-beta.21
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/dist/babel/plugin-jsx-source.d.ts +2 -0
- package/dist/babel/plugin-jsx-source.js +12 -3
- package/dist/babel/plugin-lucide-react-native.d.ts +25 -0
- package/dist/babel/plugin-lucide-react-native.js +14723 -0
- package/dist/babel/preset.d.ts +8 -0
- package/dist/babel/preset.js +9 -5
- package/dist/cli/lint.js +23 -0
- package/dist/metro.d.mts +214 -55
- package/dist/metro.d.ts +214 -55
- package/dist/metro.js +224 -66
- package/dist/metro.mjs +223 -66
- package/dist/rules/no-duplicate-expo-router-url.js +2 -2
- package/dist/rules/no-missing-css-import.js +98 -0
- package/dist/rules/no-undeclared-expo-plugin.js +4 -0
- package/dist/rules/no-unused-expo-plugin.js +162 -0
- package/dist/stubs/expo-blur-stub.js +29 -0
- package/dist/stubs/expo-camera-stub.js +28 -0
- package/dist/stubs/expo-image-stub.js +28 -0
- package/dist/stubs/expo-linear-gradient-stub.js +28 -0
- package/dist/stubs/expo-notifications-stub.js +168 -0
- package/dist/stubs/lgui-control.js +96 -9
- package/oxlint-config.json +49 -0
- package/package.json +60 -12
- package/tsconfig-base.json +7 -0
package/dist/metro.d.ts
CHANGED
|
@@ -1,52 +1,66 @@
|
|
|
1
1
|
import { MetroConfig } from 'metro-config';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* withNativeWind / patchNativeWindCachePath — NativeWind 缓存路径修复与 lazy wrapper
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* patchNativeWindCachePath:
|
|
7
|
+
* 将 NativeWind 编译缓存从 node_modules/.cache 重定向到项目根目录下的自定义目录。
|
|
8
|
+
* ⚠️ 必须在 require('nativewind/metro') 之前调用,否则 outputDirectory 已经固化,patch 无效。
|
|
9
|
+
*
|
|
10
|
+
* withNativeWind:
|
|
11
|
+
* nativewind/metro 的 lazy wrapper,确保 nativewind 在 patchNativeWindCachePath 之后加载,
|
|
12
|
+
* 拿到已 patch 的 outputDirectory。用法与 nativewind 官方 withNativeWind 完全相同。
|
|
11
13
|
*
|
|
12
14
|
* 用法(metro.config.js):
|
|
15
|
+
* const { withNativeWind } = require('miaoda-expo-devkit/metro');
|
|
16
|
+
* // 不再需要单独 require('nativewind/metro')
|
|
17
|
+
* module.exports = withNativeWind(config, { input: './global.css' });
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** patchNativeWindCachePath 的配置选项 */
|
|
21
|
+
interface PatchNativeWindCacheOptions {
|
|
22
|
+
/**
|
|
23
|
+
* 缓存目录,相对于 process.cwd()(Metro 项目根目录),默认 .native-wind-cache。
|
|
24
|
+
* 与 package.json 同级,避免写入只读的 node_modules。
|
|
25
|
+
*/
|
|
26
|
+
cacheDir?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 将 NativeWind 编译缓存从 node_modules/.cache 重定向到项目根目录下的自定义目录。
|
|
13
30
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
31
|
+
* ⚠️ 必须在 require('nativewind/metro') / require('react-native-css-interop/dist/metro')
|
|
32
|
+
* 之前调用,否则 outputDirectory 已经固化,patch 无效。
|
|
16
33
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* );
|
|
34
|
+
* 原理:react-native-css-interop/dist/metro 在模块顶层用
|
|
35
|
+
* const outputDirectory = path.resolve(__dirname, "../../.cache")
|
|
36
|
+
* 计算缓存路径。通过在 require 前临时替换 path.resolve,可将该值重定向到
|
|
37
|
+
* 项目根目录下的自定义缓存目录,而无需 fork 或修改 node_modules 源码。
|
|
22
38
|
*
|
|
23
|
-
*
|
|
39
|
+
* ⚠️ 已知限制:依赖 react-native-css-interop 使用 path.resolve 计算缓存路径,
|
|
40
|
+
* 升级该依赖时需确认此假设仍然成立。
|
|
24
41
|
*
|
|
25
|
-
*
|
|
42
|
+
* @param options 配置选项
|
|
26
43
|
*/
|
|
27
|
-
|
|
44
|
+
declare function patchNativeWindCachePath(options?: PatchNativeWindCacheOptions): void;
|
|
28
45
|
/**
|
|
29
|
-
*
|
|
46
|
+
* withNativeWind 的 lazy wrapper。
|
|
30
47
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
48
|
+
* nativewind/metro 在模块顶层捕获 react-native-css-interop 的 withCssInterop 引用,
|
|
49
|
+
* 因此必须在 patchNativeWindCachePath() 执行完之后才能加载 nativewind/metro。
|
|
50
|
+
* 这里使用 lazy require(在函数调用时才加载),确保 nativewind 拿到已 patch 的
|
|
51
|
+
* outputDirectory,而不需要在 metro.config.js 中手动处理加载顺序。
|
|
34
52
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @param config Metro config 对象(来自 getDefaultConfig 或 getSentryExpoConfig)
|
|
38
|
-
* @returns 注入 resolveRequest 后的新 Metro config
|
|
53
|
+
* @param config Metro config 对象
|
|
54
|
+
* @param options nativewind withNativeWind 选项(与原包 API 完全一致)
|
|
39
55
|
*/
|
|
40
|
-
declare function
|
|
41
|
-
|
|
42
|
-
interface InjectOptions {
|
|
43
|
-
}
|
|
56
|
+
declare function withNativeWind(config: MetroConfig, options?: any): MetroConfig;
|
|
57
|
+
|
|
44
58
|
/**
|
|
45
|
-
* 在 expo-router
|
|
59
|
+
* withEntryInjection — 在 expo-router 启动前注入脚本
|
|
46
60
|
*
|
|
47
61
|
* 注入原理:
|
|
48
62
|
* 拦截 Metro 对 expo-router/entry-classic 的解析,将其重定向到
|
|
49
|
-
* dist/stubs/expo-router-entry-stub.js。
|
|
63
|
+
* dist/stubs/expo-router-entry-stub.js。stub 先 require entry-inject.js
|
|
50
64
|
* (注入脚本),再 require expo-router/entry-classic(原入口),
|
|
51
65
|
* 从而在 expo-router 启动前执行注入逻辑。
|
|
52
66
|
*
|
|
@@ -57,20 +71,45 @@ interface InjectOptions {
|
|
|
57
71
|
* 这条 import 语句经过 resolveRequest,可以被拦截。
|
|
58
72
|
*
|
|
59
73
|
* 执行顺序(在 bundle 中):
|
|
60
|
-
* entry-inject.js
|
|
61
|
-
* → expo-router/entry-classic(原 expo-router 入口)
|
|
62
|
-
* → renderRootComponent(App)
|
|
74
|
+
* entry-inject.js → expo-router/entry-classic → renderRootComponent(App)
|
|
63
75
|
*
|
|
64
76
|
* 注入的脚本经过完整 Babel 编译,支持现代语法,web + native 双平台均有效。
|
|
77
|
+
* 支持与 withDevStubs 及其他 Metro wrapper 链式组合。
|
|
65
78
|
*
|
|
66
|
-
*
|
|
79
|
+
* 用法(metro.config.js):
|
|
80
|
+
* const { withEntryInjection } = require('miaoda-expo-devkit/metro');
|
|
67
81
|
* module.exports = withEntryInjection(withDevStubs(config));
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
/** withEntryInjection 的配置选项(预留,供未来支持自定义注入脚本路径扩展) */
|
|
85
|
+
interface InjectOptions {
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 在 expo-router 启动前注入一段脚本。
|
|
68
89
|
*
|
|
69
90
|
* @param config Metro config 对象
|
|
70
91
|
* @param options 注入选项(当前预留,未来支持自定义注入脚本路径)
|
|
71
92
|
* @returns 注入 resolveRequest 后的新 Metro config
|
|
72
93
|
*/
|
|
73
94
|
declare function withEntryInjection(config: MetroConfig, options?: InjectOptions): MetroConfig;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* withRouteEndpoint — 为 Metro server 添加路由树查询端点
|
|
98
|
+
*
|
|
99
|
+
* 端点(默认 /__routes)返回 JSON 格式的路由树:
|
|
100
|
+
* {
|
|
101
|
+
* "routes": [
|
|
102
|
+
* { "title": "首页", "pageId": "/", "pageName": "index", "path": "src/app/index.tsx" }
|
|
103
|
+
* ]
|
|
104
|
+
* }
|
|
105
|
+
*
|
|
106
|
+
* 用法(metro.config.js):
|
|
107
|
+
* const { withRouteEndpoint } = require('miaoda-expo-devkit/metro');
|
|
108
|
+
* module.exports = withRouteEndpoint(config, {
|
|
109
|
+
* appDir: path.join(__dirname, 'src', 'app'),
|
|
110
|
+
* });
|
|
111
|
+
*/
|
|
112
|
+
|
|
74
113
|
/** withRouteEndpoint 的配置选项 */
|
|
75
114
|
interface RouteEndpointOptions {
|
|
76
115
|
/** app 目录的绝对路径(包含路由文件的目录) */
|
|
@@ -81,38 +120,158 @@ interface RouteEndpointOptions {
|
|
|
81
120
|
/**
|
|
82
121
|
* 为 Metro server 添加 /__routes 端点,返回路由树 JSON。
|
|
83
122
|
*
|
|
84
|
-
* 端点返回格式:
|
|
85
|
-
* {
|
|
86
|
-
* "routes": [
|
|
87
|
-
* { "title": "首页", "pageId": "/", "pageName": "index", "visible": true, "path": "index.tsx" },
|
|
88
|
-
* { "title": "id", "pageId": "/user/[id]", "pageName": "user-[id]", "visible": false, "path": "user/[id].tsx" }
|
|
89
|
-
* ]
|
|
90
|
-
* }
|
|
91
|
-
*
|
|
92
123
|
* @param config Metro config 对象
|
|
93
124
|
* @param options 配置选项,必须提供 appDir
|
|
94
125
|
* @returns 增强 server.enhanceMiddleware 后的新 Metro config
|
|
95
126
|
*/
|
|
96
127
|
declare function withRouteEndpoint(config: MetroConfig, options: RouteEndpointOptions): MetroConfig;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* withDevkit — 一站式 Metro 配置入口
|
|
131
|
+
*
|
|
132
|
+
* 将模板 metro.config.js 所需的所有 devkit wrapper 封装为单个函数调用,
|
|
133
|
+
* 消除模板侧的 boilerplate。内部按固定顺序依次应用:
|
|
134
|
+
*
|
|
135
|
+
* withWorkspaceNodeModules — 修复沙箱中 node_modules 不在 projectRoot 内的问题
|
|
136
|
+
* withCssInterop — 为 expo-image / expo-camera 注入 NativeWind cssInterop
|
|
137
|
+
* withExpoNotificationsStub — Android:expo-notifications → stub(Expo Go no-op,Dev Build 透传)
|
|
138
|
+
* withEntryInjection — 在 expo-router 启动前注入脚本(仅 __DEV__)
|
|
139
|
+
* withDevStubs — 替换 Sentry DSN / 屏蔽 LogBox(仅 __DEV__)
|
|
140
|
+
* withRouteEndpoint — 添加 /__routes 端点(仅 __DEV__)
|
|
141
|
+
* withNativeWind — NativeWind 支持(含缓存路径修复)
|
|
142
|
+
*
|
|
143
|
+
* 用法(metro.config.js):
|
|
144
|
+
* const { getDefaultConfig } = require('expo/metro-config');
|
|
145
|
+
* const { withDevkit } = require('miaoda-expo-devkit/metro');
|
|
146
|
+
*
|
|
147
|
+
* module.exports = withDevkit(getDefaultConfig(__dirname));
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Android 平台:将 expo-notifications 替换为 stub。
|
|
152
|
+
* stub 内部根据 isRunningInExpoGo() 决定是 no-op(Expo Go)还是透传真实模块(Development Build)。
|
|
153
|
+
*
|
|
154
|
+
* 注意:此 wrapper 必须在 if (__DEV__) 外部调用,因为它需要在所有构建模式下生效。
|
|
155
|
+
* Expo Go 中 native module 的缺失是运行时问题,与开发/生产模式无关。
|
|
156
|
+
*/
|
|
157
|
+
declare function withExpoNotificationsStub(config: MetroConfig): MetroConfig;
|
|
158
|
+
/** withDevkit 的配置选项 */
|
|
159
|
+
interface DevkitOptions {
|
|
160
|
+
/**
|
|
161
|
+
* NativeWind 的 CSS 入口文件路径(相对于 projectRoot)。
|
|
162
|
+
* 默认:'./src/global.css'
|
|
163
|
+
*/
|
|
164
|
+
input?: string;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* 一站式应用所有 devkit Metro wrapper。
|
|
168
|
+
*
|
|
169
|
+
* @param config Metro config 对象(来自 getDefaultConfig)
|
|
170
|
+
* @param options 配置选项
|
|
171
|
+
* @returns 完整配置后的 Metro config
|
|
172
|
+
*/
|
|
173
|
+
declare function withDevkit(config: MetroConfig, options?: DevkitOptions): MetroConfig;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* withDevStubs — Metro resolver 注入开发阶段 stub
|
|
177
|
+
*
|
|
178
|
+
* 注入行为:
|
|
179
|
+
* 1. web 平台:@expo/log-box 及 ErrorOverlayWebControls → no-op-logbox stub(屏蔽全屏错误遮罩)
|
|
180
|
+
* 2. 所有平台:@sentry/react-native → sentry-react-native-stub(替换 DSN,注入内置捕获器)
|
|
181
|
+
*
|
|
182
|
+
* 自动保留并调用已有的 resolveRequest,支持与其他 Metro 配置链式组合。
|
|
183
|
+
*
|
|
184
|
+
* 用法(metro.config.js):
|
|
185
|
+
* const { withDevStubs } = require('miaoda-expo-devkit/metro');
|
|
186
|
+
* module.exports = withDevStubs(getDefaultConfig(__dirname));
|
|
187
|
+
*/
|
|
188
|
+
|
|
97
189
|
/**
|
|
98
|
-
*
|
|
190
|
+
* 将开发阶段 stub 注入到 Metro config 中。
|
|
99
191
|
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
192
|
+
* @param config Metro config 对象(来自 getDefaultConfig 或 getSentryExpoConfig)
|
|
193
|
+
* @returns 注入 resolveRequest 后的新 Metro config
|
|
194
|
+
*/
|
|
195
|
+
declare function withDevStubs(config: MetroConfig): MetroConfig;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* withWorkspaceNodeModules — 修复沙箱中 node_modules 不在 projectRoot 内时的模块解析问题
|
|
106
199
|
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* 和 resolver.nodeModulesPaths(让模块解析也能找到包)。
|
|
200
|
+
* 适用场景:node_modules 位于 projectRoot 的祖先目录(如 /workspace/node_modules),
|
|
201
|
+
* 而 projectRoot 自身的 node_modules 为空目录或不存在。
|
|
110
202
|
*
|
|
111
|
-
*
|
|
203
|
+
* 问题:
|
|
204
|
+
* 1. Metro 只监听 projectRoot,祖先目录的 node_modules 不在 watchFolders 内,
|
|
205
|
+
* 导致模块无法被 file map 索引。
|
|
206
|
+
* 2. pnpm 的 .pnpm 目录可能是指向外部路径的 symlink
|
|
207
|
+
* (如 /workspace/node_modules/.pnpm → /data/expo/node_modules/.pnpm)。
|
|
208
|
+
* Metro 跟随 symlink 后,将文件以真实路径(/data/expo/...)存入 file map,
|
|
209
|
+
* HTML 入口的 bundle URL 也随之变为 /data/expo/...bundle。
|
|
210
|
+
* 若 /data/expo/node_modules/ 不在 watchFolders,Metro HTTP server 会返回 404。
|
|
211
|
+
*
|
|
212
|
+
* 修复:
|
|
213
|
+
* 1. 将祖先目录的 node_modules 加入 watchFolders 和 resolver.nodeModulesPaths。
|
|
214
|
+
* 2. 若该 node_modules 下的 .pnpm 是指向外部路径的 symlink,
|
|
215
|
+
* 同样将外部真实路径加入 watchFolders 和 resolver.nodeModulesPaths。
|
|
216
|
+
*
|
|
217
|
+
* 用法(metro.config.js):
|
|
218
|
+
* const { withWorkspaceNodeModules } = require('miaoda-expo-devkit/metro');
|
|
219
|
+
* module.exports = withWorkspaceNodeModules(config);
|
|
220
|
+
*/
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 修复沙箱环境中 node_modules 位于祖先目录时,Metro 模块解析和 bundle 请求失败的问题。
|
|
112
224
|
*
|
|
113
225
|
* @param config Metro config 对象(来自 getDefaultConfig)
|
|
114
|
-
* @returns 修正 watchFolders
|
|
226
|
+
* @returns 修正 watchFolders、nodeModulesPaths 后的新 Metro config
|
|
115
227
|
*/
|
|
116
228
|
declare function withWorkspaceNodeModules(config: MetroConfig): MetroConfig;
|
|
117
229
|
|
|
118
|
-
|
|
230
|
+
/**
|
|
231
|
+
* withCssInterop — 为第三方 Expo 组件注入 NativeWind cssInterop
|
|
232
|
+
*
|
|
233
|
+
* 注入方式:Metro resolver 层拦截对应包的 import,重定向到 stub 文件。
|
|
234
|
+
* stub 文件透传原包的所有导出,并调用 cssInterop 完成注册。
|
|
235
|
+
* stub 内部 import 原包时,originModulePath 检查避免循环依赖。
|
|
236
|
+
*
|
|
237
|
+
* 当前支持的包:
|
|
238
|
+
* - expo-image:Image 组件(className → style)
|
|
239
|
+
* - expo-camera:CameraView 组件(className → style)
|
|
240
|
+
* - expo-linear-gradient:LinearGradient 组件(className → style)
|
|
241
|
+
* - expo-blur:BlurView / BlurTargetView 组件(className → style)
|
|
242
|
+
*
|
|
243
|
+
* 注意:react-native-reanimated 不拦截。cssInterop 全局注册 Animated.* 会导致所有动画 style 注入失败。
|
|
244
|
+
* 需要同时使用 Tailwind className 和动画的场景,请在组件层面单独用 createAnimatedComponent + cssInterop 封装。
|
|
245
|
+
*
|
|
246
|
+
* 注意:expo-video 的 VideoView 在 web 上直接渲染 DOM <video> 元素,不经过 RN 样式系统,
|
|
247
|
+
* cssInterop/remapProps 均无效,不做拦截。需要 className 时请用 View 包裹 VideoView。
|
|
248
|
+
*
|
|
249
|
+
* 此函数在开发和生产环境均需启用(cssInterop 注册与环境无关)。
|
|
250
|
+
* 支持与其他 Metro wrapper 链式组合。
|
|
251
|
+
*
|
|
252
|
+
* 用法(metro.config.js):
|
|
253
|
+
* const { withCssInterop } = require('miaoda-expo-devkit/metro');
|
|
254
|
+
* module.exports = withCssInterop(config);
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* 为第三方 Expo 组件注入 NativeWind cssInterop,使其支持 className prop。
|
|
259
|
+
*
|
|
260
|
+
* @param config Metro config 对象
|
|
261
|
+
* @returns 注入 resolveRequest 后的新 Metro config
|
|
262
|
+
*/
|
|
263
|
+
declare function withCssInterop(config: MetroConfig): MetroConfig;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* 将 Metro transformer 的 minifier 切换为 esbuild。
|
|
267
|
+
*
|
|
268
|
+
* esbuild 比 terser 快数十倍,内存占用极低,非常适合 web 生产构建。
|
|
269
|
+
* 通过 metro-minify-esbuild 桥接,pnpm 会将 esbuild 作为其 peer dep 一并安装,
|
|
270
|
+
* 解析路径在 devkit 上下文中(metro.config.js 加载时)完成。
|
|
271
|
+
*
|
|
272
|
+
* 注意:切换 minifier 时必须清空 minifierConfig,因为默认 config 含有
|
|
273
|
+
* terser 专属选项(如 mangle、compress 等),传给 esbuild 会报错。
|
|
274
|
+
*/
|
|
275
|
+
declare function withEsbuildMinify(config: MetroConfig): MetroConfig;
|
|
276
|
+
|
|
277
|
+
export { type DevkitOptions, type InjectOptions, type PatchNativeWindCacheOptions, type RouteEndpointOptions, patchNativeWindCachePath, withCssInterop, withDevStubs, withDevkit, withEntryInjection, withEsbuildMinify, withExpoNotificationsStub, withNativeWind, withRouteEndpoint, withWorkspaceNodeModules };
|