Skip to content

Commit

Permalink
Update @nrwl/workspace to v10
Browse files Browse the repository at this point in the history
  • Loading branch information
abdatta committed Oct 3, 2020
1 parent c7121b9 commit 969b222
Show file tree
Hide file tree
Showing 12 changed files with 3,937 additions and 1,667 deletions.
14 changes: 4 additions & 10 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@
"apps/ngx-localstorage-demo/tsconfig.app.json",
"apps/ngx-localstorage-demo/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**",
"!apps/ngx-localstorage-demo/**"
]
"exclude": ["**/node_modules/**", "!apps/ngx-localstorage-demo/**"]
}
}
}
Expand All @@ -125,7 +122,7 @@
"tsConfig": "apps/ngx-localstorage-demo-e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**",
"!apps/ngx-localstorage-demo-e2e/**"
"!apps/ngx-localstorage-demo-e2e/**/*"
]
}
}
Expand Down Expand Up @@ -165,10 +162,7 @@
"libs/ngx-localstorage/tsconfig.lib.json",
"libs/ngx-localstorage/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**",
"!libs/ngx-localstorage/**"
]
"exclude": ["**/node_modules/**", "!libs/ngx-localstorage/**/*"]
}
}
}
Expand Down Expand Up @@ -198,4 +192,4 @@
"framework": "express"
}
}
}
}
11 changes: 9 additions & 2 deletions apps/ngx-localstorage-demo-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["jasmine", "jasminewd2", "node"]
}
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.e2e.json"
}
]
}
5 changes: 1 addition & 4 deletions apps/ngx-localstorage-demo/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"outDir": "../../dist/out-tsc",
"types": []
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"files": ["src/main.ts", "src/polyfills.ts"],
"include": ["**/*.d.ts"]
}
14 changes: 12 additions & 2 deletions apps/ngx-localstorage-demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["jasmine", "node"]
}
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
96 changes: 96 additions & 0 deletions decorate-angular-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* 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";
const { output } = require("@nrwl/workspace");

/**
* Paths to files being patched
*/
const angularCLIInitPath = "node_modules/@angular/cli/lib/cli/index.js";

/**
* Patch index.js to warn you if you invoke the undecorated Angular CLI.
*/
function patchAngularCLI(initPath) {
const angularCLIInit = fs.readFileSync(initPath, "utf-8").toString();

if (!angularCLIInit.includes("NX_CLI_SET")) {
fs.writeFileSync(
initPath,
`
if (!process.env['NX_CLI_SET']) {
const { output } = require('@nrwl/workspace');
output.warn({ title: 'The Angular CLI was invoked instead of the Nx CLI. Use "npx ng [command]" or "nx [command]" instead.' });
}
${angularCLIInit}
`
);
}
}

/**
* 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();
patchAngularCLI(angularCLIInitPath);
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",
});
}
14 changes: 12 additions & 2 deletions libs/ngx-localstorage/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"extends": "../../tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["jasmine", "node"]
}
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
12 changes: 3 additions & 9 deletions libs/ngx-localstorage/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
"experimentalDecorators": true,
"importHelpers": true,
"types": [],
"lib": [
"dom",
"es2018"
]
"lib": ["dom", "es2018"]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
Expand All @@ -25,8 +22,5 @@
"flatModuleId": "AUTOGENERATED",
"flatModuleOutFile": "AUTOGENERATED"
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}
"exclude": ["src/test.ts", "**/*.spec.ts"]
}
15 changes: 13 additions & 2 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"implicitDependencies": {
"angular.json": "*",
"package.json": "*",
"tsconfig.json": "*",
"tslint.json": "*",
"nx.json": "*"
"nx.json": "*",
"tsconfig.base.json": "*"
},
"projects": {
"ngx-localstorage": {
Expand All @@ -18,5 +18,16 @@
"tags": [],
"implicitDependencies": ["ngx-localstorage-demo"]
}
},
"tasksRunnerOptions": {
"default": {
"runner": "@nrwl/workspace/tasks-runners/default",
"options": {
"cacheableOperations": ["build", "lint", "test", "e2e"]
}
}
},
"affected": {
"defaultBase": "master"
}
}
Loading

0 comments on commit 969b222

Please sign in to comment.