Skip to content
Merged
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v24.18.0
v24
182 changes: 107 additions & 75 deletions lib/interface/cli/completion/completion.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,86 +68,118 @@ jest.mock('./context/create.completion', () => { // eslint-disable-line
};
}, { virtual: true });

jest.mock('fs', () => {
const existsSync = (p) => {
if (p.startsWith(`${mockCwd()}/`)) {
p = p.replace(`${mockCwd()}/`, '');
}
if (p.startsWith(mockCwd())) {
p = p.replace(mockCwd(), '');
}
switch (p) {
case '':
case 'libe/':
case 'libe':
case 'another':
case 'another/':
case 'libe/cli':
case 'libe/cli/':
return true;
default:
return false;
}
};
const lstatSync = (p) => {
let isFile = false;
let isDir = true;
if (p.startsWith(`${mockCwd()}/`)) {
p = p.replace(`${mockCwd()}/`, '');
}
if (p.startsWith(mockCwd())) {
p = p.replace(mockCwd(), '');
}
switch (p) {
case 'some.yaml':
case 'libe/another.yaml':
isFile = true;
isDir = false;
break;
default:
break;
}
return {
isFile: () => isFile,
isDirectory: () => isDir,
};
};
// Mock fs locally to not break SDK loading

const stat = (p, options = { bigint: false }, callback) => {
const result = lstatSync(p);
return callback(null, result);
};
process.argv = []; // completion is sensitive to process args

const readdirSync = (p) => {
if (p.startsWith(`${mockCwd()}/`)) {
p = p.replace(`${mockCwd()}/`, '');
}
if (p.startsWith(mockCwd())) {
p = p.replace(mockCwd(), '');
}
switch (p) {
case '':
return ['libe', 'like', 'another', 'some.yaml'];
case 'libe':
case 'libe/':
return ['cli', 'clo', 'another.yaml'];
default:
return [];
}
};
return Object.assign(jest.requireActual('fs'), {
lstat: (p, callback) => callback(null, lstatSync(p)),
stat: (p, callback) => callback(null, lstatSync(p)),
access: (path, c) => c(null, true),
readdirSync,
existsSync,
lstatSync,
describe('codefresh completions', () => {
let originalArgv;
let originalEnv;

beforeAll(() => {
// Save original state
originalArgv = [...process.argv];
originalEnv = { ...process.env };
});
});

process.argv = []; // completion is sensitive to process args
beforeEach(() => {
// Reset to clean state for each test
process.argv = [...originalArgv];

// Mock fs methods for completion tests
const fs = require('fs');
const originalFs = jest.requireActual('fs');

// Mock readdirSync
jest.spyOn(fs, 'readdirSync').mockImplementation((p) => {
// Allow SDK to load properly - use real fs for node_modules
if (p.includes('node_modules') || p.includes('codefresh-sdk')) {
return originalFs.readdirSync(p);
}

// Completion test logic for local paths
let testPath = p;
if (testPath.startsWith(`${mockCwd()}/`)) {
testPath = testPath.replace(`${mockCwd()}/`, '');
}
if (testPath.startsWith(mockCwd())) {
testPath = testPath.replace(mockCwd(), '');
}

switch (testPath) {
case '':
return ['libe', 'like', 'another', 'some.yaml'];
case 'libe':
case 'libe/':
return ['cli', 'clo', 'another.yaml'];
default:
return [];
}
});

describe('codefresh completions', () => {
// Mock existsSync
jest.spyOn(fs, 'existsSync').mockImplementation((p) => {
let testPath = p;
if (testPath.startsWith(`${mockCwd()}/`)) {
testPath = testPath.replace(`${mockCwd()}/`, '');
}
if (testPath.startsWith(mockCwd())) {
testPath = testPath.replace(mockCwd(), '');
}

switch (testPath) {
case '':
case 'libe/':
case 'libe':
case 'another':
case 'another/':
case 'libe/cli':
case 'libe/cli/':
return true;
default:
return false;
}
});

// Mock lstatSync
jest.spyOn(fs, 'lstatSync').mockImplementation((p) => {
let isFile = false;
let isDir = true;
let testPath = p;
if (testPath.startsWith(`${mockCwd()}/`)) {
testPath = testPath.replace(`${mockCwd()}/`, '');
}
if (testPath.startsWith(mockCwd())) {
testPath = testPath.replace(mockCwd(), '');
}

switch (testPath) {
case 'some.yaml':
case 'libe/another.yaml':
isFile = true;
isDir = false;
break;
default:
break;
}

return {
isFile: () => isFile,
isDirectory: () => isDir,
};
});
});

afterEach(() => {
// Restore real fs methods
jest.restoreAllMocks();
});

afterAll(() => {
// Restore original state
process.argv = originalArgv;
process.env = originalEnv;
});
describe('static', () => {
it('should not display any completions when no word is entered', async () => {
const result = await getCompletion([]);
Expand Down
6 changes: 4 additions & 2 deletions lib/interface/cli/helpers/cli-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const flatten = require('flat');
const columnify = require('columnify');
const yaml = require('js-yaml');
const Style = require('../../../output/Style');
const { NoPropertyError, MultiplePropertiesError, NotFullPropertyError, SchemaValidationError } = require('../../../logic/cli-config/errors');
const {
NoPropertyError, MultiplePropertiesError, NotFullPropertyError, SchemaValidationError,
} = require('../../../logic/cli-config/errors');

const _jsonFormatter = data => JSON.stringify(data, null, 4);
const COLUMNIFY_OPTS = { columnSplitter: ' ', headingTransform: Style.bold.uppercase };
Expand Down Expand Up @@ -38,7 +40,7 @@ function _defaultOutput(data) {
function _formatter(format) {
switch (format) {
case 'yaml':
return yaml.safeDump;
return yaml.dump;
case 'json':
return _jsonFormatter;
default:
Expand Down
2 changes: 1 addition & 1 deletion lib/interface/cli/helpers/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const crudFilenameOption = (yargs, options = {}) => {
return options.raw ? rawFile : JSON.parse(rawFile);
}
if (arg.endsWith('.yml') || arg.endsWith('yaml')) {
return options.raw ? rawFile : yaml.safeLoad(rawFile);
return options.raw ? rawFile : yaml.load(rawFile);
}
throw new CFError('File extension is not recognized');
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion lib/interface/cli/helpers/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function validatePipelineSpec(data) {
if (specTemplate) { // CR-6414 Using specTemplate - skip check spec/stages - they are not used
return { valid: true, message: 'Using specTemplate' };
}
const validatedYaml = yaml.safeDump(yamlObj);
const validatedYaml = yaml.dump(yamlObj);
const result = await sdk.pipelines.validateYaml({ yaml: validatedYaml, outputFormat: 'lint' });
let message;
if (result.summarize) {
Expand Down
6 changes: 3 additions & 3 deletions lib/logic/cli-config/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ function _loadFullConfig() {
},
};
const file = fs.openSync(filePath, 'w');
fs.writeSync(file, yaml.safeDump(fullConfig));
fs.writeSync(file, yaml.dump(fullConfig));
fs.closeSync(file);
return fullConfig;
}
return yaml.safeLoad(fs.readFileSync(filePath));
return yaml.load(fs.readFileSync(filePath));
}

function _validate(properties, propertyName) {
Expand Down Expand Up @@ -127,7 +127,7 @@ class CliConfigManager {
static persistConfig() {
this._preloadConfig();
const file = fs.openSync(filePath, 'w');
fs.writeSync(file, yaml.safeDump(FULL_CONFIG));
fs.writeSync(file, yaml.dump(FULL_CONFIG));
fs.closeSync(file);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/logic/cli-config/manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ jest.mock('fs', () => { // eslint-disable-line
});

jest.mock('js-yaml', () => {
const safeLoad = (d) => d;
const safeDump = (d) => d;
const load = (d) => d;
const dump = (d) => d;
return {
safeLoad,
safeDump,
load,
dump,
};
});

Expand Down
2 changes: 1 addition & 1 deletion lib/logic/entities/Entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Entity {
}

toYaml() {
return yaml.safeDump(this.info);
return yaml.dump(this.info);
}

toName() {
Expand Down
4 changes: 2 additions & 2 deletions lib/output/types/yaml.output.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ function output(data) {
});

if (yamlArray.items.length === 1) {
return yaml.safeDump(yamlArray.items[0]);
return yaml.dump(yamlArray.items[0]);
}
return yaml.safeDump(yamlArray);
return yaml.dump(yamlArray);
}

module.exports = output;
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "codefresh",
"version": "1.2.3",
"version": "1.2.4",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
"scripts": {
"generate-completion": "node ./lib/interface/cli/completion/generate",
"test": "jest .spec.js --coverage",
"test": "rm -rf ./temp && jest .spec.js --runInBand --ci --color --coverage --silent",
"e2e": "bash e2e/e2e.spec.sh",
"eslint": "eslint --fix lib/logic/**",
"pkg": "npx pkg . -t node20-alpine-x64,node20-alpine-arm64,node20-macos-x64,node20-linux-x64,node20-win-x64,node20-linux-arm64 --out-path ./dist",
Expand Down Expand Up @@ -68,7 +68,7 @@
"firebase": "git+https://github.com/codefresh-io/firebase.git#80b2ed883ff281cd67b53bd0f6a0bbd6f330fed5",
"flat": "^5.0.2",
"inquirer": "^12.11.1",
"js-yaml": "^3.10.0",
"js-yaml": "^4.3.0",
"kefir": "^3.8.1",
"kubernetes-client": "^9.0.0",
"lodash": "^4.17.23",
Expand Down
28 changes: 14 additions & 14 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2491,9 +2491,9 @@ bowser@^2.11.0:
integrity sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg==

brace-expansion@^1.1.7:
version "1.1.14"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.14.tgz#d9de602370d91347cd9ddad1224d4fd701eb348b"
integrity sha512-MWPGfDxnyzKU7rNOW9SP/c50vi3xrmrua/+6hfPbCS2ABNWfx24vPidzvC7krjU/RTo235sV776ymlsMtGKj8g==
version "1.1.16"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.16.tgz#723d3a30c0558c225abc9fc479a73e14e26c3c2f"
integrity sha512-IDw48K2/2kRkg9LdJxurvq3lV3aBgq0REY89duEqFRthjlPdXHKMj7EnQOXVckxzgisinf3nHfrcE2FufFLXMw==
dependencies:
balanced-match "^1.0.0"
concat-map "0.0.1"
Expand Down Expand Up @@ -3796,9 +3796,9 @@ fast-levenshtein@^2.0.6:
integrity sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==

fast-uri@^3.0.1:
version "3.1.2"
resolved "https://registry.yarnpkg.com/fast-uri/-/fast-uri-3.1.2.tgz#8af3d4fc9d3e71b11572cc2673b514a7d1a8c8ec"
integrity sha512-rVjf7ArG3LTk+FS6Yw81V1DLuZl1bRbNrev6Tmd/9RaroeeRRJhAt7jg/6YFxbvAQXUCavSoZhPPj6oOx+5KjQ==
version "3.1.4"
resolved "https://registry.yarnpkg.com/fast-uri/-/fast-uri-3.1.4.tgz#3b3daf9ce68f41f956df0b505132c0cfce9ec7af"
integrity sha512-8JnbkQ4juDyvYs4mgFGQqg4yCYtFDtUtmp2QIQq11ZZe5CFQ5wcqm1rqDgAh/QdMySuBnPzMUiJUNZG5N/AiQw==

fast-xml-builder@^1.1.5:
version "1.1.8"
Expand Down Expand Up @@ -5117,18 +5117,18 @@ js-tokens@^4.0.0:
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==

js-yaml@^3.10.0, js-yaml@^3.13.1, js-yaml@^3.14.0:
js-yaml@^3.13.1, js-yaml@^3.14.0:
version "3.15.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.15.0.tgz#586e5214eafe3e893756a41e979b50d89d3e4a67"
integrity sha512-ttBQIIQPDeLjpPOohtUdXuXUVoA2uIB6fEH9HyJ7234s5mBJ5wTx20njxplLZQgLaOfpmPQA7X2t5AX6tIPbog==
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"

js-yaml@^4.1.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.2.0.tgz#2bd9e85682dd91bd469afb809d816043b3d49524"
integrity sha512-ePWsvanv0DWuDRsW8dnt+R4jQ31SCRCQ7hhNcPXZPsoBZiemuZNYGf7adZdqX2D86j6rvKp3RpCxVTSb8WQlOw==
js-yaml@^4.1.0, js-yaml@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.3.0.tgz#d1900572a7f7cf0b5f540c83673e60bad3436592"
integrity sha512-1td788aAnnZ5qs7V2QIRl1owjtYpbKt749Y3xauqQgwIIGF/xXWz1wMTEBx5O3LK3lXLVuqXPdPxj2BoFHaW9Q==
dependencies:
argparse "^2.0.1"

Expand Down Expand Up @@ -6903,9 +6903,9 @@ tar-stream@^3.1.5:
streamx "^2.15.0"

tar@^7.0.0, tar@^7.5.7:
version "7.5.17"
resolved "https://registry.yarnpkg.com/tar/-/tar-7.5.17.tgz#5eace4af68b088bb1d737ba9fffdacbbb70ba6e0"
integrity sha512-wPEBwzapC+2PaTYPH6e2L+cNOEE227S47wUYFqlegcs8zlLLmeb9Fcff1HVZY4Fwku/1Eyv38n7GYwB2aaS71g==
version "7.5.21"
resolved "https://registry.yarnpkg.com/tar/-/tar-7.5.21.tgz#b3405af2eb493523ce4379f531e9ebda0601bc59"
integrity sha512-XdhtCvlMywwxpCW8YEq3lOXBJpUPTR2OHHcwLPO3HwsJqOHa2Ok/oJ7ruGzp+JrKoRPVCzJwAdEjqLW/vNRPHA==
dependencies:
"@isaacs/fs-minipass" "^4.0.0"
chownr "^3.0.0"
Expand Down