Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@
"nyc": "15.1.0",
"prettier": "3.2.5",
"shx": "0.3.4",
"typescript": "~4.5.0"
"typescript": "~5.1.0"
}
}
5 changes: 3 additions & 2 deletions packages/backend/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"require": ["ts-node/register/transpile-only", "source-map-support/register"],
"recursive": ["test/**/*.spec.ts"],
"require": ["ts-node/register"],
"extensions": ["ts"],
"spec": ["test/**/*.spec.ts"],
"timeout": 5000
}
1 change: 1 addition & 0 deletions packages/backend/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
!Wizard_logo.png
!dist/media
!dist/*.js
!dist/*.cjs
!resources
18 changes: 12 additions & 6 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "1.20.2",
"private": true,
"description": "Provides rich user experience for Yeoman generators.",
"type": "module",
"categories": [
"Other"
],
Expand All @@ -26,19 +27,21 @@
"name": "SAP SE"
},
"publisher": "SAPOS",
"main": "./dist/extension",
"main": "./dist/extension.cjs",
"scripts": {
"bundle": "webpack --mode production",
"ci": "npm-run-all clean compile coverage bundle frontend:copy package coverage:copy",
"clean": "shx rm -rf ./dist ./coverage *.vsix",
"clean:frontend": "cd ./dist && shx rm -rf ./media",
"compile": "tsc",
"compile:watch": "tsc -watch",
"coverage": "nyc mocha",
"coverage": "vitest run --coverage",
"coverage:copy": "shx mkdir -p ../../coverage && shx cp -u ./coverage/lcov.info ../../coverage/lcov_backend.info",
"frontend:copy": "npm-run-all clean:frontend && shx cp -r ../frontend/dist/. ./dist/media/",
"package": "vsce package --yarn",
"test": "mocha",
"test": "vitest run",
"test:watch": "vitest",
"test:ui": "vitest --ui",
"webpack": "webpack --mode development",
"webpack-dev:watch": "webpack --mode development --watch",
"ws:egRun": "node ./dist/src/webSocketServer/exploregens.js",
Expand Down Expand Up @@ -198,27 +201,30 @@
"strip-ansi": "6.0.0",
"sudo-prompt": "9.2.1",
"titleize": "2.1.0",
"yeoman-environment": "3.3.0"
"yeoman-environment": "3.19.3"
},
"devDependencies": {
"@types/cheerio": "^0.22.31",
"@types/inquirer": "^7.3.3",
"@types/jest": "^30.0.0",
"@types/lodash": "^4.14.170",
"@types/node": "^14.14.44",
"@types/npm-registry-fetch": "^8.0.0",
"@types/object-hash": "^2.1.0",
"@types/sinon": "^17.0.3",
"@types/vscode": "^1.50.0",
"@types/webpack-env": "^1.16.2",
"@types/ws": "^7.4.5",
"@types/yeoman-environment": "^2.10.3",
"@vitest/ui": "^4.0.8",
"@vscode/vsce": "2.24.0",
"copy-webpack-plugin": "^12.0.2",
"jest": "^30.2.0",
"lcov-result-merger": "5.0.0",
"sinon": "^18.0.1",
"string-replace-loader": "3.0.3",
"ts-jest": "^29.4.5",
"ts-loader": "^9.2.3",
"ts-node": "^9.1.1",
"vitest": "^4.0.8",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4",
"ws": "8.17.1"
Expand Down
5 changes: 1 addition & 4 deletions packages/backend/src/logger/settings-changes-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,4 @@ export function listenToLogSettingsChanges(context: vscode.ExtensionContext) {
);
}

module.exports = {
listenToLogSettingsChanges,
logLoggerDetails,
};
// Converted to ESM: direct exports already defined above
7 changes: 1 addition & 6 deletions packages/backend/src/logger/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,4 @@ export function getSourceLocationTrackingSetting(): boolean {
return config.get(SOURCE_TRACKING_CONFIG_PROP);
}

module.exports = {
LOGGING_LEVEL_CONFIG_PROP,
SOURCE_TRACKING_CONFIG_PROP,
getLoggingLevelSetting,
getSourceLocationTrackingSetting,
};
// Converted to ESM: named exports used directly
12 changes: 6 additions & 6 deletions packages/backend/src/panels/YeomanUIPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ export class YeomanUIPanel extends AbstractWebviewPanel {
}

public notifyGeneratorsChange(args?: any[]) {
const yeomanUi = get(this, "yeomanui");
const yeomanUi = this.yeomanui;
this.installGens = !yeomanUi && isEmpty(args) ? undefined : args;
if (yeomanUi) {
if (!this.installGens) {
if (!isEmpty(this.installGens)) {
void yeomanUi._notifyGeneratorsChange();
} else {
void yeomanUi._notifyGeneratorsInstall(this.installGens);
if (isEmpty(this.installGens)) {
Env.loadNpmPath(true); // force to reload the env existing npm paths
}
if (isEmpty(this.installGens)) {
setTimeout(() => {
void yeomanUi._notifyGeneratorsChange();
this.installGens = undefined;
}
}, 500);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/replayUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Environment from "yeoman-environment";
import { IPrompt } from "@sap-devx/yeoman-ui-types";
import * as hash from "object-hash";
import TerminalAdapter = require("yeoman-environment/lib/adapter");
import hash from "object-hash";
import TerminalAdapter from "yeoman-environment/lib/adapter";

export enum ReplayState {
Replaying,
Expand Down
30 changes: 30 additions & 0 deletions packages/backend/src/types/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Ambient module declarations for internal packages lacking type definitions under ESM migration
// Allow importing internal types package without published typings in consumer package.
declare module "@sap-devx/yeoman-ui-types" {
export class AppWizard {
// Add minimal class for AppWizard
[key: string]: any;
}

export interface IPrompt {
name?: string;
description?: string;
questions?: any[];
[key: string]: any;
}

export interface IBannerProps {
[key: string]: any;
}

export enum Severity {
error = "error",
warning = "warning",
information = "information"
}

export enum MessageType {
prompt = "prompt",
notification = "notification"
}
}
14 changes: 9 additions & 5 deletions packages/backend/src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { existsSync } from "fs";
import { isWin32, NpmCommand } from "./npm";
import * as customLocation from "./customLocation";
import * as Environment from "yeoman-environment";
import TerminalAdapter = require("yeoman-environment/lib/adapter");
import TerminalAdapter from "yeoman-environment/lib/adapter";
import { IChildLogger } from "@vscode-logging/logger";
import { getClassLogger } from "../logger/logger-wrapper";

Expand Down Expand Up @@ -90,20 +90,23 @@ class EnvUtil {
opts?: Environment.Options,
adapter?: TerminalAdapter,
): Environment<Environment.Options> {
return Environment.createEnv(args, opts, adapter);
// @ts-ignore createEnv is available at runtime; types are incomplete
return (Environment as any).createEnv(args, opts, adapter);
}

private unloadGeneratorModules(genNamespace: string): void {
let generatorName;
const genShortName = Environment.namespaceToName(genNamespace);
// @ts-ignore namespaceToName exists at runtime
const genShortName = (Environment as any).namespaceToName(genNamespace) as string;
if (genShortName.startsWith("@")) {
const firstSlashIndex = genShortName.indexOf("/");
generatorName = `${GENERATOR}${genShortName.substring(firstSlashIndex + 1)}`;
} else {
generatorName = `${GENERATOR}${genShortName}`;
}

const keys = Object.keys(require.cache);
// @ts-ignore require cache available in CJS context when bundled
const keys = Object.keys(require.cache);
for (const key of keys) {
if (key.includes(generatorName)) {
delete require.cache[key];
Expand Down Expand Up @@ -216,7 +219,8 @@ class EnvUtil {
}

public getGeneratorFullName(genNamespace: string): string {
const genName = Environment.namespaceToName(genNamespace);
// @ts-ignore namespaceToName exists at runtime
const genName = (Environment as any).namespaceToName(genNamespace) as string;
const parts = _.split(genName, "/");
return _.size(parts) === 1 ? `${GENERATOR}${genName}` : `${parts[0]}/${GENERATOR}${parts[1]}`;
}
Expand Down
6 changes: 4 additions & 2 deletions packages/backend/src/utils/log.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import stripAnsi = require("strip-ansi");
import stripAnsi from "strip-ansi";
import { get } from "lodash";
import { Output } from "../output";
import { YeomanUI } from "../yeomanui";

module.exports = (output: Output, yeomanUi: YeomanUI) => {
const createLog = (output: Output, yeomanUi: YeomanUI) => {
function pad(methodName: string) {
const max = "identical".length;
const delta = max - methodName.length;
Expand Down Expand Up @@ -84,3 +84,5 @@ module.exports = (output: Output, yeomanUi: YeomanUI) => {

return log;
};

export default createLog;
2 changes: 2 additions & 0 deletions packages/backend/src/utils/shellJsWorkarounds.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Use CommonJS style import for 'module' to retain original types
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Module = require("module");

// Replaces shelljs.exec method when execResult is undefined
Expand Down
7 changes: 7 additions & 0 deletions packages/backend/src/utils/vscodeProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,20 @@ const ViewColumn = {
Two: 2,
};

const ProgressLocation = {
SourceControl: 1,
Window: 10,
Notification: 15,
};

const vscodeMock = {
Uri,
context,
workspace,
commands,
window,
ViewColumn,
ProgressLocation,
};

export const getVscodeMock = () => vscodeMock;
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/vscode-output.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from "vscode";
import stripAnsi = require("strip-ansi");
import stripAnsi from "strip-ansi";
import { Output } from "./output";

export class GeneratorOutput implements Output {
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/webSocketServer/exploregens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class ExploreGensWebSocketServer {
wss.on("connection", (ws) => {
console.log("exploregens: new ws connection");
const childLogger: IChildLogger = getConsoleWarnLogger();
this.rpc = new RpcExtensionWebSockets(ws, childLogger);
// @ts-ignore WebSocket type incompatibility under ESM build
this.rpc = new RpcExtensionWebSockets(ws as any, childLogger);

this.exploreGens = new ExploreGens(childLogger, vscode.context);
this.exploreGens.init(this.rpc);
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/webSocketServer/server-output.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RpcCommon } from "@sap-devx/webview-rpc/out.ext/rpc-common";
import stripAnsi = require("strip-ansi");
import stripAnsi from "strip-ansi";
import { Output } from "../output";

export class ServerOutput implements Output {
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/webSocketServer/youi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class YeomanUIWebSocketServer {
wss.on("connection", (ws) => {
console.log("new ws connection");
const childLogger: IChildLogger = getConsoleWarnLogger();
this.rpc = new RpcExtensionWebSockets(ws, childLogger);
// @ts-ignore WebSocket type incompatibility under ESM build
this.rpc = new RpcExtensionWebSockets(ws as any, childLogger);
const serverOutput = new ServerOutput(this.rpc, true);
const youiEvents: YouiEvents = new ServerYouiEvents(this.rpc);

Expand Down
10 changes: 6 additions & 4 deletions packages/backend/src/yeomanui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { promises } from "fs";
import * as _ from "lodash";
import * as inquirer from "inquirer";
import { ReplayUtils, ReplayState } from "./replayUtils";
const datauri = require("datauri"); // eslint-disable-line @typescript-eslint/no-var-requires
const titleize = require("titleize"); // eslint-disable-line @typescript-eslint/no-var-requires
const humanizeString = require("humanize-string"); // eslint-disable-line @typescript-eslint/no-var-requires
import datauri from "datauri";
import titleize from "titleize";
import humanizeString from "humanize-string";
import * as defaultImage from "./images/defaultImage";
import { YouiAdapter } from "./youi-adapter";
import { YouiEvents } from "./youi-events";
Expand All @@ -20,6 +20,8 @@ import { Env, EnvGen, GeneratorData, GeneratorNotFoundError } from "./utils/env"
import { vscode, getVscode } from "./utils/vscodeProxy";
import * as Generator from "yeoman-generator";
import * as Environment from "yeoman-environment";
// @ts-ignore incomplete types
const EnvironmentAny: any = Environment as any;
import { Questions } from "yeoman-environment/lib/adapter";
import { State } from "./utils/promise";
import { Constants } from "./utils/constants";
Expand Down Expand Up @@ -598,7 +600,7 @@ export class YeomanUI {
this.logger.debug(error);
}

const genName = Environment.namespaceToName(genNamespace);
const genName = EnvironmentAny.namespaceToName(genNamespace);
const genMessage = _.get(packageJson, "description", YeomanUI.defaultMessage);
const genDisplayName = _.get(packageJson, "displayName", "");
const genPrettyName = _.isEmpty(genDisplayName) ? titleize(humanizeString(genName)) : genDisplayName;
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/youi-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { YeomanUI } from "./yeomanui";
import { YouiEvents } from "./youi-events";
const yoUiLog = require("./utils/log"); // eslint-disable-line @typescript-eslint/no-var-requires
import createLog from "./utils/log";
import { isFunction, get } from "lodash";
const chalk = require("chalk");
import chalk from "chalk";
import { Questions } from "yeoman-environment/lib/adapter";
import { Output } from "./output";

Expand All @@ -20,7 +20,7 @@ export class YouiAdapter {

public setYeomanUI(yeomanui: YeomanUI) {
this.yeomanui = yeomanui;
this.log = yoUiLog(this.output, this.yeomanui);
this.log = createLog(this.output, this.yeomanui);
}

get colorDiffAdded() {
Expand Down
Loading
Loading