@teambit/config 0.0.859 → 0.0.860

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.
@@ -0,0 +1 @@
1
+ !function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports["teambit.harmony/config-preview"]=o():e["teambit.harmony/config-preview"]=o()}(self,(()=>(()=>{"use strict";var e={d:(o,t)=>{for(var r in t)e.o(t,r)&&!e.o(o,r)&&Object.defineProperty(o,r,{enumerable:!0,get:t[r]})},o:(e,o)=>Object.prototype.hasOwnProperty.call(e,o),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},o={};e.r(o),e.d(o,{compositions:()=>t,compositions_metadata:()=>i,overview:()=>r});const t=[],r=[],i={compositions:[]};return o})()));
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/config",
3
- "version": "0.0.859",
3
+ "version": "0.0.860",
4
4
  "homepage": "https://bit.cloud/teambit/harmony/config",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.harmony",
8
8
  "name": "config",
9
- "version": "0.0.859"
9
+ "version": "0.0.860"
10
10
  },
11
11
  "dependencies": {
12
12
  "comment-json": "3.0.3",
@@ -15,8 +15,8 @@
15
15
  "chalk": "2.4.2",
16
16
  "@teambit/harmony": "0.4.6",
17
17
  "@teambit/bit-error": "0.0.404",
18
- "@teambit/cli": "0.0.840",
19
- "@teambit/workspace": "1.0.108"
18
+ "@teambit/cli": "0.0.841",
19
+ "@teambit/workspace": "1.0.109"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/fs-extra": "9.0.7",
@@ -24,7 +24,7 @@
24
24
  "@types/mocha": "9.1.0",
25
25
  "@types/jest": "^29.2.2",
26
26
  "@types/testing-library__jest-dom": "^5.9.5",
27
- "@teambit/harmony.envs.core-aspect-env": "0.0.13"
27
+ "@teambit/harmony.envs.core-aspect-env": "0.0.14"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@teambit/legacy": "1.0.624"
package/config.aspect.ts DELETED
@@ -1,9 +0,0 @@
1
- import { Aspect, RuntimeDefinition } from '@teambit/harmony';
2
-
3
- export const ConfigRuntime = new RuntimeDefinition('main');
4
-
5
- export const ConfigAspect = Aspect.create({
6
- id: 'teambit.harmony/config',
7
- dependencies: [],
8
- declareRuntime: ConfigRuntime,
9
- });
@@ -1,163 +0,0 @@
1
- import { getConsumerInfo } from '@teambit/legacy/dist/consumer';
2
- import {
3
- ExtensionDataEntry,
4
- ExtensionDataList,
5
- ILegacyWorkspaceConfig,
6
- LegacyWorkspaceConfigProps,
7
- } from '@teambit/legacy/dist/consumer/config';
8
- import LegacyWorkspaceConfig, {
9
- WorkspaceConfigEnsureFunction,
10
- WorkspaceConfigIsExistFunction,
11
- WorkspaceConfigLoadFunction,
12
- } from '@teambit/legacy/dist/consumer/config/workspace-config';
13
- import { PathOsBased, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';
14
- import { MainRuntime } from '@teambit/cli';
15
- import { GlobalConfig } from '@teambit/harmony';
16
- import path from 'path';
17
- import { transformLegacyPropsToExtensions, WorkspaceConfig, WorkspaceConfigFileProps } from './workspace-config';
18
- import { ConfigType, HostConfig } from './types';
19
- import { ConfigAspect } from './config.aspect';
20
-
21
- export type SetExtensionOptions = {
22
- overrideExisting?: boolean;
23
- ignoreVersion: boolean;
24
- mergeIntoExisting?: boolean;
25
- };
26
-
27
- export type ConfigDeps = [];
28
-
29
- export type ConfigConfig = {};
30
-
31
- export class ConfigMain {
32
- constructor(public workspaceConfig?: WorkspaceConfig, public scopeConfig?: WorkspaceConfig) {}
33
-
34
- get type(): ConfigType {
35
- if (this.workspaceConfig) {
36
- return 'workspace';
37
- }
38
- return 'scope';
39
- }
40
-
41
- get path(): PathOsBased | undefined {
42
- return this.config?.path;
43
- }
44
-
45
- get config(): HostConfig | undefined {
46
- if (this.workspaceConfig) {
47
- return this.workspaceConfig;
48
- }
49
- return this.scopeConfig;
50
- }
51
-
52
- async reloadWorkspaceConfig() {
53
- const workspaceConfig = await loadWorkspaceConfigIfExist();
54
- if (workspaceConfig) this.workspaceConfig = workspaceConfig;
55
- }
56
-
57
- /**
58
- * Ensure the given directory has a workspace config
59
- * Load if existing and create new if not
60
- *
61
- * @static
62
- * @param {PathOsBasedAbsolute} dirPath
63
- * @param {WorkspaceConfigFileProps} [workspaceConfigProps={} as any]
64
- * @returns {Promise<WorkspaceConfig>}
65
- * @memberof WorkspaceConfig
66
- */
67
- static async ensureWorkspace(
68
- dirPath: PathOsBasedAbsolute,
69
- workspaceConfigProps: WorkspaceConfigFileProps = {} as any
70
- ): Promise<ConfigMain> {
71
- const workspaceConfig = await WorkspaceConfig.ensure(dirPath, workspaceConfigProps);
72
- return new ConfigMain(workspaceConfig);
73
- }
74
-
75
- get extensions(): ExtensionDataList | undefined {
76
- return this.config?.extensions;
77
- }
78
-
79
- extension(extensionId: string, ignoreVersion: boolean): ExtensionDataEntry | undefined {
80
- return this.config?.extension(extensionId, ignoreVersion);
81
- }
82
-
83
- setExtension(extensionId: string, config: Record<string, any>, options: SetExtensionOptions) {
84
- this.config?.setExtension(extensionId, config, options);
85
- }
86
-
87
- getHarmonyConfigObject(): GlobalConfig {
88
- const config = {};
89
- if (!this.extensions) return config;
90
- this.extensions.forEach((extension) => {
91
- config[extension.stringId] = extension.config;
92
- });
93
- return config;
94
- }
95
-
96
- static runtime = MainRuntime;
97
- static slots = [];
98
- static dependencies = [];
99
- static config = {};
100
- static async provider() {
101
- LegacyWorkspaceConfig.registerOnWorkspaceConfigIsExist(onLegacyWorkspaceConfigIsExist());
102
- LegacyWorkspaceConfig.registerOnWorkspaceConfigEnsuring(onLegacyWorkspaceEnsure());
103
-
104
- let configMain: ConfigMain | any;
105
- const workspaceConfig = await loadWorkspaceConfigIfExist();
106
- if (workspaceConfig) {
107
- configMain = new ConfigMain(workspaceConfig, undefined);
108
- } else {
109
- // TODO: try load scope config here
110
- configMain = {};
111
- }
112
- LegacyWorkspaceConfig.registerOnWorkspaceConfigLoading(onLegacyWorkspaceLoad(configMain));
113
- LegacyWorkspaceConfig.registerOnWorkspaceConfigReset((dirPath, resetHard) =>
114
- WorkspaceConfig.reset(dirPath, resetHard)
115
- );
116
- return configMain;
117
- }
118
- }
119
-
120
- ConfigAspect.addRuntime(ConfigMain);
121
-
122
- async function loadWorkspaceConfigIfExist(): Promise<WorkspaceConfig | undefined> {
123
- const consumerInfo = await getConsumerInfo(process.cwd());
124
- const configDirPath = consumerInfo?.path || process.cwd();
125
- const workspaceConfig = await WorkspaceConfig.loadIfExist(configDirPath);
126
- return workspaceConfig;
127
- }
128
-
129
- function onLegacyWorkspaceConfigIsExist(): WorkspaceConfigIsExistFunction {
130
- return async (dirPath: PathOsBased): Promise<boolean | undefined> => {
131
- return WorkspaceConfig.isExist(dirPath);
132
- };
133
- }
134
-
135
- function onLegacyWorkspaceLoad(config?: ConfigMain): WorkspaceConfigLoadFunction {
136
- return async (dirPath: PathOsBased): Promise<ILegacyWorkspaceConfig | undefined> => {
137
- if (config?.workspaceConfig && config.path && path.normalize(dirPath) === path.dirname(config.path)) {
138
- return (config.config as WorkspaceConfig).toLegacy();
139
- }
140
- const newConfig = await WorkspaceConfig.loadIfExist(dirPath);
141
- if (newConfig) {
142
- return newConfig.toLegacy();
143
- }
144
- return undefined;
145
- };
146
- }
147
-
148
- function onLegacyWorkspaceEnsure(): WorkspaceConfigEnsureFunction {
149
- const func: WorkspaceConfigEnsureFunction = async (
150
- dirPath: string,
151
- standAlone,
152
- legacyWorkspaceConfigProps?: LegacyWorkspaceConfigProps
153
- ) => {
154
- let workspaceConfigProps;
155
- if (legacyWorkspaceConfigProps) {
156
- workspaceConfigProps = transformLegacyPropsToExtensions(legacyWorkspaceConfigProps);
157
- }
158
- const config = await ConfigMain.ensureWorkspace(dirPath, workspaceConfigProps);
159
- const workspaceConfig = config.config;
160
- return (workspaceConfig as WorkspaceConfig).toLegacy();
161
- };
162
- return func;
163
- }
package/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export { ConfigMain } from './config.main.runtime';
2
- export { ConfigAspect, ConfigRuntime } from './config.aspect';
3
- export type { ComponentScopeDirMap } from './workspace-config';
4
- export { getWorkspaceConfigTemplateParsed, stringifyWorkspaceConfig } from './workspace-config';
package/types.ts DELETED
@@ -1,29 +0,0 @@
1
- import { ExtensionDataEntry, ExtensionDataList } from '@teambit/legacy/dist/consumer/config';
2
- import { PathOsBased, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';
3
-
4
- import { SetExtensionOptions } from './config.main.runtime';
5
-
6
- export type WriteOptions = {
7
- dir?: PathOsBasedAbsolute;
8
- };
9
-
10
- /**
11
- * An interface implemented by component host (workspace / scope) config file
12
- * This used to be able to abstract the workspace/scope config.
13
- */
14
- export interface HostConfig {
15
- /**
16
- * Path to the actual file
17
- */
18
- path: PathOsBased;
19
-
20
- extensions: ExtensionDataList;
21
-
22
- extension: (extensionId: string, ignoreVersion: boolean) => ExtensionDataEntry;
23
-
24
- setExtension(extensionId: string, config: Record<string, any>, options: SetExtensionOptions): void;
25
-
26
- write(opts: WriteOptions): Promise<void>;
27
- }
28
-
29
- export type ConfigType = 'workspace' | 'scope';
@@ -1,357 +0,0 @@
1
- import { DEFAULT_LANGUAGE, WORKSPACE_JSONC } from '@teambit/legacy/dist/constants';
2
- import { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
3
- import DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';
4
- import { ExtensionDataList, ILegacyWorkspaceConfig } from '@teambit/legacy/dist/consumer/config';
5
- import LegacyWorkspaceConfig, {
6
- WorkspaceConfigProps as LegacyWorkspaceConfigProps,
7
- } from '@teambit/legacy/dist/consumer/config/workspace-config';
8
- import logger from '@teambit/legacy/dist/logger/logger';
9
- import { PathOsBased, PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';
10
- import { assign, parse, stringify, CommentJSONValue } from 'comment-json';
11
- import * as fs from 'fs-extra';
12
- import * as path from 'path';
13
- import { isEmpty, omit } from 'lodash';
14
- import WorkspaceAspect from '@teambit/workspace';
15
- import { SetExtensionOptions } from './config.main.runtime';
16
- import { ExtensionAlreadyConfigured } from './exceptions';
17
- import { ConfigDirNotDefined } from './exceptions/config-dir-not-defined';
18
- import InvalidConfigFile from './exceptions/invalid-config-file';
19
- import { HostConfig } from './types';
20
-
21
- const INTERNAL_CONFIG_PROPS = ['$schema', '$schemaVersion'];
22
-
23
- export type LegacyInitProps = {
24
- standAlone?: boolean;
25
- };
26
-
27
- export type WorkspaceConfigFileProps = {
28
- // TODO: make it no optional
29
- $schema?: string;
30
- $schemaVersion?: string;
31
- } & ExtensionsDefs;
32
-
33
- export type ComponentScopeDirMapEntry = {
34
- defaultScope?: string;
35
- directory: string;
36
- };
37
-
38
- export type ComponentScopeDirMap = Array<ComponentScopeDirMapEntry>;
39
-
40
- export type WorkspaceExtensionProps = {
41
- defaultScope?: string;
42
- defaultDirectory?: string;
43
- components?: ComponentScopeDirMap;
44
- };
45
-
46
- export type PackageManagerClients = 'npm' | 'yarn' | undefined;
47
-
48
- export interface DependencyResolverExtensionProps {
49
- packageManager: PackageManagerClients;
50
- strictPeerDependencies?: boolean;
51
- extraArgs?: string[];
52
- packageManagerProcessOptions?: any;
53
- useWorkspaces?: boolean;
54
- manageWorkspaces?: boolean;
55
- }
56
-
57
- export type WorkspaceSettingsNewProps = {
58
- 'teambit.workspace/workspace': WorkspaceExtensionProps;
59
- 'teambit.dependencies/dependency-resolver': DependencyResolverExtensionProps;
60
- };
61
-
62
- export type WorkspaceLegacyProps = {
63
- dependenciesDirectory?: string;
64
- saveDependenciesAsComponents?: boolean;
65
- };
66
-
67
- export type ExtensionsDefs = WorkspaceSettingsNewProps;
68
-
69
- export class WorkspaceConfig implements HostConfig {
70
- raw?: any;
71
- _path?: string;
72
- _extensions: ExtensionDataList;
73
- _legacyProps?: WorkspaceLegacyProps;
74
- isLegacy: boolean;
75
-
76
- constructor(private data: WorkspaceConfigFileProps) {
77
- this.raw = data;
78
- this.loadExtensions();
79
- }
80
-
81
- get path(): PathOsBased {
82
- return this._path || '';
83
- }
84
-
85
- set path(configPath: PathOsBased) {
86
- this._path = configPath;
87
- }
88
-
89
- get extensions(): ExtensionDataList {
90
- return this._extensions;
91
- }
92
-
93
- private loadExtensions() {
94
- const withoutInternalConfig = omit(this.raw, INTERNAL_CONFIG_PROPS);
95
- this._extensions = ExtensionDataList.fromConfigObject(withoutInternalConfig);
96
- }
97
-
98
- extension(extensionId: string, ignoreVersion: boolean): any {
99
- const existing = this.extensions.findExtension(extensionId, ignoreVersion);
100
- return existing?.config;
101
- }
102
-
103
- setExtension(extensionId: string, config: Record<string, any>, options: SetExtensionOptions): any {
104
- const existing = this.extension(extensionId, options.ignoreVersion);
105
- if (existing) {
106
- if (options.mergeIntoExisting) {
107
- config = { ...existing, ...config };
108
- } else if (!options.overrideExisting) {
109
- throw new ExtensionAlreadyConfigured(extensionId);
110
- }
111
- }
112
-
113
- this.raw[extensionId] = config;
114
- this.loadExtensions();
115
- }
116
-
117
- renameExtensionInRaw(oldExtId: string, newExtId: string): boolean {
118
- if (this.raw[oldExtId]) {
119
- this.raw[newExtId] = this.raw[oldExtId];
120
- delete this.raw[oldExtId];
121
- return true;
122
- }
123
- return false;
124
- }
125
-
126
- /**
127
- * Create an instance of the WorkspaceConfig by data
128
- *
129
- * @static
130
- * @param {WorkspaceConfigFileProps} data
131
- * @returns
132
- * @memberof WorkspaceConfig
133
- */
134
- static fromObject(data: WorkspaceConfigFileProps) {
135
- return new WorkspaceConfig(data);
136
- }
137
-
138
- /**
139
- * Create an instance of the WorkspaceConfig by the workspace config template and override values
140
- *
141
- * @static
142
- * @param {WorkspaceConfigFileProps} data values to override in the default template
143
- * @returns
144
- * @memberof WorkspaceConfig
145
- */
146
- static async create(props: WorkspaceConfigFileProps, dirPath?: PathOsBasedAbsolute) {
147
- const template = await getWorkspaceConfigTemplateParsed();
148
- // previously, we just did `assign(template, props)`, but it was replacing the entire workspace config with the "props".
149
- // so for example, if the props only had defaultScope, it was removing the defaultDirectory.
150
- const workspaceAspectConf = assign(template[WorkspaceAspect.id], props[WorkspaceAspect.id]);
151
- const merged = assign(template, { [WorkspaceAspect.id]: workspaceAspectConf });
152
- const instance = new WorkspaceConfig(merged);
153
- if (dirPath) {
154
- instance.path = WorkspaceConfig.composeWorkspaceJsoncPath(dirPath);
155
- }
156
- return instance;
157
- }
158
-
159
- /**
160
- * Ensure the given directory has a workspace config
161
- * Load if existing and create new if not
162
- *
163
- * @static
164
- * @param {PathOsBasedAbsolute} dirPath
165
- * @param {WorkspaceConfigFileProps} [workspaceConfigProps={} as any]
166
- * @returns {Promise<WorkspaceConfig>}
167
- * @memberof WorkspaceConfig
168
- */
169
- static async ensure(
170
- dirPath: PathOsBasedAbsolute,
171
- workspaceConfigProps: WorkspaceConfigFileProps = {} as any
172
- ): Promise<WorkspaceConfig> {
173
- try {
174
- let workspaceConfig = await this.loadIfExist(dirPath);
175
- if (workspaceConfig) {
176
- return workspaceConfig;
177
- }
178
- workspaceConfig = await this.create(workspaceConfigProps, dirPath);
179
- return workspaceConfig;
180
- } catch (err: any) {
181
- if (err instanceof InvalidConfigFile) {
182
- const workspaceConfig = this.create(workspaceConfigProps, dirPath);
183
- return workspaceConfig;
184
- }
185
- throw err;
186
- }
187
- }
188
-
189
- static async reset(dirPath: PathOsBasedAbsolute, resetHard: boolean): Promise<void> {
190
- const workspaceJsoncPath = WorkspaceConfig.composeWorkspaceJsoncPath(dirPath);
191
- if (resetHard && workspaceJsoncPath) {
192
- logger.info(`deleting the consumer workspace.jsonc file at ${workspaceJsoncPath}`);
193
- await fs.remove(workspaceJsoncPath);
194
- }
195
- }
196
-
197
- /**
198
- * Get the path of the workspace.jsonc file by a containing folder
199
- *
200
- * @static
201
- * @param {PathOsBased} dirPath containing dir of the workspace.jsonc file
202
- * @returns {PathOsBased}
203
- * @memberof WorkspaceConfig
204
- */
205
- static composeWorkspaceJsoncPath(dirPath: PathOsBased): PathOsBased {
206
- return path.join(dirPath, WORKSPACE_JSONC);
207
- }
208
-
209
- static async pathHasWorkspaceJsonc(dirPath: PathOsBased): Promise<boolean> {
210
- const isExist = await fs.pathExists(WorkspaceConfig.composeWorkspaceJsoncPath(dirPath));
211
- return isExist;
212
- }
213
-
214
- /**
215
- * Check if the given dir has workspace config (new or legacy)
216
- * @param dirPath
217
- */
218
- static async isExist(dirPath: PathOsBased): Promise<boolean | undefined> {
219
- const jsoncExist = await WorkspaceConfig.pathHasWorkspaceJsonc(dirPath);
220
- if (jsoncExist) {
221
- return true;
222
- }
223
- return LegacyWorkspaceConfig._isExist(dirPath);
224
- }
225
-
226
- /**
227
- * Load the workspace configuration if it's exist
228
- *
229
- * @static
230
- * @param {PathOsBased} dirPath
231
- * @returns {(Promise<WorkspaceConfig | undefined>)}
232
- * @memberof WorkspaceConfig
233
- */
234
- static async loadIfExist(dirPath: PathOsBased): Promise<WorkspaceConfig | undefined> {
235
- const jsoncExist = await WorkspaceConfig.pathHasWorkspaceJsonc(dirPath);
236
- if (jsoncExist) {
237
- const jsoncPath = WorkspaceConfig.composeWorkspaceJsoncPath(dirPath);
238
- const instance = await WorkspaceConfig._loadFromWorkspaceJsonc(jsoncPath);
239
- instance.path = jsoncPath;
240
- return instance;
241
- }
242
- return undefined;
243
- }
244
-
245
- static async _loadFromWorkspaceJsonc(workspaceJsoncPath: PathOsBased): Promise<WorkspaceConfig> {
246
- const contentBuffer = await fs.readFile(workspaceJsoncPath);
247
- let parsed;
248
- try {
249
- parsed = parse(contentBuffer.toString());
250
- } catch (e: any) {
251
- throw new InvalidConfigFile(workspaceJsoncPath);
252
- }
253
- return WorkspaceConfig.fromObject(parsed);
254
- }
255
-
256
- async write({ dir }: { dir?: PathOsBasedAbsolute } = {}): Promise<void> {
257
- const getCalculatedDir = () => {
258
- if (dir) return dir;
259
- if (this._path) return path.dirname(this._path);
260
- throw new ConfigDirNotDefined();
261
- };
262
- const calculatedDir = getCalculatedDir();
263
- const files = await this.toVinyl(calculatedDir);
264
- const dataToPersist = new DataToPersist();
265
- if (files) {
266
- dataToPersist.addManyFiles(files);
267
- return dataToPersist.persistAllToFS();
268
- }
269
- return undefined;
270
- }
271
-
272
- async toVinyl(workspaceDir: PathOsBasedAbsolute): Promise<AbstractVinyl[] | undefined> {
273
- const jsonStr = `${stringify(this.data, undefined, 2)}\n`;
274
- const base = workspaceDir;
275
- const fullPath = workspaceDir ? WorkspaceConfig.composeWorkspaceJsoncPath(workspaceDir) : this.path;
276
- const jsonFile = new AbstractVinyl({ base, path: fullPath, contents: Buffer.from(jsonStr) });
277
- return [jsonFile];
278
- }
279
-
280
- toLegacy(): ILegacyWorkspaceConfig {
281
- let componentsDefaultDirectory = this.extension('teambit.workspace/workspace', true)?.defaultDirectory;
282
- if (componentsDefaultDirectory && !componentsDefaultDirectory.includes('{name}')) {
283
- componentsDefaultDirectory = `${componentsDefaultDirectory}/{name}`;
284
- }
285
-
286
- return {
287
- lang: DEFAULT_LANGUAGE,
288
- defaultScope: this.extension('teambit.workspace/workspace', true)?.defaultScope,
289
- _useWorkspaces: this.extension('teambit.dependencies/dependency-resolver', true)?.useWorkspaces,
290
- dependencyResolver: this.extension('teambit.dependencies/dependency-resolver', true),
291
- packageManager: this.extension('teambit.dependencies/dependency-resolver', true)?.packageManager,
292
- _saveDependenciesAsComponents: this._legacyProps?.saveDependenciesAsComponents,
293
- _dependenciesDirectory: this._legacyProps?.dependenciesDirectory,
294
- componentsDefaultDirectory,
295
- _manageWorkspaces: this.extension('teambit.dependencies/dependency-resolver', true)?.manageWorkspaces,
296
- extensions: this.extensions.toConfigObject(),
297
- // @ts-ignore
298
- path: this.path,
299
- isLegacy: false,
300
- write: ({ workspaceDir }) => this.write.call(this, { dir: workspaceDir }),
301
- toVinyl: this.toVinyl.bind(this),
302
- _legacyPlainObject: () => undefined,
303
- };
304
- }
305
- }
306
-
307
- export function transformLegacyPropsToExtensions(
308
- legacyConfig: LegacyWorkspaceConfig | LegacyWorkspaceConfigProps
309
- ): ExtensionsDefs {
310
- // TODO: move to utils
311
- const removeUndefined = (obj) => {
312
- // const res = omit(mapObjIndexed((val) => val === undefined))(obj);
313
- // return res;
314
- Object.entries(obj).forEach((e) => {
315
- if (e[1] === undefined) delete obj[e[0]];
316
- });
317
- return obj;
318
- };
319
-
320
- const workspace = removeUndefined({
321
- defaultScope: legacyConfig.defaultScope,
322
- defaultDirectory: legacyConfig.componentsDefaultDirectory,
323
- });
324
- const dependencyResolver = removeUndefined({
325
- packageManager: legacyConfig.packageManager,
326
- // strictPeerDependencies: false,
327
- extraArgs: legacyConfig.packageManagerArgs,
328
- packageManagerProcessOptions: legacyConfig.packageManagerProcessOptions,
329
- manageWorkspaces: legacyConfig.manageWorkspaces,
330
- useWorkspaces: legacyConfig.useWorkspaces,
331
- });
332
- const data = {};
333
- if (workspace && !isEmpty(workspace)) {
334
- data['teambit.workspace/workspace'] = workspace;
335
- }
336
- if (dependencyResolver && !isEmpty(dependencyResolver)) {
337
- data['teambit.dependencies/dependency-resolver'] = dependencyResolver;
338
- }
339
- // @ts-ignore
340
- return data;
341
- }
342
-
343
- export async function getWorkspaceConfigTemplateParsed(): Promise<CommentJSONValue> {
344
- let fileContent: Buffer;
345
- try {
346
- fileContent = await fs.readFile(path.join(__dirname, 'workspace-template.jsonc'));
347
- } catch (err: any) {
348
- if (err.code !== 'ENOENT') throw err;
349
- // when the extension is compiled by tsc, it doesn't copy .jsonc files into the dists, grab it from src
350
- fileContent = await fs.readFile(path.join(__dirname, '..', 'workspace-template.jsonc'));
351
- }
352
- return parse(fileContent.toString());
353
- }
354
-
355
- export function stringifyWorkspaceConfig(workspaceConfig: CommentJSONValue): string {
356
- return stringify(workspaceConfig, undefined, 2);
357
- }