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

Migrate NX #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
42 changes: 42 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"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": {}
},
{
"files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
"env": {
"jest": true
},
"rules": {}
}
]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ package-lock.json
# System Files
.DS_Store
Thumbs.db

.angular
80 changes: 50 additions & 30 deletions angular.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"version": 2,
"newProjectRoot": "packages",
"projects": {
"core": {
"root": "packages/core",
"sourceRoot": "packages/core/src",
"projectType": "library",
"prefix": "validation",
"targets": {
"build": {
"executor": "@angular-devkit/build-angular:ng-packagr",
"options": {
"tsConfig": "packages/core/tsconfig.lib.json",
"project": "packages/core/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "packages/core/tsconfig.lib.prod.json"
}
}
},
"test": {
"executor": "@angular-devkit/build-angular:karma",
"options": {
"main": "packages/core/src/test.ts",
"tsConfig": "packages/core/tsconfig.spec.json",
"karmaConfig": "packages/core/karma.conf.js"
}
}
}
},
"ngx-validate": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {
"generators": {
"@schematics/angular:class": {
"skipTests": true
},
Expand All @@ -29,9 +57,9 @@
"skipTests": true
}
},
"architect": {
"targets": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"executor": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/ngx-validate",
"index": "src/index.html",
Expand Down Expand Up @@ -79,7 +107,7 @@
"defaultConfiguration": ""
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"executor": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "ngx-validate:build"
},
Expand All @@ -90,13 +118,13 @@
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"executor": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "ngx-validate:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"executor": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
Expand All @@ -109,36 +137,28 @@
}
}
},
"core": {
"root": "packages/core",
"sourceRoot": "packages/core/src",
"validators": {
"projectType": "library",
"prefix": "validation",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:ng-packagr",
"root": "packages/validators",
"sourceRoot": "packages/validators/src",
"prefix": "ngx-validate",
"targets": {
"test": {
"executor": "@nrwl/jest:jest",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test executor different from other packages' test executor.

"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"tsConfig": "packages/core/tsconfig.lib.json",
"project": "packages/core/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "packages/core/tsconfig.lib.prod.json"
}
"jestConfig": "packages/validators/jest.config.ts",
"passWithNoTests": true
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"lint": {
"executor": "@nrwl/linter:eslint",
"options": {
"main": "packages/core/src/test.ts",
"tsConfig": "packages/core/tsconfig.spec.json",
"karmaConfig": "packages/core/karma.conf.js"
"lintFilePatterns": ["packages/validators/**/*.ts", "packages/validators/**/*.html"]
}
}
}
},
"tags": []
}
},
"cli": {
"analytics": false
}
}
73 changes: 73 additions & 0 deletions decorate-angular-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* This file decorates the Angular CLI with the Nx CLI to enable features such as computation caching
* and faster execution of tasks.
*
* It does this by:
*
* - Patching the Angular CLI to warn you in case you accidentally use the undecorated ng command.
* - Symlinking the ng to nx command, so all commands run through the Nx CLI
* - Updating the package.json postinstall script to give you control over this script
*
* The Nx CLI decorates the Angular CLI, so the Nx CLI is fully compatible with it.
* Every command you run should work the same when using the Nx CLI, except faster.
*
* Because of symlinking you can still type `ng build/test/lint` in the terminal. The ng command, in this case,
* will point to nx, which will perform optimizations before invoking ng. So the Angular CLI is always invoked.
* The Nx CLI simply does some optimizations before invoking the Angular CLI.
*
* To opt out of this patch:
* - Replace occurrences of nx with ng in your package.json
* - Remove the script from your postinstall script in your package.json
* - Delete and reinstall your node_modules
*/

const fs = require('fs');
const os = require('os');
const cp = require('child_process');
const isWindows = os.platform() === 'win32';
let output;
try {
output = require('@nrwl/workspace').output;
} catch (e) {
console.warn(
'Angular CLI could not be decorated to enable computation caching. Please ensure @nrwl/workspace is installed.',
);
process.exit(0);
}

/**
* Symlink of ng to nx, so you can keep using `ng build/test/lint` and still
* invoke the Nx CLI and get the benefits of computation caching.
*/
function symlinkNgCLItoNxCLI() {
try {
const ngPath = './node_modules/.bin/ng';
const nxPath = './node_modules/.bin/nx';
if (isWindows) {
/**
* This is the most reliable way to create symlink-like behavior on Windows.
* Such that it works in all shells and works with npx.
*/
['', '.cmd', '.ps1'].forEach(ext => {
if (fs.existsSync(nxPath + ext))
fs.writeFileSync(ngPath + ext, fs.readFileSync(nxPath + ext));
});
} else {
// If unix-based, symlink
cp.execSync(`ln -sf ./nx ${ngPath}`);
}
} catch (e) {
output.error({
title: 'Unable to create a symlink from the Angular CLI to the Nx CLI:' + e.message,
});
throw e;
}
}

try {
symlinkNgCLItoNxCLI();
require('nx/src/adapter/decorate-cli').decorateCli();
output.log({ title: 'Angular CLI has been decorated to enable computation caching.' });
} catch (e) {
output.error({ title: 'Decoration of the Angular CLI did not complete successfully' });
}
5 changes: 5 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { getJestProjects } from '@nrwl/jest';

export default {
projects: getJestProjects(),
};
3 changes: 3 additions & 0 deletions jest.preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const nxPreset = require('@nrwl/jest/preset').default;

module.exports = { ...nxPreset };
55 changes: 55 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"npmScope": "ngx-validate",
"affected": {
"defaultBase": "main"
},
"implicitDependencies": {
"package.json": {
"dependencies": "*",
"devDependencies": "*"
},
".eslintrc.json": "*"
},
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": ["build", "lint", "test", "e2e"]
}
}
},
"targetDefaults": {
"build": {
"dependsOn": ["^build"]
},
"test": {
"inputs": ["default", "^default", "{workspaceRoot}/jest.preset.js"]
},
"lint": {
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"]
}
},
"workspaceLayout": {
"appsDir": "packages",
"libsDir": "packages"
},
"cli": {
"analytics": false
},
"defaultProject": "ngx-validate",
"generators": {
"@nrwl/angular:application": {
"style": "css",
"linter": "eslint",
"unitTestRunner": "jest",
"e2eTestRunner": "none"
},
"@nrwl/angular:library": {
"linter": "eslint",
"unitTestRunner": "jest"
},
"@nrwl/angular:component": {
"style": "css"
}
}
}
Loading