@teambit/envs 0.0.881 → 0.0.883
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/dist/components/env-console/env-console.js +1 -10
- package/dist/components/env-console/env-console.js.map +1 -1
- package/dist/components/env-console/index.js +0 -3
- package/dist/components/env-console/index.js.map +1 -1
- package/dist/components/env-overview/env-overview.js +0 -8
- package/dist/components/env-overview/env-overview.js.map +1 -1
- package/dist/components/env-overview/index.js +0 -3
- package/dist/components/env-overview/index.js.map +1 -1
- package/dist/components/index.js +0 -3
- package/dist/components/index.js.map +1 -1
- package/dist/context/context.js +1 -17
- package/dist/context/context.js.map +1 -1
- package/dist/context/index.js +0 -3
- package/dist/context/index.js.map +1 -1
- package/dist/env-definition.js +3 -11
- package/dist/env-definition.js.map +1 -1
- package/dist/env-service-list.js +0 -6
- package/dist/env-service-list.js.map +1 -1
- package/dist/env.composition.js +0 -6
- package/dist/env.composition.js.map +1 -1
- package/dist/env.fragment.js +0 -11
- package/dist/env.fragment.js.map +1 -1
- package/dist/environment.js +1 -1
- package/dist/environment.js.map +1 -1
- package/dist/environments.aspect.js +0 -5
- package/dist/environments.aspect.js.map +1 -1
- package/dist/environments.graphql.js +0 -5
- package/dist/environments.graphql.js.map +1 -1
- package/dist/environments.main.runtime.js +52 -194
- package/dist/environments.main.runtime.js.map +1 -1
- package/dist/envs.cmd.js +7 -46
- package/dist/envs.cmd.js.map +1 -1
- package/dist/exceptions/env-not-configured-for-component.js +0 -6
- package/dist/exceptions/env-not-configured-for-component.js.map +1 -1
- package/dist/exceptions/env-not-found-in-runtime.js +0 -6
- package/dist/exceptions/env-not-found-in-runtime.js.map +1 -1
- package/dist/exceptions/env-not-found.js +0 -7
- package/dist/exceptions/env-not-found.js.map +1 -1
- package/dist/exceptions/index.js +0 -9
- package/dist/exceptions/index.js.map +1 -1
- package/dist/index.js +0 -25
- package/dist/index.js.map +1 -1
- package/dist/runtime/env-runtime.js +0 -3
- package/dist/runtime/env-runtime.js.map +1 -1
- package/dist/runtime/envs-execution-result.js +2 -13
- package/dist/runtime/envs-execution-result.js.map +1 -1
- package/dist/runtime/index.js +0 -6
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/runtime.js +3 -29
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/services/index.js +0 -9
- package/dist/services/index.js.map +1 -1
- package/package-tar/teambit-envs-0.0.883.tgz +0 -0
- package/package.json +18 -18
- package/{preview-1666409808293.js → preview-1666582798766.js} +2 -2
- package/package-tar/teambit-envs-0.0.881.tgz +0 -0
@@ -1,179 +1,126 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
-
|
5
4
|
require("core-js/modules/es.array.iterator.js");
|
6
|
-
|
7
5
|
require("core-js/modules/es.promise.js");
|
8
|
-
|
9
6
|
Object.defineProperty(exports, "__esModule", {
|
10
7
|
value: true
|
11
8
|
});
|
12
9
|
exports.EnvsMain = exports.DEFAULT_ENV = void 0;
|
13
|
-
|
14
10
|
function _defineProperty2() {
|
15
11
|
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
16
|
-
|
17
12
|
_defineProperty2 = function () {
|
18
13
|
return data;
|
19
14
|
};
|
20
|
-
|
21
15
|
return data;
|
22
16
|
}
|
23
|
-
|
24
17
|
function _cli() {
|
25
18
|
const data = require("@teambit/cli");
|
26
|
-
|
27
19
|
_cli = function () {
|
28
20
|
return data;
|
29
21
|
};
|
30
|
-
|
31
22
|
return data;
|
32
23
|
}
|
33
|
-
|
34
24
|
function _component() {
|
35
25
|
const data = require("@teambit/component");
|
36
|
-
|
37
26
|
_component = function () {
|
38
27
|
return data;
|
39
28
|
};
|
40
|
-
|
41
29
|
return data;
|
42
30
|
}
|
43
|
-
|
44
31
|
function _graphql() {
|
45
32
|
const data = require("@teambit/graphql");
|
46
|
-
|
47
33
|
_graphql = function () {
|
48
34
|
return data;
|
49
35
|
};
|
50
|
-
|
51
36
|
return data;
|
52
37
|
}
|
53
|
-
|
54
38
|
function _harmony() {
|
55
39
|
const data = require("@teambit/harmony");
|
56
|
-
|
57
40
|
_harmony = function () {
|
58
41
|
return data;
|
59
42
|
};
|
60
|
-
|
61
43
|
return data;
|
62
44
|
}
|
63
|
-
|
64
45
|
function _logger() {
|
65
46
|
const data = require("@teambit/logger");
|
66
|
-
|
67
47
|
_logger = function () {
|
68
48
|
return data;
|
69
49
|
};
|
70
|
-
|
71
50
|
return data;
|
72
51
|
}
|
73
|
-
|
74
52
|
function _bitError() {
|
75
53
|
const data = require("@teambit/bit-error");
|
76
|
-
|
77
54
|
_bitError = function () {
|
78
55
|
return data;
|
79
56
|
};
|
80
|
-
|
81
57
|
return data;
|
82
58
|
}
|
83
|
-
|
84
59
|
function _findDuplications() {
|
85
60
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/utils/array/find-duplications"));
|
86
|
-
|
87
61
|
_findDuplications = function () {
|
88
62
|
return data;
|
89
63
|
};
|
90
|
-
|
91
64
|
return data;
|
92
65
|
}
|
93
|
-
|
94
66
|
function _environments() {
|
95
67
|
const data = require("./environments.aspect");
|
96
|
-
|
97
68
|
_environments = function () {
|
98
69
|
return data;
|
99
70
|
};
|
100
|
-
|
101
71
|
return data;
|
102
72
|
}
|
103
|
-
|
104
73
|
function _environments2() {
|
105
74
|
const data = require("./environments.graphql");
|
106
|
-
|
107
75
|
_environments2 = function () {
|
108
76
|
return data;
|
109
77
|
};
|
110
|
-
|
111
78
|
return data;
|
112
79
|
}
|
113
|
-
|
114
80
|
function _runtime() {
|
115
81
|
const data = require("./runtime");
|
116
|
-
|
117
82
|
_runtime = function () {
|
118
83
|
return data;
|
119
84
|
};
|
120
|
-
|
121
85
|
return data;
|
122
86
|
}
|
123
|
-
|
124
87
|
function _envDefinition() {
|
125
88
|
const data = require("./env-definition");
|
126
|
-
|
127
89
|
_envDefinition = function () {
|
128
90
|
return data;
|
129
91
|
};
|
130
|
-
|
131
92
|
return data;
|
132
93
|
}
|
133
|
-
|
134
94
|
function _envServiceList() {
|
135
95
|
const data = require("./env-service-list");
|
136
|
-
|
137
96
|
_envServiceList = function () {
|
138
97
|
return data;
|
139
98
|
};
|
140
|
-
|
141
99
|
return data;
|
142
100
|
}
|
143
|
-
|
144
101
|
function _envs() {
|
145
102
|
const data = require("./envs.cmd");
|
146
|
-
|
147
103
|
_envs = function () {
|
148
104
|
return data;
|
149
105
|
};
|
150
|
-
|
151
106
|
return data;
|
152
107
|
}
|
153
|
-
|
154
108
|
function _env() {
|
155
109
|
const data = require("./env.fragment");
|
156
|
-
|
157
110
|
_env = function () {
|
158
111
|
return data;
|
159
112
|
};
|
160
|
-
|
161
113
|
return data;
|
162
114
|
}
|
163
|
-
|
164
115
|
function _exceptions() {
|
165
116
|
const data = require("./exceptions");
|
166
|
-
|
167
117
|
_exceptions = function () {
|
168
118
|
return data;
|
169
119
|
};
|
170
|
-
|
171
120
|
return data;
|
172
121
|
}
|
173
|
-
|
174
122
|
const DEFAULT_ENV = 'teambit.harmony/node';
|
175
123
|
exports.DEFAULT_ENV = DEFAULT_ENV;
|
176
|
-
|
177
124
|
class EnvsMain {
|
178
125
|
/**
|
179
126
|
* icon of the extension.
|
@@ -183,7 +130,6 @@ class EnvsMain {
|
|
183
130
|
<circle cx="25" cy="25" r="20"/>
|
184
131
|
</svg>`;
|
185
132
|
}
|
186
|
-
|
187
133
|
constructor(
|
188
134
|
/**
|
189
135
|
* environments extension configuration.
|
@@ -205,33 +151,29 @@ class EnvsMain {
|
|
205
151
|
this.componentMain = componentMain;
|
206
152
|
(0, _defineProperty2().default)(this, "alreadyShownWarning", {});
|
207
153
|
}
|
154
|
+
|
208
155
|
/**
|
209
156
|
* creates a new runtime environments for a set of components.
|
210
157
|
*/
|
211
|
-
|
212
|
-
|
213
158
|
async createEnvironment(components) {
|
214
159
|
return this.createRuntime(components);
|
215
160
|
}
|
161
|
+
|
216
162
|
/**
|
217
163
|
* get the configured default env.
|
218
164
|
*/
|
219
|
-
|
220
|
-
|
221
165
|
getDefaultEnv() {
|
222
166
|
const defaultEnv = this.envSlot.get(DEFAULT_ENV);
|
223
167
|
if (!defaultEnv) throw new Error('default env must be set.');
|
224
168
|
return new (_envDefinition().EnvDefinition)(DEFAULT_ENV, defaultEnv);
|
225
169
|
}
|
226
|
-
|
227
170
|
getCoreEnvsIds() {
|
228
171
|
return ['teambit.harmony/aspect', 'teambit.react/react', 'teambit.harmony/node', 'teambit.react/react-native', 'teambit.html/html', 'teambit.mdx/mdx', 'teambit.envs/env', 'teambit.mdx/readme'];
|
229
172
|
}
|
173
|
+
|
230
174
|
/**
|
231
175
|
* compose a new environment from a list of environment transformers.
|
232
176
|
*/
|
233
|
-
|
234
|
-
|
235
177
|
compose(targetEnv, envTransformers) {
|
236
178
|
const a = envTransformers.reduce((acc, transformer) => {
|
237
179
|
acc = transformer(acc);
|
@@ -239,56 +181,48 @@ class EnvsMain {
|
|
239
181
|
}, targetEnv);
|
240
182
|
return a;
|
241
183
|
}
|
184
|
+
|
242
185
|
/**
|
243
186
|
* create an env transformer which overrides specific env properties.
|
244
187
|
*/
|
245
|
-
|
246
|
-
|
247
188
|
override(propsToOverride) {
|
248
189
|
return env => {
|
249
190
|
return this.merge(propsToOverride, env);
|
250
191
|
};
|
251
192
|
}
|
193
|
+
|
252
194
|
/**
|
253
195
|
* compose two environments into one.
|
254
196
|
*/
|
255
|
-
|
256
|
-
|
257
197
|
merge(targetEnv, sourceEnv) {
|
258
198
|
const allNames = new Set();
|
259
199
|
const keys = ['icon', 'name', 'description'];
|
260
|
-
|
261
200
|
for (let o = sourceEnv; o !== Object.prototype; o = Object.getPrototypeOf(o)) {
|
262
201
|
for (const name of Object.getOwnPropertyNames(o)) {
|
263
202
|
allNames.add(name);
|
264
203
|
}
|
265
204
|
}
|
266
|
-
|
267
205
|
allNames.forEach(key => {
|
268
206
|
const fn = sourceEnv[key];
|
269
207
|
if (targetEnv[key]) return;
|
270
208
|
if (keys.includes(key)) targetEnv[key] = fn;
|
271
|
-
|
272
209
|
if (!fn || !fn.bind) {
|
273
210
|
return;
|
274
211
|
}
|
275
|
-
|
276
212
|
targetEnv[key] = fn.bind(sourceEnv);
|
277
213
|
});
|
278
214
|
return targetEnv;
|
279
215
|
}
|
280
|
-
|
281
216
|
getEnvData(component) {
|
282
217
|
let envsData = component.state.aspects.get(_environments().EnvsAspect.id);
|
283
|
-
|
284
218
|
if (!envsData) {
|
285
219
|
// TODO: remove this once we re-export old components used to store the data here
|
286
220
|
envsData = component.state.aspects.get('teambit.workspace/workspace');
|
287
221
|
}
|
288
|
-
|
289
222
|
if (!envsData) throw new Error(`env was not configured on component ${component.id.toString()}`);
|
290
223
|
return envsData.data;
|
291
224
|
}
|
225
|
+
|
292
226
|
/**
|
293
227
|
* Return the id of the env as configured in the envs data (without version by default)
|
294
228
|
* The reason it's not contain version by default is that we want to take the version from the aspect defined on the component itself
|
@@ -296,39 +230,33 @@ class EnvsMain {
|
|
296
230
|
* @param component
|
297
231
|
* @param ignoreVersion
|
298
232
|
*/
|
299
|
-
|
300
|
-
|
301
233
|
getEnvIdFromEnvsData(component, ignoreVersion = true) {
|
302
234
|
const envsData = this.getEnvData(component);
|
303
235
|
if (!envsData) return undefined;
|
304
236
|
const rawEnvId = envsData.id;
|
305
237
|
if (!rawEnvId) return undefined;
|
306
238
|
if (!ignoreVersion) return rawEnvId;
|
307
|
-
|
308
239
|
const envIdWithoutVersion = _component().ComponentID.fromString(rawEnvId).toStringWithoutVersion();
|
309
|
-
|
310
240
|
return envIdWithoutVersion;
|
311
241
|
}
|
242
|
+
|
312
243
|
/**
|
313
244
|
* get the env id of the given component.
|
314
245
|
*/
|
315
|
-
|
316
|
-
|
317
246
|
getEnvId(component) {
|
318
247
|
const envIdFromEnvData = this.getEnvIdFromEnvsData(component);
|
319
|
-
|
320
248
|
if (!envIdFromEnvData) {
|
321
249
|
// This should never happen
|
322
250
|
throw new Error(`no env found for ${component.id.toString()}`);
|
323
251
|
}
|
324
|
-
|
325
252
|
const withVersion = this.resolveEnv(component, envIdFromEnvData);
|
326
253
|
const withVersionMatch = this.envSlot.toArray().find(([envId]) => {
|
327
254
|
return (withVersion === null || withVersion === void 0 ? void 0 : withVersion.toString()) === envId;
|
328
255
|
});
|
329
256
|
const withVersionMatchId = withVersionMatch === null || withVersionMatch === void 0 ? void 0 : withVersionMatch[0];
|
330
|
-
if (withVersionMatchId) return withVersionMatchId;
|
257
|
+
if (withVersionMatchId) return withVersionMatchId;
|
331
258
|
|
259
|
+
// Handle core envs
|
332
260
|
const exactMatch = this.envSlot.toArray().find(([envId]) => {
|
333
261
|
return envIdFromEnvData === envId;
|
334
262
|
});
|
@@ -337,64 +265,54 @@ class EnvsMain {
|
|
337
265
|
if (!withVersion) throw new (_exceptions().EnvNotConfiguredForComponent)(envIdFromEnvData, component.id.toString());
|
338
266
|
return withVersion.toString();
|
339
267
|
}
|
340
|
-
|
341
268
|
isUsingCoreEnv(component) {
|
342
269
|
const envId = this.getEnvId(component);
|
343
270
|
return this.isCoreEnv(envId);
|
344
271
|
}
|
345
|
-
|
346
272
|
isCoreEnv(envId) {
|
347
273
|
return this.getCoreEnvsIds().includes(envId);
|
348
274
|
}
|
275
|
+
|
349
276
|
/**
|
350
277
|
* get the env of the given component.
|
351
278
|
* In case you are asking for the env during on load you should use calculateEnv instead
|
352
279
|
*/
|
353
|
-
|
354
|
-
|
355
280
|
getEnv(component) {
|
356
281
|
const id = this.getEnvId(component);
|
357
282
|
const envDef = this.getEnvDefinitionByStringId(id);
|
358
|
-
|
359
283
|
if (envDef) {
|
360
284
|
return envDef;
|
361
|
-
}
|
362
|
-
|
363
|
-
|
285
|
+
}
|
286
|
+
// Do not allow a non existing env
|
364
287
|
throw new (_exceptions().EnvNotFound)(id, component.id.toString());
|
365
288
|
}
|
289
|
+
|
366
290
|
/**
|
367
291
|
* get the env component of the given component.
|
368
292
|
*/
|
369
|
-
|
370
|
-
|
371
293
|
async getEnvComponent(component) {
|
372
294
|
const envId = this.getEnvId(component);
|
373
295
|
return this.getEnvComponentByEnvId(envId, component.id.toString());
|
374
296
|
}
|
297
|
+
|
375
298
|
/**
|
376
299
|
* get the env component by the env id.
|
377
300
|
*/
|
378
|
-
|
379
|
-
|
380
301
|
async getEnvComponentByEnvId(envId, requesting) {
|
381
302
|
const host = this.componentMain.getHost();
|
382
303
|
const newId = await host.resolveComponentId(envId);
|
383
304
|
const envComponent = await host.get(newId);
|
384
|
-
|
385
305
|
if (!envComponent) {
|
386
306
|
throw new (_bitError().BitError)(`can't load env. env id is ${envId} used by component ${requesting}`);
|
387
307
|
}
|
388
|
-
|
389
308
|
return envComponent;
|
390
309
|
}
|
310
|
+
|
391
311
|
/**
|
392
312
|
* get the env of the given component.
|
393
313
|
* This will try to use the regular getEnv but fallback to the calculate env (in case you are using it during on load)
|
394
314
|
* This is safe to be used on onLoad as well
|
395
315
|
*/
|
396
|
-
|
397
|
-
|
398
316
|
getOrCalculateEnv(component) {
|
399
317
|
try {
|
400
318
|
return this.getEnv(component);
|
@@ -402,11 +320,10 @@ class EnvsMain {
|
|
402
320
|
return this.calculateEnv(component);
|
403
321
|
}
|
404
322
|
}
|
323
|
+
|
405
324
|
/**
|
406
325
|
* get an environment Descriptor.
|
407
326
|
*/
|
408
|
-
|
409
|
-
|
410
327
|
getDescriptor(component) {
|
411
328
|
const envsData = this.getEnvData(component);
|
412
329
|
return {
|
@@ -415,7 +332,6 @@ class EnvsMain {
|
|
415
332
|
services: envsData.services
|
416
333
|
};
|
417
334
|
}
|
418
|
-
|
419
335
|
resolveEnv(component, id) {
|
420
336
|
const matchedEntry = component.state.aspects.entries.find(aspectEntry => {
|
421
337
|
return id === aspectEntry.id.toString() || id === aspectEntry.id.toString({
|
@@ -424,73 +340,63 @@ class EnvsMain {
|
|
424
340
|
});
|
425
341
|
return matchedEntry === null || matchedEntry === void 0 ? void 0 : matchedEntry.id;
|
426
342
|
}
|
343
|
+
|
427
344
|
/**
|
428
345
|
* This used to calculate the actual env during the component load.
|
429
346
|
* Do not use it to get the env (use getEnv instead)
|
430
347
|
* This should be used only during on load
|
431
348
|
*/
|
432
|
-
|
433
|
-
|
434
349
|
calculateEnv(component) {
|
435
350
|
// Search first for env configured via envs aspect itself
|
436
351
|
const envIdFromEnvsConfig = this.getEnvIdFromEnvsConfig(component);
|
437
352
|
let envIdFromEnvsConfigWithoutVersion;
|
438
|
-
|
439
353
|
if (envIdFromEnvsConfig) {
|
440
354
|
envIdFromEnvsConfigWithoutVersion = _component().ComponentID.fromString(envIdFromEnvsConfig).toStringWithoutVersion();
|
441
355
|
const envDef = this.getEnvDefinitionByStringId(envIdFromEnvsConfigWithoutVersion);
|
442
|
-
|
443
356
|
if (envDef) {
|
444
357
|
return envDef;
|
445
358
|
}
|
446
|
-
}
|
359
|
+
}
|
360
|
+
|
361
|
+
// in some cases we have the id configured in the teambit.envs/envs but without the version
|
447
362
|
// in such cases we won't find it in the slot
|
448
363
|
// we search in the component aspect list a matching aspect which is match the id from the teambit.envs/envs
|
449
|
-
|
450
|
-
|
451
364
|
if (envIdFromEnvsConfigWithoutVersion) {
|
452
365
|
const matchedEntry = component.state.aspects.entries.find(aspectEntry => {
|
453
366
|
return envIdFromEnvsConfigWithoutVersion === aspectEntry.id.toString() || envIdFromEnvsConfigWithoutVersion === aspectEntry.id.toString({
|
454
367
|
ignoreVersion: true
|
455
368
|
});
|
456
369
|
});
|
457
|
-
|
458
370
|
if (matchedEntry) {
|
459
371
|
// during the tag process, the version in the aspect-entry-id is changed and is not the
|
460
372
|
// same as it was when it registered to the slot.
|
461
373
|
const envDef = this.getEnvDefinitionById(matchedEntry.id);
|
462
|
-
|
463
374
|
if (envDef) {
|
464
375
|
return envDef;
|
465
|
-
}
|
466
|
-
|
467
|
-
|
376
|
+
}
|
377
|
+
// Do not allow a non existing env
|
468
378
|
this.printWarningIfFirstTime(matchedEntry.id.toString(), `environment with ID: ${matchedEntry.id.toString()} configured on component ${component.id.toString()} was not found`);
|
469
|
-
}
|
470
|
-
|
471
|
-
|
379
|
+
}
|
380
|
+
// Do not allow configure teambit.envs/envs on the component without configure the env aspect itself
|
472
381
|
const errMsg = new (_exceptions().EnvNotConfiguredForComponent)(envIdFromEnvsConfig, component.id.toString()).message;
|
473
382
|
this.printWarningIfFirstTime(envIdFromEnvsConfig, errMsg);
|
474
|
-
}
|
475
|
-
|
383
|
+
}
|
476
384
|
|
385
|
+
// in case there is no config in teambit.envs/envs search the aspects for the first env that registered as env
|
477
386
|
let envDefFromList;
|
478
387
|
component.state.aspects.entries.find(aspectEntry => {
|
479
388
|
const envDef = this.getEnvDefinitionById(aspectEntry.id);
|
480
|
-
|
481
389
|
if (envDef) {
|
482
390
|
envDefFromList = envDef;
|
483
391
|
}
|
484
|
-
|
485
392
|
return !!envDef;
|
486
393
|
});
|
487
|
-
|
488
394
|
if (envDefFromList) {
|
489
395
|
return envDefFromList;
|
490
396
|
}
|
491
|
-
|
492
397
|
return this.getDefaultEnv();
|
493
398
|
}
|
399
|
+
|
494
400
|
/**
|
495
401
|
* an env can be configured on a component in two ways:
|
496
402
|
* 1) explicitly inside "teambit.envs/envs". `{ "teambit.envs/envs": { "env": "my-env" } }`
|
@@ -498,31 +404,26 @@ class EnvsMain {
|
|
498
404
|
*
|
499
405
|
* this method returns #1 if exists, otherwise, #2.
|
500
406
|
*/
|
501
|
-
|
502
|
-
|
503
407
|
getAllEnvsConfiguredOnComponent(component) {
|
504
408
|
// if a component has "envs" config, use it and ignore other components that are set up
|
505
409
|
// in this components which happen to be envs.
|
506
410
|
const envDef = this.getEnvFromEnvsConfig(component);
|
507
|
-
|
508
411
|
if (envDef) {
|
509
412
|
return [envDef];
|
510
413
|
}
|
511
|
-
|
512
414
|
return this.getEnvsNotFromEnvsConfig(component);
|
513
415
|
}
|
416
|
+
|
514
417
|
/**
|
515
418
|
* whether a component has an env configured (either by variant or .bitmap).
|
516
419
|
*/
|
517
|
-
|
518
|
-
|
519
420
|
hasEnvConfigured(component) {
|
520
421
|
return Boolean(this.getAllEnvsConfiguredOnComponent(component).length);
|
521
422
|
}
|
522
|
-
|
523
423
|
getAllRegisteredEnvs() {
|
524
424
|
return this.envSlot.toArray().map(envData => envData[0]);
|
525
425
|
}
|
426
|
+
|
526
427
|
/**
|
527
428
|
* an env can be configured on a component in two ways:
|
528
429
|
* 1) explicitly inside "teambit.envs/envs". `{ "teambit.envs/envs": { "env": "my-env" } }`
|
@@ -530,20 +431,16 @@ class EnvsMain {
|
|
530
431
|
*
|
531
432
|
* this method returns only #1
|
532
433
|
*/
|
533
|
-
|
534
|
-
|
535
434
|
getEnvFromEnvsConfig(component) {
|
536
435
|
const envIdFromEnvsConfig = this.getEnvIdFromEnvsConfig(component);
|
537
|
-
|
538
436
|
if (!envIdFromEnvsConfig) {
|
539
437
|
return undefined;
|
540
438
|
}
|
541
|
-
|
542
439
|
const envIdFromEnvsConfigWithoutVersion = _component().ComponentID.fromString(envIdFromEnvsConfig).toStringWithoutVersion();
|
543
|
-
|
544
440
|
const envDef = this.getEnvDefinitionByStringId(envIdFromEnvsConfigWithoutVersion);
|
545
441
|
return envDef;
|
546
442
|
}
|
443
|
+
|
547
444
|
/**
|
548
445
|
* an env can be configured on a component in two ways:
|
549
446
|
* 1) explicitly inside "teambit.envs/envs". `{ "teambit.envs/envs": { "env": "my-env" } }`
|
@@ -551,8 +448,6 @@ class EnvsMain {
|
|
551
448
|
*
|
552
449
|
* this method returns only #2
|
553
450
|
*/
|
554
|
-
|
555
|
-
|
556
451
|
getEnvsNotFromEnvsConfig(component) {
|
557
452
|
return component.state.aspects.entries.reduce((acc, aspectEntry) => {
|
558
453
|
const envDef = this.getEnvDefinitionById(aspectEntry.id);
|
@@ -560,34 +455,30 @@ class EnvsMain {
|
|
560
455
|
return acc;
|
561
456
|
}, []);
|
562
457
|
}
|
458
|
+
|
563
459
|
/**
|
564
460
|
* @deprecated DO NOT USE THIS METHOD ANYMORE!!! (PLEASE USE .calculateEnv() instead!)
|
565
461
|
*/
|
566
|
-
|
567
|
-
|
568
462
|
calculateEnvFromExtensions(extensions) {
|
569
463
|
// Search first for env configured via envs aspect itself
|
570
464
|
const envsAspect = extensions.findCoreExtension(_environments().EnvsAspect.id);
|
571
465
|
const envIdFromEnvsConfig = envsAspect === null || envsAspect === void 0 ? void 0 : envsAspect.config.env;
|
572
466
|
let envIdFromEnvsConfigWithoutVersion;
|
573
|
-
|
574
467
|
if (envIdFromEnvsConfig) {
|
575
468
|
envIdFromEnvsConfigWithoutVersion = _component().ComponentID.fromString(envIdFromEnvsConfig).toStringWithoutVersion();
|
576
469
|
const envDef = this.getEnvDefinitionByStringId(envIdFromEnvsConfigWithoutVersion);
|
577
|
-
|
578
470
|
if (envDef) {
|
579
471
|
return envDef;
|
580
472
|
}
|
581
473
|
}
|
582
|
-
|
583
474
|
const getEnvDefinitionByLegacyExtension = extension => {
|
584
475
|
const envDef = extension.newExtensionId ? this.getEnvDefinitionById(extension.newExtensionId) : this.getEnvDefinitionByStringId(extension.stringId);
|
585
476
|
return envDef;
|
586
|
-
};
|
477
|
+
};
|
478
|
+
|
479
|
+
// in some cases we have the id configured in the teambit.envs/envs but without the version
|
587
480
|
// in such cases we won't find it in the slot
|
588
481
|
// we search in the component aspect list a matching aspect which is match the id from the teambit.envs/envs
|
589
|
-
|
590
|
-
|
591
482
|
if (envIdFromEnvsConfigWithoutVersion) {
|
592
483
|
const matchedEntry = extensions.find(extension => {
|
593
484
|
if (extension.newExtensionId) {
|
@@ -595,139 +486,115 @@ class EnvsMain {
|
|
595
486
|
ignoreVersion: true
|
596
487
|
});
|
597
488
|
}
|
598
|
-
|
599
489
|
return envIdFromEnvsConfigWithoutVersion === extension.stringId;
|
600
490
|
});
|
601
|
-
|
602
491
|
if (matchedEntry) {
|
603
492
|
// during the tag process, the version in the aspect-entry-id is changed and is not the
|
604
493
|
// same as it was when it registered to the slot.
|
605
494
|
const envDef = getEnvDefinitionByLegacyExtension(matchedEntry);
|
606
|
-
|
607
495
|
if (envDef) {
|
608
496
|
return envDef;
|
609
|
-
}
|
610
|
-
|
611
|
-
|
497
|
+
}
|
498
|
+
// Do not allow a non existing env
|
612
499
|
this.printWarningIfFirstTime(matchedEntry.id.toString(), `environment with ID: ${matchedEntry.id.toString()} was not found`);
|
613
|
-
}
|
614
|
-
|
615
|
-
|
500
|
+
}
|
501
|
+
// Do not allow configure teambit.envs/envs on the component without configure the env aspect itself
|
616
502
|
const errMsg = new (_exceptions().EnvNotConfiguredForComponent)(envIdFromEnvsConfig).message;
|
617
503
|
this.printWarningIfFirstTime(envIdFromEnvsConfig, errMsg);
|
618
|
-
}
|
619
|
-
|
504
|
+
}
|
620
505
|
|
506
|
+
// in case there is no config in teambit.envs/envs search the aspects for the first env that registered as env
|
621
507
|
let envDefFromList;
|
622
508
|
extensions.find(extension => {
|
623
509
|
const envDef = getEnvDefinitionByLegacyExtension(extension);
|
624
|
-
|
625
510
|
if (envDef) {
|
626
511
|
envDefFromList = envDef;
|
627
512
|
}
|
628
|
-
|
629
513
|
return !!envDef;
|
630
514
|
});
|
631
|
-
|
632
515
|
if (envDefFromList) {
|
633
516
|
return envDefFromList;
|
634
517
|
}
|
635
|
-
|
636
518
|
return this.getDefaultEnv();
|
637
519
|
}
|
638
|
-
|
639
520
|
getEnvIdFromEnvsConfig(component) {
|
640
521
|
const envsAspect = component.state.aspects.get(_environments().EnvsAspect.id);
|
641
522
|
return envsAspect === null || envsAspect === void 0 ? void 0 : envsAspect.config.env;
|
642
523
|
}
|
643
|
-
|
644
524
|
getEnvDefinitionById(id) {
|
645
525
|
const envDef = this.getEnvDefinitionByStringId(id.toString()) || this.getEnvDefinitionByStringId(id.toString({
|
646
526
|
ignoreVersion: true
|
647
527
|
}));
|
648
528
|
return envDef;
|
649
529
|
}
|
650
|
-
|
651
530
|
async getEnvDefinitionByLegacyId(id) {
|
652
531
|
const host = this.componentMain.getHost();
|
653
532
|
const newId = await host.resolveComponentId(id);
|
654
533
|
return this.getEnvDefinitionById(newId);
|
655
534
|
}
|
656
|
-
|
657
535
|
getEnvDefinitionByStringId(envId) {
|
658
536
|
const env = this.envSlot.get(envId);
|
659
|
-
|
660
537
|
if (env) {
|
661
538
|
return new (_envDefinition().EnvDefinition)(envId, env);
|
662
539
|
}
|
663
|
-
|
664
540
|
return undefined;
|
665
541
|
}
|
666
|
-
|
667
542
|
getEnvFromComponent(envComponent) {
|
668
543
|
const env = this.getEnvDefinitionById(envComponent.id);
|
669
544
|
return env;
|
670
545
|
}
|
546
|
+
|
671
547
|
/**
|
672
548
|
* Return the env definition of teambit.envs/env
|
673
549
|
*/
|
674
|
-
|
675
|
-
|
676
550
|
getEnvsEnvDefinition() {
|
677
551
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
678
552
|
return this.getEnvDefinitionByStringId('teambit.envs/env');
|
679
553
|
}
|
680
|
-
|
681
554
|
printWarningIfFirstTime(envId, message) {
|
682
555
|
if (!this.alreadyShownWarning[envId]) {
|
683
556
|
this.alreadyShownWarning[envId] = true;
|
684
557
|
this.logger.consoleWarning(message);
|
685
558
|
}
|
686
559
|
}
|
560
|
+
|
687
561
|
/**
|
688
562
|
* determines whether an env is registered.
|
689
563
|
*/
|
690
|
-
|
691
|
-
|
692
564
|
isEnvRegistered(id) {
|
693
565
|
return Boolean(this.envSlot.get(id));
|
694
566
|
}
|
695
|
-
|
696
567
|
isUsingAspectEnv(component) {
|
697
568
|
const data = this.getEnvData(component);
|
698
569
|
if (!data) return false;
|
699
570
|
return data.type === 'aspect';
|
700
571
|
}
|
701
|
-
|
702
572
|
isUsingEnvEnv(component) {
|
703
573
|
const data = this.getEnvData(component);
|
704
574
|
if (!data) return false;
|
705
575
|
return data.type === 'env';
|
706
576
|
}
|
577
|
+
|
707
578
|
/**
|
708
579
|
* Check if the given component is an env component.
|
709
580
|
* @param component
|
710
581
|
* @returns
|
711
582
|
*/
|
712
|
-
|
713
|
-
|
714
583
|
isEnv(component) {
|
715
584
|
return this.isUsingEnvEnv(component) || this.isEnvRegistered(component.id.toString());
|
716
585
|
}
|
586
|
+
|
717
587
|
/**
|
718
588
|
* register a new environment service.
|
719
589
|
*/
|
720
|
-
|
721
|
-
|
722
590
|
registerService(...envServices) {
|
723
591
|
this.serviceSlot.register(envServices);
|
724
592
|
return this;
|
725
593
|
}
|
594
|
+
|
726
595
|
/**
|
727
596
|
* get list of services enabled on an env.
|
728
597
|
*/
|
729
|
-
|
730
|
-
|
731
598
|
getServices(env) {
|
732
599
|
const allServices = this.serviceSlot.toArray();
|
733
600
|
const services = [];
|
@@ -740,35 +607,33 @@ class EnvsMain {
|
|
740
607
|
});
|
741
608
|
return new (_envServiceList().EnvServiceList)(env, services);
|
742
609
|
}
|
743
|
-
|
744
610
|
implements(env, service) {
|
745
611
|
// TODO: remove this after refactoring everything and remove getDescriptor from being optional.
|
746
612
|
if (!service.getDescriptor) return false;
|
747
613
|
return !!service.getDescriptor(env);
|
748
614
|
}
|
615
|
+
|
749
616
|
/**
|
750
617
|
* register an environment.
|
751
618
|
*/
|
752
|
-
|
753
|
-
|
754
619
|
registerEnv(env) {
|
755
620
|
return this.envSlot.register(env);
|
756
|
-
}
|
757
|
-
|
621
|
+
}
|
758
622
|
|
623
|
+
// refactor here
|
759
624
|
async createRuntime(components) {
|
760
625
|
return new (_runtime().Runtime)(await this.aggregateByDefs(components), this.logger);
|
761
|
-
}
|
762
|
-
|
626
|
+
}
|
763
627
|
|
628
|
+
// :TODO can be refactored to few utilities who will make repeating this very easy.
|
764
629
|
async aggregateByDefs(components) {
|
765
630
|
this.throwForDuplicateComponents(components);
|
766
631
|
const envsMap = {};
|
767
632
|
components.forEach(component => {
|
768
633
|
const envDef = this.getEnv(component);
|
769
634
|
const envId = envDef.id;
|
770
|
-
const env = envDef.env;
|
771
|
-
|
635
|
+
const env = envDef.env;
|
636
|
+
// handle config as well when aggregating envs.
|
772
637
|
if (envsMap[envId]) envsMap[envId].components.push(component);else envsMap[envId] = {
|
773
638
|
components: [component],
|
774
639
|
env
|
@@ -779,7 +644,6 @@ class EnvsMain {
|
|
779
644
|
return new (_runtime().EnvRuntime)(key, envsMap[key].env, envsMap[key].components, envAspectDef);
|
780
645
|
}));
|
781
646
|
}
|
782
|
-
|
783
647
|
async getEnvAspectDef(envId) {
|
784
648
|
const host = this.componentMain.getHost();
|
785
649
|
const id = await host.resolveComponentId(envId);
|
@@ -788,16 +652,13 @@ class EnvsMain {
|
|
788
652
|
}))[0];
|
789
653
|
return def;
|
790
654
|
}
|
791
|
-
|
792
655
|
throwForDuplicateComponents(components) {
|
793
656
|
const idsStr = components.map(c => c.id.toString());
|
794
657
|
const duplications = (0, _findDuplications().default)(idsStr);
|
795
|
-
|
796
658
|
if (duplications.length) {
|
797
659
|
throw new Error(`found duplicated components: ${duplications.join(', ')}`);
|
798
660
|
}
|
799
661
|
}
|
800
|
-
|
801
662
|
static async provider([graphql, loggerAspect, component, cli], config, [envSlot, serviceSlot], context) {
|
802
663
|
const logger = loggerAspect.createLogger(_environments().EnvsAspect.id);
|
803
664
|
const envs = new EnvsMain(config, context, envSlot, logger, serviceSlot, component);
|
@@ -808,14 +669,11 @@ class EnvsMain {
|
|
808
669
|
graphql.register((0, _environments2().environmentsSchema)(envs));
|
809
670
|
return envs;
|
810
671
|
}
|
811
|
-
|
812
672
|
}
|
813
|
-
|
814
673
|
exports.EnvsMain = EnvsMain;
|
815
674
|
(0, _defineProperty2().default)(EnvsMain, "runtime", _cli().MainRuntime);
|
816
675
|
(0, _defineProperty2().default)(EnvsMain, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType()]);
|
817
676
|
(0, _defineProperty2().default)(EnvsMain, "dependencies", [_graphql().GraphqlAspect, _logger().LoggerAspect, _component().ComponentAspect, _cli().CLIAspect]);
|
818
|
-
|
819
677
|
_environments().EnvsAspect.addRuntime(EnvsMain);
|
820
678
|
|
821
679
|
//# sourceMappingURL=environments.main.runtime.js.map
|