From 5c091631bb600ad910803645a31fbf55b0119fa7 Mon Sep 17 00:00:00 2001 From: Tomer Epstein Date: Thu, 19 Dec 2019 15:09:06 +0200 Subject: [PATCH 01/11] overide env.getNpmPaths --- backend/package.json | 5 +++-- backend/src/yeomanui.ts | 28 ++++++++++++++++++++++-- backend/tests/yeomanui.spec.ts | 2 +- frontend/src/App.vue | 4 ++-- frontend/src/components/Header.vue | 6 +---- frontend/tests/App.spec.js | 2 +- frontend/tests/components/Header.spec.js | 11 +--------- 7 files changed, 35 insertions(+), 23 deletions(-) diff --git a/backend/package.json b/backend/package.json index 315e49409..7079c5f97 100644 --- a/backend/package.json +++ b/backend/package.json @@ -5,7 +5,7 @@ "license": "Apache 2.0", "description": "Provide rich user experience for Yeoman generators using VSCode extension or the browser", "repository": "https://github.com/SAP/yeoman-ui", - "version": "0.0.12", + "version": "0.0.13", "engines": { "vscode": "^1.38.0" }, @@ -53,7 +53,8 @@ "strip-ansi": "^6.0.0", "ws": "^7.2.0", "yeoman-environment": "^2.6.0", - "fs-extra": "^8.1.0" + "fs-extra": "^8.1.0", + "array-uniq": "^2.1.0" }, "devDependencies": { "@types/fs-extra": "^8.0.1", diff --git a/backend/src/yeomanui.ts b/backend/src/yeomanui.ts index b78958643..8f619bf25 100644 --- a/backend/src/yeomanui.ts +++ b/backend/src/yeomanui.ts @@ -13,6 +13,9 @@ import { IRpc } from "@sap-devx/webview-rpc/out.ext/rpc-common"; import Generator = require("yeoman-generator"); import { GeneratorType, GeneratorFilter } from "./filter"; +const uniq = require('array-uniq'); +const win32 = process.platform === 'win32'; + export interface IGeneratorChoice { name: string; message: string; @@ -73,7 +76,28 @@ export class YeomanUI { // on the other hand, we never look for newly installed generators... const promise: Promise = new Promise(resolve => { + const cwd = path.join(os.homedir(), "projects"); const env: Environment.Options = Environment.createEnv(); + const envGetNpmPaths: Function = env.getNpmPaths; + env.getNpmPaths = function (localOnly:any = false) { + // Start with the local paths derived by cwd in vscode + // (as opposed to cwd of the plugin host process which is what is used by yeoman/environment) + const localPaths: any[] = []; + + // Walk up the CWD and add `node_modules/` folder lookup on each level + cwd.split(path.sep).forEach((part, i, parts) => { + let lookup = path.join(...parts.slice(0, i + 1), 'node_modules'); + + if (!win32) { + lookup = `/${lookup}`; + } + + localPaths.push(lookup); + }); + const defaultPaths = envGetNpmPaths.call(this, localOnly); + + return uniq(localPaths.concat(defaultPaths)); + }; env.lookup(async () => this.onEnvLookup(env, resolve, this.genFilter)); }); @@ -141,7 +165,7 @@ export class YeomanUI { } console.log("done running yeomanui"); - message = `${generatorName} is done. Destination directory is ${destinationRoot}`; + message = `The '${generatorName}' project has been generated. You can find it at ${destinationRoot}`; this.doGeneratorDone(true, message); }); } catch (err) { @@ -211,7 +235,7 @@ export class YeomanUI { message: "", choices: _.compact(generatorChoices) }; - resolve({ name: "Generator Selection", questions: [generatorQuestion] }); + resolve({ name: "Select Generator", questions: [generatorQuestion] }); } private async getGeneratorChoice(genName: string, filter?: GeneratorFilter): Promise { diff --git a/backend/tests/yeomanui.spec.ts b/backend/tests/yeomanui.spec.ts index be98768dc..fbaf1674b 100644 --- a/backend/tests/yeomanui.spec.ts +++ b/backend/tests/yeomanui.spec.ts @@ -139,7 +139,7 @@ describe('yeomanui unit test', () => { message: "", choices: [] }; - expect(result).to.be.deep.equal({ name: "Generator Selection", questions: [generatorQuestion] }); + expect(result).to.be.deep.equal({ name: "Select Generator", questions: [generatorQuestion] }); }); it("get generators with type project", async () => { diff --git a/frontend/src/App.vue b/frontend/src/App.vue index e1d8d487d..3194bfbe2 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -189,7 +189,7 @@ export default { delete currentPrompt.status } } else { - // first prompt (Generator Selection) + // first prompt (Select Generator) prompt.active = true this.prompts.push(prompt) } @@ -253,7 +253,7 @@ export default { }, generatorDone(success, message) { if (this.currentPrompt.status === "pending") { - this.currentPrompt.name = "Done" + this.currentPrompt.name = "Confirmation" } this.doneMessage = message this.isDone = true diff --git a/frontend/src/components/Header.vue b/frontend/src/components/Header.vue index 0c49563d3..97471035a 100644 --- a/frontend/src/components/Header.vue +++ b/frontend/src/components/Header.vue @@ -1,11 +1,7 @@