@teambit/aspect-loader 0.0.509 → 0.0.513
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/aspect-loader.main.runtime.ts +30 -19
- package/dist/aspect-loader.main.runtime.d.ts +2 -0
- package/dist/aspect-loader.main.runtime.js +33 -22
- package/dist/aspect-loader.main.runtime.js.map +1 -1
- package/package-tar/teambit-aspect-loader-0.0.513.tgz +0 -0
- package/package.json +9 -9
- package/package-tar/teambit-aspect-loader-0.0.509.tgz +0 -0
|
@@ -241,6 +241,18 @@ export class AspectLoaderMain {
|
|
|
241
241
|
this.failedLoadAspect.push(id);
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
+
/**
|
|
245
|
+
* run "require" of the component code to get the manifest
|
|
246
|
+
*/
|
|
247
|
+
async doRequire(requireableExtension: RequireableComponent): Promise<ExtensionManifest | Aspect> {
|
|
248
|
+
const idStr = requireableExtension.component.id.toString();
|
|
249
|
+
const aspect = await requireableExtension.require();
|
|
250
|
+
const manifest = aspect.default || aspect;
|
|
251
|
+
manifest.id = idStr;
|
|
252
|
+
const newManifest = await this.runOnLoadRequireableExtensionSubscribers(requireableExtension, manifest);
|
|
253
|
+
return newManifest;
|
|
254
|
+
}
|
|
255
|
+
|
|
244
256
|
/**
|
|
245
257
|
* in case the extension failed to load, prefer to throw an error, unless `throwOnError` param
|
|
246
258
|
* passed as `false`.
|
|
@@ -262,18 +274,11 @@ export class AspectLoaderMain {
|
|
|
262
274
|
* in some cases, such as "bit tag", it's better not to tag if an extension changes the model.
|
|
263
275
|
*/
|
|
264
276
|
async loadRequireableExtensions(requireableExtensions: RequireableComponent[], throwOnError = false): Promise<void> {
|
|
265
|
-
const doRequire = async (requireableExtension: RequireableComponent, idStr: string) => {
|
|
266
|
-
const aspect = await requireableExtension.require();
|
|
267
|
-
const manifest = aspect.default || aspect;
|
|
268
|
-
manifest.id = idStr;
|
|
269
|
-
const newManifest = await this.runOnLoadRequireableExtensionSubscribers(requireableExtension, manifest);
|
|
270
|
-
return newManifest;
|
|
271
|
-
};
|
|
272
277
|
const manifestsP = mapSeries(requireableExtensions, async (requireableExtension) => {
|
|
273
278
|
if (!requireableExtensions) return undefined;
|
|
274
279
|
const idStr = requireableExtension.component.id.toString();
|
|
275
280
|
try {
|
|
276
|
-
return await doRequire(requireableExtension
|
|
281
|
+
return await this.doRequire(requireableExtension);
|
|
277
282
|
} catch (e: any) {
|
|
278
283
|
this.addFailure(idStr);
|
|
279
284
|
const errorMsg = UNABLE_TO_LOAD_EXTENSION(idStr);
|
|
@@ -283,23 +288,14 @@ export class AspectLoaderMain {
|
|
|
283
288
|
if (isFixed) {
|
|
284
289
|
this.logger.info(`the loading issue has been fixed, re-loading ${idStr}`);
|
|
285
290
|
try {
|
|
286
|
-
return await doRequire(requireableExtension
|
|
291
|
+
return await this.doRequire(requireableExtension);
|
|
287
292
|
} catch (err: any) {
|
|
288
293
|
this.logger.error('re-load of the aspect failed as well', err);
|
|
289
294
|
errAfterReLoad = err;
|
|
290
295
|
}
|
|
291
296
|
}
|
|
292
297
|
const error = errAfterReLoad || e;
|
|
293
|
-
|
|
294
|
-
this.logger.console(error);
|
|
295
|
-
throw new CannotLoadExtension(idStr, error);
|
|
296
|
-
}
|
|
297
|
-
if (this.logger.isLoaderStarted) {
|
|
298
|
-
this.logger.consoleFailure(errorMsg);
|
|
299
|
-
} else {
|
|
300
|
-
this.logger.console(errorMsg);
|
|
301
|
-
this.logger.console(error.message);
|
|
302
|
-
}
|
|
298
|
+
this.handleExtensionLoadingError(error, idStr, throwOnError);
|
|
303
299
|
}
|
|
304
300
|
return undefined;
|
|
305
301
|
});
|
|
@@ -310,6 +306,21 @@ export class AspectLoaderMain {
|
|
|
310
306
|
return this.loadExtensionsByManifests(filteredManifests, throwOnError);
|
|
311
307
|
}
|
|
312
308
|
|
|
309
|
+
handleExtensionLoadingError(error: Error, idStr: string, throwOnError: boolean) {
|
|
310
|
+
const errorMsg = UNABLE_TO_LOAD_EXTENSION(idStr);
|
|
311
|
+
if (throwOnError) {
|
|
312
|
+
// @ts-ignore
|
|
313
|
+
this.logger.console(error);
|
|
314
|
+
throw new CannotLoadExtension(idStr, error);
|
|
315
|
+
}
|
|
316
|
+
if (this.logger.isLoaderStarted) {
|
|
317
|
+
this.logger.consoleFailure(errorMsg);
|
|
318
|
+
} else {
|
|
319
|
+
this.logger.console(errorMsg);
|
|
320
|
+
this.logger.console(error.message);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
313
324
|
async runOnLoadRequireableExtensionSubscribers(
|
|
314
325
|
requireableExtension: RequireableComponent,
|
|
315
326
|
manifest: ExtensionManifest | Aspect
|
|
@@ -57,7 +57,9 @@ export declare class AspectLoaderMain {
|
|
|
57
57
|
private failedLoadAspect;
|
|
58
58
|
get failedAspects(): string[];
|
|
59
59
|
private addFailure;
|
|
60
|
+
doRequire(requireableExtension: RequireableComponent): Promise<ExtensionManifest | Aspect>;
|
|
60
61
|
loadRequireableExtensions(requireableExtensions: RequireableComponent[], throwOnError?: boolean): Promise<void>;
|
|
62
|
+
handleExtensionLoadingError(error: Error, idStr: string, throwOnError: boolean): void;
|
|
61
63
|
runOnLoadRequireableExtensionSubscribers(requireableExtension: RequireableComponent, manifest: ExtensionManifest | Aspect): Promise<ExtensionManifest | Aspect>;
|
|
62
64
|
isAspect(manifest: any): boolean;
|
|
63
65
|
loadAspectsFromGlobalScope(aspectIds: string[]): Promise<Component[]>;
|
|
@@ -351,6 +351,19 @@ class AspectLoaderMain {
|
|
|
351
351
|
if (this.failedAspects.includes(id)) return;
|
|
352
352
|
this.failedLoadAspect.push(id);
|
|
353
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* run "require" of the component code to get the manifest
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
async doRequire(requireableExtension) {
|
|
360
|
+
const idStr = requireableExtension.component.id.toString();
|
|
361
|
+
const aspect = await requireableExtension.require();
|
|
362
|
+
const manifest = aspect.default || aspect;
|
|
363
|
+
manifest.id = idStr;
|
|
364
|
+
const newManifest = await this.runOnLoadRequireableExtensionSubscribers(requireableExtension, manifest);
|
|
365
|
+
return newManifest;
|
|
366
|
+
}
|
|
354
367
|
/**
|
|
355
368
|
* in case the extension failed to load, prefer to throw an error, unless `throwOnError` param
|
|
356
369
|
* passed as `false`.
|
|
@@ -374,20 +387,12 @@ class AspectLoaderMain {
|
|
|
374
387
|
|
|
375
388
|
|
|
376
389
|
async loadRequireableExtensions(requireableExtensions, throwOnError = false) {
|
|
377
|
-
const doRequire = async (requireableExtension, idStr) => {
|
|
378
|
-
const aspect = await requireableExtension.require();
|
|
379
|
-
const manifest = aspect.default || aspect;
|
|
380
|
-
manifest.id = idStr;
|
|
381
|
-
const newManifest = await this.runOnLoadRequireableExtensionSubscribers(requireableExtension, manifest);
|
|
382
|
-
return newManifest;
|
|
383
|
-
};
|
|
384
|
-
|
|
385
390
|
const manifestsP = (0, _pMapSeries().default)(requireableExtensions, async requireableExtension => {
|
|
386
391
|
if (!requireableExtensions) return undefined;
|
|
387
392
|
const idStr = requireableExtension.component.id.toString();
|
|
388
393
|
|
|
389
394
|
try {
|
|
390
|
-
return await doRequire(requireableExtension
|
|
395
|
+
return await this.doRequire(requireableExtension);
|
|
391
396
|
} catch (e) {
|
|
392
397
|
this.addFailure(idStr);
|
|
393
398
|
const errorMsg = (0, _constants2().UNABLE_TO_LOAD_EXTENSION)(idStr);
|
|
@@ -399,7 +404,7 @@ class AspectLoaderMain {
|
|
|
399
404
|
this.logger.info(`the loading issue has been fixed, re-loading ${idStr}`);
|
|
400
405
|
|
|
401
406
|
try {
|
|
402
|
-
return await doRequire(requireableExtension
|
|
407
|
+
return await this.doRequire(requireableExtension);
|
|
403
408
|
} catch (err) {
|
|
404
409
|
this.logger.error('re-load of the aspect failed as well', err);
|
|
405
410
|
errAfterReLoad = err;
|
|
@@ -407,18 +412,7 @@ class AspectLoaderMain {
|
|
|
407
412
|
}
|
|
408
413
|
|
|
409
414
|
const error = errAfterReLoad || e;
|
|
410
|
-
|
|
411
|
-
if (throwOnError) {
|
|
412
|
-
this.logger.console(error);
|
|
413
|
-
throw new (_exceptions().CannotLoadExtension)(idStr, error);
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
if (this.logger.isLoaderStarted) {
|
|
417
|
-
this.logger.consoleFailure(errorMsg);
|
|
418
|
-
} else {
|
|
419
|
-
this.logger.console(errorMsg);
|
|
420
|
-
this.logger.console(error.message);
|
|
421
|
-
}
|
|
415
|
+
this.handleExtensionLoadingError(error, idStr, throwOnError);
|
|
422
416
|
}
|
|
423
417
|
|
|
424
418
|
return undefined;
|
|
@@ -429,6 +423,23 @@ class AspectLoaderMain {
|
|
|
429
423
|
return this.loadExtensionsByManifests(filteredManifests, throwOnError);
|
|
430
424
|
}
|
|
431
425
|
|
|
426
|
+
handleExtensionLoadingError(error, idStr, throwOnError) {
|
|
427
|
+
const errorMsg = (0, _constants2().UNABLE_TO_LOAD_EXTENSION)(idStr);
|
|
428
|
+
|
|
429
|
+
if (throwOnError) {
|
|
430
|
+
// @ts-ignore
|
|
431
|
+
this.logger.console(error);
|
|
432
|
+
throw new (_exceptions().CannotLoadExtension)(idStr, error);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (this.logger.isLoaderStarted) {
|
|
436
|
+
this.logger.consoleFailure(errorMsg);
|
|
437
|
+
} else {
|
|
438
|
+
this.logger.console(errorMsg);
|
|
439
|
+
this.logger.console(error.message);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
432
443
|
async runOnLoadRequireableExtensionSubscribers(requireableExtension, manifest) {
|
|
433
444
|
let updatedManifest = manifest;
|
|
434
445
|
const entries = this.onLoadRequireableExtensionSlot.toArray();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["aspect-loader.main.runtime.ts"],"names":["AspectLoaderMain","constructor","logger","envs","harmony","onAspectLoadErrorSlot","onLoadRequireableExtensionSlot","getCompiler","component","env","getEnv","registerOnAspectLoadErrorSlot","onAspectLoadError","register","registerOnLoadRequireableExtensionSlot","onLoadRequireableExtension","triggerOnAspectLoadError","err","entries","toArray","isFixed","onAspectFailFunc","result","id","getRuntimePath","modulePath","runtime","runtimeFile","filesystem","files","find","file","relative","includes","compiler","dist","getDistPathBySrcPath","isAspectLoaded","failedAspects","get","getDescriptor","instance","iconFn","icon","apply","undefined","getNotLoadedConfiguredExtensions","configuredAspects","Array","from","config","raw","keys","loadedExtensions","extensionsIds","extensionsToLoad","loadDefinition","props","AspectDefinition","coreAspects","_coreAspects","isCoreAspect","ids","getCoreAspectIds","setCoreAspects","aspects","map","aspect","concat","_reserved","getUserAspects","coreAspectIds","getCoreAspectDefs","runtimeName","defs","Promise","all","rawDef","filter","def","runtimePath","resolveAspects","components","resolver","promises","resolvedAspect","aspectPath","aspectDefs","mainAspect","_mainAspect","setMainAspect","failedLoadAspect","addFailure","push","loadRequireableExtensions","requireableExtensions","throwOnError","doRequire","requireableExtension","idStr","require","manifest","default","newManifest","runOnLoadRequireableExtensionSubscribers","manifestsP","toString","e","errorMsg","error","errAfterReLoad","info","console","CannotLoadExtension","isLoaderStarted","consoleFailure","message","manifests","filteredManifests","loadExtensionsByManifests","updatedManifest","onLoadRequireableExtensionFunc","isAspect","addRuntime","getRuntime","loadAspectsFromGlobalScope","aspectIds","globalScope","LegacyScope","ensure","GLOBAL_SCOPE","ensureDir","globalScopeHarmony","path","scope","ScopeAspect","ComponentID","fromLegacy","BitId","parse","hasVersions","every","hasVersion","useCache","import","resolvedAspects","getResolvedAspects","code","resolvedAspectsAgain","skipIfExists","prepareManifests","MainRuntime","Error","Aspect","create","extensionsManifests","isValid","provider","warn","preparedManifests","load","warning","loggerExt","createLogger","AspectLoaderAspect","aspectLoader","LoggerAspect","EnvsAspect","Slot","withType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;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,CAACK,SAAD,EAAY/J,IAAZ,CADmB,EAEnB+C,MAFmB,EAGnB,CAAC7C,qBAAD,EAAwBC,8BAAxB,CAHmB,EAInBF,OAJmB,EAKnB;AACA,UAAMF,MAAM,GAAGgK,SAAS,CAACC,YAAV,CAAuBC,mCAAmB7I,EAA1C,CAAf;AACA,UAAM8I,YAAY,GAAG,IAAIrK,gBAAJ,CACnBE,MADmB,EAEnBC,IAFmB,EAGnBC,OAHmB,EAInBC,qBAJmB,EAKnBC,8BALmB,CAArB;AAOA,WAAO+J,YAAP;AACD;;AAnV2B;;;gCAAjBrK,gB,aAgUMuJ,kB;gCAhUNvJ,gB,kBAiUW,CAACsK,sBAAD,EAAeC,kBAAf,C;gCAjUXvK,gB,WAkUI,CAACwK,gBAAKC,QAAL,EAAD,EAAqCD,gBAAKC,QAAL,EAArC,C;;AAoBjBL,mCAAmBzC,UAAnB,CAA8B3H,gBAA9B","sourcesContent":["import { join } from 'path';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport LegacyScope from '@teambit/legacy/dist/scope/scope';\nimport { GLOBAL_SCOPE } from '@teambit/legacy/dist/constants';\nimport { MainRuntime } from '@teambit/cli';\nimport { Component, ComponentID } from '@teambit/component';\nimport { ExtensionManifest, Harmony, Aspect, SlotRegistry, Slot } from '@teambit/harmony';\nimport type { LoggerMain } from '@teambit/logger';\nimport { Logger, LoggerAspect } from '@teambit/logger';\nimport { RequireableComponent } from '@teambit/harmony.modules.requireable-component';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { loadBit } from '@teambit/bit';\nimport { ScopeAspect, ScopeMain } from '@teambit/scope';\nimport mapSeries from 'p-map-series';\nimport { difference, compact } from 'lodash';\nimport { AspectDefinition, AspectDefinitionProps } from './aspect-definition';\nimport { AspectLoaderAspect } from './aspect-loader.aspect';\nimport { UNABLE_TO_LOAD_EXTENSION, UNABLE_TO_LOAD_EXTENSION_FROM_LIST } from './constants';\nimport { CannotLoadExtension } from './exceptions';\nimport { getAspectDef } from './core-aspects';\n\nexport type AspectDescriptor = {\n /**\n * name of the extension.\n */\n id: string;\n\n /**\n * icon of the extension.\n */\n icon?: string;\n};\n\nexport type AspectResolver = (component: Component) => Promise<ResolvedAspect>;\n\nexport type ResolvedAspect = {\n aspectPath: string;\n runtimePath: string | null;\n};\n\ntype OnAspectLoadError = (err: Error, id: ComponentID) => Promise<boolean>;\nexport type OnAspectLoadErrorSlot = SlotRegistry<OnAspectLoadError>;\n\nexport type OnLoadRequireableExtension = (\n requireableExtension: RequireableComponent,\n manifest: ExtensionManifest | Aspect\n) => Promise<ExtensionManifest | Aspect>;\n/**\n * A slot which run during loading the requirable extension (after first manifest calculation)\n */\nexport type OnLoadRequireableExtensionSlot = SlotRegistry<OnLoadRequireableExtension>;\n\nexport type MainAspect = {\n /**\n * path to the main aspect.\n */\n path: string;\n\n /**\n * version of the aspect.\n */\n version: string | undefined;\n\n /**\n * package name of the aspect\n */\n packageName: string | undefined;\n\n /**\n * reference to aspect manifest.\n */\n aspect: Aspect;\n\n /**\n * The name of the aspect (without the scope prefix)\n */\n name: string;\n\n /**\n * The name of the aspect\n */\n id: string;\n};\n\nexport class AspectLoaderMain {\n constructor(\n private logger: Logger,\n private envs: EnvsMain,\n private harmony: Harmony,\n private onAspectLoadErrorSlot: OnAspectLoadErrorSlot,\n private onLoadRequireableExtensionSlot: OnLoadRequireableExtensionSlot\n ) {}\n\n private getCompiler(component: Component) {\n const env = this.envs.getEnv(component)?.env;\n return env?.getCompiler();\n }\n\n registerOnAspectLoadErrorSlot(onAspectLoadError: OnAspectLoadError) {\n this.onAspectLoadErrorSlot.register(onAspectLoadError);\n }\n\n registerOnLoadRequireableExtensionSlot(onLoadRequireableExtension: OnLoadRequireableExtension) {\n this.onLoadRequireableExtensionSlot.register(onLoadRequireableExtension);\n }\n\n /**\n * returns whether the aspect-load issue has been fixed.\n */\n async triggerOnAspectLoadError(err: Error, component: Component): Promise<boolean> {\n const entries = this.onAspectLoadErrorSlot.toArray(); // e.g. [ [ 'teambit.bit/compiler', [Function: bound onAspectLoadError] ] ]\n let isFixed = false;\n await mapSeries(entries, async ([, onAspectFailFunc]) => {\n const result = await onAspectFailFunc(err, component.id);\n if (result) isFixed = true;\n });\n\n return isFixed;\n }\n\n async getRuntimePath(component: Component, modulePath: string, runtime: string): Promise<string | null> {\n const runtimeFile = component.filesystem.files.find((file: any) => {\n return file.relative.includes(`.${runtime}.runtime`);\n });\n\n // @david we should add a compiler api for this.\n if (!runtimeFile) return null;\n\n const compiler = this.getCompiler(component);\n\n if (!compiler) {\n return join(modulePath, runtimeFile.relative);\n }\n\n const dist = compiler.getDistPathBySrcPath(runtimeFile.relative);\n return join(modulePath, dist);\n }\n\n isAspectLoaded(id: string) {\n if (this.failedAspects.includes(id)) return true;\n try {\n return this.harmony.get(id);\n } catch (err: any) {\n return false;\n }\n }\n\n getDescriptor(id: string): AspectDescriptor {\n const instance = this.harmony.get<any>(id);\n const iconFn = instance.icon;\n\n const icon = iconFn ? iconFn.apply(instance) : undefined;\n\n return {\n id,\n icon,\n };\n }\n\n getNotLoadedConfiguredExtensions() {\n const configuredAspects = Array.from(this.harmony.config.raw.keys());\n const loadedExtensions = this.harmony.extensionsIds;\n const extensionsToLoad = difference(configuredAspects, loadedExtensions);\n return extensionsToLoad;\n }\n\n loadDefinition(props: AspectDefinitionProps): AspectDefinition {\n return AspectDefinition.from(props);\n }\n\n private _coreAspects: Aspect[] = [];\n\n get coreAspects() {\n return this._coreAspects;\n }\n\n isCoreAspect(id: string) {\n const ids = this.getCoreAspectIds();\n return ids.includes(id);\n }\n\n setCoreAspects(aspects: Aspect[]) {\n this._coreAspects = aspects;\n return this;\n }\n\n getCoreAspectIds() {\n const ids = this.coreAspects.map((aspect) => aspect.id);\n return ids.concat(this._reserved);\n }\n\n private _reserved = ['teambit.harmony/bit', 'teambit.harmony/config'];\n\n getUserAspects(): string[] {\n const coreAspectIds = this.getCoreAspectIds();\n return difference(this.harmony.extensionsIds, coreAspectIds);\n }\n\n async getCoreAspectDefs(runtimeName?: string) {\n const defs = await Promise.all(\n this.coreAspects.map(async (aspect) => {\n const id = aspect.id;\n const rawDef = await getAspectDef(id, runtimeName);\n return this.loadDefinition(rawDef);\n })\n );\n\n return defs.filter((def) => def.runtimePath);\n }\n\n async resolveAspects(components: Component[], resolver: AspectResolver): Promise<AspectDefinition[]> {\n const promises = components.map(async (component) => {\n const resolvedAspect = await resolver(component);\n return new AspectDefinition(resolvedAspect.aspectPath, resolvedAspect.runtimePath, component);\n });\n\n const aspectDefs = await Promise.all(promises);\n // return aspectDefs.filter((def) => def.runtimePath);\n return aspectDefs;\n }\n\n private _mainAspect: MainAspect;\n\n get mainAspect() {\n return this._mainAspect;\n }\n\n setMainAspect(mainAspect: MainAspect) {\n this._mainAspect = mainAspect;\n return this;\n }\n\n private failedLoadAspect: string[] = [];\n\n get failedAspects() {\n return this.failedLoadAspect;\n }\n\n private addFailure(id: string): void {\n if (this.failedAspects.includes(id)) return;\n this.failedLoadAspect.push(id);\n }\n\n /**\n * in case the extension failed to load, prefer to throw an error, unless `throwOnError` param\n * passed as `false`.\n * there are cases when throwing an error blocks the user from doing anything else. for example,\n * when a user develops an extension and deletes the node-modules, the extension on the workspace\n * cannot be loaded anymore until \"bit compile\" is running. however, if this function throws an\n * error, it'll throw for \"bit compile\" as well, which blocks the user.\n * for the CI, it is important to throw an error because errors on console can be ignored.\n * for now, when loading the extension from the workspace the throwOnError is passed as false.\n * when loading from the scope (CI) it should be true.\n *\n * the console printing here is done directly by \"console.error\" and not by the logger. the reason\n * is that the logger.console only prints when the loader started (which, btw, happens after\n * entering this function, so it can't work) and here we want it to be printed regardless of the\n * rules of starting the loader. e.g. if by mistake the CI got it as throwOnError=false, it's ok\n * to break the output by the console.error.\n *\n * @todo: this is not the final word however about throwing/non throwing errors here.\n * in some cases, such as \"bit tag\", it's better not to tag if an extension changes the model.\n */\n async loadRequireableExtensions(requireableExtensions: RequireableComponent[], throwOnError = false): Promise<void> {\n const doRequire = async (requireableExtension: RequireableComponent, idStr: string) => {\n const aspect = await requireableExtension.require();\n const manifest = aspect.default || aspect;\n manifest.id = idStr;\n const newManifest = await this.runOnLoadRequireableExtensionSubscribers(requireableExtension, manifest);\n return newManifest;\n };\n const manifestsP = mapSeries(requireableExtensions, async (requireableExtension) => {\n if (!requireableExtensions) return undefined;\n const idStr = requireableExtension.component.id.toString();\n try {\n return await doRequire(requireableExtension, idStr);\n } catch (e: any) {\n this.addFailure(idStr);\n const errorMsg = UNABLE_TO_LOAD_EXTENSION(idStr);\n this.logger.error(errorMsg, e);\n const isFixed = await this.triggerOnAspectLoadError(e, requireableExtension.component);\n let errAfterReLoad;\n if (isFixed) {\n this.logger.info(`the loading issue has been fixed, re-loading ${idStr}`);\n try {\n return await doRequire(requireableExtension, idStr);\n } catch (err: any) {\n this.logger.error('re-load of the aspect failed as well', err);\n errAfterReLoad = err;\n }\n }\n const error = errAfterReLoad || e;\n if (throwOnError) {\n this.logger.console(error);\n throw new CannotLoadExtension(idStr, error);\n }\n if (this.logger.isLoaderStarted) {\n this.logger.consoleFailure(errorMsg);\n } else {\n this.logger.console(errorMsg);\n this.logger.console(error.message);\n }\n }\n return undefined;\n });\n const manifests = await manifestsP;\n\n // Remove empty manifests as a result of loading issue\n const filteredManifests = compact(manifests);\n return this.loadExtensionsByManifests(filteredManifests, throwOnError);\n }\n\n async runOnLoadRequireableExtensionSubscribers(\n requireableExtension: RequireableComponent,\n manifest: ExtensionManifest | Aspect\n ): Promise<ExtensionManifest | Aspect> {\n let updatedManifest = manifest;\n const entries = this.onLoadRequireableExtensionSlot.toArray();\n await mapSeries(entries, async ([, onLoadRequireableExtensionFunc]) => {\n updatedManifest = await onLoadRequireableExtensionFunc(requireableExtension, updatedManifest);\n });\n return updatedManifest;\n }\n\n isAspect(manifest: any) {\n return !!(manifest.addRuntime && manifest.getRuntime);\n }\n\n /**\n * get or create a global scope, import the non-core aspects, load bit from that scope, create\n * capsules for the aspects and load them from the capsules.\n */\n async loadAspectsFromGlobalScope(aspectIds: string[]): Promise<Component[]> {\n const globalScope = await LegacyScope.ensure(GLOBAL_SCOPE, 'global-scope');\n await globalScope.ensureDir();\n const globalScopeHarmony = await loadBit(globalScope.path);\n const scope = globalScopeHarmony.get<ScopeMain>(ScopeAspect.id);\n // @todo: Gilad make this work\n // const ids = await scope.resolveMultipleComponentIds(aspectIds);\n const ids = aspectIds.map((id) => ComponentID.fromLegacy(BitId.parse(id, true)));\n const hasVersions = ids.every((id) => id.hasVersion());\n const useCache = hasVersions; // if all components has versions, try to use the cached aspects\n const components = await scope.import(ids, useCache, true);\n\n // don't use `await scope.loadAspectsFromCapsules(components, true);`\n // it won't work for globalScope because `this !== scope.aspectLoader` (this instance\n // is not the same as the aspectLoader instance Scope has)\n const resolvedAspects = await scope.getResolvedAspects(components);\n try {\n await this.loadRequireableExtensions(resolvedAspects, true);\n } catch (err: any) {\n if (err?.error.code === 'MODULE_NOT_FOUND') {\n const resolvedAspectsAgain = await scope.getResolvedAspects(components, { skipIfExists: false });\n await this.loadRequireableExtensions(resolvedAspectsAgain, true);\n } else {\n throw err;\n }\n }\n\n return components;\n }\n\n private prepareManifests(manifests: Array<ExtensionManifest | Aspect>): Aspect[] {\n return manifests.map((manifest: any) => {\n if (this.isAspect(manifest)) return manifest as Aspect;\n manifest.runtime = MainRuntime;\n if (!manifest.id) throw new Error('manifest must have static id');\n const aspect = Aspect.create({\n id: manifest.id,\n });\n aspect.addRuntime(manifest);\n return aspect;\n });\n }\n\n // TODO: change to use the new logger, see more info at loadExtensions function in the workspace\n async loadExtensionsByManifests(extensionsManifests: Array<ExtensionManifest | Aspect>, throwOnError = true) {\n try {\n const manifests = extensionsManifests.filter((manifest) => {\n // @ts-ignore TODO: fix this\n const isValid = this.isAspect(manifest) || manifest.provider;\n if (!isValid) this.logger.warn(`${manifest.id} is invalid. please make sure the extension is valid.`);\n return isValid;\n });\n const preparedManifests = this.prepareManifests(manifests);\n // @ts-ignore TODO: fix this\n await this.harmony.load(preparedManifests);\n } catch (e: any) {\n const ids = extensionsManifests.map((manifest) => manifest.id || 'unknown');\n // TODO: improve texts\n const warning = UNABLE_TO_LOAD_EXTENSION_FROM_LIST(ids);\n this.logger.warn(warning, e);\n if (this.logger.isLoaderStarted) {\n this.logger.consoleFailure(warning);\n } else {\n this.logger.console(warning);\n this.logger.console(e);\n }\n if (throwOnError) {\n throw e;\n }\n }\n }\n\n static runtime = MainRuntime;\n static dependencies = [LoggerAspect, EnvsAspect];\n static slots = [Slot.withType<OnAspectLoadError>(), Slot.withType<OnLoadRequireableExtension>()];\n\n static async provider(\n [loggerExt, envs]: [LoggerMain, EnvsMain],\n config,\n [onAspectLoadErrorSlot, onLoadRequireableExtensionSlot]: [OnAspectLoadErrorSlot, OnLoadRequireableExtensionSlot],\n harmony: Harmony\n ) {\n const logger = loggerExt.createLogger(AspectLoaderAspect.id);\n const aspectLoader = new AspectLoaderMain(\n logger,\n envs,\n harmony,\n onAspectLoadErrorSlot,\n onLoadRequireableExtensionSlot\n );\n return aspectLoader;\n }\n}\n\nAspectLoaderAspect.addRuntime(AspectLoaderMain);\n"]}
|
|
1
|
+
{"version":3,"sources":["aspect-loader.main.runtime.ts"],"names":["AspectLoaderMain","constructor","logger","envs","harmony","onAspectLoadErrorSlot","onLoadRequireableExtensionSlot","getCompiler","component","env","getEnv","registerOnAspectLoadErrorSlot","onAspectLoadError","register","registerOnLoadRequireableExtensionSlot","onLoadRequireableExtension","triggerOnAspectLoadError","err","entries","toArray","isFixed","onAspectFailFunc","result","id","getRuntimePath","modulePath","runtime","runtimeFile","filesystem","files","find","file","relative","includes","compiler","dist","getDistPathBySrcPath","isAspectLoaded","failedAspects","get","getDescriptor","instance","iconFn","icon","apply","undefined","getNotLoadedConfiguredExtensions","configuredAspects","Array","from","config","raw","keys","loadedExtensions","extensionsIds","extensionsToLoad","loadDefinition","props","AspectDefinition","coreAspects","_coreAspects","isCoreAspect","ids","getCoreAspectIds","setCoreAspects","aspects","map","aspect","concat","_reserved","getUserAspects","coreAspectIds","getCoreAspectDefs","runtimeName","defs","Promise","all","rawDef","filter","def","runtimePath","resolveAspects","components","resolver","promises","resolvedAspect","aspectPath","aspectDefs","mainAspect","_mainAspect","setMainAspect","failedLoadAspect","addFailure","push","doRequire","requireableExtension","idStr","toString","require","manifest","default","newManifest","runOnLoadRequireableExtensionSubscribers","loadRequireableExtensions","requireableExtensions","throwOnError","manifestsP","e","errorMsg","error","errAfterReLoad","info","handleExtensionLoadingError","manifests","filteredManifests","loadExtensionsByManifests","console","CannotLoadExtension","isLoaderStarted","consoleFailure","message","updatedManifest","onLoadRequireableExtensionFunc","isAspect","addRuntime","getRuntime","loadAspectsFromGlobalScope","aspectIds","globalScope","LegacyScope","ensure","GLOBAL_SCOPE","ensureDir","globalScopeHarmony","path","scope","ScopeAspect","ComponentID","fromLegacy","BitId","parse","hasVersions","every","hasVersion","useCache","import","resolvedAspects","getResolvedAspects","code","resolvedAspectsAgain","skipIfExists","prepareManifests","MainRuntime","Error","Aspect","create","extensionsManifests","isValid","provider","warn","preparedManifests","load","warning","loggerExt","createLogger","AspectLoaderAspect","aspectLoader","LoggerAspect","EnvsAspect","Slot","withType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA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AAS,CAACC,YAAV,CAAuBC,mCAAmB9I,EAA1C,CAAf;AACA,UAAM+I,YAAY,GAAG,IAAItK,gBAAJ,CACnBE,MADmB,EAEnBC,IAFmB,EAGnBC,OAHmB,EAInBC,qBAJmB,EAKnBC,8BALmB,CAArB;AAOA,WAAOgK,YAAP;AACD;;AA9V2B;;;gCAAjBtK,gB,aA2UMwJ,kB;gCA3UNxJ,gB,kBA4UW,CAACuK,sBAAD,EAAeC,kBAAf,C;gCA5UXxK,gB,WA6UI,CAACyK,gBAAKC,QAAL,EAAD,EAAqCD,gBAAKC,QAAL,EAArC,C;;AAoBjBL,mCAAmBzC,UAAnB,CAA8B5H,gBAA9B","sourcesContent":["import { join } from 'path';\nimport { BitId } from '@teambit/legacy-bit-id';\nimport LegacyScope from '@teambit/legacy/dist/scope/scope';\nimport { GLOBAL_SCOPE } from '@teambit/legacy/dist/constants';\nimport { MainRuntime } from '@teambit/cli';\nimport { Component, ComponentID } from '@teambit/component';\nimport { ExtensionManifest, Harmony, Aspect, SlotRegistry, Slot } from '@teambit/harmony';\nimport type { LoggerMain } from '@teambit/logger';\nimport { Logger, LoggerAspect } from '@teambit/logger';\nimport { RequireableComponent } from '@teambit/harmony.modules.requireable-component';\nimport { EnvsAspect, EnvsMain } from '@teambit/envs';\nimport { loadBit } from '@teambit/bit';\nimport { ScopeAspect, ScopeMain } from '@teambit/scope';\nimport mapSeries from 'p-map-series';\nimport { difference, compact } from 'lodash';\nimport { AspectDefinition, AspectDefinitionProps } from './aspect-definition';\nimport { AspectLoaderAspect } from './aspect-loader.aspect';\nimport { UNABLE_TO_LOAD_EXTENSION, UNABLE_TO_LOAD_EXTENSION_FROM_LIST } from './constants';\nimport { CannotLoadExtension } from './exceptions';\nimport { getAspectDef } from './core-aspects';\n\nexport type AspectDescriptor = {\n /**\n * name of the extension.\n */\n id: string;\n\n /**\n * icon of the extension.\n */\n icon?: string;\n};\n\nexport type AspectResolver = (component: Component) => Promise<ResolvedAspect>;\n\nexport type ResolvedAspect = {\n aspectPath: string;\n runtimePath: string | null;\n};\n\ntype OnAspectLoadError = (err: Error, id: ComponentID) => Promise<boolean>;\nexport type OnAspectLoadErrorSlot = SlotRegistry<OnAspectLoadError>;\n\nexport type OnLoadRequireableExtension = (\n requireableExtension: RequireableComponent,\n manifest: ExtensionManifest | Aspect\n) => Promise<ExtensionManifest | Aspect>;\n/**\n * A slot which run during loading the requirable extension (after first manifest calculation)\n */\nexport type OnLoadRequireableExtensionSlot = SlotRegistry<OnLoadRequireableExtension>;\n\nexport type MainAspect = {\n /**\n * path to the main aspect.\n */\n path: string;\n\n /**\n * version of the aspect.\n */\n version: string | undefined;\n\n /**\n * package name of the aspect\n */\n packageName: string | undefined;\n\n /**\n * reference to aspect manifest.\n */\n aspect: Aspect;\n\n /**\n * The name of the aspect (without the scope prefix)\n */\n name: string;\n\n /**\n * The name of the aspect\n */\n id: string;\n};\n\nexport class AspectLoaderMain {\n constructor(\n private logger: Logger,\n private envs: EnvsMain,\n private harmony: Harmony,\n private onAspectLoadErrorSlot: OnAspectLoadErrorSlot,\n private onLoadRequireableExtensionSlot: OnLoadRequireableExtensionSlot\n ) {}\n\n private getCompiler(component: Component) {\n const env = this.envs.getEnv(component)?.env;\n return env?.getCompiler();\n }\n\n registerOnAspectLoadErrorSlot(onAspectLoadError: OnAspectLoadError) {\n this.onAspectLoadErrorSlot.register(onAspectLoadError);\n }\n\n registerOnLoadRequireableExtensionSlot(onLoadRequireableExtension: OnLoadRequireableExtension) {\n this.onLoadRequireableExtensionSlot.register(onLoadRequireableExtension);\n }\n\n /**\n * returns whether the aspect-load issue has been fixed.\n */\n async triggerOnAspectLoadError(err: Error, component: Component): Promise<boolean> {\n const entries = this.onAspectLoadErrorSlot.toArray(); // e.g. [ [ 'teambit.bit/compiler', [Function: bound onAspectLoadError] ] ]\n let isFixed = false;\n await mapSeries(entries, async ([, onAspectFailFunc]) => {\n const result = await onAspectFailFunc(err, component.id);\n if (result) isFixed = true;\n });\n\n return isFixed;\n }\n\n async getRuntimePath(component: Component, modulePath: string, runtime: string): Promise<string | null> {\n const runtimeFile = component.filesystem.files.find((file: any) => {\n return file.relative.includes(`.${runtime}.runtime`);\n });\n\n // @david we should add a compiler api for this.\n if (!runtimeFile) return null;\n\n const compiler = this.getCompiler(component);\n\n if (!compiler) {\n return join(modulePath, runtimeFile.relative);\n }\n\n const dist = compiler.getDistPathBySrcPath(runtimeFile.relative);\n return join(modulePath, dist);\n }\n\n isAspectLoaded(id: string) {\n if (this.failedAspects.includes(id)) return true;\n try {\n return this.harmony.get(id);\n } catch (err: any) {\n return false;\n }\n }\n\n getDescriptor(id: string): AspectDescriptor {\n const instance = this.harmony.get<any>(id);\n const iconFn = instance.icon;\n\n const icon = iconFn ? iconFn.apply(instance) : undefined;\n\n return {\n id,\n icon,\n };\n }\n\n getNotLoadedConfiguredExtensions() {\n const configuredAspects = Array.from(this.harmony.config.raw.keys());\n const loadedExtensions = this.harmony.extensionsIds;\n const extensionsToLoad = difference(configuredAspects, loadedExtensions);\n return extensionsToLoad;\n }\n\n loadDefinition(props: AspectDefinitionProps): AspectDefinition {\n return AspectDefinition.from(props);\n }\n\n private _coreAspects: Aspect[] = [];\n\n get coreAspects() {\n return this._coreAspects;\n }\n\n isCoreAspect(id: string) {\n const ids = this.getCoreAspectIds();\n return ids.includes(id);\n }\n\n setCoreAspects(aspects: Aspect[]) {\n this._coreAspects = aspects;\n return this;\n }\n\n getCoreAspectIds() {\n const ids = this.coreAspects.map((aspect) => aspect.id);\n return ids.concat(this._reserved);\n }\n\n private _reserved = ['teambit.harmony/bit', 'teambit.harmony/config'];\n\n getUserAspects(): string[] {\n const coreAspectIds = this.getCoreAspectIds();\n return difference(this.harmony.extensionsIds, coreAspectIds);\n }\n\n async getCoreAspectDefs(runtimeName?: string) {\n const defs = await Promise.all(\n this.coreAspects.map(async (aspect) => {\n const id = aspect.id;\n const rawDef = await getAspectDef(id, runtimeName);\n return this.loadDefinition(rawDef);\n })\n );\n\n return defs.filter((def) => def.runtimePath);\n }\n\n async resolveAspects(components: Component[], resolver: AspectResolver): Promise<AspectDefinition[]> {\n const promises = components.map(async (component) => {\n const resolvedAspect = await resolver(component);\n return new AspectDefinition(resolvedAspect.aspectPath, resolvedAspect.runtimePath, component);\n });\n\n const aspectDefs = await Promise.all(promises);\n // return aspectDefs.filter((def) => def.runtimePath);\n return aspectDefs;\n }\n\n private _mainAspect: MainAspect;\n\n get mainAspect() {\n return this._mainAspect;\n }\n\n setMainAspect(mainAspect: MainAspect) {\n this._mainAspect = mainAspect;\n return this;\n }\n\n private failedLoadAspect: string[] = [];\n\n get failedAspects() {\n return this.failedLoadAspect;\n }\n\n private addFailure(id: string): void {\n if (this.failedAspects.includes(id)) return;\n this.failedLoadAspect.push(id);\n }\n\n /**\n * run \"require\" of the component code to get the manifest\n */\n async doRequire(requireableExtension: RequireableComponent): Promise<ExtensionManifest | Aspect> {\n const idStr = requireableExtension.component.id.toString();\n const aspect = await requireableExtension.require();\n const manifest = aspect.default || aspect;\n manifest.id = idStr;\n const newManifest = await this.runOnLoadRequireableExtensionSubscribers(requireableExtension, manifest);\n return newManifest;\n }\n\n /**\n * in case the extension failed to load, prefer to throw an error, unless `throwOnError` param\n * passed as `false`.\n * there are cases when throwing an error blocks the user from doing anything else. for example,\n * when a user develops an extension and deletes the node-modules, the extension on the workspace\n * cannot be loaded anymore until \"bit compile\" is running. however, if this function throws an\n * error, it'll throw for \"bit compile\" as well, which blocks the user.\n * for the CI, it is important to throw an error because errors on console can be ignored.\n * for now, when loading the extension from the workspace the throwOnError is passed as false.\n * when loading from the scope (CI) it should be true.\n *\n * the console printing here is done directly by \"console.error\" and not by the logger. the reason\n * is that the logger.console only prints when the loader started (which, btw, happens after\n * entering this function, so it can't work) and here we want it to be printed regardless of the\n * rules of starting the loader. e.g. if by mistake the CI got it as throwOnError=false, it's ok\n * to break the output by the console.error.\n *\n * @todo: this is not the final word however about throwing/non throwing errors here.\n * in some cases, such as \"bit tag\", it's better not to tag if an extension changes the model.\n */\n async loadRequireableExtensions(requireableExtensions: RequireableComponent[], throwOnError = false): Promise<void> {\n const manifestsP = mapSeries(requireableExtensions, async (requireableExtension) => {\n if (!requireableExtensions) return undefined;\n const idStr = requireableExtension.component.id.toString();\n try {\n return await this.doRequire(requireableExtension);\n } catch (e: any) {\n this.addFailure(idStr);\n const errorMsg = UNABLE_TO_LOAD_EXTENSION(idStr);\n this.logger.error(errorMsg, e);\n const isFixed = await this.triggerOnAspectLoadError(e, requireableExtension.component);\n let errAfterReLoad;\n if (isFixed) {\n this.logger.info(`the loading issue has been fixed, re-loading ${idStr}`);\n try {\n return await this.doRequire(requireableExtension);\n } catch (err: any) {\n this.logger.error('re-load of the aspect failed as well', err);\n errAfterReLoad = err;\n }\n }\n const error = errAfterReLoad || e;\n this.handleExtensionLoadingError(error, idStr, throwOnError);\n }\n return undefined;\n });\n const manifests = await manifestsP;\n\n // Remove empty manifests as a result of loading issue\n const filteredManifests = compact(manifests);\n return this.loadExtensionsByManifests(filteredManifests, throwOnError);\n }\n\n handleExtensionLoadingError(error: Error, idStr: string, throwOnError: boolean) {\n const errorMsg = UNABLE_TO_LOAD_EXTENSION(idStr);\n if (throwOnError) {\n // @ts-ignore\n this.logger.console(error);\n throw new CannotLoadExtension(idStr, error);\n }\n if (this.logger.isLoaderStarted) {\n this.logger.consoleFailure(errorMsg);\n } else {\n this.logger.console(errorMsg);\n this.logger.console(error.message);\n }\n }\n\n async runOnLoadRequireableExtensionSubscribers(\n requireableExtension: RequireableComponent,\n manifest: ExtensionManifest | Aspect\n ): Promise<ExtensionManifest | Aspect> {\n let updatedManifest = manifest;\n const entries = this.onLoadRequireableExtensionSlot.toArray();\n await mapSeries(entries, async ([, onLoadRequireableExtensionFunc]) => {\n updatedManifest = await onLoadRequireableExtensionFunc(requireableExtension, updatedManifest);\n });\n return updatedManifest;\n }\n\n isAspect(manifest: any) {\n return !!(manifest.addRuntime && manifest.getRuntime);\n }\n\n /**\n * get or create a global scope, import the non-core aspects, load bit from that scope, create\n * capsules for the aspects and load them from the capsules.\n */\n async loadAspectsFromGlobalScope(aspectIds: string[]): Promise<Component[]> {\n const globalScope = await LegacyScope.ensure(GLOBAL_SCOPE, 'global-scope');\n await globalScope.ensureDir();\n const globalScopeHarmony = await loadBit(globalScope.path);\n const scope = globalScopeHarmony.get<ScopeMain>(ScopeAspect.id);\n // @todo: Gilad make this work\n // const ids = await scope.resolveMultipleComponentIds(aspectIds);\n const ids = aspectIds.map((id) => ComponentID.fromLegacy(BitId.parse(id, true)));\n const hasVersions = ids.every((id) => id.hasVersion());\n const useCache = hasVersions; // if all components has versions, try to use the cached aspects\n const components = await scope.import(ids, useCache, true);\n\n // don't use `await scope.loadAspectsFromCapsules(components, true);`\n // it won't work for globalScope because `this !== scope.aspectLoader` (this instance\n // is not the same as the aspectLoader instance Scope has)\n const resolvedAspects = await scope.getResolvedAspects(components);\n try {\n await this.loadRequireableExtensions(resolvedAspects, true);\n } catch (err: any) {\n if (err?.error.code === 'MODULE_NOT_FOUND') {\n const resolvedAspectsAgain = await scope.getResolvedAspects(components, { skipIfExists: false });\n await this.loadRequireableExtensions(resolvedAspectsAgain, true);\n } else {\n throw err;\n }\n }\n\n return components;\n }\n\n private prepareManifests(manifests: Array<ExtensionManifest | Aspect>): Aspect[] {\n return manifests.map((manifest: any) => {\n if (this.isAspect(manifest)) return manifest as Aspect;\n manifest.runtime = MainRuntime;\n if (!manifest.id) throw new Error('manifest must have static id');\n const aspect = Aspect.create({\n id: manifest.id,\n });\n aspect.addRuntime(manifest);\n return aspect;\n });\n }\n\n // TODO: change to use the new logger, see more info at loadExtensions function in the workspace\n async loadExtensionsByManifests(extensionsManifests: Array<ExtensionManifest | Aspect>, throwOnError = true) {\n try {\n const manifests = extensionsManifests.filter((manifest) => {\n // @ts-ignore TODO: fix this\n const isValid = this.isAspect(manifest) || manifest.provider;\n if (!isValid) this.logger.warn(`${manifest.id} is invalid. please make sure the extension is valid.`);\n return isValid;\n });\n const preparedManifests = this.prepareManifests(manifests);\n // @ts-ignore TODO: fix this\n await this.harmony.load(preparedManifests);\n } catch (e: any) {\n const ids = extensionsManifests.map((manifest) => manifest.id || 'unknown');\n // TODO: improve texts\n const warning = UNABLE_TO_LOAD_EXTENSION_FROM_LIST(ids);\n this.logger.warn(warning, e);\n if (this.logger.isLoaderStarted) {\n this.logger.consoleFailure(warning);\n } else {\n this.logger.console(warning);\n this.logger.console(e);\n }\n if (throwOnError) {\n throw e;\n }\n }\n }\n\n static runtime = MainRuntime;\n static dependencies = [LoggerAspect, EnvsAspect];\n static slots = [Slot.withType<OnAspectLoadError>(), Slot.withType<OnLoadRequireableExtension>()];\n\n static async provider(\n [loggerExt, envs]: [LoggerMain, EnvsMain],\n config,\n [onAspectLoadErrorSlot, onLoadRequireableExtensionSlot]: [OnAspectLoadErrorSlot, OnLoadRequireableExtensionSlot],\n harmony: Harmony\n ) {\n const logger = loggerExt.createLogger(AspectLoaderAspect.id);\n const aspectLoader = new AspectLoaderMain(\n logger,\n envs,\n harmony,\n onAspectLoadErrorSlot,\n onLoadRequireableExtensionSlot\n );\n return aspectLoader;\n }\n}\n\nAspectLoaderAspect.addRuntime(AspectLoaderMain);\n"]}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/aspect-loader",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.513",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/harmony/aspect-loader",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.harmony",
|
|
8
8
|
"name": "aspect-loader",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.513"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@teambit/harmony": "0.2.11",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
"fs-extra": "10.0.0",
|
|
16
16
|
"@babel/runtime": "7.12.18",
|
|
17
17
|
"core-js": "^3.0.0",
|
|
18
|
-
"@teambit/component": "0.0.
|
|
19
|
-
"@teambit/bit": "0.0.
|
|
20
|
-
"@teambit/cli": "0.0.
|
|
21
|
-
"@teambit/envs": "0.0.
|
|
22
|
-
"@teambit/harmony.modules.requireable-component": "0.0.
|
|
18
|
+
"@teambit/component": "0.0.513",
|
|
19
|
+
"@teambit/bit": "0.0.515",
|
|
20
|
+
"@teambit/cli": "0.0.379",
|
|
21
|
+
"@teambit/envs": "0.0.513",
|
|
22
|
+
"@teambit/harmony.modules.requireable-component": "0.0.439",
|
|
23
23
|
"@teambit/legacy-bit-id": "0.0.368",
|
|
24
|
-
"@teambit/logger": "0.0.
|
|
25
|
-
"@teambit/scope": "0.0.
|
|
24
|
+
"@teambit/logger": "0.0.445",
|
|
25
|
+
"@teambit/scope": "0.0.513",
|
|
26
26
|
"@teambit/bit-error": "0.0.365"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
Binary file
|