@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,100 +1,70 @@
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
  require("core-js/modules/es.regexp.exec.js");
10
-
11
7
  require("core-js/modules/es.string.replace.js");
12
-
13
8
  Object.defineProperty(exports, "__esModule", {
14
9
  value: true
15
10
  });
16
11
  exports.PREVIEW_CHUNK_SUFFIX = exports.PREVIEW_CHUNK_FILENAME_SUFFIX = exports.ComponentBundlingStrategy = exports.COMPONENT_STRATEGY_SIZE_KEY_NAME = exports.COMPONENT_STRATEGY_ARTIFACT_NAME = exports.COMPONENT_CHUNK_SUFFIX = exports.COMPONENT_CHUNK_FILENAME_SUFFIX = void 0;
17
-
18
12
  function _defineProperty2() {
19
13
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
-
21
14
  _defineProperty2 = function () {
22
15
  return data;
23
16
  };
24
-
25
17
  return data;
26
18
  }
27
-
28
19
  function _path() {
29
20
  const data = require("path");
30
-
31
21
  _path = function () {
32
22
  return data;
33
23
  };
34
-
35
24
  return data;
36
25
  }
37
-
38
26
  function _fsExtra() {
39
27
  const data = require("fs-extra");
40
-
41
28
  _fsExtra = function () {
42
29
  return data;
43
30
  };
44
-
45
31
  return data;
46
32
  }
47
-
48
33
  function _lodash() {
49
34
  const data = require("lodash");
50
-
51
35
  _lodash = function () {
52
36
  return data;
53
37
  };
54
-
55
38
  return data;
56
39
  }
57
-
58
40
  function _builder() {
59
41
  const data = require("@teambit/builder");
60
-
61
42
  _builder = function () {
62
43
  return data;
63
44
  };
64
-
65
45
  return data;
66
46
  }
67
-
68
47
  function _bitError() {
69
48
  const data = require("@teambit/bit-error");
70
-
71
49
  _bitError = function () {
72
50
  return data;
73
51
  };
74
-
75
52
  return data;
76
53
  }
77
-
78
54
  function _generateComponentLink() {
79
55
  const data = require("./generate-component-link");
80
-
81
56
  _generateComponentLink = function () {
82
57
  return data;
83
58
  };
84
-
85
59
  return data;
86
60
  }
87
-
88
61
  function _exceptions() {
89
62
  const data = require("../exceptions");
90
-
91
63
  _exceptions = function () {
92
64
  return data;
93
65
  };
94
-
95
66
  return data;
96
67
  }
97
-
98
68
  const PREVIEW_CHUNK_SUFFIX = 'preview';
99
69
  exports.PREVIEW_CHUNK_SUFFIX = PREVIEW_CHUNK_SUFFIX;
100
70
  const COMPONENT_CHUNK_SUFFIX = 'component';
@@ -107,7 +77,6 @@ const COMPONENT_STRATEGY_SIZE_KEY_NAME = 'size';
107
77
  exports.COMPONENT_STRATEGY_SIZE_KEY_NAME = COMPONENT_STRATEGY_SIZE_KEY_NAME;
108
78
  const COMPONENT_STRATEGY_ARTIFACT_NAME = 'preview-component';
109
79
  exports.COMPONENT_STRATEGY_ARTIFACT_NAME = COMPONENT_STRATEGY_ARTIFACT_NAME;
110
-
111
80
  /**
112
81
  * bundles all components in a given env into the same bundle.
113
82
  */
@@ -118,10 +87,11 @@ class ComponentBundlingStrategy {
118
87
  this.dependencyResolver = dependencyResolver;
119
88
  (0, _defineProperty2().default)(this, "name", 'component');
120
89
  }
121
-
122
90
  async computeTargets(context, previewDefs) {
123
91
  const outputPath = this.getOutputPath(context);
124
- if (!(0, _fsExtra().existsSync)(outputPath)) (0, _fsExtra().mkdirpSync)(outputPath); // const entriesArr = flatten(
92
+ if (!(0, _fsExtra().existsSync)(outputPath)) (0, _fsExtra().mkdirpSync)(outputPath);
93
+
94
+ // const entriesArr = flatten(
125
95
  // await Promise.all(
126
96
  // context.capsuleNetwork.seedersCapsules.map((capsule) => {
127
97
  // return this.computeComponentEntry(previewDefs, capsule.component, context);
@@ -147,7 +117,6 @@ class ComponentBundlingStrategy {
147
117
  entries,
148
118
  components,
149
119
  outputPath,
150
-
151
120
  /* It's a path to the root of the host component. */
152
121
  // hostRootDir, handle this
153
122
  hostDependencies: peers,
@@ -155,10 +124,12 @@ class ComponentBundlingStrategy {
155
124
  externalizeHostDependencies: true
156
125
  };
157
126
  });
158
- return targets; // const entries = entriesArr.reduce((entriesMap, entry) => {
127
+ return targets;
128
+ // const entries = entriesArr.reduce((entriesMap, entry) => {
159
129
  // entriesMap[entry.library.name] = entry;
160
130
  // return entriesMap;
161
131
  // }, {});
132
+
162
133
  // const modules = await Promise.all(entriesArr.map(async (entry) => {
163
134
  // const dependencies = await this.dependencyResolver.getDependencies(entry.component);
164
135
  // const manifest = dependencies.toDependenciesManifest();
@@ -167,6 +138,7 @@ class ComponentBundlingStrategy {
167
138
  // singleton: true,
168
139
  // requiredVersion: version
169
140
  // };
141
+
170
142
  // return acc;
171
143
  // }, {});
172
144
  // // console.log(entry);
@@ -204,7 +176,6 @@ class ComponentBundlingStrategy {
204
176
  }
205
177
  }
206
178
  };
