Skip to content

Commit 6259b7b

Browse files
In generator-aspnetcore-spa, use 'yarn' (if available) instead of 'npm' to restore dependencies because it's > 10x faster
1 parent dfcaae6 commit 6259b7b

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

templates/package-builder/src/yeoman/app/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as path from 'path';
22
import * as yeoman from 'yeoman-generator';
33
import * as uuid from 'node-uuid';
44
import * as glob from 'glob';
5+
import npmWhich = require('npm-which');
56
const yosay = require('yosay');
67
const toPascalCase = require('to-pascal-case');
78

@@ -80,6 +81,15 @@ class MyGenerator extends yeoman.Base {
8081
}
8182

8283
installingDeps() {
84+
// If available, restore dependencies using Yarn instead of NPM
85+
const yarnPath = getPathToExecutable('yarn');
86+
if (!!yarnPath) {
87+
this.log('Will restore NPM dependencies using \'yarn\' installed at ' + yarnPath);
88+
this.npmInstall = (pkgs, options, cb) => {
89+
return (this as any).runInstall(yarnPath, pkgs, options, cb);
90+
};
91+
}
92+
8393
this.installDependencies({
8494
npm: true,
8595
bower: false,
@@ -92,5 +102,13 @@ class MyGenerator extends yeoman.Base {
92102
}
93103
}
94104

105+
function getPathToExecutable(executableName: string) {
106+
try {
107+
return npmWhich(__dirname).sync(executableName);
108+
} catch(ex) {
109+
return null;
110+
}
111+
}
112+
95113
declare var module: any;
96114
(module).exports = MyGenerator;

templates/package-builder/src/yeoman/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "generator-aspnetcore-spa",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "Single-Page App templates for ASP.NET Core",
55
"author": "Microsoft",
66
"license": "Apache-2.0",
@@ -20,6 +20,7 @@
2020
"dependencies": {
2121
"glob": "^7.0.3",
2222
"node-uuid": "^1.4.7",
23+
"npm-which": "^3.0.1",
2324
"to-pascal-case": "^1.0.0",
2425
"yeoman-generator": "^0.20.2",
2526
"yeoman-option-or-prompt": "^1.0.2",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare module 'npm-which' {
2+
interface NpmWhichContext {
3+
sync(executableName: string): string;
4+
}
5+
6+
function defaultFunction(rootDir: string) : NpmWhichContext;
7+
export = defaultFunction;
8+
}

0 commit comments

Comments
 (0)