@teambit/workspace.modules.node-modules-linker 0.0.56 → 0.0.57
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/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/node-modules-linker.d.ts +2 -11
- package/dist/node-modules-linker.js +17 -46
- package/dist/node-modules-linker.js.map +1 -1
- package/index.ts +1 -0
- package/node-modules-linker.ts +22 -62
- package/package-tar/teambit-workspace.modules.node-modules-linker-0.0.57.tgz +0 -0
- package/package.json +3 -5
- package/package-tar/teambit-workspace.modules.node-modules-linker-0.0.56.tgz +0 -0
- /package/dist/{preview-1684294998398.js → preview-1684385399904.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { NodeModulesLinksResult, linkToNodeModulesByIds, linkToNodeModulesWithCodemod, linkToNodeModulesByComponents, } from './node-modules-linker';
|
|
1
|
+
export { NodeModulesLinksResult, linkToNodeModulesByIds, linkToNodeModulesWithCodemod, linkToNodeModulesByComponents, removeLinksFromNodeModules, } from './node-modules-linker';
|
|
2
2
|
export { PackageJsonTransformer } from './package-json-transformer';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PackageJsonTransformer = exports.linkToNodeModulesByComponents = exports.linkToNodeModulesWithCodemod = exports.linkToNodeModulesByIds = void 0;
|
|
3
|
+
exports.PackageJsonTransformer = exports.removeLinksFromNodeModules = exports.linkToNodeModulesByComponents = exports.linkToNodeModulesWithCodemod = exports.linkToNodeModulesByIds = void 0;
|
|
4
4
|
var node_modules_linker_1 = require("./node-modules-linker");
|
|
5
5
|
Object.defineProperty(exports, "linkToNodeModulesByIds", { enumerable: true, get: function () { return node_modules_linker_1.linkToNodeModulesByIds; } });
|
|
6
6
|
Object.defineProperty(exports, "linkToNodeModulesWithCodemod", { enumerable: true, get: function () { return node_modules_linker_1.linkToNodeModulesWithCodemod; } });
|
|
7
7
|
Object.defineProperty(exports, "linkToNodeModulesByComponents", { enumerable: true, get: function () { return node_modules_linker_1.linkToNodeModulesByComponents; } });
|
|
8
|
+
Object.defineProperty(exports, "removeLinksFromNodeModules", { enumerable: true, get: function () { return node_modules_linker_1.removeLinksFromNodeModules; } });
|
|
8
9
|
var package_json_transformer_1 = require("./package-json-transformer");
|
|
9
10
|
Object.defineProperty(exports, "PackageJsonTransformer", { enumerable: true, get: function () { return package_json_transformer_1.PackageJsonTransformer; } });
|
|
10
11
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,6DAM+B;AAJ7B,6HAAA,sBAAsB,OAAA;AACtB,mIAAA,4BAA4B,OAAA;AAC5B,oIAAA,6BAA6B,OAAA;AAC7B,iIAAA,0BAA0B,OAAA;AAG5B,uEAAoE;AAA3D,kIAAA,sBAAsB,OAAA"}
|
|
@@ -4,8 +4,7 @@ import ConsumerComponent from '@teambit/legacy/dist/consumer/component/consumer-
|
|
|
4
4
|
import PackageJsonFile from '@teambit/legacy/dist/consumer/component/package-json-file';
|
|
5
5
|
import DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';
|
|
6
6
|
import Consumer from '@teambit/legacy/dist/consumer/consumer';
|
|
7
|
-
import {
|
|
8
|
-
import Symlink from '@teambit/legacy/dist/links/symlink';
|
|
7
|
+
import { PathOsBasedAbsolute } from '@teambit/legacy/dist/utils/path';
|
|
9
8
|
import { Workspace } from '@teambit/workspace';
|
|
10
9
|
import { Component } from '@teambit/component';
|
|
11
10
|
declare type LinkDetail = {
|
|
@@ -38,9 +37,6 @@ export default class NodeModuleLinker {
|
|
|
38
37
|
* property or an index.js file. this main property can't be relative.
|
|
39
38
|
*/
|
|
40
39
|
_populateComponentsLinks(component: Component): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* symlink the entire source directory into "src" in node-modules.
|
|
43
|
-
*/
|
|
44
40
|
private symlinkComponentDir;
|
|
45
41
|
/**
|
|
46
42
|
* Removing existing links root (the package path) - to handle cases it was linked by package manager for example
|
|
@@ -50,12 +46,6 @@ export default class NodeModuleLinker {
|
|
|
50
46
|
* @param component
|
|
51
47
|
*/
|
|
52
48
|
_deleteExistingLinksRootIfSymlink(linkPath: string): any;
|
|
53
|
-
/**
|
|
54
|
-
* When the dists is outside the components directory, it doesn't have access to the node_modules of the component's
|
|
55
|
-
* root-dir. The solution is to go through the node_modules packages one by one and symlink them.
|
|
56
|
-
*/
|
|
57
|
-
_getSymlinkPackages(from: string, to: string, component: ConsumerComponent): Symlink[];
|
|
58
|
-
_getDependencyLink(parentRootDir: PathOsBasedRelative, bitId: BitId, rootDir: PathOsBasedRelative, bindingPrefix: string, component: ConsumerComponent): Symlink;
|
|
59
49
|
/**
|
|
60
50
|
* create package.json on node_modules/@bit/component-name/package.json with a property 'main'
|
|
61
51
|
* pointing to the component's main file.
|
|
@@ -75,4 +65,5 @@ export declare function linkToNodeModulesWithCodemod(workspace: Workspace, bitId
|
|
|
75
65
|
}>;
|
|
76
66
|
export declare function linkToNodeModulesByIds(workspace: Workspace, bitIds: BitId[], loadFromScope?: boolean): Promise<NodeModulesLinksResult[]>;
|
|
77
67
|
export declare function linkToNodeModulesByComponents(components: Component[], workspace: Workspace): Promise<NodeModulesLinksResult[]>;
|
|
68
|
+
export declare function removeLinksFromNodeModules(component: Component, workspace: Workspace, files: PathOsBasedAbsolute[]): Promise<void>;
|
|
78
69
|
export {};
|
|
@@ -35,12 +35,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.linkToNodeModulesByComponents = exports.linkToNodeModulesByIds = exports.linkToNodeModulesWithCodemod = void 0;
|
|
38
|
+
exports.removeLinksFromNodeModules = exports.linkToNodeModulesByComponents = exports.linkToNodeModulesByIds = exports.linkToNodeModulesWithCodemod = void 0;
|
|
39
39
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
40
|
-
const glob_1 = __importDefault(require("glob"));
|
|
41
40
|
const p_map_series_1 = __importDefault(require("p-map-series"));
|
|
42
41
|
const path = __importStar(require("path"));
|
|
43
|
-
const ramda_1 = __importDefault(require("ramda"));
|
|
44
42
|
const bit_roots_1 = require("@teambit/bit-roots");
|
|
45
43
|
const constants_1 = require("@teambit/legacy/dist/constants");
|
|
46
44
|
const package_json_file_1 = __importDefault(require("@teambit/legacy/dist/consumer/component/package-json-file"));
|
|
@@ -71,14 +69,11 @@ class NodeModuleLinker {
|
|
|
71
69
|
this.components = this.components.filter((component) => this.bitMap.getComponentIfExist(component.id._legacy));
|
|
72
70
|
const links = yield this.getLinks();
|
|
73
71
|
const linksResults = this.getLinksResults();
|
|
74
|
-
const workspacePath = this.
|
|
75
|
-
|
|
76
|
-
links.addBasePath(workspacePath);
|
|
72
|
+
const workspacePath = this.workspace.path;
|
|
73
|
+
links.addBasePath(workspacePath);
|
|
77
74
|
yield links.persistAllToFS();
|
|
78
75
|
yield ((_a = this.consumer) === null || _a === void 0 ? void 0 : _a.componentFsCache.deleteAllDependenciesDataCache());
|
|
79
|
-
|
|
80
|
-
yield (0, bit_roots_1.linkPkgsToBitRoots)(workspacePath, this.components.map((comp) => (0, component_id_to_package_name_1.default)(comp.state._consumer)));
|
|
81
|
-
}
|
|
76
|
+
yield (0, bit_roots_1.linkPkgsToBitRoots)(workspacePath, this.components.map((comp) => (0, component_id_to_package_name_1.default)(comp.state._consumer)));
|
|
82
77
|
return linksResults;
|
|
83
78
|
});
|
|
84
79
|
}
|
|
@@ -146,9 +141,6 @@ class NodeModuleLinker {
|
|
|
146
141
|
yield this.createPackageJson(component);
|
|
147
142
|
});
|
|
148
143
|
}
|
|
149
|
-
/**
|
|
150
|
-
* symlink the entire source directory into "src" in node-modules.
|
|
151
|
-
*/
|
|
152
144
|
symlinkComponentDir(component, linkPath) {
|
|
153
145
|
const componentMap = this.bitMap.getComponent(component.id._legacy);
|
|
154
146
|
const filesToBind = componentMap.getAllFilesPaths();
|
|
@@ -158,6 +150,7 @@ class NodeModuleLinker {
|
|
|
158
150
|
this.dataToPersist.addSymlink(symlink_1.default.makeInstance(fileWithRootDir, dest, component.id._legacy, true));
|
|
159
151
|
});
|
|
160
152
|
if (constants_1.IS_WINDOWS) {
|
|
153
|
+
// symlink the entire source directory into "_src" in node-modules.
|
|
161
154
|
this.dataToPersist.addSymlink(symlink_1.default.makeInstance(componentMap.rootDir, path.join(linkPath, constants_1.SOURCE_DIR_SYMLINK_TO_NM), component.id._legacy));
|
|
162
155
|
}
|
|
163
156
|
}
|
|
@@ -180,40 +173,6 @@ class NodeModuleLinker {
|
|
|
180
173
|
return undefined; // probably file does not exist
|
|
181
174
|
}
|
|
182
175
|
}
|
|
183
|
-
/**
|
|
184
|
-
* When the dists is outside the components directory, it doesn't have access to the node_modules of the component's
|
|
185
|
-
* root-dir. The solution is to go through the node_modules packages one by one and symlink them.
|
|
186
|
-
*/
|
|
187
|
-
_getSymlinkPackages(from, to, component) {
|
|
188
|
-
if (!this.consumer)
|
|
189
|
-
throw new Error('getSymlinkPackages expects the Consumer to be defined');
|
|
190
|
-
const dependenciesSavedAsComponents = component.dependenciesSavedAsComponents;
|
|
191
|
-
const fromNodeModules = path.join(from, 'node_modules');
|
|
192
|
-
const toNodeModules = path.join(to, 'node_modules');
|
|
193
|
-
logger_1.default.debug(`symlinkPackages for dists outside the component directory from ${fromNodeModules} to ${toNodeModules}`);
|
|
194
|
-
const unfilteredDirs = glob_1.default.sync('*', { cwd: fromNodeModules });
|
|
195
|
-
// when dependenciesSavedAsComponents the node_modules/@bit has real link files, we don't want to touch them
|
|
196
|
-
// otherwise, node_modules/@bit has packages as any other directory in node_modules
|
|
197
|
-
const dirsToFilter = dependenciesSavedAsComponents ? [this.consumer.config._bindingPrefix] : [];
|
|
198
|
-
const customResolvedData = component.dependencies.getCustomResolvedData();
|
|
199
|
-
if (!ramda_1.default.isEmpty(customResolvedData)) {
|
|
200
|
-
// filter out packages that are actually symlinks to dependencies
|
|
201
|
-
Object.keys(customResolvedData).forEach((importSource) => dirsToFilter.push(importSource.split('/')[0]));
|
|
202
|
-
}
|
|
203
|
-
const dirs = dirsToFilter.length ? unfilteredDirs.filter((dir) => !dirsToFilter.includes(dir)) : unfilteredDirs;
|
|
204
|
-
if (!dirs.length)
|
|
205
|
-
return [];
|
|
206
|
-
return dirs.map((dir) => {
|
|
207
|
-
const fromDir = path.join(fromNodeModules, dir);
|
|
208
|
-
const toDir = path.join(toNodeModules, dir);
|
|
209
|
-
return symlink_1.default.makeInstance(fromDir, toDir);
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
_getDependencyLink(parentRootDir, bitId, rootDir, bindingPrefix, component) {
|
|
213
|
-
const relativeDestPath = (0, component_node_modules_path_1.default)(Object.assign(Object.assign({}, component), { id: bitId, allowNonScope: true, bindingPrefix, isDependency: true }));
|
|
214
|
-
const destPathInsideParent = path.join(parentRootDir, relativeDestPath);
|
|
215
|
-
return symlink_1.default.makeInstance(rootDir, destPathInsideParent, bitId);
|
|
216
|
-
}
|
|
217
176
|
/**
|
|
218
177
|
* create package.json on node_modules/@bit/component-name/package.json with a property 'main'
|
|
219
178
|
* pointing to the component's main file.
|
|
@@ -294,4 +253,16 @@ function linkToNodeModulesByComponents(components, workspace) {
|
|
|
294
253
|
});
|
|
295
254
|
}
|
|
296
255
|
exports.linkToNodeModulesByComponents = linkToNodeModulesByComponents;
|
|
256
|
+
function removeLinksFromNodeModules(component, workspace, files) {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
258
|
+
const absoluteCompDir = workspace.componentDir(component.id); // os format
|
|
259
|
+
const relativeFilesInsideCompDir = files.map((file) => path.relative(absoluteCompDir, file));
|
|
260
|
+
const pkgDir = workspace.getComponentPackagePath(component);
|
|
261
|
+
const pathsToRemove = relativeFilesInsideCompDir.map((file) => path.join(pkgDir, file));
|
|
262
|
+
logger_1.default.debug(`removeLinksFromNodeModules, deleting the following files:
|
|
263
|
+
${pathsToRemove.join('\n')}`);
|
|
264
|
+
yield Promise.all(pathsToRemove.map((file) => fs_extra_1.default.remove(file)));
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
exports.removeLinksFromNodeModules = removeLinksFromNodeModules;
|
|
297
268
|
//# sourceMappingURL=node-modules-linker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-modules-linker.js","sourceRoot":"","sources":["../node-modules-linker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0B;AAC1B,
|
|
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,uGAAqH;AACrH,iFAAyD;AACzD,+HAAmG;AAEnG,kFAAkE;AAElE,yEAAoE;AAQpE;;;GAGG;AACH,MAAqB,gBAAgB;IAInC,YAAoB,UAAuB,EAAU,SAAoB;QAArD,eAAU,GAAV,UAAU,CAAa;QAAU,cAAS,GAAT,SAAS,CAAW;QACvE,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,IAAI,C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e,EAAE,IAAI,CAAC,CAAC,CAAC;QAC7F,MAAM,MAAM,GAAG,SAAS,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;QAC5D,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/index.ts
CHANGED
package/node-modules-linker.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
|
-
import glob from 'glob';
|
|
3
2
|
import pMapSeries from 'p-map-series';
|
|
4
3
|
import * as path from 'path';
|
|
5
|
-
import R from 'ramda';
|
|
6
4
|
import { linkPkgsToBitRoots } from '@teambit/bit-roots';
|
|
7
5
|
import { BitId } from '@teambit/legacy-bit-id';
|
|
8
6
|
import { IS_WINDOWS, PACKAGE_JSON, SOURCE_DIR_SYMLINK_TO_NM } from '@teambit/legacy/dist/constants';
|
|
@@ -14,7 +12,7 @@ import RemovePath from '@teambit/legacy/dist/consumer/component/sources/remove-p
|
|
|
14
12
|
import Consumer from '@teambit/legacy/dist/consumer/consumer';
|
|
15
13
|
import logger from '@teambit/legacy/dist/logger/logger';
|
|
16
14
|
import getNodeModulesPathOfComponent from '@teambit/legacy/dist/utils/bit/component-node-modules-path';
|
|
17
|
-
import { PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';
|
|
15
|
+
import { PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';
|
|
18
16
|
import { changeCodeFromRelativeToModulePaths } from '@teambit/legacy/dist/consumer/component-ops/codemod-components';
|
|
19
17
|
import Symlink from '@teambit/legacy/dist/links/symlink';
|
|
20
18
|
import componentIdToPackageName from '@teambit/legacy/dist/utils/bit/component-id-to-package-name';
|
|
@@ -46,16 +44,14 @@ export default class NodeModuleLinker {
|
|
|
46
44
|
this.components = this.components.filter((component) => this.bitMap.getComponentIfExist(component.id._legacy));
|
|
47
45
|
const links = await this.getLinks();
|
|
48
46
|
const linksResults = this.getLinksResults();
|
|
49
|
-
const workspacePath = this.
|
|
50
|
-
|
|
47
|
+
const workspacePath = this.workspace.path;
|
|
48
|
+
links.addBasePath(workspacePath);
|
|
51
49
|
await links.persistAllToFS();
|
|
52
50
|
await this.consumer?.componentFsCache.deleteAllDependenciesDataCache();
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
);
|
|
58
|
-
}
|
|
51
|
+
await linkPkgsToBitRoots(
|
|
52
|
+
workspacePath,
|
|
53
|
+
this.components.map((comp) => componentIdToPackageName(comp.state._consumer))
|
|
54
|
+
);
|
|
59
55
|
return linksResults;
|
|
60
56
|
}
|
|
61
57
|
async getLinks(): Promise<DataToPersist> {
|
|
@@ -121,9 +117,6 @@ export default class NodeModuleLinker {
|
|
|
121
117
|
await this.createPackageJson(component);
|
|
122
118
|
}
|
|
123
119
|
|
|
124
|
-
/**
|
|
125
|
-
* symlink the entire source directory into "src" in node-modules.
|
|
126
|
-
*/
|
|
127
120
|
private symlinkComponentDir(component: Component, linkPath: PathOsBasedRelative) {
|
|
128
121
|
const componentMap = this.bitMap.getComponent(component.id._legacy);
|
|
129
122
|
|
|
@@ -135,6 +128,7 @@ export default class NodeModuleLinker {
|
|
|
135
128
|
});
|
|
136
129
|
|
|
137
130
|
if (IS_WINDOWS) {
|
|
131
|
+
// symlink the entire source directory into "_src" in node-modules.
|
|
138
132
|
this.dataToPersist.addSymlink(
|
|
139
133
|
Symlink.makeInstance(
|
|
140
134
|
componentMap.rootDir as string,
|
|
@@ -164,54 +158,6 @@ export default class NodeModuleLinker {
|
|
|
164
158
|
}
|
|
165
159
|
}
|
|
166
160
|
|
|
167
|
-
/**
|
|
168
|
-
* When the dists is outside the components directory, it doesn't have access to the node_modules of the component's
|
|
169
|
-
* root-dir. The solution is to go through the node_modules packages one by one and symlink them.
|
|
170
|
-
*/
|
|
171
|
-
_getSymlinkPackages(from: string, to: string, component: ConsumerComponent): Symlink[] {
|
|
172
|
-
if (!this.consumer) throw new Error('getSymlinkPackages expects the Consumer to be defined');
|
|
173
|
-
const dependenciesSavedAsComponents = component.dependenciesSavedAsComponents;
|
|
174
|
-
const fromNodeModules = path.join(from, 'node_modules');
|
|
175
|
-
const toNodeModules = path.join(to, 'node_modules');
|
|
176
|
-
logger.debug(
|
|
177
|
-
`symlinkPackages for dists outside the component directory from ${fromNodeModules} to ${toNodeModules}`
|
|
178
|
-
);
|
|
179
|
-
const unfilteredDirs = glob.sync('*', { cwd: fromNodeModules });
|
|
180
|
-
// when dependenciesSavedAsComponents the node_modules/@bit has real link files, we don't want to touch them
|
|
181
|
-
// otherwise, node_modules/@bit has packages as any other directory in node_modules
|
|
182
|
-
const dirsToFilter = dependenciesSavedAsComponents ? [this.consumer.config._bindingPrefix] : [];
|
|
183
|
-
const customResolvedData = component.dependencies.getCustomResolvedData();
|
|
184
|
-
if (!R.isEmpty(customResolvedData)) {
|
|
185
|
-
// filter out packages that are actually symlinks to dependencies
|
|
186
|
-
Object.keys(customResolvedData).forEach((importSource) => dirsToFilter.push(importSource.split('/')[0]));
|
|
187
|
-
}
|
|
188
|
-
const dirs = dirsToFilter.length ? unfilteredDirs.filter((dir) => !dirsToFilter.includes(dir)) : unfilteredDirs;
|
|
189
|
-
if (!dirs.length) return [];
|
|
190
|
-
return dirs.map((dir) => {
|
|
191
|
-
const fromDir = path.join(fromNodeModules, dir);
|
|
192
|
-
const toDir = path.join(toNodeModules, dir);
|
|
193
|
-
return Symlink.makeInstance(fromDir, toDir);
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
_getDependencyLink(
|
|
198
|
-
parentRootDir: PathOsBasedRelative,
|
|
199
|
-
bitId: BitId,
|
|
200
|
-
rootDir: PathOsBasedRelative,
|
|
201
|
-
bindingPrefix: string,
|
|
202
|
-
component: ConsumerComponent
|
|
203
|
-
): Symlink {
|
|
204
|
-
const relativeDestPath = getNodeModulesPathOfComponent({
|
|
205
|
-
...component,
|
|
206
|
-
id: bitId,
|
|
207
|
-
allowNonScope: true,
|
|
208
|
-
bindingPrefix,
|
|
209
|
-
isDependency: true,
|
|
210
|
-
});
|
|
211
|
-
const destPathInsideParent = path.join(parentRootDir, relativeDestPath);
|
|
212
|
-
return Symlink.makeInstance(rootDir, destPathInsideParent, bitId);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
161
|
/**
|
|
216
162
|
* create package.json on node_modules/@bit/component-name/package.json with a property 'main'
|
|
217
163
|
* pointing to the component's main file.
|
|
@@ -295,3 +241,17 @@ export async function linkToNodeModulesByComponents(components: Component[], wor
|
|
|
295
241
|
const nodeModuleLinker = new NodeModuleLinker(components, workspace);
|
|
296
242
|
return nodeModuleLinker.link();
|
|
297
243
|
}
|
|
244
|
+
|
|
245
|
+
export async function removeLinksFromNodeModules(
|
|
246
|
+
component: Component,
|
|
247
|
+
workspace: Workspace,
|
|
248
|
+
files: PathOsBasedAbsolute[]
|
|
249
|
+
) {
|
|
250
|
+
const absoluteCompDir = workspace.componentDir(component.id); // os format
|
|
251
|
+
const relativeFilesInsideCompDir = files.map((file) => path.relative(absoluteCompDir, file));
|
|
252
|
+
const pkgDir = workspace.getComponentPackagePath(component);
|
|
253
|
+
const pathsToRemove = relativeFilesInsideCompDir.map((file) => path.join(pkgDir, file));
|
|
254
|
+
logger.debug(`removeLinksFromNodeModules, deleting the following files:
|
|
255
|
+
${pathsToRemove.join('\n')}`);
|
|
256
|
+
await Promise.all(pathsToRemove.map((file) => fs.remove(file)));
|
|
257
|
+
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/workspace.modules.node-modules-linker",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.57",
|
|
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.57"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"fs-extra": "10.0.0",
|
|
13
|
-
"glob": "7.1.6",
|
|
14
13
|
"p-map-series": "2.1.0",
|
|
15
|
-
"ramda": "0.27.1",
|
|
16
14
|
"@teambit/legacy-bit-id": "0.0.423",
|
|
17
|
-
"@teambit/bit-roots": "0.0.
|
|
15
|
+
"@teambit/bit-roots": "0.0.50",
|
|
18
16
|
"@teambit/component-package-version": "0.0.422"
|
|
19
17
|
},
|
|
20
18
|
"devDependencies": {
|
|
Binary file
|
|
File without changes
|