2121 * - Delete and reinstall your node_modules
2222 */
2323
24- const fs = require ( "fs" ) ;
25- const os = require ( "os" ) ;
26- const cp = require ( "child_process" ) ;
27- const isWindows = os . platform ( ) === "win32" ;
28- const { output } = require ( "@nrwl/workspace" ) ;
29-
30- /**
31- * Paths to files being patched
32- */
33- const angularCLIInitPath = "node_modules/@angular/cli/lib/cli/index.js" ;
34-
35- /**
36- * Patch index.js to warn you if you invoke the undecorated Angular CLI.
37- */
38- function patchAngularCLI ( initPath ) {
39- const angularCLIInit = fs . readFileSync ( initPath , "utf-8" ) . toString ( ) ;
40-
41- if ( ! angularCLIInit . includes ( "NX_CLI_SET" ) ) {
42- fs . writeFileSync (
43- initPath ,
44- `
45- if (!process.env['NX_CLI_SET']) {
46- const { output } = require('@nrwl/workspace');
47- output.warn({ title: 'The Angular CLI was invoked instead of the Nx CLI. Use "npx ng [command]" or "nx [command]" instead.' });
48- }
49- ${ angularCLIInit }
50- `
51- ) ;
52- }
24+ const fs = require ( 'fs' ) ;
25+ const os = require ( 'os' ) ;
26+ const cp = require ( 'child_process' ) ;
27+ const isWindows = os . platform ( ) === 'win32' ;
28+ let output ;
29+ try {
30+ output = require ( '@nrwl/workspace' ) . output ;
31+ } catch ( e ) {
32+ console . warn ( 'Angular CLI could not be decorated to enable computation caching. Please ensure @nrwl/workspace is installed.' ) ;
33+ process . exit ( 0 ) ;
5334}
5435
5536/**
@@ -58,39 +39,31 @@ ${angularCLIInit}
5839 */
5940function symlinkNgCLItoNxCLI ( ) {
6041 try {
61- const ngPath = " ./node_modules/.bin/ng" ;
62- const nxPath = " ./node_modules/.bin/nx" ;
42+ const ngPath = ' ./node_modules/.bin/ng' ;
43+ const nxPath = ' ./node_modules/.bin/nx' ;
6344 if ( isWindows ) {
6445 /**
6546 * This is the most reliable way to create symlink-like behavior on Windows.
6647 * Such that it works in all shells and works with npx.
6748 */
68- [ "" , ".cmd" , ".ps1" ] . forEach ( ( ext ) => {
69- if ( fs . existsSync ( nxPath + ext ) )
70- fs . writeFileSync ( ngPath + ext , fs . readFileSync ( nxPath + ext ) ) ;
49+ [ '' , '.cmd' , '.ps1' ] . forEach ( ext => {
50+ if ( fs . existsSync ( nxPath + ext ) ) fs . writeFileSync ( ngPath + ext , fs . readFileSync ( nxPath + ext ) ) ;
7151 } ) ;
7252 } else {
7353 // If unix-based, symlink
7454 cp . execSync ( `ln -sf ./nx ${ ngPath } ` ) ;
7555 }
76- } catch ( e ) {
77- output . error ( {
78- title :
79- "Unable to create a symlink from the Angular CLI to the Nx CLI:" +
80- e . message ,
81- } ) ;
56+ }
57+ catch ( e ) {
58+ output . error ( { title : 'Unable to create a symlink from the Angular CLI to the Nx CLI:' + e . message } ) ;
8259 throw e ;
8360 }
8461}
8562
8663try {
8764 symlinkNgCLItoNxCLI ( ) ;
88- patchAngularCLI ( angularCLIInitPath ) ;
89- output . log ( {
90- title : "Angular CLI has been decorated to enable computation caching." ,
91- } ) ;
92- } catch ( e ) {
93- output . error ( {
94- title : "Decoration of the Angular CLI did not complete successfully" ,
95- } ) ;
65+ require ( '@nrwl/cli/lib/decorate-cli' ) . decorateCli ( ) ;
66+ output . log ( { title : 'Angular CLI has been decorated to enable computation caching.' } ) ;
67+ } catch ( e ) {
68+ output . error ( { title : 'Decoration of the Angular CLI did not complete successfully' } ) ;
9669}
0 commit comments