@teambit/isolator 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.
@@ -1,322 +1,225 @@
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
  Object.defineProperty(exports, "__esModule", {
12
8
  value: true
13
9
  });
14
10
  exports.IsolatorMain = void 0;
15
-
16
11
  function _defineProperty2() {
17
12
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
-
19
13
  _defineProperty2 = function () {
20
14
  return data;
21
15
  };
22
-
23
16
  return data;
24
17
  }
25
-
26
18
  function _cli() {
27
19
  const data = require("@teambit/cli");
28
-
29
20
  _cli = function () {
30
21
  return data;
31
22
  };
32
-
33
23
  return data;
34
24
  }
35
-
36
25
  function _semver() {
37
26
  const data = _interopRequireDefault(require("semver"));
38
-
39
27
  _semver = function () {
40
28
  return data;
41
29
  };
42
-
43
30
  return data;
44
31
  }
45
-
46
32
  function _lodash() {
47
33
  const data = require("lodash");
48
-
49
34
  _lodash = function () {
50
35
  return data;
51
36
  };
52
-
53
37
  return data;
54
38
  }
55
-
56
39
  function _aspectLoader() {
57
40
  const data = require("@teambit/aspect-loader");
58
-
59
41
  _aspectLoader = function () {
60
42
  return data;
61
43
  };
62
-
63
44
  return data;
64
45
  }
65
-
66
46
  function _component() {
67
47
  const data = require("@teambit/component");
68
-
69
48
  _component = function () {
70
49
  return data;
71
50
  };
72
-
73
51
  return data;
74
52
  }
75
-
76
53
  function _componentPackageVersion() {
77
54
  const data = require("@teambit/component-package-version");
78
-
79
55
  _componentPackageVersion = function () {
80
56
  return data;
81
57
  };
82
-
83
58
  return data;
84
59
  }
85
-
86
60
  function _graph() {
87
61
  const data = require("@teambit/graph");
88
-
89
62
  _graph = function () {
90
63
  return data;
91
64
  };
92
-
93
65
  return data;
94
66
  }
95
-
96
67
  function _dependencyResolver() {
97
68
  const data = require("@teambit/dependency-resolver");
98
-
99
69
  _dependencyResolver = function () {
100
70
  return data;
101
71
  };
102
-
103
72
  return data;
104
73
  }
105
-
106
74
  function _logger() {
107
75
  const data = require("@teambit/logger");
108
-
109
76
  _logger = function () {
110
77
  return data;
111
78
  };
112
-
113
79
  return data;
114
80
  }
115
-
116
81
  function _bitId() {
117
82
  const data = require("@teambit/legacy/dist/bit-id");
118
-
119
83
  _bitId = function () {
120
84
  return data;
121
85
  };
122
-
123
86
  return data;
124
87
  }
125
-
126
88
  function _globalConfig() {
127
89
  const data = _interopRequireDefault(require("@teambit/global-config"));
128
-
129
90
  _globalConfig = function () {
130
91
  return data;
131
92
  };
132
-
133
93
  return data;
134
94
  }
135
-
136
95
  function _constants() {
137
96
  const data = require("@teambit/legacy/dist/constants");
138
-
139
97
  _constants = function () {
140
98
  return data;
141
99
  };
142
-
143
100
  return data;
144
101
  }
145
-
146
102
  function _packageJsonFile() {
147
103
  const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/package-json-file"));
148
-
149
104
  _packageJsonFile = function () {
150
105
  return data;
151
106
  };
152
-
153
107
  return data;
154
108
  }
155
-
156
109
  function _artifactFiles() {
157
110
  const data = require("@teambit/legacy/dist/consumer/component/sources/artifact-files");
158
-
159
111
  _artifactFiles = function () {
160
112
  return data;
161
113
  };
162
-
163
114
  return data;
164
115
  }
165
-
166
116
  function _path() {
167
117
  const data = require("@teambit/legacy/dist/utils/path");
168
-
169
118
  _path = function () {
170
119
  return data;
171
120
  };
172
-
173
121
  return data;
174
122
  }
175
-
176
123
  function _fsExtra() {
177
124
  const data = _interopRequireDefault(require("fs-extra"));
178
-
179
125
  _fsExtra = function () {
180
126
  return data;
181
127
  };
182
-
183
128
  return data;
184
129
  }
