Skip to content

Commit

Permalink
feat(nx-melos): add nx-melos plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tinesoft committed Jan 10, 2023
1 parent d1cf8c7 commit 4fb5da8
Show file tree
Hide file tree
Showing 42 changed files with 926 additions and 94 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/run-e2e-tests-nx-melos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Run e2e Tests for nx-melos

on:
push:
branches: [ develop ]
paths: [ "nx.json", "package.json", "workspace.json", "packages/common/**", "packages/nx-melos/**" ]
pull_request:
branches: [ develop ]
paths: [ "nx.json", "package.json", "workspace.json", "packages/common/**", "packages/nx-melos/**" ]

jobs:
run_e2e:
name: Run e2e Tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [16.x]
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Use Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17

- name: Use Flutter
uses: subosito/flutter-action@v2
with:
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' # optional, change this to force refresh cache
cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:' # optional, change this to specify the cache path
architecture: x64 # optional, x64 or arm64

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
shell: bash

- name: Cache Yarn
uses: actions/cache@v3
env:
cache-name: yarn
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ matrix.os }}-node-${{ matrix.node-version }}-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ matrix.os }}-node-${{ matrix.node-version }}-${{ env.cache-name }}-
- name: Install packages
run: yarn install --frozen-lockfile

- name: Run e2e tests
env:
NX_E2E_CI_CACHE_KEY: e2e-gha-${{ matrix.os }}-${{ matrix.node-version }}
NX_RUN_GROUP: ${{ github.run_id }}-${{ matrix.os }}-${{ matrix.node-version }}
run: |
yarn ts-node -P ./tools/tsconfig.tools.json ./tools/patch-nx-project.ts
yarn nx e2e nx-melos-e2e
2 changes: 1 addition & 1 deletion .github/workflows/run-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ jobs:
${{ matrix.os }}-node-${{ matrix.node-version }}-${{ env.cache-name }}-
- run: yarn install --frozen-lockfile
- run: yarn run affected:test -- --base=origin/develop --parallel=5 --exclude=smoke
- run: yarn run affected:test -- --base=origin/develop --parallel=6 --exclude=smoke


1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/dist
/tmp
/out-tsc
/bin