207
-
208
179
  if (chunks.component) {
209
180
  entries[chunks.component] = {
210
181
  filename: this.getComponentChunkFileName(component.id.toString({
@@ -219,63 +190,55 @@ class ComponentBundlingStrategy {
219
190
  }
220
191
  };
221
192
  }
222
-
223
193
  return {
224
194
  component,
225
195
  entries
226
196
  };
227
197
  }
228
-
229
198
  getComponentChunkId(componentId, type) {
230
199
  const id = type === 'component' ? componentId.toStringWithoutVersion() : `${componentId.toStringWithoutVersion()}-${PREVIEW_CHUNK_SUFFIX}`;
231
200
  return id;
232
201
  }
233
-
234
202
  getComponentChunkFileName(idstr, type) {
235
203
  const suffix = type === 'component' ? COMPONENT_CHUNK_FILENAME_SUFFIX : PREVIEW_CHUNK_FILENAME_SUFFIX;
236
204
  return `${idstr}-${suffix}`;
237
205
  }
238
-
239
206
  getAssetAbsolutePath(context, asset) {
240
207
  const path = this.getOutputPath(context);
241
208
  return (0, _path().join)(path, 'public', this.getAssetFilename(asset));
242
209
  }
243
-
244
210
  getAssetFilename(asset) {
245
211
  // handle cases where the asset name is something like my-image.svg?hash (while the filename in the fs is just my-image.svg)
246
212
  const [name] = asset.name.split('?');
247
213
  return name;
248
214
  }
249
-
250
215
  copyAssetsToCapsules(context, result) {
251
216
  context.components.forEach(component => {
252
217
  const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);
253
218
  if (!capsule) return;
254
219
  const files = this.findAssetsForComponent(component, result.assets, result.entriesAssetsMap || {});
255
220
  if (!files) return;
256
- const artifactDirFullPath = (0, _path().join)(capsule.path, this.getArtifactDirectory()); // We don't use the mkdirSync as it uses the capsule fs which uses memfs, which doesn't know to handle nested none existing folders
257
-
221
+ const artifactDirFullPath = (0, _path().join)(capsule.path, this.getArtifactDirectory());
222
+ // We don't use the mkdirSync as it uses the capsule fs which uses memfs, which doesn't know to handle nested none existing folders
258
223
  (0, _fsExtra().mkdirpSync)(artifactDirFullPath);
259
224
  files.forEach(asset => {
260
225
  const filePath = this.getAssetAbsolutePath(context, asset);
261
-
262
226
  if (!(0, _fsExtra().existsSync)(filePath)) {
263
227
  throw new (_exceptions().PreviewOutputFileNotFound)(component.id, filePath);
264
228
  }
265
-
266
229
  const destFilePath = (0, _path().join)(artifactDirFullPath, this.getAssetFilename(asset));
267
230
  (0, _fsExtra().mkdirpSync)((0, _path().dirname)(destFilePath));
268
231
  capsule.fs.copyFileSync(filePath, destFilePath);
269
232
  });
270
233
  });
271
- } // private getCssFileName(componentId: ComponentID): string {
234
+ }
235
+
236
+ // private getCssFileName(componentId: ComponentID): string {
272
237
  // return `${componentId.toString({ ignoreVersion: true, fsCompatible: true })}.css`;
273
238
  // }
274
239
 
