@teambit/bundler 0.0.568 → 0.0.572

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.
@@ -0,0 +1,150 @@
1
+ import { EnvService, ExecutionContext, EnvDefinition } from '@teambit/envs';
2
+ import { PubsubMain } from '@teambit/pubsub';
3
+ import { flatten } from 'lodash';
4
+ import React from 'react';
5
+ import { Text, Newline } from 'ink';
6
+ import highlight from 'cli-highlight';
7
+ import { BrowserRuntimeSlot } from './bundler.main.runtime';
8
+ import { ComponentServer } from './component-server';
9
+ import { dedupEnvs } from './dedup-envs';
10
+ import { DevServer } from './dev-server';
11
+ import { DevServerContext } from './dev-server-context';
12
+ import { getEntry } from './get-entry';
13
+
14
+ export type DevServerServiceOptions = { dedicatedEnvDevServers?: string[] };
15
+
16
+ export type DevServerDescriptor = {
17
+ /**
18
+ * id of the dev server (e.g. jest/mocha)
19
+ */
20
+ id: string;
21
+
22
+ /**
23
+ * display name of the dev server (e.g. Jest / Mocha)
24
+ */
25
+ displayName: string;
26
+
27
+ /**
28
+ * icon of the configured dev server.
29
+ */
30
+ icon: string;
31
+
32
+ /**
33
+ * string containing the config for display.
34
+ */
35
+ config: string;
36
+
37
+ version?: string;
38
+ };
39
+
40
+ export class DevServerService implements EnvService<ComponentServer, DevServerDescriptor> {
41
+ name = 'dev server';
42
+
43
+ constructor(
44
+ /**
45
+ * browser runtime slot
46
+ */
47
+ private pubsub: PubsubMain,
48
+
49
+ /**
50
+ * browser runtime slot
51
+ */
52
+ private runtimeSlot: BrowserRuntimeSlot
53
+ ) {}
54
+
55
+ async render(env: EnvDefinition, context: ExecutionContext[]) {
56
+ const descriptor = await this.getDescriptor(env, context);
57
+ return (
58
+ <Text key={descriptor?.id}>
59
+ <Text color="cyan">configured dev server: </Text>
60
+ <Text>
61
+ {descriptor?.id} ({descriptor?.displayName} @ {descriptor?.version})
62
+ </Text>
63
+ <Newline />
64
+ <Text underline color="cyan">
65
+ dev server config:
66
+ </Text>
67
+ <Newline />
68
+ <Text>
69
+ {/* refactor a separate component which highlights for cli */}
70
+ {highlight(descriptor?.config || '', { language: 'javascript', ignoreIllegals: true })}
71
+ </Text>
72
+ <Newline />
73
+ </Text>
74
+ );
75
+ }
76
+
77
+ async getDescriptor(
78
+ environment: EnvDefinition,
79
+ context?: ExecutionContext[]
80
+ ): Promise<DevServerDescriptor | undefined> {
81
+ if (!environment.env.getDevServer || !context) return undefined;
82
+ const mergedContext = await this.buildContext(context[0], []);
83
+ const devServer: DevServer = environment.env.getDevServer(mergedContext);
84
+
85
+ return {
86
+ id: devServer.id || '',
87
+ displayName: devServer.displayName || '',
88
+ icon: devServer.icon || '',
89
+ config: devServer.displayConfig ? devServer.displayConfig() : '',
90
+ version: devServer.version ? devServer.version() : '?',
91
+ };
92
+ }
93
+
94
+ // async run(context: ExecutionContext): Promise<ComponentServer[]> {
95
+ // const devServerContext = await this.buildContext(context);
96
+ // const devServer: DevServer = context.env.getDevServer(devServerContext);
97
+ // const port = await selectPort();
98
+ // // TODO: refactor to replace with a component server instance.
99
+ // return new ComponentServer(this.pubsub, context, port, devServer);
100
+ // }
101
+
102
+ async runOnce(
103
+ contexts: ExecutionContext[],
104
+ { dedicatedEnvDevServers }: DevServerServiceOptions
105
+ ): Promise<ComponentServer[]> {
106
+ const groupedEnvs = dedupEnvs(contexts, dedicatedEnvDevServers);
107
+
108
+ const servers = await Promise.all(
109
+ Object.entries(groupedEnvs).map(async ([id, contextList]) => {
110
+ const mainContext = contextList.find((context) => context.envDefinition.id === id) || contextList[0];
111
+ const additionalContexts = contextList.filter((context) => context.envDefinition.id !== id);
112
+
113
+ const devServerContext = await this.buildContext(mainContext, additionalContexts);
114
+ const devServer: DevServer = await devServerContext.envRuntime.env.getDevServer(devServerContext);
115
+
116
+ return new ComponentServer(this.pubsub, devServerContext, [3300, 3400], devServer);
117
+ })
118
+ );
119
+
120
+ return servers;
121
+ }
122
+
123
+ mergeContext() {}
124
+
125
+ private getComponentsFromContexts(contexts: ExecutionContext[]) {
126
+ return flatten(
127
+ contexts.map((context) => {
128
+ return context.components;
129
+ })
130
+ );
131
+ }
132
+
133
+ /**
134
+ * builds the execution context for the dev server.
135
+ */
136
+ private async buildContext(
137
+ context: ExecutionContext,
138
+ additionalContexts: ExecutionContext[] = []
139
+ ): Promise<DevServerContext> {
140
+ context.relatedContexts = additionalContexts.map((ctx) => ctx.envDefinition.id);
141
+ context.components = context.components.concat(this.getComponentsFromContexts(additionalContexts));
142
+
143
+ return Object.assign(context, {
144
+ entry: await getEntry(context, this.runtimeSlot),
145
+ // don't start with a leading "/" because it generates errors on Windows
146
+ rootPath: `preview/${context.envRuntime.id}`,
147
+ publicPath: `/public`,
148
+ });
149
+ }
150
+ }
@@ -0,0 +1,20 @@
1
+ /* eslint-disable max-classes-per-file */
2
+
3
+ import { BitBaseEvent } from '@teambit/pubsub';
4
+
5
+ class ComponentsServerStartedEventData {
6
+ constructor(readonly componentsServer, readonly context, readonly hostname, readonly port) {}
7
+ }
8
+
9
+ export class ComponentsServerStartedEvent extends BitBaseEvent<ComponentsServerStartedEventData> {
10
+ static readonly TYPE = 'components-server-started';
11
+
12
+ constructor(readonly timestamp, readonly componentsServer, readonly context, readonly hostname, readonly port) {
13
+ super(
14
+ ComponentsServerStartedEvent.TYPE,
15
+ '0.0.1',
16
+ timestamp,
17
+ new ComponentsServerStartedEventData(componentsServer, context, hostname, port)
18
+ );
19
+ }
20
+ }
@@ -0,0 +1 @@
1
+ export * from './components-server-started-event';
@@ -0,0 +1 @@
1
+ export class BindError extends Error {}
@@ -0,0 +1 @@
1
+ export { BindError } from './bind-error';
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/bundler",
3
- "version": "0.0.568",
3
+ "version": "0.0.572",
4
4
  "homepage": "https://bit.dev/teambit/compilation/bundler",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.compilation",
