@teambit/envs 0.0.0-3e44e878fae3f5f31fce2dc240a57a798e67137e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/context/context.ts +55 -0
- package/context/index.ts +1 -0
- package/dist/context/context.d.ts +44 -0
- package/dist/context/context.js +61 -0
- package/dist/context/context.js.map +1 -0
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.js +20 -0
- package/dist/context/index.js.map +1 -0
- package/dist/env-definition.d.ts +41 -0
- package/dist/env-definition.js +57 -0
- package/dist/env-definition.js.map +1 -0
- package/dist/env-interface.d.ts +4 -0
- package/dist/env-interface.js +3 -0
- package/dist/env-interface.js.map +1 -0
- package/dist/env-jsonc.detector.d.ts +5 -0
- package/dist/env-jsonc.detector.js +26 -0
- package/dist/env-jsonc.detector.js.map +1 -0
- package/dist/env-service-list.d.ts +35 -0
- package/dist/env-service-list.js +37 -0
- package/dist/env-service-list.js.map +1 -0
- package/dist/env.composition.d.ts +1 -0
- package/dist/env.composition.js +29 -0
- package/dist/env.composition.js.map +1 -0
- package/dist/env.fragment.d.ts +17 -0
- package/dist/env.fragment.js +48 -0
- package/dist/env.fragment.js.map +1 -0
- package/dist/env.plugin.d.ts +20 -0
- package/dist/env.plugin.js +92 -0
- package/dist/env.plugin.js.map +1 -0
- package/dist/environment.d.ts +201 -0
- package/dist/environment.js +17 -0
- package/dist/environment.js.map +1 -0
- package/dist/environments.aspect.d.ts +2 -0
- package/dist/environments.aspect.js +18 -0
- package/dist/environments.aspect.js.map +1 -0
- package/dist/environments.graphql.d.ts +3 -0
- package/dist/environments.graphql.js +36 -0
- package/dist/environments.graphql.js.map +1 -0
- package/dist/environments.main.runtime.d.ts +366 -0
- package/dist/environments.main.runtime.js +1160 -0
- package/dist/environments.main.runtime.js.map +1 -0
- package/dist/envs.cmd.d.ts +51 -0
- package/dist/envs.cmd.js +153 -0
- package/dist/envs.cmd.js.map +1 -0
- package/dist/envs.docs.mdx +8 -0
- package/dist/esm.mjs +13 -0
- package/dist/exceptions/env-not-configured-for-component.d.ts +4 -0
- package/dist/exceptions/env-not-configured-for-component.js +24 -0
- package/dist/exceptions/env-not-configured-for-component.js.map +1 -0
- package/dist/exceptions/env-not-found-in-runtime.d.ts +5 -0
- package/dist/exceptions/env-not-found-in-runtime.js +22 -0
- package/dist/exceptions/env-not-found-in-runtime.js.map +1 -0
- package/dist/exceptions/env-not-found.d.ts +6 -0
- package/dist/exceptions/env-not-found.js +27 -0
- package/dist/exceptions/env-not-found.js.map +1 -0
- package/dist/exceptions/index.d.ts +3 -0
- package/dist/exceptions/index.js +46 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +128 -0
- package/dist/index.js.map +1 -0
- package/dist/preview-1752254355761.js +7 -0
- package/dist/runtime/env-runtime.d.ts +41 -0
- package/dist/runtime/env-runtime.js +36 -0
- package/dist/runtime/env-runtime.js.map +1 -0
- package/dist/runtime/envs-execution-result.d.ts +18 -0
- package/dist/runtime/envs-execution-result.js +56 -0
- package/dist/runtime/envs-execution-result.js.map +1 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +33 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/runtime.d.ts +49 -0
- package/dist/runtime/runtime.js +117 -0
- package/dist/runtime/runtime.js.map +1 -0
- package/dist/services/concrete-service.d.ts +8 -0
- package/dist/services/concrete-service.js +3 -0
- package/dist/services/concrete-service.js.map +1 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.js +89 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/service-handler-context.d.ts +30 -0
- package/dist/services/service-handler-context.js +44 -0
- package/dist/services/service-handler-context.js.map +1 -0
- package/dist/services/service-handler.d.ts +18 -0
- package/dist/services/service-handler.js +25 -0
- package/dist/services/service-handler.js.map +1 -0
- package/dist/services/service.d.ts +66 -0
- package/dist/services/service.js +3 -0
- package/dist/services/service.js.map +1 -0
- package/env.composition.tsx +7 -0
- package/envs.docs.mdx +8 -0
- package/esm.mjs +13 -0
- package/exceptions/env-not-configured-for-component.ts +10 -0
- package/exceptions/env-not-found-in-runtime.ts +7 -0
- package/exceptions/env-not-found.ts +15 -0
- package/exceptions/index.ts +3 -0
- package/package.json +90 -0
- package/runtime/env-runtime.ts +31 -0
- package/runtime/envs-execution-result.ts +46 -0
- package/runtime/index.ts +2 -0
- package/runtime/runtime.ts +100 -0
- package/services/concrete-service.ts +8 -0
- package/services/index.ts +13 -0
- package/services/service-handler-context.ts +40 -0
- package/services/service-handler.ts +41 -0
- package/services/service.ts +79 -0
- package/types/asset.d.ts +41 -0
- package/types/style.d.ts +42 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "AsyncServiceHandlerFactory", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _serviceHandler().AsyncServiceHandlerFactory;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ConcreteService", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _concreteService().ConcreteService;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "EnvService", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _service().Service;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "ServiceExecutionResult", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _service().ServiceExecutionResult;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "ServiceHandler", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _serviceHandler().ServiceHandler;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "ServiceHandlerContext", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _serviceHandlerContext().ServiceHandlerContext;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "ServiceHandlerFactory", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _serviceHandler().ServiceHandlerFactory;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "ServiceTransformationMap", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _service().TransformationMap;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "reduceServiceHandlersFactories", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _serviceHandler().reduceServiceHandlersFactories;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
function _service() {
|
|
61
|
+
const data = require("./service");
|
|
62
|
+
_service = function () {
|
|
63
|
+
return data;
|
|
64
|
+
};
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
67
|
+
function _concreteService() {
|
|
68
|
+
const data = require("./concrete-service");
|
|
69
|
+
_concreteService = function () {
|
|
70
|
+
return data;
|
|
71
|
+
};
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
function _serviceHandler() {
|
|
75
|
+
const data = require("./service-handler");
|
|
76
|
+
_serviceHandler = function () {
|
|
77
|
+
return data;
|
|
78
|
+
};
|
|
79
|
+
return data;
|
|
80
|
+
}
|
|
81
|
+
function _serviceHandlerContext() {
|
|
82
|
+
const data = require("./service-handler-context");
|
|
83
|
+
_serviceHandlerContext = function () {
|
|
84
|
+
return data;
|
|
85
|
+
};
|
|
86
|
+
return data;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_service","data","require","_concreteService","_serviceHandler","_serviceHandlerContext"],"sources":["index.ts"],"sourcesContent":["export {\n Service as EnvService,\n ServiceExecutionResult,\n TransformationMap as ServiceTransformationMap,\n} from './service';\nexport { ConcreteService } from './concrete-service';\nexport {\n ServiceHandler,\n ServiceHandlerFactory,\n AsyncServiceHandlerFactory,\n reduceServiceHandlersFactories,\n} from './service-handler';\nexport { ServiceHandlerContext } from './service-handler-context';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAKA,SAAAE,iBAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,gBAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,gBAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,eAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAMA,SAAAI,uBAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,sBAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ComponentID } from '@teambit/component';
|
|
2
|
+
import { Harmony } from '@teambit/harmony';
|
|
3
|
+
import { Logger, LoggerMain } from '@teambit/logger';
|
|
4
|
+
import { WorkerMain } from '@teambit/worker';
|
|
5
|
+
export declare class ServiceHandlerContext {
|
|
6
|
+
/**
|
|
7
|
+
* id of the environment defined in the context.
|
|
8
|
+
*/
|
|
9
|
+
readonly envId: ComponentID;
|
|
10
|
+
readonly loggerMain: LoggerMain;
|
|
11
|
+
readonly workerMain: WorkerMain;
|
|
12
|
+
readonly harmony: Harmony;
|
|
13
|
+
constructor(
|
|
14
|
+
/**
|
|
15
|
+
* id of the environment defined in the context.
|
|
16
|
+
*/
|
|
17
|
+
envId: ComponentID, loggerMain: LoggerMain, workerMain: WorkerMain, harmony: Harmony);
|
|
18
|
+
/**
|
|
19
|
+
* return a logger instance for the env.
|
|
20
|
+
*/
|
|
21
|
+
createLogger(name?: string): Logger;
|
|
22
|
+
/**
|
|
23
|
+
* get an instance of an aspect. make sure it is loaded prior to requesting it.
|
|
24
|
+
*/
|
|
25
|
+
getAspect<T>(aspectId: string): T;
|
|
26
|
+
/**
|
|
27
|
+
* create worker for the env context.
|
|
28
|
+
*/
|
|
29
|
+
createWorker<T>(name: string, path: string): import("@teambit/worker").HarmonyWorker<T>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ServiceHandlerContext = void 0;
|
|
7
|
+
class ServiceHandlerContext {
|
|
8
|
+
constructor(
|
|
9
|
+
/**
|
|
10
|
+
* id of the environment defined in the context.
|
|
11
|
+
*/
|
|
12
|
+
envId, loggerMain, workerMain, harmony) {
|
|
13
|
+
this.envId = envId;
|
|
14
|
+
this.loggerMain = loggerMain;
|
|
15
|
+
this.workerMain = workerMain;
|
|
16
|
+
this.harmony = harmony;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* return a logger instance for the env.
|
|
21
|
+
*/
|
|
22
|
+
createLogger(name) {
|
|
23
|
+
const loggerName = name ? `${this.envId.toString()}::${name}` : this.envId.toString();
|
|
24
|
+
return this.loggerMain.createLogger(loggerName);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* get an instance of an aspect. make sure it is loaded prior to requesting it.
|
|
29
|
+
*/
|
|
30
|
+
getAspect(aspectId) {
|
|
31
|
+
return this.harmony.get(aspectId);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* create worker for the env context.
|
|
36
|
+
*/
|
|
37
|
+
createWorker(name, path) {
|
|
38
|
+
const worker = this.workerMain.declareWorker(name, path);
|
|
39
|
+
return worker;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.ServiceHandlerContext = ServiceHandlerContext;
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=service-handler-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ServiceHandlerContext","constructor","envId","loggerMain","workerMain","harmony","createLogger","name","loggerName","toString","getAspect","aspectId","get","createWorker","path","worker","declareWorker","exports"],"sources":["service-handler-context.ts"],"sourcesContent":["import { ComponentID } from '@teambit/component';\nimport { Harmony } from '@teambit/harmony';\nimport { Logger, LoggerMain } from '@teambit/logger';\nimport { WorkerMain } from '@teambit/worker';\n\nexport class ServiceHandlerContext {\n constructor(\n /**\n * id of the environment defined in the context.\n */\n readonly envId: ComponentID,\n readonly loggerMain: LoggerMain,\n readonly workerMain: WorkerMain,\n readonly harmony: Harmony\n ) {}\n\n /**\n * return a logger instance for the env.\n */\n createLogger(name?: string): Logger {\n const loggerName = name ? `${this.envId.toString()}::${name}` : this.envId.toString();\n\n return this.loggerMain.createLogger(loggerName);\n }\n\n /**\n * get an instance of an aspect. make sure it is loaded prior to requesting it.\n */\n getAspect<T>(aspectId: string) {\n return this.harmony.get<T>(aspectId);\n }\n\n /**\n * create worker for the env context.\n */\n createWorker<T>(name: string, path: string) {\n const worker = this.workerMain.declareWorker<T>(name, path);\n return worker;\n }\n}\n"],"mappings":";;;;;;AAKO,MAAMA,qBAAqB,CAAC;EACjCC,WAAWA;EACT;AACJ;AACA;EACaC,KAAkB,EAClBC,UAAsB,EACtBC,UAAsB,EACtBC,OAAgB,EACzB;IAAA,KAJSH,KAAkB,GAAlBA,KAAkB;IAAA,KAClBC,UAAsB,GAAtBA,UAAsB;IAAA,KACtBC,UAAsB,GAAtBA,UAAsB;IAAA,KACtBC,OAAgB,GAAhBA,OAAgB;EACxB;;EAEH;AACF;AACA;EACEC,YAAYA,CAACC,IAAa,EAAU;IAClC,MAAMC,UAAU,GAAGD,IAAI,GAAG,GAAG,IAAI,CAACL,KAAK,CAACO,QAAQ,CAAC,CAAC,KAAKF,IAAI,EAAE,GAAG,IAAI,CAACL,KAAK,CAACO,QAAQ,CAAC,CAAC;IAErF,OAAO,IAAI,CAACN,UAAU,CAACG,YAAY,CAACE,UAAU,CAAC;EACjD;;EAEA;AACF;AACA;EACEE,SAASA,CAAIC,QAAgB,EAAE;IAC7B,OAAO,IAAI,CAACN,OAAO,CAACO,GAAG,CAAID,QAAQ,CAAC;EACtC;;EAEA;AACF;AACA;EACEE,YAAYA,CAAIN,IAAY,EAAEO,IAAY,EAAE;IAC1C,MAAMC,MAAM,GAAG,IAAI,CAACX,UAAU,CAACY,aAAa,CAAIT,IAAI,EAAEO,IAAI,CAAC;IAC3D,OAAOC,MAAM;EACf;AACF;AAACE,OAAA,CAAAjB,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ServiceHandlerContext } from './service-handler-context';
|
|
2
|
+
/**
|
|
3
|
+
* definition of the service handler.
|
|
4
|
+
*/
|
|
5
|
+
export type ServiceHandlerFactory<T> = (context: ServiceHandlerContext) => ServiceHandler & T;
|
|
6
|
+
export type AsyncServiceHandlerFactory<T> = (context: ServiceHandlerContext) => Promise<ServiceHandler & T>;
|
|
7
|
+
export interface ServiceHandler {
|
|
8
|
+
/**
|
|
9
|
+
* name of the service. e.g. 'typescript-compiler'
|
|
10
|
+
*/
|
|
11
|
+
name?: string;
|
|
12
|
+
/**
|
|
13
|
+
* version of the service. optional.
|
|
14
|
+
*/
|
|
15
|
+
version?: () => string;
|
|
16
|
+
}
|
|
17
|
+
export type ReduceFactoryCallback<T> = (acc: T, value: T) => ServiceHandler & T;
|
|
18
|
+
export declare function reduceServiceHandlersFactories<T>(factories: ServiceHandlerFactory<T>[], callback: ReduceFactoryCallback<T>): ServiceHandlerFactory<T>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.reduceServiceHandlersFactories = reduceServiceHandlersFactories;
|
|
7
|
+
/**
|
|
8
|
+
* definition of the service handler.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
function reduceServiceHandlersFactories(factories, callback) {
|
|
12
|
+
if (!factories.length) throw new Error('no factories were provided');
|
|
13
|
+
const result = context => {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
const initialVal = factories.shift()(context);
|
|
16
|
+
const reduced = factories.reduce((acc, currFactory) => {
|
|
17
|
+
const curr = currFactory(context);
|
|
18
|
+
return callback(acc, curr);
|
|
19
|
+
}, initialVal);
|
|
20
|
+
return reduced;
|
|
21
|
+
};
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=service-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["reduceServiceHandlersFactories","factories","callback","length","Error","result","context","initialVal","shift","reduced","reduce","acc","currFactory","curr"],"sources":["service-handler.ts"],"sourcesContent":["import { ServiceHandlerContext } from './service-handler-context';\n\n/**\n * definition of the service handler.\n */\nexport type ServiceHandlerFactory<T> = (context: ServiceHandlerContext) => ServiceHandler & T;\nexport type AsyncServiceHandlerFactory<T> = (context: ServiceHandlerContext) => Promise<ServiceHandler & T>;\n\nexport interface ServiceHandler {\n /**\n * name of the service. e.g. 'typescript-compiler'\n */\n name?: string;\n /**\n * version of the service. optional.\n */\n version?: () => string;\n\n /**\n * config of the service. e.g. tsconfig.json\n */\n // config?: string;\n}\n\nexport type ReduceFactoryCallback<T> = (acc: T, value: T) => ServiceHandler & T;\nexport function reduceServiceHandlersFactories<T>(\n factories: ServiceHandlerFactory<T>[],\n callback: ReduceFactoryCallback<T>\n): ServiceHandlerFactory<T> {\n if (!factories.length) throw new Error('no factories were provided');\n const result: ServiceHandlerFactory<T> = (context: ServiceHandlerContext) => {\n // @ts-ignore\n const initialVal = factories.shift()(context);\n const reduced: ServiceHandler & T = factories.reduce((acc, currFactory) => {\n const curr = currFactory(context);\n return callback(acc, curr);\n }, initialVal);\n return reduced;\n };\n return result;\n}\n"],"mappings":";;;;;;AAEA;AACA;AACA;;AAqBO,SAASA,8BAA8BA,CAC5CC,SAAqC,EACrCC,QAAkC,EACR;EAC1B,IAAI,CAACD,SAAS,CAACE,MAAM,EAAE,MAAM,IAAIC,KAAK,CAAC,4BAA4B,CAAC;EACpE,MAAMC,MAAgC,GAAIC,OAA8B,IAAK;IAC3E;IACA,MAAMC,UAAU,GAAGN,SAAS,CAACO,KAAK,CAAC,CAAC,CAACF,OAAO,CAAC;IAC7C,MAAMG,OAA2B,GAAGR,SAAS,CAACS,MAAM,CAAC,CAACC,GAAG,EAAEC,WAAW,KAAK;MACzE,MAAMC,IAAI,GAAGD,WAAW,CAACN,OAAO,CAAC;MACjC,OAAOJ,QAAQ,CAACS,GAAG,EAAEE,IAAI,CAAC;IAC5B,CAAC,EAAEN,UAAU,CAAC;IACd,OAAOE,OAAO;EAChB,CAAC;EACD,OAAOJ,MAAM;AACf","ignoreList":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Component } from '@teambit/component';
|
|
2
|
+
import { Env } from '../env-interface';
|
|
3
|
+
import { Environment } from '../environment';
|
|
4
|
+
import { ServiceHandler } from './service-handler';
|
|
5
|
+
import { ServiceHandlerContext } from './service-handler-context';
|
|
6
|
+
export type EnvContext = {
|
|
7
|
+
components: Component[];
|
|
8
|
+
};
|
|
9
|
+
export interface ServiceExecutionResult {
|
|
10
|
+
errors?: Error[];
|
|
11
|
+
}
|
|
12
|
+
export type ServiceTransformHandlerFactory<T> = (handlerContext?: any) => (ServiceHandler & T) | Promise<ServiceHandler & T>;
|
|
13
|
+
/**
|
|
14
|
+
* definition of the service handler type
|
|
15
|
+
* This used to define new types of handlers like
|
|
16
|
+
* Compiler, Tester, Preview, etc.
|
|
17
|
+
*/
|
|
18
|
+
export type TransformationMap = {
|
|
19
|
+
/**
|
|
20
|
+
* The name of the function that will be called on the service run/run once later.
|
|
21
|
+
* This func will be exist on the final env object
|
|
22
|
+
*/
|
|
23
|
+
[funcName: string]: ServiceTransformHandlerFactory<any>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* services allows to reuse and standardize services for development environments.
|
|
27
|
+
* examples for services can be: `linting`, `compilation`, `build`, and others which offer
|
|
28
|
+
* standard services to environments such as `react`, `angular` and `vue` and different compositions of each for
|
|
29
|
+
* more concrete needs.
|
|
30
|
+
*
|
|
31
|
+
* `TData` - type of data returned by the service handler.
|
|
32
|
+
* `TOpts` is the type of options passed to the environment through execution.
|
|
33
|
+
* `TExecResponse` is the execution result of the service.
|
|
34
|
+
*/
|
|
35
|
+
export interface Service<TExecResponse extends ServiceExecutionResult, TData = {}, TOpts = {}> {
|
|
36
|
+
/**
|
|
37
|
+
* name of the service. (e.g. `compile`, `test`, etc.)
|
|
38
|
+
*/
|
|
39
|
+
name?: string;
|
|
40
|
+
/**
|
|
41
|
+
* description of the env.
|
|
42
|
+
*/
|
|
43
|
+
description?: string;
|
|
44
|
+
/**
|
|
45
|
+
* create a string to describe to service in the env cli.
|
|
46
|
+
*/
|
|
47
|
+
render?(env: Environment, context: EnvContext[]): string | Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* get service data from an environment.
|
|
50
|
+
*/
|
|
51
|
+
getDescriptor?(environment: Environment, context?: EnvContext[]): TData | undefined | Promise<TData | undefined>;
|
|
52
|
+
/**
|
|
53
|
+
* executes a service on a subset of components.
|
|
54
|
+
*/
|
|
55
|
+
run?(context: EnvContext, options?: TOpts): Promise<TExecResponse>;
|
|
56
|
+
/**
|
|
57
|
+
* run the service only once.
|
|
58
|
+
*/
|
|
59
|
+
runOnce?(context: EnvContext[], options?: TOpts): Promise<any>;
|
|
60
|
+
/**
|
|
61
|
+
* Return a map of functions that will be called on the service run/run once later.
|
|
62
|
+
* @param env the original env plugin object
|
|
63
|
+
* @param context ServiceHandlerContext(EnvContext)
|
|
64
|
+
*/
|
|
65
|
+
transform?(env: Env, context: ServiceHandlerContext): TransformationMap | undefined;
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["service.ts"],"sourcesContent":["import { Component } from '@teambit/component';\nimport { Env } from '../env-interface';\nimport { Environment } from '../environment';\nimport { ServiceHandler } from './service-handler';\nimport { ServiceHandlerContext } from './service-handler-context';\n\nexport type EnvContext = {\n components: Component[];\n};\n\nexport interface ServiceExecutionResult {\n errors?: Error[];\n}\n\nexport type ServiceTransformHandlerFactory<T> = (\n handlerContext?: any\n) => (ServiceHandler & T) | Promise<ServiceHandler & T>;\n\n/**\n * definition of the service handler type\n * This used to define new types of handlers like\n * Compiler, Tester, Preview, etc.\n */\nexport type TransformationMap = {\n /**\n * The name of the function that will be called on the service run/run once later.\n * This func will be exist on the final env object\n */\n [funcName: string]: ServiceTransformHandlerFactory<any>;\n};\n\n/**\n * services allows to reuse and standardize services for development environments.\n * examples for services can be: `linting`, `compilation`, `build`, and others which offer\n * standard services to environments such as `react`, `angular` and `vue` and different compositions of each for\n * more concrete needs.\n *\n * `TData` - type of data returned by the service handler.\n * `TOpts` is the type of options passed to the environment through execution.\n * `TExecResponse` is the execution result of the service.\n */\nexport interface Service<TExecResponse extends ServiceExecutionResult, TData = {}, TOpts = {}> {\n /**\n * name of the service. (e.g. `compile`, `test`, etc.)\n */\n name?: string;\n\n /**\n * description of the env.\n */\n description?: string;\n\n /**\n * create a string to describe to service in the env cli.\n */\n render?(env: Environment, context: EnvContext[]): string | Promise<string>;\n\n /**\n * get service data from an environment.\n */\n getDescriptor?(environment: Environment, context?: EnvContext[]): TData | undefined | Promise<TData | undefined>;\n\n /**\n * executes a service on a subset of components.\n */\n run?(context: EnvContext, options?: TOpts): Promise<TExecResponse>;\n\n /**\n * run the service only once.\n */\n runOnce?(context: EnvContext[], options?: TOpts): Promise<any>;\n\n /**\n * Return a map of functions that will be called on the service run/run once later.\n * @param env the original env plugin object\n * @param context ServiceHandlerContext(EnvContext)\n */\n transform?(env: Env, context: ServiceHandlerContext): TransformationMap | undefined;\n}\n"],"mappings":"","ignoreList":[]}
|
package/envs.docs.mdx
ADDED
package/esm.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-unresolved
|
|
2
|
+
import cjsModule from './index.js';
|
|
3
|
+
|
|
4
|
+
export const EnvsAspect = cjsModule.EnvsAspect;
|
|
5
|
+
export const EnvContext = cjsModule.EnvContext;
|
|
6
|
+
export const DEFAULT_ENV = cjsModule.DEFAULT_ENV;
|
|
7
|
+
export const ExecutionContext = cjsModule.ExecutionContext;
|
|
8
|
+
export const reduceServiceHandlersFactories = cjsModule.reduceServiceHandlersFactories;
|
|
9
|
+
export const EnvRuntime = cjsModule.EnvRuntime;
|
|
10
|
+
export const EnvsExecutionResult = cjsModule.EnvsExecutionResult;
|
|
11
|
+
export const EnvDefinition = cjsModule.EnvDefinition;
|
|
12
|
+
|
|
13
|
+
export default cjsModule;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BitError } from '@teambit/bit-error';
|
|
2
|
+
|
|
3
|
+
export class EnvNotConfiguredForComponent extends BitError {
|
|
4
|
+
constructor(id: string, componentId?: string) {
|
|
5
|
+
const suffix = componentId ? ` for the component ${componentId}` : '';
|
|
6
|
+
super(`environment with ID: "${id}" is not configured as extension${suffix}.
|
|
7
|
+
you probably need to set this environment to your component(s). for example, "bit env set <component-pattern> ${id}"
|
|
8
|
+
`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BitError } from '@teambit/bit-error';
|
|
2
|
+
|
|
3
|
+
export class EnvNotFound extends BitError {
|
|
4
|
+
constructor(
|
|
5
|
+
private id: string,
|
|
6
|
+
private componentId?: string
|
|
7
|
+
) {
|
|
8
|
+
super(getMessage(id, componentId));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getMessage(id: string, componentId?: string): string {
|
|
13
|
+
const compIdDetails = componentId ? `configured on component ${componentId}` : '';
|
|
14
|
+
return `environment with ID: ${id} ${compIdDetails} was not found`;
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@teambit/envs",
|
|
3
|
+
"version": "0.0.0-3e44e878fae3f5f31fce2dc240a57a798e67137e",
|
|
4
|
+
"homepage": "https://bit.cloud/teambit/envs/envs",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"componentId": {
|
|
7
|
+
"scope": "teambit.envs",
|
|
8
|
+
"name": "envs",
|
|
9
|
+
"version": "3e44e878fae3f5f31fce2dc240a57a798e67137e"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"comment-json": "4.2.5",
|
|
13
|
+
"chalk": "4.1.2",
|
|
14
|
+
"lodash": "4.17.21",
|
|
15
|
+
"graphql-tag": "2.12.1",
|
|
16
|
+
"p-locate": "5.0.0",
|
|
17
|
+
"p-map-series": "2.1.0",
|
|
18
|
+
"@teambit/harmony": "0.4.7",
|
|
19
|
+
"@teambit/bit-error": "0.0.404",
|
|
20
|
+
"@teambit/component-id": "1.2.4",
|
|
21
|
+
"@teambit/dependency-resolver": "0.0.0-19d0b976dbeddcecb365fb558ea83042f04ab2d1",
|
|
22
|
+
"@teambit/component": "0.0.0-c8ba8f4e3b6fdc2e774efe3c2d40eac295ccd914",
|
|
23
|
+
"@teambit/aspect-loader": "0.0.0-7ea1cbdf0e9bd47c4a1d51479ce10c975b28c953",
|
|
24
|
+
"@teambit/cli": "0.0.0-d52a20dfe7f90d6d807ddba2a1deef609d335076",
|
|
25
|
+
"@teambit/logger": "0.0.0-5dec32734b29aa18fab6933c221ed88ec6cad975",
|
|
26
|
+
"@teambit/worker": "0.0.0-ebf2fb59e3f5526c8e7a5e2edfd029c06179697c",
|
|
27
|
+
"@teambit/builder": "0.0.0-6bd1048b37afde835ce234c006226828c5e6a66c",
|
|
28
|
+
"@teambit/bundler": "0.0.0-0cf352ce9e86ee13b74f6603d8b93ca26f9e8d89",
|
|
29
|
+
"@teambit/compiler": "0.0.0-eda8f485d7d4c0c7f81596735f67c3e664b12be0",
|
|
30
|
+
"@teambit/formatter": "0.0.0-1a616cfd1feccfbdc35ef05b801437b4f4f995c0",
|
|
31
|
+
"@teambit/isolator": "0.0.0-32ffef9b6a8b78db2d8f8af969486ee8b04571db",
|
|
32
|
+
"@teambit/linter": "0.0.0-0d0aaa7ddeaa4d78dd244bae82eb612826f0aad9",
|
|
33
|
+
"@teambit/pkg": "0.0.0-8fc29d531e629f35c2e58a1143664a2d6a77ac8f",
|
|
34
|
+
"@teambit/preview": "0.0.0-95dacf87f5f920d5ba9e07d049e5db1bde70090f",
|
|
35
|
+
"@teambit/schema": "0.0.0-a0ccff8e3e73763262206b81e90f34b832b4fa6f",
|
|
36
|
+
"@teambit/tester": "0.0.0-9c53069e69970106400a9343fad851e13f3937d2",
|
|
37
|
+
"@teambit/typescript": "0.0.0-db4aec20dc9806fe40f565da134118923c576706",
|
|
38
|
+
"@teambit/webpack": "0.0.0-24b7f745a9a18c534db1d211592707afeb57f067",
|
|
39
|
+
"@teambit/graphql": "0.0.0-fd3e774bac57829b5798d5c35433faed38d0292d",
|
|
40
|
+
"@teambit/component-issues": "0.0.159",
|
|
41
|
+
"@teambit/component.sources": "0.0.0-0a7957d9dce8437df5c368f4c1278bf3f2b1f560",
|
|
42
|
+
"@teambit/dev-files": "0.0.0-a8cf4609d2167ba8d86fa8d612d1752bedbc23cd",
|
|
43
|
+
"@teambit/issues": "0.0.0-47aa9235bd6b99f4b9bc0458e0deed4fce546d52",
|
|
44
|
+
"@teambit/legacy.consumer-component": "0.0.0-dba92da5457a298373d07f2bb6057c0d91e1f494",
|
|
45
|
+
"@teambit/legacy.extension-data": "0.0.0-6c006730fa831ef48f3a6ef6765e95d8a1209999",
|
|
46
|
+
"@teambit/toolbox.array.duplications-finder": "0.0.3",
|
|
47
|
+
"@teambit/cli-table": "0.0.50"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/lodash": "4.14.165",
|
|
51
|
+
"@types/mocha": "9.1.0",
|
|
52
|
+
"@teambit/harmony.envs.core-aspect-env": "0.0.69",
|
|
53
|
+
"@teambit/envs.aspect-docs.envs": "0.0.173"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"react": "^17.0.0 || ^18.0.0",
|
|
57
|
+
"@types/react": "^17.0.73"
|
|
58
|
+
},
|
|
59
|
+
"license": "Apache-2.0",
|
|
60
|
+
"optionalDependencies": {},
|
|
61
|
+
"peerDependenciesMeta": {},
|
|
62
|
+
"exports": {
|
|
63
|
+
".": {
|
|
64
|
+
"node": {
|
|
65
|
+
"require": "./dist/index.js",
|
|
66
|
+
"import": "./dist/esm.mjs"
|
|
67
|
+
},
|
|
68
|
+
"default": "./dist/index.js"
|
|
69
|
+
},
|
|
70
|
+
"./dist/*": "./dist/*",
|
|
71
|
+
"./artifacts/*": "./artifacts/*",
|
|
72
|
+
"./*": "./*.ts"
|
|
73
|
+
},
|
|
74
|
+
"private": false,
|
|
75
|
+
"engines": {
|
|
76
|
+
"node": ">=16.0.0"
|
|
77
|
+
},
|
|
78
|
+
"repository": {
|
|
79
|
+
"type": "git",
|
|
80
|
+
"url": "https://github.com/teambit/bit"
|
|
81
|
+
},
|
|
82
|
+
"keywords": [
|
|
83
|
+
"bit",
|
|
84
|
+
"bit-aspect",
|
|
85
|
+
"bit-core-aspect",
|
|
86
|
+
"components",
|
|
87
|
+
"collaboration",
|
|
88
|
+
"web"
|
|
89
|
+
]
|
|
90
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AspectDefinition } from '@teambit/aspect-loader';
|
|
2
|
+
import { Component } from '@teambit/component';
|
|
3
|
+
|
|
4
|
+
import { Environment } from '../environment';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* env runtime is an instance which represent the given env in a
|
|
8
|
+
*/
|
|
9
|
+
export class EnvRuntime {
|
|
10
|
+
constructor(
|
|
11
|
+
/**
|
|
12
|
+
* ID of the wrapping extension.
|
|
13
|
+
*/
|
|
14
|
+
readonly id: string,
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* environment
|
|
18
|
+
*/
|
|
19
|
+
readonly env: Environment,
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* components to be loaded in the environment
|
|
23
|
+
*/
|
|
24
|
+
readonly components: Component[],
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Aspect definition of the env.
|
|
28
|
+
*/
|
|
29
|
+
readonly envAspectDefinition: AspectDefinition
|
|
30
|
+
) {}
|
|
31
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { flatten } from 'lodash';
|
|
2
|
+
|
|
3
|
+
import { ServiceExecutionResult } from '../services';
|
|
4
|
+
import { EnvResult } from './runtime';
|
|
5
|
+
|
|
6
|
+
export class EnvsExecutionResult<T extends ServiceExecutionResult> {
|
|
7
|
+
constructor(readonly results: EnvResult<T>[]) {}
|
|
8
|
+
|
|
9
|
+
hasErrors() {
|
|
10
|
+
return Boolean(this.errors.length);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* execution errors.
|
|
15
|
+
*/
|
|
16
|
+
get errors(): Error[] {
|
|
17
|
+
return flatten(this.results.map((envResult) => this.getErrorsOfEnv(envResult)));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getErrorsOfEnv(envResult: EnvResult<T>): Error[] {
|
|
21
|
+
const execError = envResult.error;
|
|
22
|
+
const errors = envResult.data ? envResult.data.errors || [] : [];
|
|
23
|
+
if (execError) errors.push(execError);
|
|
24
|
+
return errors;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* if only one error is found, throw it. otherwise, summarize the errors per env and throw the
|
|
29
|
+
* output
|
|
30
|
+
*/
|
|
31
|
+
throwErrorsIfExist() {
|
|
32
|
+
if (!this.errors || !this.errors.length) return;
|
|
33
|
+
if (this.errors.length === 1 && this.errors[0] instanceof Error) throw this.errors[0];
|
|
34
|
+
const errorsPerEnvs = this.results.map((envResult) => this.getEnvErrorsAsString(envResult));
|
|
35
|
+
const errorOutput = errorsPerEnvs.join('\n\n');
|
|
36
|
+
throw new Error(errorOutput);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getEnvErrorsAsString(envResult: EnvResult<T>): string {
|
|
40
|
+
const errors = this.getErrorsOfEnv(envResult);
|
|
41
|
+
if (!errors.length) return '';
|
|
42
|
+
const title = `found ${errors.length} error(s) for ${envResult.env.id}`;
|
|
43
|
+
const errorsStr = errors.map((error) => `${error.message}\n${error.stack}`).join('\n');
|
|
44
|
+
return `${title}\n${errorsStr}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
package/runtime/index.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Logger } from '@teambit/logger';
|
|
2
|
+
import { ComponentID } from '@teambit/component';
|
|
3
|
+
import mapSeries from 'p-map-series';
|
|
4
|
+
import { EnvNotFoundInRuntime } from '../exceptions';
|
|
5
|
+
import { ExecutionContext } from '../context';
|
|
6
|
+
import { EnvService, ServiceExecutionResult } from '../services';
|
|
7
|
+
import { EnvRuntime } from './env-runtime';
|
|
8
|
+
import { EnvsExecutionResult } from './envs-execution-result';
|
|
9
|
+
|
|
10
|
+
export interface EnvResult<T extends ServiceExecutionResult> {
|
|
11
|
+
env: EnvRuntime;
|
|
12
|
+
data?: T;
|
|
13
|
+
error?: Error;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class Runtime {
|
|
17
|
+
constructor(
|
|
18
|
+
/**
|
|
19
|
+
* runtime instances of the environments.
|
|
20
|
+
*/
|
|
21
|
+
readonly runtimeEnvs: EnvRuntime[],
|
|
22
|
+
|
|
23
|
+
private logger: Logger
|
|
24
|
+
) {}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* execute a service on a specific env.
|
|
28
|
+
*/
|
|
29
|
+
runEnv<T extends ServiceExecutionResult>(
|
|
30
|
+
envRuntimeId: string,
|
|
31
|
+
service: EnvService<T>,
|
|
32
|
+
options?: { [key: string]: any }
|
|
33
|
+
): Promise<EnvsExecutionResult<T>> {
|
|
34
|
+
const envRuntime = this.runtimeEnvs.find((runtime) => {
|
|
35
|
+
const id = ComponentID.fromString(runtime.id);
|
|
36
|
+
const withoutVersion = id.toStringWithoutVersion();
|
|
37
|
+
return withoutVersion === envRuntimeId;
|
|
38
|
+
});
|
|
39
|
+
if (!envRuntime) throw new EnvNotFoundInRuntime(envRuntimeId);
|
|
40
|
+
return this.run(service, options, [envRuntime]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* execute a service once for all environments.
|
|
45
|
+
*/
|
|
46
|
+
async runOnce<T extends ServiceExecutionResult>(
|
|
47
|
+
service: EnvService<T>,
|
|
48
|
+
options?: { [key: string]: any }
|
|
49
|
+
): Promise<any> {
|
|
50
|
+
if (!service.runOnce) throw new Error('a service must implement `runOnce()` in order to be executed');
|
|
51
|
+
const envsExecutionContext = this.getEnvExecutionContext();
|
|
52
|
+
const serviceResult = await service.runOnce(envsExecutionContext, options);
|
|
53
|
+
return serviceResult;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getEnvExecutionContext(): ExecutionContext[] {
|
|
57
|
+
const envsExecutionContext = this.runtimeEnvs.map((env) => new ExecutionContext(this, env));
|
|
58
|
+
return envsExecutionContext;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* execute a service on each one of the environments.
|
|
63
|
+
*/
|
|
64
|
+
async run<T extends ServiceExecutionResult>(
|
|
65
|
+
/**
|
|
66
|
+
* environment service to execute.
|
|
67
|
+
*/
|
|
68
|
+
service: EnvService<T>,
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* options to proxy to the service upon execution.
|
|
72
|
+
*/
|
|
73
|
+
options?: { [key: string]: any },
|
|
74
|
+
runtimes?: EnvRuntime[]
|
|
75
|
+
): Promise<EnvsExecutionResult<T>> {
|
|
76
|
+
if (!service.run) throw new Error('a service must implement `run()` in order to be executed');
|
|
77
|
+
const errors: Error[] = [];
|
|
78
|
+
const contexts: EnvResult<T>[] = await mapSeries(runtimes || this.runtimeEnvs, async (env) => {
|
|
79
|
+
try {
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
const serviceResult = await service.run(new ExecutionContext(this, env), options);
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
env,
|
|
85
|
+
data: serviceResult,
|
|
86
|
+
};
|
|
87
|
+
} catch (err: any) {
|
|
88
|
+
this.logger.error(err.message, err);
|
|
89
|
+
this.logger.consoleFailure(`service "${service.name}" of env "${env.id}" has failed. error: ${err.message}`);
|
|
90
|
+
errors.push(err);
|
|
91
|
+
return {
|
|
92
|
+
env,
|
|
93
|
+
error: err,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return new EnvsExecutionResult(contexts);
|
|
99
|
+
}
|
|
100
|
+
}
|