185
-
186
130
  function _objectHash() {
187
131
  const data = _interopRequireDefault(require("object-hash"));
188
-
189
132
  _objectHash = function () {
190
133
  return data;
191
134
  };
192
-
193
135
  return data;
194
136
  }
195
-
196
137
  function _path2() {
197
138
  const data = _interopRequireDefault(require("path"));
198
-
199
139
  _path2 = function () {
200
140
  return data;
201
141
  };
202
-
203
142
  return data;
204
143
  }
205
-
206
144
  function _equals() {
207
145
  const data = _interopRequireDefault(require("ramda/src/equals"));
208
-
209
146
  _equals = function () {
210
147
  return data;
211
148
  };
212
-
213
149
  return data;
214
150
  }
215
-
216
151
  function _dataToPersist() {
217
152
  const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/sources/data-to-persist"));
218
-
219
153
  _dataToPersist = function () {
220
154
  return data;
221
155
  };
222
-
223
156
  return data;
224
157
  }
225
-
226
158
  function _removePath() {
227
159
  const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/sources/remove-path"));
228
-
229
160
  _removePath = function () {
230
161
  return data;
231
162
  };
232
-
233
163
  return data;
234
164
  }
235
-
236
165
  function _packageJsonTransformer() {
237
166
  const data = require("@teambit/legacy/dist/consumer/component/package-json-transformer");
238
-
239
167
  _packageJsonTransformer = function () {
240
168
  return data;
241
169
  };
242
-
243
170
  return data;
244
171
  }
245
-
246
172
  function _componentIdToPackageName() {
247
173
  const data = _interopRequireDefault(require("@teambit/legacy/dist/utils/bit/component-id-to-package-name"));
248
-
249
174
  _componentIdToPackageName = function () {
250
175
  return data;
251
176
  };
252
-
253
177
  return data;
254
178
  }
255
-
256
179
  function _capsule() {
257
180
  const data = require("./capsule");
258
-
259
181
  _capsule = function () {
260
182
  return data;
261
183
  };
262
-
263
184
  return data;
264
185
  }
265
-
266
186
  function _capsuleList() {
267
187
  const data = _interopRequireDefault(require("./capsule-list"));
268
-
269
188
  _capsuleList = function () {
270
189
  return data;
271
190
  };
272
-
273
191
  return data;
274
192
  }
275
-
276
193
  function _isolator() {
277
194
  const data = require("./isolator.aspect");
278
-
279
195
  _isolator = function () {
280
196
  return data;
281
197
  };
282
-
283
198
  return data;
284
199
  }
285
-
286
200
  function _symlinkBitLegacyToCapsules() {
287
201
  const data = require("./symlink-bit-legacy-to-capsules");
288
-
289
202
  _symlinkBitLegacyToCapsules = function () {
290
203
  return data;
291
204
  };
292
-
293
205
  return data;
294
206
  }
295
-
296
207
  function _symlinkDependenciesToCapsules() {
297
208
  const data = require("./symlink-dependencies-to-capsules");
298
-
299
209
  _symlinkDependenciesToCapsules = function () {
300
210
  return data;
301
211
  };
302
-
303
212
  return data;
304
213
  }
305
-
306
214
  function _network() {
307
215
  const data = require("./network");
308
-
309
216
  _network = function () {
310
217
  return data;
311
218
  };
312
-
313
219
  return data;
314
220
  }
315
-
316
221
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
317
-
318
222
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2().default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
319
-
320
223
  const DEFAULT_ISOLATE_INSTALL_OPTIONS = {
321
224
  installPackages: true,
322
225
  dedupe: true,
@@ -324,15 +227,14 @@ const DEFAULT_ISOLATE_INSTALL_OPTIONS = {
324
227
  copyPeerToRuntimeOnComponents: false,
325
228
  copyPeerToRuntimeOnRoot: true
326
229
  };
327
-
328
230
  class IsolatorMain {
329
231
  // cache packages versions of components
232
+
330
233
  static async provider([dependencyResolver, loggerExtension, componentAspect, graphMain, globalConfig, aspectLoader]) {
331
234
  const logger = loggerExtension.createLogger(_isolator().IsolatorAspect.id);
332
235
  const isolator = new IsolatorMain(dependencyResolver, logger, componentAspect, graphMain, globalConfig, aspectLoader);
333
236
  return isolator;
334
237
  }
335
-
336
238
  constructor(dependencyResolver, logger, componentAspect, graph, globalConfig, aspectLoader) {
337
239
  this.dependencyResolver = dependencyResolver;
338
240
  this.logger = logger;
@@ -341,13 +243,12 @@ class IsolatorMain {
341
243
  this.globalConfig = globalConfig;
342
244
  this.aspectLoader = aspectLoader;
343
245
  (0, _defineProperty2().default)(this, "_componentsPackagesVersionCache", {});
344
- } // TODO: the legacy scope used for the component writer, which then decide if it need to write the artifacts and dists
345
- // TODO: we should think of another way to provide it (maybe a new opts) then take the scope internally from the host
346
-
246
+ }
347
247
 
248
+ // TODO: the legacy scope used for the component writer, which then decide if it need to write the artifacts and dists
249
+ // TODO: we should think of another way to provide it (maybe a new opts) then take the scope internally from the host
348
250
  async isolateComponents(seeders, opts = {}, legacyScope) {
349
251
  var _opts$host;
350
-
351
252
  const host = this.componentAspect.getHost();
352
253
  this.logger.debug(`isolateComponents, ${seeders.join(', ')}. opts: ${JSON.stringify(Object.assign({}, opts, {
353
254
  host: (_opts$host = opts.host) === null || _opts$host === void 0 ? void 0 : _opts$host.name
@@ -369,30 +270,28 @@ class IsolatorMain {
369
270
  this.logger.debug(`creating network with base dir: ${opts.baseDir}, rootBaseDir: ${opts.rootBaseDir}. final capsule-dir: ${capsuleDir}. capsuleList: ${capsuleList.length}`);
370
271
  return new (_network().Network)(capsuleList, seedersWithVersions, capsuleDir);
371
272
  }
372
-
373
273
  async createGraph(seeders, opts = {}) {
374
274
  const host = this.componentAspect.getHost();
375
275
  const getGraphOpts = (0, _lodash().pick)(opts, ['host']);
376
276
  const graph = await this.graph.getGraph(seeders, getGraphOpts);
377
277
  const successorsSubgraph = graph.successorsSubgraph(seeders.map(id => id.toString()));
378
- const compsAndDeps = successorsSubgraph.nodes.map(node => node.attr); // do not ignore the version here. a component might be in .bitmap with one version and
278
+ const compsAndDeps = successorsSubgraph.nodes.map(node => node.attr);
279
+ // do not ignore the version here. a component might be in .bitmap with one version and
379
280
  // installed as a package with another version. we don't want them both.
380
-
381
281
  const existingCompsP = compsAndDeps.map(async c => {
382
282
  let existing;
383
-
384
283
  if (opts.includeFromNestedHosts) {
385
284
  existing = await host.hasIdNested(c.id, true);
386
285
  } else {
387
286
  existing = await host.hasId(c.id);
388
287
  }
389
-
390
288
  if (existing) return c;
391
289
  return undefined;
392
290
  });
393
291
  const existingComps = await Promise.all(existingCompsP);
394
292
  return (0, _lodash().compact)(existingComps);
395
293
  }
294
+
396
295
  /**
397
296
  *
398
297
  * @param originalCapsule the capsule that contains the original component
@@ -400,8 +299,6 @@ class IsolatorMain {
400
299
  * @returns a new capsule with the same content of the original capsule but with a new baseDir and all packages
401
300
  * installed in the newBaseDir.
402
301
  */
403
-
404
-
405
302
  async cloneCapsule(originalCapsule, newBaseDir) {
406
303
  const network = await this.isolateComponents([originalCapsule.component.id], {
407
304
  baseDir: newBaseDir
@@ -410,6 +307,7 @@ class IsolatorMain {
410
307
  await _fsExtra().default.copy(originalCapsule.path, clonedCapsule.path);
411
308
  return clonedCapsule;
412
309
  }
310
+
413
311
  /**
414
312
  * Create capsules for the provided components
415
313
  * do not use this outside directly, use isolate components which build the entire network
@@ -417,62 +315,44 @@ class IsolatorMain {
417
315
  * @param opts
418
316
  * @param legacyScope
419
317
  */
420
-
421
-
422
318
  async createCapsules(components, opts, legacyScope) {
423
319
  var _opts$installOptions;
424
-
425
320
  this.logger.debug(`createCapsules, ${components.length} components`);
426
-
427
321
  const installOptions = _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_ISOLATE_INSTALL_OPTIONS), opts.installOptions), {}, {
428
322
  useNesting: this.dependencyResolver.hasRootComponents() && ((_opts$installOptions = opts.installOptions) === null || _opts$installOptions === void 0 ? void 0 : _opts$installOptions.useNesting)
429
323
  });
430
-
431
324
  const config = _objectSpread({
432
325
  installPackages: true
433
326
  }, opts);
434
-
435
327
  const capsulesDir = this.getCapsulesRootDir(opts.baseDir, opts.rootBaseDir);
436
-
437
328
  if (opts.emptyRootDir) {
438
329
  await _fsExtra().default.emptyDir(capsulesDir);
439
330
  }
440
-
441
331
  let capsules = await this.createCapsulesFromComponents(components, capsulesDir, config);
442
-
443
332
  const allCapsuleList = _capsuleList().default.fromArray(capsules);
444
-
445
333
  let capsuleList = allCapsuleList;
446
-
447
334
  if (opts.getExistingAsIs) {
448
335
  return capsuleList;
449
336
  }
450
-
451
337
  if (opts.skipIfExists) {
452
338
  if (!installOptions.useNesting) {
453
339
  const existingCapsules = _capsuleList().default.fromArray(capsuleList.filter(capsule => capsule.fs.existsSync('package.json')));
454
-
455
340
  if (existingCapsules.length === capsuleList.length) return existingCapsules;
456
341
  } else {
457
342
  capsules = capsules.filter(capsule => !capsule.fs.existsSync('package.json'));
458
343
  capsuleList = _capsuleList().default.fromArray(capsules);
459
344
  }
460
345
  }
461
-
462
346
  const capsulesWithPackagesData = await this.getCapsulesPreviousPackageJson(capsules);
463
347
  await this.writeComponentsInCapsules(components, capsuleList, legacyScope);
464
348
  await this.updateWithCurrentPackageJsonData(capsulesWithPackagesData, capsuleList);
465
-
466
349
  if (installOptions.installPackages) {
467
350
  var _opts$cachePackagesOn, _opts$linkingOptions;
468
-
469
351
  const cachePackagesOnCapsulesRoot = (_opts$cachePackagesOn = opts.cachePackagesOnCapsulesRoot) !== null && _opts$cachePackagesOn !== void 0 ? _opts$cachePackagesOn : false;
470
352
  const linkingOptions = (_opts$linkingOptions = opts.linkingOptions) !== null && _opts$linkingOptions !== void 0 ? _opts$linkingOptions : {};
471
-
472
353
  if (installOptions.useNesting) {
473
354
  await Promise.all(capsuleList.map(async capsule => {
474
355
  const newCapsuleList = _capsuleList().default.fromArray([capsule]);
475
-
476
356
  await this.installInCapsules(capsule.path, newCapsuleList, installOptions, cachePackagesOnCapsulesRoot);
477
357
  await this.linkInCapsules(capsulesDir, newCapsuleList, capsulesWithPackagesData, linkingOptions);
478
358
  }));
@@ -484,11 +364,11 @@ class IsolatorMain {
484
364
  await this.installInCapsules(rootDir, capsuleList, installOptions, cachePackagesOnCapsulesRoot);
485
365
  await this.linkInCapsules(capsulesDir, capsuleList, capsulesWithPackagesData, linkingOptions);
486
366
  }
487
- } // rewrite the package-json with the component dependencies in it. the original package.json
367
+ }
368
+
369
+ // rewrite the package-json with the component dependencies in it. the original package.json
488
370
  // that was written before, didn't have these dependencies in order for the package-manager to
489
371
  // be able to install them without crushing when the versions don't exist yet
490
-
491
-
492
372
  capsulesWithPackagesData.forEach(capsuleWithPackageData => {
493
373
  const {
494
374
  currentPackageJson,
@@ -499,12 +379,12 @@ class IsolatorMain {
499
379
  });
500
380
  return allCapsuleList;
501
381
  }
502
-
503
382
  async installInCapsules(capsulesDir, capsuleList, isolateInstallOptions, cachePackagesOnCapsulesRoot) {
504
383
  const installer = this.dependencyResolver.getInstaller({
505
384
  rootDir: capsulesDir,
506
385
  cacheRootDirectory: cachePackagesOnCapsulesRoot ? capsulesDir : undefined
507
- }); // When using isolator we don't want to use the policy defined in the workspace directly,
386
+ });
387
+ // When using isolator we don't want to use the policy defined in the workspace directly,
508
388
  // we only want to instal deps from components and the peer from the workspace
509
389
 
510
390
  const peerOnlyPolicy = this.getWorkspacePeersOnlyPolicy();
@@ -524,7 +404,6 @@ class IsolatorMain {
524
404
  };
525
405
  await installer.install(capsulesDir, peerOnlyPolicy, this.toComponentMap(capsuleList), installOptions, packageManagerInstallOptions);
526
406
  }
527
-
528
407
  async linkInCapsules(capsulesDir, capsuleList, capsulesWithPackagesData, linkingOptions) {
529
408
  const linker = this.dependencyResolver.getLinker({
530
409
  rootDir: capsulesDir,
@@ -536,42 +415,37 @@ class IsolatorMain {
536
415
  legacyLink: false,
537
416
  linkNestedDepsInNM: !this.dependencyResolver.hasRootComponents() && linkingOptions.linkNestedDepsInNM
538
417
  }));
539
-
540
418
  if (!this.dependencyResolver.hasRootComponents()) {
541
419
  await (0, _symlinkDependenciesToCapsules().symlinkOnCapsuleRoot)(capsuleList, this.logger, capsulesDir);
542
420
  await (0, _symlinkDependenciesToCapsules().symlinkDependenciesToCapsules)(capsulesWithModifiedPackageJson, capsuleList, this.logger);
543
421
  } else {
544
422
  const coreAspectIds = this.aspectLoader.getCoreAspectIds();
545
-
546
423
  const coreAspectCapsules = _capsuleList().default.fromArray(capsuleList.filter(capsule => {
547
424
  const [compIdWithoutVersion] = capsule.component.id.toString().split('@');
548
425
  return coreAspectIds.includes(compIdWithoutVersion);
549
426
  }));
550
-
551
427
  await (0, _symlinkDependenciesToCapsules().symlinkOnCapsuleRoot)(coreAspectCapsules, this.logger, capsulesDir);
552
- } // TODO: this is a hack to have access to the bit bin project in order to access core extensions from user extension
428
+ }
429
+ // TODO: this is a hack to have access to the bit bin project in order to access core extensions from user extension
553
430
  // TODO: remove this after exporting core extensions as components
554
-
555
-
556
- await (0, _symlinkBitLegacyToCapsules().symlinkBitLegacyToCapsules)(capsulesWithModifiedPackageJson, this.logger); // await copyBitLegacyToCapsuleRoot(capsulesDir, this.logger);
431
+ await (0, _symlinkBitLegacyToCapsules().symlinkBitLegacyToCapsules)(capsulesWithModifiedPackageJson, this.logger);
432
+ // await copyBitLegacyToCapsuleRoot(capsulesDir, this.logger);
557
433
  }
558
434
 
559
435
  getCapsulesWithModifiedPackageJson(capsulesWithPackagesData) {
560
436
  const capsulesWithModifiedPackageJson = capsulesWithPackagesData.filter(capsuleWithPackageData => {
561
- const packageJsonHasChanged = this.wereDependenciesInPackageJsonChanged(capsuleWithPackageData); // @todo: when a component is tagged, it changes all package-json of its dependents, but it
437
+ const packageJsonHasChanged = this.wereDependenciesInPackageJsonChanged(capsuleWithPackageData);
438
+ // @todo: when a component is tagged, it changes all package-json of its dependents, but it
562
439
  // should not trigger any "npm install" because they dependencies are symlinked by us
563
-
564
440
  return packageJsonHasChanged;
565
441
  }).map(capsuleWithPackageData => capsuleWithPackageData.capsule);
566
442
  return capsulesWithModifiedPackageJson;
567
443
  }
568
-
569
444
  async writeComponentsInCapsules(components, capsuleList, legacyScope) {
570
445
  const modifiedComps = [];
571
446
  const unmodifiedComps = [];
572
447
  await Promise.all(components.map(async component => {
573
448
  const isModified = await component.isModified();
574
-
575
449
  if (!isModified && component.buildStatus === 'succeed') {
576
450
  // the "component.buildStatus" check is important for "bit sign" when on lane to not go to the original scope
577
451
  unmodifiedComps.push(component);
@@ -583,9 +457,7 @@ class IsolatorMain {
583
457
  const legacyModifiedComps = modifiedComps.map(component => component.state._consumer.clone());
584
458
  const legacyComponents = [...legacyUnmodifiedComps, ...legacyModifiedComps];
585
459
  if (legacyScope && unmodifiedComps.length) await (0, _artifactFiles().importMultipleDistsArtifacts)(legacyScope, legacyUnmodifiedComps);
586
-
587
460
  const allIds = _bitId().BitIds.fromArray(legacyComponents.map(c => c.id));
588
-
589
461
  await Promise.all(components.map(async component => {
590
462
  const capsule = capsuleList.getCapsule(component.id);
591
463
  if (!capsule) return;
@@ -596,20 +468,17 @@ class IsolatorMain {
596
468
  });
597
469
  }));
598
470
  }
599
-
600
471
  getWorkspacePeersOnlyPolicy() {
601
472
  const workspacePolicy = this.dependencyResolver.getWorkspacePolicy();
602
473
  const peerOnlyPolicy = workspacePolicy.byLifecycleType('peer');
603
474
  return peerOnlyPolicy;
604
475
  }
605
-
606
476
  toComponentMap(capsuleList) {
607
477
  const tuples = capsuleList.map(capsule => {
608
478
  return [capsule.component, capsule.path];
609
479
  });
610
480
  return _component().ComponentMap.create(tuples);
611
481
  }
612
-
613
482
  async list(workspacePath) {
614
483
  try {
615
484
  const workspaceCapsuleFolder = this.getCapsulesRootDir(workspacePath);
@@ -626,22 +495,18 @@ class IsolatorMain {
626
495
  capsules: []
627
496
  };
628
497
  }
629
-
630
498
  throw e;
631
499
  }
632
500
  }
633
-
634
501
  getCapsulesRootDir(baseDir, rootBaseDir) {
635
502
  const capsulesRootBaseDir = rootBaseDir || this.getRootDirOfAllCapsules();
636
503
  return _path2().default.join(capsulesRootBaseDir, (0, _objectHash().default)(baseDir));
637
504
  }
638
-
639
505
  async deleteCapsules(capsuleBaseDir) {
640
506
  const dirToDelete = capsuleBaseDir ? this.getCapsulesRootDir(capsuleBaseDir) : this.getRootDirOfAllCapsules();
641
507
  await _fsExtra().default.remove(dirToDelete);
642
508
  return dirToDelete;
643
509
  }
644
-
645
510
  async createCapsulesFromComponents(components, baseDir, opts) {
646
511
  this.logger.debug(`createCapsulesFromComponents: ${components.length} components`);
647
512
  const capsules = await Promise.all(components.map(component => {
@@ -649,42 +514,36 @@ class IsolatorMain {
649
514
  }));
650
515
  return capsules;
651
516
  }
652
-
653
517
  getRootDirOfAllCapsules() {
654
518
  return this.globalConfig.getGlobalCapsulesBaseDir();
655
519
  }
656
-
657
520
  wereDependenciesInPackageJsonChanged(capsuleWithPackageData) {
658
521
  const {
659
522
  previousPackageJson,
660
523
  currentPackageJson
661
524
  } = capsuleWithPackageData;
662
- if (!previousPackageJson) return true; // @ts-ignore at this point, currentPackageJson is set
663
-
525
+ if (!previousPackageJson) return true;
526
+ // @ts-ignore at this point, currentPackageJson is set
664
527
  return _constants().DEPENDENCIES_FIELDS.some(field => !(0, _equals().default)(previousPackageJson[field], currentPackageJson[field]));
665
528
  }
666
-
667
529
  async getCapsulesPreviousPackageJson(capsules) {
668
530
  return Promise.all(capsules.map(async capsule => {
669
531
  const packageJsonPath = _path2().default.join(capsule.path, 'package.json');
670
-
671
532
  let previousPackageJson = null;
672
-
673
533
  try {
674
534
  const previousPackageJsonRaw = await capsule.fs.promises.readFile(packageJsonPath, {
675
535
  encoding: 'utf8'
676
536
  });
677
537
  previousPackageJson = JSON.parse(previousPackageJsonRaw);
678
- } catch (e) {// package-json doesn't exist in the capsule, that's fine, it'll be considered as a cache miss
538
+ } catch (e) {
539
+ // package-json doesn't exist in the capsule, that's fine, it'll be considered as a cache miss
679
540
  }
680
-
681
541
  return {
682
542
  capsule,
683
543
  previousPackageJson
684
544
  };
685
545
  }));
686
546
  }
687
-
688
547
  async updateWithCurrentPackageJsonData(capsulesWithPackagesData, capsules) {
689
548
  return Promise.all(capsules.map(async capsule => {
690
549
  const packageJson = await this.getCurrentPackageJson(capsule, capsules);
@@ -694,11 +553,9 @@ class IsolatorMain {
694
553
  found[0].currentPackageJson = packageJson.packageJsonObject;
695
554
  }));
696
555
  }
697
-
698
556
  async getCurrentPackageJson(capsule, capsules) {
699
557
  const component = capsule.component;
700
558
  const currentVersion = (0, _componentPackageVersion().getComponentPackageVersion)(component);
701
-
702
559
  const getComponentDepsManifest = async dependencies => {
703
560
  const manifest = {
704
561
  dependencies: {},
@@ -708,17 +565,13 @@ class IsolatorMain {
708
565
  const promises = compDeps.map(async dep => {
709
566
  const depCapsule = capsules.getCapsule(dep.componentId);
710
567
  let version = dep.version;
711
-
712
568
  if (depCapsule) {
713
569
  version = (0, _componentPackageVersion().getComponentPackageVersion)(depCapsule === null || depCapsule === void 0 ? void 0 : depCapsule.component);
714
570
  } else {
715
571
  version = (0, _componentPackageVersion().snapToSemver)(version);
716
572
  }
717
-
718
573
  const keyName = _dependencyResolver().KEY_NAME_BY_LIFECYCLE_TYPE[dep.lifecycle];
719
-
720
574
  const entry = dep.toManifest();
721
-
722
575
  if (entry) {
723
576
  manifest[keyName][entry.packageName] = version;
724
577
  }
@@ -726,24 +579,21 @@ class IsolatorMain {
726
579
  await Promise.all(promises);
727
580
  return manifest;
728
581
  };
729
-
730
582
  const deps = await this.dependencyResolver.getDependencies(component);
731
- const manifest = await getComponentDepsManifest(deps); // component.packageJsonFile is not available here. we don't mutate the component object for capsules.
583
+ const manifest = await getComponentDepsManifest(deps);
584
+
585
+ // component.packageJsonFile is not available here. we don't mutate the component object for capsules.
732
586
  // also, don't use `PackageJsonFile.createFromComponent`, as it looses the intermediate changes
733
587
  // such as postInstall scripts for custom-module-resolution.
734
-
735
588
  const packageJson = _packageJsonFile().default.loadFromCapsuleSync(capsule.path);
736
-
737
589
  const addDependencies = packageJsonFile => {
738
590
  packageJsonFile.addDependencies(manifest.dependencies);
739
591
  packageJsonFile.addDevDependencies(manifest.devDependencies);
740
592
  };
741
-
742
593
  addDependencies(packageJson);
743
594
  packageJson.addOrUpdateProperty('version', currentVersion);
744
595
  return packageJson;
745
596
  }
746
-
747
597
  async populateComponentsFilesToWriteForCapsule(component, ids, legacyScope) {
748
598
  const legacyComp = component.state._consumer;
749
599
  const dataToPersist = new (_dataToPersist().default)();
@@ -761,7 +611,6 @@ class IsolatorMain {
761
611
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
762
612
  packageJson.addOrUpdateProperty('version', _semver().default.inc(legacyComp.version, 'prerelease') || '0.0.1-0');
763
613
  }
764
-
765
614
  await _packageJsonTransformer().PackageJsonTransformer.applyTransformers(legacyComp, packageJson);
766
615
  const valuesToMerge = legacyComp.overrides.componentOverridesPackageJsonData;
767
616
  packageJson.mergePackageJsonObject(valuesToMerge);
@@ -770,11 +619,9 @@ class IsolatorMain {
770
619
  dataToPersist.addManyFiles(artifacts);
771
620
  return dataToPersist;
772
621
  }
773
-
774
622
  preparePackageJsonToWrite(component, bitDir, ignoreBitDependencies = true) {
775
623
  const legacyComp = component.state._consumer;
776
624
  this.logger.debug(`package-json.preparePackageJsonToWrite. bitDir ${bitDir}.`);
777
-
778
625
  const getBitDependencies = dependencies => {
779
626
  if (ignoreBitDependencies === true) return {};
780
627
  return dependencies.reduce((acc, depId) => {
@@ -788,78 +635,63 @@ class IsolatorMain {
788
635
  return acc;
789
636
  }, {});
790
637
  };
791
-
792
638
  const bitDependencies = getBitDependencies(legacyComp.dependencies.getAllIds());
793
639
  const bitDevDependencies = getBitDependencies(legacyComp.devDependencies.getAllIds());
794
640
  const bitExtensionDependencies = getBitDependencies(legacyComp.extensions.extensionsBitIds);
795
-
796
641
  const packageJson = _packageJsonFile().default.createFromComponent(bitDir, legacyComp, true);
797
-
798
642
  const main = (0, _path().pathNormalizeToLinux)(legacyComp.mainFile);
799
643
  packageJson.addOrUpdateProperty('main', main);
800
-
801
644
  const addDependencies = packageJsonFile => {
802
645
  packageJsonFile.addDependencies(bitDependencies);
803
646
  packageJsonFile.addDevDependencies(_objectSpread(_objectSpread({}, bitDevDependencies), bitExtensionDependencies));
804
647
  };
805
-
806
648
  addDependencies(packageJson);
807
649
  const currentVersion = (0, _componentPackageVersion().getComponentPackageVersion)(component);
808
650
  packageJson.addOrUpdateProperty('version', currentVersion);
809
651
  return packageJson;
810
652
  }
653
+
811
654
  /**
812
655
  * currently, it writes all artifacts.
813
656
  * later, this responsibility might move to pkg extension, which could write only artifacts
814
657
  * that are set in package.json.files[], to have a similar structure of a package.
815
658
  */
816
-
817
-
818
659
  async getArtifacts(component, legacyScope) {
819
660
  if (!legacyScope) {
820
661
  // when capsules are written via the workspace, do not write artifacts, they get created by
821
662
  // build-pipeline. when capsules are written via the scope, we do need the dists.
822
663
  return [];
823
664
  }
824
-
825
665
  if (component.buildStatus !== 'succeed') {
826
666
  // this is important for "bit sign" when on lane to not go to the original scope
827
667
  return [];
828
668
  }
829
-
830
669
  const extensionsNamesForArtifacts = ['teambit.compilation/compiler'];
831
670
  const artifactsFiles = (0, _lodash().flatten)(extensionsNamesForArtifacts.map(extName => (0, _artifactFiles().getArtifactFilesByExtension)(component.extensions, extName)));
832
671
  const artifactsVinylFlattened = [];
833
672
  await Promise.all(artifactsFiles.map(async artifactFiles => {
834
673
  if (!artifactFiles) return;
835
-
836
674
  if (!(artifactFiles instanceof _artifactFiles().ArtifactFiles)) {
837
675
  artifactFiles = (0, _artifactFiles().deserializeArtifactFiles)(artifactFiles);
838
- } // fyi, if this is coming from the isolator aspect, it is optimized to import all at once.
676
+ }
677
+ // fyi, if this is coming from the isolator aspect, it is optimized to import all at once.
839
678
  // see artifact-files.importMultipleDistsArtifacts().
840
-
841
-
842
679
  const vinylFiles = await artifactFiles.getVinylsAndImportIfMissing(component.id, legacyScope);
843
680
  artifactsVinylFlattened.push(...vinylFiles);
844
681
  }));
845
682
  const artifactsDir = component.writtenPath;
846
-
847
683
  if (artifactsDir) {
848
684
  artifactsVinylFlattened.forEach(a => a.updatePaths({
849
685
  newBase: artifactsDir
850
686
  }));
851
687
  }
852
-
853
688
  return artifactsVinylFlattened;
854
689
  }
855
-
856
690
  }
857
-
858
691
  exports.IsolatorMain = IsolatorMain;
859
692
  (0, _defineProperty2().default)(IsolatorMain, "runtime", _cli().MainRuntime);
860
693
  (0, _defineProperty2().default)(IsolatorMain, "dependencies", [_dependencyResolver().DependencyResolverAspect, _logger().LoggerAspect, _component().ComponentAspect, _graph().GraphAspect, _globalConfig().default, _aspectLoader().AspectLoaderAspect]);
861
694
  (0, _defineProperty2().default)(IsolatorMain, "defaultConfig", {});
862
-
863
695
  _isolator().IsolatorAspect.addRuntime(IsolatorMain);
864
696
 
865
697
  //# sourceMappingURL=isolator.main.runtime.js.map