@teambit/preview 0.0.889 → 0.0.891
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -1
- package/dist/index.js +22 -1
- package/dist/index.js.map +1 -1
- package/dist/preview.main.runtime.d.ts +71 -11
- package/dist/preview.main.runtime.js +121 -46
- package/dist/preview.main.runtime.js.map +1 -1
- package/dist/strategies/index.d.ts +3 -2
- package/dist/strategies/index.js +37 -0
- package/dist/strategies/index.js.map +1 -1
- package/dist/strategies/strategies-names.d.ts +2 -0
- package/dist/strategies/strategies-names.js +12 -0
- package/dist/strategies/strategies-names.js.map +1 -0
- package/package-tar/teambit-preview-0.0.891.tgz +0 -0
- package/package.json +23 -23
- package/{preview-1667274254521.js → preview-1667534058902.js} +2 -2
- package/preview.main.runtime.tsx +148 -30
- package/strategies/index.ts +3 -2
- package/strategies/strategies-names.ts +2 -0
- package/package-tar/teambit-preview-0.0.889.tgz +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { PreviewAspect as default, PreviewAspect, PreviewRuntime } from './preview.aspect';
|
|
2
2
|
export * from './events';
|
|
3
|
-
export type { PreviewMain, EnvPreviewConfig, ComponentPreviewSize } from './preview.main.runtime';
|
|
3
|
+
export type { PreviewMain, EnvPreviewConfig, ComponentPreviewSize, PreviewStrategyName, PreviewFiles, } from './preview.main.runtime';
|
|
4
4
|
export type { PreviewPreview, RenderingContextOptions, RenderingContextProvider } from './preview.preview.runtime';
|
|
5
5
|
export { PreviewDefinition } from './preview-definition';
|
|
6
6
|
export type { PreviewModule, ModuleFile } from './types/preview-module';
|
|
7
7
|
export type { RenderingContext } from './rendering-context';
|
|
8
|
+
export { ENV_PREVIEW_STRATEGY_NAME, COMPONENT_PREVIEW_STRATEGY_NAME } from './strategies/strategies-names';
|
package/dist/index.js
CHANGED
|
@@ -6,8 +6,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
var _exportNames = {
|
|
7
7
|
PreviewAspect: true,
|
|
8
8
|
PreviewRuntime: true,
|
|
9
|
-
PreviewDefinition: true
|
|
9
|
+
PreviewDefinition: true,
|
|
10
|
+
ENV_PREVIEW_STRATEGY_NAME: true,
|
|
11
|
+
COMPONENT_PREVIEW_STRATEGY_NAME: true
|
|
10
12
|
};
|
|
13
|
+
Object.defineProperty(exports, "COMPONENT_PREVIEW_STRATEGY_NAME", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _strategiesNames().COMPONENT_PREVIEW_STRATEGY_NAME;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "ENV_PREVIEW_STRATEGY_NAME", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _strategiesNames().ENV_PREVIEW_STRATEGY_NAME;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
11
25
|
Object.defineProperty(exports, "PreviewAspect", {
|
|
12
26
|
enumerable: true,
|
|
13
27
|
get: function () {
|
|
@@ -58,5 +72,12 @@ function _previewDefinition() {
|
|
|
58
72
|
};
|
|
59
73
|
return data;
|
|
60
74
|
}
|
|
75
|
+
function _strategiesNames() {
|
|
76
|
+
const data = require("./strategies/strategies-names");
|
|
77
|
+
_strategiesNames = function () {
|
|
78
|
+
return data;
|
|
79
|
+
};
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
61
82
|
|
|
62
83
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { PreviewAspect as default, PreviewAspect, PreviewRuntime } from './preview.aspect';\n\nexport * from './events';\nexport type {
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { PreviewAspect as default, PreviewAspect, PreviewRuntime } from './preview.aspect';\n\nexport * from './events';\nexport type {\n PreviewMain,\n EnvPreviewConfig,\n ComponentPreviewSize,\n PreviewStrategyName,\n PreviewFiles,\n} from './preview.main.runtime';\nexport type { PreviewPreview, RenderingContextOptions, RenderingContextProvider } from './preview.preview.runtime';\nexport { PreviewDefinition } from './preview-definition';\nexport type { PreviewModule, ModuleFile } from './types/preview-module';\nexport type { RenderingContext } from './rendering-context';\n// Exporting directly from the inner file to prevent breaking the bundling process\nexport { ENV_PREVIEW_STRATEGY_NAME, COMPONENT_PREVIEW_STRATEGY_NAME } from './strategies/strategies-names';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AASA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
|
|
@@ -15,7 +15,8 @@ import { PreviewArtifact } from './preview-artifact';
|
|
|
15
15
|
import { PreviewDefinition } from './preview-definition';
|
|
16
16
|
import { BundlingStrategy } from './bundling-strategy';
|
|
17
17
|
export declare type PreviewDefinitionRegistry = SlotRegistry<PreviewDefinition>;
|
|
18
|
-
declare type
|
|
18
|
+
export declare type PreviewStrategyName = 'env' | 'component';
|
|
19
|
+
export declare type PreviewFiles = {
|
|
19
20
|
files: string[];
|
|
20
21
|
isBundledWithEnv: boolean;
|
|
21
22
|
};
|
|
@@ -39,8 +40,26 @@ export declare type PreviewVariantConfig = {
|
|
|
39
40
|
/**
|
|
40
41
|
* Preview data that stored on the component on load
|
|
41
42
|
*/
|
|
42
|
-
export declare type PreviewComponentData =
|
|
43
|
+
export declare type PreviewComponentData = PreviewAnyComponentData & PreviewEnvComponentData;
|
|
44
|
+
/**
|
|
45
|
+
* Preview data that stored on the component on load for any component
|
|
46
|
+
*/
|
|
47
|
+
export declare type PreviewAnyComponentData = {
|
|
43
48
|
doesScaling?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The strategy configured by the component's env
|
|
51
|
+
*/
|
|
52
|
+
strategyName?: PreviewStrategyName;
|
|
53
|
+
/**
|
|
54
|
+
* Does the component has a bundle for the component itself (separated from the compositions/docs)
|
|
55
|
+
* Calculated by the component's env
|
|
56
|
+
*/
|
|
57
|
+
splitComponentBundle?: boolean;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Preview data that stored on the component on load if the component is an env
|
|
61
|
+
*/
|
|
62
|
+
export declare type PreviewEnvComponentData = {
|
|
44
63
|
isScaling?: boolean;
|
|
45
64
|
};
|
|
46
65
|
export declare type PreviewConfig = {
|
|
@@ -54,7 +73,7 @@ export declare type PreviewConfig = {
|
|
|
54
73
|
maxChunkSize?: number;
|
|
55
74
|
};
|
|
56
75
|
export declare type EnvPreviewConfig = {
|
|
57
|
-
strategyName?:
|
|
76
|
+
strategyName?: PreviewStrategyName;
|
|
58
77
|
splitComponentBundle?: boolean;
|
|
59
78
|
};
|
|
60
79
|
export declare type BundlingStrategySlot = SlotRegistry<BundlingStrategy>;
|
|
@@ -97,6 +116,47 @@ export declare class PreviewMain {
|
|
|
97
116
|
* @returns
|
|
98
117
|
*/
|
|
99
118
|
getPreviewFiles(component: Component): Promise<PreviewFiles | undefined>;
|
|
119
|
+
/**
|
|
120
|
+
* Get the preview config of the component.
|
|
121
|
+
* (config that was set by variants or on bitmap)
|
|
122
|
+
* @param component
|
|
123
|
+
* @returns
|
|
124
|
+
*/
|
|
125
|
+
getPreviewAspectConfig(component: Component): PreviewVariantConfig | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Get the preview data of the component.
|
|
128
|
+
* (data that was calculated during the on load process)
|
|
129
|
+
* @param component
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
132
|
+
getPreviewData(component: Component): PreviewComponentData | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* Calculate preview data on component load
|
|
135
|
+
* @param component
|
|
136
|
+
* @returns
|
|
137
|
+
*/
|
|
138
|
+
calcPreviewData(component: Component): Promise<PreviewComponentData>;
|
|
139
|
+
/**
|
|
140
|
+
* Calculate preview data on component that configured by its env
|
|
141
|
+
* @param component
|
|
142
|
+
* @returns
|
|
143
|
+
*/
|
|
144
|
+
calcPreviewDataFromEnv(component: Component): Promise<Omit<PreviewAnyComponentData, 'doesScaling'> | undefined>;
|
|
145
|
+
/**
|
|
146
|
+
* calculate extra preview data for env components (on load)
|
|
147
|
+
* @param envComponent
|
|
148
|
+
* @returns
|
|
149
|
+
*/
|
|
150
|
+
private calculateDataForEnvComponent;
|
|
151
|
+
/**
|
|
152
|
+
* Check if the component preview bundle contain the env as part of the bundle or only the component code
|
|
153
|
+
* (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)
|
|
154
|
+
* This should be used only for calculating the value on load.
|
|
155
|
+
* otherwise, use the isBundledWithEnv function
|
|
156
|
+
* @param component
|
|
157
|
+
* @returns
|
|
158
|
+
*/
|
|
159
|
+
calcIsBundledWithEnv(component: Component): Promise<boolean>;
|
|
100
160
|
/**
|
|
101
161
|
* Check if the component preview bundle contain the env as part of the bundle or only the component code
|
|
102
162
|
* (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)
|
|
@@ -104,6 +164,14 @@ export declare class PreviewMain {
|
|
|
104
164
|
* @returns
|
|
105
165
|
*/
|
|
106
166
|
isBundledWithEnv(component: Component): Promise<boolean>;
|
|
167
|
+
/**
|
|
168
|
+
* This is a legacy calculation for the isBundledWithEnv
|
|
169
|
+
* This calc is based on the component artifacts which is very expensive operation as it requires to fetch and load the artifacts
|
|
170
|
+
* See the new implementation in the isBundledWithEnv method
|
|
171
|
+
* @param component
|
|
172
|
+
* @returns
|
|
173
|
+
*/
|
|
174
|
+
private isBundledWithEnvBackward;
|
|
107
175
|
private calcDoesScalingForComponent;
|
|
108
176
|
/**
|
|
109
177
|
* can the current component preview scale in size for different preview sizes.
|
|
@@ -126,13 +194,6 @@ export declare class PreviewMain {
|
|
|
126
194
|
* @returns
|
|
127
195
|
*/
|
|
128
196
|
private calculateIsEnvSupportScaling;
|
|
129
|
-
/**
|
|
130
|
-
* Get the preview config of the component.
|
|
131
|
-
* (config that was set by variants or on bitmap)
|
|
132
|
-
* @param component
|
|
133
|
-
* @returns
|
|
134
|
-
*/
|
|
135
|
-
getPreviewConfig(component: Component): PreviewVariantConfig | undefined;
|
|
136
197
|
/**
|
|
137
198
|
* Check if the component preview bundle contain the header inside of it (legacy)
|
|
138
199
|
* today we are not including the header inside anymore
|
|
@@ -232,4 +293,3 @@ export declare class PreviewMain {
|
|
|
232
293
|
GraphqlMain
|
|
233
294
|
], config: PreviewConfig, [previewSlot, bundlingStrategySlot]: [PreviewDefinitionRegistry, BundlingStrategySlot], harmony: Harmony): Promise<PreviewMain>;
|
|
234
295
|
}
|
|
235
|
-
export {};
|
|
@@ -245,20 +245,6 @@ function _componentPreview() {
|
|
|
245
245
|
};
|
|
246
246
|
return data;
|
|
247
247
|
}
|
|
248
|
-
function _componentStrategy() {
|
|
249
|
-
const data = require("./strategies/component-strategy");
|
|
250
|
-
_componentStrategy = function () {
|
|
251
|
-
return data;
|
|
252
|
-
};
|
|
253
|
-
return data;
|
|
254
|
-
}
|
|
255
|
-
function _envStrategy() {
|
|
256
|
-
const data = require("./strategies/env-strategy");
|
|
257
|
-
_envStrategy = function () {
|
|
258
|
-
return data;
|
|
259
|
-
};
|
|
260
|
-
return data;
|
|
261
|
-
}
|
|
262
248
|
function _preview5() {
|
|
263
249
|
const data = require("./preview.graphql");
|
|
264
250
|
_preview5 = function () {
|
|
@@ -273,6 +259,8 @@ function _previewAssets() {
|
|
|
273
259
|
};
|
|
274
260
|
return data;
|
|
275
261
|
}
|
|
262
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
263
|
+
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; }
|
|
276
264
|
const noopResult = {
|
|
277
265
|
results: [],
|
|
278
266
|
toString: () => `updating link file`
|
|
@@ -335,7 +323,7 @@ class PreviewMain {
|
|
|
335
323
|
getComponentBundleSize(component) {
|
|
336
324
|
const data = this.builder.getDataByAspect(component, _preview().PreviewAspect.id);
|
|
337
325
|
if (!data) return undefined;
|
|
338
|
-
return data[
|
|
326
|
+
return data[_strategies().COMPONENT_STRATEGY_SIZE_KEY_NAME];
|
|
339
327
|
}
|
|
340
328
|
async getPreview(component) {
|
|
341
329
|
const artifacts = await this.builder.getArtifactsVinylByAspectAndTaskName(component, _preview().PreviewAspect.id, _preview3().PREVIEW_TASK_NAME);
|
|
@@ -358,6 +346,99 @@ class PreviewMain {
|
|
|
358
346
|
};
|
|
359
347
|
}
|
|
360
348
|
|
|
349
|
+
/**
|
|
350
|
+
* Get the preview config of the component.
|
|
351
|
+
* (config that was set by variants or on bitmap)
|
|
352
|
+
* @param component
|
|
353
|
+
* @returns
|
|
354
|
+
*/
|
|
355
|
+
getPreviewAspectConfig(component) {
|
|
356
|
+
var _component$state$aspe;
|
|
357
|
+
return (_component$state$aspe = component.state.aspects.get(_preview().PreviewAspect.id)) === null || _component$state$aspe === void 0 ? void 0 : _component$state$aspe.config;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Get the preview data of the component.
|
|
362
|
+
* (data that was calculated during the on load process)
|
|
363
|
+
* @param component
|
|
364
|
+
* @returns
|
|
365
|
+
*/
|
|
366
|
+
getPreviewData(component) {
|
|
367
|
+
var _component$state$aspe2;
|
|
368
|
+
const previewData = (_component$state$aspe2 = component.state.aspects.get(_preview().PreviewAspect.id)) === null || _component$state$aspe2 === void 0 ? void 0 : _component$state$aspe2.data;
|
|
369
|
+
return previewData;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Calculate preview data on component load
|
|
374
|
+
* @param component
|
|
375
|
+
* @returns
|
|
376
|
+
*/
|
|
377
|
+
async calcPreviewData(component) {
|
|
378
|
+
const doesScaling = await this.calcDoesScalingForComponent(component);
|
|
379
|
+
const dataFromEnv = await this.calcPreviewDataFromEnv(component);
|
|
380
|
+
const envData = (await this.calculateDataForEnvComponent(component)) || {};
|
|
381
|
+
const data = _objectSpread(_objectSpread({
|
|
382
|
+
doesScaling
|
|
383
|
+
}, dataFromEnv), envData);
|
|
384
|
+
return data;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Calculate preview data on component that configured by its env
|
|
389
|
+
* @param component
|
|
390
|
+
* @returns
|
|
391
|
+
*/
|
|
392
|
+
async calcPreviewDataFromEnv(component) {
|
|
393
|
+
var _envPreviewConfig$spl;
|
|
394
|
+
// Prevent infinite loop that caused by the fact that the env of the aspect env or the env env is the same as the component
|
|
395
|
+
// so we can't load it since during load we are trying to get env component and load it again
|
|
396
|
+
if (component.id.toStringWithoutVersion() === 'teambit.harmony/aspect' || component.id.toStringWithoutVersion() === 'teambit.envs/env') {
|
|
397
|
+
return {
|
|
398
|
+
strategyName: _strategies().COMPONENT_PREVIEW_STRATEGY_NAME,
|
|
399
|
+
splitComponentBundle: false
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
const env = this.envs.getEnv(component).env;
|
|
403
|
+
const envPreviewConfig = this.getEnvPreviewConfig(env);
|
|
404
|
+
const data = {
|
|
405
|
+
strategyName: envPreviewConfig === null || envPreviewConfig === void 0 ? void 0 : envPreviewConfig.strategyName,
|
|
406
|
+
splitComponentBundle: (_envPreviewConfig$spl = envPreviewConfig === null || envPreviewConfig === void 0 ? void 0 : envPreviewConfig.splitComponentBundle) !== null && _envPreviewConfig$spl !== void 0 ? _envPreviewConfig$spl : false
|
|
407
|
+
};
|
|
408
|
+
return data;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* calculate extra preview data for env components (on load)
|
|
413
|
+
* @param envComponent
|
|
414
|
+
* @returns
|
|
415
|
+
*/
|
|
416
|
+
async calculateDataForEnvComponent(envComponent) {
|
|
417
|
+
var _previewAspectConfig$;
|
|
418
|
+
const isEnv = this.envs.isEnv(envComponent);
|
|
419
|
+
// If the component is not an env, we don't want to store anything in the data
|
|
420
|
+
if (!isEnv) return undefined;
|
|
421
|
+
const previewAspectConfig = this.getPreviewAspectConfig(envComponent);
|
|
422
|
+
const data = {
|
|
423
|
+
// default to true if the env doesn't have a preview config
|
|
424
|
+
isScaling: (_previewAspectConfig$ = previewAspectConfig === null || previewAspectConfig === void 0 ? void 0 : previewAspectConfig.isScaling) !== null && _previewAspectConfig$ !== void 0 ? _previewAspectConfig$ : true
|
|
425
|
+
};
|
|
426
|
+
return data;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Check if the component preview bundle contain the env as part of the bundle or only the component code
|
|
431
|
+
* (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)
|
|
432
|
+
* This should be used only for calculating the value on load.
|
|
433
|
+
* otherwise, use the isBundledWithEnv function
|
|
434
|
+
* @param component
|
|
435
|
+
* @returns
|
|
436
|
+
*/
|
|
437
|
+
async calcIsBundledWithEnv(component) {
|
|
438
|
+
const envPreviewData = await this.calcPreviewDataFromEnv(component);
|
|
439
|
+
return (envPreviewData === null || envPreviewData === void 0 ? void 0 : envPreviewData.strategyName) !== 'component';
|
|
440
|
+
}
|
|
441
|
+
|
|
361
442
|
/**
|
|
362
443
|
* Check if the component preview bundle contain the env as part of the bundle or only the component code
|
|
363
444
|
* (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)
|
|
@@ -365,7 +446,22 @@ class PreviewMain {
|
|
|
365
446
|
* @returns
|
|
366
447
|
*/
|
|
367
448
|
async isBundledWithEnv(component) {
|
|
368
|
-
const
|
|
449
|
+
const data = await this.getPreviewData(component);
|
|
450
|
+
// For components that tagged in the past we didn't store the data, so we calculate it the old way
|
|
451
|
+
// We comparing the strategyName to undefined to cover a specific case when it doesn't exist at all.
|
|
452
|
+
if (!data || data.strategyName === undefined) return this.isBundledWithEnvBackward(component);
|
|
453
|
+
return data.strategyName === _strategies().ENV_PREVIEW_STRATEGY_NAME;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* This is a legacy calculation for the isBundledWithEnv
|
|
458
|
+
* This calc is based on the component artifacts which is very expensive operation as it requires to fetch and load the artifacts
|
|
459
|
+
* See the new implementation in the isBundledWithEnv method
|
|
460
|
+
* @param component
|
|
461
|
+
* @returns
|
|
462
|
+
*/
|
|
463
|
+
async isBundledWithEnvBackward(component) {
|
|
464
|
+
const artifacts = await this.builder.getArtifactsVinylByAspectAndName(component, _preview().PreviewAspect.id, _strategies().COMPONENT_STRATEGY_ARTIFACT_NAME);
|
|
369
465
|
if (!artifacts || !artifacts.length) return true;
|
|
370
466
|
return false;
|
|
371
467
|
}
|
|
@@ -375,7 +471,7 @@ class PreviewMain {
|
|
|
375
471
|
// if you want to get the final result use the `doesScaling` method below
|
|
376
472
|
// This should be used only for component load
|
|
377
473
|
async calcDoesScalingForComponent(component) {
|
|
378
|
-
const isBundledWithEnv = await this.
|
|
474
|
+
const isBundledWithEnv = await this.calcIsBundledWithEnv(component);
|
|
379
475
|
// if it's a core env and the env template is apart from the component it means the template bundle already contain the scaling functionality
|
|
380
476
|
if (this.envs.isUsingCoreEnv(component)) {
|
|
381
477
|
// If the component is new, no point to check the is bundle with env (there is no artifacts so it will for sure return false)
|
|
@@ -399,7 +495,7 @@ class PreviewMain {
|
|
|
399
495
|
* this calculation is based on the env of the component and if the env of the component support it.
|
|
400
496
|
*/
|
|
401
497
|
async doesScaling(component) {
|
|
402
|
-
var _this$workspace2
|
|
498
|
+
var _this$workspace2;
|
|
403
499
|
const inWorkspace = await ((_this$workspace2 = this.workspace) === null || _this$workspace2 === void 0 ? void 0 : _this$workspace2.hasId(component.id));
|
|
404
500
|
// Support case when we have the dev server for the env, in that case we calc the data of the env as we can't rely on the env data from the scope
|
|
405
501
|
// since we bundle it for the dev server again
|
|
@@ -408,7 +504,7 @@ class PreviewMain {
|
|
|
408
504
|
const envSupportScaling = await this.calculateIsEnvSupportScaling(envComponent);
|
|
409
505
|
return envSupportScaling !== null && envSupportScaling !== void 0 ? envSupportScaling : true;
|
|
410
506
|
}
|
|
411
|
-
const previewData = (
|
|
507
|
+
const previewData = this.getPreviewData(component);
|
|
412
508
|
if (!previewData) return false;
|
|
413
509
|
// Get the does scaling (the new calculation) or the old calc used in isScaling (between versions (about) 848 and 860)
|
|
414
510
|
if (previewData.doesScaling !== undefined) return previewData.doesScaling;
|
|
@@ -429,8 +525,7 @@ class PreviewMain {
|
|
|
429
525
|
* @returns
|
|
430
526
|
*/
|
|
431
527
|
isEnvSupportScaling(envComponent) {
|
|
432
|
-
|
|
433
|
-
const previewData = (_envComponent$state$a = envComponent.state.aspects.get(_preview().PreviewAspect.id)) === null || _envComponent$state$a === void 0 ? void 0 : _envComponent$state$a.data;
|
|
528
|
+
const previewData = this.getPreviewData(envComponent);
|
|
434
529
|
return !!(previewData !== null && previewData !== void 0 && previewData.isScaling);
|
|
435
530
|
}
|
|
436
531
|
|
|
@@ -444,24 +539,13 @@ class PreviewMain {
|
|
|
444
539
|
* @returns
|
|
445
540
|
*/
|
|
446
541
|
async calculateIsEnvSupportScaling(envComponent) {
|
|
447
|
-
var _previewAspectConfig
|
|
542
|
+
var _previewAspectConfig$2;
|
|
448
543
|
const isEnv = this.envs.isEnv(envComponent);
|
|
449
544
|
// If the component is not an env, we don't want to store anything in the data
|
|
450
545
|
if (!isEnv) return undefined;
|
|
451
|
-
const previewAspectConfig = this.
|
|
546
|
+
const previewAspectConfig = this.getPreviewAspectConfig(envComponent);
|
|
452
547
|
// default to true if the env doesn't have a preview config
|
|
453
|
-
return (_previewAspectConfig$ = previewAspectConfig === null || previewAspectConfig === void 0 ? void 0 : previewAspectConfig.isScaling) !== null && _previewAspectConfig$ !== void 0 ? _previewAspectConfig$ : true;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* Get the preview config of the component.
|
|
458
|
-
* (config that was set by variants or on bitmap)
|
|
459
|
-
* @param component
|
|
460
|
-
* @returns
|
|
461
|
-
*/
|
|
462
|
-
getPreviewConfig(component) {
|
|
463
|
-
var _component$state$aspe2;
|
|
464
|
-
return (_component$state$aspe2 = component.state.aspects.get(_preview().PreviewAspect.id)) === null || _component$state$aspe2 === void 0 ? void 0 : _component$state$aspe2.config;
|
|
548
|
+
return (_previewAspectConfig$2 = previewAspectConfig === null || previewAspectConfig === void 0 ? void 0 : previewAspectConfig.isScaling) !== null && _previewAspectConfig$2 !== void 0 ? _previewAspectConfig$2 : true;
|
|
465
549
|
}
|
|
466
550
|
|
|
467
551
|
/**
|
|
@@ -473,7 +557,7 @@ class PreviewMain {
|
|
|
473
557
|
async isLegacyHeader(component) {
|
|
474
558
|
// these envs had header in their docs
|
|
475
559
|
const ENV_WITH_LEGACY_DOCS = ['react', 'env', 'aspect', 'lit', 'html', 'node', 'mdx', 'react-native', 'readme'];
|
|
476
|
-
const artifacts = await this.builder.getArtifactsVinylByAspectAndName(component, _preview().PreviewAspect.id,
|
|
560
|
+
const artifacts = await this.builder.getArtifactsVinylByAspectAndName(component, _preview().PreviewAspect.id, _strategies().ENV_STRATEGY_ARTIFACT_NAME);
|
|
477
561
|
const envType = this.envs.getEnvData(component).type;
|
|
478
562
|
return !!artifacts && !!artifacts.length && ENV_WITH_LEGACY_DOCS.includes(envType);
|
|
479
563
|
}
|
|
@@ -715,16 +799,7 @@ class PreviewMain {
|
|
|
715
799
|
if (workspace) {
|
|
716
800
|
workspace.registerOnComponentAdd(c => preview.handleComponentChange(c, currentComponents => currentComponents.add(c)));
|
|
717
801
|
workspace.onComponentLoad(async component => {
|
|
718
|
-
|
|
719
|
-
const isScaling = await preview.calculateIsEnvSupportScaling(component);
|
|
720
|
-
const data = {
|
|
721
|
-
doesScaling
|
|
722
|
-
};
|
|
723
|
-
// If there is no isScaling result at all, it's probably not an env. don't store any data.
|
|
724
|
-
if (isScaling !== undefined) {
|
|
725
|
-
data.isScaling = isScaling;
|
|
726
|
-
}
|
|
727
|
-
return data;
|
|
802
|
+
return preview.calcPreviewData(component);
|
|
728
803
|
});
|
|
729
804
|
workspace.registerOnComponentChange(c => preview.handleComponentChange(c, currentComponents => currentComponents.update(c)));
|
|
730
805
|
workspace.registerOnComponentRemove(cId => preview.handleComponentRemoval(cId));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["noopResult","results","toString","DEFAULT_TEMP_DIR","join","CACHE_ROOT","PreviewAspect","id","PreviewMain","constructor","harmony","previewSlot","ui","envs","componentAspect","pkg","aspectLoader","config","bundlingStrategySlot","builder","workspace","logger","dependencyResolver","Map","Date","now","c","updater","env","getEnv","envId","executionRef","executionRefs","get","warn","updateLinkFiles","currentComponents","executionCtx","cId","component","forEach","components","found","Promise","resolve","handleComponentChange","remove","tempFolder","getTempDir","getComponentBundleSize","data","getDataByAspect","undefined","COMPONENT_STRATEGY_SIZE_KEY_NAME","getPreview","artifacts","getArtifactsVinylByAspectAndTaskName","PREVIEW_TASK_NAME","PreviewArtifact","getPreviewFiles","isBundledWithEnv","files","getPaths","getArtifactsVinylByAspectAndName","COMPONENT_STRATEGY_ARTIFACT_NAME","length","calcDoesScalingForComponent","isUsingCoreEnv","isNew","envComponent","getEnvComponent","isEnvSupportScaling","doesScaling","inWorkspace","hasId","envSupportScaling","calculateIsEnvSupportScaling","previewData","state","aspects","isScaling","isEnv","previewAspectConfig","getPreviewConfig","isLegacyHeader","ENV_WITH_LEGACY_DOCS","ENV_STRATEGY_ARTIFACT_NAME","envType","getEnvData","type","includes","getEnvTemplate","GENERATE_ENV_TEMPLATE_TASK_NAME","getCoreEnvTemplate","coreEnvDir","getAspectDir","artifactDef","getEnvTemplateArtifactDef","artifactFactory","ArtifactFactory","rootDir","getRootDir","existsSync","coreEnvDirFromBvm","getAspectDirFromBvm","paths","resolvePaths","artifactFiles","ArtifactFiles","populateVinylsFromPaths","vinyls","getEnvTemplateFromComponentEnv","getEnvId","getEnvTemplateByEnvId","isCoreEnv","host","getHost","resolvedEnvId","resolveComponentId","BitError","getDefs","values","writeLink","prefix","moduleMap","defaultModule","dirName","isSplitComponentBundle","contents","generateLink","writeLinkContents","targetDir","hash","objectHash","targetPath","timestamp","writeHash","writeFileSync","set","getPreviewTarget","context","relatedContexts","ctxId","ExecutionRef","previewRuntime","writePreviewRuntime","linkFiles","previews","map","previewDef","templatePath","renderTemplatePath","getModuleMap","getEnvPreviewConfig","splitComponentBundle","withPaths","environment","compilerInstance","getCompiler","modulePath","getPreviewComponentRootPath","getRuntimeModulePath","file","path","distRelativePath","getDistPathBySrcPath","relative","dirPath","mkdirSync","recursive","link","all","aspectsIdsToNotFilterOut","name","uiRoot","getUi","resolvedAspects","resolveAspects","PreviewRuntime","filteredAspects","filterAspectsByExecutionContext","filePath","generateRoot","runtimeName","componentIds","opts","root","MainRuntime","Error","allComponentContextAspects","reduce","acc","curr","concat","ids","hostAspects","Object","keys","toObject","allAspectsToInclude","uniq","filtered","filter","aspect","getId","isCoreAspect","getDefaultStrategies","EnvBundlingStrategy","ComponentBundlingStrategy","getBundlingStrategy","defaultStrategies","envPreviewConfig","strategyFromEnv","strategyName","bundlingStrategy","strategies","selected","find","strategy","BundlingStrategyNotFound","registerBundlingStrategy","register","registerDefinition","provider","bundler","componentExtension","uiMain","pubsub","loggerMain","graphql","createLogger","preview","registerStartPlugin","PreviewStartPlugin","registerRoute","PreviewRoute","ComponentPreviewRoute","EnvTemplateRoute","PreviewAssetsRoute","registerTarget","entry","bind","disabled","registerBuildTasks","EnvPreviewTemplateTask","PreviewTask","registerOnComponentAdd","add","onComponentLoad","registerOnComponentChange","update","registerOnComponentRemove","handleComponentRemoval","previewSchema","Slot","withType","BundlerAspect","BuilderAspect","ComponentAspect","UIAspect","EnvsAspect","WorkspaceAspect","PkgAspect","PubsubAspect","AspectLoaderAspect","LoggerAspect","DependencyResolverAspect","GraphqlAspect","addRuntime"],"sources":["preview.main.runtime.tsx"],"sourcesContent":["import { ArtifactFactory, BuilderAspect } from '@teambit/builder';\nimport type { BuilderMain } from '@teambit/builder';\nimport { Asset, BundlerAspect, BundlerMain } from '@teambit/bundler';\nimport { PubsubAspect, PubsubMain } from '@teambit/pubsub';\nimport { MainRuntime } from '@teambit/cli';\nimport {\n Component,\n ComponentAspect,\n ComponentMain,\n ComponentMap,\n ComponentID,\n ResolveAspectsOptions,\n} from '@teambit/component';\nimport { EnvsAspect } from '@teambit/envs';\nimport type { EnvsMain, ExecutionContext, PreviewEnv } from '@teambit/envs';\nimport { Slot, SlotRegistry, Harmony } from '@teambit/harmony';\nimport { UIAspect, UiMain, UIRoot } from '@teambit/ui';\nimport { CACHE_ROOT } from '@teambit/legacy/dist/constants';\nimport { BitError } from '@teambit/bit-error';\nimport objectHash from 'object-hash';\nimport { uniq } from 'lodash';\nimport { writeFileSync, existsSync, mkdirSync } from 'fs-extra';\nimport { join } from 'path';\nimport { PkgAspect, PkgMain } from '@teambit/pkg';\nimport { AspectLoaderAspect, getAspectDir, getAspectDirFromBvm } from '@teambit/aspect-loader';\nimport type { AspectDefinition, AspectLoaderMain } from '@teambit/aspect-loader';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { LoggerAspect, LoggerMain, Logger } from '@teambit/logger';\nimport { DependencyResolverAspect } from '@teambit/dependency-resolver';\nimport type { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { ArtifactFiles } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';\nimport GraphqlAspect, { GraphqlMain } from '@teambit/graphql';\nimport { BundlingStrategyNotFound } from './exceptions';\nimport { generateLink } from './generate-link';\nimport { PreviewArtifact } from './preview-artifact';\nimport { PreviewDefinition } from './preview-definition';\nimport { PreviewAspect, PreviewRuntime } from './preview.aspect';\nimport { PreviewRoute } from './preview.route';\nimport { PreviewTask, PREVIEW_TASK_NAME } from './preview.task';\nimport { BundlingStrategy } from './bundling-strategy';\nimport { EnvBundlingStrategy, ComponentBundlingStrategy } from './strategies';\nimport { ExecutionRef } from './execution-ref';\nimport { PreviewStartPlugin } from './preview.start-plugin';\nimport {\n EnvPreviewTemplateTask,\n GENERATE_ENV_TEMPLATE_TASK_NAME,\n getArtifactDef as getEnvTemplateArtifactDef,\n} from './env-preview-template.task';\nimport { EnvTemplateRoute } from './env-template.route';\nimport { ComponentPreviewRoute } from './component-preview.route';\nimport { COMPONENT_STRATEGY_ARTIFACT_NAME, COMPONENT_STRATEGY_SIZE_KEY_NAME } from './strategies/component-strategy';\nimport { ENV_STRATEGY_ARTIFACT_NAME } from './strategies/env-strategy';\nimport { previewSchema } from './preview.graphql';\nimport { PreviewAssetsRoute } from './preview-assets.route';\n\nconst noopResult = {\n results: [],\n toString: () => `updating link file`,\n};\n\nconst DEFAULT_TEMP_DIR = join(CACHE_ROOT, PreviewAspect.id);\n\nexport type PreviewDefinitionRegistry = SlotRegistry<PreviewDefinition>;\n\ntype PreviewFiles = {\n files: string[];\n isBundledWithEnv: boolean;\n};\n\nexport type ComponentPreviewSizedFile = Asset;\n\nexport type ComponentPreviewSize = {\n files: ComponentPreviewSizedFile[];\n assets: ComponentPreviewSizedFile[];\n totalFiles: number;\n compressedTotalFiles?: number;\n totalAssets: number;\n compressedTotalAssets?: number;\n total: number;\n compressedTotal?: number;\n};\n\nexport type ComponentPreviewMetaData = {\n size?: ComponentPreviewSize;\n};\n\nexport type PreviewVariantConfig = {\n isScaling?: boolean;\n};\n\n/**\n * Preview data that stored on the component on load\n */\nexport type PreviewComponentData = {\n doesScaling?: boolean;\n isScaling?: boolean;\n};\n\nexport type PreviewConfig = {\n bundlingStrategy?: string;\n disabled: boolean;\n /**\n * limit concurrent components when running the bundling step for your bundler during generate components preview task.\n * 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.\n * default - no limit.\n */\n maxChunkSize?: number;\n};\n\nexport type EnvPreviewConfig = {\n strategyName?: string;\n splitComponentBundle?: boolean;\n};\n\nexport type BundlingStrategySlot = SlotRegistry<BundlingStrategy>;\n\nexport type GenerateLinkFn = (prefix: string, componentMap: ComponentMap<string[]>, defaultModule?: string) => string;\n\nexport class PreviewMain {\n constructor(\n /**\n * harmony context.\n */\n private harmony: Harmony,\n\n /**\n * slot for preview definitions.\n */\n private previewSlot: PreviewDefinitionRegistry,\n\n private ui: UiMain,\n\n private envs: EnvsMain,\n\n private componentAspect: ComponentMain,\n\n private pkg: PkgMain,\n\n private aspectLoader: AspectLoaderMain,\n\n readonly config: PreviewConfig,\n\n private bundlingStrategySlot: BundlingStrategySlot,\n\n private builder: BuilderMain,\n\n private workspace: Workspace | undefined,\n\n private logger: Logger,\n\n private dependencyResolver: DependencyResolverMain\n ) {}\n\n get tempFolder(): string {\n return this.workspace?.getTempDir(PreviewAspect.id) || DEFAULT_TEMP_DIR;\n }\n\n getComponentBundleSize(component: Component): ComponentPreviewSize | undefined {\n const data = this.builder.getDataByAspect(component, PreviewAspect.id);\n\n if (!data) return undefined;\n return data[COMPONENT_STRATEGY_SIZE_KEY_NAME];\n }\n\n async getPreview(component: Component): Promise<PreviewArtifact | undefined> {\n const artifacts = await this.builder.getArtifactsVinylByAspectAndTaskName(\n component,\n PreviewAspect.id,\n PREVIEW_TASK_NAME\n );\n if (!artifacts) return undefined;\n return new PreviewArtifact(artifacts);\n }\n\n /**\n * Get a list of all the artifact files generated during the GeneratePreview task\n * @param component\n * @returns\n */\n async getPreviewFiles(component: Component): Promise<PreviewFiles | undefined> {\n const artifacts = await this.getPreview(component);\n const isBundledWithEnv = await this.isBundledWithEnv(component);\n if (!artifacts) return undefined;\n return {\n files: artifacts.getPaths(),\n isBundledWithEnv,\n };\n }\n\n /**\n * Check if the component preview bundle contain the env as part of the bundle or only the component code\n * (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)\n * @param component\n * @returns\n */\n async isBundledWithEnv(component: Component): Promise<boolean> {\n const artifacts = await this.builder.getArtifactsVinylByAspectAndName(\n component,\n PreviewAspect.id,\n COMPONENT_STRATEGY_ARTIFACT_NAME\n );\n if (!artifacts || !artifacts.length) return true;\n\n return false;\n }\n\n // This used on component load to calc the final result of support is scaling for a given component\n // This calc based on the env, env data, env preview config and more\n // if you want to get the final result use the `doesScaling` method below\n // This should be used only for component load\n private async calcDoesScalingForComponent(component: Component): Promise<boolean> {\n const isBundledWithEnv = await this.isBundledWithEnv(component);\n // if it's a core env and the env template is apart from the component it means the template bundle already contain the scaling functionality\n if (this.envs.isUsingCoreEnv(component)) {\n // If the component is new, no point to check the is bundle with env (there is no artifacts so it will for sure return false)\n // If it's new, and we are here, it means that we already use a version of the env that support scaling\n const isNew = await component.isNew();\n if (isNew) {\n return true;\n }\n return isBundledWithEnv === false;\n }\n // For envs that bundled with the env return true always\n if (isBundledWithEnv) {\n return true;\n }\n const envComponent = await this.envs.getEnvComponent(component);\n return this.isEnvSupportScaling(envComponent);\n }\n\n /**\n * can the current component preview scale in size for different preview sizes.\n * this calculation is based on the env of the component and if the env of the component support it.\n */\n async doesScaling(component: Component): Promise<boolean> {\n const inWorkspace = await this.workspace?.hasId(component.id);\n // Support case when we have the dev server for the env, in that case we calc the data of the env as we can't rely on the env data from the scope\n // since we bundle it for the dev server again\n if (inWorkspace) {\n const envComponent = await this.envs.getEnvComponent(component);\n const envSupportScaling = await this.calculateIsEnvSupportScaling(envComponent);\n return envSupportScaling ?? true;\n }\n const previewData = component.state.aspects.get(PreviewAspect.id)?.data;\n if (!previewData) return false;\n // Get the does scaling (the new calculation) or the old calc used in isScaling (between versions (about) 848 and 860)\n if (previewData.doesScaling !== undefined) return previewData.doesScaling;\n // in case this component were tagged with versions between 848 and 860 we need to use the old calculation\n // together with the env calculation\n // In that case it means the component already tagged, so we take the env calc from the env data and not re-calc it\n if (previewData.isScaling) {\n const envComponent = await this.envs.getEnvComponent(component);\n const envSupportScaling = this.isEnvSupportScaling(envComponent);\n return !!envSupportScaling;\n }\n return false;\n }\n\n /**\n * Check if the current version of the env support scaling\n * @param envComponent\n * @returns\n */\n isEnvSupportScaling(envComponent: Component): boolean {\n const previewData = envComponent.state.aspects.get(PreviewAspect.id)?.data;\n return !!previewData?.isScaling;\n }\n\n /**\n * This function is calculate the isScaling support flag for the component preview.\n * This is calculated only for the env component and not for the component itself.\n * It should be only used during the (env) component on load.\n * Once the component load, you should only use the `isEnvSupportScaling` to fetch it from the calculated data.\n * If you want to check if an env for a given component support scaling, use the `isScaling` function.\n * @param component\n * @returns\n */\n private async calculateIsEnvSupportScaling(envComponent: Component): Promise<boolean | undefined> {\n const isEnv = this.envs.isEnv(envComponent);\n // If the component is not an env, we don't want to store anything in the data\n if (!isEnv) return undefined;\n const previewAspectConfig = this.getPreviewConfig(envComponent);\n // default to true if the env doesn't have a preview config\n return previewAspectConfig?.isScaling ?? true;\n }\n\n /**\n * Get the preview config of the component.\n * (config that was set by variants or on bitmap)\n * @param component\n * @returns\n */\n getPreviewConfig(component: Component): PreviewVariantConfig | undefined {\n return component.state.aspects.get(PreviewAspect.id)?.config;\n }\n\n /**\n * Check if the component preview bundle contain the header inside of it (legacy)\n * today we are not including the header inside anymore\n * @param component\n * @returns\n */\n async isLegacyHeader(component: Component): Promise<boolean> {\n // these envs had header in their docs\n const ENV_WITH_LEGACY_DOCS = ['react', 'env', 'aspect', 'lit', 'html', 'node', 'mdx', 'react-native', 'readme'];\n\n const artifacts = await this.builder.getArtifactsVinylByAspectAndName(\n component,\n PreviewAspect.id,\n ENV_STRATEGY_ARTIFACT_NAME\n );\n const envType = this.envs.getEnvData(component).type;\n return !!artifacts && !!artifacts.length && ENV_WITH_LEGACY_DOCS.includes(envType);\n }\n\n /**\n * Getting the env template artifact\n * This should be called with the env itself or it will return undefined\n * If you want to get the env template from the env of the component,\n * use: getEnvTemplateFromComponentEnv below\n *\n * @param component\n * @returns\n */\n async getEnvTemplate(component: Component): Promise<PreviewArtifact | undefined> {\n const artifacts = await this.builder.getArtifactsVinylByAspectAndTaskName(\n component,\n PreviewAspect.id,\n GENERATE_ENV_TEMPLATE_TASK_NAME\n );\n if (!artifacts || !artifacts.length) return undefined;\n\n return new PreviewArtifact(artifacts);\n }\n\n /**\n * This is a special method to get a core env template\n * As the core envs doesn't exist in the scope we need to bring it from other place\n * We will bring it from the core env package files\n */\n private async getCoreEnvTemplate(envId: string): Promise<PreviewArtifact | undefined> {\n const coreEnvDir = getAspectDir(envId);\n // const finalDir = join(coreEnvDir, getEnvTemplateArtifactDirectory());\n const artifactDef = getEnvTemplateArtifactDef()[0];\n const artifactFactory = new ArtifactFactory();\n\n let rootDir = artifactFactory.getRootDir(coreEnvDir, artifactDef);\n if (!existsSync(rootDir)) {\n // fallback to the bvm folder\n const coreEnvDirFromBvm = getAspectDirFromBvm(envId);\n rootDir = artifactFactory.getRootDir(coreEnvDirFromBvm, artifactDef);\n }\n if (!existsSync(rootDir)) {\n return undefined;\n }\n const paths = artifactFactory.resolvePaths(rootDir, artifactDef);\n if (!paths || !paths.length) {\n return undefined;\n }\n const artifactFiles = new ArtifactFiles(paths);\n\n artifactFiles.populateVinylsFromPaths(rootDir);\n return new PreviewArtifact(artifactFiles.vinyls);\n }\n\n /**\n * This will fetch the component env, then will take the env template from the component env\n * @param component\n */\n async getEnvTemplateFromComponentEnv(component: Component): Promise<PreviewArtifact | undefined> {\n const envId = this.envs.getEnvId(component);\n return this.getEnvTemplateByEnvId(envId);\n }\n\n /**\n * This will fetch the component env, then will take the env template from the component env\n * @param component\n */\n async getEnvTemplateByEnvId(envId: string): Promise<PreviewArtifact | undefined> {\n // Special treatment for core envs\n if (this.aspectLoader.isCoreEnv(envId)) {\n return this.getCoreEnvTemplate(envId);\n }\n const host = this.componentAspect.getHost();\n const resolvedEnvId = await host.resolveComponentId(envId);\n const envComponent = await host.get(resolvedEnvId);\n if (!envComponent) {\n throw new BitError(`can't load env. env id is ${envId}`);\n }\n return this.getEnvTemplate(envComponent);\n }\n\n getDefs(): PreviewDefinition[] {\n return this.previewSlot.values();\n }\n\n private writeHash = new Map<string, string>();\n private timestamp = Date.now();\n\n /**\n * write a link to load custom modules dynamically.\n * @param prefix write\n * @param moduleMap map of components to module paths to require.\n * @param defaultModule\n * @param dirName\n */\n writeLink(\n prefix: string,\n moduleMap: ComponentMap<string[]>,\n defaultModule: string | undefined,\n dirName: string,\n isSplitComponentBundle: boolean\n ) {\n const contents = generateLink(prefix, moduleMap, defaultModule, isSplitComponentBundle);\n return this.writeLinkContents(contents, dirName, prefix);\n }\n\n writeLinkContents(contents: string, targetDir: string, prefix: string) {\n const hash = objectHash(contents);\n const targetPath = join(targetDir, `${prefix}-${this.timestamp}.js`);\n\n // write only if link has changed (prevents triggering fs watches)\n if (this.writeHash.get(targetPath) !== hash) {\n writeFileSync(targetPath, contents);\n this.writeHash.set(targetPath, hash);\n }\n\n return targetPath;\n }\n\n private executionRefs = new Map<string, ExecutionRef>();\n\n private async getPreviewTarget(\n /** execution context (of the specific env) */\n context: ExecutionContext\n ): Promise<string[]> {\n // store context for later link-file updates\n // also register related envs that this context is acting on their behalf\n [context.id, ...context.relatedContexts].forEach((ctxId) => {\n this.executionRefs.set(ctxId, new ExecutionRef(context));\n });\n\n const previewRuntime = await this.writePreviewRuntime(context);\n const linkFiles = await this.updateLinkFiles(context.components, context);\n\n return [...linkFiles, previewRuntime];\n }\n\n private updateLinkFiles(components: Component[] = [], context: ExecutionContext) {\n const previews = this.previewSlot.values();\n const paths = previews.map(async (previewDef) => {\n const templatePath = await previewDef.renderTemplatePath?.(context);\n\n const map = await previewDef.getModuleMap(components);\n const isSplitComponentBundle = this.getEnvPreviewConfig().splitComponentBundle ?? false;\n const withPaths = map.map<string[]>((files, component) => {\n const environment = this.envs.getEnv(component).env;\n const compilerInstance = environment.getCompiler?.();\n const modulePath =\n compilerInstance?.getPreviewComponentRootPath?.(component) || this.pkg.getRuntimeModulePath(component);\n return files.map((file) => {\n if (!this.workspace || !compilerInstance) {\n return file.path;\n }\n const distRelativePath = compilerInstance.getDistPathBySrcPath(file.relative);\n return join(this.workspace.path, modulePath, distRelativePath);\n });\n // return files.map((file) => file.path);\n });\n\n const dirPath = join(this.tempFolder, context.id);\n if (!existsSync(dirPath)) mkdirSync(dirPath, { recursive: true });\n\n const link = this.writeLink(previewDef.prefix, withPaths, templatePath, dirPath, isSplitComponentBundle);\n return link;\n });\n\n return Promise.all(paths);\n }\n\n async writePreviewRuntime(context: { components: Component[] }, aspectsIdsToNotFilterOut: string[] = []) {\n const [name, uiRoot] = this.getUi();\n const resolvedAspects = await this.resolveAspects(PreviewRuntime.name, undefined, uiRoot);\n const filteredAspects = this.filterAspectsByExecutionContext(resolvedAspects, context, aspectsIdsToNotFilterOut);\n const filePath = await this.ui.generateRoot(filteredAspects, name, 'preview', PreviewAspect.id);\n return filePath;\n }\n\n async resolveAspects(\n runtimeName?: string,\n componentIds?: ComponentID[],\n uiRoot?: UIRoot,\n opts?: ResolveAspectsOptions\n ): Promise<AspectDefinition[]> {\n const root = uiRoot || this.getUi()[1];\n runtimeName = runtimeName || MainRuntime.name;\n const resolvedAspects = await root.resolveAspects(runtimeName, componentIds, opts);\n return resolvedAspects;\n }\n\n private getUi() {\n const ui = this.ui.getUi();\n if (!ui) throw new Error('ui not found');\n return ui;\n }\n\n /**\n * Filter the aspects to have only aspects that are:\n * 1. core aspects\n * 2. configured on the host (workspace/scope)\n * 3. used by at least one component from the context\n * @param aspects\n * @param context\n */\n private filterAspectsByExecutionContext(\n aspects: AspectDefinition[],\n context: { components: Component[] },\n aspectsIdsToNotFilterOut: string[] = []\n ) {\n let allComponentContextAspects: string[] = [];\n allComponentContextAspects = context.components.reduce((acc, curr) => {\n return acc.concat(curr.state.aspects.ids);\n }, allComponentContextAspects);\n const hostAspects = Object.keys(this.harmony.config.toObject());\n const allAspectsToInclude = uniq(hostAspects.concat(allComponentContextAspects));\n const filtered = aspects.filter((aspect) => {\n if (!aspect.getId) {\n return false;\n }\n return (\n this.aspectLoader.isCoreAspect(aspect.getId) ||\n allAspectsToInclude.includes(aspect.getId) ||\n aspectsIdsToNotFilterOut.includes(aspect.getId)\n );\n });\n\n return filtered;\n }\n\n private getDefaultStrategies() {\n return [\n new EnvBundlingStrategy(this, this.pkg, this.dependencyResolver),\n new ComponentBundlingStrategy(this, this.pkg, this.dependencyResolver),\n ];\n }\n\n // TODO - executionContext should be responsible for updating components list, and emit 'update' events\n // instead we keep track of changes\n private handleComponentChange = async (c: Component, updater: (currentComponents: ExecutionRef) => void) => {\n const env = this.envs.getEnv(c);\n const envId = env.id.toString();\n\n const executionRef = this.executionRefs.get(envId);\n if (!executionRef) {\n this.logger.warn(\n `failed to update link file for component \"${c.id.toString()}\" - could not find execution context for ${envId}`\n );\n return noopResult;\n }\n\n // add / remove / etc\n updater(executionRef);\n\n await this.updateLinkFiles(executionRef.currentComponents, executionRef.executionCtx);\n\n return noopResult;\n };\n\n private handleComponentRemoval = (cId: ComponentID) => {\n let component: Component | undefined;\n this.executionRefs.forEach((components) => {\n const found = components.get(cId);\n if (found) component = found;\n });\n if (!component) return Promise.resolve(noopResult);\n\n return this.handleComponentChange(component, (currentComponents) => currentComponents.remove(cId));\n };\n\n getEnvPreviewConfig(env?: PreviewEnv): EnvPreviewConfig {\n const config = env?.getPreviewConfig && typeof env?.getPreviewConfig === 'function' ? env?.getPreviewConfig() : {};\n\n return config;\n }\n\n /**\n * return the configured bundling strategy.\n */\n getBundlingStrategy(env?: PreviewEnv): BundlingStrategy {\n const defaultStrategies = this.getDefaultStrategies();\n const envPreviewConfig = this.getEnvPreviewConfig(env);\n const strategyFromEnv = envPreviewConfig?.strategyName;\n const strategyName = strategyFromEnv || this.config.bundlingStrategy || 'env';\n const strategies = this.bundlingStrategySlot.values().concat(defaultStrategies);\n const selected = strategies.find((strategy) => {\n return strategy.name === strategyName;\n });\n\n if (!selected) throw new BundlingStrategyNotFound(strategyName);\n\n return selected;\n }\n\n /**\n * register a new bundling strategy. default available strategies are `env` and ``\n */\n registerBundlingStrategy(bundlingStrategy: BundlingStrategy) {\n this.bundlingStrategySlot.register(bundlingStrategy);\n return this;\n }\n\n /**\n * register a new preview definition.\n */\n registerDefinition(previewDef: PreviewDefinition) {\n this.previewSlot.register(previewDef);\n }\n\n static slots = [Slot.withType<PreviewDefinition>(), Slot.withType<BundlingStrategy>()];\n\n static runtime = MainRuntime;\n static dependencies = [\n BundlerAspect,\n BuilderAspect,\n ComponentAspect,\n UIAspect,\n EnvsAspect,\n WorkspaceAspect,\n PkgAspect,\n PubsubAspect,\n AspectLoaderAspect,\n LoggerAspect,\n DependencyResolverAspect,\n GraphqlAspect,\n ];\n\n static defaultConfig = {\n disabled: false,\n };\n\n static async provider(\n // eslint-disable-next-line max-len\n [\n bundler,\n builder,\n componentExtension,\n uiMain,\n envs,\n workspace,\n pkg,\n pubsub,\n aspectLoader,\n loggerMain,\n dependencyResolver,\n graphql,\n ]: [\n BundlerMain,\n BuilderMain,\n ComponentMain,\n UiMain,\n EnvsMain,\n Workspace | undefined,\n PkgMain,\n PubsubMain,\n AspectLoaderMain,\n LoggerMain,\n DependencyResolverMain,\n GraphqlMain\n ],\n config: PreviewConfig,\n [previewSlot, bundlingStrategySlot]: [PreviewDefinitionRegistry, BundlingStrategySlot],\n harmony: Harmony\n ) {\n const logger = loggerMain.createLogger(PreviewAspect.id);\n // app.registerApp(new PreviewApp());\n const preview = new PreviewMain(\n harmony,\n previewSlot,\n uiMain,\n envs,\n componentExtension,\n pkg,\n aspectLoader,\n config,\n bundlingStrategySlot,\n builder,\n workspace,\n logger,\n dependencyResolver\n );\n\n if (workspace) uiMain.registerStartPlugin(new PreviewStartPlugin(workspace, bundler, uiMain, pubsub, logger));\n\n componentExtension.registerRoute([\n new PreviewRoute(preview, logger),\n new ComponentPreviewRoute(preview, logger),\n // @ts-ignore\n new EnvTemplateRoute(preview, logger),\n new PreviewAssetsRoute(preview, logger),\n ]);\n\n bundler.registerTarget([\n {\n entry: preview.getPreviewTarget.bind(preview),\n },\n ]);\n\n if (!config.disabled)\n builder.registerBuildTasks([\n new EnvPreviewTemplateTask(preview, envs, aspectLoader, dependencyResolver, logger),\n new PreviewTask(bundler, preview, dependencyResolver, logger),\n ]);\n\n if (workspace) {\n workspace.registerOnComponentAdd((c) =>\n preview.handleComponentChange(c, (currentComponents) => currentComponents.add(c))\n );\n workspace.onComponentLoad(async (component) => {\n const doesScaling = await preview.calcDoesScalingForComponent(component);\n const isScaling = await preview.calculateIsEnvSupportScaling(component);\n const data: PreviewComponentData = {\n doesScaling,\n };\n // If there is no isScaling result at all, it's probably not an env. don't store any data.\n if (isScaling !== undefined) {\n data.isScaling = isScaling;\n }\n return data;\n });\n workspace.registerOnComponentChange((c) =>\n preview.handleComponentChange(c, (currentComponents) => currentComponents.update(c))\n );\n workspace.registerOnComponentRemove((cId) => preview.handleComponentRemoval(cId));\n }\n\n graphql.register(previewSchema(preview));\n\n return preview;\n }\n}\n\nPreviewAspect.addRuntime(PreviewMain);\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;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;AAQA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;A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AC,CAAC;IAExC,OAAOA,OAAO;EAChB;AACF;AAAC;AAAA,gCA7mBY/N,WAAW,WAofP,CAACsP,eAAI,CAACC,QAAQ,EAAqB,EAAED,eAAI,CAACC,QAAQ,EAAoB,CAAC;AAAA,gCApf3EvP,WAAW,aAsfLmL,kBAAW;AAAA,gCAtfjBnL,WAAW,kBAufA,CACpBwP,wBAAa,EACbC,wBAAa,EACbC,4BAAe,EACfC,cAAQ,EACRC,kBAAU,EACVC,oBAAe,EACfC,gBAAS,EACTC,sBAAY,EACZC,kCAAkB,EAClBC,sBAAY,EACZC,8CAAwB,EACxBC,kBAAa,CACd;AAAA,gCApgBUnQ,WAAW,mBAsgBC;EACrB0O,QAAQ,EAAE;AACZ,CAAC;AAuGH5O,wBAAa,CAACsQ,UAAU,CAACpQ,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"names":["noopResult","results","toString","DEFAULT_TEMP_DIR","join","CACHE_ROOT","PreviewAspect","id","PreviewMain","constructor","harmony","previewSlot","ui","envs","componentAspect","pkg","aspectLoader","config","bundlingStrategySlot","builder","workspace","logger","dependencyResolver","Map","Date","now","c","updater","env","getEnv","envId","executionRef","executionRefs","get","warn","updateLinkFiles","currentComponents","executionCtx","cId","component","forEach","components","found","Promise","resolve","handleComponentChange","remove","tempFolder","getTempDir","getComponentBundleSize","data","getDataByAspect","undefined","COMPONENT_STRATEGY_SIZE_KEY_NAME","getPreview","artifacts","getArtifactsVinylByAspectAndTaskName","PREVIEW_TASK_NAME","PreviewArtifact","getPreviewFiles","isBundledWithEnv","files","getPaths","getPreviewAspectConfig","state","aspects","getPreviewData","previewData","calcPreviewData","doesScaling","calcDoesScalingForComponent","dataFromEnv","calcPreviewDataFromEnv","envData","calculateDataForEnvComponent","toStringWithoutVersion","strategyName","COMPONENT_PREVIEW_STRATEGY_NAME","splitComponentBundle","envPreviewConfig","getEnvPreviewConfig","envComponent","isEnv","previewAspectConfig","isScaling","calcIsBundledWithEnv","envPreviewData","isBundledWithEnvBackward","ENV_PREVIEW_STRATEGY_NAME","getArtifactsVinylByAspectAndName","COMPONENT_STRATEGY_ARTIFACT_NAME","length","isUsingCoreEnv","isNew","getEnvComponent","isEnvSupportScaling","inWorkspace","hasId","envSupportScaling","calculateIsEnvSupportScaling","isLegacyHeader","ENV_WITH_LEGACY_DOCS","ENV_STRATEGY_ARTIFACT_NAME","envType","getEnvData","type","includes","getEnvTemplate","GENERATE_ENV_TEMPLATE_TASK_NAME","getCoreEnvTemplate","coreEnvDir","getAspectDir","artifactDef","getEnvTemplateArtifactDef","artifactFactory","ArtifactFactory","rootDir","getRootDir","existsSync","coreEnvDirFromBvm","getAspectDirFromBvm","paths","resolvePaths","artifactFiles","ArtifactFiles","populateVinylsFromPaths","vinyls","getEnvTemplateFromComponentEnv","getEnvId","getEnvTemplateByEnvId","isCoreEnv","host","getHost","resolvedEnvId","resolveComponentId","BitError","getDefs","values","writeLink","prefix","moduleMap","defaultModule","dirName","isSplitComponentBundle","contents","generateLink","writeLinkContents","targetDir","hash","objectHash","targetPath","timestamp","writeHash","writeFileSync","set","getPreviewTarget","context","relatedContexts","ctxId","ExecutionRef","previewRuntime","writePreviewRuntime","linkFiles","previews","map","previewDef","templatePath","renderTemplatePath","getModuleMap","withPaths","environment","compilerInstance","getCompiler","modulePath","getPreviewComponentRootPath","getRuntimeModulePath","file","path","distRelativePath","getDistPathBySrcPath","relative","dirPath","mkdirSync","recursive","link","all","aspectsIdsToNotFilterOut","name","uiRoot","getUi","resolvedAspects","resolveAspects","PreviewRuntime","filteredAspects","filterAspectsByExecutionContext","filePath","generateRoot","runtimeName","componentIds","opts","root","MainRuntime","Error","allComponentContextAspects","reduce","acc","curr","concat","ids","hostAspects","Object","keys","toObject","allAspectsToInclude","uniq","filtered","filter","aspect","getId","isCoreAspect","getDefaultStrategies","EnvBundlingStrategy","ComponentBundlingStrategy","getPreviewConfig","getBundlingStrategy","defaultStrategies","strategyFromEnv","bundlingStrategy","strategies","selected","find","strategy","BundlingStrategyNotFound","registerBundlingStrategy","register","registerDefinition","provider","bundler","componentExtension","uiMain","pubsub","loggerMain","graphql","createLogger","preview","registerStartPlugin","PreviewStartPlugin","registerRoute","PreviewRoute","ComponentPreviewRoute","EnvTemplateRoute","PreviewAssetsRoute","registerTarget","entry","bind","disabled","registerBuildTasks","EnvPreviewTemplateTask","PreviewTask","registerOnComponentAdd","add","onComponentLoad","registerOnComponentChange","update","registerOnComponentRemove","handleComponentRemoval","previewSchema","Slot","withType","BundlerAspect","BuilderAspect","ComponentAspect","UIAspect","EnvsAspect","WorkspaceAspect","PkgAspect","PubsubAspect","AspectLoaderAspect","LoggerAspect","DependencyResolverAspect","GraphqlAspect","addRuntime"],"sources":["preview.main.runtime.tsx"],"sourcesContent":["import { ArtifactFactory, BuilderAspect } from '@teambit/builder';\nimport type { BuilderMain } from '@teambit/builder';\nimport { Asset, BundlerAspect, BundlerMain } from '@teambit/bundler';\nimport { PubsubAspect, PubsubMain } from '@teambit/pubsub';\nimport { MainRuntime } from '@teambit/cli';\nimport {\n Component,\n ComponentAspect,\n ComponentMain,\n ComponentMap,\n ComponentID,\n ResolveAspectsOptions,\n} from '@teambit/component';\nimport { EnvsAspect } from '@teambit/envs';\nimport type { EnvsMain, ExecutionContext, PreviewEnv } from '@teambit/envs';\nimport { Slot, SlotRegistry, Harmony } from '@teambit/harmony';\nimport { UIAspect, UiMain, UIRoot } from '@teambit/ui';\nimport { CACHE_ROOT } from '@teambit/legacy/dist/constants';\nimport { BitError } from '@teambit/bit-error';\nimport objectHash from 'object-hash';\nimport { uniq } from 'lodash';\nimport { writeFileSync, existsSync, mkdirSync } from 'fs-extra';\nimport { join } from 'path';\nimport { PkgAspect, PkgMain } from '@teambit/pkg';\nimport { AspectLoaderAspect, getAspectDir, getAspectDirFromBvm } from '@teambit/aspect-loader';\nimport type { AspectDefinition, AspectLoaderMain } from '@teambit/aspect-loader';\nimport WorkspaceAspect, { Workspace } from '@teambit/workspace';\nimport { LoggerAspect, LoggerMain, Logger } from '@teambit/logger';\nimport { DependencyResolverAspect } from '@teambit/dependency-resolver';\nimport type { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { ArtifactFiles } from '@teambit/legacy/dist/consumer/component/sources/artifact-files';\nimport GraphqlAspect, { GraphqlMain } from '@teambit/graphql';\nimport { BundlingStrategyNotFound } from './exceptions';\nimport { generateLink } from './generate-link';\nimport { PreviewArtifact } from './preview-artifact';\nimport { PreviewDefinition } from './preview-definition';\nimport { PreviewAspect, PreviewRuntime } from './preview.aspect';\nimport { PreviewRoute } from './preview.route';\nimport { PreviewTask, PREVIEW_TASK_NAME } from './preview.task';\nimport { BundlingStrategy } from './bundling-strategy';\nimport {\n EnvBundlingStrategy,\n ComponentBundlingStrategy,\n COMPONENT_STRATEGY_ARTIFACT_NAME,\n COMPONENT_STRATEGY_SIZE_KEY_NAME,\n ENV_PREVIEW_STRATEGY_NAME,\n ENV_STRATEGY_ARTIFACT_NAME,\n COMPONENT_PREVIEW_STRATEGY_NAME,\n} from './strategies';\nimport { ExecutionRef } from './execution-ref';\nimport { PreviewStartPlugin } from './preview.start-plugin';\nimport {\n EnvPreviewTemplateTask,\n GENERATE_ENV_TEMPLATE_TASK_NAME,\n getArtifactDef as getEnvTemplateArtifactDef,\n} from './env-preview-template.task';\nimport { EnvTemplateRoute } from './env-template.route';\nimport { ComponentPreviewRoute } from './component-preview.route';\nimport { previewSchema } from './preview.graphql';\nimport { PreviewAssetsRoute } from './preview-assets.route';\n\nconst noopResult = {\n results: [],\n toString: () => `updating link file`,\n};\n\nconst DEFAULT_TEMP_DIR = join(CACHE_ROOT, PreviewAspect.id);\n\nexport type PreviewDefinitionRegistry = SlotRegistry<PreviewDefinition>;\n\nexport type PreviewStrategyName = 'env' | 'component';\n\nexport type PreviewFiles = {\n files: string[];\n isBundledWithEnv: boolean;\n};\n\nexport type ComponentPreviewSizedFile = Asset;\n\nexport type ComponentPreviewSize = {\n files: ComponentPreviewSizedFile[];\n assets: ComponentPreviewSizedFile[];\n totalFiles: number;\n compressedTotalFiles?: number;\n totalAssets: number;\n compressedTotalAssets?: number;\n total: number;\n compressedTotal?: number;\n};\n\nexport type ComponentPreviewMetaData = {\n size?: ComponentPreviewSize;\n};\n\nexport type PreviewVariantConfig = {\n isScaling?: boolean;\n};\n\n/**\n * Preview data that stored on the component on load\n */\nexport type PreviewComponentData = PreviewAnyComponentData & PreviewEnvComponentData;\n\n/**\n * Preview data that stored on the component on load for any component\n */\nexport type PreviewAnyComponentData = {\n doesScaling?: boolean;\n /**\n * The strategy configured by the component's env\n */\n strategyName?: PreviewStrategyName;\n /**\n * Does the component has a bundle for the component itself (separated from the compositions/docs)\n * Calculated by the component's env\n */\n splitComponentBundle?: boolean;\n};\n\n/**\n * Preview data that stored on the component on load if the component is an env\n */\nexport type PreviewEnvComponentData = {\n isScaling?: boolean;\n};\n\nexport type PreviewConfig = {\n bundlingStrategy?: string;\n disabled: boolean;\n /**\n * limit concurrent components when running the bundling step for your bundler during generate components preview task.\n * 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.\n * default - no limit.\n */\n maxChunkSize?: number;\n};\n\nexport type EnvPreviewConfig = {\n strategyName?: PreviewStrategyName;\n splitComponentBundle?: boolean;\n};\n\nexport type BundlingStrategySlot = SlotRegistry<BundlingStrategy>;\n\nexport type GenerateLinkFn = (prefix: string, componentMap: ComponentMap<string[]>, defaultModule?: string) => string;\n\nexport class PreviewMain {\n constructor(\n /**\n * harmony context.\n */\n private harmony: Harmony,\n\n /**\n * slot for preview definitions.\n */\n private previewSlot: PreviewDefinitionRegistry,\n\n private ui: UiMain,\n\n private envs: EnvsMain,\n\n private componentAspect: ComponentMain,\n\n private pkg: PkgMain,\n\n private aspectLoader: AspectLoaderMain,\n\n readonly config: PreviewConfig,\n\n private bundlingStrategySlot: BundlingStrategySlot,\n\n private builder: BuilderMain,\n\n private workspace: Workspace | undefined,\n\n private logger: Logger,\n\n private dependencyResolver: DependencyResolverMain\n ) {}\n\n get tempFolder(): string {\n return this.workspace?.getTempDir(PreviewAspect.id) || DEFAULT_TEMP_DIR;\n }\n\n getComponentBundleSize(component: Component): ComponentPreviewSize | undefined {\n const data = this.builder.getDataByAspect(component, PreviewAspect.id);\n\n if (!data) return undefined;\n return data[COMPONENT_STRATEGY_SIZE_KEY_NAME];\n }\n\n async getPreview(component: Component): Promise<PreviewArtifact | undefined> {\n const artifacts = await this.builder.getArtifactsVinylByAspectAndTaskName(\n component,\n PreviewAspect.id,\n PREVIEW_TASK_NAME\n );\n if (!artifacts) return undefined;\n return new PreviewArtifact(artifacts);\n }\n\n /**\n * Get a list of all the artifact files generated during the GeneratePreview task\n * @param component\n * @returns\n */\n async getPreviewFiles(component: Component): Promise<PreviewFiles | undefined> {\n const artifacts = await this.getPreview(component);\n const isBundledWithEnv = await this.isBundledWithEnv(component);\n if (!artifacts) return undefined;\n return {\n files: artifacts.getPaths(),\n isBundledWithEnv,\n };\n }\n\n /**\n * Get the preview config of the component.\n * (config that was set by variants or on bitmap)\n * @param component\n * @returns\n */\n getPreviewAspectConfig(component: Component): PreviewVariantConfig | undefined {\n return component.state.aspects.get(PreviewAspect.id)?.config;\n }\n\n /**\n * Get the preview data of the component.\n * (data that was calculated during the on load process)\n * @param component\n * @returns\n */\n getPreviewData(component: Component): PreviewComponentData | undefined {\n const previewData = component.state.aspects.get(PreviewAspect.id)?.data;\n return previewData;\n }\n\n /**\n * Calculate preview data on component load\n * @param component\n * @returns\n */\n async calcPreviewData(component: Component): Promise<PreviewComponentData> {\n const doesScaling = await this.calcDoesScalingForComponent(component);\n const dataFromEnv = await this.calcPreviewDataFromEnv(component);\n const envData = (await this.calculateDataForEnvComponent(component)) || {};\n const data: PreviewComponentData = {\n doesScaling,\n ...dataFromEnv,\n ...envData,\n };\n return data;\n }\n\n /**\n * Calculate preview data on component that configured by its env\n * @param component\n * @returns\n */\n async calcPreviewDataFromEnv(component: Component): Promise<Omit<PreviewAnyComponentData, 'doesScaling'> | undefined> {\n // Prevent infinite loop that caused by the fact that the env of the aspect env or the env env is the same as the component\n // so we can't load it since during load we are trying to get env component and load it again\n if (component.id.toStringWithoutVersion() === 'teambit.harmony/aspect' || component.id.toStringWithoutVersion() === 'teambit.envs/env'){\n return {\n strategyName: COMPONENT_PREVIEW_STRATEGY_NAME,\n splitComponentBundle: false,\n }\n }\n\n const env = this.envs.getEnv(component).env;\n const envPreviewConfig = this.getEnvPreviewConfig(env);\n const data = {\n strategyName: envPreviewConfig?.strategyName,\n splitComponentBundle: envPreviewConfig?.splitComponentBundle ?? false,\n };\n return data;\n }\n\n /**\n * calculate extra preview data for env components (on load)\n * @param envComponent\n * @returns\n */\n private async calculateDataForEnvComponent(envComponent: Component): Promise<PreviewEnvComponentData | undefined> {\n const isEnv = this.envs.isEnv(envComponent);\n // If the component is not an env, we don't want to store anything in the data\n if (!isEnv) return undefined;\n const previewAspectConfig = this.getPreviewAspectConfig(envComponent);\n\n const data = {\n // default to true if the env doesn't have a preview config\n isScaling: previewAspectConfig?.isScaling ?? true,\n };\n return data;\n }\n\n /**\n * Check if the component preview bundle contain the env as part of the bundle or only the component code\n * (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)\n * This should be used only for calculating the value on load.\n * otherwise, use the isBundledWithEnv function\n * @param component\n * @returns\n */\n async calcIsBundledWithEnv(component: Component): Promise<boolean> {\n const envPreviewData = await this.calcPreviewDataFromEnv(component);\n return envPreviewData?.strategyName !== 'component';\n }\n\n\n /**\n * Check if the component preview bundle contain the env as part of the bundle or only the component code\n * (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)\n * @param component\n * @returns\n */\n async isBundledWithEnv(component: Component): Promise<boolean> {\n const data = await this.getPreviewData(component);\n // For components that tagged in the past we didn't store the data, so we calculate it the old way\n // We comparing the strategyName to undefined to cover a specific case when it doesn't exist at all.\n if (!data || data.strategyName === undefined) return this.isBundledWithEnvBackward(component);\n return data.strategyName === ENV_PREVIEW_STRATEGY_NAME;\n }\n\n /**\n * This is a legacy calculation for the isBundledWithEnv\n * This calc is based on the component artifacts which is very expensive operation as it requires to fetch and load the artifacts\n * See the new implementation in the isBundledWithEnv method\n * @param component\n * @returns\n */\n private async isBundledWithEnvBackward(component: Component): Promise<boolean> {\n const artifacts = await this.builder.getArtifactsVinylByAspectAndName(\n component,\n PreviewAspect.id,\n COMPONENT_STRATEGY_ARTIFACT_NAME\n );\n if (!artifacts || !artifacts.length) return true;\n\n return false;\n }\n\n // This used on component load to calc the final result of support is scaling for a given component\n // This calc based on the env, env data, env preview config and more\n // if you want to get the final result use the `doesScaling` method below\n // This should be used only for component load\n private async calcDoesScalingForComponent(component: Component): Promise<boolean> {\n const isBundledWithEnv = await this.calcIsBundledWithEnv(component);\n // if it's a core env and the env template is apart from the component it means the template bundle already contain the scaling functionality\n if (this.envs.isUsingCoreEnv(component)) {\n // If the component is new, no point to check the is bundle with env (there is no artifacts so it will for sure return false)\n // If it's new, and we are here, it means that we already use a version of the env that support scaling\n const isNew = await component.isNew();\n if (isNew) {\n return true;\n }\n return isBundledWithEnv === false;\n }\n // For envs that bundled with the env return true always\n if (isBundledWithEnv) {\n return true;\n }\n const envComponent = await this.envs.getEnvComponent(component);\n return this.isEnvSupportScaling(envComponent);\n }\n\n /**\n * can the current component preview scale in size for different preview sizes.\n * this calculation is based on the env of the component and if the env of the component support it.\n */\n async doesScaling(component: Component): Promise<boolean> {\n const inWorkspace = await this.workspace?.hasId(component.id);\n // Support case when we have the dev server for the env, in that case we calc the data of the env as we can't rely on the env data from the scope\n // since we bundle it for the dev server again\n if (inWorkspace) {\n const envComponent = await this.envs.getEnvComponent(component);\n const envSupportScaling = await this.calculateIsEnvSupportScaling(envComponent);\n return envSupportScaling ?? true;\n }\n const previewData = this.getPreviewData(component);\n if (!previewData) return false;\n // Get the does scaling (the new calculation) or the old calc used in isScaling (between versions (about) 848 and 860)\n if (previewData.doesScaling !== undefined) return previewData.doesScaling;\n // in case this component were tagged with versions between 848 and 860 we need to use the old calculation\n // together with the env calculation\n // In that case it means the component already tagged, so we take the env calc from the env data and not re-calc it\n if (previewData.isScaling) {\n const envComponent = await this.envs.getEnvComponent(component);\n const envSupportScaling = this.isEnvSupportScaling(envComponent);\n return !!envSupportScaling;\n }\n return false;\n }\n\n /**\n * Check if the current version of the env support scaling\n * @param envComponent\n * @returns\n */\n isEnvSupportScaling(envComponent: Component): boolean {\n const previewData = this.getPreviewData(envComponent);\n return !!previewData?.isScaling;\n }\n\n /**\n * This function is calculate the isScaling support flag for the component preview.\n * This is calculated only for the env component and not for the component itself.\n * It should be only used during the (env) component on load.\n * Once the component load, you should only use the `isEnvSupportScaling` to fetch it from the calculated data.\n * If you want to check if an env for a given component support scaling, use the `isScaling` function.\n * @param component\n * @returns\n */\n private async calculateIsEnvSupportScaling(envComponent: Component): Promise<boolean | undefined> {\n const isEnv = this.envs.isEnv(envComponent);\n // If the component is not an env, we don't want to store anything in the data\n if (!isEnv) return undefined;\n const previewAspectConfig = this.getPreviewAspectConfig(envComponent);\n // default to true if the env doesn't have a preview config\n return previewAspectConfig?.isScaling ?? true;\n }\n\n /**\n * Check if the component preview bundle contain the header inside of it (legacy)\n * today we are not including the header inside anymore\n * @param component\n * @returns\n */\n async isLegacyHeader(component: Component): Promise<boolean> {\n // these envs had header in their docs\n const ENV_WITH_LEGACY_DOCS = ['react', 'env', 'aspect', 'lit', 'html', 'node', 'mdx', 'react-native', 'readme'];\n\n const artifacts = await this.builder.getArtifactsVinylByAspectAndName(\n component,\n PreviewAspect.id,\n ENV_STRATEGY_ARTIFACT_NAME\n );\n const envType = this.envs.getEnvData(component).type;\n return !!artifacts && !!artifacts.length && ENV_WITH_LEGACY_DOCS.includes(envType);\n }\n\n /**\n * Getting the env template artifact\n * This should be called with the env itself or it will return undefined\n * If you want to get the env template from the env of the component,\n * use: getEnvTemplateFromComponentEnv below\n *\n * @param component\n * @returns\n */\n async getEnvTemplate(component: Component): Promise<PreviewArtifact | undefined> {\n const artifacts = await this.builder.getArtifactsVinylByAspectAndTaskName(\n component,\n PreviewAspect.id,\n GENERATE_ENV_TEMPLATE_TASK_NAME\n );\n if (!artifacts || !artifacts.length) return undefined;\n\n return new PreviewArtifact(artifacts);\n }\n\n /**\n * This is a special method to get a core env template\n * As the core envs doesn't exist in the scope we need to bring it from other place\n * We will bring it from the core env package files\n */\n private async getCoreEnvTemplate(envId: string): Promise<PreviewArtifact | undefined> {\n const coreEnvDir = getAspectDir(envId);\n // const finalDir = join(coreEnvDir, getEnvTemplateArtifactDirectory());\n const artifactDef = getEnvTemplateArtifactDef()[0];\n const artifactFactory = new ArtifactFactory();\n\n let rootDir = artifactFactory.getRootDir(coreEnvDir, artifactDef);\n if (!existsSync(rootDir)) {\n // fallback to the bvm folder\n const coreEnvDirFromBvm = getAspectDirFromBvm(envId);\n rootDir = artifactFactory.getRootDir(coreEnvDirFromBvm, artifactDef);\n }\n if (!existsSync(rootDir)) {\n return undefined;\n }\n const paths = artifactFactory.resolvePaths(rootDir, artifactDef);\n if (!paths || !paths.length) {\n return undefined;\n }\n const artifactFiles = new ArtifactFiles(paths);\n\n artifactFiles.populateVinylsFromPaths(rootDir);\n return new PreviewArtifact(artifactFiles.vinyls);\n }\n\n /**\n * This will fetch the component env, then will take the env template from the component env\n * @param component\n */\n async getEnvTemplateFromComponentEnv(component: Component): Promise<PreviewArtifact | undefined> {\n const envId = this.envs.getEnvId(component);\n return this.getEnvTemplateByEnvId(envId);\n }\n\n /**\n * This will fetch the component env, then will take the env template from the component env\n * @param component\n */\n async getEnvTemplateByEnvId(envId: string): Promise<PreviewArtifact | undefined> {\n // Special treatment for core envs\n if (this.aspectLoader.isCoreEnv(envId)) {\n return this.getCoreEnvTemplate(envId);\n }\n const host = this.componentAspect.getHost();\n const resolvedEnvId = await host.resolveComponentId(envId);\n const envComponent = await host.get(resolvedEnvId);\n if (!envComponent) {\n throw new BitError(`can't load env. env id is ${envId}`);\n }\n return this.getEnvTemplate(envComponent);\n }\n\n getDefs(): PreviewDefinition[] {\n return this.previewSlot.values();\n }\n\n private writeHash = new Map<string, string>();\n private timestamp = Date.now();\n\n /**\n * write a link to load custom modules dynamically.\n * @param prefix write\n * @param moduleMap map of components to module paths to require.\n * @param defaultModule\n * @param dirName\n */\n writeLink(\n prefix: string,\n moduleMap: ComponentMap<string[]>,\n defaultModule: string | undefined,\n dirName: string,\n isSplitComponentBundle: boolean\n ) {\n const contents = generateLink(prefix, moduleMap, defaultModule, isSplitComponentBundle);\n return this.writeLinkContents(contents, dirName, prefix);\n }\n\n writeLinkContents(contents: string, targetDir: string, prefix: string) {\n const hash = objectHash(contents);\n const targetPath = join(targetDir, `${prefix}-${this.timestamp}.js`);\n\n // write only if link has changed (prevents triggering fs watches)\n if (this.writeHash.get(targetPath) !== hash) {\n writeFileSync(targetPath, contents);\n this.writeHash.set(targetPath, hash);\n }\n\n return targetPath;\n }\n\n private executionRefs = new Map<string, ExecutionRef>();\n\n private async getPreviewTarget(\n /** execution context (of the specific env) */\n context: ExecutionContext\n ): Promise<string[]> {\n // store context for later link-file updates\n // also register related envs that this context is acting on their behalf\n [context.id, ...context.relatedContexts].forEach((ctxId) => {\n this.executionRefs.set(ctxId, new ExecutionRef(context));\n });\n\n const previewRuntime = await this.writePreviewRuntime(context);\n const linkFiles = await this.updateLinkFiles(context.components, context);\n\n return [...linkFiles, previewRuntime];\n }\n\n private updateLinkFiles(components: Component[] = [], context: ExecutionContext) {\n const previews = this.previewSlot.values();\n const paths = previews.map(async (previewDef) => {\n const templatePath = await previewDef.renderTemplatePath?.(context);\n\n const map = await previewDef.getModuleMap(components);\n const isSplitComponentBundle = this.getEnvPreviewConfig().splitComponentBundle ?? false;\n const withPaths = map.map<string[]>((files, component) => {\n const environment = this.envs.getEnv(component).env;\n const compilerInstance = environment.getCompiler?.();\n const modulePath =\n compilerInstance?.getPreviewComponentRootPath?.(component) || this.pkg.getRuntimeModulePath(component);\n return files.map((file) => {\n if (!this.workspace || !compilerInstance) {\n return file.path;\n }\n const distRelativePath = compilerInstance.getDistPathBySrcPath(file.relative);\n return join(this.workspace.path, modulePath, distRelativePath);\n });\n // return files.map((file) => file.path);\n });\n\n const dirPath = join(this.tempFolder, context.id);\n if (!existsSync(dirPath)) mkdirSync(dirPath, { recursive: true });\n\n const link = this.writeLink(previewDef.prefix, withPaths, templatePath, dirPath, isSplitComponentBundle);\n return link;\n });\n\n return Promise.all(paths);\n }\n\n async writePreviewRuntime(context: { components: Component[] }, aspectsIdsToNotFilterOut: string[] = []) {\n const [name, uiRoot] = this.getUi();\n const resolvedAspects = await this.resolveAspects(PreviewRuntime.name, undefined, uiRoot);\n const filteredAspects = this.filterAspectsByExecutionContext(resolvedAspects, context, aspectsIdsToNotFilterOut);\n const filePath = await this.ui.generateRoot(filteredAspects, name, 'preview', PreviewAspect.id);\n return filePath;\n }\n\n async resolveAspects(\n runtimeName?: string,\n componentIds?: ComponentID[],\n uiRoot?: UIRoot,\n opts?: ResolveAspectsOptions\n ): Promise<AspectDefinition[]> {\n const root = uiRoot || this.getUi()[1];\n runtimeName = runtimeName || MainRuntime.name;\n const resolvedAspects = await root.resolveAspects(runtimeName, componentIds, opts);\n return resolvedAspects;\n }\n\n private getUi() {\n const ui = this.ui.getUi();\n if (!ui) throw new Error('ui not found');\n return ui;\n }\n\n /**\n * Filter the aspects to have only aspects that are:\n * 1. core aspects\n * 2. configured on the host (workspace/scope)\n * 3. used by at least one component from the context\n * @param aspects\n * @param context\n */\n private filterAspectsByExecutionContext(\n aspects: AspectDefinition[],\n context: { components: Component[] },\n aspectsIdsToNotFilterOut: string[] = []\n ) {\n let allComponentContextAspects: string[] = [];\n allComponentContextAspects = context.components.reduce((acc, curr) => {\n return acc.concat(curr.state.aspects.ids);\n }, allComponentContextAspects);\n const hostAspects = Object.keys(this.harmony.config.toObject());\n const allAspectsToInclude = uniq(hostAspects.concat(allComponentContextAspects));\n const filtered = aspects.filter((aspect) => {\n if (!aspect.getId) {\n return false;\n }\n return (\n this.aspectLoader.isCoreAspect(aspect.getId) ||\n allAspectsToInclude.includes(aspect.getId) ||\n aspectsIdsToNotFilterOut.includes(aspect.getId)\n );\n });\n\n return filtered;\n }\n\n private getDefaultStrategies() {\n return [\n new EnvBundlingStrategy(this, this.pkg, this.dependencyResolver),\n new ComponentBundlingStrategy(this, this.pkg, this.dependencyResolver),\n ];\n }\n\n // TODO - executionContext should be responsible for updating components list, and emit 'update' events\n // instead we keep track of changes\n private handleComponentChange = async (c: Component, updater: (currentComponents: ExecutionRef) => void) => {\n const env = this.envs.getEnv(c);\n const envId = env.id.toString();\n\n const executionRef = this.executionRefs.get(envId);\n if (!executionRef) {\n this.logger.warn(\n `failed to update link file for component \"${c.id.toString()}\" - could not find execution context for ${envId}`\n );\n return noopResult;\n }\n\n // add / remove / etc\n updater(executionRef);\n\n await this.updateLinkFiles(executionRef.currentComponents, executionRef.executionCtx);\n\n return noopResult;\n };\n\n private handleComponentRemoval = (cId: ComponentID) => {\n let component: Component | undefined;\n this.executionRefs.forEach((components) => {\n const found = components.get(cId);\n if (found) component = found;\n });\n if (!component) return Promise.resolve(noopResult);\n\n return this.handleComponentChange(component, (currentComponents) => currentComponents.remove(cId));\n };\n\n getEnvPreviewConfig(env?: PreviewEnv): EnvPreviewConfig {\n const config = env?.getPreviewConfig && typeof env?.getPreviewConfig === 'function' ? env?.getPreviewConfig() : {};\n\n return config;\n }\n\n /**\n * return the configured bundling strategy.\n */\n getBundlingStrategy(env?: PreviewEnv): BundlingStrategy {\n const defaultStrategies = this.getDefaultStrategies();\n const envPreviewConfig = this.getEnvPreviewConfig(env);\n const strategyFromEnv = envPreviewConfig?.strategyName;\n const strategyName = strategyFromEnv || this.config.bundlingStrategy || 'env';\n const strategies = this.bundlingStrategySlot.values().concat(defaultStrategies);\n const selected = strategies.find((strategy) => {\n return strategy.name === strategyName;\n });\n\n if (!selected) throw new BundlingStrategyNotFound(strategyName);\n\n return selected;\n }\n\n /**\n * register a new bundling strategy. default available strategies are `env` and ``\n */\n registerBundlingStrategy(bundlingStrategy: BundlingStrategy) {\n this.bundlingStrategySlot.register(bundlingStrategy);\n return this;\n }\n\n /**\n * register a new preview definition.\n */\n registerDefinition(previewDef: PreviewDefinition) {\n this.previewSlot.register(previewDef);\n }\n\n static slots = [Slot.withType<PreviewDefinition>(), Slot.withType<BundlingStrategy>()];\n\n static runtime = MainRuntime;\n static dependencies = [\n BundlerAspect,\n BuilderAspect,\n ComponentAspect,\n UIAspect,\n EnvsAspect,\n WorkspaceAspect,\n PkgAspect,\n PubsubAspect,\n AspectLoaderAspect,\n LoggerAspect,\n DependencyResolverAspect,\n GraphqlAspect,\n ];\n\n static defaultConfig = {\n disabled: false,\n };\n\n static async provider(\n // eslint-disable-next-line max-len\n [\n bundler,\n builder,\n componentExtension,\n uiMain,\n envs,\n workspace,\n pkg,\n pubsub,\n aspectLoader,\n loggerMain,\n dependencyResolver,\n graphql,\n ]: [\n BundlerMain,\n BuilderMain,\n ComponentMain,\n UiMain,\n EnvsMain,\n Workspace | undefined,\n PkgMain,\n PubsubMain,\n AspectLoaderMain,\n LoggerMain,\n DependencyResolverMain,\n GraphqlMain\n ],\n config: PreviewConfig,\n [previewSlot, bundlingStrategySlot]: [PreviewDefinitionRegistry, BundlingStrategySlot],\n harmony: Harmony\n ) {\n const logger = loggerMain.createLogger(PreviewAspect.id);\n // app.registerApp(new PreviewApp());\n const preview = new PreviewMain(\n harmony,\n previewSlot,\n uiMain,\n envs,\n componentExtension,\n pkg,\n aspectLoader,\n config,\n bundlingStrategySlot,\n builder,\n workspace,\n logger,\n dependencyResolver\n );\n\n if (workspace) uiMain.registerStartPlugin(new PreviewStartPlugin(workspace, bundler, uiMain, pubsub, logger));\n\n componentExtension.registerRoute([\n new PreviewRoute(preview, logger),\n new ComponentPreviewRoute(preview, logger),\n // @ts-ignore\n new EnvTemplateRoute(preview, logger),\n new PreviewAssetsRoute(preview, logger),\n ]);\n\n bundler.registerTarget([\n {\n entry: preview.getPreviewTarget.bind(preview),\n },\n ]);\n\n if (!config.disabled)\n builder.registerBuildTasks([\n new EnvPreviewTemplateTask(preview, envs, aspectLoader, dependencyResolver, logger),\n new PreviewTask(bundler, preview, dependencyResolver, logger),\n ]);\n\n if (workspace) {\n workspace.registerOnComponentAdd((c) =>\n preview.handleComponentChange(c, (currentComponents) => currentComponents.add(c))\n );\n workspace.onComponentLoad(async (component) => {\n return preview.calcPreviewData(component);\n });\n workspace.registerOnComponentChange((c) =>\n preview.handleComponentChange(c, (currentComponents) => currentComponents.update(c))\n );\n workspace.registerOnComponentRemove((cId) => preview.handleComponentRemoval(cId));\n }\n\n graphql.register(previewSchema(preview));\n\n return preview;\n }\n}\n\nPreviewAspect.addRuntime(PreviewMain);\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;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;AAQA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;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;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;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AiB,IAAKA,iBAAiB,CAACmO,MAAM,CAAC7O,CAAC,CAAC,CAAC,CACrF;MACDN,SAAS,CAACoP,yBAAyB,CAAElO,GAAG,IAAK8M,OAAO,CAACqB,sBAAsB,CAACnO,GAAG,CAAC,CAAC;IACnF;IAEA4M,OAAO,CAACR,QAAQ,CAAC,IAAAgC,yBAAa,EAACtB,OAAO,CAAC,CAAC;IAExC,OAAOA,OAAO;EAChB;AACF;AAAC;AAAA,gCAvsBY5O,WAAW,WAulBP,CAACmQ,eAAI,CAACC,QAAQ,EAAqB,EAAED,eAAI,CAACC,QAAQ,EAAoB,CAAC;AAAA,gCAvlB3EpQ,WAAW,aAylBLiM,kBAAW;AAAA,gCAzlBjBjM,WAAW,kBA0lBA,CACpBqQ,wBAAa,EACbC,wBAAa,EACbC,4BAAe,EACfC,cAAQ,EACRC,kBAAU,EACVC,oBAAe,EACfC,gBAAS,EACTC,sBAAY,EACZC,kCAAkB,EAClBC,sBAAY,EACZC,8CAAwB,EACxBC,kBAAa,CACd;AAAA,gCAvmBUhR,WAAW,mBAymBC;EACrBuP,QAAQ,EAAE;AACZ,CAAC;AA8FHzP,wBAAa,CAACmR,UAAU,CAACjR,WAAW,CAAC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { EnvBundlingStrategy } from './env-strategy';
|
|
2
|
-
export { ComponentBundlingStrategy } from './component-strategy';
|
|
1
|
+
export { EnvBundlingStrategy, ENV_STRATEGY_ARTIFACT_NAME } from './env-strategy';
|
|
2
|
+
export { ComponentBundlingStrategy, COMPONENT_STRATEGY_ARTIFACT_NAME, COMPONENT_STRATEGY_SIZE_KEY_NAME } from './component-strategy';
|
|
3
|
+
export { ENV_PREVIEW_STRATEGY_NAME, COMPONENT_PREVIEW_STRATEGY_NAME } from './strategies-names';
|
package/dist/strategies/index.js
CHANGED
|
@@ -3,12 +3,42 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "COMPONENT_PREVIEW_STRATEGY_NAME", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _strategiesNames().COMPONENT_PREVIEW_STRATEGY_NAME;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "COMPONENT_STRATEGY_ARTIFACT_NAME", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _componentStrategy().COMPONENT_STRATEGY_ARTIFACT_NAME;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "COMPONENT_STRATEGY_SIZE_KEY_NAME", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _componentStrategy().COMPONENT_STRATEGY_SIZE_KEY_NAME;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
6
24
|
Object.defineProperty(exports, "ComponentBundlingStrategy", {
|
|
7
25
|
enumerable: true,
|
|
8
26
|
get: function () {
|
|
9
27
|
return _componentStrategy().ComponentBundlingStrategy;
|
|
10
28
|
}
|
|
11
29
|
});
|
|
30
|
+
Object.defineProperty(exports, "ENV_PREVIEW_STRATEGY_NAME", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _strategiesNames().ENV_PREVIEW_STRATEGY_NAME;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "ENV_STRATEGY_ARTIFACT_NAME", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _envStrategy().ENV_STRATEGY_ARTIFACT_NAME;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
12
42
|
Object.defineProperty(exports, "EnvBundlingStrategy", {
|
|
13
43
|
enumerable: true,
|
|
14
44
|
get: function () {
|
|
@@ -29,5 +59,12 @@ function _componentStrategy() {
|
|
|
29
59
|
};
|
|
30
60
|
return data;
|
|
31
61
|
}
|
|
62
|
+
function _strategiesNames() {
|
|
63
|
+
const data = require("./strategies-names");
|
|
64
|
+
_strategiesNames = function () {
|
|
65
|
+
return data;
|
|
66
|
+
};
|
|
67
|
+
return data;
|
|
68
|
+
}
|
|
32
69
|
|
|
33
70
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { EnvBundlingStrategy } from './env-strategy';\nexport { ComponentBundlingStrategy } from './component-strategy';\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { EnvBundlingStrategy, ENV_STRATEGY_ARTIFACT_NAME } from './env-strategy';\nexport { ComponentBundlingStrategy, COMPONENT_STRATEGY_ARTIFACT_NAME, COMPONENT_STRATEGY_SIZE_KEY_NAME } from './component-strategy';\nexport { ENV_PREVIEW_STRATEGY_NAME, COMPONENT_PREVIEW_STRATEGY_NAME } from './strategies-names';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ENV_PREVIEW_STRATEGY_NAME = exports.COMPONENT_PREVIEW_STRATEGY_NAME = void 0;
|
|
7
|
+
const ENV_PREVIEW_STRATEGY_NAME = 'env';
|
|
8
|
+
exports.ENV_PREVIEW_STRATEGY_NAME = ENV_PREVIEW_STRATEGY_NAME;
|
|
9
|
+
const COMPONENT_PREVIEW_STRATEGY_NAME = 'component';
|
|
10
|
+
exports.COMPONENT_PREVIEW_STRATEGY_NAME = COMPONENT_PREVIEW_STRATEGY_NAME;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=strategies-names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ENV_PREVIEW_STRATEGY_NAME","COMPONENT_PREVIEW_STRATEGY_NAME"],"sources":["strategies-names.ts"],"sourcesContent":["export const ENV_PREVIEW_STRATEGY_NAME = 'env';\nexport const COMPONENT_PREVIEW_STRATEGY_NAME = 'component';\n"],"mappings":";;;;;;AAAO,MAAMA,yBAAyB,GAAG,KAAK;AAAC;AACxC,MAAMC,+BAA+B,GAAG,WAAW;AAAC"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/preview",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.891",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/preview/preview",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.preview",
|
|
8
8
|
"name": "preview",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.891"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"mime": "2.5.2",
|
|
@@ -23,29 +23,29 @@
|
|
|
23
23
|
"@babel/runtime": "7.20.0",
|
|
24
24
|
"core-js": "^3.0.0",
|
|
25
25
|
"@teambit/harmony": "0.3.3",
|
|
26
|
-
"@teambit/express": "0.0.
|
|
27
|
-
"@teambit/logger": "0.0.
|
|
28
|
-
"@teambit/ui-foundation.ui.pages.static-error": "0.0.
|
|
29
|
-
"@teambit/builder": "0.0.
|
|
30
|
-
"@teambit/bundler": "0.0.
|
|
31
|
-
"@teambit/component": "0.0.
|
|
26
|
+
"@teambit/express": "0.0.696",
|
|
27
|
+
"@teambit/logger": "0.0.691",
|
|
28
|
+
"@teambit/ui-foundation.ui.pages.static-error": "0.0.84",
|
|
29
|
+
"@teambit/builder": "0.0.891",
|
|
30
|
+
"@teambit/bundler": "0.0.891",
|
|
31
|
+
"@teambit/component": "0.0.891",
|
|
32
32
|
"@teambit/preview.ui.component-preview": "0.0.506",
|
|
33
|
-
"@teambit/aspect-loader": "0.0.
|
|
34
|
-
"@teambit/cli": "0.0.
|
|
35
|
-
"@teambit/dependency-resolver": "0.0.
|
|
36
|
-
"@teambit/envs": "0.0.
|
|
33
|
+
"@teambit/aspect-loader": "0.0.891",
|
|
34
|
+
"@teambit/cli": "0.0.598",
|
|
35
|
+
"@teambit/dependency-resolver": "0.0.891",
|
|
36
|
+
"@teambit/envs": "0.0.891",
|
|
37
37
|
"@teambit/toolbox.path.to-windows-compatible-path": "0.0.490",
|
|
38
|
-
"@teambit/component-id": "0.0.
|
|
39
|
-
"@teambit/bit-error": "0.0.
|
|
40
|
-
"@teambit/graphql": "0.0.
|
|
41
|
-
"@teambit/pkg": "0.0.
|
|
42
|
-
"@teambit/pubsub": "0.0.
|
|
43
|
-
"@teambit/ui": "0.0.
|
|
44
|
-
"@teambit/workspace": "0.0.
|
|
45
|
-
"@teambit/compiler": "0.0.
|
|
38
|
+
"@teambit/component-id": "0.0.423",
|
|
39
|
+
"@teambit/bit-error": "0.0.402",
|
|
40
|
+
"@teambit/graphql": "0.0.891",
|
|
41
|
+
"@teambit/pkg": "0.0.891",
|
|
42
|
+
"@teambit/pubsub": "0.0.891",
|
|
43
|
+
"@teambit/ui": "0.0.891",
|
|
44
|
+
"@teambit/workspace": "0.0.891",
|
|
45
|
+
"@teambit/compiler": "0.0.891",
|
|
46
46
|
"@teambit/preview.cli.preview-server-status": "0.0.499",
|
|
47
47
|
"@teambit/preview.cli.webpack-events-listener": "0.0.168",
|
|
48
|
-
"@teambit/isolator": "0.0.
|
|
48
|
+
"@teambit/isolator": "0.0.891"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/mime": "2.0.3",
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"@types/jest": "^26.0.0",
|
|
61
61
|
"@types/react-dom": "^17.0.5",
|
|
62
62
|
"@types/node": "12.20.4",
|
|
63
|
-
"@teambit/preview.aspect-docs.preview": "0.0.
|
|
63
|
+
"@teambit/preview.aspect-docs.preview": "0.0.148"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
|
-
"@teambit/legacy": "1.0.
|
|
66
|
+
"@teambit/legacy": "1.0.381",
|
|
67
67
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
68
68
|
"react": "^16.8.0 || ^17.0.0"
|
|
69
69
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@0.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@0.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@0.0.891/dist/preview.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.preview_preview@0.0.891/dist/preview.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
package/preview.main.runtime.tsx
CHANGED
|
@@ -38,7 +38,15 @@ import { PreviewAspect, PreviewRuntime } from './preview.aspect';
|
|
|
38
38
|
import { PreviewRoute } from './preview.route';
|
|
39
39
|
import { PreviewTask, PREVIEW_TASK_NAME } from './preview.task';
|
|
40
40
|
import { BundlingStrategy } from './bundling-strategy';
|
|
41
|
-
import {
|
|
41
|
+
import {
|
|
42
|
+
EnvBundlingStrategy,
|
|
43
|
+
ComponentBundlingStrategy,
|
|
44
|
+
COMPONENT_STRATEGY_ARTIFACT_NAME,
|
|
45
|
+
COMPONENT_STRATEGY_SIZE_KEY_NAME,
|
|
46
|
+
ENV_PREVIEW_STRATEGY_NAME,
|
|
47
|
+
ENV_STRATEGY_ARTIFACT_NAME,
|
|
48
|
+
COMPONENT_PREVIEW_STRATEGY_NAME,
|
|
49
|
+
} from './strategies';
|
|
42
50
|
import { ExecutionRef } from './execution-ref';
|
|
43
51
|
import { PreviewStartPlugin } from './preview.start-plugin';
|
|
44
52
|
import {
|
|
@@ -48,8 +56,6 @@ import {
|
|
|
48
56
|
} from './env-preview-template.task';
|
|
49
57
|
import { EnvTemplateRoute } from './env-template.route';
|
|
50
58
|
import { ComponentPreviewRoute } from './component-preview.route';
|
|
51
|
-
import { COMPONENT_STRATEGY_ARTIFACT_NAME, COMPONENT_STRATEGY_SIZE_KEY_NAME } from './strategies/component-strategy';
|
|
52
|
-
import { ENV_STRATEGY_ARTIFACT_NAME } from './strategies/env-strategy';
|
|
53
59
|
import { previewSchema } from './preview.graphql';
|
|
54
60
|
import { PreviewAssetsRoute } from './preview-assets.route';
|
|
55
61
|
|
|
@@ -62,7 +68,9 @@ const DEFAULT_TEMP_DIR = join(CACHE_ROOT, PreviewAspect.id);
|
|
|
62
68
|
|
|
63
69
|
export type PreviewDefinitionRegistry = SlotRegistry<PreviewDefinition>;
|
|
64
70
|
|
|
65
|
-
type
|
|
71
|
+
export type PreviewStrategyName = 'env' | 'component';
|
|
72
|
+
|
|
73
|
+
export type PreviewFiles = {
|
|
66
74
|
files: string[];
|
|
67
75
|
isBundledWithEnv: boolean;
|
|
68
76
|
};
|
|
@@ -91,8 +99,28 @@ export type PreviewVariantConfig = {
|
|
|
91
99
|
/**
|
|
92
100
|
* Preview data that stored on the component on load
|
|
93
101
|
*/
|
|
94
|
-
export type PreviewComponentData =
|
|
102
|
+
export type PreviewComponentData = PreviewAnyComponentData & PreviewEnvComponentData;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Preview data that stored on the component on load for any component
|
|
106
|
+
*/
|
|
107
|
+
export type PreviewAnyComponentData = {
|
|
95
108
|
doesScaling?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* The strategy configured by the component's env
|
|
111
|
+
*/
|
|
112
|
+
strategyName?: PreviewStrategyName;
|
|
113
|
+
/**
|
|
114
|
+
* Does the component has a bundle for the component itself (separated from the compositions/docs)
|
|
115
|
+
* Calculated by the component's env
|
|
116
|
+
*/
|
|
117
|
+
splitComponentBundle?: boolean;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Preview data that stored on the component on load if the component is an env
|
|
122
|
+
*/
|
|
123
|
+
export type PreviewEnvComponentData = {
|
|
96
124
|
isScaling?: boolean;
|
|
97
125
|
};
|
|
98
126
|
|
|
@@ -108,7 +136,7 @@ export type PreviewConfig = {
|
|
|
108
136
|
};
|
|
109
137
|
|
|
110
138
|
export type EnvPreviewConfig = {
|
|
111
|
-
strategyName?:
|
|
139
|
+
strategyName?: PreviewStrategyName;
|
|
112
140
|
splitComponentBundle?: boolean;
|
|
113
141
|
};
|
|
114
142
|
|
|
@@ -187,6 +215,100 @@ export class PreviewMain {
|
|
|
187
215
|
};
|
|
188
216
|
}
|
|
189
217
|
|
|
218
|
+
/**
|
|
219
|
+
* Get the preview config of the component.
|
|
220
|
+
* (config that was set by variants or on bitmap)
|
|
221
|
+
* @param component
|
|
222
|
+
* @returns
|
|
223
|
+
*/
|
|
224
|
+
getPreviewAspectConfig(component: Component): PreviewVariantConfig | undefined {
|
|
225
|
+
return component.state.aspects.get(PreviewAspect.id)?.config;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Get the preview data of the component.
|
|
230
|
+
* (data that was calculated during the on load process)
|
|
231
|
+
* @param component
|
|
232
|
+
* @returns
|
|
233
|
+
*/
|
|
234
|
+
getPreviewData(component: Component): PreviewComponentData | undefined {
|
|
235
|
+
const previewData = component.state.aspects.get(PreviewAspect.id)?.data;
|
|
236
|
+
return previewData;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Calculate preview data on component load
|
|
241
|
+
* @param component
|
|
242
|
+
* @returns
|
|
243
|
+
*/
|
|
244
|
+
async calcPreviewData(component: Component): Promise<PreviewComponentData> {
|
|
245
|
+
const doesScaling = await this.calcDoesScalingForComponent(component);
|
|
246
|
+
const dataFromEnv = await this.calcPreviewDataFromEnv(component);
|
|
247
|
+
const envData = (await this.calculateDataForEnvComponent(component)) || {};
|
|
248
|
+
const data: PreviewComponentData = {
|
|
249
|
+
doesScaling,
|
|
250
|
+
...dataFromEnv,
|
|
251
|
+
...envData,
|
|
252
|
+
};
|
|
253
|
+
return data;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Calculate preview data on component that configured by its env
|
|
258
|
+
* @param component
|
|
259
|
+
* @returns
|
|
260
|
+
*/
|
|
261
|
+
async calcPreviewDataFromEnv(component: Component): Promise<Omit<PreviewAnyComponentData, 'doesScaling'> | undefined> {
|
|
262
|
+
// Prevent infinite loop that caused by the fact that the env of the aspect env or the env env is the same as the component
|
|
263
|
+
// so we can't load it since during load we are trying to get env component and load it again
|
|
264
|
+
if (component.id.toStringWithoutVersion() === 'teambit.harmony/aspect' || component.id.toStringWithoutVersion() === 'teambit.envs/env'){
|
|
265
|
+
return {
|
|
266
|
+
strategyName: COMPONENT_PREVIEW_STRATEGY_NAME,
|
|
267
|
+
splitComponentBundle: false,
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const env = this.envs.getEnv(component).env;
|
|
272
|
+
const envPreviewConfig = this.getEnvPreviewConfig(env);
|
|
273
|
+
const data = {
|
|
274
|
+
strategyName: envPreviewConfig?.strategyName,
|
|
275
|
+
splitComponentBundle: envPreviewConfig?.splitComponentBundle ?? false,
|
|
276
|
+
};
|
|
277
|
+
return data;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* calculate extra preview data for env components (on load)
|
|
282
|
+
* @param envComponent
|
|
283
|
+
* @returns
|
|
284
|
+
*/
|
|
285
|
+
private async calculateDataForEnvComponent(envComponent: Component): Promise<PreviewEnvComponentData | undefined> {
|
|
286
|
+
const isEnv = this.envs.isEnv(envComponent);
|
|
287
|
+
// If the component is not an env, we don't want to store anything in the data
|
|
288
|
+
if (!isEnv) return undefined;
|
|
289
|
+
const previewAspectConfig = this.getPreviewAspectConfig(envComponent);
|
|
290
|
+
|
|
291
|
+
const data = {
|
|
292
|
+
// default to true if the env doesn't have a preview config
|
|
293
|
+
isScaling: previewAspectConfig?.isScaling ?? true,
|
|
294
|
+
};
|
|
295
|
+
return data;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Check if the component preview bundle contain the env as part of the bundle or only the component code
|
|
300
|
+
* (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)
|
|
301
|
+
* This should be used only for calculating the value on load.
|
|
302
|
+
* otherwise, use the isBundledWithEnv function
|
|
303
|
+
* @param component
|
|
304
|
+
* @returns
|
|
305
|
+
*/
|
|
306
|
+
async calcIsBundledWithEnv(component: Component): Promise<boolean> {
|
|
307
|
+
const envPreviewData = await this.calcPreviewDataFromEnv(component);
|
|
308
|
+
return envPreviewData?.strategyName !== 'component';
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
|
|
190
312
|
/**
|
|
191
313
|
* Check if the component preview bundle contain the env as part of the bundle or only the component code
|
|
192
314
|
* (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)
|
|
@@ -194,6 +316,21 @@ export class PreviewMain {
|
|
|
194
316
|
* @returns
|
|
195
317
|
*/
|
|
196
318
|
async isBundledWithEnv(component: Component): Promise<boolean> {
|
|
319
|
+
const data = await this.getPreviewData(component);
|
|
320
|
+
// For components that tagged in the past we didn't store the data, so we calculate it the old way
|
|
321
|
+
// We comparing the strategyName to undefined to cover a specific case when it doesn't exist at all.
|
|
322
|
+
if (!data || data.strategyName === undefined) return this.isBundledWithEnvBackward(component);
|
|
323
|
+
return data.strategyName === ENV_PREVIEW_STRATEGY_NAME;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* This is a legacy calculation for the isBundledWithEnv
|
|
328
|
+
* This calc is based on the component artifacts which is very expensive operation as it requires to fetch and load the artifacts
|
|
329
|
+
* See the new implementation in the isBundledWithEnv method
|
|
330
|
+
* @param component
|
|
331
|
+
* @returns
|
|
332
|
+
*/
|
|
333
|
+
private async isBundledWithEnvBackward(component: Component): Promise<boolean> {
|
|
197
334
|
const artifacts = await this.builder.getArtifactsVinylByAspectAndName(
|
|
198
335
|
component,
|
|
199
336
|
PreviewAspect.id,
|
|
@@ -209,7 +346,7 @@ export class PreviewMain {
|
|
|
209
346
|
// if you want to get the final result use the `doesScaling` method below
|
|
210
347
|
// This should be used only for component load
|
|
211
348
|
private async calcDoesScalingForComponent(component: Component): Promise<boolean> {
|
|
212
|
-
const isBundledWithEnv = await this.
|
|
349
|
+
const isBundledWithEnv = await this.calcIsBundledWithEnv(component);
|
|
213
350
|
// if it's a core env and the env template is apart from the component it means the template bundle already contain the scaling functionality
|
|
214
351
|
if (this.envs.isUsingCoreEnv(component)) {
|
|
215
352
|
// If the component is new, no point to check the is bundle with env (there is no artifacts so it will for sure return false)
|
|
@@ -241,7 +378,7 @@ export class PreviewMain {
|
|
|
241
378
|
const envSupportScaling = await this.calculateIsEnvSupportScaling(envComponent);
|
|
242
379
|
return envSupportScaling ?? true;
|
|
243
380
|
}
|
|
244
|
-
const previewData =
|
|
381
|
+
const previewData = this.getPreviewData(component);
|
|
245
382
|
if (!previewData) return false;
|
|
246
383
|
// Get the does scaling (the new calculation) or the old calc used in isScaling (between versions (about) 848 and 860)
|
|
247
384
|
if (previewData.doesScaling !== undefined) return previewData.doesScaling;
|
|
@@ -262,7 +399,7 @@ export class PreviewMain {
|
|
|
262
399
|
* @returns
|
|
263
400
|
*/
|
|
264
401
|
isEnvSupportScaling(envComponent: Component): boolean {
|
|
265
|
-
const previewData =
|
|
402
|
+
const previewData = this.getPreviewData(envComponent);
|
|
266
403
|
return !!previewData?.isScaling;
|
|
267
404
|
}
|
|
268
405
|
|
|
@@ -279,21 +416,11 @@ export class PreviewMain {
|
|
|
279
416
|
const isEnv = this.envs.isEnv(envComponent);
|
|
280
417
|
// If the component is not an env, we don't want to store anything in the data
|
|
281
418
|
if (!isEnv) return undefined;
|
|
282
|
-
const previewAspectConfig = this.
|
|
419
|
+
const previewAspectConfig = this.getPreviewAspectConfig(envComponent);
|
|
283
420
|
// default to true if the env doesn't have a preview config
|
|
284
421
|
return previewAspectConfig?.isScaling ?? true;
|
|
285
422
|
}
|
|
286
423
|
|
|
287
|
-
/**
|
|
288
|
-
* Get the preview config of the component.
|
|
289
|
-
* (config that was set by variants or on bitmap)
|
|
290
|
-
* @param component
|
|
291
|
-
* @returns
|
|
292
|
-
*/
|
|
293
|
-
getPreviewConfig(component: Component): PreviewVariantConfig | undefined {
|
|
294
|
-
return component.state.aspects.get(PreviewAspect.id)?.config;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
424
|
/**
|
|
298
425
|
* Check if the component preview bundle contain the header inside of it (legacy)
|
|
299
426
|
* today we are not including the header inside anymore
|
|
@@ -716,16 +843,7 @@ export class PreviewMain {
|
|
|
716
843
|
preview.handleComponentChange(c, (currentComponents) => currentComponents.add(c))
|
|
717
844
|
);
|
|
718
845
|
workspace.onComponentLoad(async (component) => {
|
|
719
|
-
|
|
720
|
-
const isScaling = await preview.calculateIsEnvSupportScaling(component);
|
|
721
|
-
const data: PreviewComponentData = {
|
|
722
|
-
doesScaling,
|
|
723
|
-
};
|
|
724
|
-
// If there is no isScaling result at all, it's probably not an env. don't store any data.
|
|
725
|
-
if (isScaling !== undefined) {
|
|
726
|
-
data.isScaling = isScaling;
|
|
727
|
-
}
|
|
728
|
-
return data;
|
|
846
|
+
return preview.calcPreviewData(component);
|
|
729
847
|
});
|
|
730
848
|
workspace.registerOnComponentChange((c) =>
|
|
731
849
|
preview.handleComponentChange(c, (currentComponents) => currentComponents.update(c))
|
package/strategies/index.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { EnvBundlingStrategy } from './env-strategy';
|
|
2
|
-
export { ComponentBundlingStrategy } from './component-strategy';
|
|
1
|
+
export { EnvBundlingStrategy, ENV_STRATEGY_ARTIFACT_NAME } from './env-strategy';
|
|
2
|
+
export { ComponentBundlingStrategy, COMPONENT_STRATEGY_ARTIFACT_NAME, COMPONENT_STRATEGY_SIZE_KEY_NAME } from './component-strategy';
|
|
3
|
+
export { ENV_PREVIEW_STRATEGY_NAME, COMPONENT_PREVIEW_STRATEGY_NAME } from './strategies-names';
|
|
Binary file
|