@teambit/tracker 1.0.1174 → 1.0.1176
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/dist/add-cmd.d.ts +2 -1
- package/dist/add-cmd.js +5 -3
- package/dist/add-cmd.js.map +1 -1
- package/dist/add-components.d.ts +35 -2
- package/dist/add-components.js +259 -40
- package/dist/add-components.js.map +1 -1
- package/dist/add-components.spec.d.ts +1 -0
- package/dist/add-components.spec.js +205 -0
- package/dist/add-components.spec.js.map +1 -0
- package/dist/determine-main-file.js +10 -1
- package/dist/determine-main-file.js.map +1 -1
- package/dist/determine-main-file.spec.d.ts +1 -0
- package/dist/determine-main-file.spec.js +231 -0
- package/dist/determine-main-file.spec.js.map +1 -0
- package/dist/track-workspace-root.spec.d.ts +1 -0
- package/dist/track-workspace-root.spec.js +377 -0
- package/dist/track-workspace-root.spec.js.map +1 -0
- package/dist/tracker.main.runtime.d.ts +8 -1
- package/dist/tracker.main.runtime.js +2 -1
- package/dist/tracker.main.runtime.js.map +1 -1
- package/package.json +20 -16
- /package/dist/{preview-1789911586102.js → preview-1790183760587.js} +0 -0
package/dist/add-cmd.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ type AddFlags = {
|
|
|
9
9
|
scope?: string;
|
|
10
10
|
env?: string;
|
|
11
11
|
override: boolean;
|
|
12
|
+
root?: boolean;
|
|
12
13
|
};
|
|
13
14
|
type AddResults = {
|
|
14
15
|
addedComponents: Array<{
|
|
@@ -29,6 +30,6 @@ export declare class AddCmd implements Command {
|
|
|
29
30
|
loader: boolean;
|
|
30
31
|
constructor(tracker: TrackerMain);
|
|
31
32
|
report([paths]: [string[]], addFlags: AddFlags): Promise<string>;
|
|
32
|
-
json([paths]: [string[]], { id, main, namespace, scope, env, override }: AddFlags): Promise<AddResults>;
|
|
33
|
+
json([paths]: [string[]], { id, main, namespace, scope, env, override, root }: AddFlags): Promise<AddResults>;
|
|
33
34
|
}
|
|
34
35
|
export {};
|
package/dist/add-cmd.js
CHANGED
|
@@ -53,7 +53,7 @@ class AddCmd {
|
|
|
53
53
|
_defineProperty(this, "extendedDescription", 'Registers one or more directories as Bit components without changing your files. Each provided path becomes a component root tracked by Bit.');
|
|
54
54
|
_defineProperty(this, "helpUrl", 'reference/workspace/component-directory');
|
|
55
55
|
_defineProperty(this, "alias", 'a');
|
|
56
|
-
_defineProperty(this, "options", [['i', 'id <name>', 'manually set component id'], ['m', 'main <file>', 'define component entry point'], ['n', 'namespace <namespace>', 'organize component in a namespace'], ['o', 'override <boolean>', 'override existing component if exists (default = false)'], ['s', 'scope <string>', `sets the component's scope. if not entered, the default-scope from workspace.jsonc will be used`], ['e', 'env <string>', "set the component's environment. (overrides the env from variants if exists)"], ['j', 'json', 'output as json format']]);
|
|
56
|
+
_defineProperty(this, "options", [['i', 'id <name>', 'manually set component id'], ['m', 'main <file>', 'define component entry point'], ['n', 'namespace <namespace>', 'organize component in a namespace'], ['o', 'override <boolean>', 'override existing component if exists (default = false)'], ['s', 'scope <string>', `sets the component's scope. if not entered, the default-scope from workspace.jsonc will be used`], ['e', 'env <string>', "set the component's environment. (overrides the env from variants if exists)"], ['', 'root', 'track the workspace root itself as a component, which owns every file no other component claims'], ['j', 'json', 'output as json format']]);
|
|
57
57
|
_defineProperty(this, "loader", true);
|
|
58
58
|
}
|
|
59
59
|
async report([paths = []], addFlags) {
|
|
@@ -91,7 +91,8 @@ class AddCmd {
|
|
|
91
91
|
namespace,
|
|
92
92
|
scope,
|
|
93
93
|
env,
|
|
94
|
-
override = false
|
|
94
|
+
override = false,
|
|
95
|
+
root = false
|
|
95
96
|
}) {
|
|
96
97
|
if (namespace && id) {
|
|
97
98
|
throw new (_bitError().BitError)('please use either [id] or [namespace] to add a particular component - they cannot be used together');
|
|
@@ -109,7 +110,8 @@ class AddCmd {
|
|
|
109
110
|
namespace,
|
|
110
111
|
defaultScope: scope,
|
|
111
112
|
override,
|
|
112
|
-
env
|
|
113
|
+
env,
|
|
114
|
+
root
|
|
113
115
|
});
|
|
114
116
|
return {
|
|
115
117
|
addedComponents: addedComponents.map(added => ({
|
package/dist/add-cmd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_cli","data","require","_chalk","_interopRequireDefault","path","_interopRequireWildcard","_bitError","_legacy","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_defineProperty","_toPropertyKey","value","enumerable","configurable","writable","_toPrimitive","Symbol","toPrimitive","TypeError","String","Number","AddCmd","constructor","tracker","report","paths","addFlags","addedComponents","warnings","json","paintWarning","alreadyUsedOutput","alreadyUsedWarning","keys","alreadyUsed","map","key","formatItem","chalk","bold","join","warnSymbol","filter","x","emptyDirectoryOutput","emptyDirectory","length","items","dir","formatTitle","formatSuccessSummary","joinSections","result","files","errorSymbol","id","title","file","main","namespace","scope","env","override","BitError","normalizedPaths","p","pathNormalizeToLinux","normalize","addForCLI","componentPaths","undefined","defaultScope","added","toString","relativePath","exports"],"sources":["add-cmd.ts"],"sourcesContent":["import type { Command, CommandOptions } from '@teambit/cli';\nimport { formatTitle, formatItem, formatSuccessSummary, warnSymbol, errorSymbol, joinSections } from '@teambit/cli';\nimport chalk from 'chalk';\nimport * as path from 'path';\nimport { BitError } from '@teambit/bit-error';\nimport type { PathLinux, PathOsBased } from '@teambit/legacy.utils';\nimport { pathNormalizeToLinux } from '@teambit/legacy.utils';\nimport type { AddActionResults, Warnings } from './add-components';\nimport type { TrackerMain } from './tracker.main.runtime';\n\ntype AddFlags = {\n id: string | null | undefined;\n main: string | null | undefined;\n namespace: string | null | undefined;\n scope?: string;\n env?: string;\n override: boolean;\n};\n\ntype AddResults = {\n addedComponents: Array<{ id: string; files: PathLinux[] }>;\n warnings: Warnings;\n};\n\nexport class AddCmd implements Command {\n name = 'add [path...]';\n description = 'track existing directory contents as new components in the workspace';\n group = 'component-development';\n extendedDescription =\n 'Registers one or more directories as Bit components without changing your files. Each provided path becomes a component root tracked by Bit.';\n helpUrl = 'reference/workspace/component-directory';\n alias = 'a';\n options = [\n ['i', 'id <name>', 'manually set component id'],\n ['m', 'main <file>', 'define component entry point'],\n ['n', 'namespace <namespace>', 'organize component in a namespace'],\n ['o', 'override <boolean>', 'override existing component if exists (default = false)'],\n [\n 's',\n 'scope <string>',\n `sets the component's scope. if not entered, the default-scope from workspace.jsonc will be used`,\n ],\n ['e', 'env <string>', \"set the component's environment. (overrides the env from variants if exists)\"],\n ['j', 'json', 'output as json format'],\n ] as CommandOptions;\n loader = true;\n\n constructor(private tracker: TrackerMain) {}\n\n async report([paths = []]: [string[]], addFlags: AddFlags) {\n const { addedComponents, warnings }: AddResults = await this.json([paths], addFlags);\n\n const paintWarning = () => {\n const alreadyUsedOutput = () => {\n const alreadyUsedWarning = Object.keys(warnings.alreadyUsed)\n .map((key) =>\n formatItem(\n `files ${chalk.bold(warnings.alreadyUsed[key].join(', '))} already used by component: ${key}`,\n warnSymbol\n )\n )\n .filter((x) => x)\n .join('\\n');\n return alreadyUsedWarning ? `${alreadyUsedWarning}\\n` : '';\n };\n const emptyDirectoryOutput = () => {\n if (!warnings.emptyDirectory.length) return '';\n const items = warnings.emptyDirectory.map((dir) => formatItem(chalk.bold(dir), warnSymbol));\n return `${formatTitle(`${warnSymbol} empty or excluded directories`)}\\n${items.join('\\n')}\\n`;\n };\n return alreadyUsedOutput() + emptyDirectoryOutput();\n };\n\n if (addedComponents.length > 1) {\n return paintWarning() + formatSuccessSummary(`tracking ${addedComponents.length} new components`);\n }\n\n return joinSections([\n paintWarning(),\n ...addedComponents.map((result) => {\n if (result.files.length === 0) {\n return `${errorSymbol} could not track component ${chalk.bold(result.id)}: no files to track`;\n }\n const title = formatTitle(`tracking component ${chalk.bold(result.id)}`);\n const files = result.files.map((file) => formatItem(`added ${file}`));\n return `${title}\\n${files.join('\\n')}`;\n }),\n ]);\n }\n\n async json(\n [paths = []]: [string[]],\n { id, main, namespace, scope, env, override = false }: AddFlags\n ): Promise<AddResults> {\n if (namespace && id) {\n throw new BitError(\n 'please use either [id] or [namespace] to add a particular component - they cannot be used together'\n );\n }\n\n const normalizedPaths: PathOsBased[] = paths.map((p) => pathNormalizeToLinux(path.normalize(p)));\n const { addedComponents, warnings }: AddActionResults = await this.tracker.addForCLI({\n componentPaths: normalizedPaths,\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n id,\n main: main ? pathNormalizeToLinux(path.normalize(main)) : undefined,\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n namespace,\n defaultScope: scope,\n override,\n env,\n });\n return {\n addedComponents: addedComponents.map((added) => ({\n id: added.id.toString(),\n files: added.files.map((f) => f.relativePath),\n })),\n warnings,\n };\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,KAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,IAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,OAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EAAAC,MAAA,YAAAA,CAAA;IAAA,OAAAF,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,KAAA;EAAA,MAAAJ,IAAA,GAAAK,uBAAA,CAAAJ,OAAA;EAAAG,IAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,UAAA;EAAA,MAAAN,IAAA,GAAAC,OAAA;EAAAK,SAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,SAAAO,QAAA;EAAA,MAAAP,IAAA,GAAAC,OAAA;EAAAM,OAAA,YAAAA,CAAA;IAAA,OAAAP,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAA6D,SAAAK,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAA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AAEL,eAAe;MAC/B;MACAT,EAAE;MACFG,IAAI,EAAEA,IAAI,GAAG,IAAAQ,8BAAoB,EAAChF,IAAI,CAAD,CAAC,CAACiF,SAAS,CAACT,IAAI,CAAC,CAAC,GAAGY,SAAS;MACnE;MACAX,SAAS;MACTY,YAAY,EAAEX,KAAK;MACnBE,QAAQ;MACRD;IACF,CAAC,CAAC;IACF,OAAO;MACLlC,eAAe,EAAEA,eAAe,CAACQ,GAAG,CAAEqC,KAAK,KAAM;QAC/CjB,EAAE,EAAEiB,KAAK,CAACjB,EAAE,CAACkB,QAAQ,CAAC,CAAC;QACvBpB,KAAK,EAAEmB,KAAK,CAACnB,KAAK,CAAClB,GAAG,CAAErC,CAAC,IAAKA,CAAC,CAAC4E,YAAY;MAC9C,CAAC,CAAC,CAAC;MACH9C;IACF,CAAC;EACH;AACF;AAAC+C,OAAA,CAAAtD,MAAA,GAAAA,MAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_cli","data","require","_chalk","_interopRequireDefault","path","_interopRequireWildcard","_bitError","_legacy","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_defineProperty","_toPropertyKey","value","enumerable","configurable","writable","_toPrimitive","Symbol","toPrimitive","TypeError","String","Number","AddCmd","constructor","tracker","report","paths","addFlags","addedComponents","warnings","json","paintWarning","alreadyUsedOutput","alreadyUsedWarning","keys","alreadyUsed","map","key","formatItem","chalk","bold","join","warnSymbol","filter","x","emptyDirectoryOutput","emptyDirectory","length","items","dir","formatTitle","formatSuccessSummary","joinSections","result","files","errorSymbol","id","title","file","main","namespace","scope","env","override","root","BitError","normalizedPaths","p","pathNormalizeToLinux","normalize","addForCLI","componentPaths","undefined","defaultScope","added","toString","relativePath","exports"],"sources":["add-cmd.ts"],"sourcesContent":["import type { Command, CommandOptions } from '@teambit/cli';\nimport { formatTitle, formatItem, formatSuccessSummary, warnSymbol, errorSymbol, joinSections } from '@teambit/cli';\nimport chalk from 'chalk';\nimport * as path from 'path';\nimport { BitError } from '@teambit/bit-error';\nimport type { PathLinux, PathOsBased } from '@teambit/legacy.utils';\nimport { pathNormalizeToLinux } from '@teambit/legacy.utils';\nimport type { AddActionResults, Warnings } from './add-components';\nimport type { TrackerMain } from './tracker.main.runtime';\n\ntype AddFlags = {\n id: string | null | undefined;\n main: string | null | undefined;\n namespace: string | null | undefined;\n scope?: string;\n env?: string;\n override: boolean;\n root?: boolean;\n};\n\ntype AddResults = {\n addedComponents: Array<{ id: string; files: PathLinux[] }>;\n warnings: Warnings;\n};\n\nexport class AddCmd implements Command {\n name = 'add [path...]';\n description = 'track existing directory contents as new components in the workspace';\n group = 'component-development';\n extendedDescription =\n 'Registers one or more directories as Bit components without changing your files. Each provided path becomes a component root tracked by Bit.';\n helpUrl = 'reference/workspace/component-directory';\n alias = 'a';\n options = [\n ['i', 'id <name>', 'manually set component id'],\n ['m', 'main <file>', 'define component entry point'],\n ['n', 'namespace <namespace>', 'organize component in a namespace'],\n ['o', 'override <boolean>', 'override existing component if exists (default = false)'],\n [\n 's',\n 'scope <string>',\n `sets the component's scope. if not entered, the default-scope from workspace.jsonc will be used`,\n ],\n ['e', 'env <string>', \"set the component's environment. (overrides the env from variants if exists)\"],\n ['', 'root', 'track the workspace root itself as a component, which owns every file no other component claims'],\n ['j', 'json', 'output as json format'],\n ] as CommandOptions;\n loader = true;\n\n constructor(private tracker: TrackerMain) {}\n\n async report([paths = []]: [string[]], addFlags: AddFlags) {\n const { addedComponents, warnings }: AddResults = await this.json([paths], addFlags);\n\n const paintWarning = () => {\n const alreadyUsedOutput = () => {\n const alreadyUsedWarning = Object.keys(warnings.alreadyUsed)\n .map((key) =>\n formatItem(\n `files ${chalk.bold(warnings.alreadyUsed[key].join(', '))} already used by component: ${key}`,\n warnSymbol\n )\n )\n .filter((x) => x)\n .join('\\n');\n return alreadyUsedWarning ? `${alreadyUsedWarning}\\n` : '';\n };\n const emptyDirectoryOutput = () => {\n if (!warnings.emptyDirectory.length) return '';\n const items = warnings.emptyDirectory.map((dir) => formatItem(chalk.bold(dir), warnSymbol));\n return `${formatTitle(`${warnSymbol} empty or excluded directories`)}\\n${items.join('\\n')}\\n`;\n };\n return alreadyUsedOutput() + emptyDirectoryOutput();\n };\n\n if (addedComponents.length > 1) {\n return paintWarning() + formatSuccessSummary(`tracking ${addedComponents.length} new components`);\n }\n\n return joinSections([\n paintWarning(),\n ...addedComponents.map((result) => {\n if (result.files.length === 0) {\n return `${errorSymbol} could not track component ${chalk.bold(result.id)}: no files to track`;\n }\n const title = formatTitle(`tracking component ${chalk.bold(result.id)}`);\n const files = result.files.map((file) => formatItem(`added ${file}`));\n return `${title}\\n${files.join('\\n')}`;\n }),\n ]);\n }\n\n async json(\n [paths = []]: [string[]],\n { id, main, namespace, scope, env, override = false, root = false }: AddFlags\n ): Promise<AddResults> {\n if (namespace && id) {\n throw new BitError(\n 'please use either [id] or [namespace] to add a particular component - they cannot be used together'\n );\n }\n\n const normalizedPaths: PathOsBased[] = paths.map((p) => pathNormalizeToLinux(path.normalize(p)));\n const { addedComponents, warnings }: AddActionResults = await this.tracker.addForCLI({\n componentPaths: normalizedPaths,\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n id,\n main: main ? pathNormalizeToLinux(path.normalize(main)) : undefined,\n // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!\n namespace,\n defaultScope: scope,\n override,\n env,\n root,\n });\n return {\n addedComponents: addedComponents.map((added) => ({\n id: added.id.toString(),\n files: added.files.map((f) => f.relativePath),\n })),\n warnings,\n };\n }\n}\n"],"mappings":";;;;;;AACA,SAAAA,KAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,IAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAE,OAAA;EAAA,MAAAF,IAAA,GAAAG,sBAAA,CAAAF,OAAA;EA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2,7 +2,7 @@ import { ComponentID } from '@teambit/component-id';
|
|
|
2
2
|
import type { BitMap, ComponentMapFile, Config } from '@teambit/legacy.bit-map';
|
|
3
3
|
import { ComponentMap } from '@teambit/legacy.bit-map';
|
|
4
4
|
import type { Consumer } from '@teambit/legacy.consumer';
|
|
5
|
-
import type { PathLinux, PathOsBased } from '@teambit/legacy.utils';
|
|
5
|
+
import type { PathLinux, PathLinuxRelative, PathOsBased } from '@teambit/legacy.utils';
|
|
6
6
|
import type { Workspace } from '@teambit/workspace';
|
|
7
7
|
import type { ResolvedTrackData } from './tracker.main.runtime';
|
|
8
8
|
export type AddResult = {
|
|
@@ -42,6 +42,11 @@ export type AddProps = {
|
|
|
42
42
|
config?: Config;
|
|
43
43
|
shouldHandleOutOfSync?: boolean;
|
|
44
44
|
env?: string;
|
|
45
|
+
/**
|
|
46
|
+
* spells out the intent to track the workspace root itself. required for it and only for it, see
|
|
47
|
+
* AddComponents.throwForWorkspaceRootFlagMismatch.
|
|
48
|
+
*/
|
|
49
|
+
root?: boolean;
|
|
45
50
|
};
|
|
46
51
|
export type AddContext = {
|
|
47
52
|
workspace: Workspace;
|
|
@@ -63,7 +68,27 @@ export default class AddComponents {
|
|
|
63
68
|
defaultScope?: string;
|
|
64
69
|
config?: Config;
|
|
65
70
|
shouldHandleOutOfSync?: boolean;
|
|
71
|
+
root?: boolean;
|
|
66
72
|
constructor(context: AddContext, addProps: AddProps);
|
|
73
|
+
/**
|
|
74
|
+
* tracking the workspace root turns the workspace itself into a component: it owns every file no
|
|
75
|
+
* other component claims, `.bitmap` included, and every other component becomes a member of it.
|
|
76
|
+
* "bit add ." is one keystroke away from "git add .", which means something else entirely, so the
|
|
77
|
+
* intent is spelled out rather than inferred from the path.
|
|
78
|
+
*
|
|
79
|
+
* only the workspace root needs the flag, and it is the only thing the flag does: "bit add ." from
|
|
80
|
+
* a sub-directory names that directory, not the root, and is tracked like any other path.
|
|
81
|
+
*
|
|
82
|
+
* a workspace that already has a root does not ask again. what the flag guards against is creating
|
|
83
|
+
* one by accident, and there is none to create here - the add either refreshes the root that exists
|
|
84
|
+
* or names a second owner for ".", which has its own message saying who holds it.
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* the paths reach here as the user typed them - relative to the cwd, or absolute - so the workspace
|
|
88
|
+
* root arrives as ".", as "", or as the workspace path itself, depending on where the command ran.
|
|
89
|
+
*/
|
|
90
|
+
private isWorkspaceRootPath;
|
|
91
|
+
private throwForWorkspaceRootFlagMismatch;
|
|
67
92
|
add(): Promise<AddActionResults>;
|
|
68
93
|
/**
|
|
69
94
|
* @param {string[]} files - array of file-paths from which it should search for the dsl patterns.
|
|
@@ -125,7 +150,7 @@ export default class AddComponents {
|
|
|
125
150
|
* e.g. bar/foo.js, the id would be bar/foo.
|
|
126
151
|
* in case bitmap has already the same id, the complete id is taken from bitmap (see _getIdAccordingToExistingComponent)
|
|
127
152
|
*/
|
|
128
|
-
addOneComponent(componentPath: PathOsBased): Promise<AddedComponent>;
|
|
153
|
+
addOneComponent(componentPath: PathOsBased, batchRootDirs?: PathLinuxRelative[]): Promise<AddedComponent>;
|
|
129
154
|
getIgnoreList(): Promise<string[]>;
|
|
130
155
|
linkComponents(ids: ComponentID[]): Promise<void>;
|
|
131
156
|
addMultipleComponents(componentPathsStats: PathsStats): Promise<void>;
|
|
@@ -140,5 +165,13 @@ export default class AddComponents {
|
|
|
140
165
|
_tryAddingMultiple(componentPathsStats: PathsStats): Promise<AddedComponent[]>;
|
|
141
166
|
_throwForOutsideConsumer(relativeToConsumerPath: PathOsBased): void;
|
|
142
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* the workspace-root component (rootDir ".") is a bag of config files, not a source component:
|
|
170
|
+
* nothing compiles it, nothing tests it, and nothing imports it as a package. the regular default
|
|
171
|
+
* env would give it a compiler and a dependency policy it can never satisfy, so it is tracked with
|
|
172
|
+
* the empty env - as explicit config, so every path that resolves an env or a dependency policy
|
|
173
|
+
* sees the same answer. an env configured by the caller, or set later with "bit env set", wins.
|
|
174
|
+
*/
|
|
175
|
+
export declare function configForWorkspaceRoot(existingConfig?: Config, addedConfig?: Config): Config;
|
|
143
176
|
export declare function addMultipleFromResolvedTrackData(workspace: Workspace, trackData: ResolvedTrackData[]): Promise<ComponentID[]>;
|
|
144
177
|
export {};
|