@teambit/preview 0.0.881 → 0.0.883

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.
Files changed (84) hide show
  1. package/dist/artifact-file-middleware.js +2 -22
  2. package/dist/artifact-file-middleware.js.map +1 -1
  3. package/dist/bundler/chunks.js +1 -9
  4. package/dist/bundler/chunks.js.map +1 -1
  5. package/dist/bundler/create-peer-link.spec.js +0 -3
  6. package/dist/bundler/create-peer-link.spec.js.map +1 -1
  7. package/dist/bundler/create-peers-link.js +3 -20
  8. package/dist/bundler/create-peers-link.js.map +1 -1
  9. package/dist/bundler/html-plugin.js +0 -13
  10. package/dist/bundler/html-plugin.js.map +1 -1
  11. package/dist/bundler/html-template.js +0 -1
  12. package/dist/bundler/html-template.js.map +1 -1
  13. package/dist/component-preview.js +0 -3
  14. package/dist/component-preview.js.map +1 -1
  15. package/dist/component-preview.route.js +8 -23
  16. package/dist/component-preview.route.js.map +1 -1
  17. package/dist/env-preview-template.task.js +9 -75
  18. package/dist/env-preview-template.task.js.map +1 -1
  19. package/dist/env-template.route.js +6 -22
  20. package/dist/env-template.route.js.map +1 -1
  21. package/dist/events/click-inside-an-iframe.js +1 -12
  22. package/dist/events/click-inside-an-iframe.js.map +1 -1
  23. package/dist/events/index.js +0 -2
  24. package/dist/events/index.js.map +1 -1
  25. package/dist/exceptions/bundling-strategy-not-found.js +0 -3
  26. package/dist/exceptions/bundling-strategy-not-found.js.map +1 -1
  27. package/dist/exceptions/index.js +0 -12
  28. package/dist/exceptions/index.js.map +1 -1
  29. package/dist/exceptions/preview-artifact-not-found.js +0 -6
  30. package/dist/exceptions/preview-artifact-not-found.js.map +1 -1
  31. package/dist/exceptions/preview-not-found.js +0 -3
  32. package/dist/exceptions/preview-not-found.js.map +1 -1
  33. package/dist/exceptions/preview-output-file-not-found.js +0 -6
  34. package/dist/exceptions/preview-output-file-not-found.js.map +1 -1
  35. package/dist/execution-ref.js +0 -11
  36. package/dist/execution-ref.js.map +1 -1
  37. package/dist/generate-link.js +2 -7
  38. package/dist/generate-link.js.map +1 -1
  39. package/dist/gql/fetch-component-aspects.js +0 -6
  40. package/dist/gql/fetch-component-aspects.js.map +1 -1
  41. package/dist/html-utils.js +0 -9
  42. package/dist/html-utils.js.map +1 -1
  43. package/dist/index.js +0 -8
  44. package/dist/index.js.map +1 -1
  45. package/dist/mk-temp-dir.js +0 -10
  46. package/dist/mk-temp-dir.js.map +1 -1
  47. package/dist/preview-artifact.js +0 -12
  48. package/dist/preview-artifact.js.map +1 -1
  49. package/dist/preview-assets.route.js +2 -13
  50. package/dist/preview-assets.route.js.map +1 -1
  51. package/dist/preview-modules.js +0 -11
  52. package/dist/preview-modules.js.map +1 -1
  53. package/dist/preview.aspect.js +0 -6
  54. package/dist/preview.aspect.js.map +1 -1
  55. package/dist/preview.composition.js +0 -6
  56. package/dist/preview.composition.js.map +1 -1
  57. package/dist/preview.graphql.js +0 -5
  58. package/dist/preview.graphql.js.map +1 -1
  59. package/dist/preview.main.runtime.js +53 -226
  60. package/dist/preview.main.runtime.js.map +1 -1
  61. package/dist/preview.preview.runtime.js +18 -108
  62. package/dist/preview.preview.runtime.js.map +1 -1
  63. package/dist/preview.route.js +6 -21
  64. package/dist/preview.route.js.map +1 -1
  65. package/dist/preview.start-plugin.js +8 -42
  66. package/dist/preview.start-plugin.js.map +1 -1
  67. package/dist/preview.task.js +1 -20
  68. package/dist/preview.task.js.map +1 -1
  69. package/dist/rendering-context.js +1 -5
  70. package/dist/rendering-context.js.map +1 -1
  71. package/dist/size-event.js +0 -10
  72. package/dist/size-event.js.map +1 -1
  73. package/dist/strategies/component-strategy.js +19 -69
  74. package/dist/strategies/component-strategy.js.map +1 -1
  75. package/dist/strategies/env-strategy.js +1 -40
  76. package/dist/strategies/env-strategy.js.map +1 -1
  77. package/dist/strategies/generate-component-link.js +4 -7
  78. package/dist/strategies/generate-component-link.js.map +1 -1
  79. package/dist/strategies/index.js +0 -6
  80. package/dist/strategies/index.js.map +1 -1
  81. package/package-tar/teambit-preview-0.0.883.tgz +0 -0
  82. package/package.json +15 -15
  83. package/{preview-1666409808293.js → preview-1666582798766.js} +2 -2
  84. package/package-tar/teambit-preview-0.0.881.tgz +0 -0
