Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/install-without-peer-autoinstall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@reactivapp/cli': minor
---

One `npm install` for the whole project, and no more peers arriving uninvited.

The app template now lists `app/` as an npm workspace of the project root, so `reactiv app init` and `reactiv app upgrade` run a single `npm install` at the root that installs the library's dependencies and the shell's platform into one `node_modules`. Adding a package is one command at the root; `app/package.json` pins the platform and declares nothing else, and the sync check reports a library package that still appears there instead of asking you to mirror it. The installed-version, nested-copy, podspec and lockfile checks read the root tree and the root `package-lock.json`.

Every install also runs with `--legacy-peer-deps`, and the managed block the CLI writes into the project's `.npmrc` files sets `legacy-peer-deps=true` so your own `npm install` behaves the same way: npm no longer pulls in packages that a transitive dependency names as a peer. A fresh scaffold was failing with ERESOLVE when such a peer's newest release conflicted with the platform's `react-native`, even though nothing in the project used it.

Projects scaffolded before this release do not list the workspace; the CLI says so and asks for a fresh `reactiv app init`, into which `src/` moves unchanged. This release needs an app template that carries the workspace; an older template is refused at `init` with the same hint.
10 changes: 5 additions & 5 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ reactiv app init [--path <dir>] [--bundle-id <id>] [--app-uuid <uuid>] [--skip-i
| `--app-uuid` | Optional. The app UUID; defaults to the app your login is provisioned for (`reactiv whoami` shows it) and is refused when it differs. |
| `--path` | Parent directory to scaffold into. Default: the current directory. |
| `--bundle-id` | iOS bundle identifier. Default: `com.reactiv.<slug without dashes>`. |
| `--skip-install` | Skip `npm install` in the root and in `app/`. |
| `--skip-install` | Skip the `npm install` at the project root. |
| `--package-manager` | Only `npm` is supported today. |

What happens:

1. Your login decides the project identity, and nothing is asked: the merchant slug Reactiv provisioned for your key (lowercase letters, digits and dashes) becomes the folder name, the root package name, the app name in `reactiv.conf.js` and the shell, and the default bundle identifier; the app UUID comes from the same login.
2. The current platform version and its pinned `react` and `react-native` versions are read from the registry, and the template is downloaded with npm so the transcript shows where it came from.
3. The template is expanded into `<path>/<slug>`, which must not exist or must be empty. A `git init` follows, and the CLI refuses to continue if the scaffold's `.gitignore` does not ignore `.npmrc`.
4. Dependencies are installed in the root and in `app/` with install scripts turned off. The CLI tells you which packages declared one so you can run `npm rebuild` in `app/` if the native build needs it.
4. Dependencies are installed once at the project root (`app/` is an npm workspace of it) with install scripts turned off, development dependencies included whatever `NODE_ENV` says, and without npm's automatic peer installation (`--legacy-peer-deps`), so a peer a transitive package asks for never enters the project uninvited. The CLI tells you which packages declared an install script so you can run `npm rebuild` at the project root if the native build needs it.
5. An initial commit is created. If anything fails, what this run created is removed so you can fix the cause and run again.

### `reactiv app run ios`
Expand All @@ -74,7 +74,7 @@ reactiv app run ios [--skip-pods] [--simulator <name>]
| `--skip-pods` | Skip `pod install`. |
| `--simulator` | Simulator name to target, for example `"iPhone 16"`. Default: the booted iOS simulator when one is found; otherwise React Native's own choice. |

Before building, the CLI checks that `app/package.json` mirrors the library's dependencies, runs `pod install` in `app/ios`, checks that port 8081 is free, starts Metro in the background (log: `.reactiv-metro.log` in the project root) and runs `react-native run-ios` from `app/`. If the build fails, the Metro it started is stopped. This command does not refresh the registry token.
Before building, the CLI checks that `app/package.json` declares only the platform, runs `pod install` in `app/ios`, checks that port 8081 is free, starts Metro in the background (log: `.reactiv-metro.log` in the project root) and runs `react-native run-ios` from `app/`. If the build fails, the Metro it started is stopped. This command does not refresh the registry token.

### `reactiv app upgrade`

Expand All @@ -91,7 +91,7 @@ reactiv app upgrade [--to <version>]
What happens:

1. The target version and its pinned `react` and `react-native` are resolved from the registry. Without `--to`, a target older than the project's current version is refused.
2. `package.json` (`peerDependencies`) and `app/package.json` (`dependencies`) are updated to the new trio and both are reinstalled with install scripts off.
2. `package.json` (`peerDependencies`) and `app/package.json` (`dependencies`) are updated to the new trio and the project is reinstalled once at the root with install scripts off and `--legacy-peer-deps`.
3. The current template's toolchain files (`app/metro.config.js`, `app/babel.config.js`, `app/react-native.config.js`, `tsconfig.json`, `app/ios/Podfile`) are compared with yours. Differences are printed for you to apply by hand; the CLI does not overwrite them.
4. `npm run typecheck` runs at the project root.

Expand Down Expand Up @@ -126,7 +126,7 @@ The checks are listed in [Project layout](project-layout.md#what-reactiv-app-sub
| --- | --- |
| `~/.config/reactiv/credentials.json` | Your API key and the merchant it belongs to. Mode `0600`. Removed by `reactiv logout`. |
| `~/.cache/reactiv/token-cache.json` | The current registry token and its expiry. Mode `0600`. |
| `<project>/.npmrc` and `<project>/app/.npmrc` | A managed block between `# >>> reactiv` and `# <<< reactiv` markers holding the registry URLs and the token, so plain `npm install` works for the token's lifetime. The CLI refuses to write it into a file git does not ignore (where git can tell), into a symlink, or into a file readable by others (it makes the file `0600` first). Your own lines outside the block are kept, except `@reactivapp` and `@reactiv-submissions` registry lines and token lines for the registry host shape, which the block replaces. |
| `<project>/.npmrc` and `<project>/app/.npmrc` | A managed block between `# >>> reactiv` and `# <<< reactiv` markers holding the registry URLs, the token and `legacy-peer-deps=true`, so plain `npm install` works for the token's lifetime and resolves the same tree the CLI does. The CLI refuses to write it into a file git does not ignore (where git can tell), into a symlink, or into a file readable by others (it makes the file `0600` first). Your own lines outside the block are kept, except `@reactivapp` and `@reactiv-submissions` registry lines and token lines for the registry host shape, which the block replaces. |
| `<project>/.reactiv-metro.log` | Metro's output from `reactiv app run`. |

Registry tokens are short-lived (up to 12 hours). `reactiv login` and `reactiv whoami` run inside a project, and `app init`, `app upgrade` and `app submit`, refresh the token when it is missing or about to expire; `app run` and a login that only validates `REACTIV_API_KEY` do not. The CLI only accepts registry URLs from Reactiv's token service that are https and match the expected registry host shape; anything else is refused and nothing is written.
9 changes: 5 additions & 4 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,18 @@ This installs pods, starts Metro, and launches the app on the booted simulator (

## 5. Adding packages

Install at the root **and** in `app/`, always with an exact version:
Install at the project root, always with an exact version:

```bash
npm install --save-exact date-fns@4.1.0
cd app && npm install --save-exact date-fns@4.1.0 && cd ..
```

`app/` is an npm workspace of the root, so the one install serves the library and the shell.

`reactiv app submit` checks that:

- every package `src/` imports is declared in the root `package.json`, with an exact version (no `^`, `~`, tags, URLs or git links);
- `app/package.json` mirrors the library's dependencies, so what you ran is what you submit;
- `app/package.json` declares nothing but the platform; your packages live in the root `package.json`, so what you ran is what you submit;
- nothing the platform already provides is listed: `react`, `react-native` and the Reactiv packages are supplied for you and stay in `peerDependencies`;
- no dependency needs changes to the native iOS project, as far as the CLI can tell from a list of known libraries and your direct dependencies' CocoaPods podspecs. Pure JavaScript and TypeScript libraries are fine; a library with its own native setup cannot ship inside a customization, so ask Reactiv if you need one.

Expand Down Expand Up @@ -121,7 +122,7 @@ reactiv app upgrade # move to the current platform release
reactiv app upgrade --to 2610.9.3 # or pick a version
```

The CLI updates the platform version in both `package.json` files, reinstalls, and runs your typecheck. Then run `cd app/ios && pod install`. If the project no longer checks clean, the change stays in place and the output ends with the exact command to roll back.
The CLI updates the platform version in both `package.json` files, reinstalls once at the root, and runs your typecheck. Then run `cd app/ios && pod install`. If the project no longer checks clean, the change stays in place and the output ends with the exact command to roll back.

Some toolchain files (Metro, Babel, tsconfig, Podfile) are yours after the first install. When the current template differs, the CLI prints the new content and leaves the edit to you.

Expand Down
16 changes: 9 additions & 7 deletions docs/project-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
```
<your-app>/
├── reactiv.conf.js app identity: appName and appUuid
├── package.json the library: what you submit
├── package.json the library: what you submit; lists app/ as an npm workspace
├── package-lock.json one lockfile for the library and the shell
├── node_modules/ one shared install
├── src/
│ └── index.ts must export CustomCompositions and registerCustomComponents
├── tsconfig.json
├── .npmrc generated, git-ignored, never committed
└── app/ the runnable shell, never submitted
├── package.json mirrors the library's dependencies and pins the platform
├── package-lock.json
├── package.json pins the platform; declares nothing else
├── ios/
├── metro.config.js
├── babel.config.js
Expand All @@ -28,12 +29,13 @@ The root `package.json` and `src/` are the submission. Its `name` is the merchan
- `files`: `["src"]`.
- `dependencies`: packages your code imports, each with an exact version.
- `peerDependencies`: `@reactivapp/mobile`, `react` and `react-native` at the exact versions the app shell runs, plus any package the platform supplies that your code imports.
- `workspaces`: `["app"]`, so one `npm install` at the root installs the library's dependencies and the shell's platform into one `node_modules`. The CLI installs with `--legacy-peer-deps` and writes `legacy-peer-deps=true` into the project's managed `.npmrc` block, so npm never adds peers on its own, from the CLI or from your own `npm install`: a package your code needs is declared, never inherited.

`src/index.ts` must export `CustomCompositions` and `registerCustomComponents` as named values. Type-only and default exports do not count. Everything your code imports by relative path must live under `src/`.

## The app shell (`app/`)

`app/` wraps the library in a real React Native app so you can run it. It depends on `@reactivapp/mobile`, the Reactiv platform package, at a pinned version, and delegates its Metro, Babel and React Native configuration to the platform's toolchain. It is never submitted. Its `package.json` must list the same dependencies as the library at the same versions, because native modules autolink from there.
`app/` wraps the library in a real React Native app so you can run it. It is an npm workspace of the root: its `package.json` depends on `@reactivapp/mobile`, the Reactiv platform package, at a pinned version, and on nothing else; the root install hoists the platform and your library's dependencies into one `node_modules`, and the shell delegates its Metro, Babel and React Native configuration to the platform's toolchain. It is never submitted.

After the first install, the toolchain files are yours. `reactiv app upgrade` tells you when the current template's versions differ.

Expand All @@ -42,9 +44,9 @@ After the first install, the toolchain files are yours. `reactiv app upgrade` te
The checks run in this order. Steps 1 to 8 finish before the CLI contacts Reactiv; it then obtains a registry token (at which point the signed-in key must belong to this app's UUID and slug) and the next draft version, and steps 9 and 10 run on the staged copy before the publish.

1. **Project identity.** `reactiv.conf.js` exports `appUuid` and `appName`, and the name produces a usable slug.
2. **Layout.** `app/package.json` exists and the root manifest has a `files: ["src"]` entry and an entry point inside `src/`.
3. **Dependencies in sync.** The library's `dependencies` appear in `app/package.json` at the same versions; packages the platform provides are not in the library's `dependencies`; the platform trio is pinned identically in both; `app/node_modules` holds what the manifests declare, without duplicate copies.
4. **Submittable dependencies.** Every dependency is an exact registry version (no ranges, tags, URLs, git links or local paths); nothing in the `@reactivapp` or `@reactiv-submissions` scopes; no `overrides` in `app/package.json`; `app/package-lock.json` exists and records the installed platform version.
2. **Layout.** The root manifest lists `app` in `workspaces` and has a `files: ["src"]` entry and an entry point inside `src/`; `app/package.json` exists.
3. **Dependencies in sync.** `app/package.json` declares only the platform trio, never a library dependency; packages the platform provides are not in the library's `dependencies`; the platform trio is pinned identically in both; `node_modules` holds what the manifests declare, without duplicate copies.
4. **Submittable dependencies.** Every dependency is an exact registry version (no ranges, tags, URLs, git links or local paths); nothing in the `@reactivapp` or `@reactiv-submissions` scopes; no `overrides` in either manifest; `package-lock.json` exists and records the installed platform version.
5. **Native integration.** No dependency needs changes to the native project: a short list of known libraries with app-level setup is refused, and the CocoaPods podspecs of your direct dependencies are checked for build hooks. Gradle changes, Info.plist usage descriptions and entitlements are not detected here and are rejected at Reactiv's review instead.
6. **Forbidden content.** No `node_modules`, `build`, `dist`, `Pods`, `.git` or `DerivedData` under `src/`, and `src/` is not a symlink.
7. **Imports.** Every bare import in `src/` names a declared dependency or a platform package by its public entry, and every relative import stays inside `src/`. Node built-ins, package.json `imports` aliases, absolute paths and computed import specifiers are refused. Whether a relative import's target exists is not checked here; a missing file fails your typecheck and Reactiv's build.
Expand Down
12 changes: 6 additions & 6 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ Add `.npmrc` (no leading slash) to `.gitignore` so both the root and `app/` copi

## `package.json dependencies must be exact versions`

Reinstall the package with `--save-exact`, at the root and in `app/`.
Reinstall the package with `--save-exact` at the project root.

## `src/ imports packages that package.json does not declare`

Install the named package at the root and in `app/`. The message shows the exact command.
Install the named package at the project root. The message shows the exact command.

## `package.json dependencies include packages the platform provides`

Remove the named package from `dependencies`; it is supplied by the platform. The message tells you where it belongs.

## `app/package.json dependencies are out of sync with the library's package.json`
## `app/package.json declares packages that belong to the library's package.json`

Make both manifests declare the same packages at the same versions, then run `npm install` in `app/`. The message lists each difference.
Declare your packages in the root `package.json` only (`npm install --save-exact <name>@<version>` at the project root) and remove them from `app/package.json`; the shell pins nothing but the platform. The message names each one.

## `app/node_modules does not hold the declared versions`
## `node_modules does not hold the declared versions`

Run `npm install` in `app/`.
Run `npm install` at the project root.

## `entry point must export CustomCompositions and registerCustomComponents`

Expand Down
16 changes: 10 additions & 6 deletions packages/cli/src/commands/app/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ export class AppInit extends Command {
reactNativeVersion,
})

const libraryManifest = fs.existsSync(path.join(targetDir, 'package.json')) ? readManifest(path.join(targetDir, 'package.json')) : {}
if (!Array.isArray(libraryManifest.workspaces) || !libraryManifest.workspaces.includes(APP_DIR)) {
throw new Error(
`the downloaded @reactivapp/app-template does not list ${APP_DIR}/ as an npm workspace — it predates the single-install layout this CLI expects; ask Reactiv to publish the current template`,
)
}
if (!fs.existsSync(path.join(targetDir, APP_DIR, 'package.json')) || !fs.existsSync(path.join(targetDir, 'src'))) {
throw new Error(
`the downloaded @reactivapp/app-template has no ${APP_DIR}/ shell or src/ library — it predates the library layout this CLI expects; ask Reactiv to publish the current template`,
Expand All @@ -144,16 +150,14 @@ export class AppInit extends Command {
assertSameRegistries(registry, await ensureRegistryAuth(ctx, targetDir))

if (!flags['skip-install']) {
this.log('Installing library dependencies (npm, root)…')
this.log(`Installing dependencies (npm, one install for the library and ${APP_DIR}/)…`)
await installWithRegistryAuth(ctx, registry, targetDir, targetDir)
if (!fs.existsSync(path.join(targetDir, 'node_modules', '@reactivapp', 'mobile', 'package.json'))) {
this.warn('the root install did not add the @reactivapp/mobile peer (is legacy-peer-deps set in your npm config?) — editor types and `npm run typecheck` need it; the app still runs')
throw new Error(`the install did not place @reactivapp/mobile@${platformVersion} in node_modules — ${APP_DIR}/package.json must depend on it and the root package.json must list ${APP_DIR} in workspaces`)
}
this.log(`Installing app shell dependencies (npm, ${APP_DIR}/)…`)
await installWithRegistryAuth(ctx, registry, targetDir, path.join(targetDir, APP_DIR))
const skipped = skippedInstallScripts(path.join(targetDir, APP_DIR))
const skipped = skippedInstallScripts(targetDir)
if (skipped.length > 0) {
this.warn(`install scripts were not run in ${APP_DIR}/ for: ${skipped.join(', ')} — run \`npm rebuild\` in ${APP_DIR}/ if the app fails to build`)
this.warn(`install scripts were not run for: ${skipped.join(', ')} — run \`npm rebuild\` at the project root if the app fails to build`)
}
}

Expand Down
Loading
Loading