New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@eclipse-che/devfile-converter

Package Overview
Dependencies
Maintainers
5
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eclipse-che/devfile-converter - npm Package Compare versions

Comparing version 0.0.1-b03c439 to 0.0.1-ba9d381

LICENSE

5

lib/converter/devfile-converter.d.ts

@@ -29,3 +29,8 @@ import { V220DevfileCommands, V220DevfileComponents, V220DevfileComponentsItemsContainerEndpoints, V220DevfileComponentsItemsContainerEnv, V220DevfileComponentsItemsContainerVolumeMounts, V220DevfileProjects, V220DevfileProjectsItemsGit } from '@devfile/api';

processPluginsAndEditorsFromDevfileV2(devfileV2: Devfile, devfileV1: che.workspace.devfile.Devfile, externalContentAccess?: (filename: string) => Promise<string>): Promise<void>;
findFirstProjectPath(devfileV1: che.workspace.devfile.Devfile): string | undefined;
prunePlaceHolderComponents(devfileV1: che.workspace.devfile.Devfile): void;
fixNightlyImages(devfileV1: che.workspace.devfile.Devfile): void;
fixMemoryLimit(devfileV1: che.workspace.devfile.Devfile): void;
processDefaultWorkDirCommands(devfileV1: che.workspace.devfile.Devfile, path: string): Promise<void>;
devfileV2toDevfileV1(devfileV2: Devfile, externalContentAccess?: (filename: string) => Promise<string>): Promise<che.workspace.devfile.Devfile>;
}

100

lib/converter/devfile-converter.js

@@ -192,4 +192,9 @@ "use strict";

if (componentV2.kubernetes) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
return JSON.parse(componentV2.kubernetes.inlined);
if (componentV2.kubernetes.inlined) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
return JSON.parse(componentV2.kubernetes.inlined);
}
else {
return undefined;
}
}

@@ -342,4 +347,5 @@ else if (componentV2.openshift) {

devfileV1Command.actions = [devfileAction];
return devfileV1Command;
}
return devfileV1Command;
return undefined;
};

@@ -786,5 +792,65 @@ DevfileConverter.prototype.projectV1toProjectV2 = function (projectV1) {

};
DevfileConverter.prototype.findFirstProjectPath = function (devfileV1) {
var projects = devfileV1.projects;
if (!projects || projects.length === 0) {
return undefined;
}
// take first project
var project = projects[0];
var path;
if (project.clonePath) {
path = "${CHE_PROJECTS_ROOT}/".concat(project.clonePath);
}
else {
path = "${CHE_PROJECTS_ROOT}/".concat(project.name);
}
return path;
};
DevfileConverter.prototype.prunePlaceHolderComponents = function (devfileV1) {
devfileV1.components = devfileV1.components.filter(function (component) { return component.image !== 'buildguidanceimage-placeholder'; });
};
DevfileConverter.prototype.fixNightlyImages = function (devfileV1) {
devfileV1.components.forEach(function (component) {
if (component.image && component.image === 'quay.io/eclipse/che-quarkus:nightly') {
component.image = 'quay.io/eclipse/che-quarkus:next';
}
else if (component.image && component.image === 'quay.io/eclipse/che-java11-maven:nightly') {
component.image = 'quay.io/eclipse/che-java11-maven:next';
}
});
};
// Apply 1Gi on all components without memoryLimit
DevfileConverter.prototype.fixMemoryLimit = function (devfileV1) {
devfileV1.components.forEach(function (component) {
if (component.type === 'dockerimage' && !component.memoryLimit) {
component.memoryLimit = '1Gi';
}
});
};
DevfileConverter.prototype.processDefaultWorkDirCommands = function (devfileV1, path) {
return __awaiter(this, void 0, void 0, function () {
var execWithoutWorkingdir;
return __generator(this, function (_a) {
execWithoutWorkingdir = devfileV1.commands
.filter(function (command) {
return command.actions &&
command.actions.find(function (action) {
return (!action.workdir || action.workdir === '$PROJECTS_ROOT' || action.workdir === '${PROJECTS_ROOT}') &&
action.type === 'exec';
});
})
.map(function (command) { return command.actions; })
.flat();
// update working directory
if (execWithoutWorkingdir.length > 0 && path) {
// set the working directory to the project directory
execWithoutWorkingdir.forEach(function (exec) { return (exec.workdir = path); });
}
return [2 /*return*/];
});
});
};
DevfileConverter.prototype.devfileV2toDevfileV1 = function (devfileV2, externalContentAccess) {
return __awaiter(this, void 0, void 0, function () {
var devfileV1, attributeKeys, attributes_1, devfileV1Any, content;
var devfileV1, attributeKeys, attributes_1, firstProjectPath, devfileV1Any, content;
var _this = this;

@@ -820,2 +886,14 @@ return __generator(this, function (_a) {

_a.sent();
firstProjectPath = this.findFirstProjectPath(devfileV1);
// update workDir of commands to be inside the current project if missing
return [4 /*yield*/, this.processDefaultWorkDirCommands(devfileV1, firstProjectPath)];
case 2:
// update workDir of commands to be inside the current project if missing
_a.sent();
// prune placeholder components
this.prunePlaceHolderComponents(devfileV1);
// fix nightly images of che
this.fixNightlyImages(devfileV1);
// memoryLimit is a mandatory attribute in devfile v1
this.fixMemoryLimit(devfileV1);
devfileV1Any = devfileV1;

@@ -831,2 +909,13 @@ if (devfileV1.components && devfileV1.components.length === 0) {

}
// cleanup attributes that are not string
if (devfileV1.attributes) {
Object.keys(devfileV1.attributes).forEach(function (key) {
if (typeof devfileV1.attributes[key] !== 'string') {
delete devfileV1.attributes[key];
}
});
}
if (devfileV1.attributes && Object.keys(devfileV1.attributes).length === 0) {
delete devfileV1Any.attributes;
}
content = JSON.stringify(devfileV1, undefined, 2);

@@ -836,2 +925,5 @@ // update devfile v2 constants

content = content.replace(/\$\{PROJECTS_ROOT\}/g, '${CHE_PROJECTS_ROOT}');
if (firstProjectPath) {
content = content.replace(/\$\{PROJECT_SOURCE\}/g, firstProjectPath);
}
return [2 /*return*/, JSON.parse(content)];

@@ -838,0 +930,0 @@ }

3

package.json
{
"name": "@eclipse-che/devfile-converter",
"version": "0.0.1-b03c439",
"version": "0.0.1-ba9d381",
"description": "Convert devfile v1 to v2 or v2 to v1",

@@ -50,2 +50,3 @@ "publishConfig": {

"jest": "^27.3.1",
"jsonschema": "^1.4.0",
"prettier": "^2.4.1",

@@ -52,0 +53,0 @@ "rimraf": "^3.0.2",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc