@teambit/bit 0.0.883 → 0.0.884

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/load-bit.js CHANGED
@@ -1,324 +1,227 @@
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.loadBit = loadBit;
13
10
  exports.requireAspects = requireAspects;
14
11
  exports.runCLI = runCLI;
15
-
16
12
  function _toolboxPerformance() {
17
13
  const data = require("@teambit/toolbox.performance.v8-cache");
18
-
19
14
  _toolboxPerformance = function () {
20
15
  return data;
21
16
  };
22
-
23
17
  return data;
24
18
  }
25
-
26
19
  require("reflect-metadata");
27
-
28
20
  require("./hook-require");
29
-
30
21
  function _aspectLoader() {
31
22
  const data = require("@teambit/aspect-loader");
32
-
33
23
  _aspectLoader = function () {
34
24
  return data;
35
25
  };
36
-
37
26
  return data;
38
27
  }
39
-
40
28
  function _commentJson() {
41
29
  const data = _interopRequireDefault(require("comment-json"));
42
-
43
30
  _commentJson = function () {
44
31
  return data;
45
32
  };
46
-
47
33
  return data;
48
34
  }
49
-
50
35
  function _cli() {
51
36
  const data = require("@teambit/cli");
52
-
53
37
  _cli = function () {
54
38
  return data;
55
39
  };
56
-
57
40
  return data;
58
41
  }
59
-
60
42
  function _config() {
61
43
  const data = require("@teambit/config");
62
-
63
44
  _config = function () {
64
45
  return data;
65
46
  };
66
-
67
47
  return data;
68
48
  }
69
-
70
49
  function _harmony() {
71
50
  const data = require("@teambit/harmony");
72
-
73
51
  _harmony = function () {
74
52
  return data;
75
53
  };
76
-
77
54
  return data;
78
55
  }
79
-
80
56
  function _harmonyConfig() {
81
57
  const data = require("@teambit/harmony/dist/harmony-config");
82
-
83
58
  _harmonyConfig = function () {
84
59
  return data;
85
60
  };
86
-
87
61
  return data;
88
62
  }
89
-
90
63
  function _legacyBitId() {
91
64
  const data = require("@teambit/legacy-bit-id");
92
-
93
65
  _legacyBitId = function () {
94
66
  return data;
95
67
  };
96
-
97
68
  return data;
98
69
  }
99
-
100
70
  function _dependencyResolver() {
101
71
  const data = require("@teambit/legacy/dist/consumer/component/dependencies/dependency-resolver");
102
-
103
72
  _dependencyResolver = function () {
104
73
  return data;
105
74
  };
106
-
107
75
  return data;
108
76
  }
109
-
110
77
  function _consumer() {
111
78
  const data = require("@teambit/legacy/dist/consumer");
112
-
113
79
  _consumer = function () {
114
80
  return data;
115
81
  };
116
-
117
82
  return data;
118
83
  }
119
-
120
84
  function _bitMap() {
121
85
  const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/bit-map"));
122
-
123
86
  _bitMap = function () {
124
87
  return data;
125
88
  };
126
-
127
89
  return data;
128
90
  }
129
-
130
91
  function _componentLoader() {
131
92
  const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/component-loader"));
132
-
133
93
  _componentLoader = function () {
134
94
  return data;
135
95
  };
136
-
137
96
  return data;
138
97
  }
139
-
140
98
  function _componentConfig() {
141
99
  const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/config/component-config"));
142
-
143
100
  _componentConfig = function () {
144
101
  return data;
145
102
  };
146
-
147
103
  return data;
148
104
  }
149
-
150
105
  function _componentOverrides() {
151
106
  const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/config/component-overrides"));
152
-
153
107
  _componentOverrides = function () {
154
108
  return data;
155
109
  };
156
-
157
110
  return data;
158
111
  }
