@multiplatform.one/config 9.17.0 → 10.1.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/design-lint.mjs +29 -6
- package/lib/index.js +4 -4
- package/lib/{storybook-BpaziEtP.js → storybook-LYamvanr.js} +13 -9
- package/lib/storybook.js +1 -1
- package/lib/{tamaguiWorkspacePaths-DR3dud79.js → tamaguiWorkspacePaths-7eT9XxzE.js} +9 -6
- package/lib/{vite-CgiDLR6V.js → vite-BtlhFd_U.js} +40 -52
- package/lib/vite.js +4 -4
- package/lib/{vitest-B2vcGrZM.js → vitest-B8Z8ZZQR.js} +97 -10
- package/lib/vitest.js +2 -2
- package/lib/{workspacePublicPackages-DN-1LPcH.js → workspacePublicPackages-B_kw7fuc.js} +379 -129
- package/lint.mjs +874 -52
- package/oxlint.mjs +26 -1
- package/package.json +6 -6
- package/press-lint.mjs +86 -5
- package/spec-registry.mjs +15 -0
- package/src/lint.spec.ts +696 -12
- package/src/movedDepAliases.spec.ts +24 -0
- package/src/nativeBlockScoping.spec.ts +12 -14
- package/src/noVoicelessText.rule.spec.ts +1 -1
- package/src/noVoicelessText.spec.ts +1 -1
- package/src/oxlint.spec.ts +5 -5
- package/src/phosphorNativeInk.spec.ts +17 -18
- package/src/phosphorTokenColor.spec.ts +35 -0
- package/src/phosphorTokenColor.ts +8 -5
- package/src/press-lint.spec.ts +64 -3
- package/src/react-native.config.cjs +9 -0
- package/src/shims/phosphorThemeInk.js +6 -1
- package/src/singletonDepAliases.spec.ts +99 -14
- package/src/singletonDepAliases.ts +102 -7
- package/src/storybook.spec.ts +0 -3
- package/src/storybook.ts +20 -6
- package/src/vite.nativeEntries.spec.ts +21 -20
- package/src/vite.spec.ts +11 -20
- package/src/vite.ts +44 -69
- package/src/vitest.spec.ts +142 -4
- package/src/vitest.ts +106 -8
- package/types/phosphorTokenColor.d.ts.map +1 -1
- package/types/singletonDepAliases.d.ts +55 -3
- package/types/singletonDepAliases.d.ts.map +1 -1
- package/types/storybook.d.ts.map +1 -1
- package/types/vite.d.ts +10 -1
- package/types/vite.d.ts.map +1 -1
- package/types/vitest.d.ts +46 -1
- package/types/vitest.d.ts.map +1 -1
|
@@ -2,10 +2,306 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
5
6
|
|
|
6
7
|
//#region \0rolldown/runtime.js
|
|
7
8
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
8
9
|
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region ../utils/src/movedDepAliases.ts
|
|
12
|
+
const MOVED_MODULES = [{
|
|
13
|
+
specifier: "@react-native/assets-registry/registry",
|
|
14
|
+
goneWith: "@react-native/assets-registry",
|
|
15
|
+
nowIn: "react-native-web",
|
|
16
|
+
file: "dist/modules/AssetRegistry/index.js"
|
|
17
|
+
}];
|
|
18
|
+
/**
|
|
19
|
+
* Vite `resolve.alias` entries for modules that moved out from under a
|
|
20
|
+
* publisher's import.
|
|
21
|
+
*
|
|
22
|
+
* @param root Directory whose `node_modules` the packages resolve from.
|
|
23
|
+
*/
|
|
24
|
+
function movedDepAliases(root = process.cwd()) {
|
|
25
|
+
const requireFrom = createRequire(path.join(root, "package.json"));
|
|
26
|
+
const aliases = {};
|
|
27
|
+
for (const moved of MOVED_MODULES) {
|
|
28
|
+
if (resolvesPackage(moved.goneWith, root, requireFrom)) continue;
|
|
29
|
+
const host = resolvePackageDir$2(moved.nowIn, root, requireFrom);
|
|
30
|
+
if (!host) continue;
|
|
31
|
+
const target = path.join(host, moved.file);
|
|
32
|
+
if (fs.existsSync(target)) aliases[moved.specifier] = target;
|
|
33
|
+
}
|
|
34
|
+
return aliases;
|
|
35
|
+
}
|
|
36
|
+
function resolvesPackage(pkgName, root, requireFrom) {
|
|
37
|
+
return resolvePackageDir$2(pkgName, root, requireFrom) !== void 0;
|
|
38
|
+
}
|
|
39
|
+
function resolvePackageDir$2(pkgName, root, requireFrom) {
|
|
40
|
+
try {
|
|
41
|
+
return path.dirname(requireFrom.resolve(`${pkgName}/package.json`));
|
|
42
|
+
} catch {
|
|
43
|
+
const hoisted = path.join(root, "node_modules", ...pkgName.split("/"));
|
|
44
|
+
return fs.existsSync(path.join(hoisted, "package.json")) ? hoisted : void 0;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region ../utils/src/nativeOnlyDepStubs.ts
|
|
50
|
+
const NATIVE_ONLY_MODULES = [{
|
|
51
|
+
pkg: "react-native-svg",
|
|
52
|
+
flavours: [
|
|
53
|
+
"lib/module/fabric/NativeSvgSoundModule.js",
|
|
54
|
+
"lib/commonjs/fabric/NativeSvgSoundModule.js",
|
|
55
|
+
"src/fabric/NativeSvgSoundModule.ts"
|
|
56
|
+
],
|
|
57
|
+
specifier: "../fabric/NativeSvgSoundModule",
|
|
58
|
+
binding: "TurboModuleRegistry",
|
|
59
|
+
stub: "svgTouchSound.web.js"
|
|
60
|
+
}];
|
|
61
|
+
/** The web stand-in for `react-native`, whose exports decide every entry. */
|
|
62
|
+
const webRuntime = {
|
|
63
|
+
pkg: "react-native-web",
|
|
64
|
+
entry: "dist/index.js"
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Entries whose breakage is real in this tree, with their stub resolved.
|
|
68
|
+
*
|
|
69
|
+
* @param root Directory whose `node_modules` the packages resolve from.
|
|
70
|
+
*/
|
|
71
|
+
function nativeOnlyDepStubs(root = process.cwd()) {
|
|
72
|
+
const requireFrom = createRequire(path.join(root, "package.json"));
|
|
73
|
+
const webExports = runtimeExports(root, requireFrom);
|
|
74
|
+
const stubs = [];
|
|
75
|
+
for (const entry of NATIVE_ONLY_MODULES) {
|
|
76
|
+
if (!webExports || webExports.has(entry.binding)) continue;
|
|
77
|
+
const pkgDir = resolvePackageDir$1(entry.pkg, root, requireFrom);
|
|
78
|
+
if (!pkgDir) continue;
|
|
79
|
+
if (!entry.flavours.map((flavour) => path.join(pkgDir, flavour)).filter((file) => fs.existsSync(file)).some((file) => importsBinding(file, entry.binding))) continue;
|
|
80
|
+
const stub = stubFile(entry.stub);
|
|
81
|
+
if (!stub) continue;
|
|
82
|
+
stubs.push({
|
|
83
|
+
marker: `${path.sep}${entry.pkg}${path.sep}`,
|
|
84
|
+
specifiers: [
|
|
85
|
+
entry.specifier,
|
|
86
|
+
`${entry.specifier}.js`,
|
|
87
|
+
`${entry.specifier}.ts`
|
|
88
|
+
],
|
|
89
|
+
stub
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return stubs;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The resolver behind both plugins below, or undefined when nothing in this
|
|
96
|
+
* tree measures as broken.
|
|
97
|
+
*/
|
|
98
|
+
function nativeOnlyDepResolver(root = process.cwd()) {
|
|
99
|
+
const stubs = nativeOnlyDepStubs(root);
|
|
100
|
+
if (!stubs.length) return void 0;
|
|
101
|
+
return (id, importer) => {
|
|
102
|
+
if (!importer) return null;
|
|
103
|
+
for (const stub of stubs) {
|
|
104
|
+
if (!importer.includes(stub.marker)) continue;
|
|
105
|
+
if (stub.specifiers.includes(id)) return stub.stub;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Vite plugin for the transform pipeline (`vite build`, `storybook build`).
|
|
112
|
+
*
|
|
113
|
+
* `enforce: "pre"` is load-bearing: a normal-order plugin resolves after
|
|
114
|
+
* `vite:resolve`, which has already turned the relative specifier into a real
|
|
115
|
+
* file by then.
|
|
116
|
+
*/
|
|
117
|
+
function nativeOnlyDepStubPlugin(root = process.cwd()) {
|
|
118
|
+
const resolver = nativeOnlyDepResolver(root);
|
|
119
|
+
if (!resolver) return void 0;
|
|
120
|
+
return {
|
|
121
|
+
name: "multiplatform-native-only-dep-stubs",
|
|
122
|
+
enforce: "pre",
|
|
123
|
+
resolveId(id, importer) {
|
|
124
|
+
return resolver(id, importer);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The same resolver for the dev dep-optimizer, which runs its own rolldown
|
|
130
|
+
* build that sees neither user plugins nor `resolve.alias` for a relative
|
|
131
|
+
* specifier — only `optimizeDeps.rolldownOptions.plugins`. Carries no vite-only
|
|
132
|
+
* fields, since rolldown receives this object directly.
|
|
133
|
+
*/
|
|
134
|
+
function nativeOnlyDepStubOptimizerPlugin(root = process.cwd()) {
|
|
135
|
+
const resolver = nativeOnlyDepResolver(root);
|
|
136
|
+
if (!resolver) return void 0;
|
|
137
|
+
return {
|
|
138
|
+
name: "multiplatform-native-only-dep-stubs",
|
|
139
|
+
resolveId: resolver
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/** Names the web runtime re-exports, or undefined when it cannot be read. */
|
|
143
|
+
function runtimeExports(root, requireFrom) {
|
|
144
|
+
const pkgDir = resolvePackageDir$1(webRuntime.pkg, root, requireFrom);
|
|
145
|
+
if (!pkgDir) return void 0;
|
|
146
|
+
let source;
|
|
147
|
+
try {
|
|
148
|
+
source = fs.readFileSync(path.join(pkgDir, webRuntime.entry), "utf8");
|
|
149
|
+
} catch {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const names = /* @__PURE__ */ new Set();
|
|
153
|
+
for (const match of source.matchAll(/^export\s*\{([^}]*)\}/gm)) for (const clause of match[1].split(",")) {
|
|
154
|
+
const name = clause.trim().split(/\s+as\s+/).pop()?.trim();
|
|
155
|
+
if (name) names.add(name);
|
|
156
|
+
}
|
|
157
|
+
for (const match of source.matchAll(/^export\s+(?:const|let|var|function|class)\s+(\w+)/gm)) names.add(match[1]);
|
|
158
|
+
return names.size ? names : void 0;
|
|
159
|
+
}
|
|
160
|
+
/** Whether the module takes the binding off `react-native` by name. */
|
|
161
|
+
function importsBinding(file, binding) {
|
|
162
|
+
let source;
|
|
163
|
+
try {
|
|
164
|
+
source = fs.readFileSync(file, "utf8");
|
|
165
|
+
} catch {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
return new RegExp(`(?:import|require)[^;]*\\b${binding}\\b[^;]*['"]react-native['"]`, "s").test(source);
|
|
169
|
+
}
|
|
170
|
+
/** `src/shims/<name>` from source, `../src/shims/<name>` from the built `lib`. */
|
|
171
|
+
function stubFile(name) {
|
|
172
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
173
|
+
return [path.resolve(here, "shims", name), path.resolve(here, "../src/shims", name)].find((candidate) => fs.existsSync(candidate));
|
|
174
|
+
}
|
|
175
|
+
function resolvePackageDir$1(pkgName, root, requireFrom) {
|
|
176
|
+
try {
|
|
177
|
+
return path.dirname(requireFrom.resolve(`${pkgName}/package.json`));
|
|
178
|
+
} catch {
|
|
179
|
+
const hoisted = path.join(root, "node_modules", ...pkgName.split("/"));
|
|
180
|
+
return fs.existsSync(path.join(hoisted, "package.json")) ? hoisted : void 0;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region ../utils/src/dev.ts
|
|
186
|
+
const logger = console;
|
|
187
|
+
function lookupTamaguiModules(packageDirs, { log = true } = {}) {
|
|
188
|
+
const projectRoot = lookupProjectRoot();
|
|
189
|
+
const tamaguiModules = [...new Set(["tamagui", ...[...new Set([
|
|
190
|
+
projectRoot,
|
|
191
|
+
path.resolve(projectRoot, "app"),
|
|
192
|
+
path.resolve(projectRoot, "features"),
|
|
193
|
+
...packageDirs || []
|
|
194
|
+
])].map((packageDir) => {
|
|
195
|
+
const pkgPath = path.join(packageDir, "package.json");
|
|
196
|
+
if (!fs.existsSync(pkgPath)) return [];
|
|
197
|
+
try {
|
|
198
|
+
return JSON.parse(fs.readFileSync(pkgPath, "utf-8")).tamaguiModules || [];
|
|
199
|
+
} catch (err) {
|
|
200
|
+
if (log) logger.error(err);
|
|
201
|
+
return [];
|
|
202
|
+
}
|
|
203
|
+
})])].flat();
|
|
204
|
+
if (log) logger.debug("tamaguiModules:", tamaguiModules.join(", "));
|
|
205
|
+
return tamaguiModules;
|
|
206
|
+
}
|
|
207
|
+
function resolveConfig(keys = []) {
|
|
208
|
+
return keys.reduce((acc, key) => {
|
|
209
|
+
if (process.env[key]) acc[key] = process.env[key];
|
|
210
|
+
return acc;
|
|
211
|
+
}, {});
|
|
212
|
+
}
|
|
213
|
+
let _projectRoot;
|
|
214
|
+
function lookupProjectRoot() {
|
|
215
|
+
if (_projectRoot) return _projectRoot;
|
|
216
|
+
try {
|
|
217
|
+
const { stdout } = spawnSync("git", ["rev-parse", "--show-toplevel"], { encoding: "utf-8" });
|
|
218
|
+
_projectRoot = stdout.trim();
|
|
219
|
+
return _projectRoot;
|
|
220
|
+
} catch {
|
|
221
|
+
_projectRoot = process.cwd();
|
|
222
|
+
return _projectRoot;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const webConditionOrder = [
|
|
226
|
+
"import",
|
|
227
|
+
"default",
|
|
228
|
+
"require"
|
|
229
|
+
];
|
|
230
|
+
const skippedConditions = new Set(["types", "react-native"]);
|
|
231
|
+
const tsSourcePattern = /\.[cm]?tsx?$/;
|
|
232
|
+
function collectExportTargets(target, out) {
|
|
233
|
+
if (typeof target === "string") {
|
|
234
|
+
out.push(target);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (!target) return;
|
|
238
|
+
if (Array.isArray(target)) {
|
|
239
|
+
for (const item of target) collectExportTargets(item, out);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (typeof target.source === "string") out.push(target.source);
|
|
243
|
+
const keys = Object.keys(target).filter((k) => k !== "source" && !skippedConditions.has(k));
|
|
244
|
+
const ordered = [...webConditionOrder.filter((k) => keys.includes(k)), ...keys.filter((k) => !webConditionOrder.includes(k))];
|
|
245
|
+
for (const key of ordered) collectExportTargets(target[key], out);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* The file a web build should compile for one `exports` entry: its `source`
|
|
249
|
+
* condition, else the first TypeScript file among its web conditions, else
|
|
250
|
+
* the first existing file (css, a prebuilt .mjs), so the package-name alias
|
|
251
|
+
* never swallows a subpath it cannot see.
|
|
252
|
+
*/
|
|
253
|
+
function resolveExportSource(pkgDir, target) {
|
|
254
|
+
const candidates = [];
|
|
255
|
+
collectExportTargets(target, candidates);
|
|
256
|
+
const existing = candidates.map((c) => path.resolve(pkgDir, c)).filter((c) => !c.endsWith(".d.ts") && fs.existsSync(c) && fs.statSync(c).isFile());
|
|
257
|
+
return existing.find((c) => tsSourcePattern.test(c)) ?? existing[0];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The file a subpath declares when none of its targets is on disk yet, such
|
|
261
|
+
* as a prebuilt `./dist/...` asset in an unbuilt tree. Aliasing it keeps the
|
|
262
|
+
* bare package alias from rewriting the subpath into `src/index.ts/<subpath>`,
|
|
263
|
+
* so a missing build fails on the real path. Types-only subpaths get none.
|
|
264
|
+
*/
|
|
265
|
+
function declaredExportTarget(pkgDir, target) {
|
|
266
|
+
const candidates = [];
|
|
267
|
+
collectExportTargets(target, candidates);
|
|
268
|
+
const runtime = candidates.find((c) => !c.endsWith(".d.ts"));
|
|
269
|
+
return runtime ? path.resolve(pkgDir, runtime) : void 0;
|
|
270
|
+
}
|
|
271
|
+
function directoryPatternAlias(pkgDir, target) {
|
|
272
|
+
const targets = [];
|
|
273
|
+
collectExportTargets(target, targets);
|
|
274
|
+
const dirTarget = targets.find((t) => t.endsWith("/*"));
|
|
275
|
+
if (!dirTarget) return void 0;
|
|
276
|
+
const dir = path.resolve(pkgDir, dirTarget.slice(0, -2));
|
|
277
|
+
return fs.existsSync(dir) && fs.statSync(dir).isDirectory() ? dir : void 0;
|
|
278
|
+
}
|
|
279
|
+
function subpathAlias(pkgDir, key, target) {
|
|
280
|
+
if (key === "." || key === "./package.json" || !key.startsWith("./")) return void 0;
|
|
281
|
+
if (key.endsWith("/*")) {
|
|
282
|
+
const pattern = key.slice(2, -2);
|
|
283
|
+
if (pattern.includes("*")) return void 0;
|
|
284
|
+
const dir = directoryPatternAlias(pkgDir, target);
|
|
285
|
+
return dir ? [pattern, dir] : void 0;
|
|
286
|
+
}
|
|
287
|
+
if (key.includes("*")) return void 0;
|
|
288
|
+
const file = resolveExportSource(pkgDir, target) ?? declaredExportTarget(pkgDir, target);
|
|
289
|
+
return file ? [key.slice(2), file] : void 0;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Vite `resolve.alias` entries for one package's `exports` subpaths:
|
|
293
|
+
* `<name>/<subpath>` → its source file, and a `./dir/*` pattern → the directory.
|
|
294
|
+
*/
|
|
295
|
+
function packageSubpathSourceAliases(pkgName, pkgDir, exportsField) {
|
|
296
|
+
const aliases = {};
|
|
297
|
+
if (!exportsField || typeof exportsField !== "object" || Array.isArray(exportsField)) return aliases;
|
|
298
|
+
for (const [key, target] of Object.entries(exportsField)) {
|
|
299
|
+
const alias = subpathAlias(pkgDir, key, target);
|
|
300
|
+
if (alias) aliases[`${pkgName}/${alias[0]}`] = alias[1];
|
|
301
|
+
}
|
|
302
|
+
return aliases;
|
|
303
|
+
}
|
|
304
|
+
|
|
9
305
|
//#endregion
|
|
10
306
|
//#region src/singletonDepAliases.ts
|
|
11
307
|
/**
|
|
@@ -103,20 +399,95 @@ const CONTEXT_SINGLETONS = [
|
|
|
103
399
|
* Vite `resolve.alias` entries pinning each context singleton to one directory.
|
|
104
400
|
*
|
|
105
401
|
* Alias keys match the whole specifier or a `key + "/"` prefix, so subpath
|
|
106
|
-
* imports follow the same copy instead of resolving independently.
|
|
107
|
-
*
|
|
108
|
-
*
|
|
402
|
+
* imports follow the same copy instead of resolving independently. That holds
|
|
403
|
+
* only while every subpath is a real file under the package directory; a
|
|
404
|
+
* package whose `exports` map REMAPS one is pinned by
|
|
405
|
+
* `singletonResolvePlugin` instead, because the prefix would rewrite the
|
|
406
|
+
* specifier to a path that does not exist. Entries are omitted when the
|
|
407
|
+
* package is not installed, so a consumer that does not use cookies is
|
|
408
|
+
* unaffected.
|
|
109
409
|
*
|
|
110
410
|
* @param root Directory whose `node_modules` the packages resolve from.
|
|
111
411
|
*/
|
|
112
412
|
function singletonDepAliases(root = process.cwd()) {
|
|
113
413
|
const aliases = {};
|
|
414
|
+
for (const { name, dir, exportsMapped } of resolveSingletons(root)) if (!exportsMapped) aliases[name] = dir;
|
|
415
|
+
return aliases;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Every installed context singleton with its pinned directory.
|
|
419
|
+
*
|
|
420
|
+
* `exportsMapped` is measured rather than listed: a subpath key whose literal
|
|
421
|
+
* path does not exist under the package is one only the `exports` map can
|
|
422
|
+
* resolve. Measured on the installed tree at Tamagui 3.2.3, `@tamagui/core`
|
|
423
|
+
* and `@tamagui/web` each remap `./theme-update`, `./dom` and
|
|
424
|
+
* `./static-resolve`, and `react-cookie` and the three tanstack packages remap
|
|
425
|
+
* nothing. So a tanstack upgrade that adds a remapped subpath moves itself to
|
|
426
|
+
* the plugin instead of breaking a build.
|
|
427
|
+
*/
|
|
428
|
+
function resolveSingletons(root = process.cwd()) {
|
|
114
429
|
const requireFrom = createRequire(path.join(root, "package.json"));
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
430
|
+
const pins = [];
|
|
431
|
+
for (const name of CONTEXT_SINGLETONS) {
|
|
432
|
+
const dir = resolvePackageDir(name, root, requireFrom);
|
|
433
|
+
if (dir) pins.push({
|
|
434
|
+
name,
|
|
435
|
+
dir,
|
|
436
|
+
exportsMapped: remapsASubpath(dir)
|
|
437
|
+
});
|
|
118
438
|
}
|
|
119
|
-
return
|
|
439
|
+
return pins;
|
|
440
|
+
}
|
|
441
|
+
function remapsASubpath(pkgDir) {
|
|
442
|
+
let exports;
|
|
443
|
+
try {
|
|
444
|
+
exports = JSON.parse(fs.readFileSync(path.join(pkgDir, "package.json"), "utf8")).exports;
|
|
445
|
+
} catch {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
if (typeof exports !== "object" || exports === null) return false;
|
|
449
|
+
for (const key of Object.keys(exports)) {
|
|
450
|
+
if (key === "." || key === "./package.json" || !key.startsWith("./")) continue;
|
|
451
|
+
if (key.includes("*")) return true;
|
|
452
|
+
if (!fs.existsSync(path.join(pkgDir, key.slice(2)))) return true;
|
|
453
|
+
}
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Pins the singletons a directory alias cannot reach.
|
|
458
|
+
*
|
|
459
|
+
* `tamagui`'s own index imports `./theme-update.mjs`, which imports
|
|
460
|
+
* `@tamagui/core/theme-update`, which imports `@tamagui/web/theme-update`, so
|
|
461
|
+
* every import of `tamagui` anywhere walks that chain. Under a directory alias
|
|
462
|
+
* the prefix match rewrites it to `<pkgDir>/theme-update`, which is not a file,
|
|
463
|
+
* and `apps/one`'s production build dies with
|
|
464
|
+
* `[UNLOADABLE_DEPENDENCY] Could not load @tamagui/core/theme-update`. The dev
|
|
465
|
+
* server and vitest pre-bundle bare imports by package NAME and never see it,
|
|
466
|
+
* which is why 19,236 specs pass against a build that cannot be made.
|
|
467
|
+
*
|
|
468
|
+
* Re-resolving ANCHORED at the pinned package's own `package.json` is what
|
|
469
|
+
* keeps both halves: the exports map runs, so the environment's own conditions
|
|
470
|
+
* pick `.mjs` on web and `.native.js` on native, and the copy is the pinned one
|
|
471
|
+
* because that is where the resolution starts. A static target cannot do this,
|
|
472
|
+
* since the web and native files differ and this alias set is shared by both.
|
|
473
|
+
*
|
|
474
|
+
* @param root Directory whose `node_modules` the packages resolve from.
|
|
475
|
+
*/
|
|
476
|
+
function singletonResolvePlugin(root = process.cwd()) {
|
|
477
|
+
const pinned = resolveSingletons(root).filter((pin) => pin.exportsMapped);
|
|
478
|
+
return {
|
|
479
|
+
name: "multiplatform-singleton-resolve",
|
|
480
|
+
enforce: "pre",
|
|
481
|
+
async resolveId(source, _importer, options) {
|
|
482
|
+
const pin = pinned.find((p) => source === p.name || source.startsWith(`${p.name}/`));
|
|
483
|
+
if (!pin) return null;
|
|
484
|
+
const anchor = path.join(pin.dir, "package.json");
|
|
485
|
+
return (await this.resolve(source, anchor, {
|
|
486
|
+
...options,
|
|
487
|
+
skipSelf: true
|
|
488
|
+
}))?.id ?? null;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
120
491
|
}
|
|
121
492
|
/**
|
|
122
493
|
* Merges `base` with the singleton pins and orders the result for Vite.
|
|
@@ -163,127 +534,6 @@ function resolvePackageDir(pkgName, root, requireFrom) {
|
|
|
163
534
|
}
|
|
164
535
|
}
|
|
165
536
|
|
|
166
|
-
//#endregion
|
|
167
|
-
//#region ../utils/src/dev.ts
|
|
168
|
-
const logger = console;
|
|
169
|
-
function lookupTamaguiModules(packageDirs, { log = true } = {}) {
|
|
170
|
-
const projectRoot = lookupProjectRoot();
|
|
171
|
-
const tamaguiModules = [...new Set(["tamagui", ...[...new Set([
|
|
172
|
-
projectRoot,
|
|
173
|
-
path.resolve(projectRoot, "app"),
|
|
174
|
-
path.resolve(projectRoot, "features"),
|
|
175
|
-
...packageDirs || []
|
|
176
|
-
])].map((packageDir) => {
|
|
177
|
-
const pkgPath = path.join(packageDir, "package.json");
|
|
178
|
-
if (!fs.existsSync(pkgPath)) return [];
|
|
179
|
-
try {
|
|
180
|
-
return JSON.parse(fs.readFileSync(pkgPath, "utf-8")).tamaguiModules || [];
|
|
181
|
-
} catch (err) {
|
|
182
|
-
if (log) logger.error(err);
|
|
183
|
-
return [];
|
|
184
|
-
}
|
|
185
|
-
})])].flat();
|
|
186
|
-
if (log) logger.debug("tamaguiModules:", tamaguiModules.join(", "));
|
|
187
|
-
return tamaguiModules;
|
|
188
|
-
}
|
|
189
|
-
function resolveConfig(keys = []) {
|
|
190
|
-
return keys.reduce((acc, key) => {
|
|
191
|
-
if (process.env[key]) acc[key] = process.env[key];
|
|
192
|
-
return acc;
|
|
193
|
-
}, {});
|
|
194
|
-
}
|
|
195
|
-
let _projectRoot;
|
|
196
|
-
function lookupProjectRoot() {
|
|
197
|
-
if (_projectRoot) return _projectRoot;
|
|
198
|
-
try {
|
|
199
|
-
const { stdout } = spawnSync("git", ["rev-parse", "--show-toplevel"], { encoding: "utf-8" });
|
|
200
|
-
_projectRoot = stdout.trim();
|
|
201
|
-
return _projectRoot;
|
|
202
|
-
} catch {
|
|
203
|
-
_projectRoot = process.cwd();
|
|
204
|
-
return _projectRoot;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
const webConditionOrder = [
|
|
208
|
-
"import",
|
|
209
|
-
"default",
|
|
210
|
-
"require"
|
|
211
|
-
];
|
|
212
|
-
const skippedConditions = new Set(["types", "react-native"]);
|
|
213
|
-
const tsSourcePattern = /\.[cm]?tsx?$/;
|
|
214
|
-
function collectExportTargets(target, out) {
|
|
215
|
-
if (typeof target === "string") {
|
|
216
|
-
out.push(target);
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
if (!target) return;
|
|
220
|
-
if (Array.isArray(target)) {
|
|
221
|
-
for (const item of target) collectExportTargets(item, out);
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
if (typeof target.source === "string") out.push(target.source);
|
|
225
|
-
const keys = Object.keys(target).filter((k) => k !== "source" && !skippedConditions.has(k));
|
|
226
|
-
const ordered = [...webConditionOrder.filter((k) => keys.includes(k)), ...keys.filter((k) => !webConditionOrder.includes(k))];
|
|
227
|
-
for (const key of ordered) collectExportTargets(target[key], out);
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* The file a web build should compile for one `exports` entry: its `source`
|
|
231
|
-
* condition, else the first TypeScript file among its web conditions, else
|
|
232
|
-
* the first existing file (css, a prebuilt .mjs), so the package-name alias
|
|
233
|
-
* never swallows a subpath it cannot see.
|
|
234
|
-
*/
|
|
235
|
-
function resolveExportSource(pkgDir, target) {
|
|
236
|
-
const candidates = [];
|
|
237
|
-
collectExportTargets(target, candidates);
|
|
238
|
-
const existing = candidates.map((c) => path.resolve(pkgDir, c)).filter((c) => !c.endsWith(".d.ts") && fs.existsSync(c) && fs.statSync(c).isFile());
|
|
239
|
-
return existing.find((c) => tsSourcePattern.test(c)) ?? existing[0];
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* The file a subpath declares when none of its targets is on disk yet, such
|
|
243
|
-
* as a prebuilt `./dist/...` asset in an unbuilt tree. Aliasing it keeps the
|
|
244
|
-
* bare package alias from rewriting the subpath into `src/index.ts/<subpath>`,
|
|
245
|
-
* so a missing build fails on the real path. Types-only subpaths get none.
|
|
246
|
-
*/
|
|
247
|
-
function declaredExportTarget(pkgDir, target) {
|
|
248
|
-
const candidates = [];
|
|
249
|
-
collectExportTargets(target, candidates);
|
|
250
|
-
const runtime = candidates.find((c) => !c.endsWith(".d.ts"));
|
|
251
|
-
return runtime ? path.resolve(pkgDir, runtime) : void 0;
|
|
252
|
-
}
|
|
253
|
-
function directoryPatternAlias(pkgDir, target) {
|
|
254
|
-
const targets = [];
|
|
255
|
-
collectExportTargets(target, targets);
|
|
256
|
-
const dirTarget = targets.find((t) => t.endsWith("/*"));
|
|
257
|
-
if (!dirTarget) return void 0;
|
|
258
|
-
const dir = path.resolve(pkgDir, dirTarget.slice(0, -2));
|
|
259
|
-
return fs.existsSync(dir) && fs.statSync(dir).isDirectory() ? dir : void 0;
|
|
260
|
-
}
|
|
261
|
-
function subpathAlias(pkgDir, key, target) {
|
|
262
|
-
if (key === "." || key === "./package.json" || !key.startsWith("./")) return void 0;
|
|
263
|
-
if (key.endsWith("/*")) {
|
|
264
|
-
const pattern = key.slice(2, -2);
|
|
265
|
-
if (pattern.includes("*")) return void 0;
|
|
266
|
-
const dir = directoryPatternAlias(pkgDir, target);
|
|
267
|
-
return dir ? [pattern, dir] : void 0;
|
|
268
|
-
}
|
|
269
|
-
if (key.includes("*")) return void 0;
|
|
270
|
-
const file = resolveExportSource(pkgDir, target) ?? declaredExportTarget(pkgDir, target);
|
|
271
|
-
return file ? [key.slice(2), file] : void 0;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Vite `resolve.alias` entries for one package's `exports` subpaths:
|
|
275
|
-
* `<name>/<subpath>` → its source file, and a `./dir/*` pattern → the directory.
|
|
276
|
-
*/
|
|
277
|
-
function packageSubpathSourceAliases(pkgName, pkgDir, exportsField) {
|
|
278
|
-
const aliases = {};
|
|
279
|
-
if (!exportsField || typeof exportsField !== "object" || Array.isArray(exportsField)) return aliases;
|
|
280
|
-
for (const [key, target] of Object.entries(exportsField)) {
|
|
281
|
-
const alias = subpathAlias(pkgDir, key, target);
|
|
282
|
-
if (alias) aliases[`${pkgName}/${alias[0]}`] = alias[1];
|
|
283
|
-
}
|
|
284
|
-
return aliases;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
537
|
//#endregion
|
|
288
538
|
//#region src/workspacePublicPackages.ts
|
|
289
539
|
/**
|
|
@@ -429,4 +679,4 @@ function publicPackageViteSourceAliases(workspaceRoot) {
|
|
|
429
679
|
}
|
|
430
680
|
|
|
431
681
|
//#endregion
|
|
432
|
-
export { staleNativeDistSource as a,
|
|
682
|
+
export { staleNativeDistSource as a, lookupTamaguiModules as c, nativeOnlyDepStubPlugin as d, movedDepAliases as f, resolveWorkspaceNativeEntry as i, resolveConfig as l, publicPackageViteSourceAliases as n, singletonResolvePlugin as o, __require as p, resolvePackageMainSource as r, withSingletonDepAliases as s, discoverPublicPackageRoots as t, nativeOnlyDepStubOptimizerPlugin as u };
|