@rn-iso/expo-build-cache 1.3.3 → 1.4.0

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
@@ -44,4 +44,4 @@ npx rn-iso gc --delete --older-than 30 # drop entries unused for 30 days
44
44
  rn-iso is an optional peer. Without it the cache works exactly the same; it is
45
45
  just invisible to housekeeping.
46
46
 
47
- `RN_ISO_BUILD_CACHE` overrides the location.
47
+ The location can be overridden by `RN_ISO_BUILD_CACHE`, or machine-wide by `caches.buildCache` in `~/.rn-iso/config.json` (an absolute path; the env var wins). The CLI and this package resolve both identically, so they always share one store.
package/dist/index.d.ts CHANGED
@@ -1,23 +1,16 @@
1
+ import { BuildRunOptions, buildCacheKey } from "@rn-iso/core";
1
2
  //#region index.d.ts
2
- interface RunOptions {
3
- variant?: unknown;
4
- configuration?: unknown;
5
- buildConfiguration?: unknown;
6
- isSimulator?: unknown;
7
- device?: unknown;
8
- }
9
3
  declare function cacheRoot(): string;
10
- declare function buildCacheKey(platform: string, fingerprintHash: string, runOptions?: RunOptions): string;
11
4
  declare function resolveBuildCache({ platform, fingerprintHash, runOptions }: {
12
5
  platform: string;
13
6
  fingerprintHash: string;
14
- runOptions?: RunOptions;
7
+ runOptions?: BuildRunOptions;
15
8
  }): Promise<string | null>;
16
9
  declare function uploadBuildCache({ platform, fingerprintHash, buildPath, runOptions }: {
17
10
  platform: string;
18
11
  fingerprintHash: string;
19
12
  buildPath?: string;
20
- runOptions?: RunOptions;
13
+ runOptions?: BuildRunOptions;
21
14
  }): Promise<string | null>;
22
15
  //#endregion
23
16
  export { buildCacheKey, cacheRoot, resolveBuildCache, uploadBuildCache };
package/dist/index.js CHANGED
@@ -23,44 +23,18 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  //#endregion
24
24
  let node_fs = require("node:fs");
25
25
  node_fs = __toESM(node_fs);
26
- let node_os = require("node:os");
27
- node_os = __toESM(node_os);
28
26
  let node_path = require("node:path");
29
27
  node_path = __toESM(node_path);
28
+ let _rn_iso_core = require("@rn-iso/core");
30
29
  let node_child_process = require("node:child_process");
31
30
  //#region index.ts
32
- function configDir() {
33
- return process.env.RN_ISO_HOME || node_path.default.join(node_os.default.homedir(), ".rn-iso");
34
- }
31
+ let registeredDir = null;
35
32
  function cacheRoot() {
36
- return process.env.RN_ISO_BUILD_CACHE || node_path.default.join(configDir(), "build-cache");
33
+ return (0, _rn_iso_core.buildCacheRoot)();
37
34
  }
38
35
  function entryDir(platform, key) {
39
36
  return node_path.default.join(cacheRoot(), platform, key);
40
37
  }
41
- const SIMULATOR_UDID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
42
- const EMULATOR_SERIAL = /^emulator-\d+$/;
43
- function slug(value) {
44
- return String(value).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
45
- }
46
- function buildVariant(platform, options) {
47
- const raw = platform === "android" ? options.variant : options.configuration != null ? options.configuration : options.buildConfiguration;
48
- return (typeof raw === "string" ? slug(raw) : "") || "debug";
49
- }
50
- function buildTarget(options) {
51
- if (typeof options.isSimulator === "boolean") return options.isSimulator ? "sim" : "device";
52
- const device = options.device;
53
- if (device === void 0 || device === null || device === false) return "sim";
54
- if (typeof device !== "string") return "prompted";
55
- const name = device.trim();
56
- if (name === "" || name === "generic") return "sim";
57
- if (SIMULATOR_UDID.test(name) || EMULATOR_SERIAL.test(name)) return "sim";
58
- return `on-${slug(name)}`;
59
- }
60
- function buildCacheKey(platform, fingerprintHash, runOptions) {
61
- const opts = runOptions && typeof runOptions === "object" ? runOptions : {};
62
- return `${fingerprintHash}-${buildVariant(platform, opts)}-${buildTarget(opts)}`;
63
- }
64
38
  function shortKey(key, fingerprintHash) {
65
39
  return `${String(fingerprintHash).slice(0, 12)}${key.slice(String(fingerprintHash).length)}`;
66
40
  }
@@ -74,44 +48,11 @@ function artifactIn(dir) {
74
48
  }
75
49
  return found ? node_path.default.join(dir, found) : null;
76
50
  }
