@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.
Files changed (108) hide show
  1. package/context/context.ts +55 -0
  2. package/context/index.ts +1 -0
  3. package/dist/context/context.d.ts +44 -0
  4. package/dist/context/context.js +61 -0
  5. package/dist/context/context.js.map +1 -0
  6. package/dist/context/index.d.ts +1 -0
  7. package/dist/context/index.js +20 -0
  8. package/dist/context/index.js.map +1 -0
  9. package/dist/env-definition.d.ts +41 -0
  10. package/dist/env-definition.js +57 -0
  11. package/dist/env-definition.js.map +1 -0
  12. package/dist/env-interface.d.ts +4 -0
  13. package/dist/env-interface.js +3 -0
  14. package/dist/env-interface.js.map +1 -0
  15. package/dist/env-jsonc.detector.d.ts +5 -0
  16. package/dist/env-jsonc.detector.js +26 -0
  17. package/dist/env-jsonc.detector.js.map +1 -0
  18. package/dist/env-service-list.d.ts +35 -0
  19. package/dist/env-service-list.js +37 -0
  20. package/dist/env-service-list.js.map +1 -0
  21. package/dist/env.composition.d.ts +1 -0
  22. package/dist/env.composition.js +29 -0
  23. package/dist/env.composition.js.map +1 -0
  24. package/dist/env.fragment.d.ts +17 -0
  25. package/dist/env.fragment.js +48 -0
  26. package/dist/env.fragment.js.map +1 -0
  27. package/dist/env.plugin.d.ts +20 -0
  28. package/dist/env.plugin.js +92 -0
  29. package/dist/env.plugin.js.map +1 -0
  30. package/dist/environment.d.ts +201 -0
  31. package/dist/environment.js +17 -0
  32. package/dist/environment.js.map +1 -0
  33. package/dist/environments.aspect.d.ts +2 -0
  34. package/dist/environments.aspect.js +18 -0
  35. package/dist/environments.aspect.js.map +1 -0
  36. package/dist/environments.graphql.d.ts +3 -0
  37. package/dist/environments.graphql.js +36 -0
  38. package/dist/environments.graphql.js.map +1 -0
  39. package/dist/environments.main.runtime.d.ts +366 -0
  40. package/dist/environments.main.runtime.js +1160 -0
  41. package/dist/environments.main.runtime.js.map +1 -0
  42. package/dist/envs.cmd.d.ts +51 -0
  43. package/dist/envs.cmd.js +153 -0
  44. package/dist/envs.cmd.js.map +1 -0
  45. package/dist/envs.docs.mdx +8 -0
  46. package/dist/esm.mjs +13 -0
  47. package/dist/exceptions/env-not-configured-for-component.d.ts +4 -0
  48. package/dist/exceptions/env-not-configured-for-component.js +24 -0
  49. package/dist/exceptions/env-not-configured-for-component.js.map +1 -0
  50. package/dist/exceptions/env-not-found-in-runtime.d.ts +5 -0
  51. package/dist/exceptions/env-not-found-in-runtime.js +22 -0
  52. package/dist/exceptions/env-not-found-in-runtime.js.map +1 -0
  53. package/dist/exceptions/env-not-found.d.ts +6 -0
  54. package/dist/exceptions/env-not-found.js +27 -0
  55. package/dist/exceptions/env-not-found.js.map +1 -0
  56. package/dist/exceptions/index.d.ts +3 -0
  57. package/dist/exceptions/index.js +46 -0
  58. package/dist/exceptions/index.js.map +1 -0
  59. package/dist/index.d.ts +16 -0
  60. package/dist/index.js +128 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/preview-1752254355761.js +7 -0
  63. package/dist/runtime/env-runtime.d.ts +41 -0
  64. package/dist/runtime/env-runtime.js +36 -0
  65. package/dist/runtime/env-runtime.js.map +1 -0
  66. package/dist/runtime/envs-execution-result.d.ts +18 -0
  67. package/dist/runtime/envs-execution-result.js +56 -0
  68. package/dist/runtime/envs-execution-result.js.map +1 -0
  69. package/dist/runtime/index.d.ts +2 -0
  70. package/dist/runtime/index.js +33 -0
  71. package/dist/runtime/index.js.map +1 -0
  72. package/dist/runtime/runtime.d.ts +49 -0
  73. package/dist/runtime/runtime.js +117 -0
  74. package/dist/runtime/runtime.js.map +1 -0
  75. package/dist/services/concrete-service.d.ts +8 -0
  76. package/dist/services/concrete-service.js +3 -0
  77. package/dist/services/concrete-service.js.map +1 -0
  78. package/dist/services/index.d.ts +4 -0
  79. package/dist/services/index.js +89 -0
  80. package/dist/services/index.js.map +1 -0
  81. package/dist/services/service-handler-context.d.ts +30 -0
  82. package/dist/services/service-handler-context.js +44 -0
  83. package/dist/services/service-handler-context.js.map +1 -0
  84. package/dist/services/service-handler.d.ts +18 -0
  85. package/dist/services/service-handler.js +25 -0
  86. package/dist/services/service-handler.js.map +1 -0
  87. package/dist/services/service.d.ts +66 -0
  88. package/dist/services/service.js +3 -0
  89. package/dist/services/service.js.map +1 -0
  90. package/env.composition.tsx +7 -0
  91. package/envs.docs.mdx +8 -0
  92. package/esm.mjs +13 -0
  93. package/exceptions/env-not-configured-for-component.ts +10 -0
  94. package/exceptions/env-not-found-in-runtime.ts +7 -0
  95. package/exceptions/env-not-found.ts +15 -0
  96. package/exceptions/index.ts +3 -0
  97. package/package.json +90 -0
  98. package/runtime/env-runtime.ts +31 -0
  99. package/runtime/envs-execution-result.ts +46 -0
  100. package/runtime/index.ts +2 -0
  101. package/runtime/runtime.ts +100 -0
  102. package/services/concrete-service.ts +8 -0
  103. package/services/index.ts +13 -0
  104. package/services/service-handler-context.ts +40 -0
  105. package/services/service-handler.ts +41 -0
  106. package/services/service.ts +79 -0
  107. package/types/asset.d.ts +41 -0
  108. package/types/style.d.ts +42 -0
