@teambit/scope 1.0.106 → 1.0.108
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/clear-cache-action.ts +11 -0
- package/dist/get-scope-options.d.ts +1 -1
- package/dist/{preview-1703505948637.js → preview-1703647408454.js} +2 -2
- package/dist/scope-aspects-loader.d.ts +4 -4
- package/dist/scope-aspects-loader.js +8 -9
- package/dist/scope-aspects-loader.js.map +1 -1
- package/dist/scope-cmd.d.ts +1 -1
- package/dist/scope-component-loader.js +2 -2
- package/dist/scope-component-loader.js.map +1 -1
- package/dist/scope.composition.d.ts +2 -2
- package/dist/scope.graphql.d.ts +4 -4
- package/dist/scope.main.runtime.d.ts +30 -22
- package/dist/scope.main.runtime.js +37 -15
- package/dist/scope.main.runtime.js.map +1 -1
- package/dist/scope.ui-root.d.ts +2 -2
- package/dist/scope.ui.drawer.d.ts +1 -1
- package/dist/scope.ui.drawer.js +6 -8
- package/dist/scope.ui.drawer.js.map +1 -1
- package/dist/scope.ui.runtime.d.ts +14 -14
- package/dist/scope.ui.runtime.js +8 -11
- package/dist/scope.ui.runtime.js.map +1 -1
- package/dist/staged-config.d.ts +3 -3
- package/dist/staged-config.js +2 -3
- package/dist/staged-config.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/ui/menu/menu.d.ts +4 -4
- package/dist/ui/scope-overview/scope-overview.d.ts +5 -5
- package/dist/ui/scope-overview/scope-overview.js +2 -4
- package/dist/ui/scope-overview/scope-overview.js.map +1 -1
- package/dist/ui/scope.d.ts +3 -3
- package/dist/ui/scope.js +1 -1
- package/dist/ui/scope.js.map +1 -1
- package/get-scope-options.ts +16 -0
- package/index.ts +11 -0
- package/package.json +33 -40
- package/scope-aspects-loader.ts +493 -0
- package/scope-cmd.ts +17 -0
- package/scope-component-loader.ts +208 -0
- package/scope.aspect.ts +7 -0
- package/scope.graphql.ts +115 -0
- package/scope.main.runtime.ts +1263 -0
- package/scope.ui-root.ts +43 -0
- package/scope.ui.runtime.tsx +1 -0
- package/staged-config.ts +79 -0
- package/tsconfig.json +16 -21
- package/types/asset.d.ts +15 -3
- package/types.ts +12 -0
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
import { GlobalConfigMain } from '@teambit/global-config';
|
|
2
|
+
import mapSeries from 'p-map-series';
|
|
3
|
+
import { Lane } from '@teambit/legacy/dist/scope/models';
|
|
4
|
+
import { existsSync } from 'fs-extra';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_DIST_DIRNAME,
|
|
8
|
+
CFG_CAPSULES_SCOPES_ASPECTS_BASE_DIR,
|
|
9
|
+
CFG_CAPSULES_GLOBAL_SCOPE_ASPECTS_BASE_DIR,
|
|
10
|
+
CFG_USE_DATED_CAPSULES,
|
|
11
|
+
CFG_CACHE_LOCK_ONLY_CAPSULES,
|
|
12
|
+
} from '@teambit/legacy/dist/constants';
|
|
13
|
+
import { Compiler, TranspileFileOutputOneFile } from '@teambit/compiler';
|
|
14
|
+
import { Capsule, IsolateComponentsOptions, IsolatorMain } from '@teambit/isolator';
|
|
15
|
+
import { AspectLoaderMain, AspectDefinition } from '@teambit/aspect-loader';
|
|
16
|
+
import { compact, uniq, difference, groupBy, defaultsDeep } from 'lodash';
|
|
17
|
+
import { MainRuntime } from '@teambit/cli';
|
|
18
|
+
import { RequireableComponent } from '@teambit/harmony.modules.requireable-component';
|
|
19
|
+
import { ExtensionManifest, Aspect } from '@teambit/harmony';
|
|
20
|
+
import { Component, ComponentID, LoadAspectsOptions, ResolveAspectsOptions } from '@teambit/component';
|
|
21
|
+
import { ScopeMain } from '@teambit/scope';
|
|
22
|
+
import { Logger } from '@teambit/logger';
|
|
23
|
+
import { EnvsMain } from '@teambit/envs';
|
|
24
|
+
import { NodeLinker } from '@teambit/dependency-resolver';
|
|
25
|
+
|
|
26
|
+
type ManifestOrAspect = ExtensionManifest | Aspect;
|
|
27
|
+
|
|
28
|
+
export type ScopeLoadAspectsOptions = LoadAspectsOptions & {
|
|
29
|
+
useScopeAspectsCapsule?: boolean;
|
|
30
|
+
packageManagerConfigRootDir?: string;
|
|
31
|
+
workspaceName?: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export class ScopeAspectsLoader {
|
|
35
|
+
constructor(
|
|
36
|
+
private scope: ScopeMain,
|
|
37
|
+
private aspectLoader: AspectLoaderMain,
|
|
38
|
+
private envs: EnvsMain,
|
|
39
|
+
private isolator: IsolatorMain,
|
|
40
|
+
private logger: Logger,
|
|
41
|
+
private globalConfig: GlobalConfigMain
|
|
42
|
+
) {}
|
|
43
|
+
|
|
44
|
+
async loadAspects(
|
|
45
|
+
ids: string[],
|
|
46
|
+
throwOnError = false,
|
|
47
|
+
neededFor?: string,
|
|
48
|
+
lane?: Lane,
|
|
49
|
+
opts?: ScopeLoadAspectsOptions
|
|
50
|
+
): Promise<string[]> {
|
|
51
|
+
if (!ids.length) return [];
|
|
52
|
+
// generate a random callId to be able to identify the call from the logs
|
|
53
|
+
const callId = Math.floor(Math.random() * 1000);
|
|
54
|
+
const loggerPrefix = `[${callId}] loadAspects,`;
|
|
55
|
+
this.logger.info(`${loggerPrefix} loading ${ids.length} aspects.
|
|
56
|
+
ids: ${ids.join(', ')}
|
|
57
|
+
needed-for: ${neededFor || '<unknown>'}`);
|
|
58
|
+
const grouped = await this.groupAspectIdsByEnvOfTheList(ids, lane);
|
|
59
|
+
this.logger.info(`${loggerPrefix} getManifestsAndLoadAspects for grouped.envs, total ${grouped.envs?.length || 0}`);
|
|
60
|
+
const envsManifestsIds = await this.getManifestsAndLoadAspects(grouped.envs, throwOnError, lane, opts);
|
|
61
|
+
this.logger.info(
|
|
62
|
+
`${loggerPrefix} getManifestsAndLoadAspects for grouped.other, total ${grouped.other?.length || 0}`
|
|
63
|
+
);
|
|
64
|
+
const otherManifestsIds = await this.getManifestsAndLoadAspects(grouped.other, throwOnError, lane, opts);
|
|
65
|
+
this.logger.debug(`${loggerPrefix} finish loading aspects`);
|
|
66
|
+
return envsManifestsIds.concat(otherManifestsIds);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* This function get's a list of aspect ids and return them grouped by whether any of them is the env of other from the list
|
|
71
|
+
* @param ids
|
|
72
|
+
*/
|
|
73
|
+
async groupAspectIdsByEnvOfTheList(ids: string[], lane?: Lane): Promise<{ envs?: string[]; other?: string[] }> {
|
|
74
|
+
const components = await this.getNonLoadedAspects(ids, lane);
|
|
75
|
+
const envsIds = uniq(
|
|
76
|
+
components
|
|
77
|
+
.map((component) => this.envs.getEnvId(component))
|
|
78
|
+
.filter((envId) => !this.aspectLoader.isCoreEnv(envId))
|
|
79
|
+
);
|
|
80
|
+
const grouped = groupBy(ids, (id) => {
|
|
81
|
+
if (envsIds.includes(id)) return 'envs';
|
|
82
|
+
return 'other';
|
|
83
|
+
});
|
|
84
|
+
return grouped as { envs: string[]; other: string[] };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private async getManifestsAndLoadAspects(
|
|
88
|
+
ids: string[] = [],
|
|
89
|
+
throwOnError = false,
|
|
90
|
+
lane?: Lane,
|
|
91
|
+
opts?: ScopeLoadAspectsOptions
|
|
92
|
+
): Promise<string[]> {
|
|
93
|
+
const { manifests: scopeManifests, potentialPluginsIds } = await this.getManifestsGraphRecursively(
|
|
94
|
+
ids,
|
|
95
|
+
[],
|
|
96
|
+
throwOnError,
|
|
97
|
+
lane,
|
|
98
|
+
opts
|
|
99
|
+
);
|
|
100
|
+
await this.aspectLoader.loadExtensionsByManifests(scopeManifests);
|
|
101
|
+
const { manifests: scopePluginsManifests } = await this.getManifestsGraphRecursively(
|
|
102
|
+
potentialPluginsIds,
|
|
103
|
+
[],
|
|
104
|
+
throwOnError,
|
|
105
|
+
lane,
|
|
106
|
+
opts
|
|
107
|
+
);
|
|
108
|
+
await this.aspectLoader.loadExtensionsByManifests(scopePluginsManifests);
|
|
109
|
+
const allManifests = scopeManifests.concat(scopePluginsManifests);
|
|
110
|
+
return compact(allManifests.map((manifest) => manifest.id));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async getManifestsGraphRecursively(
|
|
114
|
+
ids: string[],
|
|
115
|
+
visited: string[] = [],
|
|
116
|
+
throwOnError = false,
|
|
117
|
+
lane?: Lane,
|
|
118
|
+
opts: {
|
|
119
|
+
packageManagerConfigRootDir?: string;
|
|
120
|
+
workspaceName?: string;
|
|
121
|
+
} = {}
|
|
122
|
+
): Promise<{ manifests: ManifestOrAspect[]; potentialPluginsIds: string[] }> {
|
|
123
|
+
ids = uniq(ids);
|
|
124
|
+
this.logger.debug(`getManifestsGraphRecursively, ids:\n${ids.join('\n')}`);
|
|
125
|
+
const nonVisitedId = ids.filter((id) => !visited.includes(id));
|
|
126
|
+
if (!nonVisitedId.length) {
|
|
127
|
+
return { manifests: [], potentialPluginsIds: [] };
|
|
128
|
+
}
|
|
129
|
+
const components = await this.getNonLoadedAspects(nonVisitedId, lane);
|
|
130
|
+
// Adding all the envs ids to the array to support case when one (or more) of the aspects has custom aspect env
|
|
131
|
+
const customEnvsIds = components
|
|
132
|
+
.map((component) => this.envs.getEnvId(component))
|
|
133
|
+
.filter((envId) => !this.aspectLoader.isCoreEnv(envId));
|
|
134
|
+
// In case there is custom env we need to load it right away, otherwise we will fail during the require aspects
|
|
135
|
+
await this.getManifestsAndLoadAspects(customEnvsIds, undefined, lane);
|
|
136
|
+
visited.push(...nonVisitedId);
|
|
137
|
+
const manifests = await this.requireAspects(components, throwOnError, opts);
|
|
138
|
+
const potentialPluginsIds = compact(
|
|
139
|
+
manifests.map((manifest, index) => {
|
|
140
|
+
if (this.aspectLoader.isValidAspect(manifest)) return undefined;
|
|
141
|
+
// return index;
|
|
142
|
+
return components[index].id.toString();
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const depsToLoad: Array<ExtensionManifest | Aspect> = [];
|
|
147
|
+
await mapSeries(manifests, async (manifest) => {
|
|
148
|
+
depsToLoad.push(...(manifest.dependencies || []));
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
(manifest._runtimes || []).forEach((runtime) => {
|
|
151
|
+
depsToLoad.push(...(runtime.dependencies || []));
|
|
152
|
+
});
|
|
153
|
+
const depIds = depsToLoad.map((d) => d.id).filter((id) => id) as string[];
|
|
154
|
+
this.logger.debug(
|
|
155
|
+
`getManifestsGraphRecursively, id: ${manifest.id || '<unknown>'}, found ${depIds.length}: ${depIds.join(', ')}`
|
|
156
|
+
);
|
|
157
|
+
const { manifests: loaded } = await this.getManifestsGraphRecursively(depIds, visited, throwOnError, lane);
|
|
158
|
+
manifests.push(...loaded);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
return { manifests, potentialPluginsIds };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private async getNonLoadedAspects(ids: string[], lane?: Lane): Promise<Component[]> {
|
|
165
|
+
const notLoadedIds = ids.filter((id) => !this.aspectLoader.isAspectLoaded(id));
|
|
166
|
+
if (!notLoadedIds.length) return [];
|
|
167
|
+
const coreAspectsStringIds = this.aspectLoader.getCoreAspectIds();
|
|
168
|
+
const idsWithoutCore: string[] = difference(ids, coreAspectsStringIds);
|
|
169
|
+
const aspectIds = idsWithoutCore.filter((id) => !id.startsWith('file://'));
|
|
170
|
+
// TODO: use diff instead of filter twice
|
|
171
|
+
const localAspects = ids.filter((id) => id.startsWith('file://'));
|
|
172
|
+
this.scope.localAspects = uniq(this.scope.localAspects.concat(localAspects));
|
|
173
|
+
// load local aspects for debugging purposes.
|
|
174
|
+
await this.aspectLoader.loadAspectFromPath(localAspects);
|
|
175
|
+
const componentIds = await this.scope.resolveMultipleComponentIds(aspectIds);
|
|
176
|
+
if (!componentIds || !componentIds.length) return [];
|
|
177
|
+
await this.scope.import(componentIds, {
|
|
178
|
+
reFetchUnBuiltVersion: false,
|
|
179
|
+
lane,
|
|
180
|
+
reason: 'for loading aspects from the scope',
|
|
181
|
+
});
|
|
182
|
+
const components = await this.scope.getMany(componentIds);
|
|
183
|
+
|
|
184
|
+
return components;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async getResolvedAspects(
|
|
188
|
+
components: Component[],
|
|
189
|
+
opts?: { skipIfExists?: boolean; packageManagerConfigRootDir?: string; workspaceName?: string }
|
|
190
|
+
): Promise<RequireableComponent[]> {
|
|
191
|
+
if (!components || !components.length) return [];
|
|
192
|
+
const isolateOpts = this.getIsolateOpts(opts);
|
|
193
|
+
const network = await this.isolator.isolateComponents(
|
|
194
|
+
components.map((c) => c.id),
|
|
195
|
+
// includeFromNestedHosts - to support case when you are in a workspace, trying to load aspect defined in the workspace.jsonc but not part of the workspace
|
|
196
|
+
isolateOpts,
|
|
197
|
+
this.scope.legacyScope
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
const capsules = network.seedersCapsules;
|
|
201
|
+
|
|
202
|
+
return capsules.map((capsule) => {
|
|
203
|
+
return new RequireableComponent(
|
|
204
|
+
capsule.component,
|
|
205
|
+
async () => {
|
|
206
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
207
|
+
const plugins = this.aspectLoader.getPlugins(capsule.component, capsule.path);
|
|
208
|
+
if (plugins.has()) {
|
|
209
|
+
await this.compileIfNoDist(capsule, capsule.component);
|
|
210
|
+
return plugins.load(MainRuntime.name);
|
|
211
|
+
}
|
|
212
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
213
|
+
const aspect = require(capsule.path);
|
|
214
|
+
const scopeRuntime = await this.aspectLoader.getRuntimePath(capsule.component, capsule.path, 'scope');
|
|
215
|
+
const mainRuntime = await this.aspectLoader.getRuntimePath(capsule.component, capsule.path, MainRuntime.name);
|
|
216
|
+
const runtimePath = scopeRuntime || mainRuntime;
|
|
217
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
218
|
+
if (runtimePath) require(runtimePath);
|
|
219
|
+
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
220
|
+
return aspect;
|
|
221
|
+
},
|
|
222
|
+
capsule
|
|
223
|
+
);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private async compileIfNoDist(capsule: Capsule, component: Component) {
|
|
228
|
+
const env = this.envs.getEnv(component);
|
|
229
|
+
const compiler: Compiler = env.env.getCompiler();
|
|
230
|
+
const distDir = compiler?.distDir || DEFAULT_DIST_DIRNAME;
|
|
231
|
+
const distExists = existsSync(join(capsule.path, distDir));
|
|
232
|
+
if (distExists) return;
|
|
233
|
+
|
|
234
|
+
const compiledCode = (
|
|
235
|
+
await Promise.all(
|
|
236
|
+
component.filesystem.files.flatMap(async (file) => {
|
|
237
|
+
if (!compiler.isFileSupported(file.path)) {
|
|
238
|
+
return [
|
|
239
|
+
{
|
|
240
|
+
outputText: file.contents.toString('utf8'),
|
|
241
|
+
outputPath: file.path,
|
|
242
|
+
},
|
|
243
|
+
] as TranspileFileOutputOneFile[];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (compiler.transpileFile) {
|
|
247
|
+
return compiler.transpileFile(file.contents.toString('utf8'), {
|
|
248
|
+
filePath: file.path,
|
|
249
|
+
componentDir: capsule.path,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return [];
|
|
254
|
+
})
|
|
255
|
+
)
|
|
256
|
+
).flat();
|
|
257
|
+
|
|
258
|
+
await Promise.all(
|
|
259
|
+
compact(compiledCode).map((compiledFile) => {
|
|
260
|
+
const path = compiler.getDistPathBySrcPath(compiledFile.outputPath);
|
|
261
|
+
return capsule?.outputFile(path, compiledFile.outputText);
|
|
262
|
+
})
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
private async tryCompile(requirableAspect: RequireableComponent) {
|
|
267
|
+
if (requirableAspect.capsule) return this.compileIfNoDist(requirableAspect.capsule, requirableAspect.component);
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async requireAspects(
|
|
272
|
+
components: Component[],
|
|
273
|
+
throwOnError = false,
|
|
274
|
+
opts: { packageManagerConfigRootDir?: string; workspaceName?: string } = {}
|
|
275
|
+
): Promise<Array<ExtensionManifest | Aspect>> {
|
|
276
|
+
const requireableExtensions = await this.getResolvedAspects(components, opts);
|
|
277
|
+
if (!requireableExtensions) {
|
|
278
|
+
return [];
|
|
279
|
+
}
|
|
280
|
+
let error: any;
|
|
281
|
+
let erroredId = '';
|
|
282
|
+
const requireWithCatch = async (requireableAspects: RequireableComponent[]) => {
|
|
283
|
+
error = undefined;
|
|
284
|
+
try {
|
|
285
|
+
const manifests = await mapSeries(requireableAspects, async (requireableExtension) => {
|
|
286
|
+
try {
|
|
287
|
+
return await this.aspectLoader.doRequire(requireableExtension);
|
|
288
|
+
} catch (err: any) {
|
|
289
|
+
erroredId = requireableExtension.component.id.toString();
|
|
290
|
+
if (err.code === 'MODULE_NOT_FOUND') {
|
|
291
|
+
try {
|
|
292
|
+
await this.tryCompile(requireableExtension);
|
|
293
|
+
return await this.aspectLoader.doRequire(requireableExtension);
|
|
294
|
+
} catch (newErr: any) {
|
|
295
|
+
error = newErr;
|
|
296
|
+
throw newErr;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
error = err;
|
|
300
|
+
throw err;
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
return manifests;
|
|
304
|
+
} catch (err) {
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
const manifests = await requireWithCatch(requireableExtensions);
|
|
309
|
+
if (!error) {
|
|
310
|
+
return compact(manifests);
|
|
311
|
+
}
|
|
312
|
+
if (error.code === 'MODULE_NOT_FOUND') {
|
|
313
|
+
this.logger.warn(
|
|
314
|
+
`failed loading aspects from capsules due to MODULE_NOT_FOUND error, re-creating the capsules and trying again`
|
|
315
|
+
);
|
|
316
|
+
const resolvedAspectsAgain = await this.getResolvedAspects(components, {
|
|
317
|
+
...opts,
|
|
318
|
+
skipIfExists: false,
|
|
319
|
+
});
|
|
320
|
+
const manifestAgain = await requireWithCatch(resolvedAspectsAgain);
|
|
321
|
+
if (!error) {
|
|
322
|
+
return compact(manifestAgain);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
this.aspectLoader.handleExtensionLoadingError(error, erroredId, throwOnError);
|
|
327
|
+
return [];
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
shouldUseDatedCapsules(): boolean {
|
|
331
|
+
const globalConfig = this.globalConfig.getSync(CFG_USE_DATED_CAPSULES);
|
|
332
|
+
// @ts-ignore
|
|
333
|
+
return globalConfig === true || globalConfig === 'true';
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
shouldCacheLockFileOnly(): boolean {
|
|
337
|
+
const globalConfig = this.globalConfig.getSync(CFG_CACHE_LOCK_ONLY_CAPSULES);
|
|
338
|
+
// @ts-ignore
|
|
339
|
+
return globalConfig === true || globalConfig === 'true';
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
getAspectCapsulePath() {
|
|
343
|
+
const defaultPath = `${this.scope.path}-aspects`;
|
|
344
|
+
if (this.scope.isGlobalScope) {
|
|
345
|
+
return this.globalConfig.getSync(CFG_CAPSULES_GLOBAL_SCOPE_ASPECTS_BASE_DIR) || defaultPath;
|
|
346
|
+
}
|
|
347
|
+
return this.globalConfig.getSync(CFG_CAPSULES_SCOPES_ASPECTS_BASE_DIR) || defaultPath;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
shouldUseHashForCapsules(): boolean {
|
|
351
|
+
if (this.scope.isGlobalScope) {
|
|
352
|
+
return !this.globalConfig.getSync(CFG_CAPSULES_GLOBAL_SCOPE_ASPECTS_BASE_DIR);
|
|
353
|
+
}
|
|
354
|
+
return !this.globalConfig.getSync(CFG_CAPSULES_SCOPES_ASPECTS_BASE_DIR);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
getAspectsPackageManager(): string | undefined {
|
|
358
|
+
return this.scope.aspectsPackageManager;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
getAspectsNodeLinker(): NodeLinker | undefined {
|
|
362
|
+
return this.scope.aspectsNodeLinker;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
private async resolveUserAspects(
|
|
366
|
+
runtimeName?: string,
|
|
367
|
+
userAspectsIds?: ComponentID[],
|
|
368
|
+
opts?: ResolveAspectsOptions
|
|
369
|
+
): Promise<AspectDefinition[]> {
|
|
370
|
+
if (!userAspectsIds || !userAspectsIds.length) return [];
|
|
371
|
+
const components = await this.scope.getMany(userAspectsIds);
|
|
372
|
+
const isolateOpts = this.getIsolateOpts(opts);
|
|
373
|
+
const network = await this.isolator.isolateComponents(userAspectsIds, isolateOpts, this.scope.legacyScope);
|
|
374
|
+
|
|
375
|
+
const capsules = network.seedersCapsules;
|
|
376
|
+
const aspectDefs = await this.aspectLoader.resolveAspects(components, async (component) => {
|
|
377
|
+
const capsule = capsules.getCapsule(component.id);
|
|
378
|
+
if (!capsule) throw new Error(`failed loading aspect: ${component.id.toString()}`);
|
|
379
|
+
const localPath = capsule.path;
|
|
380
|
+
const runtimePath = runtimeName
|
|
381
|
+
? await this.aspectLoader.getRuntimePath(component, localPath, runtimeName)
|
|
382
|
+
: null;
|
|
383
|
+
const aspectFilePath = await this.aspectLoader.getAspectFilePath(component, localPath);
|
|
384
|
+
|
|
385
|
+
this.logger.debug(
|
|
386
|
+
`scope resolveUserAspects, resolving id: ${component.id.toString()}, localPath: ${localPath}, runtimePath: ${runtimePath}`
|
|
387
|
+
);
|
|
388
|
+
|
|
389
|
+
return {
|
|
390
|
+
id: capsule.component.id,
|
|
391
|
+
aspectPath: localPath,
|
|
392
|
+
aspectFilePath,
|
|
393
|
+
runtimePath,
|
|
394
|
+
};
|
|
395
|
+
});
|
|
396
|
+
return aspectDefs;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
async resolveAspects(
|
|
400
|
+
runtimeName?: string,
|
|
401
|
+
componentIds?: ComponentID[],
|
|
402
|
+
opts?: ResolveAspectsOptions
|
|
403
|
+
): Promise<AspectDefinition[]> {
|
|
404
|
+
const originalStringIds = componentIds?.map((id) => id.toString());
|
|
405
|
+
this.logger.debug(`scope resolveAspects, runtimeName: ${runtimeName}, componentIds: ${originalStringIds}`);
|
|
406
|
+
|
|
407
|
+
const defaultOpts: ResolveAspectsOptions = {
|
|
408
|
+
excludeCore: false,
|
|
409
|
+
requestedOnly: false,
|
|
410
|
+
filterByRuntime: true,
|
|
411
|
+
};
|
|
412
|
+
const mergedOpts = { ...defaultOpts, ...opts };
|
|
413
|
+
const coreAspectsIds = this.aspectLoader.getCoreAspectIds();
|
|
414
|
+
let userAspectsIds: ComponentID[];
|
|
415
|
+
// let requestedCoreStringIds;
|
|
416
|
+
if (componentIds && componentIds.length) {
|
|
417
|
+
const groupedByIsCore = groupBy(componentIds, (id) => coreAspectsIds.includes(id.toString()));
|
|
418
|
+
userAspectsIds = groupedByIsCore.false || [];
|
|
419
|
+
// requestedCoreStringIds = groupedByIsCore.true?.map((id) => id.toStringWithoutVersion()) || [];
|
|
420
|
+
} else {
|
|
421
|
+
userAspectsIds = await this.scope.resolveMultipleComponentIds(this.aspectLoader.getUserAspects());
|
|
422
|
+
}
|
|
423
|
+
const localResolved = await this.aspectLoader.resolveLocalAspects(this.scope.localAspects, runtimeName);
|
|
424
|
+
|
|
425
|
+
const withoutLocalAspects = userAspectsIds.filter((aspectId) => {
|
|
426
|
+
return !localResolved.find((localAspect) => {
|
|
427
|
+
return localAspect.id === aspectId.toStringWithoutVersion();
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
const userAspectsDefs = await this.resolveUserAspects(runtimeName, withoutLocalAspects, opts);
|
|
431
|
+
const coreAspectsDefs = await this.aspectLoader.getCoreAspectDefs(runtimeName);
|
|
432
|
+
|
|
433
|
+
const allDefs = userAspectsDefs.concat(coreAspectsDefs).concat(localResolved);
|
|
434
|
+
// const userAspectsIdsWithoutVersion = userAspectsIds.map((aspectId) => aspectId.toStringWithoutVersion());
|
|
435
|
+
// const userAspectsIdsWithoutVersionAndCoreRequested = userAspectsIdsWithoutVersion.concat(requestedCoreStringIds);
|
|
436
|
+
const filteredDefs = this.aspectLoader.filterAspectDefs(
|
|
437
|
+
allDefs,
|
|
438
|
+
componentIds || userAspectsIds,
|
|
439
|
+
runtimeName,
|
|
440
|
+
mergedOpts
|
|
441
|
+
);
|
|
442
|
+
return filteredDefs;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
getIsolateOpts(opts?: {
|
|
446
|
+
skipIfExists?: boolean;
|
|
447
|
+
packageManagerConfigRootDir?: string;
|
|
448
|
+
workspaceName?: string;
|
|
449
|
+
}): IsolateComponentsOptions {
|
|
450
|
+
const overrideOpts = {
|
|
451
|
+
skipIfExists: opts?.skipIfExists ?? true,
|
|
452
|
+
installOptions: {
|
|
453
|
+
packageManagerConfigRootDir: opts?.packageManagerConfigRootDir,
|
|
454
|
+
},
|
|
455
|
+
context: {
|
|
456
|
+
workspaceName: opts?.workspaceName,
|
|
457
|
+
},
|
|
458
|
+
};
|
|
459
|
+
const isolateOpts = defaultsDeep(overrideOpts, this.getDefaultIsolateOpts());
|
|
460
|
+
return isolateOpts;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
getDefaultIsolateOpts() {
|
|
464
|
+
const useHash = this.shouldUseHashForCapsules();
|
|
465
|
+
const useDatedDirs = this.shouldUseDatedCapsules();
|
|
466
|
+
const cacheLockFileOnly = this.shouldCacheLockFileOnly();
|
|
467
|
+
const nodeLinker = this.getAspectsNodeLinker();
|
|
468
|
+
|
|
469
|
+
const opts = {
|
|
470
|
+
datedDirId: this.scope.name,
|
|
471
|
+
baseDir: this.getAspectCapsulePath(),
|
|
472
|
+
useHash,
|
|
473
|
+
packageManager: this.getAspectsPackageManager(),
|
|
474
|
+
nodeLinker,
|
|
475
|
+
useDatedDirs,
|
|
476
|
+
cacheLockFileOnly,
|
|
477
|
+
skipIfExists: true,
|
|
478
|
+
seedersOnly: true,
|
|
479
|
+
includeFromNestedHosts: true,
|
|
480
|
+
host: this.scope,
|
|
481
|
+
installOptions: {
|
|
482
|
+
copyPeerToRuntimeOnRoot: true,
|
|
483
|
+
useNesting: true,
|
|
484
|
+
copyPeerToRuntimeOnComponents: true,
|
|
485
|
+
installPeersFromEnvs: true,
|
|
486
|
+
},
|
|
487
|
+
context: {
|
|
488
|
+
aspects: true,
|
|
489
|
+
},
|
|
490
|
+
};
|
|
491
|
+
return opts;
|
|
492
|
+
}
|
|
493
|
+
}
|
package/scope-cmd.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Command } from '@teambit/cli';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
|
|
4
|
+
export class ScopeCmd implements Command {
|
|
5
|
+
name = 'scope <sub-command>';
|
|
6
|
+
alias = '';
|
|
7
|
+
description = 'manage the scope-name for components';
|
|
8
|
+
options = [];
|
|
9
|
+
group = 'development';
|
|
10
|
+
commands: Command[] = [];
|
|
11
|
+
|
|
12
|
+
async report([unrecognizedSubcommand]: [string]) {
|
|
13
|
+
return chalk.red(
|
|
14
|
+
`"${unrecognizedSubcommand}" is not a subcommand of "scope", please run "bit scope --help" to list the subcommands`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
}
|