@rn-iso/core 1.3.3
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/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +116 -0
- package/package.json +26 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Janic Duplessis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @rn-iso/core
|
|
2
|
+
|
|
3
|
+
The primitives [`rn-iso`](https://www.npmjs.com/package/rn-iso),
|
|
4
|
+
[`@rn-iso/metro`](https://www.npmjs.com/package/@rn-iso/metro) and
|
|
5
|
+
[`@rn-iso/expo-build-cache`](https://www.npmjs.com/package/@rn-iso/expo-build-cache)
|
|
6
|
+
must agree on, implemented once: where the rn-iso config dir and the two
|
|
7
|
+
shared caches live (env override > machine config > default), how a build
|
|
8
|
+
cache key is derived, and how a cache registers itself for `rn-iso gc`.
|
|
9
|
+
|
|
10
|
+
This is an internal dependency of those packages, not a user-facing API --
|
|
11
|
+
install one of them instead. It is deliberately CJS with no dependencies, so
|
|
12
|
+
a `metro.config.js` or an Expo build-cache provider can `require()` it on any
|
|
13
|
+
supported Node.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region index.d.ts
|
|
2
|
+
declare function configDir(): string;
|
|
3
|
+
declare function cachePathSetting(key: 'buildCache' | 'metroCache'): string | null;
|
|
4
|
+
declare function cacheNameSegment(name: string | null | undefined): string;
|
|
5
|
+
declare function buildCacheRoot(): string;
|
|
6
|
+
declare function metroCacheRoot(name?: string | null): string;
|
|
7
|
+
interface BuildRunOptions {
|
|
8
|
+
variant?: string;
|
|
9
|
+
configuration?: string;
|
|
10
|
+
buildConfiguration?: string;
|
|
11
|
+
isSimulator?: boolean;
|
|
12
|
+
device?: string | boolean | null;
|
|
13
|
+
}
|
|
14
|
+
declare function buildCacheKey(platform: string, fingerprintHash: string, options?: unknown): string;
|
|
15
|
+
interface RegisterOptions {
|
|
16
|
+
dir: string;
|
|
17
|
+
name: string;
|
|
18
|
+
prune: string;
|
|
19
|
+
note: string;
|
|
20
|
+
entriesDepth?: number;
|
|
21
|
+
}
|
|
22
|
+
declare function registerCache({ dir, name, prune, note, entriesDepth }: RegisterOptions): void;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { BuildRunOptions, RegisterOptions, buildCacheKey, buildCacheRoot, cacheNameSegment, cachePathSetting, configDir, metroCacheRoot, registerCache };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let node_fs = require("node:fs");
|
|
25
|
+
node_fs = __toESM(node_fs);
|
|
26
|
+
let node_os = require("node:os");
|
|
27
|
+
node_os = __toESM(node_os);
|
|
28
|
+
let node_path = require("node:path");
|
|
29
|
+
node_path = __toESM(node_path);
|
|
30
|
+
//#region index.ts
|
|
31
|
+
function configDir() {
|
|
32
|
+
return process.env.RN_ISO_HOME || node_path.default.join(node_os.default.homedir(), ".rn-iso");
|
|
33
|
+
}
|
|
34
|
+
function cachePathSetting(key) {
|
|
35
|
+
try {
|
|
36
|
+
const value = JSON.parse(node_fs.default.readFileSync(node_path.default.join(configDir(), "config.json"), "utf-8"))?.caches?.[key];
|
|
37
|
+
return typeof value === "string" && value.startsWith("/") ? value : null;
|
|
38
|
+
} catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function cacheNameSegment(name) {
|
|
43
|
+
return String(name).replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^\.+/, "") || "app";
|
|
44
|
+
}
|
|
45
|
+
function buildCacheRoot() {
|
|
46
|
+
return process.env.RN_ISO_BUILD_CACHE || cachePathSetting("buildCache") || node_path.default.join(configDir(), "build-cache");
|
|
47
|
+
}
|
|
48
|
+
function metroCacheRoot(name) {
|
|
49
|
+
const override = process.env.RN_ISO_METRO_CACHE || cachePathSetting("metroCache");
|
|
50
|
+
if (override) return override;
|
|
51
|
+
const root = node_path.default.join(configDir(), "metro-cache");
|
|
52
|
+
return name === void 0 || name === null || name === "" ? root : node_path.default.join(root, cacheNameSegment(name));
|
|
53
|
+
}
|
|
54
|
+
const SIMULATOR_UDID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
55
|
+
const EMULATOR_SERIAL = /^emulator-\d+$/;
|
|
56
|
+
function slug(value) {
|
|
57
|
+
return String(value).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
58
|
+
}
|
|
59
|
+
function buildVariant(platform, options) {
|
|
60
|
+
const raw = platform === "android" ? options.variant : options.configuration ?? options.buildConfiguration;
|
|
61
|
+
return (typeof raw === "string" ? slug(raw) : "") || "debug";
|
|
62
|
+
}
|
|
63
|
+
function buildTarget(options) {
|
|
64
|
+
if (typeof options.isSimulator === "boolean") return options.isSimulator ? "sim" : "device";
|
|
65
|
+
const device = options.device;
|
|
66
|
+
if (device === void 0 || device === null || device === false) return "sim";
|
|
67
|
+
if (typeof device !== "string") return "prompted";
|
|
68
|
+
const name = device.trim();
|
|
69
|
+
if (name === "" || name === "generic") return "sim";
|
|
70
|
+
if (SIMULATOR_UDID.test(name) || EMULATOR_SERIAL.test(name)) return "sim";
|
|
71
|
+
return `on-${slug(name)}`;
|
|
72
|
+
}
|
|
73
|
+
function buildCacheKey(platform, fingerprintHash, options = {}) {
|
|
74
|
+
const opts = options && typeof options === "object" ? options : {};
|
|
75
|
+
return `${fingerprintHash}-${buildVariant(platform, opts)}-${buildTarget(opts)}`;
|
|
76
|
+
}
|
|
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
|
+
//#endregion
|
|
110
|
+
exports.buildCacheKey = buildCacheKey;
|
|
111
|
+
exports.buildCacheRoot = buildCacheRoot;
|
|
112
|
+
exports.cacheNameSegment = cacheNameSegment;
|
|
113
|
+
exports.cachePathSetting = cachePathSetting;
|
|
114
|
+
exports.configDir = configDir;
|
|
115
|
+
exports.metroCacheRoot = metroCacheRoot;
|
|
116
|
+
exports.registerCache = registerCache;
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rn-iso/core",
|
|
3
|
+
"version": "1.3.3",
|
|
4
|
+
"description": "Shared primitives for rn-iso and its cache packages: config-dir and cache-root resolution, the build cache key, and cache self-registration. Not a user-facing API.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"README.md",
|
|
9
|
+
"LICENSE"
|
|
10
|
+
],
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"require": "./dist/index.js",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsdown"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22"
|
|
25
|
+
}
|
|
26
|
+
}
|