@teambit/application 1.0.107 → 1.0.108
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/app-build-context.ts +55 -0
- package/app-build-result.ts +26 -0
- package/app-context.ts +97 -0
- package/app-deploy-context.ts +38 -0
- package/app-instance.ts +36 -0
- package/app-server.ts +9 -0
- package/app-type-list.ts +25 -0
- package/app-type.plugin.ts +24 -0
- package/app.cmd.ts +46 -0
- package/app.plugin.ts +17 -0
- package/application-type.ts +18 -0
- package/application.aspect.ts +5 -0
- package/application.main.runtime.ts +485 -0
- package/application.service.ts +32 -0
- package/application.ts +41 -0
- package/apps-env-type.ts +9 -0
- package/build-application.task.ts +183 -0
- package/deploy.task.ts +134 -0
- package/deployment-provider.ts +5 -0
- package/dist/app-build-context.d.ts +1 -1
- package/dist/app-context.d.ts +6 -6
- package/dist/app-context.js +1 -1
- package/dist/app-context.js.map +1 -1
- package/dist/app-deploy-context.d.ts +4 -4
- package/dist/app-instance.d.ts +2 -2
- package/dist/app-type-list.d.ts +1 -1
- package/dist/application.composition.d.ts +2 -2
- package/dist/application.d.ts +3 -3
- package/dist/application.main.runtime.d.ts +10 -10
- package/dist/application.main.runtime.js +3 -5
- package/dist/application.main.runtime.js.map +1 -1
- package/dist/application.service.d.ts +2 -2
- package/dist/application.service.js +1 -1
- package/dist/application.service.js.map +1 -1
- package/dist/build-application.task.d.ts +5 -5
- package/dist/deploy.task.js +6 -7
- package/dist/deploy.task.js.map +1 -1
- package/dist/{preview-1703590665075.js → preview-1703647408454.js} +2 -2
- package/dist/run.cmd.d.ts +1 -1
- package/index.ts +13 -0
- package/package.json +23 -30
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
import mapSeries from 'p-map-series';
|
|
3
|
+
import {
|
|
4
|
+
BuildTask,
|
|
5
|
+
BuiltTaskResult,
|
|
6
|
+
BuildContext,
|
|
7
|
+
ComponentResult,
|
|
8
|
+
ArtifactDefinition,
|
|
9
|
+
CAPSULE_ARTIFACTS_DIR,
|
|
10
|
+
} from '@teambit/builder';
|
|
11
|
+
import { compact } from 'lodash';
|
|
12
|
+
import { Capsule } from '@teambit/isolator';
|
|
13
|
+
import { Component } from '@teambit/component';
|
|
14
|
+
|
|
15
|
+
import { ApplicationAspect } from './application.aspect';
|
|
16
|
+
import { ApplicationMain } from './application.main.runtime';
|
|
17
|
+
import { AppBuildContext } from './app-build-context';
|
|
18
|
+
import { Application } from './application';
|
|
19
|
+
|
|
20
|
+
export const BUILD_TASK = 'build_application';
|
|
21
|
+
export const ARTIFACTS_DIR_NAME = 'apps';
|
|
22
|
+
|
|
23
|
+
export type OneAppResult = {
|
|
24
|
+
componentResult: ComponentResult;
|
|
25
|
+
artifacts?: ArtifactDefinition[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type OneComponentResult = {
|
|
29
|
+
componentResult: ComponentResult;
|
|
30
|
+
artifacts?: ArtifactDefinition[];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type BuildAppResult = {
|
|
34
|
+
componentResult: ComponentResult;
|
|
35
|
+
artifacts?: ArtifactDefinition[];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type BuildDeployContexts = {
|
|
39
|
+
deployContext: { publicDir?: string; ssrPublicDir?: string };
|
|
40
|
+
name: string;
|
|
41
|
+
appType: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type Options = {
|
|
45
|
+
deploy: boolean;
|
|
46
|
+
};
|
|
47
|
+
export class AppsBuildTask implements BuildTask {
|
|
48
|
+
name = BUILD_TASK;
|
|
49
|
+
aspectId = ApplicationAspect.id;
|
|
50
|
+
readonly location = 'end';
|
|
51
|
+
constructor(private application: ApplicationMain, private opt: Options = { deploy: true }) {}
|
|
52
|
+
|
|
53
|
+
async execute(context: BuildContext): Promise<BuiltTaskResult> {
|
|
54
|
+
const originalSeedersIds = context.capsuleNetwork.originalSeedersCapsules.map((c) => c.component.id.toString());
|
|
55
|
+
const { capsuleNetwork } = context;
|
|
56
|
+
const result: BuiltTaskResult = {
|
|
57
|
+
componentsResults: [],
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// const componentsResults = await mapSeries(apps, async (app): Promise<AppsResults | undefined> => {
|
|
61
|
+
await mapSeries(capsuleNetwork.originalSeedersCapsules, async (capsule) => {
|
|
62
|
+
const component = capsule.component;
|
|
63
|
+
if (originalSeedersIds && originalSeedersIds.length && !originalSeedersIds.includes(component.id.toString())) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const apps = await this.application.loadAppsFromComponent(component, capsule.path);
|
|
68
|
+
if (!apps || !apps.length) return undefined;
|
|
69
|
+
const componentsResults = await mapSeries(compact(apps), async (app) =>
|
|
70
|
+
this.runForOneApp(app, component, capsule, context)
|
|
71
|
+
);
|
|
72
|
+
const merged = this.mergeAppsResults(compact(componentsResults));
|
|
73
|
+
if (merged) {
|
|
74
|
+
result.componentsResults.push(merged.componentResult);
|
|
75
|
+
if (!result.artifacts) result.artifacts = [];
|
|
76
|
+
result.artifacts.push(...(merged.artifacts || []));
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private async runForOneApp(
|
|
85
|
+
app: Application,
|
|
86
|
+
component: Component,
|
|
87
|
+
capsule: Capsule,
|
|
88
|
+
context: BuildContext
|
|
89
|
+
): Promise<OneAppResult | undefined> {
|
|
90
|
+
if (!app.build) return undefined;
|
|
91
|
+
const artifactsDir = this.getArtifactDirectory();
|
|
92
|
+
const capsuleRootDir = context.capsuleNetwork.capsulesRootDir;
|
|
93
|
+
const appContext = await this.application.createAppBuildContext(
|
|
94
|
+
component.id,
|
|
95
|
+
app.name,
|
|
96
|
+
capsuleRootDir,
|
|
97
|
+
capsule.path
|
|
98
|
+
);
|
|
99
|
+
const appBuildContext = AppBuildContext.create({
|
|
100
|
+
appContext,
|
|
101
|
+
buildContext: context,
|
|
102
|
+
appComponent: component,
|
|
103
|
+
name: app.name,
|
|
104
|
+
capsule,
|
|
105
|
+
artifactsDir,
|
|
106
|
+
});
|
|
107
|
+
const deployContext = await app.build(appBuildContext);
|
|
108
|
+
const defaultArtifacts: ArtifactDefinition[] = this.getDefaultArtifactDef(app.applicationType || app.name);
|
|
109
|
+
const artifacts = defaultArtifacts.concat(deployContext.artifacts || []);
|
|
110
|
+
|
|
111
|
+
const getDeployContextFromMetadata = () => {
|
|
112
|
+
if (deployContext.metadata) {
|
|
113
|
+
return deployContext.metadata;
|
|
114
|
+
}
|
|
115
|
+
// if metadata is not defined, don't save deployContext blindly. in node-app for example it includes the entire
|
|
116
|
+
// Network object, with all capsules and components.
|
|
117
|
+
return {};
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
artifacts,
|
|
122
|
+
componentResult: {
|
|
123
|
+
component: capsule.component,
|
|
124
|
+
errors: deployContext.errors,
|
|
125
|
+
warnings: deployContext.warnings,
|
|
126
|
+
metadata: { deployContext: getDeployContextFromMetadata(), name: app.name, appType: app.applicationType },
|
|
127
|
+
/**
|
|
128
|
+
* @deprecated - please use metadata instead
|
|
129
|
+
*
|
|
130
|
+
* @guysaar223
|
|
131
|
+
* @ranm8
|
|
132
|
+
* TODO: we need to think how to pass private metadata between build pipes, maybe create shared context
|
|
133
|
+
* or create new deploy context on builder
|
|
134
|
+
*/
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
_metadata: { deployContext, name: app.name, appType: app.applicationType },
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private mergeAppsResults(appsResults: OneAppResult[]): OneComponentResult | undefined {
|
|
142
|
+
if (!appsResults || !appsResults.length) return undefined;
|
|
143
|
+
const merged: OneComponentResult = {
|
|
144
|
+
artifacts: [],
|
|
145
|
+
componentResult: {
|
|
146
|
+
component: appsResults[0].componentResult.component,
|
|
147
|
+
errors: [],
|
|
148
|
+
warnings: [],
|
|
149
|
+
metadata: {
|
|
150
|
+
buildDeployContexts: [],
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
appsResults.forEach((appResult) => {
|
|
155
|
+
merged.artifacts = (merged.artifacts || []).concat(appResult.artifacts || []);
|
|
156
|
+
merged.componentResult.errors = (merged.componentResult.errors || []).concat(
|
|
157
|
+
appResult.componentResult.errors || []
|
|
158
|
+
);
|
|
159
|
+
merged.componentResult.warnings = (merged.componentResult.warnings || []).concat(
|
|
160
|
+
appResult.componentResult.warnings || []
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
164
|
+
merged.componentResult.metadata!.buildDeployContexts =
|
|
165
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
166
|
+
(merged.componentResult.metadata!.buildDeployContexts || []).concat(appResult.componentResult.metadata || []);
|
|
167
|
+
});
|
|
168
|
+
return merged;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private getArtifactDirectory() {
|
|
172
|
+
return join(CAPSULE_ARTIFACTS_DIR, ARTIFACTS_DIR_NAME);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private getDefaultArtifactDef(nameSuffix: string): ArtifactDefinition[] {
|
|
176
|
+
return [
|
|
177
|
+
{
|
|
178
|
+
name: `app-build-${nameSuffix}`,
|
|
179
|
+
globPatterns: [`${this.getArtifactDirectory()}/**`],
|
|
180
|
+
},
|
|
181
|
+
];
|
|
182
|
+
}
|
|
183
|
+
}
|
package/deploy.task.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import mapSeries from 'p-map-series';
|
|
2
|
+
import {
|
|
3
|
+
BuilderMain,
|
|
4
|
+
BuildTask,
|
|
5
|
+
BuildContext,
|
|
6
|
+
ComponentResult,
|
|
7
|
+
TaskResults,
|
|
8
|
+
BuiltTaskResult,
|
|
9
|
+
CAPSULE_ARTIFACTS_DIR,
|
|
10
|
+
} from '@teambit/builder';
|
|
11
|
+
import { compact, join } from 'lodash';
|
|
12
|
+
import { Capsule } from '@teambit/isolator';
|
|
13
|
+
import { Component } from '@teambit/component';
|
|
14
|
+
import { ApplicationAspect } from './application.aspect';
|
|
15
|
+
import { ApplicationMain } from './application.main.runtime';
|
|
16
|
+
import { ARTIFACTS_DIR_NAME, BUILD_TASK, BuildDeployContexts } from './build-application.task';
|
|
17
|
+
import { AppDeployContext } from './app-deploy-context';
|
|
18
|
+
import { Application } from './application';
|
|
19
|
+
import { ApplicationDeployment } from './app-instance';
|
|
20
|
+
import { AppBuildContext } from './app-build-context';
|
|
21
|
+
|
|
22
|
+
export const DEPLOY_TASK = 'deploy_application';
|
|
23
|
+
|
|
24
|
+
export class DeployTask implements BuildTask {
|
|
25
|
+
name = DEPLOY_TASK;
|
|
26
|
+
aspectId = ApplicationAspect.id;
|
|
27
|
+
readonly location = 'end';
|
|
28
|
+
constructor(private application: ApplicationMain, private builder: BuilderMain) {}
|
|
29
|
+
|
|
30
|
+
async execute(context: BuildContext): Promise<BuiltTaskResult> {
|
|
31
|
+
const originalSeedersIds = context.capsuleNetwork.originalSeedersCapsules.map((c) => c.component.id.toString());
|
|
32
|
+
const { capsuleNetwork } = context;
|
|
33
|
+
|
|
34
|
+
const components = await mapSeries(capsuleNetwork.originalSeedersCapsules, async (capsule) => {
|
|
35
|
+
const component = capsule.component;
|
|
36
|
+
if (originalSeedersIds && originalSeedersIds.length && !originalSeedersIds.includes(component.id.toString())) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const apps = await this.application.loadAppsFromComponent(component, capsule.path);
|
|
40
|
+
if (!apps || !apps.length) return undefined;
|
|
41
|
+
const appDeployments = await mapSeries(compact(apps), async (app) => this.runForOneApp(app, capsule, context));
|
|
42
|
+
const deploys = compact(appDeployments);
|
|
43
|
+
return { component, deploys };
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const _componentsResults: ComponentResult[] = compact(components).map(({ component, deploys }) => {
|
|
47
|
+
return {
|
|
48
|
+
component,
|
|
49
|
+
metadata: {
|
|
50
|
+
deployments: deploys.map((deploy) => {
|
|
51
|
+
const deployObject = deploy || {};
|
|
52
|
+
return {
|
|
53
|
+
appName: deployObject?.appName,
|
|
54
|
+
timestamp: deployObject?.timestamp,
|
|
55
|
+
url: deployObject?.url,
|
|
56
|
+
};
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
componentsResults: _componentsResults,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private async runForOneApp(
|
|
68
|
+
app: Application,
|
|
69
|
+
capsule: Capsule,
|
|
70
|
+
context: BuildContext
|
|
71
|
+
): Promise<ApplicationDeployment | void | undefined> {
|
|
72
|
+
const aspectId = this.application.getAppAspect(app.name);
|
|
73
|
+
if (!aspectId) return undefined;
|
|
74
|
+
|
|
75
|
+
if (!capsule || !capsule?.component) return undefined;
|
|
76
|
+
|
|
77
|
+
const buildTask = this.getBuildTask(context.previousTasksResults, context.envRuntime.id);
|
|
78
|
+
|
|
79
|
+
const metadata = this.getBuildMetadata(buildTask, capsule.component);
|
|
80
|
+
if (!metadata) return undefined;
|
|
81
|
+
const buildDeployContexts = metadata.find((ctx) => ctx.name === app.name && ctx.appType === app.applicationType);
|
|
82
|
+
if (!buildDeployContexts) return undefined;
|
|
83
|
+
|
|
84
|
+
const artifacts = this.builder.getArtifacts(capsule.component);
|
|
85
|
+
const appContext = await this.application.createAppBuildContext(capsule.component.id, app.name, capsule.path);
|
|
86
|
+
const artifactsDir = this.getArtifactDirectory();
|
|
87
|
+
const appBuildContext = AppBuildContext.create({
|
|
88
|
+
appContext,
|
|
89
|
+
buildContext: context,
|
|
90
|
+
appComponent: capsule.component,
|
|
91
|
+
name: app.name,
|
|
92
|
+
capsule,
|
|
93
|
+
artifactsDir,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const appDeployContext = new AppDeployContext(
|
|
97
|
+
appBuildContext,
|
|
98
|
+
artifacts,
|
|
99
|
+
buildDeployContexts.deployContext.publicDir,
|
|
100
|
+
buildDeployContexts.deployContext.ssrPublicDir
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
if (app && typeof app.deploy === 'function') {
|
|
104
|
+
return app.deploy(appDeployContext);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private getArtifactDirectory() {
|
|
111
|
+
return join(CAPSULE_ARTIFACTS_DIR, ARTIFACTS_DIR_NAME);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private getBuildMetadata(
|
|
115
|
+
buildTask: TaskResults | undefined,
|
|
116
|
+
component: Component
|
|
117
|
+
): BuildDeployContexts[] | undefined {
|
|
118
|
+
if (!buildTask) {
|
|
119
|
+
const appData = this.builder.getDataByAspect(component, ApplicationAspect.id);
|
|
120
|
+
if (!appData) return undefined;
|
|
121
|
+
return appData.buildDeployContexts;
|
|
122
|
+
}
|
|
123
|
+
const componentResults = buildTask?.componentsResults.find((res) =>
|
|
124
|
+
res.component.id.isEqual(component.id, { ignoreVersion: true })
|
|
125
|
+
);
|
|
126
|
+
return componentResults?.metadata?.buildDeployContexts;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private getBuildTask(taskResults: TaskResults[], runtime: string) {
|
|
130
|
+
return taskResults.find(
|
|
131
|
+
({ task, env }) => task.aspectId === ApplicationAspect.id && task.name === BUILD_TASK && env.id === runtime
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -3,7 +3,7 @@ import { Capsule, Network } from '@teambit/isolator';
|
|
|
3
3
|
import { BuildContext, PipeName, TaskResults } from '@teambit/builder';
|
|
4
4
|
import { LaneId } from '@teambit/lane-id';
|
|
5
5
|
import { AppContext } from './app-context';
|
|
6
|
-
export
|
|
6
|
+
export type AppBuildContextCreate = {
|
|
7
7
|
appContext: AppContext;
|
|
8
8
|
buildContext: BuildContext;
|
|
9
9
|
name: string;
|
package/dist/app-context.d.ts
CHANGED
|
@@ -33,15 +33,15 @@ export declare class AppContext extends ExecutionContext {
|
|
|
33
33
|
* This can be used in different bundle options which run require.resolve
|
|
34
34
|
* for example when configuring webpack aliases or webpack expose loader on the peers deps
|
|
35
35
|
*/
|
|
36
|
-
readonly hostRootDir?: string
|
|
36
|
+
readonly hostRootDir?: string;
|
|
37
37
|
/**
|
|
38
38
|
* A port to run the app on
|
|
39
39
|
*/
|
|
40
|
-
readonly port?: number
|
|
40
|
+
readonly port?: number;
|
|
41
41
|
/**
|
|
42
42
|
* path to the application component in the workspace
|
|
43
43
|
*/
|
|
44
|
-
readonly workspaceComponentPath?: string
|
|
44
|
+
readonly workspaceComponentPath?: string;
|
|
45
45
|
/**
|
|
46
46
|
* list of env variables to include.
|
|
47
47
|
*/
|
|
@@ -77,15 +77,15 @@ export declare class AppContext extends ExecutionContext {
|
|
|
77
77
|
* This can be used in different bundle options which run require.resolve
|
|
78
78
|
* for example when configuring webpack aliases or webpack expose loader on the peers deps
|
|
79
79
|
*/
|
|
80
|
-
hostRootDir?: string
|
|
80
|
+
hostRootDir?: string,
|
|
81
81
|
/**
|
|
82
82
|
* A port to run the app on
|
|
83
83
|
*/
|
|
84
|
-
port?: number
|
|
84
|
+
port?: number,
|
|
85
85
|
/**
|
|
86
86
|
* path to the application component in the workspace
|
|
87
87
|
*/
|
|
88
|
-
workspaceComponentPath?: string
|
|
88
|
+
workspaceComponentPath?: string,
|
|
89
89
|
/**
|
|
90
90
|
* list of env variables to include.
|
|
91
91
|
*/
|
package/dist/app-context.js
CHANGED
|
@@ -94,7 +94,7 @@ class AppContext extends _envs().ExecutionContext {
|
|
|
94
94
|
return this.harmony.get(aspectId);
|
|
95
95
|
}
|
|
96
96
|
static compose(appContext, overrides) {
|
|
97
|
-
return new AppContext(
|
|
97
|
+
return new AppContext(overrides?.appName || appContext?.appName, overrides?.harmony || appContext?.harmony, overrides?.dev || appContext?.dev, overrides?.appComponent || appContext?.appComponent, overrides?.workdir || appContext?.workdir, overrides?.execContext || appContext?.execContext, overrides?.hostRootDir || appContext?.hostRootDir, overrides?.port || appContext?.port, overrides?.workspaceComponentPath || appContext?.workspaceComponentPath, overrides?.envVariables || appContext?.envVariables);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
exports.AppContext = AppContext;
|
package/dist/app-context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_envs","data","require","_logger","AppContext","ExecutionContext","constructor","appName","harmony","dev","appComponent","workdir","execContext","hostRootDir","port","workspaceComponentPath","envVariables","upper","envRuntime","components","createLogger","name","loggerMain","get","LoggerAspect","id","appComponentId","loggerName","toString","getAspect","aspectId","compose","appContext","overrides","exports"],"sources":["app-context.ts"],"sourcesContent":["import { ExecutionContext } from '@teambit/envs';\nimport { Harmony } from '@teambit/harmony';\nimport { Component } from '@teambit/component';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\n\nexport class AppContext extends ExecutionContext {\n constructor(\n /**\n * name of the app\n */\n readonly appName: string,\n\n /**\n * instance of harmony.\n */\n readonly harmony: Harmony,\n\n /**\n * determine whether to serve the application in dev mode.\n */\n readonly dev: boolean,\n\n /**\n * application component instance.\n */\n readonly appComponent: Component,\n\n /**\n * working directory of the component.\n */\n readonly workdir: string,\n\n /**\n * execution context of the app.\n */\n readonly execContext: ExecutionContext,\n\n /**\n * A path for the host root dir\n * Host root dir is the dir where we run the app from\n * This can be used in different bundle options which run require.resolve\n * for example when configuring webpack aliases or webpack expose loader on the peers deps\n */\n readonly hostRootDir?: string,\n\n /**\n * A port to run the app on\n */\n readonly port?: number,\n\n /**\n * path to the application component in the workspace\n */\n readonly workspaceComponentPath?: string,\n\n /**\n * list of env variables to include.\n */\n readonly envVariables: Record<string, string> = {}\n ) {\n super(execContext.upper, execContext.envRuntime, execContext.components);\n }\n\n /**\n * return a logger instance for the env.\n */\n createLogger(name?: string): Logger {\n const loggerMain = this.harmony.get<LoggerMain>(LoggerAspect.id);\n const appComponentId = this.appComponent.id;\n const loggerName = name ? `${appComponentId.toString()}::${name}` : appComponentId.toString();\n\n return loggerMain.createLogger(loggerName);\n }\n\n /**\n * get an instance of an aspect.\n * make sure it is loaded prior to requesting it.\n */\n getAspect<T>(aspectId: string): T | undefined {\n return this.harmony.get<T>(aspectId);\n }\n\n static compose(appContext: AppContext, overrides?: Partial<AppContext>) {\n return new AppContext(\n overrides?.appName || appContext?.appName,\n overrides?.harmony || appContext?.harmony,\n overrides?.dev || appContext?.dev,\n overrides?.appComponent || appContext?.appComponent,\n overrides?.workdir || appContext?.workdir,\n overrides?.execContext || appContext?.execContext,\n overrides?.hostRootDir || appContext?.hostRootDir,\n overrides?.port || appContext?.port,\n overrides?.workspaceComponentPath || appContext?.workspaceComponentPath,\n overrides?.envVariables || appContext?.envVariables\n );\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,MAAMG,UAAU,SAASC,wBAAgB,CAAC;EAC/CC,WAAWA;EACT;AACJ;AACA;EACaC,OAAe;EAExB;AACJ;AACA;EACaC,OAAgB;EAEzB;AACJ;AACA;EACaC,GAAY;EAErB;AACJ;AACA;EACaC,YAAuB;EAEhC;AACJ;AACA;EACaC,OAAe;EAExB;AACJ;AACA;EACaC,WAA6B;EAEtC;AACJ;AACA;AACA;A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ExecutionContext","constructor","appName","harmony","dev","appComponent","workdir","execContext","hostRootDir","port","workspaceComponentPath","envVariables","upper","envRuntime","components","createLogger","name","loggerMain","get","LoggerAspect","id","appComponentId","loggerName","toString","getAspect","aspectId","compose","appContext","overrides","exports"],"sources":["app-context.ts"],"sourcesContent":["import { ExecutionContext } from '@teambit/envs';\nimport { Harmony } from '@teambit/harmony';\nimport { Component } from '@teambit/component';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\n\nexport class AppContext extends ExecutionContext {\n constructor(\n /**\n * name of the app\n */\n readonly appName: string,\n\n /**\n * instance of harmony.\n */\n readonly harmony: Harmony,\n\n /**\n * determine whether to serve the application in dev mode.\n */\n readonly dev: boolean,\n\n /**\n * application component instance.\n */\n readonly appComponent: Component,\n\n /**\n * working directory of the component.\n */\n readonly workdir: string,\n\n /**\n * execution context of the app.\n */\n readonly execContext: ExecutionContext,\n\n /**\n * A path for the host root dir\n * Host root dir is the dir where we run the app from\n * This can be used in different bundle options which run require.resolve\n * for example when configuring webpack aliases or webpack expose loader on the peers deps\n */\n readonly hostRootDir?: string,\n\n /**\n * A port to run the app on\n */\n readonly port?: number,\n\n /**\n * path to the application component in the workspace\n */\n readonly workspaceComponentPath?: string,\n\n /**\n * list of env variables to include.\n */\n readonly envVariables: Record<string, string> = {}\n ) {\n super(execContext.upper, execContext.envRuntime, execContext.components);\n }\n\n /**\n * return a logger instance for the env.\n */\n createLogger(name?: string): Logger {\n const loggerMain = this.harmony.get<LoggerMain>(LoggerAspect.id);\n const appComponentId = this.appComponent.id;\n const loggerName = name ? `${appComponentId.toString()}::${name}` : appComponentId.toString();\n\n return loggerMain.createLogger(loggerName);\n }\n\n /**\n * get an instance of an aspect.\n * make sure it is loaded prior to requesting it.\n */\n getAspect<T>(aspectId: string): T | undefined {\n return this.harmony.get<T>(aspectId);\n }\n\n static compose(appContext: AppContext, overrides?: Partial<AppContext>) {\n return new AppContext(\n overrides?.appName || appContext?.appName,\n overrides?.harmony || appContext?.harmony,\n overrides?.dev || appContext?.dev,\n overrides?.appComponent || appContext?.appComponent,\n overrides?.workdir || appContext?.workdir,\n overrides?.execContext || appContext?.execContext,\n overrides?.hostRootDir || appContext?.hostRootDir,\n overrides?.port || appContext?.port,\n overrides?.workspaceComponentPath || appContext?.workspaceComponentPath,\n overrides?.envVariables || appContext?.envVariables\n );\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,MAAMG,UAAU,SAASC,wBAAgB,CAAC;EAC/CC,WAAWA;EACT;AACJ;AACA;EACaC,OAAe;EAExB;AACJ;AACA;EACaC,OAAgB;EAEzB;AACJ;AACA;EACaC,GAAY;EAErB;AACJ;AACA;EACaC,YAAuB;EAEhC;AACJ;AACA;EACaC,OAAe;EAExB;AACJ;AACA;EACaC,WAA6B;EAEtC;AACJ;AACA;AACA;AACA;AACA;EACaC,WAAoB;EAE7B;AACJ;AACA;EACaC,IAAa;EAEtB;AACJ;AACA;EACaC,sBAA+B;EAExC;AACJ;AACA;EACaC,YAAoC,GAAG,CAAC,CAAC,EAClD;IACA,KAAK,CAACJ,WAAW,CAACK,KAAK,EAAEL,WAAW,CAACM,UAAU,EAAEN,WAAW,CAACO,UAAU,CAAC;IAAC,KAlDhEZ,OAAe,GAAfA,OAAe;IAAA,KAKfC,OAAgB,GAAhBA,OAAgB;IAAA,KAKhBC,GAAY,GAAZA,GAAY;IAAA,KAKZC,YAAuB,GAAvBA,YAAuB;IAAA,KAKvBC,OAAe,GAAfA,OAAe;IAAA,KAKfC,WAA6B,GAA7BA,WAA6B;IAAA,KAQ7BC,WAAoB,GA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B,EACvEkB,SAAS,EAAEjB,YAAY,IAAIgB,UAAU,EAAEhB,YACzC,CAAC;EACH;AACF;AAACkB,OAAA,CAAA9B,UAAA,GAAAA,UAAA"}
|
|
@@ -8,11 +8,11 @@ export declare class AppDeployContext extends AppBuildContext {
|
|
|
8
8
|
/**
|
|
9
9
|
* public dir generated by the build.
|
|
10
10
|
*/
|
|
11
|
-
readonly publicDir?: string
|
|
11
|
+
readonly publicDir?: string;
|
|
12
12
|
/**
|
|
13
13
|
* ssr dir generated by the build.
|
|
14
14
|
*/
|
|
15
|
-
readonly ssrPublicDir?: string
|
|
15
|
+
readonly ssrPublicDir?: string;
|
|
16
16
|
constructor(
|
|
17
17
|
/**
|
|
18
18
|
* app build context.
|
|
@@ -25,9 +25,9 @@ export declare class AppDeployContext extends AppBuildContext {
|
|
|
25
25
|
/**
|
|
26
26
|
* public dir generated by the build.
|
|
27
27
|
*/
|
|
28
|
-
publicDir?: string
|
|
28
|
+
publicDir?: string,
|
|
29
29
|
/**
|
|
30
30
|
* ssr dir generated by the build.
|
|
31
31
|
*/
|
|
32
|
-
ssrPublicDir?: string
|
|
32
|
+
ssrPublicDir?: string);
|
|
33
33
|
}
|
package/dist/app-instance.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type ApplicationInstance = {
|
|
2
2
|
/**
|
|
3
3
|
* port in which app is running.
|
|
4
4
|
*/
|
|
@@ -15,7 +15,7 @@ export declare type ApplicationInstance = {
|
|
|
15
15
|
/**
|
|
16
16
|
* an instance of an application deployment.
|
|
17
17
|
*/
|
|
18
|
-
export
|
|
18
|
+
export type ApplicationDeployment = {
|
|
19
19
|
/**
|
|
20
20
|
* timestamp of the deployment.
|
|
21
21
|
*/
|
package/dist/app-type-list.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const Logo: () =>
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const Logo: () => JSX.Element;
|
package/dist/application.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { AppDeployContext } from './app-deploy-context';
|
|
|
3
3
|
import { AppBuildContext } from './app-build-context';
|
|
4
4
|
import { AppBuildResult } from './app-build-result';
|
|
5
5
|
import { ApplicationDeployment, ApplicationInstance } from './app-instance';
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
6
|
+
export type DeployFn = (context: AppDeployContext) => Promise<ApplicationDeployment | void | undefined>;
|
|
7
|
+
export type BuildFn = (context: AppBuildContext) => Promise<AppBuildResult>;
|
|
8
|
+
export type AppResult = {
|
|
9
9
|
port?: number;
|
|
10
10
|
errors?: Error[];
|
|
11
11
|
};
|
|
@@ -13,10 +13,10 @@ import { Application } from './application';
|
|
|
13
13
|
import { DeploymentProvider } from './deployment-provider';
|
|
14
14
|
import { AppService } from './application.service';
|
|
15
15
|
import { AppContext } from './app-context';
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
16
|
+
export type ApplicationTypeSlot = SlotRegistry<ApplicationType<unknown>[]>;
|
|
17
|
+
export type ApplicationSlot = SlotRegistry<Application[]>;
|
|
18
|
+
export type DeploymentProviderSlot = SlotRegistry<DeploymentProvider[]>;
|
|
19
|
+
export type ApplicationAspectConfig = {
|
|
20
20
|
/**
|
|
21
21
|
* envs ids to load app types.
|
|
22
22
|
*/
|
|
@@ -25,11 +25,11 @@ export declare type ApplicationAspectConfig = {
|
|
|
25
25
|
/**
|
|
26
26
|
* Application meta data that is stored on the component on load if it's an application.
|
|
27
27
|
*/
|
|
28
|
-
export
|
|
28
|
+
export type ApplicationMetadata = {
|
|
29
29
|
appName: string;
|
|
30
30
|
type?: string;
|
|
31
31
|
};
|
|
32
|
-
export
|
|
32
|
+
export type ServeAppOptions = {
|
|
33
33
|
/**
|
|
34
34
|
* default port range used to serve applications.
|
|
35
35
|
*/
|
|
@@ -86,12 +86,12 @@ export declare class ApplicationMain {
|
|
|
86
86
|
/**
|
|
87
87
|
* get an application by a component id.
|
|
88
88
|
*/
|
|
89
|
-
getAppById(id: ComponentID): Promise<Application
|
|
89
|
+
getAppById(id: ComponentID): Promise<Application>;
|
|
90
90
|
/**
|
|
91
91
|
* calculate an application by a component.
|
|
92
92
|
* This should be only used during the on component load slot
|
|
93
93
|
*/
|
|
94
|
-
calculateAppByComponent(component: Component): Application
|
|
94
|
+
calculateAppByComponent(component: Component): Application;
|
|
95
95
|
listAppTypes(): ApplicationType<unknown>[];
|
|
96
96
|
/**
|
|
97
97
|
* @deprecated use `listAppsComponents` instead.
|
|
@@ -126,8 +126,8 @@ export declare class ApplicationMain {
|
|
|
126
126
|
loadAppsToSlot(): Promise<this>;
|
|
127
127
|
runApp(appName: string, options?: ServeAppOptions): Promise<{
|
|
128
128
|
app: Application;
|
|
129
|
-
port: number
|
|
130
|
-
errors:
|
|
129
|
+
port: number;
|
|
130
|
+
errors: any;
|
|
131
131
|
isOldApi: boolean;
|
|
132
132
|
}>;
|
|
133
133
|
/**
|
|
@@ -288,14 +288,13 @@ class ApplicationMain {
|
|
|
288
288
|
// const app = require(appPath);
|
|
289
289
|
const appManifests = Promise.all((0, _lodash().compact)(pluginsToLoad.map(async pluginPath => {
|
|
290
290
|
try {
|
|
291
|
-
var _require;
|
|
292
291
|
const isModule = await this.aspectLoader.isEsmModule(pluginPath);
|
|
293
292
|
if (isModule) {
|
|
294
293
|
const appManifest = await this.aspectLoader.loadEsm(pluginPath);
|
|
295
294
|
return appManifest;
|
|
296
295
|
}
|
|
297
296
|
// eslint-disable-next-line
|
|
298
|
-
const appManifest =
|
|
297
|
+
const appManifest = require(pluginPath)?.default;
|
|
299
298
|
return appManifest;
|
|
300
299
|
} catch (err) {
|
|
301
300
|
this.logger.error(`failed loading app manifest: ${pluginPath}`);
|
|
@@ -365,8 +364,7 @@ class ApplicationMain {
|
|
|
365
364
|
* get an app AspectId.
|
|
366
365
|
*/
|
|
367
366
|
getAppAspect(appName) {
|
|
368
|
-
|
|
369
|
-
return (_this$appSlot$toArray = this.appSlot.toArray().find(([, apps]) => apps.find(app => app.name === appName))) === null || _this$appSlot$toArray === void 0 ? void 0 : _this$appSlot$toArray[0];
|
|
367
|
+
return this.appSlot.toArray().find(([, apps]) => apps.find(app => app.name === appName))?.[0];
|
|
370
368
|
}
|
|
371
369
|
|
|
372
370
|
/**
|
|
@@ -401,7 +399,7 @@ class ApplicationMain {
|
|
|
401
399
|
});
|
|
402
400
|
}
|
|
403
401
|
const isOldApi = typeof instance === 'number';
|
|
404
|
-
const port = isOldApi ? instance : instance
|
|
402
|
+
const port = isOldApi ? instance : instance?.port;
|
|
405
403
|
return {
|
|
406
404
|
app,
|
|
407
405
|
port,
|