@teambit/workspace 0.0.1002 → 0.0.1006
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/aspects-merger.js +2 -14
- package/dist/aspects-merger.js.map +1 -1
- package/dist/{preview-1677741019617.js → preview-1677900877836.js} +2 -2
- package/dist/workspace-aspects-loader.d.ts +99 -0
- package/dist/workspace-aspects-loader.js +588 -0
- package/dist/workspace-aspects-loader.js.map +1 -0
- package/dist/workspace.d.ts +12 -10
- package/dist/workspace.js +38 -301
- package/dist/workspace.js.map +1 -1
- package/dist/workspace.main.runtime.d.ts +2 -2
- package/dist/workspace.main.runtime.js +1 -1
- package/dist/workspace.main.runtime.js.map +1 -1
- package/dist/workspace.provider.d.ts +9 -3
- package/dist/workspace.provider.js +2 -2
- package/dist/workspace.provider.js.map +1 -1
- package/package-tar/teambit-workspace-0.0.1006.tgz +0 -0
- package/package.json +39 -36
- package/package-tar/teambit-workspace-0.0.1002.tgz +0 -0
package/dist/workspace.js
CHANGED
|
@@ -39,20 +39,6 @@ function _graph() {
|
|
|
39
39
|
};
|
|
40
40
|
return data;
|
|
41
41
|
}
|
|
42
|
-
function _aspectLoader() {
|
|
43
|
-
const data = require("@teambit/aspect-loader");
|
|
44
|
-
_aspectLoader = function () {
|
|
45
|
-
return data;
|
|
46
|
-
};
|
|
47
|
-
return data;
|
|
48
|
-
}
|
|
49
|
-
function _cli() {
|
|
50
|
-
const data = require("@teambit/cli");
|
|
51
|
-
_cli = function () {
|
|
52
|
-
return data;
|
|
53
|
-
};
|
|
54
|
-
return data;
|
|
55
|
-
}
|
|
56
42
|
function _scopeGraph() {
|
|
57
43
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/scope/graph/scope-graph"));
|
|
58
44
|
_scopeGraph = function () {
|
|
@@ -95,13 +81,6 @@ function _workspaceModules() {
|
|
|
95
81
|
};
|
|
96
82
|
return data;
|
|
97
83
|
}
|
|
98
|
-
function _harmonyModules() {
|
|
99
|
-
const data = require("@teambit/harmony.modules.requireable-component");
|
|
100
|
-
_harmonyModules = function () {
|
|
101
|
-
return data;
|
|
102
|
-
};
|
|
103
|
-
return data;
|
|
104
|
-
}
|
|
105
84
|
function _bitId() {
|
|
106
85
|
const data = require("@teambit/legacy/dist/bit-id");
|
|
107
86
|
_bitId = function () {
|
|
@@ -137,13 +116,6 @@ function _cacheFactory() {
|
|
|
137
116
|
};
|
|
138
117
|
return data;
|
|
139
118
|
}
|
|
140
|
-
function _exceptions() {
|
|
141
|
-
const data = require("@teambit/legacy/dist/scope/exceptions");
|
|
142
|
-
_exceptions = function () {
|
|
143
|
-
return data;
|
|
144
|
-
};
|
|
145
|
-
return data;
|
|
146
|
-
}
|
|
147
119
|
function _componentsList() {
|
|
148
120
|
const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/component/components-list"));
|
|
149
121
|
_componentsList = function () {
|
|
@@ -221,9 +193,9 @@ function _scopeComponentsImporter() {
|
|
|
221
193
|
};
|
|
222
194
|
return data;
|
|
223
195
|
}
|
|
224
|
-
function
|
|
196
|
+
function _exceptions() {
|
|
225
197
|
const data = require("@teambit/legacy/dist/consumer/bit-map/exceptions");
|
|
226
|
-
|
|
198
|
+
_exceptions = function () {
|
|
227
199
|
return data;
|
|
228
200
|
};
|
|
229
201
|
return data;
|
|
@@ -249,13 +221,6 @@ function _scopeNotFoundOrDenied() {
|
|
|
249
221
|
};
|
|
250
222
|
return data;
|
|
251
223
|
}
|
|
252
|
-
function _workspaceModules2() {
|
|
253
|
-
const data = require("@teambit/workspace.modules.node-modules-linker");
|
|
254
|
-
_workspaceModules2 = function () {
|
|
255
|
-
return data;
|
|
256
|
-
};
|
|
257
|
-
return data;
|
|
258
|
-
}
|
|
259
224
|
function _componentVersion() {
|
|
260
225
|
const data = require("@teambit/component-version");
|
|
261
226
|
_componentVersion = function () {
|
|
@@ -319,6 +284,13 @@ function _aspectsMerger() {
|
|
|
319
284
|
};
|
|
320
285
|
return data;
|
|
321
286
|
}
|
|
287
|
+
function _workspaceAspectsLoader() {
|
|
288
|
+
const data = require("./workspace-aspects-loader");
|
|
289
|
+
_workspaceAspectsLoader = function () {
|
|
290
|
+
return data;
|
|
291
|
+
};
|
|
292
|
+
return data;
|
|
293
|
+
}
|
|
322
294
|
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; }
|
|
323
295
|
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; }
|
|
324
296
|
const AspectSpecificField = '__specific';
|
|
@@ -369,7 +341,7 @@ class Workspace {
|
|
|
369
341
|
/**
|
|
370
342
|
* on component add slot.
|
|
371
343
|
*/
|
|
372
|
-
onComponentAddSlot, onComponentRemoveSlot, graphql) {
|
|
344
|
+
onComponentAddSlot, onComponentRemoveSlot, onAspectsResolveSlot, onRootAspectAddedSlot, graphql) {
|
|
373
345
|
var _this$config;
|
|
374
346
|
this.pubsub = pubsub;
|
|
375
347
|
this.config = config;
|
|
@@ -387,6 +359,8 @@ class Workspace {
|
|
|
387
359
|
this.envs = envs;
|
|
388
360
|
this.onComponentAddSlot = onComponentAddSlot;
|
|
389
361
|
this.onComponentRemoveSlot = onComponentRemoveSlot;
|
|
362
|
+
this.onAspectsResolveSlot = onAspectsResolveSlot;
|
|
363
|
+
this.onRootAspectAddedSlot = onRootAspectAddedSlot;
|
|
390
364
|
this.graphql = graphql;
|
|
391
365
|
(0, _defineProperty2().default)(this, "priority", true);
|
|
392
366
|
(0, _defineProperty2().default)(this, "owner", void 0);
|
|
@@ -452,6 +426,14 @@ class Workspace {
|
|
|
452
426
|
this.onComponentRemoveSlot.register(onComponentRemoveFunc);
|
|
453
427
|
return this;
|
|
454
428
|
}
|
|
429
|
+
registerOnAspectsResolve(onAspectsResolveFunc) {
|
|
430
|
+
this.onAspectsResolveSlot.register(onAspectsResolveFunc);
|
|
431
|
+
return this;
|
|
432
|
+
}
|
|
433
|
+
registerOnRootAspectAdded(onRootAspectAddedFunc) {
|
|
434
|
+
this.onRootAspectAddedSlot.register(onRootAspectAddedFunc);
|
|
435
|
+
return this;
|
|
436
|
+
}
|
|
455
437
|
|
|
456
438
|
/**
|
|
457
439
|
* name of the workspace as configured in either `workspace.json`.
|
|
@@ -716,6 +698,10 @@ class Workspace {
|
|
|
716
698
|
this.componentLoadedSelfAsAspects.set(component.id.toString(), false);
|
|
717
699
|
return component;
|
|
718
700
|
}
|
|
701
|
+
async getConfiguredUserAspectsPackages(options) {
|
|
702
|
+
const workspaceAspectsLoader = this.getWorkspaceAspectsLoader();
|
|
703
|
+
return workspaceAspectsLoader.getConfiguredUserAspectsPackages(options);
|
|
704
|
+
}
|
|
719
705
|
|
|
720
706
|
// TODO: @gilad we should refactor this asap into to the envs aspect.
|
|
721
707
|
async getEnvSystemDescriptor(component) {
|
|
@@ -822,6 +808,9 @@ class Workspace {
|
|
|
822
808
|
getCurrentLaneId() {
|
|
823
809
|
return this.consumer.getCurrentLaneId();
|
|
824
810
|
}
|
|
811
|
+
async getCurrentLaneObject() {
|
|
812
|
+
return this.consumer.getCurrentLaneObject();
|
|
813
|
+
}
|
|
825
814
|
isOnMain() {
|
|
826
815
|
return this.consumer.isOnMain();
|
|
827
816
|
}
|
|
@@ -930,7 +919,7 @@ class Workspace {
|
|
|
930
919
|
// if it's not a pattern but just id, resolve it without multimatch to support specifying id without scope-name
|
|
931
920
|
const id = await this.resolveComponentId(pattern);
|
|
932
921
|
if (this.exists(id)) return [id];
|
|
933
|
-
if (throwForNoMatch) throw new (
|
|
922
|
+
if (throwForNoMatch) throw new (_exceptions().MissingBitMapComponent)(pattern);
|
|
934
923
|
return [];
|
|
935
924
|
}
|
|
936
925
|
const ids = await this.listIds();
|
|
@@ -1040,22 +1029,8 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
|
|
|
1040
1029
|
});
|
|
1041
1030
|
}
|
|
1042
1031
|
async use(aspectIdStr) {
|
|
1043
|
-
const
|
|
1044
|
-
|
|
1045
|
-
if (!(await this.hasId(aspectId))) {
|
|
1046
|
-
const loadedIds = await this.scope.loadAspects([aspectIdStr], true, 'bit use command');
|
|
1047
|
-
if (loadedIds[0]) aspectIdToAdd = loadedIds[0];
|
|
1048
|
-
}
|
|
1049
|
-
const config = this.harmony.get('teambit.harmony/config').workspaceConfig;
|
|
1050
|
-
if (!config) {
|
|
1051
|
-
throw new Error(`use() unable to get the workspace config`);
|
|
1052
|
-
}
|
|
1053
|
-
config.setExtension(aspectIdToAdd, {}, {
|
|
1054
|
-
overrideExisting: false,
|
|
1055
|
-
ignoreVersion: false
|
|
1056
|
-
});
|
|
1057
|
-
await config.write();
|
|
1058
|
-
return aspectIdToAdd;
|
|
1032
|
+
const workspaceAspectsLoader = this.getWorkspaceAspectsLoader();
|
|
1033
|
+
return workspaceAspectsLoader.use(aspectIdStr);
|
|
1059
1034
|
}
|
|
1060
1035
|
async write(component, rootPath) {
|
|
1061
1036
|
await Promise.all(component.filesystem.files.map(async file => {
|
|
@@ -1311,108 +1286,14 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
|
|
|
1311
1286
|
}
|
|
1312
1287
|
return componentConfigFile;
|
|
1313
1288
|
}
|
|
1314
|
-
async getAspectsGraphWithoutCore(components, isAspect) {
|
|
1315
|
-
const ids = components.map(component => component.id);
|
|
1316
|
-
const coreAspectsStringIds = this.aspectLoader.getCoreAspectIds();
|
|
1317
|
-
// const coreAspectsComponentIds = coreAspectsStringIds.map((id) => BitId.parse(id, true));
|
|
1318
|
-
// const aspectsIds = components.reduce((acc, curr) => {
|
|
1319
|
-
// const currIds = curr.state.aspects.ids;
|
|
1320
|
-
// acc = acc.concat(currIds);
|
|
1321
|
-
// return acc;
|
|
1322
|
-
// }, [] as any);
|
|
1323
|
-
// const otherDependenciesMap = components.reduce((acc, curr) => {
|
|
1324
|
-
// // const currIds = curr.state.dependencies.dependencies.map(dep => dep.id.toString());
|
|
1325
|
-
// const currMap = curr.state.dependencies.getIdsMap();
|
|
1326
|
-
// Object.assign(acc, currMap);
|
|
1327
|
-
// return acc;
|
|
1328
|
-
// }, {});
|
|
1329
|
-
|
|
1330
|
-
// const depsWhichAreNotAspects = difference(Object.keys(otherDependenciesMap), aspectsIds);
|
|
1331
|
-
// const depsWhichAreNotAspectsBitIds = depsWhichAreNotAspects.map((strId) => otherDependenciesMap[strId]);
|
|
1332
|
-
// We only want to load into the graph components which are aspects and not regular dependencies
|
|
1333
|
-
// This come to solve a circular loop when an env aspect use an aspect (as regular dep) and the aspect use the env aspect as its env
|
|
1334
|
-
// TODO: @gilad it causes many issues we need to find a better solution. removed for now.
|
|
1335
|
-
return this.buildOneGraphForComponents(ids, coreAspectsStringIds, isAspect);
|
|
1336
|
-
}
|
|
1337
1289
|
|
|
1338
1290
|
/**
|
|
1339
1291
|
* load aspects from the workspace and if not exists in the workspace, load from the scope.
|
|
1340
1292
|
* keep in mind that the graph may have circles.
|
|
1341
1293
|
*/
|
|
1342
1294
|
async loadAspects(ids = [], throwOnError = false, neededFor) {
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
const loggerPrefix = `[${callId}] loadAspects,`;
|
|
1346
|
-
this.logger.info(`${loggerPrefix} loading ${ids.length} aspects.
|
|
1347
|
-
ids: ${ids.join(', ')}
|
|
1348
|
-
needed-for: ${neededFor || '<unknown>'}`);
|
|
1349
|
-
const notLoadedIds = ids.filter(id => !this.aspectLoader.isAspectLoaded(id));
|
|
1350
|
-
if (!notLoadedIds.length) return [];
|
|
1351
|
-
const coreAspectsStringIds = this.aspectLoader.getCoreAspectIds();
|
|
1352
|
-
const idsWithoutCore = (0, _lodash().difference)(notLoadedIds, coreAspectsStringIds);
|
|
1353
|
-
const componentIds = await this.resolveMultipleComponentIds(idsWithoutCore);
|
|
1354
|
-
const components = await this.importAndGetAspects(componentIds);
|
|
1355
|
-
const isAspect = async id => {
|
|
1356
|
-
const component = await this.get(id);
|
|
1357
|
-
const isUsingAspectEnv = this.envs.isUsingAspectEnv(component);
|
|
1358
|
-
const isUsingEnvEnv = this.envs.isUsingEnvEnv(component);
|
|
1359
|
-
const isValidAspect = isUsingAspectEnv || isUsingEnvEnv;
|
|
1360
|
-
// if (!isValidAspect && idsWithoutCore.includes(component.id.toString())) {
|
|
1361
|
-
// const data = this.envs.getEnvData(component);
|
|
1362
|
-
// const err = new IncorrectEnvAspect(component.id.toString(), data.type, data.id);
|
|
1363
|
-
// if (data.id === DEFAULT_ENV) {
|
|
1364
|
-
// // when cloning a project, or when the node-modules dir is deleted, nothing works and all
|
|
1365
|
-
// // components are default to the DEFAULT_ENV, which is node-env. we must allow "bit
|
|
1366
|
-
// // install" to prepare the workspace and let the proper the envs to be loaded
|
|
1367
|
-
// this.logger.error(err.message);
|
|
1368
|
-
// } else {
|
|
1369
|
-
// throw err;
|
|
1370
|
-
// }
|
|
1371
|
-
// }
|
|
1372
|
-
return isValidAspect;
|
|
1373
|
-
};
|
|
1374
|
-
const graph = await this.getAspectsGraphWithoutCore(components, isAspect);
|
|
1375
|
-
const aspects = graph.nodes.map(node => node.attr);
|
|
1376
|
-
this.logger.debug(`${loggerPrefix} found ${aspects.length} aspects in the aspects-graph`);
|
|
1377
|
-
const {
|
|
1378
|
-
workspaceComps,
|
|
1379
|
-
scopeComps
|
|
1380
|
-
} = await this.groupComponentsByWorkspaceAndScope(aspects);
|
|
1381
|
-
this.logger.debug(`${loggerPrefix} found ${workspaceComps.length} components in the workspace:\n${workspaceComps.map(c => c.id.toString()).join('\n')}`);
|
|
1382
|
-
this.logger.debug(`${loggerPrefix} ${scopeComps.length} components are not in the workspace and are loaded from the scope:\n${scopeComps.map(c => c.id.toString()).join('\n')}`);
|
|
1383
|
-
const scopeIds = scopeComps.map(aspect => aspect.id.toString());
|
|
1384
|
-
const workspaceAspects = await this.requireComponents(workspaceComps);
|
|
1385
|
-
const workspaceManifests = await this.aspectLoader.getManifestsFromRequireableExtensions(workspaceAspects, throwOnError);
|
|
1386
|
-
const potentialPluginsIndexes = (0, _lodash().compact)(workspaceManifests.map((manifest, index) => {
|
|
1387
|
-
if (this.aspectLoader.isValidAspect(manifest)) return undefined;
|
|
1388
|
-
return index;
|
|
1389
|
-
}));
|
|
1390
|
-
const workspaceManifestsIds = (0, _lodash().compact)(workspaceManifests.map(m => m.id));
|
|
1391
|
-
// We are grouping the scope aspects by whether they are envs of something of the list or not
|
|
1392
|
-
// if yes, we want to load them first
|
|
1393
|
-
// the rest we will load together with the workspace aspects
|
|
1394
|
-
const scopeIdsGrouped = await this.scope.groupAspectIdsByEnvOfTheList(scopeIds);
|
|
1395
|
-
const scopeEnvsManifestsIds = scopeIdsGrouped.envs && scopeIdsGrouped.envs.length ? await this.scope.loadAspects(scopeIdsGrouped.envs, throwOnError, 'workspace.loadAspects loading scope aspects') : [];
|
|
1396
|
-
const currentLane = await this.consumer.getCurrentLaneObject();
|
|
1397
|
-
const {
|
|
1398
|
-
manifests: scopeOtherManifests
|
|
1399
|
-
} = scopeIdsGrouped.other && scopeIdsGrouped.other.length ? await this.scope.getManifestsGraphRecursively(scopeIdsGrouped.other, (0, _lodash().compact)(workspaceManifestsIds), throwOnError, currentLane || undefined, {
|
|
1400
|
-
packageManagerConfigRootDir: this.path
|
|
1401
|
-
}) : {
|
|
1402
|
-
manifests: []
|
|
1403
|
-
};
|
|
1404
|
-
const scopeOtherManifestsIds = (0, _lodash().compact)(scopeOtherManifests.map(m => m.id));
|
|
1405
|
-
await this.aspectLoader.loadExtensionsByManifests([...scopeOtherManifests, ...workspaceManifests], throwOnError, idsWithoutCore);
|
|
1406
|
-
// Try require components for potential plugins
|
|
1407
|
-
const pluginsWorkspaceComps = potentialPluginsIndexes.map(index => {
|
|
1408
|
-
return workspaceComps[index];
|
|
1409
|
-
});
|
|
1410
|
-
// Do the require again now that the plugins defs already registered
|
|
1411
|
-
const pluginsWorkspaceAspects = await this.requireComponents(pluginsWorkspaceComps);
|
|
1412
|
-
const pluginsWorkspaceManifests = await this.aspectLoader.getManifestsFromRequireableExtensions(pluginsWorkspaceAspects, throwOnError);
|
|
1413
|
-
await this.aspectLoader.loadExtensionsByManifests(pluginsWorkspaceManifests, throwOnError);
|
|
1414
|
-
this.logger.debug(`${loggerPrefix} finish loading aspects`);
|
|
1415
|
-
return (0, _lodash().compact)(scopeEnvsManifestsIds.concat(scopeOtherManifestsIds).concat(workspaceManifestsIds));
|
|
1295
|
+
const workspaceAspectsLoader = this.getWorkspaceAspectsLoader();
|
|
1296
|
+
return workspaceAspectsLoader.loadAspects(ids, throwOnError, neededFor);
|
|
1416
1297
|
}
|
|
1417
1298
|
|
|
1418
1299
|
/**
|
|
@@ -1424,105 +1305,8 @@ needed-for: ${neededFor || '<unknown>'}`);
|
|
|
1424
1305
|
return graphFromFsBuilder.buildGraph(ids);
|
|
1425
1306
|
}
|
|
1426
1307
|
async resolveAspects(runtimeName, componentIds, opts) {
|
|
1427
|
-
this.
|
|
1428
|
-
|
|
1429
|
-
excludeCore: false,
|
|
1430
|
-
requestedOnly: false,
|
|
1431
|
-
filterByRuntime: true
|
|
1432
|
-
};
|
|
1433
|
-
const mergedOpts = _objectSpread(_objectSpread({}, defaultOpts), opts);
|
|
1434
|
-
let missingPaths = false;
|
|
1435
|
-
const bitIds = [];
|
|
1436
|
-
const idsToResolve = componentIds ? componentIds.map(id => id.toString()) : this.harmony.extensionsIds;
|
|
1437
|
-
const coreAspectsIds = this.aspectLoader.getCoreAspectIds();
|
|
1438
|
-
const userAspectsIds = (0, _lodash().difference)(idsToResolve, coreAspectsIds);
|
|
1439
|
-
const componentIdsToResolve = await this.resolveMultipleComponentIds(userAspectsIds);
|
|
1440
|
-
const {
|
|
1441
|
-
workspaceIds,
|
|
1442
|
-
scopeIds
|
|
1443
|
-
} = await this.groupIdsByWorkspaceAndScope(componentIdsToResolve);
|
|
1444
|
-
const wsComponents = await this.getMany(workspaceIds);
|
|
1445
|
-
const aspectDefs = await this.aspectLoader.resolveAspects(wsComponents, async component => {
|
|
1446
|
-
const compStringId = component.id._legacy.toString();
|
|
1447
|
-
bitIds.push(component.id._legacy);
|
|
1448
|
-
const localPath = this.getComponentPackagePath(component);
|
|
1449
|
-
const isExist = await _fsExtra().default.pathExists(localPath);
|
|
1450
|
-
if (!isExist) {
|
|
1451
|
-
missingPaths = true;
|
|
1452
|
-
}
|
|
1453
|
-
const runtimePath = runtimeName ? await this.aspectLoader.getRuntimePath(component, localPath, runtimeName) : null;
|
|
1454
|
-
const aspectFilePath = await this.aspectLoader.getAspectFilePath(component, localPath);
|
|
1455
|
-
this.logger.debug(`workspace resolveAspects, resolving id: ${compStringId}, localPath: ${localPath}, runtimePath: ${runtimePath}`);
|
|
1456
|
-
return {
|
|
1457
|
-
aspectPath: localPath,
|
|
1458
|
-
aspectFilePath,
|
|
1459
|
-
runtimePath
|
|
1460
|
-
};
|
|
1461
|
-
});
|
|
1462
|
-
let scopeAspectDefs = [];
|
|
1463
|
-
if (scopeIds.length) {
|
|
1464
|
-
scopeAspectDefs = await this.scope.resolveAspects(runtimeName, scopeIds, mergedOpts);
|
|
1465
|
-
}
|
|
1466
|
-
let coreAspectDefs = await Promise.all(coreAspectsIds.map(async coreId => {
|
|
1467
|
-
const rawDef = await (0, _aspectLoader().getAspectDef)(coreId, runtimeName);
|
|
1468
|
-
return this.aspectLoader.loadDefinition(rawDef);
|
|
1469
|
-
}));
|
|
1470
|
-
|
|
1471
|
-
// due to lack of workspace and scope runtimes. TODO: fix after adding them.
|
|
1472
|
-
if (runtimeName && mergedOpts.filterByRuntime) {
|
|
1473
|
-
coreAspectDefs = coreAspectDefs.filter(coreAspect => {
|
|
1474
|
-
return coreAspect.runtimePath;
|
|
1475
|
-
});
|
|
1476
|
-
}
|
|
1477
|
-
if (missingPaths) {
|
|
1478
|
-
await (0, _workspaceModules2().linkToNodeModulesByIds)(this, bitIds);
|
|
1479
|
-
}
|
|
1480
|
-
const allDefs = aspectDefs.concat(coreAspectDefs).concat(scopeAspectDefs);
|
|
1481
|
-
const ids = idsToResolve.map(idStr => _component().ComponentID.fromString(idStr).toStringWithoutVersion());
|
|
1482
|
-
const afterExclusion = mergedOpts.excludeCore ? allDefs.filter(def => {
|
|
1483
|
-
const isCore = coreAspectDefs.find(coreId => def.getId === coreId.getId);
|
|
1484
|
-
const id = _component().ComponentID.fromString(def.getId || '');
|
|
1485
|
-
const isTarget = ids.includes(id.toStringWithoutVersion());
|
|
1486
|
-
if (isTarget) return true;
|
|
1487
|
-
return !isCore;
|
|
1488
|
-
}) : allDefs;
|
|
1489
|
-
const uniqDefs = (0, _lodash().uniqBy)(afterExclusion, def => `${def.aspectPath}-${def.runtimePath}`);
|
|
1490
|
-
let defs = uniqDefs;
|
|
1491
|
-
if (runtimeName && mergedOpts.filterByRuntime) {
|
|
1492
|
-
defs = defs.filter(def => def.runtimePath);
|
|
1493
|
-
}
|
|
1494
|
-
if (componentIds && componentIds.length && mergedOpts.requestedOnly) {
|
|
1495
|
-
const componentIdsString = componentIds.map(id => id.toString());
|
|
1496
|
-
defs = defs.filter(def => {
|
|
1497
|
-
var _def$component;
|
|
1498
|
-
return def.id && componentIdsString.includes(def.id) || def.component && componentIdsString.includes((_def$component = def.component) === null || _def$component === void 0 ? void 0 : _def$component.id.toString());
|
|
1499
|
-
});
|
|
1500
|
-
}
|
|
1501
|
-
return defs;
|
|
1502
|
-
}
|
|
1503
|
-
async groupIdsByWorkspaceAndScope(ids) {
|
|
1504
|
-
const workspaceIds = [];
|
|
1505
|
-
const scopeIds = [];
|
|
1506
|
-
await Promise.all(ids.map(async id => {
|
|
1507
|
-
const existOnWorkspace = await this.hasId(id);
|
|
1508
|
-
existOnWorkspace ? workspaceIds.push(id) : scopeIds.push(id);
|
|
1509
|
-
}));
|
|
1510
|
-
return {
|
|
1511
|
-
workspaceIds,
|
|
1512
|
-
scopeIds
|
|
1513
|
-
};
|
|
1514
|
-
}
|
|
1515
|
-
async groupComponentsByWorkspaceAndScope(components) {
|
|
1516
|
-
const workspaceComps = [];
|
|
1517
|
-
const scopeComps = [];
|
|
1518
|
-
await Promise.all(components.map(async component => {
|
|
1519
|
-
const existOnWorkspace = await this.hasId(component.id);
|
|
1520
|
-
existOnWorkspace ? workspaceComps.push(component) : scopeComps.push(component);
|
|
1521
|
-
}));
|
|
1522
|
-
return {
|
|
1523
|
-
workspaceComps,
|
|
1524
|
-
scopeComps
|
|
1525
|
-
};
|
|
1308
|
+
const workspaceAspectsLoader = this.getWorkspaceAspectsLoader();
|
|
1309
|
+
return workspaceAspectsLoader.resolveAspects(runtimeName, componentIds, opts);
|
|
1526
1310
|
}
|
|
1527
1311
|
|
|
1528
1312
|
/**
|
|
@@ -1545,61 +1329,14 @@ needed-for: ${neededFor || '<unknown>'}`);
|
|
|
1545
1329
|
}
|
|
1546
1330
|
return cacheDir;
|
|
1547
1331
|
}
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
const resolveP = components.map(async component => {
|
|
1552
|
-
bitIds.push(component.id._legacy);
|
|
1553
|
-
const localPath = this.getComponentPackagePath(component);
|
|
1554
|
-
const isExist = await _fsExtra().default.pathExists(localPath);
|
|
1555
|
-
if (!isExist) {
|
|
1556
|
-
missingPaths = true;
|
|
1557
|
-
}
|
|
1558
|
-
const requireFunc = async () => {
|
|
1559
|
-
const plugins = this.aspectLoader.getPlugins(component, localPath);
|
|
1560
|
-
if (plugins.has()) {
|
|
1561
|
-
return plugins.load(_cli().MainRuntime.name);
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
1565
|
-
const aspect = require(localPath);
|
|
1566
|
-
// require aspect runtimes
|
|
1567
|
-
const runtimePath = await this.aspectLoader.getRuntimePath(component, localPath, _cli().MainRuntime.name);
|
|
1568
|
-
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
1569
|
-
if (runtimePath) require(runtimePath);
|
|
1570
|
-
return aspect;
|
|
1571
|
-
};
|
|
1572
|
-
return new (_harmonyModules().RequireableComponent)(component, requireFunc);
|
|
1573
|
-
});
|
|
1574
|
-
const resolved = await Promise.all(resolveP);
|
|
1575
|
-
// Make sure to link missing components
|
|
1576
|
-
if (missingPaths) {
|
|
1577
|
-
await (0, _workspaceModules2().linkToNodeModulesByIds)(this, bitIds);
|
|
1578
|
-
}
|
|
1579
|
-
return resolved;
|
|
1332
|
+
getWorkspaceAspectsLoader() {
|
|
1333
|
+
const workspaceAspectsLoader = new (_workspaceAspectsLoader().WorkspaceAspectsLoader)(this, this.scope, this.aspectLoader, this.envs, this.dependencyResolver, this.logger, this.harmony, this.onAspectsResolveSlot, this.onRootAspectAddedSlot);
|
|
1334
|
+
return workspaceAspectsLoader;
|
|
1580
1335
|
}
|
|
1581
1336
|
|
|
1582
1337
|
/**
|
|
1583
|
-
* same as `this.importAndGetMany()` with a specific error handling of ComponentNotFound
|
|
1584
|
-
*/
|
|
1585
|
-
async importAndGetAspects(componentIds) {
|
|
1586
|
-
try {
|
|
1587
|
-
return await this.importAndGetMany(componentIds);
|
|
1588
|
-
} catch (err) {
|
|
1589
|
-
if (err instanceof _exceptions().ComponentNotFound) {
|
|
1590
|
-
var _config$workspaceConf3;
|
|
1591
|
-
const config = this.harmony.get('teambit.harmony/config');
|
|
1592
|
-
const configStr = JSON.stringify(((_config$workspaceConf3 = config.workspaceConfig) === null || _config$workspaceConf3 === void 0 ? void 0 : _config$workspaceConf3.raw) || {});
|
|
1593
|
-
if (configStr.includes(err.id)) {
|
|
1594
|
-
throw new (_bitError().BitError)(`error: a component "${err.id}" was not found
|
|
1595
|
-
your workspace.jsonc has this component-id set. you might want to remove/change it.`);
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
throw err;
|
|
1599
|
-
}
|
|
1600
1338
|
}
|
|
1601
|
-
|
|
1602
|
-
/**
|
|
1339
|
+
/**
|
|
1603
1340
|
* this should be rarely in-use.
|
|
1604
1341
|
* it's currently used by watch extension as a quick workaround to load .bitmap and the components
|
|
1605
1342
|
*/
|