@teambit/workspace 1.0.838 → 1.0.840
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 +8 -1
- package/dist/component-config-file/component-config-file.d.ts +1 -1
- package/dist/component-config-file/component-config-file.js +3 -0
- package/dist/component-config-file/component-config-file.js.map +1 -1
- package/dist/{preview-1764865689118.js → preview-1765230464444.js} +2 -2
- package/dist/workspace.d.ts +1 -1
- package/dist/workspace.js +17 -9
- package/dist/workspace.js.map +1 -1
- package/package.json +21 -21
|
@@ -127,14 +127,21 @@ export class ComponentConfigFile {
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
async removeAspect(
|
|
130
|
+
async removeAspect(
|
|
131
|
+
aspectId: string,
|
|
132
|
+
markWithMinusIfNotExist: boolean,
|
|
133
|
+
resolveComponentId: ResolveComponentIdFunc
|
|
134
|
+
): Promise<boolean> {
|
|
131
135
|
const existing = this.aspects.get(aspectId);
|
|
132
136
|
if (existing) {
|
|
133
137
|
const aspectList = this.aspects.withoutEntries([aspectId]);
|
|
134
138
|
this.aspects = aspectList;
|
|
139
|
+
return true;
|
|
135
140
|
} else if (markWithMinusIfNotExist) {
|
|
136
141
|
await this.addAspect(aspectId, REMOVE_EXTENSION_SPECIAL_SIGN, resolveComponentId);
|
|
142
|
+
return true;
|
|
137
143
|
}
|
|
144
|
+
return false;
|
|
138
145
|
}
|
|
139
146
|
|
|
140
147
|
private async aspectEntryFromConfigObject(id: string, config: any, resolveComponentId: ResolveComponentIdFunc) {
|
|
@@ -29,7 +29,7 @@ export declare class ComponentConfigFile {
|
|
|
29
29
|
toVinylFile(options?: WriteConfigFileOptions): Promise<JsonVinyl>;
|
|
30
30
|
write(options?: WriteConfigFileOptions): Promise<void>;
|
|
31
31
|
addAspect(aspectId: string, config: any, resolveComponentId: ResolveComponentIdFunc, shouldMergeConfig?: boolean): Promise<void>;
|
|
32
|
-
removeAspect(aspectId: string, markWithMinusIfNotExist: boolean, resolveComponentId: ResolveComponentIdFunc): Promise<
|
|
32
|
+
removeAspect(aspectId: string, markWithMinusIfNotExist: boolean, resolveComponentId: ResolveComponentIdFunc): Promise<boolean>;
|
|
33
33
|
private aspectEntryFromConfigObject;
|
|
34
34
|
toJson(): ComponentConfigFileJson;
|
|
35
35
|
}
|
|
@@ -154,9 +154,12 @@ class ComponentConfigFile {
|
|
|
154
154
|
if (existing) {
|
|
155
155
|
const aspectList = this.aspects.withoutEntries([aspectId]);
|
|
156
156
|
this.aspects = aspectList;
|
|
157
|
+
return true;
|
|
157
158
|
} else if (markWithMinusIfNotExist) {
|
|
158
159
|
await this.addAspect(aspectId, _legacy2().REMOVE_EXTENSION_SPECIAL_SIGN, resolveComponentId);
|
|
160
|
+
return true;
|
|
159
161
|
}
|
|
162
|
+
return false;
|
|
160
163
|
}
|
|
161
164
|
async aspectEntryFromConfigObject(id, config, resolveComponentId) {
|
|
162
165
|
const aspectId = await resolveComponentId(id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_component","data","require","_legacy","_legacy2","_component2","_detectIndent","_interopRequireDefault","_detectNewline","_fsExtra","_path","_lodash","_exceptions","e","__esModule","default","DEFAULT_INDENT","DEFAULT_NEWLINE","ComponentConfigFile","constructor","componentId","aspects","componentDir","propagate","options","indent","newLine","defaultScope","load","aspectListFactory","filePath","composePath","isExist","fs","pathExists","undefined","content","readFile","parsed","parseComponentJsonContent","detectIndent","detectNewline","scope","Error","ComponentID","fromObject","ExtensionDataList","fromConfigObject","extensions","Boolean","componentRootFolder","path","join","COMPONENT_CONFIG_FILE_NAME","toVinylFile","json","toJson","override","AlreadyExistsError","JsonVinyl","base","dirname","newline","write","vinyl","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","exports","str","dir","JSON","parse","err","message"],"sources":["component-config-file.ts"],"sourcesContent":["import type { AspectList, ResolveComponentIdFunc } from '@teambit/component';\nimport { ComponentID, AspectEntry } from '@teambit/component';\nimport { COMPONENT_CONFIG_FILE_NAME } from '@teambit/legacy.constants';\nimport {\n ExtensionDataList,\n configEntryToDataEntry,\n REMOVE_EXTENSION_SPECIAL_SIGN,\n} from '@teambit/legacy.extension-data';\nimport type { PathOsBasedAbsolute } from '@teambit/legacy.utils';\nimport { JsonVinyl } from '@teambit/component.sources';\nimport detectIndent from 'detect-indent';\nimport detectNewline from 'detect-newline';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport { merge } from 'lodash';\nimport { AlreadyExistsError } from './exceptions';\n\ninterface ComponentConfigFileOptions {\n indent: string;\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 = ' ';\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 ): 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).indent;\n const newLine = detectNewline(content);\n if (!parsed.componentId.scope) {\n throw new Error(\n `component.json file at ${componentDir} is invalid, it must contain 'scope' property in the componentId`\n );\n }\n const componentId = ComponentID.fromObject(parsed.componentId);\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 toVinylFile(options: WriteConfigFileOptions = {}): Promise<JsonVinyl> {\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\n return JsonVinyl.load({\n base: path.dirname(filePath),\n path: filePath,\n content: json,\n override: true,\n indent: this.options.indent,\n newline: this.options.newLine,\n });\n }\n\n async write(options: WriteConfigFileOptions = {}): Promise<void> {\n const vinyl = await this.toVinylFile(options);\n await vinyl.write();\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\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":";;;;;;AACA,SAAAA,WAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,UAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,QAAA;EAAA,MAAAF,IAAA,GAAAC,OAAA;EAAAC,OAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,SAAA;EAAA,MAAAH,IAAA,GAAAC,OAAA;EAAAE,QAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAMA,SAAAI,YAAA;EAAA,MAAAJ,IAAA,GAAAC,OAAA;EAAAG,WAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,cAAA;EAAA,MAAAL,IAAA,GAAAM,sBAAA,CAAAL,OAAA;EAAAI,aAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAO,eAAA;EAAA,MAAAP,IAAA,GAAAM,sBAAA,CAAAL,OAAA;EAAAM,cAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAQ,SAAA;EAAA,MAAAR,I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AAACC,OAAA,CAAAvE,mBAAA,GAAAA,mBAAA;AAED,SAASqB,yBAAyBA,CAACmD,GAAW,EAAEC,GAAW,EAAE;EAC3D,IAAI;IACF,OAAOC,IAAI,CAACC,KAAK,CAACH,GAAG,CAAC;EACxB,CAAC,CAAC,OAAOI,GAAQ,EAAE;IACjB,MAAM,IAAInD,KAAK,CAAC,yCAAyCgD,GAAG,qBAAqBG,GAAG,CAACC,OAAO,EAAE,CAAC;EACjG;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_component","data","require","_legacy","_legacy2","_component2","_detectIndent","_interopRequireDefault","_detectNewline","_fsExtra","_path","_lodash","_exceptions","e","__esModule","default","DEFAULT_INDENT","DEFAULT_NEWLINE","ComponentConfigFile","constructor","componentId","aspects","componentDir","propagate","options","indent","newLine","defaultScope","load","aspectListFactory","filePath","composePath","isExist","fs","pathExists","undefined","content","readFile","parsed","parseComponentJsonContent","detectIndent","detectNewline","scope","Error","ComponentID","fromObject","ExtensionDataList","fromConfigObject","extensions","Boolean","componentRootFolder","path","join","COMPONENT_CONFIG_FILE_NAME","toVinylFile","json","toJson","override","AlreadyExistsError","JsonVinyl","base","dirname","newline","write","vinyl","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","exports","str","dir","JSON","parse","err","message"],"sources":["component-config-file.ts"],"sourcesContent":["import type { AspectList, ResolveComponentIdFunc } from '@teambit/component';\nimport { ComponentID, AspectEntry } from '@teambit/component';\nimport { COMPONENT_CONFIG_FILE_NAME } from '@teambit/legacy.constants';\nimport {\n ExtensionDataList,\n configEntryToDataEntry,\n REMOVE_EXTENSION_SPECIAL_SIGN,\n} from '@teambit/legacy.extension-data';\nimport type { PathOsBasedAbsolute } from '@teambit/legacy.utils';\nimport { JsonVinyl } from '@teambit/component.sources';\nimport detectIndent from 'detect-indent';\nimport detectNewline from 'detect-newline';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport { merge } from 'lodash';\nimport { AlreadyExistsError } from './exceptions';\n\ninterface ComponentConfigFileOptions {\n indent: string;\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 = ' ';\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 ): 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).indent;\n const newLine = detectNewline(content);\n if (!parsed.componentId.scope) {\n throw new Error(\n `component.json file at ${componentDir} is invalid, it must contain 'scope' property in the componentId`\n );\n }\n const componentId = ComponentID.fromObject(parsed.componentId);\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 toVinylFile(options: WriteConfigFileOptions = {}): Promise<JsonVinyl> {\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\n return JsonVinyl.load({\n base: path.dirname(filePath),\n path: filePath,\n content: json,\n override: true,\n indent: this.options.indent,\n newline: this.options.newLine,\n });\n }\n\n async write(options: WriteConfigFileOptions = {}): Promise<void> {\n const vinyl = await this.toVinylFile(options);\n await vinyl.write();\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(\n aspectId: string,\n markWithMinusIfNotExist: boolean,\n resolveComponentId: ResolveComponentIdFunc\n ): Promise<boolean> {\n const existing = this.aspects.get(aspectId);\n if (existing) {\n const aspectList = this.aspects.withoutEntries([aspectId]);\n this.aspects = aspectList;\n return true;\n } else if (markWithMinusIfNotExist) {\n await this.addAspect(aspectId, REMOVE_EXTENSION_SPECIAL_SIGN, resolveComponentId);\n return true;\n }\n return false;\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\nfunction parseComponentJsonContent(str: string, dir: string) {\n try {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GAAG,CAACC,OAAO,EAAE,CAAC;EACjG;AACF","ignoreList":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_workspace@1.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_workspace@1.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_workspace@1.0.840/dist/workspace.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad/teambit.workspace_workspace@1.0.840/dist/workspace.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
package/dist/workspace.d.ts
CHANGED
|
@@ -519,7 +519,7 @@ export declare class Workspace implements ComponentFactory {
|
|
|
519
519
|
*/
|
|
520
520
|
shouldMergeWithPrevious?: boolean;
|
|
521
521
|
}): Promise<void>;
|
|
522
|
-
removeSpecificComponentConfig(id: ComponentID, aspectId: string, markWithMinusIfNotExist?: boolean): Promise<
|
|
522
|
+
removeSpecificComponentConfig(id: ComponentID, aspectId: string, markWithMinusIfNotExist?: boolean): Promise<boolean>;
|
|
523
523
|
getAspectIdFromConfig(componentId: ComponentID, aspectIdStr: string, ignoreAspectVersion?: boolean): Promise<string | undefined>;
|
|
524
524
|
getSpecificComponentConfig(id: ComponentID, aspectId: string): Promise<any>;
|
|
525
525
|
private isVendorComponentByComponentDir;
|
package/dist/workspace.js
CHANGED
|
@@ -1696,12 +1696,15 @@ the following envs are used in this workspace: ${(0, _lodash().uniq)(availableEn
|
|
|
1696
1696
|
async removeSpecificComponentConfig(id, aspectId, markWithMinusIfNotExist = false) {
|
|
1697
1697
|
const componentConfigFile = await this.componentConfigFile(id);
|
|
1698
1698
|
if (componentConfigFile) {
|
|
1699
|
-
await componentConfigFile.removeAspect(aspectId, markWithMinusIfNotExist, this.resolveComponentId.bind(this));
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1699
|
+
const removed = await componentConfigFile.removeAspect(aspectId, markWithMinusIfNotExist, this.resolveComponentId.bind(this));
|
|
1700
|
+
if (removed) {
|
|
1701
|
+
await componentConfigFile.write({
|
|
1702
|
+
override: true
|
|
1703
|
+
});
|
|
1704
|
+
}
|
|
1705
|
+
return removed;
|
|
1703
1706
|
} else {
|
|
1704
|
-
this.bitMap.removeComponentConfig(id, aspectId, markWithMinusIfNotExist);
|
|
1707
|
+
return this.bitMap.removeComponentConfig(id, aspectId, markWithMinusIfNotExist);
|
|
1705
1708
|
}
|
|
1706
1709
|
}
|
|
1707
1710
|
async getAspectIdFromConfig(componentId, aspectIdStr, ignoreAspectVersion = false) {
|
|
@@ -2205,12 +2208,17 @@ the following envs are used in this workspace: ${(0, _lodash().uniq)(availableEn
|
|
|
2205
2208
|
// env by `this.getAspectIdFromConfig`, it returns the env with version.
|
|
2206
2209
|
// to make sure we remove the env from the .bitmap, we need to remove both with and without version.
|
|
2207
2210
|
const currentEnvWithPotentialVersion = await this.getAspectIdFromConfig(id, currentEnv, true);
|
|
2208
|
-
|
|
2211
|
+
let anyRemoved = false;
|
|
2212
|
+
anyRemoved = (await this.removeSpecificComponentConfig(id, currentEnv)) || anyRemoved;
|
|
2209
2213
|
if (currentEnvWithPotentialVersion && currentEnvWithPotentialVersion.includes('@')) {
|
|
2210
|
-
await this.removeSpecificComponentConfig(id, currentEnvWithPotentialVersion);
|
|
2214
|
+
anyRemoved = (await this.removeSpecificComponentConfig(id, currentEnvWithPotentialVersion)) || anyRemoved;
|
|
2215
|
+
}
|
|
2216
|
+
anyRemoved = (await this.removeSpecificComponentConfig(id, _envs().EnvsAspect.id)) || anyRemoved;
|
|
2217
|
+
if (anyRemoved) {
|
|
2218
|
+
changed.push(id);
|
|
2219
|
+
} else {
|
|
2220
|
+
unchanged.push(id);
|
|
2211
2221
|
}
|
|
2212
|
-
await this.removeSpecificComponentConfig(id, _envs().EnvsAspect.id);
|
|
2213
|
-
changed.push(id);
|
|
2214
2222
|
}));
|
|
2215
2223
|
await this.bitMap.write(`env-unset`);
|
|
2216
2224
|
return {
|