159
-
160
112
  function _packageJsonTransformer() {
161
113
  const data = require("@teambit/legacy/dist/consumer/component/package-json-transformer");
162
-
163
114
  _packageJsonTransformer = function () {
164
115
  return data;
165
116
  };
166
-
167
117
  return data;
168
118
  }
169
-
170
119
  function _semver() {
171
120
  const data = require("semver");
172
-
173
121
  _semver = function () {
174
122
  return data;
175
123
  };
176
-
177
124
  return data;
178
125
  }
179
-
180
126
  function _manyComponentsWriter() {
181
127
  const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component-ops/many-components-writer"));
182
-
183
128
  _manyComponentsWriter = function () {
184
129
  return data;
185
130
  };
186
-
187
131
  return data;
188
132
  }
189
-
190
133
  function _bootstrap() {
191
134
  const data = require("@teambit/legacy/dist/bootstrap");
192
-
193
135
  _bootstrap = function () {
194
136
  return data;
195
137
  };
196
-
197
138
  return data;
198
139
  }
199
-
200
140
  function _config2() {
201
141
  const data = require("@teambit/legacy/dist/consumer/config");
202
-
203
142
  _config2 = function () {
204
143
  return data;
205
144
  };
206
-
207
145
  return data;
208
146
  }
209
-
210
147
  function _workspaceConfig() {
211
148
  const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/config/workspace-config"));
212
-
213
149
  _workspaceConfig = function () {
214
150
  return data;
215
151
  };
216
-
217
152
  return data;
218
153
  }
219
-
220
154
  function _bitId() {
221
155
  const data = require("@teambit/legacy/dist/bit-id");
222
-
223
156
  _bitId = function () {
224
157
  return data;
225
158
  };
226
-
227
159
  return data;
228
160
  }
229
-
230
161
  function _utils() {
231
162
  const data = require("@teambit/legacy/dist/utils");
232
-
233
163
  _utils = function () {
234
164
  return data;
235
165
  };
236
-
237
166
  return data;
238
167
  }
239
-
240
168
  function _logger() {
241
169
  const data = _interopRequireDefault(require("@teambit/legacy/dist/logger/logger"));
242
-
243
170
  _logger = function () {
244
171
  return data;
245
172
  };
246
-
247
173
  return data;
248
174
  }
249
-
250
175
  function _action() {
251
176
  const data = require("@teambit/legacy/dist/api/scope/lib/action");
252
-
253
177
  _action = function () {
254
178
  return data;
255
179
  };
256
-
257
180
  return data;
258
181
  }
259
-
260
182
  function _loader() {
261
183
  const data = _interopRequireDefault(require("@teambit/legacy/dist/cli/loader"));
262
-
263
184
  _loader = function () {
264
185
  return data;
265
186
  };
266
-
267
187
  return data;
268
188
  }
269
-
270
189
  function _fsExtra() {
271
190
  const data = require("fs-extra");
272
-
273
191
  _fsExtra = function () {
274
192
  return data;
275
193
  };
276
-
277
194
  return data;
278
195
  }
279
-
280
196
  function _path() {
281
197
  const data = require("path");
282
-
283
198
  _path = function () {
284
199
  return data;
285
200
  };
286
-
287
201
  return data;
288
202
  }
289
-
290
203
  function _manifests() {
291
204
  const data = require("./manifests");
292
-
293
205
  _manifests = function () {
294
206
  return data;
295
207
  };
296
-
297
208
  return data;
298
209
  }
299
-
300
210
  function _bit() {
301
211
  const data = require("./bit.aspect");
302
-
303
212
  _bit = function () {
304
213
  return data;
305
214
  };
306
-
307
215
  return data;
308
216
  }
309
-
310
217
  function _bitMain() {
311
218
  const data = require("./bit.main.runtime");
312
-
313
219
  _bitMain = function () {
314
220
  return data;
315
221
  };
316
-
317
222
  return data;
318
223
  }
319
-
320
224
  /* eslint-disable import/no-dynamic-require */
321
-
322
225
  /* eslint-disable import/first */
