@teambit/dependency-resolver 1.0.108 → 1.0.109
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/artifacts/__bit_junit.xml +55 -0
- package/artifacts/preview/teambit_dependencies_dependency_resolver-preview.js +1 -0
- package/dist/{preview-1703647408454.js → preview-1703698405864.js} +2 -2
- package/package.json +16 -16
- package/apply-updates.spec.ts +0 -215
- package/apply-updates.ts +0 -81
- package/dependency-detector.ts +0 -5
- package/dependency-env.ts +0 -6
- package/dependency-installer.ts +0 -347
- package/dependency-linker.ts +0 -719
- package/dependency-resolver.aspect.ts +0 -7
- package/dependency-resolver.graphql.ts +0 -99
- package/dependency-resolver.main.runtime.spec.ts +0 -530
- package/dependency-resolver.main.runtime.ts +0 -1797
- package/dependency-version-resolver.ts +0 -42
- package/extend-with-components-from-dir.ts +0 -29
- package/get-all-policy-pkgs.spec.ts +0 -82
- package/get-all-policy-pkgs.ts +0 -126
- package/index.ts +0 -70
- package/package-manager-legacy.ts +0 -137
- package/package-manager.ts +0 -174
- package/types.ts +0 -77
package/dependency-installer.ts
DELETED
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
import mapSeries from 'p-map-series';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import fs from 'fs-extra';
|
|
4
|
-
import { MainAspect, AspectLoaderMain } from '@teambit/aspect-loader';
|
|
5
|
-
import { ComponentMap } from '@teambit/component';
|
|
6
|
-
import { CreateFromComponentsOptions, DependencyResolverMain } from '@teambit/dependency-resolver';
|
|
7
|
-
import { Logger } from '@teambit/logger';
|
|
8
|
-
import { PathAbsolute } from '@teambit/legacy/dist/utils/path';
|
|
9
|
-
import { PeerDependencyRules, ProjectManifest } from '@pnpm/types';
|
|
10
|
-
import { MainAspectNotInstallable, RootDirNotDefined } from './exceptions';
|
|
11
|
-
import { PackageManager, PackageManagerInstallOptions, PackageImportMethod } from './package-manager';
|
|
12
|
-
import { WorkspacePolicy } from './policy';
|
|
13
|
-
|
|
14
|
-
const DEFAULT_PM_INSTALL_OPTIONS: PackageManagerInstallOptions = {
|
|
15
|
-
dedupe: true,
|
|
16
|
-
copyPeerToRuntimeOnRoot: true,
|
|
17
|
-
copyPeerToRuntimeOnComponents: false,
|
|
18
|
-
installPeersFromEnvs: false,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const DEFAULT_INSTALL_OPTIONS: InstallOptions = {
|
|
22
|
-
installTeambitBit: false,
|
|
23
|
-
excludeExtensionsDependencies: false,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type DepInstallerContext = {
|
|
27
|
-
inCapsule?: boolean;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type InstallArgs = {
|
|
31
|
-
rootDir: string | undefined;
|
|
32
|
-
rootPolicy: WorkspacePolicy;
|
|
33
|
-
componentDirectoryMap: ComponentMap<string>;
|
|
34
|
-
options: InstallOptions;
|
|
35
|
-
packageManagerOptions: PackageManagerInstallOptions;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export type InstallOptions = {
|
|
39
|
-
installTeambitBit: boolean;
|
|
40
|
-
packageManagerConfigRootDir?: string;
|
|
41
|
-
resolveVersionsFromDependenciesOnly?: boolean;
|
|
42
|
-
linkedDependencies?: Record<string, Record<string, string>>;
|
|
43
|
-
forceTeambitHarmonyLink?: boolean;
|
|
44
|
-
excludeExtensionsDependencies?: boolean;
|
|
45
|
-
dedupeInjectedDeps?: boolean;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type GetComponentManifestsOptions = {
|
|
49
|
-
componentDirectoryMap: ComponentMap<string>;
|
|
50
|
-
rootPolicy: WorkspacePolicy;
|
|
51
|
-
rootDir: string;
|
|
52
|
-
resolveVersionsFromDependenciesOnly?: boolean;
|
|
53
|
-
referenceLocalPackages?: boolean;
|
|
54
|
-
hasRootComponents?: boolean;
|
|
55
|
-
excludeExtensionsDependencies?: boolean;
|
|
56
|
-
} & Pick<
|
|
57
|
-
PackageManagerInstallOptions,
|
|
58
|
-
'dedupe' | 'dependencyFilterFn' | 'copyPeerToRuntimeOnComponents' | 'copyPeerToRuntimeOnRoot' | 'installPeersFromEnvs'
|
|
59
|
-
>;
|
|
60
|
-
|
|
61
|
-
export type PreInstallSubscriber = (installer: DependencyInstaller, installArgs: InstallArgs) => Promise<void>;
|
|
62
|
-
export type PreInstallSubscriberList = Array<PreInstallSubscriber>;
|
|
63
|
-
|
|
64
|
-
export type PostInstallSubscriber = (installer: DependencyInstaller, installArgs: InstallArgs) => Promise<void>;
|
|
65
|
-
export type PostInstallSubscriberList = Array<PostInstallSubscriber>;
|
|
66
|
-
|
|
67
|
-
export class DependencyInstaller {
|
|
68
|
-
constructor(
|
|
69
|
-
/**
|
|
70
|
-
* package manager instance.
|
|
71
|
-
*/
|
|
72
|
-
private packageManager: PackageManager,
|
|
73
|
-
|
|
74
|
-
private aspectLoader: AspectLoaderMain,
|
|
75
|
-
|
|
76
|
-
private logger: Logger,
|
|
77
|
-
|
|
78
|
-
private dependencyResolver: DependencyResolverMain,
|
|
79
|
-
|
|
80
|
-
private rootDir?: string | PathAbsolute,
|
|
81
|
-
|
|
82
|
-
private cacheRootDir?: string | PathAbsolute,
|
|
83
|
-
|
|
84
|
-
private preInstallSubscriberList?: PreInstallSubscriberList,
|
|
85
|
-
|
|
86
|
-
private postInstallSubscriberList?: PostInstallSubscriberList,
|
|
87
|
-
|
|
88
|
-
private nodeLinker?: 'hoisted' | 'isolated',
|
|
89
|
-
|
|
90
|
-
private packageImportMethod?: PackageImportMethod,
|
|
91
|
-
|
|
92
|
-
private sideEffectsCache?: boolean,
|
|
93
|
-
|
|
94
|
-
private nodeVersion?: string,
|
|
95
|
-
|
|
96
|
-
private engineStrict?: boolean,
|
|
97
|
-
|
|
98
|
-
private peerDependencyRules?: PeerDependencyRules,
|
|
99
|
-
|
|
100
|
-
private neverBuiltDependencies?: string[],
|
|
101
|
-
|
|
102
|
-
private preferOffline?: boolean,
|
|
103
|
-
|
|
104
|
-
private installingContext: DepInstallerContext = {}
|
|
105
|
-
) {}
|
|
106
|
-
|
|
107
|
-
async install(
|
|
108
|
-
rootDir: string | undefined,
|
|
109
|
-
rootPolicy: WorkspacePolicy,
|
|
110
|
-
componentDirectoryMap: ComponentMap<string>,
|
|
111
|
-
options: InstallOptions = DEFAULT_INSTALL_OPTIONS,
|
|
112
|
-
packageManagerOptions: PackageManagerInstallOptions = DEFAULT_PM_INSTALL_OPTIONS
|
|
113
|
-
) {
|
|
114
|
-
const finalRootDir = rootDir ?? this.rootDir;
|
|
115
|
-
if (!finalRootDir) {
|
|
116
|
-
throw new RootDirNotDefined();
|
|
117
|
-
}
|
|
118
|
-
const manifests = await this.getComponentManifests({
|
|
119
|
-
...packageManagerOptions,
|
|
120
|
-
componentDirectoryMap,
|
|
121
|
-
rootPolicy,
|
|
122
|
-
rootDir: finalRootDir,
|
|
123
|
-
resolveVersionsFromDependenciesOnly: options.resolveVersionsFromDependenciesOnly,
|
|
124
|
-
referenceLocalPackages: packageManagerOptions.rootComponentsForCapsules,
|
|
125
|
-
excludeExtensionsDependencies: options.excludeExtensionsDependencies,
|
|
126
|
-
});
|
|
127
|
-
return this.installComponents(
|
|
128
|
-
finalRootDir,
|
|
129
|
-
manifests,
|
|
130
|
-
rootPolicy,
|
|
131
|
-
componentDirectoryMap,
|
|
132
|
-
options,
|
|
133
|
-
packageManagerOptions
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async installComponents(
|
|
138
|
-
rootDir: string | undefined,
|
|
139
|
-
manifests: Record<string, ProjectManifest>,
|
|
140
|
-
rootPolicy: WorkspacePolicy,
|
|
141
|
-
componentDirectoryMap: ComponentMap<string>,
|
|
142
|
-
options: InstallOptions = DEFAULT_INSTALL_OPTIONS,
|
|
143
|
-
packageManagerOptions: PackageManagerInstallOptions = DEFAULT_PM_INSTALL_OPTIONS
|
|
144
|
-
): Promise<{ dependenciesChanged: boolean }> {
|
|
145
|
-
const args = {
|
|
146
|
-
componentDirectoryMap,
|
|
147
|
-
options,
|
|
148
|
-
packageManagerOptions,
|
|
149
|
-
rootDir,
|
|
150
|
-
rootPolicy,
|
|
151
|
-
};
|
|
152
|
-
await this.runPrePostSubscribers(this.preInstallSubscriberList, 'pre', args);
|
|
153
|
-
const mainAspect: MainAspect = this.aspectLoader.mainAspect;
|
|
154
|
-
const finalRootDir = rootDir || this.rootDir;
|
|
155
|
-
if (!finalRootDir) {
|
|
156
|
-
throw new RootDirNotDefined();
|
|
157
|
-
}
|
|
158
|
-
if (options.linkedDependencies) {
|
|
159
|
-
manifests = JSON.parse(JSON.stringify(manifests));
|
|
160
|
-
const linkedDependencies = JSON.parse(
|
|
161
|
-
JSON.stringify(options.linkedDependencies)
|
|
162
|
-
) as typeof options.linkedDependencies;
|
|
163
|
-
if (linkedDependencies[finalRootDir]) {
|
|
164
|
-
const directDeps = new Set<string>();
|
|
165
|
-
Object.values(manifests).forEach((manifest) => {
|
|
166
|
-
for (const depName of Object.keys({ ...manifest.dependencies, ...manifest.devDependencies })) {
|
|
167
|
-
directDeps.add(depName);
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
for (const manifest of Object.values(manifests)) {
|
|
171
|
-
if (manifest.name && directDeps.has(manifest.name)) {
|
|
172
|
-
delete linkedDependencies[finalRootDir][manifest.name];
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (options.forceTeambitHarmonyLink && manifests[finalRootDir].dependencies?.['@teambit/harmony']) {
|
|
176
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
177
|
-
delete manifests[finalRootDir].dependencies!['@teambit/harmony'];
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
Object.entries(linkedDependencies).forEach(([dir, linkedDeps]) => {
|
|
181
|
-
if (!manifests[dir]) {
|
|
182
|
-
manifests[dir] = {};
|
|
183
|
-
}
|
|
184
|
-
manifests[dir].dependencies = {
|
|
185
|
-
...linkedDeps,
|
|
186
|
-
...manifests[dir].dependencies,
|
|
187
|
-
};
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
const hidePackageManagerOutput = !!(this.installingContext.inCapsule && process.env.VERBOSE_PM_OUTPUT !== 'true');
|
|
191
|
-
|
|
192
|
-
// Make sure to take other default if passed options with only one option
|
|
193
|
-
const calculatedPmOpts = {
|
|
194
|
-
...DEFAULT_PM_INSTALL_OPTIONS,
|
|
195
|
-
cacheRootDir: this.cacheRootDir,
|
|
196
|
-
nodeLinker: this.nodeLinker,
|
|
197
|
-
packageImportMethod: this.packageImportMethod,
|
|
198
|
-
sideEffectsCache: this.sideEffectsCache,
|
|
199
|
-
nodeVersion: this.nodeVersion,
|
|
200
|
-
engineStrict: this.engineStrict,
|
|
201
|
-
packageManagerConfigRootDir: options.packageManagerConfigRootDir,
|
|
202
|
-
peerDependencyRules: this.peerDependencyRules,
|
|
203
|
-
hidePackageManagerOutput,
|
|
204
|
-
neverBuiltDependencies: ['core-js', ...(this.neverBuiltDependencies ?? [])],
|
|
205
|
-
preferOffline: this.preferOffline,
|
|
206
|
-
dedupeInjectedDeps: options.dedupeInjectedDeps,
|
|
207
|
-
...packageManagerOptions,
|
|
208
|
-
};
|
|
209
|
-
if (options.installTeambitBit) {
|
|
210
|
-
if (!mainAspect.version || !mainAspect.packageName) {
|
|
211
|
-
throw new MainAspectNotInstallable();
|
|
212
|
-
}
|
|
213
|
-
const version = mainAspect.version;
|
|
214
|
-
rootPolicy.add({
|
|
215
|
-
dependencyId: mainAspect.packageName,
|
|
216
|
-
lifecycleType: 'runtime',
|
|
217
|
-
value: {
|
|
218
|
-
version,
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (!packageManagerOptions.rootComponents && !packageManagerOptions.keepExistingModulesDir) {
|
|
224
|
-
// Remove node modules dir for all components dirs, since it might contain left overs from previous install.
|
|
225
|
-
//
|
|
226
|
-
// This is not needed when "rootComponents" are used, as in that case the package manager handles the node_modules
|
|
227
|
-
// and it never leaves node_modules in a broken state.
|
|
228
|
-
// Removing node_modules in that case would delete useful state information that is used by Yarn or pnpm.
|
|
229
|
-
await this.cleanCompsNodeModules(componentDirectoryMap);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const messagePrefix = 'running package installation';
|
|
233
|
-
const messageSuffix = `using ${this.packageManager.name}`;
|
|
234
|
-
const message = this.installingContext?.inCapsule
|
|
235
|
-
? `(capsule) ${messagePrefix} in root dir ${this.rootDir} ${messageSuffix}`
|
|
236
|
-
: `${messagePrefix} ${messageSuffix}`;
|
|
237
|
-
if (!hidePackageManagerOutput) {
|
|
238
|
-
this.logger.setStatusLine(message);
|
|
239
|
-
}
|
|
240
|
-
const startTime = process.hrtime();
|
|
241
|
-
|
|
242
|
-
// TODO: the cache should be probably passed to the package manager constructor not to the install function
|
|
243
|
-
const installResult = await this.packageManager.install(
|
|
244
|
-
{
|
|
245
|
-
rootDir: finalRootDir,
|
|
246
|
-
manifests,
|
|
247
|
-
componentDirectoryMap,
|
|
248
|
-
},
|
|
249
|
-
calculatedPmOpts
|
|
250
|
-
);
|
|
251
|
-
if (!hidePackageManagerOutput) {
|
|
252
|
-
this.logger.consoleSuccess(`done ${message}`, startTime);
|
|
253
|
-
}
|
|
254
|
-
await this.runPrePostSubscribers(this.postInstallSubscriberList, 'post', args);
|
|
255
|
-
return installResult;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
public async pruneModules(rootDir: string): Promise<void> {
|
|
259
|
-
if (!this.packageManager.pruneModules) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
await this.packageManager.pruneModules(rootDir);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Compute all the component manifests (a.k.a. package.json files) that should be passed to the package manager
|
|
267
|
-
* in order to install the dependencies.
|
|
268
|
-
*/
|
|
269
|
-
public async getComponentManifests({
|
|
270
|
-
componentDirectoryMap,
|
|
271
|
-
rootPolicy,
|
|
272
|
-
rootDir,
|
|
273
|
-
dedupe,
|
|
274
|
-
dependencyFilterFn,
|
|
275
|
-
copyPeerToRuntimeOnComponents,
|
|
276
|
-
copyPeerToRuntimeOnRoot,
|
|
277
|
-
installPeersFromEnvs,
|
|
278
|
-
resolveVersionsFromDependenciesOnly,
|
|
279
|
-
referenceLocalPackages,
|
|
280
|
-
hasRootComponents,
|
|
281
|
-
excludeExtensionsDependencies,
|
|
282
|
-
}: GetComponentManifestsOptions) {
|
|
283
|
-
const options: CreateFromComponentsOptions = {
|
|
284
|
-
filterComponentsFromManifests: true,
|
|
285
|
-
createManifestForComponentsWithoutDependencies: true,
|
|
286
|
-
dedupe,
|
|
287
|
-
dependencyFilterFn,
|
|
288
|
-
resolveVersionsFromDependenciesOnly,
|
|
289
|
-
referenceLocalPackages,
|
|
290
|
-
hasRootComponents,
|
|
291
|
-
excludeExtensionsDependencies,
|
|
292
|
-
};
|
|
293
|
-
const workspaceManifest = await this.dependencyResolver.getWorkspaceManifest(
|
|
294
|
-
undefined,
|
|
295
|
-
undefined,
|
|
296
|
-
rootPolicy,
|
|
297
|
-
rootDir,
|
|
298
|
-
componentDirectoryMap.components,
|
|
299
|
-
options,
|
|
300
|
-
this.installingContext
|
|
301
|
-
);
|
|
302
|
-
const manifests: Record<string, ProjectManifest> = componentDirectoryMap
|
|
303
|
-
.toArray()
|
|
304
|
-
.reduce((acc, [component, dir]) => {
|
|
305
|
-
const packageName = this.dependencyResolver.getPackageName(component);
|
|
306
|
-
const manifest = workspaceManifest.componentsManifestsMap.get(packageName);
|
|
307
|
-
if (manifest) {
|
|
308
|
-
acc[dir] = manifest.toJson({ copyPeerToRuntime: copyPeerToRuntimeOnComponents });
|
|
309
|
-
}
|
|
310
|
-
return acc;
|
|
311
|
-
}, {});
|
|
312
|
-
if (!manifests[rootDir]) {
|
|
313
|
-
manifests[rootDir] = workspaceManifest.toJson({
|
|
314
|
-
copyPeerToRuntime: copyPeerToRuntimeOnRoot,
|
|
315
|
-
installPeersFromEnvs,
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
return manifests;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
private async cleanCompsNodeModules(componentDirectoryMap: ComponentMap<string>) {
|
|
322
|
-
const promises = componentDirectoryMap.toArray().map(([, dir]) => {
|
|
323
|
-
const nmDir = path.join(dir, 'node_modules');
|
|
324
|
-
return fs.remove(nmDir);
|
|
325
|
-
});
|
|
326
|
-
return Promise.all(promises);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
private async runPrePostSubscribers(
|
|
330
|
-
subscribers: PreInstallSubscriberList | PostInstallSubscriberList = [],
|
|
331
|
-
type: 'pre' | 'post',
|
|
332
|
-
args: InstallArgs
|
|
333
|
-
): Promise<void> {
|
|
334
|
-
const message = this.installingContext?.inCapsule
|
|
335
|
-
? `(capsule) running ${type} install subscribers in root dir ${this.rootDir}`
|
|
336
|
-
: `running ${type} install subscribers`;
|
|
337
|
-
if (!this.installingContext?.inCapsule) {
|
|
338
|
-
this.logger.setStatusLine(message);
|
|
339
|
-
}
|
|
340
|
-
await mapSeries(subscribers, async (subscriber) => {
|
|
341
|
-
return subscriber(this, args);
|
|
342
|
-
});
|
|
343
|
-
if (!this.installingContext?.inCapsule) {
|
|
344
|
-
this.logger.consoleSuccess(message);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|