@teambit/application 0.0.444 → 0.0.447

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.
@@ -7,4 +7,12 @@ export interface AppContext extends ExecutionContext {
7
7
  dev: boolean;
8
8
  appName: string;
9
9
  appComponent: Component;
10
+ workdir: string;
11
+ /**
12
+ * A path for the host root dir
13
+ * Host root dir is the dir where we run the app from
14
+ * This can be used in different bundle options which run require.resolve
15
+ * for example when configuring webpack aliases or webpack expose loader on the peers deps
16
+ */
17
+ hostRootDir?: string;
10
18
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["app-context.ts"],"sourcesContent":["import { ExecutionContext } from '@teambit/envs';\nimport { Component } from '@teambit/component';\n\nexport interface AppContext extends ExecutionContext {\n /**\n * determine whether to serve the application in dev mode.\n */\n dev: boolean;\n\n appName: string;\n\n appComponent: Component;\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["app-context.ts"],"sourcesContent":["import { ExecutionContext } from '@teambit/envs';\nimport { Component } from '@teambit/component';\n\nexport interface AppContext extends ExecutionContext {\n /**\n * determine whether to serve the application in dev mode.\n */\n dev: boolean;\n\n appName: string;\n\n appComponent: Component;\n \n workdir: string;\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 hostRootDir?: string;\n}\n"],"mappings":""}
@@ -34,7 +34,8 @@ class AppPlugin {
34
34
  this.appSlot = appSlot;
35
35
  (0, _defineProperty2().default)(this, "pattern", '*.app.*?(ts|tsx|js|jsx)$');
36
36
  (0, _defineProperty2().default)(this, "runtimes", [_cli().MainRuntime.name]);
37
- }
37
+ } // TODO - this matches NOTHING
38
+
38
39
 
39
40
  async register(object) {
40
41
  return this.appSlot.register([object]);
@@ -1 +1 @@
1
- {"version":3,"names":["AppPlugin","constructor","appSlot","MainRuntime","name","register","object"],"sources":["app.plugin.ts"],"sourcesContent":["import { PluginDefinition } from '@teambit/aspect-loader';\nimport { MainRuntime } from '@teambit/cli';\nimport { ApplicationSlot } from './application.main.runtime';\n\nexport class AppPlugin implements PluginDefinition {\n constructor(private appSlot: ApplicationSlot) {}\n\n pattern = '*.app.*?(ts|tsx|js|jsx)$';\n\n runtimes = [MainRuntime.name];\n\n async register(object: any) {\n return this.appSlot.register([object]);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGO,MAAMA,SAAN,CAA4C;EACjDC,WAAW,CAASC,OAAT,EAAmC;IAAA,KAA1BA,OAA0B,GAA1BA,OAA0B;IAAA,iDAEpC,0BAFoC;IAAA,kDAInC,CAACC,kBAAA,CAAYC,IAAb,CAJmC;EAAE;;EAMlC,MAARC,QAAQ,CAACC,MAAD,EAAc;IAC1B,OAAO,KAAKJ,OAAL,CAAaG,QAAb,CAAsB,CAACC,MAAD,CAAtB,CAAP;EACD;;AATgD"}
1
+ {"version":3,"names":["AppPlugin","constructor","appSlot","MainRuntime","name","register","object"],"sources":["app.plugin.ts"],"sourcesContent":["import { PluginDefinition } from '@teambit/aspect-loader';\nimport { MainRuntime } from '@teambit/cli';\nimport { ApplicationSlot } from './application.main.runtime';\n\nexport class AppPlugin implements PluginDefinition {\n constructor(private appSlot: ApplicationSlot) {}\n\n // TODO - this matches NOTHING\n pattern = '*.app.*?(ts|tsx|js|jsx)$';\n\n runtimes = [MainRuntime.name];\n\n async register(object: any) {\n return this.appSlot.register([object]);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGO,MAAMA,SAAN,CAA4C;EACjDC,WAAW,CAASC,OAAT,EAAmC;IAAA,KAA1BA,OAA0B,GAA1BA,OAA0B;IAAA,iDAGpC,0BAHoC;IAAA,kDAKnC,CAACC,kBAAA,CAAYC,IAAb,CALmC;EAAE,CADC,CAGjD;;;EAKc,MAARC,QAAQ,CAACC,MAAD,EAAc;IAC1B,OAAO,KAAKJ,OAAL,CAAaG,QAAb,CAAsB,CAACC,MAAD,CAAtB,CAAP;EACD;;AAVgD"}
@@ -3,6 +3,10 @@ import { AppDeployContext } from './app-deploy-context';
3
3
  import { AppBuildContext } from './app-build-context';
4
4
  import { AppBuildResult } from './app-build-result';
5
5
  export declare type DeployFn = (context: AppDeployContext) => Promise<void>;
6
+ export declare type AppResult = {
7
+ port?: number;
8
+ errors?: Error[];
9
+ };
6
10
  export interface Application {
7
11
  /**
8
12
  * name of the application. e.g. ripple-ci.
@@ -12,6 +16,10 @@ export interface Application {
12
16
  * run the application.
13
17
  */
14
18
  run(context: AppContext): Promise<number | void>;
19
+ /**
20
+ * run the application in ssr mode
21
+ */
22
+ runSsr?(context: AppContext): Promise<AppResult>;
15
23
  /**
16
24
  * build the application.
17
25
  */
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["application.ts"],"sourcesContent":["import { AppContext } from './app-context';\nimport { AppDeployContext } from './app-deploy-context';\nimport { AppBuildContext } from './app-build-context';\nimport { AppBuildResult } from './app-build-result';\n\nexport type DeployFn = (context: AppDeployContext) => Promise<void>;\n\nexport interface Application {\n /**\n * name of the application. e.g. ripple-ci.\n */\n name: string;\n\n /**\n * run the application.\n */\n run(context: AppContext): Promise<number | void>;\n\n /**\n * build the application.\n */\n build?(context: AppBuildContext): Promise<AppBuildResult>;\n\n /**\n * application deployment. this is a build task.\n */\n deploy?: DeployFn;\n\n /**\n * Type of the application\n */\n applicationType?: string;\n}\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["application.ts"],"sourcesContent":["import { AppContext } from './app-context';\nimport { AppDeployContext } from './app-deploy-context';\nimport { AppBuildContext } from './app-build-context';\nimport { AppBuildResult } from './app-build-result';\n\nexport type DeployFn = (context: AppDeployContext) => Promise<void>;\n\nexport type AppResult = {\n port?: number;\n errors?: Error[];\n};\n\nexport interface Application {\n /**\n * name of the application. e.g. ripple-ci.\n */\n name: string;\n\n /**\n * run the application.\n */\n run(context: AppContext): Promise<number | void>;\n\n /**\n * run the application in ssr mode\n */\n runSsr?(context: AppContext): Promise<AppResult>;\n\n /**\n * build the application.\n */\n build?(context: AppBuildContext): Promise<AppBuildResult>;\n\n /**\n * application deployment. this is a build task.\n */\n deploy?: DeployFn;\n\n /**\n * Type of the application\n */\n applicationType?: string;\n}\n"],"mappings":""}
@@ -18,11 +18,21 @@ export declare type ServeAppOptions = {
18
18
  /**
19
19
  * default port range used to serve applications.
20
20
  */
21
- defaultPortRange?: number[];
21
+ defaultPortRange?: [start: number, end: number];
22
22
  /**
23
23
  * determine whether to start the application in dev mode.
24
24
  */
25
25
  dev: boolean;
26
+ /**
27
+ * actively watch and compile the workspace (like the bit watch command)
28
+ * @default true
29
+ */
30
+ watch?: boolean;
31
+ /**
32
+ * determine whether to start the application in server side mode.
33
+ * @default false
34
+ */
35
+ ssr?: boolean;
26
36
  };
27
37
  export declare class ApplicationMain {
28
38
  private appSlot;
@@ -67,12 +77,16 @@ export declare class ApplicationMain {
67
77
  * get app to throw.
68
78
  */
69
79
  getAppOrThrow(appName: string): Application;
80
+ defaultOpts: ServeAppOptions;
70
81
  private computeOptions;
71
- runApp(appName: string, options?: Partial<ServeAppOptions> & {
72
- skipWatch?: boolean;
73
- }): Promise<{
82
+ runApp(appName: string, options?: ServeAppOptions): Promise<{
83
+ port?: number | undefined;
84
+ errors?: Error[] | undefined;
85
+ app: Application;
86
+ } | {
74
87
  app: Application;
75
88
  port: number | void;
89
+ errors: undefined;
76
90
  }>;
77
91
  /**
78
92
  * get the component ID of a certain app.
@@ -211,6 +211,16 @@ function _deploy() {
211
211
  return data;
212
212
  }
213
213
 
214
+ function _appNoSsr() {
215
+ const data = require("./exceptions/app-no-ssr");
216
+
217
+ _appNoSsr = function () {
218
+ return data;
219
+ };
220
+
221
+ return data;
222
+ }
223
+
214
224
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
215
225
 
216
226
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -220,7 +230,8 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
220
230
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
221
231
 
222
232
  class ApplicationMain {
223
- constructor(appSlot, appTypeSlot, deploymentProviderSlot, envs, componentAspect, appService, aspectLoader, workspace, logger) {
233
+ constructor(appSlot, // TODO unused
234
+ appTypeSlot, deploymentProviderSlot, envs, componentAspect, appService, aspectLoader, workspace, logger) {
224
235
  this.appSlot = appSlot;
225
236
  this.appTypeSlot = appTypeSlot;
226
237
  this.deploymentProviderSlot = deploymentProviderSlot;
@@ -230,6 +241,12 @@ class ApplicationMain {
230
241
  this.aspectLoader = aspectLoader;
231
242
  this.workspace = workspace;
232
243
  this.logger = logger;
244
+ (0, _defineProperty2().default)(this, "defaultOpts", {
245
+ dev: false,
246
+ ssr: false,
247
+ watch: true,
248
+ defaultPortRange: [3100, 3500]
249
+ });
233
250
  }
234
251
  /**
235
252
  * register a new app.
@@ -306,24 +323,27 @@ class ApplicationMain {
306
323
  return app;
307
324
  }
308
325
 
309
- computeOptions(opts) {
310
- const defaultOpts = {
311
- dev: false,
312
- defaultPortRange: [3100, 3500]
313
- };
314
- return _objectSpread({
315
- defaultOpts
316
- }, opts);
326
+ computeOptions(opts = {}) {
327
+ return _objectSpread(_objectSpread({}, this.defaultOpts), opts);
317
328
  }
318
329
 
319
- async runApp(appName, options = {}) {
330
+ async runApp(appName, options) {
331
+ options = this.computeOptions(options);
320
332
  const app = this.getAppOrThrow(appName);
321
- this.computeOptions(options);
322
333
  const context = await this.createAppContext(appName);
323
334
  if (!context) throw new (_exceptions().AppNotFound)(appName);
335
+
336
+ if (options.ssr) {
337
+ if (!app.runSsr) throw new (_appNoSsr().AppNoSsr)(appName);
338
+ const result = await app.runSsr(context);
339
+ return _objectSpread({
340
+ app
341
+ }, result);
342
+ }
343
+
324
344
  const port = await app.run(context);
325
345
 
326
- if (!options.skipWatch) {
346
+ if (options.watch) {
327
347
  this.workspace.watcher.watchAll({
328
348
  preCompile: false
329
349
  }).catch(err => {
@@ -334,7 +354,8 @@ class ApplicationMain {
334
354
 
335
355
  return {
336
356
  app,
337
- port
357
+ port,
358
+ errors: undefined
338
359
  };
339
360
  }
340
361
  /**
@@ -361,9 +382,12 @@ class ApplicationMain {
361
382
  const res = await env.run(this.appService);
362
383
  const context = res.results[0].data;
363
384
  if (!context) throw new (_exceptions().AppNotFound)(appName);
385
+ const hostRootDir = this.workspace.getComponentPackagePath(component);
364
386
  return Object.assign((0, _lodash().cloneDeep)(context), {
365
387
  appName,
366
- appComponent: component
388
+ appComponent: component,
389
+ hostRootDir,
390
+ workdir: this.workspace.path
367
391
  });
368
392
  }
369
393
 
@@ -372,7 +396,7 @@ class ApplicationMain {
372
396
  const appService = new (_application2().AppService)();
373
397
  const application = new ApplicationMain(appSlot, appTypeSlot, deploymentProviderSlot, envs, component, appService, aspectLoader, workspace, logger);
374
398
  const appCmd = new (_app().AppCmd)();
375
- appCmd.commands = [new (_app().AppListCmd)(application)];
399
+ appCmd.commands = [new (_app().AppListCmd)(application), new (_run().RunCmd)(application, logger)];
376
400
  aspectLoader.registerPlugins([new (_app2().AppPlugin)(appSlot)]);
377
401
  builder.registerBuildTasks([new (_build().AppsBuildTask)(application)]);
378
402
  builder.registerSnapTasks([new (_deploy().DeployTask)(application, builder)]);
@@ -1 +1 @@
1
- {"version":3,"names":["ApplicationMain","constructor","appSlot","appTypeSlot","deploymentProviderSlot","envs","componentAspect","appService","aspectLoader","workspace","logger","registerApp","app","register","listApps","flatten","values","mapApps","toArray","listAppsById","id","undefined","get","toString","getApp","appName","apps","find","name","registerAppType","appType","plugin","AppTypePlugin","registerPlugins","getAppAspect","getAppOrThrow","AppNotFound","computeOptions","opts","defaultOpts","dev","defaultPortRange","runApp","options","context","createAppContext","port","run","skipWatch","watcher","watchAll","preCompile","catch","err","error","getAppIdOrThrow","maybeApp","ComponentID","fromString","host","getHost","components","list","component","c","isEqual","env","createEnvironment","res","results","data","Object","assign","cloneDeep","appComponent","provider","cli","loggerAspect","builder","config","createLogger","ApplicationAspect","AppService","application","appCmd","AppCmd","commands","AppListCmd","AppPlugin","registerBuildTasks","AppsBuildTask","registerSnapTasks","DeployTask","registerTagTasks","registerGroup","RunCmd","AppListCmdDeprecated","MainRuntime","CLIAspect","LoggerAspect","BuilderAspect","EnvsAspect","ComponentAspect","AspectLoaderAspect","WorkspaceAspect","Slot","withType","addRuntime"],"sources":["application.main.runtime.ts"],"sourcesContent":["import { MainRuntime, CLIMain, CLIAspect } from '@teambit/cli';\nimport { flatten, cloneDeep } from 'lodash';\nimport { AspectLoaderMain, AspectLoaderAspect } from '@teambit/aspect-loader';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { BuilderAspect, BuilderMain } from '@teambit/builder';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport ComponentAspect, { ComponentMain, ComponentID } from '@teambit/component';\nimport { ApplicationType } from './application-type';\nimport { Application } from './application';\nimport { DeploymentProvider } from './deployment-provider';\nimport { AppNotFound } from './exceptions';\nimport { ApplicationAspect } from './application.aspect';\nimport { AppListCmdDeprecated } from './app-list.cmd';\nimport { AppsBuildTask } from './build.task';\nimport { RunCmd } from './run.cmd';\nimport { AppService } from './application.service';\nimport { AppCmd, AppListCmd } from './app.cmd';\nimport { AppPlugin } from './app.plugin';\nimport { AppTypePlugin } from './app-type.plugin';\nimport { AppContext } from './app-context';\nimport { DeployTask } from './deploy.task';\n\nexport type ApplicationTypeSlot = SlotRegistry<ApplicationType<unknown>[]>;\nexport type ApplicationSlot = SlotRegistry<Application[]>;\nexport type DeploymentProviderSlot = SlotRegistry<DeploymentProvider[]>;\n\nexport type ApplicationAspectConfig = {};\n\nexport type ServeAppOptions = {\n /**\n * default port range used to serve applications.\n */\n defaultPortRange?: number[];\n\n /**\n * determine whether to start the application in dev mode.\n */\n dev: boolean;\n};\n\nexport class ApplicationMain {\n constructor(\n private appSlot: ApplicationSlot,\n private appTypeSlot: ApplicationTypeSlot,\n private deploymentProviderSlot: DeploymentProviderSlot,\n private envs: EnvsMain,\n private componentAspect: ComponentMain,\n private appService: AppService,\n private aspectLoader: AspectLoaderMain,\n private workspace: Workspace,\n private logger: Logger\n ) {}\n\n /**\n * register a new app.\n */\n registerApp(app: Application) {\n this.appSlot.register([app]);\n return this;\n }\n\n /**\n * list all registered apps.\n */\n listApps(): Application[] {\n return flatten(this.appSlot.values());\n }\n\n /**\n * map all apps by component ID.\n */\n mapApps() {\n return this.appSlot.toArray();\n }\n\n /**\n * list apps by a component id.\n */\n listAppsById(id?: ComponentID): Application[] | undefined {\n if (!id) return undefined;\n return this.appSlot.get(id.toString());\n }\n\n /**\n * get an app.\n */\n getApp(appName: string, id?: ComponentID): Application | undefined {\n const apps = this.listAppsById(id) || this.listApps();\n return apps.find((app) => app.name === appName);\n }\n\n /**\n * registers a new app and sets a plugin for it.\n */\n registerAppType<T>(appType: ApplicationType<T>) {\n const plugin = new AppTypePlugin(`*.${appType.name}.*`, appType, this.appSlot);\n this.aspectLoader.registerPlugins([plugin]);\n this.appTypeSlot.register([appType]);\n return this;\n }\n\n /**\n * get an app AspectId.\n */\n getAppAspect(appName: string): string | undefined {\n return this.appSlot.toArray().find(([, apps]) => apps.find((app) => app.name === appName))?.[0];\n }\n\n /**\n * get app to throw.\n */\n getAppOrThrow(appName: string) {\n const app = this.getApp(appName);\n if (!app) throw new AppNotFound(appName);\n return app;\n }\n\n private computeOptions(opts: Partial<ServeAppOptions>) {\n const defaultOpts: ServeAppOptions = {\n dev: false,\n defaultPortRange: [3100, 3500],\n };\n\n return {\n defaultOpts,\n ...opts,\n };\n }\n\n async runApp(appName: string, options: Partial<ServeAppOptions> & { skipWatch?: boolean } = {}) {\n const app = this.getAppOrThrow(appName);\n this.computeOptions(options);\n const context = await this.createAppContext(appName);\n if (!context) throw new AppNotFound(appName);\n const port = await app.run(context);\n if (!options.skipWatch) {\n this.workspace.watcher\n .watchAll({\n preCompile: false,\n })\n .catch((err) => {\n // don't throw an error, we don't want to break the \"run\" process\n this.logger.error(`compilation failed`, err);\n });\n }\n return { app, port };\n }\n\n /**\n * get the component ID of a certain app.\n */\n getAppIdOrThrow(appName: string) {\n const maybeApp = this.appSlot.toArray().find(([, apps]) => {\n return apps.find((app) => app.name === appName);\n });\n\n if (!maybeApp) throw new AppNotFound(appName);\n return ComponentID.fromString(maybeApp[0]);\n }\n\n private async createAppContext(appName: string): Promise<AppContext> {\n const host = this.componentAspect.getHost();\n const components = await host.list();\n const id = this.getAppIdOrThrow(appName);\n const component = components.find((c) => c.id.isEqual(id));\n if (!component) throw new AppNotFound(appName);\n // console.log(comp)\n\n const env = await this.envs.createEnvironment([component]);\n const res = await env.run(this.appService);\n const context = res.results[0].data;\n if (!context) throw new AppNotFound(appName);\n return Object.assign(cloneDeep(context), {\n appName,\n appComponent: component,\n });\n }\n\n static runtime = MainRuntime;\n static dependencies = [\n CLIAspect,\n LoggerAspect,\n BuilderAspect,\n EnvsAspect,\n ComponentAspect,\n AspectLoaderAspect,\n WorkspaceAspect,\n ];\n\n static slots = [\n Slot.withType<ApplicationType<unknown>[]>(),\n Slot.withType<Application[]>(),\n Slot.withType<DeploymentProvider[]>(),\n ];\n\n static async provider(\n [cli, loggerAspect, builder, envs, component, aspectLoader, workspace]: [\n CLIMain,\n LoggerMain,\n BuilderMain,\n EnvsMain,\n ComponentMain,\n AspectLoaderMain,\n Workspace\n ],\n config: ApplicationAspectConfig,\n [appTypeSlot, appSlot, deploymentProviderSlot]: [ApplicationTypeSlot, ApplicationSlot, DeploymentProviderSlot]\n ) {\n const logger = loggerAspect.createLogger(ApplicationAspect.id);\n const appService = new AppService();\n const application = new ApplicationMain(\n appSlot,\n appTypeSlot,\n deploymentProviderSlot,\n envs,\n component,\n appService,\n aspectLoader,\n workspace,\n logger\n );\n const appCmd = new AppCmd();\n appCmd.commands = [new AppListCmd(application)];\n aspectLoader.registerPlugins([new AppPlugin(appSlot)]);\n builder.registerBuildTasks([new AppsBuildTask(application)]);\n builder.registerSnapTasks([new DeployTask(application, builder)]);\n builder.registerTagTasks([new DeployTask(application, builder)]);\n cli.registerGroup('apps', 'Applications');\n cli.register(new RunCmd(application, logger), new AppListCmdDeprecated(application), appCmd);\n\n return application;\n }\n}\n\nApplicationAspect.addRuntime(ApplicationMain);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA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EACD;;AA/L0B;;;gCAAhBnF,e,aA0IMiG,kB;gCA1INjG,e,kBA2IW,CACpBkG,gBADoB,EAEpBC,sBAFoB,EAGpBC,wBAHoB,EAIpBC,kBAJoB,EAKpBC,oBALoB,EAMpBC,kCANoB,EAOpBC,oBAPoB,C;gCA3IXxG,e,WAqJI,CACbyG,eAAA,CAAKC,QAAL,EADa,EAEbD,eAAA,CAAKC,QAAL,EAFa,EAGbD,eAAA,CAAKC,QAAL,EAHa,C;;AA6CjBzB,gCAAA,CAAkB0B,UAAlB,CAA6B3G,eAA7B"}
1
+ {"version":3,"names":["ApplicationMain","constructor","appSlot","appTypeSlot","deploymentProviderSlot","envs","componentAspect","appService","aspectLoader","workspace","logger","dev","ssr","watch","defaultPortRange","registerApp","app","register","listApps","flatten","values","mapApps","toArray","listAppsById","id","undefined","get","toString","getApp","appName","apps","find","name","registerAppType","appType","plugin","AppTypePlugin","registerPlugins","getAppAspect","getAppOrThrow","AppNotFound","computeOptions","opts","defaultOpts","runApp","options","context","createAppContext","runSsr","AppNoSsr","result","port","run","watcher","watchAll","preCompile","catch","err","error","errors","getAppIdOrThrow","maybeApp","ComponentID","fromString","host","getHost","components","list","component","c","isEqual","env","createEnvironment","res","results","data","hostRootDir","getComponentPackagePath","Object","assign","cloneDeep","appComponent","workdir","path","provider","cli","loggerAspect","builder","config","createLogger","ApplicationAspect","AppService","application","appCmd","AppCmd","commands","AppListCmd","RunCmd","AppPlugin","registerBuildTasks","AppsBuildTask","registerSnapTasks","DeployTask","registerTagTasks","registerGroup","AppListCmdDeprecated","MainRuntime","CLIAspect","LoggerAspect","BuilderAspect","EnvsAspect","ComponentAspect","AspectLoaderAspect","WorkspaceAspect","Slot","withType","addRuntime"],"sources":["application.main.runtime.ts"],"sourcesContent":["import { MainRuntime, CLIMain, CLIAspect } from '@teambit/cli';\nimport { flatten, cloneDeep } from 'lodash';\nimport { AspectLoaderMain, AspectLoaderAspect } from '@teambit/aspect-loader';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { BuilderAspect, BuilderMain } from '@teambit/builder';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport ComponentAspect, { ComponentMain, ComponentID } from '@teambit/component';\nimport { ApplicationType } from './application-type';\nimport { Application } from './application';\nimport { DeploymentProvider } from './deployment-provider';\nimport { AppNotFound } from './exceptions';\nimport { ApplicationAspect } from './application.aspect';\nimport { AppListCmdDeprecated } from './app-list.cmd';\nimport { AppsBuildTask } from './build.task';\nimport { RunCmd } from './run.cmd';\nimport { AppService } from './application.service';\nimport { AppCmd, AppListCmd } from './app.cmd';\nimport { AppPlugin } from './app.plugin';\nimport { AppTypePlugin } from './app-type.plugin';\nimport { AppContext } from './app-context';\nimport { DeployTask } from './deploy.task';\nimport { AppNoSsr } from './exceptions/app-no-ssr';\n\nexport type ApplicationTypeSlot = SlotRegistry<ApplicationType<unknown>[]>;\nexport type ApplicationSlot = SlotRegistry<Application[]>;\nexport type DeploymentProviderSlot = SlotRegistry<DeploymentProvider[]>;\n\nexport type ApplicationAspectConfig = {};\n\nexport type ServeAppOptions = {\n /**\n * default port range used to serve applications.\n */\n defaultPortRange?: [start: number, end: number];\n\n /**\n * determine whether to start the application in dev mode.\n */\n dev: boolean;\n\n /**\n * actively watch and compile the workspace (like the bit watch command)\n * @default true\n */\n watch?: boolean;\n\n /**\n * determine whether to start the application in server side mode.\n * @default false\n */\n ssr?: boolean;\n};\n\nexport class ApplicationMain {\n constructor(\n private appSlot: ApplicationSlot,\n // TODO unused\n private appTypeSlot: ApplicationTypeSlot,\n private deploymentProviderSlot: DeploymentProviderSlot,\n private envs: EnvsMain,\n private componentAspect: ComponentMain,\n private appService: AppService,\n private aspectLoader: AspectLoaderMain,\n private workspace: Workspace,\n private logger: Logger\n ) {}\n\n /**\n * register a new app.\n */\n registerApp(app: Application) {\n this.appSlot.register([app]);\n return this;\n }\n\n /**\n * list all registered apps.\n */\n listApps(): Application[] {\n return flatten(this.appSlot.values());\n }\n\n /**\n * map all apps by component ID.\n */\n mapApps() {\n return this.appSlot.toArray();\n }\n\n /**\n * list apps by a component id.\n */\n listAppsById(id?: ComponentID): Application[] | undefined {\n if (!id) return undefined;\n return this.appSlot.get(id.toString());\n }\n\n /**\n * get an app.\n */\n getApp(appName: string, id?: ComponentID): Application | undefined {\n const apps = this.listAppsById(id) || this.listApps();\n return apps.find((app) => app.name === appName);\n }\n\n /**\n * registers a new app and sets a plugin for it.\n */\n registerAppType<T>(appType: ApplicationType<T>) {\n const plugin = new AppTypePlugin(`*.${appType.name}.*`, appType, this.appSlot);\n this.aspectLoader.registerPlugins([plugin]);\n this.appTypeSlot.register([appType]);\n return this;\n }\n\n /**\n * get an app AspectId.\n */\n getAppAspect(appName: string): string | undefined {\n return this.appSlot.toArray().find(([, apps]) => apps.find((app) => app.name === appName))?.[0];\n }\n\n /**\n * get app to throw.\n */\n getAppOrThrow(appName: string) {\n const app = this.getApp(appName);\n if (!app) throw new AppNotFound(appName);\n return app;\n }\n\n defaultOpts: ServeAppOptions = {\n dev: false,\n ssr: false,\n watch: true,\n defaultPortRange: [3100, 3500],\n };\n private computeOptions(opts: Partial<ServeAppOptions> = {}) {\n return {\n ...this.defaultOpts,\n ...opts,\n };\n }\n\n async runApp(appName: string, options?: ServeAppOptions) {\n options = this.computeOptions(options);\n const app = this.getAppOrThrow(appName);\n const context = await this.createAppContext(appName);\n if (!context) throw new AppNotFound(appName);\n\n if (options.ssr) {\n if (!app.runSsr) throw new AppNoSsr(appName);\n\n const result = await app.runSsr(context);\n return { app, ...result };\n }\n\n const port = await app.run(context);\n if (options.watch) {\n this.workspace.watcher\n .watchAll({\n preCompile: false,\n })\n .catch((err) => {\n // don't throw an error, we don't want to break the \"run\" process\n this.logger.error(`compilation failed`, err);\n });\n }\n return { app, port, errors: undefined };\n }\n\n /**\n * get the component ID of a certain app.\n */\n getAppIdOrThrow(appName: string) {\n const maybeApp = this.appSlot.toArray().find(([, apps]) => {\n return apps.find((app) => app.name === appName);\n });\n\n if (!maybeApp) throw new AppNotFound(appName);\n return ComponentID.fromString(maybeApp[0]);\n }\n\n private async createAppContext(appName: string): Promise<AppContext> {\n const host = this.componentAspect.getHost();\n const components = await host.list();\n const id = this.getAppIdOrThrow(appName);\n const component = components.find((c) => c.id.isEqual(id));\n if (!component) throw new AppNotFound(appName);\n // console.log(comp)\n\n const env = await this.envs.createEnvironment([component]);\n const res = await env.run(this.appService);\n const context = res.results[0].data;\n if (!context) throw new AppNotFound(appName);\n const hostRootDir = this.workspace.getComponentPackagePath(component);\n return Object.assign(cloneDeep(context), {\n appName,\n appComponent: component,\n hostRootDir,\n workdir: this.workspace.path,\n });\n }\n\n static runtime = MainRuntime;\n static dependencies = [\n CLIAspect,\n LoggerAspect,\n BuilderAspect,\n EnvsAspect,\n ComponentAspect,\n AspectLoaderAspect,\n WorkspaceAspect,\n ];\n\n static slots = [\n Slot.withType<ApplicationType<unknown>[]>(),\n Slot.withType<Application[]>(),\n Slot.withType<DeploymentProvider[]>(),\n ];\n\n static async provider(\n [cli, loggerAspect, builder, envs, component, aspectLoader, workspace]: [\n CLIMain,\n LoggerMain,\n BuilderMain,\n EnvsMain,\n ComponentMain,\n AspectLoaderMain,\n Workspace\n ],\n config: ApplicationAspectConfig,\n [appTypeSlot, appSlot, deploymentProviderSlot]: [ApplicationTypeSlot, ApplicationSlot, DeploymentProviderSlot]\n ) {\n const logger = loggerAspect.createLogger(ApplicationAspect.id);\n const appService = new AppService();\n const application = new ApplicationMain(\n appSlot,\n appTypeSlot,\n deploymentProviderSlot,\n envs,\n component,\n appService,\n aspectLoader,\n workspace,\n logger\n );\n const appCmd = new AppCmd();\n appCmd.commands = [new AppListCmd(application), new RunCmd(application, logger)];\n aspectLoader.registerPlugins([new AppPlugin(appSlot)]);\n builder.registerBuildTasks([new AppsBuildTask(application)]);\n builder.registerSnapTasks([new DeployTask(application, builder)]);\n builder.registerTagTasks([new DeployTask(application, builder)]);\n cli.registerGroup('apps', 'Applications');\n cli.register(new RunCmd(application, logger), new AppListCmdDeprecated(application), appCmd);\n\n return application;\n }\n}\n\nApplicationAspect.addRuntime(ApplicationMain);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAIA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;;;;;;;AAgCO,MAAMA,eAAN,CAAsB;EAC3BC,WAAW,CACDC,OADC,EAET;EACQC,WAHC,EAIDC,sBAJC,EAKDC,IALC,EAMDC,eANC,EAODC,UAPC,EAQDC,YARC,EASDC,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AA6CjBzB,gCAAA,CAAkB0B,UAAlB,CAA6BpH,eAA7B"}
@@ -0,0 +1,3 @@
1
+ export declare class AppNoSsr extends Error {
2
+ constructor(appName: string);
3
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AppNoSsr = void 0;
7
+
8
+ class AppNoSsr extends Error {
9
+ constructor(appName) {
10
+ super(`app "${appName}" does not support serverside execution`);
11
+ }
12
+
13
+ }
14
+
15
+ exports.AppNoSsr = AppNoSsr;
16
+
17
+ //# sourceMappingURL=app-no-ssr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AppNoSsr","Error","constructor","appName"],"sources":["app-no-ssr.ts"],"sourcesContent":["export class AppNoSsr extends Error {\n constructor(appName: string) {\n super(`app \"${appName}\" does not support serverside execution`);\n }\n}\n"],"mappings":";;;;;;;AAAO,MAAMA,QAAN,SAAuBC,KAAvB,CAA6B;EAClCC,WAAW,CAACC,OAAD,EAAkB;IAC3B,MAAO,QAAOA,OAAQ,yCAAtB;EACD;;AAHiC"}
@@ -7,7 +7,7 @@ exports.AppNotFound = void 0;
7
7
 
8
8
  class AppNotFound extends Error {
9
9
  constructor(appName) {
10
- super(`app ${appName} was not found`);
10
+ super(`app "${appName}" was not found`);
11
11
  }
12
12
 
13
13
  }
@@ -1 +1 @@
1
- {"version":3,"names":["AppNotFound","Error","constructor","appName"],"sources":["app-not-found.ts"],"sourcesContent":["export class AppNotFound extends Error {\n constructor(appName: string) {\n super(`app ${appName} was not found`);\n }\n}\n"],"mappings":";;;;;;;AAAO,MAAMA,WAAN,SAA0BC,KAA1B,CAAgC;EACrCC,WAAW,CAACC,OAAD,EAAkB;IAC3B,MAAO,OAAMA,OAAQ,gBAArB;EACD;;AAHoC"}
1
+ {"version":3,"names":["AppNotFound","Error","constructor","appName"],"sources":["app-not-found.ts"],"sourcesContent":["export class AppNotFound extends Error {\n constructor(appName: string) {\n super(`app \"${appName}\" was not found`);\n }\n}\n"],"mappings":";;;;;;;AAAO,MAAMA,WAAN,SAA0BC,KAA1B,CAAgC;EACrCC,WAAW,CAACC,OAAD,EAAkB;IAC3B,MAAO,QAAOA,OAAQ,iBAAtB;EACD;;AAHoC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { ApplicationAspect } from './application.aspect';
2
2
  export type { ApplicationMain } from './application.main.runtime';
3
- export type { Application, DeployFn } from './application';
3
+ export type { Application, DeployFn, AppResult } from './application';
4
4
  export { AppContext } from './app-context';
5
5
  export { DeploymentProvider } from './deployment-provider';
6
6
  export { ApplicationType } from './application-type';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { ApplicationAspect } from './application.aspect';\nexport type { ApplicationMain } from './application.main.runtime';\nexport type { Application, DeployFn } from './application';\nexport { AppContext } from './app-context';\nexport { DeploymentProvider } from './deployment-provider';\nexport { ApplicationType } from './application-type';\nexport { AppDeployContext } from './app-deploy-context';\nexport { AppBuildContext } from './app-build-context';\nexport { AppBuildResult } from './app-build-result';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { ApplicationAspect } from './application.aspect';\nexport type { ApplicationMain } from './application.main.runtime';\nexport type { Application, DeployFn, AppResult } from './application';\nexport { AppContext } from './app-context';\nexport { DeploymentProvider } from './deployment-provider';\nexport { ApplicationType } from './application-type';\nexport { AppDeployContext } from './app-deploy-context';\nexport { AppBuildContext } from './app-build-context';\nexport { AppBuildResult } from './app-build-result';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA"}
package/dist/run.cmd.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import React from 'react';
2
2
  import { Command, CommandOptions } from '@teambit/cli';
3
3
  import { Logger } from '@teambit/logger';
4
+ import type { RenderResult } from '@teambit/legacy/dist/cli/command';
4
5
  import { ApplicationMain } from './application.main.runtime';
5
6
  declare type RunOptions = {
6
7
  dev: boolean;
7
8
  verbose: boolean;
8
9
  skipWatch: boolean;
10
+ ssr: boolean;
9
11
  };
10
12
  export declare class RunCmd implements Command {
11
13
  /**
@@ -27,6 +29,6 @@ export declare class RunCmd implements Command {
27
29
  * access to the extension instance.
28
30
  */
29
31
  application: ApplicationMain, logger: Logger);
30
- render([appName]: [string], { dev, skipWatch }: RunOptions): Promise<React.ReactElement>;
32
+ render([appName]: [string], { dev, skipWatch, ssr }: RunOptions): Promise<React.ReactElement | RenderResult>;
31
33
  }
32
34
  export {};
package/dist/run.cmd.js CHANGED
@@ -31,6 +31,16 @@ function _react() {
31
31
  return data;
32
32
  }
33
33
 
34
+ function _pluralize() {
35
+ const data = _interopRequireDefault(require("pluralize"));
36
+
37
+ _pluralize = function () {
38
+ return data;
39
+ };
40
+
41
+ return data;
42
+ }
43
+
34
44
  function _ink() {
35
45
  const data = require("ink");
36
46
 
@@ -57,30 +67,52 @@ class RunCmd {
57
67
  }]);
58
68
  (0, _defineProperty2().default)(this, "alias", 'c');
59
69
  (0, _defineProperty2().default)(this, "group", 'apps');
60
- (0, _defineProperty2().default)(this, "options", [['d', 'dev', 'start the application in dev mode.'], ['v', 'verbose', 'showing verbose output for inspection and prints stack trace'], ['', 'skip-watch', 'avoid running the watch process that compiles components in the background']]);
70
+ (0, _defineProperty2().default)(this, "options", [['d', 'dev', 'start the application in dev mode.'], ['v', 'verbose', 'showing verbose output for inspection and prints stack trace'], ['', 'skip-watch', 'avoid running the watch process that compiles components in the background'], ['', 'ssr', 'run app in server side rendering mode.']]);
61
71
  }
62
72
 
63
73
  async render([appName], {
64
74
  dev,
65
- skipWatch
75
+ skipWatch,
76
+ ssr
66
77
  }) {
67
78
  // remove wds logs until refactoring webpack to a worker through the Worker aspect.
68
79
  const {
69
- port
80
+ port,
81
+ errors
70
82
  } = await this.application.runApp(appName, {
71
83
  dev,
72
- skipWatch
84
+ watch: !skipWatch,
85
+ ssr
73
86
  });
74
87
 
88
+ if (errors) {
89
+ return {
90
+ code: 1,
91
+ data: /*#__PURE__*/_react().default.createElement(ShowErrors, {
92
+ errors: errors
93
+ })
94
+ };
95
+ }
96
+
75
97
  if (port) {
76
98
  return /*#__PURE__*/_react().default.createElement(_ink().Text, null, appName, " app is running on http://localhost:", port);
77
99
  }
78
100
 
79
- return /*#__PURE__*/_react().default.createElement(_ink().Text, null, appName, " app is running"); // return <UIServerConsole appName={appName} futureUiServer={uiServer} />;
101
+ return /*#__PURE__*/_react().default.createElement(_ink().Text, null, appName, " app is running");
80
102
  }
81
103
 
82
104
  }
83
105
 
84
106
  exports.RunCmd = RunCmd;
85
107
 
108
+ function ShowErrors({
109
+ errors
110
+ }) {
111
+ return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, /*#__PURE__*/_react().default.createElement(_ink().Newline, null), /*#__PURE__*/_react().default.createElement(_ink().Text, {
112
+ underline: true
113
+ }, "Fatal ", (0, _pluralize().default)('error', errors.length), ":"), errors.map((x, idx) => /*#__PURE__*/_react().default.createElement(_ink().Text, {
114
+ key: idx
115
+ }, x.toString())));
116
+ }
117
+
86
118
  //# sourceMappingURL=run.cmd.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["RunCmd","constructor","application","logger","name","description","render","appName","dev","skipWatch","port","runApp"],"sources":["run.cmd.tsx"],"sourcesContent":["import React from 'react';\nimport { Command, CommandOptions } from '@teambit/cli';\nimport { Text } from 'ink';\nimport { Logger } from '@teambit/logger';\nimport { ApplicationMain } from './application.main.runtime';\n\ntype RunOptions = {\n dev: boolean;\n verbose: boolean;\n skipWatch: boolean;\n};\n\nexport class RunCmd implements Command {\n name = 'run <app-name>';\n description = \"run an app (independent of bit's dev server)\";\n arguments = [\n {\n name: 'app-name',\n description:\n \"the app's name is registered by the app (run 'bit app list' to list the names of the available apps)\",\n },\n ];\n alias = 'c';\n group = 'apps';\n options = [\n ['d', 'dev', 'start the application in dev mode.'],\n ['v', 'verbose', 'showing verbose output for inspection and prints stack trace'],\n ['', 'skip-watch', 'avoid running the watch process that compiles components in the background'],\n ] as CommandOptions;\n\n constructor(\n /**\n * access to the extension instance.\n */\n private application: ApplicationMain,\n\n private logger: Logger\n ) {}\n\n async render([appName]: [string], { dev, skipWatch }: RunOptions): Promise<React.ReactElement> {\n // remove wds logs until refactoring webpack to a worker through the Worker aspect.\n const { port } = await this.application.runApp(appName, {\n dev,\n skipWatch,\n });\n\n if (port) {\n return (\n <Text>\n {appName} app is running on http://localhost:{port}\n </Text>\n );\n }\n return <Text>{appName} app is running</Text>;\n // return <UIServerConsole appName={appName} futureUiServer={uiServer} />;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAUO,MAAMA,MAAN,CAAgC;EAkBrCC,WAAW;EACT;AACJ;AACA;EACYC,WAJC,EAMDC,MANC,EAOT;IAAA,KAHQD,WAGR,GAHQA,WAGR;IAAA,KADQC,MACR,GADQA,MACR;IAAA,8CAxBK,gBAwBL;IAAA,qDAvBY,8CAuBZ;IAAA,mDAtBU,CACV;MACEC,IAAI,EAAE,UADR;MAEEC,WAAW,EACT;IAHJ,CADU,CAsBV;IAAA,+CAfM,GAeN;IAAA,+CAdM,MAcN;IAAA,iDAbQ,CACR,CAAC,GAAD,EAAM,KAAN,EAAa,oCAAb,CADQ,EAER,CAAC,GAAD,EAAM,SAAN,EAAiB,8DAAjB,CAFQ,EAGR,CAAC,EAAD,EAAK,YAAL,EAAmB,4EAAnB,CAHQ,CAaR;EAAE;;EAEQ,MAANC,MAAM,CAAC,CAACC,OAAD,CAAD,EAAsB;IAAEC,GAAF;IAAOC;EAAP,CAAtB,EAAmF;IAC7F;IACA,MAAM;MAAEC;IAAF,IAAW,MAAM,KAAKR,WAAL,CAAiBS,MAAjB,CAAwBJ,OAAxB,EAAiC;MACtDC,GADsD;MAEtDC;IAFsD,CAAjC,CAAvB;;IAKA,IAAIC,IAAJ,EAAU;MACR,oBACE,+BAAC,WAAD,QACGH,OADH,0CACgDG,IADhD,CADF;IAKD;;IACD,oBAAO,+BAAC,WAAD,QAAOH,OAAP,oBAAP,CAd6F,CAe7F;EACD;;AA3CoC"}
1
+ {"version":3,"names":["RunCmd","constructor","application","logger","name","description","render","appName","dev","skipWatch","ssr","port","errors","runApp","watch","code","data","ShowErrors","pluralize","length","map","x","idx","toString"],"sources":["run.cmd.tsx"],"sourcesContent":["import React from 'react';\nimport pluralize from 'pluralize';\nimport { Command, CommandOptions } from '@teambit/cli';\nimport { Newline, Text } from 'ink';\nimport { Logger } from '@teambit/logger';\nimport type { RenderResult } from '@teambit/legacy/dist/cli/command';\nimport { ApplicationMain } from './application.main.runtime';\n\ntype RunOptions = {\n dev: boolean;\n verbose: boolean;\n skipWatch: boolean;\n ssr: boolean;\n};\n\nexport class RunCmd implements Command {\n name = 'run <app-name>';\n description = \"run an app (independent of bit's dev server)\";\n arguments = [\n {\n name: 'app-name',\n description:\n \"the app's name is registered by the app (run 'bit app list' to list the names of the available apps)\",\n },\n ];\n alias = 'c';\n group = 'apps';\n options = [\n ['d', 'dev', 'start the application in dev mode.'],\n ['v', 'verbose', 'showing verbose output for inspection and prints stack trace'],\n ['', 'skip-watch', 'avoid running the watch process that compiles components in the background'],\n ['', 'ssr', 'run app in server side rendering mode.'],\n ] as CommandOptions;\n\n constructor(\n /**\n * access to the extension instance.\n */\n private application: ApplicationMain,\n\n private logger: Logger\n ) {}\n\n async render([appName]: [string], { dev, skipWatch, ssr }: RunOptions): Promise<React.ReactElement | RenderResult> {\n // remove wds logs until refactoring webpack to a worker through the Worker aspect.\n const { port, errors } = await this.application.runApp(appName, {\n dev,\n watch: !skipWatch,\n ssr,\n });\n\n if (errors) {\n return {\n code: 1,\n data: <ShowErrors errors={errors} />,\n };\n }\n\n if (port) {\n return (\n <Text>\n {appName} app is running on http://localhost:{port}\n </Text>\n );\n }\n return <Text>{appName} app is running</Text>;\n }\n}\n\nfunction ShowErrors({ errors }: { errors: Error[] }) {\n return (\n <>\n <Newline />\n <Text underline>Fatal {pluralize('error', errors.length)}:</Text>\n {errors.map((x, idx) => (\n <Text key={idx}>{x.toString()}</Text>\n ))}\n </>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAYO,MAAMA,MAAN,CAAgC;EAmBrCC,WAAW;EACT;AACJ;AACA;EACYC,WAJC,EAMDC,MANC,EAOT;IAAA,KAHQD,WAGR,GAHQA,WAGR;IAAA,KADQC,MACR,GADQA,MACR;IAAA,8CAzBK,gBAyBL;IAAA,qDAxBY,8CAwBZ;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EA;EAAX,GAAiBD,CAAC,CAACE,QAAF,EAAjB,CADD,CAHH,CADF;AASD"}
@@ -0,0 +1,5 @@
1
+ export class AppNoSsr extends Error {
2
+ constructor(appName: string) {
3
+ super(`app "${appName}" does not support serverside execution`);
4
+ }
5
+ }
@@ -1,5 +1,5 @@
1
1
  export class AppNotFound extends Error {
2
2
  constructor(appName: string) {
3
- super(`app ${appName} was not found`);
3
+ super(`app "${appName}" was not found`);
4
4
  }
5
5
  }
package/package.json CHANGED
@@ -1,34 +1,36 @@
1
1
  {
2
2
  "name": "@teambit/application",
3
- "version": "0.0.444",
3
+ "version": "0.0.447",
4
4
  "homepage": "https://bit.dev/teambit/harmony/application",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.harmony",
8
8
  "name": "application",
9
- "version": "0.0.444"
9
+ "version": "0.0.447"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "2.4.2",
13
13
  "lodash": "4.17.21",
14
14
  "p-map-series": "2.1.0",
15
15
  "ink": "3.2.0",
16
+ "pluralize": "8.0.0",
16
17
  "@babel/runtime": "7.12.18",
17
18
  "core-js": "^3.0.0",
18
19
  "@teambit/harmony": "0.3.3",
19
- "@teambit/builder": "0.0.802",
20
- "@teambit/component": "0.0.802",
21
- "@teambit/isolator": "0.0.802",
22
- "@teambit/envs": "0.0.802",
20
+ "@teambit/builder": "0.0.805",
21
+ "@teambit/component": "0.0.805",
22
+ "@teambit/isolator": "0.0.805",
23
+ "@teambit/envs": "0.0.805",
23
24
  "@teambit/cli-table": "0.0.34",
24
- "@teambit/cli": "0.0.534",
25
- "@teambit/aspect-loader": "0.0.802",
26
- "@teambit/logger": "0.0.627",
27
- "@teambit/workspace": "0.0.802"
25
+ "@teambit/cli": "0.0.536",
26
+ "@teambit/aspect-loader": "0.0.805",
27
+ "@teambit/logger": "0.0.629",
28
+ "@teambit/workspace": "0.0.805"
28
29
  },
29
30
  "devDependencies": {
30
31
  "@types/react": "^17.0.8",
31
32
  "@types/lodash": "4.14.165",
33
+ "@types/pluralize": "0.0.29",
32
34
  "@types/mocha": "9.1.0",
33
35
  "@types/testing-library__jest-dom": "5.9.5",
34
36
  "@types/jest": "^26.0.0",
@@ -36,7 +38,7 @@
36
38
  "@types/node": "12.20.4"
37
39
  },
38
40
  "peerDependencies": {
39
- "@teambit/legacy": "1.0.316",
41
+ "@teambit/legacy": "1.0.319",
40
42
  "react-dom": "^16.8.0 || ^17.0.0",
41
43
  "react": "^16.8.0 || ^17.0.0"
42
44
  },
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_application@0.0.444/dist/application.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_application@0.0.444/dist/application.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_application@0.0.447/dist/application.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_application@0.0.447/dist/application.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/run.cmd.tsx CHANGED
@@ -1,13 +1,16 @@
1
1
  import React from 'react';
2
+ import pluralize from 'pluralize';
2
3
  import { Command, CommandOptions } from '@teambit/cli';
3
- import { Text } from 'ink';
4
+ import { Newline, Text } from 'ink';
4
5
  import { Logger } from '@teambit/logger';
6
+ import type { RenderResult } from '@teambit/legacy/dist/cli/command';
5
7
  import { ApplicationMain } from './application.main.runtime';
6
8
 
7
9
  type RunOptions = {
8
10
  dev: boolean;
9
11
  verbose: boolean;
10
12
  skipWatch: boolean;
13
+ ssr: boolean;
11
14
  };
12
15
 
13
16
  export class RunCmd implements Command {
@@ -26,6 +29,7 @@ export class RunCmd implements Command {
26
29
  ['d', 'dev', 'start the application in dev mode.'],
27
30
  ['v', 'verbose', 'showing verbose output for inspection and prints stack trace'],
28
31
  ['', 'skip-watch', 'avoid running the watch process that compiles components in the background'],
32
+ ['', 'ssr', 'run app in server side rendering mode.'],
29
33
  ] as CommandOptions;
30
34
 
31
35
  constructor(
@@ -37,13 +41,21 @@ export class RunCmd implements Command {
37
41
  private logger: Logger
38
42
  ) {}
39
43
 
40
- async render([appName]: [string], { dev, skipWatch }: RunOptions): Promise<React.ReactElement> {
44
+ async render([appName]: [string], { dev, skipWatch, ssr }: RunOptions): Promise<React.ReactElement | RenderResult> {
41
45
  // remove wds logs until refactoring webpack to a worker through the Worker aspect.
42
- const { port } = await this.application.runApp(appName, {
46
+ const { port, errors } = await this.application.runApp(appName, {
43
47
  dev,
44
- skipWatch,
48
+ watch: !skipWatch,
49
+ ssr,
45
50
  });
46
51
 
52
+ if (errors) {
53
+ return {
54
+ code: 1,
55
+ data: <ShowErrors errors={errors} />,
56
+ };
57
+ }
58
+
47
59
  if (port) {
48
60
  return (
49
61
  <Text>
@@ -52,6 +64,17 @@ export class RunCmd implements Command {
52
64
  );
53
65
  }
54
66
  return <Text>{appName} app is running</Text>;
55
- // return <UIServerConsole appName={appName} futureUiServer={uiServer} />;
56
67
  }
57
68
  }
69
+
70
+ function ShowErrors({ errors }: { errors: Error[] }) {
71
+ return (
72
+ <>
73
+ <Newline />
74
+ <Text underline>Fatal {pluralize('error', errors.length)}:</Text>
75
+ {errors.map((x, idx) => (
76
+ <Text key={idx}>{x.toString()}</Text>
77
+ ))}
78
+ </>
79
+ );
80
+ }