@@ -1,402 +1,283 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  require("core-js/modules/es.array.iterator.js");
6
-
7
5
  require("core-js/modules/es.promise.js");
8
-
9
6
  Object.defineProperty(exports, "__esModule", {
10
7
  value: true
11
8
  });
12
9
  exports.PreviewMain = void 0;
13
-
14
10
  function _defineProperty2() {
15
11
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
-
17
12
  _defineProperty2 = function () {
18
13
  return data;
19
14
  };
20
-
21
15
  return data;
22
16
  }
23
-
24
17
  function _builder() {
25
18
  const data = require("@teambit/builder");
26
-
27
19
  _builder = function () {
28
20
  return data;
29
21
  };
30
-
31
22
  return data;
32
23
  }
33
-
34
24
  function _bundler() {
35
25
  const data = require("@teambit/bundler");
36
-
37
26
  _bundler = function () {
38
27
  return data;
39
28
  };
40
-
41
29
  return data;
42
30
  }
43
-
44
31
  function _pubsub() {
45
32
  const data = require("@teambit/pubsub");
46
-
47
33
  _pubsub = function () {
48
34
  return data;
49
35
  };
50
-
51
36
  return data;
52
37
  }
53
-
54
38
  function _cli() {
55
39
  const data = require("@teambit/cli");
56
-
57
40
  _cli = function () {
58
41
  return data;
59
42
  };
60
-
61
43
  return data;
62
44
  }
63
-
64
45
  function _component() {
65
46
  const data = require("@teambit/component");
66
-
67
47
  _component = function () {
68
48
  return data;
69
49
  };
70
-
71
50
  return data;
72
51
  }
73
-
74
52
  function _envs() {
75
53
  const data = require("@teambit/envs");
76
-
77
54
  _envs = function () {
78
55
  return data;
79
56
  };
80
-
81
57
  return data;
82
58
  }
83
-
84
59
  function _harmony() {
85
60
  const data = require("@teambit/harmony");
86
-
87
61
  _harmony = function () {
88
62
  return data;
89
63
  };
90
-
91
64
  return data;
92
65
  }
93
-
94
66
  function _ui() {
95
67
  const data = require("@teambit/ui");
96
-
97
68
  _ui = function () {
98
69
  return data;
99
70
  };
100
-
101
71
  return data;
102
72
  }
103
-
104
73
  function _constants() {
105
74
  const data = require("@teambit/legacy/dist/constants");
106
-
107
75
  _constants = function () {
108
76
  return data;
109
77
  };
110
-
111
78
  return data;
112
79
  }
113
-
114
80
  function _bitError() {
115
81
  const data = require("@teambit/bit-error");
116
-
117
82
  _bitError = function () {
118
83
  return data;
119
84
  };
120
-
121
85
  return data;
122
86
  }
123
-
124
87
  function _objectHash() {
125
88
  const data = _interopRequireDefault(require("object-hash"));
126
-
127
89
  _objectHash = function () {
128
90
  return data;
129
91
  };
130
-
131
92
  return data;
132
93
  }
133
-
134
94
  function _lodash() {
135
95
  const data = require("lodash");
136
-
137
96
  _lodash = function () {
138
97
  return data;
139
98
  };
140
-
141
99
  return data;
142
100
  }
143
-
144
101
  function _fsExtra() {
145
102
  const data = require("fs-extra");
146
-
147
103
  _fsExtra = function () {
148
104
  return data;
149
105
  };
150
-
151
106
  return data;
152
107
  }
153
-
154
108
  function _path() {
155
109
  const data = require("path");
156
-
157
110
  _path = function () {
158
111
  return data;
159
112
  };
160
-
161
113
  return data;
162
114
  }
163
-
164
115
  function _pkg() {
165
116
  const data = require("@teambit/pkg");
166
-
167
117
  _pkg = function () {
168
118
  return data;
169
119
  };
170
-
171
120
  return data;
172
121
  }
173
-
174
122
  function _aspectLoader() {
175
123
  const data = require("@teambit/aspect-loader");
176
-
177
124
  _aspectLoader = function () {
178
125
  return data;
179
126
  };
180
-
181
127
  return data;
182
128
  }
183
-
184
129
  function _workspace() {
185
130
  const data = _interopRequireDefault(require("@teambit/workspace"));
186
-
187
131
  _workspace = function () {
188
132
  return data;
189
133
  };
190
-
191
134
  return data;
192
135
  }
193
-
194
136
  function _logger() {
195
137
  const data = require("@teambit/logger");
196
-
197
138
  _logger = function () {
198
139
  return data;
199
140
  };
200
-
201
141
  return data;
202
142
  }
203
-
204
143
  function _dependencyResolver() {
205
144
  const data = require("@teambit/dependency-resolver");
206
-
207
145
  _dependencyResolver = function () {
208
146
  return data;
209
147
  };
210
-
211
148
  return data;
212
149
  }
