@weapp-tailwindcss/react-native 0.3.3 → 0.3.5
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.ts +1 -2
- package/dist/babel.js +1 -2
- package/dist/compiler.cjs +12 -2
- package/dist/compiler.d.ts +1 -3
- package/dist/compiler.js +13 -3
- package/dist/env.d.ts +1 -3
- package/dist/index.cjs +7 -3
- 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-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.ts +1 -3
- package/dist/metro-transformer.js +4 -10
- package/dist/metro.cjs +4 -1
- 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-BivP43Uy.cjs +382 -0
- package/dist/{runtime-B3hAisFx.d.ts → runtime-Bm9mAKDC.d.ts} +13 -10
- package/dist/runtime-BzHdtM5_.js +329 -0
- package/dist/runtime.cjs +10 -186
- 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.cjs +2 -58
- package/dist/tailwind.d.ts +2 -16
- package/dist/tailwind.js +1 -55
- package/dist/{types-CKAFTXX9.d.ts → types-CxNMLBiF.d.ts} +6 -3
- package/package.json +9 -8
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
const require_rolldown_runtime = require("./rolldown-runtime-
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-CmQyd0Gu.cjs");
|
|
2
2
|
const require_compiler = require("./compiler.cjs");
|
|
3
|
+
const require_manifest = require("./manifest-DRxbQp2v.cjs");
|
|
3
4
|
let node_crypto = require("node:crypto");
|
|
4
5
|
let node_fs = require("node:fs");
|
|
5
6
|
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
@@ -12,7 +13,14 @@ let node_process = require("node:process");
|
|
|
12
13
|
node_process = require_rolldown_runtime.__toESM(node_process, 1);
|
|
13
14
|
let node_url = require("node:url");
|
|
14
15
|
let node_timers_promises = require("node:timers/promises");
|
|
15
|
-
|
|
16
|
+
// src/metro/manifest-store.ts
|
|
17
|
+
function throwWhenAborted(signal) {
|
|
18
|
+
if (!signal?.aborted) return;
|
|
19
|
+
if ("reason" in signal) throw signal.reason;
|
|
20
|
+
const error = /* @__PURE__ */ new Error("React Native manifest 读取已取消");
|
|
21
|
+
error.name = "AbortError";
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
16
24
|
/** 同目录替换,避免 Metro 或 worker 读到截断后的虚拟模块与 JSON。 */
|
|
17
25
|
function writeManifestFile(filename, content) {
|
|
18
26
|
const temporary = `${filename}.${(0, node_crypto.randomUUID)()}.tmp`;
|
|
@@ -24,40 +32,98 @@ function writeManifestFile(filename, content) {
|
|
|
24
32
|
}
|
|
25
33
|
}
|
|
26
34
|
/** ready 前后版本一致才接受产物;失败和超时不能降级成旧 manifest。 */
|
|
27
|
-
async function readPublishedSnapshot(filename, readyPath) {
|
|
35
|
+
async function readPublishedSnapshot(filename, readyPath, signal) {
|
|
36
|
+
throwWhenAborted(signal);
|
|
28
37
|
if (!readyPath) try {
|
|
29
|
-
|
|
38
|
+
const manifestJson = await node_fs.default.promises.readFile(filename, {
|
|
39
|
+
encoding: "utf8",
|
|
40
|
+
signal
|
|
41
|
+
});
|
|
42
|
+
return require_manifest.freezeSnapshot({
|
|
43
|
+
manifest: require_manifest.parseManifestSnapshot(manifestJson),
|
|
44
|
+
manifestJson
|
|
45
|
+
});
|
|
30
46
|
} catch (error) {
|
|
31
47
|
if (error.code === "ENOENT") return;
|
|
32
48
|
throw error;
|
|
33
49
|
}
|
|
34
50
|
const deadline = Date.now() + 12e4;
|
|
35
51
|
while (Date.now() < deadline) {
|
|
52
|
+
throwWhenAborted(signal);
|
|
36
53
|
try {
|
|
37
|
-
const before = await node_fs.default.promises.readFile(readyPath,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
const before = await node_fs.default.promises.readFile(readyPath, {
|
|
55
|
+
encoding: "utf8",
|
|
56
|
+
signal
|
|
57
|
+
});
|
|
58
|
+
const ready = JSON.parse(before);
|
|
59
|
+
if (ready?.error) {
|
|
60
|
+
if (before !== await node_fs.default.promises.readFile(readyPath, {
|
|
61
|
+
encoding: "utf8",
|
|
62
|
+
signal
|
|
63
|
+
})) continue;
|
|
64
|
+
throw new Error(ready.error);
|
|
65
|
+
}
|
|
66
|
+
if (!ready || typeof ready.virtualPath !== "string" || !ready.virtualPath || !ready.revision || !ready.manifestSha256) throw new Error("React Native manifest 缺少发布身份");
|
|
67
|
+
const publication = require_manifest.copyPublication({
|
|
68
|
+
revision: ready.revision,
|
|
69
|
+
manifestSha256: ready.manifestSha256
|
|
70
|
+
});
|
|
71
|
+
const content = await node_fs.default.promises.readFile(filename, {
|
|
72
|
+
encoding: "utf8",
|
|
73
|
+
signal
|
|
74
|
+
});
|
|
75
|
+
if (before === await node_fs.default.promises.readFile(readyPath, {
|
|
76
|
+
encoding: "utf8",
|
|
77
|
+
signal
|
|
78
|
+
})) {
|
|
79
|
+
if ((0, node_crypto.createHash)("sha256").update(content, "utf8").digest("hex") !== publication.manifestSha256) throw new Error("React Native manifest 字节摘要不匹配");
|
|
80
|
+
return require_manifest.freezeSnapshot({
|
|
81
|
+
manifest: require_manifest.parseManifestSnapshot(content),
|
|
82
|
+
manifestJson: content,
|
|
83
|
+
virtualPath: ready.virtualPath,
|
|
84
|
+
publication
|
|
85
|
+
});
|
|
51
86
|
}
|
|
52
87
|
} catch (error) {
|
|
53
88
|
if (error.code !== "ENOENT") throw error;
|
|
54
89
|
}
|
|
55
|
-
await (0, node_timers_promises.setTimeout)(25);
|
|
90
|
+
await (0, node_timers_promises.setTimeout)(25, void 0, { signal });
|
|
56
91
|
}
|
|
57
92
|
throw new Error(`等待 React Native manifest 超时:${filename}`);
|
|
58
93
|
}
|
|
59
|
-
|
|
60
|
-
|
|
94
|
+
// src/metro/virtual-module.ts
|
|
95
|
+
function virtualModuleCode(manifest, publication, manifestJson = JSON.stringify(manifest)) {
|
|
96
|
+
const identity = publication ? `, ${JSON.stringify(publication)}` : "";
|
|
97
|
+
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;`;
|
|
98
|
+
}
|
|
99
|
+
// src/metro/publication.ts
|
|
100
|
+
function createManifestSnapshot(manifest, virtualPath, version) {
|
|
101
|
+
const manifestJson = JSON.stringify(manifest);
|
|
102
|
+
const publication = version > 0 ? {
|
|
103
|
+
revision: (0, node_crypto.randomUUID)(),
|
|
104
|
+
manifestSha256: (0, node_crypto.createHash)("sha256").update(manifestJson, "utf8").digest("hex")
|
|
105
|
+
} : void 0;
|
|
106
|
+
return require_manifest.freezeSnapshot({
|
|
107
|
+
manifest: require_manifest.parseManifestSnapshot(manifestJson),
|
|
108
|
+
manifestJson,
|
|
109
|
+
virtualPath,
|
|
110
|
+
version,
|
|
111
|
+
...publication ? { publication } : {}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/** 三份产物共用一次序列化;最后的 ready 成功前不提交内存状态。 */
|
|
115
|
+
function writeManifestSnapshot(paths, snapshot) {
|
|
116
|
+
node_fs.default.mkdirSync(node_path.default.dirname(snapshot.virtualPath), { recursive: true });
|
|
117
|
+
node_fs.default.mkdirSync(node_path.default.dirname(paths.manifestPath), { recursive: true });
|
|
118
|
+
writeManifestFile(snapshot.virtualPath, virtualModuleCode(snapshot.manifest, snapshot.publication, snapshot.manifestJson));
|
|
119
|
+
writeManifestFile(paths.manifestPath, snapshot.manifestJson);
|
|
120
|
+
if (snapshot.publication) writeManifestFile(paths.manifestReadyPath, JSON.stringify({
|
|
121
|
+
...snapshot.publication,
|
|
122
|
+
version: snapshot.version,
|
|
123
|
+
virtualPath: snapshot.virtualPath
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
// src/metro/refresh.ts
|
|
61
127
|
function fingerprint(files) {
|
|
62
128
|
const hash = (0, node_crypto.createHash)("sha256");
|
|
63
129
|
for (const file of files) try {
|
|
@@ -96,8 +162,26 @@ async function compileStableInput(files, compile, isCurrent) {
|
|
|
96
162
|
}
|
|
97
163
|
if (isCurrent()) throw new Error("React Native 样式输入持续变化,5 次稳定性检查后仍未完成保存;请完成保存后重试。");
|
|
98
164
|
}
|
|
99
|
-
|
|
100
|
-
|
|
165
|
+
// src/metro/registry.ts
|
|
166
|
+
const registry = /* @__PURE__ */ new Map();
|
|
167
|
+
const publicEntries = /* @__PURE__ */ new WeakMap();
|
|
168
|
+
function getRegisteredVirtualModule(filename) {
|
|
169
|
+
const entry = [...registry.values()].find((entry) => entry.virtualPath === filename);
|
|
170
|
+
if (!entry) return;
|
|
171
|
+
let view = publicEntries.get(entry);
|
|
172
|
+
if (!view) {
|
|
173
|
+
const properties = Object.fromEntries(Object.keys(entry).map((key) => [key, {
|
|
174
|
+
enumerable: true,
|
|
175
|
+
get: () => entry[key]
|
|
176
|
+
}]));
|
|
177
|
+
view = Object.freeze(Object.defineProperties({}, properties));
|
|
178
|
+
publicEntries.set(entry, view);
|
|
179
|
+
}
|
|
180
|
+
return view;
|
|
181
|
+
}
|
|
182
|
+
/** 检查 ready 与返回 snapshot 在同一微任务内完成,不能夹入新的刷新。 */
|
|
183
|
+
async function readRegisteredSnapshot(entry) {
|
|
184
|
+
if (!entry) return;
|
|
101
185
|
for (;;) {
|
|
102
186
|
const ready = entry.ready;
|
|
103
187
|
try {
|
|
@@ -105,31 +189,106 @@ async function waitForCurrentRefresh(entry) {
|
|
|
105
189
|
} catch (error) {
|
|
106
190
|
if (ready === entry.ready) throw error;
|
|
107
191
|
}
|
|
108
|
-
if (ready === entry.ready) return;
|
|
192
|
+
if (ready === entry.ready) return entry.snapshot;
|
|
109
193
|
}
|
|
110
194
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
195
|
+
function getRegisteredSnapshot(id) {
|
|
196
|
+
return readRegisteredSnapshot(registry.get(id));
|
|
197
|
+
}
|
|
198
|
+
/** 文件路径与项目根目录查询均选择最近注册的入口,不能混用两个实例的身份。 */
|
|
199
|
+
function getRegisteredSnapshotByPath(filename) {
|
|
200
|
+
return readRegisteredSnapshot([...registry.values()].filter((entry) => entry.manifestPath === filename).at(-1));
|
|
201
|
+
}
|
|
202
|
+
function getRegisteredSnapshotByProjectRoot(projectRoot) {
|
|
203
|
+
const resolvedRoot = node_path.default.resolve(projectRoot);
|
|
204
|
+
return readRegisteredSnapshot([...registry.values()].filter((entry) => entry.projectRoot === resolvedRoot).at(-1));
|
|
115
205
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
206
|
+
async function getRegisteredManifest(id) {
|
|
207
|
+
return (await getRegisteredSnapshot(id))?.manifest;
|
|
208
|
+
}
|
|
209
|
+
async function getRegisteredManifestByPath(filename) {
|
|
210
|
+
return (await getRegisteredSnapshotByPath(filename))?.manifest;
|
|
211
|
+
}
|
|
212
|
+
async function getRegisteredManifestByProjectRoot(projectRoot) {
|
|
213
|
+
return (await getRegisteredSnapshotByProjectRoot(projectRoot))?.manifest;
|
|
214
|
+
}
|
|
215
|
+
/** 同步读取最近快照供诊断;只有异步入口会等待当前发布成功。 */
|
|
216
|
+
function getVirtualModuleCode(filename) {
|
|
217
|
+
const snapshot = getRegisteredVirtualModule(filename)?.snapshot;
|
|
218
|
+
return snapshot ? virtualModuleCode(snapshot.manifest, snapshot.publication, snapshot.manifestJson) : void 0;
|
|
219
|
+
}
|
|
220
|
+
async function getVirtualModuleCodeAsync(filename) {
|
|
221
|
+
const snapshot = await readRegisteredSnapshot(getRegisteredVirtualModule(filename));
|
|
222
|
+
return snapshot ? virtualModuleCode(snapshot.manifest, snapshot.publication, snapshot.manifestJson) : void 0;
|
|
223
|
+
}
|
|
224
|
+
// src/metro/watch.ts
|
|
225
|
+
function fileVersion(stat) {
|
|
226
|
+
return [
|
|
227
|
+
stat.dev,
|
|
228
|
+
stat.ino,
|
|
229
|
+
stat.size,
|
|
230
|
+
stat.mtimeNs,
|
|
231
|
+
stat.ctimeNs
|
|
232
|
+
].join(":");
|
|
233
|
+
}
|
|
234
|
+
function readFileVersion(target) {
|
|
235
|
+
try {
|
|
236
|
+
return fileVersion(node_fs.default.statSync(target, { bigint: true }));
|
|
237
|
+
} catch (error) {
|
|
238
|
+
if (["ENOENT", "ENOTDIR"].includes(error.code ?? "")) return;
|
|
239
|
+
throw error;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/** 父目录事件提供即时通知,文件版本核对补齐原生通知遗漏。 */
|
|
119
243
|
function watchInput(target, changed) {
|
|
120
|
-
const
|
|
244
|
+
const initial = node_fs.default.statSync(target, { bigint: true });
|
|
245
|
+
const recursive = initial.isDirectory();
|
|
121
246
|
const watchRoot = recursive ? target : node_path.default.dirname(target);
|
|
122
|
-
|
|
247
|
+
let version = fileVersion(initial);
|
|
248
|
+
let closed = false;
|
|
249
|
+
let timer;
|
|
250
|
+
const watcher = node_fs.default.watch(watchRoot, {
|
|
123
251
|
persistent: false,
|
|
124
252
|
recursive
|
|
125
253
|
}, (_event, filename) => {
|
|
126
|
-
if (
|
|
254
|
+
if (closed) return;
|
|
255
|
+
if (recursive) changed();
|
|
256
|
+
else if (filename === null || node_path.default.resolve(watchRoot, filename) === target) reconcile(true);
|
|
127
257
|
});
|
|
258
|
+
function reconcile(force) {
|
|
259
|
+
if (closed) return;
|
|
260
|
+
let current;
|
|
261
|
+
try {
|
|
262
|
+
current = readFileVersion(target);
|
|
263
|
+
} catch (error) {
|
|
264
|
+
watcher.close();
|
|
265
|
+
watcher.emit("error", error);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (force || current !== version) {
|
|
269
|
+
version = current;
|
|
270
|
+
changed();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const stop = () => {
|
|
274
|
+
closed = true;
|
|
275
|
+
clearInterval(timer);
|
|
276
|
+
};
|
|
277
|
+
const close = watcher.close.bind(watcher);
|
|
278
|
+
watcher.close = () => {
|
|
279
|
+
if (closed) return;
|
|
280
|
+
stop();
|
|
281
|
+
close();
|
|
282
|
+
};
|
|
283
|
+
watcher.once("close", stop);
|
|
284
|
+
if (!recursive) {
|
|
285
|
+
timer = setInterval(reconcile, 100, false);
|
|
286
|
+
timer.unref();
|
|
287
|
+
}
|
|
288
|
+
return watcher;
|
|
128
289
|
}
|
|
129
|
-
|
|
130
|
-
//#region src/metro.ts
|
|
290
|
+
// src/metro.ts
|
|
131
291
|
const VIRTUAL_MANIFEST_MODULE = "@weapp-tailwindcss/react-native/virtual";
|
|
132
|
-
const registry = /* @__PURE__ */ new Map();
|
|
133
292
|
const appRootSingletonModules = /* @__PURE__ */ new Set(["react"]);
|
|
134
293
|
let nextId = 0;
|
|
135
294
|
function packageNameFromModuleId(moduleName) {
|
|
@@ -177,12 +336,6 @@ function emptyManifest() {
|
|
|
177
336
|
warnings: []
|
|
178
337
|
};
|
|
179
338
|
}
|
|
180
|
-
function writeVirtualModule(entry) {
|
|
181
|
-
node_fs.default.mkdirSync(node_path.default.dirname(entry.virtualPath), { recursive: true });
|
|
182
|
-
node_fs.default.mkdirSync(node_path.default.dirname(entry.manifestPath), { recursive: true });
|
|
183
|
-
writeManifestFile(entry.virtualPath, virtualModuleCode(entry.manifest));
|
|
184
|
-
writeManifestFile(entry.manifestPath, JSON.stringify(entry.manifest));
|
|
185
|
-
}
|
|
186
339
|
/**
|
|
187
340
|
* Metro worker 会把文件路径先相对化再恢复为绝对路径。虚拟模块必须位于
|
|
188
341
|
* 项目根目录内,否则 Windows 跨盘符路径会被错误拼接成 `D:\\C:\\...`。
|
|
@@ -193,13 +346,6 @@ function getVirtualModulePath(projectRoot, id) {
|
|
|
193
346
|
function markManifestPending(entry) {
|
|
194
347
|
node_fs.default.rmSync(entry.manifestReadyPath, { force: true });
|
|
195
348
|
}
|
|
196
|
-
function markManifestReady(entry) {
|
|
197
|
-
writeManifestFile(entry.manifestReadyPath, JSON.stringify({
|
|
198
|
-
revision: (0, node_crypto.randomUUID)(),
|
|
199
|
-
version: entry.version,
|
|
200
|
-
virtualPath: entry.virtualPath
|
|
201
|
-
}));
|
|
202
|
-
}
|
|
203
349
|
async function compileOptions(options, projectRoot) {
|
|
204
350
|
if (options.manifest) return options.manifest;
|
|
205
351
|
if (options.input) {
|
|
@@ -217,37 +363,46 @@ function register(options) {
|
|
|
217
363
|
const id = `weapp-tailwindcss-native-${nextId++}`;
|
|
218
364
|
const projectRoot = node_path.default.resolve(options.projectRoot ?? node_process.default.cwd());
|
|
219
365
|
const manifestPaths = getManifestPathsForProjectRoot(projectRoot);
|
|
366
|
+
const virtualPath = getVirtualModulePath(projectRoot, id);
|
|
220
367
|
const entry = {
|
|
221
|
-
|
|
222
|
-
|
|
368
|
+
snapshot: createManifestSnapshot(options.manifest ?? (options.css ? require_compiler.compileNativeStylesheet(options.css, { classSet: options.classSet }) : emptyManifest()), virtualPath, 0),
|
|
369
|
+
get version() {
|
|
370
|
+
return this.snapshot.version;
|
|
371
|
+
},
|
|
372
|
+
get manifest() {
|
|
373
|
+
return this.snapshot.manifest;
|
|
374
|
+
},
|
|
223
375
|
projectRoot,
|
|
224
|
-
virtualPath
|
|
376
|
+
virtualPath,
|
|
225
377
|
manifestPath: manifestPaths.manifestPath,
|
|
226
378
|
manifestReadyPath: manifestPaths.manifestReadyPath,
|
|
227
379
|
ready: Promise.resolve(),
|
|
228
380
|
refresh: async () => {}
|
|
229
381
|
};
|
|
382
|
+
node_fs.default.mkdirSync(node_path.default.dirname(virtualPath), { recursive: true });
|
|
383
|
+
writeManifestFile(virtualPath, virtualModuleCode(entry.snapshot.manifest));
|
|
230
384
|
registry.set(id, entry);
|
|
231
|
-
markManifestPending(entry);
|
|
232
|
-
writeVirtualModule(entry);
|
|
233
385
|
const inputFiles = [...new Set([...options.watchFiles ?? [], ...options.input ? [options.input] : []].map((file) => node_path.default.resolve(projectRoot, file)))];
|
|
234
386
|
let generation = 0;
|
|
235
387
|
entry.refresh = () => {
|
|
236
388
|
const currentGeneration = ++generation;
|
|
237
|
-
markManifestPending(entry);
|
|
238
389
|
entry.ready = (async () => {
|
|
239
390
|
try {
|
|
391
|
+
markManifestPending(entry);
|
|
240
392
|
const manifest = await compileStableInput(inputFiles, () => compileOptions(options, projectRoot), () => currentGeneration === generation);
|
|
241
393
|
if (manifest && currentGeneration === generation) {
|
|
242
|
-
entry.
|
|
243
|
-
entry
|
|
244
|
-
|
|
245
|
-
markManifestReady(entry);
|
|
394
|
+
const snapshot = createManifestSnapshot(manifest, entry.virtualPath, entry.version + 1);
|
|
395
|
+
writeManifestSnapshot(entry, snapshot);
|
|
396
|
+
entry.snapshot = snapshot;
|
|
246
397
|
}
|
|
247
398
|
} catch (error) {
|
|
248
399
|
if (currentGeneration !== generation) return;
|
|
249
400
|
const message = `生成 React Native manifest 失败:${error instanceof Error ? error.message : String(error)}`;
|
|
250
|
-
|
|
401
|
+
try {
|
|
402
|
+
writeManifestFile(entry.manifestReadyPath, JSON.stringify({ error: message }));
|
|
403
|
+
} catch (publicationError) {
|
|
404
|
+
throw new AggregateError([error, publicationError], message, { cause: error });
|
|
405
|
+
}
|
|
251
406
|
throw new Error(message, { cause: error });
|
|
252
407
|
}
|
|
253
408
|
})();
|
|
@@ -275,41 +430,6 @@ function register(options) {
|
|
|
275
430
|
entry
|
|
276
431
|
};
|
|
277
432
|
}
|
|
278
|
-
function getRegisteredVirtualModule(filename) {
|
|
279
|
-
for (const entry of registry.values()) if (entry.virtualPath === filename) return entry;
|
|
280
|
-
}
|
|
281
|
-
async function getRegisteredManifest(id) {
|
|
282
|
-
const registered = registry.get(id);
|
|
283
|
-
if (!registered) return;
|
|
284
|
-
await waitForCurrentRefresh(registered);
|
|
285
|
-
return registered.manifest;
|
|
286
|
-
}
|
|
287
|
-
/** 等待并读取由 Metro 配置注册的 manifest 文件,兼容未透传自定义 Metro id 的 transformer。 */
|
|
288
|
-
async function getRegisteredManifestByPath(filename) {
|
|
289
|
-
for (const entry of registry.values()) if (entry.manifestPath === filename) {
|
|
290
|
-
await waitForCurrentRefresh(entry);
|
|
291
|
-
return entry.manifest;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
/** 按 Metro 传入的项目根目录读取当前注册项,兼容 transformer 未透传自定义字段的实现。 */
|
|
295
|
-
async function getRegisteredManifestByProjectRoot(projectRoot) {
|
|
296
|
-
const resolvedRoot = node_path.default.resolve(projectRoot);
|
|
297
|
-
const entry = [...registry.values()].filter((entry) => entry.projectRoot === resolvedRoot).at(-1);
|
|
298
|
-
if (!entry) return;
|
|
299
|
-
await waitForCurrentRefresh(entry);
|
|
300
|
-
return entry.manifest;
|
|
301
|
-
}
|
|
302
|
-
function getVirtualModuleCode(filename) {
|
|
303
|
-
const registered = getRegisteredVirtualModule(filename);
|
|
304
|
-
if (!registered) return;
|
|
305
|
-
return virtualModuleCode(registered.manifest);
|
|
306
|
-
}
|
|
307
|
-
async function getVirtualModuleCodeAsync(filename) {
|
|
308
|
-
const registered = getRegisteredVirtualModule(filename);
|
|
309
|
-
if (!registered) return;
|
|
310
|
-
await waitForCurrentRefresh(registered);
|
|
311
|
-
return getVirtualModuleCode(filename);
|
|
312
|
-
}
|
|
313
433
|
function withWeappTailwindcss(config, options = {}) {
|
|
314
434
|
if (typeof config === "function" || config && typeof config.then === "function") return Promise.resolve(typeof config === "function" ? config() : config).then((resolved) => withWeappTailwindcss(resolved, options));
|
|
315
435
|
const resolvedConfig = config;
|
|
@@ -354,7 +474,6 @@ function withWeappTailwindcss(config, options = {}) {
|
|
|
354
474
|
}
|
|
355
475
|
};
|
|
356
476
|
}
|
|
357
|
-
//#endregion
|
|
358
477
|
Object.defineProperty(exports, "VIRTUAL_MANIFEST_MODULE", {
|
|
359
478
|
enumerable: true,
|
|
360
479
|
get: function() {
|
|
@@ -385,6 +504,24 @@ Object.defineProperty(exports, "getRegisteredManifestByProjectRoot", {
|
|
|
385
504
|
return getRegisteredManifestByProjectRoot;
|
|
386
505
|
}
|
|
387
506
|
});
|
|
507
|
+
Object.defineProperty(exports, "getRegisteredSnapshot", {
|
|
508
|
+
enumerable: true,
|
|
509
|
+
get: function() {
|
|
510
|
+
return getRegisteredSnapshot;
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
Object.defineProperty(exports, "getRegisteredSnapshotByPath", {
|
|
514
|
+
enumerable: true,
|
|
515
|
+
get: function() {
|
|
516
|
+
return getRegisteredSnapshotByPath;
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
Object.defineProperty(exports, "getRegisteredSnapshotByProjectRoot", {
|
|
520
|
+
enumerable: true,
|
|
521
|
+
get: function() {
|
|
522
|
+
return getRegisteredSnapshotByProjectRoot;
|
|
523
|
+
}
|
|
524
|
+
});
|
|
388
525
|
Object.defineProperty(exports, "getRegisteredVirtualModule", {
|
|
389
526
|
enumerable: true,
|
|
390
527
|
get: function() {
|
|
@@ -409,16 +546,16 @@ Object.defineProperty(exports, "readPublishedSnapshot", {
|
|
|
409
546
|
return readPublishedSnapshot;
|
|
410
547
|
}
|
|
411
548
|
});
|
|
412
|
-
Object.defineProperty(exports, "
|
|
549
|
+
Object.defineProperty(exports, "readRegisteredSnapshot", {
|
|
413
550
|
enumerable: true,
|
|
414
551
|
get: function() {
|
|
415
|
-
return
|
|
552
|
+
return readRegisteredSnapshot;
|
|
416
553
|
}
|
|
417
554
|
});
|
|
418
|
-
Object.defineProperty(exports, "
|
|
555
|
+
Object.defineProperty(exports, "virtualModuleCode", {
|
|
419
556
|
enumerable: true,
|
|
420
557
|
get: function() {
|
|
421
|
-
return
|
|
558
|
+
return virtualModuleCode;
|
|
422
559
|
}
|
|
423
560
|
});
|
|
424
561
|
Object.defineProperty(exports, "withWeappTailwindcss", {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_rolldown_runtime = require("./rolldown-runtime-
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-CmQyd0Gu.cjs");
|
|
3
3
|
const require_babel = require("./babel.cjs");
|
|
4
|
-
const require_metro = require("./metro-
|
|
4
|
+
const require_metro = require("./metro-kaKzXOAU.cjs");
|
|
5
5
|
let node_fs = require("node:fs");
|
|
6
6
|
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
7
7
|
let node_module = require("node:module");
|
|
@@ -9,24 +9,19 @@ let node_process = require("node:process");
|
|
|
9
9
|
node_process = require_rolldown_runtime.__toESM(node_process, 1);
|
|
10
10
|
let node_buffer = require("node:buffer");
|
|
11
11
|
let _babel_core = require("@babel/core");
|
|
12
|
-
|
|
12
|
+
// src/metro-transformer.ts
|
|
13
13
|
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
14
14
|
async function transform(config, projectRoot, filename, data, options) {
|
|
15
15
|
const registeredVirtual = require_metro.getRegisteredVirtualModule(filename);
|
|
16
|
-
if (registeredVirtual) await require_metro.waitForCurrentRefresh(registeredVirtual);
|
|
17
16
|
const metroId = config.weappTailwindcssMetroId;
|
|
18
17
|
const manifestPath = config.weappTailwindcssManifestPath;
|
|
19
18
|
const manifestReadyPath = config.weappTailwindcssManifestReadyPath;
|
|
20
19
|
const virtualModulePath = config.weappTailwindcssVirtualModulePath;
|
|
21
20
|
const projectManifestPaths = require_metro.getManifestPathsForProjectRoot(projectRoot);
|
|
22
|
-
const
|
|
23
|
-
const snapshot = registeredManifest ? {
|
|
24
|
-
manifest: registeredManifest,
|
|
25
|
-
virtualPath: registeredVirtual?.virtualPath
|
|
26
|
-
} : await require_metro.readPublishedSnapshot(manifestPath ?? projectManifestPaths.manifestPath, manifestReadyPath ?? projectManifestPaths.manifestReadyPath);
|
|
21
|
+
const snapshot = await require_metro.readRegisteredSnapshot(registeredVirtual) ?? (metroId ? await require_metro.getRegisteredSnapshot(metroId) : void 0) ?? (manifestPath ? await require_metro.getRegisteredSnapshotByPath(manifestPath) : void 0) ?? await require_metro.getRegisteredSnapshotByProjectRoot(projectRoot) ?? await require_metro.readPublishedSnapshot(manifestPath ?? projectManifestPaths.manifestPath, manifestReadyPath ?? projectManifestPaths.manifestReadyPath);
|
|
27
22
|
const manifest = snapshot?.manifest;
|
|
28
23
|
const publishedVirtualPath = snapshot?.virtualPath ?? virtualModulePath;
|
|
29
|
-
const virtualCode = manifest && publishedVirtualPath === filename ? require_metro.virtualModuleCode(manifest) : void 0;
|
|
24
|
+
const virtualCode = manifest && publishedVirtualPath === filename ? require_metro.virtualModuleCode(manifest, snapshot.publication, snapshot.manifestJson) : void 0;
|
|
30
25
|
if (node_process.default.env.WEAPP_TW_RN_DEBUG === "1" && !filename.replaceAll("\\", "/").includes("/node_modules/")) console.error(`[react-native-debug] ${JSON.stringify({
|
|
31
26
|
filename,
|
|
32
27
|
projectRoot,
|
|
@@ -57,5 +52,4 @@ async function transform(config, projectRoot, filename, data, options) {
|
|
|
57
52
|
const originalPath = config.weappTailwindcssOriginalTransformerPath;
|
|
58
53
|
return (originalPath ? require$1(originalPath) : require$1("metro-react-native-babel-transformer")).transform(config, projectRoot, filename, source, options);
|
|
59
54
|
}
|
|
60
|
-
//#endregion
|
|
61
55
|
exports.transform = transform;
|
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
|
-
|
|
3
|
-
export declare function transform(config: Record<string, unknown>, projectRoot: string, filename: string, data: Buffer, options: Record<string, unknown>): Promise<any>;
|
|
4
|
-
//#endregion
|
|
2
|
+
export declare function transform(config: Record<string, unknown>, projectRoot: string, filename: string, data: Buffer, options: Record<string, unknown>): Promise<any>;
|
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
import weappReactNativeBabel from "./babel.js";
|
|
2
|
-
import {
|
|
2
|
+
import { c as getRegisteredSnapshotByPath, h as readPublishedSnapshot, l as getRegisteredSnapshotByProjectRoot, m as virtualModuleCode, n as getManifestPathsForProjectRoot, p as readRegisteredSnapshot, s as getRegisteredSnapshot, u as getRegisteredVirtualModule } from "./metro-OMh6z1jy.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import { Buffer } from "node:buffer";
|
|
7
7
|
import { transformSync } from "@babel/core";
|
|
8
|
-
|
|
8
|
+
// src/metro-transformer.ts
|
|
9
9
|
const require = createRequire(import.meta.url);
|
|
10
10
|
async function transform(config, projectRoot, filename, data, options) {
|
|
11
11
|
const registeredVirtual = getRegisteredVirtualModule(filename);
|
|
12
|
-
if (registeredVirtual) await waitForCurrentRefresh(registeredVirtual);
|
|
13
12
|
const metroId = config.weappTailwindcssMetroId;
|
|
14
13
|
const manifestPath = config.weappTailwindcssManifestPath;
|
|
15
14
|
const manifestReadyPath = config.weappTailwindcssManifestReadyPath;
|
|
16
15
|
const virtualModulePath = config.weappTailwindcssVirtualModulePath;
|
|
17
16
|
const projectManifestPaths = getManifestPathsForProjectRoot(projectRoot);
|
|
18
|
-
const
|
|
19
|
-
const snapshot = registeredManifest ? {
|
|
20
|
-
manifest: registeredManifest,
|
|
21
|
-
virtualPath: registeredVirtual?.virtualPath
|
|
22
|
-
} : await readPublishedSnapshot(manifestPath ?? projectManifestPaths.manifestPath, manifestReadyPath ?? projectManifestPaths.manifestReadyPath);
|
|
17
|
+
const snapshot = await readRegisteredSnapshot(registeredVirtual) ?? (metroId ? await getRegisteredSnapshot(metroId) : void 0) ?? (manifestPath ? await getRegisteredSnapshotByPath(manifestPath) : void 0) ?? await getRegisteredSnapshotByProjectRoot(projectRoot) ?? await readPublishedSnapshot(manifestPath ?? projectManifestPaths.manifestPath, manifestReadyPath ?? projectManifestPaths.manifestReadyPath);
|
|
23
18
|
const manifest = snapshot?.manifest;
|
|
24
19
|
const publishedVirtualPath = snapshot?.virtualPath ?? virtualModulePath;
|
|
25
|
-
const virtualCode = manifest && publishedVirtualPath === filename ? virtualModuleCode(manifest) : void 0;
|
|
20
|
+
const virtualCode = manifest && publishedVirtualPath === filename ? virtualModuleCode(manifest, snapshot.publication, snapshot.manifestJson) : void 0;
|
|
26
21
|
if (process.env.WEAPP_TW_RN_DEBUG === "1" && !filename.replaceAll("\\", "/").includes("/node_modules/")) console.error(`[react-native-debug] ${JSON.stringify({
|
|
27
22
|
filename,
|
|
28
23
|
projectRoot,
|
|
@@ -53,5 +48,4 @@ async function transform(config, projectRoot, filename, data, options) {
|
|
|
53
48
|
const originalPath = config.weappTailwindcssOriginalTransformerPath;
|
|
54
49
|
return (originalPath ? require(originalPath) : require("metro-react-native-babel-transformer")).transform(config, projectRoot, filename, source, options);
|
|
55
50
|
}
|
|
56
|
-
//#endregion
|
|
57
51
|
export { transform };
|
package/dist/metro.cjs
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_metro = require("./metro-
|
|
2
|
+
const require_metro = require("./metro-kaKzXOAU.cjs");
|
|
3
3
|
exports.VIRTUAL_MANIFEST_MODULE = require_metro.VIRTUAL_MANIFEST_MODULE;
|
|
4
4
|
exports.getManifestPathsForProjectRoot = require_metro.getManifestPathsForProjectRoot;
|
|
5
5
|
exports.getRegisteredManifest = require_metro.getRegisteredManifest;
|
|
6
6
|
exports.getRegisteredManifestByPath = require_metro.getRegisteredManifestByPath;
|
|
7
7
|
exports.getRegisteredManifestByProjectRoot = require_metro.getRegisteredManifestByProjectRoot;
|
|
8
|
+
exports.getRegisteredSnapshot = require_metro.getRegisteredSnapshot;
|
|
9
|
+
exports.getRegisteredSnapshotByPath = require_metro.getRegisteredSnapshotByPath;
|
|
10
|
+
exports.getRegisteredSnapshotByProjectRoot = require_metro.getRegisteredSnapshotByProjectRoot;
|
|
8
11
|
exports.getRegisteredVirtualModule = require_metro.getRegisteredVirtualModule;
|
|
9
12
|
exports.getVirtualModuleCode = require_metro.getVirtualModuleCode;
|
|
10
13
|
exports.getVirtualModuleCodeAsync = require_metro.getVirtualModuleCodeAsync;
|
package/dist/metro.d.ts
CHANGED
|
@@ -1,53 +1,2 @@
|
|
|
1
|
-
import { i as
|
|
2
|
-
|
|
3
|
-
export declare const VIRTUAL_MANIFEST_MODULE = "@weapp-tailwindcss/react-native/virtual";
|
|
4
|
-
export interface MetroConfigLike {
|
|
5
|
-
resolver?: {
|
|
6
|
-
extraNodeModules?: Record<string, string>;
|
|
7
|
-
sourceExts?: string[];
|
|
8
|
-
resolveRequest?: (context: unknown, moduleName: string, platform?: string) => unknown;
|
|
9
|
-
[key: string]: unknown;
|
|
10
|
-
};
|
|
11
|
-
transformer?: Record<string, unknown>;
|
|
12
|
-
transformerPath?: string;
|
|
13
|
-
watchFolders?: string[];
|
|
14
|
-
server?: Record<string, unknown>;
|
|
15
|
-
[key: string]: unknown;
|
|
16
|
-
}
|
|
17
|
-
export interface WeappReactNativeMetroOptions {
|
|
18
|
-
projectRoot?: string | undefined;
|
|
19
|
-
input?: string | undefined;
|
|
20
|
-
css?: string | undefined;
|
|
21
|
-
manifest?: NativeStyleManifest | undefined;
|
|
22
|
-
classSet?: Iterable<string> | undefined;
|
|
23
|
-
sourceGlobs?: string[] | undefined;
|
|
24
|
-
watchFiles?: string[] | undefined;
|
|
25
|
-
}
|
|
26
|
-
interface RegisteredManifest {
|
|
27
|
-
version: number;
|
|
28
|
-
manifest: NativeStyleManifest;
|
|
29
|
-
projectRoot: string;
|
|
30
|
-
virtualPath: string;
|
|
31
|
-
manifestPath: string;
|
|
32
|
-
manifestReadyPath: string;
|
|
33
|
-
ready: Promise<void>;
|
|
34
|
-
refresh: () => Promise<void>;
|
|
35
|
-
}
|
|
36
|
-
export interface NativeManifestPaths {
|
|
37
|
-
manifestPath: string;
|
|
38
|
-
manifestReadyPath: string;
|
|
39
|
-
}
|
|
40
|
-
/** 为 Metro worker 提供不依赖进程内 registry 的 manifest 入口。 */
|
|
41
|
-
export declare function getManifestPathsForProjectRoot(projectRoot: string): NativeManifestPaths;
|
|
42
|
-
export declare function getRegisteredVirtualModule(filename: string): RegisteredManifest | undefined;
|
|
43
|
-
export declare function getRegisteredManifest(id: string): Promise<NativeStyleManifest | undefined>;
|
|
44
|
-
/** 等待并读取由 Metro 配置注册的 manifest 文件,兼容未透传自定义 Metro id 的 transformer。 */
|
|
45
|
-
export declare function getRegisteredManifestByPath(filename: string): Promise<NativeStyleManifest | undefined>;
|
|
46
|
-
/** 按 Metro 传入的项目根目录读取当前注册项,兼容 transformer 未透传自定义字段的实现。 */
|
|
47
|
-
export declare function getRegisteredManifestByProjectRoot(projectRoot: string): Promise<NativeStyleManifest | undefined>;
|
|
48
|
-
export declare function getVirtualModuleCode(filename: string): string | undefined;
|
|
49
|
-
export declare function getVirtualModuleCodeAsync(filename: string): Promise<string | undefined>;
|
|
50
|
-
export declare function withWeappTailwindcss<T extends MetroConfigLike>(config: T, options?: WeappReactNativeMetroOptions): T & MetroConfigLike;
|
|
51
|
-
export declare function withWeappTailwindcss<T extends MetroConfigLike>(config: Promise<T> | (() => T | Promise<T>), options?: WeappReactNativeMetroOptions): Promise<T & MetroConfigLike>;
|
|
52
|
-
export declare function withWeappTailwindcss<T extends MetroConfigLike>(config: T | Promise<T> | (() => T | Promise<T>), options?: WeappReactNativeMetroOptions): (T & MetroConfigLike) | Promise<T & MetroConfigLike>;
|
|
53
|
-
//#endregion
|
|
1
|
+
import { a as getManifestPathsForProjectRoot, c as getRegisteredManifestByPath, d as getRegisteredSnapshotByPath, f as getRegisteredSnapshotByProjectRoot, h as getVirtualModuleCodeAsync, i as WeappReactNativeMetroOptions, l as getRegisteredManifestByProjectRoot, m as getVirtualModuleCode, n as NativeManifestPaths, o as withWeappTailwindcss, p as getRegisteredVirtualModule, r as VIRTUAL_MANIFEST_MODULE, s as getRegisteredManifest, t as MetroConfigLike, u as getRegisteredSnapshot } from "./metro-ahmChgsA.js";
|
|
2
|
+
export { MetroConfigLike, NativeManifestPaths, VIRTUAL_MANIFEST_MODULE, WeappReactNativeMetroOptions, getManifestPathsForProjectRoot, getRegisteredManifest, getRegisteredManifestByPath, getRegisteredManifestByProjectRoot, getRegisteredSnapshot, getRegisteredSnapshotByPath, getRegisteredSnapshotByProjectRoot, getRegisteredVirtualModule, getVirtualModuleCode, getVirtualModuleCodeAsync, withWeappTailwindcss };
|
package/dist/metro.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { VIRTUAL_MANIFEST_MODULE, getManifestPathsForProjectRoot, getRegisteredManifest, getRegisteredManifestByPath, getRegisteredManifestByProjectRoot, getRegisteredVirtualModule, getVirtualModuleCode, getVirtualModuleCodeAsync, withWeappTailwindcss };
|
|
1
|
+
export { t as VIRTUAL_MANIFEST_MODULE, n as getManifestPathsForProjectRoot, i as getRegisteredManifest, a as getRegisteredManifestByPath, o as getRegisteredManifestByProjectRoot, s as getRegisteredSnapshot, c as getRegisteredSnapshotByPath, l as getRegisteredSnapshotByProjectRoot, u as getRegisteredVirtualModule, d as getVirtualModuleCode, f as getVirtualModuleCodeAsync, r as withWeappTailwindcss } from "./metro-OMh6z1jy.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -19,7 +19,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
19
19
|
value: mod,
|
|
20
20
|
enumerable: true
|
|
21
21
|
}) : target, mod));
|
|
22
|
-
//#endregion
|
|
23
22
|
Object.defineProperty(exports, "__toESM", {
|
|
24
23
|
enumerable: true,
|
|
25
24
|
get: function() {
|