@teambit/workspace.modules.node-modules-linker 0.0.1 → 0.0.3
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 +3 -2
- package/dist/index.js.map +1 -1
- package/dist/node-modules-linker.d.ts +11 -9
- package/dist/node-modules-linker.js +17 -7
- package/dist/node-modules-linker.js.map +1 -1
- package/dist/{preview-1675308621306.js → preview-1675759172294.js} +0 -0
- package/index.ts +6 -1
- package/node-modules-linker.ts +27 -16
- package/package-tar/teambit-workspace.modules.node-modules-linker-0.0.3.tgz +0 -0
- package/package.json +4 -2
- package/package-tar/teambit-workspace.modules.node-modules-linker-0.0.1.tgz +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { NodeModulesLinksResult,
|
|
1
|
+
export { NodeModulesLinksResult, linkToNodeModulesByIds, linkToNodeModulesWithCodemod, linkToNodeModulesByComponents, } from './node-modules-linker';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.linkToNodeModulesWithCodemod = exports.
|
|
3
|
+
exports.linkToNodeModulesByComponents = exports.linkToNodeModulesWithCodemod = exports.linkToNodeModulesByIds = void 0;
|
|
4
4
|
var node_modules_linker_1 = require("./node-modules-linker");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
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
|
+
Object.defineProperty(exports, "linkToNodeModulesByComponents", { enumerable: true, get: function () { return node_modules_linker_1.linkToNodeModulesByComponents; } });
|
|
7
8
|
//# 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,6DAK+B;AAH7B,6HAAA,sBAAsB,OAAA;AACtB,mIAAA,4BAA4B,OAAA;AAC5B,oIAAA,6BAA6B,OAAA"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { BitId } from '@teambit/legacy-bit-id';
|
|
2
2
|
import BitMap from '@teambit/legacy/dist/consumer/bit-map/bit-map';
|
|
3
|
-
import
|
|
3
|
+
import ConsumerComponent from '@teambit/legacy/dist/consumer/component/consumer-component';
|
|
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
7
|
import { PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';
|
|
8
8
|
import Symlink from '@teambit/legacy/dist/links/symlink';
|
|
9
9
|
import { Workspace } from '@teambit/workspace';
|
|
10
|
+
import { Component } from '@teambit/component';
|
|
10
11
|
declare type LinkDetail = {
|
|
11
12
|
from: string;
|
|
12
13
|
to: string;
|
|
@@ -20,22 +21,22 @@ export declare type NodeModulesLinksResult = {
|
|
|
20
21
|
* for example, require('@bit/remote-scope.bar.foo)
|
|
21
22
|
*/
|
|
22
23
|
export default class NodeModuleLinker {
|
|
23
|
-
components:
|
|
24
|
+
components: ConsumerComponent[];
|
|
24
25
|
consumer: Consumer;
|
|
25
26
|
bitMap: BitMap;
|
|
26
27
|
dataToPersist: DataToPersist;
|
|
27
|
-
constructor(components:
|
|
28
|
+
constructor(components: ConsumerComponent[], consumer: Consumer);
|
|
28
29
|
link(): Promise<NodeModulesLinksResult[]>;
|
|
29
30
|
getLinks(): Promise<DataToPersist>;
|
|
30
31
|
getLinksResults(): NodeModulesLinksResult[];
|
|
31
|
-
_getDefaultScope(component?:
|
|
32
|
+
_getDefaultScope(component?: ConsumerComponent): string | undefined | null;
|
|
32
33
|
/**
|
|
33
34
|
* even when an authored component has rootDir, we can't just symlink that rootDir to
|
|
34
35
|
* node_modules/rootDir. it could work only when the main-file is index.js, not for other cases.
|
|
35
36
|
* node expects the module inside node_modules to have either package.json with valid "main"
|
|
36
37
|
* property or an index.js file. this main property can't be relative.
|
|
37
38
|
*/
|
|
38
|
-
_populateComponentsLinks(component:
|
|
39
|
+
_populateComponentsLinks(component: ConsumerComponent): Promise<void>;
|
|
39
40
|
/**
|
|
40
41
|
* symlink the entire source directory into "src" in node-modules.
|
|
41
42
|
*/
|
|
@@ -52,8 +53,8 @@ export default class NodeModuleLinker {
|
|
|
52
53
|
* When the dists is outside the components directory, it doesn't have access to the node_modules of the component's
|
|
53
54
|
* root-dir. The solution is to go through the node_modules packages one by one and symlink them.
|
|
54
55
|
*/
|
|
55
|
-
_getSymlinkPackages(from: string, to: string, component:
|
|
56
|
-
_getDependencyLink(parentRootDir: PathOsBasedRelative, bitId: BitId, rootDir: PathOsBasedRelative, bindingPrefix: string, component:
|
|
56
|
+
_getSymlinkPackages(from: string, to: string, component: ConsumerComponent): Symlink[];
|
|
57
|
+
_getDependencyLink(parentRootDir: PathOsBasedRelative, bitId: BitId, rootDir: PathOsBasedRelative, bindingPrefix: string, component: ConsumerComponent): Symlink;
|
|
57
58
|
/**
|
|
58
59
|
* create package.json on node_modules/@bit/component-name/package.json with a property 'main'
|
|
59
60
|
* pointing to the component's main file.
|
|
@@ -65,11 +66,12 @@ export default class NodeModuleLinker {
|
|
|
65
66
|
/**
|
|
66
67
|
* these are changes made by aspects
|
|
67
68
|
*/
|
|
68
|
-
_applyTransformers(component:
|
|
69
|
+
_applyTransformers(component: ConsumerComponent, packageJson: PackageJsonFile): Promise<void>;
|
|
69
70
|
}
|
|
70
71
|
export declare function linkToNodeModulesWithCodemod(workspace: Workspace, bitIds: BitId[], changeRelativeToModulePaths: boolean): Promise<{
|
|
71
72
|
linksResults: NodeModulesLinksResult[];
|
|
72
73
|
codemodResults: any;
|
|
73
74
|
}>;
|
|
74
|
-
export declare function
|
|
75
|
+
export declare function linkToNodeModulesByIds(workspace: Workspace, bitIds: BitId[], loadFromScope?: boolean): Promise<NodeModulesLinksResult[]>;
|
|
76
|
+
export declare function linkToNodeModulesByComponents(components: Component[], workspace: Workspace): Promise<NodeModulesLinksResult[]>;
|
|
75
77
|
export {};
|
|
@@ -35,7 +35,7 @@ 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.
|
|
38
|
+
exports.linkToNodeModulesByComponents = exports.linkToNodeModulesByIds = exports.linkToNodeModulesWithCodemod = void 0;
|
|
39
39
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
40
40
|
const glob_1 = __importDefault(require("glob"));
|
|
41
41
|
const p_map_series_1 = __importDefault(require("p-map-series"));
|
|
@@ -53,6 +53,7 @@ const component_node_modules_path_1 = __importDefault(require("@teambit/legacy/d
|
|
|
53
53
|
const bit_id_1 = require("@teambit/legacy/dist/bit-id");
|
|
54
54
|
const codemod_components_1 = require("@teambit/legacy/dist/consumer/component-ops/codemod-components");
|
|
55
55
|
const symlink_1 = __importDefault(require("@teambit/legacy/dist/links/symlink"));
|
|
56
|
+
const component_package_version_1 = require("@teambit/component-package-version");
|
|
56
57
|
/**
|
|
57
58
|
* link given components to node_modules, so it's possible to use absolute link instead of relative
|
|
58
59
|
* for example, require('@bit/remote-scope.bar.foo)
|
|
@@ -235,11 +236,13 @@ class NodeModuleLinker {
|
|
|
235
236
|
if (packageJson.packageJsonObject.version === 'latest') {
|
|
236
237
|
packageJson.packageJsonObject.version = '0.0.1-new';
|
|
237
238
|
}
|
|
239
|
+
else {
|
|
240
|
+
packageJson.packageJsonObject.version = (0, component_package_version_1.snapToSemver)(packageJson.packageJsonObject.version);
|
|
241
|
+
}
|
|
238
242
|
// packageJson.mergePropsFromExtensions(component);
|
|
239
243
|
// TODO: we need to have an hook here to get the transformer from the pkg extension
|
|
240
|
-
// delete the version
|
|
241
|
-
//
|
|
242
|
-
delete packageJson.packageJsonObject.version;
|
|
244
|
+
// don't delete the "version" prop, because in some scenarios, it's needed for the component to work properly.
|
|
245
|
+
// an example is when developing a vscode extension, vscode expects to have a valid package.json during the development.
|
|
243
246
|
this.dataToPersist.addFile(packageJson.toVinylFile());
|
|
244
247
|
});
|
|
245
248
|
}
|
|
@@ -259,12 +262,12 @@ function linkToNodeModulesWithCodemod(workspace, bitIds, changeRelativeToModuleP
|
|
|
259
262
|
if (changeRelativeToModulePaths) {
|
|
260
263
|
codemodResults = yield (0, codemod_components_1.changeCodeFromRelativeToModulePaths)(workspace.consumer, bitIds);
|
|
261
264
|
}
|
|
262
|
-
const linksResults = yield
|
|
265
|
+
const linksResults = yield linkToNodeModulesByIds(workspace, bitIds);
|
|
263
266
|
return { linksResults, codemodResults };
|
|
264
267
|
});
|
|
265
268
|
}
|
|
266
269
|
exports.linkToNodeModulesWithCodemod = linkToNodeModulesWithCodemod;
|
|
267
|
-
function
|
|
270
|
+
function linkToNodeModulesByIds(workspace, bitIds, loadFromScope = false) {
|
|
268
271
|
return __awaiter(this, void 0, void 0, function* () {
|
|
269
272
|
const componentsIds = bit_id_1.BitIds.fromArray(bitIds);
|
|
270
273
|
if (!componentsIds.length)
|
|
@@ -281,5 +284,12 @@ function linkToNodeModules(workspace, bitIds, loadFromScope = false) {
|
|
|
281
284
|
return nodeModuleLinker.link();
|
|
282
285
|
});
|
|
283
286
|
}
|
|
284
|
-
exports.
|
|
287
|
+
exports.linkToNodeModulesByIds = linkToNodeModulesByIds;
|
|
288
|
+
function linkToNodeModulesByComponents(components, workspace) {
|
|
289
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
+
const nodeModuleLinker = new NodeModuleLinker(components.map((c) => c.state._consumer), workspace.consumer);
|
|
291
|
+
return nodeModuleLinker.link();
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
exports.linkToNodeModulesByComponents = linkToNodeModulesByComponents;
|
|
285
295
|
//# 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,gDAAwB;AACxB,gEAAsC;AACtC,2CAA6B;AAC7B,kDAAsB;AAEtB,8DAAoG;AAGpG,8GAAqF;AAErF,kHAAwF;AACxF,+GAA0G;AAC1G,sHAA4F;AAC5F,8GAAqF;AAErF,gFAAwD;AACxD,sDAAmD;AACnD,6HAAuG;AAEvG,wDAAqD;AACrD,uGAAqH;AACrH,iFAAyD;
|
|
1
|
+
{"version":3,"file":"node-modules-linker.js","sourceRoot":"","sources":["../node-modules-linker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA0B;AAC1B,gDAAwB;AACxB,gEAAsC;AACtC,2CAA6B;AAC7B,kDAAsB;AAEtB,8DAAoG;AAGpG,8GAAqF;AAErF,kHAAwF;AACxF,+GAA0G;AAC1G,sHAA4F;AAC5F,8GAAqF;AAErF,gFAAwD;AACxD,sDAAmD;AACnD,6HAAuG;AAEvG,wDAAqD;AACrD,uGAAqH;AACrH,iFAAyD;AAEzD,kFAAkE;AASlE;;;GAGG;AACH,MAAqB,gBAAgB;IAKnC,YAAY,UAA+B,EAAE,QAAkB;QAC7D,IAAI,CAAC,UAAU,GAAG,yBAAc,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;QACjE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;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AQ,CAAC,CAAC;QAC9E,OAAO,gBAAgB,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;CAAA;AAjBD,wDAiBC;AAED,SAAsB,6BAA6B,CAAC,UAAuB,EAAE,SAAoB;;QAC/F,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,CAC3C,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,EACxC,SAAS,CAAC,QAAQ,CACnB,CAAC;QACF,OAAO,gBAAgB,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;CAAA;AAND,sEAMC"}
|
|
File without changes
|
package/index.ts
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
NodeModulesLinksResult,
|
|
3
|
+
linkToNodeModulesByIds,
|
|
4
|
+
linkToNodeModulesWithCodemod,
|
|
5
|
+
linkToNodeModulesByComponents,
|
|
6
|
+
} from './node-modules-linker';
|
package/node-modules-linker.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { IS_WINDOWS, PACKAGE_JSON, SOURCE_DIR_SYMLINK_TO_NM } from '@teambit/leg
|
|
|
8
8
|
import BitMap from '@teambit/legacy/dist/consumer/bit-map/bit-map';
|
|
9
9
|
import ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';
|
|
10
10
|
import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
|
|
11
|
-
import
|
|
11
|
+
import ConsumerComponent from '@teambit/legacy/dist/consumer/component/consumer-component';
|
|
12
12
|
import PackageJsonFile from '@teambit/legacy/dist/consumer/component/package-json-file';
|
|
13
13
|
import { PackageJsonTransformer } from '@teambit/legacy/dist/consumer/component/package-json-transformer';
|
|
14
14
|
import DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';
|
|
@@ -22,6 +22,8 @@ import { BitIds } from '@teambit/legacy/dist/bit-id';
|
|
|
22
22
|
import { changeCodeFromRelativeToModulePaths } from '@teambit/legacy/dist/consumer/component-ops/codemod-components';
|
|
23
23
|
import Symlink from '@teambit/legacy/dist/links/symlink';
|
|
24
24
|
import { Workspace } from '@teambit/workspace';
|
|
25
|
+
import { snapToSemver } from '@teambit/component-package-version';
|
|
26
|
+
import { Component } from '@teambit/component';
|
|
25
27
|
|
|
26
28
|
type LinkDetail = { from: string; to: string };
|
|
27
29
|
export type NodeModulesLinksResult = {
|
|
@@ -34,11 +36,11 @@ export type NodeModulesLinksResult = {
|
|
|
34
36
|
* for example, require('@bit/remote-scope.bar.foo)
|
|
35
37
|
*/
|
|
36
38
|
export default class NodeModuleLinker {
|
|
37
|
-
components:
|
|
39
|
+
components: ConsumerComponent[];
|
|
38
40
|
consumer: Consumer;
|
|
39
41
|
bitMap: BitMap; // preparation for the capsule, which is going to have only BitMap with no Consumer
|
|
40
42
|
dataToPersist: DataToPersist;
|
|
41
|
-
constructor(components:
|
|
43
|
+
constructor(components: ConsumerComponent[], consumer: Consumer) {
|
|
42
44
|
this.components = ComponentsList.getUniqueComponents(components);
|
|
43
45
|
this.consumer = consumer;
|
|
44
46
|
this.bitMap = consumer.bitMap;
|
|
@@ -89,7 +91,7 @@ export default class NodeModuleLinker {
|
|
|
89
91
|
return linksResults;
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
_getDefaultScope(component?:
|
|
94
|
+
_getDefaultScope(component?: ConsumerComponent): string | undefined | null {
|
|
93
95
|
if (component) {
|
|
94
96
|
return component.defaultScope;
|
|
95
97
|
}
|
|
@@ -102,7 +104,7 @@ export default class NodeModuleLinker {
|
|
|
102
104
|
* node expects the module inside node_modules to have either package.json with valid "main"
|
|
103
105
|
* property or an index.js file. this main property can't be relative.
|
|
104
106
|
*/
|
|
105
|
-
async _populateComponentsLinks(component:
|
|
107
|
+
async _populateComponentsLinks(component: ConsumerComponent): Promise<void> {
|
|
106
108
|
const componentId = component.id;
|
|
107
109
|
const linkPath: PathOsBasedRelative = getNodeModulesPathOfComponent({
|
|
108
110
|
bindingPrefix: component.bindingPrefix,
|
|
@@ -120,7 +122,7 @@ export default class NodeModuleLinker {
|
|
|
120
122
|
/**
|
|
121
123
|
* symlink the entire source directory into "src" in node-modules.
|
|
122
124
|
*/
|
|
123
|
-
private symlinkComponentDir(component:
|
|
125
|
+
private symlinkComponentDir(component: ConsumerComponent, linkPath: PathOsBasedRelative) {
|
|
124
126
|
const componentMap = component.componentMap as ComponentMap;
|
|
125
127
|
|
|
126
128
|
const filesToBind = componentMap.getAllFilesPaths();
|
|
@@ -164,7 +166,7 @@ export default class NodeModuleLinker {
|
|
|
164
166
|
* When the dists is outside the components directory, it doesn't have access to the node_modules of the component's
|
|
165
167
|
* root-dir. The solution is to go through the node_modules packages one by one and symlink them.
|
|
166
168
|
*/
|
|
167
|
-
_getSymlinkPackages(from: string, to: string, component:
|
|
169
|
+
_getSymlinkPackages(from: string, to: string, component: ConsumerComponent): Symlink[] {
|
|
168
170
|
if (!this.consumer) throw new Error('getSymlinkPackages expects the Consumer to be defined');
|
|
169
171
|
const dependenciesSavedAsComponents = component.dependenciesSavedAsComponents;
|
|
170
172
|
const fromNodeModules = path.join(from, 'node_modules');
|
|
@@ -195,7 +197,7 @@ export default class NodeModuleLinker {
|
|
|
195
197
|
bitId: BitId,
|
|
196
198
|
rootDir: PathOsBasedRelative,
|
|
197
199
|
bindingPrefix: string,
|
|
198
|
-
component:
|
|
200
|
+
component: ConsumerComponent
|
|
199
201
|
): Symlink {
|
|
200
202
|
const relativeDestPath = getNodeModulesPathOfComponent({
|
|
201
203
|
...component,
|
|
@@ -215,7 +217,7 @@ export default class NodeModuleLinker {
|
|
|
215
217
|
* Since an authored component doesn't have rootDir, it's impossible to symlink to the component directory.
|
|
216
218
|
* It makes it easier for Author to use absolute syntax between their own components.
|
|
217
219
|
*/
|
|
218
|
-
private async createPackageJson(component:
|
|
220
|
+
private async createPackageJson(component: ConsumerComponent) {
|
|
219
221
|
// @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
|
|
220
222
|
const hasPackageJsonAsComponentFile = component.files.some((file) => file.relative === PACKAGE_JSON);
|
|
221
223
|
if (hasPackageJsonAsComponentFile) return; // don't generate package.json on top of the user package.json
|
|
@@ -236,21 +238,22 @@ export default class NodeModuleLinker {
|
|
|
236
238
|
}
|
|
237
239
|
if (packageJson.packageJsonObject.version === 'latest') {
|
|
238
240
|
packageJson.packageJsonObject.version = '0.0.1-new';
|
|
241
|
+
} else {
|
|
242
|
+
packageJson.packageJsonObject.version = snapToSemver(packageJson.packageJsonObject.version);
|
|
239
243
|
}
|
|
240
|
-
|
|
241
244
|
// packageJson.mergePropsFromExtensions(component);
|
|
242
245
|
// TODO: we need to have an hook here to get the transformer from the pkg extension
|
|
243
246
|
|
|
244
|
-
// delete the version
|
|
245
|
-
//
|
|
246
|
-
|
|
247
|
+
// don't delete the "version" prop, because in some scenarios, it's needed for the component to work properly.
|
|
248
|
+
// an example is when developing a vscode extension, vscode expects to have a valid package.json during the development.
|
|
249
|
+
|
|
247
250
|
this.dataToPersist.addFile(packageJson.toVinylFile());
|
|
248
251
|
}
|
|
249
252
|
|
|
250
253
|
/**
|
|
251
254
|
* these are changes made by aspects
|
|
252
255
|
*/
|
|
253
|
-
async _applyTransformers(component:
|
|
256
|
+
async _applyTransformers(component: ConsumerComponent, packageJson: PackageJsonFile) {
|
|
254
257
|
return PackageJsonTransformer.applyTransformers(component, packageJson);
|
|
255
258
|
}
|
|
256
259
|
}
|
|
@@ -264,11 +267,11 @@ export async function linkToNodeModulesWithCodemod(
|
|
|
264
267
|
if (changeRelativeToModulePaths) {
|
|
265
268
|
codemodResults = await changeCodeFromRelativeToModulePaths(workspace.consumer, bitIds);
|
|
266
269
|
}
|
|
267
|
-
const linksResults = await
|
|
270
|
+
const linksResults = await linkToNodeModulesByIds(workspace, bitIds);
|
|
268
271
|
return { linksResults, codemodResults };
|
|
269
272
|
}
|
|
270
273
|
|
|
271
|
-
export async function
|
|
274
|
+
export async function linkToNodeModulesByIds(
|
|
272
275
|
workspace: Workspace,
|
|
273
276
|
bitIds: BitId[],
|
|
274
277
|
loadFromScope = false
|
|
@@ -286,3 +289,11 @@ export async function linkToNodeModules(
|
|
|
286
289
|
const nodeModuleLinker = new NodeModuleLinker(components, workspace.consumer);
|
|
287
290
|
return nodeModuleLinker.link();
|
|
288
291
|
}
|
|
292
|
+
|
|
293
|
+
export async function linkToNodeModulesByComponents(components: Component[], workspace: Workspace) {
|
|
294
|
+
const nodeModuleLinker = new NodeModuleLinker(
|
|
295
|
+
components.map((c) => c.state._consumer),
|
|
296
|
+
workspace.consumer
|
|
297
|
+
);
|
|
298
|
+
return nodeModuleLinker.link();
|
|
299
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/workspace.modules.node-modules-linker",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"homepage": "https://bit.dev/teambit/workspace/modules/node-modules-linker",
|
|
4
5
|
"main": "dist/index.js",
|
|
5
6
|
"componentId": {
|
|
6
7
|
"scope": "teambit.workspace",
|
|
7
8
|
"name": "modules/node-modules-linker",
|
|
8
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.3"
|
|
9
10
|
},
|
|
10
11
|
"dependencies": {
|
|
11
12
|
"fs-extra": "10.0.0",
|
|
12
13
|
"glob": "7.1.6",
|
|
13
14
|
"p-map-series": "2.1.0",
|
|
14
15
|
"ramda": "0.27.1",
|
|
16
|
+
"@teambit/component-package-version": "0.0.421",
|
|
15
17
|
"@teambit/legacy-bit-id": "0.0.421"
|
|
16
18
|
},
|
|
17
19
|
"devDependencies": {
|
|
Binary file
|