8
8
  "name": "bundler",
9
- "version": "0.0.568"
9
+ "version": "0.0.572"
10
10
  },
11
11
  "dependencies": {
12
12
  "@teambit/harmony": "0.2.11",
@@ -15,13 +15,13 @@
15
15
  "lodash": "4.17.21",
16
16
  "@babel/runtime": "7.12.18",
17
17
  "core-js": "^3.0.0",
18
- "@teambit/envs": "0.0.568",
19
- "@teambit/cli": "0.0.394",
20
- "@teambit/component": "0.0.568",
21
- "@teambit/graphql": "0.0.568",
22
- "@teambit/pubsub": "0.0.568",
23
- "@teambit/builder": "0.0.568",
24
- "@teambit/toolbox.network.get-port": "0.0.98"
18
+ "@teambit/envs": "0.0.572",
19
+ "@teambit/cli": "0.0.395",
20
+ "@teambit/component": "0.0.572",
21
+ "@teambit/graphql": "0.0.572",
22
+ "@teambit/pubsub": "0.0.572",
23
+ "@teambit/builder": "0.0.572",
24
+ "@teambit/toolbox.network.get-port": "0.0.99"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/lodash": "4.14.165",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@apollo/client": "^3.0.0",
37
- "@teambit/legacy": "1.0.180",
37
+ "@teambit/legacy": "1.0.181",
38
38
  "react-dom": "^16.8.0 || ^17.0.0",
39
39
  "react": "^16.8.0 || ^17.0.0"
40
40
  },
