@observerkit/metro 0.2.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 +118 -0
- package/dist/chunk-6RJOM2CO.cjs +199 -0
- package/dist/chunk-AUOVSTQX.cjs +7 -0
- package/dist/chunk-DFCKYXBG.js +199 -0
- package/dist/cli.cjs +156 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +155 -0
- package/dist/expo.cjs +92 -0
- package/dist/expo.d.cts +24 -0
- package/dist/expo.d.ts +22 -0
- package/dist/expo.js +88 -0
- package/dist/index.cjs +135 -0
- package/dist/index.d.cts +65 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +132 -0
- package/package.json +59 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildStackKeyedDebugIdSnippet,
|
|
3
|
+
generateDebugId,
|
|
4
|
+
isJsonObject
|
|
5
|
+
} from "./chunk-DFCKYXBG.js";
|
|
6
|
+
|
|
7
|
+
// src/serializer.ts
|
|
8
|
+
import { createRequire } from "module";
|
|
9
|
+
var DEBUG_ID_PLACEHOLDER = "00000000-0000-0000-0000-000000000000";
|
|
10
|
+
var DEBUG_ID_MODULE_PATH = "__observerkit-debug-id__";
|
|
11
|
+
function createDebugIdModule(code) {
|
|
12
|
+
return {
|
|
13
|
+
path: DEBUG_ID_MODULE_PATH,
|
|
14
|
+
dependencies: /* @__PURE__ */ new Map(),
|
|
15
|
+
getSource: () => Buffer.from(code),
|
|
16
|
+
inverseDependencies: /* @__PURE__ */ new Set(),
|
|
17
|
+
output: [
|
|
18
|
+
{
|
|
19
|
+
type: "js/script/virtual",
|
|
20
|
+
data: { code, lineCount: 1, map: [] }
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function injectDebugIdModule(preModules, debugIdModule) {
|
|
26
|
+
if (preModules.some((m) => m.path === DEBUG_ID_MODULE_PATH)) return preModules;
|
|
27
|
+
const preludeIndex = preModules.findIndex((m) => m.path === "__prelude__");
|
|
28
|
+
if (preludeIndex === -1) return [debugIdModule, ...preModules];
|
|
29
|
+
return [
|
|
30
|
+
...preModules.slice(0, preludeIndex + 1),
|
|
31
|
+
debugIdModule,
|
|
32
|
+
...preModules.slice(preludeIndex + 1)
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
function addDebugIdToMap(map, debugId) {
|
|
36
|
+
let parsed;
|
|
37
|
+
try {
|
|
38
|
+
parsed = JSON.parse(map);
|
|
39
|
+
} catch {
|
|
40
|
+
return map;
|
|
41
|
+
}
|
|
42
|
+
if (!isJsonObject(parsed)) return map;
|
|
43
|
+
return JSON.stringify({ ...parsed, debugId });
|
|
44
|
+
}
|
|
45
|
+
function unwrapModuleExport(mod, exportName) {
|
|
46
|
+
if (exportName) {
|
|
47
|
+
const named = isJsonObject(mod) ? mod[exportName] : void 0;
|
|
48
|
+
if (typeof named === "function") return named;
|
|
49
|
+
}
|
|
50
|
+
const defaultExport = isJsonObject(mod) ? mod["default"] : void 0;
|
|
51
|
+
if (typeof defaultExport === "function") return defaultExport;
|
|
52
|
+
if (typeof mod === "function") return mod;
|
|
53
|
+
throw new Error(
|
|
54
|
+
`[ObserverKit] Could not resolve${exportName ? ` a "${exportName}" or` : ""} a default export from a Metro internal module.`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
function loadDefaultSerializer() {
|
|
58
|
+
const require2 = createRequire(import.meta.url);
|
|
59
|
+
const load = (id, exportName) => {
|
|
60
|
+
const mod = require2(id);
|
|
61
|
+
return unwrapModuleExport(mod, exportName);
|
|
62
|
+
};
|
|
63
|
+
let baseJSBundle;
|
|
64
|
+
let bundleToString;
|
|
65
|
+
let sourceMapString;
|
|
66
|
+
try {
|
|
67
|
+
baseJSBundle = load("metro/src/DeltaBundler/Serializers/baseJSBundle");
|
|
68
|
+
bundleToString = load("metro/src/lib/bundleToString");
|
|
69
|
+
sourceMapString = load(
|
|
70
|
+
"metro/src/DeltaBundler/Serializers/sourceMapString",
|
|
71
|
+
"sourceMapString"
|
|
72
|
+
);
|
|
73
|
+
} catch (err) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
"[ObserverKit] Could not load Metro's serializer internals. Add metro as a devDependency of your app (pnpm add -D metro) or set a customSerializer in metro.config.js before withObserverkit.",
|
|
76
|
+
{ cause: err }
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return (entryPoint, preModules, graph, options) => {
|
|
80
|
+
const bundle = baseJSBundle.apply(void 0, [entryPoint, preModules, graph, options]);
|
|
81
|
+
const { code } = bundleToString.apply(void 0, [bundle]);
|
|
82
|
+
if (options.dev) return code;
|
|
83
|
+
const sortedModules = [...graph.dependencies.values()].sort(
|
|
84
|
+
(a, b) => options.createModuleId(a.path) - options.createModuleId(b.path)
|
|
85
|
+
);
|
|
86
|
+
const map = sourceMapString.apply(void 0, [
|
|
87
|
+
[...preModules, ...sortedModules],
|
|
88
|
+
{
|
|
89
|
+
excludeSource: false,
|
|
90
|
+
processModuleFilter: options.processModuleFilter,
|
|
91
|
+
shouldAddToIgnoreList: options.shouldAddToIgnoreList
|
|
92
|
+
}
|
|
93
|
+
]);
|
|
94
|
+
return { code, map };
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function createObserverkitSerializer(wrapped) {
|
|
98
|
+
return async (entryPoint, preModules, graph, options) => {
|
|
99
|
+
const serializer = wrapped ?? loadDefaultSerializer();
|
|
100
|
+
if (options.dev) {
|
|
101
|
+
return serializer(entryPoint, preModules, graph, options);
|
|
102
|
+
}
|
|
103
|
+
const { snippet } = buildStackKeyedDebugIdSnippet(DEBUG_ID_PLACEHOLDER);
|
|
104
|
+
const withDebugId = injectDebugIdModule(preModules, createDebugIdModule(snippet));
|
|
105
|
+
const result = await serializer(entryPoint, withDebugId, graph, options);
|
|
106
|
+
const code = typeof result === "string" ? result : result.code;
|
|
107
|
+
const map = typeof result === "string" ? null : result.map;
|
|
108
|
+
const debugId = generateDebugId(code);
|
|
109
|
+
const finalCode = `${code.split(DEBUG_ID_PLACEHOLDER).join(debugId)}
|
|
110
|
+
//# debugId=${debugId}`;
|
|
111
|
+
if (map === null) return finalCode;
|
|
112
|
+
return { code: finalCode, map: addDebugIdToMap(map, debugId) };
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/index.ts
|
|
117
|
+
function withObserverkit(config) {
|
|
118
|
+
return {
|
|
119
|
+
...config,
|
|
120
|
+
serializer: {
|
|
121
|
+
...config.serializer,
|
|
122
|
+
customSerializer: createObserverkitSerializer(
|
|
123
|
+
config.serializer?.customSerializer
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
export {
|
|
129
|
+
DEBUG_ID_PLACEHOLDER,
|
|
130
|
+
createObserverkitSerializer,
|
|
131
|
+
withObserverkit as default
|
|
132
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@observerkit/metro",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Metro plugin for ObserverKit: injects debug IDs and uploads React Native source maps",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
17
|
+
},
|
|
18
|
+
"./expo": {
|
|
19
|
+
"types": "./dist/expo.d.ts",
|
|
20
|
+
"import": "./dist/expo.js",
|
|
21
|
+
"require": "./dist/expo.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"observerkit-upload": "./dist/cli.cjs"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"metro": ">=0.80.0",
|
|
32
|
+
"@expo/config-plugins": ">=8.0.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"metro": {
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
"@expo/config-plugins": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@expo/config-plugins": "^57.0.0",
|
|
44
|
+
"@types/node": "^22",
|
|
45
|
+
"tsup": "^8.3.5",
|
|
46
|
+
"typescript": "5.9.2",
|
|
47
|
+
"vitest": "^3.2.4",
|
|
48
|
+
"@repo/plugin-core": "0.0.0"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"uuid": "^13.0.0"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsup",
|
|
55
|
+
"test": "vitest run",
|
|
56
|
+
"test:watch": "vitest",
|
|
57
|
+
"typecheck": "tsc --noEmit"
|
|
58
|
+
}
|
|
59
|
+
}
|