@teambit/install 1.0.379 → 1.0.381
Sign up to get free protection for your applications and to get access to all the features.
- package/artifacts/__bit_junit.xml +2 -2
- package/artifacts/schema.json +579 -441
- package/dist/install.main.runtime.d.ts +37 -5
- package/dist/install.main.runtime.js +91 -7
- package/dist/install.main.runtime.js.map +1 -1
- package/package.json +17 -15
- /package/dist/{preview-1723386924285.js → preview-1723519217877.js} +0 -0
@@ -5,7 +5,7 @@ import { GenerateResult, GeneratorMain } from '@teambit/generator';
|
|
5
5
|
import { ApplicationMain } from '@teambit/application';
|
6
6
|
import { VariantsMain } from '@teambit/variants';
|
7
7
|
import { Component, ComponentMap } from '@teambit/component';
|
8
|
-
import { SlotRegistry } from '@teambit/harmony';
|
8
|
+
import { Harmony, SlotRegistry } from '@teambit/harmony';
|
9
9
|
import { CodemodResult, NodeModulesLinksResult } from '@teambit/workspace.modules.node-modules-linker';
|
10
10
|
import { EnvsMain } from '@teambit/envs';
|
11
11
|
import { IpcEventsMain } from '@teambit/ipc-events';
|
@@ -13,6 +13,7 @@ import { WorkspaceDependencyLifecycleType, DependencyResolverMain, LinkingOption
|
|
13
13
|
import { WorkspaceConfigFilesMain } from '@teambit/workspace-config-files';
|
14
14
|
import { Logger, LoggerMain } from '@teambit/logger';
|
15
15
|
import { IssuesMain } from '@teambit/issues';
|
16
|
+
import { AspectLoaderMain } from '@teambit/aspect-loader';
|
16
17
|
export type WorkspaceLinkOptions = LinkingOptions & {
|
17
18
|
rootPolicy?: WorkspacePolicy;
|
18
19
|
linkToBitRoots?: boolean;
|
@@ -57,14 +58,16 @@ export declare class InstallMain {
|
|
57
58
|
private compiler;
|
58
59
|
private envs;
|
59
60
|
private wsConfigFiles;
|
61
|
+
private aspectLoader;
|
60
62
|
private app;
|
61
63
|
private generator;
|
62
64
|
private preLinkSlot;
|
63
65
|
private preInstallSlot;
|
64
66
|
private postInstallSlot;
|
65
67
|
private ipcEvents;
|
68
|
+
private harmony;
|
66
69
|
private visitedAspects;
|
67
|
-
constructor(dependencyResolver: DependencyResolverMain, logger: Logger, workspace: Workspace, variants: VariantsMain, compiler: CompilerMain, envs: EnvsMain, wsConfigFiles: WorkspaceConfigFilesMain, app: ApplicationMain, generator: GeneratorMain, preLinkSlot: PreLinkSlot, preInstallSlot: PreInstallSlot, postInstallSlot: PostInstallSlot, ipcEvents: IpcEventsMain);
|
70
|
+
constructor(dependencyResolver: DependencyResolverMain, logger: Logger, workspace: Workspace, variants: VariantsMain, compiler: CompilerMain, envs: EnvsMain, wsConfigFiles: WorkspaceConfigFilesMain, aspectLoader: AspectLoaderMain, app: ApplicationMain, generator: GeneratorMain, preLinkSlot: PreLinkSlot, preInstallSlot: PreInstallSlot, postInstallSlot: PostInstallSlot, ipcEvents: IpcEventsMain, harmony: Harmony);
|
68
71
|
/**
|
69
72
|
* Install dependencies for all components in the workspace
|
70
73
|
*
|
@@ -79,6 +82,34 @@ export declare class InstallMain {
|
|
79
82
|
private _addPackages;
|
80
83
|
private _installModules;
|
81
84
|
private shouldClearCacheOnInstall;
|
85
|
+
/**
|
86
|
+
* This function is very important to fix some issues that might happen during the installation process.
|
87
|
+
* The case is the following:
|
88
|
+
* during/before the installation process we load some envs from their bit.env files
|
89
|
+
* this contains code like:
|
90
|
+
* protected tsconfigPath = require.resolve('./config/tsconfig.json');
|
91
|
+
* protected eslintConfigPath = require.resolve('./config/eslintrc.cjs');
|
92
|
+
* When we load that file, we calculated the resolved path, and it's stored in the env
|
93
|
+
* object instance.
|
94
|
+
* then later on during the install we move the env to another location (like bit roots)
|
95
|
+
* which points to a .pnpm folder with some peers, that changed during the install
|
96
|
+
* then when we take this env object and call write ws config for example
|
97
|
+
* or compile
|
98
|
+
* we use that resolved path to calculate the final tsconfig
|
99
|
+
* however that file is no longer exists which result in an error
|
100
|
+
* This function will check if an env folder doesn't exist anymore, and will re-load it
|
101
|
+
* from its new location.
|
102
|
+
* This usually happen when we have install running in the middle of the process followed
|
103
|
+
* by other bit ops.
|
104
|
+
* examples:
|
105
|
+
* bit new - which might run few installs then other ops.
|
106
|
+
* bit switch - which might run few installs then other ops, and potentially change the
|
107
|
+
* peer deps during the install.
|
108
|
+
* bit server (vscode plugin) - which keep the process always live, so any install ops
|
109
|
+
* that change the location, will cause the vscode plugin/bit server to crash later.
|
110
|
+
* @returns
|
111
|
+
*/
|
112
|
+
private reloadMovedEnvs;
|
82
113
|
private _getComponentsManifestsAndRootPolicy;
|
83
114
|
/**
|
84
115
|
* The function `tryWriteConfigFiles` attempts to write workspace config files, and if it fails, it logs an error
|
@@ -166,7 +197,7 @@ export declare class InstallMain {
|
|
166
197
|
static slots: (((registerFn: () => string) => SlotRegistry<PreLinkSlot>) | ((registerFn: () => string) => SlotRegistry<PreInstallSlot>))[];
|
167
198
|
static dependencies: import("@teambit/harmony").Aspect[];
|
168
199
|
static runtime: import("@teambit/harmony").RuntimeDefinition;
|
169
|
-
static provider([dependencyResolver, workspace, loggerExt, variants, cli, compiler, issues, envs, app, ipcEvents, generator, wsConfigFiles,]: [
|
200
|
+
static provider([dependencyResolver, workspace, loggerExt, variants, cli, compiler, issues, envs, app, ipcEvents, generator, wsConfigFiles, aspectLoader,]: [
|
170
201
|
DependencyResolverMain,
|
171
202
|
Workspace,
|
172
203
|
LoggerMain,
|
@@ -178,7 +209,8 @@ export declare class InstallMain {
|
|
178
209
|
ApplicationMain,
|
179
210
|
IpcEventsMain,
|
180
211
|
GeneratorMain,
|
181
|
-
WorkspaceConfigFilesMain
|
182
|
-
|
212
|
+
WorkspaceConfigFilesMain,
|
213
|
+
AspectLoaderMain
|
214
|
+
], _: any, [preLinkSlot, preInstallSlot, postInstallSlot]: [PreLinkSlot, PreInstallSlot, PostInstallSlot], harmony: Harmony): Promise<InstallMain>;
|
183
215
|
}
|
184
216
|
export default InstallMain;
|
@@ -4,6 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = exports.InstallMain = void 0;
|
7
|
+
function _pFilter() {
|
8
|
+
const data = _interopRequireDefault(require("p-filter"));
|
9
|
+
_pFilter = function () {
|
10
|
+
return data;
|
11
|
+
};
|
12
|
+
return data;
|
13
|
+
}
|
7
14
|
function _fsExtra() {
|
8
15
|
const data = _interopRequireWildcard(require("fs-extra"));
|
9
16
|
_fsExtra = function () {
|
@@ -235,16 +242,23 @@ function _update() {
|
|
235
242
|
};
|
236
243
|
return data;
|
237
244
|
}
|
238
|
-
function
|
245
|
+
function _aspectLoader() {
|
246
|
+
const data = require("@teambit/aspect-loader");
|
247
|
+
_aspectLoader = function () {
|
248
|
+
return data;
|
249
|
+
};
|
250
|
+
return data;
|
251
|
+
}
|
239
252
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
240
253
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
254
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
241
255
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
242
256
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
243
257
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
244
258
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
245
259
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
246
260
|
class InstallMain {
|
247
|
-
constructor(dependencyResolver, logger, workspace, variants, compiler, envs, wsConfigFiles, app, generator, preLinkSlot, preInstallSlot, postInstallSlot, ipcEvents) {
|
261
|
+
constructor(dependencyResolver, logger, workspace, variants, compiler, envs, wsConfigFiles, aspectLoader, app, generator, preLinkSlot, preInstallSlot, postInstallSlot, ipcEvents, harmony) {
|
248
262
|
this.dependencyResolver = dependencyResolver;
|
249
263
|
this.logger = logger;
|
250
264
|
this.workspace = workspace;
|
@@ -252,12 +266,14 @@ class InstallMain {
|
|
252
266
|
this.compiler = compiler;
|
253
267
|
this.envs = envs;
|
254
268
|
this.wsConfigFiles = wsConfigFiles;
|
269
|
+
this.aspectLoader = aspectLoader;
|
255
270
|
this.app = app;
|
256
271
|
this.generator = generator;
|
257
272
|
this.preLinkSlot = preLinkSlot;
|
258
273
|
this.preInstallSlot = preInstallSlot;
|
259
274
|
this.postInstallSlot = postInstallSlot;
|
260
275
|
this.ipcEvents = ipcEvents;
|
276
|
+
this.harmony = harmony;
|
261
277
|
_defineProperty(this, "visitedAspects", new Set());
|
262
278
|
}
|
263
279
|
/**
|
@@ -352,8 +368,8 @@ class InstallMain {
|
|
352
368
|
await this.install(packages, {
|
353
369
|
addMissingDeps: installMissing,
|
354
370
|
skipIfExisting: true,
|
355
|
-
writeConfigFiles: false
|
356
|
-
skipPrune: true
|
371
|
+
writeConfigFiles: false
|
372
|
+
// skipPrune: true,
|
357
373
|
});
|
358
374
|
}
|
359
375
|
async _addPackages(packages, options) {
|
@@ -460,6 +476,7 @@ class InstallMain {
|
|
460
476
|
}, pmInstallOptions);
|
461
477
|
let cacheCleared = false;
|
462
478
|
await this.linkCodemods(compDirMap);
|
479
|
+
await this.reloadMovedEnvs();
|
463
480
|
const shouldClearCacheOnInstall = this.shouldClearCacheOnInstall();
|
464
481
|
if (options?.compile ?? true) {
|
465
482
|
const compileStartTime = process.hrtime();
|
@@ -477,6 +494,7 @@ class InstallMain {
|
|
477
494
|
await this.compiler.compileOnWorkspace([], {
|
478
495
|
initiator: _compiler().CompilationInitiator.Install
|
479
496
|
});
|
497
|
+
|
480
498
|
// Right now we don't need to load extensions/execute load slot at this point
|
481
499
|
// await this.compiler.compileOnWorkspace([], { initiator: CompilationInitiator.Install }, undefined, {
|
482
500
|
// executeLoadSlot: true,
|
@@ -522,6 +540,72 @@ class InstallMain {
|
|
522
540
|
const nonLoadedEnvs = this.envs.getFailedToLoadEnvs();
|
523
541
|
return nonLoadedEnvs.length > 0;
|
524
542
|
}
|
543
|
+
|
544
|
+
/**
|
545
|
+
* This function is very important to fix some issues that might happen during the installation process.
|
546
|
+
* The case is the following:
|
547
|
+
* during/before the installation process we load some envs from their bit.env files
|
548
|
+
* this contains code like:
|
549
|
+
* protected tsconfigPath = require.resolve('./config/tsconfig.json');
|
550
|
+
* protected eslintConfigPath = require.resolve('./config/eslintrc.cjs');
|
551
|
+
* When we load that file, we calculated the resolved path, and it's stored in the env
|
552
|
+
* object instance.
|
553
|
+
* then later on during the install we move the env to another location (like bit roots)
|
554
|
+
* which points to a .pnpm folder with some peers, that changed during the install
|
555
|
+
* then when we take this env object and call write ws config for example
|
556
|
+
* or compile
|
557
|
+
* we use that resolved path to calculate the final tsconfig
|
558
|
+
* however that file is no longer exists which result in an error
|
559
|
+
* This function will check if an env folder doesn't exist anymore, and will re-load it
|
560
|
+
* from its new location.
|
561
|
+
* This usually happen when we have install running in the middle of the process followed
|
562
|
+
* by other bit ops.
|
563
|
+
* examples:
|
564
|
+
* bit new - which might run few installs then other ops.
|
565
|
+
* bit switch - which might run few installs then other ops, and potentially change the
|
566
|
+
* peer deps during the install.
|
567
|
+
* bit server (vscode plugin) - which keep the process always live, so any install ops
|
568
|
+
* that change the location, will cause the vscode plugin/bit server to crash later.
|
569
|
+
* @returns
|
570
|
+
*/
|
571
|
+
async reloadMovedEnvs() {
|
572
|
+
const allEnvs = this.envs.getAllRegisteredEnvs();
|
573
|
+
const movedEnvs = await (0, _pFilter().default)(allEnvs, async env => {
|
574
|
+
if (!env.__path) return false;
|
575
|
+
const regularPathExists = await (0, _fsExtra().pathExists)(env.__path);
|
576
|
+
const resolvedPathExists = await (0, _fsExtra().pathExists)(env.__resolvedPath);
|
577
|
+
return !regularPathExists || !resolvedPathExists;
|
578
|
+
});
|
579
|
+
const idsToLoad = movedEnvs.map(env => env.id);
|
580
|
+
// const envPlugin = this.envs.getEnvPlugin();
|
581
|
+
|
582
|
+
if (idsToLoad.length && this.workspace) {
|
583
|
+
const componentIdsToLoad = idsToLoad.map(id => _component().ComponentID.fromString(id));
|
584
|
+
const aspects = await this.workspace.resolveAspects(undefined, componentIdsToLoad, {
|
585
|
+
requestedOnly: true,
|
586
|
+
excludeCore: true,
|
587
|
+
throwOnError: false
|
588
|
+
// Theoretically we should use skipDeps here, but according to implementation at the moment
|
589
|
+
// it will lead to plugins not load, and we need them to be loaded.
|
590
|
+
// This is a bug in the flow and should be fixed.
|
591
|
+
// skipDeps: true,
|
592
|
+
});
|
593
|
+
const loadedPlugins = (0, _lodash().compact)(await Promise.all(aspects.map(aspectDef => {
|
594
|
+
const localPath = aspectDef.aspectPath;
|
595
|
+
const component = aspectDef.component;
|
596
|
+
if (!component) return undefined;
|
597
|
+
const plugins = this.aspectLoader.getPlugins(component, localPath);
|
598
|
+
if (plugins.has()) {
|
599
|
+
return plugins.load(_cli().MainRuntime.name);
|
600
|
+
}
|
601
|
+
})));
|
602
|
+
await Promise.all(loadedPlugins.map(plugin => {
|
603
|
+
const runtime = plugin.getRuntime(_cli().MainRuntime);
|
604
|
+
return runtime?.provider(undefined, undefined, undefined, this.harmony);
|
605
|
+
}));
|
606
|
+
}
|
607
|
+
return movedEnvs;
|
608
|
+
}
|
525
609
|
async _getComponentsManifestsAndRootPolicy(installer, options) {
|
526
610
|
const mergedRootPolicy = await this.addConfiguredAspectsToWorkspacePolicy();
|
527
611
|
await this.addConfiguredGeneratorEnvsToWorkspacePolicy(mergedRootPolicy);
|
@@ -1032,7 +1116,7 @@ class InstallMain {
|
|
1032
1116
|
await this.link();
|
1033
1117
|
}
|
1034
1118
|
}
|
1035
|
-
static async provider([dependencyResolver, workspace, loggerExt, variants, cli, compiler, issues, envs, app, ipcEvents, generator, wsConfigFiles], _, [preLinkSlot, preInstallSlot, postInstallSlot]) {
|
1119
|
+
static async provider([dependencyResolver, workspace, loggerExt, variants, cli, compiler, issues, envs, app, ipcEvents, generator, wsConfigFiles, aspectLoader], _, [preLinkSlot, preInstallSlot, postInstallSlot], harmony) {
|
1036
1120
|
const logger = loggerExt.createLogger(_install().InstallAspect.id);
|
1037
1121
|
ipcEvents.registerGotEventSlot(async eventName => {
|
1038
1122
|
if (eventName !== 'onPostInstall') return;
|
@@ -1041,7 +1125,7 @@ class InstallMain {
|
|
1041
1125
|
workspace.clearAllComponentsCache();
|
1042
1126
|
await (0, _pMapSeries().default)(postInstallSlot.values(), fn => fn());
|
1043
1127
|
});
|
1044
|
-
const installExt = new InstallMain(dependencyResolver, logger, workspace, variants, compiler, envs, wsConfigFiles, app, generator, preLinkSlot, preInstallSlot, postInstallSlot, ipcEvents);
|
1128
|
+
const installExt = new InstallMain(dependencyResolver, logger, workspace, variants, compiler, envs, wsConfigFiles, aspectLoader, app, generator, preLinkSlot, preInstallSlot, postInstallSlot, ipcEvents, harmony);
|
1045
1129
|
if (issues) {
|
1046
1130
|
issues.registerAddComponentsIssues(installExt.addDuplicateComponentAndPackageIssue.bind(installExt));
|
1047
1131
|
}
|
@@ -1058,7 +1142,7 @@ class InstallMain {
|
|
1058
1142
|
}
|
1059
1143
|
exports.InstallMain = InstallMain;
|
1060
1144
|
_defineProperty(InstallMain, "slots", [_harmony().Slot.withType(), _harmony().Slot.withType(), _harmony().Slot.withType()]);
|
1061
|
-
_defineProperty(InstallMain, "dependencies", [_dependencyResolver().DependencyResolverAspect, _workspace2().WorkspaceAspect, _logger().LoggerAspect, _variants().VariantsAspect, _cli().CLIAspect, _compiler().CompilerAspect, _issues().IssuesAspect, _envs().EnvsAspect, _application().ApplicationAspect, _ipcEvents().IpcEventsAspect, _generator().GeneratorAspect, _workspaceConfigFiles().WorkspaceConfigFilesAspect]);
|
1145
|
+
_defineProperty(InstallMain, "dependencies", [_dependencyResolver().DependencyResolverAspect, _workspace2().WorkspaceAspect, _logger().LoggerAspect, _variants().VariantsAspect, _cli().CLIAspect, _compiler().CompilerAspect, _issues().IssuesAspect, _envs().EnvsAspect, _application().ApplicationAspect, _ipcEvents().IpcEventsAspect, _generator().GeneratorAspect, _workspaceConfigFiles().WorkspaceConfigFilesAspect, _aspectLoader().AspectLoaderAspect]);
|
1062
1146
|
_defineProperty(InstallMain, "runtime", _cli().MainRuntime);
|
1063
1147
|
function hasComponentsFromWorkspaceInMissingDeps({
|
1064
1148
|
componentDirectoryMap,
|