@@ -62,27 +62,12 @@
62
62
  "react": "-"
63
63
  },
64
64
  "peerDependencies": {
65
- "@teambit/legacy": "1.0.180",
65
+ "@teambit/legacy": "1.0.181",
66
66
  "react-dom": "^16.8.0 || ^17.0.0",
67
67
  "react": "^16.8.0 || ^17.0.0"
68
68
  }
69
69
  }
70
70
  },
71
- "files": [
72
- "dist",
73
- "!dist/tsconfig.tsbuildinfo",
74
- "**/*.md",
75
- "**/*.mdx",
76
- "**/*.js",
77
- "**/*.json",
78
- "**/*.sass",
79
- "**/*.scss",
80
- "**/*.less",
81
- "**/*.css",
82
- "**/*.css",
83
- "**/*.jpeg",
84
- "**/*.gif"
85
- ],
86
71
  "private": false,
87
72
  "engines": {
88
73
  "node": ">=12.22.0"
@@ -0,0 +1,29 @@
1
+ declare module '*.png' {
2
+ const value: any;
3
+ export = value;
4
+ }
5
+ declare module '*.svg' {
6
+ import type { FunctionComponent, SVGProps } from 'react';
7
+
8
+ export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
9
+ const src: string;
10
+ export default src;
11
+ }
12
+
13
+ // @TODO Gilad
14
+ declare module '*.jpg' {
15
+ const value: any;
16
+ export = value;
17
+ }
18
+ declare module '*.jpeg' {
19
+ const value: any;
20
+ export = value;
21
+ }
22
+ declare module '*.gif' {
23
+ const value: any;
24
+ export = value;
25
+ }
26
+ declare module '*.bmp' {
27
+ const value: any;
28
+ export = value;
29
+ }
@@ -0,0 +1,42 @@
1
+ declare module '*.module.css' {
2
+ const classes: { readonly [key: string]: string };
3
+ export default classes;
4
+ }
5
+ declare module '*.module.scss' {
6
+ const classes: { readonly [key: string]: string };
7
+ export default classes;
8
+ }
9
+ declare module '*.module.sass' {
10
+ const classes: { readonly [key: string]: string };
11
+ export default classes;
12
+ }
13
+
14
+ declare module '*.module.less' {
15
+ const classes: { readonly [key: string]: string };
16
+ export default classes;
17
+ }
18
+
19
+ declare module '*.less' {
20
+ const classes: { readonly [key: string]: string };
21
+ export default classes;
22
+ }
23
+
24
+ declare module '*.css' {
25
+ const classes: { readonly [key: string]: string };
26
+ export default classes;
27
+ }
28
+
29
+ declare module '*.sass' {
30
+ const classes: { readonly [key: string]: string };
31
+ export default classes;
32
+ }
33
+
34
+ declare module '*.scss' {
35
+ const classes: { readonly [key: string]: string };
36
+ export default classes;
37
+ }
38
+
39
+ declare module '*.mdx' {
40
+ const component: any;
41
+ export default component;
42
+ }