213
-
214
150
  function _artifactFiles() {
215
151
  const data = require("@teambit/legacy/dist/consumer/component/sources/artifact-files");
216
-
217
152
  _artifactFiles = function () {
218
153
  return data;
219
154
  };
220
-
221
155
  return data;
222
156
  }
223
-
224
157
  function _graphql() {
225
158
  const data = _interopRequireDefault(require("@teambit/graphql"));
226
-
227
159
  _graphql = function () {
228
160
  return data;
229
161
  };
230
-
231
162
  return data;
232
163
  }
233
-
234
164
  function _exceptions() {
235
165
  const data = require("./exceptions");
236
-
237
166
  _exceptions = function () {
238
167
  return data;
239
168
  };
240
-
241
169
  return data;
242
170
  }
243
-
244
171
  function _generateLink() {
245
172
  const data = require("./generate-link");
246
-
247
173
  _generateLink = function () {
248
174
  return data;
249
175
  };
250
-
251
176
  return data;
252
177
  }
253
-
254
178
  function _previewArtifact() {
255
179
  const data = require("./preview-artifact");
256
-
257
180
  _previewArtifact = function () {
258
181
  return data;
259
182
  };
260
-
261
183
  return data;
262
184
  }
263
-
264
185
  function _preview() {
265
186
  const data = require("./preview.aspect");
266
-
267
187
  _preview = function () {
268
188
  return data;
269
189
  };
270
-
271
190
  return data;
272
191
  }
273
-
274
192
  function _preview2() {
275
193
  const data = require("./preview.route");
276
-
277
194
  _preview2 = function () {
278
195
  return data;
279
196
  };
280
-
281
197
  return data;
282
198
  }
283
-
284
199
  function _preview3() {
285
200
  const data = require("./preview.task");
286
-
287
201
  _preview3 = function () {
288
202
  return data;
289
203
  };
290
-
291
204
  return data;
292
205
  }
293
-
294
206
  function _strategies() {
295
207
  const data = require("./strategies");
296
-
297
208
  _strategies = function () {
298
209
  return data;
299
210
  };
300
-
301
211
  return data;
302
212
  }
303
-
304
213
  function _executionRef() {
305
214
  const data = require("./execution-ref");
306
-
307
215
  _executionRef = function () {
308
216
  return data;
309
217
  };
310
-
311
218
  return data;
312
219
  }
313
-
314
220
  function _preview4() {
315
221
  const data = require("./preview.start-plugin");
316
-
317
222
  _preview4 = function () {
318
223
  return data;
319
224
  };
320
-
321
225
  return data;
322
226
  }
323
-
324
227
  function _envPreviewTemplate() {
325
228
  const data = require("./env-preview-template.task");
326
-
327
229
  _envPreviewTemplate = function () {
328
230
  return data;
329
231
  };
330
-
331
232
  return data;
332
233
  }
333
-
334
234
  function _envTemplate() {
335
235
  const data = require("./env-template.route");
336
-
337
236
  _envTemplate = function () {
338
237
  return data;
339
238
  };
340
-
341
239
  return data;
342
240
  }
343
-
344
241
  function _componentPreview() {
345
242
  const data = require("./component-preview.route");
346
-
347
243
  _componentPreview = function () {
348
244
  return data;
349
245
  };
350
-
351
246
  return data;
352
247
  }
353
-
354
248
  function _componentStrategy() {
355
249
  const data = require("./strategies/component-strategy");
356
-
357
250
  _componentStrategy = function () {
358
251
  return data;
359
252
  };
360
-
361
253
  return data;
362
254
  }
363
-
364
255
  function _envStrategy() {
365
256
  const data = require("./strategies/env-strategy");
366
-
367
257
  _envStrategy = function () {
368
258
  return data;
369
259
  };
370
-
371
260
  return data;
372
261
  }
373
-
374
262
  function _preview5() {
375
263
  const data = require("./preview.graphql");
376
-
377
264
  _preview5 = function () {
378
265
  return data;
379
266
  };
380
-
381
267
  return data;
382
268
  }
383
-
384
269
  function _previewAssets() {
385
270
  const data = require("./preview-assets.route");
386
-
387
271
  _previewAssets = function () {
388
272
  return data;
389
273
  };
390
-
391
274
  return data;
392
275
  }
393
-
394
276
  const noopResult = {
395
277
  results: [],
396
278
  toString: () => `updating link file`
397
279
  };
398
280
  const DEFAULT_TEMP_DIR = (0, _path().join)(_constants().CACHE_ROOT, _preview().PreviewAspect.id);
