@teambit/workspace.modules.node-modules-linker 0.0.0-598ddc1cd9f365bfa60c2cb341589576d3477c6a
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/codemod-components.ts +141 -0
- package/dist/codemod-components.d.ts +8 -0
- package/dist/codemod-components.js +168 -0
- package/dist/codemod-components.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/node-modules-linker.d.ts +72 -0
- package/dist/node-modules-linker.js +363 -0
- package/dist/node-modules-linker.js.map +1 -0
- package/dist/package-json-transformer.d.ts +12 -0
- package/dist/package-json-transformer.js +86 -0
- package/dist/package-json-transformer.js.map +1 -0
- package/index.ts +11 -0
- package/node-modules-linker.ts +335 -0
- package/package-json-transformer.ts +67 -0
- package/package.json +58 -0
- package/types/asset.d.ts +41 -0
- package/types/style.d.ts +42 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.linkToNodeModulesByComponents = linkToNodeModulesByComponents;
|
|
8
|
+
exports.linkToNodeModulesByIds = linkToNodeModulesByIds;
|
|
9
|
+
exports.linkToNodeModulesWithCodemod = linkToNodeModulesWithCodemod;
|
|
10
|
+
exports.removeLinksFromNodeModules = removeLinksFromNodeModules;
|
|
11
|
+
function _fsExtra() {
|
|
12
|
+
const data = _interopRequireDefault(require("fs-extra"));
|
|
13
|
+
_fsExtra = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
function _pMapSeries() {
|
|
19
|
+
const data = _interopRequireDefault(require("p-map-series"));
|
|
20
|
+
_pMapSeries = function () {
|
|
21
|
+
return data;
|
|
22
|
+
};
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
function path() {
|
|
26
|
+
const data = _interopRequireWildcard(require("path"));
|
|
27
|
+
path = function () {
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
function _workspace() {
|
|
33
|
+
const data = require("@teambit/workspace.root-components");
|
|
34
|
+
_workspace = function () {
|
|
35
|
+
return data;
|
|
36
|
+
};
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
function _legacy() {
|
|
40
|
+
const data = require("@teambit/legacy.constants");
|
|
41
|
+
_legacy = function () {
|
|
42
|
+
return data;
|
|
43
|
+
};
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
function _component() {
|
|
47
|
+
const data = require("@teambit/component.sources");
|
|
48
|
+
_component = function () {
|
|
49
|
+
return data;
|
|
50
|
+
};
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
function _legacy2() {
|
|
54
|
+
const data = require("@teambit/legacy.logger");
|
|
55
|
+
_legacy2 = function () {
|
|
56
|
+
return data;
|
|
57
|
+
};
|
|
58
|
+
return data;
|
|
59
|
+
}
|
|
60
|
+
function _pkgModules() {
|
|
61
|
+
const data = require("@teambit/pkg.modules.component-package-name");
|
|
62
|
+
_pkgModules = function () {
|
|
63
|
+
return data;
|
|
64
|
+
};
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
67
|
+
function _componentPackageVersion() {
|
|
68
|
+
const data = require("@teambit/component-package-version");
|
|
69
|
+
_componentPackageVersion = function () {
|
|
70
|
+
return data;
|
|
71
|
+
};
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
function _packageJsonTransformer() {
|
|
75
|
+
const data = require("./package-json-transformer");
|
|
76
|
+
_packageJsonTransformer = function () {
|
|
77
|
+
return data;
|
|
78
|
+
};
|
|
79
|
+
return data;
|
|
80
|
+
}
|
|
81
|
+
function _codemodComponents() {
|
|
82
|
+
const data = require("./codemod-components");
|
|
83
|
+
_codemodComponents = function () {
|
|
84
|
+
return data;
|
|
85
|
+
};
|
|
86
|
+
return data;
|
|
87
|
+
}
|
|
88
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
89
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
90
|
+
/**
|
|
91
|
+
* link given components to node_modules, so it's possible to use absolute link instead of relative
|
|
92
|
+
* for example, require('@bit/remote-scope.bar.foo)
|
|
93
|
+
*/
|
|
94
|
+
class NodeModuleLinker {
|
|
95
|
+
// preparation for the capsule, which is going to have only BitMap with no Consumer
|
|
96
|
+
|
|
97
|
+
constructor(components, workspace) {
|
|
98
|
+
this.components = components;
|
|
99
|
+
this.workspace = workspace;
|
|
100
|
+
this.consumer = this.workspace.consumer;
|
|
101
|
+
this.bitMap = this.consumer.bitMap;
|
|
102
|
+
this.dataToPersist = new (_component().DataToPersist)();
|
|
103
|
+
this.existingLinks = [];
|
|
104
|
+
this.packageJsonCreated = false;
|
|
105
|
+
}
|
|
106
|
+
async link() {
|
|
107
|
+
this.components = this.components.filter(component => this.bitMap.getComponentIfExist(component.id));
|
|
108
|
+
const links = await this.getLinks();
|
|
109
|
+
const linksResults = this.getLinksResults();
|
|
110
|
+
if (!linksResults.length) {
|
|
111
|
+
// avoid clearing the cache if it ends up with no links. (e.g. happens when mistakenly generating links for a
|
|
112
|
+
// component not in the workspace)
|
|
113
|
+
// or when all links are already exist.
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
const workspacePath = this.workspace.path;
|
|
117
|
+
links.addBasePath(workspacePath);
|
|
118
|
+
await links.persistAllToFS();
|
|
119
|
+
// Only clear cache if new package.json of components were created
|
|
120
|
+
if (this.packageJsonCreated) {
|
|
121
|
+
await Promise.all(this.components.map(component => this.consumer?.componentFsCache.deleteDependenciesDataCache(component.id.toString())));
|
|
122
|
+
// if this cache is not cleared, then when asking workspace.get again to the same component, it returns it with
|
|
123
|
+
// component-issues like "MissingLinksFromNodeModulesToSrc" incorrectly.
|
|
124
|
+
this.workspace.clearAllComponentsCache();
|
|
125
|
+
}
|
|
126
|
+
await (0, _workspace().linkPkgsToRootComponents)({
|
|
127
|
+
rootComponentsPath: this.workspace.rootComponentsPath,
|
|
128
|
+
workspacePath
|
|
129
|
+
}, this.components.map(comp => (0, _pkgModules().componentIdToPackageName)(comp.state._consumer)));
|
|
130
|
+
return linksResults;
|
|
131
|
+
}
|
|
132
|
+
async getLinks() {
|
|
133
|
+
this.dataToPersist = new (_component().DataToPersist)();
|
|
134
|
+
await (0, _pMapSeries().default)(this.components, async component => {
|
|
135
|
+
const componentId = component.id.toString();
|
|
136
|
+
_legacy2().logger.debug(`linking component to node_modules: ${componentId}`);
|
|
137
|
+
await this._populateComponentsLinks(component);
|
|
138
|
+
});
|
|
139
|
+
return this.dataToPersist;
|
|
140
|
+
}
|
|
141
|
+
addLinkResult(linksResults, id, from, to, existsBefore) {
|
|
142
|
+
if (!id) return;
|
|
143
|
+
const existingLinkResult = linksResults.find(linkResult => linkResult.id.isEqual(id));
|
|
144
|
+
if (existingLinkResult) {
|
|
145
|
+
existingLinkResult.bound.push({
|
|
146
|
+
from,
|
|
147
|
+
to,
|
|
148
|
+
existsBefore
|
|
149
|
+
});
|
|
150
|
+
} else {
|
|
151
|
+
linksResults.push({
|
|
152
|
+
id,
|
|
153
|
+
bound: [{
|
|
154
|
+
from,
|
|
155
|
+
to,
|
|
156
|
+
existsBefore
|
|
157
|
+
}]
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
getLinksResults() {
|
|
162
|
+
const linksResults = [];
|
|
163
|
+
this.dataToPersist.symlinks.forEach(symlink => {
|
|
164
|
+
this.addLinkResult(linksResults, symlink.componentId, symlink.src, symlink.dest, false);
|
|
165
|
+
});
|
|
166
|
+
this.existingLinks.forEach(link => {
|
|
167
|
+
const componentId = link.id;
|
|
168
|
+
link.bound.forEach(bound => {
|
|
169
|
+
this.addLinkResult(linksResults, componentId, bound.from, bound.to, true);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
this.components.forEach(component => {
|
|
173
|
+
const existingLinkResult = linksResults.find(linkResult => linkResult.id.isEqual(component.id));
|
|
174
|
+
if (!existingLinkResult) {
|
|
175
|
+
linksResults.push({
|
|
176
|
+
id: component.id,
|
|
177
|
+
bound: []
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
return linksResults;
|
|
182
|
+
}
|
|
183
|
+
_getDefaultScope(component) {
|
|
184
|
+
if (component) {
|
|
185
|
+
return component.defaultScope;
|
|
186
|
+
}
|
|
187
|
+
return this.consumer ? this.consumer.config.defaultScope : null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* even when an authored component has rootDir, we can't just symlink that rootDir to
|
|
192
|
+
* node_modules/rootDir. it could work only when the main-file is index.js, not for other cases.
|
|
193
|
+
* node expects the module inside node_modules to have either package.json with valid "main"
|
|
194
|
+
* property or an index.js file. this main property can't be relative.
|
|
195
|
+
*/
|
|
196
|
+
async _populateComponentsLinks(component) {
|
|
197
|
+
const legacyComponent = component.state._consumer;
|
|
198
|
+
const linkPath = (0, _pkgModules().getNodeModulesPathOfComponent)(legacyComponent);
|
|
199
|
+
await this.symlinkComponentDir(component, linkPath);
|
|
200
|
+
this._deleteExistingLinksRootIfSymlink(linkPath);
|
|
201
|
+
await this.createPackageJson(component);
|
|
202
|
+
}
|
|
203
|
+
async symlinkComponentDir(component, linkPath) {
|
|
204
|
+
const componentMap = this.bitMap.getComponent(component.id);
|
|
205
|
+
const filesToBind = componentMap.getAllFilesPaths();
|
|
206
|
+
await Promise.all(filesToBind.map(async file => {
|
|
207
|
+
const fileWithRootDir = path().join(componentMap.rootDir, file);
|
|
208
|
+
const dest = path().join(linkPath, file);
|
|
209
|
+
let stat;
|
|
210
|
+
try {
|
|
211
|
+
stat = await _fsExtra().default.lstat(dest);
|
|
212
|
+
} catch {
|
|
213
|
+
// Ignore this error, it's probably because the file doesn't exist
|
|
214
|
+
}
|
|
215
|
+
if (stat && stat.isSymbolicLink()) {
|
|
216
|
+
this.addLinkResult(this.existingLinks, component.id, fileWithRootDir, dest, true);
|
|
217
|
+
} else {
|
|
218
|
+
this.dataToPersist.addSymlink(_component().Symlink.makeInstance(fileWithRootDir, dest, component.id, true));
|
|
219
|
+
}
|
|
220
|
+
}));
|
|
221
|
+
if (_legacy().IS_WINDOWS) {
|
|
222
|
+
// symlink the entire source directory into "_src" in node-modules.
|
|
223
|
+
this.dataToPersist.addSymlink(_component().Symlink.makeInstance(componentMap.rootDir, path().join(linkPath, _legacy().SOURCE_DIR_SYMLINK_TO_NM), component.id));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Removing existing links root (the package path) - to handle cases it was linked by package manager for example
|
|
229
|
+
* this makes sure we are not affecting other places (like package manager cache) we shouldn't touch
|
|
230
|
+
* If you have a case when this deletes something created by the package manager and it's not the desired behavior,
|
|
231
|
+
* do not delete this code, but make sure the package manger nest the installed version into it's dependent
|
|
232
|
+
* @param component
|
|
233
|
+
*/
|
|
234
|
+
_deleteExistingLinksRootIfSymlink(linkPath) {
|
|
235
|
+
try {
|
|
236
|
+
const stat = _fsExtra().default.lstatSync(linkPath);
|
|
237
|
+
if (stat.isSymbolicLink()) {
|
|
238
|
+
this.dataToPersist.removePath(new (_component().RemovePath)(linkPath));
|
|
239
|
+
}
|
|
240
|
+
return undefined;
|
|
241
|
+
} catch {
|
|
242
|
+
return undefined; // probably file does not exist
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* create package.json on node_modules/@bit/component-name/package.json with a property 'main'
|
|
248
|
+
* pointing to the component's main file.
|
|
249
|
+
* It is needed for Authored components only.
|
|
250
|
+
* Since an authored component doesn't have rootDir, it's impossible to symlink to the component directory.
|
|
251
|
+
* It makes it easier for Author to use absolute syntax between their own components.
|
|
252
|
+
*/
|
|
253
|
+
async createPackageJson(component) {
|
|
254
|
+
const legacyComp = component.state._consumer;
|
|
255
|
+
const hasPackageJsonAsComponentFile = legacyComp.files.some(file => file.relative === _legacy().PACKAGE_JSON);
|
|
256
|
+
if (hasPackageJsonAsComponentFile) return; // don't generate package.json on top of the user package.json
|
|
257
|
+
const dest = path().join((0, _pkgModules().getNodeModulesPathOfComponent)({
|
|
258
|
+
...legacyComp,
|
|
259
|
+
id: legacyComp.id
|
|
260
|
+
}));
|
|
261
|
+
const packageJsonExist = await _fsExtra().default.pathExists(path().join(dest, 'package.json'));
|
|
262
|
+
if (!packageJsonExist) {
|
|
263
|
+
this.packageJsonCreated = true;
|
|
264
|
+
}
|
|
265
|
+
const packageJson = _component().PackageJsonFile.createFromComponent(dest, legacyComp, true);
|
|
266
|
+
await this._applyTransformers(component, packageJson);
|
|
267
|
+
if (_legacy().IS_WINDOWS) {
|
|
268
|
+
// in the workspace, override the "types" and add the "src" prefix.
|
|
269
|
+
// otherwise, the navigation and auto-complete won't work on the IDE.
|
|
270
|
+
// this is for Windows only. For Linux, we use symlinks for the files.
|
|
271
|
+
packageJson.addOrUpdateProperty('types', `${_legacy().SOURCE_DIR_SYMLINK_TO_NM}/${legacyComp.mainFile}`);
|
|
272
|
+
}
|
|
273
|
+
if (packageJson.packageJsonObject.version === 'latest') {
|
|
274
|
+
packageJson.packageJsonObject.version = '0.0.1-new';
|
|
275
|
+
} else {
|
|
276
|
+
packageJson.packageJsonObject.version = (0, _componentPackageVersion().snapToSemver)(packageJson.packageJsonObject.version);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// indicate that this component exists locally and it is symlinked into the workspace. not a normal package.
|
|
280
|
+
packageJson.packageJsonObject._bit_local = true;
|
|
281
|
+
packageJson.packageJsonObject.source = component.mainFile.relative;
|
|
282
|
+
|
|
283
|
+
// This is a hack because we have in the workspace package.json types:index.ts
|
|
284
|
+
// but also exports for core aspects
|
|
285
|
+
// TS can't find the types
|
|
286
|
+
// in order to solve it we copy the types to exports.types
|
|
287
|
+
// this will be applied only to aspects to minimize how it affects users
|
|
288
|
+
const envsData = component.state.aspects.get('teambit.envs/envs');
|
|
289
|
+
const isAspect = envsData?.data.type === 'aspect';
|
|
290
|
+
if (isAspect && packageJson.packageJsonObject.types && packageJson.packageJsonObject.exports) {
|
|
291
|
+
const exports = packageJson.packageJsonObject.exports['.'] ? packageJson.packageJsonObject.exports['.'] : packageJson.packageJsonObject.exports;
|
|
292
|
+
if (!exports.types) {
|
|
293
|
+
const defaultModule = exports.default;
|
|
294
|
+
if (defaultModule) delete exports.default;
|
|
295
|
+
exports.types = `./${packageJson.packageJsonObject.types}`;
|
|
296
|
+
exports.default = defaultModule;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// packageJson.mergePropsFromExtensions(component);
|
|
301
|
+
// TODO: we need to have an hook here to get the transformer from the pkg extension
|
|
302
|
+
|
|
303
|
+
// don't delete the "version" prop, because in some scenarios, it's needed for the component to work properly.
|
|
304
|
+
// an example is when developing a vscode extension, vscode expects to have a valid package.json during the development.
|
|
305
|
+
|
|
306
|
+
this.dataToPersist.addFile(packageJson.toVinylFile());
|
|
307
|
+
const injectedDirs = await this.workspace.getInjectedDirs(component);
|
|
308
|
+
const src = path().join(dest, 'package.json');
|
|
309
|
+
for (const injectedDir of injectedDirs) {
|
|
310
|
+
this.dataToPersist.addSymlink(_component().Symlink.makeInstance(src, path().join(injectedDir, 'package.json')));
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* these are changes made by aspects
|
|
316
|
+
*/
|
|
317
|
+
async _applyTransformers(component, packageJson) {
|
|
318
|
+
return _packageJsonTransformer().PackageJsonTransformer.applyTransformers(component, packageJson);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
exports.default = NodeModuleLinker;
|
|
322
|
+
async function linkToNodeModulesWithCodemod(workspace, bitIds, changeRelativeToModulePaths) {
|
|
323
|
+
let codemodResults;
|
|
324
|
+
if (changeRelativeToModulePaths) {
|
|
325
|
+
codemodResults = await (0, _codemodComponents().changeCodeFromRelativeToModulePaths)(workspace, bitIds);
|
|
326
|
+
}
|
|
327
|
+
const linksResults = await linkToNodeModulesByIds(workspace, bitIds);
|
|
328
|
+
return {
|
|
329
|
+
linksResults,
|
|
330
|
+
codemodResults
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
async function linkToNodeModulesByIds(workspace, componentsIds, loadFromScope = false) {
|
|
334
|
+
if (!componentsIds.length) return [];
|
|
335
|
+
const getComponents = async () => {
|
|
336
|
+
if (loadFromScope) {
|
|
337
|
+
return workspace.scope.getMany(componentsIds);
|
|
338
|
+
}
|
|
339
|
+
return workspace.getMany(componentsIds, {
|
|
340
|
+
idsToNotLoadAsAspects: componentsIds.map(id => id.toString()),
|
|
341
|
+
loadSeedersAsAspects: false,
|
|
342
|
+
loadExtensions: false
|
|
343
|
+
});
|
|
344
|
+
};
|
|
345
|
+
const components = await getComponents();
|
|
346
|
+
const nodeModuleLinker = new NodeModuleLinker(components, workspace);
|
|
347
|
+
return nodeModuleLinker.link();
|
|
348
|
+
}
|
|
349
|
+
async function linkToNodeModulesByComponents(components, workspace) {
|
|
350
|
+
const nodeModuleLinker = new NodeModuleLinker(components, workspace);
|
|
351
|
+
return nodeModuleLinker.link();
|
|
352
|
+
}
|
|
353
|
+
async function removeLinksFromNodeModules(component, workspace, files) {
|
|
354
|
+
const absoluteCompDir = workspace.componentDir(component.id); // os format
|
|
355
|
+
const relativeFilesInsideCompDir = files.map(file => path().relative(absoluteCompDir, file));
|
|
356
|
+
const pkgDir = await workspace.getComponentPackagePath(component);
|
|
357
|
+
const pathsToRemove = relativeFilesInsideCompDir.map(file => path().join(pkgDir, file));
|
|
358
|
+
_legacy2().logger.debug(`removeLinksFromNodeModules, deleting the following files:
|
|
359
|
+
${pathsToRemove.join('\n')}`);
|
|
360
|
+
await Promise.all(pathsToRemove.map(file => _fsExtra().default.remove(file)));
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
//# sourceMappingURL=node-modules-linker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_fsExtra","data","_interopRequireDefault","require","_pMapSeries","path","_interopRequireWildcard","_workspace","_legacy","_component","_legacy2","_pkgModules","_componentPackageVersion","_packageJsonTransformer","_codemodComponents","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","NodeModuleLinker","constructor","components","workspace","consumer","bitMap","dataToPersist","DataToPersist","existingLinks","packageJsonCreated","link","filter","component","getComponentIfExist","id","links","getLinks","linksResults","getLinksResults","length","workspacePath","addBasePath","persistAllToFS","Promise","all","map","componentFsCache","deleteDependenciesDataCache","toString","clearAllComponentsCache","linkPkgsToRootComponents","rootComponentsPath","comp","componentIdToPackageName","state","_consumer","pMapSeries","componentId","logger","debug","_populateComponentsLinks","addLinkResult","from","to","existsBefore","existingLinkResult","find","linkResult","isEqual","bound","push","symlinks","forEach","symlink","src","dest","_getDefaultScope","defaultScope","config","legacyComponent","linkPath","getNodeModulesPathOfComponent","symlinkComponentDir","_deleteExistingLinksRootIfSymlink","createPackageJson","componentMap","getComponent","filesToBind","getAllFilesPaths","file","fileWithRootDir","join","rootDir","stat","fs","lstat","isSymbolicLink","addSymlink","Symlink","makeInstance","IS_WINDOWS","SOURCE_DIR_SYMLINK_TO_NM","lstatSync","removePath","RemovePath","undefined","legacyComp","hasPackageJsonAsComponentFile","files","some","relative","PACKAGE_JSON","packageJsonExist","pathExists","packageJson","PackageJsonFile","createFromComponent","_applyTransformers","addOrUpdateProperty","mainFile","packageJsonObject","version","snapToSemver","_bit_local","source","envsData","aspects","isAspect","type","types","exports","defaultModule","addFile","toVinylFile","injectedDirs","getInjectedDirs","injectedDir","PackageJsonTransformer","applyTransformers","linkToNodeModulesWithCodemod","bitIds","changeRelativeToModulePaths","codemodResults","changeCodeFromRelativeToModulePaths","linkToNodeModulesByIds","componentsIds","loadFromScope","getComponents","scope","getMany","idsToNotLoadAsAspects","loadSeedersAsAspects","loadExtensions","nodeModuleLinker","linkToNodeModulesByComponents","removeLinksFromNodeModules","absoluteCompDir","componentDir","relativeFilesInsideCompDir","pkgDir","getComponentPackagePath","pathsToRemove","remove"],"sources":["node-modules-linker.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport pMapSeries from 'p-map-series';\nimport * as path from 'path';\nimport { linkPkgsToRootComponents } from '@teambit/workspace.root-components';\nimport { ComponentID } from '@teambit/component-id';\nimport { IS_WINDOWS, PACKAGE_JSON, SOURCE_DIR_SYMLINK_TO_NM } from '@teambit/legacy.constants';\nimport { BitMap } from '@teambit/legacy.bit-map';\nimport { ConsumerComponent } from '@teambit/legacy.consumer-component';\nimport { PackageJsonFile, DataToPersist, RemovePath, Symlink } from '@teambit/component.sources';\nimport { Consumer } from '@teambit/legacy.consumer';\nimport { logger } from '@teambit/legacy.logger';\nimport { PathOsBasedAbsolute, PathOsBasedRelative } from '@teambit/toolbox.path.path';\nimport { componentIdToPackageName, getNodeModulesPathOfComponent } from '@teambit/pkg.modules.component-package-name';\nimport { Workspace } from '@teambit/workspace';\nimport { snapToSemver } from '@teambit/component-package-version';\nimport { Component } from '@teambit/component';\nimport { PackageJsonTransformer } from './package-json-transformer';\nimport { changeCodeFromRelativeToModulePaths } from './codemod-components';\n\ntype LinkDetail = { from: string; to: string; existsBefore: boolean };\nexport type NodeModulesLinksResult = {\n id: ComponentID;\n bound: LinkDetail[];\n};\n\n/**\n * link given components to node_modules, so it's possible to use absolute link instead of relative\n * for example, require('@bit/remote-scope.bar.foo)\n */\nexport default class NodeModuleLinker {\n consumer: Consumer;\n bitMap: BitMap; // preparation for the capsule, which is going to have only BitMap with no Consumer\n dataToPersist: DataToPersist;\n existingLinks: NodeModulesLinksResult[];\n packageJsonCreated: boolean;\n\n constructor(\n private components: Component[],\n private workspace: Workspace\n ) {\n this.consumer = this.workspace.consumer;\n this.bitMap = this.consumer.bitMap;\n this.dataToPersist = new DataToPersist();\n this.existingLinks = [];\n this.packageJsonCreated = false;\n }\n async link(): Promise<NodeModulesLinksResult[]> {\n this.components = this.components.filter((component) => this.bitMap.getComponentIfExist(component.id));\n const links = await this.getLinks();\n\n const linksResults = this.getLinksResults();\n if (!linksResults.length) {\n // avoid clearing the cache if it ends up with no links. (e.g. happens when mistakenly generating links for a\n // component not in the workspace)\n // or when all links are already exist.\n return [];\n }\n const workspacePath = this.workspace.path;\n links.addBasePath(workspacePath);\n await links.persistAllToFS();\n // Only clear cache if new package.json of components were created\n if (this.packageJsonCreated) {\n await Promise.all(\n this.components.map((component) =>\n this.consumer?.componentFsCache.deleteDependenciesDataCache(component.id.toString())\n )\n );\n // if this cache is not cleared, then when asking workspace.get again to the same component, it returns it with\n // component-issues like \"MissingLinksFromNodeModulesToSrc\" incorrectly.\n this.workspace.clearAllComponentsCache();\n }\n\n await linkPkgsToRootComponents(\n {\n rootComponentsPath: this.workspace.rootComponentsPath,\n workspacePath,\n },\n this.components.map((comp) => componentIdToPackageName(comp.state._consumer))\n );\n return linksResults;\n }\n async getLinks(): Promise<DataToPersist> {\n this.dataToPersist = new DataToPersist();\n await pMapSeries(this.components, async (component) => {\n const componentId = component.id.toString();\n logger.debug(`linking component to node_modules: ${componentId}`);\n await this._populateComponentsLinks(component);\n });\n\n return this.dataToPersist;\n }\n private addLinkResult(\n linksResults: NodeModulesLinksResult[],\n id: ComponentID | null | undefined,\n from: string,\n to: string,\n existsBefore: boolean\n ) {\n if (!id) return;\n const existingLinkResult = linksResults.find((linkResult) => linkResult.id.isEqual(id));\n if (existingLinkResult) {\n existingLinkResult.bound.push({ from, to, existsBefore });\n } else {\n linksResults.push({ id, bound: [{ from, to, existsBefore }] });\n }\n }\n\n getLinksResults(): NodeModulesLinksResult[] {\n const linksResults: NodeModulesLinksResult[] = [];\n this.dataToPersist.symlinks.forEach((symlink: Symlink) => {\n this.addLinkResult(linksResults, symlink.componentId, symlink.src, symlink.dest, false);\n });\n this.existingLinks.forEach((link: NodeModulesLinksResult) => {\n const componentId = link.id;\n link.bound.forEach((bound) => {\n this.addLinkResult(linksResults, componentId, bound.from, bound.to, true);\n });\n });\n this.components.forEach((component) => {\n const existingLinkResult = linksResults.find((linkResult) => linkResult.id.isEqual(component.id));\n if (!existingLinkResult) {\n linksResults.push({ id: component.id, bound: [] });\n }\n });\n return linksResults;\n }\n\n _getDefaultScope(component?: ConsumerComponent): string | undefined | null {\n if (component) {\n return component.defaultScope;\n }\n return this.consumer ? this.consumer.config.defaultScope : null;\n }\n\n /**\n * even when an authored component has rootDir, we can't just symlink that rootDir to\n * node_modules/rootDir. it could work only when the main-file is index.js, not for other cases.\n * node expects the module inside node_modules to have either package.json with valid \"main\"\n * property or an index.js file. this main property can't be relative.\n */\n async _populateComponentsLinks(component: Component): Promise<void> {\n const legacyComponent = component.state._consumer as ConsumerComponent;\n const linkPath: PathOsBasedRelative = getNodeModulesPathOfComponent(legacyComponent);\n\n await this.symlinkComponentDir(component, linkPath);\n this._deleteExistingLinksRootIfSymlink(linkPath);\n await this.createPackageJson(component);\n }\n\n private async symlinkComponentDir(component: Component, linkPath: PathOsBasedRelative) {\n const componentMap = this.bitMap.getComponent(component.id);\n\n const filesToBind = componentMap.getAllFilesPaths();\n await Promise.all(\n filesToBind.map(async (file) => {\n const fileWithRootDir = path.join(componentMap.rootDir as string, file);\n const dest = path.join(linkPath, file);\n let stat;\n try {\n stat = await fs.lstat(dest);\n } catch {\n // Ignore this error, it's probably because the file doesn't exist\n }\n if (stat && stat.isSymbolicLink()) {\n this.addLinkResult(this.existingLinks, component.id, fileWithRootDir, dest, true);\n } else {\n this.dataToPersist.addSymlink(Symlink.makeInstance(fileWithRootDir, dest, component.id, true));\n }\n })\n );\n\n if (IS_WINDOWS) {\n // symlink the entire source directory into \"_src\" in node-modules.\n this.dataToPersist.addSymlink(\n Symlink.makeInstance(\n componentMap.rootDir as string,\n path.join(linkPath, SOURCE_DIR_SYMLINK_TO_NM),\n component.id\n )\n );\n }\n }\n\n /**\n * Removing existing links root (the package path) - to handle cases it was linked by package manager for example\n * this makes sure we are not affecting other places (like package manager cache) we shouldn't touch\n * If you have a case when this deletes something created by the package manager and it's not the desired behavior,\n * do not delete this code, but make sure the package manger nest the installed version into it's dependent\n * @param component\n */\n _deleteExistingLinksRootIfSymlink(linkPath: string) {\n try {\n const stat = fs.lstatSync(linkPath);\n if (stat.isSymbolicLink()) {\n this.dataToPersist.removePath(new RemovePath(linkPath));\n }\n return undefined;\n } catch {\n return undefined; // probably file does not exist\n }\n }\n\n /**\n * create package.json on node_modules/@bit/component-name/package.json with a property 'main'\n * pointing to the component's main file.\n * It is needed for Authored components only.\n * Since an authored component doesn't have rootDir, it's impossible to symlink to the component directory.\n * It makes it easier for Author to use absolute syntax between their own components.\n */\n private async createPackageJson(component: Component) {\n const legacyComp = component.state._consumer as ConsumerComponent;\n const hasPackageJsonAsComponentFile = legacyComp.files.some((file) => file.relative === PACKAGE_JSON);\n if (hasPackageJsonAsComponentFile) return; // don't generate package.json on top of the user package.json\n const dest = path.join(\n getNodeModulesPathOfComponent({\n ...legacyComp,\n id: legacyComp.id,\n })\n );\n const packageJsonExist = await fs.pathExists(path.join(dest, 'package.json'));\n if (!packageJsonExist) {\n this.packageJsonCreated = true;\n }\n\n const packageJson = PackageJsonFile.createFromComponent(dest, legacyComp, true);\n await this._applyTransformers(component, packageJson);\n if (IS_WINDOWS) {\n // in the workspace, override the \"types\" and add the \"src\" prefix.\n // otherwise, the navigation and auto-complete won't work on the IDE.\n // this is for Windows only. For Linux, we use symlinks for the files.\n packageJson.addOrUpdateProperty('types', `${SOURCE_DIR_SYMLINK_TO_NM}/${legacyComp.mainFile}`);\n }\n if (packageJson.packageJsonObject.version === 'latest') {\n packageJson.packageJsonObject.version = '0.0.1-new';\n } else {\n packageJson.packageJsonObject.version = snapToSemver(packageJson.packageJsonObject.version);\n }\n\n // indicate that this component exists locally and it is symlinked into the workspace. not a normal package.\n packageJson.packageJsonObject._bit_local = true;\n packageJson.packageJsonObject.source = component.mainFile.relative;\n\n // This is a hack because we have in the workspace package.json types:index.ts\n // but also exports for core aspects\n // TS can't find the types\n // in order to solve it we copy the types to exports.types\n // this will be applied only to aspects to minimize how it affects users\n const envsData = component.state.aspects.get('teambit.envs/envs');\n const isAspect = envsData?.data.type === 'aspect';\n if (isAspect && packageJson.packageJsonObject.types && packageJson.packageJsonObject.exports) {\n const exports = packageJson.packageJsonObject.exports['.']\n ? packageJson.packageJsonObject.exports['.']\n : packageJson.packageJsonObject.exports;\n if (!exports.types) {\n const defaultModule = exports.default;\n if (defaultModule) delete exports.default;\n exports.types = `./${packageJson.packageJsonObject.types}`;\n exports.default = defaultModule;\n }\n }\n\n // packageJson.mergePropsFromExtensions(component);\n // TODO: we need to have an hook here to get the transformer from the pkg extension\n\n // don't delete the \"version\" prop, because in some scenarios, it's needed for the component to work properly.\n // an example is when developing a vscode extension, vscode expects to have a valid package.json during the development.\n\n this.dataToPersist.addFile(packageJson.toVinylFile());\n const injectedDirs = await this.workspace.getInjectedDirs(component);\n const src = path.join(dest, 'package.json');\n for (const injectedDir of injectedDirs) {\n this.dataToPersist.addSymlink(Symlink.makeInstance(src, path.join(injectedDir, 'package.json')));\n }\n }\n\n /**\n * these are changes made by aspects\n */\n async _applyTransformers(component: Component, packageJson: PackageJsonFile) {\n return PackageJsonTransformer.applyTransformers(component, packageJson);\n }\n}\n\nexport async function linkToNodeModulesWithCodemod(\n workspace: Workspace,\n bitIds: ComponentID[],\n changeRelativeToModulePaths: boolean\n) {\n let codemodResults;\n if (changeRelativeToModulePaths) {\n codemodResults = await changeCodeFromRelativeToModulePaths(workspace, bitIds);\n }\n const linksResults = await linkToNodeModulesByIds(workspace, bitIds);\n return { linksResults, codemodResults };\n}\n\nexport async function linkToNodeModulesByIds(\n workspace: Workspace,\n componentsIds: ComponentID[],\n loadFromScope = false\n): Promise<NodeModulesLinksResult[]> {\n if (!componentsIds.length) return [];\n const getComponents = async () => {\n if (loadFromScope) {\n return workspace.scope.getMany(componentsIds);\n }\n return workspace.getMany(componentsIds, {\n idsToNotLoadAsAspects: componentsIds.map((id) => id.toString()),\n loadSeedersAsAspects: false,\n loadExtensions: false,\n });\n };\n const components = await getComponents();\n const nodeModuleLinker = new NodeModuleLinker(components, workspace);\n return nodeModuleLinker.link();\n}\n\nexport async function linkToNodeModulesByComponents(components: Component[], workspace: Workspace) {\n const nodeModuleLinker = new NodeModuleLinker(components, workspace);\n return nodeModuleLinker.link();\n}\n\nexport async function removeLinksFromNodeModules(\n component: Component,\n workspace: Workspace,\n files: PathOsBasedAbsolute[]\n) {\n const absoluteCompDir = workspace.componentDir(component.id); // os format\n const relativeFilesInsideCompDir = files.map((file) => path.relative(absoluteCompDir, file));\n const pkgDir = await workspace.getComponentPackagePath(component);\n const pathsToRemove = relativeFilesInsideCompDir.map((file) => path.join(pkgDir, file));\n logger.debug(`removeLinksFromNodeModules, deleting the following files:\n${pathsToRemove.join('\\n')}`);\n await Promise.all(pathsToRemove.map((file) => fs.remove(file)));\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAG,YAAA;EAAA,MAAAH,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAC,WAAA,YAAAA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AAI,CAAD,CAAC,CAACuH,QAAQ,CAAC8C,eAAe,EAAEnE,IAAI,CAAC,CAAC;EAC5F,MAAMsE,MAAM,GAAG,MAAMxI,SAAS,CAACyI,uBAAuB,CAAChI,SAAS,CAAC;EACjE,MAAMiI,aAAa,GAAGH,0BAA0B,CAACjH,GAAG,CAAE4C,IAAI,IAAKlG,IAAI,CAAD,CAAC,CAACoG,IAAI,CAACoE,MAAM,EAAEtE,IAAI,CAAC,CAAC;EACvF/B,iBAAM,CAACC,KAAK,CAAC;AACf,EAAEsG,aAAa,CAACtE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;EAC3B,MAAMhD,OAAO,CAACC,GAAG,CAACqH,aAAa,CAACpH,GAAG,CAAE4C,IAAI,IAAKK,kBAAE,CAACoE,MAAM,CAACzE,IAAI,CAAC,CAAC,CAAC;AACjE","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PackageJsonFile } from '@teambit/component.sources';
|
|
2
|
+
import { Component } from '@teambit/component';
|
|
3
|
+
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,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PackageJsonTransformer = void 0;
|
|
7
|
+
function _lodash() {
|
|
8
|
+
const data = require("lodash");
|
|
9
|
+
_lodash = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _pMapSeries() {
|
|
15
|
+
const data = _interopRequireDefault(require("p-map-series"));
|
|
16
|
+
_pMapSeries = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _legacy() {
|
|
22
|
+
const data = require("@teambit/legacy.utils");
|
|
23
|
+
_legacy = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
29
|
+
class PackageJsonTransformer {
|
|
30
|
+
static packageJsonTransformersRegistry = [];
|
|
31
|
+
static registerPackageJsonTransformer(func) {
|
|
32
|
+
this.packageJsonTransformersRegistry.push(func);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* these are changes made by aspects
|
|
37
|
+
*/
|
|
38
|
+
static async applyTransformers(component, packageJson) {
|
|
39
|
+
let newPackageJsonObject = packageJson.packageJsonObject;
|
|
40
|
+
await (0, _pMapSeries().default)(PackageJsonTransformer.packageJsonTransformersRegistry, async transformer => {
|
|
41
|
+
newPackageJsonObject = await transformer(component, newPackageJsonObject);
|
|
42
|
+
});
|
|
43
|
+
const scopeId = component.id.scope;
|
|
44
|
+
const {
|
|
45
|
+
scope,
|
|
46
|
+
owner
|
|
47
|
+
} = (0, _legacy().parseScope)(scopeId);
|
|
48
|
+
const name = component.id.fullName;
|
|
49
|
+
const contextForReplace = {
|
|
50
|
+
mainFile: component.state._consumer.mainFile,
|
|
51
|
+
name,
|
|
52
|
+
scope,
|
|
53
|
+
scopeId,
|
|
54
|
+
owner
|
|
55
|
+
};
|
|
56
|
+
// TODO: Consider calling the replacePlaceHoldersRecursive instead
|
|
57
|
+
replacePlaceHolders(newPackageJsonObject, contextForReplace);
|
|
58
|
+
if (newPackageJsonObject.exports && typeof newPackageJsonObject.exports === 'object') {
|
|
59
|
+
replacePlaceHoldersRecursive(newPackageJsonObject.exports, contextForReplace);
|
|
60
|
+
}
|
|
61
|
+
packageJson.mergePackageJsonObject(newPackageJsonObject);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.PackageJsonTransformer = PackageJsonTransformer;
|
|
65
|
+
function replacePlaceHoldersRecursive(obj, contextForReplace) {
|
|
66
|
+
Object.keys(obj).forEach(key => {
|
|
67
|
+
let value = obj[key];
|
|
68
|
+
if (typeof value === 'string') {
|
|
69
|
+
value = (0, _legacy().replacePlaceHolderForPackageValue)(contextForReplace, obj[key]);
|
|
70
|
+
obj[key] = value;
|
|
71
|
+
} else if ((0, _lodash().isObject)(value)) {
|
|
72
|
+
replacePlaceHoldersRecursive(value, contextForReplace);
|
|
73
|
+
}
|
|
74
|
+
}, {});
|
|
75
|
+
}
|
|
76
|
+
function replacePlaceHolders(obj, contextForReplace) {
|
|
77
|
+
Object.keys(obj).forEach(key => {
|
|
78
|
+
let value = obj[key];
|
|
79
|
+
if (typeof value === 'string') {
|
|
80
|
+
value = (0, _legacy().replacePlaceHolderForPackageValue)(contextForReplace, obj[key]);
|
|
81
|
+
}
|
|
82
|
+
obj[key] = value;
|
|
83
|
+
}, {});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=package-json-transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_lodash","data","require","_pMapSeries","_interopRequireDefault","_legacy","e","__esModule","default","PackageJsonTransformer","packageJsonTransformersRegistry","registerPackageJsonTransformer","func","push","applyTransformers","component","packageJson","newPackageJsonObject","packageJsonObject","mapSeries","transformer","scopeId","id","scope","owner","parseScope","name","fullName","contextForReplace","mainFile","state","_consumer","replacePlaceHolders","exports","replacePlaceHoldersRecursive","mergePackageJsonObject","obj","Object","keys","forEach","key","value","replacePlaceHolderForPackageValue","isObject"],"sources":["package-json-transformer.ts"],"sourcesContent":["import { isObject } from 'lodash';\nimport mapSeries from 'p-map-series';\nimport { PackageJsonFile } from '@teambit/component.sources';\nimport { parseScope, replacePlaceHolderForPackageValue } from '@teambit/legacy.utils';\nimport { Component } from '@teambit/component';\n\ntype PackageJsonTransformers = Function[];\n\nexport class PackageJsonTransformer {\n static packageJsonTransformersRegistry: PackageJsonTransformers = [];\n static registerPackageJsonTransformer(\n func: (component: Component, packageJsonObject: Record<string, any>) => Promise<Record<string, any>>\n ) {\n this.packageJsonTransformersRegistry.push(func);\n }\n\n /**\n * these are changes made by aspects\n */\n static async applyTransformers(component: Component, packageJson: PackageJsonFile) {\n let newPackageJsonObject = packageJson.packageJsonObject;\n\n await mapSeries(PackageJsonTransformer.packageJsonTransformersRegistry, async (transformer) => {\n newPackageJsonObject = await transformer(component, newPackageJsonObject);\n });\n\n const scopeId = component.id.scope;\n const { scope, owner } = parseScope(scopeId);\n const name = component.id.fullName;\n\n const contextForReplace = {\n mainFile: component.state._consumer.mainFile,\n name,\n scope,\n scopeId,\n owner,\n };\n // TODO: Consider calling the replacePlaceHoldersRecursive instead\n replacePlaceHolders(newPackageJsonObject, contextForReplace);\n if (newPackageJsonObject.exports && typeof newPackageJsonObject.exports === 'object') {\n replacePlaceHoldersRecursive(newPackageJsonObject.exports, contextForReplace);\n }\n packageJson.mergePackageJsonObject(newPackageJsonObject);\n }\n}\n\nfunction replacePlaceHoldersRecursive(obj: Record<string, string>, contextForReplace): void {\n Object.keys(obj).forEach((key) => {\n let value = obj[key];\n if (typeof value === 'string') {\n value = replacePlaceHolderForPackageValue(contextForReplace, obj[key]);\n obj[key] = value;\n } else if (isObject(value)) {\n replacePlaceHoldersRecursive(value, contextForReplace);\n }\n }, {});\n}\n\nfunction replacePlaceHolders(obj: Record<string, string>, contextForReplace): void {\n Object.keys(obj).forEach((key) => {\n let value = obj[key];\n if (typeof value === 'string') {\n value = replacePlaceHolderForPackageValue(contextForReplace, obj[key]);\n }\n obj[key] = value;\n }, {});\n}\n"],"mappings":";;;;;;AAAA,SAAAA,QAAA;EAAA,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ACAJ,GAAG,CAACI,GAAG,CAAC,GAAGC,KAAK;EAClB,CAAC,EAAE,CAAC,CAAC,CAAC;AACR","ignoreList":[]}
|
package/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export {
|
|
2
|
+
NodeModulesLinksResult,
|
|
3
|
+
linkToNodeModulesByIds,
|
|
4
|
+
linkToNodeModulesWithCodemod,
|
|
5
|
+
linkToNodeModulesByComponents,
|
|
6
|
+
removeLinksFromNodeModules,
|
|
7
|
+
} from './node-modules-linker';
|
|
8
|
+
|
|
9
|
+
export { PackageJsonTransformer } from './package-json-transformer';
|
|
10
|
+
|
|
11
|
+
export type { CodemodResult } from './codemod-components';
|