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

@eclipse-che/che-code-devworkspace-handler

Package Overview
Dependencies
Maintainers
5
Versions
331
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eclipse-che/che-code-devworkspace-handler - npm Package Compare versions

Comparing version 1.64.0-dev-4c3f224 to 1.64.0-dev-77b11ab

lib/fetch/fetch-module.js

1

lib/entrypoint.js

@@ -0,1 +1,2 @@

#!/usr/bin/env node
"use strict";

@@ -2,0 +3,0 @@ /**********************************************************************

@@ -53,2 +53,5 @@ "use strict";

var k8s_module_1 = require("../k8s/k8s-module");
var fetch_module_1 = require("../fetch/fetch-module");
var github_module_1 = require("../github/github-module");
var plugin_registry_module_1 = require("../plugin-registry/plugin-registry-module");
/**

@@ -69,3 +72,8 @@ * Manage all bindings for inversify

this.container.load(devfile_module_1.devfileModule);
this.container.load(fetch_module_1.fetchModule);
this.container.load(github_module_1.githubModule);
this.container.load(k8s_module_1.k8sModule);
this.container.load(plugin_registry_module_1.pluginRegistryModule);
this.container.bind(Symbol["for"]('AxiosInstance')).toConstantValue(options.axiosInstance);
this.container.bind('string').toConstantValue(options.pluginRegistryUrl).whenTargetNamed('PLUGIN_REGISTRY_URL');
return [2 /*return*/, this.container];

@@ -72,0 +80,0 @@ });

@@ -68,5 +68,10 @@ "use strict";

