@teambit/workspace 0.0.807 → 0.0.810
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/component-config-file/component-config-file.ts +17 -3
- package/dist/bit-map.d.ts +1 -1
- package/dist/bit-map.js +16 -4
- package/dist/bit-map.js.map +1 -1
- package/dist/component-config-file/component-config-file.d.ts +1 -1
- package/dist/component-config-file/component-config-file.js +21 -2
- package/dist/component-config-file/component-config-file.js.map +1 -1
- package/dist/workspace.d.ts +1 -1
- package/dist/workspace.js +11 -6
- package/dist/workspace.js.map +1 -1
- package/package-tar/teambit-workspace-0.0.810.tgz +0 -0
- package/package.json +30 -30
- package/{preview-1659583874630.js → preview-1659929475189.js} +2 -2
- package/package-tar/teambit-workspace-0.0.807.tgz +0 -0
|
@@ -8,7 +8,7 @@ import fs from 'fs-extra';
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import stringifyPackage from 'stringify-package';
|
|
10
10
|
import { REMOVE_EXTENSION_SPECIAL_SIGN } from '@teambit/legacy/dist/consumer/config';
|
|
11
|
-
|
|
11
|
+
import { merge } from 'lodash';
|
|
12
12
|
import { AlreadyExistsError } from './exceptions';
|
|
13
13
|
|
|
14
14
|
interface ComponentConfigFileOptions {
|
|
@@ -82,10 +82,24 @@ export class ComponentConfigFile {
|
|
|
82
82
|
return fs.writeJsonSync(filePath, json, { spaces: this.options.indent, EOL: this.options.newLine });
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
async addAspect(
|
|
85
|
+
async addAspect(
|
|
86
|
+
aspectId: string,
|
|
87
|
+
config: any,
|
|
88
|
+
resolveComponentId: ResolveComponentIdFunc,
|
|
89
|
+
shouldMergeConfig = false
|
|
90
|
+
) {
|
|
86
91
|
const existing = this.aspects.get(aspectId);
|
|
92
|
+
|
|
87
93
|
if (existing) {
|
|
88
|
-
|
|
94
|
+
const getNewConfig = () => {
|
|
95
|
+
if (!shouldMergeConfig) return config;
|
|
96
|
+
if (!config || config === '-') return config;
|
|
97
|
+
if (!existing.config) return config;
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
if (existing.config === '-') return config;
|
|
100
|
+
return merge(existing.config, config);
|
|
101
|
+
};
|
|
102
|
+
existing.config = getNewConfig();
|
|
89
103
|
} else {
|
|
90
104
|
const aspectEntry = await this.aspectEntryFromConfigObject(aspectId, config, resolveComponentId);
|
|
91
105
|
this.aspects.entries.push(aspectEntry);
|
package/dist/bit-map.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare class BitMap {
|
|
|
17
17
|
* later, upon `bit tag`, the data is saved in the scope.
|
|
18
18
|
* returns a boolean indicating whether a change has been made.
|
|
19
19
|
*/
|
|
20
|
-
addComponentConfig(id: ComponentID, aspectId: string, config?: Record<string, any
|
|
20
|
+
addComponentConfig(id: ComponentID, aspectId: string, config?: Record<string, any>, shouldMergeConfig?: boolean): boolean;
|
|
21
21
|
removeComponentConfig(id: ComponentID, aspectId: string, markWithMinusIfNotExist: boolean): boolean;
|
|
22
22
|
removeEntireConfig(id: ComponentID): boolean;
|
|
23
23
|
setEntireConfig(id: ComponentID, config: Record<string, any>): void;
|
package/dist/bit-map.js
CHANGED
|
@@ -53,7 +53,7 @@ class BitMap {
|
|
|
53
53
|
*/
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
addComponentConfig(id, aspectId, config = {}) {
|
|
56
|
+
addComponentConfig(id, aspectId, config = {}, shouldMergeConfig = false) {
|
|
57
57
|
if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);
|
|
58
58
|
const bitMapEntry = this.getBitmapEntry(id, {
|
|
59
59
|
ignoreScopeAndVersion: true
|
|
@@ -64,10 +64,22 @@ class BitMap {
|
|
|
64
64
|
return false; // no changes
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const getNewConfig = () => {
|
|
68
|
+
if (!config) return null;
|
|
69
|
+
if (!shouldMergeConfig) return config; // should merge
|
|
70
|
+
|
|
71
|
+
if (!currentConfig) return config;
|
|
72
|
+
if (currentConfig === '-') return config; // lodash merge performs a deep merge. (the native concatenation don't)
|
|
73
|
+
|
|
74
|
+
return (0, _lodash().merge)(currentConfig, config);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const newConfig = getNewConfig();
|
|
78
|
+
|
|
79
|
+
if (newConfig) {
|
|
80
|
+
bitMapEntry.config[aspectId] = newConfig;
|
|
69
81
|
} else {
|
|
70
|
-
bitMapEntry.config[aspectId]
|
|
82
|
+
delete bitMapEntry.config[aspectId];
|
|
71
83
|
}
|
|
72
84
|
|
|
73
85
|
this.legacyBitMap.markAsChanged();
|
package/dist/bit-map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BitMap","constructor","legacyBitMap","consumer","addComponentConfig","id","aspectId","config","Error","bitMapEntry","getBitmapEntry","ignoreScopeAndVersion","currentConfig","isEqual","markAsChanged","removeComponentConfig","markWithMinusIfNotExist","REMOVE_EXTENSION_SPECIAL_SIGN","removeEntireConfig","setEntireConfig","removeDefaultScope","defaultScope","setDefaultScope","write","writeBitMap","ignoreVersion","getComponent","_legacy","getAspectIdFromConfig","componentId","ignoreAspectVersion","undefined","toString","allVersions","Object","keys","filter","startsWith","toStringWithoutVersion","length","BitError","join","renameNewComponent","sourceId","targetId","hasVersion","removeComponent","setComponent","getExportedLaneId","isLaneExported","laneId","hasChanged"],"sources":["bit-map.ts"],"sourcesContent":["import { isEqual } from 'lodash';\nimport { ComponentID } from '@teambit/component-id';\nimport LegacyBitMap from '@teambit/legacy/dist/consumer/bit-map';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport { GetBitMapComponentOptions } from '@teambit/legacy/dist/consumer/bit-map/bit-map';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\nimport { REMOVE_EXTENSION_SPECIAL_SIGN } from '@teambit/legacy/dist/consumer/config';\nimport { BitError } from '@teambit/bit-error';\nimport { LaneId } from '@teambit/lane-id';\n/**\n * consider extracting to a new component.\n * (pro: making Workspace aspect smaller. con: it's an implementation details of the workspace)\n */\nexport class BitMap {\n constructor(private legacyBitMap: LegacyBitMap, private consumer: Consumer) {}\n\n /**\n * adds component config to the .bitmap file.\n * later, upon `bit tag`, the data is saved in the scope.\n * returns a boolean indicating whether a change has been made.\n */\n addComponentConfig(id: ComponentID, aspectId: string, config: Record<string, any> = {}): boolean {\n if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n const currentConfig = (bitMapEntry.config ||= {})[aspectId];\n if (isEqual(currentConfig, config)) {\n return false; // no changes\n }\n if (!config) {\n delete bitMapEntry.config[aspectId];\n } else {\n bitMapEntry.config[aspectId] = config;\n }\n this.legacyBitMap.markAsChanged();\n\n return true; // changes have been made\n }\n\n removeComponentConfig(id: ComponentID, aspectId: string, markWithMinusIfNotExist: boolean): boolean {\n if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n const currentConfig = (bitMapEntry.config ||= {})[aspectId];\n if (currentConfig) {\n delete bitMapEntry.config[aspectId];\n } else {\n if (!markWithMinusIfNotExist) {\n return false; // no changes\n }\n bitMapEntry.config[aspectId] = REMOVE_EXTENSION_SPECIAL_SIGN;\n }\n\n this.legacyBitMap.markAsChanged();\n\n return true; // changes have been made\n }\n\n removeEntireConfig(id: ComponentID): boolean {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n if (!bitMapEntry.config) return false;\n delete bitMapEntry.config;\n this.legacyBitMap.markAsChanged();\n return true;\n }\n\n setEntireConfig(id: ComponentID, config: Record<string, any>) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n bitMapEntry.config = config;\n this.legacyBitMap.markAsChanged();\n }\n\n removeDefaultScope(id: ComponentID) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n if (bitMapEntry.defaultScope) {\n delete bitMapEntry.defaultScope;\n this.legacyBitMap.markAsChanged();\n }\n }\n\n setDefaultScope(id: ComponentID, defaultScope: string) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n bitMapEntry.defaultScope = defaultScope;\n this.legacyBitMap.markAsChanged();\n }\n\n /**\n * write .bitmap object to the filesystem\n */\n async write() {\n await this.consumer.writeBitMap();\n }\n\n /**\n * get the data saved in the .bitmap file for this component-id.\n */\n getBitmapEntry(\n id: ComponentID,\n { ignoreVersion, ignoreScopeAndVersion }: GetBitMapComponentOptions = {}\n ): ComponentMap {\n return this.legacyBitMap.getComponent(id._legacy, { ignoreVersion, ignoreScopeAndVersion });\n }\n\n getAspectIdFromConfig(\n componentId: ComponentID,\n aspectId: ComponentID,\n ignoreAspectVersion = false\n ): string | undefined {\n const bitMapEntry = this.getBitmapEntry(componentId);\n const config = bitMapEntry.config;\n if (!config) {\n return undefined;\n }\n if (config[aspectId.toString()]) {\n return aspectId.toString();\n }\n if (!ignoreAspectVersion) {\n return undefined;\n }\n const allVersions = Object.keys(config).filter((id) => id.startsWith(`${aspectId.toStringWithoutVersion()}@`));\n if (allVersions.length > 1) {\n throw new BitError(\n `error: the same aspect ${\n aspectId.toStringWithoutVersion\n } configured multiple times for \"${componentId.toString()}\"\\n${allVersions.join('\\n')}`\n );\n }\n return allVersions.length === 1 ? allVersions[0] : undefined;\n }\n\n /**\n * components that were not tagged yet are safe to rename them from the .bitmap file.\n */\n renameNewComponent(sourceId: ComponentID, targetId: ComponentID) {\n const bitMapEntry = this.getBitmapEntry(sourceId);\n if (bitMapEntry.id.hasVersion()) {\n throw new Error(`unable to rename tagged or exported component: ${bitMapEntry.id.toString()}`);\n }\n this.legacyBitMap.removeComponent(bitMapEntry.id);\n bitMapEntry.id = targetId._legacy;\n this.legacyBitMap.setComponent(bitMapEntry.id, bitMapEntry);\n }\n\n /**\n * this is the lane-id of the recently exported lane. in case of a new lane, which was not exported yet, this will be\n * empty.\n */\n getExportedLaneId(): LaneId | undefined {\n return this.legacyBitMap.isLaneExported ? this.legacyBitMap.laneId : undefined;\n }\n\n /**\n * whether .bitmap file has changed in-memory\n */\n hasChanged(): boolean {\n return this.legacyBitMap.hasChanged;\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAMA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;AACA;AACA;AACA;AACO,MAAMA,MAAN,CAAa;EAClBC,WAAW,CAASC,YAAT,EAA6CC,QAA7C,EAAiE;IAAA,KAAxDD,YAAwD,GAAxDA,YAAwD;IAAA,KAApBC,QAAoB,GAApBA,QAAoB;EAAE;EAE9E;AACF;AACA;AACA;AACA;;;EACEC,kBAAkB,CAACC,EAAD,EAAkBC,QAAlB,EAAoCC,MAA2B,GAAG,EAAlE,EAA+E;IAC/F,IAAI,CAACD,QAAD,IAAa,OAAOA,QAAP,KAAoB,QAArC,EAA+C,MAAM,IAAIE,KAAJ,CAAW,qCAAoCF,QAAS,EAAxD,CAAN;IAC/C,MAAMG,WAAW,GAAG,KAAKC,cAAL,CAAoBL,EAApB,EAAwB;MAAEM,qBAAqB,EAAE;IAAzB,CAAxB,CAApB;IACA,MAAMC,aAAa,GAAG,CAACH,WAAW,CAACF,MAAb,KAACE,WAAW,CAACF,MAAb,GAAwB,EAAxB,GAA4BD,QAA5B,CAAtB;;IACA,IAAI,IAAAO,iBAAA,EAAQD,aAAR,EAAuBL,MAAvB,CAAJ,EAAoC;MAClC,OAAO,KAAP,CADkC,CACpB;IACf;;IACD,IAAI,CAACA,MAAL,EAAa;MACX,OAAOE,WAAW,CAACF,MAAZ,CAAmBD,QAAnB,CAAP;IACD,CAFD,MAEO;MACLG,WAAW,CAACF,MA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AArE;EACD;EAED;AACF;AACA;;;EACEoB,UAAU,GAAY;IACpB,OAAO,KAAKjD,YAAL,CAAkBiD,UAAzB;EACD;;AA7IiB"}
|
|
1
|
+
{"version":3,"names":["BitMap","constructor","legacyBitMap","consumer","addComponentConfig","id","aspectId","config","shouldMergeConfig","Error","bitMapEntry","getBitmapEntry","ignoreScopeAndVersion","currentConfig","isEqual","getNewConfig","merge","newConfig","markAsChanged","removeComponentConfig","markWithMinusIfNotExist","REMOVE_EXTENSION_SPECIAL_SIGN","removeEntireConfig","setEntireConfig","removeDefaultScope","defaultScope","setDefaultScope","write","writeBitMap","ignoreVersion","getComponent","_legacy","getAspectIdFromConfig","componentId","ignoreAspectVersion","undefined","toString","allVersions","Object","keys","filter","startsWith","toStringWithoutVersion","length","BitError","join","renameNewComponent","sourceId","targetId","hasVersion","removeComponent","setComponent","getExportedLaneId","isLaneExported","laneId","hasChanged"],"sources":["bit-map.ts"],"sourcesContent":["import { isEqual, merge } from 'lodash';\nimport { ComponentID } from '@teambit/component-id';\nimport LegacyBitMap from '@teambit/legacy/dist/consumer/bit-map';\nimport { Consumer } from '@teambit/legacy/dist/consumer';\nimport { GetBitMapComponentOptions } from '@teambit/legacy/dist/consumer/bit-map/bit-map';\nimport ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';\nimport { REMOVE_EXTENSION_SPECIAL_SIGN } from '@teambit/legacy/dist/consumer/config';\nimport { BitError } from '@teambit/bit-error';\nimport { LaneId } from '@teambit/lane-id';\n/**\n * consider extracting to a new component.\n * (pro: making Workspace aspect smaller. con: it's an implementation details of the workspace)\n */\nexport class BitMap {\n constructor(private legacyBitMap: LegacyBitMap, private consumer: Consumer) {}\n\n /**\n * adds component config to the .bitmap file.\n * later, upon `bit tag`, the data is saved in the scope.\n * returns a boolean indicating whether a change has been made.\n */\n addComponentConfig(\n id: ComponentID,\n aspectId: string,\n config: Record<string, any> = {},\n shouldMergeConfig = false\n ): boolean {\n if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n const currentConfig = (bitMapEntry.config ||= {})[aspectId];\n if (isEqual(currentConfig, config)) {\n return false; // no changes\n }\n const getNewConfig = () => {\n if (!config) return null;\n if (!shouldMergeConfig) return config;\n // should merge\n if (!currentConfig) return config;\n if (currentConfig === '-') return config;\n // lodash merge performs a deep merge. (the native concatenation don't)\n return merge(currentConfig, config);\n };\n const newConfig = getNewConfig();\n if (newConfig) {\n bitMapEntry.config[aspectId] = newConfig;\n } else {\n delete bitMapEntry.config[aspectId];\n }\n this.legacyBitMap.markAsChanged();\n\n return true; // changes have been made\n }\n\n removeComponentConfig(id: ComponentID, aspectId: string, markWithMinusIfNotExist: boolean): boolean {\n if (!aspectId || typeof aspectId !== 'string') throw new Error(`expect aspectId to be string, got ${aspectId}`);\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n const currentConfig = (bitMapEntry.config ||= {})[aspectId];\n if (currentConfig) {\n delete bitMapEntry.config[aspectId];\n } else {\n if (!markWithMinusIfNotExist) {\n return false; // no changes\n }\n bitMapEntry.config[aspectId] = REMOVE_EXTENSION_SPECIAL_SIGN;\n }\n\n this.legacyBitMap.markAsChanged();\n\n return true; // changes have been made\n }\n\n removeEntireConfig(id: ComponentID): boolean {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n if (!bitMapEntry.config) return false;\n delete bitMapEntry.config;\n this.legacyBitMap.markAsChanged();\n return true;\n }\n\n setEntireConfig(id: ComponentID, config: Record<string, any>) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n bitMapEntry.config = config;\n this.legacyBitMap.markAsChanged();\n }\n\n removeDefaultScope(id: ComponentID) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n if (bitMapEntry.defaultScope) {\n delete bitMapEntry.defaultScope;\n this.legacyBitMap.markAsChanged();\n }\n }\n\n setDefaultScope(id: ComponentID, defaultScope: string) {\n const bitMapEntry = this.getBitmapEntry(id, { ignoreScopeAndVersion: true });\n bitMapEntry.defaultScope = defaultScope;\n this.legacyBitMap.markAsChanged();\n }\n\n /**\n * write .bitmap object to the filesystem\n */\n async write() {\n await this.consumer.writeBitMap();\n }\n\n /**\n * get the data saved in the .bitmap file for this component-id.\n */\n getBitmapEntry(\n id: ComponentID,\n { ignoreVersion, ignoreScopeAndVersion }: GetBitMapComponentOptions = {}\n ): ComponentMap {\n return this.legacyBitMap.getComponent(id._legacy, { ignoreVersion, ignoreScopeAndVersion });\n }\n\n getAspectIdFromConfig(\n componentId: ComponentID,\n aspectId: ComponentID,\n ignoreAspectVersion = false\n ): string | undefined {\n const bitMapEntry = this.getBitmapEntry(componentId);\n const config = bitMapEntry.config;\n if (!config) {\n return undefined;\n }\n if (config[aspectId.toString()]) {\n return aspectId.toString();\n }\n if (!ignoreAspectVersion) {\n return undefined;\n }\n const allVersions = Object.keys(config).filter((id) => id.startsWith(`${aspectId.toStringWithoutVersion()}@`));\n if (allVersions.length > 1) {\n throw new BitError(\n `error: the same aspect ${\n aspectId.toStringWithoutVersion\n } configured multiple times for \"${componentId.toString()}\"\\n${allVersions.join('\\n')}`\n );\n }\n return allVersions.length === 1 ? allVersions[0] : undefined;\n }\n\n /**\n * components that were not tagged yet are safe to rename them from the .bitmap file.\n */\n renameNewComponent(sourceId: ComponentID, targetId: ComponentID) {\n const bitMapEntry = this.getBitmapEntry(sourceId);\n if (bitMapEntry.id.hasVersion()) {\n throw new Error(`unable to rename tagged or exported component: ${bitMapEntry.id.toString()}`);\n }\n this.legacyBitMap.removeComponent(bitMapEntry.id);\n bitMapEntry.id = targetId._legacy;\n this.legacyBitMap.setComponent(bitMapEntry.id, bitMapEntry);\n }\n\n /**\n * this is the lane-id of the recently exported lane. in case of a new lane, which was not exported yet, this will be\n * empty.\n */\n getExportedLaneId(): LaneId | undefined {\n return this.legacyBitMap.isLaneExported ? this.legacyBitMap.laneId : undefined;\n }\n\n /**\n * whether .bitmap file has changed in-memory\n */\n hasChanged(): boolean {\n return this.legacyBitMap.hasChanged;\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAMA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;AACA;AACA;AACA;AACO,MAAMA,MAAN,CAAa;EAClBC,WAAW,CAASC,YAAT,EAA6CC,QAA7C,EAAiE;IAAA,KAAxDD,YAAwD,GAAxDA,YAAwD;IAAA,KAApBC,QAAoB,GAApBA,QAAoB;EAAE;EAE9E;AACF;AACA;AACA;AACA;;;EACEC,kBAAkB,CAChBC,EADgB,EAEhBC,QAFgB,EAGhBC,MAA2B,GAAG,EAHd,EAIhBC,iBAAiB,GAAG,KAJJ,EAKP;IACT,IAAI,CAACF,QAAD,IAAa,OAAOA,QAAP,KAAoB,QAArC,EAA+C,MAAM,IAAIG,KAAJ,CAAW,qCAAoCH,QAAS,EAAxD,CAAN;IAC/C,MAAMI,WAAW,GAAG,KAAKC,cAAL,CAAoBN,EAApB,EAAwB;MAAEO,qBAAqB,EAAE;IAAzB,CAAxB,CAApB;IACA,MAAMC,aAAa,GAAG,CAACH,WAAW,CAACH,MAAb,KAACG,WAAW,CAACH,MAAb,GAAwB,EAAxB,GAA4BD,QAA5B,CAAtB;;IACA,IAAI,IAAAQ,iBAAA,EAAQD,aAAR,EAAuBN,MAAvB,CAAJ,EAAoC;MAClC,OAAO,KAAP,CADkC,CACpB;IACf;;IACD,MAAMQ,YAAY,GAAG,MAAM;MACzB,IAAI,CAACR,MAAL,EAAa,OAAO,IAAP;MACb,IAAI,CAACC,iBAAL,EAAwB,OAAOD,MAAP,CAFC,CAGzB;;MACA,IAAI,CAACM,aAAL,EAAoB,OAAON,MAAP;MACpB,IAAIM,aAAa,KAAK,GAAtB,EAA2B,OAAON,M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Z,GAAiB2C,QAAQ,CAACjB,OAA1B;IACA,KAAK7B,YAAL,CAAkBiD,YAAlB,CAA+BzC,WAAW,CAACL,EAA3C,EAA+CK,WAA/C;EACD;EAED;AACF;AACA;AACA;;;EACE0C,iBAAiB,GAAuB;IACtC,OAAO,KAAKlD,YAAL,CAAkBmD,cAAlB,GAAmC,KAAKnD,YAAL,CAAkBoD,MAArD,GAA8DnB,SAArE;EACD;EAED;AACF;AACA;;;EACEoB,UAAU,GAAY;IACpB,OAAO,KAAKrD,YAAL,CAAkBqD,UAAzB;EACD;;AA5JiB"}
|
|
@@ -25,7 +25,7 @@ export declare class ComponentConfigFile {
|
|
|
25
25
|
static load(componentDir: PathOsBasedAbsolute, aspectListFactory: (extensionDataList: ExtensionDataList) => Promise<AspectList>, outsideDefaultScope?: string): Promise<ComponentConfigFile | undefined>;
|
|
26
26
|
static composePath(componentRootFolder: string): string;
|
|
27
27
|
write(options?: WriteConfigFileOptions): Promise<void>;
|
|
28
|
-
addAspect(aspectId: string, config: any, resolveComponentId: ResolveComponentIdFunc): Promise<void>;
|
|
28
|
+
addAspect(aspectId: string, config: any, resolveComponentId: ResolveComponentIdFunc, shouldMergeConfig?: boolean): Promise<void>;
|
|
29
29
|
removeAspect(aspectId: string, markWithMinusIfNotExist: boolean, resolveComponentId: ResolveComponentIdFunc): Promise<void>;
|
|
30
30
|
private aspectEntryFromConfigObject;
|
|
31
31
|
toJson(): ComponentConfigFileJson;
|
|
@@ -101,6 +101,16 @@ function _config() {
|
|
|
101
101
|
return data;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
function _lodash() {
|
|
105
|
+
const data = require("lodash");
|
|
106
|
+
|
|
107
|
+
_lodash = function () {
|
|
108
|
+
return data;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return data;
|
|
112
|
+
}
|
|
113
|
+
|
|
104
114
|
function _exceptions() {
|
|
105
115
|
const data = require("./exceptions");
|
|
106
116
|
|
|
@@ -168,11 +178,20 @@ class ComponentConfigFile {
|
|
|
168
178
|
});
|
|
169
179
|
}
|
|
170
180
|
|
|
171
|
-
async addAspect(aspectId, config, resolveComponentId) {
|
|
181
|
+
async addAspect(aspectId, config, resolveComponentId, shouldMergeConfig = false) {
|
|
172
182
|
const existing = this.aspects.get(aspectId);
|
|
173
183
|
|
|
174
184
|
if (existing) {
|
|
175
|
-
|
|
185
|
+
const getNewConfig = () => {
|
|
186
|
+
if (!shouldMergeConfig) return config;
|
|
187
|
+
if (!config || config === '-') return config;
|
|
188
|
+
if (!existing.config) return config; // @ts-ignore
|
|
189
|
+
|
|
190
|
+
if (existing.config === '-') return config;
|
|
191
|
+
return (0, _lodash().merge)(existing.config, config);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
existing.config = getNewConfig();
|
|
176
195
|
} else {
|
|
177
196
|
const aspectEntry = await this.aspectEntryFromConfigObject(aspectId, config, resolveComponentId);
|
|
178
197
|
this.aspects.entries.push(aspectEntry);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_INDENT","DEFAULT_NEWLINE","ComponentConfigFile","constructor","componentId","aspects","componentDir","propagate","options","indent","newLine","defaultScope","load","aspectListFactory","outsideDefaultScope","filePath","composePath","isExist","fs","pathExists","undefined","content","readFile","parsed","parseComponentJsonContent","detectIndent","amount","detectNewline","ComponentID","fromObject","ExtensionDataList","fromConfigObject","extensions","Boolean","componentRootFolder","path","join","COMPONENT_CONFIG_FILE_NAME","write","json","toJson","override","AlreadyExistsError","writeJsonSync","spaces","EOL","addAspect","aspectId","config","resolveComponentId","existing","get","aspectEntry","aspectEntryFromConfigObject","entries","push","removeAspect","markWithMinusIfNotExist","aspectList","withoutEntries","REMOVE_EXTENSION_SPECIAL_SIGN","id","legacyEntry","configEntryToDataEntry","AspectEntry","toObject","toConfigObject","toString","stringifyPackage","str","dir","JSON","parse","err","Error","message"],"sources":["component-config-file.ts"],"sourcesContent":["import { ComponentID, AspectList, AspectEntry, ResolveComponentIdFunc } from '@teambit/component';\nimport { COMPONENT_CONFIG_FILE_NAME } from '@teambit/legacy/dist/constants';\nimport { ExtensionDataList, configEntryToDataEntry } from '@teambit/legacy/dist/consumer/config/extension-data';\nimport { PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';\nimport detectIndent from 'detect-indent';\nimport detectNewline from 'detect-newline';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport stringifyPackage from 'stringify-package';\nimport { REMOVE_EXTENSION_SPECIAL_SIGN } from '@teambit/legacy/dist/consumer/config';\n\nimport { AlreadyExistsError } from './exceptions';\n\ninterface ComponentConfigFileOptions {\n indent: number;\n newLine: '\\r\\n' | '\\n' | undefined;\n}\n\ninterface WriteConfigFileOptions {\n override?: boolean;\n}\n\ninterface ComponentConfigFileJson {\n componentId: any;\n // TODO: think if we want to change it to aspects\n extensions: any;\n propagate: boolean;\n defaultScope?: string;\n}\n\nconst DEFAULT_INDENT = 2;\nconst DEFAULT_NEWLINE = '\\n';\n\nexport class ComponentConfigFile {\n constructor(\n public componentId: ComponentID,\n public aspects: AspectList,\n private componentDir: PathOsBasedAbsolute,\n public propagate: boolean = false,\n private options: ComponentConfigFileOptions = { indent: DEFAULT_INDENT, newLine: DEFAULT_NEWLINE },\n public defaultScope?: string\n ) {}\n\n static async load(\n componentDir: PathOsBasedAbsolute,\n aspectListFactory: (extensionDataList: ExtensionDataList) => Promise<AspectList>,\n outsideDefaultScope?: string\n ): Promise<ComponentConfigFile | undefined> {\n const filePath = ComponentConfigFile.composePath(componentDir);\n const isExist = await fs.pathExists(filePath);\n if (!isExist) {\n return undefined;\n }\n const content = await fs.readFile(filePath, 'utf-8');\n const parsed: ComponentConfigFileJson = parseComponentJsonContent(content, componentDir);\n const indent = detectIndent(content).amount;\n const newLine = detectNewline(content);\n const componentId = ComponentID.fromObject(parsed.componentId, parsed.defaultScope || outsideDefaultScope);\n const aspects = await aspectListFactory(ExtensionDataList.fromConfigObject(parsed.extensions));\n\n return new ComponentConfigFile(\n componentId,\n aspects,\n componentDir,\n Boolean(parsed.propagate),\n { indent, newLine },\n parsed.defaultScope\n );\n }\n\n static composePath(componentRootFolder: string) {\n return path.join(componentRootFolder, COMPONENT_CONFIG_FILE_NAME);\n }\n\n async write(options: WriteConfigFileOptions = {}): Promise<void> {\n const json = this.toJson();\n const filePath = ComponentConfigFile.composePath(this.componentDir);\n const isExist = await fs.pathExists(filePath);\n if (isExist && !options.override) {\n throw new AlreadyExistsError(filePath);\n }\n return fs.writeJsonSync(filePath, json, { spaces: this.options.indent, EOL: this.options.newLine });\n }\n\n async addAspect(aspectId: string, config: any, resolveComponentId: ResolveComponentIdFunc) {\n const existing = this.aspects.get(aspectId);\n if (existing) {\n existing.config = config;\n } else {\n const aspectEntry = await this.aspectEntryFromConfigObject(aspectId, config, resolveComponentId);\n this.aspects.entries.push(aspectEntry);\n }\n }\n\n async removeAspect(aspectId: string, markWithMinusIfNotExist: boolean, resolveComponentId: ResolveComponentIdFunc) {\n const existing = this.aspects.get(aspectId);\n if (existing) {\n const aspectList = this.aspects.withoutEntries([aspectId]);\n this.aspects = aspectList;\n } else if (markWithMinusIfNotExist) {\n await this.addAspect(aspectId, REMOVE_EXTENSION_SPECIAL_SIGN, resolveComponentId);\n }\n }\n\n private async aspectEntryFromConfigObject(id: string, config: any, resolveComponentId: ResolveComponentIdFunc) {\n const aspectId = await resolveComponentId(id);\n const legacyEntry = configEntryToDataEntry(id, config);\n return new AspectEntry(aspectId, legacyEntry);\n }\n\n toJson(): ComponentConfigFileJson {\n return {\n componentId: this.componentId.toObject(),\n propagate: this.propagate,\n defaultScope: this.defaultScope,\n extensions: this.aspects.toConfigObject(),\n };\n }\n\n toString(): string {\n const json = this.toJson();\n return stringifyPackage(json, this.options.indent, this.options.newLine);\n }\n}\n\nfunction parseComponentJsonContent(str: string, dir: string) {\n try {\n return JSON.parse(str);\n } catch (err: any) {\n throw new Error(`failed parsing component.json file at ${dir}. original error: ${err.message}`);\n }\n}\n"],"mappings":";;;;;;;;;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;;EAEDtB,MAAM,GAA4B;IAChC,OAAO;MACLpC,WAAW,EAAE,KAAKA,WAAL,CAAiB6D,QAAjB,EADR;MAEL1D,SAAS,EAAE,KAAKA,SAFX;MAGLI,YAAY,EAAE,KAAKA,YAHd;MAILqB,UAAU,EAAE,KAAK3B,OAAL,CAAa6D,cAAb;IAJP,CAAP;EAMD;;EAEDC,QAAQ,GAAW;IACjB,MAAM5B,IAAI,GAAG,KAAKC,MAAL,EAAb;IACA,OAAO,IAAA4B,2BAAA,EAAiB7B,IAAjB,EAAuB,KAAK/B,OAAL,CAAaC,MAApC,EAA4C,KAAKD,OAAL,CAAaE,OAAzD,CAAP;EACD;;AAzF8B;;;;AA4FjC,SAASc,yBAAT,CAAmC6C,GAAnC,EAAgDC,GAAhD,EAA6D;EAC3D,IAAI;IACF,OAAOC,IAAI,CAACC,KAAL,CAAWH,GAAX,CAAP;EACD,CAFD,CAEE,OAAOI,GAAP,EAAiB;IACjB,MAAM,IAAIC,KAAJ,CAAW,yCAAwCJ,GAAI,qBAAoBG,GAAG,CAACE,OAAQ,EAAvF,CAAN;EACD;AACF"}
|
|
1
|
+
{"version":3,"names":["DEFAULT_INDENT","DEFAULT_NEWLINE","ComponentConfigFile","constructor","componentId","aspects","componentDir","propagate","options","indent","newLine","defaultScope","load","aspectListFactory","outsideDefaultScope","filePath","composePath","isExist","fs","pathExists","undefined","content","readFile","parsed","parseComponentJsonContent","detectIndent","amount","detectNewline","ComponentID","fromObject","ExtensionDataList","fromConfigObject","extensions","Boolean","componentRootFolder","path","join","COMPONENT_CONFIG_FILE_NAME","write","json","toJson","override","AlreadyExistsError","writeJsonSync","spaces","EOL","addAspect","aspectId","config","resolveComponentId","shouldMergeConfig","existing","get","getNewConfig","merge","aspectEntry","aspectEntryFromConfigObject","entries","push","removeAspect","markWithMinusIfNotExist","aspectList","withoutEntries","REMOVE_EXTENSION_SPECIAL_SIGN","id","legacyEntry","configEntryToDataEntry","AspectEntry","toObject","toConfigObject","toString","stringifyPackage","str","dir","JSON","parse","err","Error","message"],"sources":["component-config-file.ts"],"sourcesContent":["import { ComponentID, AspectList, AspectEntry, ResolveComponentIdFunc } from '@teambit/component';\nimport { COMPONENT_CONFIG_FILE_NAME } from '@teambit/legacy/dist/constants';\nimport { ExtensionDataList, configEntryToDataEntry } from '@teambit/legacy/dist/consumer/config/extension-data';\nimport { PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';\nimport detectIndent from 'detect-indent';\nimport detectNewline from 'detect-newline';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport stringifyPackage from 'stringify-package';\nimport { REMOVE_EXTENSION_SPECIAL_SIGN } from '@teambit/legacy/dist/consumer/config';\nimport { merge } from 'lodash';\nimport { AlreadyExistsError } from './exceptions';\n\ninterface ComponentConfigFileOptions {\n indent: number;\n newLine: '\\r\\n' | '\\n' | undefined;\n}\n\ninterface WriteConfigFileOptions {\n override?: boolean;\n}\n\ninterface ComponentConfigFileJson {\n componentId: any;\n // TODO: think if we want to change it to aspects\n extensions: any;\n propagate: boolean;\n defaultScope?: string;\n}\n\nconst DEFAULT_INDENT = 2;\nconst DEFAULT_NEWLINE = '\\n';\n\nexport class ComponentConfigFile {\n constructor(\n public componentId: ComponentID,\n public aspects: AspectList,\n private componentDir: PathOsBasedAbsolute,\n public propagate: boolean = false,\n private options: ComponentConfigFileOptions = { indent: DEFAULT_INDENT, newLine: DEFAULT_NEWLINE },\n public defaultScope?: string\n ) {}\n\n static async load(\n componentDir: PathOsBasedAbsolute,\n aspectListFactory: (extensionDataList: ExtensionDataList) => Promise<AspectList>,\n outsideDefaultScope?: string\n ): Promise<ComponentConfigFile | undefined> {\n const filePath = ComponentConfigFile.composePath(componentDir);\n const isExist = await fs.pathExists(filePath);\n if (!isExist) {\n return undefined;\n }\n const content = await fs.readFile(filePath, 'utf-8');\n const parsed: ComponentConfigFileJson = parseComponentJsonContent(content, componentDir);\n const indent = detectIndent(content).amount;\n const newLine = detectNewline(content);\n const componentId = ComponentID.fromObject(parsed.componentId, parsed.defaultScope || outsideDefaultScope);\n const aspects = await aspectListFactory(ExtensionDataList.fromConfigObject(parsed.extensions));\n\n return new ComponentConfigFile(\n componentId,\n aspects,\n componentDir,\n Boolean(parsed.propagate),\n { indent, newLine },\n parsed.defaultScope\n );\n }\n\n static composePath(componentRootFolder: string) {\n return path.join(componentRootFolder, COMPONENT_CONFIG_FILE_NAME);\n }\n\n async write(options: WriteConfigFileOptions = {}): Promise<void> {\n const json = this.toJson();\n const filePath = ComponentConfigFile.composePath(this.componentDir);\n const isExist = await fs.pathExists(filePath);\n if (isExist && !options.override) {\n throw new AlreadyExistsError(filePath);\n }\n return fs.writeJsonSync(filePath, json, { spaces: this.options.indent, EOL: this.options.newLine });\n }\n\n async addAspect(\n aspectId: string,\n config: any,\n resolveComponentId: ResolveComponentIdFunc,\n shouldMergeConfig = false\n ) {\n const existing = this.aspects.get(aspectId);\n\n if (existing) {\n const getNewConfig = () => {\n if (!shouldMergeConfig) return config;\n if (!config || config === '-') return config;\n if (!existing.config) return config;\n // @ts-ignore\n if (existing.config === '-') return config;\n return merge(existing.config, config);\n };\n existing.config = getNewConfig();\n } else {\n const aspectEntry = await this.aspectEntryFromConfigObject(aspectId, config, resolveComponentId);\n this.aspects.entries.push(aspectEntry);\n }\n }\n\n async removeAspect(aspectId: string, markWithMinusIfNotExist: boolean, resolveComponentId: ResolveComponentIdFunc) {\n const existing = this.aspects.get(aspectId);\n if (existing) {\n const aspectList = this.aspects.withoutEntries([aspectId]);\n this.aspects = aspectList;\n } else if (markWithMinusIfNotExist) {\n await this.addAspect(aspectId, REMOVE_EXTENSION_SPECIAL_SIGN, resolveComponentId);\n }\n }\n\n private async aspectEntryFromConfigObject(id: string, config: any, resolveComponentId: ResolveComponentIdFunc) {\n const aspectId = await resolveComponentId(id);\n const legacyEntry = configEntryToDataEntry(id, config);\n return new AspectEntry(aspectId, legacyEntry);\n }\n\n toJson(): ComponentConfigFileJson {\n return {\n componentId: this.componentId.toObject(),\n propagate: this.propagate,\n defaultScope: this.defaultScope,\n extensions: this.aspects.toConfigObject(),\n };\n }\n\n toString(): string {\n const json = this.toJson();\n return stringifyPackage(json, this.options.indent, this.options.newLine);\n }\n}\n\nfunction parseComponentJsonContent(str: string, dir: string) {\n try {\n return JSON.parse(str);\n } catch (err: any) {\n throw new Error(`failed parsing component.json file at ${dir}. original error: ${err.message}`);\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAmBA,MAAMA,cAAc,GAAG,CAAvB;AACA,MAAMC,eAAe,GAAG,IAAxB;;AAEO,MAAMC,mBAAN,CAA0B;EAC/BC,WAAW,CACFC,WADE,EAEFC,OAFE,EAGDC,YAHC,EAIFC,SAAkB,GAAG,KAJnB,EAKDC,OAAmC,GAAG;IAAEC,MAAM,EAAET,cAAV;IAA0BU,OAAO,EAAET;EAAnC,CALrC,EAMFU,YANE,EAOT;IAAA,KANOP,WAMP,GANOA,WAMP;IAAA,KALOC,OAKP,GALOA,OAKP;IAAA,KAJQC,YAIR,GAJQA,YAIR;IAAA,KAHOC,SAGP,GAHOA,SAGP;IAAA,KAFQC,OAER,GAFQA,OAER;IAAA,KADOG,YACP,GADOA,YACP;EAAE;;EAEa,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AL,CAAWH,GAAX,CAAP;EACD,CAFD,CAEE,OAAOI,GAAP,EAAiB;IACjB,MAAM,IAAIC,KAAJ,CAAW,yCAAwCJ,GAAI,qBAAoBG,GAAG,CAACE,OAAQ,EAAvF,CAAN;EACD;AACF"}
|
package/dist/workspace.d.ts
CHANGED
|
@@ -390,7 +390,7 @@ export declare class Workspace implements ComponentFactory {
|
|
|
390
390
|
*/
|
|
391
391
|
setDefaultScopeToComponents(componentIds: ComponentID[], scopeName: string): Promise<ComponentID[]>;
|
|
392
392
|
setDefaultScope(scopeName: string): Promise<void>;
|
|
393
|
-
addSpecificComponentConfig(id: ComponentID, aspectId: string, config?: Record<string, any
|
|
393
|
+
addSpecificComponentConfig(id: ComponentID, aspectId: string, config?: Record<string, any>, shouldMergeWithExisting?: boolean): Promise<void>;
|
|
394
394
|
removeSpecificComponentConfig(id: ComponentID, aspectId: string, markWithMinusIfNotExist: boolean): Promise<void>;
|
|
395
395
|
getAspectIdFromConfig(componentId: ComponentID, aspectIdStr: string, ignoreAspectVersion?: boolean): Promise<string | undefined>;
|
|
396
396
|
getSpecificComponentConfig(id: ComponentID, aspectId: string): Promise<any>;
|
package/dist/workspace.js
CHANGED
|
@@ -1707,16 +1707,16 @@ the following envs are used in this workspace: ${availableEnvs.join(', ')}`);
|
|
|
1707
1707
|
}));
|
|
1708
1708
|
}
|
|
1709
1709
|
|
|
1710
|
-
async addSpecificComponentConfig(id, aspectId, config = {}) {
|
|
1710
|
+
async addSpecificComponentConfig(id, aspectId, config = {}, shouldMergeWithExisting = false) {
|
|
1711
1711
|
const componentConfigFile = await this.componentConfigFile(id);
|
|
1712
1712
|
|
|
1713
1713
|
if (componentConfigFile) {
|
|
1714
|
-
await componentConfigFile.addAspect(aspectId, config, this.resolveComponentId.bind(this));
|
|
1714
|
+
await componentConfigFile.addAspect(aspectId, config, this.resolveComponentId.bind(this), shouldMergeWithExisting);
|
|
1715
1715
|
await componentConfigFile.write({
|
|
1716
1716
|
override: true
|
|
1717
1717
|
});
|
|
1718
1718
|
} else {
|
|
1719
|
-
this.bitMap.addComponentConfig(id, aspectId, config);
|
|
1719
|
+
this.bitMap.addComponentConfig(id, aspectId, config, shouldMergeWithExisting);
|
|
1720
1720
|
}
|
|
1721
1721
|
}
|
|
1722
1722
|
|
|
@@ -1935,6 +1935,7 @@ needed-for: ${neededFor || '<unknown>'}`);
|
|
|
1935
1935
|
}
|
|
1936
1936
|
|
|
1937
1937
|
async resolveAspects(runtimeName, componentIds, opts) {
|
|
1938
|
+
this.logger.debug(`workspace resolveAspects, runtimeName: ${runtimeName}, componentIds: ${componentIds}`);
|
|
1938
1939
|
const defaultOpts = {
|
|
1939
1940
|
excludeCore: false,
|
|
1940
1941
|
requestedOnly: false
|
|
@@ -1954,7 +1955,9 @@ needed-for: ${neededFor || '<unknown>'}`);
|
|
|
1954
1955
|
} = await this.groupIdsByWorkspaceAndScope(componentIdsToResolve);
|
|
1955
1956
|
const wsComponents = await this.getMany(workspaceIds);
|
|
1956
1957
|
const aspectDefs = await this.aspectLoader.resolveAspects(wsComponents, async component => {
|
|
1957
|
-
|
|
1958
|
+
const compStringId = component.id._legacy.toString();
|
|
1959
|
+
|
|
1960
|
+
stringIds.push(compStringId);
|
|
1958
1961
|
const localPath = this.getComponentPackagePath(component);
|
|
1959
1962
|
const isExist = await _fsExtra().default.pathExists(localPath);
|
|
1960
1963
|
|
|
@@ -1962,15 +1965,17 @@ needed-for: ${neededFor || '<unknown>'}`);
|
|
|
1962
1965
|
missingPaths = true;
|
|
1963
1966
|
}
|
|
1964
1967
|
|
|
1968
|
+
const runtimePath = runtimeName ? await this.aspectLoader.getRuntimePath(component, localPath, runtimeName) : null;
|
|
1969
|
+
this.logger.debug(`workspace resolveAspects, resolving id: ${compStringId}, localPath: ${localPath}, runtimePath: ${runtimePath}`);
|
|
1965
1970
|
return {
|
|
1966
1971
|
aspectPath: localPath,
|
|
1967
|
-
runtimePath
|
|
1972
|
+
runtimePath
|
|
1968
1973
|
};
|
|
1969
1974
|
});
|
|
1970
1975
|
let scopeAspectDefs = [];
|
|
1971
1976
|
|
|
1972
1977
|
if (scopeIds.length) {
|
|
1973
|
-
scopeAspectDefs = await this.scope.resolveAspects(runtimeName, scopeIds);
|
|
1978
|
+
scopeAspectDefs = await this.scope.resolveAspects(runtimeName, scopeIds, mergedOpts);
|
|
1974
1979
|
}
|
|
1975
1980
|
|
|
1976
1981
|
let coreAspectDefs = await Promise.all(coreAspectsIds.map(async coreId => {
|