399
-
400
281
  class PreviewMain {
401
282
  constructor(
402
283
  /**
@@ -427,13 +308,12 @@ class PreviewMain {
427
308
  const env = this.envs.getEnv(c);
428
309
  const envId = env.id.toString();
429
310
  const executionRef = this.executionRefs.get(envId);
430
-
431
311
  if (!executionRef) {
432
312
  this.logger.warn(`failed to update link file for component "${c.id.toString()}" - could not find execution context for ${envId}`);
433
313
  return noopResult;
434
- } // add / remove / etc
435
-
314
+ }
436
315
 
316
+ // add / remove / etc
437
317
  updater(executionRef);
438
318
  await this.updateLinkFiles(executionRef.currentComponents, executionRef.executionCtx);
439
319
  return noopResult;
@@ -448,31 +328,26 @@ class PreviewMain {
448
328
  return this.handleComponentChange(component, currentComponents => currentComponents.remove(cId));
449
329
  });
450
330
  }
451
-
452
331
  get tempFolder() {
453
332
  var _this$workspace;
454
-
455
333
  return ((_this$workspace = this.workspace) === null || _this$workspace === void 0 ? void 0 : _this$workspace.getTempDir(_preview().PreviewAspect.id)) || DEFAULT_TEMP_DIR;
456
334
  }
457
-
458
335
  getComponentBundleSize(component) {
459
336
  const data = this.builder.getDataByAspect(component, _preview().PreviewAspect.id);
460
337
  if (!data) return undefined;
461
338
  return data[_componentStrategy().COMPONENT_STRATEGY_SIZE_KEY_NAME];
462
339
  }
463
-
464
340
  async getPreview(component) {
465
341
  const artifacts = await this.builder.getArtifactsVinylByAspectAndTaskName(component, _preview().PreviewAspect.id, _preview3().PREVIEW_TASK_NAME);
466
342
  if (!artifacts) return undefined;
467
343
  return new (_previewArtifact().PreviewArtifact)(artifacts);
468
344
  }
345
+
469
346
  /**
470
347
  * Get a list of all the artifact files generated during the GeneratePreview task
471
348
  * @param component
472
349
  * @returns
473
350
  */
474
-
475
-
476
351
  async getPreviewFiles(component) {
477
352
  const artifacts = await this.getPreview(component);
478
353
  const isBundledWithEnv = await this.isBundledWithEnv(component);
@@ -482,93 +357,83 @@ class PreviewMain {
482
357
  isBundledWithEnv
483
358
  };
484
359
  }
360
+
485
361
  /**
486
362
  * Check if the component preview bundle contain the env as part of the bundle or only the component code
487
363
  * (we used in the past to bundle them together, there might also be specific envs which still uses the env strategy)
488
364
  * @param component
489
365
  * @returns
490
366
  */
491
-
492
-
493
367
  async isBundledWithEnv(component) {
494
368
  const artifacts = await this.builder.getArtifactsVinylByAspectAndName(component, _preview().PreviewAspect.id, _componentStrategy().COMPONENT_STRATEGY_ARTIFACT_NAME);
495
369
  if (!artifacts || !artifacts.length) return true;
496
370
  return false;
497
- } // This used on component load to calc the final result of support is scaling for a given component
371
+ }
372
+
373
+ // This used on component load to calc the final result of support is scaling for a given component
498
374
  // This calc based on the env, env data, env preview config and more
499
375
  // if you want to get the final result use the `doesScaling` method below
500
376
  // This should be used only for component load
501
-
502
-
503
377
  async calcDoesScalingForComponent(component) {
504
- const isBundledWithEnv = await this.isBundledWithEnv(component); // 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
505
-
378
+ const isBundledWithEnv = await this.isBundledWithEnv(component);
379
+ // 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
506
380
  if (this.envs.isUsingCoreEnv(component)) {
507
381
  // 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)
508
382
  // If it's new, and we are here, it means that we already use a version of the env that support scaling
509
383
  const isNew = await component.isNew();
510
-
511
384
  if (isNew) {
512
385
  return true;
513
386
  }
514
-
515
387
  return isBundledWithEnv === false;
516
- } // For envs that bundled with the env return true always
517
-
518
-
388
+ }
389
+ // For envs that bundled with the env return true always
519
390
  if (isBundledWithEnv) {
520
391
  return true;
521
392
  }
522
-
523
393
  const envComponent = await this.envs.getEnvComponent(component);
524
394
  return this.isEnvSupportScaling(envComponent);
525
395
  }
396
+
526
397
  /**
527
398
  * can the current component preview scale in size for different preview sizes.
528
399
  * this calculation is based on the env of the component and if the env of the component support it.
529
400
  */
