Skip to content

Commit

Permalink
Handle nx monorepo setup (#724)
Browse files Browse the repository at this point in the history
Fixes #683

This PR adds nx monorepo setup handling by: 
- adding recognizing nx monorepo root 
- installing dependencies in the workspace root 
- adding nx-monorepo test-app 

**Remarks**:
- I created PR (nrwl/nx#28931) to nx so their
template doesn't fail in Radon IDE, we don't set their envs, my
understanding is that those are used internally by their CLI tool, and I
don't think want to implement that
- ~~iOS fails on `bundle install && bundle exec pod install` with
`EACCES: Permission denied` I'm investigating if it's related to IDE or
something else (i.e. my setup), manual `pod install` solves the issue~~
seems like problem with my setup (those files were owned by root,
reinstalling ruby using rbenv solved the problem)

### How Has This Been Tested: 
**Scenario:** Open iOS and Android, check if it builds.
**Tested on:** 
- workspace-example
- expo-52
- nx-monorepo
  • Loading branch information
maciekstosio authored Nov 19, 2024
1 parent c8a987d commit c1c8348
Show file tree
Hide file tree
Showing 74 changed files with 23,474 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class DependencyManager implements Disposable, DependencyManagerInterface

// all managers support the `install` command
await command(`${manager.name} install`, {
cwd: getAppRootFolder(),
cwd: manager.workspacePath ?? getAppRootFolder(),
quietErrorsOnExit: true,
});

Expand Down
20 changes: 12 additions & 8 deletions packages/vscode-extension/src/utilities/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ export function getDevServerScriptUrl() {

export function isWorkspaceRoot(dir: string) {
const packageJsonPath = path.join(dir, "package.json");
let workspaces;
try {
workspaces = require(packageJsonPath).workspaces;
} catch (e) {
// No package.json
return false;
}
const nxJsonPath = path.join(dir, "nx.json");

if (workspaces) {
if (fs.existsSync(nxJsonPath)) {
return true;
}

try {
const workspaces = require(packageJsonPath).workspaces;

if (workspaces) {
return true;
}
} catch (e) {
// No "workspace" property in package.json precede
}

return false;
}

Expand Down
13 changes: 13 additions & 0 deletions test-apps/nx-monorepo/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
114 changes: 114 additions & 0 deletions test-apps/nx-monorepo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
dist
tmp
/out-tsc

# dependencies
node_modules

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings

# System Files
.DS_Store
Thumbs.db

.nx/cache
.nx/workspace-data

# React Native

# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
**/.xcode.env.local

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof
.cxx/
*.keystore
!debug.keystore

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

**/fastlane/report.xml
**/fastlane/Preview.html
**/fastlane/screenshots
**/fastlane/test_output

# Bundle artifact
*.jsbundle

# Ruby / CocoaPods
**/Pods/
**/vendor/bundle/

# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

# testing
/coverage


vite.config.*.timestamp*
5 changes: 5 additions & 0 deletions test-apps/nx-monorepo/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Add files here to ignore them from prettier formatting
/dist
/coverage
/.nx/cache
/.nx/workspace-data
3 changes: 3 additions & 0 deletions test-apps/nx-monorepo/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
101 changes: 101 additions & 0 deletions test-apps/nx-monorepo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# NxMonorepo

<a alt="Nx logo" href="https://nx.dev" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="45"></a>

✨ Your new, shiny [Nx workspace](https://nx.dev) is ready ✨.

[Learn more about this workspace setup and its capabilities](https://nx.dev/nx-api/react-native?utm_source=nx_project&amp;utm_medium=readme&amp;utm_campaign=nx_projects) or run `npx nx graph` to visually explore what was created. Now, let's get you up to speed!

## Run tasks

To run the dev server for your app, use:

```sh
npx nx serve mobile
```

To create a production bundle:

```sh
npx nx build mobile
```

To see all available targets to run for a project, run:

```sh
npx nx show project mobile
```

These targets are either [inferred automatically](https://nx.dev/concepts/inferred-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) or defined in the `project.json` or `package.json` files.

[More about running tasks in the docs &raquo;](https://nx.dev/features/run-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

## Add new projects

While you could add new projects to your workspace manually, you might want to leverage [Nx plugins](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) and their [code generation](https://nx.dev/features/generate-code?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) feature.

Use the plugin's generator to create new projects.

To generate a new application, use:

```sh
npx nx g @nx/react-native:app demo
```

To generate a new library, use:

```sh
npx nx g @nx/react:lib mylib
```

You can use `npx nx list` to get a list of installed plugins. Then, run `npx nx list <plugin-name>` to learn about more specific capabilities of a particular plugin. Alternatively, [install Nx Console](https://nx.dev/getting-started/editor-setup?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) to browse plugins and generators in your IDE.

[Learn more about Nx plugins &raquo;](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) | [Browse the plugin registry &raquo;](https://nx.dev/plugin-registry?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

## Set up CI!

### Step 1

To connect to Nx Cloud, run the following command:

```sh
npx nx connect
```

Connecting to Nx Cloud ensures a [fast and scalable CI](https://nx.dev/ci/intro/why-nx-cloud?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects) pipeline. It includes features such as:

- [Remote caching](https://nx.dev/ci/features/remote-cache?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [Task distribution across multiple machines](https://nx.dev/ci/features/distribute-task-execution?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [Automated e2e test splitting](https://nx.dev/ci/features/split-e2e-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [Task flakiness detection and rerunning](https://nx.dev/ci/features/flaky-tasks?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

### Step 2

Use the following command to configure a CI workflow for your workspace:

```sh
npx nx g ci-workflow
```

[Learn more about Nx on CI](https://nx.dev/ci/intro/ci-with-nx#ready-get-started-with-your-provider?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

## Install Nx Console

Nx Console is an editor extension that enriches your developer experience. It lets you run tasks, generate code, and improves code autocompletion in your IDE. It is available for VSCode and IntelliJ.

[Install Nx Console &raquo;](https://nx.dev/getting-started/editor-setup?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

## Useful links

Learn more:

- [Learn more about this workspace setup](https://nx.dev/nx-api/react-native?utm_source=nx_project&amp;utm_medium=readme&amp;utm_campaign=nx_projects)
- [Learn about Nx on CI](https://nx.dev/ci/intro/ci-with-nx?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [Releasing Packages with Nx release](https://nx.dev/features/manage-releases?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
- [What are Nx plugins?](https://nx.dev/concepts/nx-plugins?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)

And join the Nx community:
- [Discord](https://go.nx.dev/community)
- [Follow us on X](https://twitter.com/nxdevtools) or [LinkedIn](https://www.linkedin.com/company/nrwl)
- [Our Youtube channel](https://www.youtube.com/@nxdevtools)
- [Our blog](https://nx.dev/blog?utm_source=nx_project&utm_medium=readme&utm_campaign=nx_projects)
25 changes: 25 additions & 0 deletions test-apps/nx-monorepo/apps/mobile/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = function (api) {
api.cache(true);

if (
process.env.NX_TASK_TARGET_TARGET === 'build' ||
process.env.NX_TASK_TARGET_TARGET?.includes('storybook')
) {
return {
presets: [
[
'@nx/react/babel',
{
runtime: 'automatic',
},
],
],
};
}

return {
presets: [
['module:@react-native/babel-preset', { useTransformReactJSX: true }],
],
};
};
9 changes: 9 additions & 0 deletions test-apps/nx-monorepo/apps/mobile/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source 'https://rubygems.org'

# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby ">= 2.6.10"

# Cocoapods 1.15 introduced a bug which break the build. We will remove the upper
# bound in the template on Cocoapods with next React Native release.
gem 'cocoapods', '>= 1.13', '< 1.15'
gem 'activesupport', '>= 6.1.7.5', '< 7.1.0'
Loading

0 comments on commit c1c8348

Please sign in to comment.