275
-
276
240
  findAssetsForComponent(component, assets, entriesAssetsMap) {
277
241
  var _entriesAssetsMap$com, _entriesAssetsMap$com2, _entriesAssetsMap$com3, _entriesAssetsMap$com4;
278
-
279
242
  if (!assets) return undefined;
280
243
  const componentEntryId = component.id.toStringWithoutVersion();
281
244
  const componentPreviewEntryId = this.getComponentChunkId(component.id, 'preview');
@@ -286,20 +249,15 @@ class ComponentBundlingStrategy {
286
249
  const files = componentFiles.concat(componentAuxiliaryFiles).concat(componentPreviewFiles).concat(componentPreviewAuxiliaryFiles);
287
250
  return files;
288
251
  }
289
-
290
252
  getArtifactDirectory() {
291
253
  return (0, _path().join)(_builder().CAPSULE_ARTIFACTS_DIR, 'preview');
292
254
  }
293
-
294
255
  computeComponentMetadata(context, result, component) {
295
256
  var _result$entriesAssets, _result$entriesAssets2, _result$entriesAssets3, _result$entriesAssets4, _result$entriesAssets5, _result$entriesAssets6;
296
-
297
257
  const componentEntryId = component.id.toStringWithoutVersion();
298
-
299
258
  if (!(result !== null && result !== void 0 && result.entriesAssetsMap) || !(result !== null && result !== void 0 && result.entriesAssetsMap[componentEntryId])) {
300
259
  return {};
301
260
  }
302
-
303
261
  const files = (((_result$entriesAssets = result.entriesAssetsMap[componentEntryId]) === null || _result$entriesAssets === void 0 ? void 0 : _result$entriesAssets.assets) || []).map(file => {
304
262
  return {
305
263
  name: (0, _path().basename)(file.name),
@@ -334,7 +292,6 @@ class ComponentBundlingStrategy {
334
292
  };
335
293
  return metadata;
336
294
  }
337
-
338
295
  async computeResults(context, results) {
339
296
  const componentsResults = (0, _lodash().flatten)(await Promise.all(results.map(result => this.computeTargetResult(context, result))));
340
297
  const artifacts = this.getArtifactDef();
@@ -343,13 +300,11 @@ class ComponentBundlingStrategy {
343
300
  artifacts
344
301
  };
345
302
  }
346
-
347
303
  async computeTargetResult(context, result) {
348
304
  if ((0, _lodash().isEmpty)(result.errors)) {
349
305
  // In case there are errors files will not be emitted so trying to copy them will fail anyway
350
306
  this.copyAssetsToCapsules(context, result);
351
307
  }
352
-
353
308
  const componentsResults = result.components.map(component => {
354
309
  const metadata = this.computeComponentMetadata(context, result, component);
355
310
  return {
@@ -363,16 +318,16 @@ class ComponentBundlingStrategy {
363
318
  });
364
319
  return componentsResults;
365
320
  }
366
-
367
321
  getArtifactDef() {
368
322
  // eslint-disable-next-line @typescript-eslint/prefer-as-const
369
323
  // const env: 'env' = 'env';
370
324
  // const rootDir = this.getDirName(context);
325
+
371
326
  return [{
372
327
  name: COMPONENT_STRATEGY_ARTIFACT_NAME,
373
328
  globPatterns: ['**'],
374
- rootDir: this.getArtifactDirectory() // context: env,
375
-
329
+ rootDir: this.getArtifactDirectory()
330
+ // context: env,
376
331
  }];
377
332
  }
378
333
 
@@ -380,26 +335,22 @@ class ComponentBundlingStrategy {
380
335
  const envName = context.id.replace('/', '__');
381
336
  return `${envName}-preview`;
382
337
  }
383
-
384
338
  getOutputPath(context) {
385
339
  return (0, _path().resolve)(`${context.capsuleNetwork.capsulesRootDir}/${this.getDirName(context)}`);
386
340
  }
387
-
388
341
  getPaths(context, component, files) {
389
342
  const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);
390
343
  if (!capsule) return [];
391
344
  const compiler = context.env.getCompiler();
392
345
  return files.map(file => (0, _path().join)(capsule.path, compiler.getDistPathBySrcPath(file.relative)));
393
346
  }
394
-
395
347
  getComponentOutputPath(capsule) {
396
348
  return (0, _path().resolve)(`${capsule.path}`);
397
349
  }
398
-
399
350
  async computePaths(defs, context, component) {
400
351
  // const previewMain = await this.preview.writePreviewRuntime(context);
401
- const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id); // if (!capsule) return undefined;
402
-
352
+ const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);
353
+ // if (!capsule) return undefined;
403
354
  if (!capsule) throw new (_bitError().BitError)(`could not find capsule for component ${component.id.toString()} during compute paths to bundle`);
404
355
  const moduleMapsPromise = defs.map(async previewDef => {
405
356
  const moduleMap = await previewDef.getModuleMap([component]);
@@ -419,11 +370,10 @@ class ComponentBundlingStrategy {
419
370
  });
420
371
  const moduleMaps = await Promise.all(moduleMapsPromise);
421
372
  const contents = (0, _generateComponentLink().generateComponentLink)(moduleMaps);
422
- return this.preview.writeLinkContents(contents, this.getComponentOutputPath(capsule), 'preview'); // return flatten(moduleMaps);
373
+ return this.preview.writeLinkContents(contents, this.getComponentOutputPath(capsule), 'preview');
374
+ // return flatten(moduleMaps);
423
375
  }
424
-
425
376
  }
426
-
427
377
  exports.ComponentBundlingStrategy = ComponentBundlingStrategy;
428
378
 
429
379
  //# sourceMappingURL=component-strategy.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["PREVIEW_CHUNK_SUFFIX","COMPONENT_CHUNK_SUFFIX","PREVIEW_CHUNK_FILENAME_SUFFIX","COMPONENT_CHUNK_FILENAME_SUFFIX","COMPONENT_STRATEGY_SIZE_KEY_NAME","COMPONENT_STRATEGY_ARTIFACT_NAME","ComponentBundlingStrategy","constructor","preview","pkg","dependencyResolver","computeTargets","context","previewDefs","outputPath","getOutputPath","existsSync","mkdirpSync","origComponents","capsuleNetwork","originalSeedersCapsules","map","capsule","component","entriesArr","Promise","all","computeComponentEntry","chunkSize","config","maxChunkSize","chunks","chunk","peers","getPeerDependenciesListFromEnv","env","targets","currentChunk","entries","components","forEach","entry","Object","assign","push","hostDependencies","aliasHostDependencies","externalizeHostDependencies","componentPreviewPath","computePaths","componentPath","getPaths","mainFile","componentPreview","getComponentChunkId","id","splitComponentBundle","toStringWithoutVersion","undefined","filename","getComponentChunkFileName","toString","fsCompatible","ignoreVersion","import","dependOn","library","name","type","componentId","idstr","suffix","getAssetAbsolutePath","asset","path","join","getAssetFilename","split","copyAssetsToCapsules","result","graphCapsules","getCapsule","files","findAssetsForComponent","assets","entriesAssetsMap","artifactDirFullPath","getArtifactDirectory","filePath","PreviewOutputFileNotFound","destFilePath","dirname","fs","copyFileSync","componentEntryId","componentPreviewEntryId","componentFiles","componentAuxiliaryFiles","auxiliaryAssets","componentPreviewFiles","componentPreviewAuxiliaryFiles","concat","CAPSULE_ARTIFACTS_DIR","computeComponentMetadata","file","basename","size","compressedSize","filesTotalSize","assetsSize","compressedTotalFiles","compressedAssetsSize","assetsTotalSize","auxiliaryAssetsSize","compressedTotalAssets","compressedAuxiliaryAssetsSize","totalSize","compressedTotal","metadata","totalFiles","totalAssets","total","computeResults","results","componentsResults","flatten","computeTargetResult","artifacts","getArtifactDef","isEmpty","errors","err","message","warning","warnings","startTime","endTime","globPatterns","rootDir","getDirName","envName","replace","resolve","capsulesRootDir","compiler","getCompiler","getDistPathBySrcPath","relative","getComponentOutputPath","defs","BitError","moduleMapsPromise","previewDef","moduleMap","getModuleMap","getMetadata","maybeFiles","get","prefix","paths","compiledPaths","moduleMaps","contents","generateComponentLink","writeLinkContents"],"sources":["component-strategy.ts"],"sourcesContent":["import { join, resolve, basename, dirname } from 'path';\nimport { existsSync, mkdirpSync } from 'fs-extra';\nimport { Component } from '@teambit/component';\nimport { ComponentID } from '@teambit/component-id';\nimport { flatten, isEmpty, chunk } from 'lodash';\nimport { Compiler } from '@teambit/compiler';\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport type { Capsule } from '@teambit/isolator';\nimport { CAPSULE_ARTIFACTS_DIR, ComponentResult } from '@teambit/builder';\nimport type { PkgMain } from '@teambit/pkg';\nimport { BitError } from '@teambit/bit-error';\nimport type { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport type { BundlerResult, BundlerContext, Asset, BundlerEntryMap, EntriesAssetsMap, Target } from '@teambit/bundler';\nimport { BundlingStrategy, ComputeTargetsContext } from '../bundling-strategy';\nimport type { PreviewDefinition } from '../preview-definition';\nimport type { ComponentPreviewMetaData, PreviewMain } from '../preview.main.runtime';\nimport { generateComponentLink } from './generate-component-link';\nimport { PreviewOutputFileNotFound } from '../exceptions';\n\nexport const PREVIEW_CHUNK_SUFFIX = 'preview';\nexport const COMPONENT_CHUNK_SUFFIX = 'component';\nexport const PREVIEW_CHUNK_FILENAME_SUFFIX = `${PREVIEW_CHUNK_SUFFIX}.js`;\nexport const COMPONENT_CHUNK_FILENAME_SUFFIX = `${COMPONENT_CHUNK_SUFFIX}.js`;\n\nexport const COMPONENT_STRATEGY_SIZE_KEY_NAME = 'size';\nexport const COMPONENT_STRATEGY_ARTIFACT_NAME = 'preview-component';\n\ntype ComponentEntry = {\n component: Component;\n entries: Object;\n};\n/**\n * bundles all components in a given env into the same bundle.\n */\nexport class ComponentBundlingStrategy implements BundlingStrategy {\n name = 'component';\n\n constructor(private preview: PreviewMain, private pkg: PkgMain, private dependencyResolver: DependencyResolverMain) {}\n\n async computeTargets(context: ComputeTargetsContext, previewDefs: PreviewDefinition[]): Promise<Target[]> {\n const outputPath = this.getOutputPath(context);\n if (!existsSync(outputPath)) mkdirpSync(outputPath);\n\n // const entriesArr = flatten(\n // await Promise.all(\n // context.capsuleNetwork.seedersCapsules.map((capsule) => {\n // return this.computeComponentEntry(previewDefs, capsule.component, context);\n // }, {})\n // )\n // );\n\n const origComponents = context.capsuleNetwork.originalSeedersCapsules.map((capsule) => capsule.component);\n\n const entriesArr = await Promise.all(\n origComponents.map((component) => {\n return this.computeComponentEntry(previewDefs, component, context);\n }, {})\n );\n\n const chunkSize = this.preview.config.maxChunkSize;\n\n const chunks = chunkSize ? chunk(entriesArr, chunkSize) : [entriesArr];\n\n const peers = await this.dependencyResolver.getPeerDependenciesListFromEnv(context.env);\n\n const targets = chunks.map((currentChunk) => {\n const entries: BundlerEntryMap = {};\n const components: Component[] = [];\n currentChunk.forEach((entry) => {\n Object.assign(entries, entry.entries);\n components.push(entry.component);\n });\n\n return {\n entries,\n components,\n outputPath,\n /* It's a path to the root of the host component. */\n // hostRootDir, handle this\n hostDependencies: peers,\n aliasHostDependencies: true,\n externalizeHostDependencies: true,\n };\n });\n\n return targets;\n // const entries = entriesArr.reduce((entriesMap, entry) => {\n // entriesMap[entry.library.name] = entry;\n // return entriesMap;\n // }, {});\n\n // const modules = await Promise.all(entriesArr.map(async (entry) => {\n // const dependencies = await this.dependencyResolver.getDependencies(entry.component);\n // const manifest = dependencies.toDependenciesManifest();\n // const peer = Object.entries(manifest.peerDependencies || {}).reduce((acc, [packageName, version]) => {\n // acc[packageName] = {\n // singleton: true,\n // requiredVersion: version\n // };\n\n // return acc;\n // }, {});\n // // console.log(entry);\n // return {\n // name: entry.library.name,\n // exposes: {\n // '.': entry.import || ''\n // },\n // shared: {\n // ...manifest.dependencies,\n // ...peer\n // },\n // };\n // }));\n }\n\n async computeComponentEntry(\n previewDefs: PreviewDefinition[],\n component: Component,\n context: ComputeTargetsContext\n ): Promise<ComponentEntry> {\n const componentPreviewPath = await this.computePaths(previewDefs, context, component);\n const [componentPath] = this.getPaths(context, component, [component.mainFile]);\n\n const chunks = {\n componentPreview: this.getComponentChunkId(component.id, 'preview'),\n component: context.splitComponentBundle ? component.id.toStringWithoutVersion() : undefined,\n };\n\n const entries = {\n [chunks.componentPreview]: {\n filename: this.getComponentChunkFileName(\n component.id.toString({\n fsCompatible: true,\n ignoreVersion: true,\n }),\n 'preview'\n ),\n import: componentPreviewPath,\n dependOn: chunks.component,\n library: { name: chunks.componentPreview, type: 'umd' },\n },\n };\n\n if (chunks.component) {\n entries[chunks.component] = {\n filename: this.getComponentChunkFileName(\n component.id.toString({\n fsCompatible: true,\n ignoreVersion: true,\n }),\n 'component'\n ),\n dependOn: undefined,\n import: componentPath,\n library: { name: chunks.component, type: 'umd' },\n };\n }\n\n return { component, entries };\n }\n\n private getComponentChunkId(componentId: ComponentID, type: 'component' | 'preview') {\n const id =\n type === 'component'\n ? componentId.toStringWithoutVersion()\n : `${componentId.toStringWithoutVersion()}-${PREVIEW_CHUNK_SUFFIX}`;\n return id;\n }\n\n private getComponentChunkFileName(idstr: string, type: 'component' | 'preview') {\n const suffix = type === 'component' ? COMPONENT_CHUNK_FILENAME_SUFFIX : PREVIEW_CHUNK_FILENAME_SUFFIX;\n return `${idstr}-${suffix}`;\n }\n\n private getAssetAbsolutePath(context: BundlerContext, asset: Asset): string {\n const path = this.getOutputPath(context);\n return join(path, 'public', this.getAssetFilename(asset));\n }\n\n private getAssetFilename(asset: Asset): string {\n // handle cases where the asset name is something like my-image.svg?hash (while the filename in the fs is just my-image.svg)\n const [name] = asset.name.split('?');\n return name;\n }\n\n copyAssetsToCapsules(context: BundlerContext, result: BundlerResult) {\n context.components.forEach((component) => {\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n if (!capsule) return;\n const files = this.findAssetsForComponent(component, result.assets, result.entriesAssetsMap || {});\n if (!files) return;\n const artifactDirFullPath = join(capsule.path, this.getArtifactDirectory());\n // We don't use the mkdirSync as it uses the capsule fs which uses memfs, which doesn't know to handle nested none existing folders\n mkdirpSync(artifactDirFullPath);\n\n files.forEach((asset) => {\n const filePath = this.getAssetAbsolutePath(context, asset);\n if (!existsSync(filePath)) {\n throw new PreviewOutputFileNotFound(component.id, filePath);\n }\n const destFilePath = join(artifactDirFullPath, this.getAssetFilename(asset));\n mkdirpSync(dirname(destFilePath));\n capsule.fs.copyFileSync(filePath, destFilePath);\n });\n });\n }\n\n // private getCssFileName(componentId: ComponentID): string {\n // return `${componentId.toString({ ignoreVersion: true, fsCompatible: true })}.css`;\n // }\n\n private findAssetsForComponent(\n component: Component,\n assets: Asset[],\n entriesAssetsMap: EntriesAssetsMap\n ): Asset[] | undefined {\n if (!assets) return undefined;\n\n const componentEntryId = component.id.toStringWithoutVersion();\n const componentPreviewEntryId = this.getComponentChunkId(component.id, 'preview');\n const componentFiles = entriesAssetsMap[componentEntryId]?.assets || [];\n const componentAuxiliaryFiles = entriesAssetsMap[componentEntryId]?.auxiliaryAssets || [];\n const componentPreviewFiles = entriesAssetsMap[componentPreviewEntryId]?.assets || [];\n const componentPreviewAuxiliaryFiles = entriesAssetsMap[componentPreviewEntryId]?.auxiliaryAssets || [];\n\n const files = componentFiles\n .concat(componentAuxiliaryFiles)\n .concat(componentPreviewFiles)\n .concat(componentPreviewAuxiliaryFiles);\n return files;\n }\n\n private getArtifactDirectory() {\n return join(CAPSULE_ARTIFACTS_DIR, 'preview');\n }\n\n private computeComponentMetadata(\n context: BundlerContext,\n result: BundlerResult,\n component: Component\n ): ComponentPreviewMetaData {\n const componentEntryId = component.id.toStringWithoutVersion();\n if (!result?.entriesAssetsMap || !result?.entriesAssetsMap[componentEntryId]) {\n return {};\n }\n const files = (result.entriesAssetsMap[componentEntryId]?.assets || []).map((file) => {\n return {\n name: basename(file.name),\n size: file.size,\n compressedSize: file.compressedSize,\n };\n });\n const filesTotalSize = result.entriesAssetsMap[componentEntryId]?.assetsSize || 0;\n const compressedTotalFiles = result.entriesAssetsMap[componentEntryId]?.compressedAssetsSize || 0;\n const assets = (result.entriesAssetsMap[componentEntryId]?.auxiliaryAssets || []).map((file) => {\n return {\n name: basename(file.name),\n size: file.size,\n compressedSize: file.compressedSize,\n };\n });\n const assetsTotalSize = result.entriesAssetsMap[componentEntryId]?.auxiliaryAssetsSize || 0;\n const compressedTotalAssets = result.entriesAssetsMap[componentEntryId]?.compressedAuxiliaryAssetsSize || 0;\n const totalSize = filesTotalSize + assetsTotalSize;\n const compressedTotal = compressedTotalFiles + compressedTotalAssets;\n\n const metadata = {\n [COMPONENT_STRATEGY_SIZE_KEY_NAME]: {\n files,\n assets,\n totalFiles: filesTotalSize,\n totalAssets: assetsTotalSize,\n total: totalSize,\n compressedTotalFiles,\n compressedTotalAssets,\n compressedTotal,\n },\n };\n\n return metadata;\n }\n\n async computeResults(context: BundlerContext, results: BundlerResult[]) {\n const componentsResults = flatten(\n await Promise.all(results.map((result) => this.computeTargetResult(context, result)))\n );\n\n const artifacts = this.getArtifactDef();\n\n return {\n componentsResults,\n artifacts,\n };\n }\n\n async computeTargetResult(context: BundlerContext, result: BundlerResult) {\n if (isEmpty(result.errors)) {\n // In case there are errors files will not be emitted so trying to copy them will fail anyway\n this.copyAssetsToCapsules(context, result);\n }\n\n const componentsResults: ComponentResult[] = result.components.map((component) => {\n const metadata = this.computeComponentMetadata(context, result, component);\n return {\n component,\n metadata,\n errors: result.errors.map((err) => (typeof err === 'string' ? err : err.message)),\n warning: result.warnings,\n startTime: result.startTime,\n endTime: result.endTime,\n };\n });\n\n return componentsResults;\n }\n\n private getArtifactDef() {\n // eslint-disable-next-line @typescript-eslint/prefer-as-const\n // const env: 'env' = 'env';\n // const rootDir = this.getDirName(context);\n\n return [\n {\n name: COMPONENT_STRATEGY_ARTIFACT_NAME,\n globPatterns: ['**'],\n rootDir: this.getArtifactDirectory(),\n // context: env,\n },\n ];\n }\n\n getDirName(context: ComputeTargetsContext) {\n const envName = context.id.replace('/', '__');\n return `${envName}-preview`;\n }\n\n private getOutputPath(context: ComputeTargetsContext) {\n return resolve(`${context.capsuleNetwork.capsulesRootDir}/${this.getDirName(context)}`);\n }\n\n private getPaths(context: ComputeTargetsContext, component: Component, files: AbstractVinyl[]) {\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n if (!capsule) return [];\n const compiler: Compiler = context.env.getCompiler();\n return files.map((file) => join(capsule.path, compiler.getDistPathBySrcPath(file.relative)));\n }\n\n private getComponentOutputPath(capsule: Capsule) {\n return resolve(`${capsule.path}`);\n }\n\n private async computePaths(\n defs: PreviewDefinition[],\n context: ComputeTargetsContext,\n component: Component\n ): Promise<string> {\n // const previewMain = await this.preview.writePreviewRuntime(context);\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n // if (!capsule) return undefined;\n if (!capsule)\n throw new BitError(\n `could not find capsule for component ${component.id.toString()} during compute paths to bundle`\n );\n const moduleMapsPromise = defs.map(async (previewDef) => {\n const moduleMap = await previewDef.getModuleMap([component]);\n const metadata = previewDef.getMetadata ? await previewDef.getMetadata(component) : undefined;\n const maybeFiles = moduleMap.get(component);\n if (!maybeFiles || !capsule) return { prefix: previewDef.prefix, paths: [] };\n\n const [, files] = maybeFiles;\n const compiledPaths = this.getPaths(context, component, files);\n\n return {\n prefix: previewDef.prefix,\n paths: compiledPaths,\n metadata,\n };\n });\n\n const moduleMaps = await Promise.all(moduleMapsPromise);\n\n const contents = generateComponentLink(moduleMaps);\n return this.preview.writeLinkContents(contents, this.getComponentOutputPath(capsule), 'preview');\n // return flatten(moduleMaps);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA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CAACG,WAAX,GAAyB,MAAMH,UAAU,CAACG,WAAX,CAAuBpI,SAAvB,CAA/B,GAAmEmC,SAApF;MACA,MAAMkG,UAAU,GAAGH,SAAS,CAACI,GAAV,CAActI,SAAd,CAAnB;MACA,IAAI,CAACqI,UAAD,IAAe,CAACtI,OAApB,EAA6B,OAAO;QAAEwI,MAAM,EAAEN,UAAU,CAACM,MAArB;QAA6BC,KAAK,EAAE;MAApC,CAAP;MAE7B,MAAM,GAAG7E,KAAH,IAAY0E,UAAlB;MACA,MAAMI,aAAa,GAAG,KAAK7G,QAAL,CAAcvC,OAAd,EAAuBW,SAAvB,EAAkC2D,KAAlC,CAAtB;MAEA,OAAO;QACL4E,MAAM,EAAEN,UAAU,CAACM,MADd;QAELC,KAAK,EAAEC,aAFF;QAGL1C;MAHK,CAAP;IAKD,CAdyB,CAA1B;IAgBA,MAAM2C,UAAU,GAAG,MAAMxI,OAAO,CAACC,GAAR,CAAY6H,iBAAZ,CAAzB;IAEA,MAAMW,QAAQ,GAAG,IAAAC,8CAAA,EAAsBF,UAAtB,CAAjB;IACA,OAAO,KAAKzJ,OAAL,CAAa4J,iBAAb,CAA+BF,QAA/B,EAAyC,KAAKd,sBAAL,CAA4B9H,OAA5B,CAAzC,EAA+E,SAA/E,CAAP,CA3BiB,CA4BjB;EACD;;AA/VgE"}
1
+ {"version":3,"names":["PREVIEW_CHUNK_SUFFIX","COMPONENT_CHUNK_SUFFIX","PREVIEW_CHUNK_FILENAME_SUFFIX","COMPONENT_CHUNK_FILENAME_SUFFIX","COMPONENT_STRATEGY_SIZE_KEY_NAME","COMPONENT_STRATEGY_ARTIFACT_NAME","ComponentBundlingStrategy","constructor","preview","pkg","dependencyResolver","computeTargets","context","previewDefs","outputPath","getOutputPath","existsSync","mkdirpSync","origComponents","capsuleNetwork","originalSeedersCapsules","map","capsule","component","entriesArr","Promise","all","computeComponentEntry","chunkSize","config","maxChunkSize","chunks","chunk","peers","getPeerDependenciesListFromEnv","env","targets","currentChunk","entries","components","forEach","entry","Object","assign","push","hostDependencies","aliasHostDependencies","externalizeHostDependencies","componentPreviewPath","computePaths","componentPath","getPaths","mainFile","componentPreview","getComponentChunkId","id","splitComponentBundle","toStringWithoutVersion","undefined","filename","getComponentChunkFileName","toString","fsCompatible","ignoreVersion","import","dependOn","library","name","type","componentId","idstr","suffix","getAssetAbsolutePath","asset","path","join","getAssetFilename","split","copyAssetsToCapsules","result","graphCapsules","getCapsule","files","findAssetsForComponent","assets","entriesAssetsMap","artifactDirFullPath","getArtifactDirectory","filePath","PreviewOutputFileNotFound","destFilePath","dirname","fs","copyFileSync","componentEntryId","componentPreviewEntryId","componentFiles","componentAuxiliaryFiles","auxiliaryAssets","componentPreviewFiles","componentPreviewAuxiliaryFiles","concat","CAPSULE_ARTIFACTS_DIR","computeComponentMetadata","file","basename","size","compressedSize","filesTotalSize","assetsSize","compressedTotalFiles","compressedAssetsSize","assetsTotalSize","auxiliaryAssetsSize","compressedTotalAssets","compressedAuxiliaryAssetsSize","totalSize","compressedTotal","metadata","totalFiles","totalAssets","total","computeResults","results","componentsResults","flatten","computeTargetResult","artifacts","getArtifactDef","isEmpty","errors","err","message","warning","warnings","startTime","endTime","globPatterns","rootDir","getDirName","envName","replace","resolve","capsulesRootDir","compiler","getCompiler","getDistPathBySrcPath","relative","getComponentOutputPath","defs","BitError","moduleMapsPromise","previewDef","moduleMap","getModuleMap","getMetadata","maybeFiles","get","prefix","paths","compiledPaths","moduleMaps","contents","generateComponentLink","writeLinkContents"],"sources":["component-strategy.ts"],"sourcesContent":["import { join, resolve, basename, dirname } from 'path';\nimport { existsSync, mkdirpSync } from 'fs-extra';\nimport { Component } from '@teambit/component';\nimport { ComponentID } from '@teambit/component-id';\nimport { flatten, isEmpty, chunk } from 'lodash';\nimport { Compiler } from '@teambit/compiler';\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport type { Capsule } from '@teambit/isolator';\nimport { CAPSULE_ARTIFACTS_DIR, ComponentResult } from '@teambit/builder';\nimport type { PkgMain } from '@teambit/pkg';\nimport { BitError } from '@teambit/bit-error';\nimport type { DependencyResolverMain } from '@teambit/dependency-resolver';\nimport type { BundlerResult, BundlerContext, Asset, BundlerEntryMap, EntriesAssetsMap, Target } from '@teambit/bundler';\nimport { BundlingStrategy, ComputeTargetsContext } from '../bundling-strategy';\nimport type { PreviewDefinition } from '../preview-definition';\nimport type { ComponentPreviewMetaData, PreviewMain } from '../preview.main.runtime';\nimport { generateComponentLink } from './generate-component-link';\nimport { PreviewOutputFileNotFound } from '../exceptions';\n\nexport const PREVIEW_CHUNK_SUFFIX = 'preview';\nexport const COMPONENT_CHUNK_SUFFIX = 'component';\nexport const PREVIEW_CHUNK_FILENAME_SUFFIX = `${PREVIEW_CHUNK_SUFFIX}.js`;\nexport const COMPONENT_CHUNK_FILENAME_SUFFIX = `${COMPONENT_CHUNK_SUFFIX}.js`;\n\nexport const COMPONENT_STRATEGY_SIZE_KEY_NAME = 'size';\nexport const COMPONENT_STRATEGY_ARTIFACT_NAME = 'preview-component';\n\ntype ComponentEntry = {\n component: Component;\n entries: Object;\n};\n/**\n * bundles all components in a given env into the same bundle.\n */\nexport class ComponentBundlingStrategy implements BundlingStrategy {\n name = 'component';\n\n constructor(private preview: PreviewMain, private pkg: PkgMain, private dependencyResolver: DependencyResolverMain) {}\n\n async computeTargets(context: ComputeTargetsContext, previewDefs: PreviewDefinition[]): Promise<Target[]> {\n const outputPath = this.getOutputPath(context);\n if (!existsSync(outputPath)) mkdirpSync(outputPath);\n\n // const entriesArr = flatten(\n // await Promise.all(\n // context.capsuleNetwork.seedersCapsules.map((capsule) => {\n // return this.computeComponentEntry(previewDefs, capsule.component, context);\n // }, {})\n // )\n // );\n\n const origComponents = context.capsuleNetwork.originalSeedersCapsules.map((capsule) => capsule.component);\n\n const entriesArr = await Promise.all(\n origComponents.map((component) => {\n return this.computeComponentEntry(previewDefs, component, context);\n }, {})\n );\n\n const chunkSize = this.preview.config.maxChunkSize;\n\n const chunks = chunkSize ? chunk(entriesArr, chunkSize) : [entriesArr];\n\n const peers = await this.dependencyResolver.getPeerDependenciesListFromEnv(context.env);\n\n const targets = chunks.map((currentChunk) => {\n const entries: BundlerEntryMap = {};\n const components: Component[] = [];\n currentChunk.forEach((entry) => {\n Object.assign(entries, entry.entries);\n components.push(entry.component);\n });\n\n return {\n entries,\n components,\n outputPath,\n /* It's a path to the root of the host component. */\n // hostRootDir, handle this\n hostDependencies: peers,\n aliasHostDependencies: true,\n externalizeHostDependencies: true,\n };\n });\n\n return targets;\n // const entries = entriesArr.reduce((entriesMap, entry) => {\n // entriesMap[entry.library.name] = entry;\n // return entriesMap;\n // }, {});\n\n // const modules = await Promise.all(entriesArr.map(async (entry) => {\n // const dependencies = await this.dependencyResolver.getDependencies(entry.component);\n // const manifest = dependencies.toDependenciesManifest();\n // const peer = Object.entries(manifest.peerDependencies || {}).reduce((acc, [packageName, version]) => {\n // acc[packageName] = {\n // singleton: true,\n // requiredVersion: version\n // };\n\n // return acc;\n // }, {});\n // // console.log(entry);\n // return {\n // name: entry.library.name,\n // exposes: {\n // '.': entry.import || ''\n // },\n // shared: {\n // ...manifest.dependencies,\n // ...peer\n // },\n // };\n // }));\n }\n\n async computeComponentEntry(\n previewDefs: PreviewDefinition[],\n component: Component,\n context: ComputeTargetsContext\n ): Promise<ComponentEntry> {\n const componentPreviewPath = await this.computePaths(previewDefs, context, component);\n const [componentPath] = this.getPaths(context, component, [component.mainFile]);\n\n const chunks = {\n componentPreview: this.getComponentChunkId(component.id, 'preview'),\n component: context.splitComponentBundle ? component.id.toStringWithoutVersion() : undefined,\n };\n\n const entries = {\n [chunks.componentPreview]: {\n filename: this.getComponentChunkFileName(\n component.id.toString({\n fsCompatible: true,\n ignoreVersion: true,\n }),\n 'preview'\n ),\n import: componentPreviewPath,\n dependOn: chunks.component,\n library: { name: chunks.componentPreview, type: 'umd' },\n },\n };\n\n if (chunks.component) {\n entries[chunks.component] = {\n filename: this.getComponentChunkFileName(\n component.id.toString({\n fsCompatible: true,\n ignoreVersion: true,\n }),\n 'component'\n ),\n dependOn: undefined,\n import: componentPath,\n library: { name: chunks.component, type: 'umd' },\n };\n }\n\n return { component, entries };\n }\n\n private getComponentChunkId(componentId: ComponentID, type: 'component' | 'preview') {\n const id =\n type === 'component'\n ? componentId.toStringWithoutVersion()\n : `${componentId.toStringWithoutVersion()}-${PREVIEW_CHUNK_SUFFIX}`;\n return id;\n }\n\n private getComponentChunkFileName(idstr: string, type: 'component' | 'preview') {\n const suffix = type === 'component' ? COMPONENT_CHUNK_FILENAME_SUFFIX : PREVIEW_CHUNK_FILENAME_SUFFIX;\n return `${idstr}-${suffix}`;\n }\n\n private getAssetAbsolutePath(context: BundlerContext, asset: Asset): string {\n const path = this.getOutputPath(context);\n return join(path, 'public', this.getAssetFilename(asset));\n }\n\n private getAssetFilename(asset: Asset): string {\n // handle cases where the asset name is something like my-image.svg?hash (while the filename in the fs is just my-image.svg)\n const [name] = asset.name.split('?');\n return name;\n }\n\n copyAssetsToCapsules(context: BundlerContext, result: BundlerResult) {\n context.components.forEach((component) => {\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n if (!capsule) return;\n const files = this.findAssetsForComponent(component, result.assets, result.entriesAssetsMap || {});\n if (!files) return;\n const artifactDirFullPath = join(capsule.path, this.getArtifactDirectory());\n // We don't use the mkdirSync as it uses the capsule fs which uses memfs, which doesn't know to handle nested none existing folders\n mkdirpSync(artifactDirFullPath);\n\n files.forEach((asset) => {\n const filePath = this.getAssetAbsolutePath(context, asset);\n if (!existsSync(filePath)) {\n throw new PreviewOutputFileNotFound(component.id, filePath);\n }\n const destFilePath = join(artifactDirFullPath, this.getAssetFilename(asset));\n mkdirpSync(dirname(destFilePath));\n capsule.fs.copyFileSync(filePath, destFilePath);\n });\n });\n }\n\n // private getCssFileName(componentId: ComponentID): string {\n // return `${componentId.toString({ ignoreVersion: true, fsCompatible: true })}.css`;\n // }\n\n private findAssetsForComponent(\n component: Component,\n assets: Asset[],\n entriesAssetsMap: EntriesAssetsMap\n ): Asset[] | undefined {\n if (!assets) return undefined;\n\n const componentEntryId = component.id.toStringWithoutVersion();\n const componentPreviewEntryId = this.getComponentChunkId(component.id, 'preview');\n const componentFiles = entriesAssetsMap[componentEntryId]?.assets || [];\n const componentAuxiliaryFiles = entriesAssetsMap[componentEntryId]?.auxiliaryAssets || [];\n const componentPreviewFiles = entriesAssetsMap[componentPreviewEntryId]?.assets || [];\n const componentPreviewAuxiliaryFiles = entriesAssetsMap[componentPreviewEntryId]?.auxiliaryAssets || [];\n\n const files = componentFiles\n .concat(componentAuxiliaryFiles)\n .concat(componentPreviewFiles)\n .concat(componentPreviewAuxiliaryFiles);\n return files;\n }\n\n private getArtifactDirectory() {\n return join(CAPSULE_ARTIFACTS_DIR, 'preview');\n }\n\n private computeComponentMetadata(\n context: BundlerContext,\n result: BundlerResult,\n component: Component\n ): ComponentPreviewMetaData {\n const componentEntryId = component.id.toStringWithoutVersion();\n if (!result?.entriesAssetsMap || !result?.entriesAssetsMap[componentEntryId]) {\n return {};\n }\n const files = (result.entriesAssetsMap[componentEntryId]?.assets || []).map((file) => {\n return {\n name: basename(file.name),\n size: file.size,\n compressedSize: file.compressedSize,\n };\n });\n const filesTotalSize = result.entriesAssetsMap[componentEntryId]?.assetsSize || 0;\n const compressedTotalFiles = result.entriesAssetsMap[componentEntryId]?.compressedAssetsSize || 0;\n const assets = (result.entriesAssetsMap[componentEntryId]?.auxiliaryAssets || []).map((file) => {\n return {\n name: basename(file.name),\n size: file.size,\n compressedSize: file.compressedSize,\n };\n });\n const assetsTotalSize = result.entriesAssetsMap[componentEntryId]?.auxiliaryAssetsSize || 0;\n const compressedTotalAssets = result.entriesAssetsMap[componentEntryId]?.compressedAuxiliaryAssetsSize || 0;\n const totalSize = filesTotalSize + assetsTotalSize;\n const compressedTotal = compressedTotalFiles + compressedTotalAssets;\n\n const metadata = {\n [COMPONENT_STRATEGY_SIZE_KEY_NAME]: {\n files,\n assets,\n totalFiles: filesTotalSize,\n totalAssets: assetsTotalSize,\n total: totalSize,\n compressedTotalFiles,\n compressedTotalAssets,\n compressedTotal,\n },\n };\n\n return metadata;\n }\n\n async computeResults(context: BundlerContext, results: BundlerResult[]) {\n const componentsResults = flatten(\n await Promise.all(results.map((result) => this.computeTargetResult(context, result)))\n );\n\n const artifacts = this.getArtifactDef();\n\n return {\n componentsResults,\n artifacts,\n };\n }\n\n async computeTargetResult(context: BundlerContext, result: BundlerResult) {\n if (isEmpty(result.errors)) {\n // In case there are errors files will not be emitted so trying to copy them will fail anyway\n this.copyAssetsToCapsules(context, result);\n }\n\n const componentsResults: ComponentResult[] = result.components.map((component) => {\n const metadata = this.computeComponentMetadata(context, result, component);\n return {\n component,\n metadata,\n errors: result.errors.map((err) => (typeof err === 'string' ? err : err.message)),\n warning: result.warnings,\n startTime: result.startTime,\n endTime: result.endTime,\n };\n });\n\n return componentsResults;\n }\n\n private getArtifactDef() {\n // eslint-disable-next-line @typescript-eslint/prefer-as-const\n // const env: 'env' = 'env';\n // const rootDir = this.getDirName(context);\n\n return [\n {\n name: COMPONENT_STRATEGY_ARTIFACT_NAME,\n globPatterns: ['**'],\n rootDir: this.getArtifactDirectory(),\n // context: env,\n },\n ];\n }\n\n getDirName(context: ComputeTargetsContext) {\n const envName = context.id.replace('/', '__');\n return `${envName}-preview`;\n }\n\n private getOutputPath(context: ComputeTargetsContext) {\n return resolve(`${context.capsuleNetwork.capsulesRootDir}/${this.getDirName(context)}`);\n }\n\n private getPaths(context: ComputeTargetsContext, component: Component, files: AbstractVinyl[]) {\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n if (!capsule) return [];\n const compiler: Compiler = context.env.getCompiler();\n return files.map((file) => join(capsule.path, compiler.getDistPathBySrcPath(file.relative)));\n }\n\n private getComponentOutputPath(capsule: Capsule) {\n return resolve(`${capsule.path}`);\n }\n\n private async computePaths(\n defs: PreviewDefinition[],\n context: ComputeTargetsContext,\n component: Component\n ): Promise<string> {\n // const previewMain = await this.preview.writePreviewRuntime(context);\n const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);\n // if (!capsule) return undefined;\n if (!capsule)\n throw new BitError(\n `could not find capsule for component ${component.id.toString()} during compute paths to bundle`\n );\n const moduleMapsPromise = defs.map(async (previewDef) => {\n const moduleMap = await previewDef.getModuleMap([component]);\n const metadata = previewDef.getMetadata ? await previewDef.getMetadata(component) : undefined;\n const maybeFiles = moduleMap.get(component);\n if (!maybeFiles || !capsule) return { prefix: previewDef.prefix, paths: [] };\n\n const [, files] = maybeFiles;\n const compiledPaths = this.getPaths(context, component, files);\n\n return {\n prefix: previewDef.prefix,\n paths: compiledPaths,\n metadata,\n };\n });\n\n const moduleMaps = await Promise.all(moduleMapsPromise);\n\n const contents = generateComponentLink(moduleMaps);\n return this.preview.writeLinkContents(contents, this.getComponentOutputPath(capsule), 'preview');\n // return flatten(moduleMaps);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAMA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,oBAAoB,GAAG,SAAS;AAAC;AACvC,MAAMC,sBAAsB,GAAG,WAAW;AAAC;AAC3C,MAAMC,6BAA6B,GAAI,GAAEF,oBAAqB,KAAI;AAAC;AACnE,MAAMG,+BAA+B,GAAI,GAAEF,sBAAuB,KAAI;AAAC;AAEvE,MAAMG,gCAAgC,GAAG,MAAM;AAAC;AAChD,MAAMC,gCAAgC,GAAG,mBAAmB;AAAC;AAMpE;AACA;AACA;AACO,MAAMC,yBAAyB,CAA6B;EAGj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D,MAAMW,QAAQ,GAAG,IAAAC,8CAAqB,EAACF,UAAU,CAAC;IAClD,OAAO,IAAI,CAACzJ,OAAO,CAAC4J,iBAAiB,CAACF,QAAQ,EAAE,IAAI,CAACd,sBAAsB,CAAC9H,OAAO,CAAC,EAAE,SAAS,CAAC;IAChG;EACF;AACF;AAAC"}
@@ -1,87 +1,62 @@
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
  require("core-js/modules/es.regexp.exec.js");
10
-
11
7
  require("core-js/modules/es.string.replace.js");
12
-
13
8
  Object.defineProperty(exports, "__esModule", {
14
9
  value: true
15
10
  });
16
11
  exports.EnvBundlingStrategy = exports.ENV_STRATEGY_ARTIFACT_NAME = void 0;
17
-
18
12
  function _defineProperty2() {
19
13
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
-
21
14
  _defineProperty2 = function () {
22
15
  return data;
23
16
  };
24
-
25
17
  return data;
26
18
  }
27
-
28
19
  function _path() {
29
20
  const data = require("path");
30
-
31
21
  _path = function () {
32
22
  return data;
33
23
  };
34
-
35
24
  return data;
36
25
  }
37
-
38
26
  function _fsExtra() {
39
27
  const data = require("fs-extra");
40
-
41
28
  _fsExtra = function () {
42
29
  return data;
43
30
  };
44
-
45
31
  return data;
46
32
  }
47
-
48
33
  function _lodash() {
49
34
  const data = require("lodash");
50
-
51
35
  _lodash = function () {
52
36
  return data;
53
37
  };
54
-
55
38
  return data;
56
39
  }
57
-
58
40
  function _component() {
59
41
  const data = require("@teambit/component");
60
-
61
42
  _component = function () {
62
43
  return data;
63
44
  };
64
-
65
45
  return data;
66
46
  }
67
-
68
47
  function _htmlTemplate() {
69
48
  const data = require("../bundler/html-template");
70
-
71
49
  _htmlTemplate = function () {
72
50
  return data;
73
51
  };
74
-
75
52
  return data;
76
53
  }
77
-
78
54
  const ENV_STRATEGY_ARTIFACT_NAME = 'preview';
55
+
79
56
  /**
80
57
  * bundles all components in a given env into the same bundle.
81
58
  */
82
-
83
59
  exports.ENV_STRATEGY_ARTIFACT_NAME = ENV_STRATEGY_ARTIFACT_NAME;
84
-
85
60
  class EnvBundlingStrategy {
86
61
  constructor(preview, pkg, dependencyResolver) {
87
62
  this.preview = preview;
@@ -89,7 +64,6 @@ class EnvBundlingStrategy {
89
64
  this.dependencyResolver = dependencyResolver;
90
65
  (0, _defineProperty2().default)(this, "name", 'env');
91
66
  }
92
-
93
67
  async computeTargets(context, previewDefs) {
94
68
  const outputPath = this.getOutputPath(context);
95
69
  if (!(0, _fsExtra().existsSync)(outputPath)) (0, _fsExtra().mkdirpSync)(outputPath);
@@ -102,17 +76,14 @@ class EnvBundlingStrategy {
102
76
  html: [htmlConfig],
103
77
  components: context.components,
104
78
  outputPath,
105
-
106
79
  /* It's a path to the root of the host component. */
107
80
  // hostRootDir, handle this
108
81
  hostDependencies: peers,
109
82
  aliasHostDependencies: true
110
83
  }];
111
84
  }
112
-
113
85
  generateHtmlConfig(options) {
114
86
  var _options$dev;
115
-
116
87
  const config = {
117
88
  title: 'Preview',
118
89
  templateContent: (0, _htmlTemplate().html)('Preview'),
@@ -121,7 +92,6 @@ class EnvBundlingStrategy {
121
92
  };
122
93
  return config;
123
94
  }
124
-
125
95
  async computeResults(context, results) {
126
96
  const result = results[0];
127
97
  const componentsResults = result.components.map(component => {
@@ -139,7 +109,6 @@ class EnvBundlingStrategy {
139
109
  artifacts
140
110
  };
141
111
  }
142
-
143
112
  getArtifactDef(context) {
144
113
  // eslint-disable-next-line @typescript-eslint/prefer-as-const
145
114
  const env = 'env';
@@ -151,26 +120,21 @@ class EnvBundlingStrategy {
151
120
  context: env
152
121
  }];
153
122
  }
154
-
155
123
  getDirName(context) {
156
124
  const envName = context.id.replace('/', '__');
157
125
  return `${envName}-preview`;
158
126
  }
159
-
160
127
  getOutputPath(context) {
161
128
  return (0, _path().resolve)(`${context.capsuleNetwork.capsulesRootDir}/${this.getDirName(context)}`);
162
129
  }
163
-
164
130
  getPaths(context, files, capsule) {
165
131
  const compiler = context.env.getCompiler();
166
132
  return files.map(file => (0, _path().join)(capsule.path, compiler.getDistPathBySrcPath(file.relative)));
167
133
  }
168
-
169
134
  async computePaths(outputPath, defs, context) {
170
135
  const previewMain = await this.preview.writePreviewRuntime(context);
171
136
  const moduleMapsPromise = defs.map(async previewDef => {
172
137
  const moduleMap = await previewDef.getModuleMap(context.components);
173
-
174
138
  const paths = _component().ComponentMap.as(context.components, component => {
175
139
  const capsule = context.capsuleNetwork.graphCapsules.getCapsule(component.id);
176
140
  const maybeFiles = moduleMap.get(component);
@@ -179,7 +143,6 @@ class EnvBundlingStrategy {
179
143
  const compiledPaths = this.getPaths(context, files, capsule);
180
144
  return compiledPaths;
181
145
  });
182
-
183
146
  const template = previewDef.renderTemplatePath ? await previewDef.renderTemplatePath(context) : 'undefined';
184
147
  const link = this.preview.writeLink(previewDef.prefix, paths, previewDef.renderTemplatePath ? await previewDef.renderTemplatePath(context) : undefined, outputPath, false);
185
148
  const files = (0, _lodash().flatten)(paths.toArray().map(([, file]) => file)).concat([link]);
@@ -189,9 +152,7 @@ class EnvBundlingStrategy {
189
152
  const moduleMaps = await Promise.all(moduleMapsPromise);
190
153
  return (0, _lodash().flatten)(moduleMaps.concat([previewMain]));
191
154
  }
192
-
193
155
  }
194
-
195
156
  exports.EnvBundlingStrategy = EnvBundlingStrategy;
196
157
 
197
158
  //# sourceMappingURL=env-strategy.js.map