# dependencies
/node_modules
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn nx affected:test --parallel=5 --exclude=smoke
yarn nx affected:test --parallel=6 --exclude=smoke
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Status | Name | Description
✅ | [nx-flutter](packages/nx-flutter) | [Nx](https://nx.dev) plugin adding first class support for [Flutter](https://flutter.dev) in your Nx workspace
✅ | [nx-quarkus](packages/nx-quarkus) | [Nx](https://nx.dev) plugin to generate, run, package, build (and more) [Quarkus](https://quarkus.io) projects inside your Nx workspace
✅ | [nx-micronaut](packages/nx-micronaut) | [Nx](https://nx.dev) plugin to generate, run, package, build (and more) [Micronaut](https://micronaut.io) projects inside your Nx workspace
✅ | [nx-melos](packages/nx-melos) | [Nx](https://nx.dev) plugin adding first class support for [Melos](https://melos.invertase.dev/) in your Nx workspace


## License
Expand Down
15 changes: 15 additions & 0 deletions e2e/nx-melos-e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable */
export default {
displayName: 'nx-melos-e2e',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
transform: {
'^.+\\.[tj]s$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/e2e/nx-melos-e2e',
};
17 changes: 17 additions & 0 deletions e2e/nx-melos-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "nx-melos-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"sourceRoot": "e2e/nx-melos-e2e/src",
"targets": {
"e2e": {
"executor": "@nrwl/nx-plugin:e2e",
"options": {
"target": "nx-melos:build",
"jestConfig": "e2e/nx-melos-e2e/jest.config.ts"
}
}
},
"tags": [],
"implicitDependencies": ["nx-melos"]
}
53 changes: 53 additions & 0 deletions e2e/nx-melos-e2e/tests/nx-melos.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
checkFilesExist,
runNxCommandAsync,
} from '@nrwl/nx-plugin/testing';
import { ensureNxProjectWithDeps } from '@nxrocks/common/testing';

describe('nx-melos e2e', () => {

beforeAll(async () => {

ensureNxProjectWithDeps('@nxrocks/nx-melos', 'dist/packages/nx-melos',
[{ name: '@nxrocks/common', path: 'dist/packages/common' }]);
}, 600000);

afterAll(() => {
// `nx reset` kills the daemon, and performs
// some work which can help clean up e2e leftovers
runNxCommandAsync('reset');
});

beforeEach(() => {
});

afterEach(() => {
jest.resetAllMocks();
});

it('should initialize melos in the workspace', async() => {

await runNxCommandAsync(`generate @nxrocks/nx-melos:init --scriptNameSeparator="-"`);

const scripts = [
{ name: 'melos-bootstrap', output: `NX Successfully ran target melos-bootstrap for project proj` },

];

let totalExecutorsTime = 0;
for (const script of scripts) {
const start = new Date().getTime();
const result = await runNxCommandAsync(script.name);
const end = new Date().getTime();
console.log(`${script.name} took ${end - start}ms`);
totalExecutorsTime += end - start;
expect(result.stdout).toContain(script.output);
}
console.log(`Total executors time: ${totalExecutorsTime}ms`);

expect(() =>
checkFilesExist(`melos.yaml`)
).not.toThrow();
}, 400000);

});
10 changes: 10 additions & 0 deletions e2e/nx-melos-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
]
}
9 changes: 9 additions & 0 deletions e2e/nx-melos-e2e/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"]
}
17 changes: 15 additions & 2 deletions e2e/smoke/tests/smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ describe('nxrocks smoke tests', () => {
{name: '@nxrocks/nx-spring-boot', path:'packages/nx-spring-boot'},
{name: '@nxrocks/nx-micronaut', path:'packages/nx-micronaut'},
{name: '@nxrocks/nx-quarkus', path:'packages/nx-quarkus'},
{name: '@nxrocks/nx-flutter', path:'packages/nx-flutter'}],
{name: '@nxrocks/nx-flutter', path:'packages/nx-flutter'},
{name: '@nxrocks/nx-melos', path:'packages/nx-melos'}],
[{name:'@nxrocks/common', path:'packages/common'}],
workspaceRoot);