530
-
531
-
532
401
  async doesScaling(component) {
533
402
  var _this$workspace2, _component$state$aspe;
534
-
535
- const inWorkspace = await ((_this$workspace2 = this.workspace) === null || _this$workspace2 === void 0 ? void 0 : _this$workspace2.hasId(component.id)); // 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
403
+ const inWorkspace = await ((_this$workspace2 = this.workspace) === null || _this$workspace2 === void 0 ? void 0 : _this$workspace2.hasId(component.id));
404
+ // 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
536
405
  // since we bundle it for the dev server again
537
-
538
406
  if (inWorkspace) {
539
407
  const envComponent = await this.envs.getEnvComponent(component);
540
408
  const envSupportScaling = await this.calculateIsEnvSupportScaling(envComponent);
541
409
  return envSupportScaling !== null && envSupportScaling !== void 0 ? envSupportScaling : true;
542
410
  }
543
-
544
411
  const previewData = (_component$state$aspe = component.state.aspects.get(_preview().PreviewAspect.id)) === null || _component$state$aspe === void 0 ? void 0 : _component$state$aspe.data;
545
- if (!previewData) return false; // Get the does scaling (the new calculation) or the old calc used in isScaling (between versions (about) 848 and 860)
546
-
547
- if (previewData.doesScaling !== undefined) return previewData.doesScaling; // in case this component were tagged with versions between 848 and 860 we need to use the old calculation
412
+ if (!previewData) return false;
413
+ // Get the does scaling (the new calculation) or the old calc used in isScaling (between versions (about) 848 and 860)
414
+ if (previewData.doesScaling !== undefined) return previewData.doesScaling;
415
+ // in case this component were tagged with versions between 848 and 860 we need to use the old calculation
548
416
  // together with the env calculation
549
417
  // In that case it means the component already tagged, so we take the env calc from the env data and not re-calc it
550
-
551
418
  if (previewData.isScaling) {
552
419
  const envComponent = await this.envs.getEnvComponent(component);
553
420
  const envSupportScaling = this.isEnvSupportScaling(envComponent);
554
421
  return !!envSupportScaling;
555
422
  }
556
-
557
423
  return false;
558
424
  }
425
+
559
426
  /**
560
427
  * Check if the current version of the env support scaling
561
428
  * @param envComponent
562
429
  * @returns
563
430
  */
564
-
565
-
566
431
  isEnvSupportScaling(envComponent) {
567
432
  var _envComponent$state$a;
568
-
569
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;
570
434
  return !!(previewData !== null && previewData !== void 0 && previewData.isScaling);
571
435
  }
436
+
572
437
  /**
573
438
  * This function is calculate the isScaling support flag for the component preview.
574
439
  * This is calculated only for the env component and not for the component itself.
@@ -578,39 +443,33 @@ class PreviewMain {
578
443
  * @param component
579
444
  * @returns
580
445
  */
581
-
582
-
583
446
  async calculateIsEnvSupportScaling(envComponent) {
584
447
  var _previewAspectConfig$;
585
-
586
- const isEnv = this.envs.isEnv(envComponent); // If the component is not an env, we don't want to store anything in the data
587
-
448
+ const isEnv = this.envs.isEnv(envComponent);
449
+ // If the component is not an env, we don't want to store anything in the data
588
450
  if (!isEnv) return undefined;
589
- const previewAspectConfig = this.getPreviewConfig(envComponent); // default to true if the env doesn't have a preview config
590
-
451
+ const previewAspectConfig = this.getPreviewConfig(envComponent);
452
+ // default to true if the env doesn't have a preview config
591
453
  return (_previewAspectConfig$ = previewAspectConfig === null || previewAspectConfig === void 0 ? void 0 : previewAspectConfig.isScaling) !== null && _previewAspectConfig$ !== void 0 ? _previewAspectConfig$ : true;
592
454
  }
455
+
593
456
  /**
594
457
  * Get the preview config of the component.
595
458
  * (config that was set by variants or on bitmap)
596
459
  * @param component
597
460
  * @returns
598
461
  */
599
-
600
-
601
462
  getPreviewConfig(component) {
602
463
  var _component$state$aspe2;
603
-
604
464
  return (_component$state$aspe2 = component.state.aspects.get(_preview().PreviewAspect.id)) === null || _component$state$aspe2 === void 0 ? void 0 : _component$state$aspe2.config;
605
465
  }
466
+
606
467
  /**
607
468
  * Check if the component preview bundle contain the header inside of it (legacy)
608
469
  * today we are not including the header inside anymore
609
470
  * @param component
610
471
  * @returns
611
472
  */
