@weapp-tailwindcss/react-native 0.2.11 → 0.2.13
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/dist/metro-transformer.cjs +1 -1
- package/dist/metro.cjs +37 -4
- package/dist/metro.d.ts +1 -0
- package/dist/metro.js +37 -4
- package/package.json +2 -2
|
@@ -4,9 +4,9 @@ const require_babel = require("./babel.cjs");
|
|
|
4
4
|
const require_metro = require("./metro.cjs");
|
|
5
5
|
let node_fs = require("node:fs");
|
|
6
6
|
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
7
|
+
let node_module = require("node:module");
|
|
7
8
|
let node_process = require("node:process");
|
|
8
9
|
node_process = require_rolldown_runtime.__toESM(node_process, 1);
|
|
9
|
-
let node_module = require("node:module");
|
|
10
10
|
let _babel_core = require("@babel/core");
|
|
11
11
|
//#region src/metro-transformer.ts
|
|
12
12
|
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
package/dist/metro.cjs
CHANGED
|
@@ -4,6 +4,7 @@ const require_compiler = require("./compiler.cjs");
|
|
|
4
4
|
let node_crypto = require("node:crypto");
|
|
5
5
|
let node_fs = require("node:fs");
|
|
6
6
|
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
7
|
+
let node_module = require("node:module");
|
|
7
8
|
let node_os = require("node:os");
|
|
8
9
|
node_os = require_rolldown_runtime.__toESM(node_os, 1);
|
|
9
10
|
let node_path = require("node:path");
|
|
@@ -14,14 +15,31 @@ let node_url = require("node:url");
|
|
|
14
15
|
//#region src/metro.ts
|
|
15
16
|
const VIRTUAL_MANIFEST_MODULE = "@weapp-tailwindcss/react-native/virtual";
|
|
16
17
|
const registry = /* @__PURE__ */ new Map();
|
|
17
|
-
const appRootSingletonModules = /* @__PURE__ */ new Set(["react"
|
|
18
|
+
const appRootSingletonModules = /* @__PURE__ */ new Set(["react"]);
|
|
18
19
|
let nextId = 0;
|
|
19
20
|
function packageNameFromModuleId(moduleName) {
|
|
20
21
|
const segments = moduleName.split("/");
|
|
21
22
|
return moduleName.startsWith("@") ? segments.slice(0, 2).join("/") : segments[0];
|
|
22
23
|
}
|
|
23
24
|
function shouldResolveFromAppRoot(moduleName, platform) {
|
|
24
|
-
|
|
25
|
+
const packageName = packageNameFromModuleId(moduleName);
|
|
26
|
+
if (appRootSingletonModules.has(packageName)) return true;
|
|
27
|
+
return platform !== "web" && packageName === "react-native";
|
|
28
|
+
}
|
|
29
|
+
function resolveAppRootSingleton(projectRoot, moduleName, platform) {
|
|
30
|
+
if (platform !== "web" || ![
|
|
31
|
+
"react",
|
|
32
|
+
"react-dom",
|
|
33
|
+
"react-native-web"
|
|
34
|
+
].includes(packageNameFromModuleId(moduleName))) return;
|
|
35
|
+
try {
|
|
36
|
+
return {
|
|
37
|
+
type: "sourceFile",
|
|
38
|
+
filePath: (0, node_module.createRequire)(node_path.default.join(projectRoot, "package.json")).resolve(moduleName)
|
|
39
|
+
};
|
|
40
|
+
} catch {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
25
43
|
}
|
|
26
44
|
/** 为 Metro worker 提供不依赖进程内 registry 的 manifest 入口。 */
|
|
27
45
|
function getManifestPathsForProjectRoot(projectRoot) {
|
|
@@ -49,9 +67,17 @@ function virtualModuleCode(manifest) {
|
|
|
49
67
|
}
|
|
50
68
|
function writeVirtualModule(entry) {
|
|
51
69
|
node_fs.default.mkdirSync(node_path.default.dirname(entry.virtualPath), { recursive: true });
|
|
70
|
+
node_fs.default.mkdirSync(node_path.default.dirname(entry.manifestPath), { recursive: true });
|
|
52
71
|
node_fs.default.writeFileSync(entry.virtualPath, virtualModuleCode(entry.manifest), "utf8");
|
|
53
72
|
node_fs.default.writeFileSync(entry.manifestPath, JSON.stringify(entry.manifest), "utf8");
|
|
54
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Metro worker 会把文件路径先相对化再恢复为绝对路径。虚拟模块必须位于
|
|
76
|
+
* 项目根目录内,否则 Windows 跨盘符路径会被错误拼接成 `D:\\C:\\...`。
|
|
77
|
+
*/
|
|
78
|
+
function getVirtualModulePath(projectRoot, id) {
|
|
79
|
+
return node_path.default.join(projectRoot, "node_modules", ".cache", "weapp-tailwindcss-native", `${id}.js`);
|
|
80
|
+
}
|
|
55
81
|
function markManifestPending(entry) {
|
|
56
82
|
node_fs.default.rmSync(entry.manifestReadyPath, { force: true });
|
|
57
83
|
}
|
|
@@ -79,7 +105,7 @@ function register(options) {
|
|
|
79
105
|
version: 0,
|
|
80
106
|
manifest: options.manifest ?? (options.css ? require_compiler.compileNativeStylesheet(options.css, { classSet: options.classSet }) : emptyManifest()),
|
|
81
107
|
projectRoot,
|
|
82
|
-
virtualPath:
|
|
108
|
+
virtualPath: getVirtualModulePath(projectRoot, id),
|
|
83
109
|
manifestPath: manifestPaths.manifestPath,
|
|
84
110
|
manifestReadyPath: manifestPaths.manifestReadyPath,
|
|
85
111
|
ready: Promise.resolve(),
|
|
@@ -177,12 +203,14 @@ function withWeappTailwindcss(config, options = {}) {
|
|
|
177
203
|
type: "sourceFile",
|
|
178
204
|
filePath: entry.virtualPath
|
|
179
205
|
};
|
|
206
|
+
const appRootSingleton = resolveAppRootSingleton(entry.projectRoot, moduleName, platform);
|
|
207
|
+
if (appRootSingleton) return appRootSingleton;
|
|
180
208
|
const resolverContext = context;
|
|
181
209
|
const anchoredContext = resolverContext.originModulePath === entry.virtualPath || shouldResolveFromAppRoot(moduleName, platform) ? {
|
|
182
210
|
...resolverContext,
|
|
183
211
|
originModulePath: node_path.default.join(entry.projectRoot, "package.json")
|
|
184
212
|
} : resolverContext;
|
|
185
|
-
return originalResolver?.(anchoredContext, moduleName, platform) ?? resolverContext.resolveRequest?.(anchoredContext, moduleName, platform);
|
|
213
|
+
return originalResolver?.(anchoredContext, moduleName, platform) ?? resolverContext.resolveRequest?.(anchoredContext, moduleName, platform) ?? resolveAppRootSingleton(entry.projectRoot, moduleName, platform);
|
|
186
214
|
};
|
|
187
215
|
return {
|
|
188
216
|
...resolvedConfig,
|
|
@@ -198,6 +226,11 @@ function withWeappTailwindcss(config, options = {}) {
|
|
|
198
226
|
},
|
|
199
227
|
resolver: {
|
|
200
228
|
...resolvedConfig.resolver,
|
|
229
|
+
extraNodeModules: {
|
|
230
|
+
...resolvedConfig.resolver?.extraNodeModules,
|
|
231
|
+
"react": node_path.default.resolve(entry.projectRoot, "node_modules/react"),
|
|
232
|
+
"react-dom": node_path.default.resolve(entry.projectRoot, "node_modules/react-dom")
|
|
233
|
+
},
|
|
201
234
|
sourceExts: sourceExts.includes("css") ? sourceExts : [...sourceExts, "css"],
|
|
202
235
|
resolveRequest: virtualResolver
|
|
203
236
|
}
|
package/dist/metro.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { o as NativeStyleManifest } from "./types-BTxnqaRV.js";
|
|
|
3
3
|
declare const VIRTUAL_MANIFEST_MODULE = "@weapp-tailwindcss/react-native/virtual";
|
|
4
4
|
interface MetroConfigLike {
|
|
5
5
|
resolver?: {
|
|
6
|
+
extraNodeModules?: Record<string, string>;
|
|
6
7
|
sourceExts?: string[];
|
|
7
8
|
resolveRequest?: (context: unknown, moduleName: string, platform?: string) => unknown;
|
|
8
9
|
[key: string]: unknown;
|
package/dist/metro.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { compileNativeStylesheet } from "./compiler.js";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
2
3
|
import { createHash } from "node:crypto";
|
|
3
4
|
import fs from "node:fs";
|
|
4
5
|
import os from "node:os";
|
|
@@ -8,14 +9,31 @@ import { fileURLToPath } from "node:url";
|
|
|
8
9
|
//#region src/metro.ts
|
|
9
10
|
const VIRTUAL_MANIFEST_MODULE = "@weapp-tailwindcss/react-native/virtual";
|
|
10
11
|
const registry = /* @__PURE__ */ new Map();
|
|
11
|
-
const appRootSingletonModules = /* @__PURE__ */ new Set(["react"
|
|
12
|
+
const appRootSingletonModules = /* @__PURE__ */ new Set(["react"]);
|
|
12
13
|
let nextId = 0;
|
|
13
14
|
function packageNameFromModuleId(moduleName) {
|
|
14
15
|
const segments = moduleName.split("/");
|
|
15
16
|
return moduleName.startsWith("@") ? segments.slice(0, 2).join("/") : segments[0];
|
|
16
17
|
}
|
|
17
18
|
function shouldResolveFromAppRoot(moduleName, platform) {
|
|
18
|
-
|
|
19
|
+
const packageName = packageNameFromModuleId(moduleName);
|
|
20
|
+
if (appRootSingletonModules.has(packageName)) return true;
|
|
21
|
+
return platform !== "web" && packageName === "react-native";
|
|
22
|
+
}
|
|
23
|
+
function resolveAppRootSingleton(projectRoot, moduleName, platform) {
|
|
24
|
+
if (platform !== "web" || ![
|
|
25
|
+
"react",
|
|
26
|
+
"react-dom",
|
|
27
|
+
"react-native-web"
|
|
28
|
+
].includes(packageNameFromModuleId(moduleName))) return;
|
|
29
|
+
try {
|
|
30
|
+
return {
|
|
31
|
+
type: "sourceFile",
|
|
32
|
+
filePath: createRequire(path.join(projectRoot, "package.json")).resolve(moduleName)
|
|
33
|
+
};
|
|
34
|
+
} catch {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
19
37
|
}
|
|
20
38
|
/** 为 Metro worker 提供不依赖进程内 registry 的 manifest 入口。 */
|
|
21
39
|
function getManifestPathsForProjectRoot(projectRoot) {
|
|
@@ -43,9 +61,17 @@ function virtualModuleCode(manifest) {
|
|
|
43
61
|
}
|
|
44
62
|
function writeVirtualModule(entry) {
|
|
45
63
|
fs.mkdirSync(path.dirname(entry.virtualPath), { recursive: true });
|
|
64
|
+
fs.mkdirSync(path.dirname(entry.manifestPath), { recursive: true });
|
|
46
65
|
fs.writeFileSync(entry.virtualPath, virtualModuleCode(entry.manifest), "utf8");
|
|
47
66
|
fs.writeFileSync(entry.manifestPath, JSON.stringify(entry.manifest), "utf8");
|
|
48
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Metro worker 会把文件路径先相对化再恢复为绝对路径。虚拟模块必须位于
|
|
70
|
+
* 项目根目录内,否则 Windows 跨盘符路径会被错误拼接成 `D:\\C:\\...`。
|
|
71
|
+
*/
|
|
72
|
+
function getVirtualModulePath(projectRoot, id) {
|
|
73
|
+
return path.join(projectRoot, "node_modules", ".cache", "weapp-tailwindcss-native", `${id}.js`);
|
|
74
|
+
}
|
|
49
75
|
function markManifestPending(entry) {
|
|
50
76
|
fs.rmSync(entry.manifestReadyPath, { force: true });
|
|
51
77
|
}
|
|
@@ -73,7 +99,7 @@ function register(options) {
|
|
|
73
99
|
version: 0,
|
|
74
100
|
manifest: options.manifest ?? (options.css ? compileNativeStylesheet(options.css, { classSet: options.classSet }) : emptyManifest()),
|
|
75
101
|
projectRoot,
|
|
76
|
-
virtualPath:
|
|
102
|
+
virtualPath: getVirtualModulePath(projectRoot, id),
|
|
77
103
|
manifestPath: manifestPaths.manifestPath,
|
|
78
104
|
manifestReadyPath: manifestPaths.manifestReadyPath,
|
|
79
105
|
ready: Promise.resolve(),
|
|
@@ -171,12 +197,14 @@ function withWeappTailwindcss(config, options = {}) {
|
|
|
171
197
|
type: "sourceFile",
|
|
172
198
|
filePath: entry.virtualPath
|
|
173
199
|
};
|
|
200
|
+
const appRootSingleton = resolveAppRootSingleton(entry.projectRoot, moduleName, platform);
|
|
201
|
+
if (appRootSingleton) return appRootSingleton;
|
|
174
202
|
const resolverContext = context;
|
|
175
203
|
const anchoredContext = resolverContext.originModulePath === entry.virtualPath || shouldResolveFromAppRoot(moduleName, platform) ? {
|
|
176
204
|
...resolverContext,
|
|
177
205
|
originModulePath: path.join(entry.projectRoot, "package.json")
|
|
178
206
|
} : resolverContext;
|
|
179
|
-
return originalResolver?.(anchoredContext, moduleName, platform) ?? resolverContext.resolveRequest?.(anchoredContext, moduleName, platform);
|
|
207
|
+
return originalResolver?.(anchoredContext, moduleName, platform) ?? resolverContext.resolveRequest?.(anchoredContext, moduleName, platform) ?? resolveAppRootSingleton(entry.projectRoot, moduleName, platform);
|
|
180
208
|
};
|
|
181
209
|
return {
|
|
182
210
|
...resolvedConfig,
|
|
@@ -192,6 +220,11 @@ function withWeappTailwindcss(config, options = {}) {
|
|
|
192
220
|
},
|
|
193
221
|
resolver: {
|
|
194
222
|
...resolvedConfig.resolver,
|
|
223
|
+
extraNodeModules: {
|
|
224
|
+
...resolvedConfig.resolver?.extraNodeModules,
|
|
225
|
+
"react": path.resolve(entry.projectRoot, "node_modules/react"),
|
|
226
|
+
"react-dom": path.resolve(entry.projectRoot, "node_modules/react-dom")
|
|
227
|
+
},
|
|
195
228
|
sourceExts: sourceExts.includes("css") ? sourceExts : [...sourceExts, "css"],
|
|
196
229
|
resolveRequest: virtualResolver
|
|
197
230
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/react-native",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.13",
|
|
5
5
|
"description": "Tailwind CSS compiler and Expo Metro integration for cross-platform React Native apps. 面向跨端 React Native 应用的 Tailwind CSS 编译器与 Expo Metro 集成。",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://tw.weapp.dev/docs/quick-start/react-native-expo",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"dependencies": {
|
|
94
94
|
"@babel/types": "^8.0.4",
|
|
95
95
|
"postcss": "^8.5.26",
|
|
96
|
-
"weapp-tailwindcss": "5.
|
|
96
|
+
"weapp-tailwindcss": "5.5.1"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@babel/core": "^8.0.1",
|