Expand Down Expand Up @@ -121,6 +122,11 @@ describe('nxrocks smoke tests', () => {
execSyncOptions(),
);

execSync(
`${runCommand} nx g @nxrocks/nx-melos:init`,
execSyncOptions(),
);

execSync(`git commit -am "chore: scaffold projects"`, execSyncOptions());

execSync(`${runCommand} nx print-affected --target build`, {
Expand All @@ -136,6 +142,7 @@ describe('nxrocks smoke tests', () => {
execSync(`${runCommand} nx build ${mnApp}`, execSyncOptions());
execSync(`${runCommand} nx clean ${flutterapp}`, execSyncOptions());
execSync(`${runCommand} nx clean ${flutterlib}`, execSyncOptions());
execSync(`${runCommand} nx melos-bootstrap`, execSyncOptions());

expect(true).toBeTruthy();
}, 1500000);
Expand Down Expand Up @@ -163,7 +170,7 @@ describe('nxrocks smoke tests', () => {

execSync('git init', execSyncOptions());

execSync(`${addDevCommand} @nxrocks/nx-spring-boot @nxrocks/nx-quarkus @nxrocks/nx-flutter @nxrocks/nx-micronaut`, execSyncOptions());
execSync(`${addDevCommand} @nxrocks/nx-spring-boot @nxrocks/nx-quarkus @nxrocks/nx-flutter @nxrocks/nx-micronaut @nxrocks/nx-melos`, execSyncOptions());

execSync(
`${runCommand} nx g @nxrocks/nx-spring-boot:new ${bootapp} --skip-format=false --projectType application --no-interactive`,
Expand Down Expand Up @@ -197,6 +204,10 @@ describe('nxrocks smoke tests', () => {
execSyncOptions(),
);

execSync(
`${runCommand} nx g @nxrocks/nx-melos:init`,
execSyncOptions(),
);

execSync(`git commit -am "chore: scaffold projects"`, execSyncOptions());

Expand All @@ -213,6 +224,8 @@ describe('nxrocks smoke tests', () => {
execSync(`${runCommand} nx build ${mnApp}`, execSyncOptions());
execSync(`${runCommand} nx clean ${flutterapp}`, execSyncOptions());
execSync(`${runCommand} nx clean ${flutterlib}`, execSyncOptions());
execSync(`${runCommand} nx melos-bootstrap`, execSyncOptions());


expect(true).toBeTruthy();
}, 1500000);
Expand Down
Binary file added images/melos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/nx-melos.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/nx-melos.pxz
Binary file not shown.
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"license": "MIT",
"scripts": {
"nx": "nx",
"build": "nx run-many --target build --parallel 5 --exclude smoke",
"test": "nx run-many --target test --parallel 5 --exclude smoke -- --runInBand",
"e2e": "nx run-many --target e2e --parallel 5 --exclude smoke -- --runInBand",
"build": "nx run-many --target build --parallel 6 --exclude smoke",
"test": "nx run-many --target test --parallel 6 --exclude smoke -- --runInBand",
"e2e": "nx run-many --target e2e --parallel 6 --exclude smoke -- --runInBand",
"lint": "nx workspace-lint && nx lint",
"many": "nx run-many",
"affected:build": "nx affected:build",
Expand All @@ -31,12 +31,12 @@
},
"private": true,
"dependencies": {
"@swc/helpers": "~0.3.3",
"@swc/helpers": "~0.4.11",
"hpagent": "^1.0.0",
"inquirer": "^8.2.0",
"js-yaml": "^4.1.0",
"node-fetch": "^2.6.1",
"tslib": "^2.0.0",
"tslib": "^2.3.0",
"unzipper": "^0.10.11",
"xmlbuilder2": "^3.0.2",
"xpath": "^0.0.32"
Expand All @@ -62,8 +62,8 @@
"@swc/core": "^1.2.173",
"@types/fs-extra": "^9.0.13",
"@types/inquirer": "^8.1.3",
"@types/jest": "28.1.8",
"@types/node": "18.7.1",
"@types/jest": "28.1.1",
"@types/node": "16.11.7",
"@types/node-fetch": "^2.5.8",
"@types/tmp": "^0.2.3",
"@types/unzipper": "^0.10.3",
Expand All @@ -75,17 +75,17 @@
"eslint-config-prettier": "8.1.0",
"fs-extra": "^10.0.0",
"husky": "^6.0.0",
"jest": "28.1.3",
"jest-environment-jsdom": "28.1.3",
"jest": "28.1.1",
"jest-environment-jsdom": "28.1.1",
"jest-mock": "28.1.3",
"jsonc-eslint-parser": "^2.1.0",
"nx": "15.4.5",
"prettier": "2.6.2",
"semantic-release": "^19.0.2",
"semantic-release-monorepo": "^7.0.5",
"ts-jest": "28.0.8",
"ts-jest": "28.0.5",
"ts-node": "10.9.1",
"tslib": "^2.0.0",
"tslib": "^2.3.0",
"tslint": "6.1.3",
"typescript": "4.8.4"
},
Expand All @@ -94,4 +94,3 @@
"url": "https://github.com/tinesoft/nxrocks.git"
}
}

3 changes: 3 additions & 0 deletions packages/common/src/lib/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ export const NX_SPRING_BOOT_PKG = '@nxrocks/nx-spring-boot';
export const NX_MICRONAUT = 'nx-micronaut';
export const NX_MICRONAUT_PKG = '@nxrocks/nx-micronaut';

export const NX_MELOS = 'nx-melos';
export const NX_MELOS_PKG = '@nxrocks/nx-melos';

export const COMMON = 'common';
export const COMMON_PKG = '@nxrocks/common';
25 changes: 25 additions & 0 deletions packages/nx-melos/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["./package.json", "./generators.json", "./executors.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nrwl/nx/nx-plugin-checks": "error"
}
}
]
}
7 changes: 7 additions & 0 deletions packages/nx-melos/.releaserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { createScopedReleaseConfig } = require('../../tools/release');

module.exports = createScopedReleaseConfig({
projectScope: 'nx-melos',
projectRoot: 'packages/nx-melos',
buildOutput: 'dist/packages/nx-melos',
});
Loading

0 comments on commit 4fb5da8

Please sign in to comment.