323
226
  process.on('uncaughtException', err => {
324
227
  // eslint-disable-next-line no-console
@@ -326,13 +229,14 @@ process.on('uncaughtException', err => {
326
229
  process.exit(1);
327
230
  });
328
231
  // Enable v8 compile cache, keep this before other imports
329
- _toolboxPerformance().nativeCompileCache === null || _toolboxPerformance().nativeCompileCache === void 0 ? void 0 : _toolboxPerformance().nativeCompileCache.install(); // needed for class-transformer package
232
+ _toolboxPerformance().nativeCompileCache === null || _toolboxPerformance().nativeCompileCache === void 0 ? void 0 : _toolboxPerformance().nativeCompileCache.install();
233
+
234
+ // needed for class-transformer package
330
235
 
331
236
  async function loadLegacyConfig(config) {
332
237
  const harmony = await _harmony().Harmony.load([_config().ConfigAspect], _config().ConfigRuntime.name, config.toObject());
333
238
  await harmony.run(async (aspect, runtime) => requireAspects(aspect, runtime));
334
239
  }
335
-
336
240
  async function getConfig(cwd = process.cwd()) {
337
241
  const consumerInfo = await (0, _consumer().getConsumerInfo)(cwd);
338
242
  const scopePath = (0, _utils().propogateUntil)(cwd);
@@ -344,19 +248,16 @@ async function getConfig(cwd = process.cwd()) {
344
248
  shouldThrow: false,
345
249
  cwd: (consumerInfo === null || consumerInfo === void 0 ? void 0 : consumerInfo.path) || scopePath
346
250
  };
347
-
348
251
  if (consumerInfo) {
349
252
  const config = _harmonyConfig().Config.load('workspace.jsonc', configOpts);
350
-
351
253
  return attachVersionsFromBitmap(config, consumerInfo);
352
254
  }
353
-
354
255
  if (scopePath && !consumerInfo) {
355
256
  return _harmonyConfig().Config.load('scope.jsonc', configOpts);
356
257
  }
357
-
358
258
  return _harmonyConfig().Config.loadGlobal(globalConfigOpts);
359
259
  }
260
+
360
261
  /**
361
262
  * This will attach versions of aspects configured in the config without version by resolves them from the bitmap file
362
263
  * It's required in order to support a usecase which you develop a local aspect and configure it in your workspace.jsonc
@@ -364,99 +265,78 @@ async function getConfig(cwd = process.cwd()) {
364
265
  * but you don't want to change your workspace.jsonc version after each tag of the aspect
365
266
  * @param config
366
267
  */
367
-
368
-
369
268
  function attachVersionsFromBitmap(config, consumerInfo) {
370
269
  if (!consumerInfo || !consumerInfo.hasBitMap) {
371
270
  return config;
372
271
  }
373
-
374
272
  const rawConfig = config.toObject();
375
-
376
273
  const rawBitmap = _bitMap().default.loadRawSync(consumerInfo.path);
377
-
378
274
  let parsedBitMap = {};
379
-
380
275
  try {
381
276
  var _parsedBitMap, _parsedBitMap$_bit_la;
382
-
383
- parsedBitMap = rawBitmap ? _commentJson().default.parse(rawBitmap === null || rawBitmap === void 0 ? void 0 : rawBitmap.toString('utf8'), undefined, true) : {}; // @todo: remove this if statement once we don't need the migration of the bitmap file for lanes
277
+ parsedBitMap = rawBitmap ? _commentJson().default.parse(rawBitmap === null || rawBitmap === void 0 ? void 0 : rawBitmap.toString('utf8'), undefined, true) : {};
278
+ // @todo: remove this if statement once we don't need the migration of the bitmap file for lanes
384
279
  // @ts-ignore
385
-
386
280
  if ((_parsedBitMap = parsedBitMap) !== null && _parsedBitMap !== void 0 && (_parsedBitMap$_bit_la = _parsedBitMap._bit_lane) !== null && _parsedBitMap$_bit_la !== void 0 && _parsedBitMap$_bit_la.name) {
387
281
  // backward compatibility. if "_bit_land" has the old format, then, later, when the bitmap is loaded again,
388
282
  // it'll take care of the migration.
389
283
  parsedBitMap = {};
390
284
  }
391
-
392
- _bitMap().default.removeNonComponentFields(parsedBitMap); // Do nothing here, invalid bitmaps will be handled later
285
+ _bitMap().default.removeNonComponentFields(parsedBitMap);
286
+ // Do nothing here, invalid bitmaps will be handled later
393
287
  // eslint-disable-next-line no-empty
394
-
395
288
  } catch (e) {}
396
-
397
289
  const allBitmapIds = Object.keys(parsedBitMap).map(id => _bitMap().default.getBitIdFromComponentJson(id, parsedBitMap[id]));
398
-
399
290
  const bitMapBitIds = _bitId().BitIds.fromArray(allBitmapIds);
400
-
401
291
  const result = Object.entries(rawConfig).reduce((acc, [aspectId, aspectConfig]) => {
402
- let newAspectEntry = aspectId; // In case the id already has a version we don't want to get it from the bitmap
292
+ let newAspectEntry = aspectId;
293
+ // In case the id already has a version we don't want to get it from the bitmap
403
294
  // We also don't want to add versions for core aspects
404
-
405
295
  if (!aspectId.includes(_legacyBitId().VERSION_DELIMITER) && !_manifests().manifestsMap[aspectId]) {
406
296
  const versionFromBitmap = getVersionFromBitMapIds(bitMapBitIds, aspectId);
407
-
408
297
  if (versionFromBitmap) {
409
298
  newAspectEntry = `${aspectId}${_legacyBitId().VERSION_DELIMITER}${versionFromBitmap}`;
410
299
  }
411
300
  }
412
-
413
301
  acc[newAspectEntry] = aspectConfig;
414
302
  return acc;
415
303
  }, {});
416
304
  return new (_harmonyConfig().Config)(result);
417
305
  }
418
-
419
306
  function getVersionFromBitMapIds(allBitmapIds, aspectId) {
420
307
  let aspectBitId;
421
-
422
308
  try {
423
309
  aspectBitId = _legacyBitId().BitId.parse(aspectId, true);
424
310
  } catch (err) {
425
311
  throw new Error(`unable to parse the component-id "${aspectId}" from the workspace.jsonc file, make sure this is a component id`);
426
- } // start by searching id in the bitmap with exact match (including scope name)
312
+ }
313
+ // start by searching id in the bitmap with exact match (including scope name)
427
314
  // in case the aspect is not exported yet, it will be in the bitmap without a scope,
428
315
  // while in the aspect id it will have the default scope
429
-
430
-
431
316
  const found = allBitmapIds.searchWithoutVersion(aspectBitId) || allBitmapIds.searchWithoutScopeAndVersion(aspectBitId);
432
317
  return found && found.hasVersion() ? found.version : undefined;
433
318
  }
434
-
435
319
  async function requireAspects(aspect, runtime) {
436
320
  const id = aspect.name;
437
321
  if (!id) throw new Error('could not retrieve aspect id');
438
322
  const dirPath = (0, _aspectLoader().getAspectDistDir)(id);
439
323
  const files = await (0, _fsExtra().readdir)(dirPath);
440
324
  const runtimeFile = files.find(file => file.includes(`.${runtime.name}.runtime.js`));
441
- if (!runtimeFile) return; // eslint-disable-next-line
442
-
325
+ if (!runtimeFile) return;
326
+ // eslint-disable-next-line
443
327
  require((0, _path().resolve)(`${dirPath}/${runtimeFile}`));
444
328
  }
445
-
446
329
  function getMainAspect() {
447
330
  const mainAspectDir = (0, _aspectLoader().getAspectDir)(_bit().BitAspect.id);
448
331
  let version;
449
332
  const packageName = (0, _aspectLoader().getCoreAspectPackageName)(_bit().BitAspect.id);
450
-
451
333
  try {
452
334
  // eslint-disable-next-line global-require
453
335
  const packageJson = require(`${mainAspectDir}/package.json`);
454
-
455
336
  version = packageJson.version;
456
337
  } catch (err) {
457
338
  version = undefined;
458
339
  }
459
-
460
340
  return {
461
341
  path: mainAspectDir,
462
342
  version,
@@ -466,6 +346,7 @@ function getMainAspect() {
466
346
  id: _bit().BitAspect.id
467
347
  };
468
348
  }
349
+
469
350
  /**
470
351
  * Bit may crush during the aspect loading phase or workspace/consumer initialization.
471
352
  * normally, this is the desired behavior, however, some commands are there to help overcome these
@@ -475,8 +356,6 @@ function getMainAspect() {
475
356
  * at this stage we don't have the commands objects, so we can't check the command/flags from there
476
357
  * instead, we have to check the `process.argv.` directly instead, which is not 100% accurate.
477
358
  */
478
-
479
-
480
359
  function shouldLoadInSafeMode() {
481
360
  const currentCommand = process.argv[2];
482
361
  const safeModeCommands = ['init', 'cat-scope', 'cat-object', 'cat-component', 'cmp', 'cat-lane', 'login', 'logout', 'config', 'remote'];
@@ -484,14 +363,10 @@ function shouldLoadInSafeMode() {
484
363
  const isSafeModeCommand = safeModeCommands.includes(currentCommand);
485
364
  return isSafeModeCommand || hasSafeModeFlag;
486
365
  }
487
-
488
366
  async function loadBit(path = process.cwd()) {
489
367
  var _BitAspect$id;
490
-
491
368
  clearGlobalsIfNeeded();
492
-
493
369
  _logger().default.info(`*** Loading Bit *** argv:\n${process.argv.join('\n')}`);
494
-
495
370
  const config = await getConfig(path);
496
371
  (0, _bitMain().registerCoreExtensions)();
497
372
  await loadLegacyConfig(config);
@@ -501,97 +376,81 @@ async function loadBit(path = process.cwd()) {
501
376
  verifyEngine(configMap[_bit().BitAspect.id]);
502
377
  const aspectsToLoad = [_cli().CLIAspect];
503
378
  const loadCLIOnly = shouldLoadInSafeMode();
504
-
505
379
  if (!loadCLIOnly) {
506
380
  aspectsToLoad.push(_bit().BitAspect);
507
381
  }
508
-
509
382
  const harmony = await _harmony().Harmony.load(aspectsToLoad, _cli().MainRuntime.name, configMap);
510
383
  await harmony.run(async (aspect, runtime) => requireAspects(aspect, runtime));
511
384
  if (loadCLIOnly) return harmony;
512
-
513
385
  _loader().default.start('loading aspects...');
514
-
515
386
  const aspectLoader = harmony.get('teambit.harmony/aspect-loader');
516
387
  aspectLoader.setCoreAspects(Object.values(_manifests().manifestsMap));
517
388
  aspectLoader.setMainAspect(getMainAspect());
518
389
  registerCoreAspectsToLegacyDepResolver(aspectLoader);
519
390
  return harmony;
520
391
  }
521
-
522
392
  function verifyEngine(bitConfig) {
523
393
  if (!bitConfig.engine) {
524
394
  return;
525
395
  }
526
-
527
396
  const bitVersion = (0, _bootstrap().getHarmonyVersion)(true);
528
-
529
397
  if ((0, _semver().satisfies)(bitVersion, bitConfig.engine)) {
530
398
  return;
531
399
  }
532
-
533
400
  const msg = `your bit version "${bitVersion}" doesn't satisfies the required "${bitConfig.engine}" version`;
534
-
535
401
  if (bitConfig.engineStrict) {
536
402
  throw new Error(`error: ${msg}`);
537
403
  }
538
-
539
404
  _logger().default.console(msg, 'warn', 'yellow');
540
405
  }
541
-
542
406
  async function runCLI() {
543
407
  const harmony = await loadBit();
544
408
  const cli = harmony.get('teambit.harmony/cli');
545
409
  let hasWorkspace = true;
546
-
547
410
  try {
548
411
  harmony.get('teambit.workspace/workspace');
549
412
  } catch (err) {
550
413
  hasWorkspace = false;
551
414
  }
552
-
553
415
  await cli.run(hasWorkspace);
554
416
  }
555
-
556
417
  function registerCoreAspectsToLegacyDepResolver(aspectLoader) {
557
418
  const allCoreAspectsIds = aspectLoader.getCoreAspectIds();
558
419
  const coreAspectsPackagesAndIds = {};
559
420
  allCoreAspectsIds.forEach(id => {
560
421
  const packageName = (0, _aspectLoader().getCoreAspectPackageName)(id);
561
422
  coreAspectsPackagesAndIds[packageName] = id;
562
- }); // @ts-ignore
563
-
423
+ });
424
+ // @ts-ignore
564
425
  _dependencyResolver().DependencyResolver.getCoreAspectsPackagesAndIds = () => coreAspectsPackagesAndIds;
565
426
  }
427
+
566
428
  /**
567
429
  * loadBit may gets called multiple times (currently, it's happening during e2e-tests that call loadBit).
568
430
  * when it happens, the static methods in this function still have the callbacks that were added in
569
431
  * the previous loadBit call. this callbacks have the old data such as workspace/bitmap/consumer
570
432
  * of the previous workspace, which leads to hard-to-debug issues.
571
433
  */
572
-
573
-
574
434
  function clearGlobalsIfNeeded() {
575
435
  if (!_consumer().loadConsumer.cache && !_packageJsonTransformer().PackageJsonTransformer.packageJsonTransformersRegistry.length) {
576
436
  return;
577
437
  }
578
-
579
438
  delete _consumer().loadConsumer.cache;
580
439
  _componentLoader().default.onComponentLoadSubscribers = [];
581
440
  _componentOverrides().default.componentOverridesLoadingRegistry = {};
582
441
  _componentConfig().default.componentConfigLegacyLoadingRegistry = {};
583
442
  _componentConfig().default.componentConfigLoadingRegistry = {};
584
- _packageJsonTransformer().PackageJsonTransformer.packageJsonTransformersRegistry = []; // @ts-ignore
585
-
586
- _dependencyResolver().DependencyResolver.getWorkspacePolicy = undefined; // @ts-ignore
587
-
443
+ _packageJsonTransformer().PackageJsonTransformer.packageJsonTransformersRegistry = [];
444
+ // @ts-ignore
445
+ _dependencyResolver().DependencyResolver.getWorkspacePolicy = undefined;
446
+ // @ts-ignore
588
447
  _manyComponentsWriter().default.externalInstaller = {};
589
- _config2().ExtensionDataList.coreExtensionsNames = new Map(); // @ts-ignore
590
-
591
- _workspaceConfig().default.workspaceConfigEnsuringRegistry = undefined; // @ts-ignore
592
-
593
- _workspaceConfig().default.workspaceConfigIsExistRegistry = undefined; // @ts-ignore
594
-
448
+ _config2().ExtensionDataList.coreExtensionsNames = new Map();
449
+ // @ts-ignore
450
+ _workspaceConfig().default.workspaceConfigEnsuringRegistry = undefined;
451
+ // @ts-ignore
452
+ _workspaceConfig().default.workspaceConfigIsExistRegistry = undefined;
453
+ // @ts-ignore
595
454
  _workspaceConfig().default.workspaceConfigLoadingRegistry = undefined;
596
455
  _action().ExternalActions.externalActions = [];
597
456
  }