Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dev deps and fix code smells for V3 #3130

Merged
merged 6 commits into from
Sep 23, 2024
Merged
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@typescript-eslint/parser": "^5.53.0",
"@vscode/l10n-dev": "^0.0.35",
"@vscode/test-electron": "^1.6.0",
"@vscode/vsce": "^2.26.0",
"@vscode/vsce": "^3.1.0",
"concurrently": "^6.5.1",
"esbuild-loader": "^4.1.0",
"eslint": "^8.34.0",
Expand All @@ -48,13 +48,13 @@
"mocha-junit-reporter": "^2.2.0",
"mocha-multi-reporters": "^1.5.1",
"node-loader": "^2.0.0",
"prettier": "2.6.0",
"prettier": "^2.6.0",
"rimraf": "^3.0.2",
"terser-webpack-plugin": "^5.3.10",
"ts-jest": "^29.0.3",
"tsx": "^4.9.3",
"typescript": "^5.3.3",
"webpack": "^5.89.0",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4"
},
"pnpm": {
Expand Down
4 changes: 1 addition & 3 deletions packages/zowe-explorer-api/__mocks__/mockUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ export class MockedProperty {
return;
}

const isValFn = typeof value === "function";

if (isValFn || (typeof descriptor?.value === "function" && value == null)) {
if (typeof value === "function") {
Copy link
Member

@traeok traeok Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning this logic up 😁

// wrap provided function around a Jest function, if needed
this.#val = jest.isMockFunction(value) ? value : jest.fn().mockImplementation(value);
} else {
Expand Down
4 changes: 1 addition & 3 deletions packages/zowe-explorer/__tests__/__mocks__/mockUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ export class MockedProperty {
return;
}

const isValFn = typeof value === "function";

if (isValFn || (typeof descriptor?.value === "function" && value == null)) {
if (typeof value === "function") {
// wrap provided function around a Jest function, if needed
this.#val = jest.isMockFunction(value) ? value : jest.fn().mockImplementation(value);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import * as vscode from "vscode";
import { ProfilesCache, ZoweTreeNode, imperative } from "@zowe/zowe-explorer-api";
import { ProfilesCache, ZoweTreeNode } from "@zowe/zowe-explorer-api";
import { createIProfile, createISession } from "../../__mocks__/mockCreators/shared";
import { ZoweCommandProvider } from "../../../src/commands/ZoweCommandProvider";
import { Profiles } from "../../../src/configuration/Profiles";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,6 @@ describe("readDirectory", () => {
describe("PDS entry", () => {
it("calls allMembers to fetch the members of a PDS", async () => {
const mockPdsEntry = { ...testEntries.pds, metadata: { ...testEntries.pds.metadata } };
const mockMvsApi = {
dataSet: jest.fn().mockResolvedValueOnce({
success: true,
apiResponse: {
items: [{ dsorg: "PO" }],
},
}),
allMembers: jest.fn().mockResolvedValueOnce({
success: true,
apiResponse: {
items: [{ member: "MEMB1" }, { member: "MEMB2" }, { member: "MEMB3" }, { member: "MEMB4" }],
},
}),
};
const getInfoForUriMock = jest.spyOn(FsAbstractUtils, "getInfoForUri").mockReturnValue({
isRoot: false,
slashAfterProfilePos: testUris.pds.path.indexOf("/", 1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

import * as vscode from "vscode";
import * as zosconsole from "@zowe/zos-console-for-zowe-sdk";
import * as zosjobs from "@zowe/zos-jobs-for-zowe-sdk";
import * as zosmf from "@zowe/zosmf-for-zowe-sdk";
import { Gui, IZoweJobTreeNode, Sorting, Validation, ZoweScheme } from "@zowe/zowe-explorer-api";
Expand Down
10 changes: 2 additions & 8 deletions packages/zowe-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1818,9 +1818,6 @@
"devDependencies": {
"@cucumber/cucumber": "9.5.1",
"@napi-rs/cli": "^2.16.1",
"@types/chai": "^4.2.6",
"@types/chai-as-promised": "^7.1.0",
"@types/expect": "^1.20.3",
"@types/fs-extra": "^7.0.0",
"@types/promise-queue": "^2.2.0",
"@types/sinon": "^17.0.3",
Expand All @@ -1831,19 +1828,16 @@
"@wdio/mocha-framework": "^8.40.3",
"@wdio/spec-reporter": "^8.40.3",
"@wdio/types": "^8.40.3",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"chalk": "^2.4.1",
"eslint-plugin-zowe-explorer": "3.0.0-next-SNAPSHOT",
"expect": "^24.8.0",
"expect-webdriverio": "^4.15.4",
"glob": "^7.1.6",
"jest-silent-reporter": "^0.5.0",
"log4js": "^6.4.6",
"markdownlint-cli": "^0.33.0",
"sinon": "^16.1.1",
"sinon": "^19.0.2",
"ts-node": "^10.9.2",
"wdio-vscode-service": "^6.1.0",
"wdio-vscode-service": "^6.1.1",
"wdio-wait-for": "^3.0.11",
"webdriverio": "^8.40.5"
},
Expand Down
28 changes: 22 additions & 6 deletions packages/zowe-explorer/scripts/generatePoeditorJson.js
Copy link
Member

@traeok traeok Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question for my own clarification: could we remove some of the logic in this script by defining the file suffix before looking over the entries in the JSON? E.g.:

const fileSuffix = langId ? `.${langId}.json` : ".json";

Then the same file suffix could be appended to the package.nls, poeditor and bundle.l10n files to retrieve the contents for the given language ID.

I didn't notice much of a difference between the two branches when doing the langId checks, but if we have to keep the logic separate then feel free to disregard this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can create a follow up story if decided to make the updates.

Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
/**
* Merges package.nls.json and bundle.l10n.json into a key-value JSON file that
* can be imported into POEditor.
* can be imported into POEditor. Run this script without any arguments to
* merge l10n templates, or specify a language ID to merge translation files.
*/

const fs = require("fs");
const langId = process.argv[2];
const poeditorJson = {};
const packageNls = require(__dirname + "/../package.nls.json");
for (const [k, v] of Object.entries(packageNls)) {
poeditorJson[k] = { [v]: "" };
if (!langId) {
for (const [k, v] of Object.entries(packageNls)) {
poeditorJson[k] = { [v]: "" };
}
} else {
const packageNls2 = require(__dirname + "/../package.nls." + langId + ".json");
for (const [k, v] of Object.entries(packageNls)) {
poeditorJson[k] = packageNls2[k] ? { [v]: packageNls2[k] } : undefined;
}
}
const l10nBundle = require(__dirname + "/../l10n/bundle.l10n.json");
for (const [k, v] of Object.entries(l10nBundle)) {
poeditorJson[typeof v === "string" ? k : v.message] = "";
if (!langId) {
for (const [k, v] of Object.entries(l10nBundle)) {
poeditorJson[typeof v === "string" ? k : v.message] = "";
}
} else {
const l10nBundle2 = require(__dirname + "/../l10n/bundle.l10n." + langId + ".json");
for (const [k, v] of Object.entries(l10nBundle)) {
poeditorJson[typeof v === "string" ? k : v.message] = l10nBundle2[k]?.message || l10nBundle2[k];
}
}
fs.writeFileSync(__dirname + "/../l10n/poeditor.json", JSON.stringify(poeditorJson, null, 2) + "\n");
fs.writeFileSync(__dirname + "/../l10n/poeditor." + (langId ? `${langId}.json` : "json"), JSON.stringify(poeditorJson, null, 2) + "\n");
5 changes: 2 additions & 3 deletions packages/zowe-explorer/src/trees/uss/UssFSProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,8 @@ export class UssFSProvider extends BaseProvider implements vscode.FileSystemProv
* - Look into pre-fetching a directory level below the one given
* - Should we support symlinks and can we use z/OSMF "report" option?
*/
let dir: UssDirectory = null;
try {
dir = this._lookupAsDirectory(uri, false) as UssDirectory;
this._lookupAsDirectory(uri, false) as UssDirectory;
} catch (err) {
// Errors unrelated to the filesystem cannot be handled here
if (!(err instanceof vscode.FileSystemError) || err.code !== "FileNotFound") {
Expand All @@ -244,7 +243,7 @@ export class UssFSProvider extends BaseProvider implements vscode.FileSystemProv
}

// check to see if contents have updated on the remote system before returning its children.
dir = (await this.remoteLookupForResource(uri)) as UssDirectory;
const dir = (await this.remoteLookupForResource(uri)) as UssDirectory;

return Array.from(dir.entries.entries()).map((e: [string, UssDirectory | UssFile]) => [e[0], e[1].type]);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/src/webviews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"devDependencies": {
"@preact/preset-vite": "^2.5.0",
"typescript": "^5.3.3",
"vite": "^4.5.3",
"vite": "^4.5.5",
"vite-plugin-checker": "^0.6.4",
"vite-plugin-static-copy": "^0.17.1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
VSCodeDataGridRow,
VSCodeDivider,
} from "@vscode/webview-ui-toolkit/react";
import { isSecureOrigin } from "../utils";

const vscodeApi = acquireVsCodeApi();

Expand All @@ -17,13 +18,7 @@ export function App() {
useEffect(() => {
window.addEventListener("message", (event) => {
// Prevent users from sending data into webview outside of extension/webview context
const eventUrl = new URL(event.origin);
const isWebUser =
(eventUrl.protocol === document.location.protocol && eventUrl.hostname === document.location.hostname) ||
eventUrl.hostname.endsWith(".github.dev");
const isLocalVSCodeUser = eventUrl.protocol === "vscode-webview:";

if (!isWebUser && !isLocalVSCodeUser) {
if (!isSecureOrigin(event.origin)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
VSCodeTextField,
} from "@vscode/webview-ui-toolkit/react";
import { isEqual } from "es-toolkit";
import { isSecureOrigin } from "../utils";

const vscodeApi = acquireVsCodeApi();

Expand Down Expand Up @@ -62,13 +63,7 @@ export function App() {
useEffect(() => {
window.addEventListener("message", (event) => {
// Prevent users from sending data into webview outside of extension/webview context
const eventUrl = new URL(event.origin);
const isWebUser =
(eventUrl.protocol === document.location.protocol && eventUrl.hostname === document.location.hostname) ||
eventUrl.hostname.endsWith(".github.dev");
const isLocalVSCodeUser = eventUrl.protocol === "vscode-webview:";

if (!isWebUser && !isLocalVSCodeUser) {
if (!isSecureOrigin(event.origin)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const useContextMenu = (contextMenu: ContextMenuProps) => {
callback: cellMenu,
component: open ? (
<ControlledMenu
state={open ? "open" : "closed"}
state="open"
anchorPoint={anchor}
direction="right"
onClose={() => {
Expand Down
9 changes: 2 additions & 7 deletions packages/zowe-explorer/src/webviews/src/zos-console/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Dropdown, Option, TextArea, TextField } from "@vscode/webview-ui-toolkit";
import { VSCodeDropdown, VSCodeTextArea, VSCodeTextField } from "@vscode/webview-ui-toolkit/react";
import { useEffect, useState } from "preact/hooks";
import { isSecureOrigin } from "../utils";

declare const vscode: any;

Expand All @@ -13,13 +14,7 @@ export function App() {
useEffect(() => {
window.addEventListener("message", (event) => {
// Prevent users from sending data into webview outside of extension/webview context
const eventUrl = new URL(event.origin);
const isWebUser =
(eventUrl.protocol === document.location.protocol && eventUrl.hostname === document.location.hostname) ||
eventUrl.hostname.endsWith(".github.dev");
const isLocalVSCodeUser = eventUrl.protocol === "vscode-webview:";

if (!isWebUser && !isLocalVSCodeUser) {
if (!isSecureOrigin(event.origin)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const config = {
module: {
rules: [
{
test: /\.ts|\.tsx$/,
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
Expand Down
Loading
Loading