77
- function registerCache({ dir, name, prune, note, entriesDepth }) {
78
- try {
79
- const home = configDir();
80
- const file = node_path.default.join(home, "caches.json");
81
- let manifest = {
82
- version: 1,
83
- caches: []
84
- };
85
- try {
86
- const parsed = JSON.parse(node_fs.default.readFileSync(file, "utf-8"));
87
- if (Array.isArray(parsed?.caches)) manifest = {
88
- version: 1,
89
- caches: parsed.caches
90
- };
91
- } catch {}
92
- const others = manifest.caches.filter((c) => c.dir !== dir);
93
- const record = {
94
- dir,
95
- name,
96
- prune,
97
- note,
98
- registeredBy: process.cwd()
99
- };
100
- if (entriesDepth) record.entriesDepth = entriesDepth;
101
- others.push(record);
102
- node_fs.default.mkdirSync(home, { recursive: true });
103
- node_fs.default.writeFileSync(file, JSON.stringify({
104
- version: 1,
105
- caches: others
106
- }, null, 2));
107
- } catch {}
108
- }
109
- let registeredDir = null;
110
51
  function registerOnce() {
111
52
  const root = cacheRoot();
112
53
  if (registeredDir === root) return;
113
54
  registeredDir = root;
114
- registerCache({
55
+ (0, _rn_iso_core.registerCache)({
115
56
  dir: root,
116
57
  name: "Expo build cache",
117
58
  prune: "entries",
@@ -121,7 +62,7 @@ function registerOnce() {
121
62
  }
122
63
  async function resolveBuildCache({ platform, fingerprintHash, runOptions }) {
123
64
  registerOnce();
124
- const key = buildCacheKey(platform, fingerprintHash, runOptions);
65
+ const key = (0, _rn_iso_core.buildCacheKey)(platform, fingerprintHash, runOptions);
125
66
  const hit = artifactIn(entryDir(platform, key));
126
67
  if (hit) {
127
68
  console.log(`[build-cache] hit ${platform} ${shortKey(key, fingerprintHash)}`);
@@ -136,7 +77,7 @@ async function resolveBuildCache({ platform, fingerprintHash, runOptions }) {
136
77
  async function uploadBuildCache({ platform, fingerprintHash, buildPath, runOptions }) {
137
78
  registerOnce();
138
79
  if (!buildPath || !node_fs.default.existsSync(buildPath)) return null;
139
- const key = buildCacheKey(platform, fingerprintHash, runOptions);
80
+ const key = (0, _rn_iso_core.buildCacheKey)(platform, fingerprintHash, runOptions);
140
81
  const dest = entryDir(platform, key);
141
82
  if (artifactIn(dest)) return artifactIn(dest);
142
83
  const staging = `${dest}.staging-${process.pid}`;
@@ -145,11 +86,20 @@ async function uploadBuildCache({ platform, fingerprintHash, buildPath, runOptio
145
86
  force: true
146
87
  });
147
88
  node_fs.default.mkdirSync(staging, { recursive: true });
148
- (0, node_child_process.execFileSync)("cp", [
149
- "-R",
150
- buildPath,
151
- node_path.default.join(staging, node_path.default.basename(buildPath))
152
- ]);
89
+ try {
90
+ (0, node_child_process.execFileSync)("cp", [
91
+ "-c",
92
+ "-R",
93
+ buildPath,
94
+ node_path.default.join(staging, node_path.default.basename(buildPath))
95
+ ]);
96
+ } catch {
97
+ (0, node_child_process.execFileSync)("cp", [
98
+ "-R",
99
+ buildPath,
100
+ node_path.default.join(staging, node_path.default.basename(buildPath))
101
+ ]);
102
+ }
153
103
  node_fs.default.mkdirSync(node_path.default.dirname(dest), { recursive: true });
154
104
  node_fs.default.rmSync(dest, {
155
105
  recursive: true,
@@ -167,7 +117,7 @@ async function uploadBuildCache({ platform, fingerprintHash, buildPath, runOptio
167
117
  return artifactIn(dest);
168
118
  }
169
119
  //#endregion
170
- exports.buildCacheKey = buildCacheKey;
120
+ exports.buildCacheKey = _rn_iso_core.buildCacheKey;
171
121
  exports.cacheRoot = cacheRoot;
172
122
  exports.resolveBuildCache = resolveBuildCache;
173
123
  exports.uploadBuildCache = uploadBuildCache;
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@rn-iso/expo-build-cache",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "description": "Local Expo build cache provider: installs a cached .app/.apk instead of compiling when no native input changed.",
5
5
  "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/appandflow/rn-iso.git",
9
+ "directory": "packages/expo-build-cache"
10
+ },
6
11
  "files": [
7
12
  "dist",
8
13
  "README.md",
@@ -21,6 +26,9 @@
21
26
  "test": "node --test test/*.test.js",
22
27
  "build": "tsdown"
23
28
  },
29
+ "dependencies": {
30
+ "@rn-iso/core": "^1.4.0"
31
+ },
24
32
  "engines": {
25
33
  "node": ">=22"
26
34
  }