miaoda-expo-devkit 0.1.1-beta.63 → 0.1.1-beta.65

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/metro.d.mts CHANGED
@@ -111,7 +111,7 @@ declare function withRouteEndpoint(config: MetroConfig, options: RouteEndpointOp
111
111
  * withDevkit — 一站式 Metro 配置入口
112
112
  *
113
113
  * 按固定顺序依次应用:
114
- * withPersistentCache — 将 Metro transform cache 固定到项目目录(.metro-cache/),重启不丢失
114
+ * withPersistentCache — 将 Metro transform cache 固定到持久目录(优先读取 METRO_CACHE_DIR 环境变量),重启不丢失
115
115
  * withWorkspaceNodeModules — 修复沙箱中 node_modules 位于祖先目录时的模块解析问题
116
116
  * withWasmSupport — 将 .wasm 加入 assetExts,修复 expo-sqlite web worker 打包失败
117
117
  * withCssInterop — 为 expo-image / expo-camera 等注入 NativeWind cssInterop
@@ -435,10 +435,16 @@ declare function withWasmSupport(config: MetroConfig): MetroConfig;
435
435
  declare function withTransformLogger(config: MetroConfig): MetroConfig;
436
436
 
437
437
  /**
438
- * withPersistentCache — 将 Metro transform cache 固定到项目目录
438
+ * withPersistentCache — 将 Metro transform cache 固定到可持久化目录
439
439
  *
440
- * 默认 Metro cache 位于系统临时目录,重启后丢失,每次都是冷启动。
441
- * 此 wrapper 将 cacheStores 替换为项目根目录下的 .metro-cache/,持久保留。
440
+ * Metro 默认将 transform cache 写入系统临时目录(os.tmpdir()/metro-cache),
441
+ * 系统随时可以清理,导致每次重启都是冷启动。
442
+ * 此 wrapper 将 cacheStores 替换为指定目录,持久保留。
443
+ *
444
+ * 缓存路径解析优先级(高到低):
445
+ * 1. 环境变量 METRO_CACHE_DIR(绝对路径,适用于容器/CI 挂载外部持久目录)
446
+ * 2. options.cacheDir(绝对路径直接使用;相对路径拼接到 projectRoot)
447
+ * 3. 默认值:projectRoot/.metro-cache
442
448
  *
443
449
  * cache key 由文件内容 sha1 + 相对路径 + Babel/Metro 版本共同决定,
444
450
  * 与项目绝对路径无关,换目录 clone 后缓存同样有效。
@@ -446,7 +452,10 @@ declare function withTransformLogger(config: MetroConfig): MetroConfig;
446
452
 
447
453
  interface PersistentCacheOptions {
448
454
  /**
449
- * cache 目录,相对于 projectRoot。默认:'.metro-cache'
455
+ * cache 目录。
456
+ * - 绝对路径:直接使用(适合挂载外部持久目录)
457
+ * - 相对路径:拼接到 projectRoot
458
+ * - 省略:使用环境变量 METRO_CACHE_DIR,否则默认 '.metro-cache'(相对 projectRoot)
450
459
  */
451
460
  cacheDir?: string;
452
461
  }
package/dist/metro.d.ts CHANGED
@@ -111,7 +111,7 @@ declare function withRouteEndpoint(config: MetroConfig, options: RouteEndpointOp
111
111
  * withDevkit — 一站式 Metro 配置入口
112
112
  *
113
113
  * 按固定顺序依次应用:
114
- * withPersistentCache — 将 Metro transform cache 固定到项目目录(.metro-cache/),重启不丢失
114
+ * withPersistentCache — 将 Metro transform cache 固定到持久目录(优先读取 METRO_CACHE_DIR 环境变量),重启不丢失
115
115
  * withWorkspaceNodeModules — 修复沙箱中 node_modules 位于祖先目录时的模块解析问题
116
116
  * withWasmSupport — 将 .wasm 加入 assetExts,修复 expo-sqlite web worker 打包失败
117
117
  * withCssInterop — 为 expo-image / expo-camera 等注入 NativeWind cssInterop
@@ -435,10 +435,16 @@ declare function withWasmSupport(config: MetroConfig): MetroConfig;
435
435
  declare function withTransformLogger(config: MetroConfig): MetroConfig;
436
436
 
437
437
  /**
438
- * withPersistentCache — 将 Metro transform cache 固定到项目目录
438
+ * withPersistentCache — 将 Metro transform cache 固定到可持久化目录
439
439
  *
440
- * 默认 Metro cache 位于系统临时目录,重启后丢失,每次都是冷启动。
441
- * 此 wrapper 将 cacheStores 替换为项目根目录下的 .metro-cache/,持久保留。
440
+ * Metro 默认将 transform cache 写入系统临时目录(os.tmpdir()/metro-cache),
441
+ * 系统随时可以清理,导致每次重启都是冷启动。
442
+ * 此 wrapper 将 cacheStores 替换为指定目录,持久保留。
443
+ *
444
+ * 缓存路径解析优先级(高到低):
445
+ * 1. 环境变量 METRO_CACHE_DIR(绝对路径,适用于容器/CI 挂载外部持久目录)
446
+ * 2. options.cacheDir(绝对路径直接使用;相对路径拼接到 projectRoot)
447
+ * 3. 默认值:projectRoot/.metro-cache
442
448
  *
443
449
  * cache key 由文件内容 sha1 + 相对路径 + Babel/Metro 版本共同决定,
444
450
  * 与项目绝对路径无关,换目录 clone 后缓存同样有效。
@@ -446,7 +452,10 @@ declare function withTransformLogger(config: MetroConfig): MetroConfig;
446
452
 
447
453
  interface PersistentCacheOptions {
448
454
  /**
449
- * cache 目录,相对于 projectRoot。默认:'.metro-cache'
455
+ * cache 目录。
456
+ * - 绝对路径:直接使用(适合挂载外部持久目录)
457
+ * - 相对路径:拼接到 projectRoot
458
+ * - 省略:使用环境变量 METRO_CACHE_DIR,否则默认 '.metro-cache'(相对 projectRoot)
450
459
  */
451
460
  cacheDir?: string;
452
461
  }
