@multiplatform.one/config 9.17.0 → 10.0.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.
Files changed (52) hide show
  1. package/design-lint.mjs +29 -6
  2. package/lib/index.js +4 -4
  3. package/lib/{storybook-BpaziEtP.js → storybook-BRZwQLAM.js} +150 -9
  4. package/lib/storybook.js +1 -1
  5. package/lib/{tamaguiWorkspacePaths-DR3dud79.js → tamaguiWorkspacePaths-BFMQNk1l.js} +8 -5
  6. package/lib/{vite-CgiDLR6V.js → vite-DaBjbGS0.js} +40 -52
  7. package/lib/vite.js +4 -4
  8. package/lib/{vitest-B2vcGrZM.js → vitest-NTT7k5jB.js} +97 -10
  9. package/lib/vitest.js +2 -2
  10. package/lib/{workspacePublicPackages-DN-1LPcH.js → workspacePublicPackages-z0fVhgGN.js} +121 -8
  11. package/lint.mjs +874 -52
  12. package/oxlint.mjs +26 -1
  13. package/package.json +6 -6
  14. package/press-lint.mjs +86 -5
  15. package/spec-registry.mjs +15 -0
  16. package/src/lint.spec.ts +696 -12
  17. package/src/movedDepAliases.spec.ts +73 -0
  18. package/src/movedDepAliases.ts +91 -0
  19. package/src/nativeBlockScoping.spec.ts +12 -14
  20. package/src/nativeOnlyDepStubs.spec.ts +178 -0
  21. package/src/nativeOnlyDepStubs.ts +215 -0
  22. package/src/noVoicelessText.rule.spec.ts +1 -1
  23. package/src/noVoicelessText.spec.ts +1 -1
  24. package/src/oxlint.spec.ts +5 -5
  25. package/src/phosphorNativeInk.spec.ts +17 -18
  26. package/src/phosphorTokenColor.spec.ts +35 -0
  27. package/src/phosphorTokenColor.ts +8 -5
  28. package/src/press-lint.spec.ts +64 -3
  29. package/src/react-native.config.cjs +9 -0
  30. package/src/shims/phosphorThemeInk.js +6 -1
  31. package/src/shims/svgTouchSound.web.js +23 -0
  32. package/src/singletonDepAliases.spec.ts +99 -14
  33. package/src/singletonDepAliases.ts +102 -7
  34. package/src/storybook.spec.ts +0 -3
  35. package/src/storybook.ts +17 -6
  36. package/src/vite.nativeEntries.spec.ts +21 -20
  37. package/src/vite.spec.ts +11 -20
  38. package/src/vite.ts +44 -68
  39. package/src/vitest.spec.ts +142 -4
  40. package/src/vitest.ts +106 -8
  41. package/types/movedDepAliases.d.ts +8 -0
  42. package/types/movedDepAliases.d.ts.map +1 -0
  43. package/types/nativeOnlyDepStubs.d.ts +41 -0
  44. package/types/nativeOnlyDepStubs.d.ts.map +1 -0
  45. package/types/phosphorTokenColor.d.ts.map +1 -1
  46. package/types/singletonDepAliases.d.ts +55 -3
  47. package/types/singletonDepAliases.d.ts.map +1 -1
  48. package/types/storybook.d.ts.map +1 -1
  49. package/types/vite.d.ts +10 -1
  50. package/types/vite.d.ts.map +1 -1
  51. package/types/vitest.d.ts +46 -1
  52. package/types/vitest.d.ts.map +1 -1
@@ -1,4 +1,4 @@
1
- import { i as phosphorTokenColorPlugin, r as phosphorBarrelBundlePlugin, t as ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths-DR3dud79.js";
1
+ import { i as phosphorTokenColorPlugin, r as phosphorBarrelBundlePlugin, t as ensureTamaguiWorkspacePaths } from "./tamaguiWorkspacePaths-BFMQNk1l.js";
2
2
  import Module from "node:module";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
@@ -85,6 +85,89 @@ function pinNodeReactRequire(reactDir, reactDomDir, schedulerDir) {
85
85
  };
86
86
  }
