@teambit/preview 1.0.227 → 1.0.229
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/artifacts/__bit_junit.xml +1 -1
- package/artifacts/preview/teambit_preview_preview-preview.js +1 -1
- package/artifacts/schema.json +891 -207
- package/dist/artifact-file-middleware.d.ts +12 -0
- package/dist/bundler/chunks.d.ts +17 -0
- package/dist/bundler/create-peer-link.spec.d.ts +1 -0
- package/dist/bundler/create-peers-link.d.ts +2 -0
- package/dist/bundler/html-plugin.d.ts +5 -0
- package/dist/bundler/html-template.d.ts +2 -0
- package/dist/bundling-strategy.d.ts +23 -0
- package/dist/component-preview.d.ts +2 -0
- package/dist/component-preview.route.d.ts +20 -0
- package/dist/env-preview-template.task.d.ts +45 -0
- package/dist/env-template.route.d.ts +25 -0
- package/dist/events/click-inside-an-iframe.d.ts +12 -0
- package/dist/events/index.d.ts +1 -0
- package/dist/exceptions/bundling-strategy-not-found.d.ts +4 -0
- package/dist/exceptions/index.d.ts +4 -0
- package/dist/exceptions/preview-artifact-not-found.d.ts +5 -0
- package/dist/exceptions/preview-not-found.d.ts +3 -0
- package/dist/exceptions/preview-output-file-not-found.d.ts +5 -0
- package/dist/execution-ref.d.ts +11 -0
- package/dist/generate-link.d.ts +9 -0
- package/dist/gql/fetch-component-aspects.d.ts +1 -0
- package/dist/html-utils.d.ts +6 -0
- package/dist/index.d.ts +9 -0
- package/dist/mk-temp-dir.d.ts +1 -0
- package/dist/pre-bundle-utils.d.ts +12 -0
- package/dist/pre-bundle.d.ts +8 -0
- package/dist/pre-bundle.task.d.ts +15 -0
- package/dist/{preview-1712719054377.js → preview-1712822929999.js} +2 -2
- package/dist/preview-artifact.d.ts +8 -0
- package/dist/preview-assets.route.d.ts +19 -0
- package/dist/preview-context.d.ts +4 -0
- package/dist/preview-definition.d.ts +34 -0
- package/dist/preview-env.d.ts +39 -0
- package/dist/preview-modules.d.ts +1 -0
- package/dist/preview-type.d.ts +25 -0
- package/dist/preview.aspect.d.ts +4 -0
- package/dist/preview.composition.d.ts +1 -0
- package/dist/preview.d.ts +11 -0
- package/dist/preview.graphql.d.ts +32 -0
- package/dist/preview.main.runtime.d.ts +343 -0
- package/dist/preview.preview.runtime.d.ts +77 -0
- package/dist/preview.route.d.ts +20 -0
- package/dist/preview.service.d.ts +29 -0
- package/dist/preview.start-plugin.d.ts +35 -0
- package/dist/preview.task.d.ts +39 -0
- package/dist/rendering-context.d.ts +18 -0
- package/dist/size-event.d.ts +9 -0
- package/dist/strategies/component-strategy.d.ts +54 -0
- package/dist/strategies/env-strategy.d.ts +41 -0
- package/dist/strategies/generate-component-link.d.ts +6 -0
- package/dist/strategies/index.d.ts +3 -0
- package/dist/strategies/strategies-names.d.ts +2 -0
- package/dist/types/preview-module.d.ts +1 -0
- package/dist/webpack/webpack.config.d.ts +2 -0
- package/package.json +23 -23
- package/tsconfig.json +1 -61
@@ -0,0 +1,343 @@
|
|
1
|
+
import type { BuilderMain } from '@teambit/builder';
|
2
|
+
import { Asset, BundlerMain } from '@teambit/bundler';
|
3
|
+
import { PubsubMain } from '@teambit/pubsub';
|
4
|
+
import { Component, ComponentMain, ComponentMap, ComponentID, ResolveAspectsOptions } from '@teambit/component';
|
5
|
+
import type { EnvsMain, PreviewEnv } from '@teambit/envs';
|
6
|
+
import { SlotRegistry, Harmony } from '@teambit/harmony';
|
7
|
+
import { UiMain, UIRoot } from '@teambit/ui';
|
8
|
+
import { CacheMain } from '@teambit/cache';
|
9
|
+
import { PkgMain } from '@teambit/pkg';
|
10
|
+
import type { AspectDefinition, AspectLoaderMain } from '@teambit/aspect-loader';
|
11
|
+
import { Workspace } from '@teambit/workspace';
|
12
|
+
import { LoggerMain, Logger } from '@teambit/logger';
|
13
|
+
import type { DependencyResolverMain } from '@teambit/dependency-resolver';
|
14
|
+
import { WatcherMain } from '@teambit/watcher';
|
15
|
+
import { GraphqlMain } from '@teambit/graphql';
|
16
|
+
import { ScopeMain } from '@teambit/scope';
|
17
|
+
import { MainModulesMap } from './generate-link';
|
18
|
+
import { PreviewArtifact } from './preview-artifact';
|
19
|
+
import { PreviewDefinition } from './preview-definition';
|
20
|
+
import { BundlingStrategy } from './bundling-strategy';
|
21
|
+
export type PreviewDefinitionRegistry = SlotRegistry<PreviewDefinition>;
|
22
|
+
export type PreviewStrategyName = 'env' | 'component';
|
23
|
+
export type PreviewFiles = {
|
24
|
+
files: string[];
|
25
|
+
isBundledWithEnv: boolean;
|
26
|
+
};
|
27
|
+
export type ComponentPreviewSizedFile = Asset;
|
28
|
+
export type ComponentPreviewSize = {
|
29
|
+
files: ComponentPreviewSizedFile[];
|
30
|
+
assets: ComponentPreviewSizedFile[];
|
31
|
+
totalFiles: number;
|
32
|
+
compressedTotalFiles?: number;
|
33
|
+
totalAssets: number;
|
34
|
+
compressedTotalAssets?: number;
|
35
|
+
total: number;
|
36
|
+
compressedTotal?: number;
|
37
|
+
};
|
38
|
+
export type ComponentPreviewMetaData = {
|
39
|
+
size?: ComponentPreviewSize;
|
40
|
+
};
|
41
|
+
export type PreviewVariantConfig = {
|
42
|
+
isScaling?: boolean;
|
43
|
+
};
|
44
|
+
/**
|
45
|
+
* Preview data that stored on the component on load
|
46
|
+
*/
|
47
|
+
export type PreviewComponentData = PreviewAnyComponentData & PreviewEnvComponentData;
|
48
|
+
/**
|
49
|
+
* Preview data that stored on the component on load for any component
|
50
|
+
*/
|
51
|
+
export type PreviewAnyComponentData = {
|
52
|
+
doesScaling?: boolean;
|
53
|
+
/**
|
54
|
+
* The strategy configured by the component's env
|
55
|
+
*/
|
56
|
+
strategyName?: PreviewStrategyName;
|
57
|
+
/**
|
58
|
+
* Does the component has a bundle for the component itself (separated from the compositions/docs)
|
59
|
+
* Calculated by the component's env
|
60
|
+
*/
|
61
|
+
splitComponentBundle?: boolean;
|
62
|
+
/**
|
63
|
+
* don't allow other aspects implementing a preview definition to be included in your preview.
|
64
|
+
*/
|
65
|
+
onlyOverview?: boolean;
|
66
|
+
/**
|
67
|
+
* use name query params to select a specific composition to render.
|
68
|
+
*/
|
69
|
+
useNameParam?: boolean;
|
70
|
+
/**
|
71
|
+
* don't allow other aspects implementing a preview definition to be included in your preview.
|
72
|
+
*/
|
73
|
+
skipIncludes?: boolean;
|
74
|
+
};
|
75
|
+
/**
|
76
|
+
* Preview data that stored on the component on load if the component is an env
|
77
|
+
*/
|
78
|
+
export type PreviewEnvComponentData = {
|
79
|
+
isScaling?: boolean;
|
80
|
+
supportsOnlyOverview?: boolean;
|
81
|
+
supportsUseNameParam?: boolean;
|
82
|
+
};
|
83
|
+
export type PreviewConfig = {
|
84
|
+
bundlingStrategy?: string;
|
85
|
+
disabled: boolean;
|
86
|
+
/**
|
87
|
+
* limit concurrent components when running the bundling step for your bundler during generate components preview task.
|
88
|
+
* this helps mitigate large memory consumption for the build pipeline. This may increase the overall time for the generate-preview task, but reduce memory footprint.
|
89
|
+
* default - no limit.
|
90
|
+
*/
|
91
|
+
maxChunkSize?: number;
|
92
|
+
onlyOverview?: boolean;
|
93
|
+
};
|
94
|
+
export type EnvPreviewConfig = {
|
95
|
+
strategyName?: PreviewStrategyName;
|
96
|
+
splitComponentBundle?: boolean;
|
97
|
+
};
|
98
|
+
export type BundlingStrategySlot = SlotRegistry<BundlingStrategy>;
|
99
|
+
export type GenerateLinkFn = (prefix: string, componentMap: ComponentMap<string[]>, defaultModule?: string) => string;
|
100
|
+
export declare class PreviewMain {
|
101
|
+
/**
|
102
|
+
* harmony context.
|
103
|
+
*/
|
104
|
+
private harmony;
|
105
|
+
/**
|
106
|
+
* slot for preview definitions.
|
107
|
+
*/
|
108
|
+
private previewSlot;
|
109
|
+
private ui;
|
110
|
+
private cache;
|
111
|
+
private envs;
|
112
|
+
private componentAspect;
|
113
|
+
private pkg;
|
114
|
+
private aspectLoader;
|
115
|
+
readonly config: PreviewConfig;
|
116
|
+
private bundlingStrategySlot;
|
117
|
+
private builder;
|
118
|
+
private workspace;
|
119
|
+
private logger;
|
120
|
+
private dependencyResolver;
|
121
|
+
constructor(
|
122
|
+
/**
|
123
|
+
* harmony context.
|
124
|
+
*/
|
125
|
+
harmony: Harmony,
|
126
|
+
/**
|
127
|
+
* slot for preview definitions.
|
128
|
+
*/
|
129
|
+
previewSlot: PreviewDefinitionRegistry, ui: UiMain, cache: CacheMain, envs: EnvsMain, componentAspect: ComponentMain, pkg: PkgMain, aspectLoader: AspectLoaderMain, config: PreviewConfig, bundlingStrategySlot: BundlingStrategySlot, builder: BuilderMain, workspace: Workspace | undefined, logger: Logger, dependencyResolver: DependencyResolverMain);
|
130
|
+
get tempFolder(): string;
|
131
|
+
getComponentBundleSize(component: Component): ComponentPreviewSize | undefined;
|
132
|
+
getPreview(component: Component): Promise<PreviewArtifact | undefined>;
|
133
|
+
/**
|
134
|
+
* Get a list of all the artifact files generated during the GeneratePreview task
|
135
|
+
* @param component
|
136
|
+
* @returns
|
137
|
+
*/
|
138
|
+
getPreviewFiles(component: Component): Promise<PreviewFiles | undefined>;
|
139
|
+
/**
|
140
|
+
* Get the preview config of the component.
|
141
|
+
* (config that was set by variants or on bitmap)
|
142
|
+
* @param component
|
143
|
+
* @returns
|
144
|
+
*/
|
145
|
+
getPreviewAspectConfig(component: Component): PreviewVariantConfig | undefined;
|
146
|
+
/**
|
147
|
+
* Get the preview data of the component.
|
148
|
+
* (data that was calculated during the on load process)
|
149
|
+
* @param component
|
150
|
+
* @returns
|
151
|
+
*/
|
152
|
+
getPreviewData(component: Component): PreviewComponentData | undefined;
|
153
|
+
/**
|
154
|
+
* check if the current version of env component supports skipping other included previews
|
155
|
+
* @param envComponent
|
156
|
+
* @returns
|
157
|
+
*/
|
158
|
+
doesEnvIncludesOnlyOverview(envComponent: Component): boolean;
|
159
|
+
/**
|
160
|
+
* check if the current version of env component supports name query param
|
161
|
+
* @param envComponent
|
162
|
+
* @returns
|
163
|
+
*/
|
164
|
+
doesEnvUseNameParam(envComponent: Component): boolean;
|
165
|
+
private calculateIncludeOnlyOverview;
|
166
|
+
private calculateUseNameParam;
|
167
|
+
/**
|
168
|
+
* Calculate preview data on component load
|
169
|
+
* @param component
|
170
|
+
* @returns
|
171
|
+
*/
|
172
|
+
calcPreviewData(component: Component): Promise<PreviewComponentData>;
|
173
|
+
/**
|
174
|
+
* Calculate preview data on component that configured by its env
|
175
|
+
* @param component
|
176
|
+
* @returns
|
177
|
+
*/
|
178
|
+
calcPreviewDataFromEnv(component: Component): Promise<Omit<PreviewAnyComponentData, 'doesScaling' | 'onlyOverview' | 'useNameParam'> | undefined>;
|
179
|
+
/**
|
180
|
+
* calculate extra preview data for env components (on load)
|
181
|
+
* @param envComponent
|
182
|
+
* @returns
|
183
|
+
*/
|
184
|
+
private calculateDataForEnvComponent;
|
185
|
+
/**
|
186
|
+
* Check if the component preview bundle contain the env as part of the bundle or only the component code
|
187
|
+
* (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)
|
188
|
+
* This should be used only for calculating the value on load.
|
189
|
+
* otherwise, use the isBundledWithEnv function
|
190
|
+
* @param component
|
191
|
+
* @returns
|
192
|
+
*/
|
193
|
+
calcIsBundledWithEnv(component: Component): Promise<boolean>;
|
194
|
+
/**
|
195
|
+
* Check if the component preview bundle contain the env as part of the bundle or only the component code
|
196
|
+
* (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)
|
197
|
+
* @param component
|
198
|
+
* @returns
|
199
|
+
*/
|
200
|
+
isBundledWithEnv(component: Component): Promise<boolean>;
|
201
|
+
/**
|
202
|
+
* This is a legacy calculation for the isBundledWithEnv
|
203
|
+
* This calc is based on the component artifacts which is very expensive operation as it requires to fetch and load the artifacts
|
204
|
+
* See the new implementation in the isBundledWithEnv method
|
205
|
+
* @param component
|
206
|
+
* @returns
|
207
|
+
*/
|
208
|
+
private isBundledWithEnvBackward;
|
209
|
+
private calcDoesScalingForComponent;
|
210
|
+
/**
|
211
|
+
* can the current component preview scale in size for different preview sizes.
|
212
|
+
* this calculation is based on the env of the component and if the env of the component support it.
|
213
|
+
*/
|
214
|
+
doesScaling(component: Component): Promise<boolean>;
|
215
|
+
/**
|
216
|
+
* Check if the current version of the env support scaling
|
217
|
+
* @param envComponent
|
218
|
+
* @returns
|
219
|
+
*/
|
220
|
+
isEnvSupportScaling(envComponent: Component): boolean;
|
221
|
+
isSupportSkipIncludes(component: Component): Promise<boolean>;
|
222
|
+
/**
|
223
|
+
* check if the component preview should only include the overview (skipping rendering of the compostions and properties table)
|
224
|
+
*/
|
225
|
+
getOnlyOverview(component: Component): Promise<boolean>;
|
226
|
+
/**
|
227
|
+
* check if the component preview should include the name query param
|
228
|
+
*/
|
229
|
+
getUseNameParam(component: Component): Promise<boolean>;
|
230
|
+
/**
|
231
|
+
* This function is calculate the isScaling support flag for the component preview.
|
232
|
+
* This is calculated only for the env component and not for the component itself.
|
233
|
+
* It should be only used during the (env) component on load.
|
234
|
+
* Once the component load, you should only use the `isEnvSupportScaling` to fetch it from the calculated data.
|
235
|
+
* If you want to check if an env for a given component support scaling, use the `isScaling` function.
|
236
|
+
* @param component
|
237
|
+
* @returns
|
238
|
+
*/
|
239
|
+
private calculateIsEnvSupportScaling;
|
240
|
+
/**
|
241
|
+
* Check if the component preview bundle contain the header inside of it (legacy)
|
242
|
+
* today we are not including the header inside anymore
|
243
|
+
* @param component
|
244
|
+
* @returns
|
245
|
+
*/
|
246
|
+
isLegacyHeader(component: Component): Promise<boolean>;
|
247
|
+
/**
|
248
|
+
* Getting the env template artifact
|
249
|
+
* This should be called with the env itself or it will return undefined
|
250
|
+
* If you want to get the env template from the env of the component,
|
251
|
+
* use: getEnvTemplateFromComponentEnv below
|
252
|
+
*
|
253
|
+
* @param component
|
254
|
+
* @returns
|
255
|
+
*/
|
256
|
+
getEnvTemplate(component: Component): Promise<PreviewArtifact | undefined>;
|
257
|
+
/**
|
258
|
+
* This is a special method to get a core env template
|
259
|
+
* As the core envs doesn't exist in the scope we need to bring it from other place
|
260
|
+
* We will bring it from the core env package files
|
261
|
+
*/
|
262
|
+
private getCoreEnvTemplate;
|
263
|
+
/**
|
264
|
+
* This will fetch the component env, then will take the env template from the component env
|
265
|
+
* @param component
|
266
|
+
*/
|
267
|
+
getEnvTemplateFromComponentEnv(component: Component): Promise<PreviewArtifact | undefined>;
|
268
|
+
/**
|
269
|
+
* This will fetch the component env, then will take the env template from the component env
|
270
|
+
* @param component
|
271
|
+
*/
|
272
|
+
getEnvTemplateByEnvId(envId: string): Promise<PreviewArtifact | undefined>;
|
273
|
+
getDefs(): PreviewDefinition[];
|
274
|
+
private writeHash;
|
275
|
+
private timestamp;
|
276
|
+
/**
|
277
|
+
* write a link to load custom modules dynamically.
|
278
|
+
* @param prefix write
|
279
|
+
* @param moduleMap map of components to module paths to require.
|
280
|
+
* @param defaultModule
|
281
|
+
* @param dirName
|
282
|
+
*/
|
283
|
+
writeLink(prefix: string, moduleMap: ComponentMap<string[]>, mainModulesMap: MainModulesMap, dirName: string, isSplitComponentBundle: boolean): string;
|
284
|
+
writeLinkContents(contents: string, targetDir: string, prefix: string): string;
|
285
|
+
private executionRefs;
|
286
|
+
private getPreviewTarget;
|
287
|
+
private writePreviewEntry;
|
288
|
+
private updateLinkFiles;
|
289
|
+
writePreviewRuntime(context: {
|
290
|
+
components: Component[];
|
291
|
+
}, aspectsIdsToNotFilterOut?: string[]): Promise<string>;
|
292
|
+
resolveAspects(runtimeName?: string, componentIds?: ComponentID[], uiRoot?: UIRoot, opts?: ResolveAspectsOptions): Promise<AspectDefinition[]>;
|
293
|
+
private getUi;
|
294
|
+
/**
|
295
|
+
* Filter the aspects to have only aspects that are:
|
296
|
+
* 1. core aspects
|
297
|
+
* 2. configured on the host (workspace/scope)
|
298
|
+
* 3. used by at least one component from the context
|
299
|
+
* @param aspects
|
300
|
+
* @param context
|
301
|
+
*/
|
302
|
+
private filterAspectsByExecutionContext;
|
303
|
+
private getDefaultStrategies;
|
304
|
+
private handleComponentChange;
|
305
|
+
private handleComponentRemoval;
|
306
|
+
getEnvPreviewConfig(env?: PreviewEnv): EnvPreviewConfig;
|
307
|
+
/**
|
308
|
+
* return the configured bundling strategy.
|
309
|
+
*/
|
310
|
+
getBundlingStrategy(env?: PreviewEnv): BundlingStrategy;
|
311
|
+
/**
|
312
|
+
* register a new bundling strategy. default available strategies are `env` and ``
|
313
|
+
*/
|
314
|
+
registerBundlingStrategy(bundlingStrategy: BundlingStrategy): this;
|
315
|
+
/**
|
316
|
+
* register a new preview definition.
|
317
|
+
*/
|
318
|
+
registerDefinition(previewDef: PreviewDefinition): void;
|
319
|
+
static slots: (((registerFn: () => string) => SlotRegistry<PreviewDefinition>) | ((registerFn: () => string) => SlotRegistry<BundlingStrategy>))[];
|
320
|
+
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
321
|
+
static dependencies: import("@teambit/harmony").Aspect[];
|
322
|
+
static defaultConfig: {
|
323
|
+
disabled: boolean;
|
324
|
+
onlyOverview: boolean;
|
325
|
+
};
|
326
|
+
static provider([bundler, builder, componentExtension, uiMain, cache, envs, workspace, pkg, pubsub, aspectLoader, loggerMain, dependencyResolver, graphql, watcher, scope,]: [
|
327
|
+
BundlerMain,
|
328
|
+
BuilderMain,
|
329
|
+
ComponentMain,
|
330
|
+
UiMain,
|
331
|
+
CacheMain,
|
332
|
+
EnvsMain,
|
333
|
+
Workspace | undefined,
|
334
|
+
PkgMain,
|
335
|
+
PubsubMain,
|
336
|
+
AspectLoaderMain,
|
337
|
+
LoggerMain,
|
338
|
+
DependencyResolverMain,
|
339
|
+
GraphqlMain,
|
340
|
+
WatcherMain,
|
341
|
+
ScopeMain
|
342
|
+
], config: PreviewConfig, [previewSlot, bundlingStrategySlot]: [PreviewDefinitionRegistry, BundlingStrategySlot], harmony: Harmony): Promise<PreviewMain>;
|
343
|
+
}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import { PubsubPreview } from '@teambit/pubsub';
|
2
|
+
import { SlotRegistry } from '@teambit/harmony';
|
3
|
+
import { ComponentID } from '@teambit/component-id';
|
4
|
+
import { PreviewType } from './preview-type';
|
5
|
+
import { ModuleFile, PreviewModule } from './types/preview-module';
|
6
|
+
import { RenderingContext } from './rendering-context';
|
7
|
+
export { linkModules } from './preview-modules';
|
8
|
+
export type PreviewSlot = SlotRegistry<PreviewType>;
|
9
|
+
export type RenderingContextOptions = {
|
10
|
+
aspectsFilter?: string[];
|
11
|
+
};
|
12
|
+
export type RenderingContextProvider = (options: RenderingContextOptions) => {
|
13
|
+
[key: string]: any;
|
14
|
+
};
|
15
|
+
export type RenderingContextSlot = SlotRegistry<RenderingContextProvider>;
|
16
|
+
export declare class PreviewPreview {
|
17
|
+
/**
|
18
|
+
* register to pubsub
|
19
|
+
*/
|
20
|
+
private pubsub;
|
21
|
+
/**
|
22
|
+
* preview slot.
|
23
|
+
*/
|
24
|
+
private previewSlot;
|
25
|
+
private renderingContextSlot;
|
26
|
+
constructor(
|
27
|
+
/**
|
28
|
+
* register to pubsub
|
29
|
+
*/
|
30
|
+
pubsub: PubsubPreview,
|
31
|
+
/**
|
32
|
+
* preview slot.
|
33
|
+
*/
|
34
|
+
previewSlot: PreviewSlot, renderingContextSlot: RenderingContextSlot);
|
35
|
+
private registerClickPubSub;
|
36
|
+
private isDev;
|
37
|
+
private isReady;
|
38
|
+
private _setupPromise?;
|
39
|
+
setup: () => Promise<void>;
|
40
|
+
/**
|
41
|
+
* render the preview.
|
42
|
+
*/
|
43
|
+
render: (rootExt?: string) => Promise<void>;
|
44
|
+
setFullScreen(): void;
|
45
|
+
setViewport(): void;
|
46
|
+
reportSize(): void;
|
47
|
+
getPreviewModule(previewName: string, id: ComponentID): Promise<PreviewModule>;
|
48
|
+
fetchComponentPreview(id: ComponentID, name: string): Promise<Record<string, ModuleFile[]>>;
|
49
|
+
private addComponentFileElement;
|
50
|
+
private fetchComponentPreviewFiles;
|
51
|
+
private addComponentFileScriptElement;
|
52
|
+
private addComponentFileLinkElement;
|
53
|
+
private loadPreviewScript;
|
54
|
+
private getComponentAspects;
|
55
|
+
/**
|
56
|
+
* register a new preview.
|
57
|
+
*/
|
58
|
+
registerPreview(preview: PreviewType): this;
|
59
|
+
/**
|
60
|
+
* get the preview rendering context.
|
61
|
+
*/
|
62
|
+
getRenderingContext(aspectsFilter?: string[]): RenderingContext;
|
63
|
+
/**
|
64
|
+
* allows aspects to add rendering contexts.
|
65
|
+
* render context is available through all preview definitions.
|
66
|
+
*/
|
67
|
+
registerRenderContext(renderContext: RenderingContextProvider): this;
|
68
|
+
getDefault(): string;
|
69
|
+
private getPreview;
|
70
|
+
getParam(query: string, param: string): string | null;
|
71
|
+
getQuery(): string;
|
72
|
+
private getLocation;
|
73
|
+
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
74
|
+
static dependencies: import("@teambit/harmony").Aspect[];
|
75
|
+
static slots: (((registerFn: () => string) => SlotRegistry<PreviewType>) | ((registerFn: () => string) => SlotRegistry<RenderingContextProvider>))[];
|
76
|
+
static provider([pubsub]: [PubsubPreview], config: any, [previewSlot, renderingContextSlot]: [PreviewSlot, RenderingContextSlot]): Promise<PreviewPreview>;
|
77
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/// <reference types="express" />
|
2
|
+
import type { NextFunction, Request, Response, Route } from '@teambit/express';
|
3
|
+
import type { Logger } from '@teambit/logger';
|
4
|
+
import { PreviewMain } from './preview.main.runtime';
|
5
|
+
import type { PreviewUrlParams } from './artifact-file-middleware';
|
6
|
+
export declare class PreviewRoute implements Route {
|
7
|
+
/**
|
8
|
+
* preview extension.
|
9
|
+
*/
|
10
|
+
private preview;
|
11
|
+
private logger;
|
12
|
+
constructor(
|
13
|
+
/**
|
14
|
+
* preview extension.
|
15
|
+
*/
|
16
|
+
preview: PreviewMain, logger: Logger);
|
17
|
+
route: string;
|
18
|
+
method: string;
|
19
|
+
middlewares: (import("@teambit/express").Middleware | ((req: Request<PreviewUrlParams>, res: Response, next: NextFunction) => Promise<void | import("express").Response<any, Record<string, any>>>))[];
|
20
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { EnvService, Env, EnvContext, ServiceTransformationMap } from '@teambit/envs';
|
2
|
+
import { EnvPreviewConfig } from './preview.main.runtime';
|
3
|
+
type PreviewTransformationMap = ServiceTransformationMap & {
|
4
|
+
/**
|
5
|
+
* Returns a paths to a function which mounts a given component to DOM
|
6
|
+
* Required for `bit start` & `bit build`
|
7
|
+
*/
|
8
|
+
getMounter?: () => string;
|
9
|
+
/**
|
10
|
+
* Returns a path to a docs template.
|
11
|
+
* Required for `bit start` & `bit build`
|
12
|
+
*/
|
13
|
+
getDocsTemplate?: () => string;
|
14
|
+
/**
|
15
|
+
* Returns a list of additional host dependencies
|
16
|
+
* this list will be provided as globals on the window after bit preview bundle
|
17
|
+
* by default bit will merge this list with the peers from the getDependencies function
|
18
|
+
*/
|
19
|
+
getAdditionalHostDependencies?: () => string[] | Promise<string[]>;
|
20
|
+
/**
|
21
|
+
* Returns preview config like the strategy name to use when bundling the components for the preview
|
22
|
+
*/
|
23
|
+
getPreviewConfig?: () => EnvPreviewConfig;
|
24
|
+
};
|
25
|
+
export declare class PreviewService implements EnvService<any> {
|
26
|
+
name: string;
|
27
|
+
transform(env: Env, envContext: EnvContext): PreviewTransformationMap | undefined;
|
28
|
+
}
|
29
|
+
export {};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { BundlerMain, ComponentServer } from '@teambit/bundler';
|
2
|
+
import { PubsubMain } from '@teambit/pubsub';
|
3
|
+
import { ProxyEntry, StartPlugin, StartPluginOptions, UiMain } from '@teambit/ui';
|
4
|
+
import { Workspace } from '@teambit/workspace';
|
5
|
+
import { Logger } from '@teambit/logger';
|
6
|
+
import { WatcherMain } from '@teambit/watcher';
|
7
|
+
type ServerState = {
|
8
|
+
isCompiling?: boolean;
|
9
|
+
isReady?: boolean;
|
10
|
+
errors?: Error[];
|
11
|
+
warnings?: Error[];
|
12
|
+
results?: any[];
|
13
|
+
};
|
14
|
+
type ServerStateMap = Record<string, ServerState>;
|
15
|
+
export declare class PreviewStartPlugin implements StartPlugin {
|
16
|
+
private workspace;
|
17
|
+
private bundler;
|
18
|
+
private ui;
|
19
|
+
private pubsub;
|
20
|
+
private logger;
|
21
|
+
private watcher;
|
22
|
+
constructor(workspace: Workspace, bundler: BundlerMain, ui: UiMain, pubsub: PubsubMain, logger: Logger, watcher: WatcherMain);
|
23
|
+
previewServers: ComponentServer[];
|
24
|
+
serversState: ServerStateMap;
|
25
|
+
serversMap: Record<string, ComponentServer>;
|
26
|
+
initiate(options: StartPluginOptions): Promise<void>;
|
27
|
+
getProxy(): ProxyEntry[];
|
28
|
+
private listenToDevServers;
|
29
|
+
private handleOnStartCompiling;
|
30
|
+
private handleOnDoneCompiling;
|
31
|
+
private setReady;
|
32
|
+
private readyPromise;
|
33
|
+
get whenReady(): Promise<void>;
|
34
|
+
}
|
35
|
+
export {};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import { ExecutionContext } from '@teambit/envs';
|
2
|
+
import { BuildContext, BuiltTaskResult, BuildTask, TaskLocation } from '@teambit/builder';
|
3
|
+
import { BundlerMain } from '@teambit/bundler';
|
4
|
+
import { ComponentMap } from '@teambit/component';
|
5
|
+
import { Capsule } from '@teambit/isolator';
|
6
|
+
import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
|
7
|
+
import { DependencyResolverMain } from '@teambit/dependency-resolver';
|
8
|
+
import { Logger } from '@teambit/logger';
|
9
|
+
import { PreviewMain } from './preview.main.runtime';
|
10
|
+
export declare const PREVIEW_TASK_NAME = "GeneratePreview";
|
11
|
+
export declare class PreviewTask implements BuildTask {
|
12
|
+
/**
|
13
|
+
* bundler extension.
|
14
|
+
*/
|
15
|
+
private bundler;
|
16
|
+
/**
|
17
|
+
* preview extension.
|
18
|
+
*/
|
19
|
+
private preview;
|
20
|
+
private dependencyResolver;
|
21
|
+
private logger;
|
22
|
+
constructor(
|
23
|
+
/**
|
24
|
+
* bundler extension.
|
25
|
+
*/
|
26
|
+
bundler: BundlerMain,
|
27
|
+
/**
|
28
|
+
* preview extension.
|
29
|
+
*/
|
30
|
+
preview: PreviewMain, dependencyResolver: DependencyResolverMain, logger: Logger);
|
31
|
+
aspectId: string;
|
32
|
+
name: string;
|
33
|
+
description: string;
|
34
|
+
location: TaskLocation;
|
35
|
+
execute(context: BuildContext): Promise<BuiltTaskResult>;
|
36
|
+
getLinkFileDirectory(): string;
|
37
|
+
getPreviewDirectory(context: ExecutionContext): string;
|
38
|
+
getPathsFromMap(capsule: Capsule, moduleMap: ComponentMap<AbstractVinyl[]>, context: BuildContext): ComponentMap<string[]>;
|
39
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { RenderingContextSlot } from './preview.preview.runtime';
|
2
|
+
export type RenderingContextOptions = {
|
3
|
+
aspectsFilter?: string[];
|
4
|
+
};
|
5
|
+
export type RenderingContextProvider = (options: RenderingContextOptions) => {
|
6
|
+
[key: string]: any;
|
7
|
+
};
|
8
|
+
export declare class RenderingContext {
|
9
|
+
private contexts;
|
10
|
+
private options;
|
11
|
+
constructor(contexts: RenderingContextSlot, options?: RenderingContextOptions);
|
12
|
+
/**
|
13
|
+
* obtain rendering context of a specific aspect.
|
14
|
+
*/
|
15
|
+
get(aspectId: string): {
|
16
|
+
[key: string]: any;
|
17
|
+
} | undefined;
|
18
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { BitBaseEvent } from '@teambit/pubsub';
|
2
|
+
export type SizeEventType = {
|
3
|
+
height: number;
|
4
|
+
width: number;
|
5
|
+
};
|
6
|
+
export declare class SizeEvent extends BitBaseEvent<SizeEventType> {
|
7
|
+
static readonly TYPE = "preview-size";
|
8
|
+
constructor(sizeEvent: SizeEventType);
|
9
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import { Component } from '@teambit/component';
|
2
|
+
import { ComponentResult } from '@teambit/builder';
|
3
|
+
import type { PkgMain } from '@teambit/pkg';
|
4
|
+
import type { DependencyResolverMain } from '@teambit/dependency-resolver';
|
5
|
+
import type { BundlerResult, BundlerContext, Target } from '@teambit/bundler';
|
6
|
+
import { BundlingStrategy, ComputeTargetsContext } from '../bundling-strategy';
|
7
|
+
import type { PreviewDefinition } from '../preview-definition';
|
8
|
+
import type { PreviewMain } from '../preview.main.runtime';
|
9
|
+
export declare const PREVIEW_CHUNK_SUFFIX = "preview";
|
10
|
+
export declare const COMPONENT_CHUNK_SUFFIX = "component";
|
11
|
+
export declare const PREVIEW_CHUNK_FILENAME_SUFFIX = "preview.js";
|
12
|
+
export declare const COMPONENT_CHUNK_FILENAME_SUFFIX = "component.js";
|
13
|
+
export declare const COMPONENT_STRATEGY_SIZE_KEY_NAME = "size";
|
14
|
+
export declare const COMPONENT_STRATEGY_ARTIFACT_NAME = "preview-component";
|
15
|
+
type ComponentEntry = {
|
16
|
+
component: Component;
|
17
|
+
entries: Object;
|
18
|
+
};
|
19
|
+
/**
|
20
|
+
* bundles all components in a given env into the same bundle.
|
21
|
+
*/
|
22
|
+
export declare class ComponentBundlingStrategy implements BundlingStrategy {
|
23
|
+
private preview;
|
24
|
+
private pkg;
|
25
|
+
private dependencyResolver;
|
26
|
+
name: string;
|
27
|
+
constructor(preview: PreviewMain, pkg: PkgMain, dependencyResolver: DependencyResolverMain);
|
28
|
+
computeTargets(context: ComputeTargetsContext, previewDefs: PreviewDefinition[]): Promise<Target[]>;
|
29
|
+
computeComponentEntry(previewDefs: PreviewDefinition[], component: Component, context: ComputeTargetsContext): Promise<ComponentEntry>;
|
30
|
+
private getComponentChunkId;
|
31
|
+
private getComponentChunkFileName;
|
32
|
+
private getAssetAbsolutePath;
|
33
|
+
private getAssetFilename;
|
34
|
+
copyAssetsToCapsules(context: BundlerContext, result: BundlerResult): void;
|
35
|
+
private findAssetsForComponent;
|
36
|
+
private getArtifactDirectory;
|
37
|
+
private computeComponentMetadata;
|
38
|
+
computeResults(context: BundlerContext, results: BundlerResult[]): Promise<{
|
39
|
+
componentsResults: ComponentResult[];
|
40
|
+
artifacts: {
|
41
|
+
name: string;
|
42
|
+
globPatterns: string[];
|
43
|
+
rootDir: string;
|
44
|
+
}[];
|
45
|
+
}>;
|
46
|
+
computeTargetResult(context: BundlerContext, result: BundlerResult): Promise<ComponentResult[]>;
|
47
|
+
private getArtifactDef;
|
48
|
+
getDirName(context: ComputeTargetsContext): string;
|
49
|
+
private getOutputPath;
|
50
|
+
private getPaths;
|
51
|
+
private getComponentOutputPath;
|
52
|
+
private computePaths;
|
53
|
+
}
|
54
|
+
export {};
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { ComponentResult } from '@teambit/builder';
|
2
|
+
import { BundlerContext, BundlerHtmlConfig, BundlerResult } from '@teambit/bundler';
|
3
|
+
import { DependencyResolverMain } from '@teambit/dependency-resolver';
|
4
|
+
import { PkgMain } from '@teambit/pkg';
|
5
|
+
import type { BundlingStrategy, ComputeTargetsContext } from '../bundling-strategy';
|
6
|
+
import { PreviewDefinition } from '../preview-definition';
|
7
|
+
import { PreviewMain } from '../preview.main.runtime';
|
8
|
+
export declare const ENV_STRATEGY_ARTIFACT_NAME = "preview";
|
9
|
+
/**
|
10
|
+
* bundles all components in a given env into the same bundle.
|
11
|
+
*/
|
12
|
+
export declare class EnvBundlingStrategy implements BundlingStrategy {
|
13
|
+
private preview;
|
14
|
+
private pkg;
|
15
|
+
private dependencyResolver;
|
16
|
+
name: string;
|
17
|
+
constructor(preview: PreviewMain, pkg: PkgMain, dependencyResolver: DependencyResolverMain);
|
18
|
+
computeTargets(context: ComputeTargetsContext, previewDefs: PreviewDefinition[]): Promise<{
|
19
|
+
entries: string[];
|
20
|
+
html: BundlerHtmlConfig[];
|
21
|
+
components: import("@teambit/component").Component[];
|
22
|
+
outputPath: string;
|
23
|
+
hostDependencies: string[];
|
24
|
+
aliasHostDependencies: boolean;
|
25
|
+
}[]>;
|
26
|
+
private generateHtmlConfig;
|
27
|
+
computeResults(context: BundlerContext, results: BundlerResult[]): Promise<{
|
28
|
+
componentsResults: ComponentResult[];
|
29
|
+
artifacts: {
|
30
|
+
name: string;
|
31
|
+
globPatterns: string[];
|
32
|
+
rootDir: string;
|
33
|
+
context: "env";
|
34
|
+
}[];
|
35
|
+
}>;
|
36
|
+
private getArtifactDef;
|
37
|
+
getDirName(context: ComputeTargetsContext): string;
|
38
|
+
private getOutputPath;
|
39
|
+
private getPaths;
|
40
|
+
private computePaths;
|
41
|
+
}
|