@teambit/workspace.modules.node-modules-linker 0.0.173 → 0.0.175
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/node-modules-linker.d.ts +4 -0
- package/dist/node-modules-linker.js +58 -29
- package/dist/node-modules-linker.js.map +1 -1
- package/dist/tsconfig.json +5 -0
- package/node-modules-linker.ts +68 -28
- package/package.json +3 -3
- package/tsconfig.json +5 -0
- /package/dist/{preview-1715509699621.js → preview-1720513025675.js} +0 -0
|
@@ -10,6 +10,7 @@ import { Component } from '@teambit/component';
|
|
|
10
10
|
type LinkDetail = {
|
|
11
11
|
from: string;
|
|
12
12
|
to: string;
|
|
13
|
+
existsBefore: boolean;
|
|
13
14
|
};
|
|
14
15
|
export type NodeModulesLinksResult = {
|
|
15
16
|
id: ComponentID;
|
|
@@ -25,9 +26,12 @@ export default class NodeModuleLinker {
|
|
|
25
26
|
consumer: Consumer;
|
|
26
27
|
bitMap: BitMap;
|
|
27
28
|
dataToPersist: DataToPersist;
|
|
29
|
+
existingLinks: NodeModulesLinksResult[];
|
|
30
|
+
packageJsonCreated: boolean;
|
|
28
31
|
constructor(components: Component[], workspace: Workspace);
|
|
29
32
|
link(): Promise<NodeModulesLinksResult[]>;
|
|
30
33
|
getLinks(): Promise<DataToPersist>;
|
|
34
|
+
private addLinkResult;
|
|
31
35
|
getLinksResults(): NodeModulesLinksResult[];
|
|
32
36
|
_getDefaultScope(component?: ConsumerComponent): string | undefined | null;
|
|
33
37
|
/**
|
|
@@ -62,6 +62,8 @@ class NodeModuleLinker {
|
|
|
62
62
|
this.consumer = this.workspace.consumer;
|
|
63
63
|
this.bitMap = this.consumer.bitMap;
|
|
64
64
|
this.dataToPersist = new data_to_persist_1.default();
|
|
65
|
+
this.existingLinks = [];
|
|
66
|
+
this.packageJsonCreated = false;
|
|
65
67
|
}
|
|
66
68
|
link() {
|
|
67
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -71,15 +73,19 @@ class NodeModuleLinker {
|
|
|
71
73
|
if (!linksResults.length) {
|
|
72
74
|
// avoid clearing the cache if it ends up with no links. (e.g. happens when mistakenly generating links for a
|
|
73
75
|
// component not in the workspace)
|
|
76
|
+
// or when all links are already exist.
|
|
74
77
|
return [];
|
|
75
78
|
}
|
|
76
79
|
const workspacePath = this.workspace.path;
|
|
77
80
|
links.addBasePath(workspacePath);
|
|
78
81
|
yield links.persistAllToFS();
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
// Only clear cache if new package.json of components were created
|
|
83
|
+
if (this.packageJsonCreated) {
|
|
84
|
+
yield Promise.all(this.components.map((component) => { var _a; return (_a = this.consumer) === null || _a === void 0 ? void 0 : _a.componentFsCache.deleteDependenciesDataCache(component.id.toString()); }));
|
|
85
|
+
// if this cache is not cleared, then when asking workspace.get again to the same component, it returns it with
|
|
86
|
+
// component-issues like "MissingLinksFromNodeModulesToSrc" incorrectly.
|
|
87
|
+
this.workspace.clearAllComponentsCache();
|
|
88
|
+
}
|
|
83
89
|
yield (0, bit_roots_1.linkPkgsToBitRoots)(workspacePath, this.components.map((comp) => (0, component_id_to_package_name_1.default)(comp.state._consumer)));
|
|
84
90
|
return linksResults;
|
|
85
91
|
});
|
|
@@ -95,25 +101,30 @@ class NodeModuleLinker {
|
|
|
95
101
|
return this.dataToPersist;
|
|
96
102
|
});
|
|
97
103
|
}
|
|
104
|
+
addLinkResult(linksResults, id, from, to, existsBefore) {
|
|
105
|
+
if (!id)
|
|
106
|
+
return;
|
|
107
|
+
const existingLinkResult = linksResults.find((linkResult) => linkResult.id.isEqual(id));
|
|
108
|
+
if (existingLinkResult) {
|
|
109
|
+
existingLinkResult.bound.push({ from, to, existsBefore });
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
linksResults.push({ id, bound: [{ from, to, existsBefore }] });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
98
115
|
getLinksResults() {
|
|
99
116
|
const linksResults = [];
|
|
100
|
-
const getExistingLinkResult = (id) => linksResults.find((linkResult) => linkResult.id.isEqual(id));
|
|
101
|
-
const addLinkResult = (id, from, to) => {
|
|
102
|
-
if (!id)
|
|
103
|
-
return;
|
|
104
|
-
const existingLinkResult = getExistingLinkResult(id);
|
|
105
|
-
if (existingLinkResult) {
|
|
106
|
-
existingLinkResult.bound.push({ from, to });
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
linksResults.push({ id, bound: [{ from, to }] });
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
117
|
this.dataToPersist.symlinks.forEach((symlink) => {
|
|
113
|
-
addLinkResult(symlink.componentId, symlink.src, symlink.dest);
|
|
118
|
+
this.addLinkResult(linksResults, symlink.componentId, symlink.src, symlink.dest, false);
|
|
119
|
+
});
|
|
120
|
+
this.existingLinks.forEach((link) => {
|
|
121
|
+
const componentId = link.id;
|
|
122
|
+
link.bound.forEach((bound) => {
|
|
123
|
+
this.addLinkResult(linksResults, componentId, bound.from, bound.to, true);
|
|
124
|
+
});
|
|
114
125
|
});
|
|
115
126
|
this.components.forEach((component) => {
|
|
116
|
-
const existingLinkResult =
|
|
127
|
+
const existingLinkResult = linksResults.find((linkResult) => linkResult.id.isEqual(component.id));
|
|
117
128
|
if (!existingLinkResult) {
|
|
118
129
|
linksResults.push({ id: component.id, bound: [] });
|
|
119
130
|
}
|
|
@@ -136,23 +147,37 @@ class NodeModuleLinker {
|
|
|
136
147
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
148
|
const legacyComponent = component.state._consumer;
|
|
138
149
|
const linkPath = (0, component_node_modules_path_1.default)(legacyComponent);
|
|
139
|
-
this.symlinkComponentDir(component, linkPath);
|
|
150
|
+
yield this.symlinkComponentDir(component, linkPath);
|
|
140
151
|
this._deleteExistingLinksRootIfSymlink(linkPath);
|
|
141
152
|
yield this.createPackageJson(component);
|
|
142
153
|
});
|
|
143
154
|
}
|
|
144
155
|
symlinkComponentDir(component, linkPath) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
const componentMap = this.bitMap.getComponent(component.id);
|
|
158
|
+
const filesToBind = componentMap.getAllFilesPaths();
|
|
159
|
+
yield Promise.all(filesToBind.map((file) => __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
const fileWithRootDir = path.join(componentMap.rootDir, file);
|
|
161
|
+
const dest = path.join(linkPath, file);
|
|
162
|
+
let stat;
|
|
163
|
+
try {
|
|
164
|
+
stat = yield fs_extra_1.default.lstat(dest);
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
// Ignore this error, it's probably because the file doesn't exist
|
|
168
|
+
}
|
|
169
|
+
if (stat && stat.isSymbolicLink()) {
|
|
170
|
+
this.addLinkResult(this.existingLinks, component.id, fileWithRootDir, dest, true);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
this.dataToPersist.addSymlink(symlink_1.default.makeInstance(fileWithRootDir, dest, component.id, true));
|
|
174
|
+
}
|
|
175
|
+
})));
|
|
176
|
+
if (constants_1.IS_WINDOWS) {
|
|
177
|
+
// symlink the entire source directory into "_src" in node-modules.
|
|
178
|
+
this.dataToPersist.addSymlink(symlink_1.default.makeInstance(componentMap.rootDir, path.join(linkPath, constants_1.SOURCE_DIR_SYMLINK_TO_NM), component.id));
|
|
179
|
+
}
|
|
151
180
|
});
|
|
152
|
-
if (constants_1.IS_WINDOWS) {
|
|
153
|
-
// symlink the entire source directory into "_src" in node-modules.
|
|
154
|
-
this.dataToPersist.addSymlink(symlink_1.default.makeInstance(componentMap.rootDir, path.join(linkPath, constants_1.SOURCE_DIR_SYMLINK_TO_NM), component.id));
|
|
155
|
-
}
|
|
156
181
|
}
|
|
157
182
|
/**
|
|
158
183
|
* Removing existing links root (the package path) - to handle cases it was linked by package manager for example
|
|
@@ -187,6 +212,10 @@ class NodeModuleLinker {
|
|
|
187
212
|
if (hasPackageJsonAsComponentFile)
|
|
188
213
|
return; // don't generate package.json on top of the user package.json
|
|
189
214
|
const dest = path.join((0, component_node_modules_path_1.default)(Object.assign(Object.assign({}, legacyComp), { id: legacyComp.id })));
|
|
215
|
+
const packageJsonExist = yield fs_extra_1.default.pathExists(path.join(dest, 'package.json'));
|
|
216
|
+
if (!packageJsonExist) {
|
|
217
|
+
this.packageJsonCreated = true;
|
|
218
|
+
}
|
|
190
219
|
const packageJson = package_json_file_1.default.createFromComponent(dest, legacyComp, true);
|
|
191
220
|
yield this._applyTransformers(component, packageJson);
|
|
192
221
|
if (constants_1.IS_WINDOWS) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-modules-linker.js","sourceRoot":"","sources":["../node-modules-linker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0B;AAC1B,gEAAsC;AACtC,2CAA6B;AAC7B,kDAAwD;AAExD,8DAAoG;AAGpG,kHAAwF;AACxF,sHAA4F;AAC5F,8GAAqF;AAErF,gFAAwD;AACxD,6HAAuG;AAEvG,iFAAyD;AACzD,+HAAmG;AAEnG,kFAAkE;AAElE,yEAAoE;AACpE,6DAA2E;AAQ3E;;;GAGG;AACH,MAAqB,gBAAgB;
|
|
1
|
+
{"version":3,"file":"node-modules-linker.js","sourceRoot":"","sources":["../node-modules-linker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0B;AAC1B,gEAAsC;AACtC,2CAA6B;AAC7B,kDAAwD;AAExD,8DAAoG;AAGpG,kHAAwF;AACxF,sHAA4F;AAC5F,8GAAqF;AAErF,gFAAwD;AACxD,6HAAuG;AAEvG,iFAAyD;AACzD,+HAAmG;AAEnG,kFAAkE;AAElE,yEAAoE;AACpE,6DAA2E;AAQ3E;;;GAGG;AACH,MAAqB,gBAAgB;IAOnC,YAAoB,UAAuB,EAAU,SAA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AAC,UAAU,EAAE,SAAS,CAAC,CAAC;QACrE,OAAO,gBAAgB,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;CAAA;AAfD,wDAeC;AAED,SAAsB,6BAA6B,CAAC,UAAuB,EAAE,SAAoB;;QAC/F,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;QACrE,OAAO,gBAAgB,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;CAAA;AAHD,sEAGC;AAED,SAAsB,0BAA0B,CAC9C,SAAoB,EACpB,SAAoB,EACpB,KAA4B;;QAE5B,MAAM,eAAe,GAAG,SAAS,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY;QAC1E,MAAM,0BAA0B,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC;QAC7F,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;QAClE,MAAM,aAAa,GAAG,0BAA0B,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;QACxF,gBAAM,CAAC,KAAK,CAAC;EACb,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5B,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;CAAA;AAZD,gEAYC"}
|
package/dist/tsconfig.json
CHANGED
package/node-modules-linker.ts
CHANGED
|
@@ -21,7 +21,7 @@ import { Component } from '@teambit/component';
|
|
|
21
21
|
import { PackageJsonTransformer } from './package-json-transformer';
|
|
22
22
|
import { changeCodeFromRelativeToModulePaths } from './codemod-components';
|
|
23
23
|
|
|
24
|
-
type LinkDetail = { from: string; to: string };
|
|
24
|
+
type LinkDetail = { from: string; to: string; existsBefore: boolean };
|
|
25
25
|
export type NodeModulesLinksResult = {
|
|
26
26
|
id: ComponentID;
|
|
27
27
|
bound: LinkDetail[];
|
|
@@ -35,31 +35,42 @@ export default class NodeModuleLinker {
|
|
|
35
35
|
consumer: Consumer;
|
|
36
36
|
bitMap: BitMap; // preparation for the capsule, which is going to have only BitMap with no Consumer
|
|
37
37
|
dataToPersist: DataToPersist;
|
|
38
|
+
existingLinks: NodeModulesLinksResult[];
|
|
39
|
+
packageJsonCreated: boolean;
|
|
40
|
+
|
|
38
41
|
constructor(private components: Component[], private workspace: Workspace) {
|
|
39
42
|
this.consumer = this.workspace.consumer;
|
|
40
43
|
this.bitMap = this.consumer.bitMap;
|
|
41
44
|
this.dataToPersist = new DataToPersist();
|
|
45
|
+
this.existingLinks = [];
|
|
46
|
+
this.packageJsonCreated = false;
|
|
42
47
|
}
|
|
43
48
|
async link(): Promise<NodeModulesLinksResult[]> {
|
|
44
49
|
this.components = this.components.filter((component) => this.bitMap.getComponentIfExist(component.id));
|
|
45
50
|
const links = await this.getLinks();
|
|
51
|
+
|
|
46
52
|
const linksResults = this.getLinksResults();
|
|
47
53
|
if (!linksResults.length) {
|
|
48
54
|
// avoid clearing the cache if it ends up with no links. (e.g. happens when mistakenly generating links for a
|
|
49
55
|
// component not in the workspace)
|
|
56
|
+
// or when all links are already exist.
|
|
50
57
|
return [];
|
|
51
58
|
}
|
|
52
59
|
const workspacePath = this.workspace.path;
|
|
53
60
|
links.addBasePath(workspacePath);
|
|
54
61
|
await links.persistAllToFS();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
// Only clear cache if new package.json of components were created
|
|
63
|
+
if (this.packageJsonCreated) {
|
|
64
|
+
await Promise.all(
|
|
65
|
+
this.components.map((component) =>
|
|
66
|
+
this.consumer?.componentFsCache.deleteDependenciesDataCache(component.id.toString())
|
|
67
|
+
)
|
|
68
|
+
);
|
|
69
|
+
// if this cache is not cleared, then when asking workspace.get again to the same component, it returns it with
|
|
70
|
+
// component-issues like "MissingLinksFromNodeModulesToSrc" incorrectly.
|
|
71
|
+
this.workspace.clearAllComponentsCache();
|
|
72
|
+
}
|
|
73
|
+
|
|
63
74
|
await linkPkgsToBitRoots(
|
|
64
75
|
workspacePath,
|
|
65
76
|
this.components.map((comp) => componentIdToPackageName(comp.state._consumer))
|
|
@@ -76,23 +87,35 @@ export default class NodeModuleLinker {
|
|
|
76
87
|
|
|
77
88
|
return this.dataToPersist;
|
|
78
89
|
}
|
|
90
|
+
private addLinkResult(
|
|
91
|
+
linksResults: NodeModulesLinksResult[],
|
|
92
|
+
id: ComponentID | null | undefined,
|
|
93
|
+
from: string,
|
|
94
|
+
to: string,
|
|
95
|
+
existsBefore: boolean
|
|
96
|
+
) {
|
|
97
|
+
if (!id) return;
|
|
98
|
+
const existingLinkResult = linksResults.find((linkResult) => linkResult.id.isEqual(id));
|
|
99
|
+
if (existingLinkResult) {
|
|
100
|
+
existingLinkResult.bound.push({ from, to, existsBefore });
|
|
101
|
+
} else {
|
|
102
|
+
linksResults.push({ id, bound: [{ from, to, existsBefore }] });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
79
106
|
getLinksResults(): NodeModulesLinksResult[] {
|
|
80
107
|
const linksResults: NodeModulesLinksResult[] = [];
|
|
81
|
-
const getExistingLinkResult = (id: ComponentID) => linksResults.find((linkResult) => linkResult.id.isEqual(id));
|
|
82
|
-
const addLinkResult = (id: ComponentID | null | undefined, from: string, to: string) => {
|
|
83
|
-
if (!id) return;
|
|
84
|
-
const existingLinkResult = getExistingLinkResult(id);
|
|
85
|
-
if (existingLinkResult) {
|
|
86
|
-
existingLinkResult.bound.push({ from, to });
|
|
87
|
-
} else {
|
|
88
|
-
linksResults.push({ id, bound: [{ from, to }] });
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
108
|
this.dataToPersist.symlinks.forEach((symlink: Symlink) => {
|
|
92
|
-
addLinkResult(symlink.componentId, symlink.src, symlink.dest);
|
|
109
|
+
this.addLinkResult(linksResults, symlink.componentId, symlink.src, symlink.dest, false);
|
|
110
|
+
});
|
|
111
|
+
this.existingLinks.forEach((link: NodeModulesLinksResult) => {
|
|
112
|
+
const componentId = link.id;
|
|
113
|
+
link.bound.forEach((bound) => {
|
|
114
|
+
this.addLinkResult(linksResults, componentId, bound.from, bound.to, true);
|
|
115
|
+
});
|
|
93
116
|
});
|
|
94
117
|
this.components.forEach((component) => {
|
|
95
|
-
const existingLinkResult =
|
|
118
|
+
const existingLinkResult = linksResults.find((linkResult) => linkResult.id.isEqual(component.id));
|
|
96
119
|
if (!existingLinkResult) {
|
|
97
120
|
linksResults.push({ id: component.id, bound: [] });
|
|
98
121
|
}
|
|
@@ -117,20 +140,32 @@ export default class NodeModuleLinker {
|
|
|
117
140
|
const legacyComponent = component.state._consumer as ConsumerComponent;
|
|
118
141
|
const linkPath: PathOsBasedRelative = getNodeModulesPathOfComponent(legacyComponent);
|
|
119
142
|
|
|
120
|
-
this.symlinkComponentDir(component, linkPath);
|
|
143
|
+
await this.symlinkComponentDir(component, linkPath);
|
|
121
144
|
this._deleteExistingLinksRootIfSymlink(linkPath);
|
|
122
145
|
await this.createPackageJson(component);
|
|
123
146
|
}
|
|
124
147
|
|
|
125
|
-
private symlinkComponentDir(component: Component, linkPath: PathOsBasedRelative) {
|
|
148
|
+
private async symlinkComponentDir(component: Component, linkPath: PathOsBasedRelative) {
|
|
126
149
|
const componentMap = this.bitMap.getComponent(component.id);
|
|
127
150
|
|
|
128
151
|
const filesToBind = componentMap.getAllFilesPaths();
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
152
|
+
await Promise.all(
|
|
153
|
+
filesToBind.map(async (file) => {
|
|
154
|
+
const fileWithRootDir = path.join(componentMap.rootDir as string, file);
|
|
155
|
+
const dest = path.join(linkPath, file);
|
|
156
|
+
let stat;
|
|
157
|
+
try {
|
|
158
|
+
stat = await fs.lstat(dest);
|
|
159
|
+
} catch (err) {
|
|
160
|
+
// Ignore this error, it's probably because the file doesn't exist
|
|
161
|
+
}
|
|
162
|
+
if (stat && stat.isSymbolicLink()) {
|
|
163
|
+
this.addLinkResult(this.existingLinks, component.id, fileWithRootDir, dest, true);
|
|
164
|
+
} else {
|
|
165
|
+
this.dataToPersist.addSymlink(Symlink.makeInstance(fileWithRootDir, dest, component.id, true));
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
);
|
|
134
169
|
|
|
135
170
|
if (IS_WINDOWS) {
|
|
136
171
|
// symlink the entire source directory into "_src" in node-modules.
|
|
@@ -180,6 +215,11 @@ export default class NodeModuleLinker {
|
|
|
180
215
|
id: legacyComp.id,
|
|
181
216
|
})
|
|
182
217
|
);
|
|
218
|
+
const packageJsonExist = await fs.pathExists(path.join(dest, 'package.json'));
|
|
219
|
+
if (!packageJsonExist) {
|
|
220
|
+
this.packageJsonCreated = true;
|
|
221
|
+
}
|
|
222
|
+
|
|
183
223
|
const packageJson = PackageJsonFile.createFromComponent(dest, legacyComp, true);
|
|
184
224
|
await this._applyTransformers(component, packageJson);
|
|
185
225
|
if (IS_WINDOWS) {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/workspace.modules.node-modules-linker",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.175",
|
|
4
4
|
"homepage": "https://bit.cloud/teambit/workspace/modules/node-modules-linker",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.workspace",
|
|
8
8
|
"name": "modules/node-modules-linker",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.175"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"fs-extra": "10.0.0",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"lodash": "4.17.21",
|
|
15
15
|
"@teambit/component-id": "1.2.0",
|
|
16
16
|
"@teambit/bit-roots": "0.0.133",
|
|
17
|
-
"@teambit/component-issues": "0.0.
|
|
17
|
+
"@teambit/component-issues": "0.0.150",
|
|
18
18
|
"@teambit/component-package-version": "0.0.433"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
package/tsconfig.json
CHANGED
|
File without changes
|