87
87
  /**
88
+ * The Vite environment Tamagui 3's vite plugin evaluates the tamagui config in
89
+ * (`TAMAGUI_EVALUATION_ENVIRONMENT` in @tamagui/vite-plugin's loadTamagui.ts,
90
+ * not exported). It inlines only the Tamagui packages it has to and hands every
91
+ * other bare import, react above all, to node.
92
+ */
93
+ const tamaguiEvaluationEnvironment = "tamagui";
94
+ /**
95
+ * Vitest 4 sets `resolve.noExternal = true` on every Vite environment but its
96
+ * own runner's, Tamagui's evaluation environment included, so react's CJS
97
+ * entry gets inlined there and the run dies before collecting a spec with
98
+ * `module is not defined`. Put the plugin's own list back once vitest has had
99
+ * its say. The client and ssr environments vitest runs specs in keep vitest's.
100
+ */
101
+ function tamaguiEvaluationExternals() {
102
+ let noExternal;
103
+ return {
104
+ name: "mpo:tamagui-evaluation-externals",
105
+ configEnvironment(name, config) {
106
+ if (name === tamaguiEvaluationEnvironment) noExternal = config.resolve?.noExternal;
107
+ },
108
+ configResolved(config) {
109
+ const environment = config.environments[tamaguiEvaluationEnvironment];
110
+ if (!environment || noExternal === void 0) return;
111
+ environment.resolve.noExternal = noExternal;
112
+ }
113
+ };
114
+ }
115
+ /**
116
+ * Tamagui 3 evaluates a package's tamagui config in its own environment, which
117
+ * resolves with Vite's default client conditions plus `tamagui-compiler` and
118
+ * none of MPO's. A config that imports a workspace package
119
+ * (`createDefaultThemeConfig` from @multiplatform.one/theme) then reaches for
120
+ * that package's unbuilt `dist/` and the run dies at startup with
121
+ * `Failed to resolve entry for package`. The plugin merges a user's
122
+ * `environments.tamagui` over its own, so this hands that environment the
123
+ * conditions the specs resolve with, `source` first among them.
124
+ */
125
+ function tamaguiEvaluationConditions(conditions) {
126
+ return {
127
+ name: "mpo:tamagui-evaluation-conditions",
128
+ config() {
129
+ return { environments: { [tamaguiEvaluationEnvironment]: { resolve: { conditions } } } };
130
+ }
131
+ };
132
+ }
133
+ /**
134
+ * The virtual stylesheet Tamagui 3's compiler writes each module's extracted
135
+ * atomic rules to (`virtualExt` in @tamagui/vite-plugin's plugin.ts). Vitest
136
+ * drops every CSS module its `css.include` doesn't name, so without this an
137
+ * element the compiler flattened carries hashed classes with no rule behind
138
+ * them, while a runtime-styled sibling's rules sit in `#_tamagui-styles`.
139
+ * Naming it puts both kinds of rule in `document.styleSheets`, where
140
+ * `atomicStyle()` in @multiplatform.one/test-utils reads them.
141
+ */
142
+ const tamaguiExtractedCss = /\.tamagui\.css(?:\?|$)/;
143
+ /**
144
+ * MPO-37's one-physical-copy pins as a resolver rather than `resolve.alias`.
145
+ * An alias applies in every environment, and in Tamagui's evaluation
146
+ * environment it turns `react` into a file path, which that environment
147
+ * inlines instead of handing to node. The pins only matter where specs render,
148
+ * so that environment resolves react the way node does.
149
+ *
150
+ * Matching is the alias's: a pin applies to its name and to any subpath under
151
+ * it, so `react/jsx-runtime` lands in the pinned react.
152
+ */
153
+ function pinnedPackages(pins) {
154
+ const names = Object.keys(pins).sort((a, b) => b.length - a.length);
155
+ return {
156
+ name: "mpo:pinned-packages",
157
+ enforce: "pre",
158
+ api: { pins },
159
+ async resolveId(source, importer, options) {
160
+ if (this.environment?.name === tamaguiEvaluationEnvironment) return null;
161
+ const name = names.find((pin) => source === pin || source.startsWith(`${pin}/`));
162
+ if (!name) return null;
163
+ return this.resolve(pins[name] + source.slice(name.length), importer, {
164
+ ...options,
165
+ skipSelf: true
166
+ });
167
+ }
168
+ };
169
+ }
170
+ /**
88
171
  * Creates a shared Vitest configuration for multiplatform.one packages.
89
172
  *
90
173
  * This eliminates the ~100 lines of duplicated vitest config across 13+ packages,
@@ -132,7 +215,7 @@ function createVitestConfig(options = {}) {
132
215
  if (tamaguiConfig !== false) plugins.push(tamaguiPlugin({
133
216
  components: ["tamagui"],
134
217
  config: tamaguiConfig
135
- }));
218
+ }), tamaguiEvaluationExternals(), tamaguiEvaluationConditions(conditions));
136
219
  const resolveAliases = {};
137
220
  if (replaceReactNative) {
138
221
  resolveAliases["react-native"] = "react-native-web";
@@ -147,14 +230,16 @@ function createVitestConfig(options = {}) {
147
230
  };
148
231
  const reactDir = onePhysicalCopy("react");
149
232
  const reactDomDir = onePhysicalCopy("react-dom");
150
- resolveAliases.react = reactDir;
151
- resolveAliases["react-dom"] = reactDomDir;
152
- resolveAliases["react-dom/client"] = path.join(reactDomDir, "client");
153
- resolveAliases["react-dom/server"] = path.join(reactDomDir, "server");
154
- resolveAliases["react/jsx-runtime"] = path.join(reactDir, "jsx-runtime");
155
- resolveAliases["react/jsx-dev-runtime"] = path.join(reactDir, "jsx-dev-runtime");
156
233
  const schedulerDir = onePhysicalCopy("scheduler");
157
- resolveAliases.scheduler = schedulerDir;
234
+ plugins.push(pinnedPackages({
235
+ react: reactDir,
236
+ "react-dom": reactDomDir,
237
+ "react-dom/client": path.join(reactDomDir, "client"),
238
+ "react-dom/server": path.join(reactDomDir, "server"),
239
+ "react/jsx-runtime": path.join(reactDir, "jsx-runtime"),
240
+ "react/jsx-dev-runtime": path.join(reactDir, "jsx-dev-runtime"),
241
+ scheduler: schedulerDir
242
+ }));
158
243
  process.env.MPO_VITEST_REACT = reactDir;
159
244
  process.env.MPO_VITEST_REACT_DOM = reactDomDir;
160
245
  process.env.MPO_VITEST_SCHEDULER = schedulerDir;
@@ -164,6 +249,7 @@ function createVitestConfig(options = {}) {
164
249
  const testConfig = {
165
250
  environment,
166
251
  globals: true,
252
+ env: { IS_STATIC: "" },
167
253
  setupFiles: dedupeReact ? [pinReactRequireSetup, ...resolvedSetupFiles] : resolvedSetupFiles,
168
254
  testTimeout: positiveIntEnv("VITEST_TEST_TIMEOUT") ?? testTimeout,
169
255
  ...positiveIntEnv("VITEST_MAX_WORKERS") ? { maxWorkers: positiveIntEnv("VITEST_MAX_WORKERS") } : null,
@@ -207,6 +293,7 @@ function createVitestConfig(options = {}) {
207
293
  if (include) testConfig.include = include;
208
294
  testConfig.exclude = [...exclude ?? configDefaults.exclude, ...integrationSpecs];
209
295
  if (passWithNoTests) testConfig.passWithNoTests = true;
296
+ if (tamaguiConfig !== false) testConfig.css = { include: [tamaguiExtractedCss] };
210
297
  return {
211
298
  plugins,
212
299
  test: testConfig,
@@ -256,4 +343,4 @@ function createVitestConfig(options = {}) {
256
343
  }
257
344
 
258
345
  //#endregion
259
- export { createVitestConfig as t };
346
+ export { tamaguiExtractedCss as a, tamaguiEvaluationExternals as i, pinnedPackages as n, tamaguiEvaluationConditions as r, createVitestConfig as t };
package/lib/vitest.js CHANGED
@@ -1,3 +1,3 @@
1
- import { t as createVitestConfig } from "./vitest-B2vcGrZM.js";
1
+ import { a as tamaguiExtractedCss, i as tamaguiEvaluationExternals, n as pinnedPackages, r as tamaguiEvaluationConditions, t as createVitestConfig } from "./vitest-NTT7k5jB.js";
2
2
 
3
- export { createVitestConfig };
3
+ export { createVitestConfig, pinnedPackages, tamaguiEvaluationConditions, tamaguiEvaluationExternals, tamaguiExtractedCss };
@@ -6,6 +6,44 @@ import { spawnSync } from "node:child_process";
6
6
  //#region \0rolldown/runtime.js
7
7
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
8
8
 
9
+ //#endregion
10
+ //#region src/movedDepAliases.ts
11
+ const MOVED_MODULES = [{
12
+ specifier: "@react-native/assets-registry/registry",
13
+ goneWith: "@react-native/assets-registry",
14
+ nowIn: "react-native-web",
15
+ file: "dist/modules/AssetRegistry/index.js"
16
+ }];
17
+ /**
18
+ * Vite `resolve.alias` entries for modules that moved out from under a
19
+ * publisher's import.
20
+ *
21
+ * @param root Directory whose `node_modules` the packages resolve from.
22
+ */
23
+ function movedDepAliases(root = process.cwd()) {
24
+ const requireFrom = createRequire(path.join(root, "package.json"));
25
+ const aliases = {};
26
+ for (const moved of MOVED_MODULES) {
27
+ if (resolvesPackage(moved.goneWith, root, requireFrom)) continue;
28
+ const host = resolvePackageDir$1(moved.nowIn, root, requireFrom);
29
+ if (!host) continue;
30
+ const target = path.join(host, moved.file);
31
+ if (fs.existsSync(target)) aliases[moved.specifier] = target;
32
+ }
33
+ return aliases;
34
+ }
35
+ function resolvesPackage(pkgName, root, requireFrom) {
36
+ return resolvePackageDir$1(pkgName, root, requireFrom) !== void 0;
37
+ }
38
+ function resolvePackageDir$1(pkgName, root, requireFrom) {
39
+ try {
40
+ return path.dirname(requireFrom.resolve(`${pkgName}/package.json`));
41
+ } catch {
42
+ const hoisted = path.join(root, "node_modules", ...pkgName.split("/"));
43
+ return fs.existsSync(path.join(hoisted, "package.json")) ? hoisted : void 0;
44
+ }
45
+ }
46
+
9
47
  //#endregion
