@teambit/config 0.0.398 → 0.0.402

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.
@@ -1,10 +1,47 @@
1
- import configProvider from './config.provider';
2
- declare const ConfigMain: {
3
- name: string;
4
- runtime: import("@teambit/harmony").RuntimeDefinition;
5
- dependencies: never[];
6
- config: {};
7
- provider: typeof configProvider;
1
+ import { ExtensionDataEntry, ExtensionDataList } from '@teambit/legacy/dist/consumer/config';
2
+ import { PathOsBased, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';
3
+ import { CLIMain } from '@teambit/cli';
4
+ import { SlotRegistry, GlobalConfig } from '@teambit/harmony';
5
+ import { LegacyInitProps, WorkspaceConfig, WorkspaceConfigFileProps } from './workspace-config';
6
+ import { ConfigType, HostConfig } from './types';
7
+ export declare type SetExtensionOptions = {
8
+ overrideExisting: boolean;
9
+ ignoreVersion: boolean;
8
10
  };
9
- export { ConfigMain };
10
- export default ConfigMain;
11
+ export declare type ConfigDeps = [];
12
+ export declare type ConfigConfig = {};
13
+ /**
14
+ * pass the aspectIds entered by the user. returns the complete ids including versions.
15
+ */
16
+ export declare type PreAddingAspects = (aspectIds: string[]) => Promise<string[]>;
17
+ export declare type PreAddingAspectsSlot = SlotRegistry<PreAddingAspects>;
18
+ export declare class ConfigMain {
19
+ workspaceConfig?: WorkspaceConfig | undefined;
20
+ scopeConfig?: WorkspaceConfig | undefined;
21
+ preAddingAspectsSlot?: PreAddingAspectsSlot | undefined;
22
+ constructor(workspaceConfig?: WorkspaceConfig | undefined, scopeConfig?: WorkspaceConfig | undefined, preAddingAspectsSlot?: PreAddingAspectsSlot | undefined);
23
+ get type(): ConfigType;
24
+ get path(): PathOsBased | undefined;
25
+ get config(): HostConfig | undefined;
26
+ /**
27
+ * Ensure the given directory has a workspace config
28
+ * Load if existing and create new if not
29
+ *
30
+ * @static
31
+ * @param {PathOsBasedAbsolute} dirPath
32
+ * @param {WorkspaceConfigFileProps} [workspaceConfigProps={} as any]
33
+ * @returns {Promise<WorkspaceConfig>}
34
+ * @memberof WorkspaceConfig
35
+ */
36
+ static ensureWorkspace(dirPath: PathOsBasedAbsolute, workspaceConfigProps?: WorkspaceConfigFileProps, legacyInitProps?: LegacyInitProps): Promise<ConfigMain>;
37
+ get extensions(): ExtensionDataList | undefined;
38
+ extension(extensionId: string, ignoreVersion: boolean): ExtensionDataEntry | undefined;
39
+ setExtension(extensionId: string, config: Record<string, any>, options: SetExtensionOptions): void;
40
+ getHarmonyConfigObject(): GlobalConfig;
41
+ registerPreAddingAspectsSlot(func: PreAddingAspects): void;
42
+ static runtime: import("@teambit/harmony").RuntimeDefinition;
43
+ static slots: ((registerFn: () => string) => SlotRegistry<PreAddingAspects>)[];
44
+ static dependencies: import("@teambit/harmony").Aspect[];
45
+ static config: {};
46
+ static provider([cli]: [CLIMain], config: any, [preAddingAspectsSlot]: [PreAddingAspectsSlot]): Promise<any>;
47
+ }
@@ -2,10 +2,44 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
+ require("core-js/modules/es.array.iterator.js");
6
+
7
+ require("core-js/modules/es.promise.js");
8
+
5
9
  Object.defineProperty(exports, "__esModule", {
6
10
  value: true
7
11
  });
8
- exports.default = exports.ConfigMain = void 0;
12
+ exports.ConfigMain = void 0;
13
+
14
+ function _defineProperty2() {
15
+ const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
+
17
+ _defineProperty2 = function () {
18
+ return data;
19
+ };
20
+
21
+ return data;
22
+ }
23
+
24
+ function _consumer() {
25
+ const data = require("@teambit/legacy/dist/consumer");
26
+
27
+ _consumer = function () {
28
+ return data;
29
+ };
30
+
31
+ return data;
32
+ }
33
+
34
+ function _workspaceConfig() {
35
+ const data = _interopRequireDefault(require("@teambit/legacy/dist/consumer/config/workspace-config"));
36
+
37
+ _workspaceConfig = function () {
38
+ return data;
39
+ };
40
+
41
+ return data;
42
+ }
9
43
 
10
44
  function _cli() {
11
45
  const data = require("@teambit/cli");
@@ -17,37 +51,208 @@ function _cli() {
17
51
  return data;
18
52
  }
19
53
 
20
- function _config() {
21
- const data = require("./config.aspect");
54
+ function _harmony() {
55
+ const data = require("@teambit/harmony");
22
56
 
23
- _config = function () {
57
+ _harmony = function () {
58
+ return data;
59
+ };
60
+
61
+ return data;
62
+ }
63
+
64
+ function _path() {
65
+ const data = _interopRequireDefault(require("path"));
66
+
67
+ _path = function () {
68
+ return data;
69
+ };
70
+
71
+ return data;
72
+ }
73
+
74
+ function _use() {
75
+ const data = require("./use.cmd");
76
+
77
+ _use = function () {
78
+ return data;
79
+ };
80
+
81
+ return data;
82
+ }
83
+
84
+ function _workspaceConfig2() {
85
+ const data = require("./workspace-config");
86
+
87
+ _workspaceConfig2 = function () {
24
88
  return data;
25
89
  };
26
90
 
27
91
  return data;
28
92
  }
29
93
 
30
- function _config2() {
31
- const data = _interopRequireDefault(require("./config.provider"));
94
+ function _config() {
95
+ const data = require("./config.aspect");
32
96
 
33
- _config2 = function () {
97
+ _config = function () {
34
98
  return data;
35
99
  };
36
100
 
37
101
  return data;
38
102
  }
39
103
 
40
- const ConfigMain = {
41
- name: 'config',
42
- runtime: _cli().MainRuntime,
43
- dependencies: [],
44
- config: {},
45
- provider: _config2().default
46
- };
104
+ class ConfigMain {
105
+ constructor(workspaceConfig, scopeConfig, preAddingAspectsSlot) {
106
+ this.workspaceConfig = workspaceConfig;
107
+ this.scopeConfig = scopeConfig;
108
+ this.preAddingAspectsSlot = preAddingAspectsSlot;
109
+ }
110
+
111
+ get type() {
112
+ if (this.workspaceConfig) {
113
+ return 'workspace';
114
+ }
115
+
116
+ return 'scope';
117
+ }
118
+
119
+ get path() {
120
+ var _this$config;
121
+
122
+ return (_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.path;
123
+ }
124
+
125
+ get config() {
126
+ if (this.workspaceConfig) {
127
+ return this.workspaceConfig;
128
+ }
129
+
130
+ return this.scopeConfig;
131
+ }
132
+ /**
133
+ * Ensure the given directory has a workspace config
134
+ * Load if existing and create new if not
135
+ *
136
+ * @static
137
+ * @param {PathOsBasedAbsolute} dirPath
138
+ * @param {WorkspaceConfigFileProps} [workspaceConfigProps={} as any]
139
+ * @returns {Promise<WorkspaceConfig>}
140
+ * @memberof WorkspaceConfig
141
+ */
142
+
143
+
144
+ static async ensureWorkspace(dirPath, workspaceConfigProps = {}, legacyInitProps) {
145
+ const workspaceConfig = await _workspaceConfig2().WorkspaceConfig.ensure(dirPath, workspaceConfigProps, legacyInitProps);
146
+ return new ConfigMain(workspaceConfig);
147
+ }
148
+
149
+ get extensions() {
150
+ var _this$config2;
151
+
152
+ return (_this$config2 = this.config) === null || _this$config2 === void 0 ? void 0 : _this$config2.extensions;
153
+ }
154
+
155
+ extension(extensionId, ignoreVersion) {
156
+ var _this$config3;
157
+
158
+ return (_this$config3 = this.config) === null || _this$config3 === void 0 ? void 0 : _this$config3.extension(extensionId, ignoreVersion);
159
+ }
160
+
161
+ setExtension(extensionId, config, options) {
162
+ var _this$config4;
163
+
164
+ (_this$config4 = this.config) === null || _this$config4 === void 0 ? void 0 : _this$config4.setExtension(extensionId, config, options);
165
+ }
166
+
167
+ getHarmonyConfigObject() {
168
+ const config = {};
169
+ if (!this.extensions) return config;
170
+ this.extensions.forEach(extension => {
171
+ config[extension.stringId] = extension.config;
172
+ });
173
+ return config;
174
+ }
175
+
176
+ registerPreAddingAspectsSlot(func) {
177
+ var _this$preAddingAspect;
178
+
179
+ (_this$preAddingAspect = this.preAddingAspectsSlot) === null || _this$preAddingAspect === void 0 ? void 0 : _this$preAddingAspect.register(func);
180
+ }
181
+
182
+ static async provider([cli], config, [preAddingAspectsSlot]) {
183
+ _workspaceConfig().default.registerOnWorkspaceConfigIsExist(onLegacyWorkspaceConfigIsExist());
184
+
185
+ _workspaceConfig().default.registerOnWorkspaceConfigEnsuring(onLegacyWorkspaceEnsure());
186
+
187
+ const consumerInfo = await (0, _consumer().getConsumerInfo)(process.cwd());
188
+ let configMain;
189
+ const configDirPath = (consumerInfo === null || consumerInfo === void 0 ? void 0 : consumerInfo.path) || process.cwd();
190
+ const workspaceConfig = await _workspaceConfig2().WorkspaceConfig.loadIfExist(configDirPath);
191
+
192
+ if (workspaceConfig) {
193
+ configMain = new ConfigMain(workspaceConfig, undefined, preAddingAspectsSlot);
194
+ } else {
195
+ // TODO: try load scope config here
196
+ configMain = {};
197
+ }
198
+
199
+ _workspaceConfig().default.registerOnWorkspaceConfigLoading(onLegacyWorkspaceLoad(configMain));
200
+
201
+ _workspaceConfig().default.registerOnWorkspaceConfigReset((dirPath, resetHard) => _workspaceConfig2().WorkspaceConfig.reset(dirPath, resetHard));
202
+
203
+ cli.register(new (_use().UseCmd)(configMain));
204
+ return configMain;
205
+ }
206
+
207
+ }
208
+
47
209
  exports.ConfigMain = ConfigMain;
48
- var _default = ConfigMain;
49
- exports.default = _default;
210
+ (0, _defineProperty2().default)(ConfigMain, "runtime", _cli().MainRuntime);
211
+ (0, _defineProperty2().default)(ConfigMain, "slots", [_harmony().Slot.withType()]);
212
+ (0, _defineProperty2().default)(ConfigMain, "dependencies", [_cli().CLIAspect]);
213
+ (0, _defineProperty2().default)(ConfigMain, "config", {});
50
214
 
51
215
  _config().ConfigAspect.addRuntime(ConfigMain);
52
216
 
217
+ function onLegacyWorkspaceConfigIsExist() {
218
+ return async dirPath => {
219
+ return _workspaceConfig2().WorkspaceConfig.isExist(dirPath);
220
+ };
221
+ }
222
+
223
+ function onLegacyWorkspaceLoad(config) {
224
+ return async dirPath => {
225
+ if (config !== null && config !== void 0 && config.workspaceConfig && config.path && _path().default.normalize(dirPath) === _path().default.dirname(config.path)) {
226
+ return config.config.toLegacy();
227
+ }
228
+
229
+ const newConfig = await _workspaceConfig2().WorkspaceConfig.loadIfExist(dirPath);
230
+
231
+ if (newConfig) {
232
+ return newConfig.toLegacy();
233
+ }
234
+
235
+ return undefined;
236
+ };
237
+ }
238
+
239
+ function onLegacyWorkspaceEnsure() {
240
+ const func = async (dirPath, standAlone = false, legacyWorkspaceConfigProps) => {
241
+ let workspaceConfigProps;
242
+
243
+ if (legacyWorkspaceConfigProps) {
244
+ workspaceConfigProps = (0, _workspaceConfig2().transformLegacyPropsToExtensions)(legacyWorkspaceConfigProps);
245
+ }
246
+
247
+ const legacyInitProps = {
248
+ standAlone
249
+ };
250
+ const config = await ConfigMain.ensureWorkspace(dirPath, workspaceConfigProps, legacyInitProps);
251
+ const workspaceConfig = config.config;
252
+ return workspaceConfig.toLegacy();
253
+ };
254
+
255
+ return func;
256
+ }
257
+
53
258
  //# sourceMappingURL=config.main.runtime.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["config.main.runtime.ts"],"names":["ConfigMain","name","runtime","MainRuntime","dependencies","config","provider","configProvider","ConfigAspect","addRuntime"],"mappings":";;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA,MAAMA,UAAU,GAAG;AACjBC,EAAAA,IAAI,EAAE,QADW;AAEjBC,EAAAA,OAAO,EAAEC,kBAFQ;AAGjBC,EAAAA,YAAY,EAAE,EAHG;AAIjBC,EAAAA,MAAM,EAAE,EAJS;AAKjBC,EAAAA,QAAQ,EAAEC;AALO,CAAnB;;eAUeP,U;;;AAEfQ,uBAAaC,UAAb,CAAwBT,UAAxB","sourcesContent":["import { MainRuntime } from '@teambit/cli';\n\nimport { ConfigAspect } from './config.aspect';\nimport configProvider from './config.provider';\n\nconst ConfigMain = {\n name: 'config',\n runtime: MainRuntime,\n dependencies: [],\n config: {},\n provider: configProvider,\n};\n\nexport { ConfigMain };\n\nexport default ConfigMain;\n\nConfigAspect.addRuntime(ConfigMain);\n"]}
1
+ {"version":3,"sources":["config.main.runtime.ts"],"names":["ConfigMain","constructor","workspaceConfig","scopeConfig","preAddingAspectsSlot","type","path","config","ensureWorkspace","dirPath","workspaceConfigProps","legacyInitProps","WorkspaceConfig","ensure","extensions","extension","extensionId","ignoreVersion","setExtension","options","getHarmonyConfigObject","forEach","stringId","registerPreAddingAspectsSlot","func","register","provider","cli","LegacyWorkspaceConfig","registerOnWorkspaceConfigIsExist","onLegacyWorkspaceConfigIsExist","registerOnWorkspaceConfigEnsuring","onLegacyWorkspaceEnsure","consumerInfo","process","cwd","configMain","configDirPath","loadIfExist","undefined","registerOnWorkspaceConfigLoading","onLegacyWorkspaceLoad","registerOnWorkspaceConfigReset","resetHard","reset","UseCmd","MainRuntime","Slot","withType","CLIAspect","ConfigAspect","addRuntime","isExist","normalize","dirname","toLegacy","newConfig","standAlone","legacyWorkspaceConfigProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAOA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAMA;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;;AAOA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAiBO,MAAMA,UAAN,CAAiB;AACtBC,EAAAA,WAAW,CACFC,eADE,EAEFC,WAFE,EAGFC,oBAHE,EAIT;AAAA,SAHOF,eAGP,GAHOA,eAGP;AAAA,SAFOC,WAEP,GAFOA,WAEP;AAAA,SADOC,oBACP,GADOA,oBACP;AAAE;;AAEI,MAAJC,IAAI,GAAe;AACrB,QAAI,KAAKH,eAAT,EAA0B;AACxB,aAAO,WAAP;AACD;;AACD,WAAO,OAAP;AACD;;AAEO,MAAJI,IAAI,GAA4B;AAAA;;AAClC,2BAAO,KAAKC,MAAZ,iDAAO,aAAaD,IAApB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BwC,OAAhB,CAAwB3C,OAAxB,CAAP;AACD,GAFD;AAGD;;AAED,SAASgC,qBAAT,CAA+BlC,MAA/B,EAAiF;AAC/E,SAAO,MAAOE,OAAP,IAA6E;AAClF,QAAIF,MAAM,SAAN,IAAAA,MAAM,WAAN,IAAAA,MAAM,CAAEL,eAAR,IAA2BK,MAAM,CAACD,IAAlC,IAA0CA,gBAAK+C,SAAL,CAAe5C,OAAf,MAA4BH,gBAAKgD,OAAL,CAAa/C,MAAM,CAACD,IAApB,CAA1E,EAAqG;AACnG,aAAQC,MAAM,CAACA,MAAR,CAAmCgD,QAAnC,EAAP;AACD;;AACD,UAAMC,SAAS,GAAG,MAAM5C,oCAAgB0B,WAAhB,CAA4B7B,OAA5B,CAAxB;;AACA,QAAI+C,SAAJ,EAAe;AACb,aAAOA,SAAS,CAACD,QAAV,EAAP;AACD;;AACD,WAAOhB,SAAP;AACD,GATD;AAUD;;AAED,SAASP,uBAAT,GAAkE;AAChE,QAAMR,IAAmC,GAAG,OAC1Cf,OAD0C,EAE1CgD,UAAU,GAAG,KAF6B,EAG1CC,0BAH0C,KAIvC;AACH,QAAIhD,oBAAJ;;AACA,QAAIgD,0BAAJ,EAAgC;AAC9BhD,MAAAA,oBAAoB,GAAG,0DAAiCgD,0BAAjC,CAAvB;AACD;;AACD,UAAM/C,eAAgC,GAAG;AACvC8C,MAAAA;AADuC,KAAzC;AAGA,UAAMlD,MAAM,GAAG,MAAMP,UAAU,CAACQ,eAAX,CAA2BC,OAA3B,EAAoCC,oBAApC,EAA0DC,eAA1D,CAArB;AACA,UAAMT,eAAe,GAAGK,MAAM,CAACA,MAA/B;AACA,WAAQL,eAAD,CAAqCqD,QAArC,EAAP;AACD,GAfD;;AAgBA,SAAO/B,IAAP;AACD","sourcesContent":["import { getConsumerInfo } from '@teambit/legacy/dist/consumer';\nimport {\n ExtensionDataEntry,\n ExtensionDataList,\n ILegacyWorkspaceConfig,\n LegacyWorkspaceConfigProps,\n} from '@teambit/legacy/dist/consumer/config';\nimport LegacyWorkspaceConfig, {\n WorkspaceConfigEnsureFunction,\n WorkspaceConfigIsExistFunction,\n WorkspaceConfigLoadFunction,\n} from '@teambit/legacy/dist/consumer/config/workspace-config';\nimport { PathOsBased, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';\nimport { CLIAspect, MainRuntime, CLIMain } from '@teambit/cli';\nimport { Slot, SlotRegistry, GlobalConfig } from '@teambit/harmony';\nimport path from 'path';\nimport { UseCmd } from './use.cmd';\nimport {\n LegacyInitProps,\n transformLegacyPropsToExtensions,\n WorkspaceConfig,\n WorkspaceConfigFileProps,\n} from './workspace-config';\nimport { ConfigType, HostConfig } from './types';\nimport { ConfigAspect } from './config.aspect';\n\nexport type SetExtensionOptions = {\n overrideExisting: boolean;\n ignoreVersion: boolean;\n};\n\nexport type ConfigDeps = [];\n\nexport type ConfigConfig = {};\n\n/**\n * pass the aspectIds entered by the user. returns the complete ids including versions.\n */\nexport type PreAddingAspects = (aspectIds: string[]) => Promise<string[]>;\nexport type PreAddingAspectsSlot = SlotRegistry<PreAddingAspects>;\n\nexport class ConfigMain {\n constructor(\n public workspaceConfig?: WorkspaceConfig,\n public scopeConfig?: WorkspaceConfig,\n public preAddingAspectsSlot?: PreAddingAspectsSlot\n ) {}\n\n get type(): ConfigType {\n if (this.workspaceConfig) {\n return 'workspace';\n }\n return 'scope';\n }\n\n get path(): PathOsBased | undefined {\n return this.config?.path;\n }\n\n get config(): HostConfig | undefined {\n if (this.workspaceConfig) {\n return this.workspaceConfig;\n }\n return this.scopeConfig;\n }\n\n /**\n * Ensure the given directory has a workspace config\n * Load if existing and create new if not\n *\n * @static\n * @param {PathOsBasedAbsolute} dirPath\n * @param {WorkspaceConfigFileProps} [workspaceConfigProps={} as any]\n * @returns {Promise<WorkspaceConfig>}\n * @memberof WorkspaceConfig\n */\n static async ensureWorkspace(\n dirPath: PathOsBasedAbsolute,\n workspaceConfigProps: WorkspaceConfigFileProps = {} as any,\n legacyInitProps?: LegacyInitProps\n ): Promise<ConfigMain> {\n const workspaceConfig = await WorkspaceConfig.ensure(dirPath, workspaceConfigProps, legacyInitProps);\n return new ConfigMain(workspaceConfig);\n }\n\n get extensions(): ExtensionDataList | undefined {\n return this.config?.extensions;\n }\n\n extension(extensionId: string, ignoreVersion: boolean): ExtensionDataEntry | undefined {\n return this.config?.extension(extensionId, ignoreVersion);\n }\n\n setExtension(extensionId: string, config: Record<string, any>, options: SetExtensionOptions) {\n this.config?.setExtension(extensionId, config, options);\n }\n\n getHarmonyConfigObject(): GlobalConfig {\n const config = {};\n if (!this.extensions) return config;\n this.extensions.forEach((extension) => {\n config[extension.stringId] = extension.config;\n });\n return config;\n }\n\n registerPreAddingAspectsSlot(func: PreAddingAspects) {\n this.preAddingAspectsSlot?.register(func);\n }\n\n static runtime = MainRuntime;\n static slots = [Slot.withType<PreAddingAspects>()];\n static dependencies = [CLIAspect];\n static config = {};\n static async provider([cli]: [CLIMain], config: any, [preAddingAspectsSlot]: [PreAddingAspectsSlot]) {\n LegacyWorkspaceConfig.registerOnWorkspaceConfigIsExist(onLegacyWorkspaceConfigIsExist());\n LegacyWorkspaceConfig.registerOnWorkspaceConfigEnsuring(onLegacyWorkspaceEnsure());\n const consumerInfo = await getConsumerInfo(process.cwd());\n\n let configMain: ConfigMain | any;\n const configDirPath = consumerInfo?.path || process.cwd();\n const workspaceConfig = await WorkspaceConfig.loadIfExist(configDirPath);\n if (workspaceConfig) {\n configMain = new ConfigMain(workspaceConfig, undefined, preAddingAspectsSlot);\n } else {\n // TODO: try load scope config here\n configMain = {};\n }\n LegacyWorkspaceConfig.registerOnWorkspaceConfigLoading(onLegacyWorkspaceLoad(configMain));\n LegacyWorkspaceConfig.registerOnWorkspaceConfigReset((dirPath, resetHard) =>\n WorkspaceConfig.reset(dirPath, resetHard)\n );\n cli.register(new UseCmd(configMain));\n return configMain;\n }\n}\n\nConfigAspect.addRuntime(ConfigMain);\n\nfunction onLegacyWorkspaceConfigIsExist(): WorkspaceConfigIsExistFunction {\n return async (dirPath: PathOsBased): Promise<boolean | undefined> => {\n return WorkspaceConfig.isExist(dirPath);\n };\n}\n\nfunction onLegacyWorkspaceLoad(config?: ConfigMain): WorkspaceConfigLoadFunction {\n return async (dirPath: PathOsBased): Promise<ILegacyWorkspaceConfig | undefined> => {\n if (config?.workspaceConfig && config.path && path.normalize(dirPath) === path.dirname(config.path)) {\n return (config.config as WorkspaceConfig).toLegacy();\n }\n const newConfig = await WorkspaceConfig.loadIfExist(dirPath);\n if (newConfig) {\n return newConfig.toLegacy();\n }\n return undefined;\n };\n}\n\nfunction onLegacyWorkspaceEnsure(): WorkspaceConfigEnsureFunction {\n const func: WorkspaceConfigEnsureFunction = async (\n dirPath: string,\n standAlone = false,\n legacyWorkspaceConfigProps?: LegacyWorkspaceConfigProps\n ) => {\n let workspaceConfigProps;\n if (legacyWorkspaceConfigProps) {\n workspaceConfigProps = transformLegacyPropsToExtensions(legacyWorkspaceConfigProps);\n }\n const legacyInitProps: LegacyInitProps = {\n standAlone,\n };\n const config = await ConfigMain.ensureWorkspace(dirPath, workspaceConfigProps, legacyInitProps);\n const workspaceConfig = config.config;\n return (workspaceConfig as WorkspaceConfig).toLegacy();\n };\n return func;\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { Config } from './config';
2
- export type { ConfigMain } from './config.main.runtime';
1
+ export { ConfigMain } from './config.main.runtime';
3
2
  export { ConfigAspect, ConfigRuntime } from './config.aspect';
4
3
  export { ComponentScopeDirMap, getWorkspaceConfigTemplateParsed, stringifyWorkspaceConfig } from './workspace-config';
package/dist/index.js CHANGED
@@ -9,22 +9,22 @@ Object.defineProperty(exports, "ComponentScopeDirMap", {
9
9
  return _workspaceConfig().ComponentScopeDirMap;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "Config", {
12
+ Object.defineProperty(exports, "ConfigAspect", {
13
13
  enumerable: true,
14
14
  get: function () {
15
- return _config().Config;
15
+ return _config().ConfigAspect;
16
16
  }
17
17
  });
18
- Object.defineProperty(exports, "ConfigAspect", {
18
+ Object.defineProperty(exports, "ConfigMain", {
19
19
  enumerable: true,
20
20
  get: function () {
21
- return _config2().ConfigAspect;
21
+ return _configMain().ConfigMain;
22
22
  }
23
23
  });
24
24
  Object.defineProperty(exports, "ConfigRuntime", {
25
25
  enumerable: true,
26
26
  get: function () {
27
- return _config2().ConfigRuntime;
27
+ return _config().ConfigRuntime;
28
28
  }
29
29
  });
30
30
  Object.defineProperty(exports, "getWorkspaceConfigTemplateParsed", {
@@ -40,20 +40,20 @@ Object.defineProperty(exports, "stringifyWorkspaceConfig", {
40
40
  }
41
41
  });
42
42
 
43
- function _config() {
44
- const data = require("./config");
43
+ function _configMain() {
44
+ const data = require("./config.main.runtime");
45
45
 
46
- _config = function () {
46
+ _configMain = function () {
47
47
  return data;
48
48
  };
49
49
 
50
50
  return data;
51
51
  }
52
52
 
53
- function _config2() {
53
+ function _config() {
54
54
  const data = require("./config.aspect");
55
55
 
56
- _config2 = function () {
56
+ _config = function () {
57
57
  return data;
58
58
  };
59
59
 
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export { Config } from './config';\nexport type { ConfigMain } from './config.main.runtime';\nexport { ConfigAspect, ConfigRuntime } from './config.aspect';\nexport { ComponentScopeDirMap, getWorkspaceConfigTemplateParsed, stringifyWorkspaceConfig } from './workspace-config';\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export { ConfigMain } from './config.main.runtime';\nexport { ConfigAspect, ConfigRuntime } from './config.aspect';\nexport { ComponentScopeDirMap, getWorkspaceConfigTemplateParsed, stringifyWorkspaceConfig } from './workspace-config';\n"]}
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ExtensionDataEntry, ExtensionDataList } from '@teambit/legacy/dist/consumer/config';
2
2
  import { PathOsBased, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';
3
- import { SetExtensionOptions } from './config';
3
+ import { SetExtensionOptions } from './config.main.runtime';
4
4
  export declare type WriteOptions = {
5
5
  dir?: PathOsBasedAbsolute;
6
6
  };
@@ -0,0 +1,16 @@
1
+ import { Command, CommandOptions } from '@teambit/cli';
2
+ import { ConfigMain } from '@teambit/config';
3
+ export declare class UseCmd implements Command {
4
+ private config;
5
+ name: string;
6
+ shortDescription: string;
7
+ group: string;
8
+ description: string;
9
+ alias: string;
10
+ options: CommandOptions;
11
+ loader: boolean;
12
+ migration: boolean;
13
+ remoteOp: boolean;
14
+ constructor(config: ConfigMain);
15
+ report([ids]: [string[]]): Promise<any>;
16
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ require("core-js/modules/es.array.flat.js");
6
+
7
+ require("core-js/modules/es.array.iterator.js");
8
+
9
+ require("core-js/modules/es.array.unscopables.flat.js");
10
+
11
+ require("core-js/modules/es.promise.js");
12
+
13
+ Object.defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ exports.UseCmd = void 0;
17
+
18
+ function _defineProperty2() {
19
+ const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
+
21
+ _defineProperty2 = function () {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ function _path() {
29
+ const data = _interopRequireDefault(require("path"));
30
+
31
+ _path = function () {
32
+ return data;
33
+ };
34
+
35
+ return data;
36
+ }
37
+
38
+ function _chalk() {
39
+ const data = _interopRequireDefault(require("chalk"));
40
+
41
+ _chalk = function () {
42
+ return data;
43
+ };
44
+
45
+ return data;
46
+ }
47
+
48
+ class UseCmd {
49
+ constructor(config) {
50
+ this.config = config;
51
+ (0, _defineProperty2().default)(this, "name", 'use [ids...]');
52
+ (0, _defineProperty2().default)(this, "shortDescription", 'set up aspects in the workspace/scope config');
53
+ (0, _defineProperty2().default)(this, "group", 'collaborate');
54
+ (0, _defineProperty2().default)(this, "description", 'set up aspects in the workspace/scope config');
55
+ (0, _defineProperty2().default)(this, "alias", '');
56
+ (0, _defineProperty2().default)(this, "options", []);
57
+ (0, _defineProperty2().default)(this, "loader", true);
58
+ (0, _defineProperty2().default)(this, "migration", true);
59
+ (0, _defineProperty2().default)(this, "remoteOp", true);
60
+ }
61
+
62
+ async report([ids = []]) {
63
+ var _this$config$preAddin;
64
+
65
+ const config = this.config.workspaceConfig || this.config.scopeConfig;
66
+
67
+ if (!config) {
68
+ throw new Error(`please run "bit use" from either a workspace or a scope`);
69
+ }
70
+
71
+ const preAddingAspectFunctions = (_this$config$preAddin = this.config.preAddingAspectsSlot) === null || _this$config$preAddin === void 0 ? void 0 : _this$config$preAddin.toArray();
72
+ if (!preAddingAspectFunctions) throw new Error(`can't find any registration to the preAddingAspects slot`);
73
+ const componentIds = (await Promise.all(preAddingAspectFunctions.map(([, func]) => func(ids)))).flat();
74
+ componentIds.forEach(compId => {
75
+ config.setExtension(compId, {}, {
76
+ overrideExisting: false,
77
+ ignoreVersion: false
78
+ });
79
+ });
80
+ await config.write({
81
+ dir: _path().default.dirname(config.path)
82
+ });
83
+ return _chalk().default.green(`the following aspect(s) were saved into ${this.config.workspaceConfig ? 'workspace.jsonc' : 'scopes.jsonc'} file:
84
+ ${componentIds.join('\n')}`);
85
+ }
86
+
87
+ }
88
+
89
+ exports.UseCmd = UseCmd;
90
+
91
+ //# sourceMappingURL=use.cmd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["use.cmd.ts"],"names":["UseCmd","constructor","config","report","ids","workspaceConfig","scopeConfig","Error","preAddingAspectFunctions","preAddingAspectsSlot","toArray","componentIds","Promise","all","map","func","flat","forEach","compId","setExtension","overrideExisting","ignoreVersion","write","dir","path","dirname","chalk","green","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGO,MAAMA,MAAN,CAAgC;AAWrCC,EAAAA,WAAW,CAASC,MAAT,EAA6B;AAAA,SAApBA,MAAoB,GAApBA,MAAoB;AAAA,kDAVjC,cAUiC;AAAA,8DATrB,8CASqB;AAAA,mDARhC,aAQgC;AAAA,yDAP1B,8CAO0B;AAAA,mDANhC,EAMgC;AAAA,qDAL9B,EAK8B;AAAA,oDAJ/B,IAI+B;AAAA,uDAH5B,IAG4B;AAAA,sDAF7B,IAE6B;AAAE;;AAE9B,QAANC,MAAM,CAAC,CAACC,GAAG,GAAG,EAAP,CAAD,EAAuC;AAAA;;AACjD,UAAMF,MAAM,GAAG,KAAKA,MAAL,CAAYG,eAAZ,IAA+B,KAAKH,MAAL,CAAYI,WAA1D;;AACA,QAAI,CAACJ,MAAL,EAAa;AACX,YAAM,IAAIK,KAAJ,CAAW,yDAAX,CAAN;AACD;;AACD,UAAMC,wBAAwB,4BAAG,KAAKN,MAAL,CAAYO,oBAAf,0DAAG,sBAAkCC,OAAlC,EAAjC;AACA,QAAI,CAACF,wBAAL,EAA+B,MAAM,IAAID,KAAJ,CAAW,0DAAX,CAAN;AAC/B,UAAMI,YAAY,GAAG,CAAC,MAAMC,OAAO,CAACC,GAAR,CAAYL,wBAAwB,CAACM,GAAzB,CAA6B,CAAC,GAAGC,IAAH,CAAD,KAAcA,IAAI,CAACX,GAAD,CAA/C,CAAZ,CAAP,EAA2EY,IAA3E,EAArB;AAEAL,IAAAA,YAAY,CAACM,OAAb,CAAsBC,MAAD,IAAY;AAC/BhB,MAAAA,MAAM,CAACiB,YAAP,CACED,MADF,EAEE,EAFF,EAGE;AACEE,QAAAA,gBAAgB,EAAE,KADpB;AAEEC,QAAAA,aAAa,EAAE;AAFjB,OAHF;AAQD,KATD;AAUA,UAAMnB,MAAM,CAACoB,KAAP,CAAa;AAAEC,MAAAA,GAAG,EAAEC,gBAAKC,OAAL,CAAavB,MAAM,CAACsB,IAApB;AAAP,KAAb,CAAN;AAEA,WAAOE,iBAAMC,KAAN,CAAa,2CAClB,KAAKzB,MAAL,CAAYG,eAAZ,GAA8B,iBAA9B,GAAkD,cACnD;AACL,EAAEM,YAAY,CAACiB,IAAb,CAAkB,IAAlB,CAAwB,EAHf,CAAP;AAID;;AAtCoC","sourcesContent":["import { Command, CommandOptions } from '@teambit/cli';\nimport path from 'path';\nimport chalk from 'chalk';\nimport { ConfigMain } from '@teambit/config';\n\nexport class UseCmd implements Command {\n name = 'use [ids...]';\n shortDescription = 'set up aspects in the workspace/scope config';\n group = 'collaborate';\n description = 'set up aspects in the workspace/scope config';\n alias = '';\n options = [] as CommandOptions;\n loader = true;\n migration = true;\n remoteOp = true;\n\n constructor(private config: ConfigMain) {}\n\n async report([ids = []]: [string[]]): Promise<any> {\n const config = this.config.workspaceConfig || this.config.scopeConfig;\n if (!config) {\n throw new Error(`please run \"bit use\" from either a workspace or a scope`);\n }\n const preAddingAspectFunctions = this.config.preAddingAspectsSlot?.toArray();\n if (!preAddingAspectFunctions) throw new Error(`can't find any registration to the preAddingAspects slot`);\n const componentIds = (await Promise.all(preAddingAspectFunctions.map(([, func]) => func(ids)))).flat();\n\n componentIds.forEach((compId) => {\n config.setExtension(\n compId,\n {},\n {\n overrideExisting: false,\n ignoreVersion: false,\n }\n );\n });\n await config.write({ dir: path.dirname(config.path) });\n\n return chalk.green(`the following aspect(s) were saved into ${\n this.config.workspaceConfig ? 'workspace.jsonc' : 'scopes.jsonc'\n } file:\n${componentIds.join('\\n')}`);\n }\n}\n"]}
@@ -4,7 +4,7 @@ import { ExtensionDataList, ILegacyWorkspaceConfig } from '@teambit/legacy/dist/
4
4
  import LegacyWorkspaceConfig, { WorkspaceConfigProps as LegacyWorkspaceConfigProps } from '@teambit/legacy/dist/consumer/config/workspace-config';
5
5
  import { PathOsBased, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';
6
6
  import { CommentJSONValue } from 'comment-json';
7
- import { SetExtensionOptions } from './config';
7
+ import { SetExtensionOptions } from './config.main.runtime';
8
8
  import { HostConfig } from './types';
9
9
  export declare type LegacyInitProps = {
10
10
  standAlone?: boolean;