package/dist/metro.js CHANGED
@@ -561,11 +561,22 @@ var import_path13 = __toESM(require("path"));
561
561
  var import_metro_cache = require("metro-cache");
562
562
  function withPersistentCache(config, options = {}) {
563
563
  const projectRoot = config.projectRoot ?? process.cwd();
564
- const { cacheDir = ".metro-cache" } = options;
565
- const cacheRoot = import_path13.default.join(projectRoot, cacheDir);
564
+ const { cacheDir } = options;
565
+ const envCacheDir = process.env["METRO_CACHE_DIR"];
566
+ let cacheRoot;
567
+ if (envCacheDir) {
568
+ cacheRoot = envCacheDir;
569
+ } else if (cacheDir) {
570
+ cacheRoot = import_path13.default.isAbsolute(cacheDir) ? cacheDir : import_path13.default.join(projectRoot, cacheDir);
571
+ } else {
572
+ cacheRoot = import_path13.default.join(projectRoot, ".metro-cache");
573
+ }
574
+ const existingStores = config.cacheStores;
575
+ const firstStore = Array.isArray(existingStores) ? existingStores[0] : void 0;
576
+ const StoreClass = firstStore ? Object.getPrototypeOf(firstStore).constructor : import_metro_cache.FileStore;
566
577
  return {
567
578
  ...config,
568
- cacheStores: [new import_metro_cache.FileStore({ root: cacheRoot })]
579
+ cacheStores: [new StoreClass({ root: cacheRoot })]
569
580
  };
570
581
  }
571
582
 
package/dist/metro.mjs CHANGED
@@ -513,11 +513,22 @@ import path14 from "path";
513
513
  import { FileStore } from "metro-cache";
514
514
  function withPersistentCache(config, options = {}) {
515
515
  const projectRoot = config.projectRoot ?? process.cwd();
516
- const { cacheDir = ".metro-cache" } = options;
517
- const cacheRoot = path14.join(projectRoot, cacheDir);
516
+ const { cacheDir } = options;
517
+ const envCacheDir = process.env["METRO_CACHE_DIR"];
518
+ let cacheRoot;
519
+ if (envCacheDir) {
520
+ cacheRoot = envCacheDir;
521
+ } else if (cacheDir) {
522
+ cacheRoot = path14.isAbsolute(cacheDir) ? cacheDir : path14.join(projectRoot, cacheDir);
523
+ } else {
524
+ cacheRoot = path14.join(projectRoot, ".metro-cache");
525
+ }
526
+ const existingStores = config.cacheStores;
527
+ const firstStore = Array.isArray(existingStores) ? existingStores[0] : void 0;
528
+ const StoreClass = firstStore ? Object.getPrototypeOf(firstStore).constructor : FileStore;
518
529
  return {
519
530
  ...config,
520
- cacheStores: [new FileStore({ root: cacheRoot })]
531
+ cacheStores: [new StoreClass({ root: cacheRoot })]
521
532
  };
522
533
  }
523
534
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miaoda-expo-devkit",
3
- "version": "0.1.1-beta.63",
3
+ "version": "0.1.1-beta.65",
4
4
  "description": "Expo 应用开发工具集:Sentry DSN 替换 stub、错误/网络捕获、Metro 符号化",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",