@teambit/workspace.modules.node-modules-linker 0.0.3 → 0.0.4
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 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/node-modules-linker.d.ts +4 -4
- package/dist/node-modules-linker.js +21 -25
- package/dist/node-modules-linker.js.map +1 -1
- package/dist/package-json-transformer.d.ts +12 -0
- package/dist/package-json-transformer.js +55 -0
- package/dist/package-json-transformer.js.map +1 -0
- package/dist/{preview-1675759172294.js → preview-1675822998765.js} +0 -0
- package/index.ts +2 -0
- package/node-modules-linker.ts +27 -37
- package/package-json-transformer.ts +49 -0
- package/package-tar/teambit-workspace.modules.node-modules-linker-0.0.4.tgz +0 -0
- package/package.json +2 -2
- package/package-tar/teambit-workspace.modules.node-modules-linker-0.0.3.tgz +0 -0
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.linkToNodeModulesByComponents = exports.linkToNodeModulesWithCodemod = exports.linkToNodeModulesByIds = void 0;
|
|
3
|
+
exports.PackageJsonTransformer = 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
|
+
var package_json_transformer_1 = require("./package-json-transformer");
|
|
9
|
+
Object.defineProperty(exports, "PackageJsonTransformer", { enumerable: true, get: function () { return package_json_transformer_1.PackageJsonTransformer; } });
|
|
8
10
|
//# 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,6DAK+B;AAH7B,6HAAA,sBAAsB,OAAA;AACtB,mIAAA,4BAA4B,OAAA;AAC5B,oIAAA,6BAA6B,OAAA"}
|
|
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;AAG/B,uEAAoE;AAA3D,kIAAA,sBAAsB,OAAA"}
|
|
@@ -21,11 +21,11 @@ export declare type NodeModulesLinksResult = {
|
|
|
21
21
|
* for example, require('@bit/remote-scope.bar.foo)
|
|
22
22
|
*/
|
|
23
23
|
export default class NodeModuleLinker {
|
|
24
|
-
components
|
|
24
|
+
private components;
|
|
25
25
|
consumer: Consumer;
|
|
26
26
|
bitMap: BitMap;
|
|
27
27
|
dataToPersist: DataToPersist;
|
|
28
|
-
constructor(components:
|
|
28
|
+
constructor(components: Component[], consumer: Consumer);
|
|
29
29
|
link(): Promise<NodeModulesLinksResult[]>;
|
|
30
30
|
getLinks(): Promise<DataToPersist>;
|
|
31
31
|
getLinksResults(): NodeModulesLinksResult[];
|
|
@@ -36,7 +36,7 @@ export default class NodeModuleLinker {
|
|
|
36
36
|
* node expects the module inside node_modules to have either package.json with valid "main"
|
|
37
37
|
* property or an index.js file. this main property can't be relative.
|
|
38
38
|
*/
|
|
39
|
-
_populateComponentsLinks(component:
|
|
39
|
+
_populateComponentsLinks(component: Component): Promise<void>;
|
|
40
40
|
/**
|
|
41
41
|
* symlink the entire source directory into "src" in node-modules.
|
|
42
42
|
*/
|
|
@@ -66,7 +66,7 @@ export default class NodeModuleLinker {
|
|
|
66
66
|
/**
|
|
67
67
|
* these are changes made by aspects
|
|
68
68
|
*/
|
|
69
|
-
_applyTransformers(component:
|
|
69
|
+
_applyTransformers(component: Component, packageJson: PackageJsonFile): Promise<void>;
|
|
70
70
|
}
|
|
71
71
|
export declare function linkToNodeModulesWithCodemod(workspace: Workspace, bitIds: BitId[], changeRelativeToModulePaths: boolean): Promise<{
|
|
72
72
|
linksResults: NodeModulesLinksResult[];
|
|
@@ -42,25 +42,23 @@ const p_map_series_1 = __importDefault(require("p-map-series"));
|
|
|
42
42
|
const path = __importStar(require("path"));
|
|
43
43
|
const ramda_1 = __importDefault(require("ramda"));
|
|
44
44
|
const constants_1 = require("@teambit/legacy/dist/constants");
|
|
45
|
-
const components_list_1 = __importDefault(require("@teambit/legacy/dist/consumer/component/components-list"));
|
|
46
45
|
const package_json_file_1 = __importDefault(require("@teambit/legacy/dist/consumer/component/package-json-file"));
|
|
47
|
-
const package_json_transformer_1 = require("@teambit/legacy/dist/consumer/component/package-json-transformer");
|
|
48
46
|
const data_to_persist_1 = __importDefault(require("@teambit/legacy/dist/consumer/component/sources/data-to-persist"));
|
|
49
47
|
const remove_path_1 = __importDefault(require("@teambit/legacy/dist/consumer/component/sources/remove-path"));
|
|
50
48
|
const logger_1 = __importDefault(require("@teambit/legacy/dist/logger/logger"));
|
|
51
49
|
const utils_1 = require("@teambit/legacy/dist/utils");
|
|
52
50
|
const component_node_modules_path_1 = __importDefault(require("@teambit/legacy/dist/utils/bit/component-node-modules-path"));
|
|
53
|
-
const bit_id_1 = require("@teambit/legacy/dist/bit-id");
|
|
54
51
|
const codemod_components_1 = require("@teambit/legacy/dist/consumer/component-ops/codemod-components");
|
|
55
52
|
const symlink_1 = __importDefault(require("@teambit/legacy/dist/links/symlink"));
|
|
56
53
|
const component_package_version_1 = require("@teambit/component-package-version");
|
|
54
|
+
const package_json_transformer_1 = require("./package-json-transformer");
|
|
57
55
|
/**
|
|
58
56
|
* link given components to node_modules, so it's possible to use absolute link instead of relative
|
|
59
57
|
* for example, require('@bit/remote-scope.bar.foo)
|
|
60
58
|
*/
|
|
61
59
|
class NodeModuleLinker {
|
|
62
60
|
constructor(components, consumer) {
|
|
63
|
-
this.components =
|
|
61
|
+
this.components = components;
|
|
64
62
|
this.consumer = consumer;
|
|
65
63
|
this.bitMap = consumer.bitMap;
|
|
66
64
|
this.dataToPersist = new data_to_persist_1.default();
|
|
@@ -84,8 +82,6 @@ class NodeModuleLinker {
|
|
|
84
82
|
yield (0, p_map_series_1.default)(this.components, (component) => {
|
|
85
83
|
const componentId = component.id.toString();
|
|
86
84
|
logger_1.default.debug(`linking component to node_modules: ${componentId}`);
|
|
87
|
-
const componentMap = this.bitMap.getComponent(component.id);
|
|
88
|
-
component.componentMap = componentMap;
|
|
89
85
|
return this._populateComponentsLinks(component);
|
|
90
86
|
});
|
|
91
87
|
return this.dataToPersist;
|
|
@@ -109,9 +105,9 @@ class NodeModuleLinker {
|
|
|
109
105
|
addLinkResult(symlink.componentId, symlink.src, symlink.dest);
|
|
110
106
|
});
|
|
111
107
|
this.components.forEach((component) => {
|
|
112
|
-
const existingLinkResult = getExistingLinkResult(component.id);
|
|
108
|
+
const existingLinkResult = getExistingLinkResult(component.id._legacy);
|
|
113
109
|
if (!existingLinkResult) {
|
|
114
|
-
linksResults.push({ id: component.id, bound: [] });
|
|
110
|
+
linksResults.push({ id: component.id._legacy, bound: [] });
|
|
115
111
|
}
|
|
116
112
|
});
|
|
117
113
|
return linksResults;
|
|
@@ -130,13 +126,14 @@ class NodeModuleLinker {
|
|
|
130
126
|
*/
|
|
131
127
|
_populateComponentsLinks(component) {
|
|
132
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
-
const
|
|
129
|
+
const legacyComponent = component.state._consumer;
|
|
130
|
+
const componentId = component.id._legacy;
|
|
134
131
|
const linkPath = (0, component_node_modules_path_1.default)({
|
|
135
|
-
bindingPrefix:
|
|
132
|
+
bindingPrefix: legacyComponent.bindingPrefix,
|
|
136
133
|
id: componentId,
|
|
137
134
|
allowNonScope: true,
|
|
138
|
-
defaultScope: this._getDefaultScope(
|
|
139
|
-
extensions:
|
|
135
|
+
defaultScope: this._getDefaultScope(legacyComponent),
|
|
136
|
+
extensions: legacyComponent.extensions,
|
|
140
137
|
});
|
|
141
138
|
this.symlinkComponentDir(component, linkPath);
|
|
142
139
|
this._deleteExistingLinksRootIfSymlink(linkPath);
|
|
@@ -147,15 +144,15 @@ class NodeModuleLinker {
|
|
|
147
144
|
* symlink the entire source directory into "src" in node-modules.
|
|
148
145
|
*/
|
|
149
146
|
symlinkComponentDir(component, linkPath) {
|
|
150
|
-
const componentMap = component.
|
|
147
|
+
const componentMap = this.bitMap.getComponent(component.id._legacy);
|
|
151
148
|
const filesToBind = componentMap.getAllFilesPaths();
|
|
152
149
|
filesToBind.forEach((file) => {
|
|
153
150
|
const fileWithRootDir = path.join(componentMap.rootDir, file);
|
|
154
151
|
const dest = path.join(linkPath, file);
|
|
155
|
-
this.dataToPersist.addSymlink(symlink_1.default.makeInstance(fileWithRootDir, dest, component.id, true));
|
|
152
|
+
this.dataToPersist.addSymlink(symlink_1.default.makeInstance(fileWithRootDir, dest, component.id._legacy, true));
|
|
156
153
|
});
|
|
157
154
|
if (constants_1.IS_WINDOWS) {
|
|
158
|
-
this.dataToPersist.addSymlink(symlink_1.default.makeInstance(componentMap.rootDir, path.join(linkPath, constants_1.SOURCE_DIR_SYMLINK_TO_NM), component.id));
|
|
155
|
+
this.dataToPersist.addSymlink(symlink_1.default.makeInstance(componentMap.rootDir, path.join(linkPath, constants_1.SOURCE_DIR_SYMLINK_TO_NM), component.id._legacy));
|
|
159
156
|
}
|
|
160
157
|
}
|
|
161
158
|
/**
|
|
@@ -220,18 +217,18 @@ class NodeModuleLinker {
|
|
|
220
217
|
*/
|
|
221
218
|
createPackageJson(component) {
|
|
222
219
|
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
-
|
|
224
|
-
const hasPackageJsonAsComponentFile =
|
|
220
|
+
const legacyComp = component.state._consumer;
|
|
221
|
+
const hasPackageJsonAsComponentFile = legacyComp.files.some((file) => file.relative === constants_1.PACKAGE_JSON);
|
|
225
222
|
if (hasPackageJsonAsComponentFile)
|
|
226
223
|
return; // don't generate package.json on top of the user package.json
|
|
227
|
-
const dest = path.join((0, component_node_modules_path_1.default)(Object.assign(Object.assign({},
|
|
228
|
-
const packageJson = package_json_file_1.default.createFromComponent(dest,
|
|
224
|
+
const dest = path.join((0, component_node_modules_path_1.default)(Object.assign(Object.assign({}, legacyComp), { id: legacyComp.id, allowNonScope: true })));
|
|
225
|
+
const packageJson = package_json_file_1.default.createFromComponent(dest, legacyComp, true, true);
|
|
229
226
|
yield this._applyTransformers(component, packageJson);
|
|
230
227
|
if (constants_1.IS_WINDOWS) {
|
|
231
228
|
// in the workspace, override the "types" and add the "src" prefix.
|
|
232
229
|
// otherwise, the navigation and auto-complete won't work on the IDE.
|
|
233
230
|
// this is for Windows only. For Linux, we use symlinks for the files.
|
|
234
|
-
packageJson.addOrUpdateProperty('types', `${constants_1.SOURCE_DIR_SYMLINK_TO_NM}/${
|
|
231
|
+
packageJson.addOrUpdateProperty('types', `${constants_1.SOURCE_DIR_SYMLINK_TO_NM}/${legacyComp.mainFile}`);
|
|
235
232
|
}
|
|
236
233
|
if (packageJson.packageJsonObject.version === 'latest') {
|
|
237
234
|
packageJson.packageJsonObject.version = '0.0.1-new';
|
|
@@ -269,15 +266,14 @@ function linkToNodeModulesWithCodemod(workspace, bitIds, changeRelativeToModuleP
|
|
|
269
266
|
exports.linkToNodeModulesWithCodemod = linkToNodeModulesWithCodemod;
|
|
270
267
|
function linkToNodeModulesByIds(workspace, bitIds, loadFromScope = false) {
|
|
271
268
|
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
-
const componentsIds =
|
|
269
|
+
const componentsIds = yield workspace.resolveMultipleComponentIds(bitIds);
|
|
273
270
|
if (!componentsIds.length)
|
|
274
271
|
return [];
|
|
275
272
|
const getComponents = () => __awaiter(this, void 0, void 0, function* () {
|
|
276
273
|
if (loadFromScope) {
|
|
277
|
-
return
|
|
274
|
+
return workspace.scope.getMany(componentsIds);
|
|
278
275
|
}
|
|
279
|
-
|
|
280
|
-
return components;
|
|
276
|
+
return workspace.getMany(componentsIds);
|
|
281
277
|
});
|
|
282
278
|
const components = yield getComponents();
|
|
283
279
|
const nodeModuleLinker = new NodeModuleLinker(components, workspace.consumer);
|
|
@@ -287,7 +283,7 @@ function linkToNodeModulesByIds(workspace, bitIds, loadFromScope = false) {
|
|
|
287
283
|
exports.linkToNodeModulesByIds = linkToNodeModulesByIds;
|
|
288
284
|
function linkToNodeModulesByComponents(components, workspace) {
|
|
289
285
|
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
-
const nodeModuleLinker = new NodeModuleLinker(components
|
|
286
|
+
const nodeModuleLinker = new NodeModuleLinker(components, workspace.consumer);
|
|
291
287
|
return nodeModuleLinker.link();
|
|
292
288
|
});
|
|
293
289
|
}
|
|
@@ -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,
|
|
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,kHAAwF;AACxF,sHAA4F;AAC5F,8GAAqF;AAErF,gFAAwD;AACxD,sDAAmD;AACnD,6HAAuG;AAEvG,uGAAqH;AACrH,iFAAyD;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AU,GAAG,MAAM,aAAa,EAAE,CAAC;QACzC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,UAAU,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC9E,OAAO,gBAAgB,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;CAAA;AAhBD,wDAgBC;AAED,SAAsB,6BAA6B,CAAC,UAAuB,EAAE,SAAoB;;QAC/F,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,UAAU,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC9E,OAAO,gBAAgB,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;CAAA;AAHD,sEAGC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import PackageJsonFile from '@teambit/legacy/dist/consumer/component/package-json-file';
|
|
2
|
+
import { Component } from '@teambit/component';
|
|
3
|
+
declare type PackageJsonTransformers = Function[];
|
|
4
|
+
export declare class PackageJsonTransformer {
|
|
5
|
+
static packageJsonTransformersRegistry: PackageJsonTransformers;
|
|
6
|
+
static registerPackageJsonTransformer(func: (component: Component, packageJsonObject: Record<string, any>) => Promise<Record<string, any>>): void;
|
|
7
|
+
/**
|
|
8
|
+
* these are changes made by aspects
|
|
9
|
+
*/
|
|
10
|
+
static applyTransformers(component: Component, packageJson: PackageJsonFile): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PackageJsonTransformer = void 0;
|
|
16
|
+
const p_map_series_1 = __importDefault(require("p-map-series"));
|
|
17
|
+
const parse_scope_1 = require("@teambit/legacy/dist/utils/bit/parse-scope");
|
|
18
|
+
const component_placeholders_1 = require("@teambit/legacy/dist/utils/bit/component-placeholders");
|
|
19
|
+
class PackageJsonTransformer {
|
|
20
|
+
static registerPackageJsonTransformer(func) {
|
|
21
|
+
this.packageJsonTransformersRegistry.push(func);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* these are changes made by aspects
|
|
25
|
+
*/
|
|
26
|
+
static applyTransformers(component, packageJson) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
let newPackageJsonObject = packageJson.packageJsonObject;
|
|
29
|
+
yield (0, p_map_series_1.default)(PackageJsonTransformer.packageJsonTransformersRegistry, (transformer) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
newPackageJsonObject = yield transformer(component, newPackageJsonObject);
|
|
31
|
+
}));
|
|
32
|
+
const scopeId = component.id.scope;
|
|
33
|
+
const { scope, owner } = (0, parse_scope_1.parseScope)(scopeId);
|
|
34
|
+
const name = component.id.fullName;
|
|
35
|
+
const contextForReplace = {
|
|
36
|
+
mainFile: component.state._consumer.mainFile,
|
|
37
|
+
name,
|
|
38
|
+
scope,
|
|
39
|
+
scopeId,
|
|
40
|
+
owner,
|
|
41
|
+
};
|
|
42
|
+
Object.keys(newPackageJsonObject).forEach((key) => {
|
|
43
|
+
let value = newPackageJsonObject[key];
|
|
44
|
+
if (typeof value === 'string') {
|
|
45
|
+
value = (0, component_placeholders_1.replacePlaceHolderForPackageValue)(contextForReplace, newPackageJsonObject[key]);
|
|
46
|
+
}
|
|
47
|
+
newPackageJsonObject[key] = value;
|
|
48
|
+
}, {});
|
|
49
|
+
packageJson.mergePackageJsonObject(newPackageJsonObject);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.PackageJsonTransformer = PackageJsonTransformer;
|
|
54
|
+
PackageJsonTransformer.packageJsonTransformersRegistry = [];
|
|
55
|
+
//# sourceMappingURL=package-json-transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-json-transformer.js","sourceRoot":"","sources":["../package-json-transformer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gEAAqC;AAErC,4EAAwE;AACxE,kGAA0G;AAK1G,MAAa,sBAAsB;IAEjC,MAAM,CAAC,8BAA8B,CACnC,IAAoG;QAEpG,IAAI,CAAC,+BAA+B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,MAAM,CAAO,iBAAiB,CAAC,SAAoB,EAAE,WAA4B;;YAC/E,IAAI,oBAAoB,GAAG,WAAW,CAAC,iBAAiB,CAAC;YAEzD,MAAM,IAAA,sBAAS,EAAC,sBAAsB,CAAC,+BAA+B,EAAE,CAAO,WAAW,EAAE,EAAE;gBAC5F,oBAAoB,GAAG,MAAM,WAAW,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAC;YAC5E,CAAC,CAAA,CAAC,CAAC;YAEH,MAAM,OAAO,GAAG,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC;YACnC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAA,wBAAU,EAAC,OAAO,CAAC,CAAC;YAC7C,MAAM,IAAI,GAAG,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC;YAEnC,MAAM,iBAAiB,GAAG;gBACxB,QAAQ,EAAE,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ;gBAC5C,IAAI;gBACJ,KAAK;gBACL,OAAO;gBACP,KAAK;aACN,CAAC;YAEF,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;gBAChD,IAAI,KAAK,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC;gBACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;oBAC7B,KAAK,GAAG,IAAA,0DAAiC,EAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC;iBACzF;gBACD,oBAAoB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACpC,CAAC,EAAE,EAAE,CAAC,CAAC;YAEP,WAAW,CAAC,sBAAsB,CAAC,oBAAoB,CAAC,CAAC;QAC3D,CAAC;KAAA;;AAvCH,wDAwCC;AAvCQ,sDAA+B,GAA4B,EAAE,CAAC"}
|
|
File without changes
|
package/index.ts
CHANGED
package/node-modules-linker.ts
CHANGED
|
@@ -6,11 +6,8 @@ import R from 'ramda';
|
|
|
6
6
|
import { BitId } from '@teambit/legacy-bit-id';
|
|
7
7
|
import { IS_WINDOWS, PACKAGE_JSON, SOURCE_DIR_SYMLINK_TO_NM } from '@teambit/legacy/dist/constants';
|
|
8
8
|
import BitMap from '@teambit/legacy/dist/consumer/bit-map/bit-map';
|
|
9
|
-
import ComponentMap from '@teambit/legacy/dist/consumer/bit-map/component-map';
|
|
10
|
-
import ComponentsList from '@teambit/legacy/dist/consumer/component/components-list';
|
|
11
9
|
import ConsumerComponent from '@teambit/legacy/dist/consumer/component/consumer-component';
|
|
12
10
|
import PackageJsonFile from '@teambit/legacy/dist/consumer/component/package-json-file';
|
|
13
|
-
import { PackageJsonTransformer } from '@teambit/legacy/dist/consumer/component/package-json-transformer';
|
|
14
11
|
import DataToPersist from '@teambit/legacy/dist/consumer/component/sources/data-to-persist';
|
|
15
12
|
import RemovePath from '@teambit/legacy/dist/consumer/component/sources/remove-path';
|
|
16
13
|
import Consumer from '@teambit/legacy/dist/consumer/consumer';
|
|
@@ -18,12 +15,12 @@ import logger from '@teambit/legacy/dist/logger/logger';
|
|
|
18
15
|
import { first } from '@teambit/legacy/dist/utils';
|
|
19
16
|
import getNodeModulesPathOfComponent from '@teambit/legacy/dist/utils/bit/component-node-modules-path';
|
|
20
17
|
import { PathOsBasedRelative } from '@teambit/legacy/dist/utils/path';
|
|
21
|
-
import { BitIds } from '@teambit/legacy/dist/bit-id';
|
|
22
18
|
import { changeCodeFromRelativeToModulePaths } from '@teambit/legacy/dist/consumer/component-ops/codemod-components';
|
|
23
19
|
import Symlink from '@teambit/legacy/dist/links/symlink';
|
|
24
20
|
import { Workspace } from '@teambit/workspace';
|
|
25
21
|
import { snapToSemver } from '@teambit/component-package-version';
|
|
26
22
|
import { Component } from '@teambit/component';
|
|
23
|
+
import { PackageJsonTransformer } from './package-json-transformer';
|
|
27
24
|
|
|
28
25
|
type LinkDetail = { from: string; to: string };
|
|
29
26
|
export type NodeModulesLinksResult = {
|
|
@@ -36,12 +33,10 @@ export type NodeModulesLinksResult = {
|
|
|
36
33
|
* for example, require('@bit/remote-scope.bar.foo)
|
|
37
34
|
*/
|
|
38
35
|
export default class NodeModuleLinker {
|
|
39
|
-
components: ConsumerComponent[];
|
|
40
36
|
consumer: Consumer;
|
|
41
37
|
bitMap: BitMap; // preparation for the capsule, which is going to have only BitMap with no Consumer
|
|
42
38
|
dataToPersist: DataToPersist;
|
|
43
|
-
constructor(components:
|
|
44
|
-
this.components = ComponentsList.getUniqueComponents(components);
|
|
39
|
+
constructor(private components: Component[], consumer: Consumer) {
|
|
45
40
|
this.consumer = consumer;
|
|
46
41
|
this.bitMap = consumer.bitMap;
|
|
47
42
|
this.dataToPersist = new DataToPersist();
|
|
@@ -60,8 +55,6 @@ export default class NodeModuleLinker {
|
|
|
60
55
|
await pMapSeries(this.components, (component) => {
|
|
61
56
|
const componentId = component.id.toString();
|
|
62
57
|
logger.debug(`linking component to node_modules: ${componentId}`);
|
|
63
|
-
const componentMap: ComponentMap = this.bitMap.getComponent(component.id);
|
|
64
|
-
component.componentMap = componentMap;
|
|
65
58
|
return this._populateComponentsLinks(component);
|
|
66
59
|
});
|
|
67
60
|
|
|
@@ -69,7 +62,7 @@ export default class NodeModuleLinker {
|
|
|
69
62
|
}
|
|
70
63
|
getLinksResults(): NodeModulesLinksResult[] {
|
|
71
64
|
const linksResults: NodeModulesLinksResult[] = [];
|
|
72
|
-
const getExistingLinkResult = (id) => linksResults.find((linkResult) => linkResult.id.isEqual(id));
|
|
65
|
+
const getExistingLinkResult = (id: BitId) => linksResults.find((linkResult) => linkResult.id.isEqual(id));
|
|
73
66
|
const addLinkResult = (id: BitId | null | undefined, from: string, to: string) => {
|
|
74
67
|
if (!id) return;
|
|
75
68
|
const existingLinkResult = getExistingLinkResult(id);
|
|
@@ -83,9 +76,9 @@ export default class NodeModuleLinker {
|
|
|
83
76
|
addLinkResult(symlink.componentId, symlink.src, symlink.dest);
|
|
84
77
|
});
|
|
85
78
|
this.components.forEach((component) => {
|
|
86
|
-
const existingLinkResult = getExistingLinkResult(component.id);
|
|
79
|
+
const existingLinkResult = getExistingLinkResult(component.id._legacy);
|
|
87
80
|
if (!existingLinkResult) {
|
|
88
|
-
linksResults.push({ id: component.id, bound: [] });
|
|
81
|
+
linksResults.push({ id: component.id._legacy, bound: [] });
|
|
89
82
|
}
|
|
90
83
|
});
|
|
91
84
|
return linksResults;
|
|
@@ -104,14 +97,15 @@ export default class NodeModuleLinker {
|
|
|
104
97
|
* node expects the module inside node_modules to have either package.json with valid "main"
|
|
105
98
|
* property or an index.js file. this main property can't be relative.
|
|
106
99
|
*/
|
|
107
|
-
async _populateComponentsLinks(component:
|
|
108
|
-
const
|
|
100
|
+
async _populateComponentsLinks(component: Component): Promise<void> {
|
|
101
|
+
const legacyComponent = component.state._consumer as ConsumerComponent;
|
|
102
|
+
const componentId = component.id._legacy;
|
|
109
103
|
const linkPath: PathOsBasedRelative = getNodeModulesPathOfComponent({
|
|
110
|
-
bindingPrefix:
|
|
104
|
+
bindingPrefix: legacyComponent.bindingPrefix,
|
|
111
105
|
id: componentId,
|
|
112
106
|
allowNonScope: true,
|
|
113
|
-
defaultScope: this._getDefaultScope(
|
|
114
|
-
extensions:
|
|
107
|
+
defaultScope: this._getDefaultScope(legacyComponent),
|
|
108
|
+
extensions: legacyComponent.extensions,
|
|
115
109
|
});
|
|
116
110
|
|
|
117
111
|
this.symlinkComponentDir(component, linkPath);
|
|
@@ -122,14 +116,14 @@ export default class NodeModuleLinker {
|
|
|
122
116
|
/**
|
|
123
117
|
* symlink the entire source directory into "src" in node-modules.
|
|
124
118
|
*/
|
|
125
|
-
private symlinkComponentDir(component:
|
|
126
|
-
const componentMap = component.
|
|
119
|
+
private symlinkComponentDir(component: Component, linkPath: PathOsBasedRelative) {
|
|
120
|
+
const componentMap = this.bitMap.getComponent(component.id._legacy);
|
|
127
121
|
|
|
128
122
|
const filesToBind = componentMap.getAllFilesPaths();
|
|
129
123
|
filesToBind.forEach((file) => {
|
|
130
124
|
const fileWithRootDir = path.join(componentMap.rootDir as string, file);
|
|
131
125
|
const dest = path.join(linkPath, file);
|
|
132
|
-
this.dataToPersist.addSymlink(Symlink.makeInstance(fileWithRootDir, dest, component.id, true));
|
|
126
|
+
this.dataToPersist.addSymlink(Symlink.makeInstance(fileWithRootDir, dest, component.id._legacy, true));
|
|
133
127
|
});
|
|
134
128
|
|
|
135
129
|
if (IS_WINDOWS) {
|
|
@@ -137,7 +131,7 @@ export default class NodeModuleLinker {
|
|
|
137
131
|
Symlink.makeInstance(
|
|
138
132
|
componentMap.rootDir as string,
|
|
139
133
|
path.join(linkPath, SOURCE_DIR_SYMLINK_TO_NM),
|
|
140
|
-
component.id
|
|
134
|
+
component.id._legacy
|
|
141
135
|
)
|
|
142
136
|
);
|
|
143
137
|
}
|
|
@@ -217,24 +211,24 @@ export default class NodeModuleLinker {
|
|
|
217
211
|
* Since an authored component doesn't have rootDir, it's impossible to symlink to the component directory.
|
|
218
212
|
* It makes it easier for Author to use absolute syntax between their own components.
|
|
219
213
|
*/
|
|
220
|
-
private async createPackageJson(component:
|
|
221
|
-
|
|
222
|
-
const hasPackageJsonAsComponentFile =
|
|
214
|
+
private async createPackageJson(component: Component) {
|
|
215
|
+
const legacyComp = component.state._consumer as ConsumerComponent;
|
|
216
|
+
const hasPackageJsonAsComponentFile = legacyComp.files.some((file) => file.relative === PACKAGE_JSON);
|
|
223
217
|
if (hasPackageJsonAsComponentFile) return; // don't generate package.json on top of the user package.json
|
|
224
218
|
const dest = path.join(
|
|
225
219
|
getNodeModulesPathOfComponent({
|
|
226
|
-
...
|
|
227
|
-
id:
|
|
220
|
+
...legacyComp,
|
|
221
|
+
id: legacyComp.id,
|
|
228
222
|
allowNonScope: true,
|
|
229
223
|
})
|
|
230
224
|
);
|
|
231
|
-
const packageJson = PackageJsonFile.createFromComponent(dest,
|
|
225
|
+
const packageJson = PackageJsonFile.createFromComponent(dest, legacyComp, true, true);
|
|
232
226
|
await this._applyTransformers(component, packageJson);
|
|
233
227
|
if (IS_WINDOWS) {
|
|
234
228
|
// in the workspace, override the "types" and add the "src" prefix.
|
|
235
229
|
// otherwise, the navigation and auto-complete won't work on the IDE.
|
|
236
230
|
// this is for Windows only. For Linux, we use symlinks for the files.
|
|
237
|
-
packageJson.addOrUpdateProperty('types', `${SOURCE_DIR_SYMLINK_TO_NM}/${
|
|
231
|
+
packageJson.addOrUpdateProperty('types', `${SOURCE_DIR_SYMLINK_TO_NM}/${legacyComp.mainFile}`);
|
|
238
232
|
}
|
|
239
233
|
if (packageJson.packageJsonObject.version === 'latest') {
|
|
240
234
|
packageJson.packageJsonObject.version = '0.0.1-new';
|
|
@@ -253,7 +247,7 @@ export default class NodeModuleLinker {
|
|
|
253
247
|
/**
|
|
254
248
|
* these are changes made by aspects
|
|
255
249
|
*/
|
|
256
|
-
async _applyTransformers(component:
|
|
250
|
+
async _applyTransformers(component: Component, packageJson: PackageJsonFile) {
|
|
257
251
|
return PackageJsonTransformer.applyTransformers(component, packageJson);
|
|
258
252
|
}
|
|
259
253
|
}
|
|
@@ -276,14 +270,13 @@ export async function linkToNodeModulesByIds(
|
|
|
276
270
|
bitIds: BitId[],
|
|
277
271
|
loadFromScope = false
|
|
278
272
|
): Promise<NodeModulesLinksResult[]> {
|
|
279
|
-
const componentsIds =
|
|
273
|
+
const componentsIds = await workspace.resolveMultipleComponentIds(bitIds);
|
|
280
274
|
if (!componentsIds.length) return [];
|
|
281
275
|
const getComponents = async () => {
|
|
282
276
|
if (loadFromScope) {
|
|
283
|
-
return
|
|
277
|
+
return workspace.scope.getMany(componentsIds);
|
|
284
278
|
}
|
|
285
|
-
|
|
286
|
-
return components;
|
|
279
|
+
return workspace.getMany(componentsIds);
|
|
287
280
|
};
|
|
288
281
|
const components = await getComponents();
|
|
289
282
|
const nodeModuleLinker = new NodeModuleLinker(components, workspace.consumer);
|
|
@@ -291,9 +284,6 @@ export async function linkToNodeModulesByIds(
|
|
|
291
284
|
}
|
|
292
285
|
|
|
293
286
|
export async function linkToNodeModulesByComponents(components: Component[], workspace: Workspace) {
|
|
294
|
-
const nodeModuleLinker = new NodeModuleLinker(
|
|
295
|
-
components.map((c) => c.state._consumer),
|
|
296
|
-
workspace.consumer
|
|
297
|
-
);
|
|
287
|
+
const nodeModuleLinker = new NodeModuleLinker(components, workspace.consumer);
|
|
298
288
|
return nodeModuleLinker.link();
|
|
299
289
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import mapSeries from 'p-map-series';
|
|
2
|
+
import PackageJsonFile from '@teambit/legacy/dist/consumer/component/package-json-file';
|
|
3
|
+
import { parseScope } from '@teambit/legacy/dist/utils/bit/parse-scope';
|
|
4
|
+
import { replacePlaceHolderForPackageValue } from '@teambit/legacy/dist/utils/bit/component-placeholders';
|
|
5
|
+
import { Component } from '@teambit/component';
|
|
6
|
+
|
|
7
|
+
type PackageJsonTransformers = Function[];
|
|
8
|
+
|
|
9
|
+
export class PackageJsonTransformer {
|
|
10
|
+
static packageJsonTransformersRegistry: PackageJsonTransformers = [];
|
|
11
|
+
static registerPackageJsonTransformer(
|
|
12
|
+
func: (component: Component, packageJsonObject: Record<string, any>) => Promise<Record<string, any>>
|
|
13
|
+
) {
|
|
14
|
+
this.packageJsonTransformersRegistry.push(func);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* these are changes made by aspects
|
|
19
|
+
*/
|
|
20
|
+
static async applyTransformers(component: Component, packageJson: PackageJsonFile) {
|
|
21
|
+
let newPackageJsonObject = packageJson.packageJsonObject;
|
|
22
|
+
|
|
23
|
+
await mapSeries(PackageJsonTransformer.packageJsonTransformersRegistry, async (transformer) => {
|
|
24
|
+
newPackageJsonObject = await transformer(component, newPackageJsonObject);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const scopeId = component.id.scope;
|
|
28
|
+
const { scope, owner } = parseScope(scopeId);
|
|
29
|
+
const name = component.id.fullName;
|
|
30
|
+
|
|
31
|
+
const contextForReplace = {
|
|
32
|
+
mainFile: component.state._consumer.mainFile,
|
|
33
|
+
name,
|
|
34
|
+
scope,
|
|
35
|
+
scopeId,
|
|
36
|
+
owner,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
Object.keys(newPackageJsonObject).forEach((key) => {
|
|
40
|
+
let value = newPackageJsonObject[key];
|
|
41
|
+
if (typeof value === 'string') {
|
|
42
|
+
value = replacePlaceHolderForPackageValue(contextForReplace, newPackageJsonObject[key]);
|
|
43
|
+
}
|
|
44
|
+
newPackageJsonObject[key] = value;
|
|
45
|
+
}, {});
|
|
46
|
+
|
|
47
|
+
packageJson.mergePackageJsonObject(newPackageJsonObject);
|
|
48
|
+
}
|
|
49
|
+
}
|
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.4",
|
|
4
4
|
"homepage": "https://bit.dev/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.4"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"fs-extra": "10.0.0",
|
|
Binary file
|