@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,13 @@
1
+ export {
2
+ Service as EnvService,
3
+ ServiceExecutionResult,
4
+ TransformationMap as ServiceTransformationMap,
5
+ } from './service';
6
+ export { ConcreteService } from './concrete-service';
7
+ export {
8
+ ServiceHandler,
9
+ ServiceHandlerFactory,
10
+ AsyncServiceHandlerFactory,
11
+ reduceServiceHandlersFactories,
12
+ } from './service-handler';
13
+ export { ServiceHandlerContext } from './service-handler-context';
@@ -0,0 +1,40 @@
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
+
6
+ export class ServiceHandlerContext {
7
+ constructor(
8
+ /**
9
+ * id of the environment defined in the context.
10
+ */
11
+ readonly envId: ComponentID,
12
+ readonly loggerMain: LoggerMain,
13
+ readonly workerMain: WorkerMain,
14
+ readonly harmony: Harmony
15
+ ) {}
16
+
17
+ /**
18
+ * return a logger instance for the env.
19
+ */
20
+ createLogger(name?: string): Logger {
21
+ const loggerName = name ? `${this.envId.toString()}::${name}` : this.envId.toString();
22
+
23
+ return this.loggerMain.createLogger(loggerName);
24
+ }
25
+
26
+ /**
27
+ * get an instance of an aspect. make sure it is loaded prior to requesting it.
28
+ */
29
+ getAspect<T>(aspectId: string) {
30
+ return this.harmony.get<T>(aspectId);
31
+ }
32
+
33
+ /**
34
+ * create worker for the env context.
35
+ */
36
+ createWorker<T>(name: string, path: string) {
37
+ const worker = this.workerMain.declareWorker<T>(name, path);
38
+ return worker;
39
+ }
40
+ }
@@ -0,0 +1,41 @@
1
+ import { ServiceHandlerContext } from './service-handler-context';
2
+
3
+ /**
4
+ * definition of the service handler.
5
+ */
6
+ export type ServiceHandlerFactory<T> = (context: ServiceHandlerContext) => ServiceHandler & T;
7
+ export type AsyncServiceHandlerFactory<T> = (context: ServiceHandlerContext) => Promise<ServiceHandler & T>;
8
+
9
+ export interface ServiceHandler {
10
+ /**
11
+ * name of the service. e.g. 'typescript-compiler'
12
+ */
13
+ name?: string;
14
+ /**
15
+ * version of the service. optional.
16
+ */
17
+ version?: () => string;
18
+
19
+ /**
20
+ * config of the service. e.g. tsconfig.json
21
+ */
22
+ // config?: string;
23
+ }
24
+
25
+ export type ReduceFactoryCallback<T> = (acc: T, value: T) => ServiceHandler & T;
26
+ export function reduceServiceHandlersFactories<T>(
27
+ factories: ServiceHandlerFactory<T>[],
28
+ callback: ReduceFactoryCallback<T>
29
+ ): ServiceHandlerFactory<T> {
30
+ if (!factories.length) throw new Error('no factories were provided');
31
+ const result: ServiceHandlerFactory<T> = (context: ServiceHandlerContext) => {
32
+ // @ts-ignore
33
+ const initialVal = factories.shift()(context);
34
+ const reduced: ServiceHandler & T = factories.reduce((acc, currFactory) => {
35
+ const curr = currFactory(context);
36
+ return callback(acc, curr);
37
+ }, initialVal);
38
+ return reduced;
39
+ };
40
+ return result;
41
+ }
@@ -0,0 +1,79 @@
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
+
7
+ export type EnvContext = {
8
+ components: Component[];
9
+ };
10
+
11
+ export interface ServiceExecutionResult {
12
+ errors?: Error[];
13
+ }
14
+
15
+ export type ServiceTransformHandlerFactory<T> = (
16
+ handlerContext?: any
17
+ ) => (ServiceHandler & T) | Promise<ServiceHandler & T>;
18
+
19
+ /**
20
+ * definition of the service handler type
21
+ * This used to define new types of handlers like
22
+ * Compiler, Tester, Preview, etc.
23
+ */
24
+ export type TransformationMap = {
25
+ /**
26
+ * The name of the function that will be called on the service run/run once later.
27
+ * This func will be exist on the final env object
28
+ */
29
+ [funcName: string]: ServiceTransformHandlerFactory<any>;
30
+ };
31
+
32
+ /**
33
+ * services allows to reuse and standardize services for development environments.
34
+ * examples for services can be: `linting`, `compilation`, `build`, and others which offer
35
+ * standard services to environments such as `react`, `angular` and `vue` and different compositions of each for
36
+ * more concrete needs.
37
+ *
38
+ * `TData` - type of data returned by the service handler.
39
+ * `TOpts` is the type of options passed to the environment through execution.
40
+ * `TExecResponse` is the execution result of the service.
41
+ */
42
+ export interface Service<TExecResponse extends ServiceExecutionResult, TData = {}, TOpts = {}> {
43
+ /**
44
+ * name of the service. (e.g. `compile`, `test`, etc.)
45
+ */
46
+ name?: string;
47
+
48
+ /**
49
+ * description of the env.
50
+ */
51
+ description?: string;
52
+
53
+ /**
54
+ * create a string to describe to service in the env cli.
55
+ */
56
+ render?(env: Environment, context: EnvContext[]): string | Promise<string>;
57
+
58
+ /**
59
+ * get service data from an environment.
60
+ */
61
+ getDescriptor?(environment: Environment, context?: EnvContext[]): TData | undefined | Promise<TData | undefined>;
62
+
63
+ /**
64
+ * executes a service on a subset of components.
65
+ */
66
+ run?(context: EnvContext, options?: TOpts): Promise<TExecResponse>;
67
+
68
+ /**
69
+ * run the service only once.
70
+ */
71
+ runOnce?(context: EnvContext[], options?: TOpts): Promise<any>;
72
+
73
+ /**
74
+ * Return a map of functions that will be called on the service run/run once later.
75
+ * @param env the original env plugin object
76
+ * @param context ServiceHandlerContext(EnvContext)
77
+ */
78
+ transform?(env: Env, context: ServiceHandlerContext): TransformationMap | undefined;
79
+ }
@@ -0,0 +1,41 @@
1
+ declare module '*.png' {
2
+ const value: any;
3
+ export = value;
4
+ }
5
+ declare module '*.svg' {
6
+ import type { FunctionComponent, SVGProps } from 'react';
7
+
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
11
+ const src: string;
12
+ export default src;
13
+ }
14
+ declare module '*.jpg' {
15
+ const value: any;
16
+ export = value;
17
+ }
18
+ declare module '*.jpeg' {
19
+ const value: any;
20
+ export = value;
21
+ }
22
+ declare module '*.gif' {
23
+ const value: any;
24
+ export = value;
25
+ }
26
+ declare module '*.bmp' {
27
+ const value: any;
28
+ export = value;
29
+ }
30
+ declare module '*.otf' {
31
+ const value: any;
32
+ export = value;
33
+ }
34
+ declare module '*.woff' {
35
+ const value: any;
36
+ export = value;
37
+ }
38
+ declare module '*.woff2' {
39
+ const value: any;
40
+ export = value;
41
+ }
@@ -0,0 +1,42 @@
1
+ declare module '*.module.css' {
2
+ const classes: { readonly [key: string]: string };
3
+ export default classes;
4
+ }
5
+ declare module '*.module.scss' {
6
+ const classes: { readonly [key: string]: string };
7
+ export default classes;
8
+ }
9
+ declare module '*.module.sass' {
10
+ const classes: { readonly [key: string]: string };
11
+ export default classes;
12
+ }
13
+
14
+ declare module '*.module.less' {
15
+ const classes: { readonly [key: string]: string };
16
+ export default classes;
17
+ }
18
+
19
+ declare module '*.less' {
20
+ const classes: { readonly [key: string]: string };
21
+ export default classes;
22
+ }
23
+
24
+ declare module '*.css' {
25
+ const classes: { readonly [key: string]: string };
26
+ export default classes;
27
+ }
28
+
29
+ declare module '*.sass' {
30
+ const classes: { readonly [key: string]: string };
31
+ export default classes;
32
+ }
33
+
34
+ declare module '*.scss' {
35
+ const classes: { readonly [key: string]: string };
36
+ export default classes;
37
+ }
38
+
39
+ declare module '*.mdx' {
40
+ const component: any;
41
+ export default component;
42
+ }