@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
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
require("core-js/modules/es.array.iterator.js");
|
|
5
|
+
require("core-js/modules/es.promise.js");
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.WorkspaceAspectsLoader = void 0;
|
|
10
|
+
function _defineProperty2() {
|
|
11
|
+
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
+
_defineProperty2 = function () {
|
|
13
|
+
return data;
|
|
14
|
+
};
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
function _findRoot() {
|
|
18
|
+
const data = _interopRequireDefault(require("find-root"));
|
|
19
|
+
_findRoot = function () {
|
|
20
|
+
return data;
|
|
21
|
+
};
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
function _toolboxModules() {
|
|
25
|
+
const data = require("@teambit/toolbox.modules.module-resolver");
|
|
26
|
+
_toolboxModules = function () {
|
|
27
|
+
return data;
|
|
28
|
+
};
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
function _aspectLoader() {
|
|
32
|
+
const data = require("@teambit/aspect-loader");
|
|
33
|
+
_aspectLoader = function () {
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
function _cli() {
|
|
39
|
+
const data = require("@teambit/cli");
|
|
40
|
+
_cli = function () {
|
|
41
|
+
return data;
|
|
42
|
+
};
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
function _fsExtra() {
|
|
46
|
+
const data = _interopRequireDefault(require("fs-extra"));
|
|
47
|
+
_fsExtra = function () {
|
|
48
|
+
return data;
|
|
49
|
+
};
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
function _harmonyModules() {
|
|
53
|
+
const data = require("@teambit/harmony.modules.requireable-component");
|
|
54
|
+
_harmonyModules = function () {
|
|
55
|
+
return data;
|
|
56
|
+
};
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
function _workspaceModules() {
|
|
60
|
+
const data = require("@teambit/workspace.modules.node-modules-linker");
|
|
61
|
+
_workspaceModules = function () {
|
|
62
|
+
return data;
|
|
63
|
+
};
|
|
64
|
+
return data;
|
|
65
|
+
}
|
|
66
|
+
function _exceptions() {
|
|
67
|
+
const data = require("@teambit/legacy/dist/scope/exceptions");
|
|
68
|
+
_exceptions = function () {
|
|
69
|
+
return data;
|
|
70
|
+
};
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
function _pMapSeries() {
|
|
74
|
+
const data = _interopRequireDefault(require("p-map-series"));
|
|
75
|
+
_pMapSeries = function () {
|
|
76
|
+
return data;
|
|
77
|
+
};
|
|
78
|
+
return data;
|
|
79
|
+
}
|
|
80
|
+
function _lodash() {
|
|
81
|
+
const data = require("lodash");
|
|
82
|
+
_lodash = function () {
|
|
83
|
+
return data;
|
|
84
|
+
};
|
|
85
|
+
return data;
|
|
86
|
+
}
|
|
87
|
+
function _component() {
|
|
88
|
+
const data = require("@teambit/component");
|
|
89
|
+
_component = function () {
|
|
90
|
+
return data;
|
|
91
|
+
};
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
function _bitError() {
|
|
95
|
+
const data = require("@teambit/bit-error");
|
|
96
|
+
_bitError = function () {
|
|
97
|
+
return data;
|
|
98
|
+
};
|
|
99
|
+
return data;
|
|
100
|
+
}
|
|
101
|
+
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; }
|
|
102
|
+
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; }
|
|
103
|
+
class WorkspaceAspectsLoader {
|
|
104
|
+
constructor(workspace, scope, aspectLoader, envs, dependencyResolver, logger, harmony, onAspectsResolveSlot, onRootAspectAddedSlot) {
|
|
105
|
+
this.workspace = workspace;
|
|
106
|
+
this.scope = scope;
|
|
107
|
+
this.aspectLoader = aspectLoader;
|
|
108
|
+
this.envs = envs;
|
|
109
|
+
this.dependencyResolver = dependencyResolver;
|
|
110
|
+
this.logger = logger;
|
|
111
|
+
this.harmony = harmony;
|
|
112
|
+
this.onAspectsResolveSlot = onAspectsResolveSlot;
|
|
113
|
+
this.onRootAspectAddedSlot = onRootAspectAddedSlot;
|
|
114
|
+
(0, _defineProperty2().default)(this, "consumer", void 0);
|
|
115
|
+
(0, _defineProperty2().default)(this, "resolvedInstalledAspects", void 0);
|
|
116
|
+
this.consumer = this.workspace.consumer;
|
|
117
|
+
this.resolvedInstalledAspects = new Map();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* load aspects from the workspace and if not exists in the workspace, load from the node_modules.
|
|
122
|
+
* keep in mind that the graph may have circles.
|
|
123
|
+
*/
|
|
124
|
+
async loadAspects(ids = [], throwOnError = false, neededFor, opts = {}) {
|
|
125
|
+
const defaultOpts = {
|
|
126
|
+
useScopeAspectsCapsule: false
|
|
127
|
+
};
|
|
128
|
+
const mergedOpts = _objectSpread(_objectSpread({}, defaultOpts), opts);
|
|
129
|
+
|
|
130
|
+
// generate a random callId to be able to identify the call from the logs
|
|
131
|
+
const callId = Math.floor(Math.random() * 1000);
|
|
132
|
+
const loggerPrefix = `[${callId}] loadAspects,`;
|
|
133
|
+
this.logger.info(`${loggerPrefix} loading ${ids.length} aspects.
|
|
134
|
+
ids: ${ids.join(', ')}
|
|
135
|
+
needed-for: ${neededFor || '<unknown>'}. using opts: ${JSON.stringify(mergedOpts, null, 2)}`);
|
|
136
|
+
const notLoadedIds = ids.filter(id => !this.aspectLoader.isAspectLoaded(id));
|
|
137
|
+
if (!notLoadedIds.length) return [];
|
|
138
|
+
const coreAspectsStringIds = this.aspectLoader.getCoreAspectIds();
|
|
139
|
+
const idsWithoutCore = (0, _lodash().difference)(notLoadedIds, coreAspectsStringIds);
|
|
140
|
+
const componentIds = await this.workspace.resolveMultipleComponentIds(idsWithoutCore);
|
|
141
|
+
const {
|
|
142
|
+
workspaceIds,
|
|
143
|
+
nonWorkspaceIds
|
|
144
|
+
} = await this.groupIdsByWorkspaceExistence(componentIds);
|
|
145
|
+
let idsToLoadFromWs = componentIds;
|
|
146
|
+
let scopeAspectIds = [];
|
|
147
|
+
if (mergedOpts.useScopeAspectsCapsule) {
|
|
148
|
+
idsToLoadFromWs = workspaceIds;
|
|
149
|
+
const currentLane = await this.consumer.getCurrentLaneObject();
|
|
150
|
+
const nonWorkspaceIdsString = nonWorkspaceIds.map(id => id.toString());
|
|
151
|
+
try {
|
|
152
|
+
scopeAspectIds = await this.scope.loadAspects(nonWorkspaceIdsString, throwOnError, neededFor, currentLane || undefined, {
|
|
153
|
+
packageManagerConfigRootDir: this.workspace.path
|
|
154
|
+
});
|
|
155
|
+
} catch (err) {
|
|
156
|
+
if (err instanceof _exceptions().ComponentNotFound) {
|
|
157
|
+
var _config$workspaceConf;
|
|
158
|
+
const config = this.harmony.get('teambit.harmony/config');
|
|
159
|
+
const configStr = JSON.stringify(((_config$workspaceConf = config.workspaceConfig) === null || _config$workspaceConf === void 0 ? void 0 : _config$workspaceConf.raw) || {});
|
|
160
|
+
if (configStr.includes(err.id)) {
|
|
161
|
+
throw new (_bitError().BitError)(`error: a component "${err.id}" was not found
|
|
162
|
+
your workspace.jsonc has this component-id set. you might want to remove/change it.`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
throw err;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const aspectsDefs = await this.resolveAspects(undefined, idsToLoadFromWs, _objectSpread({
|
|
169
|
+
excludeCore: true,
|
|
170
|
+
requestedOnly: false,
|
|
171
|
+
throwOnError
|
|
172
|
+
}, mergedOpts));
|
|
173
|
+
const requireableComponents = this.aspectDefsToRequireableComponents(aspectsDefs);
|
|
174
|
+
const manifests = await this.aspectLoader.getManifestsFromRequireableExtensions(requireableComponents, throwOnError);
|
|
175
|
+
const potentialPluginsIndexes = (0, _lodash().compact)(manifests.map((manifest, index) => {
|
|
176
|
+
if (this.aspectLoader.isValidAspect(manifest)) return undefined;
|
|
177
|
+
return index;
|
|
178
|
+
}));
|
|
179
|
+
await this.aspectLoader.loadExtensionsByManifests(manifests, throwOnError, idsWithoutCore);
|
|
180
|
+
|
|
181
|
+
// Try require components for potential plugins
|
|
182
|
+
const pluginsRequireableComponents = potentialPluginsIndexes.map(index => {
|
|
183
|
+
return requireableComponents[index];
|
|
184
|
+
});
|
|
185
|
+
// Do the require again now that the plugins defs already registered
|
|
186
|
+
const pluginsManifests = await this.aspectLoader.getManifestsFromRequireableExtensions(pluginsRequireableComponents, throwOnError);
|
|
187
|
+
await this.aspectLoader.loadExtensionsByManifests(pluginsManifests, throwOnError);
|
|
188
|
+
this.logger.debug(`${loggerPrefix} finish loading aspects`);
|
|
189
|
+
const manifestIds = manifests.map(manifest => manifest.id);
|
|
190
|
+
return (0, _lodash().compact)(manifestIds.concat(scopeAspectIds));
|
|
191
|
+
}
|
|
192
|
+
async resolveAspects(runtimeName, componentIds, opts) {
|
|
193
|
+
var _opts$throwOnError;
|
|
194
|
+
const callId = Math.floor(Math.random() * 1000);
|
|
195
|
+
const loggerPrefix = `[${callId}] workspace resolveAspects,`;
|
|
196
|
+
this.logger.debug(`${loggerPrefix}, resolving aspects for - runtimeName: ${runtimeName}, componentIds: ${componentIds}`);
|
|
197
|
+
const defaultOpts = {
|
|
198
|
+
excludeCore: false,
|
|
199
|
+
requestedOnly: false,
|
|
200
|
+
filterByRuntime: true,
|
|
201
|
+
useScopeAspectsCapsule: false
|
|
202
|
+
};
|
|
203
|
+
const mergedOpts = _objectSpread(_objectSpread({}, defaultOpts), opts);
|
|
204
|
+
const idsToResolve = componentIds ? componentIds.map(id => id.toString()) : this.harmony.extensionsIds;
|
|
205
|
+
const coreAspectsIds = this.aspectLoader.getCoreAspectIds();
|
|
206
|
+
const configuredAspects = this.aspectLoader.getConfiguredAspects();
|
|
207
|
+
const userAspectsIds = (0, _lodash().difference)(idsToResolve, coreAspectsIds);
|
|
208
|
+
const rootAspectsIds = (0, _lodash().difference)(configuredAspects, coreAspectsIds);
|
|
209
|
+
const componentIdsToResolve = await this.workspace.resolveMultipleComponentIds(userAspectsIds);
|
|
210
|
+
const components = await this.importAndGetAspects(componentIdsToResolve);
|
|
211
|
+
|
|
212
|
+
// Run the on load slot
|
|
213
|
+
await this.runOnAspectsResolveFunctions(components);
|
|
214
|
+
const graph = await this.getAspectsGraphWithoutCore(components, this.isAspect.bind(this));
|
|
215
|
+
const aspects = graph.nodes.map(node => node.attr);
|
|
216
|
+
this.logger.debug(`${loggerPrefix} found ${aspects.length} aspects in the aspects-graph`);
|
|
217
|
+
const {
|
|
218
|
+
workspaceComps,
|
|
219
|
+
nonWorkspaceComps
|
|
220
|
+
} = await this.groupComponentsByWorkspaceExistence(aspects);
|
|
221
|
+
const workspaceCompsIds = workspaceComps.map(c => c.id);
|
|
222
|
+
this.logger.debug(`${loggerPrefix} found ${workspaceComps.length} components in the workspace:\n${workspaceComps.map(c => c.id.toString()).join('\n')}`);
|
|
223
|
+
this.logger.debug(`${loggerPrefix} ${nonWorkspaceComps.length} components are not in the workspace and are loaded from the scope capsules or from the node_modules:\n${nonWorkspaceComps.map(c => c.id.toString()).join('\n')}`);
|
|
224
|
+
const stringIds = [];
|
|
225
|
+
const wsAspectDefs = await this.aspectLoader.resolveAspects(workspaceComps, this.getWorkspaceAspectResolver(stringIds, runtimeName));
|
|
226
|
+
await this.linkIfMissingWorkspaceAspects(wsAspectDefs, workspaceCompsIds);
|
|
227
|
+
|
|
228
|
+
// TODO: hard coded use the old approach and loading from the scope capsules
|
|
229
|
+
// This is because right now loading from the ws node_modules causes issues in some cases
|
|
230
|
+
// like for the cloud app
|
|
231
|
+
// it should be removed once we fix the issues
|
|
232
|
+
mergedOpts.useScopeAspectsCapsule = true;
|
|
233
|
+
let componentsToResolveFromScope = nonWorkspaceComps;
|
|
234
|
+
let componentsToResolveFromInstalled = [];
|
|
235
|
+
if (!mergedOpts.useScopeAspectsCapsule) {
|
|
236
|
+
const nonWorkspaceCompsGroups = (0, _lodash().groupBy)(nonWorkspaceComps, component => this.envs.isEnv(component));
|
|
237
|
+
componentsToResolveFromScope = nonWorkspaceCompsGroups.true || [];
|
|
238
|
+
componentsToResolveFromInstalled = nonWorkspaceCompsGroups.false || [];
|
|
239
|
+
}
|
|
240
|
+
const scopeIds = componentsToResolveFromScope.map(c => c.id);
|
|
241
|
+
this.logger.debug(`${loggerPrefix} ${scopeIds.length} components are not in the workspace and are loaded from the scope capsules:\n${scopeIds.map(id => id.toString()).join('\n')}`);
|
|
242
|
+
const scopeAspectsDefs = scopeIds.length ? await this.scope.resolveAspects(runtimeName, scopeIds, mergedOpts) : [];
|
|
243
|
+
this.logger.debug(`${loggerPrefix} ${componentsToResolveFromInstalled.length} components are not in the workspace and are loaded from the node_modules:\n${componentsToResolveFromInstalled.map(c => c.id.toString()).join('\n')}`);
|
|
244
|
+
const installedAspectsDefs = componentsToResolveFromInstalled.length ? await this.aspectLoader.resolveAspects(componentsToResolveFromInstalled, this.getInstalledAspectResolver(graph, rootAspectsIds, runtimeName, {
|
|
245
|
+
throwOnError: (_opts$throwOnError = opts === null || opts === void 0 ? void 0 : opts.throwOnError) !== null && _opts$throwOnError !== void 0 ? _opts$throwOnError : false
|
|
246
|
+
})) : [];
|
|
247
|
+
let coreAspectDefs = await Promise.all(coreAspectsIds.map(async coreId => {
|
|
248
|
+
const rawDef = await (0, _aspectLoader().getAspectDef)(coreId, runtimeName);
|
|
249
|
+
return this.aspectLoader.loadDefinition(rawDef);
|
|
250
|
+
}));
|
|
251
|
+
|
|
252
|
+
// due to lack of workspace and scope runtimes. TODO: fix after adding them.
|
|
253
|
+
if (runtimeName && mergedOpts.filterByRuntime) {
|
|
254
|
+
coreAspectDefs = coreAspectDefs.filter(coreAspect => {
|
|
255
|
+
return coreAspect.runtimePath;
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
const allDefs = wsAspectDefs.concat(coreAspectDefs).concat(scopeAspectsDefs).concat(installedAspectsDefs);
|
|
259
|
+
const idsToFilter = idsToResolve.map(idStr => _component().ComponentID.fromString(idStr));
|
|
260
|
+
const filteredDefs = this.aspectLoader.filterAspectDefs(allDefs, idsToFilter, runtimeName, mergedOpts);
|
|
261
|
+
return filteredDefs;
|
|
262
|
+
}
|
|
263
|
+
async use(aspectIdStr) {
|
|
264
|
+
let aspectId = await this.workspace.resolveComponentId(aspectIdStr);
|
|
265
|
+
const inWs = await this.workspace.hasId(aspectId);
|
|
266
|
+
let aspectIdToAdd = aspectId.toStringWithoutVersion();
|
|
267
|
+
let aspectsComponent;
|
|
268
|
+
// let aspectPackage;
|
|
269
|
+
if (!inWs) {
|
|
270
|
+
const aspectsComponents = await this.importAndGetAspects([aspectId]);
|
|
271
|
+
if (aspectsComponents[0]) {
|
|
272
|
+
aspectsComponent = aspectsComponents[0];
|
|
273
|
+
aspectId = aspectsComponent.id;
|
|
274
|
+
aspectIdToAdd = aspectId.toString();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const config = this.harmony.get('teambit.harmony/config').workspaceConfig;
|
|
278
|
+
if (!config) {
|
|
279
|
+
throw new Error(`use() unable to get the workspace config`);
|
|
280
|
+
}
|
|
281
|
+
config.setExtension(aspectIdToAdd, {}, {
|
|
282
|
+
overrideExisting: false,
|
|
283
|
+
ignoreVersion: false
|
|
284
|
+
});
|
|
285
|
+
await config.write();
|
|
286
|
+
this.aspectLoader.addInMemoryConfiguredAspect(aspectIdToAdd);
|
|
287
|
+
await this.runOnRootAspectAddedFunctions(aspectId, inWs);
|
|
288
|
+
return aspectIdToAdd;
|
|
289
|
+
}
|
|
290
|
+
async getConfiguredUserAspectsPackages(options = {}) {
|
|
291
|
+
const configuredAspects = this.aspectLoader.getConfiguredAspects();
|
|
292
|
+
const coreAspectsIds = this.aspectLoader.getCoreAspectIds();
|
|
293
|
+
const userAspectsIds = (0, _lodash().difference)(configuredAspects, coreAspectsIds);
|
|
294
|
+
const componentIdsToResolve = await this.workspace.resolveMultipleComponentIds(userAspectsIds);
|
|
295
|
+
const aspectsComponents = await this.importAndGetAspects(componentIdsToResolve);
|
|
296
|
+
let componentsToGetPackages = aspectsComponents;
|
|
297
|
+
if (options.externalsOnly) {
|
|
298
|
+
const {
|
|
299
|
+
nonWorkspaceComps
|
|
300
|
+
} = await this.groupComponentsByWorkspaceExistence(aspectsComponents);
|
|
301
|
+
componentsToGetPackages = nonWorkspaceComps;
|
|
302
|
+
}
|
|
303
|
+
const packages = componentsToGetPackages.map(aspectComponent => {
|
|
304
|
+
const packageName = this.dependencyResolver.getPackageName(aspectComponent);
|
|
305
|
+
const version = aspectComponent.id.version || '*';
|
|
306
|
+
return {
|
|
307
|
+
packageName,
|
|
308
|
+
version
|
|
309
|
+
};
|
|
310
|
+
});
|
|
311
|
+
return packages;
|
|
312
|
+
}
|
|
313
|
+
aspectDefsToRequireableComponents(aspectDefs) {
|
|
314
|
+
const requireableComponents = aspectDefs.map(aspectDef => {
|
|
315
|
+
const localPath = aspectDef.aspectPath;
|
|
316
|
+
const component = aspectDef.component;
|
|
317
|
+
if (!component) return undefined;
|
|
318
|
+
const requireFunc = async () => {
|
|
319
|
+
const plugins = this.aspectLoader.getPlugins(component, localPath);
|
|
320
|
+
if (plugins.has()) {
|
|
321
|
+
return plugins.load(_cli().MainRuntime.name);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
325
|
+
const aspect = require(localPath);
|
|
326
|
+
// require aspect runtimes
|
|
327
|
+
const runtimePath = await this.aspectLoader.getRuntimePath(component, localPath, _cli().MainRuntime.name);
|
|
328
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
329
|
+
if (runtimePath) require(runtimePath);
|
|
330
|
+
return aspect;
|
|
331
|
+
};
|
|
332
|
+
return new (_harmonyModules().RequireableComponent)(component, requireFunc);
|
|
333
|
+
});
|
|
334
|
+
return (0, _lodash().compact)(requireableComponents);
|
|
335
|
+
}
|
|
336
|
+
async linkIfMissingWorkspaceAspects(aspects, ids) {
|
|
337
|
+
let missingPaths = false;
|
|
338
|
+
const existsP = aspects.map(async aspect => {
|
|
339
|
+
const exist = await _fsExtra().default.pathExists(aspect.aspectPath);
|
|
340
|
+
if (!exist) {
|
|
341
|
+
missingPaths = true;
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
await Promise.all(existsP);
|
|
345
|
+
// TODO: this should be done properly by the install aspect by slot
|
|
346
|
+
if (missingPaths) {
|
|
347
|
+
const bitIds = ids.map(id => id._legacy);
|
|
348
|
+
return (0, _workspaceModules().linkToNodeModulesByIds)(this.workspace, bitIds);
|
|
349
|
+
}
|
|
350
|
+
return Promise.resolve();
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* This will return a resolver that knows to resolve aspects which are part of the workspace.
|
|
355
|
+
* means aspects exist in the bitmap file
|
|
356
|
+
* @param stringIds
|
|
357
|
+
* @param runtimeName
|
|
358
|
+
* @returns
|
|
359
|
+
*/
|
|
360
|
+
getWorkspaceAspectResolver(stringIds, runtimeName) {
|
|
361
|
+
const workspaceAspectResolver = async component => {
|
|
362
|
+
const compStringId = component.id._legacy.toString();
|
|
363
|
+
stringIds.push(compStringId);
|
|
364
|
+
const localPath = this.workspace.getComponentPackagePath(component);
|
|
365
|
+
const runtimePath = runtimeName ? await this.aspectLoader.getRuntimePath(component, localPath, runtimeName) : null;
|
|
366
|
+
const aspectFilePath = await this.aspectLoader.getAspectFilePath(component, localPath);
|
|
367
|
+
this.logger.debug(`workspace resolveAspects, resolving id: ${compStringId}, localPath: ${localPath}, runtimePath: ${runtimePath}`);
|
|
368
|
+
return {
|
|
369
|
+
aspectPath: localPath,
|
|
370
|
+
aspectFilePath,
|
|
371
|
+
runtimePath
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
return workspaceAspectResolver;
|
|
375
|
+
}
|
|
376
|
+
async runOnAspectsResolveFunctions(aspectsComponents) {
|
|
377
|
+
const funcs = this.getOnAspectsResolveFunctions();
|
|
378
|
+
await (0, _pMapSeries().default)(funcs, async func => {
|
|
379
|
+
try {
|
|
380
|
+
await func(aspectsComponents);
|
|
381
|
+
} catch (err) {
|
|
382
|
+
this.logger.error('failed running onAspectsResolve function', err);
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
getOnAspectsResolveFunctions() {
|
|
387
|
+
const aspectsResolveFunctions = this.onAspectsResolveSlot.values();
|
|
388
|
+
return aspectsResolveFunctions;
|
|
389
|
+
}
|
|
390
|
+
async runOnRootAspectAddedFunctions(aspectsId, inWs) {
|
|
391
|
+
const funcs = this.getOnRootAspectAddedFunctions();
|
|
392
|
+
await (0, _pMapSeries().default)(funcs, async func => {
|
|
393
|
+
try {
|
|
394
|
+
await func(aspectsId, inWs);
|
|
395
|
+
} catch (err) {
|
|
396
|
+
this.logger.error('failed running onRootAspectAdded function', err);
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
getOnRootAspectAddedFunctions() {
|
|
401
|
+
const RootAspectAddedFunctions = this.onRootAspectAddedSlot.values();
|
|
402
|
+
return RootAspectAddedFunctions;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* This will return a resolver that knows to resolve aspects which are not part of the workspace.
|
|
407
|
+
* means aspects that does not exist in the bitmap file
|
|
408
|
+
* instead it will resolve them from the node_modules recursively
|
|
409
|
+
* @param graph
|
|
410
|
+
* @param rootIds
|
|
411
|
+
* @param runtimeName
|
|
412
|
+
* @returns
|
|
413
|
+
*/
|
|
414
|
+
getInstalledAspectResolver(graph, rootIds, runtimeName, opts = {
|
|
415
|
+
throwOnError: false
|
|
416
|
+
}) {
|
|
417
|
+
const installedAspectsResolver = async component => {
|
|
418
|
+
const compStringId = component.id._legacy.toString();
|
|
419
|
+
// stringIds.push(compStringId);
|
|
420
|
+
const localPath = this.resolveInstalledAspectRecursively(component, rootIds, graph, opts);
|
|
421
|
+
if (!localPath) return undefined;
|
|
422
|
+
const runtimePath = runtimeName ? await this.aspectLoader.getRuntimePath(component, localPath, runtimeName) : null;
|
|
423
|
+
const aspectFilePath = await this.aspectLoader.getAspectFilePath(component, localPath);
|
|
424
|
+
this.logger.debug(`workspace resolveInstalledAspects, resolving id: ${compStringId}, localPath: ${localPath}, runtimePath: ${runtimePath}`);
|
|
425
|
+
return {
|
|
426
|
+
aspectPath: localPath,
|
|
427
|
+
aspectFilePath,
|
|
428
|
+
runtimePath
|
|
429
|
+
};
|
|
430
|
+
};
|
|
431
|
+
return installedAspectsResolver;
|
|
432
|
+
}
|
|
433
|
+
resolveInstalledAspectRecursively(aspectComponent, rootIds, graph, opts = {
|
|
434
|
+
throwOnError: false
|
|
435
|
+
}) {
|
|
436
|
+
const aspectStringId = aspectComponent.id._legacy.toString();
|
|
437
|
+
if (this.resolvedInstalledAspects.has(aspectStringId)) {
|
|
438
|
+
const resolvedPath = this.resolvedInstalledAspects.get(aspectStringId);
|
|
439
|
+
return resolvedPath;
|
|
440
|
+
}
|
|
441
|
+
if (rootIds.includes(aspectStringId)) {
|
|
442
|
+
const localPath = this.workspace.getComponentPackagePath(aspectComponent);
|
|
443
|
+
this.resolvedInstalledAspects.set(aspectStringId, localPath);
|
|
444
|
+
return localPath;
|
|
445
|
+
}
|
|
446
|
+
const parent = graph.predecessors(aspectStringId)[0];
|
|
447
|
+
const parentPath = this.resolveInstalledAspectRecursively(parent.attr, rootIds, graph);
|
|
448
|
+
if (!parentPath) {
|
|
449
|
+
this.resolvedInstalledAspects.set(aspectStringId, null);
|
|
450
|
+
return undefined;
|
|
451
|
+
}
|
|
452
|
+
const packageName = this.dependencyResolver.getPackageName(aspectComponent);
|
|
453
|
+
try {
|
|
454
|
+
const resolvedPath = (0, _toolboxModules().resolveFrom)(parentPath, [packageName]);
|
|
455
|
+
const localPath = (0, _findRoot().default)(resolvedPath);
|
|
456
|
+
this.resolvedInstalledAspects.set(aspectStringId, localPath);
|
|
457
|
+
return localPath;
|
|
458
|
+
} catch (error) {
|
|
459
|
+
this.resolvedInstalledAspects.set(aspectStringId, null);
|
|
460
|
+
if (opts.throwOnError) {
|
|
461
|
+
throw error;
|
|
462
|
+
}
|
|
463
|
+
this.logger.consoleWarning(`failed resolving aspect ${aspectStringId} from ${parentPath}, error: ${error.message}`);
|
|
464
|
+
return undefined;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Create a graph of aspects without the core aspects.
|
|
470
|
+
* @param components
|
|
471
|
+
* @param isAspect
|
|
472
|
+
* @returns
|
|
473
|
+
*/
|
|
474
|
+
async getAspectsGraphWithoutCore(components, isAspect) {
|
|
475
|
+
const ids = components.map(component => component.id);
|
|
476
|
+
const coreAspectsStringIds = this.aspectLoader.getCoreAspectIds();
|
|
477
|
+
// TODO: @gilad it causes many issues we need to find a better solution. removed for now.
|
|
478
|
+
// const coreAspectsComponentIds = coreAspectsStringIds.map((id) => BitId.parse(id, true));
|
|
479
|
+
// const aspectsIds = components.reduce((acc, curr) => {
|
|
480
|
+
// const currIds = curr.state.aspects.ids;
|
|
481
|
+
// acc = acc.concat(currIds);
|
|
482
|
+
// return acc;
|
|
483
|
+
// }, [] as any);
|
|
484
|
+
// const otherDependenciesMap = components.reduce((acc, curr) => {
|
|
485
|
+
// // const currIds = curr.state.dependencies.dependencies.map(dep => dep.id.toString());
|
|
486
|
+
// const currMap = curr.state.dependencies.getIdsMap();
|
|
487
|
+
// Object.assign(acc, currMap);
|
|
488
|
+
// return acc;
|
|
489
|
+
// }, {});
|
|
490
|
+
|
|
491
|
+
// const depsWhichAreNotAspects = difference(Object.keys(otherDependenciesMap), aspectsIds);
|
|
492
|
+
// const depsWhichAreNotAspectsBitIds = depsWhichAreNotAspects.map((strId) => otherDependenciesMap[strId]);
|
|
493
|
+
// We only want to load into the graph components which are aspects and not regular dependencies
|
|
494
|
+
// 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
|
|
495
|
+
return this.workspace.buildOneGraphForComponents(ids, coreAspectsStringIds, isAspect);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Load all unloaded extensions from an extension list
|
|
500
|
+
* this will resolve the extensions from the scope aspects capsules if they are not in the ws
|
|
501
|
+
* Only use it for component extensions
|
|
502
|
+
* for workspace/scope root aspect use the load aspects directly
|
|
503
|
+
*
|
|
504
|
+
* The reason we are loading component extensions with "scope aspects capsules" is becasuse for component extensions
|
|
505
|
+
* we might have the same extension in multiple versions
|
|
506
|
+
* (for example I might have 2 components using different versions of the same env)
|
|
507
|
+
* in such case, I can't install both version into the root of the node_modules so I need to place it somewhere else (capsules)
|
|
508
|
+
* @param extensions list of extensions with config to load
|
|
509
|
+
*/
|
|
510
|
+
async loadComponentsExtensions(extensions, originatedFrom, throwOnError = false) {
|
|
511
|
+
const extensionsIdsP = extensions.map(async extensionEntry => {
|
|
512
|
+
// Core extension
|
|
513
|
+
if (!extensionEntry.extensionId) {
|
|
514
|
+
return extensionEntry.stringId;
|
|
515
|
+
}
|
|
516
|
+
const id = await this.workspace.resolveComponentId(extensionEntry.extensionId);
|
|
517
|
+
// return this.resolveComponentId(extensionEntry.extensionId);
|
|
518
|
+
return id.toString();
|
|
519
|
+
});
|
|
520
|
+
const extensionsIds = await Promise.all(extensionsIdsP);
|
|
521
|
+
const loadedExtensions = this.harmony.extensionsIds;
|
|
522
|
+
const extensionsToLoad = (0, _lodash().difference)(extensionsIds, loadedExtensions);
|
|
523
|
+
if (!extensionsToLoad.length) return;
|
|
524
|
+
await this.loadAspects(extensionsToLoad, throwOnError, originatedFrom === null || originatedFrom === void 0 ? void 0 : originatedFrom.toString(), {
|
|
525
|
+
useScopeAspectsCapsule: true
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
async isAspect(id) {
|
|
529
|
+
const component = await this.workspace.get(id);
|
|
530
|
+
const isUsingAspectEnv = this.envs.isUsingAspectEnv(component);
|
|
531
|
+
const isUsingEnvEnv = this.envs.isUsingEnvEnv(component);
|
|
532
|
+
const isValidAspect = isUsingAspectEnv || isUsingEnvEnv;
|
|
533
|
+
return isValidAspect;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* same as `this.importAndGetMany()` with a specific error handling of ComponentNotFound
|
|
538
|
+
*/
|
|
539
|
+
async importAndGetAspects(componentIds) {
|
|
540
|
+
try {
|
|
541
|
+
return await this.workspace.importAndGetMany(componentIds);
|
|
542
|
+
} catch (err) {
|
|
543
|
+
if (err instanceof _exceptions().ComponentNotFound) {
|
|
544
|
+
var _config$workspaceConf2;
|
|
545
|
+
const config = this.harmony.get('teambit.harmony/config');
|
|
546
|
+
const configStr = JSON.stringify(((_config$workspaceConf2 = config.workspaceConfig) === null || _config$workspaceConf2 === void 0 ? void 0 : _config$workspaceConf2.raw) || {});
|
|
547
|
+
if (configStr.includes(err.id)) {
|
|
548
|
+
throw new (_bitError().BitError)(`error: a component "${err.id}" was not found
|
|
549
|
+
your workspace.jsonc has this component-id set. you might want to remove/change it.`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
throw err;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* split the provided components into 2 groups, one which are workspace components and the other which are not.
|
|
558
|
+
* @param components
|
|
559
|
+
* @returns
|
|
560
|
+
*/
|
|
561
|
+
async groupComponentsByWorkspaceExistence(components) {
|
|
562
|
+
const workspaceComps = [];
|
|
563
|
+
const nonWorkspaceComps = [];
|
|
564
|
+
await Promise.all(components.map(async component => {
|
|
565
|
+
const existOnWorkspace = await this.workspace.hasId(component.id);
|
|
566
|
+
existOnWorkspace ? workspaceComps.push(component) : nonWorkspaceComps.push(component);
|
|
567
|
+
}));
|
|
568
|
+
return {
|
|
569
|
+
workspaceComps,
|
|
570
|
+
nonWorkspaceComps
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
async groupIdsByWorkspaceExistence(ids) {
|
|
574
|
+
const workspaceIds = [];
|
|
575
|
+
const nonWorkspaceIds = [];
|
|
576
|
+
await Promise.all(ids.map(async id => {
|
|
577
|
+
const existOnWorkspace = await this.workspace.hasId(id);
|
|
578
|
+
existOnWorkspace ? workspaceIds.push(id) : nonWorkspaceIds.push(id);
|
|
579
|
+
}));
|
|
580
|
+
return {
|
|
581
|
+
workspaceIds,
|
|
582
|
+
nonWorkspaceIds
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
exports.WorkspaceAspectsLoader = WorkspaceAspectsLoader;
|
|
587
|
+
|
|
588
|
+
//# sourceMappingURL=workspace-aspects-loader.js.map
|