exports.Main = void 0;
var axios = __importStar(require("axios"));
var fs = __importStar(require("fs-extra"));
var generate_1 = require("./generate");
var github_resolver_1 = require("./github/github-resolver");
var jsYaml = __importStar(require("js-yaml"));
var inversify_binding_1 = require("./inversify/inversify-binding");
var url_fetcher_1 = require("./fetch/url-fetcher");
var plugin_registry_resolver_1 = require("./plugin-registry/plugin-registry-resolver");
var Main = /** @class */ (function () {

@@ -77,6 +82,7 @@ function Main() {

return __awaiter(this, void 0, void 0, function () {
var devfilePath, outputFile, editorPath, args, inversifyBinbding, container, devfileContent, editorContent, generate;
var devfilePath, devfileUrl, outputFile, editorPath, pluginRegistryUrl, editorEntry, projects, args, axiosInstance, inversifyBinbding, container, devfileContent, editorContent, githubResolver, githubUrl, devfileParsed, editorDevfile, generate;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
projects = [];
args = process.argv.slice(2);

@@ -87,2 +93,11 @@ args.forEach(function (arg) {

}
if (arg.startsWith('--devfile-url:')) {
devfileUrl = arg.substring('--devfile-url:'.length);
}
if (arg.startsWith('--plugin-registry-url:')) {
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
}
if (arg.startsWith('--editor-entry:')) {
editorEntry = arg.substring('--editor-entry:'.length);
}
if (arg.startsWith('--editor-path:')) {

@@ -94,15 +109,27 @@ editorPath = arg.substring('--editor-path:'.length);

}
if (arg.startsWith('--project.')) {
var name = arg.substring('--project.'.length, arg.indexOf('='));
var location = arg.substring(arg.indexOf('=') + 1);
projects.push({ name: name, location: location });
}
});
if (!editorPath) {
throw new Error('missing --editor-path: parameter');
if (!editorPath && !editorEntry) {
throw new Error('missing --editor-path: or --editor-entry: parameter');
}
if (!devfilePath) {
throw new Error('missing --devfile-path: parameter');
if (editorEntry && !pluginRegistryUrl) {
pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3';
console.log("No plug-in registry url. Setting to " + pluginRegistryUrl);
}
if (!devfilePath && !devfileUrl) {
throw new Error('missing --devfile-path: or --devfile-url: parameter');
}
if (!outputFile) {
throw new Error('missing --output-file: parameter');
}
axiosInstance = axios["default"];
inversifyBinbding = new inversify_binding_1.InversifyBinding();
return [4 /*yield*/, inversifyBinbding.initBindings({
insertDevWorkspaceTemplatesAsPlugin: true
pluginRegistryUrl: pluginRegistryUrl,
insertDevWorkspaceTemplatesAsPlugin: true,
axiosInstance: axiosInstance
})];

@@ -112,8 +139,44 @@ case 1:

container.bind(generate_1.Generate).toSelf().inSingletonScope();
return [4 /*yield*/, fs.readFile(devfilePath)];
if (!devfileUrl) return [3 /*break*/, 3];
githubResolver = container.get(github_resolver_1.GithubResolver);
githubUrl = githubResolver.resolve(devfileUrl);
return [4 /*yield*/, container.get(url_fetcher_1.UrlFetcher).fetchText(githubUrl.getContentUrl('devfile.yaml'))];
case 2:
// user devfile
devfileContent = _a.sent();
return [4 /*yield*/, fs.readFile(editorPath)];
case 3:
devfileParsed = jsYaml.load(devfileContent);
// is there projects in the devfile ?
if (devfileParsed && !devfileParsed.projects) {
// no, so add the current project being cloned
devfileParsed.projects = [
{
name: githubUrl.getRepoName(),
git: {
remotes: { origin: githubUrl.getCloneUrl() },
checkoutFrom: { revision: githubUrl.getBranchName() }
}
},
];
}
// get back the content
devfileContent = jsYaml.dump(devfileParsed);
return [3 /*break*/, 5];
case 3: return [4 /*yield*/, fs.readFile(devfilePath)];
case 4:
devfileContent = _a.sent();
_a.label = 5;
case 5:
// enhance projects
devfileContent = this.replaceIfExistingProjects(devfileContent, projects);
if (!editorEntry) return [3 /*break*/, 7];
return [4 /*yield*/, container.get(plugin_registry_resolver_1.PluginRegistryResolver).loadDevfilePlugin(editorEntry)];
case 6:
editorDevfile = _a.sent();
editorContent = jsYaml.dump(editorDevfile);
return [3 /*break*/, 9];
case 7: return [4 /*yield*/, fs.readFile(editorPath)];
case 8:
editorContent = _a.sent();
_a.label = 9;
case 9:
generate = container.get(generate_1.Generate);

@@ -146,2 +209,28 @@ return [2 /*return*/, generate.generate(devfileContent, editorContent, outputFile)];

};
// Update project entry based on the projects passed as parameter
Main.prototype.replaceIfExistingProjects = function (devfileContent, projects) {
// do nothing if no override
if (projects.length === 0) {
return devfileContent;
}
var devfileParsed = jsYaml.load(devfileContent);
if (!devfileParsed || !devfileParsed.projects) {
return devfileContent;
}
devfileParsed.projects = devfileParsed.projects.map(function (project) {
var userProjectConfiguration = projects.find(function (p) { return p.name === project.name; });
if (userProjectConfiguration) {
if (userProjectConfiguration.location.endsWith('.zip')) {
// delete git section and use instead zip
delete project.git;
project.zip = { location: userProjectConfiguration.location };
}
else {
project.git.remotes.origin = userProjectConfiguration.location;
}
}
return project;
});
return jsYaml.dump(devfileParsed);
};
return Main;

@@ -148,0 +237,0 @@ }());

{
"name": "@eclipse-che/che-code-devworkspace-handler",
"version": "1.64.0-dev-4c3f224",
"version": "1.64.0-dev-77b11ab",
"private": false,
"description": "Handle management of devWorkspace templates for che-code",
"main": "lib/entrypoint.js",
"bin": {
"che-code-devworkspace-handler": "lib/entrypoint.js"
},
"publishConfig": {

@@ -39,2 +43,3 @@ "access": "public"

"axios": "0.21.2",
"fs-extra": "^10.0.0",
"inversify": "^5.0.1",

@@ -48,3 +53,2 @@ "js-yaml": "^4.0.0",

"eslint": "^8.1.0",
"fs-extra": "^10.0.0",
"if-env": "^1.0.4",

@@ -75,2 +79,10 @@ "jest": "^27.3.1",

],
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
},
"coverageDirectory": "coverage",

@@ -77,0 +89,0 @@ "modulePathIgnorePatterns": [

@@ -0,1 +1,2 @@

#!/usr/bin/env node
/**********************************************************************

@@ -2,0 +3,0 @@ * Copyright (c) 2021 Red Hat, Inc.

@@ -12,5 +12,9 @@ /**********************************************************************

import { AxiosInstance } from 'axios';
import { Container } from 'inversify';
import { devfileModule } from '../devfile/devfile-module';
import { k8sModule } from '../k8s/k8s-module';
import { fetchModule } from '../fetch/fetch-module';
import { githubModule } from '../github/github-module';
import { pluginRegistryModule } from '../plugin-registry/plugin-registry-module';

@@ -31,3 +35,10 @@ /**

this.container.load(devfileModule);
this.container.load(fetchModule);
this.container.load(githubModule);
this.container.load(k8sModule);
this.container.load(pluginRegistryModule);
this.container.bind(Symbol.for('AxiosInstance')).toConstantValue(options.axiosInstance);
this.container.bind('string').toConstantValue(options.pluginRegistryUrl).whenTargetNamed('PLUGIN_REGISTRY_URL');
return this.container;

@@ -43,2 +54,5 @@ }

insertDevWorkspaceTemplatesAsPlugin: boolean;
pluginRegistryUrl: string;
axiosInstance: AxiosInstance;
}

@@ -11,6 +11,11 @@ /**********************************************************************

import * as axios from 'axios';
import * as fs from 'fs-extra';
import { Generate } from './generate';
import { GithubResolver } from './github/github-resolver';
import * as jsYaml from 'js-yaml';
import { InversifyBinding } from './inversify/inversify-binding';
import { UrlFetcher } from './fetch/url-fetcher';
import { PluginRegistryResolver } from './plugin-registry/plugin-registry-resolver';
import { V1alpha2DevWorkspaceSpecTemplate } from '@devfile/api';

@@ -20,4 +25,9 @@ export class Main {

let devfilePath: string | undefined;
let devfileUrl: string | undefined;
let outputFile: string | undefined;
let editorPath: string | undefined;
let pluginRegistryUrl: string | undefined;
let editorEntry: string | undefined;
const projects: { name: string; location: string }[] = [];
const args = process.argv.slice(2);

@@ -28,2 +38,11 @@ args.forEach(arg => {

}
if (arg.startsWith('--devfile-url:')) {
devfileUrl = arg.substring('--devfile-url:'.length);
}
if (arg.startsWith('--plugin-registry-url:')) {
pluginRegistryUrl = arg.substring('--plugin-registry-url:'.length);
}
if (arg.startsWith('--editor-entry:')) {
editorEntry = arg.substring('--editor-entry:'.length);
}
if (arg.startsWith('--editor-path:')) {

@@ -35,9 +54,18 @@ editorPath = arg.substring('--editor-path:'.length);

}
if (arg.startsWith('--project.')) {
const name = arg.substring('--project.'.length, arg.indexOf('='));
const location = arg.substring(arg.indexOf('=') + 1);
projects.push({ name, location });
}
});
if (!editorPath) {
throw new Error('missing --editor-path: parameter');
if (!editorPath && !editorEntry) {
throw new Error('missing --editor-path: or --editor-entry: parameter');
}
if (!devfilePath) {
throw new Error('missing --devfile-path: parameter');
if (editorEntry && !pluginRegistryUrl) {
pluginRegistryUrl = 'https://eclipse-che.github.io/che-plugin-registry/main/v3';
console.log(`No plug-in registry url. Setting to ${pluginRegistryUrl}`);
}
if (!devfilePath && !devfileUrl) {
throw new Error('missing --devfile-path: or --devfile-url: parameter');
}
if (!outputFile) {

@@ -47,11 +75,54 @@ throw new Error('missing --output-file: parameter');

const axiosInstance = axios.default;
const inversifyBinbding = new InversifyBinding();
const container = await inversifyBinbding.initBindings({
pluginRegistryUrl,
insertDevWorkspaceTemplatesAsPlugin: true,
axiosInstance,
});
container.bind(Generate).toSelf().inSingletonScope();
const devfileContent = await fs.readFile(devfilePath);
const editorContent = await fs.readFile(editorPath);
let devfileContent;
let editorContent;
// gets the github URL
if (devfileUrl) {
const githubResolver = container.get(GithubResolver);
const githubUrl = githubResolver.resolve(devfileUrl);
// user devfile
devfileContent = await container.get(UrlFetcher).fetchText(githubUrl.getContentUrl('devfile.yaml'));
// load content
const devfileParsed = jsYaml.load(devfileContent);
// is there projects in the devfile ?
if (devfileParsed && !devfileParsed.projects) {
// no, so add the current project being cloned
devfileParsed.projects = [
{
name: githubUrl.getRepoName(),
git: {
remotes: { origin: githubUrl.getCloneUrl() },
checkoutFrom: { revision: githubUrl.getBranchName() },
},
},
];
}
// get back the content
devfileContent = jsYaml.dump(devfileParsed);
} else {
devfileContent = await fs.readFile(devfilePath);
}
// enhance projects
devfileContent = this.replaceIfExistingProjects(devfileContent, projects);
if (editorEntry) {
// devfile of the editor
const editorDevfile = await container.get(PluginRegistryResolver).loadDevfilePlugin(editorEntry);
editorContent = jsYaml.dump(editorDevfile);
} else {
editorContent = await fs.readFile(editorPath);
}
const generate = container.get(Generate);

@@ -71,2 +142,29 @@ return generate.generate(devfileContent, editorContent, outputFile);

}
// Update project entry based on the projects passed as parameter
public replaceIfExistingProjects(devfileContent: string, projects: { name: string; location: string }[]): string {
// do nothing if no override
if (projects.length === 0) {
return devfileContent;
}
const devfileParsed: V1alpha2DevWorkspaceSpecTemplate = jsYaml.load(devfileContent);
if (!devfileParsed || !devfileParsed.projects) {
return devfileContent;
}
devfileParsed.projects = devfileParsed.projects.map(project => {
const userProjectConfiguration = projects.find(p => p.name === project.name);
if (userProjectConfiguration) {
if (userProjectConfiguration.location.endsWith('.zip')) {
// delete git section and use instead zip
delete project.git;
project.zip = { location: userProjectConfiguration.location };
} else {
project.git.remotes.origin = userProjectConfiguration.location;
}
}
return project;
});
return jsYaml.dump(devfileParsed);
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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