Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: suppport for NX monorepos #387

Merged
merged 41 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
191c51b
chore: added an example nx project
FinnDore Aug 3, 2022
42e2bc1
feat: added changes to support nx
FinnDore Aug 3, 2022
6ec3a98
chore: added some more fixes for express apps
FinnDore Aug 5, 2022
38d5772
chore: some fixes to make commonjs files run
FinnDore Aug 5, 2022
fef09d6
chore: some cleanup
FinnDore Aug 6, 2022
8e1e235
chore: added a help full comment :)
FinnDore Aug 6, 2022
fa724e8
chore: added a fallback of dist/apps/<app_name> for get output path
FinnDore Aug 7, 2022
caa2c52
test: fixed nx next test
FinnDore Aug 7, 2022
81ff864
test: added a test for a node-app
FinnDore Aug 7, 2022
5db7daa
chore: changed the nextjs port from 3000 to 80
FinnDore Aug 7, 2022
2500a3d
chore: fixed clippy issues 📎
FinnDore Aug 7, 2022
3a0c622
docs: some additions to the docs
FinnDore Aug 7, 2022
e7a1712
Merge branch 'railwayapp:main' into finndore/nixpack-nx
FinnDore Aug 8, 2022
8fa2798
chore: removed some stray logging that i added
FinnDore Aug 8, 2022
1f3d445
Merge branch 'finndore/nixpack-nx' of https://github.com/FinnDore/nix…
FinnDore Aug 8, 2022
279189b
chore: actioned some review feedback
FinnDore Aug 8, 2022
cd23611
lint: fixed lint waning
FinnDore Aug 8, 2022
06b203c
chore: removed the port arg from the next nx start command
FinnDore Aug 9, 2022
fcf0873
chore: removed unneeded networks
FinnDore Aug 9, 2022
b0153c5
chore: prevented each nx test building its image twice
FinnDore Aug 9, 2022
2e849fa
Merge branch 'railwayapp:main' into finndore/nixpack-nx
FinnDore Aug 10, 2022
b50f616
chore: moved nx structs to their own file
FinnDore Aug 10, 2022
c125304
chore: pub 🍻
FinnDore Aug 10, 2022
2a49a08
chore: removed the rm command from the build step
FinnDore Aug 11, 2022
c29f5d7
chore: updated start commands to use potential start target
FinnDore Aug 11, 2022
ab415db
chore: removed unneeded default
FinnDore Aug 11, 2022
3411184
chore: added two new projects and support for start commands
FinnDore Aug 11, 2022
eb76922
chore: re-ordered start commands
FinnDore Aug 11, 2022
84602d9
chore: build command change
FinnDore Aug 11, 2022
f0ccaae
chore: reverted changes to build command
FinnDore Aug 12, 2022
780dd68
chore: removed unneeded process.exit's
FinnDore Aug 12, 2022
4d44f8b
chore: moved to npx to run nx commands
FinnDore Aug 12, 2022
30bbda3
chore: removed default no need fot it
FinnDore Aug 12, 2022
aec5625
docs: updated start commands to include new options
FinnDore Aug 12, 2022
5e86bb1
chore: clippy fixes
FinnDore Aug 12, 2022
0fcdf71
Merge commit '5e860d9bfcaff721673fc2aef23914c9a3569c37' into finndore…
FinnDore Aug 12, 2022
c6515fa
chore: fixed merge issues
FinnDore Aug 12, 2022
a0ea70a
fixed: 📎
FinnDore Aug 16, 2022
b709d46
Merge branch 'main' into finndore/nixpack-nx
coffee-cup Aug 17, 2022
f9e08bc
lint fixes
coffee-cup Aug 17, 2022
f1904f6
add nx generate plan test snapshot
coffee-cup Aug 17, 2022
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
8 changes: 7 additions & 1 deletion docs/pages/docs/providers/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The Node provider sets the following environment variables:

- `NODE_ENV=production`
- `NPM_CONFIG_PRODUCTION=false`: Ensure that dev deps are always installed
- `NIXPACKS_NX_APP_NAME`: Provide a name of the NX app you want to build from your NX Monorepo

## Setup

Expand All @@ -38,12 +39,16 @@ All dependencies found in `packages.json` are installed with either NPM, Yarn, o

## Build

The build script found in `package.json` if it exists.
The build script found in `package.json` if it exists or if its an NX Monorepo `(npm|pnpm|yarn|bun) run build <NxAppName> --configuration=production`.

## Start

The start command priority is

- If its an NX Monorepo
- If the apps is a nexjs project: `npm run start -- p 90`
coffee-cup marked this conversation as resolved.
Show resolved Hide resolved
- If targets.build.options.main exists in the apps Project.json: `node <outputPath>/<mainFileName>.js` (e.g `node dist/apps/my-app/main.js`)
- Fallback: `node <outputPath/index.js>` (e.g `node dist/apps/my-app/index.js`)
- Start script in `package.json`
- Main file
- `index.js`
Expand All @@ -56,3 +61,4 @@ These directories are cached between builds
- Install (if Cypress detected): `~/.cache/Cypress`
- Build: `node_modules/.cache`
- Build (if NextJS detected): `.next/cache`
- Build (if its an NX Monorepo): `<outputPathForApp>`
35 changes: 35 additions & 0 deletions examples/node-nx/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nrwl/nx"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nrwl/nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [
{
"sourceTag": "*",
"onlyDependOnLibsWithTags": ["*"]
}
]
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nrwl/nx/typescript"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nrwl/nx/javascript"],
"rules": {}
}
]
}
39 changes: 39 additions & 0 deletions examples/node-nx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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
4 changes: 4 additions & 0 deletions examples/node-nx/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Add files here to ignore them from prettier formatting