@@ -0,0 +1,366 @@
1
+ import { Dependency as LegacyDependency } from '@teambit/legacy.consumer-component';
2
+ import { SourceFile } from '@teambit/component.sources';
3
+ import { CLIMain } from '@teambit/cli';
4
+ import { Component, ComponentMain } from '@teambit/component';
5
+ import type { EnvPolicyConfigObject } from '@teambit/dependency-resolver';
6
+ import { GraphqlMain } from '@teambit/graphql';
7
+ import { IssuesMain } from '@teambit/issues';
8
+ import type { EnvJsoncPatterns } from '@teambit/dev-files';
9
+ import { Harmony, SlotRegistry } from '@teambit/harmony';
10
+ import { Logger, LoggerMain } from '@teambit/logger';
11
+ import { ExtensionDataList, ExtensionDataEntry } from '@teambit/legacy.extension-data';
12
+ import { WorkerMain } from '@teambit/worker';
13
+ import { ComponentID } from '@teambit/component-id';
14
+ import { EnvService } from './services';
15
+ import { Environment } from './environment';
16
+ import { Runtime } from './runtime';
17
+ import { EnvDefinition } from './env-definition';
18
+ import { EnvServiceList } from './env-service-list';
19
+ import { EnvPlugin } from './env.plugin';
20
+ import { EnvJsoncDetector } from './env-jsonc.detector';
21
+ export type EnvJsonc = {
22
+ extends?: string;
23
+ policy?: EnvPolicyConfigObject;
24
+ patterns?: EnvJsoncPatterns;
25
+ };
26
+ /**
27
+ * The resolved env jsonc is the env jsonc after it was resolved from all the parent envs
28
+ */
29
+ export type ResolvedEnvJsonc = Omit<EnvJsonc, 'extends'>;
30
+ export type EnvJsoncMergeCustomizer = (parentObj: EnvJsonc, childObj: EnvJsonc) => Partial<EnvJsonc>;
31
+ export type EnvJsoncResolver = (parentId: string, envExtendsDeps?: LegacyDependency[]) => Promise<ResolvedEnvJsonc>;
32
+ export type EnvsRegistry = SlotRegistry<Environment>;
33
+ export type EnvJsoncMergeCustomizerRegistry = SlotRegistry<EnvJsoncMergeCustomizer>;
34
+ export type EnvJsoncResolverRegistry = SlotRegistry<EnvJsoncResolver>;
35
+ export type EnvsConfig = {
36
+ env: string;
37
+ options: EnvOptions;
38
+ };
39
+ type GetCalcEnvOptions = {
40
+ skipWarnings?: boolean;
41
+ };
42
+ export type EnvOptions = {};
43
+ export type EnvTransformer = (env: Environment) => Environment;
44
+ export type ServicesRegistry = SlotRegistry<Array<EnvService<any>>>;
45
+ export type RegularCompDescriptor = {
46
+ id: string;
47
+ icon?: string;
48
+ type?: string;
49
+ name?: string;
50
+ description?: string;
51
+ };
52
+ export type EnvCompDescriptorProps = RegularCompDescriptor & {
53
+ resolvedEnvJsonc?: ResolvedEnvJsonc;
54
+ services?: {
55
+ env: {
56
+ id: string;
57
+ icon: string;
58
+ name?: string;
59
+ description?: string;
60
+ };
61
+ services: Array<{
62
+ id: string;
63
+ name?: string;
64
+ description?: string;
65
+ data: any;
66
+ }>;
67
+ };
68
+ };
69
+ export type EnvCompDescriptor = EnvCompDescriptorProps & {
70
+ self?: EnvCompDescriptorProps;
71
+ };
72
+ export type Descriptor = RegularCompDescriptor | EnvCompDescriptor;
73
+ export declare const DEFAULT_ENV = "teambit.harmony/node";
74
+ export declare class EnvsMain {
75
+ /**
76
+ * environments extension configuration.
77
+ */
78
+ readonly config: EnvsConfig;
79
+ /**
80
+ * harmony context.
81
+ */
82
+ private harmony;
83
+ /**
84
+ * slot for allowing extensions to register new environment.
85
+ */
86
+ private envSlot;
87
+ private logger;
88
+ private servicesRegistry;
89
+ private componentMain;
90
+ private loggerMain;
91
+ private workerMain;
92
+ private envJsoncMergeCustomizerSlot;
93
+ private envJsoncResolverSlot;
94
+ /**
95
+ * Envs that are failed to load
96
+ */
97
+ private failedToLoadEnvs;
98
+ /**
99
+ * Extensions that are failed to load
100
+ * We use this as sometime when we couldn't load an extension we don't know if it's an env or not
101
+ * We should ideally take it from the aspect loader aspect, but right now the aspect loader is using envs
102
+ */
103
+ private failedToLoadExt;
104
+ /**
105
+ * Ids of envs (not neccesrraly loaded successfully)
106
+ */
107
+ envIds: Set<string>;
108
+ static runtime: import("@teambit/harmony").RuntimeDefinition;
109
+ private alreadyShownWarning;
110
+ private coreAspectIds;
111
+ /**
112
+ * icon of the extension.
113
+ */
114
+ icon(): string;
115
+ constructor(
116
+ /**
117
+ * environments extension configuration.
118
+ */
119
+ config: EnvsConfig,
120
+ /**
121
+ * harmony context.
122
+ */
123
+ harmony: Harmony,
124
+ /**
125
+ * slot for allowing extensions to register new environment.
126
+ */
127
+ envSlot: EnvsRegistry, logger: Logger, servicesRegistry: ServicesRegistry, componentMain: ComponentMain, loggerMain: LoggerMain, workerMain: WorkerMain, envJsoncMergeCustomizerSlot: EnvJsoncMergeCustomizerRegistry, envJsoncResolverSlot: EnvJsoncResolverRegistry);
128
+ /**
129
+ * creates a new runtime environments for a set of components.
130
+ */
131
+ createEnvironment(components: Component[]): Promise<Runtime>;
132
+ setCoreAspectIds(ids: string[]): void;
133
+ isCoreAspect(id: string): boolean;
134
+ /**
135
+ *
136
+ * @param id
137
+ */
138
+ /**
139
+ * This function adds an extension ID to a set of failed to load extensions.
140
+ * This mostly used by the aspect loader to add such issues
141
+ * Then it is used to hide different errors that are caused by the same issue.
142
+ * @param {string} id - string - represents the unique identifier of an extension that failed to load.
143
+ */
144
+ addFailedToLoadEnvs(id: string): void;
145
+ addFailedToLoadExt(id: string): void;
146
+ resetFailedToLoadEnvs(): void;
147
+ getFailedToLoadEnvs(): string[];
148
+ /**
149
+ * get the configured default env.
150
+ */
151
+ getDefaultEnv(): EnvDefinition;
152
+ getCoreEnvsIds(): string[];
153
+ /**
154
+ * compose a new environment from a list of environment transformers.
155
+ */
156
+ compose(targetEnv: Environment, envTransformers: EnvTransformer[]): Environment;
157
+ /**
158
+ * create an env transformer which overrides specific env properties.
159
+ */
160
+ override(propsToOverride: Environment): EnvTransformer;
161
+ /**
162
+ * compose two environments into one.
163
+ */
164
+ merge<T extends Environment, S extends Environment>(targetEnv: Environment, sourceEnv: Environment): T & S;
165
+ /**
166
+ * This function checks if an environment manifest file exists in a given component or set of legacy files.
167
+ * @param {Component} [envComponent] - A component object that represents an environment. It contains information about
168
+ * the files and directories that make up the environment.
169
+ * @param {SourceFile[]} [legacyFiles] - An optional array of SourceFile objects representing the files in the legacy
170
+ * file system. If this parameter is not provided, the function will attempt to retrieve the files from the envComponent
171
+ * parameter.
172
+ * @returns a boolean value indicating whether an `env.jsonc` or `env.json` file exists in the `files` array of either
173
+ * the `envComponent` object or the `legacyFiles` array. If neither `envComponent` nor `legacyFiles` are provided, the
174
+ * function returns `undefined`.
175
+ */
176
+ hasEnvManifest(envComponent?: Component, legacyFiles?: SourceFile[]): boolean | undefined;
177
+ getEnvManifest(envComponent: Component): ResolvedEnvJsonc | undefined;
178
+ getOrCalculateEnvManifest(component: Component, legacyFiles?: SourceFile[], envExtendsDeps?: LegacyDependency[]): Promise<ResolvedEnvJsonc | undefined>;
179
+ calculateEnvManifest(envComponent?: Component, legacyFiles?: SourceFile[], envExtendsDeps?: LegacyDependency[]): Promise<EnvJsonc | undefined>;
180
+ recursivelyMergeWithParentManifest(object: EnvJsonc, envExtendsDeps?: LegacyDependency[]): Promise<EnvJsonc>;
181
+ mergeEnvManifests(parent: EnvJsonc, child: EnvJsonc): EnvJsonc;
182
+ hasEnvManifestById(envId: string, requesting: string): Promise<boolean | undefined>;
183
+ getEnvData(component: Component): Descriptor;
184
+ /**
185
+ * Return the id of the env as configured in the envs data (without version by default)
186
+ * 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
187
+ * As this version is stay up to date during tagging the env along with the component
188
+ * @param component
189
+ * @param ignoreVersion
190
+ */
191
+ private getEnvIdFromEnvsData;
192
+ /**
193
+ * get the env id of the given component.
194
+ */
195
+ getEnvId(component: Component): string;
196
+ isUsingCoreEnv(component: Component): boolean;
197
+ isCoreEnv(envId: string): boolean;
198
+ /**
199
+ * get the env of the given component.
200
+ * In case you are asking for the env during on load you should use calculateEnv instead
201
+ */
202
+ getEnv(component: Component): EnvDefinition;
203
+ /**
204
+ * get the env component of the given component.
205
+ */
206
+ getEnvComponent(component: Component): Promise<Component>;
207
+ /**
208
+ * get the env component by the env id.
209
+ */
210
+ getEnvComponentByEnvId(envId: string, requesting?: string): Promise<Component>;
211
+ /**
212
+ * get the env of the given component.
213
+ * This will try to use the regular getEnv but fallback to the calculate env (in case you are using it during on load)
214
+ * This is safe to be used on onLoad as well
215
+ */
216
+ getOrCalculateEnv(component: Component): EnvDefinition;
217
+ getOrCalculateEnvId(component: Component): Promise<ComponentID>;
218
+ /**
219
+ * get an environment Descriptor.
220
+ */
221
+ getDescriptor(component: Component): Descriptor | undefined;
222
+ calcDescriptor(component: Component, opts?: GetCalcEnvOptions): Promise<Descriptor | undefined>;
223
+ /**
224
+ * Get env descriptor from the env itself if the component is an env
225
+ * This will be empty for regular component, and will only contain data for env themself
226
+ */
227
+ private getEnvSelfDescriptor;
228
+ /**
229
+ * Get env descriptor from the env that a given component is using
230
+ */
231
+ private getComponentEnvDescriptor;
232
+ private getEnvDescriptorFromEnvDef;
233
+ resolveEnv(component: Component, id: string): ComponentID | undefined;
234
+ /**
235
+ * This used to calculate the actual env during the component load.
236
+ * Do not use it to get the env (use getEnv instead)
237
+ * This should be used only during on load
238
+ */
239
+ calculateEnvId(component: Component): Promise<ComponentID>;
240
+ /**
241
+ * This used to calculate the actual env during the component load.
242
+ * Do not use it to get the env (use getEnv instead)
243
+ * This should be used only during on load
244
+ */
245
+ calculateEnv(component: Component, opts?: GetCalcEnvOptions): EnvDefinition;
246
+ /**
247
+ * an env can be configured on a component in two ways:
248
+ * 1) explicitly inside "teambit.envs/envs". `{ "teambit.envs/envs": { "env": "my-env" } }`
249
+ * 2) the env aspect is set on the variant as any other aspect, e.g. `{ "my-env": {} }`
250
+ *
251
+ * this method returns #1 if exists, otherwise, #2.
252
+ */
253
+ getAllEnvsConfiguredOnComponent(component: Component): EnvDefinition[];
254
+ /**
255
+ * whether a component has an env configured (either by variant or .bitmap).
256
+ */
257
+ hasEnvConfigured(component: Component): boolean;
258
+ getAllRegisteredEnvsIds(): string[];
259
+ getAllRegisteredEnvs(): Environment[];
260
+ getAllRegisteredEnvJsoncCustomizers(): EnvJsoncMergeCustomizer[];
261
+ getAllRegisteredEnvJsoncResolvers(): EnvJsoncResolver[];
262
+ getEnvPlugin(): EnvPlugin;
263
+ /**
264
+ * an env can be configured on a component in two ways:
265
+ * 1) explicitly inside "teambit.envs/envs". `{ "teambit.envs/envs": { "env": "my-env" } }`
266
+ * 2) the env aspect is set on the variant as any other aspect, e.g. `{ "my-env": {} }`
267
+ *
268
+ * this method returns only #1
269
+ */
270
+ getEnvFromEnvsConfig(component: Component): EnvDefinition | undefined;
271
+ /**
272
+ * an env can be configured on a component in two ways:
273
+ * 1) explicitly inside "teambit.envs/envs". `{ "teambit.envs/envs": { "env": "my-env" } }`
274
+ * 2) the env aspect is set on the variant as any other aspect, e.g. `{ "my-env": {} }`
275
+ *
276
+ * this method returns only #2
277
+ */
278
+ getEnvsNotFromEnvsConfig(component: Component): EnvDefinition[];
279
+ getEnvIdFromEnvsLegacyExtensions(extensions: ExtensionDataList): string | undefined;
280
+ /**
281
+ * @deprecated DO NOT USE THIS METHOD ANYMORE!!! (PLEASE USE .calculateEnvId() instead!)
282
+ */
283
+ calculateEnvIdFromExtensions(extensions: ExtensionDataList): Promise<string>;
284
+ validateEnvId(ext: ExtensionDataEntry): {
285
+ errorMsg: string;
286
+ minBitVersion: string;
287
+ } | undefined;
288
+ /**
289
+ * @deprecated DO NOT USE THIS METHOD ANYMORE!!! (PLEASE USE .calculateEnv() instead!)
290
+ */
291
+ calculateEnvFromExtensions(extensions: ExtensionDataList): Promise<EnvDefinition>;
292
+ /**
293
+ * This function finds the first environment ID from a list of IDs by checking if it is register as env (to the slot).
294
+ * or contains env.jsonc file
295
+ * @param {string[]} ids - `ids` is an array of string values representing environment IDs. The function `findFirstEnv`
296
+ * takes this array as input and returns a Promise that resolves to a string value representing the first environment ID
297
+ * that matches certain conditions.
298
+ * @returns The `findFirstEnv` function returns a Promise that resolves to a string or undefined. The string represents
299
+ * the ID of the first environment that matches the conditions specified in the function, or undefined if no environment
300
+ * is found.
301
+ */
302
+ private findFirstEnv;
303
+ private getEnvDefinitionByLegacyExtension;
304
+ getEnvIdFromEnvsConfig(component: Component): string | undefined;
305
+ getEnvDefinition(id: ComponentID): EnvDefinition | undefined;
306
+ getEnvDefinitionById(id: ComponentID): EnvDefinition | undefined;
307
+ getEnvDefinitionByStringId(envId: string): EnvDefinition | undefined;
308
+ getEnvFromComponent(envComponent: Component): EnvDefinition | undefined;
309
+ /**
310
+ * Return the env definition of teambit.envs/env
311
+ */
312
+ getEnvsEnvDefinition(): EnvDefinition;
313
+ private printWarningIfFirstTime;
314
+ /**
315
+ * determines whether an env is registered.
316
+ */
317
+ isEnvRegistered(id: string): boolean;
318
+ isUsingAspectEnv(component: Component): boolean;
319
+ isUsingEnvEnv(component: Component): boolean;
320
+ /**
321
+ * Check if the given component is an env component.
322
+ * @param component
323
+ * @returns
324
+ */
325
+ isEnv(component: Component): boolean;
326
+ /**
327
+ * register a new environment service.
328
+ */
329
+ registerService(...envServices: EnvService<any>[]): this;
330
+ /**
331
+ * get list of services enabled on an env.
332
+ */
333
+ getServices(env: EnvDefinition): EnvServiceList;
334
+ implements(env: EnvDefinition, service: EnvService<any>): boolean;
335
+ /**
336
+ * register an environment.
337
+ */
338
+ registerEnv(env: Environment): void;
339
+ /**
340
+ * register an env.jsonc merge customizer.
341
+ */
342
+ registerEnvJsoncMergeCustomizer(customizer: EnvJsoncMergeCustomizer): void;
343
+ registerEnvJsoncResolver(resolver: EnvJsoncResolver): void;
344
+ getEnvJsoncDetector(): EnvJsoncDetector;
345
+ addNonLoadedEnvAsComponentIssues(components: Component[]): Promise<void>;
346
+ private createRuntime;
347
+ private aggregateByDefs;
348
+ private getEnvAspectDef;
349
+ private throwForDuplicateComponents;
350
+ static slots: (((registerFn: () => string) => SlotRegistry<Environment>) | ((registerFn: () => string) => SlotRegistry<EnvService<any, {}, {}>>) | ((registerFn: () => string) => SlotRegistry<EnvJsoncMergeCustomizerRegistry>) | ((registerFn: () => string) => SlotRegistry<EnvJsoncResolverRegistry>))[];
351
+ static dependencies: import("@teambit/harmony").Aspect[];
352
+ static provider([graphql, loggerAspect, component, cli, worker, issues]: [
353
+ GraphqlMain,
354
+ LoggerMain,
355
+ ComponentMain,
356
+ CLIMain,
357
+ WorkerMain,
358
+ IssuesMain
359
+ ], config: EnvsConfig, [envSlot, servicesRegistry, envJsoncMergeCustomizerSlot, envJsoncResolverSlot]: [
360
+ EnvsRegistry,
361
+ ServicesRegistry,
362
+ EnvJsoncMergeCustomizerRegistry,
363
+ EnvJsoncResolverRegistry
364
+ ], context: Harmony): Promise<EnvsMain>;
365
+ }
366
+ export {};