@teambit/bundler 1.0.587 → 1.0.588
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/bundler.main.runtime.d.ts +33 -9
- package/dist/bundler.main.runtime.js +47 -24
- package/dist/bundler.main.runtime.js.map +1 -1
- package/dist/component-server.d.ts +8 -1
- package/dist/component-server.js +43 -5
- package/dist/component-server.js.map +1 -1
- package/dist/dev-server.graphql.d.ts +2 -2
- package/dist/dev-server.graphql.js +39 -5
- package/dist/dev-server.graphql.js.map +1 -1
- package/dist/events/components-server-started-event.d.ts +23 -11
- package/dist/events/components-server-started-event.js +13 -1
- package/dist/events/components-server-started-event.js.map +1 -1
- package/dist/{preview-1744168729194.js → preview-1744255142791.js} +2 -2
- package/events/components-server-started-event.ts +34 -9
- package/package.json +9 -9
@@ -12,8 +12,10 @@ import { DevServer } from './dev-server';
|
|
12
12
|
export type DevServerTransformer = (devServer: DevServer, { envId }: {
|
13
13
|
envId: string;
|
14
14
|
}) => DevServer;
|
15
|
+
export type OnPreDevServerCreated = (newCompsWithoutDevServer: Component[]) => Promise<void>;
|
15
16
|
export type BrowserRuntimeSlot = SlotRegistry<BrowserRuntime>;
|
16
17
|
export type DevServerTransformerSlot = SlotRegistry<DevServerTransformer>;
|
18
|
+
export type OnPreDevServerCreatedSlot = SlotRegistry<OnPreDevServerCreated>;
|
17
19
|
export type BundlerConfig = {
|
18
20
|
dedicatedEnvDevServers: string[];
|
19
21
|
};
|
@@ -42,6 +44,15 @@ export declare class BundlerMain {
|
|
42
44
|
* dev server transformer slot.
|
43
45
|
*/
|
44
46
|
private devServerTransformerSlot;
|
47
|
+
/**
|
48
|
+
* pre-dev-server operation slot.
|
49
|
+
*/
|
50
|
+
private onPreDevServerCreatedSlot;
|
51
|
+
private graphql;
|
52
|
+
/**
|
53
|
+
* component servers.
|
54
|
+
*/
|
55
|
+
private _componentServers;
|
45
56
|
constructor(config: BundlerConfig,
|
46
57
|
/**
|
47
58
|
* Pubsub extension.
|
@@ -62,12 +73,15 @@ export declare class BundlerMain {
|
|
62
73
|
/**
|
63
74
|
* dev server transformer slot.
|
64
75
|
*/
|
65
|
-
devServerTransformerSlot: DevServerTransformerSlot
|
76
|
+
devServerTransformerSlot: DevServerTransformerSlot,
|
66
77
|
/**
|
67
|
-
*
|
68
|
-
* @param components defaults to all components in the workspace.
|
78
|
+
* pre-dev-server operation slot.
|
69
79
|
*/
|
70
|
-
|
80
|
+
onPreDevServerCreatedSlot: OnPreDevServerCreatedSlot, graphql: GraphqlMain);
|
81
|
+
addNewDevServers(newCompsWithoutDevServers: Component[]): Promise<ComponentServer[]>;
|
82
|
+
devServer(components: Component[], opts?: {
|
83
|
+
configureProxy?: boolean;
|
84
|
+
}): Promise<ComponentServer[]>;
|
71
85
|
/**
|
72
86
|
* get a dev server instance containing a component.
|
73
87
|
* @param component
|
@@ -75,7 +89,7 @@ export declare class BundlerMain {
|
|
75
89
|
getComponentServer(component: Component): undefined | ComponentServer;
|
76
90
|
/**
|
77
91
|
* compute entry files for bundling components in a given execution context.
|
78
|
-
|
92
|
+
*/
|
79
93
|
computeEntries(context: BundlerContext): Promise<string[]>;
|
80
94
|
/**
|
81
95
|
* register a new browser runtime environment.
|
@@ -88,15 +102,25 @@ export declare class BundlerMain {
|
|
88
102
|
*/
|
89
103
|
registerDevServerTransformer(devServerTransformer: DevServerTransformer): this;
|
90
104
|
/**
|
91
|
-
*
|
105
|
+
* register a new pre-dev-server compiler.
|
106
|
+
* @param onPreDevServerCreated
|
92
107
|
*/
|
93
|
-
|
108
|
+
registerOnPreDevServerCreated(onPreDevServerCreated: OnPreDevServerCreated): this;
|
94
109
|
private indexByComponent;
|
95
|
-
static slots: (((registerFn: () => string) => SlotRegistry<BrowserRuntime>) | ((registerFn: () => string) => SlotRegistry<DevServerTransformerSlot>))[];
|
110
|
+
static slots: (((registerFn: () => string) => SlotRegistry<BrowserRuntime>) | ((registerFn: () => string) => SlotRegistry<DevServerTransformerSlot>) | ((registerFn: () => string) => SlotRegistry<OnPreDevServerCreatedSlot>))[];
|
96
111
|
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
97
112
|
static dependencies: import("@teambit/harmony").Aspect[];
|
98
113
|
static defaultConfig: {
|
99
114
|
dedicatedEnvDevServers: never[];
|
100
115
|
};
|
101
|
-
static provider([pubsub, envs, graphql, dependencyResolver]: [
|
116
|
+
static provider([pubsub, envs, graphql, dependencyResolver]: [
|
117
|
+
PubsubMain,
|
118
|
+
EnvsMain,
|
119
|
+
GraphqlMain,
|
120
|
+
DependencyResolverMain
|
121
|
+
], config: any, [runtimeSlot, devServerTransformerSlot, onPreDevServerCreatedSlot]: [
|
122
|
+
BrowserRuntimeSlot,
|
123
|
+
DevServerTransformerSlot,
|
124
|
+
OnPreDevServerCreatedSlot
|
125
|
+
]): Promise<BundlerMain>;
|
102
126
|
}
|
@@ -18,13 +18,6 @@ function _cli() {
|
|
18
18
|
};
|
19
19
|
return data;
|
20
20
|
}
|
21
|
-
function _component() {
|
22
|
-
const data = require("@teambit/component");
|
23
|
-
_component = function () {
|
24
|
-
return data;
|
25
|
-
};
|
26
|
-
return data;
|
27
|
-
}
|
28
21
|
function _dependencyResolver() {
|
29
22
|
const data = require("@teambit/dependency-resolver");
|
30
23
|
_dependencyResolver = function () {
|
@@ -60,6 +53,13 @@ function _bundler() {
|
|
60
53
|
};
|
61
54
|
return data;
|
62
55
|
}
|
56
|
+
function _events() {
|
57
|
+
const data = require("./events");
|
58
|
+
_events = function () {
|
59
|
+
return data;
|
60
|
+
};
|
61
|
+
return data;
|
62
|
+
}
|
63
63
|
function _devServer() {
|
64
64
|
const data = require("./dev-server.graphql");
|
65
65
|
_devServer = function () {
|
@@ -108,33 +108,47 @@ class BundlerMain {
|
|
108
108
|
/**
|
109
109
|
* dev server transformer slot.
|
110
110
|
*/
|
111
|
-
devServerTransformerSlot
|
111
|
+
devServerTransformerSlot,
|
112
|
+
/**
|
113
|
+
* pre-dev-server operation slot.
|
114
|
+
*/
|
115
|
+
onPreDevServerCreatedSlot, graphql) {
|
112
116
|
this.config = config;
|
113
117
|
this.pubsub = pubsub;
|
114
118
|
this.envs = envs;
|
115
119
|
this.devService = devService;
|
116
120
|
this.runtimeSlot = runtimeSlot;
|
117
121
|
this.devServerTransformerSlot = devServerTransformerSlot;
|
122
|
+
this.onPreDevServerCreatedSlot = onPreDevServerCreatedSlot;
|
123
|
+
this.graphql = graphql;
|
118
124
|
/**
|
119
125
|
* component servers.
|
120
126
|
*/
|
121
|
-
_defineProperty(this, "_componentServers",
|
127
|
+
_defineProperty(this, "_componentServers", []);
|
122
128
|
}
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
+
async addNewDevServers(newCompsWithoutDevServers) {
|
130
|
+
const newComponents = newCompsWithoutDevServers.filter(component => {
|
131
|
+
return !this.getComponentServer(component);
|
132
|
+
});
|
133
|
+
if (newComponents.length === 0) {
|
134
|
+
return [];
|
135
|
+
}
|
136
|
+
await Promise.all(this.onPreDevServerCreatedSlot.values().map(subscriberFn => subscriberFn(newComponents)));
|
137
|
+
return this.devServer(newComponents, {
|
138
|
+
configureProxy: true
|
139
|
+
});
|
140
|
+
}
|
141
|
+
async devServer(components, opts = {}) {
|
129
142
|
const envRuntime = await this.envs.createEnvironment(components);
|
130
|
-
// TODO: this must be refactored away from here. this logic should be in the Preview.
|
131
|
-
// @ts-ignore
|
132
143
|
const servers = await envRuntime.runOnce(this.devService, {
|
133
144
|
dedicatedEnvDevServers: this.config.dedicatedEnvDevServers
|
134
145
|
});
|
146
|
+
if (opts.configureProxy) {
|
147
|
+
this.pubsub.pub(_bundler().BundlerAspect.id, new (_events().NewDevServersCreatedEvent)(servers, Date.now(), this.graphql, true));
|
148
|
+
}
|
135
149
|
this._componentServers = servers;
|
136
150
|
this.indexByComponent();
|
137
|
-
return
|
151
|
+
return servers;
|
138
152
|
}
|
139
153
|
|
140
154
|
/**
|
@@ -150,7 +164,7 @@ class BundlerMain {
|
|
150
164
|
|
151
165
|
/**
|
152
166
|
* compute entry files for bundling components in a given execution context.
|
153
|
-
|
167
|
+
*/
|
154
168
|
async computeEntries(context) {
|
155
169
|
const slotEntries = await Promise.all(this.runtimeSlot.values().map(async browserRuntime => browserRuntime.entry(context)));
|
156
170
|
const slotPaths = slotEntries.reduce((acc, current) => {
|
@@ -179,19 +193,28 @@ class BundlerMain {
|
|
179
193
|
this.devServerTransformerSlot.register(devServerTransformer);
|
180
194
|
return this;
|
181
195
|
}
|
196
|
+
|
197
|
+
/**
|
198
|
+
* register a new pre-dev-server compiler.
|
199
|
+
* @param onPreDevServerCreated
|
200
|
+
*/
|
201
|
+
registerOnPreDevServerCreated(onPreDevServerCreated) {
|
202
|
+
this.onPreDevServerCreatedSlot.register(onPreDevServerCreated);
|
203
|
+
return this;
|
204
|
+
}
|
182
205
|
indexByComponent() {}
|
183
|
-
static async provider([pubsub, envs, graphql, dependencyResolver], config, [runtimeSlot, devServerTransformerSlot]) {
|
206
|
+
static async provider([pubsub, envs, graphql, dependencyResolver], config, [runtimeSlot, devServerTransformerSlot, onPreDevServerCreatedSlot]) {
|
184
207
|
const devServerService = new (_devServer2().DevServerService)(pubsub, dependencyResolver, runtimeSlot, devServerTransformerSlot);
|
185
|
-
const bundler = new BundlerMain(config, pubsub, envs, devServerService, runtimeSlot, devServerTransformerSlot);
|
208
|
+
const bundler = new BundlerMain(config, pubsub, envs, devServerService, runtimeSlot, devServerTransformerSlot, onPreDevServerCreatedSlot, graphql);
|
186
209
|
envs.registerService(devServerService, new (_bundler2().BundlerService)());
|
187
|
-
graphql.register(() => (0, _devServer().devServerSchema)(bundler));
|
210
|
+
graphql.register(() => (0, _devServer().devServerSchema)(bundler, graphql));
|
188
211
|
return bundler;
|
189
212
|
}
|
190
213
|
}
|
191
214
|
exports.BundlerMain = BundlerMain;
|
192
|
-
_defineProperty(BundlerMain, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType()]);
|
215
|
+
_defineProperty(BundlerMain, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType()]);
|
193
216
|
_defineProperty(BundlerMain, "runtime", _cli().MainRuntime);
|
194
|
-
_defineProperty(BundlerMain, "dependencies", [_pubsub().PubsubAspect, _envs().EnvsAspect, _graphql().GraphqlAspect, _dependencyResolver().DependencyResolverAspect
|
217
|
+
_defineProperty(BundlerMain, "dependencies", [_pubsub().PubsubAspect, _envs().EnvsAspect, _graphql().GraphqlAspect, _dependencyResolver().DependencyResolverAspect]);
|
195
218
|
_defineProperty(BundlerMain, "defaultConfig", {
|
196
219
|
dedicatedEnvDevServers: []
|
197
220
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_pubsub","data","require","_cli","_component","_dependencyResolver","_envs","_graphql","_harmony","_bundler","_devServer","_devServer2","_bundler2","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","BundlerMain","constructor","config","pubsub","envs","devService","runtimeSlot","devServerTransformerSlot","devServer","components","envRuntime","createEnvironment","servers","runOnce","dedicatedEnvDevServers","_componentServers","indexByComponent","getComponentServer","component","undefined","envId","getEnvId","server","find","componentServer","context","relatedContexts","includes","id","computeEntries","slotEntries","Promise","all","values","map","browserRuntime","entry","slotPaths","reduce","acc","current","concat","registerTarget","runtime","register","registerDevServerTransformer","devServerTransformer","provider","graphql","dependencyResolver","devServerService","DevServerService","bundler","registerService","BundlerService","devServerSchema","exports","Slot","withType","MainRuntime","PubsubAspect","EnvsAspect","GraphqlAspect","DependencyResolverAspect","ComponentAspect","BundlerAspect","addRuntime"],"sources":["bundler.main.runtime.ts"],"sourcesContent":["import { PubsubAspect, PubsubMain } from '@teambit/pubsub';\nimport { MainRuntime } from '@teambit/cli';\nimport { Component, ComponentAspect } from '@teambit/component';\nimport { DependencyResolverAspect, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { BrowserRuntime } from './browser-runtime';\nimport { BundlerAspect } from './bundler.aspect';\nimport { ComponentServer } from './component-server';\nimport { BundlerContext } from './bundler-context';\nimport { devServerSchema } from './dev-server.graphql';\nimport { DevServerService } from './dev-server.service';\nimport { BundlerService } from './bundler.service';\nimport { DevServer } from './dev-server';\n\nexport type DevServerTransformer = (devServer: DevServer, { envId }: { envId: string }) => DevServer;\n\nexport type BrowserRuntimeSlot = SlotRegistry<BrowserRuntime>;\nexport type DevServerTransformerSlot = SlotRegistry<DevServerTransformer>;\n\nexport type BundlerConfig = {\n dedicatedEnvDevServers: string[];\n};\n\n/**\n * bundler extension.\n */\nexport class BundlerMain {\n constructor(\n readonly config: BundlerConfig,\n /**\n * Pubsub extension.\n */\n private pubsub: PubsubMain,\n\n /**\n * environments extension.\n */\n private envs: EnvsMain,\n\n /**\n * dev server service.\n */\n private devService: DevServerService,\n\n /**\n * browser runtime slot.\n */\n private runtimeSlot: BrowserRuntimeSlot,\n\n /**\n * dev server transformer slot.\n */\n private devServerTransformerSlot: DevServerTransformerSlot\n ) {}\n\n /**\n * load all given components in corresponding dev servers.\n * @param components defaults to all components in the workspace.\n */\n async devServer(components: Component[]): Promise<ComponentServer[]> {\n const envRuntime = await this.envs.createEnvironment(components);\n // TODO: this must be refactored away from here. this logic should be in the Preview.\n // @ts-ignore\n const servers: ComponentServer[] = await envRuntime.runOnce<ComponentServer[]>(this.devService, {\n dedicatedEnvDevServers: this.config.dedicatedEnvDevServers,\n });\n this._componentServers = servers;\n\n this.indexByComponent();\n\n return this._componentServers;\n }\n\n /**\n * get a dev server instance containing a component.\n * @param component\n */\n getComponentServer(component: Component): undefined | ComponentServer {\n if (!this._componentServers) return undefined;\n const envId = this.envs.getEnvId(component);\n const server = this._componentServers.find(\n (componentServer) =>\n componentServer.context.relatedContexts.includes(envId) || componentServer.context.id === envId\n );\n\n return server;\n }\n\n /**\n * compute entry files for bundling components in a given execution context.\n */\n async computeEntries(context: BundlerContext) {\n const slotEntries = await Promise.all(\n this.runtimeSlot.values().map(async (browserRuntime) => browserRuntime.entry(context))\n );\n\n const slotPaths = slotEntries.reduce((acc, current) => {\n acc = acc.concat(current);\n return acc;\n });\n\n return slotPaths;\n }\n\n /**\n * register a new browser runtime environment.\n * @param browserRuntime\n */\n registerTarget(browserRuntime: BrowserRuntime[]) {\n browserRuntime.map((runtime) => {\n return this.runtimeSlot.register(runtime);\n });\n\n return this;\n }\n\n /**\n * register a new dev server transformer.\n * @param devServerTransformer\n */\n registerDevServerTransformer(devServerTransformer: DevServerTransformer) {\n this.devServerTransformerSlot.register(devServerTransformer);\n return this;\n }\n\n /**\n * component servers.\n */\n private _componentServers: null | ComponentServer[];\n\n private indexByComponent() {}\n\n static slots = [Slot.withType<BrowserRuntime>(), Slot.withType<DevServerTransformerSlot>()];\n\n static runtime = MainRuntime;\n static dependencies = [PubsubAspect, EnvsAspect, GraphqlAspect, DependencyResolverAspect, ComponentAspect];\n\n static defaultConfig = {\n dedicatedEnvDevServers: [],\n };\n\n static async provider(\n [pubsub, envs, graphql, dependencyResolver]: [PubsubMain, EnvsMain, GraphqlMain, DependencyResolverMain],\n config,\n [runtimeSlot, devServerTransformerSlot]: [BrowserRuntimeSlot, DevServerTransformerSlot]\n ) {\n const devServerService = new DevServerService(pubsub, dependencyResolver, runtimeSlot, devServerTransformerSlot);\n const bundler = new BundlerMain(config, pubsub, envs, devServerService, runtimeSlot, devServerTransformerSlot);\n envs.registerService(devServerService, new BundlerService());\n\n graphql.register(() => devServerSchema(bundler));\n\n return bundler;\n }\n}\n\nBundlerAspect.addRuntime(BundlerMain);\n"],"mappings":";;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;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aA4GL2D,kBAAW;AAAA9E,eAAA,CA5GjBmB,WAAW,kBA6GA,CAAC4D,sBAAY,EAAEC,kBAAU,EAAEC,wBAAa,EAAEC,8CAAwB,EAAEC,4BAAe,CAAC;AAAAnF,eAAA,CA7G/FmB,WAAW,mBA+GC;EACrBc,sBAAsB,EAAE;AAC1B,CAAC;AAiBHmD,wBAAa,CAACC,UAAU,CAAClE,WAAW,CAAC","ignoreList":[]}
|
1
|
+
{"version":3,"names":["_pubsub","data","require","_cli","_dependencyResolver","_envs","_graphql","_harmony","_bundler","_events","_devServer","_devServer2","_bundler2","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","BundlerMain","constructor","config","pubsub","envs","devService","runtimeSlot","devServerTransformerSlot","onPreDevServerCreatedSlot","graphql","addNewDevServers","newCompsWithoutDevServers","newComponents","filter","component","getComponentServer","length","Promise","all","values","map","subscriberFn","devServer","configureProxy","components","opts","envRuntime","createEnvironment","servers","runOnce","dedicatedEnvDevServers","pub","BundlerAspect","id","NewDevServersCreatedEvent","Date","now","_componentServers","indexByComponent","undefined","envId","getEnvId","server","find","componentServer","context","relatedContexts","includes","computeEntries","slotEntries","browserRuntime","entry","slotPaths","reduce","acc","current","concat","registerTarget","runtime","register","registerDevServerTransformer","devServerTransformer","registerOnPreDevServerCreated","onPreDevServerCreated","provider","dependencyResolver","devServerService","DevServerService","bundler","registerService","BundlerService","devServerSchema","exports","Slot","withType","MainRuntime","PubsubAspect","EnvsAspect","GraphqlAspect","DependencyResolverAspect","addRuntime"],"sources":["bundler.main.runtime.ts"],"sourcesContent":["import { PubsubAspect, PubsubMain } from '@teambit/pubsub';\nimport { MainRuntime } from '@teambit/cli';\nimport { Component } from '@teambit/component';\nimport { DependencyResolverAspect, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { GraphqlAspect, GraphqlMain } from '@teambit/graphql';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { BrowserRuntime } from './browser-runtime';\nimport { BundlerAspect } from './bundler.aspect';\nimport { ComponentServer } from './component-server';\nimport { NewDevServersCreatedEvent } from './events';\nimport { BundlerContext } from './bundler-context';\nimport { devServerSchema } from './dev-server.graphql';\nimport { DevServerService } from './dev-server.service';\nimport { BundlerService } from './bundler.service';\nimport { DevServer } from './dev-server';\n\nexport type DevServerTransformer = (devServer: DevServer, { envId }: { envId: string }) => DevServer;\nexport type OnPreDevServerCreated = (newCompsWithoutDevServer: Component[]) => Promise<void>;\nexport type BrowserRuntimeSlot = SlotRegistry<BrowserRuntime>;\nexport type DevServerTransformerSlot = SlotRegistry<DevServerTransformer>;\nexport type OnPreDevServerCreatedSlot = SlotRegistry<OnPreDevServerCreated>;\n\nexport type BundlerConfig = {\n dedicatedEnvDevServers: string[];\n};\n\n/**\n * bundler extension.\n */\nexport class BundlerMain {\n /**\n * component servers.\n */\n private _componentServers: ComponentServer[] = [];\n\n constructor(\n readonly config: BundlerConfig,\n /**\n * Pubsub extension.\n */\n private pubsub: PubsubMain,\n\n /**\n * environments extension.\n */\n private envs: EnvsMain,\n\n /**\n * dev server service.\n */\n private devService: DevServerService,\n\n /**\n * browser runtime slot.\n */\n private runtimeSlot: BrowserRuntimeSlot,\n\n /**\n * dev server transformer slot.\n */\n private devServerTransformerSlot: DevServerTransformerSlot,\n\n /**\n * pre-dev-server operation slot.\n */\n private onPreDevServerCreatedSlot: OnPreDevServerCreatedSlot,\n\n private graphql: GraphqlMain,\n ) {\n }\n\n async addNewDevServers(newCompsWithoutDevServers: Component[]): Promise<ComponentServer[]> {\n const newComponents = newCompsWithoutDevServers.filter((component) => {\n return !this.getComponentServer(component);\n });\n\n if (newComponents.length === 0) {\n return [];\n }\n\n await Promise.all(\n this.onPreDevServerCreatedSlot.values().map(subscriberFn => subscriberFn(newComponents))\n );\n\n return this.devServer(newComponents, { configureProxy: true });\n }\n\n async devServer(components: Component[], opts: { configureProxy?: boolean } = {}): Promise<ComponentServer[]> {\n const envRuntime = await this.envs.createEnvironment(components);\n const servers: ComponentServer[] = await envRuntime.runOnce<ComponentServer>(this.devService, {\n dedicatedEnvDevServers: this.config.dedicatedEnvDevServers,\n });\n if (opts.configureProxy) {\n this.pubsub.pub(BundlerAspect.id, new NewDevServersCreatedEvent(\n servers,\n Date.now(),\n this.graphql,\n true\n ));\n }\n this._componentServers = servers;\n this.indexByComponent();\n return servers;\n }\n\n /**\n * get a dev server instance containing a component.\n * @param component\n */\n getComponentServer(component: Component): undefined | ComponentServer {\n if (!this._componentServers) return undefined;\n const envId = this.envs.getEnvId(component);\n const server = this._componentServers.find(\n (componentServer) =>\n componentServer.context.relatedContexts.includes(envId) || componentServer.context.id === envId\n );\n return server;\n }\n\n /**\n * compute entry files for bundling components in a given execution context.\n */\n async computeEntries(context: BundlerContext) {\n const slotEntries = await Promise.all(\n this.runtimeSlot.values().map(async (browserRuntime) => browserRuntime.entry(context))\n );\n\n const slotPaths = slotEntries.reduce((acc, current) => {\n acc = acc.concat(current);\n return acc;\n });\n\n return slotPaths;\n }\n\n /**\n * register a new browser runtime environment.\n * @param browserRuntime\n */\n registerTarget(browserRuntime: BrowserRuntime[]) {\n browserRuntime.map((runtime) => {\n return this.runtimeSlot.register(runtime);\n });\n\n return this;\n }\n\n /**\n * register a new dev server transformer.\n * @param devServerTransformer\n */\n registerDevServerTransformer(devServerTransformer: DevServerTransformer) {\n this.devServerTransformerSlot.register(devServerTransformer);\n return this;\n }\n\n /**\n * register a new pre-dev-server compiler.\n * @param onPreDevServerCreated\n */\n registerOnPreDevServerCreated(onPreDevServerCreated: OnPreDevServerCreated) {\n this.onPreDevServerCreatedSlot.register(onPreDevServerCreated);\n return this;\n }\n\n private indexByComponent() { }\n\n static slots = [\n Slot.withType<BrowserRuntime>(),\n Slot.withType<DevServerTransformerSlot>(),\n Slot.withType<OnPreDevServerCreatedSlot>()\n ];\n\n static runtime = MainRuntime;\n static dependencies = [\n PubsubAspect,\n EnvsAspect,\n GraphqlAspect,\n DependencyResolverAspect,\n ];\n\n static defaultConfig = {\n dedicatedEnvDevServers: [],\n };\n\n static async provider(\n [pubsub, envs, graphql, dependencyResolver]:\n [\n PubsubMain,\n EnvsMain,\n GraphqlMain,\n DependencyResolverMain,\n ],\n config,\n [runtimeSlot,\n devServerTransformerSlot,\n onPreDevServerCreatedSlot\n ]: [\n BrowserRuntimeSlot,\n DevServerTransformerSlot,\n OnPreDevServerCreatedSlot\n ]\n ) {\n\n const devServerService = new DevServerService(pubsub, dependencyResolver, runtimeSlot, devServerTransformerSlot);\n const bundler = new BundlerMain(\n config,\n pubsub,\n envs,\n devServerService,\n runtimeSlot,\n devServerTransformerSlot,\n onPreDevServerCreatedSlot,\n graphql,\n );\n envs.registerService(devServerService, new BundlerService());\n graphql.register(() => devServerSchema(bundler, graphql));\n\n return bundler;\n }\n}\n\nBundlerAspect.addRuntime(BundlerMain);"],"mappings":";;;;;;AAAA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,KAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,IAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAG,oBAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,mBAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,MAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,KAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,SAAA;EAAA,MAAAL,IAAA,GAAAC,OAAA;EAAAI,QAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAA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EC,wBAAwB,CAAC;IAChH,MAAM6D,OAAO,GAAG,IAAIpE,WAAW,CAC7BE,MAAM,EACNC,MAAM,EACNC,IAAI,EACJ8D,gBAAgB,EAChB5D,WAAW,EACXC,wBAAwB,EACxBC,yBAAyB,EACzBC,OACF,CAAC;IACDL,IAAI,CAACiE,eAAe,CAACH,gBAAgB,EAAE,KAAII,0BAAc,EAAC,CAAC,CAAC;IAC5D7D,OAAO,CAACkD,QAAQ,CAAC,MAAM,IAAAY,4BAAe,EAACH,OAAO,EAAE3D,OAAO,CAAC,CAAC;IAEzD,OAAO2D,OAAO;EAChB;AACF;AAACI,OAAA,CAAAxE,WAAA,GAAAA,WAAA;AAAAnB,eAAA,CA/LYmB,WAAW,WA0IP,CACbyE,eAAI,CAACC,QAAQ,CAAiB,CAAC,EAC/BD,eAAI,CAACC,QAAQ,CAA2B,CAAC,EACzCD,eAAI,CAACC,QAAQ,CAA4B,CAAC,CAC3C;AAAA7F,eAAA,CA9IUmB,WAAW,aAgJL2E,kBAAW;AAAA9F,eAAA,CAhJjBmB,WAAW,kBAiJA,CACpB4E,sBAAY,EACZC,kBAAU,EACVC,wBAAa,EACbC,8CAAwB,CACzB;AAAAlG,eAAA,CAtJUmB,WAAW,mBAwJC;EACrB8B,sBAAsB,EAAE;AAC1B,CAAC;AAuCHE,wBAAa,CAACgD,UAAU,CAAChF,WAAW,CAAC","ignoreList":[]}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { Component } from '@teambit/component';
|
2
2
|
import { ExecutionContext } from '@teambit/envs';
|
3
3
|
import { PubsubMain } from '@teambit/pubsub';
|
4
|
+
import { Server } from 'http';
|
4
5
|
import { DevServer } from './dev-server';
|
5
6
|
export declare class ComponentServer {
|
6
7
|
/**
|
@@ -38,13 +39,19 @@ export declare class ComponentServer {
|
|
38
39
|
*/
|
39
40
|
devServer: DevServer);
|
40
41
|
hostname: string | undefined;
|
42
|
+
private _server?;
|
43
|
+
private _isRestarting;
|
44
|
+
get server(): Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | undefined;
|
45
|
+
get envId(): string;
|
41
46
|
/**
|
42
47
|
* determine whether component server contains a component.
|
43
48
|
*/
|
44
49
|
hasComponent(component: Component): Component | undefined;
|
45
50
|
get port(): number;
|
46
51
|
_port: number;
|
47
|
-
listen(): Promise<void>;
|
52
|
+
listen(specificPort?: number): Promise<void>;
|
53
|
+
close(): Promise<void>;
|
54
|
+
restart(useNewPort?: boolean): Promise<void>;
|
48
55
|
private getHostname;
|
49
56
|
private onChange;
|
50
57
|
private createComponentsServerStartedEvent;
|
package/dist/component-server.js
CHANGED
@@ -60,11 +60,19 @@ class ComponentServer {
|
|
60
60
|
// why is this here
|
61
61
|
_defineProperty(this, "errors", void 0);
|
62
62
|
_defineProperty(this, "hostname", void 0);
|
63
|
+
_defineProperty(this, "_server", void 0);
|
64
|
+
_defineProperty(this, "_isRestarting", false);
|
63
65
|
_defineProperty(this, "_port", void 0);
|
64
66
|
_defineProperty(this, "createComponentsServerStartedEvent", (componentsServer, context, hostname, port) => {
|
65
67
|
return new (_events().ComponentsServerStartedEvent)(Date.now(), componentsServer, context, hostname, port);
|
66
68
|
});
|
67
69
|
}
|
70
|
+
get server() {
|
71
|
+
return this._server;
|
72
|
+
}
|
73
|
+
get envId() {
|
74
|
+
return this.context.envRuntime.id;
|
75
|
+
}
|
68
76
|
/**
|
69
77
|
* determine whether component server contains a component.
|
70
78
|
*/
|
@@ -74,15 +82,45 @@ class ComponentServer {
|
|
74
82
|
get port() {
|
75
83
|
return this._port;
|
76
84
|
}
|
77
|
-
async listen() {
|
78
|
-
const port = await (0, _selectPort().selectPort)(this.portRange);
|
85
|
+
async listen(specificPort) {
|
86
|
+
const port = specificPort || (await (0, _selectPort().selectPort)(this.portRange));
|
79
87
|
this._port = port;
|
80
|
-
|
81
|
-
const address =
|
88
|
+
this._server = await this.devServer.listen(port);
|
89
|
+
const address = this._server.address();
|
82
90
|
const hostname = this.getHostname(address);
|
83
91
|
if (!address) throw new (_exceptions().BindError)();
|
84
92
|
this.hostname = hostname;
|
85
|
-
this.pubsub.pub(_bundler().BundlerAspect.id, this.createComponentsServerStartedEvent(
|
93
|
+
this.pubsub.pub(_bundler().BundlerAspect.id, this.createComponentsServerStartedEvent(this, this.context, hostname, port));
|
94
|
+
}
|
95
|
+
async close() {
|
96
|
+
if (!this.server) return;
|
97
|
+
return new Promise((resolve, reject) => {
|
98
|
+
this.server?.close(err => {
|
99
|
+
if (err) {
|
100
|
+
reject(err);
|
101
|
+
} else {
|
102
|
+
this._server = undefined;
|
103
|
+
this.hostname = undefined;
|
104
|
+
resolve();
|
105
|
+
}
|
106
|
+
});
|
107
|
+
});
|
108
|
+
}
|
109
|
+
async restart(useNewPort = false) {
|
110
|
+
if (this._isRestarting) {
|
111
|
+
// add a logger here once we start using this API
|
112
|
+
return;
|
113
|
+
}
|
114
|
+
this._isRestarting = true;
|
115
|
+
try {
|
116
|
+
await this.close();
|
117
|
+
await this.listen(useNewPort ? undefined : this._port);
|
118
|
+
} catch (error) {
|
119
|
+
if (!this.errors) this.errors = [];
|
120
|
+
this.errors.push(error);
|
121
|
+
} finally {
|
122
|
+
this._isRestarting = false;
|
123
|
+
}
|
86
124
|
}
|
87
125
|
getHostname(address) {
|
88
126
|
if (address === null) throw new (_exceptions().BindError)();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_exceptions","data","require","_events","_bundler","_selectPort","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","ComponentServer","constructor","pubsub","context","portRange","devServer","componentsServer","hostname","port","ComponentsServerStartedEvent","Date","now","hasComponent","component","components","find","contextComponent","equals","_port","listen","
|
1
|
+
{"version":3,"names":["_exceptions","data","require","_events","_bundler","_selectPort","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","ComponentServer","constructor","pubsub","context","portRange","devServer","componentsServer","hostname","port","ComponentsServerStartedEvent","Date","now","server","_server","envId","envRuntime","id","hasComponent","component","components","find","contextComponent","equals","_port","listen","specificPort","selectPort","address","getHostname","BindError","pub","BundlerAspect","createComponentsServerStartedEvent","close","Promise","resolve","reject","err","undefined","restart","useNewPort","_isRestarting","error","errors","push","onChange","url","exports"],"sources":["component-server.ts"],"sourcesContent":["import { Component } from '@teambit/component';\nimport { ExecutionContext } from '@teambit/envs';\nimport { PubsubMain } from '@teambit/pubsub';\nimport { AddressInfo } from 'net';\nimport { Server } from 'http';\nimport { DevServer } from './dev-server';\nimport { BindError } from './exceptions';\nimport { ComponentsServerStartedEvent } from './events';\nimport { BundlerAspect } from './bundler.aspect';\nimport { selectPort } from './select-port';\n\nexport class ComponentServer {\n // why is this here\n errors?: Error[];\n constructor(\n /**\n * browser runtime slot\n */\n private pubsub: PubsubMain,\n\n /**\n * components contained in the existing component server.\n */\n readonly context: ExecutionContext,\n\n /**\n * port range of the component server.\n */\n readonly portRange: number[],\n\n /**\n * env dev server.\n */\n readonly devServer: DevServer\n ) { }\n\n hostname: string | undefined;\n private _server?: Server;\n private _isRestarting: boolean = false;\n\n get server() {\n return this._server;\n }\n\n get envId() {\n return this.context.envRuntime.id;\n };\n /**\n * determine whether component server contains a component.\n */\n hasComponent(component: Component) {\n return this.context.components.find((contextComponent) => contextComponent.equals(component));\n }\n\n get port() {\n return this._port;\n }\n\n _port: number;\n\n async listen(specificPort?: number) {\n const port = specificPort || await selectPort(this.portRange);\n this._port = port;\n this._server = await this.devServer.listen(port);\n const address = this._server.address();\n const hostname = this.getHostname(address);\n if (!address) throw new BindError();\n this.hostname = hostname;\n\n this.pubsub.pub(\n BundlerAspect.id,\n this.createComponentsServerStartedEvent(this, this.context, hostname, port)\n );\n }\n\n async close(): Promise<void> {\n if (!this.server) return;\n\n return new Promise<void>((resolve, reject) => {\n this.server?.close((err) => {\n if (err) {\n reject(err);\n } else {\n this._server = undefined;\n this.hostname = undefined;\n resolve();\n }\n });\n });\n }\n\n async restart(useNewPort = false): Promise<void> {\n if (this._isRestarting) {\n // add a logger here once we start using this API\n return;\n }\n this._isRestarting = true;\n try {\n await this.close();\n await this.listen(useNewPort ? undefined : this._port);\n }\n catch (error) {\n if (!this.errors) this.errors = [];\n this.errors.push(error as Error);\n }\n finally {\n this._isRestarting = false;\n }\n }\n\n private getHostname(address: string | AddressInfo | null) {\n if (address === null) throw new BindError();\n if (typeof address === 'string') return address;\n\n let hostname = address.address;\n if (hostname === '::') {\n hostname = 'localhost';\n }\n\n return hostname;\n }\n\n private onChange() { }\n\n private createComponentsServerStartedEvent: (\n componentsServer,\n context,\n string,\n number\n ) => ComponentsServerStartedEvent = (componentsServer, context, hostname, port) => {\n return new ComponentsServerStartedEvent(Date.now(), componentsServer, context, hostname, port);\n };\n\n /**\n * get the url of the component server.\n */\n get url() {\n // tailing `/` is required!\n return `/preview/${this.context.envRuntime.id}/`;\n }\n}\n"],"mappings":";;;;;;AAMA,SAAAA,YAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,WAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,SAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,QAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,YAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,WAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA2C,SAAAK,gBAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,M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Y,UAAU,CAACC,EAAE,GAAG;EAClD;AACF;AAAC+B,OAAA,CAAA/C,eAAA,GAAAA,eAAA","ignoreList":[]}
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import { Schema } from '@teambit/graphql';
|
1
|
+
import { GraphqlMain, Schema } from '@teambit/graphql';
|
2
2
|
import { BundlerMain } from './bundler.main.runtime';
|
3
|
-
export declare function devServerSchema(bundler: BundlerMain): Schema;
|
3
|
+
export declare function devServerSchema(bundler: BundlerMain, graphql: GraphqlMain): Schema;
|
@@ -11,20 +11,31 @@ function _client() {
|
|
11
11
|
};
|
12
12
|
return data;
|
13
13
|
}
|
14
|
-
|
15
|
-
|
14
|
+
function _events() {
|
15
|
+
const data = require("./events");
|
16
|
+
_events = function () {
|
17
|
+
return data;
|
18
|
+
};
|
19
|
+
return data;
|
20
|
+
}
|
21
|
+
function devServerSchema(bundler, graphql) {
|
16
22
|
return {
|
17
23
|
typeDefs: (0, _client().gql)`
|
18
24
|
extend type Component {
|
19
25
|
server: ComponentServer
|
20
26
|
}
|
21
|
-
|
27
|
+
|
22
28
|
type ComponentServer {
|
29
|
+
id: ID!
|
23
30
|
env: String
|
24
31
|
url: String
|
25
32
|
host: String
|
26
33
|
basePath: String
|
27
34
|
}
|
35
|
+
|
36
|
+
type Subscription {
|
37
|
+
componentServerStarted(id: String): [ComponentServer!]!
|
38
|
+
}
|
28
39
|
`,
|
29
40
|
resolvers: {
|
30
41
|
Component: {
|
@@ -37,15 +48,38 @@ function devServerSchema(bundler) {
|
|
37
48
|
// so don't return the server url
|
38
49
|
// see https://github.com/teambit/bit/issues/5328
|
39
50
|
if (requestedId && requestedId.includes('@')) {
|
40
|
-
return {
|
51
|
+
return {
|
52
|
+
id: 'no-server'
|
53
|
+
};
|
41
54
|
}
|
42
55
|
const componentServer = bundler.getComponentServer(component);
|
43
|
-
if (!componentServer) return {
|
56
|
+
if (!componentServer) return {
|
57
|
+
id: 'no-server'
|
58
|
+
};
|
44
59
|
return {
|
60
|
+
id: `server-${componentServer.context.envRuntime.id}`,
|
45
61
|
env: componentServer.context.envRuntime.id,
|
46
62
|
url: componentServer.url
|
47
63
|
};
|
48
64
|
}
|
65
|
+
},
|
66
|
+
Subscription: {
|
67
|
+
componentServerStarted: {
|
68
|
+
subscribe: () => graphql.pubsub.asyncIterator([_events().ComponentServerStartedEvent]),
|
69
|
+
resolve: (payload, {
|
70
|
+
id
|
71
|
+
}) => {
|
72
|
+
const server = payload.componentServers;
|
73
|
+
if (!server || id && server.context.envRuntime.id !== id) {
|
74
|
+
return [];
|
75
|
+
}
|
76
|
+
return [{
|
77
|
+
id: `server-${server.context.envRuntime.id}`,
|
78
|
+
env: server.context.envRuntime.id,
|
79
|
+
url: server.url
|
80
|
+
}];
|
81
|
+
}
|
82
|
+
}
|
49
83
|
}
|
50
84
|
}
|
51
85
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_client","data","require","devServerSchema","bundler","typeDefs","gql","resolvers","Component","server","component","args","context","requestedId","body","variables","id","includes","componentServer","getComponentServer","
|
1
|
+
{"version":3,"names":["_client","data","require","_events","devServerSchema","bundler","graphql","typeDefs","gql","resolvers","Component","server","component","args","context","requestedId","body","variables","id","includes","componentServer","getComponentServer","envRuntime","env","url","Subscription","componentServerStarted","subscribe","pubsub","asyncIterator","ComponentServerStartedEvent","resolve","payload","componentServers"],"sources":["dev-server.graphql.ts"],"sourcesContent":["import { Component } from '@teambit/component';\nimport { GraphqlMain, Schema } from '@teambit/graphql';\nimport { gql } from '@apollo/client';\nimport { BundlerMain } from './bundler.main.runtime';\nimport { ComponentServerStartedEvent } from './events';\n\nexport function devServerSchema(bundler: BundlerMain, graphql: GraphqlMain): Schema {\n return {\n typeDefs: gql`\n extend type Component {\n server: ComponentServer\n }\n \n type ComponentServer {\n id: ID!\n env: String\n url: String\n host: String\n basePath: String\n }\n \n type Subscription {\n componentServerStarted(id: String): [ComponentServer!]!\n }\n `,\n resolvers: {\n Component: {\n server: (component: Component, args, context) => {\n // This is a bit of a hack to get the requested id. it assumes the variable name of\n // the gotHost.get query is \"id\".\n // see it in scopes/component/component/component.graphql.ts\n const requestedId = context?.body?.variables?.id;\n // if we ask for specific id with specific version it means we want to fetch if from scope\n // so don't return the server url\n // see https://github.com/teambit/bit/issues/5328\n if (requestedId && requestedId.includes('@')) {\n return {\n id: 'no-server'\n };\n }\n\n const componentServer = bundler.getComponentServer(component);\n if (!componentServer) return {\n id: 'no-server'\n };\n\n return {\n id: `server-${componentServer.context.envRuntime.id}`,\n env: componentServer.context.envRuntime.id,\n url: componentServer.url,\n };\n },\n },\n Subscription: {\n componentServerStarted: {\n subscribe: () => graphql.pubsub.asyncIterator([ComponentServerStartedEvent]),\n resolve: (payload, { id }) => {\n const server = payload.componentServers;\n\n if (!server || (id && server.context.envRuntime.id !== id)) {\n return [];\n }\n\n return [{\n id: `server-${server.context.envRuntime.id}`,\n env: server.context.envRuntime.id,\n url: server.url,\n }];\n }\n },\n },\n },\n };\n}"],"mappings":";;;;;;AAEA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEO,SAASG,eAAeA,CAACC,OAAoB,EAAEC,OAAoB,EAAU;EAClF,OAAO;IACLC,QAAQ,EAAE,IAAAC,aAAG;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;IACDC,SAAS,EAAE;MACTC,SAAS,EAAE;QACTC,MAAM,EAAEA,CAACC,SAAoB,EAAEC,IAAI,EAAEC,OAAO,KAAK;UAC/C;UACA;UACA;UACA,MAAMC,WAAW,GAAGD,OAAO,EAAEE,IAAI,EAAEC,S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it/pubsub';
|
3
|
+
import { ComponentServer } from '../component-server';
|
4
|
+
import { ExecutionContext } from '@teambit/envs';
|
5
|
+
export declare const ComponentServerStartedEvent = "ComponentServerStartedEvent";
|
2
6
|
declare class ComponentsServerStartedEventData {
|
3
|
-
readonly componentsServer:
|
4
|
-
readonly context:
|
5
|
-
readonly hostname
|
6
|
-
readonly port
|
7
|
-
constructor(componentsServer:
|
7
|
+
readonly componentsServer: ComponentServer;
|
8
|
+
readonly context: ExecutionContext;
|
9
|
+
readonly hostname?: string | undefined;
|
10
|
+
readonly port?: number | undefined;
|
11
|
+
constructor(componentsServer: ComponentServer, context: ExecutionContext, hostname?: string | undefined, port?: number | undefined);
|
8
12
|
}
|
9
13
|
export declare class ComponentsServerStartedEvent extends BitBaseEvent<ComponentsServerStartedEventData> {
|
10
|
-
readonly timestamp:
|
11
|
-
readonly componentsServer:
|
12
|
-
readonly context:
|
13
|
-
readonly hostname
|
14
|
-
readonly port
|
14
|
+
readonly timestamp: number;
|
15
|
+
readonly componentsServer: ComponentServer;
|
16
|
+
readonly context: ExecutionContext;
|
17
|
+
readonly hostname?: string | undefined;
|
18
|
+
readonly port?: number | undefined;
|
15
19
|
static readonly TYPE = "components-server-started";
|
16
|
-
constructor(timestamp:
|
20
|
+
constructor(timestamp: number, componentsServer: ComponentServer, context: ExecutionContext, hostname?: string | undefined, port?: number | undefined);
|
21
|
+
}
|
22
|
+
export declare class NewDevServersCreatedEvent extends BitBaseEvent<ComponentsServerStartedEventData[]> {
|
23
|
+
readonly componentsServers: ComponentServer[];
|
24
|
+
readonly timestamp: number;
|
25
|
+
readonly graphql: GraphqlMain;
|
26
|
+
readonly restartIfRunning: boolean;
|
27
|
+
static readonly TYPE = "new-dev-servers-created";
|
28
|
+
constructor(componentsServers: ComponentServer[], timestamp: number, graphql: GraphqlMain, restartIfRunning?: boolean);
|
17
29
|
}
|
18
30
|
export {};
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.ComponentsServerStartedEvent = void 0;
|
6
|
+
exports.NewDevServersCreatedEvent = exports.ComponentsServerStartedEvent = exports.ComponentServerStartedEvent = void 0;
|
7
7
|
function _pubsub() {
|
8
8
|
const data = require("@teambit/pubsub");
|
9
9
|
_pubsub = function () {
|
@@ -14,6 +14,7 @@ function _pubsub() {
|
|
14
14
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
15
15
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
16
16
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* eslint-disable max-classes-per-file */
|
17
|
+
const ComponentServerStartedEvent = exports.ComponentServerStartedEvent = 'ComponentServerStartedEvent';
|
17
18
|
class ComponentsServerStartedEventData {
|
18
19
|
constructor(componentsServer, context, hostname, port) {
|
19
20
|
this.componentsServer = componentsServer;
|
@@ -34,5 +35,16 @@ class ComponentsServerStartedEvent extends _pubsub().BitBaseEvent {
|
|
34
35
|
}
|
35
36
|
exports.ComponentsServerStartedEvent = ComponentsServerStartedEvent;
|
36
37
|
_defineProperty(ComponentsServerStartedEvent, "TYPE", 'components-server-started');
|
38
|
+
class NewDevServersCreatedEvent extends _pubsub().BitBaseEvent {
|
39
|
+
constructor(componentsServers, timestamp, graphql, restartIfRunning = false) {
|
40
|
+
super(NewDevServersCreatedEvent.TYPE, '0.0.1', timestamp, componentsServers.map(c => new ComponentsServerStartedEventData(c, c.context, c.hostname, c.port)));
|
41
|
+
this.componentsServers = componentsServers;
|
42
|
+
this.timestamp = timestamp;
|
43
|
+
this.graphql = graphql;
|
44
|
+
this.restartIfRunning = restartIfRunning;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
exports.NewDevServersCreatedEvent = NewDevServersCreatedEvent;
|
48
|
+
_defineProperty(NewDevServersCreatedEvent, "TYPE", 'new-dev-servers-created');
|
37
49
|
|
38
50
|
//# sourceMappingURL=components-server-started-event.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_pubsub","data","require","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","ComponentsServerStartedEventData","constructor","componentsServer","context","hostname","port","ComponentsServerStartedEvent","BitBaseEvent","timestamp","TYPE","
|
1
|
+
{"version":3,"names":["_pubsub","data","require","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","ComponentServerStartedEvent","exports","ComponentsServerStartedEventData","constructor","componentsServer","context","hostname","port","ComponentsServerStartedEvent","BitBaseEvent","timestamp","TYPE","NewDevServersCreatedEvent","componentsServers","graphql","restartIfRunning","map","c"],"sources":["components-server-started-event.ts"],"sourcesContent":["/* eslint-disable max-classes-per-file */\n\nimport { GraphqlMain } from '@teambit/graphql';\nimport { BitBaseEvent } from '@teambit/pubsub';\nimport { ComponentServer } from '../component-server';\nimport { ExecutionContext } from '@teambit/envs';\n\nexport const ComponentServerStartedEvent = 'ComponentServerStartedEvent';\n\nclass ComponentsServerStartedEventData {\n constructor(\n readonly componentsServer: ComponentServer,\n readonly context: ExecutionContext,\n readonly hostname?: string,\n readonly port?: number\n ) {}\n}\n\nexport class ComponentsServerStartedEvent extends BitBaseEvent<ComponentsServerStartedEventData> {\n static readonly TYPE = 'components-server-started';\n\n constructor(\n readonly timestamp: number,\n readonly componentsServer: ComponentServer,\n readonly context: ExecutionContext,\n readonly hostname?: string,\n readonly port?: number,\n ) {\n super(\n ComponentsServerStartedEvent.TYPE,\n '0.0.1',\n timestamp,\n new ComponentsServerStartedEventData(componentsServer, context, hostname, port)\n );\n }\n}\n\nexport class NewDevServersCreatedEvent extends BitBaseEvent<ComponentsServerStartedEventData[]> {\n static readonly TYPE = 'new-dev-servers-created';\n\n constructor(\n readonly componentsServers: ComponentServer[],\n readonly timestamp: number,\n readonly graphql: GraphqlMain,\n readonly restartIfRunning: boolean = false\n ) {\n super(\n NewDevServersCreatedEvent.TYPE,\n '0.0.1',\n timestamp,\n componentsServers.map(c => new ComponentsServerStartedEventData(c, c.context, c.hostname, c.port))\n );\n }\n\n}\n\n"],"mappings":";;;;;;AAGA,SAAAA,QAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,OAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA+C,SAAAE,gBAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAD,CAAA,GAAAI,MAAA,CAAAC,cAAA,CAAAL,CAAA,EAAAC,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAT,CAAA,CAAAC,CAAA,IAAAC,CAAA,EAAAF,CAAA;AAAA,SAAAG,eAAAD,CAAA,QAAAQ,CAAA,GAAAC,YAAA,CAAAT,CAAA,uCAAAQ,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAAA,SAAAC,aAAAT,CAAA,EAAAD,CAAA,2BAAAC,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAF,CAAA,GAAAE,CAAA,CAAAU,MAAA,CAAAC,WAAA,kBAAAb,CAAA,QAAAU,CAAA,GAAAV,CAAA,CAAAc,IAAA,CAAAZ,CAAA,EAAAD,CAAA,uCAAAS,CAAA,SAAAA,CAAA,YAAAK,SAAA,yEAAAd,CAAA,GAAAe,MAAA,GAAAC,MAAA,EAAAf,CAAA,KAH/C;AAOO,MAAMgB,2BAA2B,G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AAC,KAVOM,iBAAoC,GAApCA,iBAAoC;IAAA,KACpCH,SAAiB,GAAjBA,SAAiB;IAAA,KACjBI,OAAoB,GAApBA,OAAoB;IAAA,KACpBC,gBAAyB,GAAzBA,gBAAyB;EAQpC;AAEF;AAACd,OAAA,CAAAW,yBAAA,GAAAA,yBAAA;AAAA/B,eAAA,CAjBY+B,yBAAyB,UACb,yBAAyB","ignoreList":[]}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.compilation_bundler@1.0.
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.compilation_bundler@1.0.
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.compilation_bundler@1.0.588/dist/bundler.composition.js';
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.compilation_bundler@1.0.588/dist/bundler.docs.mdx';
|
3
3
|
|
4
4
|
export const compositions = [compositions_0];
|
5
5
|
export const overview = [overview_0];
|
@@ -1,13 +1,18 @@
|
|
1
1
|
/* eslint-disable max-classes-per-file */
|
2
2
|
|
3
|
+
import { GraphqlMain } from '@teambit/graphql';
|
3
4
|
import { BitBaseEvent } from '@teambit/pubsub';
|
5
|
+
import { ComponentServer } from '../component-server';
|
6
|
+
import { ExecutionContext } from '@teambit/envs';
|
7
|
+
|
8
|
+
export const ComponentServerStartedEvent = 'ComponentServerStartedEvent';
|
4
9
|
|
5
10
|
class ComponentsServerStartedEventData {
|
6
11
|
constructor(
|
7
|
-
readonly componentsServer,
|
8
|
-
readonly context,
|
9
|
-
readonly hostname,
|
10
|
-
readonly port
|
12
|
+
readonly componentsServer: ComponentServer,
|
13
|
+
readonly context: ExecutionContext,
|
14
|
+
readonly hostname?: string,
|
15
|
+
readonly port?: number
|
11
16
|
) {}
|
12
17
|
}
|
13
18
|
|
@@ -15,11 +20,11 @@ export class ComponentsServerStartedEvent extends BitBaseEvent<ComponentsServerS
|
|
15
20
|
static readonly TYPE = 'components-server-started';
|
16
21
|
|
17
22
|
constructor(
|
18
|
-
readonly timestamp,
|
19
|
-
readonly componentsServer,
|
20
|
-
readonly context,
|
21
|
-
readonly hostname,
|
22
|
-
readonly port
|
23
|
+
readonly timestamp: number,
|
24
|
+
readonly componentsServer: ComponentServer,
|
25
|
+
readonly context: ExecutionContext,
|
26
|
+
readonly hostname?: string,
|
27
|
+
readonly port?: number,
|
23
28
|
) {
|
24
29
|
super(
|
25
30
|
ComponentsServerStartedEvent.TYPE,
|
@@ -29,3 +34,23 @@ export class ComponentsServerStartedEvent extends BitBaseEvent<ComponentsServerS
|
|
29
34
|
);
|
30
35
|
}
|
31
36
|
}
|
37
|
+
|
38
|
+
export class NewDevServersCreatedEvent extends BitBaseEvent<ComponentsServerStartedEventData[]> {
|
39
|
+
static readonly TYPE = 'new-dev-servers-created';
|
40
|
+
|
41
|
+
constructor(
|
42
|
+
readonly componentsServers: ComponentServer[],
|
43
|
+
readonly timestamp: number,
|
44
|
+
readonly graphql: GraphqlMain,
|
45
|
+
readonly restartIfRunning: boolean = false
|
46
|
+
) {
|
47
|
+
super(
|
48
|
+
NewDevServersCreatedEvent.TYPE,
|
49
|
+
'0.0.1',
|
50
|
+
timestamp,
|
51
|
+
componentsServers.map(c => new ComponentsServerStartedEventData(c, c.context, c.hostname, c.port))
|
52
|
+
);
|
53
|
+
}
|
54
|
+
|
55
|
+
}
|
56
|
+
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@teambit/bundler",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.588",
|
4
4
|
"homepage": "https://bit.cloud/teambit/compilation/bundler",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"componentId": {
|
7
7
|
"scope": "teambit.compilation",
|
8
8
|
"name": "bundler",
|
9
|
-
"version": "1.0.
|
9
|
+
"version": "1.0.588"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
12
|
"chalk": "4.1.2",
|
@@ -14,13 +14,13 @@
|
|
14
14
|
"lodash": "4.17.21",
|
15
15
|
"p-map-series": "2.1.0",
|
16
16
|
"@teambit/harmony": "0.4.7",
|
17
|
-
"@teambit/envs": "1.0.
|
18
|
-
"@teambit/builder": "1.0.
|
19
|
-
"@teambit/component": "1.0.
|
20
|
-
"@teambit/cli": "0.0.
|
21
|
-
"@teambit/dependency-resolver": "1.0.
|
22
|
-
"@teambit/graphql": "1.0.
|
23
|
-
"@teambit/pubsub": "1.0.
|
17
|
+
"@teambit/envs": "1.0.588",
|
18
|
+
"@teambit/builder": "1.0.588",
|
19
|
+
"@teambit/component": "1.0.588",
|
20
|
+
"@teambit/cli": "0.0.1165",
|
21
|
+
"@teambit/dependency-resolver": "1.0.588",
|
22
|
+
"@teambit/graphql": "1.0.588",
|
23
|
+
"@teambit/pubsub": "1.0.588",
|
24
24
|
"@teambit/legacy.bit-map": "0.0.104",
|
25
25
|
"@teambit/toolbox.path.path": "0.0.8",
|
26
26
|
"@teambit/toolbox.network.get-port": "1.0.10"
|