@weapp-tailwindcss/react-native 0.3.4 → 0.3.6
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 +14 -0
- package/README.zh-CN.md +14 -0
- package/dist/babel.cjs +2 -3
- package/dist/babel.d.cts +6 -0
- package/dist/babel.d.ts +2 -3
- package/dist/babel.js +1 -2
- package/dist/compiler.cjs +12 -2
- package/dist/compiler.d.cts +7 -0
- package/dist/compiler.d.ts +1 -3
- package/dist/compiler.js +13 -3
- package/dist/env.d.cts +10 -0
- package/dist/env.d.ts +1 -3
- package/dist/index.cjs +7 -3
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +4 -4
- package/dist/manifest-DRxbQp2v.cjs +47 -0
- package/dist/manifest-DuhmZ2T9.js +24 -0
- package/dist/metro-BdsKKvRn.d.cts +63 -0
- package/dist/{metro-BZbdIyTH.js → metro-OMh6z1jy.js} +216 -97
- package/dist/metro-ahmChgsA.d.ts +63 -0
- package/dist/{metro-Ds2ZUc6_.cjs → metro-kaKzXOAU.cjs} +238 -101
- package/dist/metro-transformer.cjs +5 -11
- package/dist/metro-transformer.d.cts +2 -0
- package/dist/metro-transformer.d.ts +1 -3
- package/dist/metro-transformer.js +4 -10
- package/dist/metro.cjs +4 -1
- package/dist/metro.d.cts +2 -0
- package/dist/metro.d.ts +2 -53
- package/dist/metro.js +1 -2
- package/dist/{rolldown-runtime-VH7oDXx4.cjs → rolldown-runtime-CmQyd0Gu.cjs} +1 -2
- package/dist/runtime-CbkbHrPb.cjs +383 -0
- package/dist/runtime-D4ZGX6yk.d.cts +42 -0
- package/dist/runtime-DuvYZu4P.js +330 -0
- package/dist/{runtime-B3hAisFx.d.ts → runtime-YHlnn5ip.d.ts} +20 -12
- package/dist/runtime.cjs +10 -186
- package/dist/runtime.d.cts +3 -0
- package/dist/runtime.d.ts +3 -3
- package/dist/runtime.js +1 -179
- package/dist/tailwind-4T0v_pRK.d.ts +13 -0
- package/dist/tailwind-B1Gl9P_t.js +121 -0
- package/dist/tailwind-CVspvWID.cjs +129 -0
- package/dist/tailwind-CfKLPJuW.d.cts +13 -0
- package/dist/tailwind.cjs +2 -58
- package/dist/tailwind.d.cts +2 -0
- package/dist/tailwind.d.ts +2 -16
- package/dist/tailwind.js +1 -55
- package/dist/{types-CKAFTXX9.d.ts → types-CxNMLBiF.d.cts} +6 -3
- package/dist/types-CxNMLBiF.d.ts +20 -0
- package/package.json +75 -33
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { compileNativeStylesheet } from "./compiler.js";
|
|
2
|
+
import { i as parseManifestSnapshot, n as copyPublication, r as freezeSnapshot } from "./manifest-DuhmZ2T9.js";
|
|
2
3
|
import { createRequire } from "node:module";
|
|
3
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
5
|
import fs from "node:fs";
|
|
@@ -7,7 +8,14 @@ import path from "node:path";
|
|
|
7
8
|
import process from "node:process";
|
|
8
9
|
import { URL, fileURLToPath } from "node:url";
|
|
9
10
|
import { setTimeout } from "node:timers/promises";
|
|
10
|
-
|
|
11
|
+
// src/metro/manifest-store.ts
|
|
12
|
+
function throwWhenAborted(signal) {
|
|
13
|
+
if (!signal?.aborted) return;
|
|
14
|
+
if ("reason" in signal) throw signal.reason;
|
|
15
|
+
const error = /* @__PURE__ */ new Error("React Native manifest 读取已取消");
|
|
16
|
+
error.name = "AbortError";
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
11
19
|
/** 同目录替换,避免 Metro 或 worker 读到截断后的虚拟模块与 JSON。 */
|
|
12
20
|
function writeManifestFile(filename, content) {
|
|
13
21
|
const temporary = `${filename}.${randomUUID()}.tmp`;
|
|
@@ -19,40 +27,98 @@ function writeManifestFile(filename, content) {
|
|
|
19
27
|
}
|
|
20
28
|
}
|
|
21
29
|
/** ready 前后版本一致才接受产物;失败和超时不能降级成旧 manifest。 */
|
|
22
|
-
async function readPublishedSnapshot(filename, readyPath) {
|
|
30
|
+
async function readPublishedSnapshot(filename, readyPath, signal) {
|
|
31
|
+
throwWhenAborted(signal);
|
|
23
32
|
if (!readyPath) try {
|
|
24
|
-
|
|
33
|
+
const manifestJson = await fs.promises.readFile(filename, {
|
|
34
|
+
encoding: "utf8",
|
|
35
|
+
signal
|
|
36
|
+
});
|
|
37
|
+
return freezeSnapshot({
|
|
38
|
+
manifest: parseManifestSnapshot(manifestJson),
|
|
39
|
+
manifestJson
|
|
40
|
+
});
|
|
25
41
|
} catch (error) {
|
|
26
42
|
if (error.code === "ENOENT") return;
|
|
27
43
|
throw error;
|
|
28
44
|
}
|
|
29
45
|
const deadline = Date.now() + 12e4;
|
|
30
46
|
while (Date.now() < deadline) {
|
|
47
|
+
throwWhenAborted(signal);
|
|
31
48
|
try {
|
|
32
|
-
const before = await fs.promises.readFile(readyPath,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
const before = await fs.promises.readFile(readyPath, {
|
|
50
|
+
encoding: "utf8",
|
|
51
|
+
signal
|
|
52
|
+
});
|
|
53
|
+
const ready = JSON.parse(before);
|
|
54
|
+
if (ready?.error) {
|
|
55
|
+
if (before !== await fs.promises.readFile(readyPath, {
|
|
56
|
+
encoding: "utf8",
|
|
57
|
+
signal
|
|
58
|
+
})) continue;
|
|
59
|
+
throw new Error(ready.error);
|
|
60
|
+
}
|
|
61
|
+
if (!ready || typeof ready.virtualPath !== "string" || !ready.virtualPath || !ready.revision || !ready.manifestSha256) throw new Error("React Native manifest 缺少发布身份");
|
|
62
|
+
const publication = copyPublication({
|
|
63
|
+
revision: ready.revision,
|
|
64
|
+
manifestSha256: ready.manifestSha256
|
|
65
|
+
});
|
|
66
|
+
const content = await fs.promises.readFile(filename, {
|
|
67
|
+
encoding: "utf8",
|
|
68
|
+
signal
|
|
69
|
+
});
|
|
70
|
+
if (before === await fs.promises.readFile(readyPath, {
|
|
71
|
+
encoding: "utf8",
|
|
72
|
+
signal
|
|
73
|
+
})) {
|
|
74
|
+
if (createHash("sha256").update(content, "utf8").digest("hex") !== publication.manifestSha256) throw new Error("React Native manifest 字节摘要不匹配");
|
|
75
|
+
return freezeSnapshot({
|
|
76
|
+
manifest: parseManifestSnapshot(content),
|
|
77
|
+
manifestJson: content,
|
|
78
|
+
virtualPath: ready.virtualPath,
|
|
79
|
+
publication
|
|
80
|
+
});
|
|
46
81
|
}
|
|
47
82
|
} catch (error) {
|
|
48
83
|
if (error.code !== "ENOENT") throw error;
|
|
49
84
|
}
|
|
50
|
-
await setTimeout(25);
|
|
85
|
+
await setTimeout(25, void 0, { signal });
|
|
51
86
|
}
|
|
52
87
|
throw new Error(`等待 React Native manifest 超时:${filename}`);
|
|
53
88
|
}
|
|
54
|
-
|
|
55
|
-
|
|
89
|
+
// src/metro/virtual-module.ts
|
|
90
|
+
function virtualModuleCode(manifest, publication, manifestJson = JSON.stringify(manifest)) {
|
|
91
|
+
const identity = publication ? `, ${JSON.stringify(publication)}` : "";
|
|
92
|
+
return `import { setEnvironment, setManifest, setStyleSheetFactory } from ${JSON.stringify("@weapp-tailwindcss/react-native/runtime")};\nimport { Appearance, Platform, StyleSheet } from 'react-native';\nsetStyleSheetFactory(StyleSheet.create, StyleSheet.flatten);\nconst syncEnvironment = () => setEnvironment({ platform: Platform.OS, colorScheme: Appearance.getColorScheme() ?? 'light' });\nsetManifest(${manifestJson}${identity});\nsyncEnvironment();\nAppearance.addChangeListener?.(({ colorScheme }) => setEnvironment({ platform: Platform.OS, colorScheme: colorScheme ?? 'light' }));\nexport default undefined;`;
|
|
93
|
+
}
|
|
94
|
+
// src/metro/publication.ts
|
|
95
|
+
function createManifestSnapshot(manifest, virtualPath, version) {
|
|
96
|
+
const manifestJson = JSON.stringify(manifest);
|
|
97
|
+
const publication = version > 0 ? {
|
|
98
|
+
revision: randomUUID(),
|
|
99
|
+
manifestSha256: createHash("sha256").update(manifestJson, "utf8").digest("hex")
|
|
100
|
+
} : void 0;
|
|
101
|
+
return freezeSnapshot({
|
|
102
|
+
manifest: parseManifestSnapshot(manifestJson),
|
|
103
|
+
manifestJson,
|
|
104
|
+
virtualPath,
|
|
105
|
+
version,
|
|
106
|
+
...publication ? { publication } : {}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/** 三份产物共用一次序列化;最后的 ready 成功前不提交内存状态。 */
|
|
110
|
+
function writeManifestSnapshot(paths, snapshot) {
|
|
111
|
+
fs.mkdirSync(path.dirname(snapshot.virtualPath), { recursive: true });
|
|
112
|
+
fs.mkdirSync(path.dirname(paths.manifestPath), { recursive: true });
|
|
113
|
+
writeManifestFile(snapshot.virtualPath, virtualModuleCode(snapshot.manifest, snapshot.publication, snapshot.manifestJson));
|
|
114
|
+
writeManifestFile(paths.manifestPath, snapshot.manifestJson);
|
|
115
|
+
if (snapshot.publication) writeManifestFile(paths.manifestReadyPath, JSON.stringify({
|
|
116
|
+
...snapshot.publication,
|
|
117
|
+
version: snapshot.version,
|
|
118
|
+
virtualPath: snapshot.virtualPath
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
// src/metro/refresh.ts
|
|
56
122
|
function fingerprint(files) {
|
|
57
123
|
const hash = createHash("sha256");
|
|
58
124
|
for (const file of files) try {
|
|
@@ -91,8 +157,26 @@ async function compileStableInput(files, compile, isCurrent) {
|
|
|
91
157
|
}
|
|
92
158
|
if (isCurrent()) throw new Error("React Native 样式输入持续变化,5 次稳定性检查后仍未完成保存;请完成保存后重试。");
|
|
93
159
|
}
|
|
94
|
-
|
|
95
|
-
|
|
160
|
+
// src/metro/registry.ts
|
|
161
|
+
const registry = /* @__PURE__ */ new Map();
|
|
162
|
+
const publicEntries = /* @__PURE__ */ new WeakMap();
|
|
163
|
+
function getRegisteredVirtualModule(filename) {
|
|
164
|
+
const entry = [...registry.values()].find((entry) => entry.virtualPath === filename);
|
|
165
|
+
if (!entry) return;
|
|
166
|
+
let view = publicEntries.get(entry);
|
|
167
|
+
if (!view) {
|
|
168
|
+
const properties = Object.fromEntries(Object.keys(entry).map((key) => [key, {
|
|
169
|
+
enumerable: true,
|
|
170
|
+
get: () => entry[key]
|
|
171
|
+
}]));
|
|
172
|
+
view = Object.freeze(Object.defineProperties({}, properties));
|
|
173
|
+
publicEntries.set(entry, view);
|
|
174
|
+
}
|
|
175
|
+
return view;
|
|
176
|
+
}
|
|
177
|
+
/** 检查 ready 与返回 snapshot 在同一微任务内完成,不能夹入新的刷新。 */
|
|
178
|
+
async function readRegisteredSnapshot(entry) {
|
|
179
|
+
if (!entry) return;
|
|
96
180
|
for (;;) {
|
|
97
181
|
const ready = entry.ready;
|
|
98
182
|
try {
|
|
@@ -100,31 +184,106 @@ async function waitForCurrentRefresh(entry) {
|
|
|
100
184
|
} catch (error) {
|
|
101
185
|
if (ready === entry.ready) throw error;
|
|
102
186
|
}
|
|
103
|
-
if (ready === entry.ready) return;
|
|
187
|
+
if (ready === entry.ready) return entry.snapshot;
|
|
104
188
|
}
|
|
105
189
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
190
|
+
function getRegisteredSnapshot(id) {
|
|
191
|
+
return readRegisteredSnapshot(registry.get(id));
|
|
192
|
+
}
|
|
193
|
+
/** 文件路径与项目根目录查询均选择最近注册的入口,不能混用两个实例的身份。 */
|
|
194
|
+
function getRegisteredSnapshotByPath(filename) {
|
|
195
|
+
return readRegisteredSnapshot([...registry.values()].filter((entry) => entry.manifestPath === filename).at(-1));
|
|
196
|
+
}
|
|
197
|
+
function getRegisteredSnapshotByProjectRoot(projectRoot) {
|
|
198
|
+
const resolvedRoot = path.resolve(projectRoot);
|
|
199
|
+
return readRegisteredSnapshot([...registry.values()].filter((entry) => entry.projectRoot === resolvedRoot).at(-1));
|
|
200
|
+
}
|
|
201
|
+
async function getRegisteredManifest(id) {
|
|
202
|
+
return (await getRegisteredSnapshot(id))?.manifest;
|
|
203
|
+
}
|
|
204
|
+
async function getRegisteredManifestByPath(filename) {
|
|
205
|
+
return (await getRegisteredSnapshotByPath(filename))?.manifest;
|
|
206
|
+
}
|
|
207
|
+
async function getRegisteredManifestByProjectRoot(projectRoot) {
|
|
208
|
+
return (await getRegisteredSnapshotByProjectRoot(projectRoot))?.manifest;
|
|
209
|
+
}
|
|
210
|
+
/** 同步读取最近快照供诊断;只有异步入口会等待当前发布成功。 */
|
|
211
|
+
function getVirtualModuleCode(filename) {
|
|
212
|
+
const snapshot = getRegisteredVirtualModule(filename)?.snapshot;
|
|
213
|
+
return snapshot ? virtualModuleCode(snapshot.manifest, snapshot.publication, snapshot.manifestJson) : void 0;
|
|
214
|
+
}
|
|
215
|
+
async function getVirtualModuleCodeAsync(filename) {
|
|
216
|
+
const snapshot = await readRegisteredSnapshot(getRegisteredVirtualModule(filename));
|
|
217
|
+
return snapshot ? virtualModuleCode(snapshot.manifest, snapshot.publication, snapshot.manifestJson) : void 0;
|
|
218
|
+
}
|
|
219
|
+
// src/metro/watch.ts
|
|
220
|
+
function fileVersion(stat) {
|
|
221
|
+
return [
|
|
222
|
+
stat.dev,
|
|
223
|
+
stat.ino,
|
|
224
|
+
stat.size,
|
|
225
|
+
stat.mtimeNs,
|
|
226
|
+
stat.ctimeNs
|
|
227
|
+
].join(":");
|
|
228
|
+
}
|
|
229
|
+
function readFileVersion(target) {
|
|
230
|
+
try {
|
|
231
|
+
return fileVersion(fs.statSync(target, { bigint: true }));
|
|
232
|
+
} catch (error) {
|
|
233
|
+
if (["ENOENT", "ENOTDIR"].includes(error.code ?? "")) return;
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
110
236
|
}
|
|
111
|
-
|
|
112
|
-
//#region src/metro/watch.ts
|
|
113
|
-
/** 文件监听绑定父目录,避免编辑器原子替换文件后仍监听已移除的 inode。 */
|
|
237
|
+
/** 父目录事件提供即时通知,文件版本核对补齐原生通知遗漏。 */
|
|
114
238
|
function watchInput(target, changed) {
|
|
115
|
-
const
|
|
239
|
+
const initial = fs.statSync(target, { bigint: true });
|
|
240
|
+
const recursive = initial.isDirectory();
|
|
116
241
|
const watchRoot = recursive ? target : path.dirname(target);
|
|
117
|
-
|
|
242
|
+
let version = fileVersion(initial);
|
|
243
|
+
let closed = false;
|
|
244
|
+
let timer;
|
|
245
|
+
const watcher = fs.watch(watchRoot, {
|
|
118
246
|
persistent: false,
|
|
119
247
|
recursive
|
|
120
248
|
}, (_event, filename) => {
|
|
121
|
-
if (
|
|
249
|
+
if (closed) return;
|
|
250
|
+
if (recursive) changed();
|
|
251
|
+
else if (filename === null || path.resolve(watchRoot, filename) === target) reconcile(true);
|
|
122
252
|
});
|
|
253
|
+
function reconcile(force) {
|
|
254
|
+
if (closed) return;
|
|
255
|
+
let current;
|
|
256
|
+
try {
|
|
257
|
+
current = readFileVersion(target);
|
|
258
|
+
} catch (error) {
|
|
259
|
+
watcher.close();
|
|
260
|
+
watcher.emit("error", error);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (force || current !== version) {
|
|
264
|
+
version = current;
|
|
265
|
+
changed();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
const stop = () => {
|
|
269
|
+
closed = true;
|
|
270
|
+
clearInterval(timer);
|
|
271
|
+
};
|
|
272
|
+
const close = watcher.close.bind(watcher);
|
|
273
|
+
watcher.close = () => {
|
|
274
|
+
if (closed) return;
|
|
275
|
+
stop();
|
|
276
|
+
close();
|
|
277
|
+
};
|
|
278
|
+
watcher.once("close", stop);
|
|
279
|
+
if (!recursive) {
|
|
280
|
+
timer = setInterval(reconcile, 100, false);
|
|
281
|
+
timer.unref();
|
|
282
|
+
}
|
|
283
|
+
return watcher;
|
|
123
284
|
}
|
|
124
|
-
|
|
125
|
-
//#region src/metro.ts
|
|
285
|
+
// src/metro.ts
|
|
126
286
|
const VIRTUAL_MANIFEST_MODULE = "@weapp-tailwindcss/react-native/virtual";
|
|
127
|
-
const registry = /* @__PURE__ */ new Map();
|
|
128
287
|
const appRootSingletonModules = /* @__PURE__ */ new Set(["react"]);
|
|
129
288
|
let nextId = 0;
|
|
130
289
|
function packageNameFromModuleId(moduleName) {
|
|
@@ -172,12 +331,6 @@ function emptyManifest() {
|
|
|
172
331
|
warnings: []
|
|
173
332
|
};
|
|
174
333
|
}
|
|
175
|
-
function writeVirtualModule(entry) {
|
|
176
|
-
fs.mkdirSync(path.dirname(entry.virtualPath), { recursive: true });
|
|
177
|
-
fs.mkdirSync(path.dirname(entry.manifestPath), { recursive: true });
|
|
178
|
-
writeManifestFile(entry.virtualPath, virtualModuleCode(entry.manifest));
|
|
179
|
-
writeManifestFile(entry.manifestPath, JSON.stringify(entry.manifest));
|
|
180
|
-
}
|
|
181
334
|
/**
|
|
182
335
|
* Metro worker 会把文件路径先相对化再恢复为绝对路径。虚拟模块必须位于
|
|
183
336
|
* 项目根目录内,否则 Windows 跨盘符路径会被错误拼接成 `D:\\C:\\...`。
|
|
@@ -188,13 +341,6 @@ function getVirtualModulePath(projectRoot, id) {
|
|
|
188
341
|
function markManifestPending(entry) {
|
|
189
342
|
fs.rmSync(entry.manifestReadyPath, { force: true });
|
|
190
343
|
}
|
|
191
|
-
function markManifestReady(entry) {
|
|
192
|
-
writeManifestFile(entry.manifestReadyPath, JSON.stringify({
|
|
193
|
-
revision: randomUUID(),
|
|
194
|
-
version: entry.version,
|
|
195
|
-
virtualPath: entry.virtualPath
|
|
196
|
-
}));
|
|
197
|
-
}
|
|
198
344
|
async function compileOptions(options, projectRoot) {
|
|
199
345
|
if (options.manifest) return options.manifest;
|
|
200
346
|
if (options.input) {
|
|
@@ -212,37 +358,46 @@ function register(options) {
|
|
|
212
358
|
const id = `weapp-tailwindcss-native-${nextId++}`;
|
|
213
359
|
const projectRoot = path.resolve(options.projectRoot ?? process.cwd());
|
|
214
360
|
const manifestPaths = getManifestPathsForProjectRoot(projectRoot);
|
|
361
|
+
const virtualPath = getVirtualModulePath(projectRoot, id);
|
|
215
362
|
const entry = {
|
|
216
|
-
|
|
217
|
-
|
|
363
|
+
snapshot: createManifestSnapshot(options.manifest ?? (options.css ? compileNativeStylesheet(options.css, { classSet: options.classSet }) : emptyManifest()), virtualPath, 0),
|
|
364
|
+
get version() {
|
|
365
|
+
return this.snapshot.version;
|
|
366
|
+
},
|
|
367
|
+
get manifest() {
|
|
368
|
+
return this.snapshot.manifest;
|
|
369
|
+
},
|
|
218
370
|
projectRoot,
|
|
219
|
-
virtualPath
|
|
371
|
+
virtualPath,
|
|
220
372
|
manifestPath: manifestPaths.manifestPath,
|
|
221
373
|
manifestReadyPath: manifestPaths.manifestReadyPath,
|
|
222
374
|
ready: Promise.resolve(),
|
|
223
375
|
refresh: async () => {}
|
|
224
376
|
};
|
|
377
|
+
fs.mkdirSync(path.dirname(virtualPath), { recursive: true });
|
|
378
|
+
writeManifestFile(virtualPath, virtualModuleCode(entry.snapshot.manifest));
|
|
225
379
|
registry.set(id, entry);
|
|
226
|
-
markManifestPending(entry);
|
|
227
|
-
writeVirtualModule(entry);
|
|
228
380
|
const inputFiles = [...new Set([...options.watchFiles ?? [], ...options.input ? [options.input] : []].map((file) => path.resolve(projectRoot, file)))];
|
|
229
381
|
let generation = 0;
|
|
230
382
|
entry.refresh = () => {
|
|
231
383
|
const currentGeneration = ++generation;
|
|
232
|
-
markManifestPending(entry);
|
|
233
384
|
entry.ready = (async () => {
|
|
234
385
|
try {
|
|
386
|
+
markManifestPending(entry);
|
|
235
387
|
const manifest = await compileStableInput(inputFiles, () => compileOptions(options, projectRoot), () => currentGeneration === generation);
|
|
236
388
|
if (manifest && currentGeneration === generation) {
|
|
237
|
-
entry.
|
|
238
|
-
entry
|
|
239
|
-
|
|
240
|
-
markManifestReady(entry);
|
|
389
|
+
const snapshot = createManifestSnapshot(manifest, entry.virtualPath, entry.version + 1);
|
|
390
|
+
writeManifestSnapshot(entry, snapshot);
|
|
391
|
+
entry.snapshot = snapshot;
|
|
241
392
|
}
|
|
242
393
|
} catch (error) {
|
|
243
394
|
if (currentGeneration !== generation) return;
|
|
244
395
|
const message = `生成 React Native manifest 失败:${error instanceof Error ? error.message : String(error)}`;
|
|
245
|
-
|
|
396
|
+
try {
|
|
397
|
+
writeManifestFile(entry.manifestReadyPath, JSON.stringify({ error: message }));
|
|
398
|
+
} catch (publicationError) {
|
|
399
|
+
throw new AggregateError([error, publicationError], message, { cause: error });
|
|
400
|
+
}
|
|
246
401
|
throw new Error(message, { cause: error });
|
|
247
402
|
}
|
|
248
403
|
})();
|
|
@@ -270,41 +425,6 @@ function register(options) {
|
|
|
270
425
|
entry
|
|
271
426
|
};
|
|
272
427
|
}
|
|
273
|
-
function getRegisteredVirtualModule(filename) {
|
|
274
|
-
for (const entry of registry.values()) if (entry.virtualPath === filename) return entry;
|
|
275
|
-
}
|
|
276
|
-
async function getRegisteredManifest(id) {
|
|
277
|
-
const registered = registry.get(id);
|
|
278
|
-
if (!registered) return;
|
|
279
|
-
await waitForCurrentRefresh(registered);
|
|
280
|
-
return registered.manifest;
|
|
281
|
-
}
|
|
282
|
-
/** 等待并读取由 Metro 配置注册的 manifest 文件,兼容未透传自定义 Metro id 的 transformer。 */
|
|
283
|
-
async function getRegisteredManifestByPath(filename) {
|
|
284
|
-
for (const entry of registry.values()) if (entry.manifestPath === filename) {
|
|
285
|
-
await waitForCurrentRefresh(entry);
|
|
286
|
-
return entry.manifest;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
/** 按 Metro 传入的项目根目录读取当前注册项,兼容 transformer 未透传自定义字段的实现。 */
|
|
290
|
-
async function getRegisteredManifestByProjectRoot(projectRoot) {
|
|
291
|
-
const resolvedRoot = path.resolve(projectRoot);
|
|
292
|
-
const entry = [...registry.values()].filter((entry) => entry.projectRoot === resolvedRoot).at(-1);
|
|
293
|
-
if (!entry) return;
|
|
294
|
-
await waitForCurrentRefresh(entry);
|
|
295
|
-
return entry.manifest;
|
|
296
|
-
}
|
|
297
|
-
function getVirtualModuleCode(filename) {
|
|
298
|
-
const registered = getRegisteredVirtualModule(filename);
|
|
299
|
-
if (!registered) return;
|
|
300
|
-
return virtualModuleCode(registered.manifest);
|
|
301
|
-
}
|
|
302
|
-
async function getVirtualModuleCodeAsync(filename) {
|
|
303
|
-
const registered = getRegisteredVirtualModule(filename);
|
|
304
|
-
if (!registered) return;
|
|
305
|
-
await waitForCurrentRefresh(registered);
|
|
306
|
-
return getVirtualModuleCode(filename);
|
|
307
|
-
}
|
|
308
428
|
function withWeappTailwindcss(config, options = {}) {
|
|
309
429
|
if (typeof config === "function" || config && typeof config.then === "function") return Promise.resolve(typeof config === "function" ? config() : config).then((resolved) => withWeappTailwindcss(resolved, options));
|
|
310
430
|
const resolvedConfig = config;
|
|
@@ -349,5 +469,4 @@ function withWeappTailwindcss(config, options = {}) {
|
|
|
349
469
|
}
|
|
350
470
|
};
|
|
351
471
|
}
|
|
352
|
-
|
|
353
|
-
export { getRegisteredManifestByProjectRoot as a, getVirtualModuleCodeAsync as c, waitForCurrentRefresh as d, readPublishedSnapshot as f, getRegisteredManifestByPath as i, withWeappTailwindcss as l, getManifestPathsForProjectRoot as n, getRegisteredVirtualModule as o, getRegisteredManifest as r, getVirtualModuleCode as s, VIRTUAL_MANIFEST_MODULE as t, virtualModuleCode as u };
|
|
472
|
+
export { getRegisteredManifestByPath as a, getRegisteredSnapshotByPath as c, getVirtualModuleCode as d, getVirtualModuleCodeAsync as f, readPublishedSnapshot as h, getRegisteredManifest as i, getRegisteredSnapshotByProjectRoot as l, virtualModuleCode as m, getManifestPathsForProjectRoot as n, getRegisteredManifestByProjectRoot as o, readRegisteredSnapshot as p, withWeappTailwindcss as r, getRegisteredSnapshot as s, VIRTUAL_MANIFEST_MODULE as t, getRegisteredVirtualModule as u };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { a as NativeStyleManifest, r as NativeManifestPublication } from "./types-CxNMLBiF.js";
|
|
2
|
+
interface NativeManifestSnapshot {
|
|
3
|
+
version: number;
|
|
4
|
+
manifest: NativeStyleManifest;
|
|
5
|
+
manifestJson: string;
|
|
6
|
+
virtualPath: string;
|
|
7
|
+
publication?: NativeManifestPublication;
|
|
8
|
+
}
|
|
9
|
+
interface RegisteredManifest {
|
|
10
|
+
readonly version: number;
|
|
11
|
+
readonly manifest: NativeManifestSnapshot['manifest'];
|
|
12
|
+
snapshot: NativeManifestSnapshot;
|
|
13
|
+
projectRoot: string;
|
|
14
|
+
virtualPath: string;
|
|
15
|
+
manifestPath: string;
|
|
16
|
+
manifestReadyPath: string;
|
|
17
|
+
ready: Promise<void>;
|
|
18
|
+
refresh: () => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
declare function getRegisteredVirtualModule(filename: string): Readonly<RegisteredManifest> | undefined;
|
|
21
|
+
declare function getRegisteredSnapshot(id: string): Promise<NativeManifestSnapshot | undefined>;
|
|
22
|
+
/** 文件路径与项目根目录查询均选择最近注册的入口,不能混用两个实例的身份。 */
|
|
23
|
+
declare function getRegisteredSnapshotByPath(filename: string): Promise<NativeManifestSnapshot | undefined>;
|
|
24
|
+
declare function getRegisteredSnapshotByProjectRoot(projectRoot: string): Promise<NativeManifestSnapshot | undefined>;
|
|
25
|
+
declare function getRegisteredManifest(id: string): Promise<NativeStyleManifest | undefined>;
|
|
26
|
+
declare function getRegisteredManifestByPath(filename: string): Promise<NativeStyleManifest | undefined>;
|
|
27
|
+
declare function getRegisteredManifestByProjectRoot(projectRoot: string): Promise<NativeStyleManifest | undefined>;
|
|
28
|
+
/** 同步读取最近快照供诊断;只有异步入口会等待当前发布成功。 */
|
|
29
|
+
declare function getVirtualModuleCode(filename: string): string | undefined;
|
|
30
|
+
declare function getVirtualModuleCodeAsync(filename: string): Promise<string | undefined>;
|
|
31
|
+
declare const VIRTUAL_MANIFEST_MODULE = "@weapp-tailwindcss/react-native/virtual";
|
|
32
|
+
interface MetroConfigLike {
|
|
33
|
+
resolver?: {
|
|
34
|
+
extraNodeModules?: Record<string, string>;
|
|
35
|
+
sourceExts?: string[];
|
|
36
|
+
resolveRequest?: (context: unknown, moduleName: string, platform?: string) => unknown;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
};
|
|
39
|
+
transformer?: Record<string, unknown>;
|
|
40
|
+
transformerPath?: string;
|
|
41
|
+
watchFolders?: string[];
|
|
42
|
+
server?: Record<string, unknown>;
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
}
|
|
45
|
+
interface WeappReactNativeMetroOptions {
|
|
46
|
+
projectRoot?: string | undefined;
|
|
47
|
+
input?: string | undefined;
|
|
48
|
+
css?: string | undefined;
|
|
49
|
+
manifest?: NativeStyleManifest | undefined;
|
|
50
|
+
classSet?: Iterable<string> | undefined;
|
|
51
|
+
sourceGlobs?: string[] | undefined;
|
|
52
|
+
watchFiles?: string[] | undefined;
|
|
53
|
+
}
|
|
54
|
+
interface NativeManifestPaths {
|
|
55
|
+
manifestPath: string;
|
|
56
|
+
manifestReadyPath: string;
|
|
57
|
+
}
|
|
58
|
+
/** 为 Metro worker 提供不依赖进程内 registry 的 manifest 入口。 */
|
|
59
|
+
declare function getManifestPathsForProjectRoot(projectRoot: string): NativeManifestPaths;
|
|
60
|
+
declare function withWeappTailwindcss<T extends MetroConfigLike>(config: T, options?: WeappReactNativeMetroOptions): T & MetroConfigLike;
|
|
61
|
+
declare function withWeappTailwindcss<T extends MetroConfigLike>(config: Promise<T> | (() => T | Promise<T>), options?: WeappReactNativeMetroOptions): Promise<T & MetroConfigLike>;
|
|
62
|
+
declare function withWeappTailwindcss<T extends MetroConfigLike>(config: T | Promise<T> | (() => T | Promise<T>), options?: WeappReactNativeMetroOptions): (T & MetroConfigLike) | Promise<T & MetroConfigLike>;
|
|
63
|
+
export { getManifestPathsForProjectRoot as a, getRegisteredManifestByPath as c, getRegisteredSnapshotByPath as d, getRegisteredSnapshotByProjectRoot as f, getVirtualModuleCodeAsync as h, WeappReactNativeMetroOptions as i, getRegisteredManifestByProjectRoot as l, getVirtualModuleCode as m, NativeManifestPaths as n, withWeappTailwindcss as o, getRegisteredVirtualModule as p, VIRTUAL_MANIFEST_MODULE as r, getRegisteredManifest as s, MetroConfigLike as t, getRegisteredSnapshot as u };
|