/dist
/coverage
3 changes: 3 additions & 0 deletions examples/node-nx/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
94 changes: 94 additions & 0 deletions examples/node-nx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@


# NodeNx

This project was generated using [Nx](https://nx.dev).

<p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="450"></p>

🔎 **Smart, Fast and Extensible Build System**

## Adding capabilities to your workspace

Nx supports many plugins which add capabilities for developing different types of applications and different tools.

These capabilities include generating applications, libraries, etc as well as the devtools to test, and build projects as well.

Below are our core plugins:

- [React](https://reactjs.org)
- `npm install --save-dev @nrwl/react`
- Web (no framework frontends)
- `npm install --save-dev @nrwl/web`
- [Angular](https://angular.io)
- `npm install --save-dev @nrwl/angular`
- [Nest](https://nestjs.com)
- `npm install --save-dev @nrwl/nest`
- [Express](https://expressjs.com)
- `npm install --save-dev @nrwl/express`
- [Node](https://nodejs.org)
- `npm install --save-dev @nrwl/node`

There are also many [community plugins](https://nx.dev/community) you could add.

## Generate an application

Run `nx g @nrwl/react:app my-app` to generate an application.

> You can use any of the plugins above to generate applications as well.

When using Nx, you can create multiple applications and libraries in the same workspace.

## Generate a library

Run `nx g @nrwl/react:lib my-lib` to generate a library.

> You can also use any of the plugins above to generate libraries as well.

Libraries are shareable across libraries and applications. They can be imported from `@node-nx/mylib`.

## Development server

Run `nx serve my-app` for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

## Code scaffolding

Run `nx g @nrwl/react:component my-component --project=my-app` to generate a new component.

## Build

Run `nx build my-app` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.

## Running unit tests

Run `nx test my-app` to execute the unit tests via [Jest](https://jestjs.io).

Run `nx affected:test` to execute the unit tests affected by a change.

## Running end-to-end tests

Run `nx e2e my-app` to execute the end-to-end tests via [Cypress](https://www.cypress.io).

Run `nx affected:e2e` to execute the end-to-end tests affected by a change.

## Understand your workspace

Run `nx graph` to see a diagram of the dependencies of your projects.

## Further help

Visit the [Nx Documentation](https://nx.dev) to learn more.



## ☁ Nx Cloud

### Distributed Computation Caching & Distributed Task Execution

<p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-cloud-card.png"></p>

Nx Cloud pairs with Nx in order to enable you to build and test code more rapidly, by up to 10 times. Even teams that are new to Nx can connect to Nx Cloud and start saving time instantly.

Teams using Nx gain the advantage of building full-stack applications with their preferred framework alongside Nx’s advanced code generation and project dependency graph, plus a unified experience for both frontend and backend developers.

Visit [Nx Cloud](https://nx.app/) to learn more.
Empty file added examples/node-nx/apps/.gitkeep
Empty file.
18 changes: 18 additions & 0 deletions examples/node-nx/apps/express-app/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
16 changes: 16 additions & 0 deletions examples/node-nx/apps/express-app/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable */
export default {
displayName: 'express-app',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/express-app',
};
57 changes: 57 additions & 0 deletions examples/node-nx/apps/express-app/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/express-app/src",
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/node:webpack",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/apps/express-app",
"main": "apps/express-app/src/main.ts",
"tsConfig": "apps/express-app/tsconfig.app.json",
"assets": ["apps/express-app/src/assets"]
},
"configurations": {
"production": {
"optimization": true,
"extractLicenses": true,
"inspect": false,
"fileReplacements": [
{
"replace": "apps/express-app/src/environments/environment.ts",
"with": "apps/express-app/src/environments/environment.prod.ts"
}
]
}
}
},
"serve": {
"executor": "@nrwl/node:node",
"options": {
"buildTarget": "express-app:build"
},
"configurations": {
"production": {
"buildTarget": "express-app:build:production"
}
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/express-app/**/*.ts"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["coverage/apps/express-app"],
"options": {
"jestConfig": "apps/express-app/jest.config.ts",
"passWithNoTests": true
}
}
},
"tags": []
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const environment = {
production: true,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const environment = {
production: false,
};
19 changes: 19 additions & 0 deletions examples/node-nx/apps/express-app/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This is not a production server yet!
* This is only a minimal backend to get started.
*/

import * as express from 'express';

const app = express();

app.get('/api', (_req, res) => {
res.send({ message: 'Welcome to express-app!' });
});

const port = process.env.port || 3333;
const server = app.listen(port, () => {
console.log(`nx express app works`);
process.exit(0);
});
server.on('error', console.error);
10 changes: 10 additions & 0 deletions examples/node-nx/apps/express-app/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["node", "express"]
},
"exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"],
"include": ["**/*.ts"]
}
13 changes: 13 additions & 0 deletions examples/node-nx/apps/express-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
9 changes: 9 additions & 0 deletions examples/node-nx/apps/express-app/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"]
}
Loading