delacour 0.1.0-alpha.4 → 0.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/README.md +9 -9
- package/dist/index.js +1180 -999
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22,15 +22,6 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
22
22
|
var __getProtoOf = Object.getPrototypeOf;
|
|
23
23
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
24
24
|
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
25
|
-
var __exportAll = (all, no_symbols) => {
|
|
26
|
-
let target = {};
|
|
27
|
-
for (var name in all) __defProp(target, name, {
|
|
28
|
-
get: all[name],
|
|
29
|
-
enumerable: true
|
|
30
|
-
});
|
|
31
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
32
|
-
return target;
|
|
33
|
-
};
|
|
34
25
|
var __copyProps = (to, from, except, desc) => {
|
|
35
26
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
36
27
|
key = keys[i];
|
|
@@ -9904,8 +9895,8 @@ function datetime(params) {
|
|
|
9904
9895
|
* The five destinations a registry file can land in, and the placeholder
|
|
9905
9896
|
* scheme that keeps a file portable between them.
|
|
9906
9897
|
*
|
|
9907
|
-
* A component in `native-ui` imports its neighbours by relative path —
|
|
9908
|
-
* `../../lib/cn`. That path is only correct for `native-ui`'s own layout, and
|
|
9898
|
+
* A component in `react-native-ui` imports its neighbours by relative path —
|
|
9899
|
+
* `../../lib/cn`. That path is only correct for `react-native-ui`'s own layout, and
|
|
9909
9900
|
* the whole point of the CLI is that the consumer picks their own. So the
|
|
9910
9901
|
* registry builder rewrites every cross-directory import into a placeholder
|
|
9911
9902
|
* (`@registry/lib/cn`) and the `add` command substitutes the consumer's alias
|
|
@@ -10696,6 +10687,12 @@ const x = (command, args, userOptions) => {
|
|
|
10696
10687
|
};
|
|
10697
10688
|
const exec = x;
|
|
10698
10689
|
//#endregion
|
|
10690
|
+
//#region src/project/channel.ts
|
|
10691
|
+
function channelFor(version) {
|
|
10692
|
+
return /-alpha\b/.test(version) ? "alpha" : "latest";
|
|
10693
|
+
}
|
|
10694
|
+
const CLI_CHANNEL = channelFor("0.1.0");
|
|
10695
|
+
//#endregion
|
|
10699
10696
|
//#region src/project/package-manager.ts
|
|
10700
10697
|
const ADD = {
|
|
10701
10698
|
bun: ["bun", ["add"]],
|
|
@@ -10717,55 +10714,57 @@ const EXPO_RUNNER = {
|
|
|
10717
10714
|
npm: ["npx", ["expo", "install"]]
|
|
10718
10715
|
};
|
|
10719
10716
|
/**
|
|
10720
|
-
*
|
|
10717
|
+
* The packages this repository publishes, which follow the CLI's channel.
|
|
10721
10718
|
*
|
|
10722
|
-
*
|
|
10723
|
-
*
|
|
10724
|
-
*
|
|
10725
|
-
* on a Delacour package until `chart`.
|
|
10719
|
+
* On the alpha channel they are installed as `name@alpha`: the snapshot a
|
|
10720
|
+
* merge to `develop` published, not the last stable release `latest` serves.
|
|
10721
|
+
* Everything else is always installed untagged.
|
|
10726
10722
|
*
|
|
10727
10723
|
* Applied to the command's ARGS only, never to `packages`: `missingPackages`
|
|
10728
10724
|
* compares bare names against the project's own `package.json`, and a tagged
|
|
10729
10725
|
* spec there would never match anything and would reinstall on every run.
|
|
10730
|
-
*
|
|
10731
|
-
* Delete this map when `changeset pre exit` runs — see the root AGENTS.md.
|
|
10732
10726
|
*/
|
|
10733
|
-
const
|
|
10734
|
-
|
|
10735
|
-
|
|
10736
|
-
|
|
10737
|
-
|
|
10727
|
+
const DELACOUR_PACKAGES = /* @__PURE__ */ new Set([
|
|
10728
|
+
"@delacour/react-native-bottom-sheet",
|
|
10729
|
+
"@delacour/react-native-charts",
|
|
10730
|
+
"@delacour/react-native-ui"
|
|
10731
|
+
]);
|
|
10732
|
+
/** A package name with the dist-tag its channel pins, where it has one. */
|
|
10733
|
+
function toSpec(name, channel) {
|
|
10734
|
+
return channel === "alpha" && DELACOUR_PACKAGES.has(name) ? `${name}@alpha` : name;
|
|
10738
10735
|
}
|
|
10739
10736
|
/**
|
|
10740
10737
|
* The range a shared package declares for a peer it does not pin.
|
|
10741
10738
|
*
|
|
10742
|
-
* `*` is the usual answer, and it is wrong for a package
|
|
10743
|
-
*
|
|
10744
|
-
* `*` matches nothing `
|
|
10745
|
-
* peer as unmet and goes to the registry for a version that does
|
|
10746
|
-
* which is how `add` failed inside `expo install`, a step that
|
|
10747
|
-
* the package. `>=0.0.0-0`
|
|
10748
|
-
*
|
|
10739
|
+
* `*` is the usual answer, and it is wrong for a Delacour package: semver's
|
|
10740
|
+
* `*` admits no prerelease, so a peer on `@delacour/react-native-charts`
|
|
10741
|
+
* written as `*` matches nothing an `x.y.z-alpha.N` can ever satisfy. Bun then
|
|
10742
|
+
* treats the peer as unmet and goes to the registry for a version that does
|
|
10743
|
+
* not exist — which is how `add` failed inside `expo install`, a step that
|
|
10744
|
+
* never named the package. `>=0.0.0-0` admits every prerelease and every
|
|
10745
|
+
* stable version, so it holds on either channel.
|
|
10749
10746
|
*/
|
|
10750
10747
|
function peerRange(name) {
|
|
10751
|
-
return
|
|
10748
|
+
return DELACOUR_PACKAGES.has(name) ? ">=0.0.0-0" : "*";
|
|
10752
10749
|
}
|
|
10753
10750
|
function installCommands(request) {
|
|
10754
10751
|
const groups = [];
|
|
10752
|
+
const channel = request.channel ?? CLI_CHANNEL;
|
|
10753
|
+
const spec = (name) => toSpec(name, channel);
|
|
10755
10754
|
const [addCommand, addArgs] = ADD[request.packageManager];
|
|
10756
10755
|
if (request.expoDependencies.length > 0) {
|
|
10757
10756
|
const [command, args] = EXPO_RUNNER[request.packageManager];
|
|
10758
10757
|
groups.push({
|
|
10759
10758
|
label: "expo install",
|
|
10760
10759
|
command,
|
|
10761
|
-
args: [...args, ...request.expoDependencies.map(
|
|
10760
|
+
args: [...args, ...request.expoDependencies.map(spec)],
|
|
10762
10761
|
packages: [...request.expoDependencies]
|
|
10763
10762
|
});
|
|
10764
10763
|
}
|
|
10765
10764
|
if (request.dependencies.length > 0) groups.push({
|
|
10766
10765
|
label: `${addCommand} add`,
|
|
10767
10766
|
command: addCommand,
|
|
10768
|
-
args: [...addArgs, ...request.dependencies.map(
|
|
10767
|
+
args: [...addArgs, ...request.dependencies.map(spec)],
|
|
10769
10768
|
packages: [...request.dependencies]
|
|
10770
10769
|
});
|
|
10771
10770
|
if (request.devDependencies.length > 0) groups.push({
|
|
@@ -10774,7 +10773,7 @@ function installCommands(request) {
|
|
|
10774
10773
|
args: [
|
|
10775
10774
|
...addArgs,
|
|
10776
10775
|
DEV_FLAG[request.packageManager],
|
|
10777
|
-
...request.devDependencies.map(
|
|
10776
|
+
...request.devDependencies.map(spec)
|
|
10778
10777
|
],
|
|
10779
10778
|
packages: [...request.devDependencies]
|
|
10780
10779
|
});
|
|
@@ -10785,7 +10784,8 @@ function planDependencies(request, packageJson) {
|
|
|
10785
10784
|
packageManager: request.packageManager,
|
|
10786
10785
|
expoDependencies: missingPackages(packageJson, request.expoDependencies),
|
|
10787
10786
|
dependencies: missingPackages(packageJson, request.dependencies),
|
|
10788
|
-
devDependencies: missingPackages(packageJson, request.devDependencies)
|
|
10787
|
+
devDependencies: missingPackages(packageJson, request.devDependencies),
|
|
10788
|
+
channel: request.channel
|
|
10789
10789
|
});
|
|
10790
10790
|
const wanted = unique([
|
|
10791
10791
|
...request.expoDependencies,
|
|
@@ -11095,12 +11095,12 @@ function escapePattern(value) {
|
|
|
11095
11095
|
//#endregion
|
|
11096
11096
|
//#region src/registry/classify.ts
|
|
11097
11097
|
/**
|
|
11098
|
-
* Maps a path inside `packages/native-ui/src` onto the registry item it
|
|
11098
|
+
* Maps a path inside `packages/react-native-ui/src` onto the registry item it
|
|
11099
11099
|
* belongs to and where it lands in a consumer's project.
|
|
11100
11100
|
*
|
|
11101
|
-
* The rules here are `native-ui`'s own conventions, restated — one component
|
|
11101
|
+
* The rules here are `react-native-ui`'s own conventions, restated — one component
|
|
11102
11102
|
* per folder with an `index.ts` entry point, flat files under `lib/`, `hooks/`
|
|
11103
|
-
* and `icons/`. `packages/native-ui/scripts/gen-exports.ts` reads the same
|
|
11103
|
+
* and `icons/`. `packages/react-native-ui/scripts/gen-exports.ts` reads the same
|
|
11104
11104
|
* shape to build the package's `exports` map, so a component folder that is
|
|
11105
11105
|
* malformed fails there first.
|
|
11106
11106
|
*
|
|
@@ -11124,7 +11124,7 @@ const REGISTRY_TYPES = [
|
|
|
11124
11124
|
* field cannot make, and the one that decides whether an Expo build compiles.
|
|
11125
11125
|
*
|
|
11126
11126
|
* An item carries no file contents. `files[].path` names the library source the
|
|
11127
|
-
* file is — `packages/native-ui/src/components/button/button.tsx` — at the same
|
|
11127
|
+
* file is — `packages/react-native-ui/src/components/button/button.tsx` — at the same
|
|
11128
11128
|
* ref the item was read from, and the client fetches that. shadcn inlines
|
|
11129
11129
|
* `content` here; the cost of that is a megabyte of unreadable diff every time a
|
|
11130
11130
|
* component changes, and the benefit — one request per item — is worth less than
|
|
@@ -11171,7 +11171,7 @@ const registryRewriteSchema = object$1({
|
|
|
11171
11171
|
to: placeholderSchema
|
|
11172
11172
|
});
|
|
11173
11173
|
const registryFileSchema = object$1({
|
|
11174
|
-
/** The file's path in the repository, e.g. `packages/native-ui/src/components/button/button.tsx`. */
|
|
11174
|
+
/** The file's path in the repository, e.g. `packages/react-native-ui/src/components/button/button.tsx`. */
|
|
11175
11175
|
path: pathSchema,
|
|
11176
11176
|
/** Namespace-relative destination, e.g. `button/button.tsx`. */
|
|
11177
11177
|
target: targetSchema,
|
|
@@ -11228,14 +11228,15 @@ const registryIndexSchema = object$1({
|
|
|
11228
11228
|
* `raw.githubusercontent.com`, so there is nothing to host and nothing to keep
|
|
11229
11229
|
* running. The cost is that a ref has to be chosen: the CLI is published with
|
|
11230
11230
|
* the tag it was built from baked in, so a given version always reads the
|
|
11231
|
-
* registry it shipped against, and `--ref
|
|
11232
|
-
* since.
|
|
11231
|
+
* registry it shipped against, and `--ref develop` opts into whatever has
|
|
11232
|
+
* landed since. `main` is the last release, so `--ref main` only catches up to
|
|
11233
|
+
* the newest published CLI.
|
|
11233
11234
|
*
|
|
11234
11235
|
* That a ref pins the whole registry is also what makes it safe to split an
|
|
11235
11236
|
* item across several documents: `r/button.json` and the files it names are
|
|
11236
11237
|
* read from one immutable tree, so there is no window in which they disagree.
|
|
11237
11238
|
*
|
|
11238
|
-
* It is also why an item can name `packages/native-ui/src/...` directly rather
|
|
11239
|
+
* It is also why an item can name `packages/react-native-ui/src/...` directly rather
|
|
11239
11240
|
* than a copy under `registry/`: the library source is in that same immutable
|
|
11240
11241
|
* tree. So a source has two roots — `base`, the registry directory holding the
|
|
11241
11242
|
* index and the items, and `root`, the ref it sits in, which is what a file path
|
|
@@ -11246,13 +11247,13 @@ const DEFAULT_REGISTRY_URL = "https://raw.githubusercontent.com/delacournz/delac
|
|
|
11246
11247
|
* Replaced at build time with the git tag being published (see `tsdown.config.ts`).
|
|
11247
11248
|
* `main` in a working tree, where there is no tag yet.
|
|
11248
11249
|
*/
|
|
11249
|
-
const DEFAULT_REGISTRY_REF = "
|
|
11250
|
+
const DEFAULT_REGISTRY_REF = "8270767a831685e2008e0465214c3471f63e5187";
|
|
11250
11251
|
const RAW_GITHUB = "https://raw.githubusercontent.com";
|
|
11251
11252
|
const GITHUB_SHORTHAND = /^github:([^/#]+)\/([^/#]+)(?:#(.+))?$/;
|
|
11252
11253
|
/** `https://raw.githubusercontent.com/owner/repo` and nothing more. */
|
|
11253
11254
|
const BARE_RAW_REPO = new RegExp(`^${RAW_GITHUB}/([^/]+)/([^/]+)$`);
|
|
11254
11255
|
function resolveRegistrySource(options) {
|
|
11255
|
-
const ref = options.ref || "
|
|
11256
|
+
const ref = options.ref || "8270767a831685e2008e0465214c3471f63e5187";
|
|
11256
11257
|
const url = options.url?.trim();
|
|
11257
11258
|
if (!url) return remote(`${DEFAULT_REGISTRY_URL}/${ref}`);
|
|
11258
11259
|
const shorthand = GITHUB_SHORTHAND.exec(url);
|
|
@@ -11492,7 +11493,7 @@ var UnknownItemError = class extends Error {
|
|
|
11492
11493
|
item;
|
|
11493
11494
|
requiredBy;
|
|
11494
11495
|
constructor(item, requiredBy) {
|
|
11495
|
-
super(requiredBy ? `"${item}" is not in the registry, and is required by "${requiredBy}". The registry may be newer than this CLI — try \`--ref
|
|
11496
|
+
super(requiredBy ? `"${item}" is not in the registry, and is required by "${requiredBy}". The registry may be newer than this CLI — try \`--ref develop\`.` : `"${item}" is not in the registry. Run \`delacour list\` to see what is available.`);
|
|
11496
11497
|
this.item = item;
|
|
11497
11498
|
this.requiredBy = requiredBy;
|
|
11498
11499
|
this.name = "UnknownItemError";
|
|
@@ -11503,7 +11504,7 @@ var UnknownItemError = class extends Error {
|
|
|
11503
11504
|
* that imports it.
|
|
11504
11505
|
*
|
|
11505
11506
|
* `visiting` guards a cycle. The registry should not contain one —
|
|
11506
|
-
* `native-ui`'s own rules forbid the import shape that would create it — but a
|
|
11507
|
+
* `react-native-ui`'s own rules forbid the import shape that would create it — but a
|
|
11507
11508
|
* third-party registry can, and recursing forever is a worse failure than
|
|
11508
11509
|
* emitting the item once and moving on.
|
|
11509
11510
|
*/
|
|
@@ -11666,479 +11667,392 @@ const style = {
|
|
|
11666
11667
|
path: (value) => import_picocolors.default.dim(value)
|
|
11667
11668
|
};
|
|
11668
11669
|
//#endregion
|
|
11669
|
-
//#region src/
|
|
11670
|
-
|
|
11671
|
-
|
|
11672
|
-
|
|
11673
|
-
|
|
11674
|
-
|
|
11675
|
-
|
|
11676
|
-
|
|
11677
|
-
|
|
11678
|
-
|
|
11679
|
-
|
|
11680
|
-
|
|
11681
|
-
|
|
11682
|
-
|
|
11683
|
-
|
|
11684
|
-
|
|
11685
|
-
|
|
11686
|
-
|
|
11687
|
-
|
|
11688
|
-
|
|
11689
|
-
|
|
11690
|
-
|
|
11670
|
+
//#region src/project/css.ts
|
|
11671
|
+
/**
|
|
11672
|
+
* Wires the copied styles into the app's Tailwind entry.
|
|
11673
|
+
*
|
|
11674
|
+
* Two things have to happen and only one of them is obvious. The `@import`
|
|
11675
|
+
* pulls in the tokens and the theme. The `@source` lines are what make the
|
|
11676
|
+
* classes inside the copied components survive a production build: Tailwind
|
|
11677
|
+
* scans source text, and a class it never saw is a class it never compiled.
|
|
11678
|
+
*
|
|
11679
|
+
* The paths are computed from where the files actually landed, which resolves
|
|
11680
|
+
* the symlink trap on its own. In a monorepo the components live in a package
|
|
11681
|
+
* that Bun links into `node_modules`, and Tailwind's scanner does not follow
|
|
11682
|
+
* symlinks — a `@source` pointing at the linked copy silently contributes
|
|
11683
|
+
* nothing, and the components render unstyled in release and fine in dev. The
|
|
11684
|
+
* comment in `apps/playground/src/styles/global.css` is this bug, already paid
|
|
11685
|
+
* for once.
|
|
11686
|
+
*/
|
|
11687
|
+
const START = "/* delacour:start — managed by `delacour init`, edit outside this block */";
|
|
11688
|
+
const END = "/* delacour:end */";
|
|
11689
|
+
/**
|
|
11690
|
+
* The managed block: one import for the theme, one source glob per directory
|
|
11691
|
+
* holding copied code.
|
|
11692
|
+
*/
|
|
11693
|
+
function buildStylesBlock(context) {
|
|
11694
|
+
const from = dirname(context.cssPath);
|
|
11695
|
+
const lines = [
|
|
11696
|
+
START,
|
|
11697
|
+
`@import "${toSpecifier$1(from, `${context.directories.styles}/index.css`)}";`,
|
|
11698
|
+
""
|
|
11699
|
+
];
|
|
11700
|
+
const scanned = new Set(NAMESPACES.filter((namespace) => namespace !== "styles").map((namespace) => context.directories[namespace]));
|
|
11701
|
+
for (const directory of [...scanned].sort()) {
|
|
11702
|
+
if ([...scanned].some((other) => other !== directory && isInside(directory, other))) continue;
|
|
11703
|
+
lines.push(`@source "${toSpecifier$1(from, directory)}";`);
|
|
11691
11704
|
}
|
|
11692
|
-
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
11696
|
-
|
|
11697
|
-
|
|
11698
|
-
|
|
11699
|
-
|
|
11700
|
-
|
|
11701
|
-
|
|
11702
|
-
|
|
11703
|
-
|
|
11704
|
-
|
|
11705
|
-
|
|
11706
|
-
packageManager: project.packageManager,
|
|
11707
|
-
expoDependencies: collect$1(items, "expoDependencies"),
|
|
11708
|
-
dependencies: collect$1(items, "dependencies"),
|
|
11709
|
-
devDependencies: collect$1(items, "devDependencies")
|
|
11710
|
-
}, project.packageJson);
|
|
11711
|
-
reportDependencies(plan, output);
|
|
11712
|
-
const result = {
|
|
11713
|
-
items: items.map((item) => item.name),
|
|
11714
|
-
written: toWrite.length,
|
|
11715
|
-
dependencies: plan
|
|
11705
|
+
lines.push(END);
|
|
11706
|
+
return lines.join("\n");
|
|
11707
|
+
}
|
|
11708
|
+
/**
|
|
11709
|
+
* Writes the block into an existing entry, or creates one.
|
|
11710
|
+
*
|
|
11711
|
+
* Bounded by markers so a second `init` replaces the block rather than
|
|
11712
|
+
* appending a second copy, and so everything a developer adds around it is left
|
|
11713
|
+
* alone.
|
|
11714
|
+
*/
|
|
11715
|
+
function patchGlobalCss(existing, block) {
|
|
11716
|
+
if (existing === null) return {
|
|
11717
|
+
content: `${DEFAULT_ENTRY}\n${block}\n`,
|
|
11718
|
+
changed: true
|
|
11716
11719
|
};
|
|
11717
|
-
|
|
11718
|
-
|
|
11720
|
+
const start = existing.indexOf(START);
|
|
11721
|
+
const end = existing.indexOf(END);
|
|
11722
|
+
if (start !== -1 && end > start) {
|
|
11723
|
+
const content = `${existing.slice(0, start)}${block}${existing.slice(end + 18)}`;
|
|
11719
11724
|
return {
|
|
11720
|
-
|
|
11721
|
-
|
|
11725
|
+
content,
|
|
11726
|
+
changed: content !== existing
|
|
11722
11727
|
};
|
|
11723
11728
|
}
|
|
11724
|
-
for (const group of plan.groups) await output.task(`${group.label}: ${group.packages.join(", ")}`, () => runInstall(group, {
|
|
11725
|
-
cwd: appRoot,
|
|
11726
|
-
silent: output.silent
|
|
11727
|
-
}));
|
|
11728
|
-
warnAboutNativeRebuild(items, project, output);
|
|
11729
11729
|
return {
|
|
11730
|
-
|
|
11731
|
-
|
|
11730
|
+
content: `${existing}${existing.endsWith("\n") ? "" : "\n"}\n${block}\n`,
|
|
11731
|
+
changed: true
|
|
11732
11732
|
};
|
|
11733
11733
|
}
|
|
11734
|
+
const DEFAULT_ENTRY = `@import "tailwindcss";
|
|
11735
|
+
@import "uniwind";
|
|
11736
|
+
|
|
11737
|
+
@source "../**/*.{ts,tsx}";
|
|
11738
|
+
`;
|
|
11734
11739
|
/**
|
|
11735
|
-
*
|
|
11740
|
+
* The directories a Tailwind entry actually scans.
|
|
11736
11741
|
*
|
|
11737
|
-
*
|
|
11738
|
-
*
|
|
11739
|
-
*
|
|
11740
|
-
*
|
|
11742
|
+
* Read back rather than assumed, because this is the check that matters: a
|
|
11743
|
+
* `@source` that does not cover where the components landed produces a build
|
|
11744
|
+
* with no error and no styles. Only directory sources are returned — a glob
|
|
11745
|
+
* like `../**\/*.{ts,tsx}` is reduced to the directory it starts from, which is
|
|
11746
|
+
* what decides coverage.
|
|
11741
11747
|
*/
|
|
11742
|
-
|
|
11743
|
-
const
|
|
11744
|
-
const
|
|
11745
|
-
const
|
|
11746
|
-
|
|
11747
|
-
|
|
11748
|
-
|
|
11749
|
-
|
|
11750
|
-
|
|
11751
|
-
"",
|
|
11752
|
-
"Pass --overwrite to replace them, or run without --yes to be asked."
|
|
11753
|
-
].join("\n"));
|
|
11754
|
-
return null;
|
|
11755
|
-
}
|
|
11756
|
-
output.warn([`These files differ from the registry:`, ...conflicts.map((file) => ` ${style.path(file.displayPath)}`)].join("\n"));
|
|
11757
|
-
const overwrite = await output.confirm("Overwrite them?", false);
|
|
11758
|
-
if (!overwrite && fresh.length === 0) {
|
|
11759
|
-
output.info(`Nothing written. ${identical.length} file${identical.length === 1 ? " is" : "s are"} already current.`);
|
|
11760
|
-
return null;
|
|
11748
|
+
function parseSources(css, cssPath) {
|
|
11749
|
+
const from = dirname(cssPath);
|
|
11750
|
+
const sources = [];
|
|
11751
|
+
for (const match of css.matchAll(/@source\s+(?:not\s+)?["']([^"']+)["']/g)) {
|
|
11752
|
+
const value = match[1];
|
|
11753
|
+
if (value.startsWith("inline(")) continue;
|
|
11754
|
+
const wildcard = value.search(/[*?[]/);
|
|
11755
|
+
const directory = wildcard === -1 ? value : value.slice(0, wildcard);
|
|
11756
|
+
sources.push(resolve(from, directory));
|
|
11761
11757
|
}
|
|
11762
|
-
return
|
|
11758
|
+
return sources;
|
|
11763
11759
|
}
|
|
11764
|
-
|
|
11765
|
-
|
|
11766
|
-
|
|
11767
|
-
|
|
11768
|
-
|
|
11769
|
-
|
|
11760
|
+
/** Whether any source directory contains `directory`. */
|
|
11761
|
+
function isCovered(directory, sources) {
|
|
11762
|
+
return sources.some((source) => {
|
|
11763
|
+
const suffix = relative(source, directory);
|
|
11764
|
+
return suffix === "" || !suffix.startsWith("..");
|
|
11765
|
+
});
|
|
11766
|
+
}
|
|
11767
|
+
/** A path Tailwind can resolve from the entry file, always POSIX and always relative. */
|
|
11768
|
+
function toSpecifier$1(from, target) {
|
|
11769
|
+
const path = toPosix$3(relative(from, target));
|
|
11770
|
+
return path.startsWith(".") ? path : `./${path}`;
|
|
11771
|
+
}
|
|
11772
|
+
function isInside(directory, parent) {
|
|
11773
|
+
const suffix = relative(parent, directory);
|
|
11774
|
+
return suffix !== "" && !suffix.startsWith("..");
|
|
11775
|
+
}
|
|
11776
|
+
function toPosix$3(path) {
|
|
11777
|
+
return sep === "/" ? path : path.split(sep).join("/");
|
|
11770
11778
|
}
|
|
11779
|
+
//#endregion
|
|
11780
|
+
//#region src/project/css-entry.ts
|
|
11771
11781
|
/**
|
|
11772
|
-
*
|
|
11782
|
+
* Finds the Tailwind entry an app already has.
|
|
11773
11783
|
*
|
|
11774
|
-
*
|
|
11775
|
-
*
|
|
11776
|
-
*
|
|
11777
|
-
*
|
|
11784
|
+
* Creating a second one is the failure this exists to prevent. Metro compiles
|
|
11785
|
+
* the file its `cssEntryFile` names and no other; the app imports whichever
|
|
11786
|
+
* file its root layout imports. Write a new entry beside an existing one and
|
|
11787
|
+
* those become two different files — Tailwind compiles the one with the
|
|
11788
|
+
* `@source` globs, the app loads the one without them, and every component
|
|
11789
|
+
* renders unstyled with nothing logged.
|
|
11778
11790
|
*
|
|
11779
|
-
* The
|
|
11780
|
-
*
|
|
11781
|
-
*
|
|
11782
|
-
*
|
|
11783
|
-
* project is on.
|
|
11784
|
-
*/
|
|
11785
|
-
function reportDependencies(plan, output) {
|
|
11786
|
-
if (plan.wanted.length === 0) return;
|
|
11787
|
-
const lines = plan.groups.map((group) => ` ${style.code(commandLine(group))}`);
|
|
11788
|
-
if (plan.satisfied.length > 0) lines.push(` ${style.dim(`already installed — ${plan.satisfied.join(", ")}`)}`);
|
|
11789
|
-
output.info([plan.missing.length === 0 ? `Needs ${count(plan.wanted, "external package")}, all already here.` : `Needs ${count(plan.wanted, "external package")}, ${plan.missing.length} not here yet:`, ...lines].join("\n"));
|
|
11790
|
-
}
|
|
11791
|
-
/**
|
|
11792
|
-
* Whether to actually run the package manager.
|
|
11791
|
+
* The Metro config wins when it names one, because that is what actually
|
|
11792
|
+
* compiles — see `readUniwindPaths`. This is the fallback for a project that
|
|
11793
|
+
* has an entry but has not wired Metro to it yet, which is every app that
|
|
11794
|
+
* installed Uniwind and stopped there.
|
|
11793
11795
|
*
|
|
11794
|
-
*
|
|
11795
|
-
*
|
|
11796
|
-
*
|
|
11796
|
+
* Shallowest first: an app that ran an older version of this CLI has both
|
|
11797
|
+
* `src/global.css` and `src/styles/global.css`, and the one it imports is the
|
|
11798
|
+
* one it had first.
|
|
11797
11799
|
*/
|
|
11798
|
-
|
|
11799
|
-
|
|
11800
|
-
|
|
11801
|
-
|
|
11802
|
-
|
|
11800
|
+
const CANDIDATES$1 = [
|
|
11801
|
+
"global.css",
|
|
11802
|
+
"src/global.css",
|
|
11803
|
+
"app/global.css",
|
|
11804
|
+
"src/app/global.css",
|
|
11805
|
+
"styles/global.css",
|
|
11806
|
+
"src/styles/global.css",
|
|
11807
|
+
"src/styles/index.css"
|
|
11808
|
+
];
|
|
11809
|
+
/** `@import "tailwindcss"`, however it is quoted and whatever follows it. */
|
|
11810
|
+
const TAILWIND_IMPORT = /@import\s+["']tailwindcss["']/;
|
|
11811
|
+
function findTailwindEntry(appRoot) {
|
|
11812
|
+
for (const candidate of CANDIDATES$1) {
|
|
11813
|
+
const path = join(appRoot, candidate);
|
|
11814
|
+
if (!existsSync(path)) continue;
|
|
11815
|
+
try {
|
|
11816
|
+
if (TAILWIND_IMPORT.test(readFileSync(path, "utf-8"))) return path;
|
|
11817
|
+
} catch {}
|
|
11818
|
+
}
|
|
11819
|
+
return null;
|
|
11803
11820
|
}
|
|
11821
|
+
//#endregion
|
|
11822
|
+
//#region src/project/metro.ts
|
|
11804
11823
|
/**
|
|
11805
|
-
*
|
|
11806
|
-
*
|
|
11807
|
-
* A no-op when the components live in the app: there is no package boundary to
|
|
11808
|
-
* cross, so nothing needs exporting.
|
|
11824
|
+
* Wraps the app's Metro config with Uniwind's.
|
|
11809
11825
|
*
|
|
11810
|
-
*
|
|
11811
|
-
*
|
|
11812
|
-
*
|
|
11813
|
-
*
|
|
11826
|
+
* `withUniwindConfig` has to stay the outermost wrapper — it installs the
|
|
11827
|
+
* transformer that compiles `className` into styles, and a wrapper applied
|
|
11828
|
+
* after it can replace the `transformer` key and leave every component
|
|
11829
|
+
* unstyled with nothing logged. So the patch rewrites the export itself rather
|
|
11830
|
+
* than inserting a line somewhere in the middle.
|
|
11831
|
+
*
|
|
11832
|
+
* When the export is not in a shape this can safely rewrite, it says so and
|
|
11833
|
+
* prints what to write. Guessing at an unfamiliar config file earns nothing —
|
|
11834
|
+
* the failure it causes is a Metro error at bundle time in someone else's app.
|
|
11814
11835
|
*/
|
|
11815
|
-
|
|
11816
|
-
|
|
11817
|
-
|
|
11818
|
-
|
|
11819
|
-
|
|
11820
|
-
|
|
11836
|
+
/** Modules that must resolve to exactly one copy across a workspace. */
|
|
11837
|
+
const PINNED_MODULES = [
|
|
11838
|
+
"@shopify/react-native-skia",
|
|
11839
|
+
"react",
|
|
11840
|
+
"react-native",
|
|
11841
|
+
"react-native-gesture-handler",
|
|
11842
|
+
"react-native-keyboard-controller",
|
|
11843
|
+
"react-native-reanimated",
|
|
11844
|
+
"react-native-safe-area-context",
|
|
11845
|
+
"react-native-svg",
|
|
11846
|
+
"react-native-teleport",
|
|
11847
|
+
"react-native-worklets"
|
|
11848
|
+
];
|
|
11849
|
+
const REQUIRE = "const { withUniwindConfig } = require(\"uniwind/metro\");";
|
|
11850
|
+
const IMPORT = "import { withUniwindConfig } from \"uniwind/metro\";";
|
|
11851
|
+
/** `module.exports = config;` or `export default config;`, with nothing after it. */
|
|
11852
|
+
const COMMONJS_EXPORT = /module\.exports\s*=\s*([\s\S]+?);?\s*$/;
|
|
11853
|
+
const ESM_EXPORT = /export default\s+([\s\S]+?);?\s*$/;
|
|
11854
|
+
const CSS_ENTRY = /cssEntryFile\s*:\s*["'`]([^"'`]+)["'`]/;
|
|
11855
|
+
const DTS_FILE = /dtsFile\s*:\s*["'`]([^"'`]+)["'`]/;
|
|
11821
11856
|
/**
|
|
11822
|
-
*
|
|
11857
|
+
* Reads the paths a wrapped Metro config already names.
|
|
11823
11858
|
*
|
|
11824
|
-
*
|
|
11825
|
-
*
|
|
11826
|
-
*
|
|
11859
|
+
* A project that arrives with Uniwind set up — Expo's `with-router-uniwind`
|
|
11860
|
+
* example is the common one — has chosen its own CSS entry, and Metro compiles
|
|
11861
|
+
* **that file and no other**. Writing the `@source` block into the path this
|
|
11862
|
+
* CLI would have picked leaves Tailwind scanning a file with no globs in it, so
|
|
11863
|
+
* every class the components use is dropped and every one of them renders
|
|
11864
|
+
* unstyled. Nothing errors; the app just looks wrong.
|
|
11865
|
+
*
|
|
11866
|
+
* So the wired config wins. Returns nothing when the config is not wired, in
|
|
11867
|
+
* which case `init` is about to wrap it with paths of its own.
|
|
11827
11868
|
*/
|
|
11828
|
-
function
|
|
11829
|
-
if (
|
|
11830
|
-
|
|
11869
|
+
function readUniwindPaths(existing) {
|
|
11870
|
+
if (!existing?.includes("withUniwindConfig")) return {};
|
|
11871
|
+
return {
|
|
11872
|
+
css: CSS_ENTRY.exec(existing)?.[1],
|
|
11873
|
+
types: DTS_FILE.exec(existing)?.[1]
|
|
11874
|
+
};
|
|
11875
|
+
}
|
|
11876
|
+
function patchMetroConfig(existing, options) {
|
|
11877
|
+
const wrapper = optionsLiteral(options);
|
|
11878
|
+
const monorepo = options.workspaceRoot && options.workspaceRoot !== options.metroConfigPath ? monorepoResolverBlock(dirname(options.metroConfigPath), options.workspaceRoot) : "";
|
|
11879
|
+
if (existing === null) return {
|
|
11880
|
+
status: "created",
|
|
11881
|
+
content: template(wrapper, monorepo)
|
|
11882
|
+
};
|
|
11883
|
+
if (existing.includes("withUniwindConfig")) return { status: "already-wired" };
|
|
11884
|
+
const isEsm = /^\s*(import|export default)/m.test(existing);
|
|
11885
|
+
const match = (isEsm ? ESM_EXPORT : COMMONJS_EXPORT).exec(existing);
|
|
11886
|
+
if (!match?.[1]) return {
|
|
11887
|
+
status: "manual",
|
|
11888
|
+
snippet: manualSnippet(wrapper, isEsm)
|
|
11889
|
+
};
|
|
11890
|
+
const keyword = isEsm ? "export default" : "module.exports =";
|
|
11891
|
+
const head = existing.slice(0, match.index);
|
|
11892
|
+
const wrapped = `${keyword} withUniwindConfig(${match[1].trim()}, ${wrapper});\n`;
|
|
11893
|
+
const body = monorepo ? `${head}${monorepo}\n` : head;
|
|
11894
|
+
return {
|
|
11895
|
+
status: "patched",
|
|
11896
|
+
content: `${isEsm ? IMPORT : REQUIRE}\n${body}${wrapped}`
|
|
11897
|
+
};
|
|
11898
|
+
}
|
|
11899
|
+
function optionsLiteral(options) {
|
|
11900
|
+
const from = dirname(options.metroConfigPath);
|
|
11901
|
+
return `{\n\tcssEntryFile: "${toSpecifier(from, options.cssPath)}",\n\tdtsFile: "${toSpecifier(from, options.typesPath)}",\n}`;
|
|
11831
11902
|
}
|
|
11832
11903
|
/**
|
|
11833
|
-
*
|
|
11904
|
+
* The resolver settings an app needs to reach a package outside its own tree.
|
|
11834
11905
|
*
|
|
11835
|
-
*
|
|
11836
|
-
* and
|
|
11837
|
-
*
|
|
11838
|
-
*
|
|
11906
|
+
* Metro resolves by walking `node_modules` from the app downwards, so without
|
|
11907
|
+
* `watchFolders` and `nodeModulesPaths` it simply cannot see a sibling package —
|
|
11908
|
+
* the import fails at bundle time with a missing module, pointing at the app
|
|
11909
|
+
* rather than at the workspace.
|
|
11910
|
+
*
|
|
11911
|
+
* `extraNodeModules` is the other half, and it is about runtime rather than
|
|
11912
|
+
* resolution: a package manager can materialise a second copy of a native module
|
|
11913
|
+
* under the app, and two registrations of one native module break. This is the
|
|
11914
|
+
* block `apps/playground/metro.config.js` in this repository carries for exactly
|
|
11915
|
+
* this reason.
|
|
11839
11916
|
*/
|
|
11840
|
-
function
|
|
11841
|
-
const
|
|
11842
|
-
|
|
11843
|
-
|
|
11844
|
-
|
|
11845
|
-
|
|
11846
|
-
|
|
11847
|
-
|
|
11917
|
+
function monorepoResolverBlock(appRoot, workspaceRoot) {
|
|
11918
|
+
const pins = PINNED_MODULES.map((name) => `\t${JSON.stringify(name)}: path.resolve(workspaceRoot, "node_modules/${name}"),`).join("\n");
|
|
11919
|
+
return `const path = require("node:path");
|
|
11920
|
+
|
|
11921
|
+
const workspaceRoot = path.resolve(__dirname, "${toSpecifier(appRoot, workspaceRoot)}");
|
|
11922
|
+
|
|
11923
|
+
// The components live in a package outside this app, so Metro has to watch and
|
|
11924
|
+
// resolve beyond the app's own directory.
|
|
11925
|
+
config.watchFolders = [workspaceRoot];
|
|
11926
|
+
config.resolver.nodeModulesPaths = [
|
|
11927
|
+
\tpath.resolve(__dirname, "node_modules"),
|
|
11928
|
+
\tpath.resolve(workspaceRoot, "node_modules"),
|
|
11929
|
+
];
|
|
11930
|
+
config.resolver.disableHierarchicalLookup = true;
|
|
11931
|
+
|
|
11932
|
+
// One copy of each native module for the whole bundle: two registrations of a
|
|
11933
|
+
// native module break at runtime.
|
|
11934
|
+
config.resolver.extraNodeModules = {
|
|
11935
|
+
${pins}
|
|
11936
|
+
};
|
|
11937
|
+
`;
|
|
11848
11938
|
}
|
|
11849
|
-
function
|
|
11850
|
-
return
|
|
11939
|
+
function template(wrapper, monorepo) {
|
|
11940
|
+
return `const { getDefaultConfig } = require("expo/metro-config");
|
|
11941
|
+
${REQUIRE}
|
|
11942
|
+
|
|
11943
|
+
const config = getDefaultConfig(__dirname);
|
|
11944
|
+
${monorepo ? `\n${monorepo}` : ""}
|
|
11945
|
+
// withUniwindConfig must stay the outermost wrapper.
|
|
11946
|
+
module.exports = withUniwindConfig(config, ${wrapper});
|
|
11947
|
+
`;
|
|
11851
11948
|
}
|
|
11852
|
-
function
|
|
11853
|
-
return
|
|
11949
|
+
function manualSnippet(wrapper, isEsm) {
|
|
11950
|
+
return `${isEsm ? IMPORT : REQUIRE}\n\n// Keep this the outermost wrapper.\n${isEsm ? "export default" : "module.exports ="} withUniwindConfig(config, ${wrapper});`;
|
|
11854
11951
|
}
|
|
11855
|
-
|
|
11856
|
-
|
|
11857
|
-
|
|
11858
|
-
const configPath = findConfig(options.cwd);
|
|
11859
|
-
const config = configPath ? await readConfig(configPath) : null;
|
|
11860
|
-
return createRegistryClient({
|
|
11861
|
-
cwd: options.cwd,
|
|
11862
|
-
url: options.registry ?? config?.registry.url,
|
|
11863
|
-
ref: options.ref ?? config?.registry.ref,
|
|
11864
|
-
offline: options.offline
|
|
11865
|
-
});
|
|
11952
|
+
function toSpecifier(from, target) {
|
|
11953
|
+
const path = toPosix$2(relative(from, target));
|
|
11954
|
+
return path.startsWith(".") ? path : `./${path}`;
|
|
11866
11955
|
}
|
|
11867
|
-
|
|
11868
|
-
|
|
11869
|
-
const index = await (await openRegistry(options)).getIndex();
|
|
11870
|
-
if (options.json) {
|
|
11871
|
-
process.stdout.write(`${JSON.stringify(index.items, null, 2)}\n`);
|
|
11872
|
-
return;
|
|
11873
|
-
}
|
|
11874
|
-
printGroups(index.items, output);
|
|
11956
|
+
function toPosix$2(path) {
|
|
11957
|
+
return sep === "/" ? path : path.split(sep).join("/");
|
|
11875
11958
|
}
|
|
11876
|
-
|
|
11877
|
-
|
|
11878
|
-
|
|
11879
|
-
|
|
11880
|
-
|
|
11881
|
-
|
|
11882
|
-
|
|
11883
|
-
|
|
11884
|
-
|
|
11885
|
-
|
|
11886
|
-
|
|
11887
|
-
|
|
11888
|
-
|
|
11889
|
-
|
|
11890
|
-
|
|
11891
|
-
|
|
11892
|
-
|
|
11959
|
+
//#endregion
|
|
11960
|
+
//#region src/project/root-layout.ts
|
|
11961
|
+
/**
|
|
11962
|
+
* Router layouts first: an app holding both is an Expo Router app whose
|
|
11963
|
+
* `App.tsx` is left over, and the layout is the file that actually renders.
|
|
11964
|
+
*/
|
|
11965
|
+
const CANDIDATES = [
|
|
11966
|
+
{
|
|
11967
|
+
path: "src/app/_layout.tsx",
|
|
11968
|
+
router: true
|
|
11969
|
+
},
|
|
11970
|
+
{
|
|
11971
|
+
path: "app/_layout.tsx",
|
|
11972
|
+
router: true
|
|
11973
|
+
},
|
|
11974
|
+
{
|
|
11975
|
+
path: "src/app/_layout.jsx",
|
|
11976
|
+
router: true
|
|
11977
|
+
},
|
|
11978
|
+
{
|
|
11979
|
+
path: "app/_layout.jsx",
|
|
11980
|
+
router: true
|
|
11981
|
+
},
|
|
11982
|
+
{
|
|
11983
|
+
path: "App.tsx",
|
|
11984
|
+
router: false
|
|
11985
|
+
},
|
|
11986
|
+
{
|
|
11987
|
+
path: "src/App.tsx",
|
|
11988
|
+
router: false
|
|
11989
|
+
},
|
|
11990
|
+
{
|
|
11991
|
+
path: "App.jsx",
|
|
11992
|
+
router: false
|
|
11993
|
+
},
|
|
11994
|
+
{
|
|
11995
|
+
path: "index.tsx",
|
|
11996
|
+
router: false
|
|
11893
11997
|
}
|
|
11894
|
-
|
|
11998
|
+
];
|
|
11999
|
+
function findRootLayout(appRoot) {
|
|
12000
|
+
return CANDIDATES.find((candidate) => existsSync(join(appRoot, candidate.path))) ?? null;
|
|
11895
12001
|
}
|
|
11896
12002
|
/**
|
|
11897
|
-
*
|
|
12003
|
+
* The root layout, whole, ready to paste.
|
|
11898
12004
|
*
|
|
11899
|
-
* The
|
|
11900
|
-
*
|
|
11901
|
-
*
|
|
11902
|
-
*
|
|
11903
|
-
*
|
|
11904
|
-
*
|
|
11905
|
-
*
|
|
12005
|
+
* The CSS import is the first line because that is the rule it exists to
|
|
12006
|
+
* teach — anywhere else and every component renders unstyled with nothing
|
|
12007
|
+
* logged.
|
|
12008
|
+
*
|
|
12009
|
+
* `<Slot />` is Expo Router's minimal root. A layout already rendering a
|
|
12010
|
+
* `<Stack>` keeps it; the provider goes around whatever is there, which is
|
|
12011
|
+
* what the line printed beside this says.
|
|
11906
12012
|
*/
|
|
11907
|
-
|
|
11908
|
-
const
|
|
11909
|
-
|
|
11910
|
-
|
|
11911
|
-
|
|
11912
|
-
process.stdout.write(`${JSON.stringify(await client.loadItem(item), null, 2)}\n`);
|
|
11913
|
-
return;
|
|
11914
|
-
}
|
|
11915
|
-
const index = await client.getIndex();
|
|
11916
|
-
const byName = new Map(index.items.map((entry) => [entry.name, entry]));
|
|
11917
|
-
const order = resolveItemGraph([name], (candidate) => byName.get(candidate));
|
|
11918
|
-
const closure = order.filter((candidate) => candidate !== name);
|
|
11919
|
-
const resolved = order.flatMap((candidate) => byName.get(candidate) ?? []);
|
|
11920
|
-
const configPath = findConfig(options.cwd);
|
|
11921
|
-
const project = await detectProject((configPath ? await readConfig(configPath) : null)?.app.resolved.root ?? options.cwd);
|
|
11922
|
-
const union = (key) => [...new Set(resolved.flatMap((entry) => entry[key]))].sort();
|
|
11923
|
-
const commands = installCommands({
|
|
11924
|
-
packageManager: project.packageManager,
|
|
11925
|
-
expoDependencies: union("expoDependencies"),
|
|
11926
|
-
dependencies: union("dependencies"),
|
|
11927
|
-
devDependencies: union("devDependencies")
|
|
11928
|
-
});
|
|
11929
|
-
const lines = [
|
|
11930
|
-
`${style.bold(item.title)} ${style.dim(item.name)}`,
|
|
11931
|
-
item.description,
|
|
12013
|
+
function renderRootLayout(layout, specifiers) {
|
|
12014
|
+
const { css, provider } = specifiers;
|
|
12015
|
+
if (!layout.router) return [
|
|
12016
|
+
`import "${css}";`,
|
|
12017
|
+
`import { DelacourProvider } from "${provider}";`,
|
|
11932
12018
|
"",
|
|
11933
|
-
|
|
11934
|
-
|
|
11935
|
-
|
|
11936
|
-
|
|
11937
|
-
|
|
11938
|
-
|
|
11939
|
-
|
|
11940
|
-
|
|
11941
|
-
|
|
11942
|
-
|
|
11943
|
-
|
|
11944
|
-
|
|
11945
|
-
const report = {
|
|
11946
|
-
config: configPath ?? null,
|
|
11947
|
-
registry: client.source,
|
|
11948
|
-
project: {
|
|
11949
|
-
packageManager: project.packageManager,
|
|
11950
|
-
expo: project.expoVersion,
|
|
11951
|
-
reactNative: project.reactNativeVersion,
|
|
11952
|
-
uniwind: project.hasUniwind,
|
|
11953
|
-
tailwind: project.hasTailwind,
|
|
11954
|
-
workspaceRoot: project.workspaceRoot,
|
|
11955
|
-
appRoot: project.appRoot,
|
|
11956
|
-
aliases: project.pathMappings.map((mapping) => `${mapping.prefix}* → ${mapping.directory}`)
|
|
11957
|
-
},
|
|
11958
|
-
paths: config?.directories ?? null
|
|
11959
|
-
};
|
|
11960
|
-
if (options.json) {
|
|
11961
|
-
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
11962
|
-
return;
|
|
11963
|
-
}
|
|
11964
|
-
output.log(JSON.stringify(report, null, 2));
|
|
11965
|
-
}
|
|
11966
|
-
function printGroups(items, output) {
|
|
11967
|
-
if (output.silent) return;
|
|
11968
|
-
const components = items.filter((item) => item.type === "registry:ui");
|
|
11969
|
-
const rest = items.filter((item) => item.type !== "registry:ui");
|
|
11970
|
-
const width = Math.max(...items.map((item) => item.name.length));
|
|
11971
|
-
const render = (entry) => ` ${style.cyan(entry.name.padEnd(width))} ${style.dim(entry.description)}`;
|
|
11972
|
-
if (components.length > 0) log.message([style.bold("Components"), ...components.map(render)].join("\n"));
|
|
11973
|
-
if (rest.length > 0) log.message([
|
|
11974
|
-
style.bold("Utilities"),
|
|
11975
|
-
...rest.map(render),
|
|
12019
|
+
"export default function App() {",
|
|
12020
|
+
" return (",
|
|
12021
|
+
" <DelacourProvider>",
|
|
12022
|
+
" <YourApp />",
|
|
12023
|
+
" </DelacourProvider>",
|
|
12024
|
+
" );",
|
|
12025
|
+
"}"
|
|
12026
|
+
].join("\n");
|
|
12027
|
+
return [
|
|
12028
|
+
`import "${css}";`,
|
|
12029
|
+
`import { DelacourProvider } from "${provider}";`,
|
|
12030
|
+
"import { Slot } from \"expo-router\";",
|
|
11976
12031
|
"",
|
|
11977
|
-
|
|
11978
|
-
|
|
11979
|
-
|
|
11980
|
-
|
|
11981
|
-
|
|
11982
|
-
|
|
11983
|
-
|
|
11984
|
-
|
|
11985
|
-
const table = lcsTable(a, b);
|
|
11986
|
-
const lines = [];
|
|
11987
|
-
let i = 0;
|
|
11988
|
-
let j = 0;
|
|
11989
|
-
while (i < a.length && j < b.length) if (a[i] === b[j]) {
|
|
11990
|
-
lines.push({
|
|
11991
|
-
kind: "context",
|
|
11992
|
-
text: a[i]
|
|
11993
|
-
});
|
|
11994
|
-
i += 1;
|
|
11995
|
-
j += 1;
|
|
11996
|
-
} else if ((table[i + 1]?.[j] ?? 0) >= (table[i]?.[j + 1] ?? 0)) {
|
|
11997
|
-
lines.push({
|
|
11998
|
-
kind: "removed",
|
|
11999
|
-
text: a[i]
|
|
12000
|
-
});
|
|
12001
|
-
i += 1;
|
|
12002
|
-
} else {
|
|
12003
|
-
lines.push({
|
|
12004
|
-
kind: "added",
|
|
12005
|
-
text: b[j]
|
|
12006
|
-
});
|
|
12007
|
-
j += 1;
|
|
12008
|
-
}
|
|
12009
|
-
while (i < a.length) lines.push({
|
|
12010
|
-
kind: "removed",
|
|
12011
|
-
text: a[i++]
|
|
12012
|
-
});
|
|
12013
|
-
while (j < b.length) lines.push({
|
|
12014
|
-
kind: "added",
|
|
12015
|
-
text: b[j++]
|
|
12016
|
-
});
|
|
12017
|
-
return lines;
|
|
12018
|
-
}
|
|
12019
|
-
/**
|
|
12020
|
-
* Groups changes into hunks with surrounding context, dropping the long runs of
|
|
12021
|
-
* untouched code between them.
|
|
12022
|
-
*/
|
|
12023
|
-
function toHunks(lines, context = 3) {
|
|
12024
|
-
const changed = lines.map((line) => line.kind !== "context");
|
|
12025
|
-
const keep = lines.map((_, index) => changed.slice(Math.max(0, index - context), index + context + 1).some(Boolean));
|
|
12026
|
-
const hunks = [];
|
|
12027
|
-
let before = 1;
|
|
12028
|
-
let after = 1;
|
|
12029
|
-
let current = null;
|
|
12030
|
-
lines.forEach((line, index) => {
|
|
12031
|
-
if (keep[index]) {
|
|
12032
|
-
current ??= {
|
|
12033
|
-
before,
|
|
12034
|
-
after,
|
|
12035
|
-
lines: []
|
|
12036
|
-
};
|
|
12037
|
-
current.lines.push(line);
|
|
12038
|
-
} else if (current) {
|
|
12039
|
-
hunks.push(current);
|
|
12040
|
-
current = null;
|
|
12041
|
-
}
|
|
12042
|
-
if (line.kind !== "added") before += 1;
|
|
12043
|
-
if (line.kind !== "removed") after += 1;
|
|
12044
|
-
});
|
|
12045
|
-
if (current) hunks.push(current);
|
|
12046
|
-
return hunks;
|
|
12047
|
-
}
|
|
12048
|
-
function hasChanges(lines) {
|
|
12049
|
-
return lines.some((line) => line.kind !== "context");
|
|
12050
|
-
}
|
|
12051
|
-
function lcsTable(a, b) {
|
|
12052
|
-
const table = Array.from({ length: a.length + 1 }, () => new Array(b.length + 1).fill(0));
|
|
12053
|
-
for (let i = a.length - 1; i >= 0; i -= 1) for (let j = b.length - 1; j >= 0; j -= 1) {
|
|
12054
|
-
const row = table[i];
|
|
12055
|
-
row[j] = a[i] === b[j] ? (table[i + 1]?.[j + 1] ?? 0) + 1 : Math.max(table[i + 1]?.[j] ?? 0, row[j + 1] ?? 0);
|
|
12056
|
-
}
|
|
12057
|
-
return table;
|
|
12032
|
+
"export default function RootLayout() {",
|
|
12033
|
+
" return (",
|
|
12034
|
+
" <DelacourProvider>",
|
|
12035
|
+
" <Slot />",
|
|
12036
|
+
" </DelacourProvider>",
|
|
12037
|
+
" );",
|
|
12038
|
+
"}"
|
|
12039
|
+
].join("\n");
|
|
12058
12040
|
}
|
|
12059
12041
|
//#endregion
|
|
12060
|
-
//#region src/
|
|
12061
|
-
async function diff(name, options) {
|
|
12062
|
-
const output = createOutput(options);
|
|
12063
|
-
const config = await loadConfig(options.cwd);
|
|
12064
|
-
const client = createRegistryClient({
|
|
12065
|
-
cwd: options.cwd,
|
|
12066
|
-
url: options.registry ?? config.registry.url,
|
|
12067
|
-
ref: options.ref ?? config.registry.ref,
|
|
12068
|
-
offline: options.offline
|
|
12069
|
-
});
|
|
12070
|
-
const index = await client.getIndex();
|
|
12071
|
-
const candidates = name ? [name] : await installedItems(index.items, config);
|
|
12072
|
-
if (candidates.length === 0) {
|
|
12073
|
-
output.info("No components from the registry are in this project yet.");
|
|
12074
|
-
return;
|
|
12075
|
-
}
|
|
12076
|
-
let changed = 0;
|
|
12077
|
-
for (const candidate of candidates) {
|
|
12078
|
-
const item = await client.loadItem(await client.getItem(candidate));
|
|
12079
|
-
changed += await reportItem(item, config, output);
|
|
12080
|
-
}
|
|
12081
|
-
if (changed === 0) {
|
|
12082
|
-
output.success("Everything matches the registry.");
|
|
12083
|
-
return;
|
|
12084
|
-
}
|
|
12085
|
-
const command = [
|
|
12086
|
-
"delacour add",
|
|
12087
|
-
name,
|
|
12088
|
-
"--overwrite"
|
|
12089
|
-
].filter(Boolean).join(" ");
|
|
12090
|
-
output.info(`${changed} file${changed === 1 ? " differs" : "s differ"}. ${style.code(command)} takes the registry's copy.`);
|
|
12091
|
-
}
|
|
12092
|
-
async function reportItem(item, config, output) {
|
|
12093
|
-
const planned = await planFiles([item], config);
|
|
12094
|
-
let changed = 0;
|
|
12095
|
-
for (const file of planned) {
|
|
12096
|
-
if (file.current === null || file.unchanged) continue;
|
|
12097
|
-
const lines = diffLines(file.current, file.content);
|
|
12098
|
-
if (!hasChanges(lines)) continue;
|
|
12099
|
-
changed += 1;
|
|
12100
|
-
if (output.silent) continue;
|
|
12101
|
-
const body = toHunks(lines).flatMap((hunk) => [style.dim(`@@ -${hunk.before} +${hunk.after} @@`), ...hunk.lines.map(render$2)]);
|
|
12102
|
-
log.message([`${style.bold(item.name)} ${style.path(file.displayPath)}`, ...body].join("\n"));
|
|
12103
|
-
}
|
|
12104
|
-
return changed;
|
|
12105
|
-
}
|
|
12106
|
-
function render$2(line) {
|
|
12107
|
-
if (line.kind === "added") return style.green(`+ ${line.text}`);
|
|
12108
|
-
if (line.kind === "removed") return style.red(`- ${line.text}`);
|
|
12109
|
-
return style.dim(` ${line.text}`);
|
|
12110
|
-
}
|
|
12042
|
+
//#region src/project/uniwind-env.ts
|
|
12111
12043
|
/**
|
|
12112
|
-
*
|
|
12044
|
+
* The one line that makes `className` a real prop in TypeScript.
|
|
12113
12045
|
*
|
|
12114
|
-
*
|
|
12115
|
-
*
|
|
12116
|
-
*
|
|
12046
|
+
* Uniwind augments React Native's types through a global `/// <reference>`, and
|
|
12047
|
+
* a declaration file is only loaded if it is part of the program — either
|
|
12048
|
+
* matched by `tsconfig`'s `include` or reachable by import. This file is neither
|
|
12049
|
+
* importable nor, in a shared package, inside the app's `include`, which is why
|
|
12050
|
+
* the app needs a copy of its own.
|
|
12117
12051
|
*
|
|
12118
|
-
*
|
|
12119
|
-
* `<namespace>/<target>`, which is everything needed to test for one on disk —
|
|
12120
|
-
* so a bare `delacour diff` fetches one document and then only the items it
|
|
12121
|
-
* found, rather than the whole registry to discover the same thing.
|
|
12052
|
+
* Kept here rather than inlined so `init` and `doctor` agree on the contents.
|
|
12122
12053
|
*/
|
|
12123
|
-
|
|
12124
|
-
|
|
12125
|
-
for (const entry of entries) {
|
|
12126
|
-
const paths = entry.files.map((file) => destination(file, config)).filter((path) => path !== null);
|
|
12127
|
-
if ((await Promise.all(paths.map(exists))).some(Boolean)) present.push(entry.name);
|
|
12128
|
-
}
|
|
12129
|
-
return present;
|
|
12130
|
-
}
|
|
12131
|
-
/** `"ui/button/button.tsx"` → where that file would land, or `null` for an unknown namespace. */
|
|
12132
|
-
function destination(file, config) {
|
|
12133
|
-
const slash = file.indexOf("/");
|
|
12134
|
-
if (slash === -1) return null;
|
|
12135
|
-
const namespace = file.slice(0, slash);
|
|
12136
|
-
if (!isNamespace(namespace)) return null;
|
|
12137
|
-
return join(config.directories[namespace], file.slice(slash + 1));
|
|
12138
|
-
}
|
|
12139
|
-
async function exists(path) {
|
|
12140
|
-
return access(path).then(() => true, () => false);
|
|
12141
|
-
}
|
|
12054
|
+
const UNIWIND_ENV_FILENAME = "uniwind-env.d.ts";
|
|
12055
|
+
const UNIWIND_ENV_REFERENCE = "/// <reference types=\"uniwind/types\" />";
|
|
12142
12056
|
//#endregion
|
|
12143
12057
|
//#region ../design-system/src/styles.ts
|
|
12144
12058
|
/**
|
|
@@ -12177,7 +12091,10 @@ function geometry({ radius, heights, text, icons, navbar, gutter, buttonRadius }
|
|
|
12177
12091
|
"spacing-screen-gutter": gutter,
|
|
12178
12092
|
"spacing-chart-sm": chartHeight(LIBRARY_CHART[0], heights[1]),
|
|
12179
12093
|
"spacing-chart-md": chartHeight(LIBRARY_CHART[1], heights[1]),
|
|
12180
|
-
"spacing-chart-lg": chartHeight(LIBRARY_CHART[2], heights[1])
|
|
12094
|
+
"spacing-chart-lg": chartHeight(LIBRARY_CHART[2], heights[1]),
|
|
12095
|
+
"spacing-fab-sm": LIBRARY_FAB[0],
|
|
12096
|
+
"spacing-fab-md": LIBRARY_FAB[1],
|
|
12097
|
+
"spacing-fab-lg": LIBRARY_FAB[2]
|
|
12181
12098
|
};
|
|
12182
12099
|
}
|
|
12183
12100
|
const LIBRARY_HEIGHTS = [
|
|
@@ -12209,6 +12126,17 @@ const LIBRARY_CHART = [
|
|
|
12209
12126
|
280
|
|
12210
12127
|
];
|
|
12211
12128
|
/**
|
|
12129
|
+
* A floating action button's footprint, the same under every style. It floats
|
|
12130
|
+
* over content rather than sitting in a row of controls, so a denser style's
|
|
12131
|
+
* shorter buttons are no reason to shrink the one target above the list — and
|
|
12132
|
+
* 44 is the floor a touch target cannot go under.
|
|
12133
|
+
*/
|
|
12134
|
+
const LIBRARY_FAB = [
|
|
12135
|
+
44,
|
|
12136
|
+
56,
|
|
12137
|
+
64
|
|
12138
|
+
];
|
|
12139
|
+
/**
|
|
12212
12140
|
* A chart's height, scaled to a style's control density.
|
|
12213
12141
|
*
|
|
12214
12142
|
* A plot is a region rather than a control, so none of the axes a style
|
|
@@ -12433,7 +12361,10 @@ const GEOMETRY_NAMES = new Set([
|
|
|
12433
12361
|
"spacing-screen-gutter",
|
|
12434
12362
|
"spacing-chart-sm",
|
|
12435
12363
|
"spacing-chart-md",
|
|
12436
|
-
"spacing-chart-lg"
|
|
12364
|
+
"spacing-chart-lg",
|
|
12365
|
+
"spacing-fab-sm",
|
|
12366
|
+
"spacing-fab-md",
|
|
12367
|
+
"spacing-fab-lg"
|
|
12437
12368
|
].map((token) => `--${token}`));
|
|
12438
12369
|
/** Steps of the corner scale `tokens.css` derives from `--radius` on its own. */
|
|
12439
12370
|
const DERIVED_RADIUS = /^--radius-(xs|sm|md|lg|xl|2xl|3xl|4xl|full)$/;
|
|
@@ -12710,7 +12641,7 @@ function convertTheme(source) {
|
|
|
12710
12641
|
const dangling = undeclared(light);
|
|
12711
12642
|
if (dangling.length > 0) warnings.push(`${dangling.join(", ")} referenced but not declared — the tokens built on them resolve to nothing. Add them to the source theme.`);
|
|
12712
12643
|
return {
|
|
12713
|
-
css: render$
|
|
12644
|
+
css: render$2({
|
|
12714
12645
|
light,
|
|
12715
12646
|
dark,
|
|
12716
12647
|
fonts,
|
|
@@ -12772,7 +12703,7 @@ function takeFonts(source, warnings) {
|
|
|
12772
12703
|
function isColor(value) {
|
|
12773
12704
|
return /^(#|rgb|hsl|hwb|lab|lch|oklab|oklch|color-mix|color\()/i.test(value.trim()) || value.trim() === "transparent";
|
|
12774
12705
|
}
|
|
12775
|
-
function render$
|
|
12706
|
+
function render$2(theme) {
|
|
12776
12707
|
const names = orderNames(Object.keys(theme.light));
|
|
12777
12708
|
const declarations = (values, indent) => names.map((name) => `${indent}${name}: ${values[name]};`).join("\n");
|
|
12778
12709
|
const aliases = names.map((name) => {
|
|
@@ -12901,17 +12832,17 @@ function topLevelDeclarations(body) {
|
|
|
12901
12832
|
for (const character of body) {
|
|
12902
12833
|
if (character === "{") depth += 1;
|
|
12903
12834
|
else if (character === "}") depth = Math.max(0, depth - 1);
|
|
12904
|
-
else if (character === ";" && depth === 0) collect(buffer, declarations);
|
|
12835
|
+
else if (character === ";" && depth === 0) collect$1(buffer, declarations);
|
|
12905
12836
|
else {
|
|
12906
12837
|
buffer += character;
|
|
12907
12838
|
continue;
|
|
12908
12839
|
}
|
|
12909
12840
|
buffer = "";
|
|
12910
12841
|
}
|
|
12911
|
-
collect(buffer, declarations);
|
|
12842
|
+
collect$1(buffer, declarations);
|
|
12912
12843
|
return declarations;
|
|
12913
12844
|
}
|
|
12914
|
-
function collect(buffer, into) {
|
|
12845
|
+
function collect$1(buffer, into) {
|
|
12915
12846
|
const declaration = buffer.trim();
|
|
12916
12847
|
if (!declaration.startsWith("--")) return;
|
|
12917
12848
|
const separator = declaration.indexOf(":");
|
|
@@ -12922,213 +12853,6 @@ function escapeRegExp(value) {
|
|
|
12922
12853
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
12923
12854
|
}
|
|
12924
12855
|
//#endregion
|
|
12925
|
-
//#region src/project/css.ts
|
|
12926
|
-
/**
|
|
12927
|
-
* Wires the copied styles into the app's Tailwind entry.
|
|
12928
|
-
*
|
|
12929
|
-
* Two things have to happen and only one of them is obvious. The `@import`
|
|
12930
|
-
* pulls in the tokens and the theme. The `@source` lines are what make the
|
|
12931
|
-
* classes inside the copied components survive a production build: Tailwind
|
|
12932
|
-
* scans source text, and a class it never saw is a class it never compiled.
|
|
12933
|
-
*
|
|
12934
|
-
* The paths are computed from where the files actually landed, which resolves
|
|
12935
|
-
* the symlink trap on its own. In a monorepo the components live in a package
|
|
12936
|
-
* that Bun links into `node_modules`, and Tailwind's scanner does not follow
|
|
12937
|
-
* symlinks — a `@source` pointing at the linked copy silently contributes
|
|
12938
|
-
* nothing, and the components render unstyled in release and fine in dev. The
|
|
12939
|
-
* comment in `apps/playground/src/styles/global.css` is this bug, already paid
|
|
12940
|
-
* for once.
|
|
12941
|
-
*/
|
|
12942
|
-
const START = "/* delacour:start — managed by `delacour init`, edit outside this block */";
|
|
12943
|
-
const END = "/* delacour:end */";
|
|
12944
|
-
/**
|
|
12945
|
-
* The managed block: one import for the theme, one source glob per directory
|
|
12946
|
-
* holding copied code.
|
|
12947
|
-
*/
|
|
12948
|
-
function buildStylesBlock(context) {
|
|
12949
|
-
const from = dirname(context.cssPath);
|
|
12950
|
-
const lines = [
|
|
12951
|
-
START,
|
|
12952
|
-
`@import "${toSpecifier$1(from, `${context.directories.styles}/index.css`)}";`,
|
|
12953
|
-
""
|
|
12954
|
-
];
|
|
12955
|
-
const scanned = new Set(NAMESPACES.filter((namespace) => namespace !== "styles").map((namespace) => context.directories[namespace]));
|
|
12956
|
-
for (const directory of [...scanned].sort()) {
|
|
12957
|
-
if ([...scanned].some((other) => other !== directory && isInside(directory, other))) continue;
|
|
12958
|
-
lines.push(`@source "${toSpecifier$1(from, directory)}";`);
|
|
12959
|
-
}
|
|
12960
|
-
lines.push(END);
|
|
12961
|
-
return lines.join("\n");
|
|
12962
|
-
}
|
|
12963
|
-
/**
|
|
12964
|
-
* Writes the block into an existing entry, or creates one.
|
|
12965
|
-
*
|
|
12966
|
-
* Bounded by markers so a second `init` replaces the block rather than
|
|
12967
|
-
* appending a second copy, and so everything a developer adds around it is left
|
|
12968
|
-
* alone.
|
|
12969
|
-
*/
|
|
12970
|
-
function patchGlobalCss(existing, block) {
|
|
12971
|
-
if (existing === null) return {
|
|
12972
|
-
content: `${DEFAULT_ENTRY}\n${block}\n`,
|
|
12973
|
-
changed: true
|
|
12974
|
-
};
|
|
12975
|
-
const start = existing.indexOf(START);
|
|
12976
|
-
const end = existing.indexOf(END);
|
|
12977
|
-
if (start !== -1 && end > start) {
|
|
12978
|
-
const content = `${existing.slice(0, start)}${block}${existing.slice(end + 18)}`;
|
|
12979
|
-
return {
|
|
12980
|
-
content,
|
|
12981
|
-
changed: content !== existing
|
|
12982
|
-
};
|
|
12983
|
-
}
|
|
12984
|
-
return {
|
|
12985
|
-
content: `${existing}${existing.endsWith("\n") ? "" : "\n"}\n${block}\n`,
|
|
12986
|
-
changed: true
|
|
12987
|
-
};
|
|
12988
|
-
}
|
|
12989
|
-
const DEFAULT_ENTRY = `@import "tailwindcss";
|
|
12990
|
-
@import "uniwind";
|
|
12991
|
-
|
|
12992
|
-
@source "../**/*.{ts,tsx}";
|
|
12993
|
-
`;
|
|
12994
|
-
/**
|
|
12995
|
-
* The directories a Tailwind entry actually scans.
|
|
12996
|
-
*
|
|
12997
|
-
* Read back rather than assumed, because this is the check that matters: a
|
|
12998
|
-
* `@source` that does not cover where the components landed produces a build
|
|
12999
|
-
* with no error and no styles. Only directory sources are returned — a glob
|
|
13000
|
-
* like `../**\/*.{ts,tsx}` is reduced to the directory it starts from, which is
|
|
13001
|
-
* what decides coverage.
|
|
13002
|
-
*/
|
|
13003
|
-
function parseSources(css, cssPath) {
|
|
13004
|
-
const from = dirname(cssPath);
|
|
13005
|
-
const sources = [];
|
|
13006
|
-
for (const match of css.matchAll(/@source\s+(?:not\s+)?["']([^"']+)["']/g)) {
|
|
13007
|
-
const value = match[1];
|
|
13008
|
-
if (value.startsWith("inline(")) continue;
|
|
13009
|
-
const wildcard = value.search(/[*?[]/);
|
|
13010
|
-
const directory = wildcard === -1 ? value : value.slice(0, wildcard);
|
|
13011
|
-
sources.push(resolve(from, directory));
|
|
13012
|
-
}
|
|
13013
|
-
return sources;
|
|
13014
|
-
}
|
|
13015
|
-
/** Whether any source directory contains `directory`. */
|
|
13016
|
-
function isCovered(directory, sources) {
|
|
13017
|
-
return sources.some((source) => {
|
|
13018
|
-
const suffix = relative(source, directory);
|
|
13019
|
-
return suffix === "" || !suffix.startsWith("..");
|
|
13020
|
-
});
|
|
13021
|
-
}
|
|
13022
|
-
/** A path Tailwind can resolve from the entry file, always POSIX and always relative. */
|
|
13023
|
-
function toSpecifier$1(from, target) {
|
|
13024
|
-
const path = toPosix$3(relative(from, target));
|
|
13025
|
-
return path.startsWith(".") ? path : `./${path}`;
|
|
13026
|
-
}
|
|
13027
|
-
function isInside(directory, parent) {
|
|
13028
|
-
const suffix = relative(parent, directory);
|
|
13029
|
-
return suffix !== "" && !suffix.startsWith("..");
|
|
13030
|
-
}
|
|
13031
|
-
function toPosix$3(path) {
|
|
13032
|
-
return sep === "/" ? path : path.split(sep).join("/");
|
|
13033
|
-
}
|
|
13034
|
-
//#endregion
|
|
13035
|
-
//#region src/project/root-layout.ts
|
|
13036
|
-
/**
|
|
13037
|
-
* Router layouts first: an app holding both is an Expo Router app whose
|
|
13038
|
-
* `App.tsx` is left over, and the layout is the file that actually renders.
|
|
13039
|
-
*/
|
|
13040
|
-
const CANDIDATES$1 = [
|
|
13041
|
-
{
|
|
13042
|
-
path: "src/app/_layout.tsx",
|
|
13043
|
-
router: true
|
|
13044
|
-
},
|
|
13045
|
-
{
|
|
13046
|
-
path: "app/_layout.tsx",
|
|
13047
|
-
router: true
|
|
13048
|
-
},
|
|
13049
|
-
{
|
|
13050
|
-
path: "src/app/_layout.jsx",
|
|
13051
|
-
router: true
|
|
13052
|
-
},
|
|
13053
|
-
{
|
|
13054
|
-
path: "app/_layout.jsx",
|
|
13055
|
-
router: true
|
|
13056
|
-
},
|
|
13057
|
-
{
|
|
13058
|
-
path: "App.tsx",
|
|
13059
|
-
router: false
|
|
13060
|
-
},
|
|
13061
|
-
{
|
|
13062
|
-
path: "src/App.tsx",
|
|
13063
|
-
router: false
|
|
13064
|
-
},
|
|
13065
|
-
{
|
|
13066
|
-
path: "App.jsx",
|
|
13067
|
-
router: false
|
|
13068
|
-
},
|
|
13069
|
-
{
|
|
13070
|
-
path: "index.tsx",
|
|
13071
|
-
router: false
|
|
13072
|
-
}
|
|
13073
|
-
];
|
|
13074
|
-
function findRootLayout(appRoot) {
|
|
13075
|
-
return CANDIDATES$1.find((candidate) => existsSync(join(appRoot, candidate.path))) ?? null;
|
|
13076
|
-
}
|
|
13077
|
-
/**
|
|
13078
|
-
* The root layout, whole, ready to paste.
|
|
13079
|
-
*
|
|
13080
|
-
* The CSS import is the first line because that is the rule it exists to
|
|
13081
|
-
* teach — anywhere else and every component renders unstyled with nothing
|
|
13082
|
-
* logged.
|
|
13083
|
-
*
|
|
13084
|
-
* `<Slot />` is Expo Router's minimal root. A layout already rendering a
|
|
13085
|
-
* `<Stack>` keeps it; the provider goes around whatever is there, which is
|
|
13086
|
-
* what the line printed beside this says.
|
|
13087
|
-
*/
|
|
13088
|
-
function renderRootLayout(layout, specifiers) {
|
|
13089
|
-
const { css, provider } = specifiers;
|
|
13090
|
-
if (!layout.router) return [
|
|
13091
|
-
`import "${css}";`,
|
|
13092
|
-
`import { DelacourProvider } from "${provider}";`,
|
|
13093
|
-
"",
|
|
13094
|
-
"export default function App() {",
|
|
13095
|
-
" return (",
|
|
13096
|
-
" <DelacourProvider>",
|
|
13097
|
-
" <YourApp />",
|
|
13098
|
-
" </DelacourProvider>",
|
|
13099
|
-
" );",
|
|
13100
|
-
"}"
|
|
13101
|
-
].join("\n");
|
|
13102
|
-
return [
|
|
13103
|
-
`import "${css}";`,
|
|
13104
|
-
`import { DelacourProvider } from "${provider}";`,
|
|
13105
|
-
"import { Slot } from \"expo-router\";",
|
|
13106
|
-
"",
|
|
13107
|
-
"export default function RootLayout() {",
|
|
13108
|
-
" return (",
|
|
13109
|
-
" <DelacourProvider>",
|
|
13110
|
-
" <Slot />",
|
|
13111
|
-
" </DelacourProvider>",
|
|
13112
|
-
" );",
|
|
13113
|
-
"}"
|
|
13114
|
-
].join("\n");
|
|
13115
|
-
}
|
|
13116
|
-
//#endregion
|
|
13117
|
-
//#region src/project/uniwind-env.ts
|
|
13118
|
-
/**
|
|
13119
|
-
* The one line that makes `className` a real prop in TypeScript.
|
|
13120
|
-
*
|
|
13121
|
-
* Uniwind augments React Native's types through a global `/// <reference>`, and
|
|
13122
|
-
* a declaration file is only loaded if it is part of the program — either
|
|
13123
|
-
* matched by `tsconfig`'s `include` or reachable by import. This file is neither
|
|
13124
|
-
* importable nor, in a shared package, inside the app's `include`, which is why
|
|
13125
|
-
* the app needs a copy of its own.
|
|
13126
|
-
*
|
|
13127
|
-
* Kept here rather than inlined so `init` and `doctor` agree on the contents.
|
|
13128
|
-
*/
|
|
13129
|
-
const UNIWIND_ENV_FILENAME = "uniwind-env.d.ts";
|
|
13130
|
-
const UNIWIND_ENV_REFERENCE = "/// <reference types=\"uniwind/types\" />";
|
|
13131
|
-
//#endregion
|
|
13132
12856
|
//#region src/commands/doctor.ts
|
|
13133
12857
|
async function doctor(options) {
|
|
13134
12858
|
const output = createOutput(options);
|
|
@@ -13161,7 +12885,7 @@ async function runChecks(options) {
|
|
|
13161
12885
|
}
|
|
13162
12886
|
/** Prints the checks and turns them into an exit code. */
|
|
13163
12887
|
function summarise(checks, output) {
|
|
13164
|
-
if (!output.silent) log.message(checks.map(render).join("\n"));
|
|
12888
|
+
if (!output.silent) log.message(checks.map(render$1).join("\n"));
|
|
13165
12889
|
const failed = checks.filter((check) => check.status === "fail").length;
|
|
13166
12890
|
const warned = checks.filter((check) => check.status === "warn").length;
|
|
13167
12891
|
if (failed > 0) output.error(`${failed} check${failed === 1 ? "" : "s"} failed.`);
|
|
@@ -13175,7 +12899,7 @@ const ICONS = {
|
|
|
13175
12899
|
fail: style.red("✗"),
|
|
13176
12900
|
skip: style.dim("–")
|
|
13177
12901
|
};
|
|
13178
|
-
function render(check) {
|
|
12902
|
+
function render$1(check) {
|
|
13179
12903
|
const head = `${ICONS[check.status]} ${check.name} ${style.dim(check.detail)}`;
|
|
13180
12904
|
return check.fix ? `${head}\n ${style.dim("→")} ${check.fix}` : head;
|
|
13181
12905
|
}
|
|
@@ -13193,10 +12917,11 @@ function checkFramework(project) {
|
|
|
13193
12917
|
};
|
|
13194
12918
|
}
|
|
13195
12919
|
/**
|
|
13196
|
-
* Reanimated 4 is New Architecture only.
|
|
12920
|
+
* Reanimated 4 is New Architecture only, and so is the bottom sheet's portal.
|
|
13197
12921
|
*
|
|
13198
|
-
* On the old architecture
|
|
13199
|
-
* pressable in the library runs one.
|
|
12922
|
+
* On the old architecture Reanimated fails at build or at the first worklet,
|
|
12923
|
+
* and every pressable in the library runs one. `react-native-teleport`, which
|
|
12924
|
+
* `BottomSheet` teleports through, ships a Fabric view and nothing else.
|
|
13200
12925
|
*/
|
|
13201
12926
|
function checkNewArchitecture(expoConfig, project) {
|
|
13202
12927
|
if (!expoConfig) return {
|
|
@@ -13215,7 +12940,7 @@ function checkNewArchitecture(expoConfig, project) {
|
|
|
13215
12940
|
name: "New Architecture",
|
|
13216
12941
|
status: "fail",
|
|
13217
12942
|
detail: "disabled",
|
|
13218
|
-
fix: "Set \"newArchEnabled\": true — Reanimated 4 does not run without it."
|
|
12943
|
+
fix: "Set \"newArchEnabled\": true — Reanimated 4 does not run without it, and BottomSheet needs the new architecture for its portal."
|
|
13219
12944
|
};
|
|
13220
12945
|
}
|
|
13221
12946
|
/**
|
|
@@ -13585,10 +13310,10 @@ function cssImportSpecifier(config) {
|
|
|
13585
13310
|
}
|
|
13586
13311
|
/** A relative path as an import specifier: `../styles/global.css`, `./global.css`. */
|
|
13587
13312
|
function relativeSpecifier(from, target) {
|
|
13588
|
-
const path = toPosix$
|
|
13313
|
+
const path = toPosix$1(relative(from, target));
|
|
13589
13314
|
return path.startsWith(".") ? path : `./${path}`;
|
|
13590
13315
|
}
|
|
13591
|
-
function toPosix$
|
|
13316
|
+
function toPosix$1(path) {
|
|
13592
13317
|
return sep === "/" ? path : path.split(sep).join("/");
|
|
13593
13318
|
}
|
|
13594
13319
|
/**
|
|
@@ -13691,7 +13416,9 @@ async function checkDuplicateNativeModules(project) {
|
|
|
13691
13416
|
"react-native",
|
|
13692
13417
|
"react-native-reanimated",
|
|
13693
13418
|
"react-native-gesture-handler",
|
|
13694
|
-
"react-native-
|
|
13419
|
+
"react-native-keyboard-controller",
|
|
13420
|
+
"react-native-svg",
|
|
13421
|
+
"react-native-teleport"
|
|
13695
13422
|
].filter((name) => existsSync(join(project.appRoot, "node_modules", name)) && existsSync(join(project.workspaceRoot, "node_modules", name)));
|
|
13696
13423
|
if (duplicated.length === 0) return {
|
|
13697
13424
|
name: "Native modules",
|
|
@@ -13752,237 +13479,53 @@ async function read$1(path) {
|
|
|
13752
13479
|
}
|
|
13753
13480
|
}
|
|
13754
13481
|
//#endregion
|
|
13755
|
-
//#region src/
|
|
13482
|
+
//#region src/commands/init.ts
|
|
13483
|
+
async function init(components, options) {
|
|
13484
|
+
const output = createOutput(options);
|
|
13485
|
+
output.intro("delacour init");
|
|
13486
|
+
const existing = findConfig(options.cwd);
|
|
13487
|
+
if (existing && !options.force) {
|
|
13488
|
+
output.warn(`${relative(options.cwd, existing) || "native-components.json"} already exists. Pass --force to rewrite it.`);
|
|
13489
|
+
return components.length > 0 ? add(components, {
|
|
13490
|
+
...options,
|
|
13491
|
+
cwd: options.cwd
|
|
13492
|
+
}) : null;
|
|
13493
|
+
}
|
|
13494
|
+
const project = await detectProject(options.cwd);
|
|
13495
|
+
warnAboutStack(project, output);
|
|
13496
|
+
const placement = await choosePlacement(project, options, output);
|
|
13497
|
+
const source = await chooseSourceDirectory(options, output);
|
|
13498
|
+
const appRoot = project.appRoot ?? placement.root;
|
|
13499
|
+
const metroPaths = readUniwindPaths(await read(join(appRoot, "metro.config.js")));
|
|
13500
|
+
const existingEntry = findTailwindEntry(appRoot);
|
|
13501
|
+
const wired = {
|
|
13502
|
+
...metroPaths,
|
|
13503
|
+
css: metroPaths.css ?? (existingEntry ? relative(appRoot, existingEntry) : void 0)
|
|
13504
|
+
};
|
|
13505
|
+
const resolved = await writeConfigFile(buildConfig({
|
|
13506
|
+
project,
|
|
13507
|
+
root: placement.root,
|
|
13508
|
+
source,
|
|
13509
|
+
packageName: placement.packageName,
|
|
13510
|
+
wired,
|
|
13511
|
+
appRoot
|
|
13512
|
+
}), placement.root, output);
|
|
13513
|
+
await wireUpApp(resolved, resolved.package ? project.workspaceRoot : null, output);
|
|
13514
|
+
const result = await add([
|
|
13515
|
+
"styles",
|
|
13516
|
+
"provider",
|
|
13517
|
+
...components
|
|
13518
|
+
], {
|
|
13519
|
+
...options,
|
|
13520
|
+
cwd: placement.root,
|
|
13521
|
+
overwrite: true
|
|
13522
|
+
});
|
|
13523
|
+
await printFollowUps(resolved, output);
|
|
13524
|
+
output.outro(outro(components));
|
|
13525
|
+
return result;
|
|
13526
|
+
}
|
|
13756
13527
|
/**
|
|
13757
|
-
*
|
|
13758
|
-
*
|
|
13759
|
-
* Creating a second one is the failure this exists to prevent. Metro compiles
|
|
13760
|
-
* the file its `cssEntryFile` names and no other; the app imports whichever
|
|
13761
|
-
* file its root layout imports. Write a new entry beside an existing one and
|
|
13762
|
-
* those become two different files — Tailwind compiles the one with the
|
|
13763
|
-
* `@source` globs, the app loads the one without them, and every component
|
|
13764
|
-
* renders unstyled with nothing logged.
|
|
13765
|
-
*
|
|
13766
|
-
* The Metro config wins when it names one, because that is what actually
|
|
13767
|
-
* compiles — see `readUniwindPaths`. This is the fallback for a project that
|
|
13768
|
-
* has an entry but has not wired Metro to it yet, which is every app that
|
|
13769
|
-
* installed Uniwind and stopped there.
|
|
13770
|
-
*
|
|
13771
|
-
* Shallowest first: an app that ran an older version of this CLI has both
|
|
13772
|
-
* `src/global.css` and `src/styles/global.css`, and the one it imports is the
|
|
13773
|
-
* one it had first.
|
|
13774
|
-
*/
|
|
13775
|
-
const CANDIDATES = [
|
|
13776
|
-
"global.css",
|
|
13777
|
-
"src/global.css",
|
|
13778
|
-
"app/global.css",
|
|
13779
|
-
"src/app/global.css",
|
|
13780
|
-
"styles/global.css",
|
|
13781
|
-
"src/styles/global.css",
|
|
13782
|
-
"src/styles/index.css"
|
|
13783
|
-
];
|
|
13784
|
-
/** `@import "tailwindcss"`, however it is quoted and whatever follows it. */
|
|
13785
|
-
const TAILWIND_IMPORT = /@import\s+["']tailwindcss["']/;
|
|
13786
|
-
function findTailwindEntry(appRoot) {
|
|
13787
|
-
for (const candidate of CANDIDATES) {
|
|
13788
|
-
const path = join(appRoot, candidate);
|
|
13789
|
-
if (!existsSync(path)) continue;
|
|
13790
|
-
try {
|
|
13791
|
-
if (TAILWIND_IMPORT.test(readFileSync(path, "utf-8"))) return path;
|
|
13792
|
-
} catch {}
|
|
13793
|
-
}
|
|
13794
|
-
return null;
|
|
13795
|
-
}
|
|
13796
|
-
//#endregion
|
|
13797
|
-
//#region src/project/metro.ts
|
|
13798
|
-
/**
|
|
13799
|
-
* Wraps the app's Metro config with Uniwind's.
|
|
13800
|
-
*
|
|
13801
|
-
* `withUniwindConfig` has to stay the outermost wrapper — it installs the
|
|
13802
|
-
* transformer that compiles `className` into styles, and a wrapper applied
|
|
13803
|
-
* after it can replace the `transformer` key and leave every component
|
|
13804
|
-
* unstyled with nothing logged. So the patch rewrites the export itself rather
|
|
13805
|
-
* than inserting a line somewhere in the middle.
|
|
13806
|
-
*
|
|
13807
|
-
* When the export is not in a shape this can safely rewrite, it says so and
|
|
13808
|
-
* prints what to write. Guessing at an unfamiliar config file earns nothing —
|
|
13809
|
-
* the failure it causes is a Metro error at bundle time in someone else's app.
|
|
13810
|
-
*/
|
|
13811
|
-
/** Modules that must resolve to exactly one copy across a workspace. */
|
|
13812
|
-
const PINNED_MODULES = [
|
|
13813
|
-
"@shopify/react-native-skia",
|
|
13814
|
-
"react",
|
|
13815
|
-
"react-native",
|
|
13816
|
-
"react-native-gesture-handler",
|
|
13817
|
-
"react-native-reanimated",
|
|
13818
|
-
"react-native-safe-area-context",
|
|
13819
|
-
"react-native-svg",
|
|
13820
|
-
"react-native-worklets"
|
|
13821
|
-
];
|
|
13822
|
-
const REQUIRE = "const { withUniwindConfig } = require(\"uniwind/metro\");";
|
|
13823
|
-
const IMPORT = "import { withUniwindConfig } from \"uniwind/metro\";";
|
|
13824
|
-
/** `module.exports = config;` or `export default config;`, with nothing after it. */
|
|
13825
|
-
const COMMONJS_EXPORT = /module\.exports\s*=\s*([\s\S]+?);?\s*$/;
|
|
13826
|
-
const ESM_EXPORT = /export default\s+([\s\S]+?);?\s*$/;
|
|
13827
|
-
const CSS_ENTRY = /cssEntryFile\s*:\s*["'`]([^"'`]+)["'`]/;
|
|
13828
|
-
const DTS_FILE = /dtsFile\s*:\s*["'`]([^"'`]+)["'`]/;
|
|
13829
|
-
/**
|
|
13830
|
-
* Reads the paths a wrapped Metro config already names.
|
|
13831
|
-
*
|
|
13832
|
-
* A project that arrives with Uniwind set up — Expo's `with-router-uniwind`
|
|
13833
|
-
* example is the common one — has chosen its own CSS entry, and Metro compiles
|
|
13834
|
-
* **that file and no other**. Writing the `@source` block into the path this
|
|
13835
|
-
* CLI would have picked leaves Tailwind scanning a file with no globs in it, so
|
|
13836
|
-
* every class the components use is dropped and every one of them renders
|
|
13837
|
-
* unstyled. Nothing errors; the app just looks wrong.
|
|
13838
|
-
*
|
|
13839
|
-
* So the wired config wins. Returns nothing when the config is not wired, in
|
|
13840
|
-
* which case `init` is about to wrap it with paths of its own.
|
|
13841
|
-
*/
|
|
13842
|
-
function readUniwindPaths(existing) {
|
|
13843
|
-
if (!existing?.includes("withUniwindConfig")) return {};
|
|
13844
|
-
return {
|
|
13845
|
-
css: CSS_ENTRY.exec(existing)?.[1],
|
|
13846
|
-
types: DTS_FILE.exec(existing)?.[1]
|
|
13847
|
-
};
|
|
13848
|
-
}
|
|
13849
|
-
function patchMetroConfig(existing, options) {
|
|
13850
|
-
const wrapper = optionsLiteral(options);
|
|
13851
|
-
const monorepo = options.workspaceRoot && options.workspaceRoot !== options.metroConfigPath ? monorepoResolverBlock(dirname(options.metroConfigPath), options.workspaceRoot) : "";
|
|
13852
|
-
if (existing === null) return {
|
|
13853
|
-
status: "created",
|
|
13854
|
-
content: template(wrapper, monorepo)
|
|
13855
|
-
};
|
|
13856
|
-
if (existing.includes("withUniwindConfig")) return { status: "already-wired" };
|
|
13857
|
-
const isEsm = /^\s*(import|export default)/m.test(existing);
|
|
13858
|
-
const match = (isEsm ? ESM_EXPORT : COMMONJS_EXPORT).exec(existing);
|
|
13859
|
-
if (!match?.[1]) return {
|
|
13860
|
-
status: "manual",
|
|
13861
|
-
snippet: manualSnippet(wrapper, isEsm)
|
|
13862
|
-
};
|
|
13863
|
-
const keyword = isEsm ? "export default" : "module.exports =";
|
|
13864
|
-
const head = existing.slice(0, match.index);
|
|
13865
|
-
const wrapped = `${keyword} withUniwindConfig(${match[1].trim()}, ${wrapper});\n`;
|
|
13866
|
-
const body = monorepo ? `${head}${monorepo}\n` : head;
|
|
13867
|
-
return {
|
|
13868
|
-
status: "patched",
|
|
13869
|
-
content: `${isEsm ? IMPORT : REQUIRE}\n${body}${wrapped}`
|
|
13870
|
-
};
|
|
13871
|
-
}
|
|
13872
|
-
function optionsLiteral(options) {
|
|
13873
|
-
const from = dirname(options.metroConfigPath);
|
|
13874
|
-
return `{\n\tcssEntryFile: "${toSpecifier(from, options.cssPath)}",\n\tdtsFile: "${toSpecifier(from, options.typesPath)}",\n}`;
|
|
13875
|
-
}
|
|
13876
|
-
/**
|
|
13877
|
-
* The resolver settings an app needs to reach a package outside its own tree.
|
|
13878
|
-
*
|
|
13879
|
-
* Metro resolves by walking `node_modules` from the app downwards, so without
|
|
13880
|
-
* `watchFolders` and `nodeModulesPaths` it simply cannot see a sibling package —
|
|
13881
|
-
* the import fails at bundle time with a missing module, pointing at the app
|
|
13882
|
-
* rather than at the workspace.
|
|
13883
|
-
*
|
|
13884
|
-
* `extraNodeModules` is the other half, and it is about runtime rather than
|
|
13885
|
-
* resolution: a package manager can materialise a second copy of a native module
|
|
13886
|
-
* under the app, and two registrations of one native module break. This is the
|
|
13887
|
-
* block `apps/playground/metro.config.js` in this repository carries for exactly
|
|
13888
|
-
* this reason.
|
|
13889
|
-
*/
|
|
13890
|
-
function monorepoResolverBlock(appRoot, workspaceRoot) {
|
|
13891
|
-
const pins = PINNED_MODULES.map((name) => `\t${JSON.stringify(name)}: path.resolve(workspaceRoot, "node_modules/${name}"),`).join("\n");
|
|
13892
|
-
return `const path = require("node:path");
|
|
13893
|
-
|
|
13894
|
-
const workspaceRoot = path.resolve(__dirname, "${toSpecifier(appRoot, workspaceRoot)}");
|
|
13895
|
-
|
|
13896
|
-
// The components live in a package outside this app, so Metro has to watch and
|
|
13897
|
-
// resolve beyond the app's own directory.
|
|
13898
|
-
config.watchFolders = [workspaceRoot];
|
|
13899
|
-
config.resolver.nodeModulesPaths = [
|
|
13900
|
-
\tpath.resolve(__dirname, "node_modules"),
|
|
13901
|
-
\tpath.resolve(workspaceRoot, "node_modules"),
|
|
13902
|
-
];
|
|
13903
|
-
config.resolver.disableHierarchicalLookup = true;
|
|
13904
|
-
|
|
13905
|
-
// One copy of each native module for the whole bundle: two registrations of a
|
|
13906
|
-
// native module break at runtime.
|
|
13907
|
-
config.resolver.extraNodeModules = {
|
|
13908
|
-
${pins}
|
|
13909
|
-
};
|
|
13910
|
-
`;
|
|
13911
|
-
}
|
|
13912
|
-
function template(wrapper, monorepo) {
|
|
13913
|
-
return `const { getDefaultConfig } = require("expo/metro-config");
|
|
13914
|
-
${REQUIRE}
|
|
13915
|
-
|
|
13916
|
-
const config = getDefaultConfig(__dirname);
|
|
13917
|
-
${monorepo ? `\n${monorepo}` : ""}
|
|
13918
|
-
// withUniwindConfig must stay the outermost wrapper.
|
|
13919
|
-
module.exports = withUniwindConfig(config, ${wrapper});
|
|
13920
|
-
`;
|
|
13921
|
-
}
|
|
13922
|
-
function manualSnippet(wrapper, isEsm) {
|
|
13923
|
-
return `${isEsm ? IMPORT : REQUIRE}\n\n// Keep this the outermost wrapper.\n${isEsm ? "export default" : "module.exports ="} withUniwindConfig(config, ${wrapper});`;
|
|
13924
|
-
}
|
|
13925
|
-
function toSpecifier(from, target) {
|
|
13926
|
-
const path = toPosix$1(relative(from, target));
|
|
13927
|
-
return path.startsWith(".") ? path : `./${path}`;
|
|
13928
|
-
}
|
|
13929
|
-
function toPosix$1(path) {
|
|
13930
|
-
return sep === "/" ? path : path.split(sep).join("/");
|
|
13931
|
-
}
|
|
13932
|
-
//#endregion
|
|
13933
|
-
//#region src/commands/init.ts
|
|
13934
|
-
var init_exports = /* @__PURE__ */ __exportAll({
|
|
13935
|
-
defaultPlacement: () => defaultPlacement,
|
|
13936
|
-
followUps: () => followUps,
|
|
13937
|
-
init: () => init,
|
|
13938
|
-
outro: () => outro
|
|
13939
|
-
});
|
|
13940
|
-
async function init(components, options) {
|
|
13941
|
-
const output = createOutput(options);
|
|
13942
|
-
output.intro("delacour init");
|
|
13943
|
-
const existing = findConfig(options.cwd);
|
|
13944
|
-
if (existing && !options.force) {
|
|
13945
|
-
output.warn(`${relative(options.cwd, existing) || "native-components.json"} already exists. Pass --force to rewrite it.`);
|
|
13946
|
-
return components.length > 0 ? add(components, {
|
|
13947
|
-
...options,
|
|
13948
|
-
cwd: options.cwd
|
|
13949
|
-
}) : null;
|
|
13950
|
-
}
|
|
13951
|
-
const project = await detectProject(options.cwd);
|
|
13952
|
-
warnAboutStack(project, output);
|
|
13953
|
-
const placement = await choosePlacement(project, options, output);
|
|
13954
|
-
const source = await chooseSourceDirectory(options, output);
|
|
13955
|
-
const appRoot = project.appRoot ?? placement.root;
|
|
13956
|
-
const metroPaths = readUniwindPaths(await read(join(appRoot, "metro.config.js")));
|
|
13957
|
-
const existingEntry = findTailwindEntry(appRoot);
|
|
13958
|
-
const wired = {
|
|
13959
|
-
...metroPaths,
|
|
13960
|
-
css: metroPaths.css ?? (existingEntry ? relative(appRoot, existingEntry) : void 0)
|
|
13961
|
-
};
|
|
13962
|
-
const resolved = await writeConfigFile(buildConfig({
|
|
13963
|
-
project,
|
|
13964
|
-
root: placement.root,
|
|
13965
|
-
source,
|
|
13966
|
-
packageName: placement.packageName,
|
|
13967
|
-
wired,
|
|
13968
|
-
appRoot
|
|
13969
|
-
}), placement.root, output);
|
|
13970
|
-
await wireUpApp(resolved, resolved.package ? project.workspaceRoot : null, output);
|
|
13971
|
-
const result = await add([
|
|
13972
|
-
"styles",
|
|
13973
|
-
"provider",
|
|
13974
|
-
...components
|
|
13975
|
-
], {
|
|
13976
|
-
...options,
|
|
13977
|
-
cwd: placement.root,
|
|
13978
|
-
overwrite: true
|
|
13979
|
-
});
|
|
13980
|
-
await printFollowUps(resolved, output);
|
|
13981
|
-
output.outro(outro(components));
|
|
13982
|
-
return result;
|
|
13983
|
-
}
|
|
13984
|
-
/**
|
|
13985
|
-
* The default answer, decided without asking.
|
|
13528
|
+
* The default answer, decided without asking.
|
|
13986
13529
|
*
|
|
13987
13530
|
* Pure and exported so the decision table is testable: the prompt branches were
|
|
13988
13531
|
* previously unreachable from any test, which is how "running inside a package
|
|
@@ -14191,75 +13734,548 @@ function outro(components) {
|
|
|
14191
13734
|
return `Ready. ${named.length === 1 ? `${named[0]} is` : `${named.slice(0, -1).join(", ")} and ${named[named.length - 1]} are`} yours to edit.`;
|
|
14192
13735
|
}
|
|
14193
13736
|
/**
|
|
14194
|
-
* What is left, and why the CLI did not just do it.
|
|
14195
|
-
*
|
|
14196
|
-
* Each of these needs a decision or an AST edit inside a file the project owns.
|
|
14197
|
-
* `doctor` re-checks all of them, so this list is a starting point rather than
|
|
14198
|
-
* the only chance to see it.
|
|
13737
|
+
* What is left, and why the CLI did not just do it.
|
|
13738
|
+
*
|
|
13739
|
+
* Each of these needs a decision or an AST edit inside a file the project owns.
|
|
13740
|
+
* `doctor` re-checks all of them, so this list is a starting point rather than
|
|
13741
|
+
* the only chance to see it.
|
|
13742
|
+
*/
|
|
13743
|
+
async function printFollowUps(config, output) {
|
|
13744
|
+
const done = {
|
|
13745
|
+
cssImported: (await filesImporting(config.app.resolved.root, config.app.resolved.css)).length > 0,
|
|
13746
|
+
providerMounted: (await checkGestureHandlerRoot(config)).status === "pass"
|
|
13747
|
+
};
|
|
13748
|
+
const items = followUps(config, done);
|
|
13749
|
+
if (items.length === 0) return;
|
|
13750
|
+
const layout = done.cssImported && done.providerMounted ? null : rootLayoutBlock(config);
|
|
13751
|
+
output.info([
|
|
13752
|
+
`A few things need you:`,
|
|
13753
|
+
...items.map((line) => ` • ${line}`),
|
|
13754
|
+
...layout ? ["", ...layout] : [],
|
|
13755
|
+
"",
|
|
13756
|
+
`Run ${style.code("delacour doctor")} to check.`
|
|
13757
|
+
].join("\n"));
|
|
13758
|
+
}
|
|
13759
|
+
/** The root layout, whole, or nothing when there is no file to name. */
|
|
13760
|
+
function rootLayoutBlock(config) {
|
|
13761
|
+
const layout = findRootLayout(config.app.resolved.root);
|
|
13762
|
+
if (!layout) return null;
|
|
13763
|
+
const file = renderRootLayout(layout, layoutSpecifiers(config));
|
|
13764
|
+
return [
|
|
13765
|
+
style.path(layout.path),
|
|
13766
|
+
...file.split("\n").map((line) => line === "" ? "" : ` ${line}`),
|
|
13767
|
+
"",
|
|
13768
|
+
layout.router ? `Already rendering a ${style.code("<Stack>")}? Keep it — wrap it, rather than replacing it with ${style.code("<Slot />")}.` : "Wrap whatever this file already renders, rather than replacing it."
|
|
13769
|
+
];
|
|
13770
|
+
}
|
|
13771
|
+
function followUps(config, done = {}) {
|
|
13772
|
+
const items = [];
|
|
13773
|
+
if (Object.keys(config.aliases).length > 0) items.push(`Set ${style.code("experiments.tsconfigPaths: true")} in app.config — Metro ignores tsconfig paths without it.`);
|
|
13774
|
+
const cssImport = layoutSpecifiers(config).css;
|
|
13775
|
+
if (!done.cssImported) items.push(`Import ${style.code(`"${cssImport}"`)} as the first statement of your root layout — without it every component renders unstyled.`);
|
|
13776
|
+
const providerImport = layoutSpecifiers(config).provider;
|
|
13777
|
+
if (!done.providerMounted) items.push(`Wrap the app root in ${style.code("<DelacourProvider>")} from ${style.code(`"${providerImport}"`)} — presses do nothing without it.`);
|
|
13778
|
+
items.push(`${style.code("theme.css")} is the file to edit — replace it with the theme.css tab from https://ui.delacour.co.nz/theme, or paste a shadcn or tweakcn globals.css over it and run ${style.code("delacour theme")}.`);
|
|
13779
|
+
return items;
|
|
13780
|
+
}
|
|
13781
|
+
function warnAboutStack(project, output) {
|
|
13782
|
+
if (!project.packageJson) {
|
|
13783
|
+
output.warn("No package.json here. Run this inside your Expo app.");
|
|
13784
|
+
return;
|
|
13785
|
+
}
|
|
13786
|
+
if (!project.expoVersion && !project.reactNativeVersion) output.warn("This does not look like a React Native project — delacour components only run on React Native.");
|
|
13787
|
+
const styling = checkStylingConflict(project);
|
|
13788
|
+
if (styling.status === "fail") output.warn([styling.detail, styling.fix].filter(Boolean).join("\n"));
|
|
13789
|
+
}
|
|
13790
|
+
function short(from, path) {
|
|
13791
|
+
return toPosix(relative(from, path)) || ".";
|
|
13792
|
+
}
|
|
13793
|
+
function toPosix(path) {
|
|
13794
|
+
return sep === "/" ? path : path.split(sep).join("/");
|
|
13795
|
+
}
|
|
13796
|
+
async function read(path) {
|
|
13797
|
+
try {
|
|
13798
|
+
return await readFile(path, "utf-8");
|
|
13799
|
+
} catch {
|
|
13800
|
+
return null;
|
|
13801
|
+
}
|
|
13802
|
+
}
|
|
13803
|
+
async function write$1(path, content) {
|
|
13804
|
+
await mkdir(dirname(path), { recursive: true });
|
|
13805
|
+
await writeFile(path, content, "utf-8");
|
|
13806
|
+
}
|
|
13807
|
+
//#endregion
|
|
13808
|
+
//#region src/commands/add.ts
|
|
13809
|
+
async function add(names, options) {
|
|
13810
|
+
const output = createOutput(options);
|
|
13811
|
+
if (!findConfig(options.cwd)) {
|
|
13812
|
+
if (options.init === false) throw new MissingConfigError(options.cwd);
|
|
13813
|
+
output.info(`No ${CONFIG_FILENAME} here — setting this project up first.`);
|
|
13814
|
+
return init(names, options);
|
|
13815
|
+
}
|
|
13816
|
+
const config = await loadConfig(options.cwd);
|
|
13817
|
+
const project = await detectProject(config.app.resolved.root);
|
|
13818
|
+
const client = createRegistryClient({
|
|
13819
|
+
cwd: options.cwd,
|
|
13820
|
+
url: options.registry ?? config.registry.url,
|
|
13821
|
+
ref: options.ref ?? config.registry.ref,
|
|
13822
|
+
offline: options.offline
|
|
13823
|
+
});
|
|
13824
|
+
const index = await output.task("Reading the registry", () => client.getIndex());
|
|
13825
|
+
const requested = options.all ? index.items.filter((item) => item.type === "registry:ui").map((i) => i.name) : names;
|
|
13826
|
+
if (requested.length === 0) {
|
|
13827
|
+
output.warn("Nothing to add. Name a component, or pass --all.");
|
|
13828
|
+
return null;
|
|
13829
|
+
}
|
|
13830
|
+
const byName = new Map(index.items.map((item) => [item.name, item]));
|
|
13831
|
+
const order = resolveItemGraph(requested, (name) => byName.get(name));
|
|
13832
|
+
const items = await output.task(`Fetching ${order.length} item${order.length === 1 ? "" : "s"}`, async () => {
|
|
13833
|
+
const fetched = await Promise.all(order.map((name) => client.getItem(name)));
|
|
13834
|
+
return Promise.all(fetched.map((item) => client.loadItem(item)));
|
|
13835
|
+
});
|
|
13836
|
+
const planned = await planFiles(items, config);
|
|
13837
|
+
const toWrite = await resolveConflicts(planned, options, output);
|
|
13838
|
+
if (toWrite === null) return null;
|
|
13839
|
+
await writeFiles(toWrite);
|
|
13840
|
+
report$1(toWrite, planned, requested, output);
|
|
13841
|
+
await syncPackage(config, items, output);
|
|
13842
|
+
const appRoot = project.appRoot ?? project.packageRoot ?? project.cwd;
|
|
13843
|
+
const plan = planDependencies({
|
|
13844
|
+
packageManager: project.packageManager,
|
|
13845
|
+
expoDependencies: collect(items, "expoDependencies"),
|
|
13846
|
+
dependencies: collect(items, "dependencies"),
|
|
13847
|
+
devDependencies: collect(items, "devDependencies")
|
|
13848
|
+
}, project.packageJson);
|
|
13849
|
+
reportDependencies(plan, output);
|
|
13850
|
+
const result = {
|
|
13851
|
+
items: items.map((item) => item.name),
|
|
13852
|
+
written: toWrite.length,
|
|
13853
|
+
dependencies: plan
|
|
13854
|
+
};
|
|
13855
|
+
if (!await shouldInstall(plan, options, output)) {
|
|
13856
|
+
printSkippedInstall(plan, relative(options.cwd, appRoot), output);
|
|
13857
|
+
return {
|
|
13858
|
+
...result,
|
|
13859
|
+
installed: false
|
|
13860
|
+
};
|
|
13861
|
+
}
|
|
13862
|
+
for (const group of plan.groups) await output.task(`${group.label}: ${group.packages.join(", ")}`, () => runInstall(group, {
|
|
13863
|
+
cwd: appRoot,
|
|
13864
|
+
silent: output.silent
|
|
13865
|
+
}));
|
|
13866
|
+
warnAboutNativeRebuild(items, project, output);
|
|
13867
|
+
return {
|
|
13868
|
+
...result,
|
|
13869
|
+
installed: true
|
|
13870
|
+
};
|
|
13871
|
+
}
|
|
13872
|
+
/**
|
|
13873
|
+
* Decides which planned files to actually write.
|
|
13874
|
+
*
|
|
13875
|
+
* A file already on disk with identical content is not a conflict — that is the
|
|
13876
|
+
* normal state of a dependency two components share. Only a genuine difference
|
|
13877
|
+
* is worth asking about, because the premise of the tool is that the user owns
|
|
13878
|
+
* these files and may well have edited them.
|
|
13879
|
+
*/
|
|
13880
|
+
async function resolveConflicts(planned, options, output) {
|
|
13881
|
+
const fresh = planned.filter((file) => !file.exists);
|
|
13882
|
+
const identical = planned.filter((file) => file.unchanged);
|
|
13883
|
+
const conflicts = planned.filter((file) => file.exists && !file.unchanged);
|
|
13884
|
+
if (conflicts.length === 0 || options.overwrite) return [...fresh, ...conflicts];
|
|
13885
|
+
if (!output.interactive) {
|
|
13886
|
+
output.error([
|
|
13887
|
+
`${conflicts.length} file${conflicts.length === 1 ? "" : "s"} would be overwritten:`,
|
|
13888
|
+
...conflicts.map((file) => ` ${file.displayPath}`),
|
|
13889
|
+
"",
|
|
13890
|
+
"Pass --overwrite to replace them, or run without --yes to be asked."
|
|
13891
|
+
].join("\n"));
|
|
13892
|
+
return null;
|
|
13893
|
+
}
|
|
13894
|
+
output.warn([`These files differ from the registry:`, ...conflicts.map((file) => ` ${style.path(file.displayPath)}`)].join("\n"));
|
|
13895
|
+
const overwrite = await output.confirm("Overwrite them?", false);
|
|
13896
|
+
if (!overwrite && fresh.length === 0) {
|
|
13897
|
+
output.info(`Nothing written. ${identical.length} file${identical.length === 1 ? " is" : "s are"} already current.`);
|
|
13898
|
+
return null;
|
|
13899
|
+
}
|
|
13900
|
+
return overwrite ? [...fresh, ...conflicts] : fresh;
|
|
13901
|
+
}
|
|
13902
|
+
function report$1(written, planned, requested, output) {
|
|
13903
|
+
const unchanged = planned.length - written.length;
|
|
13904
|
+
const pulled = [...new Set(written.map((file) => file.item))].filter((name) => !requested.includes(name));
|
|
13905
|
+
output.success(`Wrote ${written.length} file${written.length === 1 ? "" : "s"}${unchanged > 0 ? `, ${unchanged} already current` : ""}.`);
|
|
13906
|
+
if (!output.silent && written.length > 0) log.message(written.map((file) => ` ${style.path(file.displayPath)}`).join("\n"));
|
|
13907
|
+
if (pulled.length > 0) output.info(`Pulled in as dependencies: ${pulled.join(", ")}`);
|
|
13908
|
+
}
|
|
13909
|
+
/**
|
|
13910
|
+
* What these components need from npm, printed every time.
|
|
13911
|
+
*
|
|
13912
|
+
* Every time, including the run where nothing is missing. A component that
|
|
13913
|
+
* needs `react-native-teleport` and got it three components ago is not the same
|
|
13914
|
+
* thing as a component that needs nothing, and a reader who sees no block at
|
|
13915
|
+
* all cannot tell which they are looking at.
|
|
13916
|
+
*
|
|
13917
|
+
* The missing packages are shown as the commands that would install them rather
|
|
13918
|
+
* than as a list of names, because the commands are the part that is not
|
|
13919
|
+
* obvious: a native module goes through `expo install` so the SDK picks a
|
|
13920
|
+
* version it can build, and a plain one through whichever package manager this
|
|
13921
|
+
* project is on.
|
|
13922
|
+
*/
|
|
13923
|
+
function reportDependencies(plan, output) {
|
|
13924
|
+
if (plan.wanted.length === 0) return;
|
|
13925
|
+
const lines = plan.groups.map((group) => ` ${style.code(commandLine(group))}`);
|
|
13926
|
+
if (plan.satisfied.length > 0) lines.push(` ${style.dim(`already installed — ${plan.satisfied.join(", ")}`)}`);
|
|
13927
|
+
output.info([plan.missing.length === 0 ? `Needs ${count(plan.wanted, "external package")}, all already here.` : `Needs ${count(plan.wanted, "external package")}, ${plan.missing.length} not here yet:`, ...lines].join("\n"));
|
|
13928
|
+
}
|
|
13929
|
+
/**
|
|
13930
|
+
* Whether to actually run the package manager.
|
|
13931
|
+
*
|
|
13932
|
+
* Unset means ask, and a run with no one to ask installs nothing — a script, a
|
|
13933
|
+
* CI job or an agent gets the report and decides for itself. `--install` is how
|
|
13934
|
+
* any of them says yes.
|
|
13935
|
+
*/
|
|
13936
|
+
async function shouldInstall(plan, options, output) {
|
|
13937
|
+
if (plan.groups.length === 0) return false;
|
|
13938
|
+
if (options.install !== void 0) return options.install;
|
|
13939
|
+
if (!output.interactive) return false;
|
|
13940
|
+
return output.confirm(`Install ${count(plan.missing, "package")} now?`, true);
|
|
13941
|
+
}
|
|
13942
|
+
/**
|
|
13943
|
+
* Keeps the shared package's `exports` map and peers in step with its contents.
|
|
13944
|
+
*
|
|
13945
|
+
* A no-op when the components live in the app: there is no package boundary to
|
|
13946
|
+
* cross, so nothing needs exporting.
|
|
13947
|
+
*
|
|
13948
|
+
* The peers are the same packages `install` puts in the **app** — the app owns
|
|
13949
|
+
* the versions, because `expo install` pins them against the SDK. Recording them
|
|
13950
|
+
* as peers here rather than dependencies is the rule that keeps one copy of each
|
|
13951
|
+
* native module in the tree.
|
|
13952
|
+
*/
|
|
13953
|
+
async function syncPackage(config, items, output) {
|
|
13954
|
+
const result = await syncSharedPackage(config, [...collect(items, "expoDependencies"), ...collect(items, "dependencies")]);
|
|
13955
|
+
if (!result) return;
|
|
13956
|
+
output.success(`${result.created ? "Wrote" : "Updated"} package.json — ${result.exportCount} exports`);
|
|
13957
|
+
if (await linkPackageToApp(config)) output.info(`Added ${style.code(`"${config.package?.name}": "workspace:*"`)} to the app. Re-run your install.`);
|
|
13958
|
+
}
|
|
13959
|
+
/**
|
|
13960
|
+
* Says the components will not build yet, and where to fix that.
|
|
13961
|
+
*
|
|
13962
|
+
* `appPath` matters more than it looks. The components may live in a shared
|
|
13963
|
+
* package, and running the install from there is the one thing that reliably
|
|
13964
|
+
* breaks the app — a native module resolved from two realpaths registers twice.
|
|
13965
|
+
*/
|
|
13966
|
+
function printSkippedInstall(plan, appPath, output) {
|
|
13967
|
+
if (plan.groups.length === 0) return;
|
|
13968
|
+
output.warn(`Nothing installed — these components will not build until you run the ${plan.groups.length === 1 ? "command" : "commands"} above${appPath === "" || appPath === "." ? "" : ` in ${style.path(appPath)}`}, or re-run with ${style.code("--install")}.`);
|
|
13969
|
+
}
|
|
13970
|
+
/**
|
|
13971
|
+
* A new native module is not live until the app is rebuilt.
|
|
13972
|
+
*
|
|
13973
|
+
* Reloading the JS bundle will red-box on a module that is not in the binary,
|
|
13974
|
+
* and the error names a missing turbo module rather than the component that
|
|
13975
|
+
* pulled it in — so it is worth saying plainly, once, at the point it becomes
|
|
13976
|
+
* true.
|
|
13977
|
+
*/
|
|
13978
|
+
function warnAboutNativeRebuild(items, project, output) {
|
|
13979
|
+
const added = missingPackages(project.packageJson, collect(items, "expoDependencies"));
|
|
13980
|
+
if (added.length === 0) return;
|
|
13981
|
+
output.warn([
|
|
13982
|
+
`Added native modules: ${added.join(", ")}`,
|
|
13983
|
+
"Rebuild the dev client before reloading — a JS reload alone will not pick them up:",
|
|
13984
|
+
` ${style.code("npx expo run:ios")} ${style.dim("(or run:android)")}`
|
|
13985
|
+
].join("\n"));
|
|
13986
|
+
}
|
|
13987
|
+
function count(items, noun) {
|
|
13988
|
+
return `${items.length} ${noun}${items.length === 1 ? "" : "s"}`;
|
|
13989
|
+
}
|
|
13990
|
+
function collect(items, key) {
|
|
13991
|
+
return [...new Set(items.flatMap((item) => item[key]))].sort();
|
|
13992
|
+
}
|
|
13993
|
+
//#endregion
|
|
13994
|
+
//#region src/commands/browse.ts
|
|
13995
|
+
async function openRegistry(options) {
|
|
13996
|
+
const configPath = findConfig(options.cwd);
|
|
13997
|
+
const config = configPath ? await readConfig(configPath) : null;
|
|
13998
|
+
return createRegistryClient({
|
|
13999
|
+
cwd: options.cwd,
|
|
14000
|
+
url: options.registry ?? config?.registry.url,
|
|
14001
|
+
ref: options.ref ?? config?.registry.ref,
|
|
14002
|
+
offline: options.offline
|
|
14003
|
+
});
|
|
14004
|
+
}
|
|
14005
|
+
async function list(options) {
|
|
14006
|
+
const output = createOutput(options);
|
|
14007
|
+
const index = await (await openRegistry(options)).getIndex();
|
|
14008
|
+
if (options.json) {
|
|
14009
|
+
process.stdout.write(`${JSON.stringify(index.items, null, 2)}\n`);
|
|
14010
|
+
return;
|
|
14011
|
+
}
|
|
14012
|
+
printGroups(index.items, output);
|
|
14013
|
+
}
|
|
14014
|
+
async function search(query, options) {
|
|
14015
|
+
const output = createOutput(options);
|
|
14016
|
+
const index = await (await openRegistry(options)).getIndex();
|
|
14017
|
+
const needle = query.toLowerCase();
|
|
14018
|
+
const matches = index.items.filter((item) => [
|
|
14019
|
+
item.name,
|
|
14020
|
+
item.title,
|
|
14021
|
+
item.description,
|
|
14022
|
+
...item.categories ?? []
|
|
14023
|
+
].join(" ").toLowerCase().includes(needle));
|
|
14024
|
+
if (options.json) {
|
|
14025
|
+
process.stdout.write(`${JSON.stringify(matches, null, 2)}\n`);
|
|
14026
|
+
return;
|
|
14027
|
+
}
|
|
14028
|
+
if (matches.length === 0) {
|
|
14029
|
+
output.warn(`Nothing matches "${query}".`);
|
|
14030
|
+
return;
|
|
14031
|
+
}
|
|
14032
|
+
printGroups(matches, output);
|
|
14033
|
+
}
|
|
14034
|
+
/**
|
|
14035
|
+
* One item: its files, what it copies in, and what it installs.
|
|
14036
|
+
*
|
|
14037
|
+
* The install lines are the whole closure, not this item's own `dependencies`.
|
|
14038
|
+
* `bottom-sheet` lists five native modules and renders `icon`, which needs
|
|
14039
|
+
* `react-native-svg` — so the item's own list under-reports what `add` would
|
|
14040
|
+
* install by exactly the packages a reader is deciding about. They are rendered
|
|
14041
|
+
* as real commands, against the package manager this project is on, because
|
|
14042
|
+
* `expo install` versus `bun add` is the distinction that decides whether the
|
|
14043
|
+
* build compiles.
|
|
14044
|
+
*/
|
|
14045
|
+
async function view(name, options) {
|
|
14046
|
+
const output = createOutput(options);
|
|
14047
|
+
const client = await openRegistry(options);
|
|
14048
|
+
const item = await client.getItem(name);
|
|
14049
|
+
if (options.json) {
|
|
14050
|
+
process.stdout.write(`${JSON.stringify(await client.loadItem(item), null, 2)}\n`);
|
|
14051
|
+
return;
|
|
14052
|
+
}
|
|
14053
|
+
const index = await client.getIndex();
|
|
14054
|
+
const byName = new Map(index.items.map((entry) => [entry.name, entry]));
|
|
14055
|
+
const order = resolveItemGraph([name], (candidate) => byName.get(candidate));
|
|
14056
|
+
const closure = order.filter((candidate) => candidate !== name);
|
|
14057
|
+
const resolved = order.flatMap((candidate) => byName.get(candidate) ?? []);
|
|
14058
|
+
const configPath = findConfig(options.cwd);
|
|
14059
|
+
const project = await detectProject((configPath ? await readConfig(configPath) : null)?.app.resolved.root ?? options.cwd);
|
|
14060
|
+
const union = (key) => [...new Set(resolved.flatMap((entry) => entry[key]))].sort();
|
|
14061
|
+
const commands = installCommands({
|
|
14062
|
+
packageManager: project.packageManager,
|
|
14063
|
+
expoDependencies: union("expoDependencies"),
|
|
14064
|
+
dependencies: union("dependencies"),
|
|
14065
|
+
devDependencies: union("devDependencies")
|
|
14066
|
+
});
|
|
14067
|
+
const lines = [
|
|
14068
|
+
`${style.bold(item.title)} ${style.dim(item.name)}`,
|
|
14069
|
+
item.description,
|
|
14070
|
+
"",
|
|
14071
|
+
`${style.dim("files")} ${item.files.map((file) => `${file.namespace}/${file.target}`).join("\n ")}`
|
|
14072
|
+
];
|
|
14073
|
+
if (closure.length > 0) lines.push(`${style.dim("copies in")} ${closure.join(", ")}`);
|
|
14074
|
+
if (commands.length > 0) lines.push("", style.dim("needs installing"), ...commands.map((group) => ` ${style.code(commandLine(group))}`), style.dim(" Run these in the app, never in a shared package."));
|
|
14075
|
+
output.log(lines.join("\n"));
|
|
14076
|
+
}
|
|
14077
|
+
async function info(options) {
|
|
14078
|
+
const output = createOutput(options);
|
|
14079
|
+
const configPath = findConfig(options.cwd);
|
|
14080
|
+
const config = configPath ? await readConfig(configPath) : null;
|
|
14081
|
+
const project = await detectProject(config?.app.resolved.root ?? options.cwd);
|
|
14082
|
+
const client = await openRegistry(options);
|
|
14083
|
+
const report = {
|
|
14084
|
+
config: configPath ?? null,
|
|
14085
|
+
registry: client.source,
|
|
14086
|
+
project: {
|
|
14087
|
+
packageManager: project.packageManager,
|
|
14088
|
+
expo: project.expoVersion,
|
|
14089
|
+
reactNative: project.reactNativeVersion,
|
|
14090
|
+
uniwind: project.hasUniwind,
|
|
14091
|
+
tailwind: project.hasTailwind,
|
|
14092
|
+
workspaceRoot: project.workspaceRoot,
|
|
14093
|
+
appRoot: project.appRoot,
|
|
14094
|
+
aliases: project.pathMappings.map((mapping) => `${mapping.prefix}* → ${mapping.directory}`)
|
|
14095
|
+
},
|
|
14096
|
+
paths: config?.directories ?? null
|
|
14097
|
+
};
|
|
14098
|
+
if (options.json) {
|
|
14099
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
14100
|
+
return;
|
|
14101
|
+
}
|
|
14102
|
+
output.log(JSON.stringify(report, null, 2));
|
|
14103
|
+
}
|
|
14104
|
+
function printGroups(items, output) {
|
|
14105
|
+
if (output.silent) return;
|
|
14106
|
+
const components = items.filter((item) => item.type === "registry:ui");
|
|
14107
|
+
const rest = items.filter((item) => item.type !== "registry:ui");
|
|
14108
|
+
const width = Math.max(...items.map((item) => item.name.length));
|
|
14109
|
+
const render = (entry) => ` ${style.cyan(entry.name.padEnd(width))} ${style.dim(entry.description)}`;
|
|
14110
|
+
if (components.length > 0) log.message([style.bold("Components"), ...components.map(render)].join("\n"));
|
|
14111
|
+
if (rest.length > 0) log.message([
|
|
14112
|
+
style.bold("Utilities"),
|
|
14113
|
+
...rest.map(render),
|
|
14114
|
+
"",
|
|
14115
|
+
style.dim("Pulled in automatically when a component needs them.")
|
|
14116
|
+
].join("\n"));
|
|
14117
|
+
}
|
|
14118
|
+
//#endregion
|
|
14119
|
+
//#region src/ui/diff.ts
|
|
14120
|
+
function diffLines(before, after) {
|
|
14121
|
+
const a = before.split("\n");
|
|
14122
|
+
const b = after.split("\n");
|
|
14123
|
+
const table = lcsTable(a, b);
|
|
14124
|
+
const lines = [];
|
|
14125
|
+
let i = 0;
|
|
14126
|
+
let j = 0;
|
|
14127
|
+
while (i < a.length && j < b.length) if (a[i] === b[j]) {
|
|
14128
|
+
lines.push({
|
|
14129
|
+
kind: "context",
|
|
14130
|
+
text: a[i]
|
|
14131
|
+
});
|
|
14132
|
+
i += 1;
|
|
14133
|
+
j += 1;
|
|
14134
|
+
} else if ((table[i + 1]?.[j] ?? 0) >= (table[i]?.[j + 1] ?? 0)) {
|
|
14135
|
+
lines.push({
|
|
14136
|
+
kind: "removed",
|
|
14137
|
+
text: a[i]
|
|
14138
|
+
});
|
|
14139
|
+
i += 1;
|
|
14140
|
+
} else {
|
|
14141
|
+
lines.push({
|
|
14142
|
+
kind: "added",
|
|
14143
|
+
text: b[j]
|
|
14144
|
+
});
|
|
14145
|
+
j += 1;
|
|
14146
|
+
}
|
|
14147
|
+
while (i < a.length) lines.push({
|
|
14148
|
+
kind: "removed",
|
|
14149
|
+
text: a[i++]
|
|
14150
|
+
});
|
|
14151
|
+
while (j < b.length) lines.push({
|
|
14152
|
+
kind: "added",
|
|
14153
|
+
text: b[j++]
|
|
14154
|
+
});
|
|
14155
|
+
return lines;
|
|
14156
|
+
}
|
|
14157
|
+
/**
|
|
14158
|
+
* Groups changes into hunks with surrounding context, dropping the long runs of
|
|
14159
|
+
* untouched code between them.
|
|
14199
14160
|
*/
|
|
14200
|
-
|
|
14201
|
-
const
|
|
14202
|
-
|
|
14203
|
-
|
|
14204
|
-
|
|
14205
|
-
|
|
14206
|
-
|
|
14207
|
-
|
|
14208
|
-
|
|
14209
|
-
|
|
14210
|
-
|
|
14211
|
-
|
|
14212
|
-
|
|
14213
|
-
|
|
14214
|
-
|
|
14161
|
+
function toHunks(lines, context = 3) {
|
|
14162
|
+
const changed = lines.map((line) => line.kind !== "context");
|
|
14163
|
+
const keep = lines.map((_, index) => changed.slice(Math.max(0, index - context), index + context + 1).some(Boolean));
|
|
14164
|
+
const hunks = [];
|
|
14165
|
+
let before = 1;
|
|
14166
|
+
let after = 1;
|
|
14167
|
+
let current = null;
|
|
14168
|
+
lines.forEach((line, index) => {
|
|
14169
|
+
if (keep[index]) {
|
|
14170
|
+
current ??= {
|
|
14171
|
+
before,
|
|
14172
|
+
after,
|
|
14173
|
+
lines: []
|
|
14174
|
+
};
|
|
14175
|
+
current.lines.push(line);
|
|
14176
|
+
} else if (current) {
|
|
14177
|
+
hunks.push(current);
|
|
14178
|
+
current = null;
|
|
14179
|
+
}
|
|
14180
|
+
if (line.kind !== "added") before += 1;
|
|
14181
|
+
if (line.kind !== "removed") after += 1;
|
|
14182
|
+
});
|
|
14183
|
+
if (current) hunks.push(current);
|
|
14184
|
+
return hunks;
|
|
14215
14185
|
}
|
|
14216
|
-
|
|
14217
|
-
|
|
14218
|
-
const layout = findRootLayout(config.app.resolved.root);
|
|
14219
|
-
if (!layout) return null;
|
|
14220
|
-
const file = renderRootLayout(layout, layoutSpecifiers(config));
|
|
14221
|
-
return [
|
|
14222
|
-
style.path(layout.path),
|
|
14223
|
-
...file.split("\n").map((line) => line === "" ? "" : ` ${line}`),
|
|
14224
|
-
"",
|
|
14225
|
-
layout.router ? `Already rendering a ${style.code("<Stack>")}? Keep it — wrap it, rather than replacing it with ${style.code("<Slot />")}.` : "Wrap whatever this file already renders, rather than replacing it."
|
|
14226
|
-
];
|
|
14186
|
+
function hasChanges(lines) {
|
|
14187
|
+
return lines.some((line) => line.kind !== "context");
|
|
14227
14188
|
}
|
|
14228
|
-
function
|
|
14229
|
-
const
|
|
14230
|
-
|
|
14231
|
-
|
|
14232
|
-
|
|
14233
|
-
|
|
14234
|
-
|
|
14235
|
-
items.push(`${style.code("theme.css")} is the file to edit — replace it with the theme.css tab from https://ui.delacour.co.nz/theme, or paste a shadcn or tweakcn globals.css over it and run ${style.code("delacour theme")}.`);
|
|
14236
|
-
return items;
|
|
14189
|
+
function lcsTable(a, b) {
|
|
14190
|
+
const table = Array.from({ length: a.length + 1 }, () => new Array(b.length + 1).fill(0));
|
|
14191
|
+
for (let i = a.length - 1; i >= 0; i -= 1) for (let j = b.length - 1; j >= 0; j -= 1) {
|
|
14192
|
+
const row = table[i];
|
|
14193
|
+
row[j] = a[i] === b[j] ? (table[i + 1]?.[j + 1] ?? 0) + 1 : Math.max(table[i + 1]?.[j] ?? 0, row[j + 1] ?? 0);
|
|
14194
|
+
}
|
|
14195
|
+
return table;
|
|
14237
14196
|
}
|
|
14238
|
-
|
|
14239
|
-
|
|
14240
|
-
|
|
14197
|
+
//#endregion
|
|
14198
|
+
//#region src/commands/diff.ts
|
|
14199
|
+
async function diff(name, options) {
|
|
14200
|
+
const output = createOutput(options);
|
|
14201
|
+
const config = await loadConfig(options.cwd);
|
|
14202
|
+
const client = createRegistryClient({
|
|
14203
|
+
cwd: options.cwd,
|
|
14204
|
+
url: options.registry ?? config.registry.url,
|
|
14205
|
+
ref: options.ref ?? config.registry.ref,
|
|
14206
|
+
offline: options.offline
|
|
14207
|
+
});
|
|
14208
|
+
const index = await client.getIndex();
|
|
14209
|
+
const candidates = name ? [name] : await installedItems(index.items, config);
|
|
14210
|
+
if (candidates.length === 0) {
|
|
14211
|
+
output.info("No components from the registry are in this project yet.");
|
|
14241
14212
|
return;
|
|
14242
14213
|
}
|
|
14243
|
-
|
|
14244
|
-
const
|
|
14245
|
-
|
|
14214
|
+
let changed = 0;
|
|
14215
|
+
for (const candidate of candidates) {
|
|
14216
|
+
const item = await client.loadItem(await client.getItem(candidate));
|
|
14217
|
+
changed += await reportItem(item, config, output);
|
|
14218
|
+
}
|
|
14219
|
+
if (changed === 0) {
|
|
14220
|
+
output.success("Everything matches the registry.");
|
|
14221
|
+
return;
|
|
14222
|
+
}
|
|
14223
|
+
const command = [
|
|
14224
|
+
"delacour add",
|
|
14225
|
+
name,
|
|
14226
|
+
"--overwrite"
|
|
14227
|
+
].filter(Boolean).join(" ");
|
|
14228
|
+
output.info(`${changed} file${changed === 1 ? " differs" : "s differ"}. ${style.code(command)} takes the registry's copy.`);
|
|
14246
14229
|
}
|
|
14247
|
-
function
|
|
14248
|
-
|
|
14230
|
+
async function reportItem(item, config, output) {
|
|
14231
|
+
const planned = await planFiles([item], config);
|
|
14232
|
+
let changed = 0;
|
|
14233
|
+
for (const file of planned) {
|
|
14234
|
+
if (file.current === null || file.unchanged) continue;
|
|
14235
|
+
const lines = diffLines(file.current, file.content);
|
|
14236
|
+
if (!hasChanges(lines)) continue;
|
|
14237
|
+
changed += 1;
|
|
14238
|
+
if (output.silent) continue;
|
|
14239
|
+
const body = toHunks(lines).flatMap((hunk) => [style.dim(`@@ -${hunk.before} +${hunk.after} @@`), ...hunk.lines.map(render)]);
|
|
14240
|
+
log.message([`${style.bold(item.name)} ${style.path(file.displayPath)}`, ...body].join("\n"));
|
|
14241
|
+
}
|
|
14242
|
+
return changed;
|
|
14249
14243
|
}
|
|
14250
|
-
function
|
|
14251
|
-
|
|
14244
|
+
function render(line) {
|
|
14245
|
+
if (line.kind === "added") return style.green(`+ ${line.text}`);
|
|
14246
|
+
if (line.kind === "removed") return style.red(`- ${line.text}`);
|
|
14247
|
+
return style.dim(` ${line.text}`);
|
|
14252
14248
|
}
|
|
14253
|
-
|
|
14254
|
-
|
|
14255
|
-
|
|
14256
|
-
|
|
14257
|
-
|
|
14249
|
+
/**
|
|
14250
|
+
* Which registry items this project actually holds.
|
|
14251
|
+
*
|
|
14252
|
+
* Judged by the files on disk rather than by anything recorded at `add` time.
|
|
14253
|
+
* A lockfile of "what was installed" would be one more thing to drift from
|
|
14254
|
+
* reality, and the reality is right there in the directory.
|
|
14255
|
+
*
|
|
14256
|
+
* Answered from the index alone. Each entry already lists its files as
|
|
14257
|
+
* `<namespace>/<target>`, which is everything needed to test for one on disk —
|
|
14258
|
+
* so a bare `delacour diff` fetches one document and then only the items it
|
|
14259
|
+
* found, rather than the whole registry to discover the same thing.
|
|
14260
|
+
*/
|
|
14261
|
+
async function installedItems(entries, config) {
|
|
14262
|
+
const present = [];
|
|
14263
|
+
for (const entry of entries) {
|
|
14264
|
+
const paths = entry.files.map((file) => destination(file, config)).filter((path) => path !== null);
|
|
14265
|
+
if ((await Promise.all(paths.map(exists))).some(Boolean)) present.push(entry.name);
|
|
14258
14266
|
}
|
|
14267
|
+
return present;
|
|
14259
14268
|
}
|
|
14260
|
-
|
|
14261
|
-
|
|
14262
|
-
|
|
14269
|
+
/** `"ui/button/button.tsx"` → where that file would land, or `null` for an unknown namespace. */
|
|
14270
|
+
function destination(file, config) {
|
|
14271
|
+
const slash = file.indexOf("/");
|
|
14272
|
+
if (slash === -1) return null;
|
|
14273
|
+
const namespace = file.slice(0, slash);
|
|
14274
|
+
if (!isNamespace(namespace)) return null;
|
|
14275
|
+
return join(config.directories[namespace], file.slice(slash + 1));
|
|
14276
|
+
}
|
|
14277
|
+
async function exists(path) {
|
|
14278
|
+
return access(path).then(() => true, () => false);
|
|
14263
14279
|
}
|
|
14264
14280
|
//#endregion
|
|
14265
14281
|
//#region ../../node_modules/zod/v3/helpers/util.js
|
|
@@ -30107,6 +30123,16 @@ const COMPONENTS = [
|
|
|
30107
30123
|
title: "Accordion",
|
|
30108
30124
|
description: "Collapsible sections whose panels animate to their measured height."
|
|
30109
30125
|
},
|
|
30126
|
+
{
|
|
30127
|
+
name: "alert",
|
|
30128
|
+
title: "Alert",
|
|
30129
|
+
description: "A status message with a glyph picked from its status, a title, a description and an optional action."
|
|
30130
|
+
},
|
|
30131
|
+
{
|
|
30132
|
+
name: "avatar",
|
|
30133
|
+
title: "Avatar",
|
|
30134
|
+
description: "A person as a picture, with an initials fallback, a corner badge and an overlapping group."
|
|
30135
|
+
},
|
|
30110
30136
|
{
|
|
30111
30137
|
name: "badge",
|
|
30112
30138
|
title: "Badge",
|
|
@@ -30115,13 +30141,23 @@ const COMPONENTS = [
|
|
|
30115
30141
|
{
|
|
30116
30142
|
name: "bottom-sheet",
|
|
30117
30143
|
title: "Bottom Sheet",
|
|
30118
|
-
description: "A draggable sheet over the screen, on @
|
|
30144
|
+
description: "A draggable sheet over the screen: snap points, keyboard, sticky footer, scrollables, steps and a teleported portal, on @delacour/react-native-bottom-sheet."
|
|
30119
30145
|
},
|
|
30120
30146
|
{
|
|
30121
30147
|
name: "button",
|
|
30122
30148
|
title: "Button",
|
|
30123
30149
|
description: "A pressable action composed from parts, with variants, sizes and a loading state."
|
|
30124
30150
|
},
|
|
30151
|
+
{
|
|
30152
|
+
name: "calendar",
|
|
30153
|
+
title: "Calendar",
|
|
30154
|
+
description: "A month grid for picking a day, several days or a range, with swipe paging and month and year jump views."
|
|
30155
|
+
},
|
|
30156
|
+
{
|
|
30157
|
+
name: "card",
|
|
30158
|
+
title: "Card",
|
|
30159
|
+
description: "A content surface with a header, a body and a footer, built on Surface."
|
|
30160
|
+
},
|
|
30125
30161
|
{
|
|
30126
30162
|
name: "chart",
|
|
30127
30163
|
title: "Chart",
|
|
@@ -30132,6 +30168,46 @@ const COMPONENTS = [
|
|
|
30132
30168
|
title: "Checkbox",
|
|
30133
30169
|
description: "A checkbox with an indeterminate state, and a group that owns the selection."
|
|
30134
30170
|
},
|
|
30171
|
+
{
|
|
30172
|
+
name: "chip",
|
|
30173
|
+
title: "Chip",
|
|
30174
|
+
description: "An interactive pill: a filter that toggles, a tag, or a token with a remove control."
|
|
30175
|
+
},
|
|
30176
|
+
{
|
|
30177
|
+
name: "collapsible",
|
|
30178
|
+
title: "Collapsible",
|
|
30179
|
+
description: "One section shown and hidden by its own trigger, animated to its measured height."
|
|
30180
|
+
},
|
|
30181
|
+
{
|
|
30182
|
+
name: "context-menu",
|
|
30183
|
+
title: "Context Menu",
|
|
30184
|
+
description: "The actions that belong to a piece of content, reached by holding it — Menu's rows over a scrim, with a lifted preview."
|
|
30185
|
+
},
|
|
30186
|
+
{
|
|
30187
|
+
name: "dialog",
|
|
30188
|
+
title: "Dialog",
|
|
30189
|
+
description: "A centred card over a dimmed app that asks for a decision or a short input: confirm, alert dialog, form, with keyboard lift and focus handling."
|
|
30190
|
+
},
|
|
30191
|
+
{
|
|
30192
|
+
name: "drawer",
|
|
30193
|
+
title: "Drawer",
|
|
30194
|
+
description: "A panel that slides in from an edge and covers the app until dismissed: a navigation menu, a filter panel, a notifications tray, with swipe-to-dismiss and RTL-aware sides."
|
|
30195
|
+
},
|
|
30196
|
+
{
|
|
30197
|
+
name: "empty-state",
|
|
30198
|
+
title: "Empty State",
|
|
30199
|
+
description: "A placeholder for a list or screen with nothing in it: media, title, description and actions."
|
|
30200
|
+
},
|
|
30201
|
+
{
|
|
30202
|
+
name: "fab",
|
|
30203
|
+
title: "Fab",
|
|
30204
|
+
description: "A floating action button, extended with a label or unfolding a dial of related actions."
|
|
30205
|
+
},
|
|
30206
|
+
{
|
|
30207
|
+
name: "feedback",
|
|
30208
|
+
title: "Feedback",
|
|
30209
|
+
description: "A dialog for writing: the field in a recessed well, a send that waits on a promise, a draft kept across close, and steps that ease between heights."
|
|
30210
|
+
},
|
|
30135
30211
|
{
|
|
30136
30212
|
name: "field",
|
|
30137
30213
|
title: "Field",
|
|
@@ -30147,16 +30223,61 @@ const COMPONENTS = [
|
|
|
30147
30223
|
title: "Input",
|
|
30148
30224
|
description: "A text field, with a group that puts a prefix or suffix inside its border."
|
|
30149
30225
|
},
|
|
30226
|
+
{
|
|
30227
|
+
name: "item",
|
|
30228
|
+
title: "Item",
|
|
30229
|
+
description: "A row of media, text and actions for lists and settings, standalone or as a List Group row."
|
|
30230
|
+
},
|
|
30231
|
+
{
|
|
30232
|
+
name: "kpi",
|
|
30233
|
+
title: "Kpi",
|
|
30234
|
+
description: "One number, its change coloured by what it means, and a sparkline of how it got there, built on Card."
|
|
30235
|
+
},
|
|
30236
|
+
{
|
|
30237
|
+
name: "label",
|
|
30238
|
+
title: "Label",
|
|
30239
|
+
description: "A form control's name, with required, invalid and disabled states."
|
|
30240
|
+
},
|
|
30150
30241
|
{
|
|
30151
30242
|
name: "list-group",
|
|
30152
30243
|
title: "List Group",
|
|
30153
30244
|
description: "A surface grouping related rows, with dividers inserted automatically."
|
|
30154
30245
|
},
|
|
30246
|
+
{
|
|
30247
|
+
name: "menu",
|
|
30248
|
+
title: "Menu",
|
|
30249
|
+
description: "A list of actions anchored to the control that opens it — checkbox and radio rows, in-place submenus."
|
|
30250
|
+
},
|
|
30251
|
+
{
|
|
30252
|
+
name: "meter",
|
|
30253
|
+
title: "Meter",
|
|
30254
|
+
description: "A measurement on a fixed scale, coloured by where it falls — by regions, thresholds or whole blocks."
|
|
30255
|
+
},
|
|
30256
|
+
{
|
|
30257
|
+
name: "overlay",
|
|
30258
|
+
title: "Overlay",
|
|
30259
|
+
description: "The provider, teleported portal, scrim, presence lifecycle and back-button handling every dialog, drawer, popover, tooltip and toast is drawn with."
|
|
30260
|
+
},
|
|
30261
|
+
{
|
|
30262
|
+
name: "popover",
|
|
30263
|
+
title: "Popover",
|
|
30264
|
+
description: "A small panel anchored to its trigger that flips and shifts to stay on screen, with an arrow, a title, a close control and an optional scrim."
|
|
30265
|
+
},
|
|
30155
30266
|
{
|
|
30156
30267
|
name: "pressable",
|
|
30157
30268
|
title: "Pressable",
|
|
30158
30269
|
description: "The Gesture API press primitive: scale and fade feedback, haptics, disabled and busy states."
|
|
30159
30270
|
},
|
|
30271
|
+
{
|
|
30272
|
+
name: "progress",
|
|
30273
|
+
title: "Progress",
|
|
30274
|
+
description: "A bar showing how far a task has got, or a looping segment while it is under way."
|
|
30275
|
+
},
|
|
30276
|
+
{
|
|
30277
|
+
name: "progress-button",
|
|
30278
|
+
title: "Progress Button",
|
|
30279
|
+
description: "A button held to confirm: a fill grows while it is held and the action fires when it reaches the end."
|
|
30280
|
+
},
|
|
30160
30281
|
{
|
|
30161
30282
|
name: "provider",
|
|
30162
30283
|
title: "Provider",
|
|
@@ -30167,16 +30288,36 @@ const COMPONENTS = [
|
|
|
30167
30288
|
title: "Radio",
|
|
30168
30289
|
description: "A radio and the group that owns which one is selected."
|
|
30169
30290
|
},
|
|
30291
|
+
{
|
|
30292
|
+
name: "rating",
|
|
30293
|
+
title: "Rating",
|
|
30294
|
+
description: "A row of stars that reads or sets a score, by tap or by drag, in whole or half steps."
|
|
30295
|
+
},
|
|
30170
30296
|
{
|
|
30171
30297
|
name: "screen",
|
|
30172
30298
|
title: "Screen",
|
|
30173
30299
|
description: "A screen frame: pinned chrome, a content region, and whatever scrolls between them."
|
|
30174
30300
|
},
|
|
30301
|
+
{
|
|
30302
|
+
name: "selection-mode",
|
|
30303
|
+
title: "Selection Mode",
|
|
30304
|
+
description: "Pick several things at once — a long press enters the mode — then act on them from a bar, in a list, a grid or a strip."
|
|
30305
|
+
},
|
|
30175
30306
|
{
|
|
30176
30307
|
name: "separator",
|
|
30177
30308
|
title: "Separator",
|
|
30178
30309
|
description: "A one-pixel rule, hidden from assistive technology."
|
|
30179
30310
|
},
|
|
30311
|
+
{
|
|
30312
|
+
name: "skeleton",
|
|
30313
|
+
title: "Skeleton",
|
|
30314
|
+
description: "A placeholder that shimmers or pulses while content loads, in step across a group."
|
|
30315
|
+
},
|
|
30316
|
+
{
|
|
30317
|
+
name: "slide-button",
|
|
30318
|
+
title: "Slide Button",
|
|
30319
|
+
description: "A handle dragged across a rail to confirm an action a tap should not reach."
|
|
30320
|
+
},
|
|
30180
30321
|
{
|
|
30181
30322
|
name: "slider",
|
|
30182
30323
|
title: "Slider",
|
|
@@ -30187,6 +30328,26 @@ const COMPONENTS = [
|
|
|
30187
30328
|
title: "Spinner",
|
|
30188
30329
|
description: "An animated loading indicator drawn on the icon scale."
|
|
30189
30330
|
},
|
|
30331
|
+
{
|
|
30332
|
+
name: "stack-card",
|
|
30333
|
+
title: "Stack Card",
|
|
30334
|
+
description: "A deck taken one card at a time by throwing the top one off, with stamps, undo and a decline."
|
|
30335
|
+
},
|
|
30336
|
+
{
|
|
30337
|
+
name: "steps",
|
|
30338
|
+
title: "Steps",
|
|
30339
|
+
description: "A stepper for multi-step flows: completed, current and upcoming steps joined by a line."
|
|
30340
|
+
},
|
|
30341
|
+
{
|
|
30342
|
+
name: "surface",
|
|
30343
|
+
title: "Surface",
|
|
30344
|
+
description: "A rounded container on the theme's fill ladder, stepping to the next fill as it nests."
|
|
30345
|
+
},
|
|
30346
|
+
{
|
|
30347
|
+
name: "swipe",
|
|
30348
|
+
title: "Swipe",
|
|
30349
|
+
description: "A row that slides aside to reveal actions behind it, with a full swipe and a group that keeps one open."
|
|
30350
|
+
},
|
|
30190
30351
|
{
|
|
30191
30352
|
name: "switch",
|
|
30192
30353
|
title: "Switch",
|
|
@@ -30201,6 +30362,26 @@ const COMPONENTS = [
|
|
|
30201
30362
|
name: "text",
|
|
30202
30363
|
title: "Text",
|
|
30203
30364
|
description: "Typography: the type scale, weights and the page-level colours."
|
|
30365
|
+
},
|
|
30366
|
+
{
|
|
30367
|
+
name: "textarea",
|
|
30368
|
+
title: "Textarea",
|
|
30369
|
+
description: "A multiline text field sized in rows, with auto-grow and a character count."
|
|
30370
|
+
},
|
|
30371
|
+
{
|
|
30372
|
+
name: "toast",
|
|
30373
|
+
title: "Toast",
|
|
30374
|
+
description: "A brief message shown from anywhere, even outside React: stacked at an edge, swiped away, paused while touched, with a promise form and Alert's statuses."
|
|
30375
|
+
},
|
|
30376
|
+
{
|
|
30377
|
+
name: "toggle-button",
|
|
30378
|
+
title: "Toggle Button",
|
|
30379
|
+
description: "A button that stays pressed, alone or in a group with single or multiple selection."
|
|
30380
|
+
},
|
|
30381
|
+
{
|
|
30382
|
+
name: "tooltip",
|
|
30383
|
+
title: "Tooltip",
|
|
30384
|
+
description: "A short label on a long press, anchored to its control: hides itself, lets an outside tap through, and reads to a screen reader on the trigger."
|
|
30204
30385
|
}
|
|
30205
30386
|
];
|
|
30206
30387
|
//#endregion
|
|
@@ -30251,10 +30432,10 @@ Run them with the project's package manager — \`bunx\`, \`npx\`, \`pnpm dlx\`
|
|
|
30251
30432
|
|
|
30252
30433
|
| You need | Run |
|
|
30253
30434
|
| --- | --- |
|
|
30254
|
-
| what exists, and what each one is for | \`bunx delacour@
|
|
30255
|
-
| one component's files, props, closure and packages | \`bunx delacour@
|
|
30256
|
-
| to add one | \`bunx delacour@
|
|
30257
|
-
| to find out why something renders wrong with no error | \`bunx delacour@
|
|
30435
|
+
| what exists, and what each one is for | \`bunx delacour@latest list\` |
|
|
30436
|
+
| one component's files, props, closure and packages | \`bunx delacour@latest view <name>\` |
|
|
30437
|
+
| to add one | \`bunx delacour@latest add <name>\` |
|
|
30438
|
+
| to find out why something renders wrong with no error | \`bunx delacour@latest doctor\` |
|
|
30258
30439
|
|
|
30259
30440
|
**Always \`list\` before writing any React Native UI in this project.** A component that exists here
|
|
30260
30441
|
should be added, never reimplemented.
|
|
@@ -30264,7 +30445,7 @@ Uniwind's transform, points Tailwind at where the components landed, and copies
|
|
|
30264
30445
|
root provider in. There is no separate setup step to run first.
|
|
30265
30446
|
|
|
30266
30447
|
\`\`\`bash
|
|
30267
|
-
bunx delacour@
|
|
30448
|
+
bunx delacour@latest add button input field
|
|
30268
30449
|
\`\`\`
|
|
30269
30450
|
|
|
30270
30451
|
It prints what the components need from npm and **installs nothing** unless told to. Add
|
|
@@ -30275,7 +30456,7 @@ If the layout is not the default — a monorepo where the components belong to a
|
|
|
30275
30456
|
source directory this project does not call \`src\` — run \`init\` deliberately instead:
|
|
30276
30457
|
|
|
30277
30458
|
\`\`\`bash
|
|
30278
|
-
bunx delacour@
|
|
30459
|
+
bunx delacour@latest init --src app --package-name @acme/ui --package-path packages/ui
|
|
30279
30460
|
\`\`\`
|
|
30280
30461
|
|
|
30281
30462
|
## Six things that fail silently
|
|
@@ -30354,7 +30535,7 @@ The palette is one file, \`styles/theme.css\`, in Uniwind's \`@variant light\` /
|
|
|
30354
30535
|
shape. Two ways to change it, and neither is editing a component:
|
|
30355
30536
|
|
|
30356
30537
|
- build one at <https://ui.delacour.co.nz/theme> and paste the \`theme.css\` tab over the file;
|
|
30357
|
-
- bring a web app's across — \`bunx delacour@
|
|
30538
|
+
- bring a web app's across — \`bunx delacour@latest theme ./globals.css\` converts it in place.
|
|
30358
30539
|
|
|
30359
30540
|
A literal \`.dark { … }\` block is the trap. Uniwind registers it as a **utility class named \`dark\`**
|
|
30360
30541
|
that contributes nothing — no error, and a dark theme that never arrives. That is what \`theme\`
|
|
@@ -30370,7 +30551,7 @@ converts, and what \`doctor\` fails on.
|
|
|
30370
30551
|
| composition, sizing, tokens, styling | \`references/rules.md\` beside this file |
|
|
30371
30552
|
| something rendering wrong | \`references/troubleshooting.md\` beside this file |
|
|
30372
30553
|
|
|
30373
|
-
There is also an MCP server — \`bunx delacour@
|
|
30554
|
+
There is also an MCP server — \`bunx delacour@latest mcp\` — which exposes \`list_components\`,
|
|
30374
30555
|
\`get_component\`, \`add_components\`, \`init_project\` and \`check_project\` as tools. Prefer it when the
|
|
30375
30556
|
host supports MCP; the commands above are the same functions and need nothing installed.
|
|
30376
30557
|
`
|
|
@@ -30506,7 +30687,7 @@ runtime, \`--radius-md\` does not, so anything computing a corner applies the mu
|
|
|
30506
30687
|
path: "references/troubleshooting.md",
|
|
30507
30688
|
content: `# Delacour UI — symptom to cause
|
|
30508
30689
|
|
|
30509
|
-
Run \`bunx delacour@
|
|
30690
|
+
Run \`bunx delacour@latest doctor\` first. Every symptom below is configuration, produces no error of
|
|
30510
30691
|
its own, and \`doctor\` names the file and the fix for nine of them. Changing component code before
|
|
30511
30692
|
running it is how an afternoon goes.
|
|
30512
30693
|
|
|
@@ -30515,14 +30696,14 @@ running it is how an afternoon goes.
|
|
|
30515
30696
|
| Components render, but unstyled | Nothing imports the CSS entry, or the import is not the **first** statement of the root layout |
|
|
30516
30697
|
| Styled in dev, unstyled in a release build | Tailwind's \`@source\` globs do not cover where the components landed — the scanner does not follow a monorepo's symlink, so the glob must be a real path |
|
|
30517
30698
|
| Some classes work, others do nothing | \`withUniwindConfig\` is present but not the **outermost** Metro wrapper; an outer wrapper replaced the transformer |
|
|
30518
|
-
| Light works, dark never arrives | \`theme.css\` has a literal \`.dark { … }\` block. Run \`bunx delacour@
|
|
30699
|
+
| Light works, dark never arrives | \`theme.css\` has a literal \`.dark { … }\` block. Run \`bunx delacour@latest theme\` to convert it |
|
|
30519
30700
|
| Classes resolve oddly, or the build fails naming no library | NativeWind is installed. It compiles \`className\` and wraps Metro too, and two Tailwind transforms cannot share one Metro config — move across with [Uniwind's migration guide](https://docs.uniwind.dev/migration-from-nativewind) |
|
|
30520
30701
|
| Presses do nothing | No \`GestureHandlerRootView\` above the component — mount \`DelacourProvider\` at the root |
|
|
30521
30702
|
| \`Unable to resolve "@/components/ui/button"\` | \`experiments.tsconfigPaths\` is not \`true\` in the Expo config; Metro ignores tsconfig paths without it |
|
|
30522
30703
|
| A red box naming a module you just installed | A native module needs a rebuilt dev client. \`npx expo run:ios\` — a JS reload will not pick it up |
|
|
30523
30704
|
| Every \`className\` is a type error | \`uniwind-env.d.ts\` is not inside the app's own \`tsconfig\` include. It is one triple-slash reference and only works from there |
|
|
30524
30705
|
| \`Ref<never>\`, or two copies of React Native's types | Two realpaths for one package. A Bun workspace needs \`linker = "hoisted"\` in \`bunfig.toml\` |
|
|
30525
|
-
| \`add\` overwrote something you had edited | A file that differs is a conflict and \`add\` asks; \`--overwrite\` answers yes. \`bunx delacour@
|
|
30706
|
+
| \`add\` overwrote something you had edited | A file that differs is a conflict and \`add\` asks; \`--overwrite\` answers yes. \`bunx delacour@latest diff <name>\` shows what upstream changed |
|
|
30526
30707
|
| A component on the docs site is not in the registry | The published CLI reads the registry at the commit it shipped against. \`--ref main\` opts into what has landed since |
|
|
30527
30708
|
|
|
30528
30709
|
## What \`doctor\` checks
|
|
@@ -30533,9 +30714,9 @@ actually imports the CSS entry · New Architecture · path aliases and \`tsconfi
|
|
|
30533
30714
|
copies of a native module.
|
|
30534
30715
|
|
|
30535
30716
|
\`\`\`bash
|
|
30536
|
-
bunx delacour@
|
|
30537
|
-
bunx delacour@
|
|
30538
|
-
bunx delacour@
|
|
30717
|
+
bunx delacour@latest doctor # a report, with a fix per failure
|
|
30718
|
+
bunx delacour@latest doctor --json # the same, for a tool to read
|
|
30719
|
+
bunx delacour@latest info # the resolved config, and what was detected
|
|
30539
30720
|
\`\`\`
|
|
30540
30721
|
|
|
30541
30722
|
## When none of it fits
|
|
@@ -30772,7 +30953,7 @@ function report(result, output) {
|
|
|
30772
30953
|
if (result.derived.length > 0) output.info(`${result.derived.length} filled in, derived from tokens the theme does define: ${result.derived.map((name) => name.slice(2)).join(", ")}.`);
|
|
30773
30954
|
for (const warning of result.warnings) output.warn(warning);
|
|
30774
30955
|
}
|
|
30775
|
-
const program = new Command().name("delacour").description("Add React Native components to your Expo app. You own the code.").version("0.1.0
|
|
30956
|
+
const program = new Command().name("delacour").description("Add React Native components to your Expo app. You own the code.").version("0.1.0");
|
|
30776
30957
|
/** Shared by every command that reads the registry. */
|
|
30777
30958
|
function withRegistryOptions(command) {
|
|
30778
30959
|
return command.addOption(new Option("--registry <url>", "registry to read from: a URL, github:owner/repo, or a local path")).addOption(new Option("--ref <ref>", "git ref to read the registry at").default(DEFAULT_REGISTRY_REF)).addOption(new Option("--offline", "use only what is already cached")).addOption(new Option("-c, --cwd <path>", "directory to work in").default(process.cwd()));
|