@eclipse-che/che-theia-devworkspace-handler
Advanced tools
Comparing version 0.0.1-1636123823 to 0.0.1-1636126533
@@ -16,4 +16,5 @@ /********************************************************************** | ||
export declare class DevContainerComponentFinder { | ||
static readonly DEV_CONTAINER_ATTRIBUTE = "che-theia.eclipse.org/dev-container"; | ||
find(devfileContext: DevfileContext): Promise<V1alpha2DevWorkspaceSpecTemplateComponents>; | ||
} | ||
//# sourceMappingURL=dev-container-component-finder.d.ts.map |
@@ -17,2 +17,3 @@ "use strict"; | ||
}; | ||
var DevContainerComponentFinder_1; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -24,8 +25,22 @@ exports.DevContainerComponentFinder = void 0; | ||
*/ | ||
let DevContainerComponentFinder = class DevContainerComponentFinder { | ||
let DevContainerComponentFinder = DevContainerComponentFinder_1 = class DevContainerComponentFinder { | ||
async find(devfileContext) { | ||
// need to find definition | ||
var _a, _b, _c; | ||
var _a, _b, _c, _d, _e, _f; | ||
// first search if we have an optional annotated container | ||
const annotatedContainers = (_c = (_b = (_a = devfileContext.devWorkspace.spec) === null || _a === void 0 ? void 0 : _a.template) === null || _b === void 0 ? void 0 : _b.components) === null || _c === void 0 ? void 0 : _c.filter(component => component.attributes && | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
component.attributes[DevContainerComponentFinder_1.DEV_CONTAINER_ATTRIBUTE] === true); | ||
if (annotatedContainers) { | ||
if (annotatedContainers.length === 1) { | ||
return annotatedContainers[0]; | ||
} | ||
else if (annotatedContainers.length > 1) { | ||
throw new Error(`Only one container can be annotated with ${DevContainerComponentFinder_1.DEV_CONTAINER_ATTRIBUTE}: true`); | ||
} | ||
} | ||
// search in main devWorkspace (exclude theia as component name) | ||
const devComponents = (_c = (_b = (_a = devfileContext.devWorkspace.spec) === null || _a === void 0 ? void 0 : _a.template) === null || _b === void 0 ? void 0 : _b.components) === null || _c === void 0 ? void 0 : _c.filter(component => component.container && component.name !== 'theia-ide'); | ||
const devComponents = (_f = (_e = (_d = devfileContext.devWorkspace.spec) === null || _d === void 0 ? void 0 : _d.template) === null || _e === void 0 ? void 0 : _e.components) === null || _f === void 0 ? void 0 : _f.filter(component => component.container && component.name !== 'theia-ide').filter( | ||
// we should ignore component that do not mount the sources | ||
component => component.container && component.container.mountSources !== false); | ||
// only one, fine, else error | ||
@@ -39,7 +54,9 @@ if (!devComponents || devComponents.length === 0) { | ||
else { | ||
throw new Error(`Too many components have been found that could be considered as dev container. There should be only one to merge sidecars. Found component names: ${devComponents.map(component => component.name)}`); | ||
console.warn(`More than one dev container component has been potentially found, taking the first one of ${devComponents.map(component => component.name)}`); | ||
return devComponents[0]; | ||
} | ||
} | ||
}; | ||
DevContainerComponentFinder = __decorate([ | ||
DevContainerComponentFinder.DEV_CONTAINER_ATTRIBUTE = 'che-theia.eclipse.org/dev-container'; | ||
DevContainerComponentFinder = DevContainerComponentFinder_1 = __decorate([ | ||
inversify_1.injectable() | ||
@@ -46,0 +63,0 @@ ], DevContainerComponentFinder); |
{ | ||
"name": "@eclipse-che/che-theia-devworkspace-handler", | ||
"version": "0.0.1-1636123823", | ||
"version": "0.0.1-1636126533", | ||
"private": false, | ||
@@ -16,3 +16,3 @@ "description": "Handle management of che-theia-plugins and devWorkspace templates", | ||
"clean": "rimraf lib", | ||
"build": "yarn run format && yarn run compile && yarn run lint", | ||
"build": "yarn run format && yarn run compile && yarn run lint && yarn run test", | ||
"compile": "tsc --project .", | ||
@@ -19,0 +19,0 @@ "format": "if-env SKIP_FORMAT=true && echo 'skip format check' || prettier --check '{src,tests}/**/*.ts' package.json", |
@@ -20,9 +20,32 @@ /********************************************************************** | ||
export class DevContainerComponentFinder { | ||
public static readonly DEV_CONTAINER_ATTRIBUTE = 'che-theia.eclipse.org/dev-container'; | ||
async find(devfileContext: DevfileContext): Promise<V1alpha2DevWorkspaceSpecTemplateComponents> { | ||
// need to find definition | ||
// first search if we have an optional annotated container | ||
const annotatedContainers = devfileContext.devWorkspace.spec?.template?.components?.filter( | ||
component => | ||
component.attributes && | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(component.attributes as any)[DevContainerComponentFinder.DEV_CONTAINER_ATTRIBUTE] === true | ||
); | ||
if (annotatedContainers) { | ||
if (annotatedContainers.length === 1) { | ||
return annotatedContainers[0]; | ||
} else if (annotatedContainers.length > 1) { | ||
throw new Error( | ||
`Only one container can be annotated with ${DevContainerComponentFinder.DEV_CONTAINER_ATTRIBUTE}: true` | ||
); | ||
} | ||
} | ||
// search in main devWorkspace (exclude theia as component name) | ||
const devComponents = devfileContext.devWorkspace.spec?.template?.components?.filter( | ||
component => component.container && component.name !== 'theia-ide' | ||
); | ||
const devComponents = devfileContext.devWorkspace.spec?.template?.components | ||
?.filter(component => component.container && component.name !== 'theia-ide') | ||
.filter( | ||
// we should ignore component that do not mount the sources | ||
component => component.container && component.container.mountSources !== false | ||
); | ||
// only one, fine, else error | ||
@@ -34,9 +57,10 @@ if (!devComponents || devComponents.length === 0) { | ||
} else { | ||
throw new Error( | ||
`Too many components have been found that could be considered as dev container. There should be only one to merge sidecars. Found component names: ${devComponents.map( | ||
console.warn( | ||
`More than one dev container component has been potentially found, taking the first one of ${devComponents.map( | ||
component => component.name | ||
)}` | ||
); | ||
return devComponents[0]; | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
203890
3285