Skip to content

Commit

Permalink
Merge pull request #26 from zowe/secrets
Browse files Browse the repository at this point in the history
fix: Secrets SDK usage + CLI bundle process
  • Loading branch information
zFernand0 authored Feb 2, 2024
2 parents d3e8139 + f8686e3 commit 04bd8ae
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .github/release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
level: "minor",
devDependencies: {
"@zowe/imperative": "zowe-v2-lts",
"@zowe/secrets-for-zowe-sdk": "zowe-v2-lts",
"@zowe/zowe-explorer-api": "zowe-v2-lts",
}
},
Expand All @@ -15,6 +16,7 @@ module.exports = {
level: "patch",
devDependencies: {
"@zowe/imperative": "zowe-v1-lts",
"@zowe/secrets-for-zowe-sdk": "zowe-v2-lts",
"@zowe/zowe-explorer-api": "zowe-v1-lts",
}
},
Expand All @@ -25,6 +27,7 @@ module.exports = {
prerelease: true,
devDependencies: {
"@zowe/imperative": "next",
"@zowe/secrets-for-zowe-sdk": "next",
"@zowe/zowe-explorer-api": "next",
}
}
Expand Down
8 changes: 4 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
"version": "0.2.0",
"configurations": [
{
"name": "Run Kubernetes Secrets Extension for Zowe",
"name": "Run CICS Extension for Zowe",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode",
"--extensionDevelopmentPath=${workspaceFolder}/packages/vsce",
"--verbose"
],
"outFiles": ["${workspaceFolder}/packages/vscode/dist/**/*.js"],
"preLaunchTask": "build dev watch",
"outFiles": ["${workspaceFolder}/packages/vsce/dist/**/*.js"],
"preLaunchTask": "npm run watch",
"smartStep": true,
"skipFiles": ["<node_internals>/**"],
"enableTurboSourcemaps": true,
Expand Down
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"version": "2.0.0",
"tasks": [
{
"label": "build dev watch",
"label": "npm run watch",
"group": "build",
"isBackground": true,
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/packages/vscode"
"cwd": "${workspaceFolder}/packages/vsce"
},
"command": "npm",
"args": ["run", "dev"],
"args": ["run", "watch"],
"problemMatcher": {
"owner": "typescript",
"source": "ts",
Expand Down
27 changes: 23 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"private": true,
"scripts": {
"build": "turbo build",
"watch": "turbo watch",
"package": "turbo package",
"test": "npm run test --workspaces",
"test:system": "npm run test:system --workspaces",
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"lint": "eslint \"src/**/*.ts\" \"**/__tests__/**/*.ts\"",
"lint:src": "eslint \"src/**/*.ts\" --ignore-pattern \"**/__tests__/**/*.ts\"",
"lint:tests": "eslint \"**/__tests__/**/*.ts\"",
"package": "node ../../scripts/bundleTgz.js",
"prepack": "node ../../scripts/bundleTgz.js",
"postpack": "node ../../scripts/bundleTgz.js post",
"package": "npm pack --pack-destination=../../dist",
"test": "npm run test:unit && npm run test:system",
"test:system": "jest --config system.jest_config.ts",
"test:unit": "jest --config unit.jest_config.ts",
Expand All @@ -53,7 +55,7 @@
"peerDependencies": {
"@zowe/imperative": "^5.0.0"
},
"bundleDependencies": [
"bundledDependencies": [
"@zowe/cics-for-zowe-sdk"
]
}
3 changes: 2 additions & 1 deletion packages/vsce/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ lib/
.history/
logs/
.vscode-test/
results/
results/
prebuilds/
1 change: 1 addition & 0 deletions packages/vsce/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Allowlist what we need
!dist/extension.*
!prebuilds/*
# !out/src/nls.metadata*.json
!resources/**/*.png
!resources/**/*.svg
Expand Down
7 changes: 4 additions & 3 deletions packages/vsce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -871,18 +871,19 @@
}
},
"scripts": {
"vscode:prepublish": "npm run tsupDep -- add && tsup && npm run tsupDep",
"vscode:prepublish": "npm run getPrebuilds && npm run tsupDep -- add && tsup && npm run tsupDep",
"build": "tsup && npm run checkTestsCompile && npm run madge",
"checkTestsCompile": "echo \"Checking that test source compiles...\" && tsc --project __tests__/test-tsconfig.json --noEmit ",
"madge": "echo 'Nothing to check'",
"lint": "eslint src --ext ts",
"prebuild": "npm run clean && echo Using TypeScript && tsc --version && echo Using TSUP && tsup --version",
"clean": "rimraf lib && rimraf dist",
"watch": "tsc -watch -p ./",
"watch": "tsup --watch",
"test:system": "echo 'Please run the system tests via VSCode UI' && exit 0",
"test:unit": "jest --config unit.jest_config.ts --no-coverage",
"test": "npm run test:unit",
"tsupDep": "node ./scripts/tsup-deps.js",
"getPrebuilds": "node ./scripts/getSecretsPrebuilds.js",
"package": "vsce package --dependencies --allow-star-activation && node ../../scripts/mv-pack.js cics-extension-for-zowe vsix"
},
"devDependencies": {
Expand All @@ -896,4 +897,4 @@
"https": "~1.0.0",
"xml-js": "~1.6.11"
}
}
}
15 changes: 15 additions & 0 deletions packages/vsce/scripts/getSecretsPrebuilds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