10
48
  //#region src/singletonDepAliases.ts
11
49
  /**
@@ -103,20 +141,95 @@ const CONTEXT_SINGLETONS = [
103
141
  * Vite `resolve.alias` entries pinning each context singleton to one directory.
104
142
  *
105
143
  * Alias keys match the whole specifier or a `key + "/"` prefix, so subpath
106
- * imports follow the same copy instead of resolving independently. Entries are
107
- * omitted when the package is not installed, so a consumer that does not use
108
- * cookies is unaffected.
144
+ * imports follow the same copy instead of resolving independently. That holds
145
+ * only while every subpath is a real file under the package directory; a
146
+ * package whose `exports` map REMAPS one is pinned by
147
+ * `singletonResolvePlugin` instead, because the prefix would rewrite the
148
+ * specifier to a path that does not exist. Entries are omitted when the
149
+ * package is not installed, so a consumer that does not use cookies is
150
+ * unaffected.
109
151
  *
110
152
  * @param root Directory whose `node_modules` the packages resolve from.
111
153
  */
112
154
  function singletonDepAliases(root = process.cwd()) {
113
155
  const aliases = {};
156
+ for (const { name, dir, exportsMapped } of resolveSingletons(root)) if (!exportsMapped) aliases[name] = dir;
157
+ return aliases;
158
+ }
159
+ /**
160
+ * Every installed context singleton with its pinned directory.
161
+ *
162
+ * `exportsMapped` is measured rather than listed: a subpath key whose literal
163
+ * path does not exist under the package is one only the `exports` map can
164
+ * resolve. Measured on the installed tree at Tamagui 3.2.3, `@tamagui/core`
165
+ * and `@tamagui/web` each remap `./theme-update`, `./dom` and
166
+ * `./static-resolve`, and `react-cookie` and the three tanstack packages remap
167
+ * nothing. So a tanstack upgrade that adds a remapped subpath moves itself to
168
+ * the plugin instead of breaking a build.
169
+ */
170
+ function resolveSingletons(root = process.cwd()) {
114
171
  const requireFrom = createRequire(path.join(root, "package.json"));
115
- for (const pkgName of CONTEXT_SINGLETONS) {
116
- const pkgDir = resolvePackageDir(pkgName, root, requireFrom);
117
- if (pkgDir) aliases[pkgName] = pkgDir;
172
+ const pins = [];
173
+ for (const name of CONTEXT_SINGLETONS) {
174
+ const dir = resolvePackageDir(name, root, requireFrom);
175
+ if (dir) pins.push({
176
+ name,
177
+ dir,
178
+ exportsMapped: remapsASubpath(dir)
179
+ });
118
180
  }
119
- return aliases;
181
+ return pins;
182
+ }
183
+ function remapsASubpath(pkgDir) {
184
+ let exports;
185
+ try {
186
+ exports = JSON.parse(fs.readFileSync(path.join(pkgDir, "package.json"), "utf8")).exports;
187
+ } catch {
188
+ return false;
189
+ }
190
+ if (typeof exports !== "object" || exports === null) return false;
191
+ for (const key of Object.keys(exports)) {
192
+ if (key === "." || key === "./package.json" || !key.startsWith("./")) continue;
193
+ if (key.includes("*")) return true;
194
+ if (!fs.existsSync(path.join(pkgDir, key.slice(2)))) return true;
195
+ }
196
+ return false;
197
+ }
198
+ /**
199
+ * Pins the singletons a directory alias cannot reach.
200
+ *
201
+ * `tamagui`'s own index imports `./theme-update.mjs`, which imports
202
+ * `@tamagui/core/theme-update`, which imports `@tamagui/web/theme-update`, so
203
+ * every import of `tamagui` anywhere walks that chain. Under a directory alias
204
+ * the prefix match rewrites it to `<pkgDir>/theme-update`, which is not a file,
205
+ * and `apps/one`'s production build dies with
206
+ * `[UNLOADABLE_DEPENDENCY] Could not load @tamagui/core/theme-update`. The dev
207
+ * server and vitest pre-bundle bare imports by package NAME and never see it,
208
+ * which is why 19,236 specs pass against a build that cannot be made.
209
+ *
210
+ * Re-resolving ANCHORED at the pinned package's own `package.json` is what
211
+ * keeps both halves: the exports map runs, so the environment's own conditions
212
+ * pick `.mjs` on web and `.native.js` on native, and the copy is the pinned one
213
+ * because that is where the resolution starts. A static target cannot do this,
214
+ * since the web and native files differ and this alias set is shared by both.
215
+ *
216
+ * @param root Directory whose `node_modules` the packages resolve from.
217
+ */
218
+ function singletonResolvePlugin(root = process.cwd()) {
219
+ const pinned = resolveSingletons(root).filter((pin) => pin.exportsMapped);
220
+ return {
221
+ name: "multiplatform-singleton-resolve",
222
+ enforce: "pre",
223
+ async resolveId(source, _importer, options) {
224
+ const pin = pinned.find((p) => source === p.name || source.startsWith(`${p.name}/`));
225
+ if (!pin) return null;
226
+ const anchor = path.join(pin.dir, "package.json");
227
+ return (await this.resolve(source, anchor, {
228
+ ...options,
229
+ skipSelf: true
230
+ }))?.id ?? null;
231
+ }
232
+ };
120
233
  }
121
234
  /**
122
235
  * Merges `base` with the singleton pins and orders the result for Vite.
@@ -429,4 +542,4 @@ function publicPackageViteSourceAliases(workspaceRoot) {
429
542
  }
430
543
 
431
544
  //#endregion
432
- export { staleNativeDistSource as a, withSingletonDepAliases as c, resolveWorkspaceNativeEntry as i, __require as l, publicPackageViteSourceAliases as n, lookupTamaguiModules as o, resolvePackageMainSource as r, resolveConfig as s, discoverPublicPackageRoots as t };
545
+ export { staleNativeDistSource as a, singletonResolvePlugin as c, __require as d, resolveWorkspaceNativeEntry as i, withSingletonDepAliases as l, publicPackageViteSourceAliases as n, lookupTamaguiModules as o, resolvePackageMainSource as r, resolveConfig as s, discoverPublicPackageRoots as t, movedDepAliases as u };