612
-
613
-
614
473
  async isLegacyHeader(component) {
615
474
  // these envs had header in their docs
616
475
  const ENV_WITH_LEGACY_DOCS = ['react', 'env', 'aspect', 'lit', 'html', 'node', 'mdx', 'react-native', 'readme'];
@@ -618,6 +477,7 @@ class PreviewMain {
618
477
  const envType = this.envs.getEnvData(component).type;
619
478
  return !!artifacts && !!artifacts.length && ENV_WITH_LEGACY_DOCS.includes(envType);
620
479
  }
480
+
621
481
  /**
622
482
  * Getting the env template artifact
623
483
  * This should be called with the env itself or it will return undefined
@@ -627,84 +487,69 @@ class PreviewMain {
627
487
  * @param component
628
488
  * @returns
629
489
  */
630
-
631
-
632
490
  async getEnvTemplate(component) {
633
491
  const artifacts = await this.builder.getArtifactsVinylByAspectAndTaskName(component, _preview().PreviewAspect.id, _envPreviewTemplate().GENERATE_ENV_TEMPLATE_TASK_NAME);
634
492
  if (!artifacts || !artifacts.length) return undefined;
635
493
  return new (_previewArtifact().PreviewArtifact)(artifacts);
636
494
  }
495
+
637
496
  /**
638
497
  * This is a special method to get a core env template
639
498
  * As the core envs doesn't exist in the scope we need to bring it from other place
640
499
  * We will bring it from the core env package files
641
500
  */
642
-
643
-
644
501
  async getCoreEnvTemplate(envId) {
645
- const coreEnvDir = (0, _aspectLoader().getAspectDir)(envId); // const finalDir = join(coreEnvDir, getEnvTemplateArtifactDirectory());
646
-
502
+ const coreEnvDir = (0, _aspectLoader().getAspectDir)(envId);
503
+ // const finalDir = join(coreEnvDir, getEnvTemplateArtifactDirectory());
647
504
  const artifactDef = (0, _envPreviewTemplate().getArtifactDef)()[0];
648
505
  const artifactFactory = new (_builder().ArtifactFactory)();
649
506
  let rootDir = artifactFactory.getRootDir(coreEnvDir, artifactDef);
650
-
651
507
  if (!(0, _fsExtra().existsSync)(rootDir)) {
652
508
  // fallback to the bvm folder
653
509
  const coreEnvDirFromBvm = (0, _aspectLoader().getAspectDirFromBvm)(envId);
654
510
  rootDir = artifactFactory.getRootDir(coreEnvDirFromBvm, artifactDef);
655
511
  }
656
-
657
512
  if (!(0, _fsExtra().existsSync)(rootDir)) {
658
513
  return undefined;
659
514
  }
660
-
661
515
  const paths = artifactFactory.resolvePaths(rootDir, artifactDef);
662
-
663
516
  if (!paths || !paths.length) {
664
517
  return undefined;
665
518
  }
666
-
667
519
  const artifactFiles = new (_artifactFiles().ArtifactFiles)(paths);
668
520
  artifactFiles.populateVinylsFromPaths(rootDir);
669
521
  return new (_previewArtifact().PreviewArtifact)(artifactFiles.vinyls);
670
522
  }
523
+
671
524
  /**
672
525
  * This will fetch the component env, then will take the env template from the component env
673
526
  * @param component
674
527
  */
675
-
676
-
677
528
  async getEnvTemplateFromComponentEnv(component) {
678
529
  const envId = this.envs.getEnvId(component);
679
530
  return this.getEnvTemplateByEnvId(envId);
680
531
  }
532
+
681
533
  /**
682
534
  * This will fetch the component env, then will take the env template from the component env
683
535
  * @param component
684
536
  */
685
-
686
-
687
537
  async getEnvTemplateByEnvId(envId) {
688
538
  // Special treatment for core envs
689
539
  if (this.aspectLoader.isCoreEnv(envId)) {
690
540
  return this.getCoreEnvTemplate(envId);
691
541
  }
692
-
693
542
  const host = this.componentAspect.getHost();
694
543
  const resolvedEnvId = await host.resolveComponentId(envId);
695
544
  const envComponent = await host.get(resolvedEnvId);
696
-
697
545
  if (!envComponent) {
698
546
  throw new (_bitError().BitError)(`can't load env. env id is ${envId}`);
699
547
  }
700
-
701
548
  return this.getEnvTemplate(envComponent);
702
549
  }
703
-
704
550
  getDefs() {
705
551
  return this.previewSlot.values();
706
552
  }
707
-
708
553
  /**
709
554
  * write a link to load custom modules dynamically.
710
555
  * @param prefix write
@@ -716,21 +561,18 @@ class PreviewMain {
716
561
  const contents = (0, _generateLink().generateLink)(prefix, moduleMap, defaultModule, isSplitComponentBundle);
717
562
  return this.writeLinkContents(contents, dirName, prefix);
718
563
  }
719
-
720
564
  writeLinkContents(contents, targetDir, prefix) {
721
565
  const hash = (0, _objectHash().default)(contents);
722
- const targetPath = (0, _path().join)(targetDir, `${prefix}-${this.timestamp}.js`); // write only if link has changed (prevents triggering fs watches)
566
+ const targetPath = (0, _path().join)(targetDir, `${prefix}-${this.timestamp}.js`);
723
567
 
568
+ // write only if link has changed (prevents triggering fs watches)
724
569
  if (this.writeHash.get(targetPath) !== hash) {
725
570
  (0, _fsExtra().writeFileSync)(targetPath, contents);
726
571
  this.writeHash.set(targetPath, hash);
727
572
  }
728
-
729
573
  return targetPath;
730
574
  }
731
-
732
- async getPreviewTarget(
733
- /** execution context (of the specific env) */
575
+ async getPreviewTarget( /** execution context (of the specific env) */
734
576
  context) {
735
577
  // store context for later link-file updates
736
578
  // also register related envs that this context is acting on their behalf
@@ -741,18 +583,15 @@ class PreviewMain {
741
583
  const linkFiles = await this.updateLinkFiles(context.components, context);
742
584
  return [...linkFiles, previewRuntime];
743
585
  }
744
-
745
586
  updateLinkFiles(components = [], context) {
746
587
  const previews = this.previewSlot.values();
747
588
  const paths = previews.map(async previewDef => {
748
589
  var _previewDef$renderTem, _this$getEnvPreviewCo;
749
-
750
590
  const templatePath = await ((_previewDef$renderTem = previewDef.renderTemplatePath) === null || _previewDef$renderTem === void 0 ? void 0 : _previewDef$renderTem.call(previewDef, context));
751
591
  const map = await previewDef.getModuleMap(components);
752
592
  const isSplitComponentBundle = (_this$getEnvPreviewCo = this.getEnvPreviewConfig().splitComponentBundle) !== null && _this$getEnvPreviewCo !== void 0 ? _this$getEnvPreviewCo : false;
753
593
  const withPaths = map.map((files, component) => {
754
594
  var _environment$getCompi, _compilerInstance$get;
755
-
756
595
  const environment = this.envs.getEnv(component).env;
757
596
  const compilerInstance = (_environment$getCompi = environment.getCompiler) === null || _environment$getCompi === void 0 ? void 0 : _environment$getCompi.call(environment);
758
597
  const modulePath = (compilerInstance === null || compilerInstance === void 0 ? void 0 : (_compilerInstance$get = compilerInstance.getPreviewComponentRootPath) === null || _compilerInstance$get === void 0 ? void 0 : _compilerInstance$get.call(compilerInstance, component)) || this.pkg.getRuntimeModulePath(component);
@@ -760,11 +599,12 @@ class PreviewMain {
760
599
  if (!this.workspace || !compilerInstance) {
761
600
  return file.path;
762
601
  }
763
-
764
602
  const distRelativePath = compilerInstance.getDistPathBySrcPath(file.relative);
765
603
  return (0, _path().join)(this.workspace.path, modulePath, distRelativePath);
766
- }); // return files.map((file) => file.path);
604
+ });
605
+ // return files.map((file) => file.path);
767
606
  });
607
+
768
608
  const dirPath = (0, _path().join)(this.tempFolder, context.id);
769
609
  if (!(0, _fsExtra().existsSync)(dirPath)) (0, _fsExtra().mkdirSync)(dirPath, {
770
610
  recursive: true
@@ -774,7 +614,6 @@ class PreviewMain {
774
614
  });
775
615
  return Promise.all(paths);
776
616
  }
777
-
778
617
  async writePreviewRuntime(context, aspectsIdsToNotFilterOut = []) {
779
618
  const [name, uiRoot] = this.getUi();
780
619
  const resolvedAspects = await this.resolveAspects(_preview().PreviewRuntime.name, undefined, uiRoot);
@@ -782,19 +621,18 @@ class PreviewMain {
782
621
  const filePath = await this.ui.generateRoot(filteredAspects, name, 'preview', _preview().PreviewAspect.id);
783
622
  return filePath;
784
623
  }
785
-
786
624
  async resolveAspects(runtimeName, componentIds, uiRoot, opts) {
787
625
  const root = uiRoot || this.getUi()[1];
788
626
  runtimeName = runtimeName || _cli().MainRuntime.name;
789
627
  const resolvedAspects = await root.resolveAspects(runtimeName, componentIds, opts);
790
628
  return resolvedAspects;
791
629
  }
792
-
793
630
  getUi() {
794
631
  const ui = this.ui.getUi();
795
632
  if (!ui) throw new Error('ui not found');
796
633
  return ui;
797
634
  }
635
+
798
636
  /**
799
637
  * Filter the aspects to have only aspects that are:
800
638
  * 1. core aspects
@@ -803,8 +641,6 @@ class PreviewMain {
803
641
  * @param aspects
804
642
  * @param context
805
643
  */
806
-
807
-
808
644
  filterAspectsByExecutionContext(aspects, context, aspectsIdsToNotFilterOut = []) {
809
645
  let allComponentContextAspects = [];
810
646
  allComponentContextAspects = context.components.reduce((acc, curr) => {
@@ -816,27 +652,25 @@ class PreviewMain {
816
652
  if (!aspect.getId) {
817
653
  return false;
818
654
  }
819
-
820
655
  return this.aspectLoader.isCoreAspect(aspect.getId) || allAspectsToInclude.includes(aspect.getId) || aspectsIdsToNotFilterOut.includes(aspect.getId);
821
656
  });
822
657
  return filtered;
823
658
  }
824
-
825
659
  getDefaultStrategies() {
826
660
  return [new (_strategies().EnvBundlingStrategy)(this, this.pkg, this.dependencyResolver), new (_strategies().ComponentBundlingStrategy)(this, this.pkg, this.dependencyResolver)];
827
- } // TODO - executionContext should be responsible for updating components list, and emit 'update' events
828
- // instead we keep track of changes
661
+ }
829
662
 
663
+ // TODO - executionContext should be responsible for updating components list, and emit 'update' events
664
+ // instead we keep track of changes
830
665
 
831
666
  getEnvPreviewConfig(env) {
832
667
  const config = env !== null && env !== void 0 && env.getPreviewConfig && typeof (env === null || env === void 0 ? void 0 : env.getPreviewConfig) === 'function' ? env === null || env === void 0 ? void 0 : env.getPreviewConfig() : {};
833
668
  return config;
834
669
  }
670
+
835
671
  /**
836
672
  * return the configured bundling strategy.
837
673
  */
838
-
839
-
840
674
  getBundlingStrategy(env) {
841
675
  const defaultStrategies = this.getDefaultStrategies();
842
676
  const envPreviewConfig = this.getEnvPreviewConfig(env);
@@ -849,37 +683,35 @@ class PreviewMain {
849
683
  if (!selected) throw new (_exceptions().BundlingStrategyNotFound)(strategyName);
850
684
  return selected;
851
685
  }
686
+
852
687
  /**
853
688
  * register a new bundling strategy. default available strategies are `env` and ``
854
689
  */
855
-
856
-
857
690
  registerBundlingStrategy(bundlingStrategy) {
858
691
  this.bundlingStrategySlot.register(bundlingStrategy);
859
692
  return this;
860
693
  }
694
+
861
695
  /**
862
696
  * register a new preview definition.
863
697
  */
864
-
865
-
866
698
  registerDefinition(previewDef) {
867
699
  this.previewSlot.register(previewDef);
868
700
  }
869
-
870
- static async provider( // eslint-disable-next-line max-len
701
+ static async provider(
702
+ // eslint-disable-next-line max-len
871
703
  [bundler, builder, componentExtension, uiMain, envs, workspace, pkg, pubsub, aspectLoader, loggerMain, dependencyResolver, graphql], config, [previewSlot, bundlingStrategySlot], harmony) {
872
- const logger = loggerMain.createLogger(_preview().PreviewAspect.id); // app.registerApp(new PreviewApp());
873
-
704
+ const logger = loggerMain.createLogger(_preview().PreviewAspect.id);
705
+ // app.registerApp(new PreviewApp());
874
706
  const preview = new PreviewMain(harmony, previewSlot, uiMain, envs, componentExtension, pkg, aspectLoader, config, bundlingStrategySlot, builder, workspace, logger, dependencyResolver);
875
707
  if (workspace) uiMain.registerStartPlugin(new (_preview4().PreviewStartPlugin)(workspace, bundler, uiMain, pubsub, logger));
876
- componentExtension.registerRoute([new (_preview2().PreviewRoute)(preview, logger), new (_componentPreview().ComponentPreviewRoute)(preview, logger), // @ts-ignore
708
+ componentExtension.registerRoute([new (_preview2().PreviewRoute)(preview, logger), new (_componentPreview().ComponentPreviewRoute)(preview, logger),
709
+ // @ts-ignore
877
710
  new (_envTemplate().EnvTemplateRoute)(preview, logger), new (_previewAssets().PreviewAssetsRoute)(preview, logger)]);
878
711
  bundler.registerTarget([{
879
712
  entry: preview.getPreviewTarget.bind(preview)
880
713
  }]);
881
714
  if (!config.disabled) builder.registerBuildTasks([new (_envPreviewTemplate().EnvPreviewTemplateTask)(preview, envs, aspectLoader, dependencyResolver, logger), new (_preview3().PreviewTask)(bundler, preview, dependencyResolver, logger)]);
882
-
883
715
  if (workspace) {
884
716
  workspace.registerOnComponentAdd(c => preview.handleComponentChange(c, currentComponents => currentComponents.add(c)));
885
717
  workspace.onComponentLoad(async component => {
@@ -887,24 +719,20 @@ class PreviewMain {
887
719
  const isScaling = await preview.calculateIsEnvSupportScaling(component);
888
720
  const data = {
889
721
  doesScaling
890
- }; // If there is no isScaling result at all, it's probably not an env. don't store any data.
891
-
722
+ };
723
+ // If there is no isScaling result at all, it's probably not an env. don't store any data.
892
724
  if (isScaling !== undefined) {
893
725
  data.isScaling = isScaling;
894
726
  }
895
-
896
727
  return data;
897
728
  });
898
729
  workspace.registerOnComponentChange(c => preview.handleComponentChange(c, currentComponents => currentComponents.update(c)));
899
730
  workspace.registerOnComponentRemove(cId => preview.handleComponentRemoval(cId));
900
731
  }
901
-
902
732
  graphql.register((0, _preview5().previewSchema)(preview));
903
733
  return preview;
904
734
  }
905
-
906
735
  }
907
-
908
736
  exports.PreviewMain = PreviewMain;
909
737
  (0, _defineProperty2().default)(PreviewMain, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType()]);
910
738
  (0, _defineProperty2().default)(PreviewMain, "runtime", _cli().MainRuntime);
@@ -912,7 +740,6 @@ exports.PreviewMain = PreviewMain;
912
740
  (0, _defineProperty2().default)(PreviewMain, "defaultConfig", {
913
741
  disabled: false
914
742
  });
915
-
916
743
  _preview().PreviewAspect.addRuntime(PreviewMain);
917
744
 
918
745
  //# sourceMappingURL=preview.main.runtime.js.map