const fsE = require("fs-extra");
const path = require("path");
const secretsPkgDir = path.resolve(require.resolve("@zowe/secrets-for-zowe-sdk"), "..", "..");
fsE.copySync(path.join(secretsPkgDir, "prebuilds"), path.resolve(__dirname, "..", "prebuilds"));
5 changes: 3 additions & 2 deletions packages/vsce/src/utils/profileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ZoweVsCodeExtension, imperative } from "@zowe/zowe-explorer-api";
import { join } from "path";
import { CICSTree } from "../trees/CICSTree";
import { window } from "vscode";
import { ProfileManagement } from "./profileManagement";

export function missingSessionParameters(profileProfile: any): (string | undefined)[] {
const params = ["host", "port", "user", "password", "rejectUnauthorized", "protocol"];
Expand All @@ -38,10 +39,10 @@ export async function promptCredentials(sessionName: string, rePrompt?: boolean)
// });
// await mProfileInfo.readProfilesFromDisk();
// ProfilesCache.createConfigInstance(mProfileInfo);
const promptInfo = await ZoweVsCodeExtension.promptCredentials({
const promptInfo = await ZoweVsCodeExtension.updateCredentials({
sessionName,
rePrompt,
});
}, ProfileManagement.getExplorerApis());
if (!promptInfo) {
window.showInformationMessage("Input credentials operation Cancelled");
}
Expand Down
43 changes: 31 additions & 12 deletions scripts/bundleTgz.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,45 @@ const fsE = require("fs-extra");
const fs = require("fs");
const path = require("path");

const isPost = process.argv[2] === "post";

// Workaround for https://github.com/npm/cli/issues/3466
const rootDir = path.join(__dirname, "..");
process.chdir(rootDir);
const cliPkgDir = path.join(process.cwd(), "packages", "cli");
const pkgJsonFile = path.join(cliPkgDir, "package.json");
const tempPkgJson = JSON.parse(fsE.readFileSync(pkgJsonFile, "utf-8"));
const npmInstallCmd = "npm install --ignore-scripts --workspaces=false";
const execCmd = (cmd) => childProcess.execSync(cmd, { cwd: cliPkgDir, stdio: "inherit" });
fsE.mkdirpSync("dist");
if(fs.existsSync(path.join(cliPkgDir, "node_modules"))) {

const cleanUp = () => {
fsE.rmSync(path.join(cliPkgDir, "node_modules"), { recursive: true, force: true });
if (fs.existsSync(path.join(cliPkgDir, "node_modules_old"))) {
fsE.renameSync(path.join(cliPkgDir, "node_modules_old"), path.join(cliPkgDir, "node_modules"));
}
if (fs.existsSync(pkgJsonFile + ".bak")) {
fsE.renameSync(pkgJsonFile + ".bak", pkgJsonFile);
}
fs.rmSync(path.join(cliPkgDir, "npm-shrinkwrap.json"), { force: true });
fs.rmSync(path.join(rootDir, "npm-shrinkwrap.json"), { force: true });
}

if (isPost) {
cleanUp();
return;
}

if (fs.existsSync(path.join(cliPkgDir, "node_modules"))) {
fsE.renameSync(path.join(cliPkgDir, "node_modules"), path.join(cliPkgDir, "node_modules_old"));
}
fsE.copyFileSync(pkgJsonFile, pkgJsonFile + ".bak");

try {
// Install node_modules directly inside packages/cli
execCmd("npm run preshrinkwrap");
execCmd("npm install --ignore-scripts --workspaces=false --force");

execCmd(`${npmInstallCmd} ${path.relative(__dirname, "../dist/zowe-cics-for-zowe-sdk-" + tempPkgJson.version + ".tgz")}`);
execCmd(npmInstallCmd);
for (const zowePkgDir of fsE.readdirSync(path.join(cliPkgDir, "node_modules", "@zowe"))) {
const srcDir = path.join("node_modules", "@zowe", zowePkgDir);
const destDir = path.join(cliPkgDir, srcDir);
Expand All @@ -44,13 +67,9 @@ try {
...Object.keys(pkgJson.optionalDependencies ?? {})
];
fsE.writeFileSync(pkgJsonFile, JSON.stringify(pkgJson, null, 2));
execCmd("npm pack --pack-destination=../../dist");
} finally {
fsE.rmSync(path.join(cliPkgDir, "node_modules"), { recursive: true, force: true });
if(fs.existsSync(path.join(cliPkgDir, "node_modules_old"))) {
fsE.renameSync(path.join(cliPkgDir, "node_modules_old"), path.join(cliPkgDir, "node_modules"));
}
fs.rmSync(path.join(cliPkgDir, "npm-shrinkwrap.json"), { force: true });
fs.rmSync(path.join(rootDir, "npm-shrinkwrap.json"), { force: true });
fsE.renameSync(pkgJsonFile + ".bak", pkgJsonFile);

// execCmd("npm pack --pack-destination=../../dist");
} catch (err) {
cleanUp();
throw err;
}
15 changes: 15 additions & 0 deletions scripts/getSecretsPrebuilds.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

import { copySync } from "fs-extra";
import { join, resolve } from "path";
const secretsPkgDir = resolve(require.resolve("@zowe/secrets-for-zowe-sdk"), "..", "..");
copySync(join(secretsPkgDir, "prebuilds"), resolve(__dirname, "..", "prebuilds"));
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependsOn": ["^build"],
"outputs": ["dist/**", "lib/**"]
},
"dev": {
"watch": {
"dependsOn": ["build"]
},
"test": {
Expand Down

0 comments on commit 04bd8ae

Please sign in to comment.