Skip to content

Commit

Permalink
feat(nvm): Add support for .nvmrc files (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmeku authored Mar 15, 2019
1 parent 3120664 commit 6c3e975
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 14 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v10.15.1
4 changes: 2 additions & 2 deletions apps/angular-console-e2e/src/integration/extensions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ describe('Extensions', () => {
});

// check that the schematics added by angular material are available
cy.wait(300); // Needed to de-flake this test
cy.wait(1000); // Needed to de-flake this test
goToGenerate();
cy.wait(300); // Needed to de-flake this test
cy.wait(1000); // Needed to de-flake this test
taskListHeaders($p => {
expect(texts($p)[1]).to.equal('@angular/material');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@
<ng-container *ngIf="(filteredProjects$ | async) as projects">
<div cdkVirtualScrollContent>
<ng-container
*cdkVirtualFor="
let p of projects;
trackBy: trackByProjectRoot;
templateCacheSize: 0
"
*cdkVirtualFor="let p of projects; trackBy: trackByProjectRoot"
>
<mat-list-item
class="favorite-icon"
Expand Down
9 changes: 7 additions & 2 deletions libs/server/src/lib/api/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { PseudoTerminalFactory } from '@angular-console/server';
import { platform } from 'os';
import { FileUtils } from '../utils/file-utils';
import { readJsonFile } from '../utils/utils';

import { existsSync } from 'fs';
import { join } from 'path';
let commandRunIndex = 0;

export const commands = new Commands(5, 15);
Expand All @@ -23,7 +24,11 @@ export function runCommand(
const workspace =
type === 'new' ? null : readJsonFile('./package.json', cwd).json.name;
const id = `${program} ${cmds.join(' ')} ${commandRunIndex++}`;
const command = `${programName} ${cmds.join(' ')}`;
let command = `${programName} ${cmds.join(' ')}`;
if (fileUtils.hasExecutable('nvm', cwd) || existsSync(join(cwd, '.nvmrc'))) {
const nvm = fileUtils.findClosestNvm(cwd);
command = `${nvm} exec ${command}`;
}

const factory = () => {
const commandRunning = pseudoTerminalFactory({
Expand Down
38 changes: 38 additions & 0 deletions libs/server/src/lib/utils/file-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,44 @@ export class FileUtils {
}
}

findClosestNvm(d: string): string {
if (this.hasExecutable('nvm', d)) {
return 'nvm';
}
const dir = this.convertToWslPath(d);
if (this.directoryExists(this.joinForCommandRun(dir, 'node_modules'))) {
if (platform() === 'win32' && !this.isWsl()) {
if (this.fileExistsSync(this.joinForCommandRun(dir, 'nvm.cmd'))) {
return this.joinForCommandRun(dir, 'nvm.cmd');
} else {
return this.joinForCommandRun(dir, 'node_modules', '.bin', 'nvm.cmd');
}
} else {
if (
this.fileExistsSync(
this.joinForCommandRun(dir, 'node_modules', '.bin', 'nvm')
)
) {
return this.joinForCommandRun(dir, 'node_modules', '.bin', 'nvm');
} else {
return this.joinForCommandRun(
dir,
'node_modules',
'nvm',
'bin',
'nvm'
);
}
}
} else {
const parent = path.dirname(dir);
if (parent === dir) {
throw new Error(`Cannot find 'nvm'`);
}
return this.findClosestNvm(parent);
}
}

joinForCommandRun(...p: string[]) {
return p
.splice(1)
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@
"@nrwl/schematics": "7.5.2",
"@schematics/angular": "7.3.1",
"@types/d3-hierarchy": "^1.1.6",
"@types/d3-shape": "^1.3.1",
"@types/d3-selection": "^1.4.1",
"@types/d3-shape": "^1.3.1",
"@types/d3-transition": "^1.1.4",
"@types/electron-store": "^1.3.0",
"@types/fontfaceobserver": "^0.0.6",
"@types/get-port": "^4.0.1",
"@types/graphql": "14.0.5",
"@types/jest": "^24.0.0",
"@types/node": "10.12.21",
"@types/node": "^10.12.21",
"@types/opn": "^5.1.0",
"@types/request": "^2.48.1",
"@types/semver": "^5.5.0",
Expand All @@ -136,11 +136,11 @@
"apollo-server-express": "^2.4.0",
"codelyzer": "4.5.0",
"cypress": "^3.1.5",
"dotenv": "6.2.0",
"d3-hierarchy": "^1.1.8",
"d3-shape": "^1.3.4",
"d3-selection": "^1.4.0",
"d3-shape": "^1.3.4",
"d3-transition": "^1.2.0",
"dotenv": "6.2.0",
"electron": "2.0.14",
"electron-builder": "20.28.4",
"electron-installer-dmg": "2.0.0",
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -850,11 +850,16 @@
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.44.tgz#1d4a798e53f35212fd5ad4d04050620171cd5b5e"
integrity sha512-k2tWTQU8G4+iSMvqKi0Q9IIsWAp/n8xzdZS4Q4YVIltApoMA00wFBFdlJnmoaK1/z7B0Cy0yPe6GgXteSmdUNw==

"@types/node@*", "@types/node@10.12.21", "@types/node@^10.1.0":
"@types/node@*", "@types/node@^10.1.0":
version "10.12.21"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.21.tgz#7e8a0c34cf29f4e17a36e9bd0ea72d45ba03908e"
integrity sha512-CBgLNk4o3XMnqMc0rhb6lc77IwShMEglz05deDcn2lQxyXEZivfwgYJu7SMha9V5XcrP6qZuevTHV/QrN2vjKQ==

"@types/node@^10.12.21":
version "10.14.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.14.1.tgz#8701cd760acc20beba5ffe0b7a1b879f39cb8c41"
integrity sha512-Rymt08vh1GaW4vYB6QP61/5m/CFLGnFZP++bJpWbiNxceNa6RBipDmb413jvtSf/R1gg5a/jQVl2jY4XVRscEA==

"@types/node@^8.0.24":
version "8.10.39"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.39.tgz#e7e87ad00364dd7bc485c940926345b8ec1a26ca"
Expand Down

0 comments on commit 6c3e975

Please sign in to comment.